From 238b146d253fc00415dedf56904aaa06d3a6726c Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Thu, 30 Jun 2016 21:37:11 +0100 Subject: [PATCH] Added ORG to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 108 ++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 5 + source/tests/xestiaab_contactsave.h | 7 +- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 3ee868c..08135bf 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -526,7 +526,25 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessRoleListAltID, &BusinessRoleListPID, &BusinessRoleListType, &BusinessRoleListPref, &BusinessRoleListTokens, SaveData, "work"); + + // Process ORG. + SaveOrganisation(&GeneralOrganisationsList, &GeneralOrganisationsListAltID, + &GeneralOrganisationsListPID, &GeneralOrganisationsListLanguage, + &GeneralOrganisationsListSortAs, &GeneralOrganisationsListType, + &GeneralOrganisationsListPref, &GeneralOrganisationsListTokens, + SaveData, ""); + SaveOrganisation(&HomeOrganisationsList, &HomeOrganisationsListAltID, + &HomeOrganisationsListPID, &HomeOrganisationsListLanguage, + &HomeOrganisationsListSortAs, &HomeOrganisationsListType, + &HomeOrganisationsListPref, &HomeOrganisationsListTokens, + SaveData, "home"); + SaveOrganisation(&BusinessOrganisationsList, &BusinessOrganisationsListAltID, + &BusinessOrganisationsListPID, &BusinessOrganisationsListLanguage, + &BusinessOrganisationsListSortAs, &BusinessOrganisationsListType, + &BusinessOrganisationsListPref, &BusinessOrganisationsListTokens, + SaveData, "work"); + // Write the end part of the vCard data file. SaveData->Append("END:VCARD"); @@ -1366,4 +1384,94 @@ void ContactDataObject::SaveRole(map *RoleList, map *OrganisationList, map *OrganisationListAltID, + map *OrganisationListPID, map *OrganisationListLanguage, + map *OrganisationListSortAs, map *OrganisationListType, + map *OrganisationListPref, map *OrganisationListTokens, + wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator OrganisationIter = OrganisationList->begin(); + OrganisationIter != OrganisationList->end(); OrganisationIter++){ + + ProcessData.Append("ORG"); + + // 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 ((*OrganisationListAltID)[OrganisationIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*OrganisationListAltID)[OrganisationIter->first]); + + } + + // Check if there is a value for LANGUAGE. + + if ((*OrganisationListLanguage)[OrganisationIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*OrganisationListLanguage)[OrganisationIter->first]); + + } + + // Check if there is a value for PID. + + if ((*OrganisationListPID)[OrganisationIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*OrganisationListPID)[OrganisationIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*OrganisationListPref)[OrganisationIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*OrganisationListPref)[OrganisationIter->first])); + + } + + // Check if there is a value for SORT-AS. + + if ((*OrganisationListSortAs)[OrganisationIter->first].size() > 0){ + + ProcessData.Append(";SORT-AS=\""); + ProcessData.Append((*OrganisationListSortAs)[OrganisationIter->first]); + ProcessData.Append("\""); + + } + + // Check if there is a value for tokens. + + if ((*OrganisationListTokens)[OrganisationIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*OrganisationListTokens)[OrganisationIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(OrganisationIter->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 85342e4..d8c199b 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -143,6 +143,11 @@ class ContactDataObject{ map *RoleListAltID, map *RoleListPID, map *RoleListType, map *RoleListPref, map *RoleListTokens, wxString *SaveData, wxString DataType); + void SaveOrganisation(map *OrganisationList, map *OrganisationListLanguage, + map *OrganisationListAltID, map *OrganisationListPID, + map *OrganisationListSortAs, map *OrganisationListType, + map *OrganisationListPref, map *OrganisationListTokens, + wxString *SaveData, wxString DataType); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index ea07194..08f9ac8 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -130,7 +130,12 @@ TEST(ContactSave, ContactSaveTests){ "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" - + "ORG;ALTID=50;LANGUAGE=en;PID=51;PREF=52;SORT-AS=\"Organisation, Ordinary\";ASTE\n" + " RISK=None:Ordinary Organisation\n" + "ORG;TYPE=home;ALTID=60;LANGUAGE=en-GB;PID=61;PREF=62;SORT-AS=\"Person, Ordinar\n" + " y Lazy\";SOMEWHERE=There:Ordinary Lazy Person\n" + "ORG;TYPE=work;ALTID=70;LANGUAGE=en-AU;PID=71;PREF=72;SORT-AS=\"Owner, Company\"\n" + " ;HERE=Nope:Company Owner\n" "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.2