From b0ad0f7c0c3c384040f069d0aa4111388e4b0add Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 30 May 2016 16:09:36 +0100 Subject: [PATCH] Work in progress for the SaveFile functions in the CalendarObject class Progress made on the SaveFile functions. Still work needed to be done to be able to write to the file. --- .../calendarobject/CalendarObject-Save.cpp | 89 ++++++++++++++++++- .../objects/calendarobject/CalendarObject.h | 2 + 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/source/objects/calendarobject/CalendarObject-Save.cpp b/source/objects/calendarobject/CalendarObject-Save.cpp index a104384..ba19b6f 100644 --- a/source/objects/calendarobject/CalendarObject-Save.cpp +++ b/source/objects/calendarobject/CalendarObject-Save.cpp @@ -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 diff --git a/source/objects/calendarobject/CalendarObject.h b/source/objects/calendarobject/CalendarObject.h index 7ec9f4c..15792eb 100644 --- a/source/objects/calendarobject/CalendarObject.h +++ b/source/objects/calendarobject/CalendarObject.h @@ -10,6 +10,7 @@ #include #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{ -- 2.39.5