-rw-r--r-- | library/datebookdb.cpp | 14 |
1 files changed, 0 insertions, 14 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index da5a797..2ac9a0c 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -526,142 +526,128 @@ QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from, | |||
526 | if(repeat.date() > to) | 526 | if(repeat.date() > to) |
527 | break; | 527 | break; |
528 | effEv.setDate( repeat.date() ); | 528 | effEv.setDate( repeat.date() ); |
529 | if ((*it).type() == Event::AllDay) { | 529 | if ((*it).type() == Event::AllDay) { |
530 | effEv.setStart( QTime(0,0,0) ); | 530 | effEv.setStart( QTime(0,0,0) ); |
531 | effEv.setEnd( QTime(23,59,59) ); | 531 | effEv.setEnd( QTime(23,59,59) ); |
532 | } else { | 532 | } else { |
533 | /* we only occur by days, not hours/minutes/seconds. Hence | 533 | /* we only occur by days, not hours/minutes/seconds. Hence |
534 | the actual end and start times will be the same for | 534 | the actual end and start times will be the same for |
535 | every repeated event. For multi day events this is | 535 | every repeated event. For multi day events this is |
536 | fixed up later if on wronge day span */ | 536 | fixed up later if on wronge day span */ |
537 | effEv.setStart( (*it).start().time() ); | 537 | effEv.setStart( (*it).start().time() ); |
538 | effEv.setEnd( (*it).end().time() ); | 538 | effEv.setEnd( (*it).end().time() ); |
539 | } | 539 | } |
540 | if ( duration != 0 ) { | 540 | if ( duration != 0 ) { |
541 | // multi-day repeating events | 541 | // multi-day repeating events |
542 | QDate sub_it = QMAX( repeat.date(), from ); | 542 | QDate sub_it = QMAX( repeat.date(), from ); |
543 | QDate startDate = repeat.date(); | 543 | QDate startDate = repeat.date(); |
544 | QDate endDate = startDate.addDays( duration ); | 544 | QDate endDate = startDate.addDays( duration ); |
545 | 545 | ||
546 | while ( sub_it <= endDate && sub_it <= to ) { | 546 | while ( sub_it <= endDate && sub_it <= to ) { |
547 | EffectiveEvent tmpEffEv = effEv; | 547 | EffectiveEvent tmpEffEv = effEv; |
548 | Event tmpEv = *it; | 548 | Event tmpEv = *it; |
549 | tmpEffEv.setEvent( tmpEv ); | 549 | tmpEffEv.setEvent( tmpEv ); |
550 | 550 | ||
551 | if ( sub_it != startDate ) | 551 | if ( sub_it != startDate ) |
552 | tmpEffEv.setStart( QTime(0,0,0) ); | 552 | tmpEffEv.setStart( QTime(0,0,0) ); |
553 | if ( sub_it != endDate ) | 553 | if ( sub_it != endDate ) |
554 | tmpEffEv.setEnd( QTime(23,59,59) ); | 554 | tmpEffEv.setEnd( QTime(23,59,59) ); |
555 | tmpEffEv.setDate( sub_it ); | 555 | tmpEffEv.setDate( sub_it ); |
556 | tmpEffEv.setEffectiveDates( startDate, endDate ); | 556 | tmpEffEv.setEffectiveDates( startDate, endDate ); |
557 | tmpList.append( tmpEffEv ); | 557 | tmpList.append( tmpEffEv ); |
558 | sub_it = sub_it.addDays( 1 ); | 558 | sub_it = sub_it.addDays( 1 ); |
559 | } | 559 | } |
560 | itDate = endDate; | 560 | itDate = endDate; |
561 | } else { | 561 | } else { |
562 | Event tmpEv = *it; | 562 | Event tmpEv = *it; |
563 | effEv.setEvent( tmpEv ); | 563 | effEv.setEvent( tmpEv ); |
564 | tmpList.append( effEv ); | 564 | tmpList.append( effEv ); |
565 | itDate = repeat.date().addDays( 1 ); | 565 | itDate = repeat.date().addDays( 1 ); |
566 | } | 566 | } |
567 | } | 567 | } |
568 | } | 568 | } |
569 | 569 | ||
570 | qHeapSort( tmpList ); | 570 | qHeapSort( tmpList ); |
571 | return tmpList; | 571 | return tmpList; |
572 | } | 572 | } |
573 | 573 | ||
574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) | 574 | QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDateTime &dt) |
575 | { | 575 | { |
576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); | 576 | QValueList<EffectiveEvent> day = getEffectiveEvents(dt.date(), dt.date()); |
577 | QValueListConstIterator<EffectiveEvent> it; | 577 | QValueListConstIterator<EffectiveEvent> it; |
578 | QValueList<EffectiveEvent> tmpList; | 578 | QValueList<EffectiveEvent> tmpList; |
579 | QDateTime dtTmp; | 579 | QDateTime dtTmp; |
580 | 580 | ||
581 | for (it = day.begin(); it != day.end(); ++it ) { | 581 | for (it = day.begin(); it != day.end(); ++it ) { |
582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); | 582 | dtTmp = QDateTime( (*it).date(), (*it).start() ); |
583 | // 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.. |
584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) | 584 | if ( QABS(dt.secsTo(dtTmp)) < 60 ) |
585 | tmpList.append( *it ); | 585 | tmpList.append( *it ); |
586 | } | 586 | } |
587 | return tmpList; | 587 | return tmpList; |
588 | } | 588 | } |
589 | 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 | |||
603 | |||
604 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) | 590 | void DateBookDB::addEvent( const Event &ev, bool doalarm ) |
605 | { | 591 | { |
606 | // write to the journal... | 592 | // write to the journal... |
607 | saveJournalEntry( ev, ACTION_ADD, -1, false ); | 593 | saveJournalEntry( ev, ACTION_ADD, -1, false ); |
608 | addJFEvent( ev, doalarm ); | 594 | addJFEvent( ev, doalarm ); |
609 | d->clean = false; | 595 | d->clean = false; |
610 | } | 596 | } |
611 | 597 | ||
612 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) | 598 | void DateBookDB::addJFEvent( const Event &ev, bool doalarm ) |
613 | { | 599 | { |
614 | if ( doalarm && ev.hasAlarm() ) | 600 | if ( doalarm && ev.hasAlarm() ) |
615 | addEventAlarm( ev ); | 601 | addEventAlarm( ev ); |
616 | if ( ev.hasRepeat() ) | 602 | if ( ev.hasRepeat() ) |
617 | repeatEvents.append( ev ); | 603 | repeatEvents.append( ev ); |
618 | else | 604 | else |
619 | eventList.append( ev ); | 605 | eventList.append( ev ); |
620 | } | 606 | } |
621 | 607 | ||
622 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) | 608 | void DateBookDB::editEvent( const Event &old, Event &editedEv ) |
623 | { | 609 | { |
624 | int oldIndex=0; | 610 | int oldIndex=0; |
625 | bool oldHadRepeat = old.hasRepeat(); | 611 | bool oldHadRepeat = old.hasRepeat(); |
626 | Event orig; | 612 | Event orig; |
627 | 613 | ||
628 | // write to the journal... | 614 | // write to the journal... |
629 | if ( oldHadRepeat ) { | 615 | if ( oldHadRepeat ) { |
630 | if ( origRepeat( old, orig ) ) // should work always... | 616 | if ( origRepeat( old, orig ) ) // should work always... |
631 | oldIndex = repeatEvents.findIndex( orig ); | 617 | oldIndex = repeatEvents.findIndex( orig ); |
632 | } else | 618 | } else |
633 | oldIndex = eventList.findIndex( old ); | 619 | oldIndex = eventList.findIndex( old ); |
634 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); | 620 | saveJournalEntry( editedEv, ACTION_REPLACE, oldIndex, oldHadRepeat ); |
635 | 621 | ||
636 | // Delete old event | 622 | // Delete old event |
637 | if ( old.hasAlarm() ) | 623 | if ( old.hasAlarm() ) |
638 | delEventAlarm( old ); | 624 | delEventAlarm( old ); |
639 | if ( oldHadRepeat ) { | 625 | if ( oldHadRepeat ) { |
640 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and | 626 | if ( editedEv.hasRepeat() ) { // This mean that origRepeat was run above and |
641 | // orig is initialized | 627 | // orig is initialized |
642 | // assumption, when someone edits a repeating event, they | 628 | // assumption, when someone edits a repeating event, they |
643 | // want to change them all, maybe not perfect, but it works | 629 | // want to change them all, maybe not perfect, but it works |
644 | // for the moment... | 630 | // for the moment... |
645 | repeatEvents.remove( orig ); | 631 | repeatEvents.remove( orig ); |
646 | } else | 632 | } else |
647 | removeRepeat( old ); | 633 | removeRepeat( old ); |
648 | } else { | 634 | } else { |
649 | QValueList<Event>::Iterator it = eventList.find( old ); | 635 | QValueList<Event>::Iterator it = eventList.find( old ); |
650 | if ( it != eventList.end() ) | 636 | if ( it != eventList.end() ) |
651 | eventList.remove( it ); | 637 | eventList.remove( it ); |
652 | } | 638 | } |
653 | 639 | ||
654 | // Add new event | 640 | // Add new event |
655 | if ( editedEv.hasAlarm() ) | 641 | if ( editedEv.hasAlarm() ) |
656 | addEventAlarm( editedEv ); | 642 | addEventAlarm( editedEv ); |
657 | if ( editedEv.hasRepeat() ) | 643 | if ( editedEv.hasRepeat() ) |
658 | repeatEvents.append( editedEv ); | 644 | repeatEvents.append( editedEv ); |
659 | else | 645 | else |
660 | eventList.append( editedEv ); | 646 | eventList.append( editedEv ); |
661 | 647 | ||
662 | d->clean = false; | 648 | d->clean = false; |
663 | } | 649 | } |
664 | 650 | ||
665 | void DateBookDB::removeEvent( const Event &ev ) | 651 | void DateBookDB::removeEvent( const Event &ev ) |
666 | { | 652 | { |
667 | // write to the journal... | 653 | // write to the journal... |