Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code to process RECURRENCE-ID 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         
294         // Get the Date Time Start value.
295         
296         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "DTSTART");
297         
298         // Process the data from DTSTART.
299         
300         if (DataReceived.begin() != DataReceived.end()){
301         
302                 bool TokenData = false;
303                 string PropertyTokens;
304                 
305                 PropertyNameData = (string*)&DataReceived.begin()->first;
306                 
307                 PropertyData = SplitValues(*PropertyNameData);
308                 
309                 for(map<string,string>::iterator iter = PropertyData.begin();
310                         iter != PropertyData.end(); iter++){
311                         
312                         if (iter->first == "VALUE"){
313                                 
314                                 DateTimeStartDataValue = iter->second;
315                                 
316                         } else if (iter->first == "TZID"){
317                                 
318                                 DateTimeStartDataTimeZoneID = iter->second;
319                                 
320                         } else {
321                                 
322                                 if (TokenData == false){
323                                         TokenData = true;
324                                 } else {
325                                         PropertyTokens += ";";
326                                 }
327                                 
328                                 PropertyTokens += iter->first;
329                                 PropertyTokens += "=";
330                                 PropertyTokens += iter->second;
331                                 
332                         }
333                                 
334                 }
335                 
336                 if (PropertyTokens.size() > 0){
337                         DateTimeStartDataTokens = PropertyTokens;
338                 }
339                 
340                 DateTimeStartData = DataReceived.begin()->second;
341                 
342         }
343         
344         // Process the data from GEO.
345         
346         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "GEO");
347         
348         if (DataReceived.begin() != DataReceived.end()){
349         
350                 try {
351                         GeographicTokens = DataReceived.begin()->first.substr(4);
352                 }
353                 
354                 catch(const out_of_range &oor){
355                         // Do nothing as there is no data.
356                 }               
357                 
358                 GeographicData = DataReceived.begin()->second;
359                 
360         }
361         
362         // Process the data from LAST-MODIFIED.
363         
364         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LAST-MODIFIED");
365         
366         if (DataReceived.begin() != DataReceived.end()){
367         
368                 try {
369                         LastModifiedTokens = DataReceived.begin()->first.substr(14);
370                 }
371                 
372                 catch(const out_of_range &oor){
373                         // Do nothing as there is no data.
374                 }               
375                 
376                 LastModifiedData = DataReceived.begin()->second;
377                 
378         }
379         
380         // Process the data from LOCATION.
381         
382         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LOCATION");
383         
384         if (DataReceived.begin() != DataReceived.end()){
385         
386                 bool TokenData = false;
387                 string PropertyTokens;
388                 
389                 PropertyNameData = (string*)&DataReceived.begin()->first;
390                 
391                 PropertyData = SplitValues(*PropertyNameData);
392                 
393                 for(map<string,string>::iterator iter = PropertyData.begin();
394                         iter != PropertyData.end(); iter++){
395                         
396                         if (iter->first == "ALTREP"){
397                                 
398                                 LocationDataAltRep = iter->second;
399                                 
400                         } else if (iter->first == "LANGUAGE"){
401                                 
402                                 LocationDataLanguage = iter->second;
403                                 
404                         } else {
405                                 
406                                 if (TokenData == false){
407                                         TokenData = true;
408                                 } else {
409                                         PropertyTokens += ";";
410                                 }
411                                 
412                                 PropertyTokens += iter->first;
413                                 PropertyTokens += "=";
414                                 PropertyTokens += iter->second;
415                                 
416                         }
417                                 
418                 }
419                 
420                 if (PropertyTokens.size() > 0){
421                         
422                         LocationDataTokens = PropertyTokens;
423                         
424                 }
425                 
426                 LocationData = DataReceived.begin()->second;
427                 
428         }
429         
430         // Process the data from ORGANIZER.
431         
432         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "ORGANIZER");
433         
434         if (DataReceived.begin() != DataReceived.end()){
435         
436                 bool TokenData = false;
437                 string PropertyTokens;
438                 
439                 PropertyNameData = (string*)&DataReceived.begin()->first;
440                 
441                 PropertyData = SplitValues(*PropertyNameData);
442                 
443                 for(map<string,string>::iterator iter = PropertyData.begin();
444                         iter != PropertyData.end(); iter++){
445                         
446                         if (iter->first == "CN"){
447                                 
448                                 OrganiserDataCommonName = iter->second;
449                                 
450                         } else if (iter->first == "DIR"){
451                                 
452                                 OrganiserDataDirectoryEntry = iter->second;
453                                 
454                         } else if (iter->first == "SENT-BY"){
455                                 
456                                 OrganiserDataSentByParam = iter->second;
457                                 
458                         } else if (iter->first == "LANGUAGE"){
459                                 
460                                 OrganiserDataLanguage = iter->second;
461                                 
462                         } else {
463                                 
464                                 if (TokenData == false){
465                                         TokenData = true;
466                                 } else {
467                                         PropertyTokens += ";";
468                                 }
469                                 
470                                 PropertyTokens += iter->first;
471                                 PropertyTokens += "=";
472                                 PropertyTokens += iter->second;
473                                 
474                         }
475                                 
476                 }
477                 
478                 if (PropertyTokens.size() > 0){
479                         
480                         OrganiserDataTokens = PropertyTokens;
481                         
482                 }
483                 
484                 OrganiserData = DataReceived.begin()->second;
485                 
486         }
487         
488         // Process the data from PERCENT-COMPLETE.
489         
490         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "PERCENT-COMPLETE");
491         
492         if (DataReceived.begin() != DataReceived.end()){
493         
494                 try {
495                         PercentCompleteTokens = DataReceived.begin()->first.substr(17);
496                 }
497                 
498                 catch(const out_of_range &oor){
499                         // Do nothing as there is no data.
500                 }
501                 
502                 PercentCompleteData = DataReceived.begin()->second;
503                 
504         }
505         
506         // Process the data from PRIORITY.
507         
508         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "PRIORITY");
509         
510         if (DataReceived.begin() != DataReceived.end()){
511         
512                 try {
513                         PriorityTokens = DataReceived.begin()->first.substr(9);
514                 }
515                 
516                 catch(const out_of_range &oor){
517                         // Do nothing as there is no data.
518                 }               
519                 
520                 try {
521                         PriorityData = stoi(DataReceived.begin()->second);
522                 }
523                 
524                 catch(const invalid_argument &oor){
525                         PriorityTokens.clear();
526                 }
527                 
528         }
529         
530         // Process the data from RECURRENCE-ID.
531         
532         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "RECURRENCE-ID");
533         
534         if (DataReceived.begin() != DataReceived.end()){
535         
536                 bool TokenData = false;
537                 string PropertyTokens;
538                 
539                 PropertyNameData = (string*)&DataReceived.begin()->first;
540                 
541                 PropertyData = SplitValues(*PropertyNameData);
542                 
543                 for(map<string,string>::iterator iter = PropertyData.begin();
544                         iter != PropertyData.end(); iter++){
545                         
546                         if (iter->first == "TZID"){
547                                 
548                                 RecurranceIDDataTimeZoneParam = iter->second;
549                                 
550                         } else if (iter->first == "VALUE"){
551                                 
552                                 RecurranceIDDataValue = iter->second;
553                                 
554                         } else if (iter->first == "RANGE"){
555                                 
556                                 RecurranceIDDataRangeParam = iter->second;
557                                 
558                         } else {
559                                 
560                                 if (TokenData == false){
561                                         TokenData = true;
562                                 } else {
563                                         PropertyTokens += ";";
564                                 }
565                                 
566                                 PropertyTokens += iter->first;
567                                 PropertyTokens += "=";
568                                 PropertyTokens += iter->second;
569                                 
570                         }
571                                 
572                 }
573                 
574                 if (PropertyTokens.size() > 0){
575                         
576                         RecurranceIDDataTokens = PropertyTokens;
577                         
578                 }
579                 
580                 RecurranceIDData = DataReceived.begin()->second;
581                 
582         }
583         
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