-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 | |||
@@ -458,12 +458,15 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | |||
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); |
@@ -500,12 +503,14 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | |||
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); |
@@ -579,12 +584,25 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | |||
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 ); |
@@ -612,33 +630,38 @@ void DateBookDB::editEvent( const Event &old, Event &editedEv ) | |||
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... |
diff --git a/library/datebookdb.h b/library/datebookdb.h index aadb397..e4c251c 100644 --- a/library/datebookdb.h +++ b/library/datebookdb.h | |||
@@ -41,12 +41,13 @@ public: | |||
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... |
@@ -75,11 +76,13 @@ private: | |||
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 |