author | zautrix <zautrix> | 2005-06-13 13:57:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-13 13:57:22 (UTC) |
commit | 56de219c5ce910a470a01a0e5003d1a113837ef4 (patch) (unidiff) | |
tree | 3393cb306cec8dcdc05d6ed0fae3ae7d374f2794 /libkcal | |
parent | 4f3ff02932b39bf16b9692c3cb69c101a28b4616 (diff) | |
download | kdepimpi-56de219c5ce910a470a01a0e5003d1a113837ef4.zip kdepimpi-56de219c5ce910a470a01a0e5003d1a113837ef4.tar.gz kdepimpi-56de219c5ce910a470a01a0e5003d1a113837ef4.tar.bz2 |
fixxx
-rw-r--r-- | libkcal/alarm.cpp | 2 | ||||
-rw-r--r-- | libkcal/calendar.cpp | 54 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 56 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 |
5 files changed, 87 insertions, 27 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp index 0afa0a7..79e0464 100644 --- a/libkcal/alarm.cpp +++ b/libkcal/alarm.cpp | |||
@@ -1,481 +1,483 @@ | |||
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 | #include <kdebug.h> | 22 | #include <kdebug.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | 24 | ||
25 | #include "incidence.h" | 25 | #include "incidence.h" |
26 | #include "todo.h" | 26 | #include "todo.h" |
27 | 27 | ||
28 | #include "alarm.h" | 28 | #include "alarm.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | #include <qwidget.h> | 31 | #include <qwidget.h> |
32 | Alarm::Alarm(Incidence *parent) | 32 | Alarm::Alarm(Incidence *parent) |
33 | : mParent(parent), | 33 | : mParent(parent), |
34 | mType(Audio), | 34 | mType(Audio), |
35 | mDescription(""), // to make operator==() not fail | 35 | mDescription(""), // to make operator==() not fail |
36 | mFile(""), // to make operator==() not fail | 36 | mFile(""), // to make operator==() not fail |
37 | mMailSubject(""), // to make operator==() not fail | 37 | mMailSubject(""), // to make operator==() not fail |
38 | mAlarmSnoozeTime(5), | 38 | mAlarmSnoozeTime(5), |
39 | mAlarmRepeatCount(0), | 39 | mAlarmRepeatCount(0), |
40 | mEndOffset(false), | 40 | mEndOffset(false), |
41 | mHasTime(false), | 41 | mHasTime(false), |
42 | mAlarmEnabled(false) | 42 | mAlarmEnabled(false) |
43 | { | 43 | { |
44 | 44 | ||
45 | } | 45 | } |
46 | 46 | ||
47 | Alarm::~Alarm() | 47 | Alarm::~Alarm() |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
51 | bool Alarm::operator==( const Alarm& rhs ) const | 51 | bool Alarm::operator==( const Alarm& rhs ) const |
52 | { | 52 | { |
53 | 53 | ||
54 | if ( mType != rhs.mType || | 54 | if ( mType != rhs.mType || |
55 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || | 55 | mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || |
56 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || | 56 | mAlarmRepeatCount != rhs.mAlarmRepeatCount || |
57 | mAlarmEnabled != rhs.mAlarmEnabled || | 57 | mAlarmEnabled != rhs.mAlarmEnabled || |
58 | mHasTime != rhs.mHasTime) | 58 | mHasTime != rhs.mHasTime) |
59 | return false; | 59 | return false; |
60 | 60 | ||
61 | #if 0 | 61 | #if 0 |
62 | if ( mType != rhs.mType ) { | 62 | if ( mType != rhs.mType ) { |
63 | 63 | ||
64 | qDebug("aaa1 "); | 64 | qDebug("aaa1 "); |
65 | return false; | 65 | return false; |
66 | } | 66 | } |
67 | 67 | ||
68 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { | 68 | if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { |
69 | 69 | ||
70 | qDebug("aaa2 "); | 70 | qDebug("aaa2 "); |
71 | return false; | 71 | return false; |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { | 75 | if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { |
76 | 76 | ||
77 | qDebug("aaa3 "); | 77 | qDebug("aaa3 "); |
78 | return false; | 78 | return false; |
79 | } | 79 | } |
80 | 80 | ||
81 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { | 81 | if ( mAlarmEnabled != rhs.mAlarmEnabled ) { |
82 | 82 | ||
83 | qDebug("aaa4 "); | 83 | qDebug("aaa4 "); |
84 | return false; | 84 | return false; |
85 | } | 85 | } |
86 | 86 | ||
87 | if ( mHasTime != rhs.mHasTime ) { | 87 | if ( mHasTime != rhs.mHasTime ) { |
88 | 88 | ||
89 | qDebug("aaa5 "); | 89 | qDebug("aaa5 "); |
90 | return false; | 90 | return false; |
91 | } | 91 | } |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | 94 | ||
95 | if (mHasTime) { | 95 | if (mHasTime) { |
96 | if (mAlarmTime != rhs.mAlarmTime) | 96 | if (mAlarmTime != rhs.mAlarmTime) |
97 | return false; | 97 | return false; |
98 | } else { | 98 | } else { |
99 | if (mOffset != rhs.mOffset || | 99 | if (mOffset != rhs.mOffset || |
100 | mEndOffset != rhs.mEndOffset) | 100 | mEndOffset != rhs.mEndOffset) |
101 | return false; | 101 | return false; |
102 | } | 102 | } |
103 | switch (mType) { | 103 | switch (mType) { |
104 | case Display: | 104 | case Display: |
105 | return mDescription == rhs.mDescription; | 105 | return mDescription == rhs.mDescription; |
106 | 106 | ||
107 | case Email: | 107 | case Email: |
108 | return mDescription == rhs.mDescription && | 108 | return mDescription == rhs.mDescription && |
109 | mMailAttachFiles == rhs.mMailAttachFiles && | 109 | mMailAttachFiles == rhs.mMailAttachFiles && |
110 | mMailAddresses == rhs.mMailAddresses && | 110 | mMailAddresses == rhs.mMailAddresses && |
111 | mMailSubject == rhs.mMailSubject; | 111 | mMailSubject == rhs.mMailSubject; |
112 | 112 | ||
113 | case Procedure: | 113 | case Procedure: |
114 | return mFile == rhs.mFile && | 114 | return mFile == rhs.mFile && |
115 | mDescription == rhs.mDescription; | 115 | mDescription == rhs.mDescription; |
116 | 116 | ||
117 | case Audio: | 117 | case Audio: |
118 | return mFile == rhs.mFile; | 118 | return mFile == rhs.mFile; |
119 | 119 | ||
120 | case Invalid: | 120 | case Invalid: |
121 | break; | 121 | break; |
122 | } | 122 | } |
123 | return false; | 123 | return false; |
124 | } | 124 | } |
125 | 125 | ||
126 | void Alarm::setType(Alarm::Type type) | 126 | void Alarm::setType(Alarm::Type type) |
127 | { | 127 | { |
128 | if (type == mType) | 128 | if (type == mType) |
129 | return; | 129 | return; |
130 | 130 | ||
131 | switch (type) { | 131 | switch (type) { |
132 | case Display: | 132 | case Display: |
133 | mDescription = ""; | 133 | mDescription = ""; |
134 | break; | 134 | break; |
135 | case Procedure: | 135 | case Procedure: |
136 | mFile = mDescription = ""; | 136 | mFile = mDescription = ""; |
137 | break; | 137 | break; |
138 | case Audio: | 138 | case Audio: |
139 | mFile = ""; | 139 | mFile = ""; |
140 | break; | 140 | break; |
141 | case Email: | 141 | case Email: |
142 | mMailSubject = mDescription = ""; | 142 | mMailSubject = mDescription = ""; |
143 | mMailAddresses.clear(); | 143 | mMailAddresses.clear(); |
144 | mMailAttachFiles.clear(); | 144 | mMailAttachFiles.clear(); |
145 | break; | 145 | break; |
146 | case Invalid: | 146 | case Invalid: |
147 | break; | 147 | break; |
148 | default: | 148 | default: |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | mType = type; | 151 | mType = type; |
152 | mParent->updated(); | 152 | mParent->updated(); |
153 | } | 153 | } |
154 | 154 | ||
155 | Alarm::Type Alarm::type() const | 155 | Alarm::Type Alarm::type() const |
156 | { | 156 | { |
157 | return mType; | 157 | return mType; |
158 | } | 158 | } |
159 | 159 | ||
160 | void Alarm::setAudioAlarm(const QString &audioFile) | 160 | void Alarm::setAudioAlarm(const QString &audioFile) |
161 | { | 161 | { |
162 | mType = Audio; | 162 | mType = Audio; |
163 | mFile = audioFile; | 163 | mFile = audioFile; |
164 | mParent->updated(); | 164 | mParent->updated(); |
165 | } | 165 | } |
166 | 166 | ||
167 | void Alarm::setAudioFile(const QString &audioFile) | 167 | void Alarm::setAudioFile(const QString &audioFile) |
168 | { | 168 | { |
169 | if (mType == Audio) { | 169 | if (mType == Audio) { |
170 | mFile = audioFile; | 170 | mFile = audioFile; |
171 | mParent->updated(); | 171 | mParent->updated(); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | QString Alarm::audioFile() const | 175 | QString Alarm::audioFile() const |
176 | { | 176 | { |
177 | return (mType == Audio) ? mFile : QString::null; | 177 | return (mType == Audio) ? mFile : QString::null; |
178 | } | 178 | } |
179 | 179 | ||
180 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) | 180 | void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) |
181 | { | 181 | { |
182 | mType = Procedure; | 182 | mType = Procedure; |
183 | mFile = programFile; | 183 | mFile = programFile; |
184 | mDescription = arguments; | 184 | mDescription = arguments; |
185 | mParent->updated(); | 185 | mParent->updated(); |
186 | } | 186 | } |
187 | 187 | ||
188 | void Alarm::setProgramFile(const QString &programFile) | 188 | void Alarm::setProgramFile(const QString &programFile) |
189 | { | 189 | { |
190 | if (mType == Procedure) { | 190 | if (mType == Procedure) { |
191 | mFile = programFile; | 191 | mFile = programFile; |
192 | mParent->updated(); | 192 | mParent->updated(); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | QString Alarm::programFile() const | 196 | QString Alarm::programFile() const |
197 | { | 197 | { |
198 | return (mType == Procedure) ? mFile : QString::null; | 198 | return (mType == Procedure) ? mFile : QString::null; |
199 | } | 199 | } |
200 | 200 | ||
201 | void Alarm::setProgramArguments(const QString &arguments) | 201 | void Alarm::setProgramArguments(const QString &arguments) |
202 | { | 202 | { |
203 | if (mType == Procedure) { | 203 | if (mType == Procedure) { |
204 | mDescription = arguments; | 204 | mDescription = arguments; |
205 | mParent->updated(); | 205 | mParent->updated(); |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | QString Alarm::programArguments() const | 209 | QString Alarm::programArguments() const |
210 | { | 210 | { |
211 | return (mType == Procedure) ? mDescription : QString::null; | 211 | return (mType == Procedure) ? mDescription : QString::null; |
212 | } | 212 | } |
213 | 213 | ||
214 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, | 214 | void Alarm::setEmailAlarm(const QString &subject, const QString &text, |
215 | const QValueList<Person> &addressees, const QStringList &attachments) | 215 | const QValueList<Person> &addressees, const QStringList &attachments) |
216 | { | 216 | { |
217 | mType = Email; | 217 | mType = Email; |
218 | mMailSubject = subject; | 218 | mMailSubject = subject; |
219 | mDescription = text; | 219 | mDescription = text; |
220 | mMailAddresses = addressees; | 220 | mMailAddresses = addressees; |
221 | mMailAttachFiles = attachments; | 221 | mMailAttachFiles = attachments; |
222 | mParent->updated(); | 222 | mParent->updated(); |
223 | } | 223 | } |
224 | 224 | ||
225 | void Alarm::setMailAddress(const Person &mailAddress) | 225 | void Alarm::setMailAddress(const Person &mailAddress) |
226 | { | 226 | { |
227 | if (mType == Email) { | 227 | if (mType == Email) { |
228 | mMailAddresses.clear(); | 228 | mMailAddresses.clear(); |
229 | mMailAddresses += mailAddress; | 229 | mMailAddresses += mailAddress; |
230 | mParent->updated(); | 230 | mParent->updated(); |
231 | } | 231 | } |
232 | } | 232 | } |
233 | 233 | ||
234 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) | 234 | void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) |
235 | { | 235 | { |
236 | if (mType == Email) { | 236 | if (mType == Email) { |
237 | mMailAddresses = mailAddresses; | 237 | mMailAddresses = mailAddresses; |
238 | mParent->updated(); | 238 | mParent->updated(); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | void Alarm::addMailAddress(const Person &mailAddress) | 242 | void Alarm::addMailAddress(const Person &mailAddress) |
243 | { | 243 | { |
244 | if (mType == Email) { | 244 | if (mType == Email) { |
245 | mMailAddresses += mailAddress; | 245 | mMailAddresses += mailAddress; |
246 | mParent->updated(); | 246 | mParent->updated(); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | 249 | ||
250 | QValueList<Person> Alarm::mailAddresses() const | 250 | QValueList<Person> Alarm::mailAddresses() const |
251 | { | 251 | { |
252 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); | 252 | return (mType == Email) ? mMailAddresses : QValueList<Person>(); |
253 | } | 253 | } |
254 | 254 | ||
255 | void Alarm::setMailSubject(const QString &mailAlarmSubject) | 255 | void Alarm::setMailSubject(const QString &mailAlarmSubject) |
256 | { | 256 | { |
257 | if (mType == Email) { | 257 | if (mType == Email) { |
258 | mMailSubject = mailAlarmSubject; | 258 | mMailSubject = mailAlarmSubject; |
259 | mParent->updated(); | 259 | mParent->updated(); |
260 | } | 260 | } |
261 | } | 261 | } |
262 | 262 | ||
263 | QString Alarm::mailSubject() const | 263 | QString Alarm::mailSubject() const |
264 | { | 264 | { |
265 | return (mType == Email) ? mMailSubject : QString::null; | 265 | return (mType == Email) ? mMailSubject : QString::null; |
266 | } | 266 | } |
267 | 267 | ||
268 | void Alarm::setMailAttachment(const QString &mailAttachFile) | 268 | void Alarm::setMailAttachment(const QString &mailAttachFile) |
269 | { | 269 | { |
270 | if (mType == Email) { | 270 | if (mType == Email) { |
271 | mMailAttachFiles.clear(); | 271 | mMailAttachFiles.clear(); |
272 | mMailAttachFiles += mailAttachFile; | 272 | mMailAttachFiles += mailAttachFile; |
273 | mParent->updated(); | 273 | mParent->updated(); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | 276 | ||
277 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) | 277 | void Alarm::setMailAttachments(const QStringList &mailAttachFiles) |
278 | { | 278 | { |
279 | if (mType == Email) { | 279 | if (mType == Email) { |
280 | mMailAttachFiles = mailAttachFiles; | 280 | mMailAttachFiles = mailAttachFiles; |
281 | mParent->updated(); | 281 | mParent->updated(); |
282 | } | 282 | } |
283 | } | 283 | } |
284 | 284 | ||
285 | void Alarm::addMailAttachment(const QString &mailAttachFile) | 285 | void Alarm::addMailAttachment(const QString &mailAttachFile) |
286 | { | 286 | { |
287 | if (mType == Email) { | 287 | if (mType == Email) { |
288 | mMailAttachFiles += mailAttachFile; | 288 | mMailAttachFiles += mailAttachFile; |
289 | mParent->updated(); | 289 | mParent->updated(); |
290 | } | 290 | } |
291 | } | 291 | } |
292 | 292 | ||
293 | QStringList Alarm::mailAttachments() const | 293 | QStringList Alarm::mailAttachments() const |
294 | { | 294 | { |
295 | return (mType == Email) ? mMailAttachFiles : QStringList(); | 295 | return (mType == Email) ? mMailAttachFiles : QStringList(); |
296 | } | 296 | } |
297 | 297 | ||
298 | void Alarm::setMailText(const QString &text) | 298 | void Alarm::setMailText(const QString &text) |
299 | { | 299 | { |
300 | if (mType == Email) { | 300 | if (mType == Email) { |
301 | mDescription = text; | 301 | mDescription = text; |
302 | mParent->updated(); | 302 | mParent->updated(); |
303 | } | 303 | } |
304 | } | 304 | } |
305 | 305 | ||
306 | QString Alarm::mailText() const | 306 | QString Alarm::mailText() const |
307 | { | 307 | { |
308 | return (mType == Email) ? mDescription : QString::null; | 308 | return (mType == Email) ? mDescription : QString::null; |
309 | } | 309 | } |
310 | 310 | ||
311 | void Alarm::setDisplayAlarm(const QString &text) | 311 | void Alarm::setDisplayAlarm(const QString &text) |
312 | { | 312 | { |
313 | mType = Display; | 313 | mType = Display; |
314 | mDescription = text; | 314 | mDescription = text; |
315 | mParent->updated(); | 315 | mParent->updated(); |
316 | } | 316 | } |
317 | 317 | ||
318 | void Alarm::setText(const QString &text) | 318 | void Alarm::setText(const QString &text) |
319 | { | 319 | { |
320 | if (mType == Display) { | 320 | if (mType == Display) { |
321 | mDescription = text; | 321 | mDescription = text; |
322 | mParent->updated(); | 322 | mParent->updated(); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | QString Alarm::text() const | 326 | QString Alarm::text() const |
327 | { | 327 | { |
328 | return (mType == Display) ? mDescription : QString::null; | 328 | return (mType == Display) ? mDescription : QString::null; |
329 | } | 329 | } |
330 | 330 | ||
331 | void Alarm::setTime(const QDateTime &alarmTime) | 331 | void Alarm::setTime(const QDateTime &alarmTime) |
332 | { | 332 | { |
333 | mAlarmTime = alarmTime; | 333 | mAlarmTime = alarmTime; |
334 | mHasTime = true; | 334 | mHasTime = true; |
335 | 335 | ||
336 | mParent->updated(); | 336 | mParent->updated(); |
337 | } | 337 | } |
338 | int Alarm::offset() | 338 | int Alarm::offset() |
339 | { | 339 | { |
340 | if ( hasTime() ) { | 340 | if ( hasTime() ) { |
341 | if (mParent->typeID() == todoID ) { | 341 | if (mParent->typeID() == todoID ) { |
342 | Todo *t = static_cast<Todo*>(mParent); | 342 | Todo *t = static_cast<Todo*>(mParent); |
343 | return t->dtDue().secsTo( mAlarmTime ) ; | 343 | return t->dtDue().secsTo( mAlarmTime ) ; |
344 | } else | 344 | } else |
345 | return mParent->dtStart().secsTo( mAlarmTime ) ; | 345 | return mParent->dtStart().secsTo( mAlarmTime ) ; |
346 | } | 346 | } |
347 | else | 347 | else |
348 | { | 348 | { |
349 | return mOffset.asSeconds(); | 349 | return mOffset.asSeconds(); |
350 | } | 350 | } |
351 | 351 | ||
352 | } | 352 | } |
353 | QString Alarm::offsetText() | 353 | QString Alarm::offsetText() |
354 | { | 354 | { |
355 | int min = -offset()/60; | 355 | int min = -offset()/60; |
356 | int hours = min /60; | 356 | int hours = min /60; |
357 | min = min % 60; | 357 | min = min % 60; |
358 | int days = hours /24; | 358 | int days = hours /24; |
359 | hours = hours % 24; | 359 | hours = hours % 24; |
360 | QString message; | 360 | QString message; |
361 | //qDebug("%d %d %d ", days, hours, min ); | 361 | //qDebug("%d %d %d ", days, hours, min ); |
362 | if ( days > 0 ) | 362 | if ( days > 0 ) |
363 | message += i18n("%1d").arg( days ); | 363 | message += i18n("%1d").arg( days ); |
364 | if ( hours > 0 ) { | 364 | if ( hours > 0 ) { |
365 | if ( !message.isEmpty() ) message += "/"; | 365 | if ( !message.isEmpty() ) message += "/"; |
366 | message += i18n("%1h").arg( hours ); | 366 | message += i18n("%1h").arg( hours ); |
367 | } | 367 | } |
368 | if ( min > 0 ) { | 368 | if ( min > 0 ) { |
369 | if ( !message.isEmpty() ) message += "/"; | 369 | if ( !message.isEmpty() ) message += "/"; |
370 | message += i18n("%1min").arg( min ); | 370 | message += i18n("%1min").arg( min ); |
371 | } | 371 | } |
372 | if ( message.isEmpty() ) | 372 | if ( message.isEmpty() ) |
373 | message = i18n("%1min").arg( 0 ); | 373 | message = i18n("%1min").arg( 0 ); |
374 | if ( !mParent->alarmEnabled() ) | ||
375 | return "!"+message + i18n("(disabled)"); | ||
374 | return message; | 376 | return message; |
375 | } | 377 | } |
376 | 378 | ||
377 | 379 | ||
378 | QDateTime Alarm::time() const | 380 | QDateTime Alarm::time() const |
379 | { | 381 | { |
380 | if ( hasTime() ) | 382 | if ( hasTime() ) |
381 | return mAlarmTime; | 383 | return mAlarmTime; |
382 | else | 384 | else |
383 | { | 385 | { |
384 | if (mParent->typeID() == todoID ) { | 386 | if (mParent->typeID() == todoID ) { |
385 | Todo *t = static_cast<Todo*>(mParent); | 387 | Todo *t = static_cast<Todo*>(mParent); |
386 | return mOffset.end( t->dtDue() ); | 388 | return mOffset.end( t->dtDue() ); |
387 | } else if (mEndOffset) { | 389 | } else if (mEndOffset) { |
388 | return mOffset.end( mParent->dtEnd() ); | 390 | return mOffset.end( mParent->dtEnd() ); |
389 | } else { | 391 | } else { |
390 | return mOffset.end( mParent->dtStart() ); | 392 | return mOffset.end( mParent->dtStart() ); |
391 | } | 393 | } |
392 | } | 394 | } |
393 | } | 395 | } |
394 | 396 | ||
395 | bool Alarm::hasTime() const | 397 | bool Alarm::hasTime() const |
396 | { | 398 | { |
397 | return mHasTime; | 399 | return mHasTime; |
398 | } | 400 | } |
399 | 401 | ||
400 | void Alarm::setSnoozeTime(int alarmSnoozeTime) | 402 | void Alarm::setSnoozeTime(int alarmSnoozeTime) |
401 | { | 403 | { |
402 | mAlarmSnoozeTime = alarmSnoozeTime; | 404 | mAlarmSnoozeTime = alarmSnoozeTime; |
403 | mParent->updated(); | 405 | mParent->updated(); |
404 | } | 406 | } |
405 | 407 | ||
406 | int Alarm::snoozeTime() const | 408 | int Alarm::snoozeTime() const |
407 | { | 409 | { |
408 | return mAlarmSnoozeTime; | 410 | return mAlarmSnoozeTime; |
409 | } | 411 | } |
410 | 412 | ||
411 | void Alarm::setRepeatCount(int alarmRepeatCount) | 413 | void Alarm::setRepeatCount(int alarmRepeatCount) |
412 | { | 414 | { |
413 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; | 415 | kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; |
414 | 416 | ||
415 | mAlarmRepeatCount = alarmRepeatCount; | 417 | mAlarmRepeatCount = alarmRepeatCount; |
416 | mParent->updated(); | 418 | mParent->updated(); |
417 | } | 419 | } |
418 | 420 | ||
419 | int Alarm::repeatCount() const | 421 | int Alarm::repeatCount() const |
420 | { | 422 | { |
421 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; | 423 | kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; |
422 | return mAlarmRepeatCount; | 424 | return mAlarmRepeatCount; |
423 | } | 425 | } |
424 | 426 | ||
425 | void Alarm::toggleAlarm() | 427 | void Alarm::toggleAlarm() |
426 | { | 428 | { |
427 | mAlarmEnabled = !mAlarmEnabled; | 429 | mAlarmEnabled = !mAlarmEnabled; |
428 | mParent->updated(); | 430 | mParent->updated(); |
429 | } | 431 | } |
430 | 432 | ||
431 | void Alarm::setEnabled(bool enable) | 433 | void Alarm::setEnabled(bool enable) |
432 | { | 434 | { |
433 | mAlarmEnabled = enable; | 435 | mAlarmEnabled = enable; |
434 | mParent->updated(); | 436 | mParent->updated(); |
435 | } | 437 | } |
436 | 438 | ||
437 | bool Alarm::enabled() const | 439 | bool Alarm::enabled() const |
438 | { | 440 | { |
439 | return mAlarmEnabled; | 441 | return mAlarmEnabled; |
440 | } | 442 | } |
441 | 443 | ||
442 | void Alarm::setStartOffset( const Duration &offset ) | 444 | void Alarm::setStartOffset( const Duration &offset ) |
443 | { | 445 | { |
444 | mOffset = offset; | 446 | mOffset = offset; |
445 | mEndOffset = false; | 447 | mEndOffset = false; |
446 | mHasTime = false; | 448 | mHasTime = false; |
447 | mParent->updated(); | 449 | mParent->updated(); |
448 | } | 450 | } |
449 | 451 | ||
450 | Duration Alarm::startOffset() const | 452 | Duration Alarm::startOffset() const |
451 | { | 453 | { |
452 | return (mHasTime || mEndOffset) ? 0 : mOffset; | 454 | return (mHasTime || mEndOffset) ? 0 : mOffset; |
453 | } | 455 | } |
454 | 456 | ||
455 | bool Alarm::hasStartOffset() const | 457 | bool Alarm::hasStartOffset() const |
456 | { | 458 | { |
457 | return !mHasTime && !mEndOffset; | 459 | return !mHasTime && !mEndOffset; |
458 | } | 460 | } |
459 | 461 | ||
460 | bool Alarm::hasEndOffset() const | 462 | bool Alarm::hasEndOffset() const |
461 | { | 463 | { |
462 | return !mHasTime && mEndOffset; | 464 | return !mHasTime && mEndOffset; |
463 | } | 465 | } |
464 | 466 | ||
465 | void Alarm::setEndOffset( const Duration &offset ) | 467 | void Alarm::setEndOffset( const Duration &offset ) |
466 | { | 468 | { |
467 | mOffset = offset; | 469 | mOffset = offset; |
468 | mEndOffset = true; | 470 | mEndOffset = true; |
469 | mHasTime = false; | 471 | mHasTime = false; |
470 | mParent->updated(); | 472 | mParent->updated(); |
471 | } | 473 | } |
472 | 474 | ||
473 | Duration Alarm::endOffset() const | 475 | Duration Alarm::endOffset() const |
474 | { | 476 | { |
475 | return (mHasTime || !mEndOffset) ? 0 : mOffset; | 477 | return (mHasTime || !mEndOffset) ? 0 : mOffset; |
476 | } | 478 | } |
477 | 479 | ||
478 | void Alarm::setParent( Incidence *parent ) | 480 | void Alarm::setParent( Incidence *parent ) |
479 | { | 481 | { |
480 | mParent = parent; | 482 | mParent = parent; |
481 | } | 483 | } |
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 5092d1a..a662eeb 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,488 +1,488 @@ | |||
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( " 00:00 Europe/London(UTC)" ); | 41 | setTimeZoneId( " 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 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mDeleteIncidencesOnClose = true; | 56 | mDeleteIncidencesOnClose = true; |
57 | mModified = false; | 57 | mModified = false; |
58 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
59 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
60 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
61 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
62 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
63 | 63 | ||
64 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
65 | // even that good of one at that. | 65 | // even that good of one at that. |
66 | // srandom(time(0)); | 66 | // srandom(time(0)); |
67 | 67 | ||
68 | // user information... | 68 | // user information... |
69 | setOwner(i18n("Unknown Name")); | 69 | setOwner(i18n("Unknown Name")); |
70 | setEmail(i18n("unknown@nowhere")); | 70 | setEmail(i18n("unknown@nowhere")); |
71 | 71 | ||
72 | #if 0 | 72 | #if 0 |
73 | tmpStr = KOPrefs::instance()->mTimeZone; | 73 | tmpStr = KOPrefs::instance()->mTimeZone; |
74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
76 | extern long int timezone; | 76 | extern long int timezone; |
77 | struct tm *now; | 77 | struct tm *now; |
78 | time_t curtime; | 78 | time_t curtime; |
79 | curtime = time(0); | 79 | curtime = time(0); |
80 | now = localtime(&curtime); | 80 | now = localtime(&curtime); |
81 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
82 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
83 | hourOff += 1; | 83 | hourOff += 1; |
84 | QString tzStr; | 84 | QString tzStr; |
85 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
86 | hourOff, | 86 | hourOff, |
87 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
88 | 88 | ||
89 | // if no time zone was in the config file, write what we just discovered. | 89 | // if no time zone was in the config file, write what we just discovered. |
90 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
91 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
92 | } else { | 92 | } else { |
93 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
94 | } | 94 | } |
95 | 95 | ||
96 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
97 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
98 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
99 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
100 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
102 | } | 102 | } |
103 | 103 | ||
104 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
108 | } | 108 | } |
109 | 109 | ||
110 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
111 | { | 111 | { |
112 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
113 | if ( mUndoIncidence ) | 113 | if ( mUndoIncidence ) |
114 | delete mUndoIncidence; | 114 | delete mUndoIncidence; |
115 | } | 115 | } |
116 | void Calendar::setDontDeleteIncidencesOnClose () | 116 | void Calendar::setDontDeleteIncidencesOnClose () |
117 | { | 117 | { |
118 | mDeleteIncidencesOnClose = false; | 118 | mDeleteIncidencesOnClose = false; |
119 | } | 119 | } |
120 | void Calendar::setDefaultCalendar( int d ) | 120 | void Calendar::setDefaultCalendar( int d ) |
121 | { | 121 | { |
122 | mDefaultCalendar = d; | 122 | mDefaultCalendar = d; |
123 | } | 123 | } |
124 | int Calendar::defaultCalendar() | 124 | int Calendar::defaultCalendar() |
125 | { | 125 | { |
126 | return mDefaultCalendar; | 126 | return mDefaultCalendar; |
127 | } | 127 | } |
128 | const QString &Calendar::getOwner() const | 128 | const QString &Calendar::getOwner() const |
129 | { | 129 | { |
130 | return mOwner; | 130 | return mOwner; |
131 | } | 131 | } |
132 | 132 | ||
133 | bool Calendar::undoDeleteIncidence() | 133 | bool Calendar::undoDeleteIncidence() |
134 | { | 134 | { |
135 | if (!mUndoIncidence) | 135 | if (!mUndoIncidence) |
136 | return false; | 136 | return false; |
137 | addIncidence(mUndoIncidence); | 137 | addIncidence(mUndoIncidence); |
138 | mUndoIncidence = 0; | 138 | mUndoIncidence = 0; |
139 | return true; | 139 | return true; |
140 | } | 140 | } |
141 | void Calendar::setOwner(const QString &os) | 141 | void Calendar::setOwner(const QString &os) |
142 | { | 142 | { |
143 | int i; | 143 | int i; |
144 | mOwner = os; | 144 | mOwner = os; |
145 | i = mOwner.find(','); | 145 | i = mOwner.find(','); |
146 | if (i != -1) | 146 | if (i != -1) |
147 | mOwner = mOwner.left(i); | 147 | mOwner = mOwner.left(i); |
148 | 148 | ||
149 | setModified( true ); | 149 | setModified( true ); |
150 | } | 150 | } |
151 | 151 | ||
152 | void Calendar::setTimeZone(const QString & tz) | 152 | void Calendar::setTimeZone(const QString & tz) |
153 | { | 153 | { |
154 | bool neg = FALSE; | 154 | bool neg = FALSE; |
155 | int hours, minutes; | 155 | int hours, minutes; |
156 | QString tmpStr(tz); | 156 | QString tmpStr(tz); |
157 | 157 | ||
158 | if (tmpStr.left(1) == "-") | 158 | if (tmpStr.left(1) == "-") |
159 | neg = TRUE; | 159 | neg = TRUE; |
160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
161 | tmpStr.remove(0, 1); | 161 | tmpStr.remove(0, 1); |
162 | hours = tmpStr.left(2).toInt(); | 162 | hours = tmpStr.left(2).toInt(); |
163 | if (tmpStr.length() > 2) | 163 | if (tmpStr.length() > 2) |
164 | minutes = tmpStr.right(2).toInt(); | 164 | minutes = tmpStr.right(2).toInt(); |
165 | else | 165 | else |
166 | minutes = 0; | 166 | minutes = 0; |
167 | mTimeZone = (60*hours+minutes); | 167 | mTimeZone = (60*hours+minutes); |
168 | if (neg) | 168 | if (neg) |
169 | mTimeZone = -mTimeZone; | 169 | mTimeZone = -mTimeZone; |
170 | mLocalTime = false; | 170 | mLocalTime = false; |
171 | 171 | ||
172 | setModified( true ); | 172 | setModified( true ); |
173 | } | 173 | } |
174 | 174 | ||
175 | QString Calendar::getTimeZoneStr() const | 175 | QString Calendar::getTimeZoneStr() const |
176 | { | 176 | { |
177 | if (mLocalTime) | 177 | if (mLocalTime) |
178 | return ""; | 178 | return ""; |
179 | QString tmpStr; | 179 | QString tmpStr; |
180 | int hours = abs(mTimeZone / 60); | 180 | int hours = abs(mTimeZone / 60); |
181 | int minutes = abs(mTimeZone % 60); | 181 | int minutes = abs(mTimeZone % 60); |
182 | bool neg = mTimeZone < 0; | 182 | bool neg = mTimeZone < 0; |
183 | 183 | ||
184 | tmpStr.sprintf("%c%.2d%.2d", | 184 | tmpStr.sprintf("%c%.2d%.2d", |
185 | (neg ? '-' : '+'), | 185 | (neg ? '-' : '+'), |
186 | hours, minutes); | 186 | hours, minutes); |
187 | return tmpStr; | 187 | return tmpStr; |
188 | } | 188 | } |
189 | 189 | ||
190 | void Calendar::setTimeZone(int tz) | 190 | void Calendar::setTimeZone(int tz) |
191 | { | 191 | { |
192 | mTimeZone = tz; | 192 | mTimeZone = tz; |
193 | mLocalTime = false; | 193 | mLocalTime = false; |
194 | 194 | ||
195 | setModified( true ); | 195 | setModified( true ); |
196 | } | 196 | } |
197 | 197 | ||
198 | int Calendar::getTimeZone() const | 198 | int Calendar::getTimeZone() const |
199 | { | 199 | { |
200 | return mTimeZone; | 200 | return mTimeZone; |
201 | } | 201 | } |
202 | 202 | ||
203 | void Calendar::setTimeZoneId(const QString &id) | 203 | void Calendar::setTimeZoneId(const QString &id) |
204 | { | 204 | { |
205 | mTimeZoneId = id; | 205 | mTimeZoneId = id; |
206 | mLocalTime = false; | 206 | mLocalTime = false; |
207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
208 | if ( mTimeZone > 1000) | 208 | if ( mTimeZone > 1000) |
209 | setLocalTime(); | 209 | setLocalTime(); |
210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
211 | setModified( true ); | 211 | setModified( true ); |
212 | } | 212 | } |
213 | 213 | ||
214 | QString Calendar::timeZoneId() const | 214 | QString Calendar::timeZoneId() const |
215 | { | 215 | { |
216 | return mTimeZoneId; | 216 | return mTimeZoneId; |
217 | } | 217 | } |
218 | 218 | ||
219 | void Calendar::setLocalTime() | 219 | void Calendar::setLocalTime() |
220 | { | 220 | { |
221 | //qDebug("Calendar::setLocalTime() "); | 221 | //qDebug("Calendar::setLocalTime() "); |
222 | mLocalTime = true; | 222 | mLocalTime = true; |
223 | mTimeZone = 0; | 223 | mTimeZone = 0; |
224 | mTimeZoneId = ""; | 224 | mTimeZoneId = ""; |
225 | 225 | ||
226 | setModified( true ); | 226 | setModified( true ); |
227 | } | 227 | } |
228 | 228 | ||
229 | bool Calendar::isLocalTime() const | 229 | bool Calendar::isLocalTime() const |
230 | { | 230 | { |
231 | return mLocalTime; | 231 | return mLocalTime; |
232 | } | 232 | } |
233 | 233 | ||
234 | const QString &Calendar::getEmail() | 234 | const QString &Calendar::getEmail() |
235 | { | 235 | { |
236 | return mOwnerEmail; | 236 | return mOwnerEmail; |
237 | } | 237 | } |
238 | 238 | ||
239 | void Calendar::setEmail(const QString &e) | 239 | void Calendar::setEmail(const QString &e) |
240 | { | 240 | { |
241 | mOwnerEmail = e; | 241 | mOwnerEmail = e; |
242 | 242 | ||
243 | setModified( true ); | 243 | setModified( true ); |
244 | } | 244 | } |
245 | 245 | ||
246 | void Calendar::setFilter(CalFilter *filter) | 246 | void Calendar::setFilter(CalFilter *filter) |
247 | { | 247 | { |
248 | mFilter = filter; | 248 | mFilter = filter; |
249 | } | 249 | } |
250 | 250 | ||
251 | CalFilter *Calendar::filter() | 251 | CalFilter *Calendar::filter() |
252 | { | 252 | { |
253 | return mFilter; | 253 | return mFilter; |
254 | } | 254 | } |
255 | 255 | ||
256 | QPtrList<Incidence> Calendar::incidences() | 256 | QPtrList<Incidence> Calendar::incidences() |
257 | { | 257 | { |
258 | QPtrList<Incidence> incidences; | 258 | QPtrList<Incidence> incidences; |
259 | 259 | ||
260 | Incidence *i; | 260 | Incidence *i; |
261 | 261 | ||
262 | QPtrList<Event> e = events(); | 262 | QPtrList<Event> e = events(); |
263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
264 | 264 | ||
265 | QPtrList<Todo> t = todos(); | 265 | QPtrList<Todo> t = todos(); |
266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
267 | 267 | ||
268 | QPtrList<Journal> j = journals(); | 268 | QPtrList<Journal> j = journals(); |
269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
270 | 270 | ||
271 | return incidences; | 271 | return incidences; |
272 | } | 272 | } |
273 | 273 | ||
274 | void Calendar::resetPilotStat(int id ) | 274 | void Calendar::resetPilotStat(int id ) |
275 | { | 275 | { |
276 | QPtrList<Incidence> incidences; | 276 | QPtrList<Incidence> incidences; |
277 | 277 | ||
278 | Incidence *i; | 278 | Incidence *i; |
279 | 279 | ||
280 | QPtrList<Event> e = rawEvents(); | 280 | QPtrList<Event> e = rawEvents(); |
281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
282 | 282 | ||
283 | QPtrList<Todo> t = rawTodos(); | 283 | QPtrList<Todo> t = rawTodos(); |
284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
285 | 285 | ||
286 | QPtrList<Journal> j = journals(); | 286 | QPtrList<Journal> j = journals(); |
287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
288 | } | 288 | } |
289 | void Calendar::resetTempSyncStat() | 289 | void Calendar::resetTempSyncStat() |
290 | { | 290 | { |
291 | QPtrList<Incidence> incidences; | 291 | QPtrList<Incidence> incidences; |
292 | 292 | ||
293 | Incidence *i; | 293 | Incidence *i; |
294 | 294 | ||
295 | QPtrList<Event> e = rawEvents(); | 295 | QPtrList<Event> e = rawEvents(); |
296 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 296 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
297 | 297 | ||
298 | QPtrList<Todo> t = rawTodos(); | 298 | QPtrList<Todo> t = rawTodos(); |
299 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 299 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
300 | 300 | ||
301 | QPtrList<Journal> j = journals(); | 301 | QPtrList<Journal> j = journals(); |
302 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 302 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
303 | } | 303 | } |
304 | QPtrList<Incidence> Calendar::rawIncidences() | 304 | QPtrList<Incidence> Calendar::rawIncidences() |
305 | { | 305 | { |
306 | QPtrList<Incidence> incidences; | 306 | QPtrList<Incidence> incidences; |
307 | 307 | ||
308 | Incidence *i; | 308 | Incidence *i; |
309 | 309 | ||
310 | QPtrList<Event> e = rawEvents(); | 310 | QPtrList<Event> e = rawEvents(); |
311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
312 | 312 | ||
313 | QPtrList<Todo> t = rawTodos(); | 313 | QPtrList<Todo> t = rawTodos(); |
314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
315 | 315 | ||
316 | QPtrList<Journal> j = journals(); | 316 | QPtrList<Journal> j = journals(); |
317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
318 | 318 | ||
319 | return incidences; | 319 | return incidences; |
320 | } | 320 | } |
321 | 321 | ||
322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
323 | { | 323 | { |
324 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 324 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
325 | mFilter->apply(&el); | 325 | mFilter->apply(&el); |
326 | return el; | 326 | return el; |
327 | } | 327 | } |
328 | 328 | ||
329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
330 | { | 330 | { |
331 | QPtrList<Event> el = rawEventsForDate(qdt); | 331 | QPtrList<Event> el = rawEventsForDate(qdt); |
332 | mFilter->apply(&el); | 332 | mFilter->apply(&el); |
333 | return el; | 333 | return el; |
334 | } | 334 | } |
335 | 335 | ||
336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
337 | bool inclusive) | 337 | bool inclusive) |
338 | { | 338 | { |
339 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 339 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
340 | mFilter->apply(&el); | 340 | mFilter->apply(&el); |
341 | return el; | 341 | return el; |
342 | } | 342 | } |
343 | 343 | ||
344 | QPtrList<Event> Calendar::events() | 344 | QPtrList<Event> Calendar::events() |
345 | { | 345 | { |
346 | QPtrList<Event> el = rawEvents(); | 346 | QPtrList<Event> el = rawEvents(); |
347 | mFilter->apply(&el); | 347 | mFilter->apply(&el); |
348 | return el; | 348 | return el; |
349 | } | 349 | } |
350 | void Calendar::addIncidenceBranch(Incidence *i) | 350 | void Calendar::addIncidenceBranch(Incidence *i) |
351 | { | 351 | { |
352 | addIncidence( i ); | 352 | addIncidence( i ); |
353 | Incidence * inc; | 353 | Incidence * inc; |
354 | QPtrList<Incidence> Relations = i->relations(); | 354 | QPtrList<Incidence> Relations = i->relations(); |
355 | for (inc=Relations.first();inc;inc=Relations.next()) { | 355 | for (inc=Relations.first();inc;inc=Relations.next()) { |
356 | addIncidenceBranch( inc ); | 356 | addIncidenceBranch( inc ); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | bool Calendar::addIncidence(Incidence *i) | 360 | bool Calendar::addIncidence(Incidence *i) |
361 | { | 361 | { |
362 | Incidence::AddVisitor<Calendar> v(this); | 362 | Incidence::AddVisitor<Calendar> v(this); |
363 | i->setCalID( mDefaultCalendar ); | 363 | i->setCalID( mDefaultCalendar ); |
364 | i->setCalEnabled( true ); | 364 | i->setCalEnabled( true ); |
365 | return i->accept(v); | 365 | return i->accept(v); |
366 | } | 366 | } |
367 | void Calendar::deleteIncidence(Incidence *in) | 367 | void Calendar::deleteIncidence(Incidence *in) |
368 | { | 368 | { |
369 | if ( in->typeID() == eventID ) | 369 | if ( in->typeID() == eventID ) |
370 | deleteEvent( (Event*) in ); | 370 | deleteEvent( (Event*) in ); |
371 | else if ( in->typeID() == todoID ) | 371 | else if ( in->typeID() == todoID ) |
372 | deleteTodo( (Todo*) in); | 372 | deleteTodo( (Todo*) in); |
373 | else if ( in->typeID() == journalID ) | 373 | else if ( in->typeID() == journalID ) |
374 | deleteJournal( (Journal*) in ); | 374 | deleteJournal( (Journal*) in ); |
375 | } | 375 | } |
376 | 376 | ||
377 | Incidence* Calendar::incidence( const QString& uid ) | 377 | Incidence* Calendar::incidence( const QString& uid ) |
378 | { | 378 | { |
379 | Incidence* i; | 379 | Incidence* i; |
380 | 380 | ||
381 | if( (i = todo( uid )) != 0 ) | 381 | if( (i = todo( uid )) != 0 ) |
382 | return i; | 382 | return i; |
383 | if( (i = event( uid )) != 0 ) | 383 | if( (i = event( uid )) != 0 ) |
384 | return i; | 384 | return i; |
385 | if( (i = journal( uid )) != 0 ) | 385 | if( (i = journal( uid )) != 0 ) |
386 | return i; | 386 | return i; |
387 | 387 | ||
388 | return 0; | 388 | return 0; |
389 | } | 389 | } |
390 | 390 | ||
391 | QPtrList<Todo> Calendar::todos() | 391 | QPtrList<Todo> Calendar::todos() |
392 | { | 392 | { |
393 | QPtrList<Todo> tl = rawTodos(); | 393 | QPtrList<Todo> tl = rawTodos(); |
394 | mFilter->apply( &tl ); | 394 | mFilter->apply( &tl ); |
395 | return tl; | 395 | return tl; |
396 | } | 396 | } |
397 | 397 | ||
398 | // When this is called, the todo have already been added to the calendar. | 398 | // When this is called, the todo have already been added to the calendar. |
399 | // This method is only about linking related todos | 399 | // This method is only about linking related todos |
400 | void Calendar::setupRelations( Incidence *incidence ) | 400 | void Calendar::setupRelations( Incidence *incidence ) |
401 | { | 401 | { |
402 | QString uid = incidence->uid(); | 402 | QString uid = incidence->uid(); |
403 | //qDebug("Calendar::setupRelations "); | 403 | //qDebug("Calendar::setupRelations "); |
404 | // First, go over the list of orphans and see if this is their parent | 404 | // First, go over the list of orphans and see if this is their parent |
405 | while( Incidence* i = mOrphans[ uid ] ) { | 405 | while( Incidence* i = mOrphans[ uid ] ) { |
406 | mOrphans.remove( uid ); | 406 | mOrphans.remove( uid ); |
407 | i->setRelatedTo( incidence ); | 407 | i->setRelatedTo( incidence ); |
408 | incidence->addRelation( i ); | 408 | incidence->addRelation( i ); |
409 | mOrphanUids.remove( i->uid() ); | 409 | mOrphanUids.remove( i->uid() ); |
410 | } | 410 | } |
411 | 411 | ||
412 | // Now see about this incidences parent | 412 | // Now see about this incidences parent |
413 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 413 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
414 | // This incidence has a uid it is related to, but is not registered to it yet | 414 | // This incidence has a uid it is related to, but is not registered to it yet |
415 | // Try to find it | 415 | // Try to find it |
416 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 416 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
417 | if( parent ) { | 417 | if( parent ) { |
418 | // Found it | 418 | // Found it |
419 | incidence->setRelatedTo( parent ); | 419 | incidence->setRelatedTo( parent ); |
420 | parent->addRelation( incidence ); | 420 | parent->addRelation( incidence ); |
421 | } else { | 421 | } else { |
422 | // Not found, put this in the mOrphans list | 422 | // Not found, put this in the mOrphans list |
423 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 423 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
424 | mOrphanUids.insert( incidence->uid(), incidence ); | 424 | mOrphanUids.insert( incidence->uid(), incidence ); |
425 | } | 425 | } |
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 429 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
430 | void Calendar::removeRelations( Incidence *incidence ) | 430 | void Calendar::removeRelations( Incidence *incidence ) |
431 | { | 431 | { |
432 | // qDebug("Calendar::removeRelations "); | 432 | // qDebug("Calendar::removeRelations "); |
433 | QString uid = incidence->uid(); | 433 | QString uid = incidence->uid(); |
434 | 434 | ||
435 | QPtrList<Incidence> relations = incidence->relations(); | 435 | QPtrList<Incidence> relations = incidence->relations(); |
436 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 436 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
437 | if( !mOrphanUids.find( i->uid() ) ) { | 437 | if( !mOrphanUids.find( i->uid() ) ) { |
438 | mOrphans.insert( uid, i ); | 438 | mOrphans.insert( uid, i ); |
439 | mOrphanUids.insert( i->uid(), i ); | 439 | mOrphanUids.insert( i->uid(), i ); |
440 | i->setRelatedTo( 0 ); | 440 | i->setRelatedTo( 0 ); |
441 | i->setRelatedToUid( uid ); | 441 | i->setRelatedToUid( uid ); |
442 | } | 442 | } |
443 | 443 | ||
444 | // If this incidence is related to something else, tell that about it | 444 | // If this incidence is related to something else, tell that about it |
445 | if( incidence->relatedTo() ) | 445 | if( incidence->relatedTo() ) |
446 | incidence->relatedTo()->removeRelation( incidence ); | 446 | incidence->relatedTo()->removeRelation( incidence ); |
447 | 447 | ||
448 | // Remove this one from the orphans list | 448 | // Remove this one from the orphans list |
449 | if( mOrphanUids.remove( uid ) ) | 449 | if( mOrphanUids.remove( uid ) ) |
450 | // This incidence is located in the orphans list - it should be removed | 450 | // This incidence is located in the orphans list - it should be removed |
451 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 451 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
452 | // Removing wasn't that easy | 452 | // Removing wasn't that easy |
453 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 453 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
454 | if( it.current()->uid() == uid ) { | 454 | if( it.current()->uid() == uid ) { |
455 | mOrphans.remove( it.currentKey() ); | 455 | mOrphans.remove( it.currentKey() ); |
456 | break; | 456 | break; |
457 | } | 457 | } |
458 | } | 458 | } |
459 | } | 459 | } |
460 | } | 460 | } |
461 | 461 | ||
462 | void Calendar::registerObserver( Observer *observer ) | 462 | void Calendar::registerObserver( Observer *observer ) |
463 | { | 463 | { |
464 | mObserver = observer; | 464 | mObserver = observer; |
465 | mNewObserver = true; | 465 | mNewObserver = true; |
466 | } | 466 | } |
467 | 467 | ||
468 | void Calendar::setModified( bool modified ) | 468 | void Calendar::setModified( bool modified ) |
469 | { | 469 | { |
470 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 470 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
471 | if ( modified != mModified || mNewObserver ) { | 471 | if ( modified != mModified || mNewObserver ) { |
472 | mNewObserver = false; | 472 | mNewObserver = false; |
473 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 473 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
474 | mModified = modified; | 474 | mModified = modified; |
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
478 | void Calendar::setLoadedProductId( const QString &id ) | 478 | void Calendar::setLoadedProductId( const QString &id ) |
479 | { | 479 | { |
480 | mLoadedProductId = id; | 480 | mLoadedProductId = id; |
481 | } | 481 | } |
482 | 482 | ||
483 | QString Calendar::loadedProductId() | 483 | QString Calendar::loadedProductId() |
484 | { | 484 | { |
485 | return mLoadedProductId; | 485 | return mLoadedProductId; |
486 | } | 486 | } |
487 | 487 | ||
488 | //#include "calendar.moc" | 488 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 73f82bb..2243e28 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,373 +1,374 @@ | |||
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; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | Sync changes in memory to persistant storage. | 81 | Sync changes in memory to persistant storage. |
82 | */ | 82 | */ |
83 | virtual void save() = 0; | 83 | virtual void save() = 0; |
84 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 84 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
85 | virtual void removeSyncInfo( QString syncProfile) = 0; | 85 | virtual void removeSyncInfo( QString syncProfile) = 0; |
86 | virtual bool isSaving() { return false; } | 86 | virtual bool isSaving() { return false; } |
87 | 87 | ||
88 | /** | 88 | /** |
89 | Return the owner of the calendar's full name. | 89 | Return the owner of the calendar's full name. |
90 | */ | 90 | */ |
91 | const QString &getOwner() const; | 91 | const QString &getOwner() const; |
92 | /** | 92 | /** |
93 | Set the owner of the calendar. Should be owner's full name. | 93 | Set the owner of the calendar. Should be owner's full name. |
94 | */ | 94 | */ |
95 | void setOwner( const QString &os ); | 95 | void setOwner( const QString &os ); |
96 | /** | 96 | /** |
97 | Return the email address of the calendar owner. | 97 | Return the email address of the calendar owner. |
98 | */ | 98 | */ |
99 | const QString &getEmail(); | 99 | const QString &getEmail(); |
100 | /** | 100 | /** |
101 | Set the email address of the calendar owner. | 101 | Set the email address of the calendar owner. |
102 | */ | 102 | */ |
103 | void setEmail( const QString & ); | 103 | void setEmail( const QString & ); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | Set time zone from a timezone string (e.g. -2:00) | 106 | Set time zone from a timezone string (e.g. -2:00) |
107 | */ | 107 | */ |
108 | void setTimeZone( const QString &tz ); | 108 | void setTimeZone( const QString &tz ); |
109 | /** | 109 | /** |
110 | Set time zone from a minutes value (e.g. -60) | 110 | Set time zone from a minutes value (e.g. -60) |
111 | */ | 111 | */ |
112 | void setTimeZone( int tz ); | 112 | void setTimeZone( int tz ); |
113 | /** | 113 | /** |
114 | Return time zone as offest in minutes. | 114 | Return time zone as offest in minutes. |
115 | */ | 115 | */ |
116 | int getTimeZone() const; | 116 | int getTimeZone() const; |
117 | /** | 117 | /** |
118 | Compute an ISO 8601 format string from the time zone. | 118 | Compute an ISO 8601 format string from the time zone. |
119 | */ | 119 | */ |
120 | QString getTimeZoneStr() const; | 120 | QString getTimeZoneStr() const; |
121 | /** | 121 | /** |
122 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 122 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
123 | values). | 123 | values). |
124 | */ | 124 | */ |
125 | void setTimeZoneId( const QString & ); | 125 | void setTimeZoneId( const QString & ); |
126 | /** | 126 | /** |
127 | Return time zone id. | 127 | Return time zone id. |
128 | */ | 128 | */ |
129 | QString timeZoneId() const; | 129 | QString timeZoneId() const; |
130 | /** | 130 | /** |
131 | Use local time, not UTC or a time zone. | 131 | Use local time, not UTC or a time zone. |
132 | */ | 132 | */ |
133 | void setLocalTime(); | 133 | void setLocalTime(); |
134 | /** | 134 | /** |
135 | Return whether local time is being used. | 135 | Return whether local time is being used. |
136 | */ | 136 | */ |
137 | bool isLocalTime() const; | 137 | bool isLocalTime() const; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | Add an incidence to calendar. | 140 | Add an incidence to calendar. |
141 | 141 | ||
142 | @return true on success, false on error. | 142 | @return true on success, false on error. |
143 | */ | 143 | */ |
144 | virtual bool addIncidence( Incidence * ); | 144 | virtual bool addIncidence( Incidence * ); |
145 | 145 | ||
146 | // Adds an incidence and all relatedto incidences to the cal | 146 | // Adds an incidence and all relatedto incidences to the cal |
147 | void addIncidenceBranch( Incidence * ); | 147 | void addIncidenceBranch( Incidence * ); |
148 | /** | 148 | /** |
149 | Return filtered list of all incidences of this calendar. | 149 | Return filtered list of all incidences of this calendar. |
150 | */ | 150 | */ |
151 | virtual QPtrList<Incidence> incidences(); | 151 | virtual QPtrList<Incidence> incidences(); |
152 | 152 | ||
153 | /** | 153 | /** |
154 | Return unfiltered list of all incidences of this calendar. | 154 | Return unfiltered list of all incidences of this calendar. |
155 | */ | 155 | */ |
156 | virtual QPtrList<Incidence> rawIncidences(); | 156 | virtual QPtrList<Incidence> rawIncidences(); |
157 | 157 | ||
158 | /** | 158 | /** |
159 | Adds a Event to this calendar object. | 159 | Adds a Event to this calendar object. |
160 | @param anEvent a pointer to the event to add | 160 | @param anEvent a pointer to the event to add |
161 | 161 | ||
162 | @return true on success, false on error. | 162 | @return true on success, false on error. |
163 | */ | 163 | */ |
164 | virtual bool addEventNoDup( Event *event ) = 0; | 164 | virtual bool addEventNoDup( Event *event ) = 0; |
165 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 165 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
166 | virtual bool addEvent( Event *anEvent ) = 0; | 166 | virtual bool addEvent( Event *anEvent ) = 0; |
167 | /** | 167 | /** |
168 | Delete event from calendar. | 168 | Delete event from calendar. |
169 | */ | 169 | */ |
170 | virtual void deleteEvent( Event * ) = 0; | 170 | virtual void deleteEvent( Event * ) = 0; |
171 | /** | 171 | /** |
172 | Retrieves an event on the basis of the unique string ID. | 172 | Retrieves an event on the basis of the unique string ID. |
173 | */ | 173 | */ |
174 | virtual Event *event( const QString &UniqueStr ) = 0; | 174 | virtual Event *event( const QString &UniqueStr ) = 0; |
175 | virtual Event *event( QString, QString ) = 0; | 175 | virtual Event *event( QString, QString ) = 0; |
176 | /** | 176 | /** |
177 | Builds and then returns a list of all events that match for the | 177 | Builds and then returns a list of all events that match for the |
178 | date specified. useful for dayView, etc. etc. | 178 | date specified. useful for dayView, etc. etc. |
179 | The calendar filter is applied. | 179 | The calendar filter is applied. |
180 | */ | 180 | */ |
181 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 181 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
182 | /** | 182 | /** |
183 | Get events, which occur on the given date. | 183 | Get events, which occur on the given date. |
184 | The calendar filter is applied. | 184 | The calendar filter is applied. |
185 | */ | 185 | */ |
186 | QPtrList<Event> events( const QDateTime &qdt ); | 186 | QPtrList<Event> events( const QDateTime &qdt ); |
187 | /** | 187 | /** |
188 | Get events in a range of dates. If inclusive is set to true, only events | 188 | Get events in a range of dates. If inclusive is set to true, only events |
189 | are returned, which are completely included in the range. | 189 | are returned, which are completely included in the range. |
190 | The calendar filter is applied. | 190 | The calendar filter is applied. |
191 | */ | 191 | */ |
192 | QPtrList<Event> events( const QDate &start, const QDate &end, | 192 | QPtrList<Event> events( const QDate &start, const QDate &end, |
193 | bool inclusive = false); | 193 | bool inclusive = false); |
194 | /** | 194 | /** |
195 | Return filtered list of all events in calendar. | 195 | Return filtered list of all events in calendar. |
196 | */ | 196 | */ |
197 | virtual QPtrList<Event> events(); | 197 | virtual QPtrList<Event> events(); |
198 | /** | 198 | /** |
199 | Return unfiltered list of all events in calendar. | 199 | Return unfiltered list of all events in calendar. |
200 | */ | 200 | */ |
201 | virtual QPtrList<Event> rawEvents() = 0; | 201 | virtual QPtrList<Event> rawEvents() = 0; |
202 | 202 | ||
203 | /** | 203 | /** |
204 | Add a todo to the todolist. | 204 | Add a todo to the todolist. |
205 | 205 | ||
206 | @return true on success, false on error. | 206 | @return true on success, false on error. |
207 | */ | 207 | */ |
208 | virtual bool addTodo( Todo *todo ) = 0; | 208 | virtual bool addTodo( Todo *todo ) = 0; |
209 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 209 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
210 | /** | 210 | /** |
211 | Remove a todo from the todolist. | 211 | Remove a todo from the todolist. |
212 | */ | 212 | */ |
213 | virtual void deleteTodo( Todo * ) = 0; | 213 | virtual void deleteTodo( Todo * ) = 0; |
214 | virtual void deleteJournal( Journal * ) = 0; | 214 | virtual void deleteJournal( Journal * ) = 0; |
215 | /** | 215 | /** |
216 | Return filterd list of todos. | 216 | Return filterd list of todos. |
217 | */ | 217 | */ |
218 | virtual QPtrList<Todo> todos(); | 218 | virtual QPtrList<Todo> todos(); |
219 | /** | 219 | /** |
220 | Searches todolist for an event with this unique string identifier, | 220 | Searches todolist for an event with this unique string identifier, |
221 | returns a pointer or null. | 221 | returns a pointer or null. |
222 | */ | 222 | */ |
223 | virtual Todo *todo( const QString &uid ) = 0; | 223 | virtual Todo *todo( const QString &uid ) = 0; |
224 | virtual Todo *todo( QString, QString ) = 0; | 224 | virtual Todo *todo( QString, QString ) = 0; |
225 | /** | 225 | /** |
226 | Returns list of todos due on the specified date. | 226 | Returns list of todos due on the specified date. |
227 | */ | 227 | */ |
228 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 228 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
229 | /** | 229 | /** |
230 | Return unfiltered list of todos. | 230 | Return unfiltered list of todos. |
231 | */ | 231 | */ |
232 | virtual QPtrList<Todo> rawTodos() = 0; | 232 | virtual QPtrList<Todo> rawTodos() = 0; |
233 | 233 | ||
234 | /** | 234 | /** |
235 | Add a Journal entry to calendar. | 235 | Add a Journal entry to calendar. |
236 | 236 | ||
237 | @return true on success, false on error. | 237 | @return true on success, false on error. |
238 | */ | 238 | */ |
239 | virtual bool addJournal( Journal * ) = 0; | 239 | virtual bool addJournal( Journal * ) = 0; |
240 | /** | 240 | /** |
241 | Return Journal for given date. | 241 | Return Journal for given date. |
242 | */ | 242 | */ |
243 | virtual Journal *journal( const QDate & ) = 0; | 243 | virtual Journal *journal( const QDate & ) = 0; |
244 | /** | 244 | /** |
245 | Return Journal with given UID. | 245 | Return Journal with given UID. |
246 | */ | 246 | */ |
247 | virtual Journal *journal( const QString &UID ) = 0; | 247 | virtual Journal *journal( const QString &UID ) = 0; |
248 | /** | 248 | /** |
249 | Return list of all Journal entries. | 249 | Return list of all Journal entries. |
250 | */ | 250 | */ |
251 | virtual QPtrList<Journal> journals() = 0; | 251 | virtual QPtrList<Journal> journals() = 0; |
252 | 252 | ||
253 | /** | 253 | /** |
254 | Searches all incidence types for an incidence with this unique | 254 | Searches all incidence types for an incidence with this unique |
255 | string identifier, returns a pointer or null. | 255 | string identifier, returns a pointer or null. |
256 | */ | 256 | */ |
257 | Incidence* incidence( const QString&UID ); | 257 | Incidence* incidence( const QString&UID ); |
258 | 258 | ||
259 | /** | 259 | /** |
260 | Setup relations for an incidence. | 260 | Setup relations for an incidence. |
261 | */ | 261 | */ |
262 | virtual void setupRelations( Incidence * ); | 262 | virtual void setupRelations( Incidence * ); |
263 | /** | 263 | /** |
264 | Remove all relations to an incidence | 264 | Remove all relations to an incidence |
265 | */ | 265 | */ |
266 | virtual void removeRelations( Incidence * ); | 266 | virtual void removeRelations( Incidence * ); |
267 | 267 | ||
268 | /** | 268 | /** |
269 | Set calendar filter, which filters events for the events() functions. | 269 | Set calendar filter, which filters events for the events() functions. |
270 | The Filter object is owned by the caller. | 270 | The Filter object is owned by the caller. |
271 | */ | 271 | */ |
272 | void setFilter( CalFilter * ); | 272 | void setFilter( CalFilter * ); |
273 | /** | 273 | /** |
274 | Return calendar filter. | 274 | Return calendar filter. |
275 | */ | 275 | */ |
276 | CalFilter *filter(); | 276 | CalFilter *filter(); |
277 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 277 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
278 | virtual QString nextSummary( ) const = 0; | 278 | virtual QString nextSummary( ) const = 0; |
279 | virtual void reInitAlarmSettings() = 0; | 279 | virtual void reInitAlarmSettings() = 0; |
280 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 280 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
281 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 281 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
282 | /** | 282 | /** |
283 | Return all alarms, which ocur in the given time interval. | 283 | Return all alarms, which ocur in the given time interval. |
284 | */ | 284 | */ |
285 | virtual Alarm::List alarms( const QDateTime &from, | 285 | virtual Alarm::List alarms( const QDateTime &from, |
286 | const QDateTime &to ) = 0; | 286 | const QDateTime &to ) = 0; |
287 | 287 | ||
288 | class Observer { | 288 | class Observer { |
289 | public: | 289 | public: |
290 | virtual void calendarModified( bool, Calendar * ) = 0; | 290 | virtual void calendarModified( bool, Calendar * ) = 0; |
291 | }; | 291 | }; |
292 | 292 | ||
293 | void registerObserver( Observer * ); | 293 | void registerObserver( Observer * ); |
294 | 294 | ||
295 | void setModified( bool ); | 295 | void setModified( bool ); |
296 | 296 | ||
297 | /** | 297 | /** |
298 | Set product id returned by loadedProductId(). This function is only | 298 | Set product id returned by loadedProductId(). This function is only |
299 | useful for the calendar loading code. | 299 | useful for the calendar loading code. |
300 | */ | 300 | */ |
301 | void setLoadedProductId( const QString & ); | 301 | void setLoadedProductId( const QString & ); |
302 | /** | 302 | /** |
303 | Return product id taken from file that has been loaded. Returns | 303 | Return product id taken from file that has been loaded. Returns |
304 | QString::null, if no calendar has been loaded. | 304 | QString::null, if no calendar has been loaded. |
305 | */ | 305 | */ |
306 | QString loadedProductId(); | 306 | QString loadedProductId(); |
307 | int defaultCalendar(); | 307 | int defaultCalendar(); |
308 | void setDontDeleteIncidencesOnClose (); | 308 | void setDontDeleteIncidencesOnClose (); |
309 | public slots: | 309 | public slots: |
310 | void setDefaultCalendar( int ); | 310 | void setDefaultCalendar( int ); |
311 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 311 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
312 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 312 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
313 | virtual void setReadOnly( int id, bool enable ) = 0; | 313 | virtual void setReadOnly( int id, bool enable ) = 0; |
314 | virtual void setDefaultCalendarEnabledOnly() = 0; | 314 | virtual void setDefaultCalendarEnabledOnly() = 0; |
315 | virtual void setCalendarRemove( int id ) = 0; | ||
315 | signals: | 316 | signals: |
316 | void calendarChanged(); | 317 | void calendarChanged(); |
317 | void calendarSaved(); | 318 | void calendarSaved(); |
318 | void calendarLoaded(); | 319 | void calendarLoaded(); |
319 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 320 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
320 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 321 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
321 | 322 | ||
322 | protected: | 323 | protected: |
323 | /** | 324 | /** |
324 | Get unfiltered events, which occur on the given date. | 325 | Get unfiltered events, which occur on the given date. |
325 | */ | 326 | */ |
326 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 327 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
327 | /** | 328 | /** |
328 | Get unfiltered events, which occur on the given date. | 329 | Get unfiltered events, which occur on the given date. |
329 | */ | 330 | */ |
330 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 331 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
331 | bool sorted = false ) = 0; | 332 | bool sorted = false ) = 0; |
332 | /** | 333 | /** |
333 | Get events in a range of dates. If inclusive is set to true, only events | 334 | Get events in a range of dates. If inclusive is set to true, only events |
334 | are returned, which are completely included in the range. | 335 | are returned, which are completely included in the range. |
335 | */ | 336 | */ |
336 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 337 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
337 | bool inclusive = false ) = 0; | 338 | bool inclusive = false ) = 0; |
338 | 339 | ||
339 | Incidence *mNextAlarmIncidence; | 340 | Incidence *mNextAlarmIncidence; |
340 | Incidence *mUndoIncidence; | 341 | Incidence *mUndoIncidence; |
341 | int mDefaultCalendar; | 342 | int mDefaultCalendar; |
342 | bool mDeleteIncidencesOnClose; | 343 | bool mDeleteIncidencesOnClose; |
343 | 344 | ||
344 | private: | 345 | private: |
345 | void init(); | 346 | void init(); |
346 | 347 | ||
347 | QString mOwner; // who the calendar belongs to | 348 | QString mOwner; // who the calendar belongs to |
348 | QString mOwnerEmail; // email address of the owner | 349 | QString mOwnerEmail; // email address of the owner |
349 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 350 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
350 | bool mLocalTime; // use local time, not UTC or a time zone | 351 | bool mLocalTime; // use local time, not UTC or a time zone |
351 | 352 | ||
352 | 353 | ||
353 | CalFilter *mFilter; | 354 | CalFilter *mFilter; |
354 | CalFilter *mDefaultFilter; | 355 | CalFilter *mDefaultFilter; |
355 | 356 | ||
356 | 357 | ||
357 | QString mTimeZoneId; | 358 | QString mTimeZoneId; |
358 | 359 | ||
359 | Observer *mObserver; | 360 | Observer *mObserver; |
360 | bool mNewObserver; | 361 | bool mNewObserver; |
361 | 362 | ||
362 | bool mModified; | 363 | bool mModified; |
363 | 364 | ||
364 | QString mLoadedProductId; | 365 | QString mLoadedProductId; |
365 | 366 | ||
366 | // This list is used to put together related todos | 367 | // This list is used to put together related todos |
367 | QDict<Incidence> mOrphans; | 368 | QDict<Incidence> mOrphans; |
368 | QDict<Incidence> mOrphanUids; | 369 | QDict<Incidence> mOrphanUids; |
369 | }; | 370 | }; |
370 | 371 | ||
371 | } | 372 | } |
372 | 373 | ||
373 | #endif | 374 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index e48122a..749d9f6 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,834 +1,890 @@ | |||
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 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 71 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
72 | { | 72 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 73 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( id ); | 74 | calendar.setDefaultCalendar( id ); |
75 | if ( calendar.load( name ) ) { | 75 | if ( calendar.load( name ) ) { |
76 | addCalendar( &calendar ); | 76 | addCalendar( &calendar ); |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | return false; | 79 | return false; |
80 | } | 80 | } |
81 | void CalendarLocal::addCalendar( Calendar* cal ) | 81 | void CalendarLocal::addCalendar( Calendar* cal ) |
82 | { | 82 | { |
83 | cal->setDontDeleteIncidencesOnClose(); | 83 | cal->setDontDeleteIncidencesOnClose(); |
84 | { | 84 | { |
85 | QPtrList<Event> EventList = cal->rawEvents(); | 85 | QPtrList<Event> EventList = cal->rawEvents(); |
86 | Event * ev = EventList.first(); | 86 | Event * ev = EventList.first(); |
87 | while ( ev ) { | 87 | while ( ev ) { |
88 | ev->unRegisterObserver( cal ); | ||
89 | ev->registerObserver( this ); | ||
88 | mEventList.append( ev ); | 90 | mEventList.append( ev ); |
89 | ev = EventList.next(); | 91 | ev = EventList.next(); |
90 | } | 92 | } |
91 | } | 93 | } |
92 | { | 94 | { |
95 | |||
93 | QPtrList<Todo> TodoList = cal->rawTodos(); | 96 | QPtrList<Todo> TodoList = cal->rawTodos(); |
94 | Todo * ev = TodoList.first(); | 97 | Todo * ev = TodoList.first(); |
95 | while ( ev ) { | 98 | while ( ev ) { |
99 | QString rel = ev->relatedToUid(); | ||
100 | if ( !rel.isEmpty() ){ | ||
101 | ev->setRelatedTo ( 0 ); | ||
102 | ev->setRelatedToUid( rel ); | ||
103 | } | ||
104 | ev = TodoList.next(); | ||
105 | } | ||
106 | //TodoList = cal->rawTodos(); | ||
107 | ev = TodoList.first(); | ||
108 | while ( ev ) { | ||
109 | ev->unRegisterObserver( cal ); | ||
110 | ev->registerObserver( this ); | ||
96 | mTodoList.append( ev ); | 111 | mTodoList.append( ev ); |
112 | setupRelations( ev ); | ||
97 | ev = TodoList.next(); | 113 | ev = TodoList.next(); |
98 | } | 114 | } |
99 | } | 115 | } |
100 | { | 116 | { |
101 | QPtrList<Journal> JournalList = cal->journals(); | 117 | QPtrList<Journal> JournalList = cal->journals(); |
102 | Journal * ev = JournalList.first(); | 118 | Journal * ev = JournalList.first(); |
103 | while ( ev ) { | 119 | while ( ev ) { |
120 | ev->unRegisterObserver( cal ); | ||
121 | ev->registerObserver( this ); | ||
104 | mJournalList.append( ev ); | 122 | mJournalList.append( ev ); |
105 | ev = JournalList.next(); | 123 | ev = JournalList.next(); |
106 | } | 124 | } |
107 | } | 125 | } |
126 | setModified( true ); | ||
108 | } | 127 | } |
109 | bool CalendarLocal::load( const QString &fileName ) | 128 | bool CalendarLocal::load( const QString &fileName ) |
110 | { | 129 | { |
111 | FileStorage storage( this, fileName ); | 130 | FileStorage storage( this, fileName ); |
112 | return storage.load(); | 131 | return storage.load(); |
113 | } | 132 | } |
114 | 133 | ||
115 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
116 | { | 135 | { |
117 | FileStorage storage( this, fileName, format ); | 136 | FileStorage storage( this, fileName, format ); |
118 | return storage.save(); | 137 | return storage.save(); |
119 | } | 138 | } |
120 | 139 | ||
121 | void CalendarLocal::close() | 140 | void CalendarLocal::close() |
122 | { | 141 | { |
123 | 142 | ||
124 | Todo * i; | 143 | Todo * i; |
125 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
126 | 145 | ||
127 | mEventList.setAutoDelete( true ); | 146 | mEventList.setAutoDelete( true ); |
128 | mTodoList.setAutoDelete( true ); | 147 | mTodoList.setAutoDelete( true ); |
129 | mJournalList.setAutoDelete( false ); | 148 | mJournalList.setAutoDelete( false ); |
130 | 149 | ||
131 | mEventList.clear(); | 150 | mEventList.clear(); |
132 | mTodoList.clear(); | 151 | mTodoList.clear(); |
133 | mJournalList.clear(); | 152 | mJournalList.clear(); |
134 | 153 | ||
135 | mEventList.setAutoDelete( false ); | 154 | mEventList.setAutoDelete( false ); |
136 | mTodoList.setAutoDelete( false ); | 155 | mTodoList.setAutoDelete( false ); |
137 | mJournalList.setAutoDelete( false ); | 156 | mJournalList.setAutoDelete( false ); |
138 | 157 | ||
139 | setModified( false ); | 158 | setModified( false ); |
140 | } | 159 | } |
141 | 160 | ||
142 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
143 | { | 162 | { |
144 | QString cat; | 163 | QString cat; |
145 | bool isBirthday = true; | 164 | bool isBirthday = true; |
146 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
147 | isBirthday = false; | 166 | isBirthday = false; |
148 | cat = i18n( "Anniversary" ); | 167 | cat = i18n( "Anniversary" ); |
149 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
150 | isBirthday = true; | 169 | isBirthday = true; |
151 | cat = i18n( "Birthday" ); | 170 | cat = i18n( "Birthday" ); |
152 | } else { | 171 | } else { |
153 | qDebug("addAnniversaryNoDup called without fitting category! "); | 172 | qDebug("addAnniversaryNoDup called without fitting category! "); |
154 | return false; | 173 | return false; |
155 | } | 174 | } |
156 | Event * eve; | 175 | Event * eve; |
157 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
158 | if ( !(eve->categories().contains( cat ) )) | 177 | if ( !(eve->categories().contains( cat ) )) |
159 | continue; | 178 | continue; |
160 | // now we have an event with fitting category | 179 | // now we have an event with fitting category |
161 | if ( eve->dtStart().date() != event->dtStart().date() ) | 180 | if ( eve->dtStart().date() != event->dtStart().date() ) |
162 | continue; | 181 | continue; |
163 | // now we have an event with fitting category+date | 182 | // now we have an event with fitting category+date |
164 | if ( eve->summary() != event->summary() ) | 183 | if ( eve->summary() != event->summary() ) |
165 | continue; | 184 | continue; |
166 | // now we have an event with fitting category+date+summary | 185 | // now we have an event with fitting category+date+summary |
167 | return false; | 186 | return false; |
168 | } | 187 | } |
169 | return addEvent( event ); | 188 | return addEvent( event ); |
170 | 189 | ||
171 | } | 190 | } |
172 | bool CalendarLocal::addEventNoDup( Event *event ) | 191 | bool CalendarLocal::addEventNoDup( Event *event ) |
173 | { | 192 | { |
174 | Event * eve; | 193 | Event * eve; |
175 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
176 | if ( *eve == *event ) { | 195 | if ( *eve == *event ) { |
177 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
178 | return false; | 197 | return false; |
179 | } | 198 | } |
180 | } | 199 | } |
181 | return addEvent( event ); | 200 | return addEvent( event ); |
182 | } | 201 | } |
183 | 202 | ||
184 | bool CalendarLocal::addEvent( Event *event ) | 203 | bool CalendarLocal::addEvent( Event *event ) |
185 | { | 204 | { |
186 | insertEvent( event ); | 205 | insertEvent( event ); |
187 | 206 | ||
188 | event->registerObserver( this ); | 207 | event->registerObserver( this ); |
189 | 208 | ||
190 | setModified( true ); | 209 | setModified( true ); |
191 | event->setCalID( mDefaultCalendar ); | 210 | event->setCalID( mDefaultCalendar ); |
192 | event->setCalEnabled( true ); | 211 | event->setCalEnabled( true ); |
193 | 212 | ||
194 | return true; | 213 | return true; |
195 | } | 214 | } |
196 | 215 | ||
197 | void CalendarLocal::deleteEvent( Event *event ) | 216 | void CalendarLocal::deleteEvent( Event *event ) |
198 | { | 217 | { |
199 | if ( mUndoIncidence ) delete mUndoIncidence; | 218 | if ( mUndoIncidence ) delete mUndoIncidence; |
200 | mUndoIncidence = event->clone(); | 219 | mUndoIncidence = event->clone(); |
201 | if ( mEventList.removeRef( event ) ) { | 220 | if ( mEventList.removeRef( event ) ) { |
202 | setModified( true ); | 221 | setModified( true ); |
203 | } | 222 | } |
204 | } | 223 | } |
205 | 224 | ||
206 | 225 | ||
207 | Event *CalendarLocal::event( const QString &uid ) | 226 | Event *CalendarLocal::event( const QString &uid ) |
208 | { | 227 | { |
209 | 228 | ||
210 | Event *event; | 229 | Event *event; |
211 | 230 | ||
212 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 231 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
213 | if ( event->uid() == uid && event->calEnabled() ) { | 232 | if ( event->uid() == uid && event->calEnabled() ) { |
214 | return event; | 233 | return event; |
215 | } | 234 | } |
216 | } | 235 | } |
217 | 236 | ||
218 | return 0; | 237 | return 0; |
219 | } | 238 | } |
220 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 239 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
221 | { | 240 | { |
222 | Todo * eve; | 241 | Todo * eve; |
223 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 242 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
224 | if ( *eve == *todo ) { | 243 | if ( *eve == *todo ) { |
225 | //qDebug("duplicate todo found! not inserted! "); | 244 | //qDebug("duplicate todo found! not inserted! "); |
226 | return false; | 245 | return false; |
227 | } | 246 | } |
228 | } | 247 | } |
229 | return addTodo( todo ); | 248 | return addTodo( todo ); |
230 | } | 249 | } |
231 | bool CalendarLocal::addTodo( Todo *todo ) | 250 | bool CalendarLocal::addTodo( Todo *todo ) |
232 | { | 251 | { |
233 | mTodoList.append( todo ); | 252 | mTodoList.append( todo ); |
234 | 253 | ||
235 | todo->registerObserver( this ); | 254 | todo->registerObserver( this ); |
236 | 255 | ||
237 | // Set up subtask relations | 256 | // Set up subtask relations |
238 | setupRelations( todo ); | 257 | setupRelations( todo ); |
239 | 258 | ||
240 | setModified( true ); | 259 | setModified( true ); |
241 | todo->setCalID( mDefaultCalendar ); | 260 | todo->setCalID( mDefaultCalendar ); |
242 | todo->setCalEnabled( true ); | 261 | todo->setCalEnabled( true ); |
243 | return true; | 262 | return true; |
244 | } | 263 | } |
245 | 264 | ||
246 | void CalendarLocal::deleteTodo( Todo *todo ) | 265 | void CalendarLocal::deleteTodo( Todo *todo ) |
247 | { | 266 | { |
248 | // Handle orphaned children | 267 | // Handle orphaned children |
249 | if ( mUndoIncidence ) delete mUndoIncidence; | 268 | if ( mUndoIncidence ) delete mUndoIncidence; |
250 | removeRelations( todo ); | 269 | removeRelations( todo ); |
251 | mUndoIncidence = todo->clone(); | 270 | mUndoIncidence = todo->clone(); |
252 | 271 | ||
253 | if ( mTodoList.removeRef( todo ) ) { | 272 | if ( mTodoList.removeRef( todo ) ) { |
254 | setModified( true ); | 273 | setModified( true ); |
255 | } | 274 | } |
256 | } | 275 | } |
257 | 276 | ||
258 | QPtrList<Todo> CalendarLocal::rawTodos() | 277 | QPtrList<Todo> CalendarLocal::rawTodos() |
259 | { | 278 | { |
260 | QPtrList<Todo> el; | 279 | QPtrList<Todo> el; |
261 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 280 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
262 | if ( it->calEnabled() ) el.append( it ); | 281 | if ( it->calEnabled() ) el.append( it ); |
263 | return el; | 282 | return el; |
264 | } | 283 | } |
265 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 284 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
266 | { | 285 | { |
267 | Todo *todo; | 286 | Todo *todo; |
268 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 287 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
269 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 288 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
270 | } | 289 | } |
271 | 290 | ||
272 | return 0; | 291 | return 0; |
273 | } | 292 | } |
274 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 293 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
275 | { | 294 | { |
276 | QPtrList<Incidence> all = rawIncidences() ; | 295 | QPtrList<Incidence> all = rawIncidences() ; |
277 | Incidence *inc; | 296 | Incidence *inc; |
278 | for ( inc = all.first(); inc; inc = all.next() ) { | 297 | for ( inc = all.first(); inc; inc = all.next() ) { |
279 | inc->removeID( syncProfile ); | 298 | inc->removeID( syncProfile ); |
280 | } | 299 | } |
281 | if ( syncProfile.isEmpty() ) { | 300 | if ( syncProfile.isEmpty() ) { |
282 | QPtrList<Event> el; | 301 | QPtrList<Event> el; |
283 | Event *todo; | 302 | Event *todo; |
284 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 303 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
285 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 304 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
286 | el.append( todo ); | 305 | el.append( todo ); |
287 | } | 306 | } |
288 | for ( todo = el.first(); todo; todo = el.next() ) { | 307 | for ( todo = el.first(); todo; todo = el.next() ) { |
289 | deleteIncidence ( todo ); | 308 | deleteIncidence ( todo ); |
290 | } | 309 | } |
291 | } else { | 310 | } else { |
292 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 311 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
293 | if ( lse ) | 312 | if ( lse ) |
294 | deleteIncidence ( lse ); | 313 | deleteIncidence ( lse ); |
295 | } | 314 | } |
296 | } | 315 | } |
297 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 316 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
298 | { | 317 | { |
299 | QPtrList<Event> el; | 318 | QPtrList<Event> el; |
300 | Event *todo; | 319 | Event *todo; |
301 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 320 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
302 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 321 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
303 | if ( todo->summary().left(3) == "E: " ) | 322 | if ( todo->summary().left(3) == "E: " ) |
304 | el.append( todo ); | 323 | el.append( todo ); |
305 | } | 324 | } |
306 | 325 | ||
307 | return el; | 326 | return el; |
308 | 327 | ||
309 | } | 328 | } |
310 | Event *CalendarLocal::event( QString syncProf, QString id ) | 329 | Event *CalendarLocal::event( QString syncProf, QString id ) |
311 | { | 330 | { |
312 | Event *todo; | 331 | Event *todo; |
313 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 332 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
314 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 333 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
315 | } | 334 | } |
316 | 335 | ||
317 | return 0; | 336 | return 0; |
318 | } | 337 | } |
319 | Todo *CalendarLocal::todo( const QString &uid ) | 338 | Todo *CalendarLocal::todo( const QString &uid ) |
320 | { | 339 | { |
321 | Todo *todo; | 340 | Todo *todo; |
322 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 341 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
323 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; | 342 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; |
324 | } | 343 | } |
325 | 344 | ||
326 | return 0; | 345 | return 0; |
327 | } | 346 | } |
328 | QString CalendarLocal::nextSummary() const | 347 | QString CalendarLocal::nextSummary() const |
329 | { | 348 | { |
330 | return mNextSummary; | 349 | return mNextSummary; |
331 | } | 350 | } |
332 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 351 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
333 | { | 352 | { |
334 | return mNextAlarmEventDateTime; | 353 | return mNextAlarmEventDateTime; |
335 | } | 354 | } |
336 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 355 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
337 | { | 356 | { |
338 | //mNextAlarmIncidence | 357 | //mNextAlarmIncidence |
339 | //mNextAlarmDateTime | 358 | //mNextAlarmDateTime |
340 | //return mNextSummary; | 359 | //return mNextSummary; |
341 | //return mNextAlarmEventDateTime; | 360 | //return mNextAlarmEventDateTime; |
342 | bool newNextAlarm = false; | 361 | bool newNextAlarm = false; |
343 | bool computeNextAlarm = false; | 362 | bool computeNextAlarm = false; |
344 | bool ok; | 363 | bool ok; |
345 | int offset; | 364 | int offset; |
346 | QDateTime nextA; | 365 | QDateTime nextA; |
347 | // QString nextSum; | 366 | // QString nextSum; |
348 | //QDateTime nextEvent; | 367 | //QDateTime nextEvent; |
349 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 368 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
350 | computeNextAlarm = true; | 369 | computeNextAlarm = true; |
351 | } else { | 370 | } else { |
352 | if ( ! deleted ) { | 371 | if ( ! deleted ) { |
353 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 372 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
354 | if ( ok ) { | 373 | if ( ok ) { |
355 | if ( nextA < mNextAlarmDateTime ) { | 374 | if ( nextA < mNextAlarmDateTime ) { |
356 | deRegisterAlarm(); | 375 | deRegisterAlarm(); |
357 | mNextAlarmDateTime = nextA; | 376 | mNextAlarmDateTime = nextA; |
358 | mNextSummary = incidence->summary(); | 377 | mNextSummary = incidence->summary(); |
359 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 378 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
360 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 379 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
361 | newNextAlarm = true; | 380 | newNextAlarm = true; |
362 | mNextAlarmIncidence = incidence; | 381 | mNextAlarmIncidence = incidence; |
363 | } else { | 382 | } else { |
364 | if ( incidence == mNextAlarmIncidence ) { | 383 | if ( incidence == mNextAlarmIncidence ) { |
365 | computeNextAlarm = true; | 384 | computeNextAlarm = true; |
366 | } | 385 | } |
367 | } | 386 | } |
368 | } else { | 387 | } else { |
369 | if ( mNextAlarmIncidence == incidence ) { | 388 | if ( mNextAlarmIncidence == incidence ) { |
370 | computeNextAlarm = true; | 389 | computeNextAlarm = true; |
371 | } | 390 | } |
372 | } | 391 | } |
373 | } else { // deleted | 392 | } else { // deleted |
374 | if ( incidence == mNextAlarmIncidence ) { | 393 | if ( incidence == mNextAlarmIncidence ) { |
375 | computeNextAlarm = true; | 394 | computeNextAlarm = true; |
376 | } | 395 | } |
377 | } | 396 | } |
378 | } | 397 | } |
379 | if ( computeNextAlarm ) { | 398 | if ( computeNextAlarm ) { |
380 | deRegisterAlarm(); | 399 | deRegisterAlarm(); |
381 | nextA = nextAlarm( 1000 ); | 400 | nextA = nextAlarm( 1000 ); |
382 | if (! mNextAlarmIncidence ) { | 401 | if (! mNextAlarmIncidence ) { |
383 | return; | 402 | return; |
384 | } | 403 | } |
385 | newNextAlarm = true; | 404 | newNextAlarm = true; |
386 | } | 405 | } |
387 | if ( newNextAlarm ) | 406 | if ( newNextAlarm ) |
388 | registerAlarm(); | 407 | registerAlarm(); |
389 | } | 408 | } |
390 | QString CalendarLocal:: getAlarmNotification() | 409 | QString CalendarLocal:: getAlarmNotification() |
391 | { | 410 | { |
392 | QString ret; | 411 | QString ret; |
393 | // this should not happen | 412 | // this should not happen |
394 | if (! mNextAlarmIncidence ) | 413 | if (! mNextAlarmIncidence ) |
395 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 414 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
396 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 415 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
397 | if ( alarm->type() == Alarm::Procedure ) { | 416 | if ( alarm->type() == Alarm::Procedure ) { |
398 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 417 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
399 | } else { | 418 | } else { |
400 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 419 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
401 | } | 420 | } |
402 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 421 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
403 | if ( mNextSummary.length() > 25 ) | 422 | if ( mNextSummary.length() > 25 ) |
404 | ret += "\n" + mNextSummary.mid(25, 25 ); | 423 | ret += "\n" + mNextSummary.mid(25, 25 ); |
405 | ret+= "\n"+mNextAlarmEventDateTimeString; | 424 | ret+= "\n"+mNextAlarmEventDateTimeString; |
406 | return ret; | 425 | return ret; |
407 | } | 426 | } |
408 | void CalendarLocal::registerAlarm() | 427 | void CalendarLocal::registerAlarm() |
409 | { | 428 | { |
410 | mLastAlarmNotificationString = getAlarmNotification(); | 429 | mLastAlarmNotificationString = getAlarmNotification(); |
411 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 430 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
412 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 431 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
413 | // #ifndef DESKTOP_VERSION | 432 | // #ifndef DESKTOP_VERSION |
414 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 433 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
415 | // #endif | 434 | // #endif |
416 | } | 435 | } |
417 | void CalendarLocal::deRegisterAlarm() | 436 | void CalendarLocal::deRegisterAlarm() |
418 | { | 437 | { |
419 | if ( mLastAlarmNotificationString.isNull() ) | 438 | if ( mLastAlarmNotificationString.isNull() ) |
420 | return; | 439 | return; |
421 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 440 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
422 | 441 | ||
423 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 442 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
424 | mNextAlarmEventDateTime = QDateTime(); | 443 | mNextAlarmEventDateTime = QDateTime(); |
425 | // #ifndef DESKTOP_VERSION | 444 | // #ifndef DESKTOP_VERSION |
426 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 445 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
427 | // #endif | 446 | // #endif |
428 | } | 447 | } |
429 | 448 | ||
430 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 449 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
431 | { | 450 | { |
432 | QPtrList<Todo> todos; | 451 | QPtrList<Todo> todos; |
433 | 452 | ||
434 | Todo *todo; | 453 | Todo *todo; |
435 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 454 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
436 | if ( !todo->calEnabled() ) continue; | 455 | if ( !todo->calEnabled() ) continue; |
437 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 456 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
438 | todos.append( todo ); | 457 | todos.append( todo ); |
439 | } | 458 | } |
440 | } | 459 | } |
441 | 460 | ||
442 | filter()->apply( &todos ); | 461 | filter()->apply( &todos ); |
443 | return todos; | 462 | return todos; |
444 | } | 463 | } |
445 | void CalendarLocal::reInitAlarmSettings() | 464 | void CalendarLocal::reInitAlarmSettings() |
446 | { | 465 | { |
447 | if ( !mNextAlarmIncidence ) { | 466 | if ( !mNextAlarmIncidence ) { |
448 | nextAlarm( 1000 ); | 467 | nextAlarm( 1000 ); |
449 | } | 468 | } |
450 | deRegisterAlarm(); | 469 | deRegisterAlarm(); |
451 | mNextAlarmIncidence = 0; | 470 | mNextAlarmIncidence = 0; |
452 | checkAlarmForIncidence( 0, false ); | 471 | checkAlarmForIncidence( 0, false ); |
453 | 472 | ||
454 | } | 473 | } |
455 | 474 | ||
456 | 475 | ||
457 | 476 | ||
458 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 477 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
459 | { | 478 | { |
460 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 479 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
461 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 480 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
462 | QDateTime next; | 481 | QDateTime next; |
463 | Event *e; | 482 | Event *e; |
464 | bool ok; | 483 | bool ok; |
465 | bool found = false; | 484 | bool found = false; |
466 | int offset; | 485 | int offset; |
467 | mNextAlarmIncidence = 0; | 486 | mNextAlarmIncidence = 0; |
468 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 487 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
469 | if ( !e->calEnabled() ) continue; | 488 | if ( !e->calEnabled() ) continue; |
470 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 489 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
471 | if ( ok ) { | 490 | if ( ok ) { |
472 | if ( next < nextA ) { | 491 | if ( next < nextA ) { |
473 | nextA = next; | 492 | nextA = next; |
474 | found = true; | 493 | found = true; |
475 | mNextSummary = e->summary(); | 494 | mNextSummary = e->summary(); |
476 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 495 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
477 | mNextAlarmIncidence = (Incidence *) e; | 496 | mNextAlarmIncidence = (Incidence *) e; |
478 | } | 497 | } |
479 | } | 498 | } |
480 | } | 499 | } |
481 | Todo *t; | 500 | Todo *t; |
482 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 501 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
483 | if ( !t->calEnabled() ) continue; | 502 | if ( !t->calEnabled() ) continue; |
484 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 503 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
485 | if ( ok ) { | 504 | if ( ok ) { |
486 | if ( next < nextA ) { | 505 | if ( next < nextA ) { |
487 | nextA = next; | 506 | nextA = next; |
488 | found = true; | 507 | found = true; |
489 | mNextSummary = t->summary(); | 508 | mNextSummary = t->summary(); |
490 | mNextAlarmEventDateTime = next.addSecs(offset ); | 509 | mNextAlarmEventDateTime = next.addSecs(offset ); |
491 | mNextAlarmIncidence = (Incidence *) t; | 510 | mNextAlarmIncidence = (Incidence *) t; |
492 | } | 511 | } |
493 | } | 512 | } |
494 | } | 513 | } |
495 | if ( mNextAlarmIncidence ) { | 514 | if ( mNextAlarmIncidence ) { |
496 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 515 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
497 | mNextAlarmDateTime = nextA; | 516 | mNextAlarmDateTime = nextA; |
498 | } | 517 | } |
499 | return nextA; | 518 | return nextA; |
500 | } | 519 | } |
501 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 520 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
502 | { | 521 | { |
503 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 522 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
504 | } | 523 | } |
505 | 524 | ||
506 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 525 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
507 | { | 526 | { |
508 | 527 | ||
509 | Alarm::List alarms; | 528 | Alarm::List alarms; |
510 | 529 | ||
511 | Event *e; | 530 | Event *e; |
512 | 531 | ||
513 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 532 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
514 | if ( !e->calEnabled() ) continue; | 533 | if ( !e->calEnabled() ) continue; |
515 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 534 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
516 | else appendAlarms( alarms, e, from, to ); | 535 | else appendAlarms( alarms, e, from, to ); |
517 | } | 536 | } |
518 | 537 | ||
519 | Todo *t; | 538 | Todo *t; |
520 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 539 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
521 | if ( !t->calEnabled() ) continue; | 540 | if ( !t->calEnabled() ) continue; |
522 | appendAlarms( alarms, t, from, to ); | 541 | appendAlarms( alarms, t, from, to ); |
523 | } | 542 | } |
524 | 543 | ||
525 | return alarms; | 544 | return alarms; |
526 | } | 545 | } |
527 | 546 | ||
528 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 547 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
529 | const QDateTime &from, const QDateTime &to ) | 548 | const QDateTime &from, const QDateTime &to ) |
530 | { | 549 | { |
531 | QPtrList<Alarm> alarmList = incidence->alarms(); | 550 | QPtrList<Alarm> alarmList = incidence->alarms(); |
532 | Alarm *alarm; | 551 | Alarm *alarm; |
533 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 552 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
534 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 553 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
535 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 554 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
536 | if ( alarm->enabled() ) { | 555 | if ( alarm->enabled() ) { |
537 | if ( alarm->time() >= from && alarm->time() <= to ) { | 556 | if ( alarm->time() >= from && alarm->time() <= to ) { |
538 | alarms.append( alarm ); | 557 | alarms.append( alarm ); |
539 | } | 558 | } |
540 | } | 559 | } |
541 | } | 560 | } |
542 | } | 561 | } |
543 | 562 | ||
544 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 563 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
545 | Incidence *incidence, | 564 | Incidence *incidence, |
546 | const QDateTime &from, | 565 | const QDateTime &from, |
547 | const QDateTime &to ) | 566 | const QDateTime &to ) |
548 | { | 567 | { |
549 | 568 | ||
550 | QPtrList<Alarm> alarmList = incidence->alarms(); | 569 | QPtrList<Alarm> alarmList = incidence->alarms(); |
551 | Alarm *alarm; | 570 | Alarm *alarm; |
552 | QDateTime qdt; | 571 | QDateTime qdt; |
553 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 572 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
554 | if (incidence->recursOn(from.date())) { | 573 | if (incidence->recursOn(from.date())) { |
555 | qdt.setTime(alarm->time().time()); | 574 | qdt.setTime(alarm->time().time()); |
556 | qdt.setDate(from.date()); | 575 | qdt.setDate(from.date()); |
557 | } | 576 | } |
558 | else qdt = alarm->time(); | 577 | else qdt = alarm->time(); |
559 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 578 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
560 | if ( alarm->enabled() ) { | 579 | if ( alarm->enabled() ) { |
561 | if ( qdt >= from && qdt <= to ) { | 580 | if ( qdt >= from && qdt <= to ) { |
562 | alarms.append( alarm ); | 581 | alarms.append( alarm ); |
563 | } | 582 | } |
564 | } | 583 | } |
565 | } | 584 | } |
566 | } | 585 | } |
567 | 586 | ||
568 | 587 | ||
569 | /****************************** PROTECTED METHODS ****************************/ | 588 | /****************************** PROTECTED METHODS ****************************/ |
570 | 589 | ||
571 | // after changes are made to an event, this should be called. | 590 | // after changes are made to an event, this should be called. |
572 | void CalendarLocal::update( IncidenceBase *incidence ) | 591 | void CalendarLocal::update( IncidenceBase *incidence ) |
573 | { | 592 | { |
574 | incidence->setSyncStatus( Event::SYNCMOD ); | 593 | incidence->setSyncStatus( Event::SYNCMOD ); |
575 | incidence->setLastModified( QDateTime::currentDateTime() ); | 594 | incidence->setLastModified( QDateTime::currentDateTime() ); |
576 | // we should probably update the revision number here, | 595 | // we should probably update the revision number here, |
577 | // or internally in the Event itself when certain things change. | 596 | // or internally in the Event itself when certain things change. |
578 | // need to verify with ical documentation. | 597 | // need to verify with ical documentation. |
579 | 598 | ||
580 | setModified( true ); | 599 | setModified( true ); |
581 | } | 600 | } |
582 | 601 | ||
583 | void CalendarLocal::insertEvent( Event *event ) | 602 | void CalendarLocal::insertEvent( Event *event ) |
584 | { | 603 | { |
585 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 604 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
586 | } | 605 | } |
587 | 606 | ||
588 | 607 | ||
589 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 608 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
590 | { | 609 | { |
591 | QPtrList<Event> eventList; | 610 | QPtrList<Event> eventList; |
592 | 611 | ||
593 | Event *event; | 612 | Event *event; |
594 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 613 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
595 | if ( !event->calEnabled() ) continue; | 614 | if ( !event->calEnabled() ) continue; |
596 | if ( event->doesRecur() ) { | 615 | if ( event->doesRecur() ) { |
597 | if ( event->isMultiDay() ) { | 616 | if ( event->isMultiDay() ) { |
598 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 617 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
599 | int i; | 618 | int i; |
600 | for ( i = 0; i <= extraDays; i++ ) { | 619 | for ( i = 0; i <= extraDays; i++ ) { |
601 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 620 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
602 | eventList.append( event ); | 621 | eventList.append( event ); |
603 | break; | 622 | break; |
604 | } | 623 | } |
605 | } | 624 | } |
606 | } else { | 625 | } else { |
607 | if ( event->recursOn( qd ) ) | 626 | if ( event->recursOn( qd ) ) |
608 | eventList.append( event ); | 627 | eventList.append( event ); |
609 | } | 628 | } |
610 | } else { | 629 | } else { |
611 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 630 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
612 | eventList.append( event ); | 631 | eventList.append( event ); |
613 | } | 632 | } |
614 | } | 633 | } |
615 | } | 634 | } |
616 | 635 | ||
617 | if ( !sorted ) { | 636 | if ( !sorted ) { |
618 | return eventList; | 637 | return eventList; |
619 | } | 638 | } |
620 | 639 | ||
621 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 640 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
622 | // now, we have to sort it based on dtStart.time() | 641 | // now, we have to sort it based on dtStart.time() |
623 | QPtrList<Event> eventListSorted; | 642 | QPtrList<Event> eventListSorted; |
624 | Event *sortEvent; | 643 | Event *sortEvent; |
625 | for ( event = eventList.first(); event; event = eventList.next() ) { | 644 | for ( event = eventList.first(); event; event = eventList.next() ) { |
626 | sortEvent = eventListSorted.first(); | 645 | sortEvent = eventListSorted.first(); |
627 | int i = 0; | 646 | int i = 0; |
628 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 647 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
629 | { | 648 | { |
630 | i++; | 649 | i++; |
631 | sortEvent = eventListSorted.next(); | 650 | sortEvent = eventListSorted.next(); |
632 | } | 651 | } |
633 | eventListSorted.insert( i, event ); | 652 | eventListSorted.insert( i, event ); |
634 | } | 653 | } |
635 | return eventListSorted; | 654 | return eventListSorted; |
636 | } | 655 | } |
637 | 656 | ||
638 | 657 | ||
639 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 658 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
640 | bool inclusive ) | 659 | bool inclusive ) |
641 | { | 660 | { |
642 | Event *event = 0; | 661 | Event *event = 0; |
643 | 662 | ||
644 | QPtrList<Event> eventList; | 663 | QPtrList<Event> eventList; |
645 | 664 | ||
646 | // Get non-recurring events | 665 | // Get non-recurring events |
647 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 666 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
648 | if ( !event->calEnabled() ) continue; | 667 | if ( !event->calEnabled() ) continue; |
649 | if ( event->doesRecur() ) { | 668 | if ( event->doesRecur() ) { |
650 | QDate rStart = event->dtStart().date(); | 669 | QDate rStart = event->dtStart().date(); |
651 | bool found = false; | 670 | bool found = false; |
652 | if ( inclusive ) { | 671 | if ( inclusive ) { |
653 | if ( rStart >= start && rStart <= end ) { | 672 | if ( rStart >= start && rStart <= end ) { |
654 | // Start date of event is in range. Now check for end date. | 673 | // Start date of event is in range. Now check for end date. |
655 | // if duration is negative, event recurs forever, so do not include it. | 674 | // if duration is negative, event recurs forever, so do not include it. |
656 | if ( event->recurrence()->duration() == 0 ) { // End date set | 675 | if ( event->recurrence()->duration() == 0 ) { // End date set |
657 | QDate rEnd = event->recurrence()->endDate(); | 676 | QDate rEnd = event->recurrence()->endDate(); |
658 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 677 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
659 | found = true; | 678 | found = true; |
660 | } | 679 | } |
661 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 680 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
662 | // TODO: Calculate end date from duration. Should be done in Event | 681 | // TODO: Calculate end date from duration. Should be done in Event |
663 | // For now exclude all events with a duration. | 682 | // For now exclude all events with a duration. |
664 | } | 683 | } |
665 | } | 684 | } |
666 | } else { | 685 | } else { |
667 | bool founOne; | 686 | bool founOne; |
668 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 687 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
669 | if ( founOne ) { | 688 | if ( founOne ) { |
670 | if ( next <= end ) { | 689 | if ( next <= end ) { |
671 | found = true; | 690 | found = true; |
672 | } | 691 | } |
673 | } | 692 | } |
674 | 693 | ||
675 | /* | 694 | /* |
676 | // crap !!! | 695 | // crap !!! |
677 | if ( rStart <= end ) { // Start date not after range | 696 | if ( rStart <= end ) { // Start date not after range |
678 | if ( rStart >= start ) { // Start date within range | 697 | if ( rStart >= start ) { // Start date within range |
679 | found = true; | 698 | found = true; |
680 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 699 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
681 | found = true; | 700 | found = true; |
682 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 701 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
683 | QDate rEnd = event->recurrence()->endDate(); | 702 | QDate rEnd = event->recurrence()->endDate(); |
684 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 703 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
685 | found = true; | 704 | found = true; |
686 | } | 705 | } |
687 | } else { // Duration set | 706 | } else { // Duration set |
688 | // TODO: Calculate end date from duration. Should be done in Event | 707 | // TODO: Calculate end date from duration. Should be done in Event |
689 | // For now include all events with a duration. | 708 | // For now include all events with a duration. |
690 | found = true; | 709 | found = true; |
691 | } | 710 | } |
692 | } | 711 | } |
693 | */ | 712 | */ |
694 | 713 | ||
695 | } | 714 | } |
696 | 715 | ||
697 | if ( found ) eventList.append( event ); | 716 | if ( found ) eventList.append( event ); |
698 | } else { | 717 | } else { |
699 | QDate s = event->dtStart().date(); | 718 | QDate s = event->dtStart().date(); |
700 | QDate e = event->dtEnd().date(); | 719 | QDate e = event->dtEnd().date(); |
701 | 720 | ||
702 | if ( inclusive ) { | 721 | if ( inclusive ) { |
703 | if ( s >= start && e <= end ) { | 722 | if ( s >= start && e <= end ) { |
704 | eventList.append( event ); | 723 | eventList.append( event ); |
705 | } | 724 | } |
706 | } else { | 725 | } else { |
707 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 726 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
708 | eventList.append( event ); | 727 | eventList.append( event ); |
709 | } | 728 | } |
710 | } | 729 | } |
711 | } | 730 | } |
712 | } | 731 | } |
713 | 732 | ||
714 | return eventList; | 733 | return eventList; |
715 | } | 734 | } |
716 | 735 | ||
717 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 736 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
718 | { | 737 | { |
719 | return rawEventsForDate( qdt.date() ); | 738 | return rawEventsForDate( qdt.date() ); |
720 | } | 739 | } |
721 | 740 | ||
722 | QPtrList<Event> CalendarLocal::rawEvents() | 741 | QPtrList<Event> CalendarLocal::rawEvents() |
723 | { | 742 | { |
724 | QPtrList<Event> el; | 743 | QPtrList<Event> el; |
725 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 744 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
726 | if ( it->calEnabled() ) el.append( it ); | 745 | if ( it->calEnabled() ) el.append( it ); |
727 | return el; | 746 | return el; |
728 | } | 747 | } |
729 | 748 | ||
730 | bool CalendarLocal::addJournal(Journal *journal) | 749 | bool CalendarLocal::addJournal(Journal *journal) |
731 | { | 750 | { |
732 | if ( journal->dtStart().isValid()) | 751 | if ( journal->dtStart().isValid()) |
733 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 752 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
734 | else | 753 | else |
735 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 754 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
736 | 755 | ||
737 | mJournalList.append(journal); | 756 | mJournalList.append(journal); |
738 | 757 | ||
739 | journal->registerObserver( this ); | 758 | journal->registerObserver( this ); |
740 | 759 | ||
741 | setModified( true ); | 760 | setModified( true ); |
742 | journal->setCalID( mDefaultCalendar ); | 761 | journal->setCalID( mDefaultCalendar ); |
743 | journal->setCalEnabled( true ); | 762 | journal->setCalEnabled( true ); |
744 | return true; | 763 | return true; |
745 | } | 764 | } |
746 | 765 | ||
747 | void CalendarLocal::deleteJournal( Journal *journal ) | 766 | void CalendarLocal::deleteJournal( Journal *journal ) |
748 | { | 767 | { |
749 | if ( mUndoIncidence ) delete mUndoIncidence; | 768 | if ( mUndoIncidence ) delete mUndoIncidence; |
750 | mUndoIncidence = journal->clone(); | 769 | mUndoIncidence = journal->clone(); |
751 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 770 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
752 | if ( mJournalList.removeRef(journal) ) { | 771 | if ( mJournalList.removeRef(journal) ) { |
753 | setModified( true ); | 772 | setModified( true ); |
754 | } | 773 | } |
755 | } | 774 | } |
756 | 775 | ||
757 | Journal *CalendarLocal::journal( const QDate &date ) | 776 | Journal *CalendarLocal::journal( const QDate &date ) |
758 | { | 777 | { |
759 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 778 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
760 | 779 | ||
761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
762 | if ( it->calEnabled() && it->dtStart().date() == date ) | 781 | if ( it->calEnabled() && it->dtStart().date() == date ) |
763 | return it; | 782 | return it; |
764 | 783 | ||
765 | return 0; | 784 | return 0; |
766 | } | 785 | } |
767 | 786 | ||
768 | Journal *CalendarLocal::journal( const QString &uid ) | 787 | Journal *CalendarLocal::journal( const QString &uid ) |
769 | { | 788 | { |
770 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 789 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
771 | if ( it->calEnabled() && it->uid() == uid ) | 790 | if ( it->calEnabled() && it->uid() == uid ) |
772 | return it; | 791 | return it; |
773 | 792 | ||
774 | return 0; | 793 | return 0; |
775 | } | 794 | } |
776 | 795 | ||
777 | QPtrList<Journal> CalendarLocal::journals() | 796 | QPtrList<Journal> CalendarLocal::journals() |
778 | { | 797 | { |
779 | QPtrList<Journal> el; | 798 | QPtrList<Journal> el; |
780 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 799 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
781 | if ( it->calEnabled() ) el.append( it ); | 800 | if ( it->calEnabled() ) el.append( it ); |
782 | return el; | 801 | return el; |
783 | } | 802 | } |
803 | void CalendarLocal::setCalendarRemove( int id ) | ||
804 | { | ||
805 | |||
806 | { | ||
807 | QPtrList<Event> EventList = mEventList; | ||
808 | Event * ev = EventList.first(); | ||
809 | while ( ev ) { | ||
810 | if ( ev->calID() == id ) | ||
811 | deleteEvent( ev ); | ||
812 | ev = EventList.next(); | ||
813 | } | ||
814 | } | ||
815 | { | ||
816 | |||
817 | QPtrList<Todo> TodoList = mTodoList; | ||
818 | Todo * ev = TodoList.first(); | ||
819 | while ( ev ) { | ||
820 | if ( ev->calID() == id ) | ||
821 | deleteTodo( ev ); | ||
822 | ev = TodoList.next(); | ||
823 | } | ||
824 | } | ||
825 | { | ||
826 | QPtrList<Journal> JournalList = mJournalList; | ||
827 | Journal * ev = JournalList.first(); | ||
828 | while ( ev ) { | ||
829 | if ( ev->calID() == id ) | ||
830 | deleteJournal( ev ); | ||
831 | ev = JournalList.next(); | ||
832 | } | ||
833 | } | ||
834 | |||
835 | if ( mUndoIncidence ) delete mUndoIncidence; | ||
836 | mUndoIncidence = 0; | ||
837 | |||
838 | } | ||
784 | 839 | ||
785 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 840 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
786 | { | 841 | { |
787 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 842 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
788 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 843 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
789 | 844 | ||
790 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 845 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
791 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 846 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
792 | 847 | ||
793 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 848 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
794 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 849 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
795 | 850 | ||
796 | } | 851 | } |
797 | 852 | ||
798 | void CalendarLocal::setReadOnly( int id, bool enable ) | 853 | void CalendarLocal::setReadOnly( int id, bool enable ) |
799 | { | 854 | { |
800 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 855 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
801 | if ( it->calID() == id ) it->setReadOnly( enable ); | 856 | if ( it->calID() == id ) it->setReadOnly( enable ); |
802 | 857 | ||
803 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 858 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
804 | if ( it->calID() == id ) it->setReadOnly( enable ); | 859 | if ( it->calID() == id ) it->setReadOnly( enable ); |
805 | 860 | ||
806 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 861 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
807 | if ( it->calID() == id ) it->setReadOnly( enable ); | 862 | if ( it->calID() == id ) it->setReadOnly( enable ); |
808 | 863 | ||
809 | } | 864 | } |
810 | 865 | ||
811 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 866 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
812 | { | 867 | { |
813 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 868 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
814 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 869 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
815 | 870 | ||
816 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 871 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
817 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 872 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
818 | 873 | ||
819 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 874 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
820 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 875 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
876 | reInitAlarmSettings(); | ||
821 | 877 | ||
822 | } | 878 | } |
823 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 879 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
824 | { | 880 | { |
825 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 881 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
826 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 882 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
827 | 883 | ||
828 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 884 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
829 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 885 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
830 | 886 | ||
831 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 887 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
832 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 888 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
833 | 889 | ||
834 | } | 890 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 65f6aa7..5bbe55f 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,223 +1,224 @@ | |||
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 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | /** | 48 | /** |
49 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 49 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
50 | calendar. Any information already present is lost. | 50 | calendar. Any information already present is lost. |
51 | @return true, if successfull, false on error. | 51 | @return true, if successfull, false on error. |
52 | @param fileName the name of the calendar on disk. | 52 | @param fileName the name of the calendar on disk. |
53 | */ | 53 | */ |
54 | bool load( const QString &fileName ); | 54 | bool load( const QString &fileName ); |
55 | /** | 55 | /** |
56 | Writes out the calendar to disk in the specified \a format. | 56 | Writes out the calendar to disk in the specified \a format. |
57 | CalendarLocal takes ownership of the CalFormat object. | 57 | CalendarLocal takes ownership of the CalFormat object. |
58 | @return true, if successfull, false on error. | 58 | @return true, if successfull, false on error. |
59 | @param fileName the name of the file | 59 | @param fileName the name of the file |
60 | */ | 60 | */ |
61 | bool save( const QString &fileName, CalFormat *format = 0 ); | 61 | bool save( const QString &fileName, CalFormat *format = 0 ); |
62 | 62 | ||
63 | /** | 63 | /** |
64 | Clears out the current calendar, freeing all used memory etc. etc. | 64 | Clears out the current calendar, freeing all used memory etc. etc. |
65 | */ | 65 | */ |
66 | void close(); | 66 | void close(); |
67 | 67 | ||
68 | void save() {} | 68 | void save() {} |
69 | 69 | ||
70 | /** | 70 | /** |
71 | Add Event to calendar. | 71 | Add Event to calendar. |
72 | */ | 72 | */ |
73 | void removeSyncInfo( QString syncProfile); | 73 | void removeSyncInfo( QString syncProfile); |
74 | bool addAnniversaryNoDup( Event *event ); | 74 | bool addAnniversaryNoDup( Event *event ); |
75 | bool addEventNoDup( Event *event ); | 75 | bool addEventNoDup( Event *event ); |
76 | bool addEvent( Event *event ); | 76 | bool addEvent( Event *event ); |
77 | /** | 77 | /** |
78 | Deletes an event from this calendar. | 78 | Deletes an event from this calendar. |
79 | */ | 79 | */ |
80 | void deleteEvent( Event *event ); | 80 | void deleteEvent( Event *event ); |
81 | 81 | ||
82 | /** | 82 | /** |
83 | Retrieves an event on the basis of the unique string ID. | 83 | Retrieves an event on the basis of the unique string ID. |
84 | */ | 84 | */ |
85 | Event *event( const QString &uid ); | 85 | Event *event( const QString &uid ); |
86 | /** | 86 | /** |
87 | Return unfiltered list of all events in calendar. | 87 | Return unfiltered list of all events in calendar. |
88 | */ | 88 | */ |
89 | QPtrList<Event> rawEvents(); | 89 | QPtrList<Event> rawEvents(); |
90 | QPtrList<Event> getExternLastSyncEvents(); | 90 | QPtrList<Event> getExternLastSyncEvents(); |
91 | /** | 91 | /** |
92 | Add a todo to the todolist. | 92 | Add a todo to the todolist. |
93 | */ | 93 | */ |
94 | bool addTodo( Todo *todo ); | 94 | bool addTodo( Todo *todo ); |
95 | bool addTodoNoDup( Todo *todo ); | 95 | bool addTodoNoDup( Todo *todo ); |
96 | /** | 96 | /** |
97 | Remove a todo from the todolist. | 97 | Remove a todo from the todolist. |
98 | */ | 98 | */ |
99 | void deleteTodo( Todo * ); | 99 | void deleteTodo( Todo * ); |
100 | /** | 100 | /** |
101 | Searches todolist for an event with this unique string identifier, | 101 | Searches todolist for an event with this unique string identifier, |
102 | returns a pointer or null. | 102 | returns a pointer or null. |
103 | */ | 103 | */ |
104 | Todo *todo( const QString &uid ); | 104 | Todo *todo( const QString &uid ); |
105 | /** | 105 | /** |
106 | Return list of all todos. | 106 | Return list of all todos. |
107 | */ | 107 | */ |
108 | QPtrList<Todo> rawTodos(); | 108 | QPtrList<Todo> rawTodos(); |
109 | /** | 109 | /** |
110 | Returns list of todos due on the specified date. | 110 | Returns list of todos due on the specified date. |
111 | */ | 111 | */ |
112 | QPtrList<Todo> todos( const QDate &date ); | 112 | QPtrList<Todo> todos( const QDate &date ); |
113 | /** | 113 | /** |
114 | Return list of all todos. | 114 | Return list of all todos. |
115 | 115 | ||
116 | Workaround because compiler does not recognize function of base class. | 116 | Workaround because compiler does not recognize function of base class. |
117 | */ | 117 | */ |
118 | QPtrList<Todo> todos() { return Calendar::todos(); } | 118 | QPtrList<Todo> todos() { return Calendar::todos(); } |
119 | 119 | ||
120 | /** | 120 | /** |
121 | Add a Journal entry to calendar. | 121 | Add a Journal entry to calendar. |
122 | */ | 122 | */ |
123 | bool addJournal( Journal * ); | 123 | bool addJournal( Journal * ); |
124 | /** | 124 | /** |
125 | Remove a Journal from the calendar. | 125 | Remove a Journal from the calendar. |
126 | */ | 126 | */ |
127 | void deleteJournal( Journal * ); | 127 | void deleteJournal( Journal * ); |
128 | /** | 128 | /** |
129 | Return Journal for given date. | 129 | Return Journal for given date. |
130 | */ | 130 | */ |
131 | Journal *journal( const QDate & ); | 131 | Journal *journal( const QDate & ); |
132 | /** | 132 | /** |
133 | Return Journal with given UID. | 133 | Return Journal with given UID. |
134 | */ | 134 | */ |
135 | Journal *journal( const QString &uid ); | 135 | Journal *journal( const QString &uid ); |
136 | /** | 136 | /** |
137 | Return list of all Journals stored in calendar. | 137 | Return list of all Journals stored in calendar. |
138 | */ | 138 | */ |
139 | QPtrList<Journal> journals(); | 139 | QPtrList<Journal> journals(); |
140 | 140 | ||
141 | /** | 141 | /** |
142 | Return all alarms, which ocur in the given time interval. | 142 | Return all alarms, which ocur in the given time interval. |
143 | */ | 143 | */ |
144 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 144 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
145 | 145 | ||
146 | /** | 146 | /** |
147 | Return all alarms, which ocur before given date. | 147 | Return all alarms, which ocur before given date. |
148 | */ | 148 | */ |
149 | Alarm::List alarmsTo( const QDateTime &to ); | 149 | Alarm::List alarmsTo( const QDateTime &to ); |
150 | 150 | ||
151 | QDateTime nextAlarm( int daysTo ) ; | 151 | QDateTime nextAlarm( int daysTo ) ; |
152 | QDateTime nextAlarmEventDateTime() const; | 152 | QDateTime nextAlarmEventDateTime() const; |
153 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 153 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
154 | void registerAlarm(); | 154 | void registerAlarm(); |
155 | void deRegisterAlarm(); | 155 | void deRegisterAlarm(); |
156 | QString getAlarmNotification(); | 156 | QString getAlarmNotification(); |
157 | QString nextSummary() const ; | 157 | QString nextSummary() const ; |
158 | /** | 158 | /** |
159 | This method should be called whenever a Event is modified directly | 159 | This method should be called whenever a Event is modified directly |
160 | via it's pointer. It makes sure that the calendar is internally | 160 | via it's pointer. It makes sure that the calendar is internally |
161 | consistent. | 161 | consistent. |
162 | */ | 162 | */ |
163 | void update( IncidenceBase *incidence ); | 163 | void update( IncidenceBase *incidence ); |
164 | 164 | ||
165 | /** | 165 | /** |
166 | Builds and then returns a list of all events that match for the | 166 | Builds and then returns a list of all events that match for the |
167 | date specified. useful for dayView, etc. etc. | 167 | date specified. useful for dayView, etc. etc. |
168 | */ | 168 | */ |
169 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 169 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
170 | /** | 170 | /** |
171 | Get unfiltered events for date \a qdt. | 171 | Get unfiltered events for date \a qdt. |
172 | */ | 172 | */ |
173 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 173 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
174 | /** | 174 | /** |
175 | Get unfiltered events in a range of dates. If inclusive is set to true, | 175 | Get unfiltered events in a range of dates. If inclusive is set to true, |
176 | only events are returned, which are completely included in the range. | 176 | only events are returned, which are completely included in the range. |
177 | */ | 177 | */ |
178 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 178 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
179 | bool inclusive = false ); | 179 | bool inclusive = false ); |
180 | Todo *todo( QString, QString ); | 180 | Todo *todo( QString, QString ); |
181 | Event *event( QString, QString ); | 181 | Event *event( QString, QString ); |
182 | 182 | ||
183 | public slots: | 183 | public slots: |
184 | void setCalendarEnabled( int id, bool enable ); | 184 | void setCalendarEnabled( int id, bool enable ); |
185 | void setAlarmEnabled( int id, bool enable ); | 185 | void setAlarmEnabled( int id, bool enable ); |
186 | void setReadOnly( int id, bool enable ); | 186 | void setReadOnly( int id, bool enable ); |
187 | void setDefaultCalendarEnabledOnly(); | 187 | void setDefaultCalendarEnabledOnly(); |
188 | void setCalendarRemove( int id ); | ||
188 | 189 | ||
189 | protected: | 190 | protected: |
190 | 191 | ||
191 | // Event* mNextAlarmEvent; | 192 | // Event* mNextAlarmEvent; |
192 | QString mNextSummary; | 193 | QString mNextSummary; |
193 | QString mNextAlarmEventDateTimeString; | 194 | QString mNextAlarmEventDateTimeString; |
194 | QString mLastAlarmNotificationString; | 195 | QString mLastAlarmNotificationString; |
195 | QDateTime mNextAlarmEventDateTime; | 196 | QDateTime mNextAlarmEventDateTime; |
196 | QDateTime mNextAlarmDateTime; | 197 | QDateTime mNextAlarmDateTime; |
197 | void reInitAlarmSettings(); | 198 | void reInitAlarmSettings(); |
198 | 199 | ||
199 | /** Notification function of IncidenceBase::Observer. */ | 200 | /** Notification function of IncidenceBase::Observer. */ |
200 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 201 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
201 | 202 | ||
202 | /** inserts an event into its "proper place" in the calendar. */ | 203 | /** inserts an event into its "proper place" in the calendar. */ |
203 | void insertEvent( Event *event ); | 204 | void insertEvent( Event *event ); |
204 | 205 | ||
205 | /** Append alarms of incidence in interval to list of alarms. */ | 206 | /** Append alarms of incidence in interval to list of alarms. */ |
206 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 207 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
207 | const QDateTime &from, const QDateTime &to ); | 208 | const QDateTime &from, const QDateTime &to ); |
208 | 209 | ||
209 | /** Append alarms of recurring events in interval to list of alarms. */ | 210 | /** Append alarms of recurring events in interval to list of alarms. */ |
210 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 211 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
211 | const QDateTime &from, const QDateTime &to ); | 212 | const QDateTime &from, const QDateTime &to ); |
212 | 213 | ||
213 | private: | 214 | private: |
214 | void init(); | 215 | void init(); |
215 | 216 | ||
216 | QPtrList<Event> mEventList; | 217 | QPtrList<Event> mEventList; |
217 | QPtrList<Todo> mTodoList; | 218 | QPtrList<Todo> mTodoList; |
218 | QPtrList<Journal> mJournalList; | 219 | QPtrList<Journal> mJournalList; |
219 | }; | 220 | }; |
220 | 221 | ||
221 | } | 222 | } |
222 | 223 | ||
223 | #endif | 224 | #endif |