Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the TEL vCard Property for ContactDat...
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 01:50:44 +0000 (01:50 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Dec 2015 01:50:44 +0000 (01:50 +0000)
source/contacteditor/ContactDataObject.cpp
source/contacteditor/ContactDataObject.h
source/tests/LoadCheck-Load4.vcf
source/tests/xestiaab_contactload.h

index b158e19..28c12b3 100644 (file)
@@ -87,6 +87,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int AddressCount = 0;
        int EmailCount = 0;
        int IMCount = 0;
+       int TelephoneCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -235,19 +236,20 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        AddressCount++;
                
                } else if (Property == wxT("EMAIL")){
-               
-                       // See frmContactEditor-LoadEmail.cpp
-                       
+                                       
                        ProcessEmail(PropertySeg1, PropertySeg2, &EmailCount);  
                        EmailCount++;
                
                } else if (Property == wxT("IMPP")){
                
-                       // See frmContactEditor-LoadIM.cpp
-               
                        ProcessIM(PropertySeg1, PropertySeg2, &IMCount);
                        IMCount++;
                        
+               } else if (Property == wxT("TEL")){
+                               
+                       ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
+                       TelephoneCount++;
+               
                }
                
        }
@@ -1940,6 +1942,317 @@ void ContactDataObject::ProcessIM(wxString PropertySeg1, wxString PropertySeg2,
 
 }
 
