Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added CLIENTPIDMAP to the SaveString function of ContactDataObject
[xestiaab/.git] / source / contacteditor / cdo / ContactDataObject-Save.cpp
1 // ContactDataObject-Save.cpp - Client Data Object.
2 //
3 // (c) 2012-2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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){
23         
24         ContactSaveStatus SaveDataStatus = CONTACTSAVE_UNITTESTFAIL;
25         
26         // Write the header for the vCard data file.
27         
28         SaveData->Append("BEGIN:VCARD\n");
29         SaveData->Append("VERSION:4.0\n");
30         
31         // Write the product ID.
32         
33 #ifdef XAB_UNITTEST
34         
35         SaveData->Append("PRODID:-//Xestia//Address Book Unit Testing//KW\n");
36         
37 #else
38         
39         SaveData->Append(wxT("PRODID:-//Xestia//Address Book Version "));
40         SaveData->Append(wxT(XSDAB_VERSION));
41         SaveData->Append(wxT("//KW\n"));
42         
43 #endif
45         wxString ProcessData = "";
47         // Process UID.
49         if (UIDToken.size() > 0){
50                 
51                 ProcessData.Append("UID:");
52                 ProcessData.Append(UIDToken);
53                 ProcessData.Append("\n");
54                 SaveData->Append(ProcessData);
55                 ProcessData.clear();
56                 
57         }
58         
59         // Process KIND.
60         
61         switch(ContactKind){
63                 case CONTACTKIND_NONE:
64                         break;
65                 case CONTACTKIND_INDIVIDUAL:
66                         SaveData->Append("KIND:individual\n");
67                         break;
68                 case CONTACTKIND_GROUP:
69                         SaveData->Append("KIND:group\n");
70                         break;
71                 case CONTACTKIND_ORGANISATION:
72                         SaveData->Append("KIND:org\n");
73                         break;
74                 case CONTACTKIND_LOCATION:
75                         SaveData->Append("KIND:location\n");
76                         break;
77                 default:
78                         break;
79                 
80         }
81         
82         // Process SOURCE.
83         
84         SaveSource(&SourceList, &SourceListAltID, 
85                 &SourceListPID, &SourceListType,
86                 &SourceListMediatype, &SourceListPref, 
87                 &SourceListTokens, SaveData);
88         
89         // Process CLIENTPIDMAP.
90         
91         for (std::map<int, wxString>::iterator CPIDIter = ClientPIDList.begin();
92                 CPIDIter != ClientPIDList.end(); CPIDIter++){
93         
94                 ProcessData.Append("CLIENTPIDMAP");
95                         
96                 if (ClientPIDListTokens[CPIDIter->first].size() > 0){
97                 
98                         ProcessData.Append(";");
99                         ProcessData.Append(ClientPIDListTokens[CPIDIter->first]);
100                         
101                 }
102                         
103                 ProcessData.Append(":");
104                 ProcessData.Append(CPIDIter->second);
105                 ProcessData.Append("\n");
106                 
107                 ProcessData = OutputText(&ProcessData);
108                 
109                 SaveData->Append(ProcessData);
110                 ProcessData.clear();
111                         
112         }
113         
114         // Process FN.
115         
116         for (std::map<int, wxString>::iterator FNIter = FullNamesList.begin();
117                 FNIter != FullNamesList.end(); FNIter++){
118                 
119                 ProcessData.Append("FN");
121                 // Check if there is a value for TYPE.
122                 
123                 if (FullNamesListType[FNIter->first].size() > 0){
124                 
125                         ProcessData.Append(";TYPE=");
126                         ProcessData.Append(FullNamesListType[FNIter->first]);
127                         
128                 }
130                 // Check if there is a value for LANGUAGE.
131                 
132                 if (FullNamesListLanguage[FNIter->first].size() > 0){
133                 
134                         ProcessData.Append(";LANGUAGE=");
135                         ProcessData.Append(FullNamesListLanguage[FNIter->first]);
136                         
137                 }
138                 
139                 // Check if there is a value for ALTID.
140                 
141                 if (FullNamesListAltID[FNIter->first].size() > 0){
142                 
143                         ProcessData.Append(";ALTID=");
144                         ProcessData.Append(FullNamesListAltID[FNIter->first]);
145                         
146                 }
147                 
148                 // Check if there is a value for PID.
150                 if (FullNamesListPID[FNIter->first].size() > 0){
151                 
152                         ProcessData.Append(";PID=");
153                         ProcessData.Append(FullNamesListPID[FNIter->first]);
154                         
155                 }
157                 // Check if there is a value for PREF.
159                 if (FullNamesListPref[FNIter->first] > 0){
160                 
161                         ProcessData.Append(";PREF=");
162                         ProcessData.Append(wxString::Format("%i", FullNamesListPref[FNIter->first]));
163                         
164                 }
166                 // Check if there is a value for tokens.
168                 if (FullNamesListTokens[FNIter->first].size() > 0){
169                 
170                         ProcessData.Append(";");
171                         ProcessData.Append(FullNamesListTokens[FNIter->first]);
172                         
173                 }
174                 
175                 ProcessData.Append(":");
176                 ProcessData.Append(FNIter->second);
177                 ProcessData.Append("\n");
178                 
179                 ProcessData = OutputText(&ProcessData);
180                 
181                 SaveData->Append(ProcessData);
182                 ProcessData.clear();
183                         
184         }
185         
186         // Process TITLE.
188         SaveTitle(&GeneralTitleList, &GeneralTitleListLanguage,
189                 &GeneralTitleListAltID, &GeneralTitleListPID,
190                 &GeneralTitleListType, &GeneralTitleListPref,
191                 &GeneralTitleListTokens, SaveData, "");
192         SaveTitle(&HomeTitleList, &HomeTitleListLanguage,
193                 &HomeTitleListAltID, &HomeTitleListPID,
194                 &HomeTitleListType, &HomeTitleListPref,
195                 &HomeTitleListTokens, SaveData, "home");
196         SaveTitle(&BusinessTitleList, &BusinessTitleListLanguage,
197                 &BusinessTitleListAltID, &BusinessTitleListPID,
198                 &BusinessTitleListType, &BusinessTitleListPref,
199                 &BusinessTitleListTokens, SaveData, "work");
200         
201         // Write the end part of the vCard data file.
202         
203         SaveData->Append("END:VCARD");
204         
205         SaveDataStatus = CONTACTSAVE_OK;
206         
207         return SaveDataStatus;
208         
211 void ContactDataObject::SaveTitle(map<int, wxString> *TitleList, map<int, wxString> *TitleListLanguage,
212         map<int, wxString> *TitleListAltID, map<int, wxString> *TitleListPID,
213         map<int, wxString> *TitleListType, map<int, int> *TitleListPref,
214         map<int, wxString> *TitleListTokens, wxString *SaveData, wxString DataType){
216         wxString ProcessData = "";
217                 
218         for (std::map<int, wxString>::iterator TitleIter = TitleList->begin();
219                 TitleIter != TitleList->end(); TitleIter++){
221                 ProcessData.Append("TITLE");
222                         
223                 // Check if there is a value for TYPE.
224                 
225                 if (DataType.size() > 0){
226                 
227                         ProcessData.Append(";TYPE=");
228                         ProcessData.Append(DataType);
229                         
230                 }
231                 
232                 // Check if there is a value for ALTID.
233                 
234                 if ((*TitleListAltID)[TitleIter->first].size() > 0){
235                 
236                         ProcessData.Append(";ALTID=");
237                         ProcessData.Append((*TitleListAltID)[TitleIter->first]);
238                         
239                 }
241                 // Check if there is a value for LANGUAGE.
242                 
243                 if ((*TitleListLanguage)[TitleIter->first].size() > 0){
244                 
245                         ProcessData.Append(";LANGUAGE=");
246                         ProcessData.Append((*TitleListLanguage)[TitleIter->first]);
247                         
248                 }
249                 
250                 // Check if there is a value for PID.
252                 if ((*TitleListPID)[TitleIter->first].size() > 0){
253                 
254                         ProcessData.Append(";PID=");
255                         ProcessData.Append((*TitleListPID)[TitleIter->first]);
256                         
257                 }
259                 // Check if there is a value for PREF.
261                 if ((*TitleListPref)[TitleIter->first] > 0){
262                 
263                         ProcessData.Append(";PREF=");
264                         ProcessData.Append(wxString::Format("%i", (*TitleListPref)[TitleIter->first]));
265                         
266                 }
268                 // Check if there is a value for tokens.
270                 if ((*TitleListTokens)[TitleIter->first].size() > 0){
271                 
272                         ProcessData.Append(";");
273                         ProcessData.Append((*TitleListTokens)[TitleIter->first]);
274                         
275                 }
276                         
277                 ProcessData.Append(":");
278                 ProcessData.Append(TitleIter->second);
279                 ProcessData.Append("\n");
281                 ProcessData = OutputText(&ProcessData);
282                         
283                 SaveData->Append(ProcessData);
284                 ProcessData.clear();
285                         
286         }
287                 
290 void ContactDataObject::SaveSource(map<int, wxString> *SourceList, map<int, wxString> *SourceListAltID, 
291         map<int, wxString> *SourceListPID, map<int, wxString> *SourceListType,
292         map<int, wxString> *SourceListMediatype, map<int, int> *SourceListPref, 
293         map<int, wxString> *SourceListTokens, wxString *SaveData){
295         wxString ProcessData = "";
296         
297         for (std::map<int, wxString>::iterator SourceIter = SourceList->begin();
298                 SourceIter != SourceList->end(); SourceIter++){
300                 ProcessData.Append("SOURCE");
301                         
302                 // Check if there is a value for TYPE.
303                 
304                 if ((*SourceListType)[SourceIter->first].size() > 0){
305                 
306                         ProcessData.Append(";TYPE=");
307                         ProcessData.Append((*SourceListType)[SourceIter->first]);
308                         
309                 }
310                 
311                 // Check if there is a value for ALTID.
312                 
313                 if ((*SourceListAltID)[SourceIter->first].size() > 0){
314                 
315                         ProcessData.Append(";ALTID=");
316                         ProcessData.Append((*SourceListAltID)[SourceIter->first]);
317                         
318                 }
320                 // Check if there is a value for LANGUAGE.
321                 
322                 if ((*SourceListMediatype)[SourceIter->first].size() > 0){
323                 
324                         ProcessData.Append(";MEDIATYPE=");
325                         ProcessData.Append((*SourceListMediatype)[SourceIter->first]);
326                         
327                 }
328                 
329                 // Check if there is a value for PID.
331                 if ((*SourceListPID)[SourceIter->first].size() > 0){
332                 
333                         ProcessData.Append(";PID=");
334                         ProcessData.Append((*SourceListPID)[SourceIter->first]);
335                         
336                 }
338                 // Check if there is a value for PREF.
340                 if ((*SourceListPref)[SourceIter->first] > 0){
341                 
342                         ProcessData.Append(";PREF=");
343                         ProcessData.Append(wxString::Format("%i", (*SourceListPref)[SourceIter->first]));
344                         
345                 }
347                 // Check if there is a value for tokens.
349                 if ((*SourceListTokens)[SourceIter->first].size() > 0){
350                 
351                         ProcessData.Append(";");
352                         ProcessData.Append((*SourceListTokens)[SourceIter->first]);
353                         
354                 }
355                         
356                 ProcessData.Append(":");
357                 ProcessData.Append(SourceIter->second);
358                 ProcessData.Append("\n");
360                 ProcessData = OutputText(&ProcessData);
361                         
362                 SaveData->Append(ProcessData);
363                 ProcessData.clear();
364                         
365         }
366                 
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy