Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit tests for the IMPP vCard property type for Contac...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index b49e0bb..b158e19 100644 (file)
@@ -86,6 +86,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int TimeZoneCount = 0;
        int AddressCount = 0;
        int EmailCount = 0;
+       int IMCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -240,6 +241,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
                        EmailCount++;
                
+               } else if (Property == wxT("IMPP")){
+               
+                       // See frmContactEditor-LoadIM.cpp
+               
+                       ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
+                       IMCount++;
+                       
                }
                
        }
@@ -645,7 +653,7 @@ void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString Property
        
        intPrevValue = 9;
        
-       PropertyType PropType;
+       PropertyType PropType = PROPERTY_NONE;
        
        // Look for type before continuing.
        
@@ -1136,7 +1144,7 @@ void ContactDataObject::ProcessTimeZone(wxString PropertySeg1, wxString Property
        
        intPrevValue = 3;
        
-       PropertyType PropType;
+       PropertyType PropType = PROPERTY_NONE;
        
        // Look for type before continuing.
        
@@ -1315,8 +1323,8 @@ void ContactDataObject::ProcessAddress(wxString PropertySeg1, wxString PropertyS
        
        intPrevValue = 4;
        
-       PropertyType PropType;
-       
+       PropertyType PropType = PROPERTY_NONE;
+               
        // Look for type before continuing.
        
        CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
@@ -1652,8 +1660,8 @@ void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg
        
        intPrevValue = 6;
        
-       PropertyType PropType;
-       
+       PropertyType PropType = PROPERTY_NONE;
+               
        // Look for type before continuing.
        
        CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
@@ -1782,6 +1790,156 @@ void ContactDataObject::ProcessEmail(wxString PropertySeg1, wxString PropertySeg
 
 }
 
+void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+
+       int intPrevValue = 6;
+       int intPref = 0;                        
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 5;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       std::map<int, wxString> *IMList = NULL;
+       std::map<int, wxString> *IMListType = NULL;
+       std::map<int, wxString> *IMListAltID = NULL;
+       std::map<int, wxString> *IMListPID = NULL;
+       std::map<int, wxString> *IMListTokens = NULL;
+       std::map<int, wxString> *IMListMediatype = NULL;        
+       std::map<int, int> *IMListPref = NULL;
+
+       switch(PropType){
+               case PROPERTY_NONE:
+                       IMList = &GeneralIMList;
+                       IMListType = &GeneralIMListType;
+                       IMListAltID = &GeneralIMListAltID;
+                       IMListPID = &GeneralIMListPID;
+                       IMListTokens = &GeneralIMListTokens;
+                       IMListMediatype = &GeneralIMListMediatype;
+                       IMListPref = &GeneralIMListPref;        
+                       break;
+               case PROPERTY_HOME:
+                       IMList = &HomeIMList;
+                       IMListType = &HomeIMListType;
+                       IMListAltID = &HomeIMListAltID;
+                       IMListPID = &HomeIMListPID;
+                       IMListTokens = &HomeIMListTokens;
+                       IMListMediatype = &HomeIMListMediatype;         
+                       IMListPref = &HomeIMListPref;   
+                       break;
+               case PROPERTY_WORK:
+                       IMList = &BusinessIMList;
+                       IMListType = &BusinessIMListType;
+                       IMListAltID = &BusinessIMListAltID;
+                       IMListPID = &BusinessIMListPID;
+                       IMListTokens = &BusinessIMListTokens;   
+                       IMListMediatype = &BusinessIMListMediatype;     
+                       IMListPref = &BusinessIMListPref;       
+                       break;
+       }
+       
+       intPrevValue = 5;
+       
+       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")){
+
+                       IMListAltID->erase(*IMCount);
+                       IMListAltID->insert(std::make_pair(*IMCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       IMListPID->erase(*IMCount);
+                       IMListPID->insert(std::make_pair(*IMCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("MEDIATYPE")){
+
+                       IMListMediatype->erase(*IMCount);
+                       IMListMediatype->insert(std::make_pair(*IMCount, 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){
+
+                               IMListPref->erase(*IMCount);
+                               IMListPref->insert(std::make_pair(*IMCount, 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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }
+               
+       IMList->insert(std::make_pair(*IMCount, PropertySeg2));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               IMListTokens->insert(std::make_pair(*IMCount, 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