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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
#include "calendarevent.h"
#include <QSettings>
#include <QFile>
#include <QTimeZone>
CalendarEvent::CalendarEvent():
m_uuid(QUuid::createUuid())
{
}
bool CalendarEvent::isValid() const
{
return !m_id.isNull();
}
QString CalendarEvent::id() const
{
return m_id;
}
void CalendarEvent::setId(const QString &id)
{
m_id = id;
}
QUuid CalendarEvent::uuid() const
{
return m_uuid;
}
void CalendarEvent::generateNewUuid()
{
m_uuid = QUuid::createUuid();
}
QString CalendarEvent::title() const
{
return m_title;
}
void CalendarEvent::setTitle(const QString &title)
{
m_title = title;
}
QString CalendarEvent::description() const
{
return m_description;
}
void CalendarEvent::setDescription(const QString &description)
{
m_description = description;
}
QDateTime CalendarEvent::startTime() const
{
return m_startTime;
}
void CalendarEvent::setStartTime(const QDateTime &startTime)
{
m_startTime = startTime;
}
QDateTime CalendarEvent::endTime() const
{
return m_endTime;
}
void CalendarEvent::setEndTime(const QDateTime &endTime)
{
m_endTime = endTime;
}
QString CalendarEvent::location() const
{
return m_location;
}
void CalendarEvent::setLocation(const QString &location)
{
m_location = location;
}
QString CalendarEvent::calendar() const
{
return m_calendar;
}
void CalendarEvent::setCalendar(const QString &calendar)
{
m_calendar = calendar;
}
QString CalendarEvent::comment() const
{
return m_comment;
}
void CalendarEvent::setComment(const QString &comment)
{
m_comment = comment;
}
QStringList CalendarEvent::guests() const
{
return m_guests;
}
void CalendarEvent::setGuests(const QStringList &guests)
{
m_guests = guests;
}
bool CalendarEvent::recurring() const
{
return m_recurring;
}
void CalendarEvent::setRecurring(bool recurring)
{
m_recurring = recurring;
}
bool CalendarEvent::operator==(const CalendarEvent &other) const
{
// Storing a QDateTime to QSettings seems to lose time zone information. Lets ignore the time zone when
// comparing or we'll never find ourselves again.
QDateTime thisStartTime = m_startTime;
thisStartTime.setTimeZone(other.startTime().timeZone());
QDateTime thisEndTime = m_endTime;
thisEndTime.setTimeZone(other.endTime().timeZone());
return m_id == other.id()
&& m_title == other.title()
&& m_description == other.description()
&& thisStartTime == other.startTime()
&& thisEndTime == other.endTime()
&& m_location == other.location()
&& m_calendar == other.calendar()
&& m_comment == other.comment()
&& m_guests == other.guests()
&& m_recurring == other.recurring();
}
void CalendarEvent::saveToCache(const QString &cachePath) const
{
QSettings s(cachePath + "/calendarevent-" + m_uuid.toString(), QSettings::IniFormat);
s.setValue("id", m_id);
s.setValue("uuid", m_uuid);
s.setValue("title", m_title);
s.setValue("description", m_description);
s.setValue("startTime", m_startTime);
s.setValue("endTime", m_endTime);
s.setValue("location", m_location);
s.setValue("calendar", m_calendar);
s.setValue("comment", m_comment);
s.setValue("guests", m_guests);
s.setValue("recurring", m_recurring);
}
void CalendarEvent::loadFromCache(const QString &cachePath, const QString &uuid)
{
m_uuid = uuid;
QSettings s(cachePath + "/calendarevent-" + m_uuid.toString(), QSettings::IniFormat);
m_id = s.value("id").toString();
m_title = s.value("title").toString();
m_description = s.value("description").toString();
m_startTime = s.value("startTime").toDateTime();
m_endTime = s.value("endTime").toDateTime();
m_location = s.value("location").toString();
m_calendar = s.value("calendar").toString();
m_comment = s.value("comment").toString();
m_guests = s.value("guests").toStringList();
m_recurring = s.value("recurring").toBool();
}
void CalendarEvent::removeFromCache(const QString &cachePath) const
{
QFile::remove(cachePath + "/calendarevent-" + m_uuid.toString());
}
|