+void ContactDataObject::ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount){
+
+       std::map<int, int> SplitPoints;
+       std::map<int, int> SplitLength;
+       std::map<int, int>::iterator SLiter;
+       
+       int intPref = 0;
+       
+       PropertyType PropType = PROPERTY_NONE;
+               
+       // Look for type before continuing.
+       
+       wxString TelTypeUI;
+       wxString TelTypeDetail;
+       wxString PropertyData;
+       wxString PropertyName;
+       wxString PropertyValue;
+       wxString PropertyTokens;
+       
+       std::map<int,int> TypeSplitPoints;
+       std::map<int,int> TypeSplitLength;
+       std::map<int,int>::iterator TSLiter;
+       
+       int intSplitSize = 0;
+       int intSplitsFound = 0;
+       int intSplitPoint = 0;
+       int intType = 0;
+       int intPrevValue = 5;
+               
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+       
+       intPrevValue = 4;
+       
+       // Look for type before continuing.
+       
+       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;
+
+               if (PropertyName == wxT("TYPE")){
+               
+                       // Process each value in type and translate each
+                       // part.
+               
+                       // Strip out the quotes if they are there.
+               
+                       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);
+                       
+                       }
+                       
+                       TelTypeDetail = PropertyValue;
+                       
+                       intSplitSize = 0;
+                       intSplitsFound = 0;
+                       intSplitPoint = 0;
+                       
+                       for (int i = 0; i <= intPropertyValueLen; i++){
+       
+                               intSplitSize++;
+       
+                               if (PropertyValue.Mid(i, 1) == wxT(",") && PropertyValue.Mid((i - 1), 1) != wxT("\\")){
+       
+                                       if (intSplitsFound == 0){
+
+                                               TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
+                                               TypeSplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
+                       
+                                       } else {
+                       
+                                               TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
+                                               TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));
+                       
+                                       }                       
+
+                                       intSplitsFound++;
+                                       i++;
+                                       intSplitPoint = i;
+                                       intSplitSize = 0;
+       
+                               }
+       
+                       }
+                       
+                       TypeSplitPoints.insert(std::make_pair(intSplitsFound, intSplitPoint));
+                       TypeSplitLength.insert(std::make_pair(intSplitsFound, intSplitSize));                                                           
+               
+                       int intTypeSeek = 0;
+               
+                       for (std::map<int, int>::iterator typeiter = TypeSplitPoints.begin(); 
+                       typeiter != TypeSplitPoints.end(); ++typeiter){
+                       
+                               wxString TypePropertyName;
+                               
+                               TSLiter = TypeSplitLength.find(typeiter->first);
+                               
+                               TypePropertyName = PropertyValue.Mid(typeiter->second, TSLiter->second);
+                               
+                               if (intTypeSeek == 0){
+                               
+                               
+                               } else {
+                                                                               
+                                       TelTypeUI.Append(wxT(","));                                                     
+                               
+                               }
+                       
+                               if (TypePropertyName == wxT("home")){
+                               
+                                       PropType = PROPERTY_HOME;
+                               
+                               } else if (TypePropertyName == wxT("work")){
+                               
+                                       PropType = PROPERTY_WORK;
+                                                                       
+                               }
+                               
+                               
+                               if (TypePropertyName == wxT("text")){
+                               
+                                       TelTypeUI.Append(_("text"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("voice")){
+                               
+                                       TelTypeUI.Append(_("voice"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("fax")){
+                               
+                                       TelTypeUI.Append(_("fax"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("cell")){
+                               
+                                       TelTypeUI.Append(_("mobile"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("video")){
+                               
+                                       TelTypeUI.Append(_("video"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("pager")){
+                               
+                                       TelTypeUI.Append(_("pager"));
+                                       intTypeSeek++;
+                               
+                               } else if (TypePropertyName == wxT("textphone")){
+                               
+                                       TelTypeUI.Append(_("textphone"));
+                                       intTypeSeek++;
+                               
+                               }
+                       
+                       }
+               
+               }
+               
+       }
+       
+       std::map<int, wxString> *TelephoneList = NULL;
+       std::map<int, wxString> *TelephoneListType = NULL;
+       std::map<int, wxString> *TelephoneListAltID = NULL;
+       std::map<int, wxString> *TelephoneListPID = NULL;
+       std::map<int, wxString> *TelephoneListTokens = NULL;
+       std::map<int, wxString> *TelephoneListTypeInfo = NULL;  
+       std::map<int, int> *TelephoneListPref = NULL;
+
+       switch(PropType){
+               case PROPERTY_NONE:
+                       TelephoneList = &GeneralTelephoneList;
+                       TelephoneListType = &GeneralTelephoneListType;
+                       TelephoneListAltID = &GeneralTelephoneListAltID;
+                       TelephoneListPID = &GeneralTelephoneListPID;
+                       TelephoneListTokens = &GeneralTelephoneListTokens;
+                       TelephoneListTypeInfo = &GeneralTelephoneListTypeInfo;
+                       TelephoneListPref = &GeneralTelephoneListPref;  
+                       break;
+               case PROPERTY_HOME:
+                       TelephoneList = &HomeTelephoneList;
+                       TelephoneListType = &HomeTelephoneListType;
+                       TelephoneListAltID = &HomeTelephoneListAltID;
+                       TelephoneListPID = &HomeTelephoneListPID;
+                       TelephoneListTokens = &HomeTelephoneListTokens;
+                       TelephoneListTypeInfo = &HomeTelephoneListTypeInfo;     
+                       TelephoneListPref = &HomeTelephoneListPref;     
+                       break;
+               case PROPERTY_WORK:
+                       TelephoneList = &BusinessTelephoneList;
+                       TelephoneListType = &BusinessTelephoneListType;
+                       TelephoneListAltID = &BusinessTelephoneListAltID;
+                       TelephoneListPID = &BusinessTelephoneListPID;
+                       TelephoneListTokens = &BusinessTelephoneListTokens;     
+                       TelephoneListTypeInfo = &BusinessTelephoneListTypeInfo; 
+                       TelephoneListPref = &BusinessTelephoneListPref; 
+                       break;
+       }
+               
+       // Process the properties.
+       
+       bool FirstToken = TRUE;
+       
+       intPrevValue = 5;
+       SplitPoints.clear();
+       SplitLength.clear();
+
+       SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+       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;
+               
+               CaptureString(&PropertyValue, FALSE);
+               
+               // Process properties.
+               
+               if (PropertyName == wxT("ALTID")){
+
+                       TelephoneListAltID->erase(*TelephoneCount);
+                       TelephoneListAltID->insert(std::make_pair(*TelephoneCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       TelephoneListPID->erase(*TelephoneCount);
+                       TelephoneListPID->insert(std::make_pair(*TelephoneCount, 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){
+
+                               TelephoneListPref->erase(*TelephoneCount);
+                               TelephoneListPref->insert(std::make_pair(*TelephoneCount, 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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }
+               
+       TelephoneList->insert(std::make_pair(*TelephoneCount, PropertySeg2));
+       TelephoneListTypeInfo->insert(std::make_pair(*TelephoneCount, TelTypeUI));
+       
+       // Add the name token data.
+       
+       if (!PropertyTokens.IsEmpty()){
+       
+               TelephoneListTokens->insert(std::make_pair(*TelephoneCount, PropertyTokens));
+       
+       }
+
+}
+
 void SplitValues(wxString *PropertyLine, 
        std::map<int,int> *SplitPoints, 
        std::map<int,int> *SplitLength, 
index e55491b..f8e79bb 100644 (file)
@@ -142,6 +142,7 @@ class ContactDataObject{
        std::map<int, wxString> GeneralTelephoneListPID;
        std::map<int, wxString> GeneralTelephoneListType;
        std::map<int, wxString> GeneralTelephoneListTokens;
+       std::map<int, wxString> GeneralTelephoneListTypeInfo;
        std::map<int, int> GeneralTelephoneListPref;
        
        std::map<int, wxString> GeneralLanguageList;
@@ -263,6 +264,7 @@ class ContactDataObject{
        std::map<int, wxString> HomeTelephoneListPID;
        std::map<int, wxString> HomeTelephoneListType;
        std::map<int, wxString> HomeTelephoneListTokens;
+       std::map<int, wxString> HomeTelephoneListTypeInfo;
        std::map<int, int> HomeTelephoneListPref;
        
        std::map<int, wxString> HomeLanguageList;
@@ -383,6 +385,7 @@ class ContactDataObject{
        std::map<int, wxString> BusinessTelephoneListAltID;
        std::map<int, wxString> BusinessTelephoneListPID;
        std::map<int, wxString> BusinessTelephoneListType;
+       std::map<int, wxString> BusinessTelephoneListTypeInfo;
        std::map<int, wxString> BusinessTelephoneListTokens;
        std::map<int, int> BusinessTelephoneListPref;
        
@@ -576,6 +579,7 @@ class ContactDataObject{
        void ProcessAddress(wxString PropertySeg1, wxString PropertySeg2, int *AddressCount);
        void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount);
        void ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount);
+       void ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount);
 
 };
 
index 55f13d4..e4d91ac 100644 (file)
@@ -41,4 +41,7 @@ IMPP;TYPE=home;ALTID=20;PID=40;PREF=80;MEDIATYPE=text/reallyplain;PEACE=quie
  t:moo.home@example.com
 IMPP;TYPE=work;ALTID=98;PID=99;PREF=50;MEDIATYPE=text/superplain;BUSINESS=Mo
  ney:moo.business@example.com
+TEL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour;TYPE="fax,cell":tel:00000000
+TEL;TYPE="home,fax";ALTID=10;PID=20;PREF=40;BUSINESS=Money:tel:00001111
+TEL;TYPE="work,voice";ALTID=25;PID=50;PREF=75;BEEP=Boop:tel:22221111
 END:VCARD
index b76c13d..09e4c4a 100644 (file)
@@ -991,4 +991,129 @@ TEST(ContactLoad, IMTests){
 
 }
 
+TEST(ContactLoad, TelephoneTests){
+
+       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 Telephone.
+       
+       TestFileIter = TestFile.GeneralTelephoneList.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneList.end(), TestFileIter);
+       ASSERT_EQ("tel:00000000", TestFileIter->second);
+       
+       // Check the type section.
+       
+       TestFileIter = TestFile.GeneralTelephoneListTypeInfo.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneListTypeInfo.end(), TestFileIter);
+       ASSERT_EQ("fax,mobile", TestFileIter->second);  
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.GeneralTelephoneListAltID.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneListAltID.end(), TestFileIter);
+       ASSERT_EQ("10", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.GeneralTelephoneListPID.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneListPID.end(), TestFileIter);
+       ASSERT_EQ("20", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.GeneralTelephoneListPref.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneListPref.end(), TestFileIntIter);
+       ASSERT_EQ(40, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.GeneralTelephoneListTokens.find(0);
+       ASSERT_NE(TestFile.GeneralTelephoneListTokens.end(), TestFileIter);
+       ASSERT_EQ("WONDERFUL=Colour", TestFileIter->second);
+       
+       // Start with the home Telephone.
+       
+       TestFileIter = TestFile.HomeTelephoneList.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneList.end(), TestFileIter);
+       ASSERT_EQ("tel:00001111", TestFileIter->second);
+       
+       // Check the type section.
+       
+       TestFileIter = TestFile.HomeTelephoneListTypeInfo.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneListTypeInfo.end(), TestFileIter);
+       ASSERT_EQ("fax", TestFileIter->second); 
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.HomeTelephoneListAltID.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneListAltID.end(), TestFileIter);
+       ASSERT_EQ("10", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.HomeTelephoneListPID.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneListPID.end(), TestFileIter);
+       ASSERT_EQ("20", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.HomeTelephoneListPref.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneListPref.end(), TestFileIntIter);
+       ASSERT_EQ(40, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.HomeTelephoneListTokens.find(1);
+       ASSERT_NE(TestFile.HomeTelephoneListTokens.end(), TestFileIter);
+       ASSERT_EQ("BUSINESS=Money", TestFileIter->second);
+
+       // Start with the business Telephone.
+       
+       TestFileIter = TestFile.BusinessTelephoneList.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneList.end(), TestFileIter);
+       ASSERT_EQ("tel:22221111", TestFileIter->second);
+       
+       // Check the type section.
+       
+       TestFileIter = TestFile.BusinessTelephoneListTypeInfo.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneListTypeInfo.end(), TestFileIter);
+       ASSERT_EQ("voice", TestFileIter->second);       
+       
+       // Check the ALTID section.
+       
+       TestFileIter = TestFile.BusinessTelephoneListAltID.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneListAltID.end(), TestFileIter);
+       ASSERT_EQ("25", TestFileIter->second);
+       
+       // Check the PID section.
+       
+       TestFileIter = TestFile.BusinessTelephoneListPID.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneListPID.end(), TestFileIter);
+       ASSERT_EQ("50", TestFileIter->second);
+       
+       // Check the PREF section.
+       
+       TestFileIntIter = TestFile.BusinessTelephoneListPref.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneListPref.end(), TestFileIntIter);
+       ASSERT_EQ(75, TestFileIntIter->second);
+       
+       // Check the extra tokens.
+       
+       TestFileIter = TestFile.BusinessTelephoneListTokens.find(2);
+       ASSERT_NE(TestFile.BusinessTelephoneListTokens.end(), TestFileIter);
+       ASSERT_EQ("BEEP=Boop", TestFileIter->second);
+
+}
+
+TEST(ContactLoad, TelephoneTests){
+
+}
+
 // TODO: Add tests for the Contact Loading process.
\ No newline at end of file
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