Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code to process DESCRIPTION in CalendarTaskObject.
[xestiacalendar/.git] / source / objects / calendartask / CalendarTask.cpp
1 #include "CalendarTask.h"
3 using namespace std;
5 CalendarObjectValidResult CalendarTaskObject::ValidObject(){
7         bool ValidBegin = false;
8         bool ValidEnd = false;
9         bool ValidDateTimeStamp = false;
10         bool ValidUniqueID = false;
11         int SeekCount = 0;
12         string PropertyName;
13         
14         // Look for BEGIN:VTODO.
15         
16         for (vector<string>::iterator iter = ObjectName.begin();
17                 iter != ObjectName.end(); iter++){
18         
19                 if (ObjectName[SeekCount] == "BEGIN" &&
20                         ObjectData[SeekCount] == "VTODO"){
21                         
22                         if (ValidBegin == false){
23                                 ValidBegin = true;
24                         } else {
25                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
26                         }
27                                 
28                 }
29                 
30                 if (ObjectName[SeekCount] == "END" &&
31                         ObjectData[SeekCount] == "VTODO" &&
32                         ValidBegin == false){
33                 
34                         return CALENDAROBJECTVALID_INVALIDFORMAT;
35                                 
36                 }
37                 
38                 SeekCount++;
39                         
40         }
41         
42         SeekCount = 0;
43         
44         // Look for DTSTAMP.
45         
46         for (vector<string>::iterator iter = ObjectName.begin();
47                 iter != ObjectName.end(); iter++){
48                         
49                 try{
50                         PropertyName = ObjectName[SeekCount].substr(0,7);
51                 }
52                         
53                 catch(const out_of_range& oor){
54                         continue;
55                 }
56                 
57                 if (PropertyName == "DTSTAMP"){
58                         
59                         if (ValidDateTimeStamp == false){
60                                 ValidDateTimeStamp = true;
61                         } else {
62                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
63                         }
64                                 
65                 }
66                         
67                 SeekCount++;
69         }
70         
71         SeekCount = 0;
72         
73         // Look for UID.
74         
75         for (vector<string>::iterator iter = ObjectName.begin();
76                 iter != ObjectName.end(); iter++){
77         
78                 try{
79                         PropertyName = ObjectName[SeekCount].substr(0,3);
80                 }
81                 
82                 catch(const out_of_range& oor){
83                         continue;
84                 }
85                         
86                 if (PropertyName == "UID"){
87                         
88                         if (ValidUniqueID == false){
89                                 ValidUniqueID = true;
90                         } else {
91                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
92                         }
93                                 
94                 }
95                         
96                 SeekCount++;
97                         
98         }
99         
100         SeekCount = 0;
101                 
102         // Look for END:VTODO.
103         
104         for (vector<string>::iterator iter = ObjectName.begin();
105                 iter != ObjectName.end(); iter++){
106         
107                 if (ObjectName[SeekCount] == "END" &&
108                         ObjectData[SeekCount] == "VTODO"){
109                         
110                         if (ValidEnd == false){
111                                 ValidEnd = true;
112                         } else {
113                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
114                         }
115                                 
116                 }
117                         
118                 SeekCount++;
119                         
120         }
121         
122         // Check if the VTODO is valid.
123         
124         if (ValidBegin == true && 
125                 ValidEnd == true && 
126                 ValidDateTimeStamp == true &&
127                 ValidUniqueID == true){
128                         
129                 return CALENDAROBJECTVALID_OK;
130                         
131         } else {
132                 
133                 return CALENDAROBJECTVALID_INVALIDFORMAT;
134                 
135         }
136         
139 void CalendarTaskObject::ProcessData(){
141         // Process the data.
142         
143         multimap<string,string> DataReceived;
144         map<string,string> PropertyData;
145         string *PropertyNameData = nullptr;
146         int ObjectSeekCount = 0;
147         
148         // Get the Date Time Stamp (DTSTAMP).
149         
150         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTAMP");
151         
152         // Process the data from DTSTAMP.
153         
154         if (DataReceived.begin() != DataReceived.end()){
155         
156                 try {
157                         DateTimeStampTokens = DataReceived.begin()->first.substr(8);
158                 }
159                 
160                 catch(const out_of_range &oor){
161                         // Do nothing as there is no data.
162                 }               
163                 
164                 DateTimeStampData = DataReceived.begin()->second;
165                 
166         }
167         
168         // Get the Unique ID (UID).
169         
170         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "UID");
171         
172         // Process the data from UID.
173         
174         if (DataReceived.begin() != DataReceived.end()){
175         
176                 try {
177                         UniqueIDTokens = DataReceived.begin()->first.substr(4);
178                 }
179                 
180                 catch(const out_of_range &oor){
181                         // Do nothing as there is no data.
182                 }               
183                 
184                 UniqueID = DataReceived.begin()->second;
185                 
186         }
187         
188         // Process the data from CLASS.
189         
190         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CLASS");
191         
192         if (DataReceived.begin() != DataReceived.end()){
193         
194                 try {
195                         ClassDataTokens = DataReceived.begin()->first.substr(6);
196                 }
197                 
198                 catch(const out_of_range &oor){
199                         // Do nothing as there is no data.
200                 }               
201                 
202                 ClassData = DataReceived.begin()->second;
203                 
204         }
205         
206         // Process the data from COMPLETED.
207         
208         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "COMPLETED");
209         
210         if (DataReceived.begin() != DataReceived.end()){
211         
212                 try {
213                         CompletedDataTokens = DataReceived.begin()->first.substr(10);
214                 }
215                 
216                 catch(const out_of_range &oor){
217                         // Do nothing as there is no data.
218                 }               
219                 
220                 CompletedData = DataReceived.begin()->second;
221                 
222         }
223         
224         // Process the data from CREATED.
225         
226         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CREATED");
227         
228         if (DataReceived.begin() != DataReceived.end()){
229         
230                 try {
231                         DateTimeCreatedTokens = DataReceived.begin()->first.substr(8);
232                 }
233                 
234                 catch(const out_of_range &oor){
235                         // Do nothing as there is no data.
236                 }               
237                 
238                 DateTimeCreatedData = DataReceived.begin()->second;
239                 
240         }
241         
242         // Process the data from DESCRIPTION.
243         
244         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DESCRIPTION");
245         
246         if (DataReceived.begin() != DataReceived.end()){
247         
248                 bool TokenData = false;
249                 string PropertyTokens;
250                 
251                 PropertyNameData = (string*)&DataReceived.begin()->first;
252                 
253                 PropertyData = SplitValues(*PropertyNameData);
254                 
255                 for(map<string,string>::iterator iter = PropertyData.begin();
256                         iter != PropertyData.end(); iter++){
257                         
258                         if (iter->first == "ALTREP"){
259                                 
260                                 DescriptionListAltRep.clear();
261                                 DescriptionListAltRep.push_back(iter->second);
262                                 
263                         } else if (iter->first == "LANGUAGE"){
264                                 
265                                 DescriptionListLanguage.clear();
266                                 DescriptionListLanguage.push_back(iter->second);
267                                 
268                         } else {
269                                 
270                                 if (TokenData == false){
271                                         TokenData = true;
272                                 } else {
273                                         PropertyTokens += ";";
274                                 }
275                                 
276                                 PropertyTokens += iter->first;
277                                 PropertyTokens += "=";
278                                 PropertyTokens += iter->second;
279                                 
280                         }
281                                 
282                 }
283                 
284                 if (PropertyTokens.size() > 0){
285                         DescriptionListTokens.clear();
286                         DescriptionListTokens.push_back(PropertyTokens);
287                 }
288                 
289                 DescriptionList.clear();
290                 DescriptionList.push_back(DataReceived.begin()->second);
291                 
292         }
293         
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