From 30062fcf4f90524f1e5089199220eeb6cbafe82f Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Thu, 30 Jun 2016 23:32:57 +0100 Subject: [PATCH] Added NOTE to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 95 +++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 4 + source/tests/xestiaab_contactsave.h | 6 ++ 3 files changed, 105 insertions(+) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 08135bf..8107ed5 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -545,6 +545,21 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessOrganisationsListPref, &BusinessOrganisationsListTokens, SaveData, "work"); + // Process NOTE. + + SaveNote(&GeneralNoteList, &GeneralNoteListLanguage, + &GeneralNoteListAltID, &GeneralNoteListPID, + &GeneralNoteListType, &GeneralNoteListPref, + &GeneralNoteListTokens, SaveData, ""); + SaveNote(&HomeNoteList, &HomeNoteListLanguage, + &HomeNoteListAltID, &HomeNoteListPID, + &HomeNoteListType, &HomeNoteListPref, + &HomeNoteListTokens, SaveData, "home"); + SaveNote(&BusinessNoteList, &BusinessNoteListLanguage, + &BusinessNoteListAltID, &BusinessNoteListPID, + &BusinessNoteListType, &BusinessNoteListPref, + &BusinessNoteListTokens, SaveData, "work"); + // Write the end part of the vCard data file. SaveData->Append("END:VCARD"); @@ -1474,4 +1489,84 @@ void ContactDataObject::SaveOrganisation(map *OrganisationList, m } +} + +void ContactDataObject::SaveNote(map *NoteList, map *NoteListLanguage, + map *NoteListAltID, map *NoteListPID, + map *NoteListType, map *NoteListPref, + map *NoteListTokens, wxString *SaveData, wxString DataType){ + + wxString ProcessData = ""; + + for (std::map::iterator NoteIter = NoteList->begin(); + NoteIter != NoteList->end(); NoteIter++){ + + ProcessData.Append("NOTE"); + + // 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 ((*NoteListAltID)[NoteIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*NoteListAltID)[NoteIter->first]); + + } + + // Check if there is a value for LANGUAGE. + + if ((*NoteListLanguage)[NoteIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*NoteListLanguage)[NoteIter->first]); + + } + + // Check if there is a value for PID. + + if ((*NoteListPID)[NoteIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*NoteListPID)[NoteIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*NoteListPref)[NoteIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*NoteListPref)[NoteIter->first])); + + } + + // Check if there is a value for tokens. + + if ((*NoteListTokens)[NoteIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*NoteListTokens)[NoteIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(NoteIter->second); + ProcessData.Replace("\n", "\\n", true); + 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 d8c199b..6ffd214 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -148,6 +148,10 @@ class ContactDataObject{ map *OrganisationListSortAs, map *OrganisationListType, map *OrganisationListPref, map *OrganisationListTokens, wxString *SaveData, wxString DataType); + void SaveNote(map *NoteList, map *NoteListLanguage, + map *NoteListAltID, map *NoteListPID, + map *NoteListType, map *NoteListPref, + map *NoteListTokens, wxString *SaveData, wxString DataType); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index 08f9ac8..8e672c7 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -136,6 +136,12 @@ TEST(ContactSave, ContactSaveTests){ " 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" + "NOTE;ALTID=90;LANGUAGE=en;PID=91;PREF=92;WOO=WOOP:Note\\n\\nLine 3\\nLine 4\\nLin\n" + " e 5\n" + "NOTE;TYPE=home;ALTID=80;LANGUAGE=kw;PID=81;PREF=82;MOO=MEEP:Note\\n\\n\\n\\nLine \n" + " 5\\nLine 6\\nLine 7\n" + "NOTE;TYPE=work;ALTID=70;LANGUAGE=fr;PID=71;PREF=72;BOING=BOOP:Note\\n\\n\\n\\nLin\n" + " e 8\\nLine 9\\nLine 10\n" "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.5