Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated/Added copyright header and licensing to all source files
[xestiacalendar/.git] / source / objects / calendarobject / CalendarObject.cpp
index d3c6f14..5a15e1d 100644 (file)
@@ -1,3 +1,21 @@
+// CalendarObject.cpp - CalendarObject class functions
+//
+// (c) 2016-2017 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Calendar is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Calendar is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
+
 #include "CalendarObject.h"
 #include "../../common/file.h"
 
@@ -52,6 +70,7 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
        bool NewLine = false;
        bool SkipMode = false;
        bool ColonFound = false;
+       bool QuoteMode = false;
        char BufferChar = 0;
        int StringDataSize = LoadStringData->size();
        int SeekCount = 0;
@@ -73,6 +92,22 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
 
                        NewLine = false;
                                
+               } else if ((*LoadStringData)[SeekCount] == '\"'){
+                       
+                       if (QuoteMode == false){
+                               QuoteMode = true;
+                       } else {
+                               QuoteMode = false;
+                       }
+                       
+                       BufferChar = (*LoadStringData)[SeekCount];
+                       
+                       if (ColonFound == false){
+                               PropertyName += BufferChar;
+                       } else {
+                               PropertyValue += BufferChar;
+                       }
+                       
                } else if (NewLine == true){
                
                        // Character is on a new line but not a space or
@@ -81,8 +116,8 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
                        // the lists.
 
                        if (ColonFound == true){
-                               ObjectName.insert(ObjectName.end(), PropertyName);
-                               ObjectData.insert(ObjectData.end(), PropertyValue);
+                               ObjectName.push_back(PropertyName);
+                               ObjectData.push_back(PropertyValue);
                        }
                        
                        ColonFound = false;
@@ -100,12 +135,19 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
                        
                        NewLine = true;
                        
-               } else if ((*LoadStringData)[SeekCount] == ':'){
+               } else if ((*LoadStringData)[SeekCount] == ':' &&
+                               QuoteMode == false){
                
                        // Character is the colon. Set the colon
                        // found boolen to true.
                        
-                       ColonFound = true;
+                       BufferChar = (*LoadStringData)[SeekCount];
+                                       
+                       if (ColonFound == true){
+                               PropertyValue += BufferChar;
+                       } else {
+                               ColonFound = true;
+                       }
                        
                } else {
                        
@@ -133,8 +175,8 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
                PropertyName.size() > 0 &&
                PropertyValue.size() > 0){
                
-               ObjectName.insert(ObjectName.end(), PropertyName);
-               ObjectData.insert(ObjectData.end(), PropertyValue);
+               ObjectName.push_back(PropertyName);
+               ObjectData.push_back(PropertyValue);
                        
        }
        
@@ -165,9 +207,13 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData)
 CalendarObjectValidResult CalendarObject::ValidBaseObject(){
        
        bool ValidBegin = false;
+       bool ValidAlarmBegin = false;
        bool ValidVersion = false;
        bool ValidEnd = false;
        int SeekCount = 0;
+       vector<int> DeleteLines;
+       vector<string> AlarmObjectName;
+       vector<string> AlarmObjectData;
        
        // Check that the first line contains BEGIN:VCALENDAR
        // and it only appears once.
@@ -192,6 +238,58 @@ CalendarObjectValidResult CalendarObject::ValidBaseObject(){
                
                        return CALENDAROBJECTVALID_INVALIDFORMAT;
                                
+               } else if (ObjectName[SeekCount] == "END" &&
+                       ObjectData[SeekCount] == "VALARM" &&
+                       ValidAlarmBegin == false){
+
+                       return CALENDAROBJECTVALID_INVALIDFORMAT;
+                               
+               } else if (ObjectName[SeekCount] == "END" &&
+                       ObjectData[SeekCount] == "VCALENDAR" &&
+                       ValidAlarmBegin == true){
+
+                       return CALENDAROBJECTVALID_INVALIDFORMAT;
+                               
+               }
+               
+               // Look for any VALARM sections.
+               
+               if (ValidAlarmBegin == true){
+                       
+                       AlarmObjectName.push_back(ObjectName[SeekCount]);
+                       AlarmObjectData.push_back(ObjectData[SeekCount]);
+                       DeleteLines.push_back(SeekCount);
+                       
+               }
+               
+               if (ObjectName[SeekCount] == "END" &&
+                       ObjectData[SeekCount] == "VALARM" && 
+                       ValidAlarmBegin == true){
+                               
+                       EventAlarmName.push_back(AlarmObjectName);
+                       EventAlarmData.push_back(AlarmObjectData);
+                       
+                       AlarmObjectName.clear();
+                       AlarmObjectData.clear();
+
+                       ValidAlarmBegin = false;
+                               
+               }
+               
+               if (ObjectName[SeekCount] == "BEGIN" &&
+                       ObjectData[SeekCount] == "VALARM" && 
+                       ValidBegin == true){
+                               
+                       if (ValidAlarmBegin == false){
+                               ValidAlarmBegin = true;
+                       } else {
+                               return CALENDAROBJECTVALID_INVALIDFORMAT;
+                       }
+                       
+                       AlarmObjectName.push_back(ObjectName[SeekCount]);
+                       AlarmObjectData.push_back(ObjectData[SeekCount]);
+                       DeleteLines.push_back(SeekCount);
+                       
                }
                
                SeekCount++;
@@ -244,10 +342,22 @@ CalendarObjectValidResult CalendarObject::ValidBaseObject(){
                        
        }
 
+       // Remove lines that aren't needed as they have
+       // been moved to the EventAlarm section.
+       
+       for (vector<int>::reverse_iterator deliter = DeleteLines.rbegin();
+               deliter != DeleteLines.rend(); deliter++){
+
+               ObjectName.erase(ObjectName.begin()+(*deliter));
+               ObjectData.erase(ObjectData.begin()+(*deliter));
+                       
+       }
+
        if (ValidBegin == true && 
                ValidEnd == true && 
-               ValidVersion == true){
-               
+               ValidVersion == true &&
+               ValidAlarmBegin == false){
+       
                return CALENDAROBJECTVALID_OK;
                        
        } else {
@@ -282,7 +392,7 @@ void CalendarObject::ProcessBaseData(){
                
        }
        
-       // Get the method (CALSCALE).
+       // Get the calendar scale (CALSCALE).
        
        DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CALSCALE");
        
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