Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
a770ba84b08bb663f20a972672ed908e203d269e
[xestiacalendar/.git] / source / objects / calendarobject / CalendarObject-Save.cpp
1 // CalendarObject-Save.cpp - CalendarObject class save functions
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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"
22 using namespace std;
24 CalendarObjectSaveResult CalendarObject::SaveFile(string SaveFilename){
26         ofstream FileStream;
27         string ReceivedStringData = "";
28         
29         // Open the file.
30         
31         FileStream.open(SaveFilename, ofstream::out);
32         
33         if (FileStream.rdstate() & ofstream::failbit){
34                 return CALENDAROBJECTSAVE_CANNOTOPEN;
35         }
37         if (FileStream.rdstate() & ofstream::badbit){
38                 return CALENDAROBJECTSAVE_CANNOTOPEN;
39         }
40         
41         // Process the data into a string.
42         
43         CalendarObjectSaveResult SaveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
44         string SaveStringData;
45         
46         SaveResult = SaveString(&SaveStringData);
47         
48         FileStream.write(SaveStringData.c_str(), SaveStringData.size());
49         
50         FileStream.close();
51         
52         return SaveResult;
53         
54 }
56 CalendarObjectSaveResult CalendarObject::SaveString(string *SaveStringData){
58         *SaveStringData += "BEGIN:VCALENDAR\n";
59         *SaveStringData += "VERSION:2.0\n";
60         
61         // Check if METHOD has a value and print it if it does (and
62         // any token data if there).
63         
64         if (MethodData.size() > 0){
65                 
66                 if (MethodTokens.size() > 0){
67                 
68                         *SaveStringData += "METHOD;";
69                         *SaveStringData += MethodTokens;
70                         
71                 } else {
73                         *SaveStringData += "METHOD";
74                         
75                 }
77                 *SaveStringData += ":";
78                 *SaveStringData += MethodData;
79                 *SaveStringData += "\n";
80                 
81         }
82         
83         // Check if CALSCALE has a value and print it if it does (and
84         // any token data if there).
85         
86         if (CalendarScaleData.size() > 0){
87                 
88                 if (CalendarScaleTokens.size() > 0){
89                 
90                         *SaveStringData += "CALSCALE;";
91                         *SaveStringData += CalendarScaleTokens;
92                         
93                 } else {
95                         *SaveStringData += "CALSCALE";
96                         
97                 }
99                 *SaveStringData += ":";
100                 *SaveStringData += CalendarScaleData;
101                 *SaveStringData += "\n";
102                 
103         }
104         
105 #if defined(XESTIACAL_UNITTEST)
106         
107         *SaveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
108         
109 #else
111         *SaveStringData += "PRODID:-//Xestia//Calendar Version ";
112         *SaveStringData += XSDCAL_VERSION;
113         *SaveStringData += "//KW\n";
114         
115 #endif
116         
117         SaveObjectData(SaveStringData);
118         
119         *SaveStringData += "END:VCALENDAR";
120         
121         return CALENDAROBJECTSAVE_OK;
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