Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added ANNIVERSARY to the SaveString function of ContactDataObject
[xestiaab/.git] / source / contacteditor / cdo / ContactDataObject-Save.cpp
index 9e14252..9e3db13 100644 (file)
 #include "ContactDataObject.h"
 #include "../../version.h"
 
+ContactSaveStatus ContactDataObject::SaveFile(wxString SaveFilename){
+       
+       // Get the data using SaveString.
+       
+       wxString SaveData = "";
+       SaveString(&SaveData);
+       
+       // Open a file and try to write into it.
+       
+       wxFile ContactFile;
+       
+       if (!ContactFile.Open(SaveFilename, wxFile::write, wxS_DEFAULT)){
+       
+               return CONTACTSAVE_FILEERROR;
+       
+       }
+       
+       if (ContactFile.Write(SaveData, wxConvUTF8) == false){
+               
+               return CONTACTSAVE_WRITEERROR;
+               
+       }
+       
+       ContactFile.Close();
+       
+       return CONTACTSAVE_OK;
+       
+}
+
 ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
        
        ContactSaveStatus SaveDataStatus = CONTACTSAVE_UNITTESTFAIL;
@@ -268,6 +297,70 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
                        
        }
        
+       // Process N.
+       
+       if (!NameTitle.IsEmpty() || !NameForename.IsEmpty() || !NameSurname.IsEmpty() ||
+               !NameOtherNames.IsEmpty() || !NameSuffix.IsEmpty()){
+               
+               ProcessData.Append("N");
+               
+               // Check if there is a value for ALTID.
+               
+               if (NameAltID.size() > 0){
+               
+                       ProcessData.Append(";ALTID=");
+                       ProcessData.Append(NameAltID);
+                       
+               }
+
+               // Check if there is a value for LANGUAGE.
+               
+               if (NameLanguage.size() > 0){
+               
+                       ProcessData.Append(";LANGUAGE=");
+                       ProcessData.Append(NameLanguage);
+                       
+               }
+               
+               // Check if there is a value for SORT-AS.
+               
+               if (NameDisplayAs.size() > 0){
+               
+                       ProcessData.Append(";SORT-AS=\"");
+                       ProcessData.Append(NameDisplayAs);
+                       ProcessData.Append("\"");
+                       
+               }
+
+               // Check if there is a value for tokens.
+
+               if (NameTokens.size() > 0){
+               
+                       ProcessData.Append(";");
+                       ProcessData.Append(NameTokens);
+                       
+               }
+                       
+               ProcessData.Append(":");
+               ProcessData.Append(NameSurname);
+               ProcessData.Append(";");
+               ProcessData.Append(NameForename);
+               ProcessData.Append(";");
+               ProcessData.Append(NameOtherNames);
+               ProcessData.Append(";");
+               ProcessData.Append(NameTitle);
+               ProcessData.Append(";");
+               ProcessData.Append(NameSuffix);
+               
+               ProcessData.Append("\n");
+
+               ProcessData = OutputText(&ProcessData);
+               
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+                       
+       }
+       
        // Process NICKNAME.
        
        SaveNickname(&GeneralNicknamesList, &GeneralNicknamesListAltID, 
@@ -283,6 +376,126 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
                &BusinessNicknamesListLanguage, &BusinessNicknamesListPref, 
                &BusinessNicknamesListTokens, SaveData, "work");
        
+       // Process GENDER.
+       
+       if (Gender.size() > 0){
+               
+               ProcessData.Append("GENDER");
+               
+               if (GenderTokens.size() > 0){
+                       
+                       ProcessData.Append(";");
+                       ProcessData.Append(GenderTokens);
+                       
+               }
+               
+               ProcessData.Append(":");
+               ProcessData.Append(Gender);
+               
+               if (GenderDetails.size() > 0){
+                       
+                       ProcessData.Append(";");
+                       ProcessData.Append(GenderDetails);
+                       
+               }
+               
+               ProcessData.Append("\n");
+
+               ProcessData = OutputText(&ProcessData);
+               
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+               
+       }
+       
+       // Process BDAY.
+       
+       if (Birthday.size() > 0){
+               
+               ProcessData.Append("BDAY");
+
+               // Check if there is a value for ALTID.
+               
+               if (BirthdayAltID.size() > 0){
+                       
+                       ProcessData.Append(";ALTID=");
+                       ProcessData.Append(BirthdayAltID);
+                       
+               }
+
+               // Check if there is a value for CALSCALE.
+               
+               if (BirthdayAltID.size() > 0){
+                       
+                       ProcessData.Append(";CALSCALE=");
+                       ProcessData.Append(BirthdayCalScale);
+                       
+               }
+               
+               // Check if there is a value for tokens.
+               
+               if (BirthdayTokens.size() > 0){
+               
+                       ProcessData.Append(";");
+                       ProcessData.Append(BirthdayTokens);
+                       
+               }
+               
+               ProcessData.Append(":");
+               ProcessData.Append(Birthday);
+               ProcessData.Append("\n");
+               
+               ProcessData = OutputText(&ProcessData);
+               
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+               
+       }
+       
+       // Process ANNIVERSARY.
+       
+       if (Anniversary.size() > 0){
+               
+               ProcessData.Append("ANNIVERSARY");
+
+               // Check if there is a value for ALTID.
+               
+               if (AnniversaryAltID.size() > 0){
+                       
+                       ProcessData.Append(";ALTID=");
+                       ProcessData.Append(AnniversaryAltID);
+                       
+               }
+
+               // Check if there is a value for CALSCALE.
+               
+               if (AnniversaryAltID.size() > 0){
+                       
+                       ProcessData.Append(";CALSCALE=");
+                       ProcessData.Append(AnniversaryCalScale);
+                       
+               }
+               
+               // Check if there is a value for tokens.
+               
+               if (AnniversaryTokens.size() > 0){
+               
+                       ProcessData.Append(";");
+                       ProcessData.Append(AnniversaryTokens);
+                       
+               }
+               
+               ProcessData.Append(":");
+               ProcessData.Append(Anniversary);
+               ProcessData.Append("\n");
+               
+               ProcessData = OutputText(&ProcessData);
+               
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+               
+       }
+       
        // Process TITLE.
 
        SaveTitle(&GeneralTitleList, &GeneralTitleListLanguage,
@@ -355,14 +568,42 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
                &BusinessEmailListPref, &BusinessEmailListTokens, 
                SaveData, "work");
 
