author | zautrix <zautrix> | 2005-09-25 02:09:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-09-25 02:09:22 (UTC) |
commit | 3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6 (patch) (unidiff) | |
tree | 0d88d48dc1b9198c9c2deed6b55c70deffcfeadd /libkcal/todo.cpp | |
parent | 181bc87d92ecc48cb07c288cb2d135d8fde56716 (diff) | |
download | kdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.zip kdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.tar.gz kdepimpi-3bbc14431e854bc3d8870b5ba12d64f6e1af6eb6.tar.bz2 |
todo timer fix
-rw-r--r-- | libkcal/todo.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index f7d40ad..70a7711 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,79 +1,83 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
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 | #ifndef DESKTOP_VERSION | ||
33 | #include <qpe/qpeapplication.h> | ||
34 | #endif | ||
35 | |||
32 | #define SAVETIMER_TIMEOUT_SECONDS 300 | 36 | #define SAVETIMER_TIMEOUT_SECONDS 300 |
33 | //#define SAVETIMER_TIMEOUT_SECONDS 8 | 37 | //#define SAVETIMER_TIMEOUT_SECONDS 8 |
34 | #define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 | 38 | #define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 |
35 | 39 | ||
36 | using namespace KCal; | 40 | using namespace KCal; |
37 | 41 | ||
38 | Todo::Todo(): QObject(), Incidence() | 42 | Todo::Todo(): QObject(), Incidence() |
39 | { | 43 | { |
40 | // mStatus = TENTATIVE; | 44 | // mStatus = TENTATIVE; |
41 | 45 | ||
42 | mHasDueDate = false; | 46 | mHasDueDate = false; |
43 | setHasStartDate( false ); | 47 | setHasStartDate( false ); |
44 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 48 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
45 | mHasCompletedDate = false; | 49 | mHasCompletedDate = false; |
46 | mPercentComplete = 0; | 50 | mPercentComplete = 0; |
47 | mRunning = false; | 51 | mRunning = false; |
48 | mRunSaveTimer = 0; | 52 | mRunSaveTimer = 0; |
49 | setFloats( true ); | 53 | setFloats( true ); |
50 | mCurrentTimerDelay = 0; | 54 | mCurrentTimerDelay = 0; |
51 | } | 55 | } |
52 | 56 | ||
53 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 57 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
54 | { | 58 | { |
55 | mDtDue = t.mDtDue; | 59 | mDtDue = t.mDtDue; |
56 | mHasDueDate = t.mHasDueDate; | 60 | mHasDueDate = t.mHasDueDate; |
57 | mCompleted = t.mCompleted; | 61 | mCompleted = t.mCompleted; |
58 | mHasCompletedDate = t.mHasCompletedDate; | 62 | mHasCompletedDate = t.mHasCompletedDate; |
59 | mPercentComplete = t.mPercentComplete; | 63 | mPercentComplete = t.mPercentComplete; |
60 | mRunning = false; | 64 | mRunning = false; |
61 | mRunSaveTimer = 0; | 65 | mRunSaveTimer = 0; |
62 | mCurrentTimerDelay = 0; | 66 | mCurrentTimerDelay = 0; |
63 | } | 67 | } |
64 | 68 | ||
65 | Todo::~Todo() | 69 | Todo::~Todo() |
66 | { | 70 | { |
67 | setRunning( false ); | 71 | setRunning( false ); |
68 | //qDebug("Todo::~Todo() "); | 72 | //qDebug("Todo::~Todo() "); |
69 | } | 73 | } |
70 | 74 | ||
71 | void Todo::setRunningFalse( QString s ) | 75 | void Todo::setRunningFalse( QString s ) |
72 | { | 76 | { |
73 | if ( ! mRunning ) | 77 | if ( ! mRunning ) |
74 | return; | 78 | return; |
75 | mRunning = false; | 79 | mRunning = false; |
76 | if ( mRunSaveTimer ) | 80 | if ( mRunSaveTimer ) |
77 | mRunSaveTimer->stop(); | 81 | mRunSaveTimer->stop(); |
78 | saveRunningInfoToFile( s ); | 82 | saveRunningInfoToFile( s ); |
79 | } | 83 | } |
@@ -94,142 +98,146 @@ void Todo::setRunning( bool run ) | |||
94 | mRunSaveTimer = new QTimer ( this ); | 98 | mRunSaveTimer = new QTimer ( this ); |
95 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); | 99 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( timerSlotSaveRunningInfoToFile() ) ); |
96 | } | 100 | } |
97 | mRunning = run; | 101 | mRunning = run; |
98 | mRunLastSave = QDateTime::currentDateTime(); | 102 | mRunLastSave = QDateTime::currentDateTime(); |
99 | if ( mRunning ) { | 103 | if ( mRunning ) { |
100 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); | 104 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); |
101 | mRunStart = QDateTime::currentDateTime(); | 105 | mRunStart = QDateTime::currentDateTime(); |
102 | } else { | 106 | } else { |
103 | mRunSaveTimer->stop(); | 107 | mRunSaveTimer->stop(); |
104 | saveRunningInfoToFile(); | 108 | saveRunningInfoToFile(); |
105 | } | 109 | } |
106 | } | 110 | } |
107 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) | 111 | void Todo::saveRunningInfo( QString comment, QDateTime start, QDateTime end ) |
108 | { | 112 | { |
109 | if ( !mRunning) return; | 113 | if ( !mRunning) return; |
110 | mRunning = false; | 114 | mRunning = false; |
111 | mRunStart = start; | 115 | mRunStart = start; |
112 | mRunEnd = end; | 116 | mRunEnd = end; |
113 | saveRunningInfoToFile( comment ); | 117 | saveRunningInfoToFile( comment ); |
114 | } | 118 | } |
115 | void Todo::restartSaveTimer( int secs ) | 119 | void Todo::restartSaveTimer( int secs ) |
116 | { | 120 | { |
117 | mRunSaveTimer->start( secs * 1000 ); | 121 | mRunSaveTimer->start( secs * 1000 ); |
118 | mRunLastSave = QDateTime::currentDateTime(); | 122 | mRunLastSave = QDateTime::currentDateTime(); |
119 | mCurrentTimerDelay = secs; | 123 | mCurrentTimerDelay = secs; |
120 | } | 124 | } |
121 | void Todo::timerSlotSaveRunningInfoToFile() | 125 | void Todo::timerSlotSaveRunningInfoToFile() |
122 | { | 126 | { |
123 | mRunEnd = QDateTime::currentDateTime(); | 127 | mRunEnd = QDateTime::currentDateTime(); |
124 | int secsTo = mRunLastSave.secsTo( mRunEnd ); | 128 | int secsTo = mRunLastSave.secsTo( mRunEnd ); |
125 | //if( secsTo == 8 ) ++secsTo; | 129 | //if( secsTo == 8 ) ++secsTo; |
126 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); | 130 | qDebug("KO Todo::saveTimerTimeout %d %d", secsTo, mCurrentTimerDelay ); |
127 | if ( secsTo > mCurrentTimerDelay ) { | 131 | if ( secsTo > mCurrentTimerDelay ) { |
128 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 132 | qDebug("KO Todo::saveTimerTimeout restart %d ", SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
129 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 133 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
130 | return; | 134 | return; |
131 | } | 135 | } |
132 | int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); | 136 | int msecs = mRunLastSave.time().msecsTo( mRunEnd.time()); |
133 | if ( msecs < 0 ) { | 137 | if ( msecs < 0 ) { |
134 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 138 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
135 | return; | 139 | return; |
136 | } | 140 | } |
137 | // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | 141 | // qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); |
138 | if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { | 142 | if ( msecs > ( ( mCurrentTimerDelay * 1000 ) + 50 )) { |
139 | qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); | 143 | qDebug("KO Todo::saveTimerTimeout restarting! millisecs %d", msecs - ( ( mCurrentTimerDelay * 1000 ) + 50 ) ); |
140 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); | 144 | restartSaveTimer( SAVETIMER_TIMEOUT_RETRY_SECONDS ); |
141 | return; | 145 | return; |
142 | |||
143 | } | 146 | } |
144 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); | 147 | restartSaveTimer( SAVETIMER_TIMEOUT_SECONDS ); |
145 | saveRunningInfoToFile( QString::null ); | 148 | saveRunningInfoToFile( QString::null ); |
146 | } | 149 | } |
147 | void Todo::saveRunningInfoToFile() | 150 | void Todo::saveRunningInfoToFile() |
148 | { | 151 | { |
149 | mRunEnd = QDateTime::currentDateTime(); | 152 | mRunEnd = QDateTime::currentDateTime(); |
150 | saveRunningInfoToFile( QString::null ); | 153 | saveRunningInfoToFile( QString::null ); |
151 | } | 154 | } |
152 | void Todo::saveRunningInfoToFile( QString comment ) | 155 | void Todo::saveRunningInfoToFile( QString comment ) |
153 | { | 156 | { |
157 | #ifndef DESKTOP_VERSION | ||
158 | QPEApplication::setTempScreenSaverMode ( QPEApplication::Disable ); | ||
159 | #endif | ||
154 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 160 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
155 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { | 161 | if ( mRunStart.secsTo ( mRunEnd) < 15 ) { |
156 | qDebug("Running time < 15 seconds. Skipped. "); | 162 | qDebug("Running time < 15 seconds. Skipped. "); |
157 | return; | 163 | return; |
158 | } | 164 | } |
159 | QString dir = KGlobalSettings::timeTrackerDir(); | 165 | QString dir = KGlobalSettings::timeTrackerDir(); |
160 | //qDebug("%s ", dir.latin1()); | 166 | //qDebug("%s ", dir.latin1()); |
161 | QString file = "%1%2%3-%4%5%6-"; | 167 | QString file = "%1%2%3-%4%5%6-"; |
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 ); | 168 | 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 ); |
163 | file.replace ( QRegExp (" "), "0" ); | 169 | file.replace ( QRegExp (" "), "0" ); |
164 | file += uid(); | 170 | file += uid(); |
165 | //qDebug("File %s ",file.latin1() ); | 171 | //qDebug("File %s ",file.latin1() ); |
166 | CalendarLocal cal; | 172 | CalendarLocal cal; |
167 | cal.setLocalTime(); | 173 | cal.setLocalTime(); |
168 | Todo * to = (Todo*) clone(); | 174 | Todo * to = (Todo*) clone(); |
169 | to->setFloats( false ); | 175 | to->setFloats( false ); |
170 | to->setDtStart( mRunStart ); | 176 | to->setDtStart( mRunStart ); |
171 | to->setHasStartDate( true ); | 177 | to->setHasStartDate( true ); |
172 | to->setDtDue( mRunEnd ); | 178 | to->setDtDue( mRunEnd ); |
173 | to->setHasDueDate( true ); | 179 | to->setHasDueDate( true ); |
174 | to->setUid( file ); | 180 | to->setUid( file ); |
175 | if ( !comment.isEmpty() ) { | 181 | if ( !comment.isEmpty() ) { |
176 | QString des = to->description(); | 182 | QString des = to->description(); |
177 | if ( des.isEmpty () ) | 183 | if ( des.isEmpty () ) |
178 | to->setDescription( "TT-Note: " + comment ); | 184 | to->setDescription( "TT-Note: " + comment ); |
179 | else | 185 | else |
180 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 186 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
181 | } | 187 | } |
182 | cal.addIncidence( to ); | 188 | cal.addIncidence( to ); |
183 | ICalFormat format( false ); | 189 | ICalFormat format( false ); |
184 | file = dir +"/" +file +".ics"; | 190 | file = dir +"/" +file +".ics"; |
185 | format.save( &cal, file ); | 191 | format.save( &cal, file ); |
186 | saveParents(); | 192 | saveParents(); |
187 | 193 | #ifndef DESKTOP_VERSION | |
194 | QPEApplication::setTempScreenSaverMode ( QPEApplication::Enable ); | ||
195 | #endif | ||
188 | } | 196 | } |
189 | void Todo::saveParents() | 197 | void Todo::saveParents() |
190 | { | 198 | { |
191 | if (!relatedTo() ) | 199 | if (!relatedTo() ) |
192 | return; | 200 | return; |
193 | Incidence * inc = relatedTo(); | 201 | Incidence * inc = relatedTo(); |
194 | if ( inc->typeID() != todoID ) | 202 | if ( inc->typeID() != todoID ) |
195 | return; | 203 | return; |
196 | Todo* to = (Todo*)inc; | 204 | Todo* to = (Todo*)inc; |
197 | bool saveTodo = false; | 205 | bool saveTodo = false; |
198 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 206 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
199 | QFileInfo fi ( file ); | 207 | QFileInfo fi ( file ); |
200 | if ( fi.exists() ) { | 208 | if ( fi.exists() ) { |
201 | if ( fi.lastModified () < to->lastModified ()) | 209 | if ( fi.lastModified () < to->lastModified ()) |
202 | saveTodo = true; | 210 | saveTodo = true; |
203 | } else { | 211 | } else { |
204 | saveTodo = true; | 212 | saveTodo = true; |
205 | } | 213 | } |
206 | if ( saveTodo ) { | 214 | if ( saveTodo ) { |
207 | CalendarLocal cal; | 215 | CalendarLocal cal; |
208 | cal.setLocalTime(); | 216 | cal.setLocalTime(); |
209 | Todo * par = (Todo *) to->clone(); | 217 | Todo * par = (Todo *) to->clone(); |
210 | cal.addIncidence( par ); | 218 | cal.addIncidence( par ); |
211 | ICalFormat format( false ); | 219 | ICalFormat format( false ); |
212 | format.save( &cal, file ); | 220 | format.save( &cal, file ); |
213 | } | 221 | } |
214 | to->saveParents(); | 222 | to->saveParents(); |
215 | } | 223 | } |
216 | 224 | ||
217 | int Todo::runTime() | 225 | int Todo::runTime() |
218 | { | 226 | { |
219 | if ( !mRunning ) | 227 | if ( !mRunning ) |
220 | return 0; | 228 | return 0; |
221 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 229 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
222 | } | 230 | } |
223 | bool Todo::hasRunningSub() | 231 | bool Todo::hasRunningSub() |
224 | { | 232 | { |
225 | if ( mRunning ) | 233 | if ( mRunning ) |
226 | return true; | 234 | return true; |
227 | Incidence *aTodo; | 235 | Incidence *aTodo; |
228 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 236 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
229 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 237 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
230 | return true; | 238 | return true; |
231 | } | 239 | } |
232 | return false; | 240 | return false; |
233 | } | 241 | } |
234 | Incidence *Todo::clone() | 242 | Incidence *Todo::clone() |
235 | { | 243 | { |