// ContactDataObject-Save.cpp - Client Data Object.
//
// (c) 2012-2016 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by the
// Free Software Foundation, version 3 of the license.
//
// Xestia Address Book is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with Xestia Address Book. If not, see
#include "ContactDataObject.h"
#include "../../version.h"
ContactSaveStatus ContactDataObject::SaveString(wxString *SaveData){
ContactSaveStatus SaveDataStatus = CONTACTSAVE_UNITTESTFAIL;
// Write the header for the vCard data file.
SaveData->Append("BEGIN:VCARD\n");
SaveData->Append("VERSION:4.0\n");
// Write the product ID.
#ifdef XAB_UNITTEST
SaveData->Append("PRODID:-//Xestia//Address Book Unit Testing//KW\n");
#else
SaveData->Append(wxT("PRODID:-//Xestia//Address Book Version "));
SaveData->Append(wxT(XSDAB_VERSION));
SaveData->Append(wxT("//KW\n"));
#endif
// Process FN.
for (std::map::iterator FNIter = FullNamesList.begin();
FNIter != FullNamesList.end(); FNIter++){
SaveData->Append("FN");
// Check if there is a value for TYPE.
if (FullNamesListType[FNIter->first].size() > 0){
SaveData->Append(";TYPE=");
SaveData->Append(FullNamesListType[FNIter->first]);
}
// Check if there is a value for LANGUAGE.
if (FullNamesListLanguage[FNIter->first].size() > 0){
SaveData->Append(";LANGUAGE=");
SaveData->Append(FullNamesListLanguage[FNIter->first]);
}
// Check if there is a value for ALTID.
if (FullNamesListAltID[FNIter->first].size() > 0){
SaveData->Append(";ALTID=");
SaveData->Append(FullNamesListAltID[FNIter->first]);
}
// Check if there is a value for PID.
if (FullNamesListPID[FNIter->first].size() > 0){
SaveData->Append(";PID=");
SaveData->Append(FullNamesListPID[FNIter->first]);
}
// Check if there is a value for PREF.
if (FullNamesListPref[FNIter->first] > 0){
SaveData->Append(";PREF=");
SaveData->Append(wxString::Format("%i", FullNamesListPref[FNIter->first]));
}
// Check if there is a value for tokens.
if (FullNamesListTokens[FNIter->first].size() > 0){
SaveData->Append(";");
SaveData->Append(FullNamesListTokens[FNIter->first]);
}
SaveData->Append(":");
SaveData->Append(FNIter->second);
SaveData->Append("\n");
}
// Process TITLE.
for (std::map::iterator TitleIter = GeneralTitleList.begin();
TitleIter != GeneralTitleList.end(); TitleIter++){
SaveData->Append("TITLE:");
SaveData->Append(TitleIter->second);
SaveData->Append("\n");
}
// Write the end part of the vCard data file.
SaveData->Append("END:VCARD");
SaveDataStatus = CONTACTSAVE_OK;
return SaveDataStatus;
}