Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced string processing in SOURCE with ProcessStringValue.
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index 37d1361..4c2cbc6 100644 (file)
@@ -549,6 +549,7 @@ void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySe
        wxString PropertyValue;
        wxString PropertyTokens;
        bool FirstToken = TRUE;
+       bool PropertyMatched = FALSE;
        int intSplitsFound = 0;
        int intSplitSize = 0;
        int intPrevValue = 8;
@@ -599,42 +600,28 @@ void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySe
                
                CaptureString(&PropertyValue, FALSE);
                
-               if (PropertyName == wxT("ALTID")){
-
-                       SourceListAltID.erase(*SourceCount);
-                       SourceListAltID.insert(std::make_pair(*SourceCount, PropertyValue));
+               ProcessStringValue(&PropertyName, "ALTID", &SourceListAltID, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "PID", &SourceListPID, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "MEDIATYPE", &SourceListMediatype, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessIntegerValue(&PropertyName, "PREF", &SourceListPref, &PropertyValue, SourceCount, &PropertyMatched);
                
-               } else if (PropertyName == wxT("PID")){
-
-                       SourceListPID.erase(*SourceCount);
-                       SourceListPID.insert(std::make_pair(*SourceCount, PropertyValue));
+               if (PropertyMatched == TRUE){
                
-               } else if (PropertyName == wxT("PREF")){
-                       
-                       ProcessIntegerValue(this, &SourceListPref, &PropertyValue, SourceCount);
-
-               } else if (PropertyName == wxT("MEDIATYPE")){
+                       PropertyMatched = FALSE;
+                       continue;
                
-                       SourceListMediatype.erase(*SourceCount);
-                       SourceListMediatype.insert(std::make_pair(*SourceCount, PropertyValue));
-
-               } else {
+               }
                
-                       // Something else we don't know about so append
-                       // to the tokens variable.
-                       
-                       if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
+               if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
                        
-                               if (FirstToken == TRUE){
-                               
-                                       PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
-                                       FirstToken = FALSE;
-                               
-                               } else {
-                               
-                                       PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+                       if (FirstToken == TRUE){
                                
-                               }
+                               PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+                               FirstToken = FALSE;
+                       
+                       } else {
+                       
+                               PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
                        
                        }
                
@@ -769,7 +756,7 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, &GroupsListPref, &PropertyValue, GroupCount);
+                       ProcessIntegerValue(&GroupsListPref, &PropertyValue, GroupCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
 
@@ -866,7 +853,7 @@ void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2,
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, &FullNamesListPref, &PropertyValue, FNCount);
+                       ProcessIntegerValue(&FullNamesListPref, &PropertyValue, FNCount);
                
                } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
                        
