From 32778e9d9c1a7659a1fa29432f63902db4e3a9aa Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Wed, 29 Jun 2016 22:44:58 +0100 Subject: [PATCH] Added ROLE to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 94 +++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 4 + source/tests/xestiaab_contactsave.h | 5 + 3 files changed, 103 insertions(+) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 426f3f2..3ee868c 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -511,6 +511,21 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessWebsiteListPID, &BusinessWebsiteListType, &BusinessWebsiteListMediatype, &BusinessWebsiteListPref, &BusinessWebsiteListTokens, SaveData, "work"); + + // Process ROLE. + + SaveRole(&GeneralRoleList, &GeneralRoleListLanguage, + &GeneralRoleListAltID, &GeneralRoleListPID, + &GeneralRoleListType, &GeneralRoleListPref, + &GeneralRoleListTokens, SaveData, ""); + SaveRole(&HomeRoleList, &HomeRoleListLanguage, + &HomeRoleListAltID, &HomeRoleListPID, + &HomeRoleListType, &HomeRoleListPref, + &HomeRoleListTokens, SaveData, "home"); + SaveRole(&BusinessRoleList, &BusinessRoleListLanguage, + &BusinessRoleListAltID, &BusinessRoleListPID, + &BusinessRoleListType, &BusinessRoleListPref, + &BusinessRoleListTokens, SaveData, "work"); // Write the end part of the vCard data file. @@ -1272,4 +1287,83 @@ void ContactDataObject::SaveURL(map *WebsiteList, map *RoleList, map *RoleListLanguage, + map *RoleListAltID, map *RoleListPID, + map *RoleListType, map *RoleListPref, + map *RoleListTokens, wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator RoleIter = RoleList->begin(); + RoleIter != RoleList->end(); RoleIter++){ + + ProcessData.Append("ROLE"); + + // 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 ((*RoleListAltID)[RoleIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*RoleListAltID)[RoleIter->first]); + + } + + // Check if there is a value for LANGUAGE. + + if ((*RoleListLanguage)[RoleIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*RoleListLanguage)[RoleIter->first]); + + } + + // Check if there is a value for PID. + + if ((*RoleListPID)[RoleIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*RoleListPID)[RoleIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*RoleListPref)[RoleIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*RoleListPref)[RoleIter->first])); + + } + + // Check if there is a value for tokens. + + if ((*RoleListTokens)[RoleIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*RoleListTokens)[RoleIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(RoleIter->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 2cf736b..85342e4 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -139,6 +139,10 @@ class ContactDataObject{ map *WebsiteListPID, map *WebsiteListType, map *WebsiteListMediatype, map *WebsiteListPref, map *WebsiteListTokens, wxString *SaveData, wxString DataType); + void SaveRole(map *RoleList, map *RoleListLanguage, + map *RoleListAltID, map *RoleListPID, + map *RoleListType, map *RoleListPref, + map *RoleListTokens, wxString *SaveData, wxString DataType); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index b0842da..ea07194 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -126,6 +126,11 @@ TEST(ContactSave, ContactSaveTests){ " ample.com/home/\n" "URL;TYPE=work;ALTID=20;MEDIATYPE=chocolate/yummy;PID=21;PREF=22;YES=No:http:/\n" " /example.com/business/\n" + "ROLE;ALTID=50;LANGUAGE=en;PID=51;PREF=52;ASTERISK=None:Ordinary Person\n" + "ROLE;TYPE=home;ALTID=60;LANGUAGE=en-GB;PID=61;PREF=62;SOMEWHERE=There:Ordinar\n" + " y Lazy Person\n" + "ROLE;TYPE=work;ALTID=70;LANGUAGE=en-AU;PID=71;PREF=72;HERE=Nope:Company Owner\n" + "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.2