-rw-r--r-- | library/datebookdb.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index e4ec2bf..165a637 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -201,384 +201,387 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) | |||
201 | imonth = imonth % 12; | 201 | imonth = imonth % 12; |
202 | imonth++; | 202 | imonth++; |
203 | } | 203 | } |
204 | tmpDate = QDate( iyear, imonth, 1 ); | 204 | tmpDate = QDate( iyear, imonth, 1 ); |
205 | /* these loops could go for a while, check end case now */ | 205 | /* these loops could go for a while, check end case now */ |
206 | if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 206 | if ((tmpDate > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
207 | return FALSE; | 207 | return FALSE; |
208 | iday = 1; | 208 | iday = 1; |
209 | iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; | 209 | iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7; |
210 | iday += 7 * weekOfMonth; | 210 | iday += 7 * weekOfMonth; |
211 | } while (iday > tmpDate.daysInMonth()); | 211 | } while (iday > tmpDate.daysInMonth()); |
212 | tmpDate = QDate(iyear, imonth, iday); | 212 | tmpDate = QDate(iyear, imonth, iday); |
213 | 213 | ||
214 | next = QDateTime(tmpDate, e.start().time()); | 214 | next = QDateTime(tmpDate, e.start().time()); |
215 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 215 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
216 | return FALSE; | 216 | return FALSE; |
217 | return TRUE; | 217 | return TRUE; |
218 | case Event::MonthlyDate: | 218 | case Event::MonthlyDate: |
219 | iday = e.start().date().day(); | 219 | iday = e.start().date().day(); |
220 | iyear = from.year(); | 220 | iyear = from.year(); |
221 | imonth = from.month(); | 221 | imonth = from.month(); |
222 | 222 | ||
223 | a = from.year() - e.start().date().year(); | 223 | a = from.year() - e.start().date().year(); |
224 | a *= 12; | 224 | a *= 12; |
225 | a = a + (imonth - e.start().date().month()); | 225 | a = a + (imonth - e.start().date().month()); |
226 | /* a is e.start()monthsFrom(from); */ | 226 | /* a is e.start()monthsFrom(from); */ |
227 | if(a % freq) { | 227 | if(a % freq) { |
228 | a = freq - (a % freq); | 228 | a = freq - (a % freq); |
229 | imonth = from.month() + a; | 229 | imonth = from.month() + a; |
230 | if (imonth > 12) { | 230 | if (imonth > 12) { |
231 | imonth--; | 231 | imonth--; |
232 | iyear += imonth / 12; | 232 | iyear += imonth / 12; |
233 | imonth = imonth % 12; | 233 | imonth = imonth % 12; |
234 | imonth++; | 234 | imonth++; |
235 | } | 235 | } |
236 | } | 236 | } |
237 | /* imonth is now the first month after or on | 237 | /* imonth is now the first month after or on |
238 | from that matches the frequencey given */ | 238 | from that matches the frequencey given */ |
239 | 239 | ||
240 | /* this could go for a while, worse case, 4*12 iterations, probably */ | 240 | /* this could go for a while, worse case, 4*12 iterations, probably */ |
241 | while(!QDate::isValid(iyear, imonth, iday) ) { | 241 | while(!QDate::isValid(iyear, imonth, iday) ) { |
242 | imonth += freq; | 242 | imonth += freq; |
243 | if (imonth > 12) { | 243 | if (imonth > 12) { |
244 | imonth--; | 244 | imonth--; |
245 | iyear += imonth / 12; | 245 | iyear += imonth / 12; |
246 | imonth = imonth % 12; | 246 | imonth = imonth % 12; |
247 | imonth++; | 247 | imonth++; |
248 | } | 248 | } |
249 | /* these loops could go for a while, check end case now */ | 249 | /* these loops could go for a while, check end case now */ |
250 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 250 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
251 | return FALSE; | 251 | return FALSE; |
252 | } | 252 | } |
253 | 253 | ||
254 | if(QDate(iyear, imonth, iday) >= from) { | 254 | if(QDate(iyear, imonth, iday) >= from) { |
255 | /* done */ | 255 | /* done */ |
256 | next = QDateTime(QDate(iyear, imonth, iday), | 256 | next = QDateTime(QDate(iyear, imonth, iday), |
257 | e.start().time()); | 257 | e.start().time()); |
258 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 258 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
259 | return FALSE; | 259 | return FALSE; |
260 | return TRUE; | 260 | return TRUE; |
261 | } | 261 | } |
262 | 262 | ||
263 | /* ok, need to cycle */ | 263 | /* ok, need to cycle */ |
264 | imonth += freq; | 264 | imonth += freq; |
265 | imonth--; | 265 | imonth--; |
266 | iyear += imonth / 12; | 266 | iyear += imonth / 12; |
267 | imonth = imonth % 12; | 267 | imonth = imonth % 12; |
268 | imonth++; | 268 | imonth++; |
269 | 269 | ||
270 | while(!QDate::isValid(iyear, imonth, iday) ) { | 270 | while(!QDate::isValid(iyear, imonth, iday) ) { |
271 | imonth += freq; | 271 | imonth += freq; |
272 | imonth--; | 272 | imonth--; |
273 | iyear += imonth / 12; | 273 | iyear += imonth / 12; |
274 | imonth = imonth % 12; | 274 | imonth = imonth % 12; |
275 | imonth++; | 275 | imonth++; |
276 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 276 | if ((QDate(iyear, imonth, 1) > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
277 | return FALSE; | 277 | return FALSE; |
278 | } | 278 | } |
279 | 279 | ||
280 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); | 280 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); |
281 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 281 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
282 | return FALSE; | 282 | return FALSE; |
283 | return TRUE; | 283 | return TRUE; |
284 | case Event::Yearly: | 284 | case Event::Yearly: |
285 | iday = e.start().date().day(); | 285 | iday = e.start().date().day(); |
286 | imonth = e.start().date().month(); | 286 | imonth = e.start().date().month(); |
287 | iyear = from.year(); // after all, we want to start in this year | 287 | iyear = from.year(); // after all, we want to start in this year |
288 | 288 | ||
289 | diff = 1; | 289 | diff = 1; |
290 | if(imonth == 2 && iday > 28) { | 290 | if(imonth == 2 && iday > 28) { |
291 | /* leap year, and it counts, calculate actual frequency */ | 291 | /* leap year, and it counts, calculate actual frequency */ |
292 | if(freq % 4) | 292 | if(freq % 4) |
293 | if (freq % 2) | 293 | if (freq % 2) |
294 | freq = freq * 4; | 294 | freq = freq * 4; |
295 | else | 295 | else |
296 | freq = freq * 2; | 296 | freq = freq * 2; |
297 | /* else divides by 4 already, leave freq alone */ | 297 | /* else divides by 4 already, leave freq alone */ |
298 | diff = 4; | 298 | diff = 4; |
299 | } | 299 | } |
300 | 300 | ||
301 | a = from.year() - e.start().date().year(); | 301 | a = from.year() - e.start().date().year(); |
302 | if(a % freq) { | 302 | if(a % freq) { |
303 | a = freq - (a % freq); | 303 | a = freq - (a % freq); |
304 | iyear = iyear + a; | 304 | iyear = iyear + a; |
305 | } | 305 | } |
306 | 306 | ||
307 | /* under the assumption we won't hit one of the special not-leap years twice */ | 307 | /* under the assumption we won't hit one of the special not-leap years twice */ |
308 | if(!QDate::isValid(iyear, imonth, iday)) { | 308 | if(!QDate::isValid(iyear, imonth, iday)) { |
309 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 309 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
310 | iyear += freq; | 310 | iyear += freq; |
311 | } | 311 | } |
312 | 312 | ||
313 | if(QDate(iyear, imonth, iday) >= from) { | 313 | if(QDate(iyear, imonth, iday) >= from) { |
314 | next = QDateTime(QDate(iyear, imonth, iday), | 314 | next = QDateTime(QDate(iyear, imonth, iday), |
315 | e.start().time()); | 315 | e.start().time()); |
316 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 316 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
317 | return FALSE; | 317 | return FALSE; |
318 | return TRUE; | 318 | return TRUE; |
319 | } | 319 | } |
320 | /* iyear == from.year(), need to advance again */ | 320 | /* iyear == from.year(), need to advance again */ |
321 | iyear += freq; | 321 | iyear += freq; |
322 | /* under the assumption we won't hit one of the special not-leap years twice */ | 322 | /* under the assumption we won't hit one of the special not-leap years twice */ |
323 | if(!QDate::isValid(iyear, imonth, iday)) { | 323 | if(!QDate::isValid(iyear, imonth, iday)) { |
324 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ | 324 | /* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */ |
325 | iyear += freq; | 325 | iyear += freq; |
326 | } | 326 | } |
327 | 327 | ||
328 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); | 328 | next = QDateTime(QDate(iyear, imonth, iday), e.start().time()); |
329 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) | 329 | if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate) |
330 | return FALSE; | 330 | return FALSE; |
331 | return TRUE; | 331 | return TRUE; |
332 | default: | 332 | default: |
333 | return FALSE; | 333 | return FALSE; |
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) | 337 | static bool nextAlarm( const Event &ev, QDateTime& when, int& warn) |
338 | { | 338 | { |
339 | QDateTime now = QDateTime::currentDateTime(); | 339 | QDateTime now = QDateTime::currentDateTime(); |
340 | if ( ev.hasRepeat() ) { | 340 | if ( ev.hasRepeat() ) { |
341 | QDateTime ralarm; | 341 | QDateTime ralarm; |
342 | if (nextOccurance(ev, now.date(), ralarm)) { | 342 | if (nextOccurance(ev, now.date(), ralarm)) { |
343 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); | 343 | ralarm = ralarm.addSecs(-ev.alarmTime()*60); |
344 | if ( ralarm > now ) { | 344 | if ( ralarm > now ) { |
345 | when = ralarm; | 345 | when = ralarm; |
346 | warn = ev.alarmTime(); | 346 | warn = ev.alarmTime(); |
347 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { | 347 | } else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) { |
348 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); | 348 | ralarm = ralarm.addSecs( -ev.alarmTime()*60 ); |
349 | if ( ralarm > now ) { | 349 | if ( ralarm > now ) { |
350 | when = ralarm; | 350 | when = ralarm; |
351 | warn = ev.alarmTime(); | 351 | warn = ev.alarmTime(); |
352 | } | 352 | } |
353 | } | 353 | } |
354 | } | 354 | } |
355 | } else { | 355 | } else { |
356 | warn = ev.alarmTime(); | 356 | warn = ev.alarmTime(); |
357 | when = ev.start().addSecs( -ev.alarmTime()*60 ); | 357 | when = ev.start().addSecs( -ev.alarmTime()*60 ); |
358 | } | 358 | } |
359 | return when > now; | 359 | return when > now; |
360 | } | 360 | } |
361 | 361 | ||
362 | static void addEventAlarm( const Event &ev ) | 362 | static void addEventAlarm( const Event &ev ) |
363 | { | 363 | { |
364 | QDateTime when; | 364 | QDateTime when; |
365 | int warn; | 365 | int warn; |
366 | if ( nextAlarm(ev,when,warn) ) | 366 | if ( nextAlarm(ev,when,warn) ) |
367 | AlarmServer::addAlarm( when, | 367 | AlarmServer::addAlarm( when, |
368 | "QPE/Application/datebook", | 368 | "QPE/Application/datebook", |
369 | "alarm(QDateTime,int)", warn ); | 369 | "alarm(QDateTime,int)", warn ); |
370 | } | 370 | } |
371 | 371 | ||
372 | static void delEventAlarm( const Event &ev ) | 372 | static void delEventAlarm( const Event &ev ) |
373 | { | 373 | { |
374 | QDateTime when; | 374 | QDateTime when; |
375 | int warn; | 375 | int warn; |
376 | if ( nextAlarm(ev,when,warn) ) | 376 | if ( nextAlarm(ev,when,warn) ) |
377 | AlarmServer::deleteAlarm( when, | 377 | AlarmServer::deleteAlarm( when, |
378 | "QPE/Application/datebook", | 378 | "QPE/Application/datebook", |
379 | "alarm(QDateTime,int)", warn ); | 379 | "alarm(QDateTime,int)", warn ); |
380 | } | 380 | } |
381 | 381 | ||
382 | 382 | ||
383 | DateBookDB::DateBookDB() | 383 | DateBookDB::DateBookDB() |
384 | { | 384 | { |
385 | init(); | 385 | init(); |
386 | } | 386 | } |
387 | 387 | ||
388 | DateBookDB::~DateBookDB() | 388 | DateBookDB::~DateBookDB() |
389 | { | 389 | { |
390 | save(); | 390 | save(); |
391 | eventList.clear(); | 391 | eventList.clear(); |
392 | repeatEvents.clear(); | 392 | repeatEvents.clear(); |
393 | |||
394 | delete d; | ||
395 | d=0; | ||
393 | } | 396 | } |
394 | 397 | ||
395 | 398 | ||
396 | //#### Why is this code duplicated in getEffectiveEvents ????? | 399 | //#### Why is this code duplicated in getEffectiveEvents ????? |
397 | //#### Addendum. Don't use this function, lets faze it out if we can. | 400 | //#### Addendum. Don't use this function, lets faze it out if we can. |
398 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) | 401 | QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to ) |
399 | { | 402 | { |
400 | QValueList<Event> tmpList; | 403 | QValueList<Event> tmpList; |
401 | tmpList = getNonRepeatingEvents( from, to ); | 404 | tmpList = getNonRepeatingEvents( from, to ); |
402 | 405 | ||
403 | // check for repeating events... | 406 | // check for repeating events... |
404 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); | 407 | for (QValueList<Event>::ConstIterator it = repeatEvents.begin(); |
405 | it != repeatEvents.end(); ++it) { | 408 | it != repeatEvents.end(); ++it) { |
406 | QDate itDate = from; | 409 | QDate itDate = from; |
407 | QDateTime due; | 410 | QDateTime due; |
408 | 411 | ||
409 | /* create a false end date, to short circuit on hard | 412 | /* create a false end date, to short circuit on hard |
410 | MonthlyDay recurences */ | 413 | MonthlyDay recurences */ |
411 | Event dummy_event = *it; | 414 | Event dummy_event = *it; |
412 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 415 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
413 | if ( !r.hasEndDate || r.endDate() > to ) { | 416 | if ( !r.hasEndDate || r.endDate() > to ) { |
414 | r.setEndDate( to ); | 417 | r.setEndDate( to ); |
415 | r.hasEndDate = TRUE; | 418 | r.hasEndDate = TRUE; |
416 | } | 419 | } |
417 | dummy_event.setRepeat(TRUE, r); | 420 | dummy_event.setRepeat(TRUE, r); |
418 | 421 | ||
419 | while (nextOccurance(dummy_event, itDate, due)) { | 422 | while (nextOccurance(dummy_event, itDate, due)) { |
420 | if (due.date() > to) | 423 | if (due.date() > to) |
421 | break; | 424 | break; |
422 | Event newEvent = *it; | 425 | Event newEvent = *it; |
423 | newEvent.setStart(due); | 426 | newEvent.setStart(due); |
424 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); | 427 | newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end()))); |
425 | 428 | ||
426 | tmpList.append(newEvent); | 429 | tmpList.append(newEvent); |
427 | itDate = due.date().addDays(1); /* the next event */ | 430 | itDate = due.date().addDays(1); /* the next event */ |
428 | } | 431 | } |
429 | } | 432 | } |
430 | qHeapSort(tmpList); | 433 | qHeapSort(tmpList); |
431 | return tmpList; | 434 | return tmpList; |
432 | } | 435 | } |
433 | 436 | ||
434 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) | 437 | QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) |
435 | { | 438 | { |
436 | QValueList<Event> day = getEvents(start.date(),start.date()); | 439 | QValueList<Event> day = getEvents(start.date(),start.date()); |
437 | 440 | ||
438 | QValueListConstIterator<Event> it; | 441 | QValueListConstIterator<Event> it; |
439 | QDateTime dtTmp; | 442 | QDateTime dtTmp; |
440 | QValueList<Event> tmpList; | 443 | QValueList<Event> tmpList; |
441 | for (it = day.begin(); it != day.end(); ++it ) { | 444 | for (it = day.begin(); it != day.end(); ++it ) { |
442 | dtTmp = (*it).start(TRUE); | 445 | dtTmp = (*it).start(TRUE); |
443 | if ( dtTmp == start ) | 446 | if ( dtTmp == start ) |
444 | tmpList.append( *it ); | 447 | tmpList.append( *it ); |
445 | } | 448 | } |
446 | return tmpList; | 449 | return tmpList; |
447 | } | 450 | } |
448 | 451 | ||
449 | //#### Why is this code duplicated in getEvents ????? | 452 | //#### Why is this code duplicated in getEvents ????? |
450 | 453 | ||
451 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | 454 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, |
452 | const QDate &to ) | 455 | const QDate &to ) |
453 | { | 456 | { |
454 | QValueList<EffectiveEvent> tmpList; | 457 | QValueList<EffectiveEvent> tmpList; |
455 | QValueListIterator<Event> it; | 458 | QValueListIterator<Event> it; |
456 | 459 | ||
457 | EffectiveEvent effEv; | 460 | EffectiveEvent effEv; |
458 | QDateTime dtTmp, | 461 | QDateTime dtTmp, |
459 | dtEnd; | 462 | dtEnd; |
460 | 463 | ||
461 | for (it = eventList.begin(); it != eventList.end(); ++it ) { | 464 | for (it = eventList.begin(); it != eventList.end(); ++it ) { |
462 | if (!(*it).isValidUid()) | 465 | if (!(*it).isValidUid()) |
463 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 466 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
464 | 467 | ||
465 | dtTmp = (*it).start(TRUE); | 468 | dtTmp = (*it).start(TRUE); |
466 | dtEnd = (*it).end(TRUE); | 469 | dtEnd = (*it).end(TRUE); |
467 | 470 | ||
468 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { | 471 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { |
469 | Event tmpEv = *it; | 472 | Event tmpEv = *it; |
470 | effEv.setEvent(tmpEv); | 473 | effEv.setEvent(tmpEv); |
471 | effEv.setDate( dtTmp.date() ); | 474 | effEv.setDate( dtTmp.date() ); |
472 | effEv.setStart( dtTmp.time() ); | 475 | effEv.setStart( dtTmp.time() ); |
473 | if ( dtTmp.date() != dtEnd.date() ) | 476 | if ( dtTmp.date() != dtEnd.date() ) |
474 | effEv.setEnd( QTime(23, 59, 0) ); | 477 | effEv.setEnd( QTime(23, 59, 0) ); |
475 | else | 478 | else |
476 | effEv.setEnd( dtEnd.time() ); | 479 | effEv.setEnd( dtEnd.time() ); |
477 | tmpList.append( effEv ); | 480 | tmpList.append( effEv ); |
478 | } | 481 | } |
479 | // we must also check for end date information... | 482 | // we must also check for end date information... |
480 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { | 483 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { |
481 | QDateTime dt = dtTmp.addDays( 1 ); | 484 | QDateTime dt = dtTmp.addDays( 1 ); |
482 | dt.setTime( QTime(0, 0, 0) ); | 485 | dt.setTime( QTime(0, 0, 0) ); |
483 | QDateTime dtStop; | 486 | QDateTime dtStop; |
484 | if ( dtEnd > to ) { | 487 | if ( dtEnd > to ) { |
485 | dtStop = to; | 488 | dtStop = to; |
486 | } else | 489 | } else |
487 | dtStop = dtEnd; | 490 | dtStop = dtEnd; |
488 | while ( dt <= dtStop ) { | 491 | while ( dt <= dtStop ) { |
489 | Event tmpEv = *it; | 492 | Event tmpEv = *it; |
490 | effEv.setEvent( tmpEv ); | 493 | effEv.setEvent( tmpEv ); |
491 | effEv.setDate( dt.date() ); | 494 | effEv.setDate( dt.date() ); |
492 | if ( dt >= from ) { | 495 | if ( dt >= from ) { |
493 | effEv.setStart( QTime(0, 0, 0) ); | 496 | effEv.setStart( QTime(0, 0, 0) ); |
494 | if ( dt.date() == dtEnd.date() ) | 497 | if ( dt.date() == dtEnd.date() ) |
495 | effEv.setEnd( dtEnd.time() ); | 498 | effEv.setEnd( dtEnd.time() ); |
496 | else | 499 | else |
497 | effEv.setEnd( QTime(23, 59, 59) ); | 500 | effEv.setEnd( QTime(23, 59, 59) ); |
498 | tmpList.append( effEv ); | 501 | tmpList.append( effEv ); |
499 | } | 502 | } |
500 | dt = dt.addDays( 1 ); | 503 | dt = dt.addDays( 1 ); |
501 | } | 504 | } |
502 | } | 505 | } |
503 | } | 506 | } |
504 | // check for repeating events... | 507 | // check for repeating events... |
505 | QDateTime repeat; | 508 | QDateTime repeat; |
506 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { | 509 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { |
507 | if (!(*it).isValidUid()) | 510 | if (!(*it).isValidUid()) |
508 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | 511 | (*it).assignUid(); // FIXME: Hack to restore cleared uids |
509 | 512 | ||
510 | /* create a false end date, to short circuit on hard | 513 | /* create a false end date, to short circuit on hard |
511 | MonthlyDay recurences */ | 514 | MonthlyDay recurences */ |
512 | Event dummy_event = *it; | 515 | Event dummy_event = *it; |
513 | int duration = (*it).start().date().daysTo( (*it).end().date() ); | 516 | int duration = (*it).start().date().daysTo( (*it).end().date() ); |
514 | QDate itDate = from.addDays(-duration); | 517 | QDate itDate = from.addDays(-duration); |
515 | 518 | ||
516 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 519 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
517 | if ( !r.hasEndDate || r.endDate() > to ) { | 520 | if ( !r.hasEndDate || r.endDate() > to ) { |
518 | r.setEndDate( to ); | 521 | r.setEndDate( to ); |
519 | r.hasEndDate = TRUE; | 522 | r.hasEndDate = TRUE; |
520 | } | 523 | } |
521 | dummy_event.setRepeat(TRUE, r); | 524 | dummy_event.setRepeat(TRUE, r); |
522 | 525 | ||
523 | while (nextOccurance(dummy_event, itDate, repeat)) { | 526 | while (nextOccurance(dummy_event, itDate, repeat)) { |
524 | if(repeat.date() > to) | 527 | if(repeat.date() > to) |
525 | break; | 528 | break; |
526 | effEv.setDate( repeat.date() ); | 529 | effEv.setDate( repeat.date() ); |
527 | if ((*it).type() == Event::AllDay) { | 530 | if ((*it).type() == Event::AllDay) { |
528 | effEv.setStart( QTime(0,0,0) ); | 531 | effEv.setStart( QTime(0,0,0) ); |
529 | effEv.setEnd( QTime(23,59,59) ); | 532 | effEv.setEnd( QTime(23,59,59) ); |
530 | } else { | 533 | } else { |
531 | /* we only occur by days, not hours/minutes/seconds. Hence | 534 | /* we only occur by days, not hours/minutes/seconds. Hence |
532 | the actual end and start times will be the same for | 535 | the actual end and start times will be the same for |
533 | every repeated event. For multi day events this is | 536 | every repeated event. For multi day events this is |
534 | fixed up later if on wronge day span */ | 537 | fixed up later if on wronge day span */ |
535 | effEv.setStart( (*it).start().time() ); | 538 | effEv.setStart( (*it).start().time() ); |
536 | effEv.setEnd( (*it).end().time() ); | 539 | effEv.setEnd( (*it).end().time() ); |
537 | } | 540 | } |
538 | if ( duration != 0 ) { | 541 | if ( duration != 0 ) { |
539 | // multi-day repeating events | 542 | // multi-day repeating events |
540 | QDate sub_it = QMAX( repeat.date(), from ); | 543 | QDate sub_it = QMAX( repeat.date(), from ); |
541 | QDate startDate = repeat.date(); | 544 | QDate startDate = repeat.date(); |
542 | QDate endDate = startDate.addDays( duration ); | 545 | QDate endDate = startDate.addDays( duration ); |
543 | 546 | ||
544 | while ( sub_it <= endDate && sub_it <= to ) { | 547 | while ( sub_it <= endDate && sub_it <= to ) { |
545 | EffectiveEvent tmpEffEv = effEv; | 548 | EffectiveEvent tmpEffEv = effEv; |
546 | Event tmpEv = *it; | 549 | Event tmpEv = *it; |
547 | tmpEffEv.setEvent( tmpEv ); | 550 | tmpEffEv.setEvent( tmpEv ); |
548 | 551 | ||
549 | if ( sub_it != startDate ) | 552 | if ( sub_it != startDate ) |
550 | tmpEffEv.setStart( QTime(0,0,0) ); | 553 | tmpEffEv.setStart( QTime(0,0,0) ); |
551 | if ( sub_it != endDate ) | 554 | if ( sub_it != endDate ) |
552 | tmpEffEv.setEnd( QTime(23,59,59) ); | 555 | tmpEffEv.setEnd( QTime(23,59,59) ); |
553 | tmpEffEv.setDate( sub_it ); | 556 | tmpEffEv.setDate( sub_it ); |
554 | tmpEffEv.setEffectiveDates( startDate, endDate ); | 557 | tmpEffEv.setEffectiveDates( startDate, endDate ); |
555 | tmpList.append( tmpEffEv ); | 558 | tmpList.append( tmpEffEv ); |
556 | sub_it = sub_it.addDays( 1 ); | 559 | sub_it = sub_it.addDays( 1 ); |
557 | } | 560 | } |
558 | itDate = endDate; | 561 | itDate = endDate; |
559 | } else { | 562 | } else { |
560 | Event tmpEv = *it; | 563 | Event tmpEv = *it; |
561 | effEv.setEvent( tmpEv ); | 564 | effEv.setEvent( tmpEv ); |
562 | tmpList.append( effEv ); | 565 | tmpList.append( effEv ); |
563 | itDate = repeat.date().addDays( 1 ); | 566 | itDate = repeat.date().addDays( 1 ); |
564 | } | 567 | } |
565 | } | 568 | } |
566 | } | 569 | } |
567 | 570 | ||
568 | qHeapSort( tmpList ); | 571 | qHeapSort( tmpList ); |
569 | return tmpList; | 572 | return tmpList; |
570 | } | 573 | } |
571 | 574 | ||
572 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 575 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
573 | { | 576 | { |
574 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 577 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
575 | QValueListConstIterator<EffectiveEvent> it; | 578 | QValueListConstIterator<EffectiveEvent> it; |
576 | QValueList<EffectiveEvent> tmpList; | 579 | QValueList<EffectiveEvent> tmpList; |
577 | QDateTime dtTmp; | 580 | QDateTime dtTmp; |
578 | 581 | ||
579 | for (it = day.begin(); it != day.end(); ++it ) { | 582 | for (it = day.begin(); it != day.end(); ++it ) { |
580 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 583 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
581 | // at the moment we don't have second granularity, be nice about that.. | 584 | // at the moment we don't have second granularity, be nice about that.. |
582 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 585 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
583 | tmpList.append( *it ); | 586 | tmpList.append( *it ); |
584 | } | 587 | } |