Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted code in calendarobject directory
[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