summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/alarm.cpp2
-rw-r--r--libkcal/event.cpp8
-rw-r--r--libkcal/event.h1
-rw-r--r--libkcal/incidence.cpp29
-rw-r--r--libkcal/incidence.h3
-rw-r--r--libkcal/todo.cpp10
-rw-r--r--libkcal/todo.h1
7 files changed, 52 insertions, 2 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 79e0464..3157214 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,483 +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
30using namespace KCal; 30using namespace KCal;
31#include <qwidget.h> 31#include <qwidget.h>
32Alarm::Alarm(Incidence *parent) 32Alarm::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
47Alarm::~Alarm() 47Alarm::~Alarm()
48{ 48{
49} 49}
50 50
51bool Alarm::operator==( const Alarm& rhs ) const 51bool 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
126void Alarm::setType(Alarm::Type type) 126void 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
155Alarm::Type Alarm::type() const 155Alarm::Type Alarm::type() const
156{ 156{
157 return mType; 157 return mType;
158} 158}
159 159
160void Alarm::setAudioAlarm(const QString &audioFile) 160void 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
167void Alarm::setAudioFile(const QString &audioFile) 167void 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
175QString Alarm::audioFile() const 175QString Alarm::audioFile() const
176{ 176{
177 return (mType == Audio) ? mFile : QString::null; 177 return (mType == Audio) ? mFile : QString::null;
178} 178}
179 179
180void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 180void 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
188void Alarm::setProgramFile(const QString &programFile) 188void 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
196QString Alarm::programFile() const 196QString Alarm::programFile() const
197{ 197{
198 return (mType == Procedure) ? mFile : QString::null; 198 return (mType == Procedure) ? mFile : QString::null;
199} 199}
200 200
201void Alarm::setProgramArguments(const QString &arguments) 201void 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
209QString Alarm::programArguments() const 209QString Alarm::programArguments() const
210{ 210{
211 return (mType == Procedure) ? mDescription : QString::null; 211 return (mType == Procedure) ? mDescription : QString::null;
212} 212}
213 213
214void Alarm::setEmailAlarm(const QString &subject, const QString &text, 214void 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
225void Alarm::setMailAddress(const Person &mailAddress) 225void 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
234void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 234void 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
242void Alarm::addMailAddress(const Person &mailAddress) 242void 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
250QValueList<Person> Alarm::mailAddresses() const 250QValueList<Person> Alarm::mailAddresses() const
251{ 251{
252 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 252 return (mType == Email) ? mMailAddresses : QValueList<Person>();
253} 253}
254 254
255void Alarm::setMailSubject(const QString &mailAlarmSubject) 255void 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
263QString Alarm::mailSubject() const 263QString Alarm::mailSubject() const
264{ 264{
265 return (mType == Email) ? mMailSubject : QString::null; 265 return (mType == Email) ? mMailSubject : QString::null;
266} 266}
267 267
268void Alarm::setMailAttachment(const QString &mailAttachFile) 268void 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
277void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 277void 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
285void Alarm::addMailAttachment(const QString &mailAttachFile) 285void 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
293QStringList Alarm::mailAttachments() const 293QStringList Alarm::mailAttachments() const
294{ 294{
295 return (mType == Email) ? mMailAttachFiles : QStringList(); 295 return (mType == Email) ? mMailAttachFiles : QStringList();
296} 296}
297 297
298void Alarm::setMailText(const QString &text) 298void 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
306QString Alarm::mailText() const 306QString Alarm::mailText() const
307{ 307{
308 return (mType == Email) ? mDescription : QString::null; 308 return (mType == Email) ? mDescription : QString::null;
309} 309}
310 310
311void Alarm::setDisplayAlarm(const QString &text) 311void 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
318void Alarm::setText(const QString &text) 318void 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
326QString Alarm::text() const 326QString Alarm::text() const
327{ 327{
328 return (mType == Display) ? mDescription : QString::null; 328 return (mType == Display) ? mDescription : QString::null;
329} 329}
330 330
331void Alarm::setTime(const QDateTime &alarmTime) 331void 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}
338int Alarm::offset() 338int 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}
353QString Alarm::offsetText() 353QString 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() ) 374 if ( !mParent->alarmEnabled() )
375 return "!"+message + i18n("(disabled)"); 375 return "!"+message + i18n("(disabled)");
376 return message; 376 return message;
377} 377}
378 378
379 379
380QDateTime Alarm::time() const 380QDateTime Alarm::time() const
381{ 381{
382 if ( hasTime() ) 382 if ( hasTime() )
383 return mAlarmTime; 383 return mAlarmTime;
384 else 384 else
385 { 385 {
386 if (mParent->typeID() == todoID ) { 386 if (mParent->typeID() == todoID ) {
387 Todo *t = static_cast<Todo*>(mParent); 387 Todo *t = static_cast<Todo*>(mParent);
388 return mOffset.end( t->dtDue() ); 388 return mOffset.end( t->dtDue() );
389 } else if (mEndOffset) { 389 } else if (mEndOffset) {
390 return mOffset.end( mParent->dtEnd() ); 390 return mOffset.end( mParent->dtEnd() );
391 } else { 391 } else {
392 return mOffset.end( mParent->dtStart() ); 392 return mOffset.end( mParent->dtStart() );
393 } 393 }
394 } 394 }
395} 395}
396 396
397bool Alarm::hasTime() const 397bool Alarm::hasTime() const
398{ 398{
399 return mHasTime; 399 return mHasTime;
400} 400}
401 401
402void Alarm::setSnoozeTime(int alarmSnoozeTime) 402void Alarm::setSnoozeTime(int alarmSnoozeTime)
403{ 403{
404 mAlarmSnoozeTime = alarmSnoozeTime; 404 mAlarmSnoozeTime = alarmSnoozeTime;
405 mParent->updated(); 405 mParent->updated();
406} 406}
407 407
408int Alarm::snoozeTime() const 408int Alarm::snoozeTime() const
409{ 409{
410 return mAlarmSnoozeTime; 410 return mAlarmSnoozeTime;
411} 411}
412 412
413void Alarm::setRepeatCount(int alarmRepeatCount) 413void Alarm::setRepeatCount(int alarmRepeatCount)
414{ 414{
415 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; 415 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
416 416
417 mAlarmRepeatCount = alarmRepeatCount; 417 mAlarmRepeatCount = alarmRepeatCount;
418 mParent->updated(); 418 mParent->updated();
419} 419}
420 420
421int Alarm::repeatCount() const 421int Alarm::repeatCount() const
422{ 422{
423 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; 423 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
424 return mAlarmRepeatCount; 424 return mAlarmRepeatCount;
425} 425}
426 426
427void Alarm::toggleAlarm() 427void Alarm::toggleAlarm()
428{ 428{
429 mAlarmEnabled = !mAlarmEnabled; 429 mAlarmEnabled = !mAlarmEnabled;
430 mParent->updated(); 430 mParent->updated();
431} 431}
432 432
433void Alarm::setEnabled(bool enable) 433void Alarm::setEnabled(bool enable)
434{ 434{
435 mAlarmEnabled = enable; 435 mAlarmEnabled = enable;
436 mParent->updated(); 436 mParent->updated();
437} 437}
438 438
439bool Alarm::enabled() const 439bool Alarm::enabled() const
440{ 440{
441 return mAlarmEnabled; 441 return mAlarmEnabled;
442} 442}
443 443
444void Alarm::setStartOffset( const Duration &offset ) 444void Alarm::setStartOffset( const Duration &offset )
445{ 445{
446 mOffset = offset; 446 mOffset = offset;
447 mEndOffset = false; 447 mEndOffset = false;
448 mHasTime = false; 448 mHasTime = false;
449 mParent->updated(); 449 mParent->updated();
450} 450}
451 451
452Duration Alarm::startOffset() const 452Duration Alarm::startOffset() const
453{ 453{
454 return (mHasTime || mEndOffset) ? 0 : mOffset; 454 return (mHasTime || mEndOffset) ? 0 : mOffset;
455} 455}
456 456
457bool Alarm::hasStartOffset() const 457bool Alarm::hasStartOffset() const
458{ 458{
459 return !mHasTime && !mEndOffset; 459 return !mHasTime && !mEndOffset;
460} 460}
461 461
462bool Alarm::hasEndOffset() const 462bool Alarm::hasEndOffset() const
463{ 463{
464 return !mHasTime && mEndOffset; 464 return !mHasTime && mEndOffset;
465} 465}
466 466
467void Alarm::setEndOffset( const Duration &offset ) 467void Alarm::setEndOffset( const Duration &offset )
468{ 468{
469 mOffset = offset; 469 mOffset = offset;
470 mEndOffset = true; 470 mEndOffset = true;
471 mHasTime = false; 471 mHasTime = false;
472 mParent->updated(); 472 mParent->updated();
473} 473}
474 474
475Duration Alarm::endOffset() const 475Duration Alarm::endOffset() const
476{ 476{
477 return (mHasTime || !mEndOffset) ? 0 : mOffset; 477 return (mHasTime || !mEndOffset) ? 0 : mOffset;
478} 478}
479 479
480void Alarm::setParent( Incidence *parent ) 480void Alarm::setParent( Incidence *parent )
481{ 481{
482 mParent = parent; 482 mParent = parent;
483} 483}
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index 0766fd9..fdf5657 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -1,416 +1,424 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "event.h" 25#include "event.h"
26 26
27using namespace KCal; 27using namespace KCal;
28 28
29Event::Event() : 29Event::Event() :
30 mHasEndDate( false ), mTransparency( Opaque ) 30 mHasEndDate( false ), mTransparency( Opaque )
31{ 31{
32} 32}
33 33
34Event::Event(const Event &e) : Incidence(e) 34Event::Event(const Event &e) : Incidence(e)
35{ 35{
36 mDtEnd = e.mDtEnd; 36 mDtEnd = e.mDtEnd;
37 mHasEndDate = e.mHasEndDate; 37 mHasEndDate = e.mHasEndDate;
38 mTransparency = e.mTransparency; 38 mTransparency = e.mTransparency;
39} 39}
40 40
41Event::~Event() 41Event::~Event()
42{ 42{
43} 43}
44 44
45Incidence *Event::clone() 45Incidence *Event::clone()
46{ 46{
47 return new Event(*this); 47 return new Event(*this);
48} 48}
49 49
50bool KCal::operator==( const Event& e1, const Event& e2 ) 50bool KCal::operator==( const Event& e1, const Event& e2 )
51{ 51{
52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && 52 return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
53 e1.dtEnd() == e2.dtEnd() && 53 e1.dtEnd() == e2.dtEnd() &&
54 e1.hasEndDate() == e2.hasEndDate() && 54 e1.hasEndDate() == e2.hasEndDate() &&
55 e1.transparency() == e2.transparency(); 55 e1.transparency() == e2.transparency();
56} 56}
57 57
58 58
59bool Event::contains ( Event* from ) 59bool Event::contains ( Event* from )
60{ 60{
61 61
62 if ( !from->summary().isEmpty() ) 62 if ( !from->summary().isEmpty() )
63 if ( !summary().startsWith( from->summary() )) 63 if ( !summary().startsWith( from->summary() ))
64 return false; 64 return false;
65 if ( from->dtStart().isValid() ) 65 if ( from->dtStart().isValid() )
66 if (dtStart() != from->dtStart() ) 66 if (dtStart() != from->dtStart() )
67 return false; 67 return false;
68 if ( from->dtEnd().isValid() ) 68 if ( from->dtEnd().isValid() )
69 if ( dtEnd() != from->dtEnd() ) 69 if ( dtEnd() != from->dtEnd() )
70 return false; 70 return false;
71 if ( !from->location().isEmpty() ) 71 if ( !from->location().isEmpty() )
72 if ( !location().startsWith( from->location() ) ) 72 if ( !location().startsWith( from->location() ) )
73 return false; 73 return false;
74 if ( !from->description().isEmpty() ) 74 if ( !from->description().isEmpty() )
75 if ( !description().startsWith( from->description() )) 75 if ( !description().startsWith( from->description() ))
76 return false; 76 return false;
77 if ( from->alarms().count() ) { 77 if ( from->alarms().count() ) {
78 Alarm *a = from->alarms().first(); 78 Alarm *a = from->alarms().first();
79 if ( a->enabled() ){ 79 if ( a->enabled() ){
80 if ( !alarms().count() ) 80 if ( !alarms().count() )
81 return false; 81 return false;
82 Alarm *b = alarms().first(); 82 Alarm *b = alarms().first();
83 if( ! b->enabled() ) 83 if( ! b->enabled() )
84 return false; 84 return false;
85 if ( ! (a->offset() == b->offset() )) 85 if ( ! (a->offset() == b->offset() ))
86 return false; 86 return false;
87 } 87 }
88 } 88 }
89 QStringList cat = categories(); 89 QStringList cat = categories();
90 QStringList catFrom = from->categories(); 90 QStringList catFrom = from->categories();
91 QString nCat; 91 QString nCat;
92 unsigned int iii; 92 unsigned int iii;
93 for ( iii = 0; iii < catFrom.count();++iii ) { 93 for ( iii = 0; iii < catFrom.count();++iii ) {
94 nCat = catFrom[iii]; 94 nCat = catFrom[iii];
95 if ( !nCat.isEmpty() ) 95 if ( !nCat.isEmpty() )
96 if ( !cat.contains( nCat )) { 96 if ( !cat.contains( nCat )) {
97 return false; 97 return false;
98 } 98 }
99 } 99 }
100 if ( from->doesRecur() ) 100 if ( from->doesRecur() )
101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) 101 if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
102 return false; 102 return false;
103 return true; 103 return true;
104} 104}
105 105
106void Event::setDtEnd(const QDateTime &dtEnd) 106void Event::setDtEnd(const QDateTime &dtEnd)
107{ 107{
108 if (mReadOnly) return; 108 if (mReadOnly) return;
109 109
110 mDtEnd = getEvenTime( dtEnd ); 110 mDtEnd = getEvenTime( dtEnd );
111 111
112 setHasEndDate(true); 112 setHasEndDate(true);
113 setHasDuration(false); 113 setHasDuration(false);
114 114
115 updated(); 115 updated();
116} 116}
117 117
118QDateTime Event::dtEnd() const 118QDateTime Event::dtEnd() const
119{ 119{
120 if (hasEndDate()) return mDtEnd; 120 if (hasEndDate()) return mDtEnd;
121 if (hasDuration()) return dtStart().addSecs(duration()); 121 if (hasDuration()) return dtStart().addSecs(duration());
122 122
123 return dtStart(); 123 return dtStart();
124} 124}
125 125
126QString Event::dtEndTimeStr() const 126QString Event::dtEndTimeStr() const
127{ 127{
128 return KGlobal::locale()->formatTime(mDtEnd.time()); 128 return KGlobal::locale()->formatTime(mDtEnd.time());
129} 129}
130 130
131QString Event::dtEndDateStr(bool shortfmt) const 131QString Event::dtEndDateStr(bool shortfmt) const
132{ 132{
133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); 133 return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt);
134} 134}
135 135
136QString Event::dtEndStr(bool shortfmt) const 136QString Event::dtEndStr(bool shortfmt) const
137{ 137{
138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); 138 return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt);
139} 139}
140 140
141void Event::setHasEndDate(bool b) 141void Event::setHasEndDate(bool b)
142{ 142{
143 mHasEndDate = b; 143 mHasEndDate = b;
144} 144}
145 145
146bool Event::hasEndDate() const 146bool Event::hasEndDate() const
147{ 147{
148 return mHasEndDate; 148 return mHasEndDate;
149} 149}
150 150
151bool Event::isMultiDay() const 151bool Event::isMultiDay() const
152{ 152{
153 bool multi = !(dtStart().date() == dtEnd().date()); 153 bool multi = !(dtStart().date() == dtEnd().date());
154 return multi; 154 return multi;
155} 155}
156 156
157void Event::setTransparency(Event::Transparency transparency) 157void Event::setTransparency(Event::Transparency transparency)
158{ 158{
159 if (mReadOnly) return; 159 if (mReadOnly) return;
160 mTransparency = transparency; 160 mTransparency = transparency;
161 updated(); 161 updated();
162} 162}
163 163
164Event::Transparency Event::transparency() const 164Event::Transparency Event::transparency() const
165{ 165{
166 return mTransparency; 166 return mTransparency;
167} 167}
168 168
169void Event::setDuration(int seconds) 169void Event::setDuration(int seconds)
170{ 170{
171 setHasEndDate(false); 171 setHasEndDate(false);
172 Incidence::setDuration(seconds); 172 Incidence::setDuration(seconds);
173} 173}
174bool Event::matchTime(QDateTime*startDT, QDateTime* endDT) 174bool Event::matchTime(QDateTime*startDT, QDateTime* endDT)
175{ 175{
176 if ( cancelled() ) return false; 176 if ( cancelled() ) return false;
177 if ( ! doesRecur() ) { 177 if ( ! doesRecur() ) {
178 if ( doesFloat() ) { 178 if ( doesFloat() ) {
179 if ( mDtEnd.addDays( 1 ) < *startDT) 179 if ( mDtEnd.addDays( 1 ) < *startDT)
180 return false; 180 return false;
181 if ( endDT && mDtStart > * endDT) 181 if ( endDT && mDtStart > * endDT)
182 return false; 182 return false;
183 } else { 183 } else {
184 if ( mDtEnd < *startDT ) 184 if ( mDtEnd < *startDT )
185 return false; 185 return false;
186 if ( endDT && mDtStart > * endDT) 186 if ( endDT && mDtStart > * endDT)
187 return false; 187 return false;
188 } 188 }
189 } else { 189 } else {
190 if ( endDT && mDtStart > * endDT) 190 if ( endDT && mDtStart > * endDT)
191 return false; 191 return false;
192 } 192 }
193 return true; 193 return true;
194} 194}
195bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT ) 195bool Event::isOverlapping ( Event* testEvent, QDateTime* overlapDT, QDateTime* startDT )
196{ 196{
197 if ( testEvent == this ) 197 if ( testEvent == this )
198 return false; 198 return false;
199 if ( ! doesRecur() && !testEvent->doesRecur() ) { 199 if ( ! doesRecur() && !testEvent->doesRecur() ) {
200 QDateTime te; 200 QDateTime te;
201 if ( testEvent->doesFloat() ) 201 if ( testEvent->doesFloat() )
202 te = testEvent->mDtEnd.addDays( 1 ); 202 te = testEvent->mDtEnd.addDays( 1 );
203 else 203 else
204 te = testEvent->mDtEnd; 204 te = testEvent->mDtEnd;
205 QDateTime e; 205 QDateTime e;
206 if ( doesFloat() ) 206 if ( doesFloat() )
207 e = mDtEnd.addDays( 1 ); 207 e = mDtEnd.addDays( 1 );
208 else 208 else
209 e = mDtEnd; 209 e = mDtEnd;
210 if ( mDtStart < te && testEvent->mDtStart < e ) { 210 if ( mDtStart < te && testEvent->mDtStart < e ) {
211 if ( mDtStart < testEvent->mDtStart ) 211 if ( mDtStart < testEvent->mDtStart )
212 *overlapDT = testEvent->mDtStart; 212 *overlapDT = testEvent->mDtStart;
213 else 213 else
214 *overlapDT = mDtStart; 214 *overlapDT = mDtStart;
215 if ( startDT ) 215 if ( startDT )
216 return (*overlapDT >= *startDT ); 216 return (*overlapDT >= *startDT );
217 return true; 217 return true;
218 } 218 }
219 return false; 219 return false;
220 } 220 }
221 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 221 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
222 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) { 222 if ( mDtStart.time() >= testEvent->mDtEnd.time() || testEvent->mDtStart.time() >= mDtEnd.time() ) {
223 // no need to test. times mismatch 223 // no need to test. times mismatch
224 //fprintf(stderr,"timi "); 224 //fprintf(stderr,"timi ");
225 return false; 225 return false;
226 } 226 }
227 } 227 }
228 Event *nonRecur = 0; 228 Event *nonRecur = 0;
229 Event *recurEvent = 0; 229 Event *recurEvent = 0;
230 if ( ! doesRecur() ) { 230 if ( ! doesRecur() ) {
231 nonRecur = this; 231 nonRecur = this;
232 recurEvent = testEvent; 232 recurEvent = testEvent;
233 } 233 }
234 else if ( !testEvent->doesRecur() ) { 234 else if ( !testEvent->doesRecur() ) {
235 nonRecur = testEvent; 235 nonRecur = testEvent;
236 recurEvent = this; 236 recurEvent = this;
237 } 237 }
238 if ( nonRecur ) { 238 if ( nonRecur ) {
239 QDateTime enr; 239 QDateTime enr;
240 if ( nonRecur->doesFloat() ) 240 if ( nonRecur->doesFloat() )
241 enr = nonRecur->mDtEnd.addDays( 1 ); 241 enr = nonRecur->mDtEnd.addDays( 1 );
242 else 242 else
243 enr = nonRecur->mDtEnd; 243 enr = nonRecur->mDtEnd;
244 if ( enr < recurEvent->mDtStart ) 244 if ( enr < recurEvent->mDtStart )
245 return false; 245 return false;
246 if ( startDT && enr < *startDT ) 246 if ( startDT && enr < *startDT )
247 return false; 247 return false;
248 248
249 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd ); 249 int recDuration = recurEvent->mDtStart.secsTo( recurEvent->mDtEnd );
250 if ( recurEvent->doesFloat() ) 250 if ( recurEvent->doesFloat() )
251 recDuration += 86400; 251 recDuration += 86400;
252 bool ok = false; 252 bool ok = false;
253 QDateTime recStart; 253 QDateTime recStart;
254 if ( startDT ) { 254 if ( startDT ) {
255 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 255 recStart = recurEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
256 } 256 }
257 if ( recStart.isValid() ) { 257 if ( recStart.isValid() ) {
258 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1()); 258 //qDebug("%s start at %s ", startDT-> toString().latin1(), recStart.toString().latin1());
259 recStart = recStart.addSecs( -300); 259 recStart = recStart.addSecs( -300);
260 } 260 }
261 else 261 else
262 recStart = recurEvent->mDtStart.addSecs( -300); 262 recStart = recurEvent->mDtStart.addSecs( -300);
263 ok = true; 263 ok = true;
264 264
265 while ( ok ) { 265 while ( ok ) {
266 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok ); 266 recStart = recurEvent->getNextOccurence( recStart.addSecs( 60 ), &ok );
267 if ( ok ) { 267 if ( ok ) {
268 if ( recStart > enr ) 268 if ( recStart > enr )
269 return false; 269 return false;
270 QDateTime recEnd = recStart.addSecs( recDuration ); 270 QDateTime recEnd = recStart.addSecs( recDuration );
271 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) { 271 if ( nonRecur->mDtStart < recEnd && recStart < nonRecur->mDtEnd ) {
272 if ( nonRecur->mDtStart < recStart ) 272 if ( nonRecur->mDtStart < recStart )
273 *overlapDT = recStart; 273 *overlapDT = recStart;
274 else 274 else
275 *overlapDT = nonRecur->mDtStart; 275 *overlapDT = nonRecur->mDtStart;
276 if ( startDT ) { 276 if ( startDT ) {
277 if ( *overlapDT >= *startDT ) 277 if ( *overlapDT >= *startDT )
278 return true; 278 return true;
279 } else 279 } else
280 return true; 280 return true;
281 } 281 }
282 } 282 }
283 } 283 }
284 return false; 284 return false;
285 } 285 }
286 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) { 286 if ( !doesFloat() && !testEvent->doesFloat() && !isMultiDay() && !testEvent->isMultiDay() ) {
287 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) { 287 if ( recurrence()->doesRecur() == Recurrence::rWeekly && testEvent->recurrence()->doesRecur() == Recurrence::rWeekly ) {
288 bool found = false; 288 bool found = false;
289 uint i; 289 uint i;
290 for ( i=0; i< recurrence()->days().size();++i ) { 290 for ( i=0; i< recurrence()->days().size();++i ) {
291 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) ); 291 found = found || (recurrence()->days().testBit( i ) && testEvent->recurrence()->days().testBit( i ) );
292 } 292 }
293 if ( ! found ) { 293 if ( ! found ) {
294 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1()); 294 //qDebug("recurring days mismatch %s -- %s", summary().latin1(),testEvent->summary().latin1());
295 return false; 295 return false;
296 } 296 }
297 297
298 } 298 }
299 } 299 }
300 bool ok = true; 300 bool ok = true;
301 QDateTime incidenceStart;// = mDtStart; 301 QDateTime incidenceStart;// = mDtStart;
302 QDateTime testincidenceStart;// = testEvent->mDtStart; 302 QDateTime testincidenceStart;// = testEvent->mDtStart;
303 if ( startDT ) { 303 if ( startDT ) {
304 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 304 incidenceStart = recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
305 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok ); 305 testincidenceStart = testEvent->recurrence()->getPreviousDateTime( startDT->addSecs( 61 ), &ok );
306 } 306 }
307 if ( !testincidenceStart.isValid() ) 307 if ( !testincidenceStart.isValid() )
308 testincidenceStart = testEvent->mDtStart; 308 testincidenceStart = testEvent->mDtStart;
309 if ( !incidenceStart.isValid() ) 309 if ( !incidenceStart.isValid() )
310 incidenceStart = mDtStart; 310 incidenceStart = mDtStart;
311 int duration = mDtStart.secsTo( mDtEnd ); 311 int duration = mDtStart.secsTo( mDtEnd );
312 if ( doesFloat() ) 312 if ( doesFloat() )
313 duration += 86400; 313 duration += 86400;
314 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd ); 314 int testduration = testEvent->mDtStart.secsTo( testEvent->mDtEnd );
315 if ( testEvent->doesFloat() ) 315 if ( testEvent->doesFloat() )
316 testduration += 86400; 316 testduration += 86400;
317 bool computeThis = false; 317 bool computeThis = false;
318 if ( incidenceStart < testincidenceStart ) 318 if ( incidenceStart < testincidenceStart )
319 computeThis = true; 319 computeThis = true;
320 if ( computeThis ) 320 if ( computeThis )
321 incidenceStart = incidenceStart.addSecs( -300 ); 321 incidenceStart = incidenceStart.addSecs( -300 );
322 else 322 else
323 testincidenceStart = testincidenceStart.addSecs( -300 ); 323 testincidenceStart = testincidenceStart.addSecs( -300 );
324 int count = 0; 324 int count = 0;
325 ok = true; 325 ok = true;
326 int countbreak = 2000; 326 int countbreak = 2000;
327 QDateTime stopSearch; 327 QDateTime stopSearch;
328 bool testStop = false; 328 bool testStop = false;
329 if ( startDT ) { 329 if ( startDT ) {
330 stopSearch = startDT->addDays( 365*3 ); 330 stopSearch = startDT->addDays( 365*3 );
331 testStop = true; 331 testStop = true;
332 } 332 }
333 while ( ok ) { 333 while ( ok ) {
334 ++count; 334 ++count;
335 if ( count > countbreak ) break; 335 if ( count > countbreak ) break;
336 if ( computeThis ) { 336 if ( computeThis ) {
337 if ( testStop ) 337 if ( testStop )
338 if ( testincidenceStart > stopSearch ) 338 if ( testincidenceStart > stopSearch )
339 break; 339 break;
340 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok ); 340 incidenceStart = getNextOccurence( incidenceStart.addSecs( 60 ), &ok );
341 } 341 }
342 else { 342 else {
343 if ( testStop ) 343 if ( testStop )
344 if ( incidenceStart > stopSearch ) 344 if ( incidenceStart > stopSearch )
345 break; 345 break;
346 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok ); 346 testincidenceStart = testEvent->getNextOccurence( testincidenceStart.addSecs( 60 ), &ok );
347 } 347 }
348 if ( ok ) { 348 if ( ok ) {
349 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) { 349 if ( incidenceStart < testincidenceStart.addSecs( testduration ) && testincidenceStart < incidenceStart.addSecs( duration ) ) {
350 if ( incidenceStart < testincidenceStart ) 350 if ( incidenceStart < testincidenceStart )
351 *overlapDT = testincidenceStart; 351 *overlapDT = testincidenceStart;
352 else 352 else
353 *overlapDT = incidenceStart; 353 *overlapDT = incidenceStart;
354 if ( startDT ) { 354 if ( startDT ) {
355 if ( *overlapDT >= *startDT ) 355 if ( *overlapDT >= *startDT )
356 return true; 356 return true;
357 } else 357 } else
358 return true; 358 return true;
359 } 359 }
360 computeThis = ( incidenceStart < testincidenceStart ); 360 computeThis = ( incidenceStart < testincidenceStart );
361 } 361 }
362 362
363 } 363 }
364 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() ); 364 //qDebug("%d rec counter stopped at %d - %s %s", ok ,count, summary().latin1(),testEvent->summary().latin1() );
365 return false; 365 return false;
366} 366}
367QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 367QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
368{ 368{
369 *ok = false; 369 *ok = false;
370 if ( !alarmEnabled() ) 370 if ( !alarmEnabled() )
371 return QDateTime (); 371 return QDateTime ();
372 bool yes; 372 bool yes;
373 QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); 373 QDateTime incidenceStart = getNextOccurence( start_dt, &yes );
374 if ( ! yes || cancelled() ) { 374 if ( ! yes || cancelled() ) {
375 *ok = false; 375 *ok = false;
376 return QDateTime (); 376 return QDateTime ();
377 } 377 }
378 378
379 bool enabled = false; 379 bool enabled = false;
380 Alarm* alarm; 380 Alarm* alarm;
381 int off = 0; 381 int off = 0;
382 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 382 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
383 // if ( QDateTime::currentDateTime() > incidenceStart ){ 383 // if ( QDateTime::currentDateTime() > incidenceStart ){
384// *ok = false; 384// *ok = false;
385// return incidenceStart; 385// return incidenceStart;
386// } 386// }
387 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 387 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
388 if (alarm->enabled()) { 388 if (alarm->enabled()) {
389 if ( alarm->hasTime () ) { 389 if ( alarm->hasTime () ) {
390 if ( alarm->time() < alarmStart ) { 390 if ( alarm->time() < alarmStart ) {
391 alarmStart = alarm->time(); 391 alarmStart = alarm->time();
392 enabled = true; 392 enabled = true;
393 off = alarmStart.secsTo( incidenceStart ); 393 off = alarmStart.secsTo( incidenceStart );
394 } 394 }
395 395
396 } else { 396 } else {
397 int secs = alarm->startOffset().asSeconds(); 397 int secs = alarm->startOffset().asSeconds();
398 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 398 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
399 alarmStart = incidenceStart.addSecs( secs ); 399 alarmStart = incidenceStart.addSecs( secs );
400 enabled = true; 400 enabled = true;
401 off = -secs; 401 off = -secs;
402 } 402 }
403 } 403 }
404 } 404 }
405 } 405 }
406 if ( enabled ) { 406 if ( enabled ) {
407 if ( alarmStart > start_dt ) { 407 if ( alarmStart > start_dt ) {
408 *ok = true; 408 *ok = true;
409 * offset = off; 409 * offset = off;
410 return alarmStart; 410 return alarmStart;
411 } 411 }
412 } 412 }
413 *ok = false; 413 *ok = false;
414 return QDateTime (); 414 return QDateTime ();
415 415
416} 416}
417
418QString Event::durationText()
419{
420 int sec = mDtStart.secsTo( mDtEnd );
421 if ( doesFloat() )
422 sec += 86400;
423 return durationText4Time( sec );
424}
diff --git a/libkcal/event.h b/libkcal/event.h
index 2da9770..6a58618 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -1,94 +1,95 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef EVENT_H 21#ifndef EVENT_H
22#define EVENT_H 22#define EVENT_H
23// 23//
24// Event component, representing a VEVENT object 24// Event component, representing a VEVENT object
25// 25//
26 26
27#include "incidence.h" 27#include "incidence.h"
28namespace KCal { 28namespace KCal {
29 29
30/** 30/**
31 This class provides an Event in the sense of RFC2445. 31 This class provides an Event in the sense of RFC2445.
32*/ 32*/
33class Event : public Incidence 33class Event : public Incidence
34{ 34{
35 public: 35 public:
36 enum Transparency { Opaque, Transparent }; 36 enum Transparency { Opaque, Transparent };
37 typedef ListBase<Event> List; 37 typedef ListBase<Event> List;
38 Event(); 38 Event();
39 Event(const Event &); 39 Event(const Event &);
40 ~Event(); 40 ~Event();
41 bool matchTime(QDateTime*startDT, QDateTime* endDT); 41 bool matchTime(QDateTime*startDT, QDateTime* endDT);
42 42
43 QCString type() const { return "Event"; } 43 QCString type() const { return "Event"; }
44 IncTypeID typeID() const { return eventID; } 44 IncTypeID typeID() const { return eventID; }
45 45
46 Incidence *clone(); 46 Incidence *clone();
47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; 47 QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const;
48 48
49 /** for setting an event's ending date/time with a QDateTime. */ 49 /** for setting an event's ending date/time with a QDateTime. */
50 void setDtEnd(const QDateTime &dtEnd); 50 void setDtEnd(const QDateTime &dtEnd);
51 /** Return the event's ending date/time as a QDateTime. */ 51 /** Return the event's ending date/time as a QDateTime. */
52 virtual QDateTime dtEnd() const; 52 virtual QDateTime dtEnd() const;
53 /** returns an event's end time as a string formatted according to the 53 /** returns an event's end time as a string formatted according to the
54 users locale settings */ 54 users locale settings */
55 QString dtEndTimeStr() const; 55 QString dtEndTimeStr() const;
56 /** returns an event's end date as a string formatted according to the 56 /** returns an event's end date as a string formatted according to the
57 users locale settings */ 57 users locale settings */
58 QString dtEndDateStr(bool shortfmt=true) const; 58 QString dtEndDateStr(bool shortfmt=true) const;
59 /** returns an event's end date and time as a string formatted according 59 /** returns an event's end date and time as a string formatted according
60 to the users locale settings */ 60 to the users locale settings */
61 QString dtEndStr(bool shortfmt=true) const; 61 QString dtEndStr(bool shortfmt=true) const;
62 void setHasEndDate(bool); 62 void setHasEndDate(bool);
63 /** Return whether the event has an end date/time. */ 63 /** Return whether the event has an end date/time. */
64 bool hasEndDate() const; 64 bool hasEndDate() const;
65 65
66 /** Return true if the event spans multiple days, otherwise return false. */ 66 /** Return true if the event spans multiple days, otherwise return false. */
67 bool isMultiDay() const; 67 bool isMultiDay() const;
68 68
69 /** set the event's time transparency level. */ 69 /** set the event's time transparency level. */
70 void setTransparency(Transparency transparency); 70 void setTransparency(Transparency transparency);
71 /** get the event's time transparency level. */ 71 /** get the event's time transparency level. */
72 Transparency transparency() const; 72 Transparency transparency() const;
73 73
74 void setDuration(int seconds); 74 void setDuration(int seconds);
75 75
76 bool contains ( Event*); 76 bool contains ( Event*);
77 77
78 bool isOverlapping ( Event*, QDateTime*, QDateTime* ); 78 bool isOverlapping ( Event*, QDateTime*, QDateTime* );
79 QString durationText();
79 80
80 private: 81 private:
81 bool accept(Visitor &v) { return v.visit(this); } 82 bool accept(Visitor &v) { return v.visit(this); }
82 83
83 QDateTime mDtEnd; 84 QDateTime mDtEnd;
84 bool mHasEndDate; 85 bool mHasEndDate;
85 Transparency mTransparency; 86 Transparency mTransparency;
86}; 87};
87 88
88bool operator==( const Event&, const Event& ); 89bool operator==( const Event&, const Event& );
89 90
90 91
91} 92}
92 93
93 94
94#endif 95#endif
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp
index 4643a3a..201f593 100644
--- a/libkcal/incidence.cpp
+++ b/libkcal/incidence.cpp
@@ -1,811 +1,840 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24 24
25#include "calformat.h" 25#include "calformat.h"
26 26
27#include "incidence.h" 27#include "incidence.h"
28#include "todo.h" 28#include "todo.h"
29 29
30using namespace KCal; 30using namespace KCal;
31 31
32Incidence::Incidence() : 32Incidence::Incidence() :
33 IncidenceBase(), 33 IncidenceBase(),
34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) 34 mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3)
35{ 35{
36 mRecurrence = 0;//new Recurrence(this); 36 mRecurrence = 0;//new Recurrence(this);
37 mCancelled = false; 37 mCancelled = false;
38 recreate(); 38 recreate();
39 mHasStartDate = true; 39 mHasStartDate = true;
40 mAlarms.setAutoDelete(true); 40 mAlarms.setAutoDelete(true);
41 mAttachments.setAutoDelete(true); 41 mAttachments.setAutoDelete(true);
42 mHasRecurrenceID = false; 42 mHasRecurrenceID = false;
43 mHoliday = false; 43 mHoliday = false;
44 mBirthday = false; 44 mBirthday = false;
45 mAnniversary = false; 45 mAnniversary = false;
46 46
47} 47}
48 48
49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) 49Incidence::Incidence( const Incidence &i ) : IncidenceBase( i )
50{ 50{
51// TODO: reenable attributes currently commented out. 51// TODO: reenable attributes currently commented out.
52 mRevision = i.mRevision; 52 mRevision = i.mRevision;
53 mCreated = i.mCreated; 53 mCreated = i.mCreated;
54 mDescription = i.mDescription; 54 mDescription = i.mDescription;
55 mSummary = i.mSummary; 55 mSummary = i.mSummary;
56 mCategories = i.mCategories; 56 mCategories = i.mCategories;
57// Incidence *mRelatedTo; Incidence *mRelatedTo; 57// Incidence *mRelatedTo; Incidence *mRelatedTo;
58 mRelatedTo = 0; 58 mRelatedTo = 0;
59 mRelatedToUid = i.mRelatedToUid; 59 mRelatedToUid = i.mRelatedToUid;
60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; 60// QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations;
61 mExDates = i.mExDates; 61 mExDates = i.mExDates;
62 mAttachments = i.mAttachments; 62 mAttachments = i.mAttachments;
63 mResources = i.mResources; 63 mResources = i.mResources;
64 mSecrecy = i.mSecrecy; 64 mSecrecy = i.mSecrecy;
65 mPriority = i.mPriority; 65 mPriority = i.mPriority;
66 mLocation = i.mLocation; 66 mLocation = i.mLocation;
67 mCancelled = i.mCancelled; 67 mCancelled = i.mCancelled;
68 mHasStartDate = i.mHasStartDate; 68 mHasStartDate = i.mHasStartDate;
69 QPtrListIterator<Alarm> it( i.mAlarms ); 69 QPtrListIterator<Alarm> it( i.mAlarms );
70 const Alarm *a; 70 const Alarm *a;
71 while( (a = it.current()) ) { 71 while( (a = it.current()) ) {
72 Alarm *b = new Alarm( *a ); 72 Alarm *b = new Alarm( *a );
73 b->setParent( this ); 73 b->setParent( this );
74 mAlarms.append( b ); 74 mAlarms.append( b );
75 75
76 ++it; 76 ++it;
77 } 77 }
78 mAlarms.setAutoDelete(true); 78 mAlarms.setAutoDelete(true);
79 mHasRecurrenceID = i.mHasRecurrenceID; 79 mHasRecurrenceID = i.mHasRecurrenceID;
80 mRecurrenceID = i.mRecurrenceID; 80 mRecurrenceID = i.mRecurrenceID;
81 if ( i.mRecurrence ) 81 if ( i.mRecurrence )
82 mRecurrence = new Recurrence( *(i.mRecurrence), this ); 82 mRecurrence = new Recurrence( *(i.mRecurrence), this );
83 else 83 else
84 mRecurrence = 0; 84 mRecurrence = 0;
85 mHoliday = i.mHoliday ; 85 mHoliday = i.mHoliday ;
86 mBirthday = i.mBirthday; 86 mBirthday = i.mBirthday;
87 mAnniversary = i.mAnniversary; 87 mAnniversary = i.mAnniversary;
88} 88}
89 89
90Incidence::~Incidence() 90Incidence::~Incidence()
91{ 91{
92 92
93 Incidence *ev; 93 Incidence *ev;
94 QPtrList<Incidence> Relations = relations(); 94 QPtrList<Incidence> Relations = relations();
95 for (ev=Relations.first();ev;ev=Relations.next()) { 95 for (ev=Relations.first();ev;ev=Relations.next()) {
96 if (ev->relatedTo() == this) ev->setRelatedTo(0); 96 if (ev->relatedTo() == this) ev->setRelatedTo(0);
97 } 97 }
98 if (relatedTo()) relatedTo()->removeRelation(this); 98 if (relatedTo()) relatedTo()->removeRelation(this);
99 if ( mRecurrence ) 99 if ( mRecurrence )
100 delete mRecurrence; 100 delete mRecurrence;
101 101
102} 102}
103QString Incidence::durationText()
104{
105 return "---";
106}
107QString Incidence::durationText4Time( int offset )
108{
109 int min = offset/60;
110 int hours = min /60;
111 min = min % 60;
112 int days = hours /24;
113 hours = hours % 24;
114
115 if ( doesFloat() || ( min == 0 && hours == 0 ) ) {
116 if ( days == 1 )
117 return "1" + i18n(" day");
118 else
119 return QString::number( days )+ i18n(" days");
103 120
121 }
122 QString message = QString::number ( hours ) +":";
123 if ( min < 10 ) message += "0";
124 message += QString::number ( min );
125 if ( days > 0 ) {
126 if ( days == 1 )
127 message = "1" + i18n(" day") + " "+message;
128 else
129 message = QString::number( days )+ i18n(" days") + " "+message;
130 }
131 return message;
132}
104bool Incidence::isHoliday() const 133bool Incidence::isHoliday() const
105{ 134{
106 return mHoliday; 135 return mHoliday;
107} 136}
108bool Incidence::isBirthday() const 137bool Incidence::isBirthday() const
109{ 138{
110 139
111 return mBirthday ; 140 return mBirthday ;
112} 141}
113bool Incidence::isAnniversary() const 142bool Incidence::isAnniversary() const
114{ 143{
115 return mAnniversary ; 144 return mAnniversary ;
116 145
117} 146}
118 147
119bool Incidence::hasRecurrenceID() const 148bool Incidence::hasRecurrenceID() const
120{ 149{
121 return mHasRecurrenceID; 150 return mHasRecurrenceID;
122} 151}
123 152
124void Incidence::setHasRecurrenceID( bool b ) 153void Incidence::setHasRecurrenceID( bool b )
125{ 154{
126 mHasRecurrenceID = b; 155 mHasRecurrenceID = b;
127} 156}
128 157
129void Incidence::setRecurrenceID(QDateTime d) 158void Incidence::setRecurrenceID(QDateTime d)
130{ 159{
131 mRecurrenceID = d; 160 mRecurrenceID = d;
132 mHasRecurrenceID = true; 161 mHasRecurrenceID = true;
133 updated(); 162 updated();
134} 163}
135QDateTime Incidence::recurrenceID () const 164QDateTime Incidence::recurrenceID () const
136{ 165{
137 return mRecurrenceID; 166 return mRecurrenceID;
138} 167}
139 168
140bool Incidence::cancelled() const 169bool Incidence::cancelled() const
141{ 170{
142 return mCancelled; 171 return mCancelled;
143} 172}
144void Incidence::setCancelled( bool b ) 173void Incidence::setCancelled( bool b )
145{ 174{
146 mCancelled = b; 175 mCancelled = b;
147 updated(); 176 updated();
148} 177}
149bool Incidence::hasStartDate() const 178bool Incidence::hasStartDate() const
150{ 179{
151 return mHasStartDate; 180 return mHasStartDate;
152} 181}
153 182
154void Incidence::setHasStartDate(bool f) 183void Incidence::setHasStartDate(bool f)
155{ 184{
156 if (mReadOnly) return; 185 if (mReadOnly) return;
157 mHasStartDate = f; 186 mHasStartDate = f;
158 updated(); 187 updated();
159} 188}
160 189
161// A string comparison that considers that null and empty are the same 190// A string comparison that considers that null and empty are the same
162static bool stringCompare( const QString& s1, const QString& s2 ) 191static bool stringCompare( const QString& s1, const QString& s2 )
163{ 192{
164 if ( s1.isEmpty() && s2.isEmpty() ) 193 if ( s1.isEmpty() && s2.isEmpty() )
165 return true; 194 return true;
166 return s1 == s2; 195 return s1 == s2;
167} 196}
168 197
169bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) 198bool KCal::operator==( const Incidence& i1, const Incidence& i2 )
170{ 199{
171 200
172 if( i1.alarms().count() != i2.alarms().count() ) { 201 if( i1.alarms().count() != i2.alarms().count() ) {
173 return false; // no need to check further 202 return false; // no need to check further
174 } 203 }
175 if ( i1.alarms().count() > 0 ) { 204 if ( i1.alarms().count() > 0 ) {
176 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) 205 if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) )
177 { 206 {
178 qDebug("alarm not equal "); 207 qDebug("alarm not equal ");
179 return false; 208 return false;
180 } 209 }
181 } 210 }
182#if 0 211#if 0
183 QPtrListIterator<Alarm> a1( i1.alarms() ); 212 QPtrListIterator<Alarm> a1( i1.alarms() );
184 QPtrListIterator<Alarm> a2( i2.alarms() ); 213 QPtrListIterator<Alarm> a2( i2.alarms() );
185 for( ; a1.current() && a2.current(); ++a1, ++a2 ) { 214 for( ; a1.current() && a2.current(); ++a1, ++a2 ) {
186 if( *a1.current() == *a2.current() ) { 215 if( *a1.current() == *a2.current() ) {
187 continue; 216 continue;
188 } 217 }
189 else { 218 else {
190 return false; 219 return false;
191 } 220 }
192 } 221 }
193#endif 222#endif
194 223
195 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { 224 if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) {
196 if ( i1.hasRecurrenceID() ) { 225 if ( i1.hasRecurrenceID() ) {
197 if ( i1.recurrenceID() != i2.recurrenceID() ) 226 if ( i1.recurrenceID() != i2.recurrenceID() )
198 return false; 227 return false;
199 } 228 }
200 229
201 } else { 230 } else {
202 return false; 231 return false;
203 } 232 }
204 233
205 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) 234 if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) )
206 return false; 235 return false;
207 if ( i1.hasStartDate() == i2.hasStartDate() ) { 236 if ( i1.hasStartDate() == i2.hasStartDate() ) {
208 if ( i1.hasStartDate() ) { 237 if ( i1.hasStartDate() ) {
209 if ( i1.dtStart() != i2.dtStart() ) 238 if ( i1.dtStart() != i2.dtStart() )
210 return false; 239 return false;
211 } 240 }
212 } else { 241 } else {
213 return false; 242 return false;
214 } 243 }
215 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { 244 if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) {
216 if (!( *i1.mRecurrence == *i2.mRecurrence) ) { 245 if (!( *i1.mRecurrence == *i2.mRecurrence) ) {
217 //qDebug("recurrence is NOT equal "); 246 //qDebug("recurrence is NOT equal ");
218 return false; 247 return false;
219 } 248 }
220 } else { 249 } else {
221 // one ( or both ) recurrence is 0 250 // one ( or both ) recurrence is 0
222 if ( i1.mRecurrence == 0 ) { 251 if ( i1.mRecurrence == 0 ) {
223 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) 252 if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone )
224 return false; 253 return false;
225 } else { 254 } else {
226 // i1.mRecurrence != 0 255 // i1.mRecurrence != 0
227 // i2.mRecurrence == 0 256 // i2.mRecurrence == 0
228 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) 257 if ( i1.mRecurrence->doesRecur() != Recurrence::rNone )
229 return false; 258 return false;
230 } 259 }
231 } 260 }
232 261
233 return 262 return
234 // i1.created() == i2.created() && 263 // i1.created() == i2.created() &&
235 stringCompare( i1.description(), i2.description() ) && 264 stringCompare( i1.description(), i2.description() ) &&
236 stringCompare( i1.summary(), i2.summary() ) && 265 stringCompare( i1.summary(), i2.summary() ) &&
237 i1.categories() == i2.categories() && 266 i1.categories() == i2.categories() &&
238 // no need to compare mRelatedTo 267 // no need to compare mRelatedTo
239 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && 268 stringCompare( i1.relatedToUid(), i2.relatedToUid() ) &&
240 // i1.relations() == i2.relations() && 269 // i1.relations() == i2.relations() &&
241 i1.exDates() == i2.exDates() && 270 i1.exDates() == i2.exDates() &&
242 i1.attachments() == i2.attachments() && 271 i1.attachments() == i2.attachments() &&
243 i1.resources() == i2.resources() && 272 i1.resources() == i2.resources() &&
244 i1.secrecy() == i2.secrecy() && 273 i1.secrecy() == i2.secrecy() &&
245 i1.priority() == i2.priority() && 274 i1.priority() == i2.priority() &&
246 i1.cancelled() == i2.cancelled() && 275 i1.cancelled() == i2.cancelled() &&
247 stringCompare( i1.location(), i2.location() ); 276 stringCompare( i1.location(), i2.location() );
248} 277}
249 278
250Incidence* Incidence::recreateCloneException( QDate d ) 279Incidence* Incidence::recreateCloneException( QDate d )
251{ 280{
252 Incidence* newInc = clone(); 281 Incidence* newInc = clone();
253 newInc->recreate(); 282 newInc->recreate();
254 if ( doesRecur() ) { 283 if ( doesRecur() ) {
255 addExDate( d ); 284 addExDate( d );
256 newInc->recurrence()->unsetRecurs(); 285 newInc->recurrence()->unsetRecurs();
257 if ( typeID() == eventID ) { 286 if ( typeID() == eventID ) {
258 int len = dtStart().secsTo( ((Event*)this)->dtEnd()); 287 int len = dtStart().secsTo( ((Event*)this)->dtEnd());
259 QTime tim = dtStart().time(); 288 QTime tim = dtStart().time();
260 newInc->setDtStart( QDateTime(d, tim) ); 289 newInc->setDtStart( QDateTime(d, tim) );
261 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); 290 ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) );
262 } else { 291 } else {
263 int len = dtStart().secsTo( ((Todo*)this)->dtDue()); 292 int len = dtStart().secsTo( ((Todo*)this)->dtDue());
264 QTime tim = ((Todo*)this)->dtDue().time(); 293 QTime tim = ((Todo*)this)->dtDue().time();
265 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); 294 ((Todo*)newInc)->setDtDue( QDateTime(d, tim) );
266 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); 295 ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) );
267 ((Todo*)this)->setRecurDates(); 296 ((Todo*)this)->setRecurDates();
268 } 297 }
269 newInc->setExDates( DateList () ); 298 newInc->setExDates( DateList () );
270 } 299 }
271 return newInc; 300 return newInc;
272} 301}
273 302
274void Incidence::recreate() 303void Incidence::recreate()
275{ 304{
276 setCreated(QDateTime::currentDateTime()); 305 setCreated(QDateTime::currentDateTime());
277 306
278 setUid(CalFormat::createUniqueId()); 307 setUid(CalFormat::createUniqueId());
279 308
280 setRevision(0); 309 setRevision(0);
281 setIDStr( ":" ); 310 setIDStr( ":" );
282 setLastModified(QDateTime::currentDateTime()); 311 setLastModified(QDateTime::currentDateTime());
283} 312}
284void Incidence::cloneRelations( Incidence * newInc ) 313void Incidence::cloneRelations( Incidence * newInc )
285{ 314{
286 // newInc is already a clone of this incidence 315 // newInc is already a clone of this incidence
287 Incidence * inc; 316 Incidence * inc;
288 Incidence * cloneInc; 317 Incidence * cloneInc;
289 QPtrList<Incidence> Relations = relations(); 318 QPtrList<Incidence> Relations = relations();
290 for (inc=Relations.first();inc;inc=Relations.next()) { 319 for (inc=Relations.first();inc;inc=Relations.next()) {
291 cloneInc = inc->clone(); 320 cloneInc = inc->clone();
292 cloneInc->recreate(); 321 cloneInc->recreate();
293 cloneInc->setRelatedTo( newInc ); 322 cloneInc->setRelatedTo( newInc );
294 inc->cloneRelations( cloneInc ); 323 inc->cloneRelations( cloneInc );
295 } 324 }
296} 325}
297void Incidence::setReadOnly( bool readOnly ) 326void Incidence::setReadOnly( bool readOnly )
298{ 327{
299 IncidenceBase::setReadOnly( readOnly ); 328 IncidenceBase::setReadOnly( readOnly );
300 if ( mRecurrence ) 329 if ( mRecurrence )
301 mRecurrence->setRecurReadOnly( readOnly); 330 mRecurrence->setRecurReadOnly( readOnly);
302} 331}
303void Incidence::setLastModifiedSubInvalid() 332void Incidence::setLastModifiedSubInvalid()
304{ 333{
305 mLastModifiedSub = QDateTime(); 334 mLastModifiedSub = QDateTime();
306 if ( mRelatedTo ) 335 if ( mRelatedTo )
307 mRelatedTo->setLastModifiedSubInvalid(); 336 mRelatedTo->setLastModifiedSubInvalid();
308} 337}
309QDateTime Incidence::lastModifiedSub() 338QDateTime Incidence::lastModifiedSub()
310{ 339{
311 if ( !mRelations.count() ) 340 if ( !mRelations.count() )
312 return lastModified(); 341 return lastModified();
313 if ( mLastModifiedSub.isValid() ) 342 if ( mLastModifiedSub.isValid() )
314 return mLastModifiedSub; 343 return mLastModifiedSub;
315 mLastModifiedSub = lastModified(); 344 mLastModifiedSub = lastModified();
316 Incidence * inc; 345 Incidence * inc;
317 QPtrList<Incidence> Relations = relations(); 346 QPtrList<Incidence> Relations = relations();
318 for (inc=Relations.first();inc;inc=Relations.next()) { 347 for (inc=Relations.first();inc;inc=Relations.next()) {
319 if ( inc->lastModifiedSub() > mLastModifiedSub ) 348 if ( inc->lastModifiedSub() > mLastModifiedSub )
320 mLastModifiedSub = inc->lastModifiedSub(); 349 mLastModifiedSub = inc->lastModifiedSub();
321 } 350 }
322 return mLastModifiedSub; 351 return mLastModifiedSub;
323} 352}
324void Incidence::setCreated(QDateTime created) 353void Incidence::setCreated(QDateTime created)
325{ 354{
326 if (mReadOnly) return; 355 if (mReadOnly) return;
327 mCreated = getEvenTime(created); 356 mCreated = getEvenTime(created);
328} 357}
329 358
330QDateTime Incidence::created() const 359QDateTime Incidence::created() const
331{ 360{
332 return mCreated; 361 return mCreated;
333} 362}
334 363
335void Incidence::setRevision(int rev) 364void Incidence::setRevision(int rev)
336{ 365{
337 if (mReadOnly) return; 366 if (mReadOnly) return;
338 mRevision = rev; 367 mRevision = rev;
339 368
340 updated(); 369 updated();
341} 370}
342 371
343int Incidence::revision() const 372int Incidence::revision() const
344{ 373{
345 return mRevision; 374 return mRevision;
346} 375}
347 376
348void Incidence::setDtStart(const QDateTime &dtStart) 377void Incidence::setDtStart(const QDateTime &dtStart)
349{ 378{
350 379
351 QDateTime dt = getEvenTime(dtStart); 380 QDateTime dt = getEvenTime(dtStart);
352 381
353 if ( mRecurrence ) 382 if ( mRecurrence )
354 mRecurrence->setRecurStart( dt); 383 mRecurrence->setRecurStart( dt);
355 IncidenceBase::setDtStart( dt ); 384 IncidenceBase::setDtStart( dt );
356} 385}
357 386
358void Incidence::setDescription(const QString &description) 387void Incidence::setDescription(const QString &description)
359{ 388{
360 if (mReadOnly) return; 389 if (mReadOnly) return;
361 mDescription = description; 390 mDescription = description;
362 updated(); 391 updated();
363} 392}
364 393
365QString Incidence::description() const 394QString Incidence::description() const
366{ 395{
367 return mDescription; 396 return mDescription;
368} 397}
369 398
370 399
371void Incidence::setSummary(const QString &summary) 400void Incidence::setSummary(const QString &summary)
372{ 401{
373 if (mReadOnly) return; 402 if (mReadOnly) return;
374 mSummary = summary; 403 mSummary = summary;
375 updated(); 404 updated();
376} 405}
377 406
378QString Incidence::summary() const 407QString Incidence::summary() const
379{ 408{
380 return mSummary; 409 return mSummary;
381} 410}
382void Incidence::checkCategories() 411void Incidence::checkCategories()
383{ 412{
384 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); 413 mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday"));
385 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); 414 mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday"));
386 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); 415 mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary"));
387} 416}
388 417
389void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false 418void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false
390{ 419{
391 if (mReadOnly) return; 420 if (mReadOnly) return;
392 int i; 421 int i;
393 for( i = 0; i < categories.count(); ++i ) { 422 for( i = 0; i < categories.count(); ++i ) {
394 if ( !mCategories.contains (categories[i])) 423 if ( !mCategories.contains (categories[i]))
395 mCategories.append( categories[i] ); 424 mCategories.append( categories[i] );
396 } 425 }
397 checkCategories(); 426 checkCategories();
398 updated(); 427 updated();
399 if ( addToRelations ) { 428 if ( addToRelations ) {
400 Incidence * inc; 429 Incidence * inc;
401 QPtrList<Incidence> Relations = relations(); 430 QPtrList<Incidence> Relations = relations();
402 for (inc=Relations.first();inc;inc=Relations.next()) { 431 for (inc=Relations.first();inc;inc=Relations.next()) {
403 inc->addCategories( categories, true ); 432 inc->addCategories( categories, true );
404 } 433 }
405 } 434 }
406} 435}
407 436
408void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false 437void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false
409{ 438{
410 if (mReadOnly) return; 439 if (mReadOnly) return;
411 mCategories = categories; 440 mCategories = categories;
412 checkCategories(); 441 checkCategories();
413 updated(); 442 updated();
414 if ( setForRelations ) { 443 if ( setForRelations ) {
415 Incidence * inc; 444 Incidence * inc;
416 QPtrList<Incidence> Relations = relations(); 445 QPtrList<Incidence> Relations = relations();
417 for (inc=Relations.first();inc;inc=Relations.next()) { 446 for (inc=Relations.first();inc;inc=Relations.next()) {
418 inc->setCategories( categories, true ); 447 inc->setCategories( categories, true );
419 } 448 }
420 } 449 }
421} 450}
422 451
423// TODO: remove setCategories(QString) function 452// TODO: remove setCategories(QString) function
424void Incidence::setCategories(const QString &catStr) 453void Incidence::setCategories(const QString &catStr)
425{ 454{
426 if (mReadOnly) return; 455 if (mReadOnly) return;
427 mCategories.clear(); 456 mCategories.clear();
428 457
429 if (catStr.isEmpty()) return; 458 if (catStr.isEmpty()) return;
430 459
431 mCategories = QStringList::split(",",catStr); 460 mCategories = QStringList::split(",",catStr);
432 461
433 QStringList::Iterator it; 462 QStringList::Iterator it;
434 for(it = mCategories.begin();it != mCategories.end(); ++it) { 463 for(it = mCategories.begin();it != mCategories.end(); ++it) {
435 *it = (*it).stripWhiteSpace(); 464 *it = (*it).stripWhiteSpace();
436 } 465 }
437 checkCategories(); 466 checkCategories();
438 updated(); 467 updated();
439} 468}
440// using this makes filtering 3 times faster 469// using this makes filtering 3 times faster
441QStringList* Incidence::categoriesP() 470QStringList* Incidence::categoriesP()
442{ 471{
443 return &mCategories; 472 return &mCategories;
444} 473}
445 474
446QStringList Incidence::categories() const 475QStringList Incidence::categories() const
447{ 476{
448 return mCategories; 477 return mCategories;
449} 478}
450 479
451QString Incidence::categoriesStr() 480QString Incidence::categoriesStr()
452{ 481{
453 return mCategories.join(","); 482 return mCategories.join(",");
454} 483}
455QString Incidence::categoriesStrWithSpace() 484QString Incidence::categoriesStrWithSpace()
456{ 485{
457 return mCategories.join(", "); 486 return mCategories.join(", ");
458} 487}
459 488
460void Incidence::setRelatedToUid(const QString &relatedToUid) 489void Incidence::setRelatedToUid(const QString &relatedToUid)
461{ 490{
462 if (mReadOnly) return; 491 if (mReadOnly) return;
463 mRelatedToUid = relatedToUid; 492 mRelatedToUid = relatedToUid;
464} 493}
465 494
466QString Incidence::relatedToUid() const 495QString Incidence::relatedToUid() const
467{ 496{
468 return mRelatedToUid; 497 return mRelatedToUid;
469} 498}
470 499
471void Incidence::setRelatedTo(Incidence *relatedTo) 500void Incidence::setRelatedTo(Incidence *relatedTo)
472{ 501{
473 //qDebug("Incidence::setRelatedTo %d ", relatedTo); 502 //qDebug("Incidence::setRelatedTo %d ", relatedTo);
474 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); 503 //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() );
475 if (mReadOnly || mRelatedTo == relatedTo) return; 504 if (mReadOnly || mRelatedTo == relatedTo) return;
476 if(mRelatedTo) { 505 if(mRelatedTo) {
477 // updated(); 506 // updated();
478 mRelatedTo->removeRelation(this); 507 mRelatedTo->removeRelation(this);
479 } 508 }
480 mRelatedTo = relatedTo; 509 mRelatedTo = relatedTo;
481 if (mRelatedTo) { 510 if (mRelatedTo) {
482 mRelatedTo->addRelation(this); 511 mRelatedTo->addRelation(this);
483 mRelatedToUid = mRelatedTo->uid(); 512 mRelatedToUid = mRelatedTo->uid();
484 } else { 513 } else {
485 mRelatedToUid = ""; 514 mRelatedToUid = "";
486 } 515 }
487} 516}
488 517
489Incidence *Incidence::relatedTo() const 518Incidence *Incidence::relatedTo() const
490{ 519{
491 return mRelatedTo; 520 return mRelatedTo;
492} 521}
493 522
494QPtrList<Incidence> Incidence::relations() const 523QPtrList<Incidence> Incidence::relations() const
495{ 524{
496 return mRelations; 525 return mRelations;
497} 526}
498 527
499void Incidence::addRelationsToList(QPtrList<Incidence> *rel) 528void Incidence::addRelationsToList(QPtrList<Incidence> *rel)
500{ 529{
501 Incidence* inc; 530 Incidence* inc;
502 QPtrList<Incidence> Relations = relations(); 531 QPtrList<Incidence> Relations = relations();
503 for (inc=Relations.first();inc;inc=Relations.next()) { 532 for (inc=Relations.first();inc;inc=Relations.next()) {
504 inc->addRelationsToList( rel ); 533 inc->addRelationsToList( rel );
505 } 534 }
506 if ( rel->findRef( this ) == -1 ) 535 if ( rel->findRef( this ) == -1 )
507 rel->append( this ); 536 rel->append( this );
508} 537}
509 538
510void Incidence::addRelation(Incidence *event) 539void Incidence::addRelation(Incidence *event)
511{ 540{
512 setLastModifiedSubInvalid(); 541 setLastModifiedSubInvalid();
513 if( mRelations.findRef( event ) == -1 ) { 542 if( mRelations.findRef( event ) == -1 ) {
514 mRelations.append(event); 543 mRelations.append(event);
515 //updated(); 544 //updated();
516 } 545 }
517} 546}
518 547
519void Incidence::removeRelation(Incidence *event) 548void Incidence::removeRelation(Incidence *event)
520{ 549{
521 setLastModifiedSubInvalid(); 550 setLastModifiedSubInvalid();
522 mRelations.removeRef(event); 551 mRelations.removeRef(event);
523// if (event->getRelatedTo() == this) event->setRelatedTo(0); 552// if (event->getRelatedTo() == this) event->setRelatedTo(0);
524} 553}
525 554
526bool Incidence::recursOn(const QDate &qd) const 555bool Incidence::recursOn(const QDate &qd) const
527{ 556{
528 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; 557 if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true;
529 else return false; 558 else return false;
530} 559}
531 560
532void Incidence::setExDates(const DateList &exDates) 561void Incidence::setExDates(const DateList &exDates)
533{ 562{
534 if (mReadOnly) return; 563 if (mReadOnly) return;
535 mExDates = exDates; 564 mExDates = exDates;
536 recurrence()->setRecurExDatesCount(mExDates.count()); 565 recurrence()->setRecurExDatesCount(mExDates.count());
537 566
538 updated(); 567 updated();
539} 568}
540 569
541void Incidence::addExDate(const QDate &date) 570void Incidence::addExDate(const QDate &date)
542{ 571{
543 if (mReadOnly) return; 572 if (mReadOnly) return;
544 mExDates.append(date); 573 mExDates.append(date);
545 574
546 recurrence()->setRecurExDatesCount(mExDates.count()); 575 recurrence()->setRecurExDatesCount(mExDates.count());
547 576
548 updated(); 577 updated();
549} 578}
550 579
551DateList Incidence::exDates() const 580DateList Incidence::exDates() const
552{ 581{
553 return mExDates; 582 return mExDates;
554} 583}
555 584
556bool Incidence::isException(const QDate &date) const 585bool Incidence::isException(const QDate &date) const
557{ 586{
558 DateList::ConstIterator it; 587 DateList::ConstIterator it;
559 for( it = mExDates.begin(); it != mExDates.end(); ++it ) { 588 for( it = mExDates.begin(); it != mExDates.end(); ++it ) {
560 if ( (*it) == date ) { 589 if ( (*it) == date ) {
561 return true; 590 return true;
562 } 591 }
563 } 592 }
564 593
565 return false; 594 return false;
566} 595}
567 596
568void Incidence::addAttachment(Attachment *attachment) 597void Incidence::addAttachment(Attachment *attachment)
569{ 598{
570 if (mReadOnly || !attachment) return; 599 if (mReadOnly || !attachment) return;
571 mAttachments.append(attachment); 600 mAttachments.append(attachment);
572 updated(); 601 updated();
573} 602}
574 603
575void Incidence::deleteAttachment(Attachment *attachment) 604void Incidence::deleteAttachment(Attachment *attachment)
576{ 605{
577 mAttachments.removeRef(attachment); 606 mAttachments.removeRef(attachment);
578} 607}
579 608
580void Incidence::deleteAttachments(const QString& mime) 609void Incidence::deleteAttachments(const QString& mime)
581{ 610{
582 Attachment *at = mAttachments.first(); 611 Attachment *at = mAttachments.first();
583 while (at) { 612 while (at) {
584 if (at->mimeType() == mime) 613 if (at->mimeType() == mime)
585 mAttachments.remove(); 614 mAttachments.remove();
586 else 615 else
587 at = mAttachments.next(); 616 at = mAttachments.next();
588 } 617 }
589} 618}
590 619
591QPtrList<Attachment> Incidence::attachments() const 620QPtrList<Attachment> Incidence::attachments() const
592{ 621{
593 return mAttachments; 622 return mAttachments;
594} 623}
595 624
596QPtrList<Attachment> Incidence::attachments(const QString& mime) const 625QPtrList<Attachment> Incidence::attachments(const QString& mime) const
597{ 626{
598 QPtrList<Attachment> attachments; 627 QPtrList<Attachment> attachments;
599 QPtrListIterator<Attachment> it( mAttachments ); 628 QPtrListIterator<Attachment> it( mAttachments );
600 Attachment *at; 629 Attachment *at;
601 while ( (at = it.current()) ) { 630 while ( (at = it.current()) ) {
602 if (at->mimeType() == mime) 631 if (at->mimeType() == mime)
603 attachments.append(at); 632 attachments.append(at);
604 ++it; 633 ++it;
605 } 634 }
606 635
607 return attachments; 636 return attachments;
608} 637}
609 638
610void Incidence::setResources(const QStringList &resources) 639void Incidence::setResources(const QStringList &resources)
611{ 640{
612 if (mReadOnly) return; 641 if (mReadOnly) return;
613 mResources = resources; 642 mResources = resources;
614 updated(); 643 updated();
615} 644}
616 645
617QStringList Incidence::resources() const 646QStringList Incidence::resources() const
618{ 647{
619 return mResources; 648 return mResources;
620} 649}
621 650
622 651
623void Incidence::setPriority(int priority) 652void Incidence::setPriority(int priority)
624{ 653{
625 if (mReadOnly) return; 654 if (mReadOnly) return;
626 mPriority = priority; 655 mPriority = priority;
627 updated(); 656 updated();
628} 657}
629 658
630int Incidence::priority() const 659int Incidence::priority() const
631{ 660{
632 return mPriority; 661 return mPriority;
633} 662}
634 663
635void Incidence::setSecrecy(int sec) 664void Incidence::setSecrecy(int sec)
636{ 665{
637 if (mReadOnly) return; 666 if (mReadOnly) return;
638 mSecrecy = sec; 667 mSecrecy = sec;
639 updated(); 668 updated();
640} 669}
641 670
642int Incidence::secrecy() const 671int Incidence::secrecy() const
643{ 672{
644 return mSecrecy; 673 return mSecrecy;
645} 674}
646 675
647QString Incidence::secrecyStr() const 676QString Incidence::secrecyStr() const
648{ 677{
649 return secrecyName(mSecrecy); 678 return secrecyName(mSecrecy);
650} 679}
651 680
652QString Incidence::secrecyName(int secrecy) 681QString Incidence::secrecyName(int secrecy)
653{ 682{
654 switch (secrecy) { 683 switch (secrecy) {
655 case SecrecyPublic: 684 case SecrecyPublic:
656 return i18n("Public"); 685 return i18n("Public");
657 break; 686 break;
658 case SecrecyPrivate: 687 case SecrecyPrivate:
659 return i18n("Private"); 688 return i18n("Private");
660 break; 689 break;
661 case SecrecyConfidential: 690 case SecrecyConfidential:
662 return i18n("Confidential"); 691 return i18n("Confidential");
663 break; 692 break;
664 default: 693 default:
665 return i18n("Undefined"); 694 return i18n("Undefined");
666 break; 695 break;
667 } 696 }
668} 697}
669 698
670QStringList Incidence::secrecyList() 699QStringList Incidence::secrecyList()
671{ 700{
672 QStringList list; 701 QStringList list;
673 list << secrecyName(SecrecyPublic); 702 list << secrecyName(SecrecyPublic);
674 list << secrecyName(SecrecyPrivate); 703 list << secrecyName(SecrecyPrivate);
675 list << secrecyName(SecrecyConfidential); 704 list << secrecyName(SecrecyConfidential);
676 705
677 return list; 706 return list;
678} 707}
679 708
680 709
681QPtrList<Alarm> Incidence::alarms() const 710QPtrList<Alarm> Incidence::alarms() const
682{ 711{
683 return mAlarms; 712 return mAlarms;
684} 713}
685 714
686Alarm* Incidence::newAlarm() 715Alarm* Incidence::newAlarm()
687{ 716{
688 Alarm* alarm = new Alarm(this); 717 Alarm* alarm = new Alarm(this);
689 mAlarms.append(alarm); 718 mAlarms.append(alarm);
690// updated(); 719// updated();
691 return alarm; 720 return alarm;
692} 721}
693 722
694void Incidence::addAlarm(Alarm *alarm) 723void Incidence::addAlarm(Alarm *alarm)
695{ 724{
696 mAlarms.append(alarm); 725 mAlarms.append(alarm);
697 updated(); 726 updated();
698} 727}
699 728
700void Incidence::removeAlarm(Alarm *alarm) 729void Incidence::removeAlarm(Alarm *alarm)
701{ 730{
702 mAlarms.removeRef(alarm); 731 mAlarms.removeRef(alarm);
703 updated(); 732 updated();
704} 733}
705 734
706void Incidence::clearAlarms() 735void Incidence::clearAlarms()
707{ 736{
708 mAlarms.clear(); 737 mAlarms.clear();
709 updated(); 738 updated();
710} 739}
711 740
712bool Incidence::isAlarmEnabled() const 741bool Incidence::isAlarmEnabled() const
713{ 742{
714 Alarm* alarm; 743 Alarm* alarm;
715 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 744 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
716 if (alarm->enabled()) 745 if (alarm->enabled())
717 return true; 746 return true;
718 } 747 }
719 return false; 748 return false;
720} 749}
721#include <stdlib.h> 750#include <stdlib.h>
722Recurrence *Incidence::recurrence() 751Recurrence *Incidence::recurrence()
723{ 752{
724 if ( ! mRecurrence ) { 753 if ( ! mRecurrence ) {
725 mRecurrence = new Recurrence(this); 754 mRecurrence = new Recurrence(this);
726 qDebug("creating new recurence "); 755 qDebug("creating new recurence ");
727 //abort(); 756 //abort();
728 } 757 }
729 return mRecurrence; 758 return mRecurrence;
730} 759}
731void Incidence::setRecurrence( Recurrence * r) 760void Incidence::setRecurrence( Recurrence * r)
732{ 761{
733 if ( mRecurrence ) 762 if ( mRecurrence )
734 delete mRecurrence; 763 delete mRecurrence;
735 mRecurrence = r; 764 mRecurrence = r;
736} 765}
737 766
738void Incidence::setLocation(const QString &location) 767void Incidence::setLocation(const QString &location)
739{ 768{
740 if (mReadOnly) return; 769 if (mReadOnly) return;
741 mLocation = location; 770 mLocation = location;
742 updated(); 771 updated();
743} 772}
744 773
745QString Incidence::location() const 774QString Incidence::location() const
746{ 775{
747 return mLocation; 776 return mLocation;
748} 777}
749QString Incidence::recurrenceText() const 778QString Incidence::recurrenceText() const
750{ 779{
751 if ( mRecurrence ) return mRecurrence->recurrenceText(); 780 if ( mRecurrence ) return mRecurrence->recurrenceText();
752 return i18n("No"); 781 return i18n("No");
753} 782}
754 783
755ushort Incidence::doesRecur() const 784ushort Incidence::doesRecur() const
756{ 785{
757 if ( mRecurrence ) return mRecurrence->doesRecur(); 786 if ( mRecurrence ) return mRecurrence->doesRecur();
758 else return Recurrence::rNone; 787 else return Recurrence::rNone;
759} 788}
760 789
761QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const 790QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const
762{ 791{
763 QDateTime incidenceStart = dt; 792 QDateTime incidenceStart = dt;
764 *ok = false; 793 *ok = false;
765 if ( doesRecur() ) { 794 if ( doesRecur() ) {
766 bool last; 795 bool last;
767 mRecurrence->getPreviousDateTime( incidenceStart , &last ); 796 mRecurrence->getPreviousDateTime( incidenceStart , &last );
768 int count = 0; 797 int count = 0;
769 if ( !last ) { 798 if ( !last ) {
770 while ( !last ) { 799 while ( !last ) {
771 ++count; 800 ++count;
772 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); 801 incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last );
773 if ( recursOn( incidenceStart.date() ) ) { 802 if ( recursOn( incidenceStart.date() ) ) {
774 last = true; // exit while llop 803 last = true; // exit while llop
775 } else { 804 } else {
776 if ( last ) { // no alarm on last recurrence 805 if ( last ) { // no alarm on last recurrence
777 return QDateTime (); 806 return QDateTime ();
778 } 807 }
779 int year = incidenceStart.date().year(); 808 int year = incidenceStart.date().year();
780 // workaround for bug in recurrence 809 // workaround for bug in recurrence
781 if ( count == 100 || year < 1000 || year > 5000 ) { 810 if ( count == 100 || year < 1000 || year > 5000 ) {
782 return QDateTime (); 811 return QDateTime ();
783 } 812 }
784 incidenceStart = incidenceStart.addSecs( 1 ); 813 incidenceStart = incidenceStart.addSecs( 1 );
785 } 814 }
786 } 815 }
787 } else { 816 } else {
788 return QDateTime (); 817 return QDateTime ();
789 } 818 }
790 } else { 819 } else {
791 if ( hasStartDate () ) { 820 if ( hasStartDate () ) {
792 incidenceStart = dtStart(); 821 incidenceStart = dtStart();
793 } 822 }
794 if ( typeID() == todoID ) { 823 if ( typeID() == todoID ) {
795 if ( ((Todo*)this)->hasDueDate() ) 824 if ( ((Todo*)this)->hasDueDate() )
796 incidenceStart = ((Todo*)this)->dtDue(); 825 incidenceStart = ((Todo*)this)->dtDue();
797 } 826 }
798 } 827 }
799 if ( incidenceStart > dt ) 828 if ( incidenceStart > dt )
800 *ok = true; 829 *ok = true;
801 return incidenceStart; 830 return incidenceStart;
802} 831}
803QDateTime Incidence::dtStart() const 832QDateTime Incidence::dtStart() const
804{ 833{
805 if ( doesRecur() ) { 834 if ( doesRecur() ) {
806 if ( typeID() == todoID ) { 835 if ( typeID() == todoID ) {
807 ((Todo*)this)->checkSetCompletedFalse(); 836 ((Todo*)this)->checkSetCompletedFalse();
808 } 837 }
809 } 838 }
810 return mDtStart; 839 return mDtStart;
811} 840}
diff --git a/libkcal/incidence.h b/libkcal/incidence.h
index 8519f01..88df217 100644
--- a/libkcal/incidence.h
+++ b/libkcal/incidence.h
@@ -1,322 +1,323 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef INCIDENCE_H 20#ifndef INCIDENCE_H
21#define INCIDENCE_H 21#define INCIDENCE_H
22// 22//
23// Incidence - base class of calendaring components 23// Incidence - base class of calendaring components
24// 24//
25 25
26#include <qdatetime.h> 26#include <qdatetime.h>
27#include <qstringlist.h> 27#include <qstringlist.h>
28#include <qvaluelist.h> 28#include <qvaluelist.h>
29 29
30#include "recurrence.h" 30#include "recurrence.h"
31#include "alarm.h" 31#include "alarm.h"
32#include "attachment.h" 32#include "attachment.h"
33#include "listbase.h" 33#include "listbase.h"
34#include "incidencebase.h" 34#include "incidencebase.h"
35 35
36namespace KCal { 36namespace KCal {
37 37
38class Event; 38class Event;
39class Todo; 39class Todo;
40class Journal; 40class Journal;
41 41
42/** 42/**
43 This class provides the base class common to all calendar components. 43 This class provides the base class common to all calendar components.
44*/ 44*/
45class Incidence : public IncidenceBase 45class Incidence : public IncidenceBase
46{ 46{
47 public: 47 public:
48 /** 48 /**
49 This class provides the interface for a visitor of calendar components. It 49 This class provides the interface for a visitor of calendar components. It
50 serves as base class for concrete visitors, which implement certain actions on 50 serves as base class for concrete visitors, which implement certain actions on
51 calendar components. It allows to add functions, which operate on the concrete 51 calendar components. It allows to add functions, which operate on the concrete
52 types of calendar components, without changing the calendar component classes. 52 types of calendar components, without changing the calendar component classes.
53 */ 53 */
54 class Visitor 54 class Visitor
55 { 55 {
56 public: 56 public:
57 /** Destruct Incidence::Visitor */ 57 /** Destruct Incidence::Visitor */
58 virtual ~Visitor() {} 58 virtual ~Visitor() {}
59 59
60 /** 60 /**
61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 61 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
62 on an Event object. 62 on an Event object.
63 */ 63 */
64 virtual bool visit(Event *) { return false; } 64 virtual bool visit(Event *) { return false; }
65 /** 65 /**
66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 66 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
67 on an Todo object. 67 on an Todo object.
68 */ 68 */
69 virtual bool visit(Todo *) { return false; } 69 virtual bool visit(Todo *) { return false; }
70 /** 70 /**
71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions 71 Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions
72 on an Journal object. 72 on an Journal object.
73 */ 73 */
74 virtual bool visit(Journal *) { return false; } 74 virtual bool visit(Journal *) { return false; }
75 75
76 protected: 76 protected:
77 /** Constructor is protected to prevent direct creation of visitor base class. */ 77 /** Constructor is protected to prevent direct creation of visitor base class. */
78 Visitor() {} 78 Visitor() {}
79 }; 79 };
80 80
81 /** 81 /**
82 This class implements a visitor for adding an Incidence to a resource 82 This class implements a visitor for adding an Incidence to a resource
83 supporting addEvent(), addTodo() and addJournal() calls. 83 supporting addEvent(), addTodo() and addJournal() calls.
84 */ 84 */
85 template<class T> 85 template<class T>
86 class AddVisitor : public Visitor 86 class AddVisitor : public Visitor
87 { 87 {
88 public: 88 public:
89 AddVisitor( T *r ) : mResource( r ) {} 89 AddVisitor( T *r ) : mResource( r ) {}
90 bool visit( Event *e ) { return mResource->addEvent( e ); } 90 bool visit( Event *e ) { return mResource->addEvent( e ); }
91 bool visit( Todo *t ) { return mResource->addTodo( t ); } 91 bool visit( Todo *t ) { return mResource->addTodo( t ); }
92 bool visit( Journal *j ) { return mResource->addJournal( j ); } 92 bool visit( Journal *j ) { return mResource->addJournal( j ); }
93 93
94 private: 94 private:
95 T *mResource; 95 T *mResource;
96 }; 96 };
97 97
98 /** enumeration for describing an event's secrecy. */ 98 /** enumeration for describing an event's secrecy. */
99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; 99 enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 };
100 typedef ListBase<Incidence> List; 100 typedef ListBase<Incidence> List;
101 Incidence(); 101 Incidence();
102 Incidence(const Incidence &); 102 Incidence(const Incidence &);
103 ~Incidence(); 103 ~Incidence();
104 104
105 /** 105 /**
106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to 106 Accept IncidenceVisitor. A class taking part in the visitor mechanism has to
107 provide this implementation: 107 provide this implementation:
108 <pre> 108 <pre>
109 bool accept(Visitor &v) { return v.visit(this); } 109 bool accept(Visitor &v) { return v.visit(this); }
110 </pre> 110 </pre>
111 */ 111 */
112 virtual bool accept(Visitor &) { return false; } 112 virtual bool accept(Visitor &) { return false; }
113 113
114 virtual Incidence *clone() = 0; 114 virtual Incidence *clone() = 0;
115 virtual void cloneRelations( Incidence * ); 115 virtual void cloneRelations( Incidence * );
116 void addRelationsToList(QPtrList<Incidence> *rel); 116 void addRelationsToList(QPtrList<Incidence> *rel);
117 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; 117 virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0;
118 void setReadOnly( bool ); 118 void setReadOnly( bool );
119 119
120 /** 120 /**
121 Recreate event. The event is made a new unique event, but already stored 121 Recreate event. The event is made a new unique event, but already stored
122 event information is preserved. Sets uniquie id, creation date, last 122 event information is preserved. Sets uniquie id, creation date, last
123 modification date and revision number. 123 modification date and revision number.
124 */ 124 */
125 void recreate(); 125 void recreate();
126 Incidence* recreateCloneException(QDate); 126 Incidence* recreateCloneException(QDate);
127 127
128 /** set creation date */ 128 /** set creation date */
129 void setCreated(QDateTime); 129 void setCreated(QDateTime);
130 /** return time and date of creation. */ 130 /** return time and date of creation. */
131 QDateTime created() const; 131 QDateTime created() const;
132 132
133 /** set the number of revisions this event has seen */ 133 /** set the number of revisions this event has seen */
134 void setRevision(int rev); 134 void setRevision(int rev);
135 /** return the number of revisions this event has seen */ 135 /** return the number of revisions this event has seen */
136 int revision() const; 136 int revision() const;
137 137
138 /** Set starting date/time. */ 138 /** Set starting date/time. */
139 virtual void setDtStart(const QDateTime &dtStart); 139 virtual void setDtStart(const QDateTime &dtStart);
140 /** Return the incidence's ending date/time as a QDateTime. */ 140 /** Return the incidence's ending date/time as a QDateTime. */
141 virtual QDateTime dtEnd() const { return QDateTime(); } 141 virtual QDateTime dtEnd() const { return QDateTime(); }
142 142
143 /** sets the event's lengthy description. */ 143 /** sets the event's lengthy description. */
144 void setDescription(const QString &description); 144 void setDescription(const QString &description);
145 /** returns a reference to the event's description. */ 145 /** returns a reference to the event's description. */
146 QString description() const; 146 QString description() const;
147 147
148 /** sets the event's short summary. */ 148 /** sets the event's short summary. */
149 void setSummary(const QString &summary); 149 void setSummary(const QString &summary);
150 /** returns a reference to the event's summary. */ 150 /** returns a reference to the event's summary. */
151 QString summary() const; 151 QString summary() const;
152 152
153 /** set event's applicable categories */ 153 /** set event's applicable categories */
154 void setCategories(const QStringList &categories, bool setForRelations = false); 154 void setCategories(const QStringList &categories, bool setForRelations = false);
155 void addCategories(const QStringList &categories, bool addToRelations = false); 155 void addCategories(const QStringList &categories, bool addToRelations = false);
156 /** set event's categories based on a comma delimited string */ 156 /** set event's categories based on a comma delimited string */
157 void setCategories(const QString &catStr); 157 void setCategories(const QString &catStr);
158 /** return categories in a list */ 158 /** return categories in a list */
159 QStringList categories() const; 159 QStringList categories() const;
160 QStringList* categoriesP(); 160 QStringList* categoriesP();
161 /** return categories as a comma separated string */ 161 /** return categories as a comma separated string */
162 QString categoriesStr(); 162 QString categoriesStr();
163 QString categoriesStrWithSpace(); 163 QString categoriesStrWithSpace();
164 164
165 /** point at some other event to which the event relates. This function should 165 /** point at some other event to which the event relates. This function should
166 * only be used when constructing a calendar before the related Event 166 * only be used when constructing a calendar before the related Event
167 * exists. */ 167 * exists. */
168 void setRelatedToUid(const QString &); 168 void setRelatedToUid(const QString &);
169 /** what event does this one relate to? This function should 169 /** what event does this one relate to? This function should
170 * only be used when constructing a calendar before the related Event 170 * only be used when constructing a calendar before the related Event
171 * exists. */ 171 * exists. */
172 QString relatedToUid() const; 172 QString relatedToUid() const;
173 /** point at some other event to which the event relates */ 173 /** point at some other event to which the event relates */
174 void setRelatedTo(Incidence *relatedTo); 174 void setRelatedTo(Incidence *relatedTo);
175 /** what event does this one relate to? */ 175 /** what event does this one relate to? */
176 Incidence *relatedTo() const; 176 Incidence *relatedTo() const;
177 /** All events that are related to this event */ 177 /** All events that are related to this event */
178 QPtrList<Incidence> relations() const; 178 QPtrList<Incidence> relations() const;
179 /** Add an event which is related to this event */ 179 /** Add an event which is related to this event */
180 void addRelation(Incidence *); 180 void addRelation(Incidence *);
181 /** Remove event that is related to this event */ 181 /** Remove event that is related to this event */
182 void removeRelation(Incidence *); 182 void removeRelation(Incidence *);
183 183
184 /** returns the list of dates which are exceptions to the recurrence rule */ 184 /** returns the list of dates which are exceptions to the recurrence rule */
185 DateList exDates() const; 185 DateList exDates() const;
186 /** sets the list of dates which are exceptions to the recurrence rule */ 186 /** sets the list of dates which are exceptions to the recurrence rule */
187 void setExDates(const DateList &_exDates); 187 void setExDates(const DateList &_exDates);
188 void setExDates(const char *dates); 188 void setExDates(const char *dates);
189 /** Add a date to the list of exceptions of the recurrence rule. */ 189 /** Add a date to the list of exceptions of the recurrence rule. */
190 void addExDate(const QDate &date); 190 void addExDate(const QDate &date);
191 191
192 /** returns true if there is an exception for this date in the recurrence 192 /** returns true if there is an exception for this date in the recurrence
193 rule set, or false otherwise. */ 193 rule set, or false otherwise. */
194 bool isException(const QDate &qd) const; 194 bool isException(const QDate &qd) const;
195 195
196 /** add attachment to this event */ 196 /** add attachment to this event */
197 void addAttachment(Attachment *attachment); 197 void addAttachment(Attachment *attachment);
198 /** remove and delete a specific attachment */ 198 /** remove and delete a specific attachment */
199 void deleteAttachment(Attachment *attachment); 199 void deleteAttachment(Attachment *attachment);
200 /** remove and delete all attachments with this mime type */ 200 /** remove and delete all attachments with this mime type */
201 void deleteAttachments(const QString& mime); 201 void deleteAttachments(const QString& mime);
202 /** return list of all associated attachments */ 202 /** return list of all associated attachments */
203 QPtrList<Attachment> attachments() const; 203 QPtrList<Attachment> attachments() const;
204 /** find a list of attachments with this mime type */ 204 /** find a list of attachments with this mime type */
205 QPtrList<Attachment> attachments(const QString& mime) const; 205 QPtrList<Attachment> attachments(const QString& mime) const;
206 206
207 /** sets the event's status the value specified. See the enumeration 207 /** sets the event's status the value specified. See the enumeration
208 * above for possible values. */ 208 * above for possible values. */
209 void setSecrecy(int); 209 void setSecrecy(int);
210 /** return the event's secrecy. */ 210 /** return the event's secrecy. */
211 int secrecy() const; 211 int secrecy() const;
212 /** return the event's secrecy in string format. */ 212 /** return the event's secrecy in string format. */
213 QString secrecyStr() const; 213 QString secrecyStr() const;
214 /** return list of all availbale secrecy classes */ 214 /** return list of all availbale secrecy classes */
215 static QStringList secrecyList(); 215 static QStringList secrecyList();
216 /** return human-readable name of secrecy class */ 216 /** return human-readable name of secrecy class */
217 static QString secrecyName(int); 217 static QString secrecyName(int);
218 218
219 /** returns TRUE if the date specified is one on which the event will 219 /** returns TRUE if the date specified is one on which the event will
220 * recur. */ 220 * recur. */
221 bool recursOn(const QDate &qd) const; 221 bool recursOn(const QDate &qd) const;
222 222
223 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): 223 // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?):
224 224
225 /** set resources used, such as Office, Car, etc. */ 225 /** set resources used, such as Office, Car, etc. */
226 void setResources(const QStringList &resources); 226 void setResources(const QStringList &resources);
227 /** return list of current resources */ 227 /** return list of current resources */
228 QStringList resources() const; 228 QStringList resources() const;
229 229
230 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ 230 /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */
231 void setPriority(int priority); 231 void setPriority(int priority);
232 /** get the event's priority */ 232 /** get the event's priority */
233 int priority() const; 233 int priority() const;
234 234
235 /** All alarms that are associated with this incidence */ 235 /** All alarms that are associated with this incidence */
236 QPtrList<Alarm> alarms() const; 236 QPtrList<Alarm> alarms() const;
237 /** Create a new alarm which is associated with this incidence */ 237 /** Create a new alarm which is associated with this incidence */
238 Alarm* newAlarm(); 238 Alarm* newAlarm();
239 /** Add an alarm which is associated with this incidence */ 239 /** Add an alarm which is associated with this incidence */
240 void addAlarm(Alarm*); 240 void addAlarm(Alarm*);
241 /** Remove an alarm that is associated with this incidence */ 241 /** Remove an alarm that is associated with this incidence */
242 void removeAlarm(Alarm*); 242 void removeAlarm(Alarm*);
243 /** Remove all alarms that are associated with this incidence */ 243 /** Remove all alarms that are associated with this incidence */
244 void clearAlarms(); 244 void clearAlarms();
245 /** return whether any alarm associated with this incidence is enabled */ 245 /** return whether any alarm associated with this incidence is enabled */
246 bool isAlarmEnabled() const; 246 bool isAlarmEnabled() const;
247 247
248 /** 248 /**
249 Return the recurrence rule associated with this incidence. If there is 249 Return the recurrence rule associated with this incidence. If there is
250 none, returns an appropriate (non-0) object. 250 none, returns an appropriate (non-0) object.
251 */ 251 */
252 Recurrence *recurrence(); 252 Recurrence *recurrence();
253 void setRecurrence(Recurrence * r); 253 void setRecurrence(Recurrence * r);
254 /** 254 /**
255 Forward to Recurrence::doesRecur(). 255 Forward to Recurrence::doesRecur().
256 */ 256 */
257 ushort doesRecur() const; 257 ushort doesRecur() const;
258 258
259 /** set the event's/todo's location. Do _not_ use it with journal */ 259 /** set the event's/todo's location. Do _not_ use it with journal */
260 void setLocation(const QString &location); 260 void setLocation(const QString &location);
261 /** return the event's/todo's location. Do _not_ use it with journal */ 261 /** return the event's/todo's location. Do _not_ use it with journal */
262 QString location() const; 262 QString location() const;
263 /** returns TRUE or FALSE depending on whether the todo has a start date */ 263 /** returns TRUE or FALSE depending on whether the todo has a start date */
264 bool hasStartDate() const; 264 bool hasStartDate() const;
265 /** sets the event's hasStartDate value. */ 265 /** sets the event's hasStartDate value. */
266 void setHasStartDate(bool f); 266 void setHasStartDate(bool f);
267 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; 267 QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const;
268 bool cancelled() const; 268 bool cancelled() const;
269 void setCancelled( bool b ); 269 void setCancelled( bool b );
270 270
271 bool hasRecurrenceID() const; 271 bool hasRecurrenceID() const;
272 void setHasRecurrenceID( bool b ); 272 void setHasRecurrenceID( bool b );
273 273
274 void setRecurrenceID(QDateTime); 274 void setRecurrenceID(QDateTime);
275 QDateTime recurrenceID () const; 275 QDateTime recurrenceID () const;
276 QDateTime dtStart() const; 276 QDateTime dtStart() const;
277 bool isHoliday() const; 277 bool isHoliday() const;
278 bool isBirthday() const; 278 bool isBirthday() const;
279 bool isAnniversary() const; 279 bool isAnniversary() const;
280 QDateTime lastModifiedSub(); 280 QDateTime lastModifiedSub();
281 QString recurrenceText() const; 281 QString recurrenceText() const;
282 void setLastModifiedSubInvalid(); 282 void setLastModifiedSubInvalid();
283 283
284 284 virtual QString durationText();
285 QString durationText4Time( int secs );
285 Recurrence *mRecurrence; 286 Recurrence *mRecurrence;
286protected: 287protected:
287 QPtrList<Alarm> mAlarms; 288 QPtrList<Alarm> mAlarms;
288 QPtrList<Incidence> mRelations; 289 QPtrList<Incidence> mRelations;
289 QDateTime mRecurrenceID; 290 QDateTime mRecurrenceID;
290 bool mHasRecurrenceID; 291 bool mHasRecurrenceID;
291 private: 292 private:
292 void checkCategories(); 293 void checkCategories();
293 bool mHoliday, mBirthday, mAnniversary; 294 bool mHoliday, mBirthday, mAnniversary;
294 int mRevision; 295 int mRevision;
295 bool mCancelled; 296 bool mCancelled;
296 297
297 // base components of jounal, event and todo 298 // base components of jounal, event and todo
298 QDateTime mCreated; 299 QDateTime mCreated;
299 QDateTime mLastModifiedSub; 300 QDateTime mLastModifiedSub;
300 QString mDescription; 301 QString mDescription;
301 QString mSummary; 302 QString mSummary;
302 QStringList mCategories; 303 QStringList mCategories;
303 Incidence *mRelatedTo; 304 Incidence *mRelatedTo;
304 QString mRelatedToUid; 305 QString mRelatedToUid;
305 DateList mExDates; 306 DateList mExDates;
306 QPtrList<Attachment> mAttachments; 307 QPtrList<Attachment> mAttachments;
307 QStringList mResources; 308 QStringList mResources;
308 bool mHasStartDate; // if todo has associated start date 309 bool mHasStartDate; // if todo has associated start date
309 310
310 int mSecrecy; 311 int mSecrecy;
311 int mPriority; // 1 = highest, 2 = less, etc. 312 int mPriority; // 1 = highest, 2 = less, etc.
312 313
313 //QPtrList<Alarm> mAlarms; 314 //QPtrList<Alarm> mAlarms;
314 315
315 QString mLocation; 316 QString mLocation;
316}; 317};
317 318
318bool operator==( const Incidence&, const Incidence& ); 319bool operator==( const Incidence&, const Incidence& );
319 320
320} 321}
321 322
322#endif 323#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 7bf756a..e4508a0 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -1,616 +1,626 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32using namespace KCal; 32using namespace KCal;
33 33
34Todo::Todo(): QObject(), Incidence() 34Todo::Todo(): QObject(), Incidence()
35{ 35{
36// mStatus = TENTATIVE; 36// mStatus = TENTATIVE;
37 37
38 mHasDueDate = false; 38 mHasDueDate = false;
39 setHasStartDate( false ); 39 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 40 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 41 mHasCompletedDate = false;
42 mPercentComplete = 0; 42 mPercentComplete = 0;
43 mRunning = false; 43 mRunning = false;
44 mRunSaveTimer = 0; 44 mRunSaveTimer = 0;
45} 45}
46 46
47Todo::Todo(const Todo &t) : QObject(),Incidence(t) 47Todo::Todo(const Todo &t) : QObject(),Incidence(t)
48{ 48{
49 mDtDue = t.mDtDue; 49 mDtDue = t.mDtDue;
50 mHasDueDate = t.mHasDueDate; 50 mHasDueDate = t.mHasDueDate;
51 mCompleted = t.mCompleted; 51 mCompleted = t.mCompleted;
52 mHasCompletedDate = t.mHasCompletedDate; 52 mHasCompletedDate = t.mHasCompletedDate;
53 mPercentComplete = t.mPercentComplete; 53 mPercentComplete = t.mPercentComplete;
54 mRunning = false; 54 mRunning = false;
55 mRunSaveTimer = 0; 55 mRunSaveTimer = 0;
56} 56}
57 57
58Todo::~Todo() 58Todo::~Todo()
59{ 59{
60 setRunning( false ); 60 setRunning( false );
61 //qDebug("Todo::~Todo() "); 61 //qDebug("Todo::~Todo() ");
62} 62}
63 63
64void Todo::setRunningFalse( QString s ) 64void Todo::setRunningFalse( QString s )
65{ 65{
66 if ( ! mRunning ) 66 if ( ! mRunning )
67 return; 67 return;
68 mRunning = false; 68 mRunning = false;
69 if ( mRunSaveTimer ) 69 if ( mRunSaveTimer )
70 mRunSaveTimer->stop(); 70 mRunSaveTimer->stop();
71 saveRunningInfoToFile( s ); 71 saveRunningInfoToFile( s );
72} 72}
73void Todo::stopRunning() 73void Todo::stopRunning()
74{ 74{
75 if ( !mRunning ) 75 if ( !mRunning )
76 return; 76 return;
77 if ( mRunSaveTimer ) 77 if ( mRunSaveTimer )
78 mRunSaveTimer->stop(); 78 mRunSaveTimer->stop();
79 mRunning = false; 79 mRunning = false;
80} 80}
81void Todo::setRunning( bool run ) 81void Todo::setRunning( bool run )
82{ 82{
83 if ( run == mRunning ) 83 if ( run == mRunning )
84 return; 84 return;
85 //qDebug("Todo::setRunning %d ", run); 85 //qDebug("Todo::setRunning %d ", run);
86 if ( !mRunSaveTimer ) { 86 if ( !mRunSaveTimer ) {
87 mRunSaveTimer = new QTimer ( this ); 87 mRunSaveTimer = new QTimer ( this );
88 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 88 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) );
89 } 89 }
90 mRunning = run; 90 mRunning = run;
91 if ( mRunning ) { 91 if ( mRunning ) {
92 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 92 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min
93 mRunStart = QDateTime::currentDateTime(); 93 mRunStart = QDateTime::currentDateTime();
94 } else { 94 } else {
95 mRunSaveTimer->stop(); 95 mRunSaveTimer->stop();
96 saveRunningInfoToFile(); 96 saveRunningInfoToFile();
97 } 97 }
98} 98}
99void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 99void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
100{ 100{
101 if ( !mRunning) return; 101 if ( !mRunning) return;
102 mRunning = false; 102 mRunning = false;
103 mRunStart = start; 103 mRunStart = start;
104 mRunEnd = end; 104 mRunEnd = end;
105 saveRunningInfoToFile( comment ); 105 saveRunningInfoToFile( comment );
106} 106}
107void Todo::saveRunningInfoToFile() 107void Todo::saveRunningInfoToFile()
108{ 108{
109 mRunEnd = QDateTime::currentDateTime(); 109 mRunEnd = QDateTime::currentDateTime();
110 saveRunningInfoToFile( QString::null ); 110 saveRunningInfoToFile( QString::null );
111} 111}
112void Todo::saveRunningInfoToFile( QString comment ) 112void Todo::saveRunningInfoToFile( QString comment )
113{ 113{
114 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 114 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
115 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 115 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
116 qDebug("Running time < 15 seconds. Skipped. "); 116 qDebug("Running time < 15 seconds. Skipped. ");
117 return; 117 return;
118 } 118 }
119 QString dir = KGlobalSettings::timeTrackerDir(); 119 QString dir = KGlobalSettings::timeTrackerDir();
120 //qDebug("%s ", dir.latin1()); 120 //qDebug("%s ", dir.latin1());
121 QString file = "%1%2%3-%4%5%6-"; 121 QString file = "%1%2%3-%4%5%6-";
122 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); 122 file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 );
123 file.replace ( QRegExp (" "), "0" ); 123 file.replace ( QRegExp (" "), "0" );
124 file += uid(); 124 file += uid();
125 //qDebug("File %s ",file.latin1() ); 125 //qDebug("File %s ",file.latin1() );
126 CalendarLocal cal; 126 CalendarLocal cal;
127 cal.setLocalTime(); 127 cal.setLocalTime();
128 Todo * to = (Todo*) clone(); 128 Todo * to = (Todo*) clone();
129 to->setFloats( false ); 129 to->setFloats( false );
130 to->setDtStart( mRunStart ); 130 to->setDtStart( mRunStart );
131 to->setHasStartDate( true ); 131 to->setHasStartDate( true );
132 to->setDtDue( mRunEnd ); 132 to->setDtDue( mRunEnd );
133 to->setHasDueDate( true ); 133 to->setHasDueDate( true );
134 to->setUid( file ); 134 to->setUid( file );
135 if ( !comment.isEmpty() ) { 135 if ( !comment.isEmpty() ) {
136 QString des = to->description(); 136 QString des = to->description();
137 if ( des.isEmpty () ) 137 if ( des.isEmpty () )
138 to->setDescription( "TT-Note: " + comment ); 138 to->setDescription( "TT-Note: " + comment );
139 else 139 else
140 to->setDescription( "TT-Note: " + comment +"\n" + des ); 140 to->setDescription( "TT-Note: " + comment +"\n" + des );
141 } 141 }
142 cal.addIncidence( to ); 142 cal.addIncidence( to );
143 ICalFormat format( false ); 143 ICalFormat format( false );
144 file = dir +"/" +file +".ics"; 144 file = dir +"/" +file +".ics";
145 format.save( &cal, file ); 145 format.save( &cal, file );
146 saveParents(); 146 saveParents();
147 147
148} 148}
149void Todo::saveParents() 149void Todo::saveParents()
150{ 150{
151 if (!relatedTo() ) 151 if (!relatedTo() )
152 return; 152 return;
153 Incidence * inc = relatedTo(); 153 Incidence * inc = relatedTo();
154 if ( inc->typeID() != todoID ) 154 if ( inc->typeID() != todoID )
155 return; 155 return;
156 Todo* to = (Todo*)inc; 156 Todo* to = (Todo*)inc;
157 bool saveTodo = false; 157 bool saveTodo = false;
158 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; 158 QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics";
159 QFileInfo fi ( file ); 159 QFileInfo fi ( file );
160 if ( fi.exists() ) { 160 if ( fi.exists() ) {
161 if ( fi.lastModified () < to->lastModified ()) 161 if ( fi.lastModified () < to->lastModified ())
162 saveTodo = true; 162 saveTodo = true;
163 } else { 163 } else {
164 saveTodo = true; 164 saveTodo = true;
165 } 165 }
166 if ( saveTodo ) { 166 if ( saveTodo ) {
167 CalendarLocal cal; 167 CalendarLocal cal;
168 cal.setLocalTime(); 168 cal.setLocalTime();
169 Todo * par = (Todo *) to->clone(); 169 Todo * par = (Todo *) to->clone();
170 cal.addIncidence( par ); 170 cal.addIncidence( par );
171 ICalFormat format( false ); 171 ICalFormat format( false );
172 format.save( &cal, file ); 172 format.save( &cal, file );
173 } 173 }
174 to->saveParents(); 174 to->saveParents();
175} 175}
176 176
177int Todo::runTime() 177int Todo::runTime()
178{ 178{
179 if ( !mRunning ) 179 if ( !mRunning )
180 return 0; 180 return 0;
181 return mRunStart.secsTo( QDateTime::currentDateTime() ); 181 return mRunStart.secsTo( QDateTime::currentDateTime() );
182} 182}
183bool Todo::hasRunningSub() 183bool Todo::hasRunningSub()
184{ 184{
185 if ( mRunning ) 185 if ( mRunning )
186 return true; 186 return true;
187 Incidence *aTodo; 187 Incidence *aTodo;
188 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 188 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
189 if ( ((Todo*)aTodo)->hasRunningSub() ) 189 if ( ((Todo*)aTodo)->hasRunningSub() )
190 return true; 190 return true;
191 } 191 }
192 return false; 192 return false;
193} 193}
194Incidence *Todo::clone() 194Incidence *Todo::clone()
195{ 195{
196 return new Todo(*this); 196 return new Todo(*this);
197} 197}
198 198
199bool Todo::contains ( Todo* from ) 199bool Todo::contains ( Todo* from )
200{ 200{
201 201
202 if ( !from->summary().isEmpty() ) 202 if ( !from->summary().isEmpty() )
203 if ( !summary().startsWith( from->summary() )) 203 if ( !summary().startsWith( from->summary() ))
204 return false; 204 return false;
205 if ( from->hasStartDate() ) { 205 if ( from->hasStartDate() ) {
206 if ( !hasStartDate() ) 206 if ( !hasStartDate() )
207 return false; 207 return false;
208 if ( from->dtStart() != dtStart()) 208 if ( from->dtStart() != dtStart())
209 return false; 209 return false;
210 } 210 }
211 if ( from->hasDueDate() ){ 211 if ( from->hasDueDate() ){
212 if ( !hasDueDate() ) 212 if ( !hasDueDate() )
213 return false; 213 return false;
214 if ( from->dtDue() != dtDue()) 214 if ( from->dtDue() != dtDue())
215 return false; 215 return false;
216 } 216 }
217 if ( !from->location().isEmpty() ) 217 if ( !from->location().isEmpty() )
218 if ( !location().startsWith( from->location() ) ) 218 if ( !location().startsWith( from->location() ) )
219 return false; 219 return false;
220 if ( !from->description().isEmpty() ) 220 if ( !from->description().isEmpty() )
221 if ( !description().startsWith( from->description() )) 221 if ( !description().startsWith( from->description() ))
222 return false; 222 return false;
223 if ( from->alarms().count() ) { 223 if ( from->alarms().count() ) {
224 Alarm *a = from->alarms().first(); 224 Alarm *a = from->alarms().first();
225 if ( a->enabled() ){ 225 if ( a->enabled() ){
226 if ( !alarms().count() ) 226 if ( !alarms().count() )
227 return false; 227 return false;
228 Alarm *b = alarms().first(); 228 Alarm *b = alarms().first();
229 if( ! b->enabled() ) 229 if( ! b->enabled() )
230 return false; 230 return false;
231 if ( ! (a->offset() == b->offset() )) 231 if ( ! (a->offset() == b->offset() ))
232 return false; 232 return false;
233 } 233 }
234 } 234 }
235 235
236 QStringList cat = categories(); 236 QStringList cat = categories();
237 QStringList catFrom = from->categories(); 237 QStringList catFrom = from->categories();
238 QString nCat; 238 QString nCat;
239 unsigned int iii; 239 unsigned int iii;
240 for ( iii = 0; iii < catFrom.count();++iii ) { 240 for ( iii = 0; iii < catFrom.count();++iii ) {
241 nCat = catFrom[iii]; 241 nCat = catFrom[iii];
242 if ( !nCat.isEmpty() ) 242 if ( !nCat.isEmpty() )
243 if ( !cat.contains( nCat )) { 243 if ( !cat.contains( nCat )) {
244 return false; 244 return false;
245 } 245 }
246 } 246 }
247 if ( from->isCompleted() ) { 247 if ( from->isCompleted() ) {
248 if ( !isCompleted() ) 248 if ( !isCompleted() )
249 return false; 249 return false;
250 } 250 }
251 if( priority() != from->priority() ) 251 if( priority() != from->priority() )
252 return false; 252 return false;
253 253
254 254
255 return true; 255 return true;
256 256
257} 257}
258bool KCal::operator==( const Todo& t1, const Todo& t2 ) 258bool KCal::operator==( const Todo& t1, const Todo& t2 )
259{ 259{
260 260
261 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 261 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
262 if ( ! ret ) 262 if ( ! ret )
263 return false; 263 return false;
264 if ( t1.hasDueDate() == t2.hasDueDate() ) { 264 if ( t1.hasDueDate() == t2.hasDueDate() ) {
265 if ( t1.hasDueDate() ) { 265 if ( t1.hasDueDate() ) {
266 if ( t1.doesFloat() == t2.doesFloat() ) { 266 if ( t1.doesFloat() == t2.doesFloat() ) {
267 if ( t1.doesFloat() ) { 267 if ( t1.doesFloat() ) {
268 if ( t1.dtDue().date() != t2.dtDue().date() ) 268 if ( t1.dtDue().date() != t2.dtDue().date() )
269 return false; 269 return false;
270 } else 270 } else
271 if ( t1.dtDue() != t2.dtDue() ) 271 if ( t1.dtDue() != t2.dtDue() )
272 return false; 272 return false;
273 } else 273 } else
274 return false;// float != 274 return false;// float !=
275 } 275 }
276 276
277 } else 277 } else
278 return false; 278 return false;
279 if ( t1.percentComplete() != t2.percentComplete() ) 279 if ( t1.percentComplete() != t2.percentComplete() )
280 return false; 280 return false;
281 if ( t1.isCompleted() ) { 281 if ( t1.isCompleted() ) {
282 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 282 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
283 if ( t1.hasCompletedDate() ) { 283 if ( t1.hasCompletedDate() ) {
284 if ( t1.completed() != t2.completed() ) 284 if ( t1.completed() != t2.completed() )
285 return false; 285 return false;
286 } 286 }
287 287
288 } else 288 } else
289 return false; 289 return false;
290 } 290 }
291 return true; 291 return true;
292 292
293} 293}
294 294
295void Todo::setDtDue(const QDateTime &dtDue) 295void Todo::setDtDue(const QDateTime &dtDue)
296{ 296{
297 //int diffsecs = mDtDue.secsTo(dtDue); 297 //int diffsecs = mDtDue.secsTo(dtDue);
298 298
299 /*if (mReadOnly) return; 299 /*if (mReadOnly) return;
300 const QPtrList<Alarm>& alarms = alarms(); 300 const QPtrList<Alarm>& alarms = alarms();
301 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 301 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
302 if (alarm->enabled()) { 302 if (alarm->enabled()) {
303 alarm->setTime(alarm->time().addSecs(diffsecs)); 303 alarm->setTime(alarm->time().addSecs(diffsecs));
304 } 304 }
305 }*/ 305 }*/
306 mDtDue = getEvenTime(dtDue); 306 mDtDue = getEvenTime(dtDue);
307 307
308 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 308 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
309 309
310 /*const QPtrList<Alarm>& alarms = alarms(); 310 /*const QPtrList<Alarm>& alarms = alarms();
311 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 311 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
312 alarm->setAlarmStart(mDtDue);*/ 312 alarm->setAlarmStart(mDtDue);*/
313 updated(); 313 updated();
314} 314}
315 315
316QDateTime Todo::dtDue() const 316QDateTime Todo::dtDue() const
317{ 317{
318 return mDtDue; 318 return mDtDue;
319} 319}
320 320
321QString Todo::dtDueTimeStr() const 321QString Todo::dtDueTimeStr() const
322{ 322{
323 return KGlobal::locale()->formatTime(mDtDue.time()); 323 return KGlobal::locale()->formatTime(mDtDue.time());
324} 324}
325 325
326QString Todo::dtDueDateStr(bool shortfmt) const 326QString Todo::dtDueDateStr(bool shortfmt) const
327{ 327{
328 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 328 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
329} 329}
330 330
331QString Todo::dtDueStr(bool shortfmt) const 331QString Todo::dtDueStr(bool shortfmt) const
332{ 332{
333 if ( doesFloat() ) 333 if ( doesFloat() )
334 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 334 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
335 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 335 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
336} 336}
337// retval 0 : no found 337// retval 0 : no found
338// 1 : due for date found 338// 1 : due for date found
339// 2 : overdue for date found 339// 2 : overdue for date found
340int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 340int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
341{ 341{
342 int retval = 0; 342 int retval = 0;
343 if ( isCompleted() ) 343 if ( isCompleted() )
344 return 0; 344 return 0;
345 if ( hasDueDate() ) { 345 if ( hasDueDate() ) {
346 if ( dtDue().date() < date ) 346 if ( dtDue().date() < date )
347 return 2; 347 return 2;
348 // we do not return, because we may find an overdue sub todo 348 // we do not return, because we may find an overdue sub todo
349 if ( dtDue().date() == date ) 349 if ( dtDue().date() == date )
350 retval = 1; 350 retval = 1;
351 } 351 }
352 if ( checkSubtodos ) { 352 if ( checkSubtodos ) {
353 Incidence *aTodo; 353 Incidence *aTodo;
354 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 354 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
355 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 355 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
356 if ( ret == 2 ) 356 if ( ret == 2 )
357 return 2; 357 return 2;
358 if ( ret == 1) 358 if ( ret == 1)
359 retval = 1; 359 retval = 1;
360 } 360 }
361 } 361 }
362 return retval; 362 return retval;
363} 363}
364int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 364int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
365{ 365{
366 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 366 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
367} 367}
368bool Todo::hasDueDate() const 368bool Todo::hasDueDate() const
369{ 369{
370 return mHasDueDate; 370 return mHasDueDate;
371} 371}
372 372
373void Todo::setHasDueDate(bool f) 373void Todo::setHasDueDate(bool f)
374{ 374{
375 if (mReadOnly) return; 375 if (mReadOnly) return;
376 mHasDueDate = f; 376 mHasDueDate = f;
377 updated(); 377 updated();
378} 378}
379 379
380 380
381#if 0 381#if 0
382void Todo::setStatus(const QString &statStr) 382void Todo::setStatus(const QString &statStr)
383{ 383{
384 if (mReadOnly) return; 384 if (mReadOnly) return;
385 QString ss(statStr.upper()); 385 QString ss(statStr.upper());
386 386
387 if (ss == "X-ACTION") 387 if (ss == "X-ACTION")
388 mStatus = NEEDS_ACTION; 388 mStatus = NEEDS_ACTION;
389 else if (ss == "NEEDS ACTION") 389 else if (ss == "NEEDS ACTION")
390 mStatus = NEEDS_ACTION; 390 mStatus = NEEDS_ACTION;
391 else if (ss == "ACCEPTED") 391 else if (ss == "ACCEPTED")
392 mStatus = ACCEPTED; 392 mStatus = ACCEPTED;
393 else if (ss == "SENT") 393 else if (ss == "SENT")
394 mStatus = SENT; 394 mStatus = SENT;
395 else if (ss == "TENTATIVE") 395 else if (ss == "TENTATIVE")
396 mStatus = TENTATIVE; 396 mStatus = TENTATIVE;
397 else if (ss == "CONFIRMED") 397 else if (ss == "CONFIRMED")
398 mStatus = CONFIRMED; 398 mStatus = CONFIRMED;
399 else if (ss == "DECLINED") 399 else if (ss == "DECLINED")
400 mStatus = DECLINED; 400 mStatus = DECLINED;
401 else if (ss == "COMPLETED") 401 else if (ss == "COMPLETED")
402 mStatus = COMPLETED; 402 mStatus = COMPLETED;
403 else if (ss == "DELEGATED") 403 else if (ss == "DELEGATED")
404 mStatus = DELEGATED; 404 mStatus = DELEGATED;
405 405
406 updated(); 406 updated();
407} 407}
408 408
409void Todo::setStatus(int status) 409void Todo::setStatus(int status)
410{ 410{
411 if (mReadOnly) return; 411 if (mReadOnly) return;
412 mStatus = status; 412 mStatus = status;
413 updated(); 413 updated();
414} 414}
415 415
416int Todo::status() const 416int Todo::status() const
417{ 417{
418 return mStatus; 418 return mStatus;
419} 419}
420 420
421QString Todo::statusStr() const 421QString Todo::statusStr() const
422{ 422{
423 switch(mStatus) { 423 switch(mStatus) {
424 case NEEDS_ACTION: 424 case NEEDS_ACTION:
425 return QString("NEEDS ACTION"); 425 return QString("NEEDS ACTION");
426 break; 426 break;
427 case ACCEPTED: 427 case ACCEPTED:
428 return QString("ACCEPTED"); 428 return QString("ACCEPTED");
429 break; 429 break;
430 case SENT: 430 case SENT:
431 return QString("SENT"); 431 return QString("SENT");
432 break; 432 break;
433 case TENTATIVE: 433 case TENTATIVE:
434 return QString("TENTATIVE"); 434 return QString("TENTATIVE");
435 break; 435 break;
436 case CONFIRMED: 436 case CONFIRMED:
437 return QString("CONFIRMED"); 437 return QString("CONFIRMED");
438 break; 438 break;
439 case DECLINED: 439 case DECLINED:
440 return QString("DECLINED"); 440 return QString("DECLINED");
441 break; 441 break;
442 case COMPLETED: 442 case COMPLETED:
443 return QString("COMPLETED"); 443 return QString("COMPLETED");
444 break; 444 break;
445 case DELEGATED: 445 case DELEGATED:
446 return QString("DELEGATED"); 446 return QString("DELEGATED");
447 break; 447 break;
448 } 448 }
449 return QString(""); 449 return QString("");
450} 450}
451#endif 451#endif
452 452
453bool Todo::isCompleted() const 453bool Todo::isCompleted() const
454{ 454{
455 if (mPercentComplete == 100) { 455 if (mPercentComplete == 100) {
456 return true; 456 return true;
457 } 457 }
458 else return false; 458 else return false;
459} 459}
460 460
461void Todo::setCompleted(bool completed) 461void Todo::setCompleted(bool completed)
462{ 462{
463 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 463 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
464 if ( !setRecurDates() ) 464 if ( !setRecurDates() )
465 completed = false; 465 completed = false;
466 } 466 }
467 if (completed) mPercentComplete = 100; 467 if (completed) mPercentComplete = 100;
468 else { 468 else {
469 mPercentComplete = 0; 469 mPercentComplete = 0;
470 mHasCompletedDate = false; 470 mHasCompletedDate = false;
471 } 471 }
472 updated(); 472 updated();
473} 473}
474 474
475QDateTime Todo::completed() const 475QDateTime Todo::completed() const
476{ 476{
477 return mCompleted; 477 return mCompleted;
478} 478}
479 479
480QString Todo::completedStr( bool shortF ) const 480QString Todo::completedStr( bool shortF ) const
481{ 481{
482 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 482 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
483} 483}
484 484
485void Todo::setCompleted(const QDateTime &completed) 485void Todo::setCompleted(const QDateTime &completed)
486{ 486{
487 //qDebug("Todo::setCompleted "); 487 //qDebug("Todo::setCompleted ");
488 if ( mHasCompletedDate ) { 488 if ( mHasCompletedDate ) {
489 // qDebug("has completed data - return "); 489 // qDebug("has completed data - return ");
490 return; 490 return;
491 } 491 }
492 mHasCompletedDate = true; 492 mHasCompletedDate = true;
493 mPercentComplete = 100; 493 mPercentComplete = 100;
494 mCompleted = getEvenTime(completed); 494 mCompleted = getEvenTime(completed);
495 updated(); 495 updated();
496} 496}
497 497
498bool Todo::hasCompletedDate() const 498bool Todo::hasCompletedDate() const
499{ 499{
500 return mHasCompletedDate; 500 return mHasCompletedDate;
501} 501}
502 502
503int Todo::percentComplete() const 503int Todo::percentComplete() const
504{ 504{
505 return mPercentComplete; 505 return mPercentComplete;
506} 506}
507bool Todo::setRecurDates() 507bool Todo::setRecurDates()
508{ 508{
509 if ( !mHasRecurrenceID ) 509 if ( !mHasRecurrenceID )
510 return true; 510 return true;
511 int secs = mDtStart.secsTo( dtDue() ); 511 int secs = mDtStart.secsTo( dtDue() );
512 bool ok; 512 bool ok;
513 qDebug("T:setRecurDates() "); 513 qDebug("T:setRecurDates() ");
514 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 514 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
515 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 515 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
516 if ( ok ) { 516 if ( ok ) {
517 mRecurrenceID = next; 517 mRecurrenceID = next;
518 mDtStart = next; 518 mDtStart = next;
519 setDtDue( next.addSecs( secs ) ); 519 setDtDue( next.addSecs( secs ) );
520 if ( QDateTime::currentDateTime() > next) 520 if ( QDateTime::currentDateTime() > next)
521 return false; 521 return false;
522 } else { 522 } else {
523 setHasRecurrenceID( false ); 523 setHasRecurrenceID( false );
524 recurrence()->unsetRecurs(); 524 recurrence()->unsetRecurs();
525 } 525 }
526 return true; 526 return true;
527} 527}
528void Todo::setPercentComplete(int v) 528void Todo::setPercentComplete(int v)
529{ 529{
530 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 530 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
531 if ( !setRecurDates() ) 531 if ( !setRecurDates() )
532 v = 0; 532 v = 0;
533 } 533 }
534 mPercentComplete = v; 534 mPercentComplete = v;
535 if ( v != 100 ) 535 if ( v != 100 )
536 mHasCompletedDate = false; 536 mHasCompletedDate = false;
537 updated(); 537 updated();
538} 538}
539QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 539QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
540{ 540{
541 *ok = false; 541 *ok = false;
542 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { 542 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) {
543 return QDateTime (); 543 return QDateTime ();
544 } 544 }
545 // if the recurring todo is set to complete and requested time < start time of todo 545 // if the recurring todo is set to complete and requested time < start time of todo
546 // we want to get the alarm. 546 // we want to get the alarm.
547 bool iscompleted = isCompleted(); 547 bool iscompleted = isCompleted();
548 if ( iscompleted && doesRecur() ) { 548 if ( iscompleted && doesRecur() ) {
549 Todo * to = (Todo*) this; 549 Todo * to = (Todo*) this;
550 to->checkSetCompletedFalse(); 550 to->checkSetCompletedFalse();
551 iscompleted = isCompleted(); 551 iscompleted = isCompleted();
552 if ( hasStartDate() && start_dt < dtStart() ){ 552 if ( hasStartDate() && start_dt < dtStart() ){
553 iscompleted = false; 553 iscompleted = false;
554 } 554 }
555 } 555 }
556 if ( iscompleted ) { 556 if ( iscompleted ) {
557 return QDateTime (); 557 return QDateTime ();
558 } 558 }
559 QDateTime incidenceStart; 559 QDateTime incidenceStart;
560 incidenceStart = dtDue(); 560 incidenceStart = dtDue();
561 bool enabled = false; 561 bool enabled = false;
562 Alarm* alarm; 562 Alarm* alarm;
563 int off = 0; 563 int off = 0;
564 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 564 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
565 // if ( QDateTime::currentDateTime() > incidenceStart ){ 565 // if ( QDateTime::currentDateTime() > incidenceStart ){
566// *ok = false; 566// *ok = false;
567// return incidenceStart; 567// return incidenceStart;
568// } 568// }
569 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 569 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
570 if (alarm->enabled()) { 570 if (alarm->enabled()) {
571 if ( alarm->hasTime () ) { 571 if ( alarm->hasTime () ) {
572 if ( alarm->time() < alarmStart ) { 572 if ( alarm->time() < alarmStart ) {
573 alarmStart = alarm->time(); 573 alarmStart = alarm->time();
574 enabled = true; 574 enabled = true;
575 off = alarmStart.secsTo( incidenceStart ); 575 off = alarmStart.secsTo( incidenceStart );
576 } 576 }
577 577
578 } else { 578 } else {
579 int secs = alarm->startOffset().asSeconds(); 579 int secs = alarm->startOffset().asSeconds();
580 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 580 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
581 alarmStart = incidenceStart.addSecs( secs ); 581 alarmStart = incidenceStart.addSecs( secs );
582 enabled = true; 582 enabled = true;
583 off = -secs; 583 off = -secs;
584 } 584 }
585 } 585 }
586 } 586 }
587 } 587 }
588 if ( enabled ) { 588 if ( enabled ) {
589 if ( alarmStart > start_dt ) { 589 if ( alarmStart > start_dt ) {
590 *ok = true; 590 *ok = true;
591 * offset = off; 591 * offset = off;
592 return alarmStart; 592 return alarmStart;
593 } 593 }
594 } 594 }
595 *ok = false; 595 *ok = false;
596 return QDateTime (); 596 return QDateTime ();
597 597
598} 598}
599 599
600void Todo::checkSetCompletedFalse() 600void Todo::checkSetCompletedFalse()
601{ 601{
602 if ( !mHasRecurrenceID ) { 602 if ( !mHasRecurrenceID ) {
603 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 603 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
604 return; 604 return;
605 } 605 }
606 // qDebug("Todo::checkSetCompletedFalse()"); 606 // qDebug("Todo::checkSetCompletedFalse()");
607 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 607 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
608 if ( mPercentComplete == 100 ) { 608 if ( mPercentComplete == 100 ) {
609 QDateTime dt = QDateTime::currentDateTime(); 609 QDateTime dt = QDateTime::currentDateTime();
610 if ( dt > mDtStart && dt > mRecurrenceID ) { 610 if ( dt > mDtStart && dt > mRecurrenceID ) {
611 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 611 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
612 setCompleted( false ); 612 setCompleted( false );
613 qDebug("Todo::checkSetCompletedFalse "); 613 qDebug("Todo::checkSetCompletedFalse ");
614 } 614 }
615 } 615 }
616} 616}
617QString Todo::durationText()
618{
619 if ( mHasDueDate && hasStartDate() ) {
620 int sec = dtStart().secsTo( dtDue() );
621 if ( doesFloat() )
622 sec += 86400;
623 return durationText4Time( sec );
624 }
625 return "---";
626}
diff --git a/libkcal/todo.h b/libkcal/todo.h
index 425dfad..7feb32e 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -1,155 +1,156 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20#ifndef TODO_H 20#ifndef TODO_H
21#define TODO_H 21#define TODO_H
22// 22//
23// Todo component, representing a VTODO object 23// Todo component, representing a VTODO object
24// 24//
25 25
26#include "incidence.h" 26#include "incidence.h"
27 27
28#include <qtimer.h> 28#include <qtimer.h>
29 29
30namespace KCal { 30namespace KCal {
31 31
32/** 32/**
33 This class provides a Todo in the sense of RFC2445. 33 This class provides a Todo in the sense of RFC2445.
34*/ 34*/
35 class Todo : public QObject,public Incidence 35 class Todo : public QObject,public Incidence
36{ 36{
37 Q_OBJECT 37 Q_OBJECT
38 public: 38 public:
39 Todo(); 39 Todo();
40 Todo(const Todo &); 40 Todo(const Todo &);
41 ~Todo(); 41 ~Todo();
42 typedef ListBase<Todo> List; 42 typedef ListBase<Todo> List;
43 QCString type() const { return "Todo"; } 43 QCString type() const { return "Todo"; }
44 IncTypeID typeID() const { return todoID; } 44 IncTypeID typeID() const { return todoID; }
45 45
46 /** Return an exact copy of this todo. */ 46 /** Return an exact copy of this todo. */
47 Incidence *clone(); 47 Incidence *clone();
48 QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; 48 QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const;
49 49
50 /** for setting the todo's due date/time with a QDateTime. */ 50 /** for setting the todo's due date/time with a QDateTime. */
51 void setDtDue(const QDateTime &dtDue); 51 void setDtDue(const QDateTime &dtDue);
52 /** returns an event's Due date/time as a QDateTime. */ 52 /** returns an event's Due date/time as a QDateTime. */
53 QDateTime dtDue() const; 53 QDateTime dtDue() const;
54 /** returns an event's due time as a string formatted according to the 54 /** returns an event's due time as a string formatted according to the
55 users locale settings */ 55 users locale settings */
56 QString dtDueTimeStr() const; 56 QString dtDueTimeStr() const;
57 /** returns an event's due date as a string formatted according to the 57 /** returns an event's due date as a string formatted according to the
58 users locale settings */ 58 users locale settings */
59 QString dtDueDateStr(bool shortfmt=true) const; 59 QString dtDueDateStr(bool shortfmt=true) const;
60 /** returns an event's due date and time as a string formatted according 60 /** returns an event's due date and time as a string formatted according
61 to the users locale settings */ 61 to the users locale settings */
62 QString dtDueStr(bool shortfmt=true) const; 62 QString dtDueStr(bool shortfmt=true) const;
63 63
64 /** returns TRUE or FALSE depending on whether the todo has a due date */ 64 /** returns TRUE or FALSE depending on whether the todo has a due date */
65 bool hasDueDate() const; 65 bool hasDueDate() const;
66 /** sets the event's hasDueDate value. */ 66 /** sets the event's hasDueDate value. */
67 void setHasDueDate(bool f); 67 void setHasDueDate(bool f);
68 68
69 /* 69 /*
70 Looks for a subtodo (including itself ) which is not complete and is 70 Looks for a subtodo (including itself ) which is not complete and is
71 - overdue, or 71 - overdue, or
72 - due today. 72 - due today.
73 It returns 0 for nothing found, 73 It returns 0 for nothing found,
74 1 for found a todo which is due today and no overdue found 74 1 for found a todo which is due today and no overdue found
75 2 for found a overdue todo 75 2 for found a overdue todo
76 */ 76 */
77 int hasDueSubTodo( bool checkSubtodos = true ); 77 int hasDueSubTodo( bool checkSubtodos = true );
78 /* same as above, but a specific date can be specified*/ 78 /* same as above, but a specific date can be specified*/
79 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); 79 int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos );
80 80
81 81
82 /** sets the event's status to the string specified. The string 82 /** sets the event's status to the string specified. The string
83 * must be a recognized value for the status field, i.e. a string 83 * must be a recognized value for the status field, i.e. a string
84 * equivalent of the possible status enumerations previously described. */ 84 * equivalent of the possible status enumerations previously described. */
85// void setStatus(const QString &statStr); 85// void setStatus(const QString &statStr);
86 /** sets the event's status to the value specified. See the enumeration 86 /** sets the event's status to the value specified. See the enumeration
87 * above for possible values. */ 87 * above for possible values. */
88// void setStatus(int); 88// void setStatus(int);
89 /** return the event's status. */ 89 /** return the event's status. */
90// int status() const; 90// int status() const;
91 /** return the event's status in string format. */ 91 /** return the event's status in string format. */
92// QString statusStr() const; 92// QString statusStr() const;
93 93
94 /** return, if this todo is completed */ 94 /** return, if this todo is completed */
95 bool isCompleted() const; 95 bool isCompleted() const;
96 /** set completed state of this todo */ 96 /** set completed state of this todo */
97 void setCompleted(bool); 97 void setCompleted(bool);
98 98
99 /** 99 /**
100 Return how many percent of the task are completed. Returns a value 100 Return how many percent of the task are completed. Returns a value
101 between 0 and 100. 101 between 0 and 100.
102 */ 102 */
103 int percentComplete() const; 103 int percentComplete() const;
104 /** 104 /**
105 Set how many percent of the task are completed. Valid values are in the 105 Set how many percent of the task are completed. Valid values are in the
106 range from 0 to 100. 106 range from 0 to 100.
107 */ 107 */
108 void setPercentComplete(int); 108 void setPercentComplete(int);
109 109
110 /** return date and time when todo was completed */ 110 /** return date and time when todo was completed */
111 QDateTime completed() const; 111 QDateTime completed() const;
112 QString completedStr(bool shortF = true) const; 112 QString completedStr(bool shortF = true) const;
113 /** set date and time of completion */ 113 /** set date and time of completion */
114 void setCompleted(const QDateTime &completed); 114 void setCompleted(const QDateTime &completed);
115 115
116 /** Return true, if todo has a date associated with completion */ 116 /** Return true, if todo has a date associated with completion */
117 bool hasCompletedDate() const; 117 bool hasCompletedDate() const;
118 bool contains ( Todo*); 118 bool contains ( Todo*);
119 void checkSetCompletedFalse(); 119 void checkSetCompletedFalse();
120 bool setRecurDates(); 120 bool setRecurDates();
121 bool isRunning() {return mRunning;} 121 bool isRunning() {return mRunning;}
122 bool hasRunningSub(); 122 bool hasRunningSub();
123 void setRunning( bool ); 123 void setRunning( bool );
124 void setRunningFalse( QString ); 124 void setRunningFalse( QString );
125 void stopRunning(); 125 void stopRunning();
126 int runTime(); 126 int runTime();
127 QDateTime runStart () const { return mRunStart;} 127 QDateTime runStart () const { return mRunStart;}
128 void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); 128 void saveRunningInfo( QString comment, QDateTime start, QDateTime end );
129 public slots: 129 public slots:
130 void saveRunningInfoToFile( QString st ); 130 void saveRunningInfoToFile( QString st );
131 void saveRunningInfoToFile( ); 131 void saveRunningInfoToFile( );
132 void saveParents(); 132 void saveParents();
133 QString durationText();
133 private: 134 private:
134 bool mRunning; 135 bool mRunning;
135 QTimer * mRunSaveTimer; 136 QTimer * mRunSaveTimer;
136 QDateTime mRunStart; 137 QDateTime mRunStart;
137 QDateTime mRunEnd; 138 QDateTime mRunEnd;
138 bool accept(Visitor &v) { return v.visit(this); } 139 bool accept(Visitor &v) { return v.visit(this); }
139 140
140 QDateTime mDtDue; // due date of todo 141 QDateTime mDtDue; // due date of todo
141 142
142 bool mHasDueDate; // if todo has associated due date 143 bool mHasDueDate; // if todo has associated due date
143 144
144// int mStatus; // confirmed/delegated/tentative/etc 145// int mStatus; // confirmed/delegated/tentative/etc
145 146
146 QDateTime mCompleted; 147 QDateTime mCompleted;
147 bool mHasCompletedDate; 148 bool mHasCompletedDate;
148 149
149 int mPercentComplete; 150 int mPercentComplete;
150}; 151};
151 152
152 bool operator==( const Todo&, const Todo& ); 153 bool operator==( const Todo&, const Todo& );
153} 154}
154 155
155#endif 156#endif