-rw-r--r-- | libkcal/todo.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 7f1de78..d81a68f 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,384 +1,414 @@ | |||
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 <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "todo.h" | 25 | #include "todo.h" |
26 | 26 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Todo::Todo(): Incidence() | 29 | Todo::Todo(): Incidence() |
30 | { | 30 | { |
31 | // mStatus = TENTATIVE; | 31 | // mStatus = TENTATIVE; |
32 | 32 | ||
33 | mHasDueDate = false; | 33 | mHasDueDate = false; |
34 | setHasStartDate( false ); | 34 | setHasStartDate( false ); |
35 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 35 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
36 | mHasCompletedDate = false; | 36 | mHasCompletedDate = false; |
37 | mPercentComplete = 0; | 37 | mPercentComplete = 0; |
38 | } | 38 | } |
39 | 39 | ||
40 | Todo::Todo(const Todo &t) : Incidence(t) | 40 | Todo::Todo(const Todo &t) : Incidence(t) |
41 | { | 41 | { |
42 | mDtDue = t.mDtDue; | 42 | mDtDue = t.mDtDue; |
43 | mHasDueDate = t.mHasDueDate; | 43 | mHasDueDate = t.mHasDueDate; |
44 | mCompleted = t.mCompleted; | 44 | mCompleted = t.mCompleted; |
45 | mHasCompletedDate = t.mHasCompletedDate; | 45 | mHasCompletedDate = t.mHasCompletedDate; |
46 | mPercentComplete = t.mPercentComplete; | 46 | mPercentComplete = t.mPercentComplete; |
47 | } | 47 | } |
48 | 48 | ||
49 | Todo::~Todo() | 49 | Todo::~Todo() |
50 | { | 50 | { |
51 | 51 | ||
52 | } | 52 | } |
53 | 53 | ||
54 | Incidence *Todo::clone() | 54 | Incidence *Todo::clone() |
55 | { | 55 | { |
56 | return new Todo(*this); | 56 | return new Todo(*this); |
57 | } | 57 | } |
58 | 58 | ||
59 | bool Todo::contains ( Todo* from ) | 59 | bool Todo::contains ( Todo* from ) |
60 | { | 60 | { |
61 | 61 | ||
62 | if ( !from->summary().isEmpty() ) | 62 | if ( !from->summary().isEmpty() ) |
63 | if ( !summary().startsWith( from->summary() )) | 63 | if ( !summary().startsWith( from->summary() )) |
64 | return false; | 64 | return false; |
65 | if ( from->hasStartDate() ) { | 65 | if ( from->hasStartDate() ) { |
66 | if ( !hasStartDate() ) | 66 | if ( !hasStartDate() ) |
67 | return false; | 67 | return false; |
68 | if ( from->dtStart() != dtStart()) | 68 | if ( from->dtStart() != dtStart()) |
69 | return false; | 69 | return false; |
70 | } | 70 | } |
71 | if ( from->hasDueDate() ){ | 71 | if ( from->hasDueDate() ){ |
72 | if ( !hasDueDate() ) | 72 | if ( !hasDueDate() ) |
73 | return false; | 73 | return false; |
74 | if ( from->dtDue() != dtDue()) | 74 | if ( from->dtDue() != dtDue()) |
75 | return false; | 75 | return false; |
76 | } | 76 | } |
77 | if ( !from->location().isEmpty() ) | 77 | if ( !from->location().isEmpty() ) |
78 | if ( !location().startsWith( from->location() ) ) | 78 | if ( !location().startsWith( from->location() ) ) |
79 | return false; | 79 | return false; |
80 | if ( !from->description().isEmpty() ) | 80 | if ( !from->description().isEmpty() ) |
81 | if ( !description().startsWith( from->description() )) | 81 | if ( !description().startsWith( from->description() )) |
82 | return false; | 82 | return false; |
83 | if ( from->alarms().count() ) { | 83 | if ( from->alarms().count() ) { |
84 | Alarm *a = from->alarms().first(); | 84 | Alarm *a = from->alarms().first(); |
85 | if ( a->enabled() ){ | 85 | if ( a->enabled() ){ |
86 | if ( !alarms().count() ) | 86 | if ( !alarms().count() ) |
87 | return false; | 87 | return false; |
88 | Alarm *b = alarms().first(); | 88 | Alarm *b = alarms().first(); |
89 | if( ! b->enabled() ) | 89 | if( ! b->enabled() ) |
90 | return false; | 90 | return false; |
91 | if ( ! (a->offset() == b->offset() )) | 91 | if ( ! (a->offset() == b->offset() )) |
92 | return false; | 92 | return false; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | QStringList cat = categories(); | 96 | QStringList cat = categories(); |
97 | QStringList catFrom = from->categories(); | 97 | QStringList catFrom = from->categories(); |
98 | QString nCat; | 98 | QString nCat; |
99 | int iii; | 99 | int iii; |
100 | for ( iii = 0; iii < catFrom.count();++iii ) { | 100 | for ( iii = 0; iii < catFrom.count();++iii ) { |
101 | nCat = catFrom[iii]; | 101 | nCat = catFrom[iii]; |
102 | if ( !nCat.isEmpty() ) | 102 | if ( !nCat.isEmpty() ) |
103 | if ( !cat.contains( nCat )) { | 103 | if ( !cat.contains( nCat )) { |
104 | return false; | 104 | return false; |
105 | } | 105 | } |
106 | } | 106 | } |
107 | if ( from->isCompleted() ) { | 107 | if ( from->isCompleted() ) { |
108 | if ( !isCompleted() ) | 108 | if ( !isCompleted() ) |
109 | return false; | 109 | return false; |
110 | } | 110 | } |
111 | if( priority() != from->priority() ) | 111 | if( priority() != from->priority() ) |
112 | return false; | 112 | return false; |
113 | 113 | ||
114 | 114 | ||
115 | return true; | 115 | return true; |
116 | 116 | ||
117 | } | 117 | } |
118 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 118 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
119 | { | 119 | { |
120 | 120 | ||
121 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 121 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
122 | if ( ! ret ) | 122 | if ( ! ret ) |
123 | return false; | 123 | return false; |
124 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 124 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
125 | if ( t1.hasDueDate() ) { | 125 | if ( t1.hasDueDate() ) { |
126 | if ( t1.doesFloat() == t2.doesFloat() ) { | 126 | if ( t1.doesFloat() == t2.doesFloat() ) { |
127 | if ( t1.doesFloat() ) { | 127 | if ( t1.doesFloat() ) { |
128 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 128 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
129 | return false; | 129 | return false; |
130 | } else | 130 | } else |
131 | if ( t1.dtDue() != t2.dtDue() ) | 131 | if ( t1.dtDue() != t2.dtDue() ) |
132 | return false; | 132 | return false; |
133 | } else | 133 | } else |
134 | return false;// float != | 134 | return false;// float != |
135 | } | 135 | } |
136 | 136 | ||
137 | } else | 137 | } else |
138 | return false; | 138 | return false; |
139 | if ( t1.percentComplete() != t2.percentComplete() ) | 139 | if ( t1.percentComplete() != t2.percentComplete() ) |
140 | return false; | 140 | return false; |
141 | if ( t1.isCompleted() ) { | 141 | if ( t1.isCompleted() ) { |
142 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 142 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
143 | if ( t1.hasCompletedDate() ) { | 143 | if ( t1.hasCompletedDate() ) { |
144 | if ( t1.completed() != t2.completed() ) | 144 | if ( t1.completed() != t2.completed() ) |
145 | return false; | 145 | return false; |
146 | } | 146 | } |
147 | 147 | ||
148 | } else | 148 | } else |
149 | return false; | 149 | return false; |
150 | } | 150 | } |
151 | return true; | 151 | return true; |
152 | 152 | ||
153 | } | 153 | } |
154 | 154 | ||
155 | void Todo::setDtDue(const QDateTime &dtDue) | 155 | void Todo::setDtDue(const QDateTime &dtDue) |
156 | { | 156 | { |
157 | //int diffsecs = mDtDue.secsTo(dtDue); | 157 | //int diffsecs = mDtDue.secsTo(dtDue); |
158 | 158 | ||
159 | /*if (mReadOnly) return; | 159 | /*if (mReadOnly) return; |
160 | const QPtrList<Alarm>& alarms = alarms(); | 160 | const QPtrList<Alarm>& alarms = alarms(); |
161 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 161 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
162 | if (alarm->enabled()) { | 162 | if (alarm->enabled()) { |
163 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 163 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
164 | } | 164 | } |
165 | }*/ | 165 | }*/ |
166 | mDtDue = getEvenTime(dtDue); | 166 | mDtDue = getEvenTime(dtDue); |
167 | 167 | ||
168 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 168 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
169 | 169 | ||
170 | /*const QPtrList<Alarm>& alarms = alarms(); | 170 | /*const QPtrList<Alarm>& alarms = alarms(); |
171 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 171 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
172 | alarm->setAlarmStart(mDtDue);*/ | 172 | alarm->setAlarmStart(mDtDue);*/ |
173 | 173 | ||
174 | updated(); | 174 | updated(); |
175 | } | 175 | } |
176 | 176 | ||
177 | QDateTime Todo::dtDue() const | 177 | QDateTime Todo::dtDue() const |
178 | { | 178 | { |
179 | return mDtDue; | 179 | return mDtDue; |
180 | } | 180 | } |
181 | 181 | ||
182 | QString Todo::dtDueTimeStr() const | 182 | QString Todo::dtDueTimeStr() const |
183 | { | 183 | { |
184 | return KGlobal::locale()->formatTime(mDtDue.time()); | 184 | return KGlobal::locale()->formatTime(mDtDue.time()); |
185 | } | 185 | } |
186 | 186 | ||
187 | QString Todo::dtDueDateStr(bool shortfmt) const | 187 | QString Todo::dtDueDateStr(bool shortfmt) const |
188 | { | 188 | { |
189 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 189 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
190 | } | 190 | } |
191 | 191 | ||
192 | QString Todo::dtDueStr(bool shortfmt) const | 192 | QString Todo::dtDueStr(bool shortfmt) const |
193 | { | 193 | { |
194 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 194 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
195 | } | 195 | } |
196 | 196 | // retval 0 : no found | |
197 | // 1 : due for date found | ||
198 | // 2 : overdue for date found | ||
199 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | ||
200 | { | ||
201 | int retval = 0; | ||
202 | if ( isCompleted() ) | ||
203 | return 0; | ||
204 | if ( hasDueDate() ) { | ||
205 | if ( dtDue().date() < date ) | ||
206 | return 2; | ||
207 | // we do not return, because we may find an overdue sub todo | ||
208 | if ( dtDue().date() == date ) | ||
209 | retval = 1; | ||
210 | } | ||
211 | if ( checkSubtodos ) { | ||
212 | Incidence *aTodo; | ||
213 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | ||
214 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | ||
215 | if ( ret == 2 ) | ||
216 | return 2; | ||
217 | if ( ret == 1) | ||
218 | retval = 1; | ||
219 | } | ||
220 | } | ||
221 | return retval; | ||
222 | } | ||
223 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | ||
224 | { | ||
225 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | ||
226 | } | ||
197 | bool Todo::hasDueDate() const | 227 | bool Todo::hasDueDate() const |
198 | { | 228 | { |
199 | return mHasDueDate; | 229 | return mHasDueDate; |
200 | } | 230 | } |
201 | 231 | ||
202 | void Todo::setHasDueDate(bool f) | 232 | void Todo::setHasDueDate(bool f) |
203 | { | 233 | { |
204 | if (mReadOnly) return; | 234 | if (mReadOnly) return; |
205 | mHasDueDate = f; | 235 | mHasDueDate = f; |
206 | updated(); | 236 | updated(); |
207 | } | 237 | } |
208 | 238 | ||
209 | 239 | ||
210 | #if 0 | 240 | #if 0 |
211 | void Todo::setStatus(const QString &statStr) | 241 | void Todo::setStatus(const QString &statStr) |
212 | { | 242 | { |
213 | if (mReadOnly) return; | 243 | if (mReadOnly) return; |
214 | QString ss(statStr.upper()); | 244 | QString ss(statStr.upper()); |
215 | 245 | ||
216 | if (ss == "X-ACTION") | 246 | if (ss == "X-ACTION") |
217 | mStatus = NEEDS_ACTION; | 247 | mStatus = NEEDS_ACTION; |
218 | else if (ss == "NEEDS ACTION") | 248 | else if (ss == "NEEDS ACTION") |
219 | mStatus = NEEDS_ACTION; | 249 | mStatus = NEEDS_ACTION; |
220 | else if (ss == "ACCEPTED") | 250 | else if (ss == "ACCEPTED") |
221 | mStatus = ACCEPTED; | 251 | mStatus = ACCEPTED; |
222 | else if (ss == "SENT") | 252 | else if (ss == "SENT") |
223 | mStatus = SENT; | 253 | mStatus = SENT; |
224 | else if (ss == "TENTATIVE") | 254 | else if (ss == "TENTATIVE") |
225 | mStatus = TENTATIVE; | 255 | mStatus = TENTATIVE; |
226 | else if (ss == "CONFIRMED") | 256 | else if (ss == "CONFIRMED") |
227 | mStatus = CONFIRMED; | 257 | mStatus = CONFIRMED; |
228 | else if (ss == "DECLINED") | 258 | else if (ss == "DECLINED") |
229 | mStatus = DECLINED; | 259 | mStatus = DECLINED; |
230 | else if (ss == "COMPLETED") | 260 | else if (ss == "COMPLETED") |
231 | mStatus = COMPLETED; | 261 | mStatus = COMPLETED; |
232 | else if (ss == "DELEGATED") | 262 | else if (ss == "DELEGATED") |
233 | mStatus = DELEGATED; | 263 | mStatus = DELEGATED; |
234 | 264 | ||
235 | updated(); | 265 | updated(); |
236 | } | 266 | } |
237 | 267 | ||
238 | void Todo::setStatus(int status) | 268 | void Todo::setStatus(int status) |
239 | { | 269 | { |
240 | if (mReadOnly) return; | 270 | if (mReadOnly) return; |
241 | mStatus = status; | 271 | mStatus = status; |
242 | updated(); | 272 | updated(); |
243 | } | 273 | } |
244 | 274 | ||
245 | int Todo::status() const | 275 | int Todo::status() const |
246 | { | 276 | { |
247 | return mStatus; | 277 | return mStatus; |
248 | } | 278 | } |
249 | 279 | ||
250 | QString Todo::statusStr() const | 280 | QString Todo::statusStr() const |
251 | { | 281 | { |
252 | switch(mStatus) { | 282 | switch(mStatus) { |
253 | case NEEDS_ACTION: | 283 | case NEEDS_ACTION: |
254 | return QString("NEEDS ACTION"); | 284 | return QString("NEEDS ACTION"); |
255 | break; | 285 | break; |
256 | case ACCEPTED: | 286 | case ACCEPTED: |
257 | return QString("ACCEPTED"); | 287 | return QString("ACCEPTED"); |
258 | break; | 288 | break; |
259 | case SENT: | 289 | case SENT: |
260 | return QString("SENT"); | 290 | return QString("SENT"); |
261 | break; | 291 | break; |
262 | case TENTATIVE: | 292 | case TENTATIVE: |
263 | return QString("TENTATIVE"); | 293 | return QString("TENTATIVE"); |
264 | break; | 294 | break; |
265 | case CONFIRMED: | 295 | case CONFIRMED: |
266 | return QString("CONFIRMED"); | 296 | return QString("CONFIRMED"); |
267 | break; | 297 | break; |
268 | case DECLINED: | 298 | case DECLINED: |
269 | return QString("DECLINED"); | 299 | return QString("DECLINED"); |
270 | break; | 300 | break; |
271 | case COMPLETED: | 301 | case COMPLETED: |
272 | return QString("COMPLETED"); | 302 | return QString("COMPLETED"); |
273 | break; | 303 | break; |
274 | case DELEGATED: | 304 | case DELEGATED: |
275 | return QString("DELEGATED"); | 305 | return QString("DELEGATED"); |
276 | break; | 306 | break; |
277 | } | 307 | } |
278 | return QString(""); | 308 | return QString(""); |
279 | } | 309 | } |
280 | #endif | 310 | #endif |
281 | 311 | ||
282 | bool Todo::isCompleted() const | 312 | bool Todo::isCompleted() const |
283 | { | 313 | { |
284 | if (mPercentComplete == 100) return true; | 314 | if (mPercentComplete == 100) return true; |
285 | else return false; | 315 | else return false; |
286 | } | 316 | } |
287 | 317 | ||
288 | void Todo::setCompleted(bool completed) | 318 | void Todo::setCompleted(bool completed) |
289 | { | 319 | { |
290 | if (completed) mPercentComplete = 100; | 320 | if (completed) mPercentComplete = 100; |
291 | else { | 321 | else { |
292 | mPercentComplete = 0; | 322 | mPercentComplete = 0; |
293 | mHasCompletedDate = false; | 323 | mHasCompletedDate = false; |
294 | } | 324 | } |
295 | updated(); | 325 | updated(); |
296 | } | 326 | } |
297 | 327 | ||
298 | QDateTime Todo::completed() const | 328 | QDateTime Todo::completed() const |
299 | { | 329 | { |
300 | return mCompleted; | 330 | return mCompleted; |
301 | } | 331 | } |
302 | 332 | ||
303 | QString Todo::completedStr( bool shortF ) const | 333 | QString Todo::completedStr( bool shortF ) const |
304 | { | 334 | { |
305 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 335 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
306 | } | 336 | } |
307 | 337 | ||
308 | void Todo::setCompleted(const QDateTime &completed) | 338 | void Todo::setCompleted(const QDateTime &completed) |
309 | { | 339 | { |
310 | //qDebug("Todo::setCompleted "); | 340 | //qDebug("Todo::setCompleted "); |
311 | if ( mHasCompletedDate ) { | 341 | if ( mHasCompletedDate ) { |
312 | // qDebug("has completed data - return "); | 342 | // qDebug("has completed data - return "); |
313 | return; | 343 | return; |
314 | } | 344 | } |
315 | mHasCompletedDate = true; | 345 | mHasCompletedDate = true; |
316 | mPercentComplete = 100; | 346 | mPercentComplete = 100; |
317 | mCompleted = getEvenTime(completed); | 347 | mCompleted = getEvenTime(completed); |
318 | updated(); | 348 | updated(); |
319 | } | 349 | } |
320 | 350 | ||
321 | bool Todo::hasCompletedDate() const | 351 | bool Todo::hasCompletedDate() const |
322 | { | 352 | { |
323 | return mHasCompletedDate; | 353 | return mHasCompletedDate; |
324 | } | 354 | } |
325 | 355 | ||
326 | int Todo::percentComplete() const | 356 | int Todo::percentComplete() const |
327 | { | 357 | { |
328 | return mPercentComplete; | 358 | return mPercentComplete; |
329 | } | 359 | } |
330 | 360 | ||
331 | void Todo::setPercentComplete(int v) | 361 | void Todo::setPercentComplete(int v) |
332 | { | 362 | { |
333 | mPercentComplete = v; | 363 | mPercentComplete = v; |
334 | if ( v != 100 ) | 364 | if ( v != 100 ) |
335 | mHasCompletedDate = false; | 365 | mHasCompletedDate = false; |
336 | updated(); | 366 | updated(); |
337 | } | 367 | } |
338 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const | 368 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset ) const |
339 | { | 369 | { |
340 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { | 370 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { |
341 | *ok = false; | 371 | *ok = false; |
342 | return QDateTime (); | 372 | return QDateTime (); |
343 | } | 373 | } |
344 | QDateTime incidenceStart; | 374 | QDateTime incidenceStart; |
345 | incidenceStart = dtDue(); | 375 | incidenceStart = dtDue(); |
346 | bool enabled = false; | 376 | bool enabled = false; |
347 | Alarm* alarm; | 377 | Alarm* alarm; |
348 | int off; | 378 | int off; |
349 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 379 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
350 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 380 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
351 | // *ok = false; | 381 | // *ok = false; |
352 | // return incidenceStart; | 382 | // return incidenceStart; |
353 | // } | 383 | // } |
354 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 384 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
355 | if (alarm->enabled()) { | 385 | if (alarm->enabled()) { |
356 | if ( alarm->hasTime () ) { | 386 | if ( alarm->hasTime () ) { |
357 | if ( alarm->time() < alarmStart ) { | 387 | if ( alarm->time() < alarmStart ) { |
358 | alarmStart = alarm->time(); | 388 | alarmStart = alarm->time(); |
359 | enabled = true; | 389 | enabled = true; |
360 | off = alarmStart.secsTo( incidenceStart ); | 390 | off = alarmStart.secsTo( incidenceStart ); |
361 | } | 391 | } |
362 | 392 | ||
363 | } else { | 393 | } else { |
364 | int secs = alarm->startOffset().asSeconds(); | 394 | int secs = alarm->startOffset().asSeconds(); |
365 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 395 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
366 | alarmStart = incidenceStart.addSecs( secs ); | 396 | alarmStart = incidenceStart.addSecs( secs ); |
367 | enabled = true; | 397 | enabled = true; |
368 | off = -secs; | 398 | off = -secs; |
369 | } | 399 | } |
370 | } | 400 | } |
371 | } | 401 | } |
372 | } | 402 | } |
373 | if ( enabled ) { | 403 | if ( enabled ) { |
374 | if ( alarmStart > QDateTime::currentDateTime() ) { | 404 | if ( alarmStart > QDateTime::currentDateTime() ) { |
375 | *ok = true; | 405 | *ok = true; |
376 | * offset = off; | 406 | * offset = off; |
377 | return alarmStart; | 407 | return alarmStart; |
378 | } | 408 | } |
379 | } | 409 | } |
380 | *ok = false; | 410 | *ok = false; |
381 | return QDateTime (); | 411 | return QDateTime (); |
382 | 412 | ||
383 | } | 413 | } |
384 | 414 | ||