Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
cmake: Implement support for CMake on Linux and remove Makefiles
[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 #ifndef WIN32
33         fileStream.open(saveFilename, ofstream::out);
35 #else
37         wstring saveFilename_utf16;
39         int len = MultiByteToWideChar(CP_UTF8, 0, &saveFilename[0], (int)saveFilename.size(), NULL, 0);
41         if (len > 0)
42         {
43                 saveFilename_utf16.resize(len);
44                 MultiByteToWideChar(CP_UTF8, 0, &saveFilename[0], (int)saveFilename.size(), &saveFilename_utf16[0], len);
45         }
47         fileStream.open(saveFilename_utf16, ofstream::out);
49 #endif
50         
51         if (fileStream.rdstate() & ofstream::failbit){
52                 return CALENDAROBJECTSAVE_CANNOTOPEN;
53         }
55         if (fileStream.rdstate() & ofstream::badbit){
56                 return CALENDAROBJECTSAVE_CANNOTOPEN;
57         }
58         
59         // Process the data into a string.
60         
61         CalendarObjectSaveResult saveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
62         string saveStringData;
63         
64         saveResult = SaveString(&saveStringData);
65         
66         //fileStream.write(saveStringData.c_str(), saveStringData.size());
67         
68         fileStream << saveStringData.c_str();
70         fileStream.close();
71         
72         return saveResult;
73         
74 }
76 CalendarObjectSaveResult CalendarObject::SaveString(string *saveStringData){
78         *saveStringData += "BEGIN:VCALENDAR\n";
79         *saveStringData += "VERSION:2.0\n";
80         
81         // Check if METHOD has a value and print it if it does (and
82         // any token data if there).
83         
84         if (methodData.size() > 0){
85                 
86                 if (methodTokens.size() > 0){
87                 
88                         *saveStringData += "METHOD;";
89                         *saveStringData += methodTokens;
90                         
91                 } else {
93                         *saveStringData += "METHOD";
94                         
95                 }
97                 *saveStringData += ":";
98                 *saveStringData += methodData;
99                 *saveStringData += "\n";
100                 
101         }
102         
103         // Check if CALSCALE has a value and print it if it does (and
104         // any token data if there).
105         
106         if (calendarScaleData.size() > 0){
107                 
108                 if (calendarScaleTokens.size() > 0){
109                 
110                         *saveStringData += "CALSCALE;";
111                         *saveStringData += calendarScaleTokens;
112                         
113                 } else {
115                         *saveStringData += "CALSCALE";
116                         
117                 }
119                 *saveStringData += ":";
120                 *saveStringData += calendarScaleData;
121                 *saveStringData += "\n";
122                 
123         }
124         
125 #if defined(XESTIACAL_UNITTEST)
126         
127         *saveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
128         
129 #else
131         *saveStringData += "PRODID:-//Xestia//Calendar Version ";
132         *saveStringData += XSDCAL_VERSION;
133         *saveStringData += "//KW\n";
134         
135 #endif
136         
137         SaveObjectData(saveStringData);
138         
139         *saveStringData += "END:VCALENDAR";
140         
141         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