Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit tests for the ORG vCard property for ContactDataO...
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 19:54:36 +0000 (19:54 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 19:54:36 +0000 (19:54 +0000)
source/contacteditor/ContactDataObject.cpp
source/contacteditor/ContactDataObject.h
source/tests/LoadCheck-Load4.vcf
source/tests/xestiaab_contactload.h

index d40087c..7bd80be 100644 (file)
@@ -94,6 +94,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int URLCount = 0;
        int TitleCount = 0;
        int RoleCount = 0;
+       int OrganisationCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -298,6 +299,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessRole(PropertySeg1, PropertySeg2, &RoleCount);
                        RoleCount++;
                        
+               } else if (Property == wxT("ORG")) {
+               
+                       // See frmContactEditor-LoadOrg.cpp
+                       
+                       ProcessOrganisation(PropertySeg1, PropertySeg2, &OrganisationCount);
+                       OrganisationCount++;
+                       
                }
                
        }
@@ -3355,6 +3363,189 @@ void ContactDataObject::ProcessRole(wxString PropertySeg1, wxString PropertySeg2
 
 }
 
+void ContactDataObject::ProcessOrganisation(wxString PropertySeg1, wxString PropertySeg2, int *OrganisationCount){
+
+       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 = 5;
+       int intPref = 0;                        
+       int intType = 0;
+       long ListCtrlIndex;
+       
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 4;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+       
+       // Setup the pointers.
+       
+       std::map<int, wxString> *OrganisationsList = NULL;
+       std::map<int, wxString> *OrganisationsListAltID = NULL;
+       std::map<int, wxString> *OrganisationsListPID = NULL;
+       std::map<int, wxString> *OrganisationsListType = NULL;
+       std::map<int, wxString> *OrganisationsListTokens = NULL;
+       std::map<int, wxString> *OrganisationsListLanguage = NULL;
+       std::map<int, wxString> *OrganisationsListSortAs = NULL;
+       std::map<int, int> *OrganisationsListPref = NULL;
+       
+       // Setup blank lines for later on.
+       
+       switch(PropType){
+               case PROPERTY_NONE:
+                       OrganisationsList = &GeneralOrganisationsList;
+                       OrganisationsListType = &GeneralOrganisationsListType;
+                       OrganisationsListAltID = &GeneralOrganisationsListAltID;
+                       OrganisationsListPID = &GeneralOrganisationsListPID;
+                       OrganisationsListTokens = &GeneralOrganisationsListTokens;
+                       OrganisationsListLanguage = &GeneralOrganisationsListLanguage;
+                       OrganisationsListSortAs = &GeneralOrganisationsListSortAs;
+                       OrganisationsListPref = &GeneralOrganisationsListPref;  
+                       break;
+               case PROPERTY_HOME:
+                       OrganisationsList = &HomeOrganisationsList;
+                       OrganisationsListType = &HomeOrganisationsListType;
+                       OrganisationsListAltID = &HomeOrganisationsListAltID;
+                       OrganisationsListPID = &HomeOrganisationsListPID;
+                       OrganisationsListTokens = &HomeOrganisationsListTokens;
+                       OrganisationsListLanguage = &HomeOrganisationsListLanguage;
+                       OrganisationsListSortAs = &HomeOrganisationsListSortAs;
+                       OrganisationsListPref = &HomeOrganisationsListPref;     
+                       break;
+               case PROPERTY_WORK:
+                       OrganisationsList = &BusinessOrganisationsList;
+                       OrganisationsListType = &BusinessOrganisationsListType;
+                       OrganisationsListAltID = &BusinessOrganisationsListAltID;
+                       OrganisationsListPID = &BusinessOrganisationsListPID;
+                       OrganisationsListTokens = &BusinessOrganisationsListTokens;
+                       OrganisationsListLanguage = &BusinessOrganisationsListLanguage;
+                       OrganisationsListSortAs = &BusinessOrganisationsListSortAs;     
+                       OrganisationsListPref = &BusinessOrganisationsListPref;
+                       break;
+       }
+
+       intPrevValue = 4;
+               
+       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")){
+               
+                       OrganisationsListAltID->erase(*OrganisationCount);
+                       OrganisationsListAltID->insert(std::make_pair(*OrganisationCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       OrganisationsListPID->erase(*OrganisationCount);
+                       OrganisationsListPID->insert(std::make_pair(*OrganisationCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("SORT-AS")){
+
+                       OrganisationsListSortAs->erase(*OrganisationCount);
+                       OrganisationsListSortAs->insert(std::make_pair(*OrganisationCount, 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){
+
+                               OrganisationsListPref->erase(*OrganisationCount);
+                               OrganisationsListPref->insert(std::make_pair(*OrganisationCount, PriorityNumber));
+
+                       }
+                                       
+               } else if (PropertyName == wxT("LANGUAGE")){
+               
+                       OrganisationsListLanguage->erase(*OrganisationCount);
+                       OrganisationsListLanguage->insert(std::make_pair(*OrganisationCount, 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);
+
+       OrganisationsList->insert(std::make_pair(*OrganisationCount, PropertySeg2));
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               OrganisationsListTokens->insert(std::make_pair(*OrganisationCount, PropertyTokens));
+                       
+       }
+
+}
+
 void SplitValues(wxString *PropertyLine, 
        std::map<int,int> *SplitPoints, 
        std::map<int,int> *SplitLength, 
index 9c421a4..f5beef9 100644 (file)
@@ -73,6 +73,7 @@ class ContactDataObject{
        void ProcessURL(wxString PropertySeg1, wxString PropertySeg2, int *URLCount);
        void ProcessTitle(wxString PropertySeg1, wxString PropertySeg2, int *TitleCount);
        void ProcessRole(wxString PropertySeg1, wxString PropertySeg2, int *RoleCount);
+       void ProcessOrganisation(wxString PropertySeg1, wxString PropertySeg2, int *OrganisationCount);
 
        public:
 
index 673c074..317caea 100644 (file)
@@ -70,4 +70,10 @@ ROLE;TYPE=home;ALTID=60;PID=61;PREF=62;LANGUAGE=en-GB;SOMEWHERE=There:Ordina
  ry Lazy Person
 ROLE;TYPE=work;ALTID=70;PID=71;PREF=72;LANGUAGE=en-AU;HERE=Nope:Company Owne
  r
+ORG;SORT-AS="Organisation, Ordinary";ALTID=50;PID=51;PREF=52;LANGUAGE=en;AST
+ ERISK=None:Ordinary Organisation
+ORG;TYPE=home;SORT-AS="Person, Ordinary Lazy";ALTID=60;PID=61;PREF=62;LANGUA
+ GE=en-GB;SOMEWHERE=There:Ordinary Lazy Person
+ORG;TYPE=work;SORT-AS="Owner, Company";ALTID=70;PID=71;PREF=72;LANGUAGE=en-A
+ U;HERE=Nope:Company Owner
 END:VCARD
index ece3063..5746b9d 100644 (file)
@@ -1816,7 +1816,146 @@ TEST(ContactLoad, RoleTests){
        
        TestFileIter = TestFile.BusinessRoleListTokens.find(2);
        ASSERT_NE(TestFile.BusinessRoleListTokens.end(), TestFileIter);
-       ASSERT_EQ("HERE=Nope", TestFileIter->second);   
+       ASSERT_EQ("HERE=Nope", TestFileIter->second);
+
+}
+
+TEST(ContactLoad, OrganisationTests){
+
+       ContactDataObject TestFile;
+
+       // Check that the vCard 4.0 file loads OK.
+
+       ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+       std::map<int,wxString>::iterator TestFileIter;
+       std::map<int,int>::iterator TestFileIntIter;
+
+       // Start with the general organisation.
+       
+       TestFileIter = TestFile.GeneralOrganisationsList.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsList.end(), TestFileIter);
+       ASSERT_EQ("Ordinary Organisation", TestFileIter->second);
+       
+       // Check the SORT-AS section.
+
+       TestFileIter = TestFile.GeneralOrganisationsListSortAs.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListSortAs.end(), TestFileIter);
+       ASSERT_EQ("Organisation, Ordinary", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.GeneralOrganisationsListAltID.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListAltID.end(), TestFileIter);
+       ASSERT_EQ("50", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.GeneralOrganisationsListPID.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListPID.end(), TestFileIter);
+       ASSERT_EQ("51", TestFileIter->second);
+       
+       // Check the LANGUAGE section.
+       
+       TestFileIter = TestFile.GeneralOrganisationsListLanguage.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListLanguage.end(), TestFileIter);
+       ASSERT_EQ("en", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.GeneralOrganisationsListPref.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListPref.end(), TestFileIntIter);
+       ASSERT_EQ(52, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.GeneralOrganisationsListTokens.find(0);
+       ASSERT_NE(TestFile.GeneralOrganisationsListTokens.end(), TestFileIter);
+       ASSERT_EQ("ASTERISK=None", TestFileIter->second);
+
+       // Start with the home Organisation.
+
+       TestFileIter = TestFile.HomeOrganisationsList.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsList.end(), TestFileIter);
+       ASSERT_EQ("Ordinary Lazy Person", TestFileIter->second);
+       
+       // Check the SORT-AS section.
+       
+       TestFileIter = TestFile.HomeOrganisationsListSortAs.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListSortAs.end(), TestFileIter);
+       ASSERT_EQ("Person, Ordinary Lazy", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.HomeOrganisationsListAltID.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListAltID.end(), TestFileIter);
+       ASSERT_EQ("60", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.HomeOrganisationsListPID.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListPID.end(), TestFileIter);
+       ASSERT_EQ("61", TestFileIter->second);
+       
+       // Check the LANGUAGE section.
+       
+       TestFileIter = TestFile.HomeOrganisationsListLanguage.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListLanguage.end(), TestFileIter);
+       ASSERT_EQ("en-GB", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.HomeOrganisationsListPref.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListPref.end(), TestFileIntIter);
+       ASSERT_EQ(62, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.HomeOrganisationsListTokens.find(1);
+       ASSERT_NE(TestFile.HomeOrganisationsListTokens.end(), TestFileIter);
+       ASSERT_EQ("SOMEWHERE=There", TestFileIter->second);
+       
+       // Start with the business Organisation.
+
+       TestFileIter = TestFile.BusinessOrganisationsList.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsList.end(), TestFileIter);
+       ASSERT_EQ("Company Owner", TestFileIter->second);
+       
+       // Check the SORT-AS section.
+       
+       TestFileIter = TestFile.BusinessOrganisationsListSortAs.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListSortAs.end(), TestFileIter);
+       ASSERT_EQ("Owner, Company", TestFileIter->second);
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.BusinessOrganisationsListAltID.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListAltID.end(), TestFileIter);
+       ASSERT_EQ("70", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.BusinessOrganisationsListPID.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListPID.end(), TestFileIter);
+       ASSERT_EQ("71", TestFileIter->second);
+       
+       // Check the LANGUAGE section.
+       
+       TestFileIter = TestFile.BusinessOrganisationsListLanguage.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListLanguage.end(), TestFileIter);
+       ASSERT_EQ("en-AU", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.BusinessOrganisationsListPref.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListPref.end(), TestFileIntIter);
+       ASSERT_EQ(72, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.BusinessOrganisationsListTokens.find(2);
+       ASSERT_NE(TestFile.BusinessOrganisationsListTokens.end(), TestFileIter);
+       ASSERT_EQ("HERE=Nope", TestFileIter->second);
 
 }
 
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