author | zautrix <zautrix> | 2005-09-25 01:27:36 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-09-25 01:27:36 (UTC) |
commit | 181bc87d92ecc48cb07c288cb2d135d8fde56716 (patch) (unidiff) | |
tree | 97d972b99fc1a147cdbb0b9a295527e6d6fe119c /libkcal | |
parent | bd991f0a33d85385735ed4911b794b8740e4d296 (diff) | |
download | kdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.zip kdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.tar.gz kdepimpi-181bc87d92ecc48cb07c288cb2d135d8fde56716.tar.bz2 |
todo timer fix
-rw-r--r-- | libkcal/todo.cpp | 34 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
2 files changed, 24 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 | |||
@@ -1,324 +1,336 @@ | |||
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 | #define SAVETIMER_TIMEOUT_SECONDS 300 | 32 | #define SAVETIMER_TIMEOUT_SECONDS 300 |
33 | //#define SAVETIMER_TIMEOUT_SECONDS 8 | 33 | //#define SAVETIMER_TIMEOUT_SECONDS 8 |
34 | #define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 | 34 | #define SAVETIMER_TIMEOUT_RETRY_SECONDS 5 |
35 | 35 | ||
36 | using namespace KCal; | 36 | using namespace KCal; |
37 | 37 | ||
38 | Todo::Todo(): QObject(), Incidence() | 38 | Todo::Todo(): QObject(), Incidence() |
39 | { | 39 | { |
40 | // mStatus = TENTATIVE; | 40 | // mStatus = TENTATIVE; |
41 | 41 | ||
42 | mHasDueDate = false; | 42 | mHasDueDate = false; |
43 | setHasStartDate( false ); | 43 | setHasStartDate( false ); |
44 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 44 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
45 | mHasCompletedDate = false; | 45 | mHasCompletedDate = false; |
46 | mPercentComplete = 0; | 46 | mPercentComplete = 0; |
47 | mRunning = false; | 47 | mRunning = false; |
48 | mRunSaveTimer = 0; | 48 | mRunSaveTimer = 0; |
49 | setFloats( true ); | 49 | setFloats( true ); |
50 | mCurrentTimerDelay = 0; | 50 | mCurrentTimerDelay = 0; |
51 | } | 51 | } |
52 | 52 | ||
53 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 53 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
54 | { | 54 | { |
55 | mDtDue = t.mDtDue; | 55 | mDtDue = t.mDtDue; |
56 | mHasDueDate = t.mHasDueDate; | 56 | mHasDueDate = t.mHasDueDate; |
57 | mCompleted = t.mCompleted; | 57 | mCompleted = t.mCompleted; |
58 | mHasCompletedDate = t.mHasCompletedDate; | 58 | mHasCompletedDate = t.mHasCompletedDate; |
59 | mPercentComplete = t.mPercentComplete; | 59 | mPercentComplete = t.mPercentComplete; |
60 | mRunning = false; | 60 | mRunning = false; |
61 | mRunSaveTimer = 0; | 61 | mRunSaveTimer = 0; |
62 | mCurrentTimerDelay = 0; | 62 | mCurrentTimerDelay = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | Todo::~Todo() | 65 | Todo::~Todo() |
66 | { | 66 | { |
67 | setRunning( false ); | 67 | setRunning( false ); |
68 | //qDebug("Todo::~Todo() "); | 68 | //qDebug("Todo::~Todo() "); |
69 | } | 69 | } |
70 | 70 | ||
71 | void Todo::setRunningFalse( QString s ) | 71 | void Todo::setRunningFalse( QString s ) |
72 | { | 72 | { |
73 | if ( ! mRunning ) | 73 | if ( ! mRunning ) |
74 | return; | 74 | return; |
75 | mRunning = false; | 75 | mRunning = false; |
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(); |
157 | to->setFloats( false ); | 169 | to->setFloats( false ); |
158 | to->setDtStart( mRunStart ); | 170 | to->setDtStart( mRunStart ); |
159 | to->setHasStartDate( true ); | 171 | to->setHasStartDate( true ); |
160 | to->setDtDue( mRunEnd ); | 172 | to->setDtDue( mRunEnd ); |
161 | to->setHasDueDate( true ); | 173 | to->setHasDueDate( true ); |
162 | to->setUid( file ); | 174 | to->setUid( file ); |
163 | if ( !comment.isEmpty() ) { | 175 | if ( !comment.isEmpty() ) { |
164 | QString des = to->description(); | 176 | QString des = to->description(); |
165 | if ( des.isEmpty () ) | 177 | if ( des.isEmpty () ) |
166 | to->setDescription( "TT-Note: " + comment ); | 178 | to->setDescription( "TT-Note: " + comment ); |
167 | else | 179 | else |
168 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 180 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
169 | } | 181 | } |
170 | cal.addIncidence( to ); | 182 | cal.addIncidence( to ); |
171 | ICalFormat format( false ); | 183 | ICalFormat format( false ); |
172 | file = dir +"/" +file +".ics"; | 184 | file = dir +"/" +file +".ics"; |
173 | format.save( &cal, file ); | 185 | format.save( &cal, file ); |
174 | saveParents(); | 186 | saveParents(); |
175 | 187 | ||
176 | } | 188 | } |
177 | void Todo::saveParents() | 189 | void Todo::saveParents() |
178 | { | 190 | { |
179 | if (!relatedTo() ) | 191 | if (!relatedTo() ) |
180 | return; | 192 | return; |
181 | Incidence * inc = relatedTo(); | 193 | Incidence * inc = relatedTo(); |
182 | if ( inc->typeID() != todoID ) | 194 | if ( inc->typeID() != todoID ) |
183 | return; | 195 | return; |
184 | Todo* to = (Todo*)inc; | 196 | Todo* to = (Todo*)inc; |
185 | bool saveTodo = false; | 197 | bool saveTodo = false; |
186 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 198 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
187 | QFileInfo fi ( file ); | 199 | QFileInfo fi ( file ); |
188 | if ( fi.exists() ) { | 200 | if ( fi.exists() ) { |
189 | if ( fi.lastModified () < to->lastModified ()) | 201 | if ( fi.lastModified () < to->lastModified ()) |
190 | saveTodo = true; | 202 | saveTodo = true; |
191 | } else { | 203 | } else { |
192 | saveTodo = true; | 204 | saveTodo = true; |
193 | } | 205 | } |
194 | if ( saveTodo ) { | 206 | if ( saveTodo ) { |
195 | CalendarLocal cal; | 207 | CalendarLocal cal; |
196 | cal.setLocalTime(); | 208 | cal.setLocalTime(); |
197 | Todo * par = (Todo *) to->clone(); | 209 | Todo * par = (Todo *) to->clone(); |
198 | cal.addIncidence( par ); | 210 | cal.addIncidence( par ); |
199 | ICalFormat format( false ); | 211 | ICalFormat format( false ); |
200 | format.save( &cal, file ); | 212 | format.save( &cal, file ); |
201 | } | 213 | } |
202 | to->saveParents(); | 214 | to->saveParents(); |
203 | } | 215 | } |
204 | 216 | ||
205 | int Todo::runTime() | 217 | int Todo::runTime() |
206 | { | 218 | { |
207 | if ( !mRunning ) | 219 | if ( !mRunning ) |
208 | return 0; | 220 | return 0; |
209 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 221 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
210 | } | 222 | } |
211 | bool Todo::hasRunningSub() | 223 | bool Todo::hasRunningSub() |
212 | { | 224 | { |
213 | if ( mRunning ) | 225 | if ( mRunning ) |
214 | return true; | 226 | return true; |
215 | Incidence *aTodo; | 227 | Incidence *aTodo; |
216 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 228 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
217 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 229 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
218 | return true; | 230 | return true; |
219 | } | 231 | } |
220 | return false; | 232 | return false; |
221 | } | 233 | } |
222 | Incidence *Todo::clone() | 234 | Incidence *Todo::clone() |
223 | { | 235 | { |
224 | return new Todo(*this); | 236 | return new Todo(*this); |
225 | } | 237 | } |
226 | 238 | ||
227 | bool Todo::contains ( Todo* from ) | 239 | bool Todo::contains ( Todo* from ) |
228 | { | 240 | { |
229 | 241 | ||
230 | if ( !from->summary().isEmpty() ) | 242 | if ( !from->summary().isEmpty() ) |
231 | if ( !summary().startsWith( from->summary() )) | 243 | if ( !summary().startsWith( from->summary() )) |
232 | return false; | 244 | return false; |
233 | if ( from->hasStartDate() ) { | 245 | if ( from->hasStartDate() ) { |
234 | if ( !hasStartDate() ) | 246 | if ( !hasStartDate() ) |
235 | return false; | 247 | return false; |
236 | if ( from->dtStart() != dtStart()) | 248 | if ( from->dtStart() != dtStart()) |
237 | return false; | 249 | return false; |
238 | } | 250 | } |
239 | if ( from->hasDueDate() ){ | 251 | if ( from->hasDueDate() ){ |
240 | if ( !hasDueDate() ) | 252 | if ( !hasDueDate() ) |
241 | return false; | 253 | return false; |
242 | if ( from->dtDue() != dtDue()) | 254 | if ( from->dtDue() != dtDue()) |
243 | return false; | 255 | return false; |
244 | } | 256 | } |
245 | if ( !from->location().isEmpty() ) | 257 | if ( !from->location().isEmpty() ) |
246 | if ( !location().startsWith( from->location() ) ) | 258 | if ( !location().startsWith( from->location() ) ) |
247 | return false; | 259 | return false; |
248 | if ( !from->description().isEmpty() ) | 260 | if ( !from->description().isEmpty() ) |
249 | if ( !description().startsWith( from->description() )) | 261 | if ( !description().startsWith( from->description() )) |
250 | return false; | 262 | return false; |
251 | if ( from->alarms().count() ) { | 263 | if ( from->alarms().count() ) { |
252 | Alarm *a = from->alarms().first(); | 264 | Alarm *a = from->alarms().first(); |
253 | if ( a->enabled() ){ | 265 | if ( a->enabled() ){ |
254 | if ( !alarms().count() ) | 266 | if ( !alarms().count() ) |
255 | return false; | 267 | return false; |
256 | Alarm *b = alarms().first(); | 268 | Alarm *b = alarms().first(); |
257 | if( ! b->enabled() ) | 269 | if( ! b->enabled() ) |
258 | return false; | 270 | return false; |
259 | if ( ! (a->offset() == b->offset() )) | 271 | if ( ! (a->offset() == b->offset() )) |
260 | return false; | 272 | return false; |
261 | } | 273 | } |
262 | } | 274 | } |
263 | 275 | ||
264 | QStringList cat = categories(); | 276 | QStringList cat = categories(); |
265 | QStringList catFrom = from->categories(); | 277 | QStringList catFrom = from->categories(); |
266 | QString nCat; | 278 | QString nCat; |
267 | unsigned int iii; | 279 | unsigned int iii; |
268 | for ( iii = 0; iii < catFrom.count();++iii ) { | 280 | for ( iii = 0; iii < catFrom.count();++iii ) { |
269 | nCat = catFrom[iii]; | 281 | nCat = catFrom[iii]; |
270 | if ( !nCat.isEmpty() ) | 282 | if ( !nCat.isEmpty() ) |
271 | if ( !cat.contains( nCat )) { | 283 | if ( !cat.contains( nCat )) { |
272 | return false; | 284 | return false; |
273 | } | 285 | } |
274 | } | 286 | } |
275 | if ( from->isCompleted() ) { | 287 | if ( from->isCompleted() ) { |
276 | if ( !isCompleted() ) | 288 | if ( !isCompleted() ) |
277 | return false; | 289 | return false; |
278 | } | 290 | } |
279 | if( priority() != from->priority() ) | 291 | if( priority() != from->priority() ) |
280 | return false; | 292 | return false; |
281 | 293 | ||
282 | 294 | ||
283 | return true; | 295 | return true; |
284 | 296 | ||
285 | } | 297 | } |
286 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 298 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
287 | { | 299 | { |
288 | 300 | ||
289 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 301 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
290 | if ( ! ret ) | 302 | if ( ! ret ) |
291 | return false; | 303 | return false; |
292 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 304 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
293 | if ( t1.hasDueDate() ) { | 305 | if ( t1.hasDueDate() ) { |
294 | if ( t1.doesFloat() == t2.doesFloat() ) { | 306 | if ( t1.doesFloat() == t2.doesFloat() ) { |
295 | if ( t1.doesFloat() ) { | 307 | if ( t1.doesFloat() ) { |
296 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 308 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
297 | return false; | 309 | return false; |
298 | } else | 310 | } else |
299 | if ( t1.dtDue() != t2.dtDue() ) | 311 | if ( t1.dtDue() != t2.dtDue() ) |
300 | return false; | 312 | return false; |
301 | } else | 313 | } else |
302 | return false;// float != | 314 | return false;// float != |
303 | } | 315 | } |
304 | 316 | ||
305 | } else | 317 | } else |
306 | return false; | 318 | return false; |
307 | if ( t1.percentComplete() != t2.percentComplete() ) | 319 | if ( t1.percentComplete() != t2.percentComplete() ) |
308 | return false; | 320 | return false; |
309 | if ( t1.isCompleted() ) { | 321 | if ( t1.isCompleted() ) { |
310 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 322 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
311 | if ( t1.hasCompletedDate() ) { | 323 | if ( t1.hasCompletedDate() ) { |
312 | if ( t1.completed() != t2.completed() ) | 324 | if ( t1.completed() != t2.completed() ) |
313 | return false; | 325 | return false; |
314 | } | 326 | } |
315 | 327 | ||
316 | } else | 328 | } else |
317 | return false; | 329 | return false; |
318 | } | 330 | } |
319 | return true; | 331 | return true; |
320 | 332 | ||
321 | } | 333 | } |
322 | 334 | ||
323 | void Todo::setDtDue(const QDateTime &dtDue) | 335 | void Todo::setDtDue(const QDateTime &dtDue) |
324 | { | 336 | { |
diff --git a/libkcal/todo.h b/libkcal/todo.h index e6b8a21..71b7a4e 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -1,160 +1,161 @@ | |||
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 | #ifndef TODO_H | 20 | #ifndef TODO_H |
21 | #define TODO_H | 21 | #define TODO_H |
22 | // | 22 | // |
23 | // Todo component, representing a VTODO object | 23 | // Todo component, representing a VTODO object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | 27 | ||
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | 29 | ||
30 | namespace KCal { | 30 | namespace KCal { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | This class provides a Todo in the sense of RFC2445. | 33 | This class provides a Todo in the sense of RFC2445. |
34 | */ | 34 | */ |
35 | class Todo : public QObject,public Incidence | 35 | class Todo : public QObject,public Incidence |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | public: | 38 | public: |
39 | Todo(); | 39 | Todo(); |
40 | Todo(const Todo &); | 40 | Todo(const Todo &); |
41 | ~Todo(); | 41 | ~Todo(); |
42 | typedef ListBase<Todo> List; | 42 | typedef ListBase<Todo> List; |
43 | QCString type() const { return "Todo"; } | 43 | QCString type() const { return "Todo"; } |
44 | IncTypeID typeID() const { return todoID; } | 44 | IncTypeID typeID() const { return todoID; } |
45 | 45 | ||
46 | /** Return an exact copy of this todo. */ | 46 | /** Return an exact copy of this todo. */ |
47 | Incidence *clone(); | 47 | Incidence *clone(); |
48 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; | 48 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; |
49 | 49 | ||
50 | /** for setting the todo's due date/time with a QDateTime. */ | 50 | /** for setting the todo's due date/time with a QDateTime. */ |
51 | void setDtDue(const QDateTime &dtDue); | 51 | void setDtDue(const QDateTime &dtDue); |
52 | /** returns an event's Due date/time as a QDateTime. */ | 52 | /** returns an event's Due date/time as a QDateTime. */ |
53 | QDateTime dtDue() const; | 53 | QDateTime dtDue() const; |
54 | /** returns an event's due time as a string formatted according to the | 54 | /** returns an event's due time as a string formatted according to the |
55 | users locale settings */ | 55 | users locale settings */ |
56 | QString dtDueTimeStr() const; | 56 | QString dtDueTimeStr() const; |
57 | /** returns an event's due date as a string formatted according to the | 57 | /** returns an event's due date as a string formatted according to the |
58 | users locale settings */ | 58 | users locale settings */ |
59 | QString dtDueDateStr(bool shortfmt=true) const; | 59 | QString dtDueDateStr(bool shortfmt=true) const; |
60 | /** returns an event's due date and time as a string formatted according | 60 | /** returns an event's due date and time as a string formatted according |
61 | to the users locale settings */ | 61 | to the users locale settings */ |
62 | QString dtDueStr(bool shortfmt=true) const; | 62 | QString dtDueStr(bool shortfmt=true) const; |
63 | 63 | ||
64 | /** returns TRUE or FALSE depending on whether the todo has a due date */ | 64 | /** returns TRUE or FALSE depending on whether the todo has a due date */ |
65 | bool hasDueDate() const; | 65 | bool hasDueDate() const; |
66 | /** sets the event's hasDueDate value. */ | 66 | /** sets the event's hasDueDate value. */ |
67 | void setHasDueDate(bool f); | 67 | void setHasDueDate(bool f); |
68 | 68 | ||
69 | /* | 69 | /* |
70 | Looks for a subtodo (including itself ) which is not complete and is | 70 | Looks for a subtodo (including itself ) which is not complete and is |
71 | - overdue, or | 71 | - overdue, or |
72 | - due today. | 72 | - due today. |
73 | It returns 0 for nothing found, | 73 | It returns 0 for nothing found, |
74 | 1 for found a todo which is due today and no overdue found | 74 | 1 for found a todo which is due today and no overdue found |
75 | 2 for found a overdue todo | 75 | 2 for found a overdue todo |
76 | */ | 76 | */ |
77 | int hasDueSubTodo( bool checkSubtodos = true ); | 77 | int hasDueSubTodo( bool checkSubtodos = true ); |
78 | /* same as above, but a specific date can be specified*/ | 78 | /* same as above, but a specific date can be specified*/ |
79 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); | 79 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); |
80 | 80 | ||
81 | 81 | ||
82 | /** sets the event's status to the string specified. The string | 82 | /** sets the event's status to the string specified. The string |
83 | * must be a recognized value for the status field, i.e. a string | 83 | * must be a recognized value for the status field, i.e. a string |
84 | * equivalent of the possible status enumerations previously described. */ | 84 | * equivalent of the possible status enumerations previously described. */ |
85 | // void setStatus(const QString &statStr); | 85 | // void setStatus(const QString &statStr); |
86 | /** sets the event's status to the value specified. See the enumeration | 86 | /** sets the event's status to the value specified. See the enumeration |
87 | * above for possible values. */ | 87 | * above for possible values. */ |
88 | // void setStatus(int); | 88 | // void setStatus(int); |
89 | /** return the event's status. */ | 89 | /** return the event's status. */ |
90 | // int status() const; | 90 | // int status() const; |
91 | /** return the event's status in string format. */ | 91 | /** return the event's status in string format. */ |
92 | // QString statusStr() const; | 92 | // QString statusStr() const; |
93 | 93 | ||
94 | /** return, if this todo is completed */ | 94 | /** return, if this todo is completed */ |
95 | bool isCompleted() const; | 95 | bool isCompleted() const; |
96 | /** set completed state of this todo */ | 96 | /** set completed state of this todo */ |
97 | void setCompleted(bool); | 97 | void setCompleted(bool); |
98 | 98 | ||
99 | /** | 99 | /** |
100 | Return how many percent of the task are completed. Returns a value | 100 | Return how many percent of the task are completed. Returns a value |
101 | between 0 and 100. | 101 | between 0 and 100. |
102 | */ | 102 | */ |
103 | int percentComplete() const; | 103 | int percentComplete() const; |
104 | /** | 104 | /** |
105 | Set how many percent of the task are completed. Valid values are in the | 105 | Set how many percent of the task are completed. Valid values are in the |
106 | range from 0 to 100. | 106 | range from 0 to 100. |
107 | */ | 107 | */ |
108 | void setPercentComplete(int); | 108 | void setPercentComplete(int); |
109 | 109 | ||
110 | /** return date and time when todo was completed */ | 110 | /** return date and time when todo was completed */ |
111 | QDateTime completed() const; | 111 | QDateTime completed() const; |
112 | QString completedStr(bool shortF = true) const; | 112 | QString completedStr(bool shortF = true) const; |
113 | /** set date and time of completion */ | 113 | /** set date and time of completion */ |
114 | void setCompleted(const QDateTime &completed); | 114 | void setCompleted(const QDateTime &completed); |
115 | 115 | ||
116 | /** Return true, if todo has a date associated with completion */ | 116 | /** Return true, if todo has a date associated with completion */ |
117 | bool hasCompletedDate() const; | 117 | bool hasCompletedDate() const; |
118 | bool contains ( Todo*); | 118 | bool contains ( Todo*); |
119 | void checkSetCompletedFalse(); | 119 | void checkSetCompletedFalse(); |
120 | bool setRecurDates(); | 120 | bool setRecurDates(); |
121 | bool isRunning() {return mRunning;} | 121 | bool isRunning() {return mRunning;} |
122 | bool hasRunningSub(); | 122 | bool hasRunningSub(); |
123 | void setRunning( bool ); | 123 | void setRunning( bool ); |
124 | void setRunningFalse( QString ); | 124 | void setRunningFalse( QString ); |
125 | void stopRunning(); | 125 | void stopRunning(); |
126 | int runTime(); | 126 | int runTime(); |
127 | QDateTime runStart () const { return mRunStart;} | 127 | QDateTime runStart () const { return mRunStart;} |
128 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); | 128 | void saveRunningInfo( QString comment, QDateTime start, QDateTime end ); |
129 | public slots: | 129 | public slots: |
130 | void saveRunningInfoToFile( QString st ); | 130 | void saveRunningInfoToFile( QString st ); |
131 | void saveRunningInfoToFile( ); | 131 | void saveRunningInfoToFile( ); |
132 | void saveParents(); | 132 | void saveParents(); |
133 | QString durationText(); | 133 | QString durationText(); |
134 | private slots: | 134 | private slots: |
135 | void timerSlotSaveRunningInfoToFile( ); | 135 | void timerSlotSaveRunningInfoToFile( ); |
136 | private: | 136 | private: |
137 | void restartSaveTimer( int secs ); | ||
137 | int mCurrentTimerDelay; | 138 | int mCurrentTimerDelay; |
138 | bool mRunning; | 139 | bool mRunning; |
139 | QTimer * mRunSaveTimer; | 140 | QTimer * mRunSaveTimer; |
140 | QDateTime mRunStart; | 141 | QDateTime mRunStart; |
141 | QDateTime mRunLastSave; | 142 | QDateTime mRunLastSave; |
142 | QDateTime mRunEnd; | 143 | QDateTime mRunEnd; |
143 | bool accept(Visitor &v) { return v.visit(this); } | 144 | bool accept(Visitor &v) { return v.visit(this); } |
144 | 145 | ||
145 | QDateTime mDtDue; // due date of todo | 146 | QDateTime mDtDue; // due date of todo |
146 | 147 | ||
147 | bool mHasDueDate; // if todo has associated due date | 148 | bool mHasDueDate; // if todo has associated due date |
148 | 149 | ||
149 | // int mStatus; // confirmed/delegated/tentative/etc | 150 | // int mStatus; // confirmed/delegated/tentative/etc |
150 | 151 | ||
151 | QDateTime mCompleted; | 152 | QDateTime mCompleted; |
152 | bool mHasCompletedDate; | 153 | bool mHasCompletedDate; |
153 | 154 | ||
154 | int mPercentComplete; | 155 | int mPercentComplete; |
155 | }; | 156 | }; |
156 | 157 | ||
157 | bool operator==( const Todo&, const Todo& ); | 158 | bool operator==( const Todo&, const Todo& ); |
158 | } | 159 | } |
159 | 160 | ||
160 | #endif | 161 | #endif |