-rw-r--r-- | libkcal/todo.cpp | 31 | ||||
-rw-r--r-- | libkcal/todo.h | 4 |
2 files changed, 33 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 | |||
@@ -29,6 +29,10 @@ | |||
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 | |||
32 | using namespace KCal; | 36 | using namespace KCal; |
33 | 37 | ||
34 | Todo::Todo(): QObject(), Incidence() | 38 | Todo::Todo(): QObject(), Incidence() |
@@ -43,6 +47,7 @@ Todo::Todo(): QObject(), Incidence() | |||
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 | ||
48 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 53 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
@@ -54,6 +59,7 @@ Todo::Todo(const Todo &t) : QObject(),Incidence(t) | |||
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 | ||
59 | Todo::~Todo() | 65 | Todo::~Todo() |
@@ -86,12 +92,15 @@ void Todo::setRunning( bool run ) | |||
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(); |
@@ -105,6 +114,24 @@ void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | |||
105 | mRunEnd = end; | 114 | mRunEnd = end; |
106 | saveRunningInfoToFile( comment ); | 115 | saveRunningInfoToFile( comment ); |
107 | } | 116 | } |
117 | void 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 | } | ||
108 | void Todo::saveRunningInfoToFile() | 135 | void Todo::saveRunningInfoToFile() |
109 | { | 136 | { |
110 | mRunEnd = QDateTime::currentDateTime(); | 137 | mRunEnd = QDateTime::currentDateTime(); |
diff --git a/libkcal/todo.h b/libkcal/todo.h index 7feb32e..e6b8a21 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -131,10 +131,14 @@ namespace KCal { | |||
131 | void saveRunningInfoToFile( ); | 131 | void saveRunningInfoToFile( ); |
132 | void saveParents(); | 132 | void saveParents(); |
133 | QString durationText(); | 133 | QString durationText(); |
134 | private slots: | ||
135 | void timerSlotSaveRunningInfoToFile( ); | ||
134 | private: | 136 | private: |
137 | int mCurrentTimerDelay; | ||
135 | bool mRunning; | 138 | bool mRunning; |
136 | QTimer * mRunSaveTimer; | 139 | QTimer * mRunSaveTimer; |
137 | QDateTime mRunStart; | 140 | QDateTime mRunStart; |
141 | QDateTime mRunLastSave; | ||
138 | QDateTime mRunEnd; | 142 | QDateTime mRunEnd; |
139 | bool accept(Visitor &v) { return v.visit(this); } | 143 | bool accept(Visitor &v) { return v.visit(this); } |
140 | 144 | ||