From 155d784a80b1be2eb3d48b5b7cb67e250736ff68 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 2 Jul 2016 08:51:53 +0100 Subject: [PATCH] Added CATEGORIES to the SaveString function of ContactDataObject --- .../cdo/ContactDataObject-Save.cpp | 86 +++++++++++++++++++ source/contacteditor/cdo/ContactDataObject.h | 4 + source/tests/xestiaab_contactsave.h | 9 ++ 3 files changed, 99 insertions(+) diff --git a/source/contacteditor/cdo/ContactDataObject-Save.cpp b/source/contacteditor/cdo/ContactDataObject-Save.cpp index 8107ed5..2334177 100644 --- a/source/contacteditor/cdo/ContactDataObject-Save.cpp +++ b/source/contacteditor/cdo/ContactDataObject-Save.cpp @@ -560,6 +560,13 @@ ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){ &BusinessNoteListType, &BusinessNoteListPref, &BusinessNoteListTokens, SaveData, "work"); + // Process CATEGORIES. + + SaveCategory(&CategoriesList, &CategoriesListLanguage, + &CategoriesListAltID, &CategoriesListPID, + &CategoriesListType, &CategoriesListPref, + &CategoriesListTokens, SaveData); + // Write the end part of the vCard data file. SaveData->Append("END:VCARD"); @@ -1569,4 +1576,83 @@ void ContactDataObject::SaveNote(map *NoteList, map *CategoryList, map *CategoryListLanguage, + map *CategoryListAltID, map *CategoryListPID, + map *CategoryListType, map *CategoryListPref, + map *CategoryListTokens, wxString *SaveData){ + + wxString ProcessData = ""; + + for (std::map::iterator CategoryIter = CategoryList->begin(); + CategoryIter != CategoryList->end(); CategoryIter++){ + + ProcessData.Append("CATEGORIES"); + + // Check if there is a value for TYPE. + + if ((*CategoryListType)[CategoryIter->first].size() > 0){ + + ProcessData.Append(";TYPE="); + ProcessData.Append((*CategoryListType)[CategoryIter->first]); + + } + + // Check if there is a value for ALTID. + + if ((*CategoryListAltID)[CategoryIter->first].size() > 0){ + + ProcessData.Append(";ALTID="); + ProcessData.Append((*CategoryListAltID)[CategoryIter->first]); + + } + + // Check if there is a value for LANGUAGE. + + if ((*CategoryListLanguage)[CategoryIter->first].size() > 0){ + + ProcessData.Append(";LANGUAGE="); + ProcessData.Append((*CategoryListLanguage)[CategoryIter->first]); + + } + + // Check if there is a value for PID. + + if ((*CategoryListPID)[CategoryIter->first].size() > 0){ + + ProcessData.Append(";PID="); + ProcessData.Append((*CategoryListPID)[CategoryIter->first]); + + } + + // Check if there is a value for PREF. + + if ((*CategoryListPref)[CategoryIter->first] > 0){ + + ProcessData.Append(";PREF="); + ProcessData.Append(wxString::Format("%i", (*CategoryListPref)[CategoryIter->first])); + + } + + // Check if there is a value for tokens. + + if ((*CategoryListTokens)[CategoryIter->first].size() > 0){ + + ProcessData.Append(";"); + ProcessData.Append((*CategoryListTokens)[CategoryIter->first]); + + } + + ProcessData.Append(":"); + ProcessData.Append(CategoryIter->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 6ffd214..a7f4939 100644 --- a/source/contacteditor/cdo/ContactDataObject.h +++ b/source/contacteditor/cdo/ContactDataObject.h @@ -152,6 +152,10 @@ class ContactDataObject{ map *NoteListAltID, map *NoteListPID, map *NoteListType, map *NoteListPref, map *NoteListTokens, wxString *SaveData, wxString DataType); + void SaveCategory(map *CategoryList, map *CategoryListLanguage, + map *CategoryListAltID, map *CategoryListPID, + map *CategoryListType, map *CategoryListPref, + map *CategoryListTokens, wxString *SaveData); public: diff --git a/source/tests/xestiaab_contactsave.h b/source/tests/xestiaab_contactsave.h index 8e672c7..d07aabf 100644 --- a/source/tests/xestiaab_contactsave.h +++ b/source/tests/xestiaab_contactsave.h @@ -142,6 +142,15 @@ TEST(ContactSave, ContactSaveTests){ " 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" + "CATEGORIES;ALTID=40;LANGUAGE=en;PID=41;PREF=42;CAT=TAC:Category One\n" + "CATEGORIES;TYPE=home;ALTID=44;LANGUAGE=kw;PID=46;PREF=48;TAC=CAT:Category Two\n" + "CATEGORIES;TYPE=home;ALTID=44;LANGUAGE=kw;PID=46;PREF=48;TAC=CAT:Category Thr\n" + " ee\n" + "CATEGORIES;TYPE=work;ALTID=84;LANGUAGE=kw;PID=86;PREF=88;AAA=BBB:Category Fou\n" + " r\n" + "CATEGORIES;TYPE=work;ALTID=84;LANGUAGE=kw;PID=86;PREF=88;AAA=BBB:Category Fiv\n" + " e\n" + "CATEGORIES;TYPE=work;ALTID=84;LANGUAGE=kw;PID=86;PREF=88;AAA=BBB:Category Six\n" "END:VCARD"; ASSERT_EQ(CONTACTLOAD_OK, TestFile3.LoadFile("LoadCheck-Load4.vcf")); -- 2.39.5