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"));
47 for (std::map<int, wxString>::iterator FNIter = FullNamesList.begin();
48 FNIter != FullNamesList.end(); FNIter++){
50 SaveData->Append("FN");
52 // Check if there is a value for TYPE.
54 if (FullNamesListType[FNIter->first].size() > 0){
56 SaveData->Append(";TYPE=");
57 SaveData->Append(FullNamesListType[FNIter->first]);
61 // Check if there is a value for LANGUAGE.
63 if (FullNamesListLanguage[FNIter->first].size() > 0){
65 SaveData->Append(";LANGUAGE=");
66 SaveData->Append(FullNamesListLanguage[FNIter->first]);
70 // Check if there is a value for ALTID.
72 if (FullNamesListAltID[FNIter->first].size() > 0){
74 SaveData->Append(";ALTID=");
75 SaveData->Append(FullNamesListAltID[FNIter->first]);
79 // Check if there is a value for PID.
81 if (FullNamesListPID[FNIter->first].size() > 0){
83 SaveData->Append(";PID=");
84 SaveData->Append(FullNamesListPID[FNIter->first]);
88 // Check if there is a value for PREF.
90 if (FullNamesListPref[FNIter->first] > 0){
92 SaveData->Append(";PREF=");
93 SaveData->Append(wxString::Format("%i", FullNamesListPref[FNIter->first]));
97 // Check if there is a value for tokens.
99 if (FullNamesListTokens[FNIter->first].size() > 0){
101 SaveData->Append(";");
102 SaveData->Append(FullNamesListTokens[FNIter->first]);
106 SaveData->Append(":");
107 SaveData->Append(FNIter->second);
108 SaveData->Append("\n");
114 for (std::map<int, wxString>::iterator TitleIter = GeneralTitleList.begin();
115 TitleIter != GeneralTitleList.end(); TitleIter++){
117 SaveData->Append("TITLE:");
118 SaveData->Append(TitleIter->second);
119 SaveData->Append("\n");
123 // Write the end part of the vCard data file.
125 SaveData->Append("END:VCARD");
127 SaveDataStatus = CONTACTSAVE_OK;
129 return SaveDataStatus;