1 // ContactDataObject-Save.cpp - Client Data Object.
3 // (c) 2012-2016 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "ContactDataObject.h"
20 #include "../../version.h"
22 ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
24 ContactSaveStatus SaveDataStatus = CONTACTSAVE_UNITTESTFAIL;
26 // Write the header for the vCard data file.
28 SaveData->Append("BEGIN:VCARD\n");
29 SaveData->Append("VERSION:4.0\n");
31 // Write the product ID.
35 SaveData->Append("PRODID:-//Xestia//Address Book Unit Testing//KW\n");
39 SaveData->Append(wxT("PRODID:-//Xestia//Address Book Version "));
40 SaveData->Append(wxT(XSDAB_VERSION));
41 SaveData->Append(wxT("//KW\n"));
45 wxString ProcessData = "";
49 if (UIDToken.size() > 0){
51 ProcessData.Append("UID:");
52 ProcessData.Append(UIDToken);
53 ProcessData.Append("\n");
54 SaveData->Append(ProcessData);
63 case CONTACTKIND_NONE:
65 case CONTACTKIND_INDIVIDUAL:
66 SaveData->Append("KIND:individual\n");
68 case CONTACTKIND_GROUP:
69 SaveData->Append("KIND:group\n");
71 case CONTACTKIND_ORGANISATION:
72 SaveData->Append("KIND:org\n");
74 case CONTACTKIND_LOCATION:
75 SaveData->Append("KIND:location\n");
84 SaveSource(&SourceList, &SourceListAltID,
85 &SourceListPID, &SourceListType,
86 &SourceListMediatype, &SourceListPref,
87 &SourceListTokens, SaveData);
91 for (std::map<int, wxString>::iterator FNIter = FullNamesList.begin();
92 FNIter != FullNamesList.end(); FNIter++){
94 ProcessData.Append("FN");
96 // Check if there is a value for TYPE.
98 if (FullNamesListType[FNIter->first].size() > 0){
100 ProcessData.Append(";TYPE=");
101 ProcessData.Append(FullNamesListType[FNIter->first]);
105 // Check if there is a value for LANGUAGE.
107 if (FullNamesListLanguage[FNIter->first].size() > 0){
109 ProcessData.Append(";LANGUAGE=");
110 ProcessData.Append(FullNamesListLanguage[FNIter->first]);
114 // Check if there is a value for ALTID.
116 if (FullNamesListAltID[FNIter->first].size() > 0){
118 ProcessData.Append(";ALTID=");
119 ProcessData.Append(FullNamesListAltID[FNIter->first]);
123 // Check if there is a value for PID.
125 if (FullNamesListPID[FNIter->first].size() > 0){
127 ProcessData.Append(";PID=");
128 ProcessData.Append(FullNamesListPID[FNIter->first]);
132 // Check if there is a value for PREF.
134 if (FullNamesListPref[FNIter->first] > 0){
136 ProcessData.Append(";PREF=");
137 ProcessData.Append(wxString::Format("%i", FullNamesListPref[FNIter->first]));
141 // Check if there is a value for tokens.
143 if (FullNamesListTokens[FNIter->first].size() > 0){
145 ProcessData.Append(";");
146 ProcessData.Append(FullNamesListTokens[FNIter->first]);
150 ProcessData.Append(":");
151 ProcessData.Append(FNIter->second);
152 ProcessData.Append("\n");
154 ProcessData = OutputText(&ProcessData);
156 SaveData->Append(ProcessData);
163 SaveTitle(&GeneralTitleList, &GeneralTitleListLanguage,
164 &GeneralTitleListAltID, &GeneralTitleListPID,
165 &GeneralTitleListType, &GeneralTitleListPref,
166 &GeneralTitleListTokens, SaveData, "");
167 SaveTitle(&HomeTitleList, &HomeTitleListLanguage,
168 &HomeTitleListAltID, &HomeTitleListPID,
169 &HomeTitleListType, &HomeTitleListPref,
170 &HomeTitleListTokens, SaveData, "home");
171 SaveTitle(&BusinessTitleList, &BusinessTitleListLanguage,
172 &BusinessTitleListAltID, &BusinessTitleListPID,
173 &BusinessTitleListType, &BusinessTitleListPref,
174 &BusinessTitleListTokens, SaveData, "work");
176 // Write the end part of the vCard data file.
178 SaveData->Append("END:VCARD");
180 SaveDataStatus = CONTACTSAVE_OK;
182 return SaveDataStatus;
186 void ContactDataObject::SaveTitle(map<int, wxString> *TitleList, map<int, wxString> *TitleListLanguage,
187 map<int, wxString> *TitleListAltID, map<int, wxString> *TitleListPID,
188 map<int, wxString> *TitleListType, map<int, int> *TitleListPref,
189 map<int, wxString> *TitleListTokens, wxString *SaveData, wxString DataType){
191 wxString ProcessData = "";
193 for (std::map<int, wxString>::iterator TitleIter = TitleList->begin();
194 TitleIter != TitleList->end(); TitleIter++){
196 ProcessData.Append("TITLE");
198 // Check if there is a value for TYPE.
200 if (DataType.size() > 0){
202 ProcessData.Append(";TYPE=");
203 ProcessData.Append(DataType);
207 // Check if there is a value for ALTID.
209 if ((*TitleListAltID)[TitleIter->first].size() > 0){
211 ProcessData.Append(";ALTID=");
212 ProcessData.Append((*TitleListAltID)[TitleIter->first]);
216 // Check if there is a value for LANGUAGE.
218 if ((*TitleListLanguage)[TitleIter->first].size() > 0){
220 ProcessData.Append(";LANGUAGE=");
221 ProcessData.Append((*TitleListLanguage)[TitleIter->first]);
225 // Check if there is a value for PID.
227 if ((*TitleListPID)[TitleIter->first].size() > 0){
229 ProcessData.Append(";PID=");
230 ProcessData.Append((*TitleListPID)[TitleIter->first]);
234 // Check if there is a value for PREF.
236 if ((*TitleListPref)[TitleIter->first] > 0){
238 ProcessData.Append(";PREF=");
239 ProcessData.Append(wxString::Format("%i", (*TitleListPref)[TitleIter->first]));
243 // Check if there is a value for tokens.
245 if ((*TitleListTokens)[TitleIter->first].size() > 0){
247 ProcessData.Append(";");
248 ProcessData.Append((*TitleListTokens)[TitleIter->first]);
252 ProcessData.Append(":");
253 ProcessData.Append(TitleIter->second);
254 ProcessData.Append("\n");
256 ProcessData = OutputText(&ProcessData);
258 SaveData->Append(ProcessData);
265 void ContactDataObject::SaveSource(map<int, wxString> *SourceList, map<int, wxString> *SourceListAltID,
266 map<int, wxString> *SourceListPID, map<int, wxString> *SourceListType,
267 map<int, wxString> *SourceListMediatype, map<int, int> *SourceListPref,
268 map<int, wxString> *SourceListTokens, wxString *SaveData){
270 wxString ProcessData = "";
272 for (std::map<int, wxString>::iterator SourceIter = SourceList->begin();
273 SourceIter != SourceList->end(); SourceIter++){
275 ProcessData.Append("SOURCE");
277 // Check if there is a value for TYPE.
279 if ((*SourceListType)[SourceIter->first].size() > 0){
281 ProcessData.Append(";TYPE=");
282 ProcessData.Append((*SourceListType)[SourceIter->first]);
286 // Check if there is a value for ALTID.
288 if ((*SourceListAltID)[SourceIter->first].size() > 0){
290 ProcessData.Append(";ALTID=");
291 ProcessData.Append((*SourceListAltID)[SourceIter->first]);
295 // Check if there is a value for LANGUAGE.
297 if ((*SourceListMediatype)[SourceIter->first].size() > 0){
299 ProcessData.Append(";MEDIATYPE=");
300 ProcessData.Append((*SourceListMediatype)[SourceIter->first]);
304 // Check if there is a value for PID.
306 if ((*SourceListPID)[SourceIter->first].size() > 0){
308 ProcessData.Append(";PID=");
309 ProcessData.Append((*SourceListPID)[SourceIter->first]);
313 // Check if there is a value for PREF.
315 if ((*SourceListPref)[SourceIter->first] > 0){
317 ProcessData.Append(";PREF=");
318 ProcessData.Append(wxString::Format("%i", (*SourceListPref)[SourceIter->first]));
322 // Check if there is a value for tokens.
324 if ((*SourceListTokens)[SourceIter->first].size() > 0){
326 ProcessData.Append(";");
327 ProcessData.Append((*SourceListTokens)[SourceIter->first]);
331 ProcessData.Append(":");
332 ProcessData.Append(SourceIter->second);
333 ProcessData.Append("\n");
335 ProcessData = OutputText(&ProcessData);
337 SaveData->Append(ProcessData);