-       // TODO: Process IMPP.
-       
-       
-       
-       // TODO: Process TEL.
-       
+       // Process IMPP.
        
+       SaveIMPP(&GeneralIMList, &GeneralIMListAltID, 
+               &GeneralIMListPID, &GeneralIMListType,
+               &GeneralIMListTypeInfo, &GeneralIMListMediatype, 
+               &GeneralIMListPref, &GeneralIMListTokens,
+               SaveData, "");
+       SaveIMPP(&HomeIMList, &HomeIMListAltID, 
+               &HomeIMListPID, &HomeIMListType,
+               &HomeIMListTypeInfo, &HomeIMListMediatype, 
+               &HomeIMListPref, &HomeIMListTokens,
+               SaveData, "home");
+       SaveIMPP(&BusinessIMList, &BusinessIMListAltID, 
+               &BusinessIMListPID, &BusinessIMListType,
+               &BusinessIMListTypeInfo, &BusinessIMListMediatype, 
+               &BusinessIMListPref, &BusinessIMListTokens,
+               SaveData, "work");
+
+       // Process TEL.
        
+       SaveTelephone(&GeneralTelephoneList, &GeneralTelephoneListAltID, 
+               &GeneralTelephoneListPID, &GeneralTelephoneListType,
+               &GeneralTelephoneListTypeInfo, &GeneralTelephoneListDataType, 
+               &GeneralTelephoneListPref, &GeneralTelephoneListTokens, 
+               SaveData, "");
+       SaveTelephone(&HomeTelephoneList, &HomeTelephoneListAltID, 
+               &HomeTelephoneListPID, &HomeTelephoneListType,
+               &HomeTelephoneListTypeInfo, &HomeTelephoneListDataType, 
+               &HomeTelephoneListPref, &HomeTelephoneListTokens, 
+               SaveData, "home");
+       SaveTelephone(&BusinessTelephoneList, &BusinessTelephoneListAltID, 
+               &BusinessTelephoneListPID, &BusinessTelephoneListType,
+               &BusinessTelephoneListTypeInfo, &BusinessTelephoneListDataType, 
+               &BusinessTelephoneListPref, &BusinessTelephoneListTokens, 
+               SaveData, "work");
+
        // Process LANG.
        
        SaveLanguage(&GeneralLanguageList, &GeneralLanguageListAltID, 
@@ -1303,6 +1544,180 @@ void ContactDataObject::SaveEmail(map<int, wxString> *EmailList, map<int, wxStri
                
 }
 
+void ContactDataObject::SaveIMPP(map<int, wxString> *IMList, map<int, wxString> *IMListAltID, 
+       map<int, wxString> *IMListPID, map<int, wxString> *IMListType,
+       map<int, wxString> *IMListTypeInfo, map<int, wxString> *IMListMediatype, 
+       map<int, int> *IMListPref, map<int, wxString> *IMListTokens, 
+       wxString *SaveData, wxString DataType){
+
+       wxString ProcessData = "";
+       
+       for (std::map<int, wxString>::iterator IMIter = IMList->begin();
+               IMIter != IMList->end(); IMIter++){
+
+               ProcessData.Append("IMPP");
+                       
+               // Check if there is a value for TYPE.
+               
+               if (DataType.size() > 0){
+               
+                       ProcessData.Append(";TYPE=");
+                       ProcessData.Append(DataType);
+                       
+               }
+               
+               // Check if there is a value for ALTID.
+               
+               if ((*IMListAltID)[IMIter->first].size() > 0){
+               
+                       ProcessData.Append(";ALTID=");
+                       ProcessData.Append((*IMListAltID)[IMIter->first]);
+                       
+               }
+               
+               // Check if there is a value for MEDIATYPE.
+               
+               if ((*IMListMediatype)[IMIter->first].size() > 0){
+               
+                       ProcessData.Append(";MEDIATYPE=");
+                       ProcessData.Append((*IMListMediatype)[IMIter->first]);
+                       
+               }
+               
+               // Check if there is a value for PID.
+
+               if ((*IMListPID)[IMIter->first].size() > 0){
+               
+                       ProcessData.Append(";PID=");
+                       ProcessData.Append((*IMListPID)[IMIter->first]);
+                       
+               }
+
+               // Check if there is a value for PREF.
+
+               if ((*IMListPref)[IMIter->first] > 0){
+               
+                       ProcessData.Append(";PREF=");
+                       ProcessData.Append(wxString::Format("%i", (*IMListPref)[IMIter->first]));
+                       
+               }
+
+               // Check if there is a value for tokens.
+
+               if ((*IMListTokens)[IMIter->first].size() > 0){
+               
+                       ProcessData.Append(";");
+                       ProcessData.Append((*IMListTokens)[IMIter->first]);
+                       
+               }
+
+               ProcessData.Append(":");
+               ProcessData.Append((*IMListTypeInfo)[IMIter->first]);
+               ProcessData.Append(":");
+               ProcessData.Append(IMIter->second);
+               ProcessData.Append("\n");
+
+               ProcessData = OutputText(&ProcessData);
+                       
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+                       
+       }
+               
+}
+
+void ContactDataObject::SaveTelephone(map<int, wxString> *TelephoneList, map<int, wxString> *TelephoneListAltID, 
+       map<int, wxString> *TelephoneListPID, map<int, wxString> *TelephoneListType,
+       map<int, wxString> *TelephoneListTypeInfo, map<int, wxString> *TelephoneListDataType, 
+       map<int, int> *TelephoneListPref, map<int, wxString> *TelephoneListTokens, 
+       wxString *SaveData, wxString DataType){
+
+       wxString ProcessData = "";
+       
+       for (std::map<int, wxString>::iterator TelephoneIter = TelephoneList->begin();
+               TelephoneIter != TelephoneList->end(); TelephoneIter++){
+
+               ProcessData.Append("TEL");
+                       
+               // Check if there is a value for TYPE.
+
+               if (DataType.size() > 0 || (*TelephoneListAltID)[TelephoneIter->first].size() > 0){
+
+                       ProcessData.Append(";TYPE=\"");
+                       
+                       bool ProcessedType = false;
+                       
+                       if (DataType.size() > 0){
+               
+                               ProcessData.Append(DataType);
+                               ProcessedType = true;
+                       
+                       }
+                       
+                       if ((*TelephoneListAltID)[TelephoneIter->first].size() > 0){
+                               
+                               if (ProcessedType == true){
+                                       ProcessData.Append(",");
+                               }
+                               ProcessData.Append((*TelephoneListTypeInfo)[TelephoneIter->first]);
+                               
+                       }
+                       
+                       ProcessData.Append("\"");
+               
+               }
+               
+               // Check if there is a value for ALTID.
+               
+               if ((*TelephoneListAltID)[TelephoneIter->first].size() > 0){
+               
+                       ProcessData.Append(";ALTID=");
+                       ProcessData.Append((*TelephoneListAltID)[TelephoneIter->first]);
+                       
+               }
+               
+               // Check if there is a value for PID.
+
+               if ((*TelephoneListPID)[TelephoneIter->first].size() > 0){
+               
+                       ProcessData.Append(";PID=");
+                       ProcessData.Append((*TelephoneListPID)[TelephoneIter->first]);
+                       
+               }
+
+               // Check if there is a value for PREF.
+
+               if ((*TelephoneListPref)[TelephoneIter->first] > 0){
+               
+                       ProcessData.Append(";PREF=");
+                       ProcessData.Append(wxString::Format("%i", (*TelephoneListPref)[TelephoneIter->first]));
+                       
+               }
+
+               // Check if there is a value for tokens.
+
+               if ((*TelephoneListTokens)[TelephoneIter->first].size() > 0){
+               
+                       ProcessData.Append(";");
+                       ProcessData.Append((*TelephoneListTokens)[TelephoneIter->first]);
+                       
+               }
+
+               ProcessData.Append(":");
+               ProcessData.Append((*TelephoneListDataType)[TelephoneIter->first]);
+               ProcessData.Append(":");
+               ProcessData.Append(TelephoneIter->second);
+               ProcessData.Append("\n");
+
+               ProcessData = OutputText(&ProcessData);
+                       
+               SaveData->Append(ProcessData);
+               ProcessData.clear();
+                       
+       }
+               
+}
+
 void ContactDataObject::SaveLanguage(map<int, wxString> *LanguageList, map<int, wxString> *LanguageListAltID, 
        map<int, wxString> *LanguageListPID, map<int, wxString> *LanguageListType,
        map<int, int> *LangaugeListPref, map<int, wxString> *LanguageListTokens, 
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