author | zautrix <zautrix> | 2004-12-07 09:55:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-12-07 09:55:57 (UTC) |
commit | 17b25691f0332e648dd1d800e89ccf4e1da8955d (patch) (unidiff) | |
tree | b7bc28e6c57c043fc49328a7ebd86e1b5cd0f17a /libkcal | |
parent | dcd2bbbc8d3064b35f268a831c567feaafea5fd8 (diff) | |
download | kdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.zip kdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.tar.gz kdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.tar.bz2 |
some kopi usebility fixes
-rw-r--r-- | libkcal/calendar.cpp | 11 | ||||
-rw-r--r-- | libkcal/calendar.h | 3 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 17 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 14 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
5 files changed, 39 insertions, 7 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 52daaaa..88351eb 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,457 +1,466 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | 33 | #include "syncdefines.h" |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | Calendar::Calendar() | 37 | Calendar::Calendar() |
38 | { | 38 | { |
39 | 39 | ||
40 | init(); | 40 | init(); |
41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); | 41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); |
42 | } | 42 | } |
43 | 43 | ||
44 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
45 | { | 45 | { |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | 55 | mUndoIncidence = 0; | |
56 | mModified = false; | 56 | mModified = false; |
57 | 57 | ||
58 | // Setup default filter, which does nothing | 58 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 59 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 60 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 61 | mFilter->setEnabled(false); |
62 | 62 | ||
63 | // initialize random numbers. This is a hack, and not | 63 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 64 | // even that good of one at that. |
65 | // srandom(time(0)); | 65 | // srandom(time(0)); |
66 | 66 | ||
67 | // user information... | 67 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 68 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 69 | setEmail(i18n("unknown@nowhere")); |
70 | 70 | ||
71 | #if 0 | 71 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 72 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 75 | extern long int timezone; |
76 | struct tm *now; | 76 | struct tm *now; |
77 | time_t curtime; | 77 | time_t curtime; |
78 | curtime = time(0); | 78 | curtime = time(0); |
79 | now = localtime(&curtime); | 79 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 80 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 81 | if (now->tm_isdst) |
82 | hourOff += 1; | 82 | hourOff += 1; |
83 | QString tzStr; | 83 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 84 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 85 | hourOff, |
86 | abs((timezone / 60) % 60)); | 86 | abs((timezone / 60) % 60)); |
87 | 87 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 88 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 89 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 90 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 91 | } else { |
92 | tzStr = tmpStr; | 92 | tzStr = tmpStr; |
93 | } | 93 | } |
94 | 94 | ||
95 | // if daylight savings has changed since last load time, we need | 95 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 96 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 97 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 98 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 99 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 101 | } |
102 | 102 | ||
103 | setTimeZone(tzStr); | 103 | setTimeZone(tzStr); |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | // KOPrefs::instance()->writeConfig(); | 106 | // KOPrefs::instance()->writeConfig(); |
107 | } | 107 | } |
108 | 108 | ||
109 | Calendar::~Calendar() | 109 | Calendar::~Calendar() |
110 | { | 110 | { |
111 | delete mDefaultFilter; | 111 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | ||
113 | delete mUndoIncidence; | ||
112 | } | 114 | } |
113 | 115 | ||
114 | const QString &Calendar::getOwner() const | 116 | const QString &Calendar::getOwner() const |
115 | { | 117 | { |
116 | return mOwner; | 118 | return mOwner; |
117 | } | 119 | } |
118 | 120 | ||
121 | bool Calendar::undoDeleteIncidence() | ||
122 | { | ||
123 | if (!mUndoIncidence) | ||
124 | return false; | ||
125 | addIncidence(mUndoIncidence); | ||
126 | mUndoIncidence = 0; | ||
127 | } | ||
119 | void Calendar::setOwner(const QString &os) | 128 | void Calendar::setOwner(const QString &os) |
120 | { | 129 | { |
121 | int i; | 130 | int i; |
122 | mOwner = os; | 131 | mOwner = os; |
123 | i = mOwner.find(','); | 132 | i = mOwner.find(','); |
124 | if (i != -1) | 133 | if (i != -1) |
125 | mOwner = mOwner.left(i); | 134 | mOwner = mOwner.left(i); |
126 | 135 | ||
127 | setModified( true ); | 136 | setModified( true ); |
128 | } | 137 | } |
129 | 138 | ||
130 | void Calendar::setTimeZone(const QString & tz) | 139 | void Calendar::setTimeZone(const QString & tz) |
131 | { | 140 | { |
132 | bool neg = FALSE; | 141 | bool neg = FALSE; |
133 | int hours, minutes; | 142 | int hours, minutes; |
134 | QString tmpStr(tz); | 143 | QString tmpStr(tz); |
135 | 144 | ||
136 | if (tmpStr.left(1) == "-") | 145 | if (tmpStr.left(1) == "-") |
137 | neg = TRUE; | 146 | neg = TRUE; |
138 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 147 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
139 | tmpStr.remove(0, 1); | 148 | tmpStr.remove(0, 1); |
140 | hours = tmpStr.left(2).toInt(); | 149 | hours = tmpStr.left(2).toInt(); |
141 | if (tmpStr.length() > 2) | 150 | if (tmpStr.length() > 2) |
142 | minutes = tmpStr.right(2).toInt(); | 151 | minutes = tmpStr.right(2).toInt(); |
143 | else | 152 | else |
144 | minutes = 0; | 153 | minutes = 0; |
145 | mTimeZone = (60*hours+minutes); | 154 | mTimeZone = (60*hours+minutes); |
146 | if (neg) | 155 | if (neg) |
147 | mTimeZone = -mTimeZone; | 156 | mTimeZone = -mTimeZone; |
148 | mLocalTime = false; | 157 | mLocalTime = false; |
149 | 158 | ||
150 | setModified( true ); | 159 | setModified( true ); |
151 | } | 160 | } |
152 | 161 | ||
153 | QString Calendar::getTimeZoneStr() const | 162 | QString Calendar::getTimeZoneStr() const |
154 | { | 163 | { |
155 | if (mLocalTime) | 164 | if (mLocalTime) |
156 | return ""; | 165 | return ""; |
157 | QString tmpStr; | 166 | QString tmpStr; |
158 | int hours = abs(mTimeZone / 60); | 167 | int hours = abs(mTimeZone / 60); |
159 | int minutes = abs(mTimeZone % 60); | 168 | int minutes = abs(mTimeZone % 60); |
160 | bool neg = mTimeZone < 0; | 169 | bool neg = mTimeZone < 0; |
161 | 170 | ||
162 | tmpStr.sprintf("%c%.2d%.2d", | 171 | tmpStr.sprintf("%c%.2d%.2d", |
163 | (neg ? '-' : '+'), | 172 | (neg ? '-' : '+'), |
164 | hours, minutes); | 173 | hours, minutes); |
165 | return tmpStr; | 174 | return tmpStr; |
166 | } | 175 | } |
167 | 176 | ||
168 | void Calendar::setTimeZone(int tz) | 177 | void Calendar::setTimeZone(int tz) |
169 | { | 178 | { |
170 | mTimeZone = tz; | 179 | mTimeZone = tz; |
171 | mLocalTime = false; | 180 | mLocalTime = false; |
172 | 181 | ||
173 | setModified( true ); | 182 | setModified( true ); |
174 | } | 183 | } |
175 | 184 | ||
176 | int Calendar::getTimeZone() const | 185 | int Calendar::getTimeZone() const |
177 | { | 186 | { |
178 | return mTimeZone; | 187 | return mTimeZone; |
179 | } | 188 | } |
180 | 189 | ||
181 | void Calendar::setTimeZoneId(const QString &id) | 190 | void Calendar::setTimeZoneId(const QString &id) |
182 | { | 191 | { |
183 | mTimeZoneId = id; | 192 | mTimeZoneId = id; |
184 | mLocalTime = false; | 193 | mLocalTime = false; |
185 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 194 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
186 | if ( mTimeZone > 1000) | 195 | if ( mTimeZone > 1000) |
187 | setLocalTime(); | 196 | setLocalTime(); |
188 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 197 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
189 | setModified( true ); | 198 | setModified( true ); |
190 | } | 199 | } |
191 | 200 | ||
192 | QString Calendar::timeZoneId() const | 201 | QString Calendar::timeZoneId() const |
193 | { | 202 | { |
194 | return mTimeZoneId; | 203 | return mTimeZoneId; |
195 | } | 204 | } |
196 | 205 | ||
197 | void Calendar::setLocalTime() | 206 | void Calendar::setLocalTime() |
198 | { | 207 | { |
199 | //qDebug("Calendar::setLocalTime() "); | 208 | //qDebug("Calendar::setLocalTime() "); |
200 | mLocalTime = true; | 209 | mLocalTime = true; |
201 | mTimeZone = 0; | 210 | mTimeZone = 0; |
202 | mTimeZoneId = ""; | 211 | mTimeZoneId = ""; |
203 | 212 | ||
204 | setModified( true ); | 213 | setModified( true ); |
205 | } | 214 | } |
206 | 215 | ||
207 | bool Calendar::isLocalTime() const | 216 | bool Calendar::isLocalTime() const |
208 | { | 217 | { |
209 | return mLocalTime; | 218 | return mLocalTime; |
210 | } | 219 | } |
211 | 220 | ||
212 | const QString &Calendar::getEmail() | 221 | const QString &Calendar::getEmail() |
213 | { | 222 | { |
214 | return mOwnerEmail; | 223 | return mOwnerEmail; |
215 | } | 224 | } |
216 | 225 | ||
217 | void Calendar::setEmail(const QString &e) | 226 | void Calendar::setEmail(const QString &e) |
218 | { | 227 | { |
219 | mOwnerEmail = e; | 228 | mOwnerEmail = e; |
220 | 229 | ||
221 | setModified( true ); | 230 | setModified( true ); |
222 | } | 231 | } |
223 | 232 | ||
224 | void Calendar::setFilter(CalFilter *filter) | 233 | void Calendar::setFilter(CalFilter *filter) |
225 | { | 234 | { |
226 | mFilter = filter; | 235 | mFilter = filter; |
227 | } | 236 | } |
228 | 237 | ||
229 | CalFilter *Calendar::filter() | 238 | CalFilter *Calendar::filter() |
230 | { | 239 | { |
231 | return mFilter; | 240 | return mFilter; |
232 | } | 241 | } |
233 | 242 | ||
234 | QPtrList<Incidence> Calendar::incidences() | 243 | QPtrList<Incidence> Calendar::incidences() |
235 | { | 244 | { |
236 | QPtrList<Incidence> incidences; | 245 | QPtrList<Incidence> incidences; |
237 | 246 | ||
238 | Incidence *i; | 247 | Incidence *i; |
239 | 248 | ||
240 | QPtrList<Event> e = events(); | 249 | QPtrList<Event> e = events(); |
241 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 250 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
242 | 251 | ||
243 | QPtrList<Todo> t = todos(); | 252 | QPtrList<Todo> t = todos(); |
244 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 253 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
245 | 254 | ||
246 | QPtrList<Journal> j = journals(); | 255 | QPtrList<Journal> j = journals(); |
247 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 256 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
248 | 257 | ||
249 | return incidences; | 258 | return incidences; |
250 | } | 259 | } |
251 | 260 | ||
252 | void Calendar::resetPilotStat(int id ) | 261 | void Calendar::resetPilotStat(int id ) |
253 | { | 262 | { |
254 | QPtrList<Incidence> incidences; | 263 | QPtrList<Incidence> incidences; |
255 | 264 | ||
256 | Incidence *i; | 265 | Incidence *i; |
257 | 266 | ||
258 | QPtrList<Event> e = rawEvents(); | 267 | QPtrList<Event> e = rawEvents(); |
259 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 268 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
260 | 269 | ||
261 | QPtrList<Todo> t = rawTodos(); | 270 | QPtrList<Todo> t = rawTodos(); |
262 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 271 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
263 | 272 | ||
264 | QPtrList<Journal> j = journals(); | 273 | QPtrList<Journal> j = journals(); |
265 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 274 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
266 | } | 275 | } |
267 | void Calendar::resetTempSyncStat() | 276 | void Calendar::resetTempSyncStat() |
268 | { | 277 | { |
269 | QPtrList<Incidence> incidences; | 278 | QPtrList<Incidence> incidences; |
270 | 279 | ||
271 | Incidence *i; | 280 | Incidence *i; |
272 | 281 | ||
273 | QPtrList<Event> e = rawEvents(); | 282 | QPtrList<Event> e = rawEvents(); |
274 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 283 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
275 | 284 | ||
276 | QPtrList<Todo> t = rawTodos(); | 285 | QPtrList<Todo> t = rawTodos(); |
277 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 286 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
278 | 287 | ||
279 | QPtrList<Journal> j = journals(); | 288 | QPtrList<Journal> j = journals(); |
280 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 289 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
281 | } | 290 | } |
282 | QPtrList<Incidence> Calendar::rawIncidences() | 291 | QPtrList<Incidence> Calendar::rawIncidences() |
283 | { | 292 | { |
284 | QPtrList<Incidence> incidences; | 293 | QPtrList<Incidence> incidences; |
285 | 294 | ||
286 | Incidence *i; | 295 | Incidence *i; |
287 | 296 | ||
288 | QPtrList<Event> e = rawEvents(); | 297 | QPtrList<Event> e = rawEvents(); |
289 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 298 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
290 | 299 | ||
291 | QPtrList<Todo> t = rawTodos(); | 300 | QPtrList<Todo> t = rawTodos(); |
292 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 301 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
293 | 302 | ||
294 | QPtrList<Journal> j = journals(); | 303 | QPtrList<Journal> j = journals(); |
295 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 304 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
296 | 305 | ||
297 | return incidences; | 306 | return incidences; |
298 | } | 307 | } |
299 | 308 | ||
300 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 309 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
301 | { | 310 | { |
302 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 311 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
303 | mFilter->apply(&el); | 312 | mFilter->apply(&el); |
304 | return el; | 313 | return el; |
305 | } | 314 | } |
306 | 315 | ||
307 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 316 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
308 | { | 317 | { |
309 | QPtrList<Event> el = rawEventsForDate(qdt); | 318 | QPtrList<Event> el = rawEventsForDate(qdt); |
310 | mFilter->apply(&el); | 319 | mFilter->apply(&el); |
311 | return el; | 320 | return el; |
312 | } | 321 | } |
313 | 322 | ||
314 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 323 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
315 | bool inclusive) | 324 | bool inclusive) |
316 | { | 325 | { |
317 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 326 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
318 | mFilter->apply(&el); | 327 | mFilter->apply(&el); |
319 | return el; | 328 | return el; |
320 | } | 329 | } |
321 | 330 | ||
322 | QPtrList<Event> Calendar::events() | 331 | QPtrList<Event> Calendar::events() |
323 | { | 332 | { |
324 | QPtrList<Event> el = rawEvents(); | 333 | QPtrList<Event> el = rawEvents(); |
325 | mFilter->apply(&el); | 334 | mFilter->apply(&el); |
326 | return el; | 335 | return el; |
327 | } | 336 | } |
328 | 337 | ||
329 | 338 | ||
330 | bool Calendar::addIncidence(Incidence *i) | 339 | bool Calendar::addIncidence(Incidence *i) |
331 | { | 340 | { |
332 | Incidence::AddVisitor<Calendar> v(this); | 341 | Incidence::AddVisitor<Calendar> v(this); |
333 | 342 | ||
334 | return i->accept(v); | 343 | return i->accept(v); |
335 | } | 344 | } |
336 | void Calendar::deleteIncidence(Incidence *in) | 345 | void Calendar::deleteIncidence(Incidence *in) |
337 | { | 346 | { |
338 | if ( in->type() == "Event" ) | 347 | if ( in->type() == "Event" ) |
339 | deleteEvent( (Event*) in ); | 348 | deleteEvent( (Event*) in ); |
340 | else if ( in->type() =="Todo" ) | 349 | else if ( in->type() =="Todo" ) |
341 | deleteTodo( (Todo*) in); | 350 | deleteTodo( (Todo*) in); |
342 | else if ( in->type() =="Journal" ) | 351 | else if ( in->type() =="Journal" ) |
343 | deleteJournal( (Journal*) in ); | 352 | deleteJournal( (Journal*) in ); |
344 | } | 353 | } |
345 | 354 | ||
346 | Incidence* Calendar::incidence( const QString& uid ) | 355 | Incidence* Calendar::incidence( const QString& uid ) |
347 | { | 356 | { |
348 | Incidence* i; | 357 | Incidence* i; |
349 | 358 | ||
350 | if( (i = todo( uid )) != 0 ) | 359 | if( (i = todo( uid )) != 0 ) |
351 | return i; | 360 | return i; |
352 | if( (i = event( uid )) != 0 ) | 361 | if( (i = event( uid )) != 0 ) |
353 | return i; | 362 | return i; |
354 | if( (i = journal( uid )) != 0 ) | 363 | if( (i = journal( uid )) != 0 ) |
355 | return i; | 364 | return i; |
356 | 365 | ||
357 | return 0; | 366 | return 0; |
358 | } | 367 | } |
359 | 368 | ||
360 | QPtrList<Todo> Calendar::todos() | 369 | QPtrList<Todo> Calendar::todos() |
361 | { | 370 | { |
362 | QPtrList<Todo> tl = rawTodos(); | 371 | QPtrList<Todo> tl = rawTodos(); |
363 | mFilter->apply( &tl ); | 372 | mFilter->apply( &tl ); |
364 | return tl; | 373 | return tl; |
365 | } | 374 | } |
366 | 375 | ||
367 | // When this is called, the todo have already been added to the calendar. | 376 | // When this is called, the todo have already been added to the calendar. |
368 | // This method is only about linking related todos | 377 | // This method is only about linking related todos |
369 | void Calendar::setupRelations( Incidence *incidence ) | 378 | void Calendar::setupRelations( Incidence *incidence ) |
370 | { | 379 | { |
371 | QString uid = incidence->uid(); | 380 | QString uid = incidence->uid(); |
372 | //qDebug("Calendar::setupRelations "); | 381 | //qDebug("Calendar::setupRelations "); |
373 | // First, go over the list of orphans and see if this is their parent | 382 | // First, go over the list of orphans and see if this is their parent |
374 | while( Incidence* i = mOrphans[ uid ] ) { | 383 | while( Incidence* i = mOrphans[ uid ] ) { |
375 | mOrphans.remove( uid ); | 384 | mOrphans.remove( uid ); |
376 | i->setRelatedTo( incidence ); | 385 | i->setRelatedTo( incidence ); |
377 | incidence->addRelation( i ); | 386 | incidence->addRelation( i ); |
378 | mOrphanUids.remove( i->uid() ); | 387 | mOrphanUids.remove( i->uid() ); |
379 | } | 388 | } |
380 | 389 | ||
381 | // Now see about this incidences parent | 390 | // Now see about this incidences parent |
382 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 391 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
383 | // This incidence has a uid it is related to, but is not registered to it yet | 392 | // This incidence has a uid it is related to, but is not registered to it yet |
384 | // Try to find it | 393 | // Try to find it |
385 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 394 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
386 | if( parent ) { | 395 | if( parent ) { |
387 | // Found it | 396 | // Found it |
388 | incidence->setRelatedTo( parent ); | 397 | incidence->setRelatedTo( parent ); |
389 | parent->addRelation( incidence ); | 398 | parent->addRelation( incidence ); |
390 | } else { | 399 | } else { |
391 | // Not found, put this in the mOrphans list | 400 | // Not found, put this in the mOrphans list |
392 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 401 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
393 | mOrphanUids.insert( incidence->uid(), incidence ); | 402 | mOrphanUids.insert( incidence->uid(), incidence ); |
394 | } | 403 | } |
395 | } | 404 | } |
396 | } | 405 | } |
397 | 406 | ||
398 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 407 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
399 | void Calendar::removeRelations( Incidence *incidence ) | 408 | void Calendar::removeRelations( Incidence *incidence ) |
400 | { | 409 | { |
401 | // qDebug("Calendar::removeRelations "); | 410 | // qDebug("Calendar::removeRelations "); |
402 | QString uid = incidence->uid(); | 411 | QString uid = incidence->uid(); |
403 | 412 | ||
404 | QPtrList<Incidence> relations = incidence->relations(); | 413 | QPtrList<Incidence> relations = incidence->relations(); |
405 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 414 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
406 | if( !mOrphanUids.find( i->uid() ) ) { | 415 | if( !mOrphanUids.find( i->uid() ) ) { |
407 | mOrphans.insert( uid, i ); | 416 | mOrphans.insert( uid, i ); |
408 | mOrphanUids.insert( i->uid(), i ); | 417 | mOrphanUids.insert( i->uid(), i ); |
409 | i->setRelatedTo( 0 ); | 418 | i->setRelatedTo( 0 ); |
410 | i->setRelatedToUid( uid ); | 419 | i->setRelatedToUid( uid ); |
411 | } | 420 | } |
412 | 421 | ||
413 | // If this incidence is related to something else, tell that about it | 422 | // If this incidence is related to something else, tell that about it |
414 | if( incidence->relatedTo() ) | 423 | if( incidence->relatedTo() ) |
415 | incidence->relatedTo()->removeRelation( incidence ); | 424 | incidence->relatedTo()->removeRelation( incidence ); |
416 | 425 | ||
417 | // Remove this one from the orphans list | 426 | // Remove this one from the orphans list |
418 | if( mOrphanUids.remove( uid ) ) | 427 | if( mOrphanUids.remove( uid ) ) |
419 | // This incidence is located in the orphans list - it should be removed | 428 | // This incidence is located in the orphans list - it should be removed |
420 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 429 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
421 | // Removing wasn't that easy | 430 | // Removing wasn't that easy |
422 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 431 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
423 | if( it.current()->uid() == uid ) { | 432 | if( it.current()->uid() == uid ) { |
424 | mOrphans.remove( it.currentKey() ); | 433 | mOrphans.remove( it.currentKey() ); |
425 | break; | 434 | break; |
426 | } | 435 | } |
427 | } | 436 | } |
428 | } | 437 | } |
429 | } | 438 | } |
430 | 439 | ||
431 | void Calendar::registerObserver( Observer *observer ) | 440 | void Calendar::registerObserver( Observer *observer ) |
432 | { | 441 | { |
433 | mObserver = observer; | 442 | mObserver = observer; |
434 | mNewObserver = true; | 443 | mNewObserver = true; |
435 | } | 444 | } |
436 | 445 | ||
437 | void Calendar::setModified( bool modified ) | 446 | void Calendar::setModified( bool modified ) |
438 | { | 447 | { |
439 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 448 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
440 | if ( modified != mModified || mNewObserver ) { | 449 | if ( modified != mModified || mNewObserver ) { |
441 | mNewObserver = false; | 450 | mNewObserver = false; |
442 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 451 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
443 | mModified = modified; | 452 | mModified = modified; |
444 | } | 453 | } |
445 | } | 454 | } |
446 | 455 | ||
447 | void Calendar::setLoadedProductId( const QString &id ) | 456 | void Calendar::setLoadedProductId( const QString &id ) |
448 | { | 457 | { |
449 | mLoadedProductId = id; | 458 | mLoadedProductId = id; |
450 | } | 459 | } |
451 | 460 | ||
452 | QString Calendar::loadedProductId() | 461 | QString Calendar::loadedProductId() |
453 | { | 462 | { |
454 | return mLoadedProductId; | 463 | return mLoadedProductId; |
455 | } | 464 | } |
456 | 465 | ||
457 | //#include "calendar.moc" | 466 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index b7d6a1f..2f2c3aa 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,353 +1,356 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | ||
69 | bool undoDeleteIncidence(); | ||
68 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
69 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
70 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
71 | /** | 73 | /** |
72 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
73 | */ | 75 | */ |
74 | virtual void close() = 0; | 76 | virtual void close() = 0; |
75 | 77 | ||
76 | /** | 78 | /** |
77 | Sync changes in memory to persistant storage. | 79 | Sync changes in memory to persistant storage. |
78 | */ | 80 | */ |
79 | virtual void save() = 0; | 81 | virtual void save() = 0; |
80 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 82 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
81 | virtual void removeSyncInfo( QString syncProfile) = 0; | 83 | virtual void removeSyncInfo( QString syncProfile) = 0; |
82 | virtual bool isSaving() { return false; } | 84 | virtual bool isSaving() { return false; } |
83 | 85 | ||
84 | /** | 86 | /** |
85 | Return the owner of the calendar's full name. | 87 | Return the owner of the calendar's full name. |
86 | */ | 88 | */ |
87 | const QString &getOwner() const; | 89 | const QString &getOwner() const; |
88 | /** | 90 | /** |
89 | Set the owner of the calendar. Should be owner's full name. | 91 | Set the owner of the calendar. Should be owner's full name. |
90 | */ | 92 | */ |
91 | void setOwner( const QString &os ); | 93 | void setOwner( const QString &os ); |
92 | /** | 94 | /** |
93 | Return the email address of the calendar owner. | 95 | Return the email address of the calendar owner. |
94 | */ | 96 | */ |
95 | const QString &getEmail(); | 97 | const QString &getEmail(); |
96 | /** | 98 | /** |
97 | Set the email address of the calendar owner. | 99 | Set the email address of the calendar owner. |
98 | */ | 100 | */ |
99 | void setEmail( const QString & ); | 101 | void setEmail( const QString & ); |
100 | 102 | ||
101 | /** | 103 | /** |
102 | Set time zone from a timezone string (e.g. -2:00) | 104 | Set time zone from a timezone string (e.g. -2:00) |
103 | */ | 105 | */ |
104 | void setTimeZone( const QString &tz ); | 106 | void setTimeZone( const QString &tz ); |
105 | /** | 107 | /** |
106 | Set time zone from a minutes value (e.g. -60) | 108 | Set time zone from a minutes value (e.g. -60) |
107 | */ | 109 | */ |
108 | void setTimeZone( int tz ); | 110 | void setTimeZone( int tz ); |
109 | /** | 111 | /** |
110 | Return time zone as offest in minutes. | 112 | Return time zone as offest in minutes. |
111 | */ | 113 | */ |
112 | int getTimeZone() const; | 114 | int getTimeZone() const; |
113 | /** | 115 | /** |
114 | Compute an ISO 8601 format string from the time zone. | 116 | Compute an ISO 8601 format string from the time zone. |
115 | */ | 117 | */ |
116 | QString getTimeZoneStr() const; | 118 | QString getTimeZoneStr() const; |
117 | /** | 119 | /** |
118 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 120 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
119 | values). | 121 | values). |
120 | */ | 122 | */ |
121 | void setTimeZoneId( const QString & ); | 123 | void setTimeZoneId( const QString & ); |
122 | /** | 124 | /** |
123 | Return time zone id. | 125 | Return time zone id. |
124 | */ | 126 | */ |
125 | QString timeZoneId() const; | 127 | QString timeZoneId() const; |
126 | /** | 128 | /** |
127 | Use local time, not UTC or a time zone. | 129 | Use local time, not UTC or a time zone. |
128 | */ | 130 | */ |
129 | void setLocalTime(); | 131 | void setLocalTime(); |
130 | /** | 132 | /** |
131 | Return whether local time is being used. | 133 | Return whether local time is being used. |
132 | */ | 134 | */ |
133 | bool isLocalTime() const; | 135 | bool isLocalTime() const; |
134 | 136 | ||
135 | /** | 137 | /** |
136 | Add an incidence to calendar. | 138 | Add an incidence to calendar. |
137 | 139 | ||
138 | @return true on success, false on error. | 140 | @return true on success, false on error. |
139 | */ | 141 | */ |
140 | virtual bool addIncidence( Incidence * ); | 142 | virtual bool addIncidence( Incidence * ); |
141 | /** | 143 | /** |
142 | Return filtered list of all incidences of this calendar. | 144 | Return filtered list of all incidences of this calendar. |
143 | */ | 145 | */ |
144 | virtual QPtrList<Incidence> incidences(); | 146 | virtual QPtrList<Incidence> incidences(); |
145 | 147 | ||
146 | /** | 148 | /** |
147 | Return unfiltered list of all incidences of this calendar. | 149 | Return unfiltered list of all incidences of this calendar. |
148 | */ | 150 | */ |
149 | virtual QPtrList<Incidence> rawIncidences(); | 151 | virtual QPtrList<Incidence> rawIncidences(); |
150 | 152 | ||
151 | /** | 153 | /** |
152 | Adds a Event to this calendar object. | 154 | Adds a Event to this calendar object. |
153 | @param anEvent a pointer to the event to add | 155 | @param anEvent a pointer to the event to add |
154 | 156 | ||
155 | @return true on success, false on error. | 157 | @return true on success, false on error. |
156 | */ | 158 | */ |
157 | virtual bool addEventNoDup( Event *event ) = 0; | 159 | virtual bool addEventNoDup( Event *event ) = 0; |
158 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 160 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
159 | virtual bool addEvent( Event *anEvent ) = 0; | 161 | virtual bool addEvent( Event *anEvent ) = 0; |
160 | /** | 162 | /** |
161 | Delete event from calendar. | 163 | Delete event from calendar. |
162 | */ | 164 | */ |
163 | virtual void deleteEvent( Event * ) = 0; | 165 | virtual void deleteEvent( Event * ) = 0; |
164 | /** | 166 | /** |
165 | Retrieves an event on the basis of the unique string ID. | 167 | Retrieves an event on the basis of the unique string ID. |
166 | */ | 168 | */ |
167 | virtual Event *event( const QString &UniqueStr ) = 0; | 169 | virtual Event *event( const QString &UniqueStr ) = 0; |
168 | virtual Event *event( QString, QString ) = 0; | 170 | virtual Event *event( QString, QString ) = 0; |
169 | /** | 171 | /** |
170 | Builds and then returns a list of all events that match for the | 172 | Builds and then returns a list of all events that match for the |
171 | date specified. useful for dayView, etc. etc. | 173 | date specified. useful for dayView, etc. etc. |
172 | The calendar filter is applied. | 174 | The calendar filter is applied. |
173 | */ | 175 | */ |
174 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 176 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
175 | /** | 177 | /** |
176 | Get events, which occur on the given date. | 178 | Get events, which occur on the given date. |
177 | The calendar filter is applied. | 179 | The calendar filter is applied. |
178 | */ | 180 | */ |
179 | QPtrList<Event> events( const QDateTime &qdt ); | 181 | QPtrList<Event> events( const QDateTime &qdt ); |
180 | /** | 182 | /** |
181 | Get events in a range of dates. If inclusive is set to true, only events | 183 | Get events in a range of dates. If inclusive is set to true, only events |
182 | are returned, which are completely included in the range. | 184 | are returned, which are completely included in the range. |
183 | The calendar filter is applied. | 185 | The calendar filter is applied. |
184 | */ | 186 | */ |
185 | QPtrList<Event> events( const QDate &start, const QDate &end, | 187 | QPtrList<Event> events( const QDate &start, const QDate &end, |
186 | bool inclusive = false); | 188 | bool inclusive = false); |
187 | /** | 189 | /** |
188 | Return filtered list of all events in calendar. | 190 | Return filtered list of all events in calendar. |
189 | */ | 191 | */ |
190 | virtual QPtrList<Event> events(); | 192 | virtual QPtrList<Event> events(); |
191 | /** | 193 | /** |
192 | Return unfiltered list of all events in calendar. | 194 | Return unfiltered list of all events in calendar. |
193 | */ | 195 | */ |
194 | virtual QPtrList<Event> rawEvents() = 0; | 196 | virtual QPtrList<Event> rawEvents() = 0; |
195 | 197 | ||
196 | /** | 198 | /** |
197 | Add a todo to the todolist. | 199 | Add a todo to the todolist. |
198 | 200 | ||
199 | @return true on success, false on error. | 201 | @return true on success, false on error. |
200 | */ | 202 | */ |
201 | virtual bool addTodo( Todo *todo ) = 0; | 203 | virtual bool addTodo( Todo *todo ) = 0; |
202 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 204 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
203 | /** | 205 | /** |
204 | Remove a todo from the todolist. | 206 | Remove a todo from the todolist. |
205 | */ | 207 | */ |
206 | virtual void deleteTodo( Todo * ) = 0; | 208 | virtual void deleteTodo( Todo * ) = 0; |
207 | virtual void deleteJournal( Journal * ) = 0; | 209 | virtual void deleteJournal( Journal * ) = 0; |
208 | /** | 210 | /** |
209 | Return filterd list of todos. | 211 | Return filterd list of todos. |
210 | */ | 212 | */ |
211 | virtual QPtrList<Todo> todos(); | 213 | virtual QPtrList<Todo> todos(); |
212 | /** | 214 | /** |
213 | Searches todolist for an event with this unique string identifier, | 215 | Searches todolist for an event with this unique string identifier, |
214 | returns a pointer or null. | 216 | returns a pointer or null. |
215 | */ | 217 | */ |
216 | virtual Todo *todo( const QString &uid ) = 0; | 218 | virtual Todo *todo( const QString &uid ) = 0; |
217 | virtual Todo *todo( QString, QString ) = 0; | 219 | virtual Todo *todo( QString, QString ) = 0; |
218 | /** | 220 | /** |
219 | Returns list of todos due on the specified date. | 221 | Returns list of todos due on the specified date. |
220 | */ | 222 | */ |
221 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 223 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
222 | /** | 224 | /** |
223 | Return unfiltered list of todos. | 225 | Return unfiltered list of todos. |
224 | */ | 226 | */ |
225 | virtual QPtrList<Todo> rawTodos() = 0; | 227 | virtual QPtrList<Todo> rawTodos() = 0; |
226 | 228 | ||
227 | /** | 229 | /** |
228 | Add a Journal entry to calendar. | 230 | Add a Journal entry to calendar. |
229 | 231 | ||
230 | @return true on success, false on error. | 232 | @return true on success, false on error. |
231 | */ | 233 | */ |
232 | virtual bool addJournal( Journal * ) = 0; | 234 | virtual bool addJournal( Journal * ) = 0; |
233 | /** | 235 | /** |
234 | Return Journal for given date. | 236 | Return Journal for given date. |
235 | */ | 237 | */ |
236 | virtual Journal *journal( const QDate & ) = 0; | 238 | virtual Journal *journal( const QDate & ) = 0; |
237 | /** | 239 | /** |
238 | Return Journal with given UID. | 240 | Return Journal with given UID. |
239 | */ | 241 | */ |
240 | virtual Journal *journal( const QString &UID ) = 0; | 242 | virtual Journal *journal( const QString &UID ) = 0; |
241 | /** | 243 | /** |
242 | Return list of all Journal entries. | 244 | Return list of all Journal entries. |
243 | */ | 245 | */ |
244 | virtual QPtrList<Journal> journals() = 0; | 246 | virtual QPtrList<Journal> journals() = 0; |
245 | 247 | ||
246 | /** | 248 | /** |
247 | Searches all incidence types for an incidence with this unique | 249 | Searches all incidence types for an incidence with this unique |
248 | string identifier, returns a pointer or null. | 250 | string identifier, returns a pointer or null. |
249 | */ | 251 | */ |
250 | Incidence* incidence( const QString&UID ); | 252 | Incidence* incidence( const QString&UID ); |
251 | 253 | ||
252 | /** | 254 | /** |
253 | Setup relations for an incidence. | 255 | Setup relations for an incidence. |
254 | */ | 256 | */ |
255 | virtual void setupRelations( Incidence * ); | 257 | virtual void setupRelations( Incidence * ); |
256 | /** | 258 | /** |
257 | Remove all relations to an incidence | 259 | Remove all relations to an incidence |
258 | */ | 260 | */ |
259 | virtual void removeRelations( Incidence * ); | 261 | virtual void removeRelations( Incidence * ); |
260 | 262 | ||
261 | /** | 263 | /** |
262 | Set calendar filter, which filters events for the events() functions. | 264 | Set calendar filter, which filters events for the events() functions. |
263 | The Filter object is owned by the caller. | 265 | The Filter object is owned by the caller. |
264 | */ | 266 | */ |
265 | void setFilter( CalFilter * ); | 267 | void setFilter( CalFilter * ); |
266 | /** | 268 | /** |
267 | Return calendar filter. | 269 | Return calendar filter. |
268 | */ | 270 | */ |
269 | CalFilter *filter(); | 271 | CalFilter *filter(); |
270 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 272 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
271 | virtual QString nextSummary( ) const = 0; | 273 | virtual QString nextSummary( ) const = 0; |
272 | virtual void reInitAlarmSettings() = 0; | 274 | virtual void reInitAlarmSettings() = 0; |
273 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 275 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
274 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 276 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
275 | /** | 277 | /** |
276 | Return all alarms, which ocur in the given time interval. | 278 | Return all alarms, which ocur in the given time interval. |
277 | */ | 279 | */ |
278 | virtual Alarm::List alarms( const QDateTime &from, | 280 | virtual Alarm::List alarms( const QDateTime &from, |
279 | const QDateTime &to ) = 0; | 281 | const QDateTime &to ) = 0; |
280 | 282 | ||
281 | class Observer { | 283 | class Observer { |
282 | public: | 284 | public: |
283 | virtual void calendarModified( bool, Calendar * ) = 0; | 285 | virtual void calendarModified( bool, Calendar * ) = 0; |
284 | }; | 286 | }; |
285 | 287 | ||
286 | void registerObserver( Observer * ); | 288 | void registerObserver( Observer * ); |
287 | 289 | ||
288 | void setModified( bool ); | 290 | void setModified( bool ); |
289 | 291 | ||
290 | /** | 292 | /** |
291 | Set product id returned by loadedProductId(). This function is only | 293 | Set product id returned by loadedProductId(). This function is only |
292 | useful for the calendar loading code. | 294 | useful for the calendar loading code. |
293 | */ | 295 | */ |
294 | void setLoadedProductId( const QString & ); | 296 | void setLoadedProductId( const QString & ); |
295 | /** | 297 | /** |
296 | Return product id taken from file that has been loaded. Returns | 298 | Return product id taken from file that has been loaded. Returns |
297 | QString::null, if no calendar has been loaded. | 299 | QString::null, if no calendar has been loaded. |
298 | */ | 300 | */ |
299 | QString loadedProductId(); | 301 | QString loadedProductId(); |
300 | 302 | ||
301 | signals: | 303 | signals: |
302 | void calendarChanged(); | 304 | void calendarChanged(); |
303 | void calendarSaved(); | 305 | void calendarSaved(); |
304 | void calendarLoaded(); | 306 | void calendarLoaded(); |
305 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 307 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
306 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 308 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
307 | 309 | ||
308 | protected: | 310 | protected: |
309 | /** | 311 | /** |
310 | Get unfiltered events, which occur on the given date. | 312 | Get unfiltered events, which occur on the given date. |
311 | */ | 313 | */ |
312 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 314 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
313 | /** | 315 | /** |
314 | Get unfiltered events, which occur on the given date. | 316 | Get unfiltered events, which occur on the given date. |
315 | */ | 317 | */ |
316 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 318 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
317 | bool sorted = false ) = 0; | 319 | bool sorted = false ) = 0; |
318 | /** | 320 | /** |
319 | Get events in a range of dates. If inclusive is set to true, only events | 321 | Get events in a range of dates. If inclusive is set to true, only events |
320 | are returned, which are completely included in the range. | 322 | are returned, which are completely included in the range. |
321 | */ | 323 | */ |
322 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 324 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
323 | bool inclusive = false ) = 0; | 325 | bool inclusive = false ) = 0; |
324 | Incidence *mNextAlarmIncidence; | 326 | Incidence *mNextAlarmIncidence; |
327 | Incidence *mUndoIncidence; | ||
325 | 328 | ||
326 | private: | 329 | private: |
327 | void init(); | 330 | void init(); |
328 | 331 | ||
329 | QString mOwner; // who the calendar belongs to | 332 | QString mOwner; // who the calendar belongs to |
330 | QString mOwnerEmail; // email address of the owner | 333 | QString mOwnerEmail; // email address of the owner |
331 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 334 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
332 | bool mLocalTime; // use local time, not UTC or a time zone | 335 | bool mLocalTime; // use local time, not UTC or a time zone |
333 | 336 | ||
334 | CalFilter *mFilter; | 337 | CalFilter *mFilter; |
335 | CalFilter *mDefaultFilter; | 338 | CalFilter *mDefaultFilter; |
336 | 339 | ||
337 | QString mTimeZoneId; | 340 | QString mTimeZoneId; |
338 | 341 | ||
339 | Observer *mObserver; | 342 | Observer *mObserver; |
340 | bool mNewObserver; | 343 | bool mNewObserver; |
341 | 344 | ||
342 | bool mModified; | 345 | bool mModified; |
343 | 346 | ||
344 | QString mLoadedProductId; | 347 | QString mLoadedProductId; |
345 | 348 | ||
346 | // This list is used to put together related todos | 349 | // This list is used to put together related todos |
347 | QDict<Incidence> mOrphans; | 350 | QDict<Incidence> mOrphans; |
348 | QDict<Incidence> mOrphanUids; | 351 | QDict<Incidence> mOrphanUids; |
349 | }; | 352 | }; |
350 | 353 | ||
351 | } | 354 | } |
352 | 355 | ||
353 | #endif | 356 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 3f46d53..12294c0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,719 +1,724 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | mEventList.setAutoDelete( true ); | 85 | mEventList.setAutoDelete( true ); |
86 | mTodoList.setAutoDelete( true ); | 86 | mTodoList.setAutoDelete( true ); |
87 | mJournalList.setAutoDelete( false ); | 87 | mJournalList.setAutoDelete( false ); |
88 | 88 | ||
89 | mEventList.clear(); | 89 | mEventList.clear(); |
90 | mTodoList.clear(); | 90 | mTodoList.clear(); |
91 | mJournalList.clear(); | 91 | mJournalList.clear(); |
92 | 92 | ||
93 | mEventList.setAutoDelete( false ); | 93 | mEventList.setAutoDelete( false ); |
94 | mTodoList.setAutoDelete( false ); | 94 | mTodoList.setAutoDelete( false ); |
95 | mJournalList.setAutoDelete( false ); | 95 | mJournalList.setAutoDelete( false ); |
96 | 96 | ||
97 | setModified( false ); | 97 | setModified( false ); |
98 | } | 98 | } |
99 | 99 | ||
100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 100 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
101 | { | 101 | { |
102 | QString cat; | 102 | QString cat; |
103 | bool isBirthday = true; | 103 | bool isBirthday = true; |
104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 104 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
105 | isBirthday = false; | 105 | isBirthday = false; |
106 | cat = i18n( "Anniversary" ); | 106 | cat = i18n( "Anniversary" ); |
107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 107 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
108 | isBirthday = true; | 108 | isBirthday = true; |
109 | cat = i18n( "Birthday" ); | 109 | cat = i18n( "Birthday" ); |
110 | } else { | 110 | } else { |
111 | qDebug("addAnniversaryNoDup called without fitting category! "); | 111 | qDebug("addAnniversaryNoDup called without fitting category! "); |
112 | return false; | 112 | return false; |
113 | } | 113 | } |
114 | Event * eve; | 114 | Event * eve; |
115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 115 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
116 | if ( !(eve->categories().contains( cat ) )) | 116 | if ( !(eve->categories().contains( cat ) )) |
117 | continue; | 117 | continue; |
118 | // now we have an event with fitting category | 118 | // now we have an event with fitting category |
119 | if ( eve->dtStart().date() != event->dtStart().date() ) | 119 | if ( eve->dtStart().date() != event->dtStart().date() ) |
120 | continue; | 120 | continue; |
121 | // now we have an event with fitting category+date | 121 | // now we have an event with fitting category+date |
122 | if ( eve->summary() != event->summary() ) | 122 | if ( eve->summary() != event->summary() ) |
123 | continue; | 123 | continue; |
124 | // now we have an event with fitting category+date+summary | 124 | // now we have an event with fitting category+date+summary |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | return addEvent( event ); | 127 | return addEvent( event ); |
128 | 128 | ||
129 | } | 129 | } |
130 | bool CalendarLocal::addEventNoDup( Event *event ) | 130 | bool CalendarLocal::addEventNoDup( Event *event ) |
131 | { | 131 | { |
132 | Event * eve; | 132 | Event * eve; |
133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 133 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
134 | if ( *eve == *event ) { | 134 | if ( *eve == *event ) { |
135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 135 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | } | 138 | } |
139 | return addEvent( event ); | 139 | return addEvent( event ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool CalendarLocal::addEvent( Event *event ) | 142 | bool CalendarLocal::addEvent( Event *event ) |
143 | { | 143 | { |
144 | insertEvent( event ); | 144 | insertEvent( event ); |
145 | 145 | ||
146 | event->registerObserver( this ); | 146 | event->registerObserver( this ); |
147 | 147 | ||
148 | setModified( true ); | 148 | setModified( true ); |
149 | 149 | ||
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | void CalendarLocal::deleteEvent( Event *event ) | 153 | void CalendarLocal::deleteEvent( Event *event ) |
154 | { | 154 | { |
155 | 155 | if ( mUndoIncidence ) delete mUndoIncidence; | |
156 | 156 | mUndoIncidence = event->clone(); | |
157 | if ( mEventList.removeRef( event ) ) { | 157 | if ( mEventList.removeRef( event ) ) { |
158 | setModified( true ); | 158 | setModified( true ); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | Event *CalendarLocal::event( const QString &uid ) | 163 | Event *CalendarLocal::event( const QString &uid ) |
164 | { | 164 | { |
165 | 165 | ||
166 | Event *event; | 166 | Event *event; |
167 | 167 | ||
168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 168 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
169 | if ( event->uid() == uid ) { | 169 | if ( event->uid() == uid ) { |
170 | return event; | 170 | return event; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | return 0; | 174 | return 0; |
175 | } | 175 | } |
176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 176 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
177 | { | 177 | { |
178 | Todo * eve; | 178 | Todo * eve; |
179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 179 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
180 | if ( *eve == *todo ) { | 180 | if ( *eve == *todo ) { |
181 | //qDebug("duplicate todo found! not inserted! "); | 181 | //qDebug("duplicate todo found! not inserted! "); |
182 | return false; | 182 | return false; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return addTodo( todo ); | 185 | return addTodo( todo ); |
186 | } | 186 | } |
187 | bool CalendarLocal::addTodo( Todo *todo ) | 187 | bool CalendarLocal::addTodo( Todo *todo ) |
188 | { | 188 | { |
189 | mTodoList.append( todo ); | 189 | mTodoList.append( todo ); |
190 | 190 | ||
191 | todo->registerObserver( this ); | 191 | todo->registerObserver( this ); |
192 | 192 | ||
193 | // Set up subtask relations | 193 | // Set up subtask relations |
194 | setupRelations( todo ); | 194 | setupRelations( todo ); |
195 | 195 | ||
196 | setModified( true ); | 196 | setModified( true ); |
197 | 197 | ||
198 | return true; | 198 | return true; |
199 | } | 199 | } |
200 | 200 | ||
201 | void CalendarLocal::deleteTodo( Todo *todo ) | 201 | void CalendarLocal::deleteTodo( Todo *todo ) |
202 | { | 202 | { |
203 | // Handle orphaned children | 203 | // Handle orphaned children |
204 | removeRelations( todo ); | 204 | if ( mUndoIncidence ) delete mUndoIncidence; |
205 | mUndoIncidence = todo->clone(); | ||
206 | removeRelations( todo ); | ||
205 | 207 | ||
206 | if ( mTodoList.removeRef( todo ) ) { | 208 | if ( mTodoList.removeRef( todo ) ) { |
207 | setModified( true ); | 209 | setModified( true ); |
208 | } | 210 | } |
209 | } | 211 | } |
210 | 212 | ||
211 | QPtrList<Todo> CalendarLocal::rawTodos() | 213 | QPtrList<Todo> CalendarLocal::rawTodos() |
212 | { | 214 | { |
213 | return mTodoList; | 215 | return mTodoList; |
214 | } | 216 | } |
215 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 217 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
216 | { | 218 | { |
217 | Todo *todo; | 219 | Todo *todo; |
218 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 220 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
219 | if ( todo->getID( syncProf ) == id ) return todo; | 221 | if ( todo->getID( syncProf ) == id ) return todo; |
220 | } | 222 | } |
221 | 223 | ||
222 | return 0; | 224 | return 0; |
223 | } | 225 | } |
224 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 226 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
225 | { | 227 | { |
226 | QPtrList<Incidence> all = rawIncidences() ; | 228 | QPtrList<Incidence> all = rawIncidences() ; |
227 | Incidence *inc; | 229 | Incidence *inc; |
228 | for ( inc = all.first(); inc; inc = all.next() ) { | 230 | for ( inc = all.first(); inc; inc = all.next() ) { |
229 | inc->removeID( syncProfile ); | 231 | inc->removeID( syncProfile ); |
230 | } | 232 | } |
231 | if ( syncProfile.isEmpty() ) { | 233 | if ( syncProfile.isEmpty() ) { |
232 | QPtrList<Event> el; | 234 | QPtrList<Event> el; |
233 | Event *todo; | 235 | Event *todo; |
234 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 236 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
235 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 237 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
236 | el.append( todo ); | 238 | el.append( todo ); |
237 | } | 239 | } |
238 | for ( todo = el.first(); todo; todo = el.next() ) { | 240 | for ( todo = el.first(); todo; todo = el.next() ) { |
239 | deleteIncidence ( todo ); | 241 | deleteIncidence ( todo ); |
240 | } | 242 | } |
241 | } else { | 243 | } else { |
242 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 244 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
243 | deleteIncidence ( lse ); | 245 | deleteIncidence ( lse ); |
244 | } | 246 | } |
245 | } | 247 | } |
246 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 248 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
247 | { | 249 | { |
248 | QPtrList<Event> el; | 250 | QPtrList<Event> el; |
249 | Event *todo; | 251 | Event *todo; |
250 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 252 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
251 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 253 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
252 | if ( todo->summary().left(3) == "E: " ) | 254 | if ( todo->summary().left(3) == "E: " ) |
253 | el.append( todo ); | 255 | el.append( todo ); |
254 | } | 256 | } |
255 | 257 | ||
256 | return el; | 258 | return el; |
257 | 259 | ||
258 | } | 260 | } |
259 | Event *CalendarLocal::event( QString syncProf, QString id ) | 261 | Event *CalendarLocal::event( QString syncProf, QString id ) |
260 | { | 262 | { |
261 | Event *todo; | 263 | Event *todo; |
262 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 264 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
263 | if ( todo->getID( syncProf ) == id ) return todo; | 265 | if ( todo->getID( syncProf ) == id ) return todo; |
264 | } | 266 | } |
265 | 267 | ||
266 | return 0; | 268 | return 0; |
267 | } | 269 | } |
268 | Todo *CalendarLocal::todo( const QString &uid ) | 270 | Todo *CalendarLocal::todo( const QString &uid ) |
269 | { | 271 | { |
270 | Todo *todo; | 272 | Todo *todo; |
271 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 273 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
272 | if ( todo->uid() == uid ) return todo; | 274 | if ( todo->uid() == uid ) return todo; |
273 | } | 275 | } |
274 | 276 | ||
275 | return 0; | 277 | return 0; |
276 | } | 278 | } |
277 | QString CalendarLocal::nextSummary() const | 279 | QString CalendarLocal::nextSummary() const |
278 | { | 280 | { |
279 | return mNextSummary; | 281 | return mNextSummary; |
280 | } | 282 | } |
281 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 283 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
282 | { | 284 | { |
283 | return mNextAlarmEventDateTime; | 285 | return mNextAlarmEventDateTime; |
284 | } | 286 | } |
285 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 287 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
286 | { | 288 | { |
287 | //mNextAlarmIncidence | 289 | //mNextAlarmIncidence |
288 | //mNextAlarmDateTime | 290 | //mNextAlarmDateTime |
289 | //return mNextSummary; | 291 | //return mNextSummary; |
290 | //return mNextAlarmEventDateTime; | 292 | //return mNextAlarmEventDateTime; |
291 | bool newNextAlarm = false; | 293 | bool newNextAlarm = false; |
292 | bool computeNextAlarm = false; | 294 | bool computeNextAlarm = false; |
293 | bool ok; | 295 | bool ok; |
294 | int offset; | 296 | int offset; |
295 | QDateTime nextA; | 297 | QDateTime nextA; |
296 | // QString nextSum; | 298 | // QString nextSum; |
297 | //QDateTime nextEvent; | 299 | //QDateTime nextEvent; |
298 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 300 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
299 | computeNextAlarm = true; | 301 | computeNextAlarm = true; |
300 | } else { | 302 | } else { |
301 | if ( ! deleted ) { | 303 | if ( ! deleted ) { |
302 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; | 304 | nextA = incidence->getNextAlarmDateTime(& ok, &offset ) ; |
303 | if ( ok ) { | 305 | if ( ok ) { |
304 | if ( nextA < mNextAlarmDateTime ) { | 306 | if ( nextA < mNextAlarmDateTime ) { |
305 | deRegisterAlarm(); | 307 | deRegisterAlarm(); |
306 | mNextAlarmDateTime = nextA; | 308 | mNextAlarmDateTime = nextA; |
307 | mNextSummary = incidence->summary(); | 309 | mNextSummary = incidence->summary(); |
308 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 310 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
309 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 311 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
310 | newNextAlarm = true; | 312 | newNextAlarm = true; |
311 | mNextAlarmIncidence = incidence; | 313 | mNextAlarmIncidence = incidence; |
312 | } else { | 314 | } else { |
313 | if ( incidence == mNextAlarmIncidence ) { | 315 | if ( incidence == mNextAlarmIncidence ) { |
314 | computeNextAlarm = true; | 316 | computeNextAlarm = true; |
315 | } | 317 | } |
316 | } | 318 | } |
317 | } else { | 319 | } else { |
318 | if ( mNextAlarmIncidence == incidence ) { | 320 | if ( mNextAlarmIncidence == incidence ) { |
319 | computeNextAlarm = true; | 321 | computeNextAlarm = true; |
320 | } | 322 | } |
321 | } | 323 | } |
322 | } else { // deleted | 324 | } else { // deleted |
323 | if ( incidence == mNextAlarmIncidence ) { | 325 | if ( incidence == mNextAlarmIncidence ) { |
324 | computeNextAlarm = true; | 326 | computeNextAlarm = true; |
325 | } | 327 | } |
326 | } | 328 | } |
327 | } | 329 | } |
328 | if ( computeNextAlarm ) { | 330 | if ( computeNextAlarm ) { |
329 | deRegisterAlarm(); | 331 | deRegisterAlarm(); |
330 | nextA = nextAlarm( 1000 ); | 332 | nextA = nextAlarm( 1000 ); |
331 | if (! mNextAlarmIncidence ) { | 333 | if (! mNextAlarmIncidence ) { |
332 | return; | 334 | return; |
333 | } | 335 | } |
334 | newNextAlarm = true; | 336 | newNextAlarm = true; |
335 | } | 337 | } |
336 | if ( newNextAlarm ) | 338 | if ( newNextAlarm ) |
337 | registerAlarm(); | 339 | registerAlarm(); |
338 | } | 340 | } |
339 | QString CalendarLocal:: getAlarmNotification() | 341 | QString CalendarLocal:: getAlarmNotification() |
340 | { | 342 | { |
341 | QString ret; | 343 | QString ret; |
342 | // this should not happen | 344 | // this should not happen |
343 | if (! mNextAlarmIncidence ) | 345 | if (! mNextAlarmIncidence ) |
344 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 346 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
345 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 347 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
346 | if ( alarm->type() == Alarm::Procedure ) { | 348 | if ( alarm->type() == Alarm::Procedure ) { |
347 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 349 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
348 | } else { | 350 | } else { |
349 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 351 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
350 | } | 352 | } |
351 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 353 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
352 | if ( mNextSummary.length() > 25 ) | 354 | if ( mNextSummary.length() > 25 ) |
353 | ret += "\n" + mNextSummary.mid(25, 25 ); | 355 | ret += "\n" + mNextSummary.mid(25, 25 ); |
354 | ret+= "\n"+mNextAlarmEventDateTimeString; | 356 | ret+= "\n"+mNextAlarmEventDateTimeString; |
355 | return ret; | 357 | return ret; |
356 | } | 358 | } |
357 | void CalendarLocal::registerAlarm() | 359 | void CalendarLocal::registerAlarm() |
358 | { | 360 | { |
359 | mLastAlarmNotificationString = getAlarmNotification(); | 361 | mLastAlarmNotificationString = getAlarmNotification(); |
360 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 362 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
361 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 363 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
362 | // #ifndef DESKTOP_VERSION | 364 | // #ifndef DESKTOP_VERSION |
363 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 365 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
364 | // #endif | 366 | // #endif |
365 | } | 367 | } |
366 | void CalendarLocal::deRegisterAlarm() | 368 | void CalendarLocal::deRegisterAlarm() |
367 | { | 369 | { |
368 | if ( mLastAlarmNotificationString.isNull() ) | 370 | if ( mLastAlarmNotificationString.isNull() ) |
369 | return; | 371 | return; |
370 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 372 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
371 | 373 | ||
372 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 374 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
373 | // #ifndef DESKTOP_VERSION | 375 | // #ifndef DESKTOP_VERSION |
374 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 376 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
375 | // #endif | 377 | // #endif |
376 | } | 378 | } |
377 | 379 | ||
378 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 380 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
379 | { | 381 | { |
380 | QPtrList<Todo> todos; | 382 | QPtrList<Todo> todos; |
381 | 383 | ||
382 | Todo *todo; | 384 | Todo *todo; |
383 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 385 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
384 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 386 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
385 | todos.append( todo ); | 387 | todos.append( todo ); |
386 | } | 388 | } |
387 | } | 389 | } |
388 | 390 | ||
389 | filter()->apply( &todos ); | 391 | filter()->apply( &todos ); |
390 | return todos; | 392 | return todos; |
391 | } | 393 | } |
392 | void CalendarLocal::reInitAlarmSettings() | 394 | void CalendarLocal::reInitAlarmSettings() |
393 | { | 395 | { |
394 | if ( !mNextAlarmIncidence ) { | 396 | if ( !mNextAlarmIncidence ) { |
395 | nextAlarm( 1000 ); | 397 | nextAlarm( 1000 ); |
396 | } | 398 | } |
397 | deRegisterAlarm(); | 399 | deRegisterAlarm(); |
398 | mNextAlarmIncidence = 0; | 400 | mNextAlarmIncidence = 0; |
399 | checkAlarmForIncidence( 0, false ); | 401 | checkAlarmForIncidence( 0, false ); |
400 | 402 | ||
401 | } | 403 | } |
402 | 404 | ||
403 | 405 | ||
404 | 406 | ||
405 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 407 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
406 | { | 408 | { |
407 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 409 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
408 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 410 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
409 | QDateTime next; | 411 | QDateTime next; |
410 | Event *e; | 412 | Event *e; |
411 | bool ok; | 413 | bool ok; |
412 | bool found = false; | 414 | bool found = false; |
413 | int offset; | 415 | int offset; |
414 | mNextAlarmIncidence = 0; | 416 | mNextAlarmIncidence = 0; |
415 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 417 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
416 | next = e->getNextAlarmDateTime(& ok, &offset ) ; | 418 | next = e->getNextAlarmDateTime(& ok, &offset ) ; |
417 | if ( ok ) { | 419 | if ( ok ) { |
418 | if ( next < nextA ) { | 420 | if ( next < nextA ) { |
419 | nextA = next; | 421 | nextA = next; |
420 | found = true; | 422 | found = true; |
421 | mNextSummary = e->summary(); | 423 | mNextSummary = e->summary(); |
422 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 424 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
423 | mNextAlarmIncidence = (Incidence *) e; | 425 | mNextAlarmIncidence = (Incidence *) e; |
424 | } | 426 | } |
425 | } | 427 | } |
426 | } | 428 | } |
427 | Todo *t; | 429 | Todo *t; |
428 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 430 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
429 | next = t->getNextAlarmDateTime(& ok, &offset ) ; | 431 | next = t->getNextAlarmDateTime(& ok, &offset ) ; |
430 | if ( ok ) { | 432 | if ( ok ) { |
431 | if ( next < nextA ) { | 433 | if ( next < nextA ) { |
432 | nextA = next; | 434 | nextA = next; |
433 | found = true; | 435 | found = true; |
434 | mNextSummary = t->summary(); | 436 | mNextSummary = t->summary(); |
435 | mNextAlarmEventDateTime = next.addSecs(offset ); | 437 | mNextAlarmEventDateTime = next.addSecs(offset ); |
436 | mNextAlarmIncidence = (Incidence *) t; | 438 | mNextAlarmIncidence = (Incidence *) t; |
437 | } | 439 | } |
438 | } | 440 | } |
439 | } | 441 | } |
440 | if ( mNextAlarmIncidence ) { | 442 | if ( mNextAlarmIncidence ) { |
441 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 443 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
442 | mNextAlarmDateTime = nextA; | 444 | mNextAlarmDateTime = nextA; |
443 | } | 445 | } |
444 | return nextA; | 446 | return nextA; |
445 | } | 447 | } |
446 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 448 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
447 | { | 449 | { |
448 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 450 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
449 | } | 451 | } |
450 | 452 | ||
451 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 453 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
452 | { | 454 | { |
453 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 455 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " |
454 | << to.toString() << ")\n"; | 456 | << to.toString() << ")\n"; |
455 | 457 | ||
456 | Alarm::List alarms; | 458 | Alarm::List alarms; |
457 | 459 | ||
458 | Event *e; | 460 | Event *e; |
459 | 461 | ||
460 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 462 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
461 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 463 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
462 | else appendAlarms( alarms, e, from, to ); | 464 | else appendAlarms( alarms, e, from, to ); |
463 | } | 465 | } |
464 | 466 | ||
465 | Todo *t; | 467 | Todo *t; |
466 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 468 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
467 | appendAlarms( alarms, t, from, to ); | 469 | appendAlarms( alarms, t, from, to ); |
468 | } | 470 | } |
469 | 471 | ||
470 | return alarms; | 472 | return alarms; |
471 | } | 473 | } |
472 | 474 | ||
473 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 475 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
474 | const QDateTime &from, const QDateTime &to ) | 476 | const QDateTime &from, const QDateTime &to ) |
475 | { | 477 | { |
476 | QPtrList<Alarm> alarmList = incidence->alarms(); | 478 | QPtrList<Alarm> alarmList = incidence->alarms(); |
477 | Alarm *alarm; | 479 | Alarm *alarm; |
478 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 480 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
479 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 481 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
480 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 482 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
481 | if ( alarm->enabled() ) { | 483 | if ( alarm->enabled() ) { |
482 | if ( alarm->time() >= from && alarm->time() <= to ) { | 484 | if ( alarm->time() >= from && alarm->time() <= to ) { |
483 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | 485 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() |
484 | << "': " << alarm->time().toString() << endl; | 486 | << "': " << alarm->time().toString() << endl; |
485 | alarms.append( alarm ); | 487 | alarms.append( alarm ); |
486 | } | 488 | } |
487 | } | 489 | } |
488 | } | 490 | } |
489 | } | 491 | } |
490 | 492 | ||
491 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 493 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
492 | Incidence *incidence, | 494 | Incidence *incidence, |
493 | const QDateTime &from, | 495 | const QDateTime &from, |
494 | const QDateTime &to ) | 496 | const QDateTime &to ) |
495 | { | 497 | { |
496 | 498 | ||
497 | QPtrList<Alarm> alarmList = incidence->alarms(); | 499 | QPtrList<Alarm> alarmList = incidence->alarms(); |
498 | Alarm *alarm; | 500 | Alarm *alarm; |
499 | QDateTime qdt; | 501 | QDateTime qdt; |
500 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
501 | if (incidence->recursOn(from.date())) { | 503 | if (incidence->recursOn(from.date())) { |
502 | qdt.setTime(alarm->time().time()); | 504 | qdt.setTime(alarm->time().time()); |
503 | qdt.setDate(from.date()); | 505 | qdt.setDate(from.date()); |
504 | } | 506 | } |
505 | else qdt = alarm->time(); | 507 | else qdt = alarm->time(); |
506 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
507 | if ( alarm->enabled() ) { | 509 | if ( alarm->enabled() ) { |
508 | if ( qdt >= from && qdt <= to ) { | 510 | if ( qdt >= from && qdt <= to ) { |
509 | alarms.append( alarm ); | 511 | alarms.append( alarm ); |
510 | } | 512 | } |
511 | } | 513 | } |
512 | } | 514 | } |
513 | } | 515 | } |
514 | 516 | ||
515 | 517 | ||
516 | /****************************** PROTECTED METHODS ****************************/ | 518 | /****************************** PROTECTED METHODS ****************************/ |
517 | 519 | ||
518 | // after changes are made to an event, this should be called. | 520 | // after changes are made to an event, this should be called. |
519 | void CalendarLocal::update( IncidenceBase *incidence ) | 521 | void CalendarLocal::update( IncidenceBase *incidence ) |
520 | { | 522 | { |
521 | incidence->setSyncStatus( Event::SYNCMOD ); | 523 | incidence->setSyncStatus( Event::SYNCMOD ); |
522 | incidence->setLastModified( QDateTime::currentDateTime() ); | 524 | incidence->setLastModified( QDateTime::currentDateTime() ); |
523 | // we should probably update the revision number here, | 525 | // we should probably update the revision number here, |
524 | // or internally in the Event itself when certain things change. | 526 | // or internally in the Event itself when certain things change. |
525 | // need to verify with ical documentation. | 527 | // need to verify with ical documentation. |
526 | 528 | ||
527 | setModified( true ); | 529 | setModified( true ); |
528 | } | 530 | } |
529 | 531 | ||
530 | void CalendarLocal::insertEvent( Event *event ) | 532 | void CalendarLocal::insertEvent( Event *event ) |
531 | { | 533 | { |
532 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
533 | } | 535 | } |
534 | 536 | ||
535 | 537 | ||
536 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
537 | { | 539 | { |
538 | QPtrList<Event> eventList; | 540 | QPtrList<Event> eventList; |
539 | 541 | ||
540 | Event *event; | 542 | Event *event; |
541 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 543 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
542 | if ( event->doesRecur() ) { | 544 | if ( event->doesRecur() ) { |
543 | if ( event->isMultiDay() ) { | 545 | if ( event->isMultiDay() ) { |
544 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
545 | int i; | 547 | int i; |
546 | for ( i = 0; i <= extraDays; i++ ) { | 548 | for ( i = 0; i <= extraDays; i++ ) { |
547 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 549 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
548 | eventList.append( event ); | 550 | eventList.append( event ); |
549 | break; | 551 | break; |
550 | } | 552 | } |
551 | } | 553 | } |
552 | } else { | 554 | } else { |
553 | if ( event->recursOn( qd ) ) | 555 | if ( event->recursOn( qd ) ) |
554 | eventList.append( event ); | 556 | eventList.append( event ); |
555 | } | 557 | } |
556 | } else { | 558 | } else { |
557 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
558 | eventList.append( event ); | 560 | eventList.append( event ); |
559 | } | 561 | } |
560 | } | 562 | } |
561 | } | 563 | } |
562 | 564 | ||
563 | if ( !sorted ) { | 565 | if ( !sorted ) { |
564 | return eventList; | 566 | return eventList; |
565 | } | 567 | } |
566 | 568 | ||
567 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 569 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
568 | // now, we have to sort it based on dtStart.time() | 570 | // now, we have to sort it based on dtStart.time() |
569 | QPtrList<Event> eventListSorted; | 571 | QPtrList<Event> eventListSorted; |
570 | Event *sortEvent; | 572 | Event *sortEvent; |
571 | for ( event = eventList.first(); event; event = eventList.next() ) { | 573 | for ( event = eventList.first(); event; event = eventList.next() ) { |
572 | sortEvent = eventListSorted.first(); | 574 | sortEvent = eventListSorted.first(); |
573 | int i = 0; | 575 | int i = 0; |
574 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
575 | { | 577 | { |
576 | i++; | 578 | i++; |
577 | sortEvent = eventListSorted.next(); | 579 | sortEvent = eventListSorted.next(); |
578 | } | 580 | } |
579 | eventListSorted.insert( i, event ); | 581 | eventListSorted.insert( i, event ); |
580 | } | 582 | } |
581 | return eventListSorted; | 583 | return eventListSorted; |
582 | } | 584 | } |
583 | 585 | ||
584 | 586 | ||
585 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
586 | bool inclusive ) | 588 | bool inclusive ) |
587 | { | 589 | { |
588 | Event *event = 0; | 590 | Event *event = 0; |
589 | 591 | ||
590 | QPtrList<Event> eventList; | 592 | QPtrList<Event> eventList; |
591 | 593 | ||
592 | // Get non-recurring events | 594 | // Get non-recurring events |
593 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 595 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
594 | if ( event->doesRecur() ) { | 596 | if ( event->doesRecur() ) { |
595 | QDate rStart = event->dtStart().date(); | 597 | QDate rStart = event->dtStart().date(); |
596 | bool found = false; | 598 | bool found = false; |
597 | if ( inclusive ) { | 599 | if ( inclusive ) { |
598 | if ( rStart >= start && rStart <= end ) { | 600 | if ( rStart >= start && rStart <= end ) { |
599 | // Start date of event is in range. Now check for end date. | 601 | // Start date of event is in range. Now check for end date. |
600 | // if duration is negative, event recurs forever, so do not include it. | 602 | // if duration is negative, event recurs forever, so do not include it. |
601 | if ( event->recurrence()->duration() == 0 ) { // End date set | 603 | if ( event->recurrence()->duration() == 0 ) { // End date set |
602 | QDate rEnd = event->recurrence()->endDate(); | 604 | QDate rEnd = event->recurrence()->endDate(); |
603 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 605 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
604 | found = true; | 606 | found = true; |
605 | } | 607 | } |
606 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 608 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
607 | // TODO: Calculate end date from duration. Should be done in Event | 609 | // TODO: Calculate end date from duration. Should be done in Event |
608 | // For now exclude all events with a duration. | 610 | // For now exclude all events with a duration. |
609 | } | 611 | } |
610 | } | 612 | } |
611 | } else { | 613 | } else { |
612 | bool founOne; | 614 | bool founOne; |
613 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 615 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
614 | if ( founOne ) { | 616 | if ( founOne ) { |
615 | if ( next <= end ) { | 617 | if ( next <= end ) { |
616 | found = true; | 618 | found = true; |
617 | } | 619 | } |
618 | } | 620 | } |
619 | 621 | ||
620 | /* | 622 | /* |
621 | // crap !!! | 623 | // crap !!! |
622 | if ( rStart <= end ) { // Start date not after range | 624 | if ( rStart <= end ) { // Start date not after range |
623 | if ( rStart >= start ) { // Start date within range | 625 | if ( rStart >= start ) { // Start date within range |
624 | found = true; | 626 | found = true; |
625 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 627 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
626 | found = true; | 628 | found = true; |
627 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 629 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
628 | QDate rEnd = event->recurrence()->endDate(); | 630 | QDate rEnd = event->recurrence()->endDate(); |
629 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 631 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
630 | found = true; | 632 | found = true; |
631 | } | 633 | } |
632 | } else { // Duration set | 634 | } else { // Duration set |
633 | // TODO: Calculate end date from duration. Should be done in Event | 635 | // TODO: Calculate end date from duration. Should be done in Event |
634 | // For now include all events with a duration. | 636 | // For now include all events with a duration. |
635 | found = true; | 637 | found = true; |
636 | } | 638 | } |
637 | } | 639 | } |
638 | */ | 640 | */ |
639 | 641 | ||
640 | } | 642 | } |
641 | 643 | ||
642 | if ( found ) eventList.append( event ); | 644 | if ( found ) eventList.append( event ); |
643 | } else { | 645 | } else { |
644 | QDate s = event->dtStart().date(); | 646 | QDate s = event->dtStart().date(); |
645 | QDate e = event->dtEnd().date(); | 647 | QDate e = event->dtEnd().date(); |
646 | 648 | ||
647 | if ( inclusive ) { | 649 | if ( inclusive ) { |
648 | if ( s >= start && e <= end ) { | 650 | if ( s >= start && e <= end ) { |
649 | eventList.append( event ); | 651 | eventList.append( event ); |
650 | } | 652 | } |
651 | } else { | 653 | } else { |
652 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 654 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
653 | eventList.append( event ); | 655 | eventList.append( event ); |
654 | } | 656 | } |
655 | } | 657 | } |
656 | } | 658 | } |
657 | } | 659 | } |
658 | 660 | ||
659 | return eventList; | 661 | return eventList; |
660 | } | 662 | } |
661 | 663 | ||
662 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 664 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
663 | { | 665 | { |
664 | return rawEventsForDate( qdt.date() ); | 666 | return rawEventsForDate( qdt.date() ); |
665 | } | 667 | } |
666 | 668 | ||
667 | QPtrList<Event> CalendarLocal::rawEvents() | 669 | QPtrList<Event> CalendarLocal::rawEvents() |
668 | { | 670 | { |
669 | return mEventList; | 671 | return mEventList; |
670 | } | 672 | } |
671 | 673 | ||
672 | bool CalendarLocal::addJournal(Journal *journal) | 674 | bool CalendarLocal::addJournal(Journal *journal) |
673 | { | 675 | { |
674 | if ( journal->dtStart().isValid()) | 676 | if ( journal->dtStart().isValid()) |
675 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 677 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
676 | else | 678 | else |
677 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 679 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
678 | 680 | ||
679 | mJournalList.append(journal); | 681 | mJournalList.append(journal); |
680 | 682 | ||
681 | journal->registerObserver( this ); | 683 | journal->registerObserver( this ); |
682 | 684 | ||
683 | setModified( true ); | 685 | setModified( true ); |
684 | 686 | ||
685 | return true; | 687 | return true; |
686 | } | 688 | } |
687 | 689 | ||
688 | void CalendarLocal::deleteJournal( Journal *journal ) | 690 | void CalendarLocal::deleteJournal( Journal *journal ) |
689 | { | 691 | { |
692 | if ( mUndoIncidence ) delete mUndoIncidence; | ||
693 | mUndoIncidence = journal->clone(); | ||
694 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | ||
690 | if ( mJournalList.removeRef(journal) ) { | 695 | if ( mJournalList.removeRef(journal) ) { |
691 | setModified( true ); | 696 | setModified( true ); |
692 | } | 697 | } |
693 | } | 698 | } |
694 | 699 | ||
695 | Journal *CalendarLocal::journal( const QDate &date ) | 700 | Journal *CalendarLocal::journal( const QDate &date ) |
696 | { | 701 | { |
697 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 702 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
698 | 703 | ||
699 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 704 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
700 | if ( it->dtStart().date() == date ) | 705 | if ( it->dtStart().date() == date ) |
701 | return it; | 706 | return it; |
702 | 707 | ||
703 | return 0; | 708 | return 0; |
704 | } | 709 | } |
705 | 710 | ||
706 | Journal *CalendarLocal::journal( const QString &uid ) | 711 | Journal *CalendarLocal::journal( const QString &uid ) |
707 | { | 712 | { |
708 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 713 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
709 | if ( it->uid() == uid ) | 714 | if ( it->uid() == uid ) |
710 | return it; | 715 | return it; |
711 | 716 | ||
712 | return 0; | 717 | return 0; |
713 | } | 718 | } |
714 | 719 | ||
715 | QPtrList<Journal> CalendarLocal::journals() | 720 | QPtrList<Journal> CalendarLocal::journals() |
716 | { | 721 | { |
717 | return mJournalList; | 722 | return mJournalList; |
718 | } | 723 | } |
719 | 724 | ||
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 5a9ef0e..28402ae 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,603 +1,617 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | } | 42 | } |
43 | 43 | ||
44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 44 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
45 | { | 45 | { |
46 | // TODO: reenable attributes currently commented out. | 46 | // TODO: reenable attributes currently commented out. |
47 | mRevision = i.mRevision; | 47 | mRevision = i.mRevision; |
48 | mCreated = i.mCreated; | 48 | mCreated = i.mCreated; |
49 | mDescription = i.mDescription; | 49 | mDescription = i.mDescription; |
50 | mSummary = i.mSummary; | 50 | mSummary = i.mSummary; |
51 | mCategories = i.mCategories; | 51 | mCategories = i.mCategories; |
52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 52 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
53 | mRelatedTo = 0; | 53 | mRelatedTo = 0; |
54 | mRelatedToUid = i.mRelatedToUid; | 54 | mRelatedToUid = i.mRelatedToUid; |
55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 55 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
56 | mExDates = i.mExDates; | 56 | mExDates = i.mExDates; |
57 | mAttachments = i.mAttachments; | 57 | mAttachments = i.mAttachments; |
58 | mResources = i.mResources; | 58 | mResources = i.mResources; |
59 | mSecrecy = i.mSecrecy; | 59 | mSecrecy = i.mSecrecy; |
60 | mPriority = i.mPriority; | 60 | mPriority = i.mPriority; |
61 | mLocation = i.mLocation; | 61 | mLocation = i.mLocation; |
62 | mCancelled = i.mCancelled; | 62 | mCancelled = i.mCancelled; |
63 | mHasStartDate = i.mHasStartDate; | 63 | mHasStartDate = i.mHasStartDate; |
64 | QPtrListIterator<Alarm> it( i.mAlarms ); | 64 | QPtrListIterator<Alarm> it( i.mAlarms ); |
65 | const Alarm *a; | 65 | const Alarm *a; |
66 | while( (a = it.current()) ) { | 66 | while( (a = it.current()) ) { |
67 | Alarm *b = new Alarm( *a ); | 67 | Alarm *b = new Alarm( *a ); |
68 | b->setParent( this ); | 68 | b->setParent( this ); |
69 | mAlarms.append( b ); | 69 | mAlarms.append( b ); |
70 | 70 | ||
71 | ++it; | 71 | ++it; |
72 | } | 72 | } |
73 | mAlarms.setAutoDelete(true); | 73 | mAlarms.setAutoDelete(true); |
74 | 74 | ||
75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 75 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
76 | } | 76 | } |
77 | 77 | ||
78 | Incidence::~Incidence() | 78 | Incidence::~Incidence() |
79 | { | 79 | { |
80 | 80 | ||
81 | Incidence *ev; | 81 | Incidence *ev; |
82 | QPtrList<Incidence> Relations = relations(); | 82 | QPtrList<Incidence> Relations = relations(); |
83 | for (ev=Relations.first();ev;ev=Relations.next()) { | 83 | for (ev=Relations.first();ev;ev=Relations.next()) { |
84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 84 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
85 | } | 85 | } |
86 | if (relatedTo()) relatedTo()->removeRelation(this); | 86 | if (relatedTo()) relatedTo()->removeRelation(this); |
87 | delete mRecurrence; | 87 | delete mRecurrence; |
88 | 88 | ||
89 | } | 89 | } |
90 | 90 | ||
91 | bool Incidence::cancelled() const | 91 | bool Incidence::cancelled() const |
92 | { | 92 | { |
93 | return mCancelled; | 93 | return mCancelled; |
94 | } | 94 | } |
95 | void Incidence::setCancelled( bool b ) | 95 | void Incidence::setCancelled( bool b ) |
96 | { | 96 | { |
97 | mCancelled = b; | 97 | mCancelled = b; |
98 | updated(); | 98 | updated(); |
99 | } | 99 | } |
100 | bool Incidence::hasStartDate() const | 100 | bool Incidence::hasStartDate() const |
101 | { | 101 | { |
102 | return mHasStartDate; | 102 | return mHasStartDate; |
103 | } | 103 | } |
104 | 104 | ||
105 | void Incidence::setHasStartDate(bool f) | 105 | void Incidence::setHasStartDate(bool f) |
106 | { | 106 | { |
107 | if (mReadOnly) return; | 107 | if (mReadOnly) return; |
108 | mHasStartDate = f; | 108 | mHasStartDate = f; |
109 | updated(); | 109 | updated(); |
110 | } | 110 | } |
111 | 111 | ||
112 | // A string comparison that considers that null and empty are the same | 112 | // A string comparison that considers that null and empty are the same |
113 | static bool stringCompare( const QString& s1, const QString& s2 ) | 113 | static bool stringCompare( const QString& s1, const QString& s2 ) |
114 | { | 114 | { |
115 | if ( s1.isEmpty() && s2.isEmpty() ) | 115 | if ( s1.isEmpty() && s2.isEmpty() ) |
116 | return true; | 116 | return true; |
117 | return s1 == s2; | 117 | return s1 == s2; |
118 | } | 118 | } |
119 | 119 | ||
120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 120 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
121 | { | 121 | { |
122 | 122 | ||
123 | if( i1.alarms().count() != i2.alarms().count() ) { | 123 | if( i1.alarms().count() != i2.alarms().count() ) { |
124 | return false; // no need to check further | 124 | return false; // no need to check further |
125 | } | 125 | } |
126 | if ( i1.alarms().count() > 0 ) { | 126 | if ( i1.alarms().count() > 0 ) { |
127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 127 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
128 | { | 128 | { |
129 | qDebug("alarm not equal "); | 129 | qDebug("alarm not equal "); |
130 | return false; | 130 | return false; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | #if 0 | 133 | #if 0 |
134 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 134 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
135 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 135 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 136 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
137 | if( *a1.current() == *a2.current() ) { | 137 | if( *a1.current() == *a2.current() ) { |
138 | continue; | 138 | continue; |
139 | } | 139 | } |
140 | else { | 140 | else { |
141 | return false; | 141 | return false; |
142 | } | 142 | } |
143 | } | 143 | } |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 146 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
147 | return false; | 147 | return false; |
148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 148 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
149 | if ( i1.hasStartDate() ) { | 149 | if ( i1.hasStartDate() ) { |
150 | if ( i1.dtStart() != i2.dtStart() ) | 150 | if ( i1.dtStart() != i2.dtStart() ) |
151 | return false; | 151 | return false; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 156 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
157 | qDebug("recurrence is NOT equal "); | 157 | qDebug("recurrence is NOT equal "); |
158 | return false; | 158 | return false; |
159 | } | 159 | } |
160 | return | 160 | return |
161 | // i1.created() == i2.created() && | 161 | // i1.created() == i2.created() && |
162 | stringCompare( i1.description(), i2.description() ) && | 162 | stringCompare( i1.description(), i2.description() ) && |
163 | stringCompare( i1.summary(), i2.summary() ) && | 163 | stringCompare( i1.summary(), i2.summary() ) && |
164 | i1.categories() == i2.categories() && | 164 | i1.categories() == i2.categories() && |
165 | // no need to compare mRelatedTo | 165 | // no need to compare mRelatedTo |
166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 166 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
167 | // i1.relations() == i2.relations() && | 167 | // i1.relations() == i2.relations() && |
168 | i1.exDates() == i2.exDates() && | 168 | i1.exDates() == i2.exDates() && |
169 | i1.attachments() == i2.attachments() && | 169 | i1.attachments() == i2.attachments() && |
170 | i1.resources() == i2.resources() && | 170 | i1.resources() == i2.resources() && |
171 | i1.secrecy() == i2.secrecy() && | 171 | i1.secrecy() == i2.secrecy() && |
172 | i1.priority() == i2.priority() && | 172 | i1.priority() == i2.priority() && |
173 | stringCompare( i1.location(), i2.location() ); | 173 | stringCompare( i1.location(), i2.location() ); |
174 | } | 174 | } |
175 | 175 | ||
176 | Incidence* Incidence::recreateCloneException( QDate d ) | ||
177 | { | ||
178 | Incidence* newInc = clone(); | ||
179 | newInc->recreate(); | ||
180 | if ( doesRecur() ) { | ||
181 | addExDate( d ); | ||
182 | newInc->recurrence()->unsetRecurs(); | ||
183 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | ||
184 | QTime tim = dtStart().time(); | ||
185 | newInc->setDtStart( QDateTime(d, tim) ); | ||
186 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | ||
187 | } | ||
188 | return newInc; | ||
189 | } | ||
176 | 190 | ||
177 | void Incidence::recreate() | 191 | void Incidence::recreate() |
178 | { | 192 | { |
179 | setCreated(QDateTime::currentDateTime()); | 193 | setCreated(QDateTime::currentDateTime()); |
180 | 194 | ||
181 | setUid(CalFormat::createUniqueId()); | 195 | setUid(CalFormat::createUniqueId()); |
182 | 196 | ||
183 | setRevision(0); | 197 | setRevision(0); |
184 | setIDStr( ":" ); | 198 | setIDStr( ":" ); |
185 | setLastModified(QDateTime::currentDateTime()); | 199 | setLastModified(QDateTime::currentDateTime()); |
186 | } | 200 | } |
187 | 201 | ||
188 | void Incidence::setReadOnly( bool readOnly ) | 202 | void Incidence::setReadOnly( bool readOnly ) |
189 | { | 203 | { |
190 | IncidenceBase::setReadOnly( readOnly ); | 204 | IncidenceBase::setReadOnly( readOnly ); |
191 | recurrence()->setRecurReadOnly( readOnly); | 205 | recurrence()->setRecurReadOnly( readOnly); |
192 | } | 206 | } |
193 | 207 | ||
194 | void Incidence::setCreated(QDateTime created) | 208 | void Incidence::setCreated(QDateTime created) |
195 | { | 209 | { |
196 | if (mReadOnly) return; | 210 | if (mReadOnly) return; |
197 | mCreated = getEvenTime(created); | 211 | mCreated = getEvenTime(created); |
198 | } | 212 | } |
199 | 213 | ||
200 | QDateTime Incidence::created() const | 214 | QDateTime Incidence::created() const |
201 | { | 215 | { |
202 | return mCreated; | 216 | return mCreated; |
203 | } | 217 | } |
204 | 218 | ||
205 | void Incidence::setRevision(int rev) | 219 | void Incidence::setRevision(int rev) |
206 | { | 220 | { |
207 | if (mReadOnly) return; | 221 | if (mReadOnly) return; |
208 | mRevision = rev; | 222 | mRevision = rev; |
209 | 223 | ||
210 | updated(); | 224 | updated(); |
211 | } | 225 | } |
212 | 226 | ||
213 | int Incidence::revision() const | 227 | int Incidence::revision() const |
214 | { | 228 | { |
215 | return mRevision; | 229 | return mRevision; |
216 | } | 230 | } |
217 | 231 | ||
218 | void Incidence::setDtStart(const QDateTime &dtStart) | 232 | void Incidence::setDtStart(const QDateTime &dtStart) |
219 | { | 233 | { |
220 | 234 | ||
221 | QDateTime dt = getEvenTime(dtStart); | 235 | QDateTime dt = getEvenTime(dtStart); |
222 | recurrence()->setRecurStart( dt); | 236 | recurrence()->setRecurStart( dt); |
223 | IncidenceBase::setDtStart( dt ); | 237 | IncidenceBase::setDtStart( dt ); |
224 | } | 238 | } |
225 | 239 | ||
226 | void Incidence::setDescription(const QString &description) | 240 | void Incidence::setDescription(const QString &description) |
227 | { | 241 | { |
228 | if (mReadOnly) return; | 242 | if (mReadOnly) return; |
229 | mDescription = description; | 243 | mDescription = description; |
230 | updated(); | 244 | updated(); |
231 | } | 245 | } |
232 | 246 | ||
233 | QString Incidence::description() const | 247 | QString Incidence::description() const |
234 | { | 248 | { |
235 | return mDescription; | 249 | return mDescription; |
236 | } | 250 | } |
237 | 251 | ||
238 | 252 | ||
239 | void Incidence::setSummary(const QString &summary) | 253 | void Incidence::setSummary(const QString &summary) |
240 | { | 254 | { |
241 | if (mReadOnly) return; | 255 | if (mReadOnly) return; |
242 | mSummary = summary; | 256 | mSummary = summary; |
243 | updated(); | 257 | updated(); |
244 | } | 258 | } |
245 | 259 | ||
246 | QString Incidence::summary() const | 260 | QString Incidence::summary() const |
247 | { | 261 | { |
248 | return mSummary; | 262 | return mSummary; |
249 | } | 263 | } |
250 | 264 | ||
251 | void Incidence::setCategories(const QStringList &categories) | 265 | void Incidence::setCategories(const QStringList &categories) |
252 | { | 266 | { |
253 | if (mReadOnly) return; | 267 | if (mReadOnly) return; |
254 | mCategories = categories; | 268 | mCategories = categories; |
255 | updated(); | 269 | updated(); |
256 | } | 270 | } |
257 | 271 | ||
258 | // TODO: remove setCategories(QString) function | 272 | // TODO: remove setCategories(QString) function |
259 | void Incidence::setCategories(const QString &catStr) | 273 | void Incidence::setCategories(const QString &catStr) |
260 | { | 274 | { |
261 | if (mReadOnly) return; | 275 | if (mReadOnly) return; |
262 | mCategories.clear(); | 276 | mCategories.clear(); |
263 | 277 | ||
264 | if (catStr.isEmpty()) return; | 278 | if (catStr.isEmpty()) return; |
265 | 279 | ||
266 | mCategories = QStringList::split(",",catStr); | 280 | mCategories = QStringList::split(",",catStr); |
267 | 281 | ||
268 | QStringList::Iterator it; | 282 | QStringList::Iterator it; |
269 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 283 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
270 | *it = (*it).stripWhiteSpace(); | 284 | *it = (*it).stripWhiteSpace(); |
271 | } | 285 | } |
272 | 286 | ||
273 | updated(); | 287 | updated(); |
274 | } | 288 | } |
275 | 289 | ||
276 | QStringList Incidence::categories() const | 290 | QStringList Incidence::categories() const |
277 | { | 291 | { |
278 | return mCategories; | 292 | return mCategories; |
279 | } | 293 | } |
280 | 294 | ||
281 | QString Incidence::categoriesStr() | 295 | QString Incidence::categoriesStr() |
282 | { | 296 | { |
283 | return mCategories.join(","); | 297 | return mCategories.join(","); |
284 | } | 298 | } |
285 | 299 | ||
286 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 300 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
287 | { | 301 | { |
288 | if (mReadOnly) return; | 302 | if (mReadOnly) return; |
289 | mRelatedToUid = relatedToUid; | 303 | mRelatedToUid = relatedToUid; |
290 | } | 304 | } |
291 | 305 | ||
292 | QString Incidence::relatedToUid() const | 306 | QString Incidence::relatedToUid() const |
293 | { | 307 | { |
294 | return mRelatedToUid; | 308 | return mRelatedToUid; |
295 | } | 309 | } |
296 | 310 | ||
297 | void Incidence::setRelatedTo(Incidence *relatedTo) | 311 | void Incidence::setRelatedTo(Incidence *relatedTo) |
298 | { | 312 | { |
299 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 313 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
300 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 314 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
301 | if (mReadOnly || mRelatedTo == relatedTo) return; | 315 | if (mReadOnly || mRelatedTo == relatedTo) return; |
302 | if(mRelatedTo) { | 316 | if(mRelatedTo) { |
303 | // updated(); | 317 | // updated(); |
304 | mRelatedTo->removeRelation(this); | 318 | mRelatedTo->removeRelation(this); |
305 | } | 319 | } |
306 | mRelatedTo = relatedTo; | 320 | mRelatedTo = relatedTo; |
307 | if (mRelatedTo) mRelatedTo->addRelation(this); | 321 | if (mRelatedTo) mRelatedTo->addRelation(this); |
308 | } | 322 | } |
309 | 323 | ||
310 | Incidence *Incidence::relatedTo() const | 324 | Incidence *Incidence::relatedTo() const |
311 | { | 325 | { |
312 | return mRelatedTo; | 326 | return mRelatedTo; |
313 | } | 327 | } |
314 | 328 | ||
315 | QPtrList<Incidence> Incidence::relations() const | 329 | QPtrList<Incidence> Incidence::relations() const |
316 | { | 330 | { |
317 | return mRelations; | 331 | return mRelations; |
318 | } | 332 | } |
319 | 333 | ||
320 | void Incidence::addRelation(Incidence *event) | 334 | void Incidence::addRelation(Incidence *event) |
321 | { | 335 | { |
322 | if( mRelations.findRef( event ) == -1 ) { | 336 | if( mRelations.findRef( event ) == -1 ) { |
323 | mRelations.append(event); | 337 | mRelations.append(event); |
324 | //updated(); | 338 | //updated(); |
325 | } | 339 | } |
326 | } | 340 | } |
327 | 341 | ||
328 | void Incidence::removeRelation(Incidence *event) | 342 | void Incidence::removeRelation(Incidence *event) |
329 | { | 343 | { |
330 | 344 | ||
331 | mRelations.removeRef(event); | 345 | mRelations.removeRef(event); |
332 | 346 | ||
333 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 347 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
334 | } | 348 | } |
335 | 349 | ||
336 | bool Incidence::recursOn(const QDate &qd) const | 350 | bool Incidence::recursOn(const QDate &qd) const |
337 | { | 351 | { |
338 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 352 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
339 | else return false; | 353 | else return false; |
340 | } | 354 | } |
341 | 355 | ||
342 | void Incidence::setExDates(const DateList &exDates) | 356 | void Incidence::setExDates(const DateList &exDates) |
343 | { | 357 | { |
344 | if (mReadOnly) return; | 358 | if (mReadOnly) return; |
345 | mExDates = exDates; | 359 | mExDates = exDates; |
346 | 360 | ||
347 | recurrence()->setRecurExDatesCount(mExDates.count()); | 361 | recurrence()->setRecurExDatesCount(mExDates.count()); |
348 | 362 | ||
349 | updated(); | 363 | updated(); |
350 | } | 364 | } |
351 | 365 | ||
352 | void Incidence::addExDate(const QDate &date) | 366 | void Incidence::addExDate(const QDate &date) |
353 | { | 367 | { |
354 | if (mReadOnly) return; | 368 | if (mReadOnly) return; |
355 | mExDates.append(date); | 369 | mExDates.append(date); |
356 | 370 | ||
357 | recurrence()->setRecurExDatesCount(mExDates.count()); | 371 | recurrence()->setRecurExDatesCount(mExDates.count()); |
358 | 372 | ||
359 | updated(); | 373 | updated(); |
360 | } | 374 | } |
361 | 375 | ||
362 | DateList Incidence::exDates() const | 376 | DateList Incidence::exDates() const |
363 | { | 377 | { |
364 | return mExDates; | 378 | return mExDates; |
365 | } | 379 | } |
366 | 380 | ||
367 | bool Incidence::isException(const QDate &date) const | 381 | bool Incidence::isException(const QDate &date) const |
368 | { | 382 | { |
369 | DateList::ConstIterator it; | 383 | DateList::ConstIterator it; |
370 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 384 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
371 | if ( (*it) == date ) { | 385 | if ( (*it) == date ) { |
372 | return true; | 386 | return true; |
373 | } | 387 | } |
374 | } | 388 | } |
375 | 389 | ||
376 | return false; | 390 | return false; |
377 | } | 391 | } |
378 | 392 | ||
379 | void Incidence::addAttachment(Attachment *attachment) | 393 | void Incidence::addAttachment(Attachment *attachment) |
380 | { | 394 | { |
381 | if (mReadOnly || !attachment) return; | 395 | if (mReadOnly || !attachment) return; |
382 | mAttachments.append(attachment); | 396 | mAttachments.append(attachment); |
383 | updated(); | 397 | updated(); |
384 | } | 398 | } |
385 | 399 | ||
386 | void Incidence::deleteAttachment(Attachment *attachment) | 400 | void Incidence::deleteAttachment(Attachment *attachment) |
387 | { | 401 | { |
388 | mAttachments.removeRef(attachment); | 402 | mAttachments.removeRef(attachment); |
389 | } | 403 | } |
390 | 404 | ||
391 | void Incidence::deleteAttachments(const QString& mime) | 405 | void Incidence::deleteAttachments(const QString& mime) |
392 | { | 406 | { |
393 | Attachment *at = mAttachments.first(); | 407 | Attachment *at = mAttachments.first(); |
394 | while (at) { | 408 | while (at) { |
395 | if (at->mimeType() == mime) | 409 | if (at->mimeType() == mime) |
396 | mAttachments.remove(); | 410 | mAttachments.remove(); |
397 | else | 411 | else |
398 | at = mAttachments.next(); | 412 | at = mAttachments.next(); |
399 | } | 413 | } |
400 | } | 414 | } |
401 | 415 | ||
402 | QPtrList<Attachment> Incidence::attachments() const | 416 | QPtrList<Attachment> Incidence::attachments() const |
403 | { | 417 | { |
404 | return mAttachments; | 418 | return mAttachments; |
405 | } | 419 | } |
406 | 420 | ||
407 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 421 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
408 | { | 422 | { |
409 | QPtrList<Attachment> attachments; | 423 | QPtrList<Attachment> attachments; |
410 | QPtrListIterator<Attachment> it( mAttachments ); | 424 | QPtrListIterator<Attachment> it( mAttachments ); |
411 | Attachment *at; | 425 | Attachment *at; |
412 | while ( (at = it.current()) ) { | 426 | while ( (at = it.current()) ) { |
413 | if (at->mimeType() == mime) | 427 | if (at->mimeType() == mime) |
414 | attachments.append(at); | 428 | attachments.append(at); |
415 | ++it; | 429 | ++it; |
416 | } | 430 | } |
417 | 431 | ||
418 | return attachments; | 432 | return attachments; |
419 | } | 433 | } |
420 | 434 | ||
421 | void Incidence::setResources(const QStringList &resources) | 435 | void Incidence::setResources(const QStringList &resources) |
422 | { | 436 | { |
423 | if (mReadOnly) return; | 437 | if (mReadOnly) return; |
424 | mResources = resources; | 438 | mResources = resources; |
425 | updated(); | 439 | updated(); |
426 | } | 440 | } |
427 | 441 | ||
428 | QStringList Incidence::resources() const | 442 | QStringList Incidence::resources() const |
429 | { | 443 | { |
430 | return mResources; | 444 | return mResources; |
431 | } | 445 | } |
432 | 446 | ||
433 | 447 | ||
434 | void Incidence::setPriority(int priority) | 448 | void Incidence::setPriority(int priority) |
435 | { | 449 | { |
436 | if (mReadOnly) return; | 450 | if (mReadOnly) return; |
437 | mPriority = priority; | 451 | mPriority = priority; |
438 | updated(); | 452 | updated(); |
439 | } | 453 | } |
440 | 454 | ||
441 | int Incidence::priority() const | 455 | int Incidence::priority() const |
442 | { | 456 | { |
443 | return mPriority; | 457 | return mPriority; |
444 | } | 458 | } |
445 | 459 | ||
446 | void Incidence::setSecrecy(int sec) | 460 | void Incidence::setSecrecy(int sec) |
447 | { | 461 | { |
448 | if (mReadOnly) return; | 462 | if (mReadOnly) return; |
449 | mSecrecy = sec; | 463 | mSecrecy = sec; |
450 | updated(); | 464 | updated(); |
451 | } | 465 | } |
452 | 466 | ||
453 | int Incidence::secrecy() const | 467 | int Incidence::secrecy() const |
454 | { | 468 | { |
455 | return mSecrecy; | 469 | return mSecrecy; |
456 | } | 470 | } |
457 | 471 | ||
458 | QString Incidence::secrecyStr() const | 472 | QString Incidence::secrecyStr() const |
459 | { | 473 | { |
460 | return secrecyName(mSecrecy); | 474 | return secrecyName(mSecrecy); |
461 | } | 475 | } |
462 | 476 | ||
463 | QString Incidence::secrecyName(int secrecy) | 477 | QString Incidence::secrecyName(int secrecy) |
464 | { | 478 | { |
465 | switch (secrecy) { | 479 | switch (secrecy) { |
466 | case SecrecyPublic: | 480 | case SecrecyPublic: |
467 | return i18n("Public"); | 481 | return i18n("Public"); |
468 | break; | 482 | break; |
469 | case SecrecyPrivate: | 483 | case SecrecyPrivate: |
470 | return i18n("Private"); | 484 | return i18n("Private"); |
471 | break; | 485 | break; |
472 | case SecrecyConfidential: | 486 | case SecrecyConfidential: |
473 | return i18n("Confidential"); | 487 | return i18n("Confidential"); |
474 | break; | 488 | break; |
475 | default: | 489 | default: |
476 | return i18n("Undefined"); | 490 | return i18n("Undefined"); |
477 | break; | 491 | break; |
478 | } | 492 | } |
479 | } | 493 | } |
480 | 494 | ||
481 | QStringList Incidence::secrecyList() | 495 | QStringList Incidence::secrecyList() |
482 | { | 496 | { |
483 | QStringList list; | 497 | QStringList list; |
484 | list << secrecyName(SecrecyPublic); | 498 | list << secrecyName(SecrecyPublic); |
485 | list << secrecyName(SecrecyPrivate); | 499 | list << secrecyName(SecrecyPrivate); |
486 | list << secrecyName(SecrecyConfidential); | 500 | list << secrecyName(SecrecyConfidential); |
487 | 501 | ||
488 | return list; | 502 | return list; |
489 | } | 503 | } |
490 | 504 | ||
491 | 505 | ||
492 | QPtrList<Alarm> Incidence::alarms() const | 506 | QPtrList<Alarm> Incidence::alarms() const |
493 | { | 507 | { |
494 | return mAlarms; | 508 | return mAlarms; |
495 | } | 509 | } |
496 | 510 | ||
497 | Alarm* Incidence::newAlarm() | 511 | Alarm* Incidence::newAlarm() |
498 | { | 512 | { |
499 | Alarm* alarm = new Alarm(this); | 513 | Alarm* alarm = new Alarm(this); |
500 | mAlarms.append(alarm); | 514 | mAlarms.append(alarm); |
501 | // updated(); | 515 | // updated(); |
502 | return alarm; | 516 | return alarm; |
503 | } | 517 | } |
504 | 518 | ||
505 | void Incidence::addAlarm(Alarm *alarm) | 519 | void Incidence::addAlarm(Alarm *alarm) |
506 | { | 520 | { |
507 | mAlarms.append(alarm); | 521 | mAlarms.append(alarm); |
508 | updated(); | 522 | updated(); |
509 | } | 523 | } |
510 | 524 | ||
511 | void Incidence::removeAlarm(Alarm *alarm) | 525 | void Incidence::removeAlarm(Alarm *alarm) |
512 | { | 526 | { |
513 | mAlarms.removeRef(alarm); | 527 | mAlarms.removeRef(alarm); |
514 | updated(); | 528 | updated(); |
515 | } | 529 | } |
516 | 530 | ||
517 | void Incidence::clearAlarms() | 531 | void Incidence::clearAlarms() |
518 | { | 532 | { |
519 | mAlarms.clear(); | 533 | mAlarms.clear(); |
520 | updated(); | 534 | updated(); |
521 | } | 535 | } |
522 | 536 | ||
523 | bool Incidence::isAlarmEnabled() const | 537 | bool Incidence::isAlarmEnabled() const |
524 | { | 538 | { |
525 | Alarm* alarm; | 539 | Alarm* alarm; |
526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 540 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
527 | if (alarm->enabled()) | 541 | if (alarm->enabled()) |
528 | return true; | 542 | return true; |
529 | } | 543 | } |
530 | return false; | 544 | return false; |
531 | } | 545 | } |
532 | 546 | ||
533 | Recurrence *Incidence::recurrence() const | 547 | Recurrence *Incidence::recurrence() const |
534 | { | 548 | { |
535 | return mRecurrence; | 549 | return mRecurrence; |
536 | } | 550 | } |
537 | void Incidence::setRecurrence( Recurrence * r) | 551 | void Incidence::setRecurrence( Recurrence * r) |
538 | { | 552 | { |
539 | delete mRecurrence; | 553 | delete mRecurrence; |
540 | mRecurrence = r; | 554 | mRecurrence = r; |
541 | } | 555 | } |
542 | 556 | ||
543 | void Incidence::setLocation(const QString &location) | 557 | void Incidence::setLocation(const QString &location) |
544 | { | 558 | { |
545 | if (mReadOnly) return; | 559 | if (mReadOnly) return; |
546 | mLocation = location; | 560 | mLocation = location; |
547 | updated(); | 561 | updated(); |
548 | } | 562 | } |
549 | 563 | ||
550 | QString Incidence::location() const | 564 | QString Incidence::location() const |
551 | { | 565 | { |
552 | return mLocation; | 566 | return mLocation; |
553 | } | 567 | } |
554 | 568 | ||
555 | ushort Incidence::doesRecur() const | 569 | ushort Incidence::doesRecur() const |
556 | { | 570 | { |
557 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 571 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
558 | else return Recurrence::rNone; | 572 | else return Recurrence::rNone; |
559 | } | 573 | } |
560 | 574 | ||
561 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 575 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
562 | { | 576 | { |
563 | QDateTime incidenceStart = dt; | 577 | QDateTime incidenceStart = dt; |
564 | *ok = false; | 578 | *ok = false; |
565 | if ( doesRecur() ) { | 579 | if ( doesRecur() ) { |
566 | bool last; | 580 | bool last; |
567 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 581 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
568 | int count = 0; | 582 | int count = 0; |
569 | if ( !last ) { | 583 | if ( !last ) { |
570 | while ( !last ) { | 584 | while ( !last ) { |
571 | ++count; | 585 | ++count; |
572 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 586 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
573 | if ( recursOn( incidenceStart.date() ) ) { | 587 | if ( recursOn( incidenceStart.date() ) ) { |
574 | last = true; // exit while llop | 588 | last = true; // exit while llop |
575 | } else { | 589 | } else { |
576 | if ( last ) { // no alarm on last recurrence | 590 | if ( last ) { // no alarm on last recurrence |
577 | return QDateTime (); | 591 | return QDateTime (); |
578 | } | 592 | } |
579 | int year = incidenceStart.date().year(); | 593 | int year = incidenceStart.date().year(); |
580 | // workaround for bug in recurrence | 594 | // workaround for bug in recurrence |
581 | if ( count == 100 || year < 1980 || year > 5000 ) { | 595 | if ( count == 100 || year < 1980 || year > 5000 ) { |
582 | return QDateTime (); | 596 | return QDateTime (); |
583 | } | 597 | } |
584 | incidenceStart = incidenceStart.addSecs( 1 ); | 598 | incidenceStart = incidenceStart.addSecs( 1 ); |
585 | } | 599 | } |
586 | } | 600 | } |
587 | } else { | 601 | } else { |
588 | return QDateTime (); | 602 | return QDateTime (); |
589 | } | 603 | } |
590 | } else { | 604 | } else { |
591 | if ( hasStartDate () ) { | 605 | if ( hasStartDate () ) { |
592 | incidenceStart = dtStart(); | 606 | incidenceStart = dtStart(); |
593 | } | 607 | } |
594 | if ( type() =="Todo" ) { | 608 | if ( type() =="Todo" ) { |
595 | if ( ((Todo*)this)->hasDueDate() ) | 609 | if ( ((Todo*)this)->hasDueDate() ) |
596 | incidenceStart = ((Todo*)this)->dtDue(); | 610 | incidenceStart = ((Todo*)this)->dtDue(); |
597 | 611 | ||
598 | } | 612 | } |
599 | } | 613 | } |
600 | if ( incidenceStart > dt ) | 614 | if ( incidenceStart > dt ) |
601 | *ok = true; | 615 | *ok = true; |
602 | return incidenceStart; | 616 | return incidenceStart; |
603 | } | 617 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 7dc6f10..1807bc4 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -1,298 +1,299 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef INCIDENCE_H | 20 | #ifndef INCIDENCE_H |
21 | #define INCIDENCE_H | 21 | #define INCIDENCE_H |
22 | // | 22 | // |
23 | // Incidence - base class of calendaring components | 23 | // Incidence - base class of calendaring components |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include "recurrence.h" | 30 | #include "recurrence.h" |
31 | #include "alarm.h" | 31 | #include "alarm.h" |
32 | #include "attachment.h" | 32 | #include "attachment.h" |
33 | #include "listbase.h" | 33 | #include "listbase.h" |
34 | #include "incidencebase.h" | 34 | #include "incidencebase.h" |
35 | 35 | ||
36 | namespace KCal { | 36 | namespace KCal { |
37 | 37 | ||
38 | class Event; | 38 | class Event; |
39 | class Todo; | 39 | class Todo; |
40 | class Journal; | 40 | class Journal; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | This class provides the base class common to all calendar components. | 43 | This class provides the base class common to all calendar components. |
44 | */ | 44 | */ |
45 | class Incidence : public IncidenceBase | 45 | class Incidence : public IncidenceBase |
46 | { | 46 | { |
47 | public: | 47 | public: |
48 | /** | 48 | /** |
49 | This class provides the interface for a visitor of calendar components. It | 49 | This class provides the interface for a visitor of calendar components. It |
50 | serves as base class for concrete visitors, which implement certain actions on | 50 | serves as base class for concrete visitors, which implement certain actions on |
51 | calendar components. It allows to add functions, which operate on the concrete | 51 | calendar components. It allows to add functions, which operate on the concrete |
52 | types of calendar components, without changing the calendar component classes. | 52 | types of calendar components, without changing the calendar component classes. |
53 | */ | 53 | */ |
54 | class Visitor | 54 | class Visitor |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | /** Destruct Incidence::Visitor */ | 57 | /** Destruct Incidence::Visitor */ |
58 | virtual ~Visitor() {} | 58 | virtual ~Visitor() {} |
59 | 59 | ||
60 | /** | 60 | /** |
61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
62 | on an Event object. | 62 | on an Event object. |
63 | */ | 63 | */ |
64 | virtual bool visit(Event *) { return false; } | 64 | virtual bool visit(Event *) { return false; } |
65 | /** | 65 | /** |
66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
67 | on an Todo object. | 67 | on an Todo object. |
68 | */ | 68 | */ |
69 | virtual bool visit(Todo *) { return false; } | 69 | virtual bool visit(Todo *) { return false; } |
70 | /** | 70 | /** |
71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
72 | on an Journal object. | 72 | on an Journal object. |
73 | */ | 73 | */ |
74 | virtual bool visit(Journal *) { return false; } | 74 | virtual bool visit(Journal *) { return false; } |
75 | 75 | ||
76 | protected: | 76 | protected: |
77 | /** Constructor is protected to prevent direct creation of visitor base class. */ | 77 | /** Constructor is protected to prevent direct creation of visitor base class. */ |
78 | Visitor() {} | 78 | Visitor() {} |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | This class implements a visitor for adding an Incidence to a resource | 82 | This class implements a visitor for adding an Incidence to a resource |
83 | supporting addEvent(), addTodo() and addJournal() calls. | 83 | supporting addEvent(), addTodo() and addJournal() calls. |
84 | */ | 84 | */ |
85 | template<class T> | 85 | template<class T> |
86 | class AddVisitor : public Visitor | 86 | class AddVisitor : public Visitor |
87 | { | 87 | { |
88 | public: | 88 | public: |
89 | AddVisitor( T *r ) : mResource( r ) {} | 89 | AddVisitor( T *r ) : mResource( r ) {} |
90 | bool visit( Event *e ) { return mResource->addEvent( e ); } | 90 | bool visit( Event *e ) { return mResource->addEvent( e ); } |
91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } | 91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } |
92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } | 92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } |
93 | 93 | ||
94 | private: | 94 | private: |
95 | T *mResource; | 95 | T *mResource; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | /** enumeration for describing an event's secrecy. */ | 98 | /** enumeration for describing an event's secrecy. */ |
99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; | 99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; |
100 | typedef ListBase<Incidence> List; | 100 | typedef ListBase<Incidence> List; |
101 | Incidence(); | 101 | Incidence(); |
102 | Incidence(const Incidence &); | 102 | Incidence(const Incidence &); |
103 | ~Incidence(); | 103 | ~Incidence(); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to | 106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to |
107 | provide this implementation: | 107 | provide this implementation: |
108 | <pre> | 108 | <pre> |
109 | bool accept(Visitor &v) { return v.visit(this); } | 109 | bool accept(Visitor &v) { return v.visit(this); } |
110 | </pre> | 110 | </pre> |
111 | */ | 111 | */ |
112 | virtual bool accept(Visitor &) { return false; } | 112 | virtual bool accept(Visitor &) { return false; } |
113 | 113 | ||
114 | virtual Incidence *clone() = 0; | 114 | virtual Incidence *clone() = 0; |
115 | 115 | ||
116 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; | 116 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset ) const = 0; |
117 | void setReadOnly( bool ); | 117 | void setReadOnly( bool ); |
118 | 118 | ||
119 | /** | 119 | /** |
120 | Recreate event. The event is made a new unique event, but already stored | 120 | Recreate event. The event is made a new unique event, but already stored |
121 | event information is preserved. Sets uniquie id, creation date, last | 121 | event information is preserved. Sets uniquie id, creation date, last |
122 | modification date and revision number. | 122 | modification date and revision number. |
123 | */ | 123 | */ |
124 | void recreate(); | 124 | void recreate(); |
125 | Incidence* recreateCloneException(QDate); | ||
125 | 126 | ||
126 | /** set creation date */ | 127 | /** set creation date */ |
127 | void setCreated(QDateTime); | 128 | void setCreated(QDateTime); |
128 | /** return time and date of creation. */ | 129 | /** return time and date of creation. */ |
129 | QDateTime created() const; | 130 | QDateTime created() const; |
130 | 131 | ||
131 | /** set the number of revisions this event has seen */ | 132 | /** set the number of revisions this event has seen */ |
132 | void setRevision(int rev); | 133 | void setRevision(int rev); |
133 | /** return the number of revisions this event has seen */ | 134 | /** return the number of revisions this event has seen */ |
134 | int revision() const; | 135 | int revision() const; |
135 | 136 | ||
136 | /** Set starting date/time. */ | 137 | /** Set starting date/time. */ |
137 | virtual void setDtStart(const QDateTime &dtStart); | 138 | virtual void setDtStart(const QDateTime &dtStart); |
138 | /** Return the incidence's ending date/time as a QDateTime. */ | 139 | /** Return the incidence's ending date/time as a QDateTime. */ |
139 | virtual QDateTime dtEnd() const { return QDateTime(); } | 140 | virtual QDateTime dtEnd() const { return QDateTime(); } |
140 | 141 | ||
141 | /** sets the event's lengthy description. */ | 142 | /** sets the event's lengthy description. */ |
142 | void setDescription(const QString &description); | 143 | void setDescription(const QString &description); |
143 | /** returns a reference to the event's description. */ | 144 | /** returns a reference to the event's description. */ |
144 | QString description() const; | 145 | QString description() const; |
145 | 146 | ||
146 | /** sets the event's short summary. */ | 147 | /** sets the event's short summary. */ |
147 | void setSummary(const QString &summary); | 148 | void setSummary(const QString &summary); |
148 | /** returns a reference to the event's summary. */ | 149 | /** returns a reference to the event's summary. */ |
149 | QString summary() const; | 150 | QString summary() const; |
150 | 151 | ||
151 | /** set event's applicable categories */ | 152 | /** set event's applicable categories */ |
152 | void setCategories(const QStringList &categories); | 153 | void setCategories(const QStringList &categories); |
153 | /** set event's categories based on a comma delimited string */ | 154 | /** set event's categories based on a comma delimited string */ |
154 | void setCategories(const QString &catStr); | 155 | void setCategories(const QString &catStr); |
155 | /** return categories in a list */ | 156 | /** return categories in a list */ |
156 | QStringList categories() const; | 157 | QStringList categories() const; |
157 | /** return categories as a comma separated string */ | 158 | /** return categories as a comma separated string */ |
158 | QString categoriesStr(); | 159 | QString categoriesStr(); |
159 | 160 | ||
160 | /** point at some other event to which the event relates. This function should | 161 | /** point at some other event to which the event relates. This function should |
161 | * only be used when constructing a calendar before the related Event | 162 | * only be used when constructing a calendar before the related Event |
162 | * exists. */ | 163 | * exists. */ |
163 | void setRelatedToUid(const QString &); | 164 | void setRelatedToUid(const QString &); |
164 | /** what event does this one relate to? This function should | 165 | /** what event does this one relate to? This function should |
165 | * only be used when constructing a calendar before the related Event | 166 | * only be used when constructing a calendar before the related Event |
166 | * exists. */ | 167 | * exists. */ |
167 | QString relatedToUid() const; | 168 | QString relatedToUid() const; |
168 | /** point at some other event to which the event relates */ | 169 | /** point at some other event to which the event relates */ |
169 | void setRelatedTo(Incidence *relatedTo); | 170 | void setRelatedTo(Incidence *relatedTo); |
170 | /** what event does this one relate to? */ | 171 | /** what event does this one relate to? */ |
171 | Incidence *relatedTo() const; | 172 | Incidence *relatedTo() const; |
172 | /** All events that are related to this event */ | 173 | /** All events that are related to this event */ |
173 | QPtrList<Incidence> relations() const; | 174 | QPtrList<Incidence> relations() const; |
174 | /** Add an event which is related to this event */ | 175 | /** Add an event which is related to this event */ |
175 | void addRelation(Incidence *); | 176 | void addRelation(Incidence *); |
176 | /** Remove event that is related to this event */ | 177 | /** Remove event that is related to this event */ |
177 | void removeRelation(Incidence *); | 178 | void removeRelation(Incidence *); |
178 | 179 | ||
179 | /** returns the list of dates which are exceptions to the recurrence rule */ | 180 | /** returns the list of dates which are exceptions to the recurrence rule */ |
180 | DateList exDates() const; | 181 | DateList exDates() const; |
181 | /** sets the list of dates which are exceptions to the recurrence rule */ | 182 | /** sets the list of dates which are exceptions to the recurrence rule */ |
182 | void setExDates(const DateList &_exDates); | 183 | void setExDates(const DateList &_exDates); |
183 | void setExDates(const char *dates); | 184 | void setExDates(const char *dates); |
184 | /** Add a date to the list of exceptions of the recurrence rule. */ | 185 | /** Add a date to the list of exceptions of the recurrence rule. */ |
185 | void addExDate(const QDate &date); | 186 | void addExDate(const QDate &date); |
186 | 187 | ||
187 | /** returns true if there is an exception for this date in the recurrence | 188 | /** returns true if there is an exception for this date in the recurrence |
188 | rule set, or false otherwise. */ | 189 | rule set, or false otherwise. */ |
189 | bool isException(const QDate &qd) const; | 190 | bool isException(const QDate &qd) const; |
190 | 191 | ||
191 | /** add attachment to this event */ | 192 | /** add attachment to this event */ |
192 | void addAttachment(Attachment *attachment); | 193 | void addAttachment(Attachment *attachment); |
193 | /** remove and delete a specific attachment */ | 194 | /** remove and delete a specific attachment */ |
194 | void deleteAttachment(Attachment *attachment); | 195 | void deleteAttachment(Attachment *attachment); |
195 | /** remove and delete all attachments with this mime type */ | 196 | /** remove and delete all attachments with this mime type */ |
196 | void deleteAttachments(const QString& mime); | 197 | void deleteAttachments(const QString& mime); |
197 | /** return list of all associated attachments */ | 198 | /** return list of all associated attachments */ |
198 | QPtrList<Attachment> attachments() const; | 199 | QPtrList<Attachment> attachments() const; |
199 | /** find a list of attachments with this mime type */ | 200 | /** find a list of attachments with this mime type */ |
200 | QPtrList<Attachment> attachments(const QString& mime) const; | 201 | QPtrList<Attachment> attachments(const QString& mime) const; |
201 | 202 | ||
202 | /** sets the event's status the value specified. See the enumeration | 203 | /** sets the event's status the value specified. See the enumeration |
203 | * above for possible values. */ | 204 | * above for possible values. */ |
204 | void setSecrecy(int); | 205 | void setSecrecy(int); |
205 | /** return the event's secrecy. */ | 206 | /** return the event's secrecy. */ |
206 | int secrecy() const; | 207 | int secrecy() const; |
207 | /** return the event's secrecy in string format. */ | 208 | /** return the event's secrecy in string format. */ |
208 | QString secrecyStr() const; | 209 | QString secrecyStr() const; |
209 | /** return list of all availbale secrecy classes */ | 210 | /** return list of all availbale secrecy classes */ |
210 | static QStringList secrecyList(); | 211 | static QStringList secrecyList(); |
211 | /** return human-readable name of secrecy class */ | 212 | /** return human-readable name of secrecy class */ |
212 | static QString secrecyName(int); | 213 | static QString secrecyName(int); |
213 | 214 | ||
214 | /** returns TRUE if the date specified is one on which the event will | 215 | /** returns TRUE if the date specified is one on which the event will |
215 | * recur. */ | 216 | * recur. */ |
216 | bool recursOn(const QDate &qd) const; | 217 | bool recursOn(const QDate &qd) const; |
217 | 218 | ||
218 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 219 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
219 | 220 | ||
220 | /** set resources used, such as Office, Car, etc. */ | 221 | /** set resources used, such as Office, Car, etc. */ |
221 | void setResources(const QStringList &resources); | 222 | void setResources(const QStringList &resources); |
222 | /** return list of current resources */ | 223 | /** return list of current resources */ |
223 | QStringList resources() const; | 224 | QStringList resources() const; |
224 | 225 | ||
225 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 226 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
226 | void setPriority(int priority); | 227 | void setPriority(int priority); |
227 | /** get the event's priority */ | 228 | /** get the event's priority */ |
228 | int priority() const; | 229 | int priority() const; |
229 | 230 | ||
230 | /** All alarms that are associated with this incidence */ | 231 | /** All alarms that are associated with this incidence */ |
231 | QPtrList<Alarm> alarms() const; | 232 | QPtrList<Alarm> alarms() const; |
232 | /** Create a new alarm which is associated with this incidence */ | 233 | /** Create a new alarm which is associated with this incidence */ |
233 | Alarm* newAlarm(); | 234 | Alarm* newAlarm(); |
234 | /** Add an alarm which is associated with this incidence */ | 235 | /** Add an alarm which is associated with this incidence */ |
235 | void addAlarm(Alarm*); | 236 | void addAlarm(Alarm*); |
236 | /** Remove an alarm that is associated with this incidence */ | 237 | /** Remove an alarm that is associated with this incidence */ |
237 | void removeAlarm(Alarm*); | 238 | void removeAlarm(Alarm*); |
238 | /** Remove all alarms that are associated with this incidence */ | 239 | /** Remove all alarms that are associated with this incidence */ |
239 | void clearAlarms(); | 240 | void clearAlarms(); |
240 | /** return whether any alarm associated with this incidence is enabled */ | 241 | /** return whether any alarm associated with this incidence is enabled */ |
241 | bool isAlarmEnabled() const; | 242 | bool isAlarmEnabled() const; |
242 | 243 | ||
243 | /** | 244 | /** |
244 | Return the recurrence rule associated with this incidence. If there is | 245 | Return the recurrence rule associated with this incidence. If there is |
245 | none, returns an appropriate (non-0) object. | 246 | none, returns an appropriate (non-0) object. |
246 | */ | 247 | */ |
247 | Recurrence *recurrence() const; | 248 | Recurrence *recurrence() const; |
248 | void setRecurrence(Recurrence * r); | 249 | void setRecurrence(Recurrence * r); |
249 | /** | 250 | /** |
250 | Forward to Recurrence::doesRecur(). | 251 | Forward to Recurrence::doesRecur(). |
251 | */ | 252 | */ |
252 | ushort doesRecur() const; | 253 | ushort doesRecur() const; |
253 | 254 | ||
254 | /** set the event's/todo's location. Do _not_ use it with journal */ | 255 | /** set the event's/todo's location. Do _not_ use it with journal */ |
255 | void setLocation(const QString &location); | 256 | void setLocation(const QString &location); |
256 | /** return the event's/todo's location. Do _not_ use it with journal */ | 257 | /** return the event's/todo's location. Do _not_ use it with journal */ |
257 | QString location() const; | 258 | QString location() const; |
258 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 259 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
259 | bool hasStartDate() const; | 260 | bool hasStartDate() const; |
260 | /** sets the event's hasStartDate value. */ | 261 | /** sets the event's hasStartDate value. */ |
261 | void setHasStartDate(bool f); | 262 | void setHasStartDate(bool f); |
262 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 263 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
263 | bool cancelled() const; | 264 | bool cancelled() const; |
264 | void setCancelled( bool b ); | 265 | void setCancelled( bool b ); |
265 | 266 | ||
266 | protected: | 267 | protected: |
267 | QPtrList<Alarm> mAlarms; | 268 | QPtrList<Alarm> mAlarms; |
268 | private: | 269 | private: |
269 | int mRevision; | 270 | int mRevision; |
270 | bool mCancelled; | 271 | bool mCancelled; |
271 | 272 | ||
272 | // base components of jounal, event and todo | 273 | // base components of jounal, event and todo |
273 | QDateTime mCreated; | 274 | QDateTime mCreated; |
274 | QString mDescription; | 275 | QString mDescription; |
275 | QString mSummary; | 276 | QString mSummary; |
276 | QStringList mCategories; | 277 | QStringList mCategories; |
277 | Incidence *mRelatedTo; | 278 | Incidence *mRelatedTo; |
278 | QString mRelatedToUid; | 279 | QString mRelatedToUid; |
279 | QPtrList<Incidence> mRelations; | 280 | QPtrList<Incidence> mRelations; |
280 | DateList mExDates; | 281 | DateList mExDates; |
281 | QPtrList<Attachment> mAttachments; | 282 | QPtrList<Attachment> mAttachments; |
282 | QStringList mResources; | 283 | QStringList mResources; |
283 | bool mHasStartDate; // if todo has associated start date | 284 | bool mHasStartDate; // if todo has associated start date |
284 | 285 | ||
285 | int mSecrecy; | 286 | int mSecrecy; |
286 | int mPriority; // 1 = highest, 2 = less, etc. | 287 | int mPriority; // 1 = highest, 2 = less, etc. |
287 | 288 | ||
288 | //QPtrList<Alarm> mAlarms; | 289 | //QPtrList<Alarm> mAlarms; |
289 | Recurrence *mRecurrence; | 290 | Recurrence *mRecurrence; |
290 | 291 | ||
291 | QString mLocation; | 292 | QString mLocation; |
292 | }; | 293 | }; |
293 | 294 | ||
294 | bool operator==( const Incidence&, const Incidence& ); | 295 | bool operator==( const Incidence&, const Incidence& ); |
295 | 296 | ||
296 | } | 297 | } |
297 | 298 | ||
298 | #endif | 299 | #endif |