summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-06-08 09:15:20 (UTC)
committer zautrix <zautrix>2005-06-08 09:15:20 (UTC)
commit39d84e2fc3099bd5d7596e8be5dc6783826cec01 (patch) (unidiff)
treea811365972a94c65cfd4f78c802ae8e9b09d7d12 /libkcal
parent876dca14867d6a47b661c60a9c96ac3a70591d0c (diff)
downloadkdepimpi-39d84e2fc3099bd5d7596e8be5dc6783826cec01.zip
kdepimpi-39d84e2fc3099bd5d7596e8be5dc6783826cec01.tar.gz
kdepimpi-39d84e2fc3099bd5d7596e8be5dc6783826cec01.tar.bz2
rec todo fix
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 473247a..38ba2c7 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -188,390 +188,393 @@ bool Todo::contains ( Todo* from )
188 return false; 188 return false;
189 } 189 }
190 if ( from->hasDueDate() ){ 190 if ( from->hasDueDate() ){
191 if ( !hasDueDate() ) 191 if ( !hasDueDate() )
192 return false; 192 return false;
193 if ( from->dtDue() != dtDue()) 193 if ( from->dtDue() != dtDue())
194 return false; 194 return false;
195 } 195 }
196 if ( !from->location().isEmpty() ) 196 if ( !from->location().isEmpty() )
197 if ( !location().startsWith( from->location() ) ) 197 if ( !location().startsWith( from->location() ) )
198 return false; 198 return false;
199 if ( !from->description().isEmpty() ) 199 if ( !from->description().isEmpty() )
200 if ( !description().startsWith( from->description() )) 200 if ( !description().startsWith( from->description() ))
201 return false; 201 return false;
202 if ( from->alarms().count() ) { 202 if ( from->alarms().count() ) {
203 Alarm *a = from->alarms().first(); 203 Alarm *a = from->alarms().first();
204 if ( a->enabled() ){ 204 if ( a->enabled() ){
205 if ( !alarms().count() ) 205 if ( !alarms().count() )
206 return false; 206 return false;
207 Alarm *b = alarms().first(); 207 Alarm *b = alarms().first();
208 if( ! b->enabled() ) 208 if( ! b->enabled() )
209 return false; 209 return false;
210 if ( ! (a->offset() == b->offset() )) 210 if ( ! (a->offset() == b->offset() ))
211 return false; 211 return false;
212 } 212 }
213 } 213 }
214 214
215 QStringList cat = categories(); 215 QStringList cat = categories();
216 QStringList catFrom = from->categories(); 216 QStringList catFrom = from->categories();
217 QString nCat; 217 QString nCat;
218 unsigned int iii; 218 unsigned int iii;
219 for ( iii = 0; iii < catFrom.count();++iii ) { 219 for ( iii = 0; iii < catFrom.count();++iii ) {
220 nCat = catFrom[iii]; 220 nCat = catFrom[iii];
221 if ( !nCat.isEmpty() ) 221 if ( !nCat.isEmpty() )
222 if ( !cat.contains( nCat )) { 222 if ( !cat.contains( nCat )) {
223 return false; 223 return false;
224 } 224 }
225 } 225 }
226 if ( from->isCompleted() ) { 226 if ( from->isCompleted() ) {
227 if ( !isCompleted() ) 227 if ( !isCompleted() )
228 return false; 228 return false;
229 } 229 }
230 if( priority() != from->priority() ) 230 if( priority() != from->priority() )
231 return false; 231 return false;
232 232
233 233
234 return true; 234 return true;
235 235
236} 236}
237bool KCal::operator==( const Todo& t1, const Todo& t2 ) 237bool KCal::operator==( const Todo& t1, const Todo& t2 )
238{ 238{
239 239
240 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); 240 bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
241 if ( ! ret ) 241 if ( ! ret )
242 return false; 242 return false;
243 if ( t1.hasDueDate() == t2.hasDueDate() ) { 243 if ( t1.hasDueDate() == t2.hasDueDate() ) {
244 if ( t1.hasDueDate() ) { 244 if ( t1.hasDueDate() ) {
245 if ( t1.doesFloat() == t2.doesFloat() ) { 245 if ( t1.doesFloat() == t2.doesFloat() ) {
246 if ( t1.doesFloat() ) { 246 if ( t1.doesFloat() ) {
247 if ( t1.dtDue().date() != t2.dtDue().date() ) 247 if ( t1.dtDue().date() != t2.dtDue().date() )
248 return false; 248 return false;
249 } else 249 } else
250 if ( t1.dtDue() != t2.dtDue() ) 250 if ( t1.dtDue() != t2.dtDue() )
251 return false; 251 return false;
252 } else 252 } else
253 return false;// float != 253 return false;// float !=
254 } 254 }
255 255
256 } else 256 } else
257 return false; 257 return false;
258 if ( t1.percentComplete() != t2.percentComplete() ) 258 if ( t1.percentComplete() != t2.percentComplete() )
259 return false; 259 return false;
260 if ( t1.isCompleted() ) { 260 if ( t1.isCompleted() ) {
261 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { 261 if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) {
262 if ( t1.hasCompletedDate() ) { 262 if ( t1.hasCompletedDate() ) {
263 if ( t1.completed() != t2.completed() ) 263 if ( t1.completed() != t2.completed() )
264 return false; 264 return false;
265 } 265 }
266 266
267 } else 267 } else
268 return false; 268 return false;
269 } 269 }
270 return true; 270 return true;
271 271
272} 272}
273 273
274void Todo::setDtDue(const QDateTime &dtDue) 274void Todo::setDtDue(const QDateTime &dtDue)
275{ 275{
276 //int diffsecs = mDtDue.secsTo(dtDue); 276 //int diffsecs = mDtDue.secsTo(dtDue);
277 277
278 /*if (mReadOnly) return; 278 /*if (mReadOnly) return;
279 const QPtrList<Alarm>& alarms = alarms(); 279 const QPtrList<Alarm>& alarms = alarms();
280 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { 280 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) {
281 if (alarm->enabled()) { 281 if (alarm->enabled()) {
282 alarm->setTime(alarm->time().addSecs(diffsecs)); 282 alarm->setTime(alarm->time().addSecs(diffsecs));
283 } 283 }
284 }*/ 284 }*/
285 mDtDue = getEvenTime(dtDue); 285 mDtDue = getEvenTime(dtDue);
286 286
287 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; 287 //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl;
288 288
289 /*const QPtrList<Alarm>& alarms = alarms(); 289 /*const QPtrList<Alarm>& alarms = alarms();
290 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) 290 for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next())
291 alarm->setAlarmStart(mDtDue);*/ 291 alarm->setAlarmStart(mDtDue);*/
292 updated(); 292 updated();
293} 293}
294 294
295QDateTime Todo::dtDue() const 295QDateTime Todo::dtDue() const
296{ 296{
297 return mDtDue; 297 return mDtDue;
298} 298}
299 299
300QString Todo::dtDueTimeStr() const 300QString Todo::dtDueTimeStr() const
301{ 301{
302 return KGlobal::locale()->formatTime(mDtDue.time()); 302 return KGlobal::locale()->formatTime(mDtDue.time());
303} 303}
304 304
305QString Todo::dtDueDateStr(bool shortfmt) const 305QString Todo::dtDueDateStr(bool shortfmt) const
306{ 306{
307 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 307 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
308} 308}
309 309
310QString Todo::dtDueStr(bool shortfmt) const 310QString Todo::dtDueStr(bool shortfmt) const
311{ 311{
312 if ( doesFloat() ) 312 if ( doesFloat() )
313 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 313 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
314 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 314 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
315} 315}
316// retval 0 : no found 316// retval 0 : no found
317// 1 : due for date found 317// 1 : due for date found
318// 2 : overdue for date found 318// 2 : overdue for date found
319int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 319int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
320{ 320{
321 int retval = 0; 321 int retval = 0;
322 if ( isCompleted() ) 322 if ( isCompleted() )
323 return 0; 323 return 0;
324 if ( hasDueDate() ) { 324 if ( hasDueDate() ) {
325 if ( dtDue().date() < date ) 325 if ( dtDue().date() < date )
326 return 2; 326 return 2;
327 // we do not return, because we may find an overdue sub todo 327 // we do not return, because we may find an overdue sub todo
328 if ( dtDue().date() == date ) 328 if ( dtDue().date() == date )
329 retval = 1; 329 retval = 1;
330 } 330 }
331 if ( checkSubtodos ) { 331 if ( checkSubtodos ) {
332 Incidence *aTodo; 332 Incidence *aTodo;
333 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 333 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
334 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 334 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
335 if ( ret == 2 ) 335 if ( ret == 2 )
336 return 2; 336 return 2;
337 if ( ret == 1) 337 if ( ret == 1)
338 retval = 1; 338 retval = 1;
339 } 339 }
340 } 340 }
341 return retval; 341 return retval;
342} 342}
343int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 343int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
344{ 344{
345 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 345 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
346} 346}
347bool Todo::hasDueDate() const 347bool Todo::hasDueDate() const
348{ 348{
349 return mHasDueDate; 349 return mHasDueDate;
350} 350}
351 351
352void Todo::setHasDueDate(bool f) 352void Todo::setHasDueDate(bool f)
353{ 353{
354 if (mReadOnly) return; 354 if (mReadOnly) return;
355 mHasDueDate = f; 355 mHasDueDate = f;
356 updated(); 356 updated();
357} 357}
358 358
359 359
360#if 0 360#if 0
361void Todo::setStatus(const QString &statStr) 361void Todo::setStatus(const QString &statStr)
362{ 362{
363 if (mReadOnly) return; 363 if (mReadOnly) return;
364 QString ss(statStr.upper()); 364 QString ss(statStr.upper());
365 365
366 if (ss == "X-ACTION") 366 if (ss == "X-ACTION")
367 mStatus = NEEDS_ACTION; 367 mStatus = NEEDS_ACTION;
368 else if (ss == "NEEDS ACTION") 368 else if (ss == "NEEDS ACTION")
369 mStatus = NEEDS_ACTION; 369 mStatus = NEEDS_ACTION;
370 else if (ss == "ACCEPTED") 370 else if (ss == "ACCEPTED")
371 mStatus = ACCEPTED; 371 mStatus = ACCEPTED;
372 else if (ss == "SENT") 372 else if (ss == "SENT")
373 mStatus = SENT; 373 mStatus = SENT;
374 else if (ss == "TENTATIVE") 374 else if (ss == "TENTATIVE")
375 mStatus = TENTATIVE; 375 mStatus = TENTATIVE;
376 else if (ss == "CONFIRMED") 376 else if (ss == "CONFIRMED")
377 mStatus = CONFIRMED; 377 mStatus = CONFIRMED;
378 else if (ss == "DECLINED") 378 else if (ss == "DECLINED")
379 mStatus = DECLINED; 379 mStatus = DECLINED;
380 else if (ss == "COMPLETED") 380 else if (ss == "COMPLETED")
381 mStatus = COMPLETED; 381 mStatus = COMPLETED;
382 else if (ss == "DELEGATED") 382 else if (ss == "DELEGATED")
383 mStatus = DELEGATED; 383 mStatus = DELEGATED;
384 384
385 updated(); 385 updated();
386} 386}
387 387
388void Todo::setStatus(int status) 388void Todo::setStatus(int status)
389{ 389{
390 if (mReadOnly) return; 390 if (mReadOnly) return;
391 mStatus = status; 391 mStatus = status;
392 updated(); 392 updated();
393} 393}
394 394
395int Todo::status() const 395int Todo::status() const
396{ 396{
397 return mStatus; 397 return mStatus;
398} 398}
399 399
400QString Todo::statusStr() const 400QString Todo::statusStr() const
401{ 401{
402 switch(mStatus) { 402 switch(mStatus) {
403 case NEEDS_ACTION: 403 case NEEDS_ACTION:
404 return QString("NEEDS ACTION"); 404 return QString("NEEDS ACTION");
405 break; 405 break;
406 case ACCEPTED: 406 case ACCEPTED:
407 return QString("ACCEPTED"); 407 return QString("ACCEPTED");
408 break; 408 break;
409 case SENT: 409 case SENT:
410 return QString("SENT"); 410 return QString("SENT");
411 break; 411 break;
412 case TENTATIVE: 412 case TENTATIVE:
413 return QString("TENTATIVE"); 413 return QString("TENTATIVE");
414 break; 414 break;
415 case CONFIRMED: 415 case CONFIRMED:
416 return QString("CONFIRMED"); 416 return QString("CONFIRMED");
417 break; 417 break;
418 case DECLINED: 418 case DECLINED:
419 return QString("DECLINED"); 419 return QString("DECLINED");
420 break; 420 break;
421 case COMPLETED: 421 case COMPLETED:
422 return QString("COMPLETED"); 422 return QString("COMPLETED");
423 break; 423 break;
424 case DELEGATED: 424 case DELEGATED:
425 return QString("DELEGATED"); 425 return QString("DELEGATED");
426 break; 426 break;
427 } 427 }
428 return QString(""); 428 return QString("");
429} 429}
430#endif 430#endif
431 431
432bool Todo::isCompleted() const 432bool Todo::isCompleted() const
433{ 433{
434 if (mPercentComplete == 100) { 434 if (mPercentComplete == 100) {
435 return true; 435 return true;
436 } 436 }
437 else return false; 437 else return false;
438} 438}
439 439
440void Todo::setCompleted(bool completed) 440void Todo::setCompleted(bool completed)
441{ 441{
442 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 442 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
443 if ( !setRecurDates() ) 443 if ( !setRecurDates() )
444 completed = false; 444 completed = false;
445 } 445 }
446 if (completed) mPercentComplete = 100; 446 if (completed) mPercentComplete = 100;
447 else { 447 else {
448 mPercentComplete = 0; 448 mPercentComplete = 0;
449 mHasCompletedDate = false; 449 mHasCompletedDate = false;
450 } 450 }
451 updated(); 451 updated();
452} 452}
453 453
454QDateTime Todo::completed() const 454QDateTime Todo::completed() const
455{ 455{
456 return mCompleted; 456 return mCompleted;
457} 457}
458 458
459QString Todo::completedStr( bool shortF ) const 459QString Todo::completedStr( bool shortF ) const
460{ 460{
461 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 461 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
462} 462}
463 463
464void Todo::setCompleted(const QDateTime &completed) 464void Todo::setCompleted(const QDateTime &completed)
465{ 465{
466 //qDebug("Todo::setCompleted "); 466 //qDebug("Todo::setCompleted ");
467 if ( mHasCompletedDate ) { 467 if ( mHasCompletedDate ) {
468 // qDebug("has completed data - return "); 468 // qDebug("has completed data - return ");
469 return; 469 return;
470 } 470 }
471 mHasCompletedDate = true; 471 mHasCompletedDate = true;
472 mPercentComplete = 100; 472 mPercentComplete = 100;
473 mCompleted = getEvenTime(completed); 473 mCompleted = getEvenTime(completed);
474 updated(); 474 updated();
475} 475}
476 476
477bool Todo::hasCompletedDate() const 477bool Todo::hasCompletedDate() const
478{ 478{
479 return mHasCompletedDate; 479 return mHasCompletedDate;
480} 480}
481 481
482int Todo::percentComplete() const 482int Todo::percentComplete() const
483{ 483{
484 return mPercentComplete; 484 return mPercentComplete;
485} 485}
486bool Todo::setRecurDates() 486bool Todo::setRecurDates()
487{ 487{
488 if ( !mHasRecurrenceID ) 488 if ( !mHasRecurrenceID )
489 return true; 489 return true;
490 int secs = mDtStart.secsTo( dtDue() ); 490 int secs = mDtStart.secsTo( dtDue() );
491 bool ok; 491 bool ok;
492 qDebug("T:setRecurDates() "); 492 qDebug("T:setRecurDates() ");
493 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 493 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
494 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 494 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
495 if ( ok ) { 495 if ( ok ) {
496 mRecurrenceID = next; 496 mRecurrenceID = next;
497 mDtStart = next; 497 mDtStart = next;
498 setDtDue( next.addSecs( secs ) ); 498 setDtDue( next.addSecs( secs ) );
499 if ( QDateTime::currentDateTime() > next) 499 if ( QDateTime::currentDateTime() > next)
500 return false; 500 return false;
501 } else { 501 } else {
502 setHasRecurrenceID( false ); 502 setHasRecurrenceID( false );
503 recurrence()->unsetRecurs(); 503 recurrence()->unsetRecurs();
504 } 504 }
505 return true; 505 return true;
506} 506}
507void Todo::setPercentComplete(int v) 507void Todo::setPercentComplete(int v)
508{ 508{
509 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 509 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
510 if ( !setRecurDates() ) 510 if ( !setRecurDates() )
511 v = 0; 511 v = 0;
512 } 512 }
513 mPercentComplete = v; 513 mPercentComplete = v;
514 if ( v != 100 ) 514 if ( v != 100 )
515 mHasCompletedDate = false; 515 mHasCompletedDate = false;
516 updated(); 516 updated();
517} 517}
518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 518QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
519{ 519{
520 if ( isCompleted() || ! hasDueDate() || cancelled() ) { 520 if ( isCompleted() || ! hasDueDate() || cancelled() ) {
521 *ok = false; 521 *ok = false;
522 return QDateTime (); 522 return QDateTime ();
523 } 523 }
524 QDateTime incidenceStart; 524 QDateTime incidenceStart;
525 incidenceStart = dtDue(); 525 incidenceStart = dtDue();
526 bool enabled = false; 526 bool enabled = false;
527 Alarm* alarm; 527 Alarm* alarm;
528 int off = 0; 528 int off = 0;
529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 529 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
530 // if ( QDateTime::currentDateTime() > incidenceStart ){ 530 // if ( QDateTime::currentDateTime() > incidenceStart ){
531// *ok = false; 531// *ok = false;
532// return incidenceStart; 532// return incidenceStart;
533// } 533// }
534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 534 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
535 if (alarm->enabled()) { 535 if (alarm->enabled()) {
536 if ( alarm->hasTime () ) { 536 if ( alarm->hasTime () ) {
537 if ( alarm->time() < alarmStart ) { 537 if ( alarm->time() < alarmStart ) {
538 alarmStart = alarm->time(); 538 alarmStart = alarm->time();
539 enabled = true; 539 enabled = true;
540 off = alarmStart.secsTo( incidenceStart ); 540 off = alarmStart.secsTo( incidenceStart );
541 } 541 }
542 542
543 } else { 543 } else {
544 int secs = alarm->startOffset().asSeconds(); 544 int secs = alarm->startOffset().asSeconds();
545 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 545 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
546 alarmStart = incidenceStart.addSecs( secs ); 546 alarmStart = incidenceStart.addSecs( secs );
547 enabled = true; 547 enabled = true;
548 off = -secs; 548 off = -secs;
549 } 549 }
550 } 550 }
551 } 551 }
552 } 552 }
553 if ( enabled ) { 553 if ( enabled ) {
554 if ( alarmStart > start_dt ) { 554 if ( alarmStart > start_dt ) {
555 *ok = true; 555 *ok = true;
556 * offset = off; 556 * offset = off;
557 return alarmStart; 557 return alarmStart;
558 } 558 }
559 } 559 }
560 *ok = false; 560 *ok = false;
561 return QDateTime (); 561 return QDateTime ();
562 562
563} 563}
564 564
565void Todo::checkSetCompletedFalse() 565void Todo::checkSetCompletedFalse()
566{ 566{
567 if ( !hasRecurrenceID() ) { 567 if ( !hasRecurrenceID() ) {
568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 568 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
569 } 569 }
570 // qDebug("Todo::checkSetCompletedFalse()"); 570 // qDebug("Todo::checkSetCompletedFalse()");
571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 571 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
572 if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { 572 if ( mPercentComplete == 100 ) {
573 qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 573 QDateTime dt = QDateTime::currentDateTime();
574 setCompleted( false ); 574 if ( dt > mDtStart && dt > mRecurrenceID ) {
575 qDebug("Todo::checkSetCompletedFalse "); 575 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
576 setCompleted( false );
577 qDebug("Todo::checkSetCompletedFalse ");
578 }
576 } 579 }
577} 580}