summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index cc1c5ae..5a0c32e 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -370,314 +370,314 @@ void Todo::setDtDue(const QDateTime &dtDue)
370 updated(); 370 updated();
371} 371}
372 372
373QDateTime Todo::dtDue() const 373QDateTime Todo::dtDue() const
374{ 374{
375 return mDtDue; 375 return mDtDue;
376} 376}
377 377
378QString Todo::dtDueTimeStr() const 378QString Todo::dtDueTimeStr() const
379{ 379{
380 return KGlobal::locale()->formatTime(mDtDue.time()); 380 return KGlobal::locale()->formatTime(mDtDue.time());
381} 381}
382 382
383QString Todo::dtDueDateStr(bool shortfmt) const 383QString Todo::dtDueDateStr(bool shortfmt) const
384{ 384{
385 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 385 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
386} 386}
387 387
388QString Todo::dtDueStr(bool shortfmt) const 388QString Todo::dtDueStr(bool shortfmt) const
389{ 389{
390 if ( doesFloat() ) 390 if ( doesFloat() )
391 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); 391 return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt);
392 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); 392 return KGlobal::locale()->formatDateTime(mDtDue, shortfmt);
393} 393}
394// retval 0 : no found 394// retval 0 : no found
395// 1 : due for date found 395// 1 : due for date found
396// 2 : overdue for date found 396// 2 : overdue for date found
397int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) 397int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos )
398{ 398{
399 int retval = 0; 399 int retval = 0;
400 if ( isCompleted() ) 400 if ( isCompleted() )
401 return 0; 401 return 0;
402 if ( hasDueDate() ) { 402 if ( hasDueDate() ) {
403 if ( dtDue().date() < date ) 403 if ( dtDue().date() < date )
404 return 2; 404 return 2;
405 // we do not return, because we may find an overdue sub todo 405 // we do not return, because we may find an overdue sub todo
406 if ( dtDue().date() == date ) 406 if ( dtDue().date() == date )
407 retval = 1; 407 retval = 1;
408 } 408 }
409 if ( checkSubtodos ) { 409 if ( checkSubtodos ) {
410 Incidence *aTodo; 410 Incidence *aTodo;
411 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { 411 for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) {
412 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); 412 int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos );
413 if ( ret == 2 ) 413 if ( ret == 2 )
414 return 2; 414 return 2;
415 if ( ret == 1) 415 if ( ret == 1)
416 retval = 1; 416 retval = 1;
417 } 417 }
418 } 418 }
419 return retval; 419 return retval;
420} 420}
421int Todo::hasDueSubTodo( bool checkSubtodos ) //= true 421int Todo::hasDueSubTodo( bool checkSubtodos ) //= true
422{ 422{
423 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); 423 return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos );
424} 424}
425bool Todo::hasDueDate() const 425bool Todo::hasDueDate() const
426{ 426{
427 return mHasDueDate; 427 return mHasDueDate;
428} 428}
429 429
430void Todo::setHasDueDate(bool f) 430void Todo::setHasDueDate(bool f)
431{ 431{
432 if (mReadOnly) return; 432 if (mReadOnly) return;
433 mHasDueDate = f; 433 mHasDueDate = f;
434 updated(); 434 updated();
435} 435}
436 436
437 437
438#if 0 438#if 0
439void Todo::setStatus(const QString &statStr) 439void Todo::setStatus(const QString &statStr)
440{ 440{
441 if (mReadOnly) return; 441 if (mReadOnly) return;
442 QString ss(statStr.upper()); 442 QString ss(statStr.upper());
443 443
444 if (ss == "X-ACTION") 444 if (ss == "X-ACTION")
445 mStatus = NEEDS_ACTION; 445 mStatus = NEEDS_ACTION;
446 else if (ss == "NEEDS ACTION") 446 else if (ss == "NEEDS ACTION")
447 mStatus = NEEDS_ACTION; 447 mStatus = NEEDS_ACTION;
448 else if (ss == "ACCEPTED") 448 else if (ss == "ACCEPTED")
449 mStatus = ACCEPTED; 449 mStatus = ACCEPTED;
450 else if (ss == "SENT") 450 else if (ss == "SENT")
451 mStatus = SENT; 451 mStatus = SENT;
452 else if (ss == "TENTATIVE") 452 else if (ss == "TENTATIVE")
453 mStatus = TENTATIVE; 453 mStatus = TENTATIVE;
454 else if (ss == "CONFIRMED") 454 else if (ss == "CONFIRMED")
455 mStatus = CONFIRMED; 455 mStatus = CONFIRMED;
456 else if (ss == "DECLINED") 456 else if (ss == "DECLINED")
457 mStatus = DECLINED; 457 mStatus = DECLINED;
458 else if (ss == "COMPLETED") 458 else if (ss == "COMPLETED")
459 mStatus = COMPLETED; 459 mStatus = COMPLETED;
460 else if (ss == "DELEGATED") 460 else if (ss == "DELEGATED")
461 mStatus = DELEGATED; 461 mStatus = DELEGATED;
462 462
463 updated(); 463 updated();
464} 464}
465 465
466void Todo::setStatus(int status) 466void Todo::setStatus(int status)
467{ 467{
468 if (mReadOnly) return; 468 if (mReadOnly) return;
469 mStatus = status; 469 mStatus = status;
470 updated(); 470 updated();
471} 471}
472 472
473int Todo::status() const 473int Todo::status() const
474{ 474{
475 return mStatus; 475 return mStatus;
476} 476}
477 477
478QString Todo::statusStr() const 478QString Todo::statusStr() const
479{ 479{
480 switch(mStatus) { 480 switch(mStatus) {
481 case NEEDS_ACTION: 481 case NEEDS_ACTION:
482 return QString("NEEDS ACTION"); 482 return QString("NEEDS ACTION");
483 break; 483 break;
484 case ACCEPTED: 484 case ACCEPTED:
485 return QString("ACCEPTED"); 485 return QString("ACCEPTED");
486 break; 486 break;
487 case SENT: 487 case SENT:
488 return QString("SENT"); 488 return QString("SENT");
489 break; 489 break;
490 case TENTATIVE: 490 case TENTATIVE:
491 return QString("TENTATIVE"); 491 return QString("TENTATIVE");
492 break; 492 break;
493 case CONFIRMED: 493 case CONFIRMED:
494 return QString("CONFIRMED"); 494 return QString("CONFIRMED");
495 break; 495 break;
496 case DECLINED: 496 case DECLINED:
497 return QString("DECLINED"); 497 return QString("DECLINED");
498 break; 498 break;
499 case COMPLETED: 499 case COMPLETED:
500 return QString("COMPLETED"); 500 return QString("COMPLETED");
501 break; 501 break;
502 case DELEGATED: 502 case DELEGATED:
503 return QString("DELEGATED"); 503 return QString("DELEGATED");
504 break; 504 break;
505 } 505 }
506 return QString(""); 506 return QString("");
507} 507}
508#endif 508#endif
509 509
510bool Todo::isCompleted() const 510bool Todo::isCompleted() const
511{ 511{
512 if (mPercentComplete == 100) { 512 if (mPercentComplete == 100) {
513 return true; 513 return true;
514 } 514 }
515 else return false; 515 else return false;
516} 516}
517 517
518void Todo::setCompleted(bool completed) 518void Todo::setCompleted(bool completed)
519{ 519{
520 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { 520 if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) {
521 if ( !setRecurDates() ) 521 if ( !setRecurDates() )
522 completed = false; 522 completed = false;
523 } 523 }
524 if (completed) mPercentComplete = 100; 524 if (completed) mPercentComplete = 100;
525 else { 525 else {
526 mPercentComplete = 0; 526 mPercentComplete = 0;
527 mHasCompletedDate = false; 527 mHasCompletedDate = false;
528 } 528 }
529 updated(); 529 updated();
530} 530}
531 531
532QDateTime Todo::completed() const 532QDateTime Todo::completed() const
533{ 533{
534 return mCompleted; 534 return mCompleted;
535} 535}
536 536
537QString Todo::completedStr( bool shortF ) const 537QString Todo::completedStr( bool shortF ) const
538{ 538{
539 return KGlobal::locale()->formatDateTime(mCompleted, shortF); 539 return KGlobal::locale()->formatDateTime(mCompleted, shortF);
540} 540}
541 541
542void Todo::setCompleted(const QDateTime &completed) 542void Todo::setCompleted(const QDateTime &completed)
543{ 543{
544 //qDebug("Todo::setCompleted "); 544 //qDebug("Todo::setCompleted ");
545 if ( mHasCompletedDate ) { 545 if ( mHasCompletedDate ) {
546 // qDebug("has completed data - return "); 546 // qDebug("has completed data - return ");
547 return; 547 return;
548 } 548 }
549 mHasCompletedDate = true; 549 mHasCompletedDate = true;
550 mPercentComplete = 100; 550 mPercentComplete = 100;
551 mCompleted = getEvenTime(completed); 551 mCompleted = getEvenTime(completed);
552 updated(); 552 updated();
553} 553}
554 554
555bool Todo::hasCompletedDate() const 555bool Todo::hasCompletedDate() const
556{ 556{
557 return mHasCompletedDate; 557 return mHasCompletedDate;
558} 558}
559 559
560int Todo::percentComplete() const 560int Todo::percentComplete() const
561{ 561{
562 return mPercentComplete; 562 return mPercentComplete;
563} 563}
564bool Todo::setRecurDates() 564bool Todo::setRecurDates()
565{ 565{
566 if ( !mHasRecurrenceID ) 566 if ( !mHasRecurrenceID )
567 return true; 567 return true;
568 int secs = mDtStart.secsTo( dtDue() ); 568 int secs = mDtStart.secsTo( dtDue() );
569 bool ok; 569 bool ok;
570 qDebug("T:setRecurDates() "); 570 qDebug("T:setRecurDates() ");
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 QDateTime next = getNextOccurence( mRecurrenceID, &ok ); 572 QDateTime next = getNextOccurence( mRecurrenceID, &ok );
573 if ( ok ) { 573 if ( ok ) {
574 mRecurrenceID = next; 574 mRecurrenceID = next;
575 mDtStart = next; 575 mDtStart = next;
576 setDtDue( next.addSecs( secs ) ); 576 setDtDue( next.addSecs( secs ) );
577 if ( QDateTime::currentDateTime() > next) 577 if ( QDateTime::currentDateTime() > next)
578 return false; 578 return false;
579 } else { 579 } else {
580 setHasRecurrenceID( false ); 580 setHasRecurrenceID( false );
581 recurrence()->unsetRecurs(); 581 recurrence()->unsetRecurs();
582 } 582 }
583 return true; 583 return true;
584} 584}
585void Todo::setPercentComplete(int v) 585void Todo::setPercentComplete(int v)
586{ 586{
587 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { 587 if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) {
588 if ( !setRecurDates() ) 588 if ( !setRecurDates() )
589 v = 0; 589 v = 0;
590 } 590 }
591 mPercentComplete = v; 591 mPercentComplete = v;
592 if ( v != 100 ) 592 if ( v != 100 )
593 mHasCompletedDate = false; 593 mHasCompletedDate = false;
594 updated(); 594 updated();
595} 595}
596QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const 596QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const
597{ 597{
598 *ok = false; 598 *ok = false;
599 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) { 599 if ( ! hasDueDate() || cancelled() || !alarmEnabled() ) {
600 return QDateTime (); 600 return QDateTime ();
601 } 601 }
602 // if the recurring todo is set to complete and requested time < start time of todo 602 // if the recurring todo is set to complete and requested time < start time of todo
603 // we want to get the alarm. 603 // we want to get the alarm.
604 bool iscompleted = isCompleted(); 604 bool iscompleted = isCompleted();
605 if ( iscompleted && doesRecur() ) { 605 if ( iscompleted && doesRecur() ) {
606 Todo * to = (Todo*) this; 606 Todo * to = (Todo*) this;
607 to->checkSetCompletedFalse(); 607 to->checkSetCompletedFalse();
608 iscompleted = isCompleted(); 608 iscompleted = isCompleted();
609 if ( hasStartDate() && start_dt < dtStart() ){ 609 if ( hasStartDate() && start_dt < dtStart() ){
610 iscompleted = false; 610 iscompleted = false;
611 } 611 }
612 } 612 }
613 if ( iscompleted ) { 613 if ( iscompleted ) {
614 return QDateTime (); 614 return QDateTime ();
615 } 615 }
616 QDateTime incidenceStart; 616 QDateTime incidenceStart;
617 incidenceStart = dtDue(); 617 incidenceStart = dtDue();
618 bool enabled = false; 618 bool enabled = false;
619 Alarm* alarm; 619 Alarm* alarm;
620 int off = 0; 620 int off = 0;
621 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; 621 QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );;
622 // if ( QDateTime::currentDateTime() > incidenceStart ){ 622 // if ( QDateTime::currentDateTime() > incidenceStart ){
623// *ok = false; 623// *ok = false;
624// return incidenceStart; 624// return incidenceStart;
625// } 625// }
626 for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { 626 for (Q3PtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) {
627 if (alarm->enabled()) { 627 if (alarm->enabled()) {
628 if ( alarm->hasTime () ) { 628 if ( alarm->hasTime () ) {
629 if ( alarm->time() < alarmStart ) { 629 if ( alarm->time() < alarmStart ) {
630 alarmStart = alarm->time(); 630 alarmStart = alarm->time();
631 enabled = true; 631 enabled = true;
632 off = alarmStart.secsTo( incidenceStart ); 632 off = alarmStart.secsTo( incidenceStart );
633 } 633 }
634 634
635 } else { 635 } else {
636 int secs = alarm->startOffset().asSeconds(); 636 int secs = alarm->startOffset().asSeconds();
637 if ( incidenceStart.addSecs( secs ) < alarmStart ) { 637 if ( incidenceStart.addSecs( secs ) < alarmStart ) {
638 alarmStart = incidenceStart.addSecs( secs ); 638 alarmStart = incidenceStart.addSecs( secs );
639 enabled = true; 639 enabled = true;
640 off = -secs; 640 off = -secs;
641 } 641 }
642 } 642 }
643 } 643 }
644 } 644 }
645 if ( enabled ) { 645 if ( enabled ) {
646 if ( alarmStart > start_dt ) { 646 if ( alarmStart > start_dt ) {
647 *ok = true; 647 *ok = true;
648 * offset = off; 648 * offset = off;
649 return alarmStart; 649 return alarmStart;
650 } 650 }
651 } 651 }
652 *ok = false; 652 *ok = false;
653 return QDateTime (); 653 return QDateTime ();
654 654
655} 655}
656 656
657void Todo::checkSetCompletedFalse() 657void Todo::checkSetCompletedFalse()
658{ 658{
659 if ( !mHasRecurrenceID ) { 659 if ( !mHasRecurrenceID ) {
660 qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); 660 qDebug("ERROR 1 in Todo::checkSetCompletedFalse");
661 return; 661 return;
662 } 662 }
663 // qDebug("Todo::checkSetCompletedFalse()"); 663 // qDebug("Todo::checkSetCompletedFalse()");
664 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 664 //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
665 if ( mPercentComplete == 100 ) { 665 if ( mPercentComplete == 100 ) {
666 QDateTime dt = QDateTime::currentDateTime(); 666 QDateTime dt = QDateTime::currentDateTime();
667 if ( dt > mDtStart && dt > mRecurrenceID ) { 667 if ( dt > mDtStart && dt > mRecurrenceID ) {
668 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); 668 qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() );
669 setCompleted( false ); 669 setCompleted( false );
670 qDebug("Todo::checkSetCompletedFalse "); 670 qDebug("Todo::checkSetCompletedFalse ");
671 } 671 }
672 } 672 }
673} 673}
674QString Todo::durationText() 674QString Todo::durationText()
675{ 675{
676 if ( mHasDueDate && hasStartDate() ) { 676 if ( mHasDueDate && hasStartDate() ) {
677 int sec = dtStart().secsTo( dtDue() ); 677 int sec = dtStart().secsTo( dtDue() );
678 if ( doesFloat() ) 678 if ( doesFloat() )
679 sec += 86400; 679 sec += 86400;
680 return durationText4Time( sec ); 680 return durationText4Time( sec );
681 } 681 }
682 return "---"; 682 return "---";
683} 683}