Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Work in progress for the SaveFile functions in the CalendarObject class
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 30 May 2016 15:09:36 +0000 (16:09 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Mon, 30 May 2016 15:09:36 +0000 (16:09 +0100)
Progress made on the SaveFile functions. Still work needed to be done to
be able to write to the file.

source/objects/calendarobject/CalendarObject-Save.cpp
source/objects/calendarobject/CalendarObject.h

index a104384..ba19b6f 100644 (file)
@@ -3,14 +3,99 @@
 
 using namespace std;
 
-CalendarObjectSaveResult CalendarObject::SaveString(string *SaveStringData){
+CalendarObjectSaveResult CalendarObject::SaveFile(string SaveFilename){
 
+       ofstream FileStream;
+       string ReceivedStringData = "";
+       
+       // Open the file.
+       
+       FileStream.open(SaveFilename, ofstream::out);
        
+       if (FileStream.rdstate() & ofstream::failbit){
+               return CALENDAROBJECTSAVE_CANNOTOPEN;
+       }
 
+       if (FileStream.rdstate() & ofstream::badbit){
+               return CALENDAROBJECTSAVE_CANNOTOPEN;
+       }
+       
+       FileStream.close();
+       
+       // Process the data into a string.
+       
+       CalendarObjectSaveResult SaveResult = CALENDAROBJECTSAVE_UNITTESTFAIL;
+       string SaveStringData;
+       
+       SaveResult = SaveString(&SaveStringData);
+       
+       return SaveResult;
+       
 }
 
-CalendarObjectSaveResult CalendarObject::SaveFile(string SaveFilename){
+CalendarObjectSaveResult CalendarObject::SaveString(string *SaveStringData){
+
+       *SaveStringData += "BEGIN:VCARD\n";
+       *SaveStringData += "VERSION:2.0\n";
+       
+       // Check if METHOD has a value and print it if it does (and
+       // any token data if there).
+       
+       if (MethodData.size() > 0){
+               
+               if (MethodTokens.size() > 0){
+               
+                       *SaveStringData += "METHOD;";
+                       *SaveStringData += MethodTokens;
+                       
+               } else {
+
+                       *SaveStringData += "METHOD";
+                       
+               }
+
+               *SaveStringData += ":";
+               *SaveStringData += MethodData;
+               *SaveStringData += "\n";
+               
+       }
+       
+       // Check if CALSCALE has a value and print it if it does (and
+       // any token data if there).
+       
+       if (CalendarScaleData.size() > 0){
+               
+               if (CalendarScaleTokens.size() > 0){
+               
+                       *SaveStringData += "CALSCALE;";
+                       *SaveStringData += CalendarScaleTokens;
+                       
+               } else {
+
+                       *SaveStringData += "CALSCALE";
+                       
+               }
 
+               *SaveStringData += ":";
+               *SaveStringData += CalendarScaleData;
+               *SaveStringData += "\n";
+               
+       }
+       
+#if defined(XESTIACAL_UNITTEST)
+       
+       *SaveStringData += "PRODID:-//Xestia//Calendar Unit Testing//KW\n";
+       
+#else
+
+       *SaveStringData += "PRODID:-//Xestia//Calendar Version ";
+       *SaveStringData += XSDCAL_VERSION;
+       *SaveStringData += "\n";
+       
+#endif
+       
+       SaveObjectData(SaveStringData);
        
+       *SaveStringData += "END:VCARD";
 
 }
\ No newline at end of file
index 7ec9f4c..15792eb 100644 (file)
@@ -10,6 +10,7 @@
 #include <map>
 
 #include "../../common/text.h"
+#include "../../version.h"
 
 using namespace std;
 
@@ -24,6 +25,7 @@ enum CalendarObjectLoadResult {
 enum CalendarObjectSaveResult {
        CALENDAROBJECTSAVE_UNITTESTFAIL = -1,
        CALENDAROBJECTSAVE_OK,
+       CALENDAROBJECTSAVE_CANNOTOPEN
 };
 
 enum CalendarObjectValidResult{
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