Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the GEO vCard property for ContactDat...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index 3de45b7..f7a7e91 100644 (file)
@@ -89,6 +89,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int IMCount = 0;
        int TelephoneCount = 0;
        int LanguageCount = 0;
+       int GeographicCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -258,6 +259,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
                        LanguageCount++;
                
+               } else if (Property == wxT("GEO")){
+               
+                       // See frmContactEditor-LoadGeo.cpp
+                       
+                       ProcessGeographic(PropertySeg1, PropertySeg2, &GeographicCount);        
+                       GeographicCount++;
+               
                }
                
        }
@@ -2402,6 +2410,156 @@ void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString Property
 
 }
 
+void ContactDataObject::ProcessGeographic(wxString PropertySeg1, wxString PropertySeg2, int *GeographicCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+
+       int intPrevValue = 5;
+       int intPref = 0;                        
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 4;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       std::map<int, wxString> *GeopositionList = NULL;
+       std::map<int, wxString> *GeopositionListType = NULL;
+       std::map<int, wxString> *GeopositionListAltID = NULL;
+       std::map<int, wxString> *GeopositionListPID = NULL;
+       std::map<int, wxString> *GeopositionListTokens = NULL;
+       std::map<int, wxString> *GeopositionListMediatype = NULL;
+       std::map<int, int> *GeopositionListPref = NULL;
+
+       switch(PropType){
+               case PROPERTY_NONE:
+                       GeopositionList = &GeneralGeographyList;
+                       GeopositionListType = &GeneralGeographyListType;
+                       GeopositionListAltID = &GeneralGeographyListAltID;
+                       GeopositionListPID = &GeneralGeographyListPID;
+                       GeopositionListTokens = &GeneralGeographyListTokens;
+                       GeopositionListMediatype = &GeneralGeographyListMediatype;
+                       GeopositionListPref = &GeneralGeographyListPref;        
+                       break;
+               case PROPERTY_HOME:
+                       GeopositionList = &HomeGeographyList;
+                       GeopositionListType = &HomeGeographyListType;
+                       GeopositionListAltID = &HomeGeographyListAltID;
+                       GeopositionListPID = &HomeGeographyListPID;
+                       GeopositionListTokens = &HomeGeographyListTokens;
+                       GeopositionListMediatype = &HomeGeographyListMediatype;
+                       GeopositionListPref = &HomeGeographyListPref;   
+                       break;
+               case PROPERTY_WORK:
+                       GeopositionList = &BusinessGeographyList;
+                       GeopositionListType = &BusinessGeographyListType;
+                       GeopositionListAltID = &BusinessGeographyListAltID;
+                       GeopositionListPID = &BusinessGeographyListPID;
+                       GeopositionListTokens = &BusinessGeographyListTokens;
+                       GeopositionListMediatype = &BusinessGeographyListMediatype;     
+                       GeopositionListPref = &BusinessGeographyListPref;
+                       break;
+       }
+       
+       intPrevValue = 4;
+       
+       std::map<int,int>::iterator SLiter;
+       wxString PropertyData;
+       wxString PropertyName;
+       wxString PropertyValue;
+       wxString PropertyTokens;
+       bool FirstToken = TRUE;
+       
+       for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
+       intiter != SplitPoints.end(); ++intiter){
+       
+               SLiter = SplitLength.find(intiter->first);
+       
+               PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
+               
+               wxStringTokenizer PropertyElement (PropertyData, wxT("="));
+               PropertyName = PropertyElement.GetNextToken();                          
+               PropertyValue = PropertyElement.GetNextToken();
+               
+               intPrevValue = intiter->second;
+               
+               CaptureString(&PropertyValue, FALSE);
+               
+               // Process properties.
+               
+               if (PropertyName == wxT("ALTID")){
+
+                       GeopositionListAltID->erase(*GeographicCount);
+                       GeopositionListAltID->insert(std::make_pair(*GeographicCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       GeopositionListPID->erase(*GeographicCount);
+                       GeopositionListPID->insert(std::make_pair(*GeographicCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("MEDIATYPE")){
+
+                       GeopositionListMediatype->erase(*GeographicCount);
+                       GeopositionListMediatype->insert(std::make_pair(*GeographicCount, 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){
+
+                               GeopositionListPref->erase(*GeographicCount);
+                               GeopositionListPref->insert(std::make_pair(*GeographicCount, PriorityNumber));
+
+                       }
+               
+               } else {
+               
+                       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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }
+               
+       GeopositionList->insert(std::make_pair(*GeographicCount, PropertySeg2));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               GeopositionListTokens->insert(std::make_pair(*GeographicCount, PropertyTokens));
+       
+       }
+
+}
+
 void SplitValues(wxString *PropertyLine, 
        std::map<int,int> *SplitPoints, 
        std::map<int,int> *SplitLength, 
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