-rw-r--r-- | libkcal/todo.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 7dee4cd..c008fe1 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,503 +1,517 @@ | |||
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 <klocale.h> | 23 | #include <klocale.h> |
23 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | ||
24 | 26 | ||
25 | #include "todo.h" | 27 | #include "todo.h" |
26 | 28 | ||
27 | using namespace KCal; | 29 | using namespace KCal; |
28 | 30 | ||
29 | Todo::Todo(): Incidence() | 31 | Todo::Todo(): Incidence() |
30 | { | 32 | { |
31 | // mStatus = TENTATIVE; | 33 | // mStatus = TENTATIVE; |
32 | 34 | ||
33 | mHasDueDate = false; | 35 | mHasDueDate = false; |
34 | setHasStartDate( false ); | 36 | setHasStartDate( false ); |
35 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 37 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
36 | mHasCompletedDate = false; | 38 | mHasCompletedDate = false; |
37 | mPercentComplete = 0; | 39 | mPercentComplete = 0; |
38 | mRunning = false; | 40 | mRunning = false; |
39 | mRunSaveTimer = 0; | 41 | mRunSaveTimer = 0; |
40 | } | 42 | } |
41 | 43 | ||
42 | Todo::Todo(const Todo &t) : Incidence(t) | 44 | Todo::Todo(const Todo &t) : Incidence(t) |
43 | { | 45 | { |
44 | mDtDue = t.mDtDue; | 46 | mDtDue = t.mDtDue; |
45 | mHasDueDate = t.mHasDueDate; | 47 | mHasDueDate = t.mHasDueDate; |
46 | mCompleted = t.mCompleted; | 48 | mCompleted = t.mCompleted; |
47 | mHasCompletedDate = t.mHasCompletedDate; | 49 | mHasCompletedDate = t.mHasCompletedDate; |
48 | mPercentComplete = t.mPercentComplete; | 50 | mPercentComplete = t.mPercentComplete; |
49 | mRunning = false; | 51 | mRunning = false; |
50 | mRunSaveTimer = 0; | 52 | mRunSaveTimer = 0; |
51 | } | 53 | } |
52 | 54 | ||
53 | Todo::~Todo() | 55 | Todo::~Todo() |
54 | { | 56 | { |
55 | setRunning( false ); | 57 | setRunning( false ); |
56 | } | 58 | } |
57 | 59 | ||
58 | void Todo::setRunning( bool run ) | 60 | void Todo::setRunning( bool run ) |
59 | { | 61 | { |
60 | if ( run == mRunning ) | 62 | if ( run == mRunning ) |
61 | return; | 63 | return; |
62 | if ( !mRunSaveTimer ) { | 64 | if ( !mRunSaveTimer ) { |
63 | mRunSaveTimer = new QTimer ( this ); | 65 | mRunSaveTimer = new QTimer ( this ); |
64 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 66 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
65 | } | 67 | } |
66 | mRunning = run; | 68 | mRunning = run; |
67 | if ( mRunning ) { | 69 | if ( mRunning ) { |
68 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 70 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
69 | mRunStart = QDateTime::currentDateTime(); | 71 | mRunStart = QDateTime::currentDateTime(); |
70 | } else { | 72 | } else { |
71 | mRunSaveTimer->stop(); | 73 | mRunSaveTimer->stop(); |
72 | saveRunningInfoToFile(); | 74 | saveRunningInfoToFile(); |
73 | } | 75 | } |
74 | } | 76 | } |
75 | 77 | ||
76 | void Todo::saveRunningInfoToFile() | 78 | void Todo::saveRunningInfoToFile() |
77 | { | 79 | { |
78 | qDebug("Todo::saveRunningInfoToFile() "); | 80 | qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
81 | |||
82 | QString dir = KGlobalSettings::timeTrackerDir(); | ||
83 | qDebug("%s ", dir.latin1()); | ||
84 | QString file = "%1-%2-%3-%4-%5-%6-%7.tt"; | ||
85 | |||
86 | 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 ).arg( mRunStart.time().msec(), 3 ); | ||
87 | file.replace ( QRegExp (" "), "0" ); | ||
88 | file = dir +"/" +file; | ||
89 | qDebug("%s ", file.latin1()); | ||
90 | |||
91 | |||
92 | |||
79 | } | 93 | } |
80 | 94 | ||
81 | int Todo::runTime() | 95 | int Todo::runTime() |
82 | { | 96 | { |
83 | if ( !mRunning ) | 97 | if ( !mRunning ) |
84 | return 0; | 98 | return 0; |
85 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 99 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
86 | } | 100 | } |
87 | bool Todo::hasRunningSub() | 101 | bool Todo::hasRunningSub() |
88 | { | 102 | { |
89 | if ( mRunning ) | 103 | if ( mRunning ) |
90 | return true; | 104 | return true; |
91 | Incidence *aTodo; | 105 | Incidence *aTodo; |
92 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 106 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
93 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 107 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
94 | return true; | 108 | return true; |
95 | } | 109 | } |
96 | return false; | 110 | return false; |
97 | } | 111 | } |
98 | Incidence *Todo::clone() | 112 | Incidence *Todo::clone() |
99 | { | 113 | { |
100 | return new Todo(*this); | 114 | return new Todo(*this); |
101 | } | 115 | } |
102 | 116 | ||
103 | bool Todo::contains ( Todo* from ) | 117 | bool Todo::contains ( Todo* from ) |
104 | { | 118 | { |
105 | 119 | ||
106 | if ( !from->summary().isEmpty() ) | 120 | if ( !from->summary().isEmpty() ) |
107 | if ( !summary().startsWith( from->summary() )) | 121 | if ( !summary().startsWith( from->summary() )) |
108 | return false; | 122 | return false; |
109 | if ( from->hasStartDate() ) { | 123 | if ( from->hasStartDate() ) { |
110 | if ( !hasStartDate() ) | 124 | if ( !hasStartDate() ) |
111 | return false; | 125 | return false; |
112 | if ( from->dtStart() != dtStart()) | 126 | if ( from->dtStart() != dtStart()) |
113 | return false; | 127 | return false; |
114 | } | 128 | } |
115 | if ( from->hasDueDate() ){ | 129 | if ( from->hasDueDate() ){ |
116 | if ( !hasDueDate() ) | 130 | if ( !hasDueDate() ) |
117 | return false; | 131 | return false; |
118 | if ( from->dtDue() != dtDue()) | 132 | if ( from->dtDue() != dtDue()) |
119 | return false; | 133 | return false; |
120 | } | 134 | } |
121 | if ( !from->location().isEmpty() ) | 135 | if ( !from->location().isEmpty() ) |
122 | if ( !location().startsWith( from->location() ) ) | 136 | if ( !location().startsWith( from->location() ) ) |
123 | return false; | 137 | return false; |
124 | if ( !from->description().isEmpty() ) | 138 | if ( !from->description().isEmpty() ) |
125 | if ( !description().startsWith( from->description() )) | 139 | if ( !description().startsWith( from->description() )) |
126 | return false; | 140 | return false; |
127 | if ( from->alarms().count() ) { | 141 | if ( from->alarms().count() ) { |
128 | Alarm *a = from->alarms().first(); | 142 | Alarm *a = from->alarms().first(); |
129 | if ( a->enabled() ){ | 143 | if ( a->enabled() ){ |
130 | if ( !alarms().count() ) | 144 | if ( !alarms().count() ) |
131 | return false; | 145 | return false; |
132 | Alarm *b = alarms().first(); | 146 | Alarm *b = alarms().first(); |
133 | if( ! b->enabled() ) | 147 | if( ! b->enabled() ) |
134 | return false; | 148 | return false; |
135 | if ( ! (a->offset() == b->offset() )) | 149 | if ( ! (a->offset() == b->offset() )) |
136 | return false; | 150 | return false; |
137 | } | 151 | } |
138 | } | 152 | } |
139 | 153 | ||
140 | QStringList cat = categories(); | 154 | QStringList cat = categories(); |
141 | QStringList catFrom = from->categories(); | 155 | QStringList catFrom = from->categories(); |
142 | QString nCat; | 156 | QString nCat; |
143 | unsigned int iii; | 157 | unsigned int iii; |
144 | for ( iii = 0; iii < catFrom.count();++iii ) { | 158 | for ( iii = 0; iii < catFrom.count();++iii ) { |
145 | nCat = catFrom[iii]; | 159 | nCat = catFrom[iii]; |
146 | if ( !nCat.isEmpty() ) | 160 | if ( !nCat.isEmpty() ) |
147 | if ( !cat.contains( nCat )) { | 161 | if ( !cat.contains( nCat )) { |
148 | return false; | 162 | return false; |
149 | } | 163 | } |
150 | } | 164 | } |
151 | if ( from->isCompleted() ) { | 165 | if ( from->isCompleted() ) { |
152 | if ( !isCompleted() ) | 166 | if ( !isCompleted() ) |
153 | return false; | 167 | return false; |
154 | } | 168 | } |
155 | if( priority() != from->priority() ) | 169 | if( priority() != from->priority() ) |
156 | return false; | 170 | return false; |
157 | 171 | ||
158 | 172 | ||
159 | return true; | 173 | return true; |
160 | 174 | ||
161 | } | 175 | } |
162 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 176 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
163 | { | 177 | { |
164 | 178 | ||
165 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 179 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
166 | if ( ! ret ) | 180 | if ( ! ret ) |
167 | return false; | 181 | return false; |
168 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 182 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
169 | if ( t1.hasDueDate() ) { | 183 | if ( t1.hasDueDate() ) { |
170 | if ( t1.doesFloat() == t2.doesFloat() ) { | 184 | if ( t1.doesFloat() == t2.doesFloat() ) { |
171 | if ( t1.doesFloat() ) { | 185 | if ( t1.doesFloat() ) { |
172 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 186 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
173 | return false; | 187 | return false; |
174 | } else | 188 | } else |
175 | if ( t1.dtDue() != t2.dtDue() ) | 189 | if ( t1.dtDue() != t2.dtDue() ) |
176 | return false; | 190 | return false; |
177 | } else | 191 | } else |
178 | return false;// float != | 192 | return false;// float != |
179 | } | 193 | } |
180 | 194 | ||
181 | } else | 195 | } else |
182 | return false; | 196 | return false; |
183 | if ( t1.percentComplete() != t2.percentComplete() ) | 197 | if ( t1.percentComplete() != t2.percentComplete() ) |
184 | return false; | 198 | return false; |
185 | if ( t1.isCompleted() ) { | 199 | if ( t1.isCompleted() ) { |
186 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 200 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
187 | if ( t1.hasCompletedDate() ) { | 201 | if ( t1.hasCompletedDate() ) { |
188 | if ( t1.completed() != t2.completed() ) | 202 | if ( t1.completed() != t2.completed() ) |
189 | return false; | 203 | return false; |
190 | } | 204 | } |
191 | 205 | ||
192 | } else | 206 | } else |
193 | return false; | 207 | return false; |
194 | } | 208 | } |
195 | return true; | 209 | return true; |
196 | 210 | ||
197 | } | 211 | } |
198 | 212 | ||
199 | void Todo::setDtDue(const QDateTime &dtDue) | 213 | void Todo::setDtDue(const QDateTime &dtDue) |
200 | { | 214 | { |
201 | //int diffsecs = mDtDue.secsTo(dtDue); | 215 | //int diffsecs = mDtDue.secsTo(dtDue); |
202 | 216 | ||
203 | /*if (mReadOnly) return; | 217 | /*if (mReadOnly) return; |
204 | const QPtrList<Alarm>& alarms = alarms(); | 218 | const QPtrList<Alarm>& alarms = alarms(); |
205 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 219 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
206 | if (alarm->enabled()) { | 220 | if (alarm->enabled()) { |
207 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 221 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
208 | } | 222 | } |
209 | }*/ | 223 | }*/ |
210 | mDtDue = getEvenTime(dtDue); | 224 | mDtDue = getEvenTime(dtDue); |
211 | 225 | ||
212 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 226 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
213 | 227 | ||
214 | /*const QPtrList<Alarm>& alarms = alarms(); | 228 | /*const QPtrList<Alarm>& alarms = alarms(); |
215 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 229 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
216 | alarm->setAlarmStart(mDtDue);*/ | 230 | alarm->setAlarmStart(mDtDue);*/ |
217 | 231 | ||
218 | updated(); | 232 | updated(); |
219 | } | 233 | } |
220 | 234 | ||
221 | QDateTime Todo::dtDue() const | 235 | QDateTime Todo::dtDue() const |
222 | { | 236 | { |
223 | return mDtDue; | 237 | return mDtDue; |
224 | } | 238 | } |
225 | 239 | ||
226 | QString Todo::dtDueTimeStr() const | 240 | QString Todo::dtDueTimeStr() const |
227 | { | 241 | { |
228 | return KGlobal::locale()->formatTime(mDtDue.time()); | 242 | return KGlobal::locale()->formatTime(mDtDue.time()); |
229 | } | 243 | } |
230 | 244 | ||
231 | QString Todo::dtDueDateStr(bool shortfmt) const | 245 | QString Todo::dtDueDateStr(bool shortfmt) const |
232 | { | 246 | { |
233 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 247 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
234 | } | 248 | } |
235 | 249 | ||
236 | QString Todo::dtDueStr(bool shortfmt) const | 250 | QString Todo::dtDueStr(bool shortfmt) const |
237 | { | 251 | { |
238 | if ( doesFloat() ) | 252 | if ( doesFloat() ) |
239 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 253 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
240 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 254 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
241 | } | 255 | } |
242 | // retval 0 : no found | 256 | // retval 0 : no found |
243 | // 1 : due for date found | 257 | // 1 : due for date found |
244 | // 2 : overdue for date found | 258 | // 2 : overdue for date found |
245 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 259 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
246 | { | 260 | { |
247 | int retval = 0; | 261 | int retval = 0; |
248 | if ( isCompleted() ) | 262 | if ( isCompleted() ) |
249 | return 0; | 263 | return 0; |
250 | if ( hasDueDate() ) { | 264 | if ( hasDueDate() ) { |
251 | if ( dtDue().date() < date ) | 265 | if ( dtDue().date() < date ) |
252 | return 2; | 266 | return 2; |
253 | // we do not return, because we may find an overdue sub todo | 267 | // we do not return, because we may find an overdue sub todo |
254 | if ( dtDue().date() == date ) | 268 | if ( dtDue().date() == date ) |
255 | retval = 1; | 269 | retval = 1; |
256 | } | 270 | } |
257 | if ( checkSubtodos ) { | 271 | if ( checkSubtodos ) { |
258 | Incidence *aTodo; | 272 | Incidence *aTodo; |
259 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 273 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
260 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 274 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
261 | if ( ret == 2 ) | 275 | if ( ret == 2 ) |
262 | return 2; | 276 | return 2; |
263 | if ( ret == 1) | 277 | if ( ret == 1) |
264 | retval = 1; | 278 | retval = 1; |
265 | } | 279 | } |
266 | } | 280 | } |
267 | return retval; | 281 | return retval; |
268 | } | 282 | } |
269 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 283 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
270 | { | 284 | { |
271 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 285 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
272 | } | 286 | } |
273 | bool Todo::hasDueDate() const | 287 | bool Todo::hasDueDate() const |
274 | { | 288 | { |
275 | return mHasDueDate; | 289 | return mHasDueDate; |
276 | } | 290 | } |
277 | 291 | ||
278 | void Todo::setHasDueDate(bool f) | 292 | void Todo::setHasDueDate(bool f) |
279 | { | 293 | { |
280 | if (mReadOnly) return; | 294 | if (mReadOnly) return; |
281 | mHasDueDate = f; | 295 | mHasDueDate = f; |
282 | updated(); | 296 | updated(); |
283 | } | 297 | } |
284 | 298 | ||
285 | 299 | ||
286 | #if 0 | 300 | #if 0 |
287 | void Todo::setStatus(const QString &statStr) | 301 | void Todo::setStatus(const QString &statStr) |
288 | { | 302 | { |
289 | if (mReadOnly) return; | 303 | if (mReadOnly) return; |
290 | QString ss(statStr.upper()); | 304 | QString ss(statStr.upper()); |
291 | 305 | ||
292 | if (ss == "X-ACTION") | 306 | if (ss == "X-ACTION") |
293 | mStatus = NEEDS_ACTION; | 307 | mStatus = NEEDS_ACTION; |
294 | else if (ss == "NEEDS ACTION") | 308 | else if (ss == "NEEDS ACTION") |
295 | mStatus = NEEDS_ACTION; | 309 | mStatus = NEEDS_ACTION; |
296 | else if (ss == "ACCEPTED") | 310 | else if (ss == "ACCEPTED") |
297 | mStatus = ACCEPTED; | 311 | mStatus = ACCEPTED; |
298 | else if (ss == "SENT") | 312 | else if (ss == "SENT") |
299 | mStatus = SENT; | 313 | mStatus = SENT; |
300 | else if (ss == "TENTATIVE") | 314 | else if (ss == "TENTATIVE") |
301 | mStatus = TENTATIVE; | 315 | mStatus = TENTATIVE; |
302 | else if (ss == "CONFIRMED") | 316 | else if (ss == "CONFIRMED") |
303 | mStatus = CONFIRMED; | 317 | mStatus = CONFIRMED; |
304 | else if (ss == "DECLINED") | 318 | else if (ss == "DECLINED") |
305 | mStatus = DECLINED; | 319 | mStatus = DECLINED; |
306 | else if (ss == "COMPLETED") | 320 | else if (ss == "COMPLETED") |
307 | mStatus = COMPLETED; | 321 | mStatus = COMPLETED; |
308 | else if (ss == "DELEGATED") | 322 | else if (ss == "DELEGATED") |
309 | mStatus = DELEGATED; | 323 | mStatus = DELEGATED; |
310 | 324 | ||
311 | updated(); | 325 | updated(); |
312 | } | 326 | } |
313 | 327 | ||
314 | void Todo::setStatus(int status) | 328 | void Todo::setStatus(int status) |
315 | { | 329 | { |
316 | if (mReadOnly) return; | 330 | if (mReadOnly) return; |
317 | mStatus = status; | 331 | mStatus = status; |
318 | updated(); | 332 | updated(); |
319 | } | 333 | } |
320 | 334 | ||
321 | int Todo::status() const | 335 | int Todo::status() const |
322 | { | 336 | { |
323 | return mStatus; | 337 | return mStatus; |
324 | } | 338 | } |
325 | 339 | ||
326 | QString Todo::statusStr() const | 340 | QString Todo::statusStr() const |
327 | { | 341 | { |
328 | switch(mStatus) { | 342 | switch(mStatus) { |
329 | case NEEDS_ACTION: | 343 | case NEEDS_ACTION: |
330 | return QString("NEEDS ACTION"); | 344 | return QString("NEEDS ACTION"); |
331 | break; | 345 | break; |
332 | case ACCEPTED: | 346 | case ACCEPTED: |
333 | return QString("ACCEPTED"); | 347 | return QString("ACCEPTED"); |
334 | break; | 348 | break; |
335 | case SENT: | 349 | case SENT: |
336 | return QString("SENT"); | 350 | return QString("SENT"); |
337 | break; | 351 | break; |
338 | case TENTATIVE: | 352 | case TENTATIVE: |
339 | return QString("TENTATIVE"); | 353 | return QString("TENTATIVE"); |
340 | break; | 354 | break; |
341 | case CONFIRMED: | 355 | case CONFIRMED: |
342 | return QString("CONFIRMED"); | 356 | return QString("CONFIRMED"); |
343 | break; | 357 | break; |
344 | case DECLINED: | 358 | case DECLINED: |
345 | return QString("DECLINED"); | 359 | return QString("DECLINED"); |
346 | break; | 360 | break; |
347 | case COMPLETED: | 361 | case COMPLETED: |
348 | return QString("COMPLETED"); | 362 | return QString("COMPLETED"); |
349 | break; | 363 | break; |
350 | case DELEGATED: | 364 | case DELEGATED: |
351 | return QString("DELEGATED"); | 365 | return QString("DELEGATED"); |
352 | break; | 366 | break; |
353 | } | 367 | } |
354 | return QString(""); | 368 | return QString(""); |
355 | } | 369 | } |
356 | #endif | 370 | #endif |
357 | 371 | ||
358 | bool Todo::isCompleted() const | 372 | bool Todo::isCompleted() const |
359 | { | 373 | { |
360 | if (mPercentComplete == 100) { | 374 | if (mPercentComplete == 100) { |
361 | return true; | 375 | return true; |
362 | } | 376 | } |
363 | else return false; | 377 | else return false; |
364 | } | 378 | } |
365 | 379 | ||
366 | void Todo::setCompleted(bool completed) | 380 | void Todo::setCompleted(bool completed) |
367 | { | 381 | { |
368 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 382 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
369 | if ( !setRecurDates() ) | 383 | if ( !setRecurDates() ) |
370 | completed = false; | 384 | completed = false; |
371 | } | 385 | } |
372 | if (completed) mPercentComplete = 100; | 386 | if (completed) mPercentComplete = 100; |
373 | else { | 387 | else { |
374 | mPercentComplete = 0; | 388 | mPercentComplete = 0; |
375 | mHasCompletedDate = false; | 389 | mHasCompletedDate = false; |
376 | } | 390 | } |
377 | updated(); | 391 | updated(); |
378 | } | 392 | } |
379 | 393 | ||
380 | QDateTime Todo::completed() const | 394 | QDateTime Todo::completed() const |
381 | { | 395 | { |
382 | return mCompleted; | 396 | return mCompleted; |
383 | } | 397 | } |
384 | 398 | ||
385 | QString Todo::completedStr( bool shortF ) const | 399 | QString Todo::completedStr( bool shortF ) const |
386 | { | 400 | { |
387 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 401 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
388 | } | 402 | } |
389 | 403 | ||
390 | void Todo::setCompleted(const QDateTime &completed) | 404 | void Todo::setCompleted(const QDateTime &completed) |
391 | { | 405 | { |
392 | //qDebug("Todo::setCompleted "); | 406 | //qDebug("Todo::setCompleted "); |
393 | if ( mHasCompletedDate ) { | 407 | if ( mHasCompletedDate ) { |
394 | // qDebug("has completed data - return "); | 408 | // qDebug("has completed data - return "); |
395 | return; | 409 | return; |
396 | } | 410 | } |
397 | mHasCompletedDate = true; | 411 | mHasCompletedDate = true; |
398 | mPercentComplete = 100; | 412 | mPercentComplete = 100; |
399 | mCompleted = getEvenTime(completed); | 413 | mCompleted = getEvenTime(completed); |
400 | updated(); | 414 | updated(); |
401 | } | 415 | } |
402 | 416 | ||
403 | bool Todo::hasCompletedDate() const | 417 | bool Todo::hasCompletedDate() const |
404 | { | 418 | { |
405 | return mHasCompletedDate; | 419 | return mHasCompletedDate; |
406 | } | 420 | } |
407 | 421 | ||
408 | int Todo::percentComplete() const | 422 | int Todo::percentComplete() const |
409 | { | 423 | { |
410 | return mPercentComplete; | 424 | return mPercentComplete; |
411 | } | 425 | } |
412 | bool Todo::setRecurDates() | 426 | bool Todo::setRecurDates() |
413 | { | 427 | { |
414 | if ( !mHasRecurrenceID ) | 428 | if ( !mHasRecurrenceID ) |
415 | return true; | 429 | return true; |
416 | int secs = mDtStart.secsTo( dtDue() ); | 430 | int secs = mDtStart.secsTo( dtDue() ); |
417 | bool ok; | 431 | bool ok; |
418 | qDebug("T:setRecurDates() "); | 432 | qDebug("T:setRecurDates() "); |
419 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 433 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
420 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 434 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
421 | if ( ok ) { | 435 | if ( ok ) { |
422 | mRecurrenceID = next; | 436 | mRecurrenceID = next; |
423 | mDtStart = next; | 437 | mDtStart = next; |
424 | setDtDue( next.addSecs( secs ) ); | 438 | setDtDue( next.addSecs( secs ) ); |
425 | if ( QDateTime::currentDateTime() > next) | 439 | if ( QDateTime::currentDateTime() > next) |
426 | return false; | 440 | return false; |
427 | } else { | 441 | } else { |
428 | setHasRecurrenceID( false ); | 442 | setHasRecurrenceID( false ); |
429 | recurrence()->unsetRecurs(); | 443 | recurrence()->unsetRecurs(); |
430 | } | 444 | } |
431 | return true; | 445 | return true; |
432 | } | 446 | } |
433 | void Todo::setPercentComplete(int v) | 447 | void Todo::setPercentComplete(int v) |
434 | { | 448 | { |
435 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 449 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
436 | if ( !setRecurDates() ) | 450 | if ( !setRecurDates() ) |
437 | v = 0; | 451 | v = 0; |
438 | } | 452 | } |
439 | mPercentComplete = v; | 453 | mPercentComplete = v; |
440 | if ( v != 100 ) | 454 | if ( v != 100 ) |
441 | mHasCompletedDate = false; | 455 | mHasCompletedDate = false; |
442 | updated(); | 456 | updated(); |
443 | } | 457 | } |
444 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const | 458 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const |
445 | { | 459 | { |
446 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { | 460 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { |
447 | *ok = false; | 461 | *ok = false; |
448 | return QDateTime (); | 462 | return QDateTime (); |
449 | } | 463 | } |
450 | QDateTime incidenceStart; | 464 | QDateTime incidenceStart; |
451 | incidenceStart = dtDue(); | 465 | incidenceStart = dtDue(); |
452 | bool enabled = false; | 466 | bool enabled = false; |
453 | Alarm* alarm; | 467 | Alarm* alarm; |
454 | int off = 0; | 468 | int off = 0; |
455 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 469 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
456 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 470 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
457 | // *ok = false; | 471 | // *ok = false; |
458 | // return incidenceStart; | 472 | // return incidenceStart; |
459 | // } | 473 | // } |
460 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 474 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
461 | if (alarm->enabled()) { | 475 | if (alarm->enabled()) { |
462 | if ( alarm->hasTime () ) { | 476 | if ( alarm->hasTime () ) { |
463 | if ( alarm->time() < alarmStart ) { | 477 | if ( alarm->time() < alarmStart ) { |
464 | alarmStart = alarm->time(); | 478 | alarmStart = alarm->time(); |
465 | enabled = true; | 479 | enabled = true; |
466 | off = alarmStart.secsTo( incidenceStart ); | 480 | off = alarmStart.secsTo( incidenceStart ); |
467 | } | 481 | } |
468 | 482 | ||
469 | } else { | 483 | } else { |
470 | int secs = alarm->startOffset().asSeconds(); | 484 | int secs = alarm->startOffset().asSeconds(); |
471 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 485 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
472 | alarmStart = incidenceStart.addSecs( secs ); | 486 | alarmStart = incidenceStart.addSecs( secs ); |
473 | enabled = true; | 487 | enabled = true; |
474 | off = -secs; | 488 | off = -secs; |
475 | } | 489 | } |
476 | } | 490 | } |
477 | } | 491 | } |
478 | } | 492 | } |
479 | if ( enabled ) { | 493 | if ( enabled ) { |
480 | if ( alarmStart > QDateTime::currentDateTime() ) { | 494 | if ( alarmStart > QDateTime::currentDateTime() ) { |
481 | *ok = true; | 495 | *ok = true; |
482 | * offset = off; | 496 | * offset = off; |
483 | return alarmStart; | 497 | return alarmStart; |
484 | } | 498 | } |
485 | } | 499 | } |
486 | *ok = false; | 500 | *ok = false; |
487 | return QDateTime (); | 501 | return QDateTime (); |
488 | 502 | ||
489 | } | 503 | } |
490 | 504 | ||
491 | void Todo::checkSetCompletedFalse() | 505 | void Todo::checkSetCompletedFalse() |
492 | { | 506 | { |
493 | if ( !hasRecurrenceID() ) { | 507 | if ( !hasRecurrenceID() ) { |
494 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 508 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
495 | } | 509 | } |
496 | // qDebug("Todo::checkSetCompletedFalse()"); | 510 | // qDebug("Todo::checkSetCompletedFalse()"); |
497 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 511 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
498 | if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { | 512 | if ( mPercentComplete == 100 && mDtStart == mRecurrenceID && QDateTime::currentDateTime() > mDtStart) { |
499 | qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 513 | qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
500 | setCompleted( false ); | 514 | setCompleted( false ); |
501 | qDebug("Todo::checkSetCompletedFalse "); | 515 | qDebug("Todo::checkSetCompletedFalse "); |
502 | } | 516 | } |
503 | } | 517 | } |