Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Version 0.08 release
[xestiacalendar/.git] / objects / calendarobject / CalendarObject-Save.cpp
1 #include "CalendarObject.h"
2 #include "../../common/file.h"
4 using namespace std;
6 CalendarObjectSaveResult CalendarObject::SaveFile(string SaveFilename){
8         ofstream FileStream;
9         string ReceivedStringData = "";
10         
11         // Open the file.
12         
13         FileStream.open(SaveFilename, ofstream::out);
14         
15         if (FileStream.rdstate() & ofstream::failbit){
16                 return CALENDAROBJECTSAVE_CANNOTOPEN;
17         }
19         if (FileStream.rdstate() & ofstream::badbit){
20                 return CALENDAROBJECTSAVE_CANNOTOPEN;
21         }
22         
23         FileStream.close();
24         
25         // Process the data into a string.
26         
27         CalendarObjectSaveResult SaveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
28         string SaveStringData;
29         
30         SaveResult = SaveString(&SaveStringData);
31         
32         return SaveResult;
33         
34 }
36 CalendarObjectSaveResult CalendarObject::SaveString(string *SaveStringData){
38         *SaveStringData += "BEGIN:VCALENDAR\n";
39         *SaveStringData += "VERSION:2.0\n";
40         
41         // Check if METHOD has a value and print it if it does (and
42         // any token data if there).
43         
44         if (MethodData.size() > 0){
45                 
46                 if (MethodTokens.size() > 0){
47                 
48                         *SaveStringData += "METHOD;";
49                         *SaveStringData += MethodTokens;
50                         
51                 } else {
53                         *SaveStringData += "METHOD";
54                         
55                 }
57                 *SaveStringData += ":";
58                 *SaveStringData += MethodData;
59                 *SaveStringData += "\n";
60                 
61         }
62         
63         // Check if CALSCALE has a value and print it if it does (and
64         // any token data if there).
65         
66         if (CalendarScaleData.size() > 0){
67                 
68                 if (CalendarScaleTokens.size() > 0){
69                 
70                         *SaveStringData += "CALSCALE;";
71                         *SaveStringData += CalendarScaleTokens;
72                         
73                 } else {
75                         *SaveStringData += "CALSCALE";
76                         
77                 }
79                 *SaveStringData += ":";
80                 *SaveStringData += CalendarScaleData;
81                 *SaveStringData += "\n";
82                 
83         }
84         
85 #if defined(XESTIACAL_UNITTEST)
86         
87         *SaveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
88         
89 #else
91         *SaveStringData += "PRODID:-//Xestia//Calendar Version ";
92         *SaveStringData += XSDCAL_VERSION;
93         *SaveStringData += "\n";
94         
95 #endif
96         
97         SaveObjectData(SaveStringData);
98         
99         *SaveStringData += "END:VCALENDAR";
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