Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing code for the LANG vCard property for...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index 28c12b3..3de45b7 100644 (file)
@@ -88,6 +88,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int EmailCount = 0;
        int IMCount = 0;
        int TelephoneCount = 0;
+       int LanguageCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -250,6 +251,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
                        TelephoneCount++;
                
+               } else if (Property == wxT("LANG")){
+               
+                       // See frmContactEditor-LoadLanguage.cpp
+                       
+                       ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
+                       LanguageCount++;
+               
                }
                
        }
@@ -1938,7 +1946,7 @@ void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2,
        
                IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
        
-       }       
+       }
 
 }
 
@@ -2253,6 +2261,147 @@ void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString Propert
 
 }
 
+void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){
+
+       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> *LanguageList = NULL;
+       std::map<int, wxString> *LanguageListType = NULL;
+       std::map<int, wxString> *LanguageListAltID = NULL;
+       std::map<int, wxString> *LanguageListPID = NULL;
+       std::map<int, wxString> *LanguageListTokens = NULL;
+       std::map<int, int> *LanguageListPref = NULL;
+
+       switch(PropType){
+               case PROPERTY_NONE:
+                       LanguageList = &GeneralLanguageList;
+                       LanguageListType = &GeneralLanguageListType;
+                       LanguageListAltID = &GeneralLanguageListAltID;
+                       LanguageListPID = &GeneralLanguageListPID;
+                       LanguageListTokens = &GeneralLanguageListTokens;
+                       LanguageListPref = &GeneralLanguageListPref;    
+                       break;
+               case PROPERTY_HOME:
+                       LanguageList = &HomeLanguageList;
+                       LanguageListType = &HomeLanguageListType;
+                       LanguageListAltID = &HomeLanguageListAltID;
+                       LanguageListPID = &HomeLanguageListPID;
+                       LanguageListTokens = &HomeLanguageListTokens;   
+                       LanguageListPref = &HomeLanguageListPref;       
+                       break;
+               case PROPERTY_WORK:
+                       LanguageList = &BusinessLanguageList;
+                       LanguageListType = &BusinessLanguageListType;
+                       LanguageListAltID = &BusinessLanguageListAltID;
+                       LanguageListPID = &BusinessLanguageListPID;
+                       LanguageListTokens = &BusinessLanguageListTokens;       
+                       LanguageListPref = &BusinessLanguageListPref;
+                       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")){
+
+                       LanguageListAltID->erase(*LanguageCount);
+                       LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       LanguageListPID->erase(*LanguageCount);
+                       LanguageListPID->insert(std::make_pair(*LanguageCount, 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){
+
+                               LanguageListPref->erase(*LanguageCount);
+                               LanguageListPref->insert(std::make_pair(*LanguageCount, 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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }
+               
+       LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               LanguageListTokens->insert(std::make_pair(*LanguageCount, 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