This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathicalendar.h
executable file
·103 lines (87 loc) · 2.43 KB
/
icalendar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef _ICALENDAR_H
#define _ICALENDAR_H
#include <fstream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include "types.h"
using namespace std;
class ICalendar {
public:
ICalendar(const char *FileName): FileName((char *)FileName) { LoadFromFile(); }
~ICalendar() {
for_each(Events.begin(), Events.end(), DeleteItem());
}
void LoadFromFile();
//Event* GetEventByUID(char *UID);
void AddEvent(Event *NewEvent);
void DeleteEvent(Event *DeletedEvent);
void ModifyEvent(Event *ModifiedEvent);
class Query;
private:
string GetProperty(const string &Line) const {
// if VALUE=DATE or VALUE=DATE-TIME used, then the date is not directly
// after the property name so we just search for the string after ':'
string Temp = Line.substr(Line.find_first_of(':')+1);
unsigned int Length = Temp.length();
if (Length > 0 && Temp[Length-1] == '\r')
Temp.resize(Length-1);
return Temp;
}
string GetSubProperty(const string &Line, const char *SubProperty) const {
size_t Pos = Line.find(SubProperty);
if (Pos == string::npos)
return "";
Pos += strlen(SubProperty) + 1;
return Line.substr(Pos, Line.find_first_of(";\r", Pos)-Pos);
}
void FixLineEnd(string &Line, unsigned int Length) {
if (Length > 0 && Line[Length-1] == '\r')
Line.resize(Length-1);
Line += "\r\n";
}
char *FileName;
list<Event *> Events;
};
class ICalendar::Query {
public:
Query(ICalendar *Calendar): Calendar(Calendar), EventsIterator(Calendar->Events.begin()) {}
~Query() { for_each(RecurrentEvents.begin(), RecurrentEvents.end(), DeleteItem()); }
void ResetPosition() {
for_each(RecurrentEvents.begin(), RecurrentEvents.end(), DeleteItem());
RecurrentEvents.clear();
EventsIterator = Calendar->Events.begin();
}
Event* GetNextEvent(bool WithAlarm = false);
EventsCriteria Criteria;
private:
ICalendar *Calendar;
list<Event *> RecurrentEvents;
list<Event *>::iterator EventsIterator;
};
inline TimeUnit ConvertFrequency(string Name) {
if (Name == "SECONDLY")
return SECOND;
if (Name == "MINUTELY")
return MINUTE;
if (Name == "HOURLY")
return HOUR;
if (Name == "DAILY")
return DAY;
if (Name == "WEEKLY")
return WEEK;
if (Name == "MONTHLY")
return MONTH;
return YEAR;
}
inline AlarmAction ConvertAlarmAction(string Name) {
if (Name == "AUDIO")
return AUDIO;
if (Name == "PROCEDURE")
return PROCEDURE;
if (Name == "EMAIL")
return EMAIL;
return DISPLAY;
}
#endif // _ICALENDAR_H