author | hakan <hakan> | 2002-03-29 16:32:49 (UTC) |
---|---|---|
committer | hakan <hakan> | 2002-03-29 16:32:49 (UTC) |
commit | d31e0363e905aae78034626896b0d6620ffbc8fc (patch) (unidiff) | |
tree | e6a98e06b0a76008c1ca8b12a095ce2ab2cabd34 | |
parent | 6e194663130b9548c4a31afd2798d9ca1dd30be5 (diff) | |
download | opie-d31e0363e905aae78034626896b0d6620ffbc8fc.zip opie-d31e0363e905aae78034626896b0d6620ffbc8fc.tar.gz opie-d31e0363e905aae78034626896b0d6620ffbc8fc.tar.bz2 |
Added getEvent(uid) and a fix reassigning uids to events whos uids have been cleared
-rw-r--r-- | library/datebookdb.cpp | 25 | ||||
-rw-r--r-- | library/datebookdb.h | 3 |
2 files changed, 27 insertions, 1 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index bf7fd94..da5a797 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -440,90 +440,95 @@ QValueList<Event> DateBookDB::getEvents( const QDateTime &start ) | |||
440 | QValueListConstIterator<Event> it; | 440 | QValueListConstIterator<Event> it; |
441 | QDateTime dtTmp; | 441 | QDateTime dtTmp; |
442 | QValueList<Event> tmpList; | 442 | QValueList<Event> tmpList; |
443 | for (it = day.begin(); it != day.end(); ++it ) { | 443 | for (it = day.begin(); it != day.end(); ++it ) { |
444 | dtTmp = (*it).start(TRUE); | 444 | dtTmp = (*it).start(TRUE); |
445 | if ( dtTmp == start ) | 445 | if ( dtTmp == start ) |
446 | tmpList.append( *it ); | 446 | tmpList.append( *it ); |
447 | } | 447 | } |
448 | return tmpList; | 448 | return tmpList; |
449 | } | 449 | } |
450 | 450 | ||
451 | //#### Why is this code duplicated in getEvents ????? | 451 | //#### Why is this code duplicated in getEvents ????? |
452 | 452 | ||
453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | 453 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, |
454 | const QDate &to ) | 454 | const QDate &to ) |
455 | { | 455 | { |
456 | QValueList<EffectiveEvent> tmpList; | 456 | QValueList<EffectiveEvent> tmpList; |
457 | QValueListIterator<Event> it; | 457 | QValueListIterator<Event> it; |
458 | 458 | ||
459 | EffectiveEvent effEv; | 459 | EffectiveEvent effEv; |
460 | QDateTime dtTmp, | 460 | QDateTime dtTmp, |
461 | dtEnd; | 461 | dtEnd; |
462 | 462 | ||
463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { | 463 | for (it = eventList.begin(); it != eventList.end(); ++it ) { |
464 | if (!(*it).isValidUid()) | ||
465 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | ||
466 | |||
464 | dtTmp = (*it).start(TRUE); | 467 | dtTmp = (*it).start(TRUE); |
465 | dtEnd = (*it).end(TRUE); | 468 | dtEnd = (*it).end(TRUE); |
466 | 469 | ||
467 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { | 470 | if ( dtTmp.date() >= from && dtTmp.date() <= to ) { |
468 | Event tmpEv = *it; | 471 | Event tmpEv = *it; |
469 | effEv.setEvent(tmpEv); | 472 | effEv.setEvent(tmpEv); |
470 | effEv.setDate( dtTmp.date() ); | 473 | effEv.setDate( dtTmp.date() ); |
471 | effEv.setStart( dtTmp.time() ); | 474 | effEv.setStart( dtTmp.time() ); |
472 | if ( dtTmp.date() != dtEnd.date() ) | 475 | if ( dtTmp.date() != dtEnd.date() ) |
473 | effEv.setEnd( QTime(23, 59, 0) ); | 476 | effEv.setEnd( QTime(23, 59, 0) ); |
474 | else | 477 | else |
475 | effEv.setEnd( dtEnd.time() ); | 478 | effEv.setEnd( dtEnd.time() ); |
476 | tmpList.append( effEv ); | 479 | tmpList.append( effEv ); |
477 | } | 480 | } |
478 | // we must also check for end date information... | 481 | // we must also check for end date information... |
479 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { | 482 | if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) { |
480 | QDateTime dt = dtTmp.addDays( 1 ); | 483 | QDateTime dt = dtTmp.addDays( 1 ); |
481 | dt.setTime( QTime(0, 0, 0) ); | 484 | dt.setTime( QTime(0, 0, 0) ); |
482 | QDateTime dtStop; | 485 | QDateTime dtStop; |
483 | if ( dtEnd > to ) { | 486 | if ( dtEnd > to ) { |
484 | dtStop = to; | 487 | dtStop = to; |
485 | } else | 488 | } else |
486 | dtStop = dtEnd; | 489 | dtStop = dtEnd; |
487 | while ( dt <= dtStop ) { | 490 | while ( dt <= dtStop ) { |
488 | Event tmpEv = *it; | 491 | Event tmpEv = *it; |
489 | effEv.setEvent( tmpEv ); | 492 | effEv.setEvent( tmpEv ); |
490 | effEv.setDate( dt.date() ); | 493 | effEv.setDate( dt.date() ); |
491 | if ( dt >= from ) { | 494 | if ( dt >= from ) { |
492 | effEv.setStart( QTime(0, 0, 0) ); | 495 | effEv.setStart( QTime(0, 0, 0) ); |
493 | if ( dt.date() == dtEnd.date() ) | 496 | if ( dt.date() == dtEnd.date() ) |
494 | effEv.setEnd( dtEnd.time() ); | 497 | effEv.setEnd( dtEnd.time() ); |
495 | else | 498 | else |
496 | effEv.setEnd( QTime(23, 59, 59) ); | 499 | effEv.setEnd( QTime(23, 59, 59) ); |
497 | tmpList.append( effEv ); | 500 | tmpList.append( effEv ); |
498 | } | 501 | } |
499 | dt = dt.addDays( 1 ); | 502 | dt = dt.addDays( 1 ); |
500 | } | 503 | } |
501 | } | 504 | } |
502 | } | 505 | } |
503 | // check for repeating events... | 506 | // check for repeating events... |
504 | QDateTime repeat; | 507 | QDateTime repeat; |
505 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { | 508 | for ( it = repeatEvents.begin(); it != repeatEvents.end(); ++it ) { |
509 | if (!(*it).isValidUid()) | ||
510 | (*it).assignUid(); // FIXME: Hack to restore cleared uids | ||
506 | 511 | ||
507 | /* create a false end date, to short circuit on hard | 512 | /* create a false end date, to short circuit on hard |
508 | MonthlyDay recurences */ | 513 | MonthlyDay recurences */ |
509 | Event dummy_event = *it; | 514 | Event dummy_event = *it; |
510 | int duration = (*it).start().date().daysTo( (*it).end().date() ); | 515 | int duration = (*it).start().date().daysTo( (*it).end().date() ); |
511 | QDate itDate = from.addDays(-duration); | 516 | QDate itDate = from.addDays(-duration); |
512 | 517 | ||
513 | Event::RepeatPattern r = dummy_event.repeatPattern(); | 518 | Event::RepeatPattern r = dummy_event.repeatPattern(); |
514 | if ( !r.hasEndDate || r.endDate() > to ) { | 519 | if ( !r.hasEndDate || r.endDate() > to ) { |
515 | r.setEndDate( to ); | 520 | r.setEndDate( to ); |
516 | r.hasEndDate = TRUE; | 521 | r.hasEndDate = TRUE; |
517 | } | 522 | } |
518 | dummy_event.setRepeat(TRUE, r); | 523 | dummy_event.setRepeat(TRUE, r); |
519 | 524 | ||
520 | while (nextOccurance(dummy_event, itDate, repeat)) { | 525 | while (nextOccurance(dummy_event, itDate, repeat)) { |
521 | if(repeat.date() > to) | 526 | if(repeat.date() > to) |
522 | break; | 527 | break; |
523 | effEv.setDate( repeat.date() ); | 528 | effEv.setDate( repeat.date() ); |
524 | if ((*it).type() == Event::AllDay) { | 529 | if ((*it).type() == Event::AllDay) { |
525 | effEv.setStart( QTime(0,0,0) ); | 530 | effEv.setStart( QTime(0,0,0) ); |
526 | effEv.setEnd( QTime(23,59,59) ); | 531 | effEv.setEnd( QTime(23,59,59) ); |
527 | } else { | 532 | } else { |
528 | /* we only occur by days, not hours/minutes/seconds. Hence | 533 | /* we only occur by days, not hours/minutes/seconds. Hence |
529 | the actual end and start times will be the same for | 534 | the actual end and start times will be the same for |
@@ -561,102 +566,120 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | |||
561 | } | 566 | } |
562 | } | 567 | } |
563 | } | 568 | } |
564 | 569 | ||
565 | qHeapSort( tmpList ); | 570 | qHeapSort( tmpList ); |
566 | return tmpList; | 571 | return tmpList; |
567 | } | 572 | } |
568 | 573 | ||
569 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
570 | { | 575 | { |
571 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
572 | QValueListConstIterator<EffectiveEvent> it; | 577 | QValueListConstIterator<EffectiveEvent> it; |
573 | QValueList<EffectiveEvent> tmpList; | 578 | QValueList<EffectiveEvent> tmpList; |
574 | QDateTime dtTmp; | 579 | QDateTime dtTmp; |
575 | 580 | ||
576 | for (it = day.begin(); it != day.end(); ++it ) { | 581 | for (it = day.begin(); it != day.end(); ++it ) { |
577 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
578 | // at the moment we don't have second granularity, be nice about that.. | 583 | // at the moment we don't have second granularity, be nice about that.. |
579 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
580 | tmpList.append( *it ); | 585 | tmpList.append( *it ); |
581 | } | 586 | } |
582 | return tmpList; | 587 | return tmpList; |
583 | } | 588 | } |
584 | 589 | ||
590 | Event DateBookDB::getEvent( int uid ) { | ||
591 | QValueList<Event>::ConstIterator it; | ||
592 | |||
593 | for (it = eventList.begin(); it != eventList.end(); it++) { | ||
594 | if ((*it).uid() == uid) return *it; | ||
595 | } | ||
596 | for (it = repeatEvents.begin(); it != repeatEvents.end(); it++) { | ||
597 | if ((*it).uid() == uid) return *it; | ||
598 | } | ||
599 | |||
600 | qDebug("Event not found: uid=%d\n", uid); | ||
601 | } | ||
602 | |||
585 | 603 | ||
586 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) | 604 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) |
587 | { | 605 | { |
588 | // write to the journal... | 606 | // write to the journal... |
589 | saveJournalEntry( ev, ACTION_ADD, -1, false ); | 607 | saveJournalEntry( ev, ACTION_ADD, -1, false ); |
590 | addJFEvent( ev, doalarm ); | 608 | addJFEvent( ev, doalarm ); |
591 | d->clean = false; | 609 | d->clean = false; |
592 | } | 610 | } |
593 | 611 | ||
594 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) | 612 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) |
595 | { | 613 | { |
596 | if ( doalarm && ev.hasAlarm() ) | 614 | if ( doalarm && ev.hasAlarm() ) |
597 | addEventAlarm( ev ); | 615 | addEventAlarm( ev ); |
598 | if ( ev.hasRepeat() ) | 616 | if ( ev.hasRepeat() ) |
599 | repeatEvents.append( ev ); | 617 | repeatEvents.append( ev ); |
600 | else | 618 | else |
601 | eventList.append( ev ); | 619 | eventList.append( ev ); |
602 | } | 620 | } |
603 | 621 | ||
604 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) | 622 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) |
605 | { | 623 | { |
606 | int oldIndex=0; | 624 | int oldIndex=0; |
607 | bool oldHadRepeat = old.hasRepeat(); | 625 | bool oldHadRepeat = old.hasRepeat(); |
608 | Event orig; | 626 | Event orig; |
609 | 627 | ||
610 | // write to the journal... | 628 | // write to the journal... |
611 | if ( oldHadRepeat ) { | 629 | if ( oldHadRepeat ) { |
612 | if ( origRepeat( old, orig ) ) // should work always... | 630 | if ( origRepeat( old, orig ) ) // should work always... |
613 | oldIndex = repeatEvents.findIndex( orig ); | 631 | oldIndex = repeatEvents.findIndex( orig ); |
614 | } else | 632 | } else |
615 | oldIndex = eventList.findIndex( old ); | 633 | oldIndex = eventList.findIndex( old ); |
616 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); | 634 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); |
617 | 635 | ||
636 | // Delete old event | ||
618 | if ( old.hasAlarm() ) | 637 | if ( old.hasAlarm() ) |
619 | delEventAlarm( old ); | 638 | delEventAlarm( old ); |
620 | if ( oldHadRepeat ) { | 639 | if ( oldHadRepeat ) { |
621 | if ( oldHadRepeat && editedEv.hasRepeat() ) { | 640 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and |
641 | // orig is initialized | ||
622 | // assumption, when someone edits a repeating event, they | 642 | // assumption, when someone edits a repeating event, they |
623 | // want to change them all, maybe not perfect, but it works | 643 | // want to change them all, maybe not perfect, but it works |
624 | // for the moment... | 644 | // for the moment... |
625 | repeatEvents.remove( orig ); | 645 | repeatEvents.remove( orig ); |
626 | } else | 646 | } else |
627 | removeRepeat( old ); | 647 | removeRepeat( old ); |
628 | } else { | 648 | } else { |
629 | QValueList<Event>::Iterator it = eventList.find( old ); | 649 | QValueList<Event>::Iterator it = eventList.find( old ); |
630 | if ( it != eventList.end() ) | 650 | if ( it != eventList.end() ) |
631 | eventList.remove( it ); | 651 | eventList.remove( it ); |
632 | } | 652 | } |
653 | |||
654 | // Add new event | ||
633 | if ( editedEv.hasAlarm() ) | 655 | if ( editedEv.hasAlarm() ) |
634 | addEventAlarm( editedEv ); | 656 | addEventAlarm( editedEv ); |
635 | if ( editedEv.hasRepeat() ) | 657 | if ( editedEv.hasRepeat() ) |
636 | repeatEvents.append( editedEv ); | 658 | repeatEvents.append( editedEv ); |
637 | else | 659 | else |
638 | eventList.append( editedEv ); | 660 | eventList.append( editedEv ); |
661 | |||
639 | d->clean = false; | 662 | d->clean = false; |
640 | } | 663 | } |
641 | 664 | ||
642 | void DateBookDB::removeEvent( const Event &ev ) | 665 | void DateBookDB::removeEvent( const Event &ev ) |
643 | { | 666 | { |
644 | // write to the journal... | 667 | // write to the journal... |
645 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); | 668 | saveJournalEntry( ev, ACTION_REMOVE, -1, false ); |
646 | removeJFEvent( ev ); | 669 | removeJFEvent( ev ); |
647 | d->clean = false; | 670 | d->clean = false; |
648 | } | 671 | } |
649 | 672 | ||
650 | void DateBookDB::removeJFEvent( const Event&ev ) | 673 | void DateBookDB::removeJFEvent( const Event&ev ) |
651 | { | 674 | { |
652 | if ( ev.hasAlarm() ) | 675 | if ( ev.hasAlarm() ) |
653 | delEventAlarm( ev ); | 676 | delEventAlarm( ev ); |
654 | if ( ev.hasRepeat() ) { | 677 | if ( ev.hasRepeat() ) { |
655 | removeRepeat( ev ); | 678 | removeRepeat( ev ); |
656 | } else { | 679 | } else { |
657 | QValueList<Event>::Iterator it = eventList.find( ev ); | 680 | QValueList<Event>::Iterator it = eventList.find( ev ); |
658 | if ( it != eventList.end() ) | 681 | if ( it != eventList.end() ) |
659 | eventList.remove( it ); | 682 | eventList.remove( it ); |
660 | } | 683 | } |
661 | } | 684 | } |
662 | 685 | ||
diff --git a/library/datebookdb.h b/library/datebookdb.h index aadb397..e4c251c 100644 --- a/library/datebookdb.h +++ b/library/datebookdb.h | |||
@@ -23,63 +23,66 @@ | |||
23 | 23 | ||
24 | #include <qdatetime.h> | 24 | #include <qdatetime.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qvaluelist.h> | 26 | #include <qvaluelist.h> |
27 | #include <qpe/event.h> | 27 | #include <qpe/event.h> |
28 | 28 | ||
29 | // journal actions... | 29 | // journal actions... |
30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; | 30 | enum journal_action { ACTION_ADD, ACTION_REMOVE, ACTION_REPLACE }; |
31 | 31 | ||
32 | class DateBookDBPrivate; | 32 | class DateBookDBPrivate; |
33 | class DateBookDB | 33 | class DateBookDB |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | DateBookDB(); | 36 | DateBookDB(); |
37 | ~DateBookDB(); | 37 | ~DateBookDB(); |
38 | 38 | ||
39 | // very depreciated now!!! | 39 | // very depreciated now!!! |
40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); | 40 | QValueList<Event> getEvents( const QDate &from, const QDate &to ); |
41 | QValueList<Event> getEvents( const QDateTime &start ); | 41 | QValueList<Event> getEvents( const QDateTime &start ); |
42 | 42 | ||
43 | // USE THESE!!! | 43 | // USE THESE!!! |
44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, | 44 | QValueList<EffectiveEvent> getEffectiveEvents( const QDate &from, |
45 | const QDate &to ); | 45 | const QDate &to ); |
46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); | 46 | QValueList<EffectiveEvent> getEffectiveEvents( const QDateTime &start ); |
47 | Event getEvent( int uid ); | ||
47 | 48 | ||
48 | QValueList<Event> getRawRepeats() const; | 49 | QValueList<Event> getRawRepeats() const; |
49 | QValueList<Event> getNonRepeatingEvents( const QDate &from, | 50 | QValueList<Event> getNonRepeatingEvents( const QDate &from, |
50 | const QDate &to ) const; | 51 | const QDate &to ) const; |
51 | 52 | ||
52 | // Use these when dealing with adding removing events... | 53 | // Use these when dealing with adding removing events... |
53 | void addEvent( const Event &ev, bool doalarm=TRUE ); | 54 | void addEvent( const Event &ev, bool doalarm=TRUE ); |
54 | void removeEvent( const Event &ev ); | 55 | void removeEvent( const Event &ev ); |
55 | void editEvent( const Event &old, Event &ev ); | 56 | void editEvent( const Event &old, Event &ev ); |
56 | // add/remove event without journaling ( these ended up in public by accident, never | 57 | // add/remove event without journaling ( these ended up in public by accident, never |
57 | // use them unless you know what you are doing...), | 58 | // use them unless you know what you are doing...), |
58 | // please put them in private if we ever can change the class... | 59 | // please put them in private if we ever can change the class... |
59 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); | 60 | void addJFEvent( const Event &ev, bool doalarm=TRUE ); |
60 | void removeJFEvent( const Event &ev ); | 61 | void removeJFEvent( const Event &ev ); |
61 | 62 | ||
62 | bool save(); | 63 | bool save(); |
63 | void reload(); | 64 | void reload(); |
64 | private: | 65 | private: |
65 | //find the real repeat... | 66 | //find the real repeat... |
66 | bool origRepeat( const Event &ev, Event &orig ) const; | 67 | bool origRepeat( const Event &ev, Event &orig ) const; |
67 | bool removeRepeat( const Event &ev ); | 68 | bool removeRepeat( const Event &ev ); |
68 | void init(); | 69 | void init(); |
69 | void loadFile( const QString &strFile ); | 70 | void loadFile( const QString &strFile ); |
70 | // depreciated... | 71 | // depreciated... |
71 | void saveJournalEntry( const Event &ev, journal_action action ); | 72 | void saveJournalEntry( const Event &ev, journal_action action ); |
72 | // new version, uncomment the "= -1" when we remove the above | 73 | // new version, uncomment the "= -1" when we remove the above |
73 | // function.. | 74 | // function.. |
74 | bool saveJournalEntry( const Event &ev, journal_action action, | 75 | bool saveJournalEntry( const Event &ev, journal_action action, |
75 | int key/* = -1*/, bool origHadRepeat = false ); | 76 | int key/* = -1*/, bool origHadRepeat = false ); |
76 | 77 | ||
77 | QValueList<Event> eventList; // non-repeating events... | 78 | QValueList<Event> eventList; // non-repeating events... |
78 | QValueList<Event> repeatEvents; // the repeating events... | 79 | QValueList<Event> repeatEvents; // the repeating events... |
79 | DateBookDBPrivate *d; | 80 | DateBookDBPrivate *d; |
80 | QFile journalFile; | 81 | QFile journalFile; |
82 | |||
83 | intrecordIdMax; // ADDITION | ||
81 | }; | 84 | }; |
82 | 85 | ||
83 | /* helper functions, also useful to other apps. */ | 86 | /* helper functions, also useful to other apps. */ |
84 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); | 87 | bool nextOccurance( const Event &e, const QDate &from, QDateTime &next); |
85 | #endif | 88 | #endif |