From d26544d56dee0a1f6b62b096efcdbd8b7d03e245 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Wed, 29 Jun 2016 18:02:09 +0100 Subject: [PATCH] Added ADR to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 162 ++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 8 + source/tests/xestiaab_contactsave.h | 12 ++ 3 files changed, 182 insertions(+) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 5fbc386..c8a394a 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -255,6 +255,33 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessTZListMediatype, &BusinessTZListPref, &BusinessTZListTokens, SaveData, "work"); + // Process ADR. + + SaveAddress(&GeneralAddressList, &GeneralAddressListTown, + &GeneralAddressListCounty, &GeneralAddressListPostCode, + &GeneralAddressListCountry, &GeneralAddressListLabel, + &GeneralAddressListLang, &GeneralAddressListAltID, + &GeneralAddressListPID, &GeneralAddressListGeo, + &GeneralAddressListTimezone, &GeneralAddressListType, + &GeneralAddressListMediatype, &GeneralAddressListPref, + &GeneralAddressListTokens, SaveData, ""); + SaveAddress(&HomeAddressList, &HomeAddressListTown, + &HomeAddressListCounty, &HomeAddressListPostCode, + &HomeAddressListCountry, &HomeAddressListLabel, + &HomeAddressListLang, &HomeAddressListAltID, + &HomeAddressListPID, &HomeAddressListGeo, + &HomeAddressListTimezone, &HomeAddressListType, + &HomeAddressListMediatype, &HomeAddressListPref, + &HomeAddressListTokens, SaveData, "home"); + SaveAddress(&BusinessAddressList, &BusinessAddressListTown, + &BusinessAddressListCounty, &BusinessAddressListPostCode, + &BusinessAddressListCountry, &BusinessAddressListLabel, + &BusinessAddressListLang, &BusinessAddressListAltID, + &BusinessAddressListPID, &BusinessAddressListGeo, + &BusinessAddressListTimezone, &BusinessAddressListType, + &BusinessAddressListMediatype, &BusinessAddressListPref, + &BusinessAddressListTokens, SaveData, "work"); + // Write the end part of the vCard data file. SaveData->Append("END:VCARD"); @@ -579,4 +606,139 @@ void ContactDataObject::SaveTimezone(map *TZList, map *AddressList, map *AddressListTown, + map *AddressListCounty, map *AddressListPostCode, + map *AddressListCountry, map *AddressListLabel, + map *AddressListLang, map *AddressListAltID, + map *AddressListPID, map *AddressListGeo, + map *AddressListTimezone, map *AddressListType, + map *AddressListMediatype, map *AddressListPref, + map *AddressListTokens, wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator AddressIter = AddressList->begin(); + AddressIter != AddressList->end(); AddressIter++){ + + ProcessData.Append("ADR"); + + // 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 ((*AddressListAltID)[AddressIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*AddressListAltID)[AddressIter->first]); + + } + + // Check if there is a value for GEO. + + if ((*AddressListGeo)[AddressIter->first].size() > 0){ + + ProcessData.Append(";GEO=\""); + ProcessData.Append((*AddressListGeo)[AddressIter->first]); + ProcessData.Append("\""); + + } + + // Check if there is a value for LABEL. + + if ((*AddressListLabel)[AddressIter->first].size() > 0){ + + wxString AddressProcessed = ""; + AddressProcessed = (*AddressListLabel)[AddressIter->first]; + + AddressProcessed.Replace("\n", "\\n", true); + + ProcessData.Append(";LABEL="); + ProcessData.Append(AddressProcessed); + + } + + // Check if there is a value for LANGUAGE. + + if ((*AddressListLang)[AddressIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*AddressListLang)[AddressIter->first]); + + } + + // Check if there is a value for MEDIATYPE. + + if ((*AddressListMediatype)[AddressIter->first].size() > 0){ + + ProcessData.Append(";MEDIATYPE="); + ProcessData.Append((*AddressListMediatype)[AddressIter->first]); + + } + + // Check if there is a value for PID. + + if ((*AddressListPID)[AddressIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*AddressListPID)[AddressIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*AddressListPref)[AddressIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*AddressListPref)[AddressIter->first])); + + } + + // Check if there is a value for TZ. + + if ((*AddressListTimezone)[AddressIter->first].size() > 0){ + + ProcessData.Append(";TZ="); + ProcessData.Append((*AddressListTimezone)[AddressIter->first]); + + } + + // Check if there is a value for tokens. + + if ((*AddressListTokens)[AddressIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*AddressListTokens)[AddressIter->first]); + + } + + // Build the address. + + ProcessData.Append(":;;"); + ProcessData.Append((*AddressList)[AddressIter->first]); + ProcessData.Append(";"); + ProcessData.Append((*AddressListTown)[AddressIter->first]); + ProcessData.Append(";"); + ProcessData.Append((*AddressListCounty)[AddressIter->first]); + ProcessData.Append(";"); + ProcessData.Append((*AddressListPostCode)[AddressIter->first]); + ProcessData.Append(";"); + ProcessData.Append((*AddressListCountry)[AddressIter->first]); + 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 3fa2658..f12c17a 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -114,6 +114,14 @@ class ContactDataObject{ map *TZListPID, map *TZListType, map *TZListMediatype, map *TZListPref, map *TZListTokens, wxString *SaveData, wxString DataType); + void SaveAddress(map *AddressList, map *AddressListTown, + map *AddressListCounty, map *AddressListPostCode, + map *AddressListCountry, map *AddressListLabel, + map *AddressListLang, map *AddressListAltID, + map *AddressListPID, map *AddressListGeo, + map *AddressListTimezone, map *AddressListType, + map *AddressListMediatype, map *AddressListPref, + map *AddressListTokens, wxString *SaveData, wxString DataType); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index 8420e63..5afdb83 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -95,6 +95,18 @@ TEST(ContactSave, ContactSaveTests){ " nzance\n" "TZ;TYPE=work;ALTID=45;MEDIATYPE=text/plain;PID=70;PREF=80;MAYBE=yes:Europe/St\n" " Austell\n" + "ADR;ALTID=15;GEO=\"geo:1.0, 1.0\";LABEL=\"1 Lovely Lane\\nRodney\\nCornwall\\nPL99 \n" + " 1AA\\nCornwall\\nUnited Kingdom\";LANGUAGE=kw;MEDIATYPE=text/plain;PID=81;PREF=\n" + " 98;TZ=Europe/Truro;MAKES=Moo;ANIMAL=Cow:;;1 Lovely Lane;Rodney;Cornwall;PL99\n" + " 1AA;United Kingdom\n" + "ADR;TYPE=home;ALTID=40;GEO=\"geo:4.0, 4.0\";LABEL=\"3 Working Plaice\\nRoger\\nCor\n" + " nwall\\nPL75 4ZZ\\nCornwall\\nUnited Kingdom\";LANGUAGE=en;MEDIATYPE=text/plain;\n" + " PID=13;PREF=10;TZ=Europe/St Ives;TOAST=Butter:;;3 Working Plaice;Roger;Cornw\n" + " all;PL75 4ZZ;United Kingdom\n" + "ADR;TYPE=work;ALTID=45;GEO=\"geo:7.0, 7.0\";LABEL=\"7 Flyby Drive\\nElaine\\nCornw\n" + " all\\nPL84 9YE\\nCornwall\\nUnited Kingdom\";LANGUAGE=en-GB;MEDIATYPE=text/plain\n" + " ;PID=28;PREF=10;TZ=Europe/Newquay;JAM=Red:;;7 Flyby Drive;Elaine;Cornwall;PL\n" + " 84 9YE;United Kingdom\n" "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.2