summaryrefslogtreecommitdiffabout
path: root/libkcal/todo.cpp
Unidiff
Diffstat (limited to 'libkcal/todo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/todo.cpp31
1 files changed, 29 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 48d37d5..de07496 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -20,49 +20,55 @@
20 20
21#include <kglobal.h> 21#include <kglobal.h>
22#include <kglobalsettings.h> 22#include <kglobalsettings.h>
23#include <klocale.h> 23#include <klocale.h>
24#include <kdebug.h> 24#include <kdebug.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28#include "calendarlocal.h" 28#include "calendarlocal.h"
29#include "icalformat.h" 29#include "icalformat.h"
30#include "todo.h" 30#include "todo.h"
31 31
32#define SAVETIMER_TIMEOUT_SECONDS 300
33//#define SAVETIMER_TIMEOUT_SECONDS 8
34#define SAVETIMER_TIMEOUT_RETRY_SECONDS 5
35
32using namespace KCal; 36using namespace KCal;
33 37
34Todo::Todo(): QObject(), Incidence() 38Todo::Todo(): QObject(), Incidence()
35{ 39{
36// mStatus = TENTATIVE; 40// mStatus = TENTATIVE;
37 41
38 mHasDueDate = false; 42 mHasDueDate = false;
39 setHasStartDate( false ); 43 setHasStartDate( false );
40 mCompleted = getEvenTime(QDateTime::currentDateTime()); 44 mCompleted = getEvenTime(QDateTime::currentDateTime());
41 mHasCompletedDate = false; 45 mHasCompletedDate = false;
42 mPercentComplete = 0; 46 mPercentComplete = 0;
43 mRunning = false; 47 mRunning = false;
44 mRunSaveTimer = 0; 48 mRunSaveTimer = 0;
45 setFloats( true ); 49 setFloats( true );
50 mCurrentTimerDelay = 0;
46} 51}
47 52
48Todo::Todo(const Todo &t) : QObject(),Incidence(t) 53Todo::Todo(const Todo &t) : QObject(),Incidence(t)
49{ 54{
50 mDtDue = t.mDtDue; 55 mDtDue = t.mDtDue;
51 mHasDueDate = t.mHasDueDate; 56 mHasDueDate = t.mHasDueDate;
52 mCompleted = t.mCompleted; 57 mCompleted = t.mCompleted;
53 mHasCompletedDate = t.mHasCompletedDate; 58 mHasCompletedDate = t.mHasCompletedDate;
54 mPercentComplete = t.mPercentComplete; 59 mPercentComplete = t.mPercentComplete;
55 mRunning = false; 60 mRunning = false;
56 mRunSaveTimer = 0; 61 mRunSaveTimer = 0;
62 mCurrentTimerDelay = 0;
57} 63}
58 64
59Todo::~Todo() 65Todo::~Todo()
60{ 66{
61 setRunning( false ); 67 setRunning( false );
62 //qDebug("Todo::~Todo() "); 68 //qDebug("Todo::~Todo() ");
63} 69}
64 70
65void Todo::setRunningFalse( QString s ) 71void Todo::setRunningFalse( QString s )
66{ 72{
67 if ( ! mRunning ) 73 if ( ! mRunning )
68 return; 74 return;
@@ -77,43 +83,64 @@ void Todo::stopRunning()
77 return; 83 return;
78 if ( mRunSaveTimer ) 84 if ( mRunSaveTimer )
79 mRunSaveTimer->stop(); 85 mRunSaveTimer->stop();
80 mRunning = false; 86 mRunning = false;
81} 87}
82void Todo::setRunning( bool run ) 88void Todo::setRunning( bool run )
83{ 89{
84 if ( run == mRunning ) 90 if ( run == mRunning )
85 return; 91 return;
86 //qDebug("Todo::setRunning %d ", run); 92 //qDebug("Todo::setRunning %d ", run);
87 if ( !mRunSaveTimer ) { 93 if ( !mRunSaveTimer ) {
88 mRunSaveTimer = new QTimer ( this ); 94 mRunSaveTimer = new QTimer ( this );
89 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); 95 connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) );
90 } 96 }
91 mRunning = run; 97 mRunning = run;
98 mRunLastSave = QDateTime::currentDateTime();
92 if ( mRunning ) { 99 if ( mRunning ) {
93 mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min 100 mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min
94 mRunStart = QDateTime::currentDateTime(); 101 mRunStart = QDateTime::currentDateTime();
102 mRunLastSave = QDateTime::currentDateTime();
103 mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS;
95 } else { 104 } else {
96 mRunSaveTimer->stop(); 105 mRunSaveTimer->stop();
97 saveRunningInfoToFile(); 106 saveRunningInfoToFile();
98 } 107 }
99} 108}
100void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) 109void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end )
101{ 110{
102 if ( !mRunning) return; 111 if ( !mRunning) return;
103 mRunning = false; 112 mRunning = false;
104 mRunStart = start; 113 mRunStart = start;
105 mRunEnd = end; 114 mRunEnd = end;
106 saveRunningInfoToFile( comment ); 115 saveRunningInfoToFile( comment );
107} 116}
117void Todo::timerSlotSaveRunningInfoToFile()
118{
119 mRunEnd = QDateTime::currentDateTime();
120 int secsTo = mRunLastSave.secsTo( mRunEnd );
121 if( secsTo == 8 ) ++secsTo;
122 qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay );
123 if ( secsTo > mCurrentTimerDelay ) {
124 qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS );
125 mRunSaveTimer->start( SAVETIMER_TIMEOUT_RETRY_SECONDS * 1000 );
126 mRunLastSave = QDateTime::currentDateTime();
127 mCurrentTimerDelay = SAVETIMER_TIMEOUT_RETRY_SECONDS;
128 return;
129 }
130 mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min
131 mRunLastSave = QDateTime::currentDateTime();
132 mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS;
133 saveRunningInfoToFile( QString::null );
134}
108void Todo::saveRunningInfoToFile() 135void Todo::saveRunningInfoToFile()
109{ 136{
110 mRunEnd = QDateTime::currentDateTime(); 137 mRunEnd = QDateTime::currentDateTime();
111 saveRunningInfoToFile( QString::null ); 138 saveRunningInfoToFile( QString::null );
112} 139}
113void Todo::saveRunningInfoToFile( QString comment ) 140void Todo::saveRunningInfoToFile( QString comment )
114{ 141{
115 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); 142 //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1());
116 if ( mRunStart.secsTo ( mRunEnd) < 15 ) { 143 if ( mRunStart.secsTo ( mRunEnd) < 15 ) {
117 qDebug("Running time < 15 seconds. Skipped. "); 144 qDebug("Running time < 15 seconds. Skipped. ");
118 return; 145 return;
119 } 146 }