-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 | |||
@@ -76,81 +76,93 @@ void Todo::setRunningFalse( QString s ) | |||
76 | if ( mRunSaveTimer ) | 76 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 77 | mRunSaveTimer->stop(); |
78 | saveRunningInfoToFile( s ); | 78 | saveRunningInfoToFile( s ); |
79 | } | 79 | } |
80 | void Todo::stopRunning() | 80 | void Todo::stopRunning() |
81 | { | 81 | { |
82 | if ( !mRunning ) | 82 | if ( !mRunning ) |
83 | return; | 83 | return; |
84 | if ( mRunSaveTimer ) | 84 | if ( mRunSaveTimer ) |
85 | mRunSaveTimer->stop(); | 85 | mRunSaveTimer->stop(); |
86 | mRunning = false; | 86 | mRunning = false; |
87 | } | 87 | } |
88 | void Todo::setRunning( bool run ) | 88 | void Todo::setRunning( bool run ) |
89 | { | 89 | { |
90 | if ( run == mRunning ) | 90 | if ( run == mRunning ) |
91 | return; | 91 | return; |
92 | //qDebug("Todo::setRunning %d ", run); | 92 | //qDebug("Todo::setRunning %d ", run); |
93 | if ( !mRunSaveTimer ) { | 93 | if ( !mRunSaveTimer ) { |
94 | mRunSaveTimer = new QTimer ( this ); | 94 | mRunSaveTimer = new QTimer ( this ); |
95 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); | 95 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); |
96 | } | 96 | } |
97 | mRunning = run; | 97 | mRunning = run; |
98 | mRunLastSave = QDateTime::currentDateTime(); | 98 | mRunLastSave = QDateTime::currentDateTime(); |
99 | if ( mRunning ) { | 99 | if ( mRunning ) { |
100 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min | 100 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); |
101 | mRunStart = QDateTime::currentDateTime(); | 101 | mRunStart = QDateTime::currentDateTime(); |
102 | mRunLastSave = QDateTime::currentDateTime(); | ||
103 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; | ||
104 | } else { | 102 | } else { |
105 | mRunSaveTimer->stop(); | 103 | mRunSaveTimer->stop(); |
106 | saveRunningInfoToFile(); | 104 | saveRunningInfoToFile(); |
107 | } | 105 | } |
108 | } | 106 | } |
109 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 107 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
110 | { | 108 | { |
111 | if ( !mRunning) return; | 109 | if ( !mRunning) return; |
112 | mRunning = false; | 110 | mRunning = false; |
113 | mRunStart = start; | 111 | mRunStart = start; |
114 | mRunEnd = end; | 112 | mRunEnd = end; |
115 | saveRunningInfoToFile( comment ); | 113 | saveRunningInfoToFile( comment ); |
116 | } | 114 | } |
115 | void Todo::restartSaveTimer( int secs ) | ||
116 | { | ||
117 | mRunSaveTimer->start( secs * 1000 ); | ||
118 | mRunLastSave = QDateTime::currentDateTime(); | ||
119 | mCurrentTimerDelay = secs; | ||
120 | } | ||
117 | void Todo::timerSlotSaveRunningInfoToFile() | 121 | void Todo::timerSlotSaveRunningInfoToFile() |
118 | { | 122 | { |
119 | mRunEnd = QDateTime::currentDateTime(); | 123 | mRunEnd = QDateTime::currentDateTime(); |
120 | int secsTo = mRunLastSave.secsTo( mRunEnd ); | 124 | int secsTo = mRunLastSave.secsTo( mRunEnd ); |
121 | if( secsTo == 8 ) ++secsTo; | 125 | //if( secsTo == 8 ) ++secsTo; |
122 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); | 126 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); |
123 | if ( secsTo > mCurrentTimerDelay ) { | 127 | if ( secsTo > mCurrentTimerDelay ) { |
124 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 128 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
125 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_RETRY_SECONDS * 1000 ); | 129 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
126 | mRunLastSave = QDateTime::currentDateTime(); | ||
127 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_RETRY_SECONDS; | ||
128 | return; | 130 | return; |
129 | } | 131 | } |
130 | mRunSaveTimer->start( SAVETIMER_TIMEOUT_SECONDS * 1000 ); // 5 min | 132 | int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); |
131 | mRunLastSave = QDateTime::currentDateTime(); | 133 | if ( msecs < 0 ) { |
132 | mCurrentTimerDelay = SAVETIMER_TIMEOUT_SECONDS; | 134 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
135 | return; | ||
136 | } | ||
137 | // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | ||
138 | if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { | ||
139 | qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | ||
140 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | ||
141 | return; | ||
142 | |||
143 | } | ||
144 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); | ||
133 | saveRunningInfoToFile( QString::null ); | 145 | saveRunningInfoToFile( QString::null ); |
134 | } | 146 | } |
135 | void Todo::saveRunningInfoToFile() | 147 | void Todo::saveRunningInfoToFile() |
136 | { | 148 | { |
137 | mRunEnd = QDateTime::currentDateTime(); | 149 | mRunEnd = QDateTime::currentDateTime(); |
138 | saveRunningInfoToFile( QString::null ); | 150 | saveRunningInfoToFile( QString::null ); |
139 | } | 151 | } |
140 | void Todo::saveRunningInfoToFile( QString comment ) | 152 | void Todo::saveRunningInfoToFile( QString comment ) |
141 | { | 153 | { |
142 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 154 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
143 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 155 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
144 | qDebug("Running time < 15 seconds. Skipped. "); | 156 | qDebug("Running time < 15 seconds. Skipped. "); |
145 | return; | 157 | return; |
146 | } | 158 | } |
147 | QString dir = KGlobalSettings::timeTrackerDir(); | 159 | QString dir = KGlobalSettings::timeTrackerDir(); |
148 | //qDebug("%s ", dir.latin1()); | 160 | //qDebug("%s ", dir.latin1()); |
149 | QString file = "%1%2%3-%4%5%6-"; | 161 | QString file = "%1%2%3-%4%5%6-"; |
150 | 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 ); | 162 | 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 ); |
151 | file.replace ( QRegExp (" "), "0" ); | 163 | file.replace ( QRegExp (" "), "0" ); |
152 | file += uid(); | 164 | file += uid(); |
153 | //qDebug("File %s ",file.latin1() ); | 165 | //qDebug("File %s ",file.latin1() ); |
154 | CalendarLocal cal; | 166 | CalendarLocal cal; |
155 | cal.setLocalTime(); | 167 | cal.setLocalTime(); |
156 | Todo * to = (Todo*) clone(); | 168 | Todo * to = (Todo*) clone(); |