-rw-r--r-- | libkcal/todo.cpp | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 9c04a7e..1f54c2f 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -302,30 +302,36 @@ QString Todo::statusStr() const return QString("COMPLETED"); break; case DELEGATED: return QString("DELEGATED"); break; } return QString(""); } #endif bool Todo::isCompleted() const { - if (mPercentComplete == 100) return true; - else return false; + if (mPercentComplete == 100) { + return true; + } + else return false; } void Todo::setCompleted(bool completed) { + if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + completed = false; + } if (completed) mPercentComplete = 100; else { mPercentComplete = 0; mHasCompletedDate = false; } updated(); } QDateTime Todo::completed() const { return mCompleted; } @@ -348,27 +354,51 @@ void Todo::setCompleted(const QDateTime &completed) updated(); } bool Todo::hasCompletedDate() const { return mHasCompletedDate; } int Todo::percentComplete() const { return mPercentComplete; } - -void Todo::setPercentComplete(int v) +bool Todo::setRecurDates() { + if ( !mHasRecurrenceID ) + return true; + int secs = mDtStart.secsTo( dtDue() ); + bool ok; + qDebug("--------------------setRecurDates() "); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + QDateTime next = getNextOccurence( mRecurrenceID, &ok ); + if ( ok ) { + mRecurrenceID = next; + mDtStart = next; + setDtDue( next.addSecs( secs ) ); + if ( QDateTime::currentDateTime() > next) + return false; + } else { + setHasRecurrenceID( false ); + recurrence()->unsetRecurs(); + } + return true; +} +void Todo::setPercentComplete(int v) +{ + if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { + if ( !setRecurDates() ) + v = 0; + } mPercentComplete = v; if ( v != 100 ) mHasCompletedDate = false; updated(); } QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const { if ( isCompleted() || ! hasDueDate() || cancelled() ) { *ok = false; return QDateTime (); } QDateTime incidenceStart; @@ -403,12 +433,25 @@ QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const if ( enabled ) { if ( alarmStart > QDateTime::currentDateTime() ) { *ok = true; * offset = off; return alarmStart; } } *ok = false; return QDateTime (); } +void Todo::checkSetCompletedFalse() +{ + if ( !hasRecurrenceID() ) { + qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); + } + // qDebug("Todo::checkSetCompletedFalse()"); + //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { + qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); + setCompleted( false ); + qDebug("Todo::checkSetCompletedFalse++++++++++++++++++++++++++++ "); + } +} |