-rw-r--r-- | libkcal/todo.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 7bf756a..e4508a0 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -521,96 +521,106 @@ bool Todo::setRecurDates() | |||
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 | } |
528 | void Todo::setPercentComplete(int v) | 528 | void 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 | } |
539 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 539 | QDateTime 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 | ||
600 | void Todo::checkSetCompletedFalse() | 600 | void 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 | } |
617 | QString 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 | } | ||