Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added source code, headers and unit testing for the KEY vCard property for ContactDat...
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index 8bddc03..7531af0 100644 (file)
@@ -103,6 +103,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
        int CalendarCount = 0;
        int CalendarAddressCount = 0;
        int FreeBusyAddressCount = 0;
+       int KeyCount = 0;
        wxString ContactLine;
        wxString PropertyLine;
        wxString PropertySeg1;
@@ -375,6 +376,13 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
                        ProcessCalendarFreeBusy(PropertySeg1, PropertySeg2, &FreeBusyAddressCount);
                        FreeBusyAddressCount++;
 
+               } else if (Property == wxT("KEY")){
+               
+                       // See frmContactEditor-LoadKey.cpp
+                       
+                       ProcessKey(PropertySeg1, PropertySeg2, &KeyCount);
+                       KeyCount++;
+               
                }
                
        }
@@ -5201,6 +5209,233 @@ void ContactDataObject::ProcessCalendarFreeBusy(wxString PropertySeg1, wxString
 
 }
 
+void ContactDataObject::ProcessKey(wxString PropertySeg1, wxString PropertySeg2, int *KeyCount){
+
+       size_t intPropertyLen = PropertySeg1.Len();
+       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 intSplitsFound = 0;
+       int intSplitSize = 0;
+       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);
+
+       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);
+                       
+               }                               
+               
+               if (PropertyName == wxT("ALTID")){
+
+                       KeyListAltID.erase(*KeyCount);
+                       KeyListAltID.insert(std::make_pair(*KeyCount, PropertyValue));
+               
+               } else if (PropertyName == wxT("PID")){
+
+                       KeyListPID.erase(*KeyCount);
+                       KeyListPID.insert(std::make_pair(*KeyCount, 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){
+
+                               KeyListPref.erase(*KeyCount);
+                               KeyListPref.insert(std::make_pair(*KeyCount, PriorityNumber));
+
+                       }
+               
+               } 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);
+                               
+                               }
+                       
+                       }
+               
+               }
+       
+       }                               
+       
+       intPropertyLen = PropertySeg2.Len();
+       SplitPoints.clear();
+       SplitLength.clear();
+       intSplitsFound = 0;
+       intSplitSize = 0;
+       intPrevValue = 0;                       
+       
+       for (int i = 0; i <= intPropertyLen; i++){
+
+               intSplitSize++;
+       
+               if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
+       
+                       intSplitsFound++;
+                       SplitPoints.insert(std::make_pair(intSplitsFound, (i + 1)));
+                       
+                       if (intSplitsFound == 6){ 
+                       
+                               SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
+                               break; 
+                               
+                       } else {
+                       
+                               SplitLength.insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
+                       
+                       }
+                       
+                       intSplitSize = 0;                                       
+       
+               }
+
+       }
+       
+       wxString wxSKeyURI;
+       wxString wxSKeyMIME;
+       wxString wxSKeyEncoding;
+       wxString wxSKeyData;
+       std::string base64enc;
+       
+       if (intSplitsFound == 0){
+       
+       } else {
+       
+               std::map<int, int>::iterator striter;
+       
+               striter = SplitLength.find(1);
+       
+               wxStringTokenizer wSTDataType(PropertySeg2.Mid(0, striter->second), wxT(":"));
+       
+               while (wSTDataType.HasMoreTokens() == TRUE){
+               
+                       wxSKeyURI = wSTDataType.GetNextToken();
+                       wxSKeyMIME = wSTDataType.GetNextToken();
+                       break;
+               
+               }                       
+       
+               if (wxSKeyURI == wxT("data")){
+               
+                               wxStringTokenizer wSTDataInfo(PropertySeg2.Mid((striter->second + 1)), wxT(","));                       
+       
+                               while (wSTDataInfo.HasMoreTokens() == TRUE){
+               
+                               wxSKeyEncoding = wSTDataInfo.GetNextToken();
+                               wxSKeyData = wSTDataInfo.GetNextToken();
+                               break;
+               
+                       }
+               
+               }
+       
+       }
+       
+       // Add the data to the General/Home/Work address variables.
+       
+       if (wxSKeyURI == wxT("data")){
+               
+               KeyListDataEncType.erase(*KeyCount);
+               KeyListKeyType.erase(*KeyCount);
+               KeyListDataEncType.insert(std::make_pair(*KeyCount, wxSKeyEncoding));
+               KeyListKeyType.insert(std::make_pair(*KeyCount, TRUE));
+               
+               KeyList.erase(*KeyCount);
+               KeyList.insert(std::make_pair(*KeyCount, wxSKeyData));
+       
+       } else {
+               
+               KeyList.erase(*KeyCount);
+               KeyList.insert(std::make_pair(*KeyCount, PropertySeg2));
+       
+       }
+       
+       KeyListDataType.insert(std::make_pair(*KeyCount, wxSKeyMIME));
+               
+       switch (PropType){
+               case PROPERTY_NONE:
+                       break;
+               case PROPERTY_HOME: 
+                       KeyListType.insert(std::make_pair(*KeyCount, wxT("home")));
+                       break;
+               case PROPERTY_WORK: 
+                       KeyListType.insert(std::make_pair(*KeyCount, wxT("work")));
+                       break;
+       }
+
+       if (!PropertyTokens.IsEmpty()){
+
+               KeyListTokens.insert(std::make_pair(*KeyCount, 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