-rw-r--r-- | libkcal/todo.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index de07496..f7d40ad 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp @@ -52,129 +52,141 @@ Todo::Todo(): QObject(), Incidence() Todo::Todo(const Todo &t) : QObject(),Incidence(t) { mDtDue = t.mDtDue; mHasDueDate = t.mHasDueDate; mCompleted = t.mCompleted; mHasCompletedDate = t.mHasCompletedDate; mPercentComplete = t.mPercentComplete; mRunning = false; mRunSaveTimer = 0; mCurrentTimerDelay = 0; } Todo::~Todo() { setRunning( false ); //qDebug("Todo::~Todo() "); } void Todo::setRunningFalse( QString s ) { if ( ! mRunning ) return; mRunning = false; if ( mRunSaveTimer ) mRunSaveTimer->stop(); saveRunningInfoToFile( s ); } void Todo::stopRunning() { if ( !mRunning ) return; if ( mRunSaveTimer ) mRunSaveTimer->stop(); mRunning = false; } void Todo::setRunning( bool run ) { if ( run == mRunning ) return; //qDebug("Todo::setRunning %d ", run); if ( !mRunSaveTimer ) { mRunSaveTimer = new QTimer ( this ); connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); } mRunning = run; mRunLastSave = QDateTime::currentDateTime(); if ( mRunning ) { - mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min + restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); mRunStart = QDateTime::currentDateTime(); - mRunLastSave = QDateTime::currentDateTime(); - mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; } else { mRunSaveTimer->stop(); saveRunningInfoToFile(); } } void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) { if ( !mRunning) return; mRunning = false; mRunStart = start; mRunEnd = end; saveRunningInfoToFile( comment ); } +void Todo::restartSaveTimer( int secs ) +{ + mRunSaveTimer->start( secs * 1000 ); + mRunLastSave = QDateTime::currentDateTime(); + mCurrentTimerDelay = secs; +} void Todo::timerSlotSaveRunningInfoToFile() { mRunEnd = QDateTime::currentDateTime(); int secsTo = mRunLastSave.secsTo( mRunEnd ); - if( secsTo == 8 ) ++secsTo; + //if( secsTo == 8 ) ++secsTo; qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); if ( secsTo > mCurrentTimerDelay ) { - qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); - mRunSaveTimer->start( SAVETIMER_TIMEOUT_RETRY_SECONDS * 1000 ); - mRunLastSave = QDateTime::currentDateTime(); - mCurrentTimerDelay = SAVETIMER_TIMEOUT_RETRY_SECONDS; + qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); + restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); return; } - mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min - mRunLastSave = QDateTime::currentDateTime(); - mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; + int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); + if ( msecs < 0 ) { + restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); + return; + } + // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); + if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { + qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); + restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); + return; + + } + restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); saveRunningInfoToFile( QString::null ); } void Todo::saveRunningInfoToFile() { mRunEnd = QDateTime::currentDateTime(); saveRunningInfoToFile( QString::null ); } void Todo::saveRunningInfoToFile( QString comment ) { //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); if ( mRunStart.secsTo ( mRunEnd) < 15 ) { qDebug("Running time < 15 seconds. Skipped. "); return; } QString dir = KGlobalSettings::timeTrackerDir(); //qDebug("%s ", dir.latin1()); QString file = "%1%2%3-%4%5%6-"; 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 ); file.replace ( QRegExp (" "), "0" ); file += uid(); //qDebug("File %s ",file.latin1() ); CalendarLocal cal; cal.setLocalTime(); Todo * to = (Todo*) clone(); to->setFloats( false ); to->setDtStart( mRunStart ); to->setHasStartDate( true ); to->setDtDue( mRunEnd ); to->setHasDueDate( true ); to->setUid( file ); if ( !comment.isEmpty() ) { QString des = to->description(); if ( des.isEmpty () ) to->setDescription( "TT-Note: " + comment ); else to->setDescription( "TT-Note: " + comment +"\n" + des ); } cal.addIncidence( to ); ICalFormat format( false ); file = dir +"/" +file +".ics"; format.save( &cal, file ); saveParents(); } void Todo::saveParents() { if (!relatedTo() ) return; |