author | zecke <zecke> | 2004-09-12 20:43:22 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-12 20:43:22 (UTC) |
commit | 0f705db7c338e9642294823333e5f4410aa0573f (patch) (unidiff) | |
tree | 98e35fc5d53b0730ebeb49baaff391b5cd28386f | |
parent | 40440f2652c582c108a5236d8b5398dbd6b68b18 (diff) | |
download | opie-0f705db7c338e9642294823333e5f4410aa0573f.zip opie-0f705db7c338e9642294823333e5f4410aa0573f.tar.gz opie-0f705db7c338e9642294823333e5f4410aa0573f.tar.bz2 |
Delete the d pointer
-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 | |||
@@ -265,256 +265,259 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) | |||
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 | } |