Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source, headers and unit testing for the NOTE vCard property for ContactDataObject.
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index 7bd80be..0770747 100644 (file)
@@ -95,6 +95,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int TitleCount = 0;
        int RoleCount = 0;
        int OrganisationCount = 0;
+       int NoteCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -306,6 +307,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessOrganisation(PropertySeg1, PropertySeg2, &OrganisationCount);
                        OrganisationCount++;
                        
+               } else if (Property == wxT("NOTE")) {
+
+                       // See frmContactEditor-LoadNote.cpp
+
+                       ProcessNote(PropertySeg1, PropertySeg2, &NoteCount);
+                       NoteCount++;    
+                       
                }
                
        }
@@ -3546,6 +3554,186 @@ void ContactDataObject::ProcessOrganisation(wxString PropertySeg1, wxString Prop
 
 }
 
+void ContactDataObject::ProcessNote(wxString PropertySeg1, wxString PropertySeg2, int *NoteCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+       std::map<int, int>::iterator SLiter;                    
+       wxString PropertyData;
+       wxString PropertyName;
+       wxString PropertyValue;
+       wxString PropertyTokens;
+       bool FirstToken = TRUE;
+       int intPrevValue = 6;
+       int intPref = 0;                        
+       int intType = 0;
+       long ListCtrlIndex;
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 5;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       // Setup the pointers.
+       
+       std::map<int, wxString> *NoteList = NULL;
+       std::map<int, wxString> *NoteListAltID = NULL;
+       std::map<int, wxString> *NoteListPID = NULL;
+       std::map<int, wxString> *NoteListType = NULL;
+       std::map<int, wxString> *NoteListTokens = NULL;
+       std::map<int, wxString> *NoteListLanguage = NULL;
+       std::map<int, wxString> *NoteListSortAs = NULL;
+       std::map<int, int> *NoteListPref = NULL;
+       
+       // Setup blank lines for later on.
+       
+       switch(PropType){
+               case PROPERTY_NONE:
+                       NoteList = &GeneralNoteList;
+                       NoteListType = &GeneralNoteListType;
+                       NoteListAltID = &GeneralNoteListAltID;
+                       NoteListPID = &GeneralNoteListPID;
+                       NoteListTokens = &GeneralNoteListTokens;
+                       NoteListLanguage = &GeneralNoteListLanguage;
+                       NoteListPref = &GeneralNoteListPref;    
+                       break;
+               case PROPERTY_HOME:
+                       NoteList = &HomeNoteList;
+                       NoteListType = &HomeNoteListType;
+                       NoteListAltID = &HomeNoteListAltID;
+                       NoteListPID = &HomeNoteListPID;
+                       NoteListTokens = &HomeNoteListTokens;
+                       NoteListLanguage = &HomeNoteListLanguage;
+                       NoteListPref = &HomeNoteListPref;       
+                       break;
+               case PROPERTY_WORK:
+                       NoteList = &BusinessNoteList;
+                       NoteListType = &BusinessNoteListType;
+                       NoteListAltID = &BusinessNoteListAltID;
+                       NoteListPID = &BusinessNoteListPID;
+                       NoteListTokens = &BusinessNoteListTokens;
+                       NoteListLanguage = &BusinessNoteListLanguage;   
+                       NoteListPref = &BusinessNoteListPref;
+                       break;
+       }
+
+       intPrevValue = 5;
+               
+       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;
+               
+               // Process properties.
+               
+               size_t intPropertyValueLen = PropertyValue.Len();
+               
+               if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
+                       
+                       PropertyValue.Trim();
+                       PropertyValue.RemoveLast();
+                       
+               }                               
+               
+               if (PropertyValue.Mid(0, 1) == wxT("\"")){
+                       
+                       PropertyValue.Remove(0, 1);
+                       
+               }                               
+               
+               CaptureString(&PropertyValue, FALSE);
+               
+               if (PropertyName == wxT("ALTID")){
+               
+                       NoteListAltID->erase(*NoteCount);
+                       NoteListAltID->insert(std::make_pair(*NoteCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       NoteListPID->erase(*NoteCount);
+                       NoteListPID->insert(std::make_pair(*NoteCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("SORT-AS")){
+
+                       NoteListSortAs->erase(*NoteCount);
+                       NoteListSortAs->insert(std::make_pair(*NoteCount, 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){
+
+                               NoteListPref->erase(*NoteCount);
+                               NoteListPref->insert(std::make_pair(*NoteCount, PriorityNumber));
+
+                       }
+                                       
+               } else if (PropertyName == wxT("LANGUAGE")){
+               
+                       NoteListLanguage->erase(*NoteCount);
+                       NoteListLanguage->insert(std::make_pair(*NoteCount, PropertyValue));
+               
+               } else {
+               
+                       // Something else we don't know about so append
+                       // to the tokens variable.
+               
+                       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);
+                       
+                               }
+               
+                       }
+               
+               }
+       
+       }
+       
+       // Add the data to the General/Home/Work address variables.
+       
+       CaptureString(&PropertySeg2, FALSE);
+
+       NoteList->insert(std::make_pair(*NoteCount, PropertySeg2));
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               NoteListTokens->insert(std::make_pair(*NoteCount, 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