From c96aab2ca3ef9a24252dd6d09677fe7f52959fd4 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Tue, 28 Jun 2016 22:51:36 +0100 Subject: [PATCH] Added SaveTitle function to the ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 99 +++++++++++++++++-- source/contacteditor/cdo/ContactDataObject.h | 9 ++ 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 01af8ed..2a436cb 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -118,14 +118,18 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ // Process TITLE. - for (std::map::iterator TitleIter = GeneralTitleList.begin(); - TitleIter != GeneralTitleList.end(); TitleIter++){ - - SaveData->Append("TITLE:"); - SaveData->Append(TitleIter->second); - SaveData->Append("\n"); - - } + SaveTitle(&GeneralTitleList, &GeneralTitleListLanguage, + &GeneralTitleListAltID, &GeneralTitleListPID, + &GeneralTitleListType, &GeneralTitleListPref, + &GeneralTitleListTokens, SaveData, ""); + SaveTitle(&HomeTitleList, &HomeTitleListLanguage, + &HomeTitleListAltID, &HomeTitleListPID, + &HomeTitleListType, &HomeTitleListPref, + &HomeTitleListTokens, SaveData, "home"); + SaveTitle(&BusinessTitleList, &BusinessTitleListLanguage, + &BusinessTitleListAltID, &BusinessTitleListPID, + &BusinessTitleListType, &BusinessTitleListPref, + &BusinessTitleListTokens, SaveData, "work"); // Write the end part of the vCard data file. @@ -135,4 +139,83 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ return SaveDataStatus; +} + +void ContactDataObject::SaveTitle(map *TitleList, map *TitleListLanguage, + map *TitleListAltID, map *TitleListPID, + map *TitleListType, map *TitleListPref, + map *TitleListTokens, wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator TitleIter = TitleList->begin(); + TitleIter != TitleList->end(); TitleIter++){ + + ProcessData.Append("TITLE"); + + // 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 ((*TitleListAltID)[TitleIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*TitleListAltID)[TitleIter->first]); + + } + + // Check if there is a value for LANGUAGE. + + if ((*TitleListLanguage)[TitleIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*TitleListLanguage)[TitleIter->first]); + + } + + // Check if there is a value for PID. + + if ((*TitleListPID)[TitleIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*TitleListPID)[TitleIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*TitleListPref)[TitleIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*TitleListPref)[TitleIter->first])); + + } + + // Check if there is a value for tokens. + + if ((*TitleListTokens)[TitleIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*TitleListTokens)[TitleIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(TitleIter->second); + ProcessData.Append("\n"); + + ProcessData = OutputText(&ProcessData); + + SaveData->Append(ProcessData); + ProcessData.clear(); + + } + } \ No newline at end of file diff --git a/source/contacteditor/cdo/ContactDataObject.h b/source/contacteditor/cdo/ContactDataObject.h index cc7d3d9..b9bfdf1 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -27,6 +27,8 @@ #include "../../vcard/vcard.h" #include "../../common/textprocessing.h" +using namespace std; + enum ContactLoadStatus{ CONTACTLOAD_UNITTESTFAIL = -1, CONTACTLOAD_OK, @@ -93,6 +95,13 @@ class ContactDataObject{ void ProcessCalendarFreeBusy(wxString PropertySeg1, wxString PropertySeg2, int *FreeBusyAddressCount); void ProcessKey(wxString PropertySeg1, wxString PropertySeg2, int *KeyCount); void ProcessVendor(wxString PropertySeg1, wxString PropertySeg2, int *VendorCount); + + // Save functions + + void SaveTitle(map *TitleList, map *TitleListLanguage, + map *TitleListAltID, map *TitleListPID, + map *TitleListType, map *TitleListPref, + map *TitleListTokens, wxString *SaveData, wxString DataType); public: -- 2.39.5