@@ -1226,7 +1213,7 @@ void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString Property
 
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, NicknamesListPref, &PropertyValue, NicknameCount);
+                       ProcessIntegerValue(NicknamesListPref, &PropertyValue, NicknameCount);
                
                } else if (PropertyName == wxT("LANGUAGE")){
 
@@ -1701,7 +1688,7 @@ void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString Property
 
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, TZListPref, &PropertyValue, TimeZoneCount);
+                       ProcessIntegerValue(TZListPref, &PropertyValue, TimeZoneCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
 
@@ -1918,7 +1905,7 @@ void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertyS
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, AddressListPref, &PropertyValue, AddressCount);
+                       ProcessIntegerValue(AddressListPref, &PropertyValue, AddressCount);
                
                } else {
                
@@ -2183,7 +2170,7 @@ void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg
                
                } else if (PropertyName == wxT("PREF")){
                        
-                       ProcessIntegerValue(this, EmailListPref, &PropertyValue, EmailCount);
+                       ProcessIntegerValue(EmailListPref, &PropertyValue, EmailCount);
                
                } else {
                
@@ -2318,7 +2305,7 @@ void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2,
                
                } else if (PropertyName == wxT("PREF")){
                        
-                       ProcessIntegerValue(this, IMListPref, &PropertyValue, IMCount);
+                       ProcessIntegerValue(IMListPref, &PropertyValue, IMCount);
                
                } else {
                
@@ -2612,7 +2599,7 @@ void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString Propert
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, TelephoneListPref, &PropertyValue, TelephoneCount);
+                       ProcessIntegerValue(TelephoneListPref, &PropertyValue, TelephoneCount);
                
                } else {
                
@@ -2738,7 +2725,7 @@ void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString Property
                
                } else if (PropertyName == wxT("PREF")){
                        
-                       ProcessIntegerValue(this, LanguageListPref, &PropertyValue, LanguageCount);
+                       ProcessIntegerValue(LanguageListPref, &PropertyValue, LanguageCount);
                
                } else {
                
@@ -2872,7 +2859,7 @@ void ContactDataObject::ProcessGeographic(wxString PropertySeg1, wxString Proper
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, GeopositionListPref, &PropertyValue, GeographicCount);
+                       ProcessIntegerValue(GeopositionListPref, &PropertyValue, GeographicCount);
                
                } else {
                
@@ -3108,7 +3095,7 @@ void ContactDataObject::ProcessRelated(wxString PropertySeg1, wxString PropertyS
                
                } else if (PropertyName == wxT("LANGUAGE")){
 
-                       ProcessIntegerValue(this, &GeneralRelatedListPref, &PropertyValue, RelatedCount);
+                       ProcessIntegerValue(&GeneralRelatedListPref, &PropertyValue, RelatedCount);
                
                } else if (PropertyName != wxT("TYPE")) {
                
@@ -3260,7 +3247,7 @@ void ContactDataObject::ProcessURL(wxString PropertySeg1, wxString PropertySeg2,
                        
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, WebsiteListPref, &PropertyValue, URLCount);
+                       ProcessIntegerValue(WebsiteListPref, &PropertyValue, URLCount);
                                                        
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -3418,7 +3405,7 @@ void ContactDataObject::ProcessTitle(wxString PropertySeg1, wxString PropertySeg
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, TitleListPref, &PropertyValue, TitleCount);
+                       ProcessIntegerValue(TitleListPref, &PropertyValue, TitleCount);
                        
                } else if (PropertyName == wxT("LANGUAGE")){
                
@@ -3576,7 +3563,7 @@ void ContactDataObject::ProcessRole(wxString PropertySeg1, wxString PropertySeg2
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, RoleListPref, &PropertyValue, RoleCount);
+                       ProcessIntegerValue(RoleListPref, &PropertyValue, RoleCount);
                                
                } else if (PropertyName == wxT("LANGUAGE")){
                
@@ -3743,7 +3730,7 @@ void ContactDataObject::ProcessOrganisation(wxString PropertySeg1, wxString Prop
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, OrganisationsListPref, &PropertyValue, OrganisationCount);
+                       ProcessIntegerValue(OrganisationsListPref, &PropertyValue, OrganisationCount);
                        
                } else if (PropertyName == wxT("LANGUAGE")){
                
@@ -3901,7 +3888,7 @@ void ContactDataObject::ProcessNote(wxString PropertySeg1, wxString PropertySeg2
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, NoteListPref, &PropertyValue, NoteCount);
+                       ProcessIntegerValue(NoteListPref, &PropertyValue, NoteCount);
                
                } else if (PropertyName == wxT("LANGUAGE")){
                
@@ -4030,7 +4017,7 @@ void ContactDataObject::ProcessCategory(wxString PropertySeg1, wxString Property
                
                } else if (PropertyName == wxT("PREF")){
 
-                       ProcessIntegerValue(this, &CategoriesListPref, &PropertyValue, CategoryCount);
+                       ProcessIntegerValue(&CategoriesListPref, &PropertyValue, CategoryCount);
                        
                } else if (PropertyName == wxT("LANGUAGE")){
                
@@ -4302,24 +4289,8 @@ void ContactDataObject::ProcessPhoto(wxString PropertySeg1, wxString PropertySeg
                        PicturesListPID.insert(std::make_pair(*PhotoCount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
-
-                       if (ValidNumber == TRUE){
 
-                               PicturesListPref.erase(*PhotoCount);
-                               PicturesListPref.insert(std::make_pair(*PhotoCount, PriorityNumber));
-
-                       }
+                       ProcessIntegerValue(&PicturesListPref, &PropertyValue, PhotoCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -4519,24 +4490,8 @@ void ContactDataObject::ProcessLogo(wxString PropertySeg1, wxString PropertySeg2
                        LogosListPID.insert(std::make_pair(*LogoCount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
 
-                       if (ValidNumber == TRUE){
-
-                               LogosListPref.erase(*LogoCount);
-                               LogosListPref.insert(std::make_pair(*LogoCount, PriorityNumber));
-
-                       }
+                       ProcessIntegerValue(&LogosListPref, &PropertyValue, LogoCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -4736,24 +4691,8 @@ void ContactDataObject::ProcessSound(wxString PropertySeg1, wxString PropertySeg
                        SoundsListPID.insert(std::make_pair(*SoundCount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
 
-                       if (ValidNumber == TRUE){
-
-                               SoundsListPref.erase(*SoundCount);
-                               SoundsListPref.insert(std::make_pair(*SoundCount, PriorityNumber));
-
-                       }
+                       ProcessIntegerValue(&SoundsListPref, &PropertyValue, SoundCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -4958,24 +4897,8 @@ void ContactDataObject::ProcessCalendarURI(wxString PropertySeg1, wxString Prope
                        CalendarListPID.insert(std::make_pair(*CalURICount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
 
-                       if (ValidNumber == TRUE){
-
-                               CalendarListPref.erase(*CalURICount);
-                               CalendarListPref.insert(std::make_pair(*CalURICount, PriorityNumber));
-
-                       }
+                       ProcessIntegerValue(&CalendarListPref, &PropertyValue, CalURICount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -5110,24 +5033,8 @@ void ContactDataObject::ProcessCalendarAddressURI(wxString PropertySeg1, wxStrin
                        CalendarRequestListPID.insert(std::make_pair(*CalAdrURICount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
-
-                       if (ValidNumber == TRUE){
-
-                               CalendarRequestListPref.erase(*CalAdrURICount);
-                               CalendarRequestListPref.insert(std::make_pair(*CalAdrURICount, PriorityNumber));
 
-                       }
+                       ProcessIntegerValue(&CalendarRequestListPref, &PropertyValue, CalAdrURICount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -5262,24 +5169,8 @@ void ContactDataObject::ProcessCalendarFreeBusy(wxString PropertySeg1, wxString
                        FreeBusyListPID.insert(std::make_pair(*FreeBusyAddressCount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
-
-                       if (ValidNumber == TRUE){
 
-                               FreeBusyListPref.erase(*FreeBusyAddressCount);
-                               FreeBusyListPref.insert(std::make_pair(*FreeBusyAddressCount, PriorityNumber));
-
-                       }
+                       ProcessIntegerValue(&FreeBusyListPref, &PropertyValue, FreeBusyAddressCount);
                
                } else if (PropertyName == wxT("MEDIATYPE")){
                
@@ -5413,24 +5304,8 @@ void ContactDataObject::ProcessKey(wxString PropertySeg1, wxString PropertySeg2,
                        KeyListPID.insert(std::make_pair(*KeyCount, PropertyValue));
                
                } else if (PropertyName == wxT("PREF")){
-                       
-                       int PriorityNumber = 0;
-                       bool ValidNumber = TRUE;
-                       
-                       try{
-                               PriorityNumber = std::stoi(PropertyValue.ToStdString());
-                       }
-                       
-                       catch(std::invalid_argument &e){
-                               ValidNumber = FALSE;
-                       }
-
-                       if (ValidNumber == TRUE){
-
-                               KeyListPref.erase(*KeyCount);
-                               KeyListPref.insert(std::make_pair(*KeyCount, PriorityNumber));
 
-                       }
+                       ProcessIntegerValue(&KeyListPref, &PropertyValue, KeyCount);
                
                } else {
                
@@ -5604,8 +5479,55 @@ void ContactDataObject::ProcessVendor(wxString PropertySeg1, wxString PropertySe
 
 }
 
-void ProcessIntegerValue(ContactDataObject *ContactData,
+void ProcessStringValue(wxString *PropertyName,
+       wxString PropertyNameMatch,
+       std::map<int,wxString> *MapPtr,
+       wxString *PropertyValue,
+       int *ItemCount,
+       bool *PropertyMatched){
+       
+       if (*PropertyName == PropertyNameMatch){
+               MapPtr->erase(*ItemCount);
+               MapPtr->insert(std::make_pair(*ItemCount, *PropertyValue));
+               *PropertyMatched = TRUE;
+       }
+       
+}
+
+void ProcessIntegerValue(wxString *PropertyName,
+       wxString PropertyNameMatch,
        std::map<int,int> *PrefPtr, 
+       wxString *PropertyValue, 
+       int *ItemCount,
+       bool *PropertyMatched){
+
+       if (*PropertyName == PropertyNameMatch){
+               *PropertyMatched = TRUE;
+       } else {
+               return;
+       }
+
+       int PriorityNumber = 0; 
+       bool ValidNumber = TRUE;
+                       
+       try{
+               PriorityNumber = std::stoi(PropertyValue->ToStdString());
+       }
+                       
+       catch(std::invalid_argument &e){
+               ValidNumber = FALSE;
+       }
+
+       if (ValidNumber == TRUE){
+
+               PrefPtr->erase(*ItemCount);
+               PrefPtr->insert(std::make_pair(*ItemCount, PriorityNumber));
+
+       }
+
+}
+
+void ProcessIntegerValue(std::map<int,int> *PrefPtr, 
        wxString *PropertyValue, 
        int *ItemCount){
 
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy