1 // CalendarObject-Save.cpp - CalendarObject class save functions
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar 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 Calendar 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 Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "CalendarObject.h"
20 #include "../../common/file.h"
24 CalendarObjectSaveResult CalendarObject::SaveFile(string saveFilename){
27 string receivedStringData = "";
31 fileStream.open(saveFilename, ofstream::out);
33 if (fileStream.rdstate() & ofstream::failbit){
34 return CALENDAROBJECTSAVE_CANNOTOPEN;
37 if (fileStream.rdstate() & ofstream::badbit){
38 return CALENDAROBJECTSAVE_CANNOTOPEN;
41 // Process the data into a string.
43 CalendarObjectSaveResult saveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
44 string saveStringData;
46 saveResult = SaveString(&saveStringData);
48 fileStream.write(saveStringData.c_str(), saveStringData.size());
56 CalendarObjectSaveResult CalendarObject::SaveString(string *saveStringData){
58 *saveStringData += "BEGIN:VCALENDAR\n";
59 *saveStringData += "VERSION:2.0\n";
61 // Check if METHOD has a value and print it if it does (and
62 // any token data if there).
64 if (methodData.size() > 0){
66 if (methodTokens.size() > 0){
68 *saveStringData += "METHOD;";
69 *saveStringData += methodTokens;
73 *saveStringData += "METHOD";
77 *saveStringData += ":";
78 *saveStringData += methodData;
79 *saveStringData += "\n";
83 // Check if CALSCALE has a value and print it if it does (and
84 // any token data if there).
86 if (calendarScaleData.size() > 0){
88 if (calendarScaleTokens.size() > 0){
90 *saveStringData += "CALSCALE;";
91 *saveStringData += calendarScaleTokens;
95 *saveStringData += "CALSCALE";
99 *saveStringData += ":";
100 *saveStringData += calendarScaleData;
101 *saveStringData += "\n";
105 #if defined(XESTIACAL_UNITTEST)
107 *saveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
111 *saveStringData += "PRODID:-//Xestia//Calendar Version ";
112 *saveStringData += XSDCAL_VERSION;
113 *saveStringData += "//KW\n";
117 SaveObjectData(saveStringData);
119 *saveStringData += "END:VCALENDAR";
121 return CALENDAROBJECTSAVE_OK;