-rw-r--r-- | libkcal/calendarlocal.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0eba6a9..e75154b 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -494,192 +494,193 @@ void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | |||
494 | Incidence *incidence, | 494 | Incidence *incidence, |
495 | const QDateTime &from, | 495 | const QDateTime &from, |
496 | const QDateTime &to ) | 496 | const QDateTime &to ) |
497 | { | 497 | { |
498 | 498 | ||
499 | QPtrList<Alarm> alarmList = incidence->alarms(); | 499 | QPtrList<Alarm> alarmList = incidence->alarms(); |
500 | Alarm *alarm; | 500 | Alarm *alarm; |
501 | QDateTime qdt; | 501 | QDateTime qdt; |
502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 502 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
503 | if (incidence->recursOn(from.date())) { | 503 | if (incidence->recursOn(from.date())) { |
504 | qdt.setTime(alarm->time().time()); | 504 | qdt.setTime(alarm->time().time()); |
505 | qdt.setDate(from.date()); | 505 | qdt.setDate(from.date()); |
506 | } | 506 | } |
507 | else qdt = alarm->time(); | 507 | else qdt = alarm->time(); |
508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 508 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
509 | if ( alarm->enabled() ) { | 509 | if ( alarm->enabled() ) { |
510 | if ( qdt >= from && qdt <= to ) { | 510 | if ( qdt >= from && qdt <= to ) { |
511 | alarms.append( alarm ); | 511 | alarms.append( alarm ); |
512 | } | 512 | } |
513 | } | 513 | } |
514 | } | 514 | } |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | /****************************** PROTECTED METHODS ****************************/ | 518 | /****************************** PROTECTED METHODS ****************************/ |
519 | 519 | ||
520 | // after changes are made to an event, this should be called. | 520 | // after changes are made to an event, this should be called. |
521 | void CalendarLocal::update( IncidenceBase *incidence ) | 521 | void CalendarLocal::update( IncidenceBase *incidence ) |
522 | { | 522 | { |
523 | incidence->setSyncStatus( Event::SYNCMOD ); | 523 | incidence->setSyncStatus( Event::SYNCMOD ); |
524 | incidence->setLastModified( QDateTime::currentDateTime() ); | 524 | incidence->setLastModified( QDateTime::currentDateTime() ); |
525 | // we should probably update the revision number here, | 525 | // we should probably update the revision number here, |
526 | // or internally in the Event itself when certain things change. | 526 | // or internally in the Event itself when certain things change. |
527 | // need to verify with ical documentation. | 527 | // need to verify with ical documentation. |
528 | 528 | ||
529 | setModified( true ); | 529 | setModified( true ); |
530 | } | 530 | } |
531 | 531 | ||
532 | void CalendarLocal::insertEvent( Event *event ) | 532 | void CalendarLocal::insertEvent( Event *event ) |
533 | { | 533 | { |
534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 534 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
535 | } | 535 | } |
536 | 536 | ||
537 | 537 | ||
538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 538 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
539 | { | 539 | { |
540 | QPtrList<Event> eventList; | 540 | QPtrList<Event> eventList; |
541 | 541 | ||
542 | Event *event; | 542 | Event *event; |
543 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 543 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
544 | if ( event->doesRecur() ) { | 544 | if ( event->doesRecur() ) { |
545 | if ( event->isMultiDay() ) { | 545 | if ( event->isMultiDay() ) { |
546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 546 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
547 | int i; | 547 | int i; |
548 | for ( i = 0; i <= extraDays; i++ ) { | 548 | for ( i = 0; i <= extraDays; i++ ) { |
549 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 549 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
550 | eventList.append( event ); | 550 | eventList.append( event ); |
551 | break; | 551 | break; |
552 | } | 552 | } |
553 | } | 553 | } |
554 | } else { | 554 | } else { |
555 | if ( event->recursOn( qd ) ) | 555 | if ( event->recursOn( qd ) ) |
556 | eventList.append( event ); | 556 | eventList.append( event ); |
557 | } | 557 | } |
558 | } else { | 558 | } else { |
559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 559 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
560 | eventList.append( event ); | 560 | eventList.append( event ); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | if ( !sorted ) { | 565 | if ( !sorted ) { |
566 | return eventList; | 566 | return eventList; |
567 | } | 567 | } |
568 | 568 | ||
569 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 569 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
570 | // now, we have to sort it based on dtStart.time() | 570 | // now, we have to sort it based on dtStart.time() |
571 | QPtrList<Event> eventListSorted; | 571 | QPtrList<Event> eventListSorted; |
572 | Event *sortEvent; | 572 | Event *sortEvent; |
573 | for ( event = eventList.first(); event; event = eventList.next() ) { | 573 | for ( event = eventList.first(); event; event = eventList.next() ) { |
574 | sortEvent = eventListSorted.first(); | 574 | sortEvent = eventListSorted.first(); |
575 | int i = 0; | 575 | int i = 0; |
576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 576 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
577 | { | 577 | { |
578 | i++; | 578 | i++; |
579 | sortEvent = eventListSorted.next(); | 579 | sortEvent = eventListSorted.next(); |
580 | } | 580 | } |
581 | eventListSorted.insert( i, event ); | 581 | eventListSorted.insert( i, event ); |
582 | } | 582 | } |
583 | return eventListSorted; | 583 | return eventListSorted; |
584 | } | 584 | } |
585 | 585 | ||
586 | 586 | ||
587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 587 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
588 | bool inclusive ) | 588 | bool inclusive ) |
589 | { | 589 | { |
590 | qDebug("CalendarLocal::rawEvents called "); | ||
590 | Event *event = 0; | 591 | Event *event = 0; |
591 | 592 | ||
592 | QPtrList<Event> eventList; | 593 | QPtrList<Event> eventList; |
593 | 594 | ||
594 | // Get non-recurring events | 595 | // Get non-recurring events |
595 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 596 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
596 | if ( event->doesRecur() ) { | 597 | if ( event->doesRecur() ) { |
597 | QDate rStart = event->dtStart().date(); | 598 | QDate rStart = event->dtStart().date(); |
598 | bool found = false; | 599 | bool found = false; |
599 | if ( inclusive ) { | 600 | if ( inclusive ) { |
600 | if ( rStart >= start && rStart <= end ) { | 601 | if ( rStart >= start && rStart <= end ) { |
601 | // Start date of event is in range. Now check for end date. | 602 | // Start date of event is in range. Now check for end date. |
602 | // if duration is negative, event recurs forever, so do not include it. | 603 | // if duration is negative, event recurs forever, so do not include it. |
603 | if ( event->recurrence()->duration() == 0 ) { // End date set | 604 | if ( event->recurrence()->duration() == 0 ) { // End date set |
604 | QDate rEnd = event->recurrence()->endDate(); | 605 | QDate rEnd = event->recurrence()->endDate(); |
605 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 606 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
606 | found = true; | 607 | found = true; |
607 | } | 608 | } |
608 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 609 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
609 | // TODO: Calculate end date from duration. Should be done in Event | 610 | // TODO: Calculate end date from duration. Should be done in Event |
610 | // For now exclude all events with a duration. | 611 | // For now exclude all events with a duration. |
611 | } | 612 | } |
612 | } | 613 | } |
613 | } else { | 614 | } else { |
614 | bool founOne; | 615 | bool founOne; |
615 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 616 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
616 | if ( founOne ) { | 617 | if ( founOne ) { |
617 | if ( next <= end ) { | 618 | if ( next <= end ) { |
618 | found = true; | 619 | found = true; |
619 | } | 620 | } |
620 | } | 621 | } |
621 | 622 | ||
622 | /* | 623 | /* |
623 | // crap !!! | 624 | // crap !!! |
624 | if ( rStart <= end ) { // Start date not after range | 625 | if ( rStart <= end ) { // Start date not after range |
625 | if ( rStart >= start ) { // Start date within range | 626 | if ( rStart >= start ) { // Start date within range |
626 | found = true; | 627 | found = true; |
627 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 628 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
628 | found = true; | 629 | found = true; |
629 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 630 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
630 | QDate rEnd = event->recurrence()->endDate(); | 631 | QDate rEnd = event->recurrence()->endDate(); |
631 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 632 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
632 | found = true; | 633 | found = true; |
633 | } | 634 | } |
634 | } else { // Duration set | 635 | } else { // Duration set |
635 | // TODO: Calculate end date from duration. Should be done in Event | 636 | // TODO: Calculate end date from duration. Should be done in Event |
636 | // For now include all events with a duration. | 637 | // For now include all events with a duration. |
637 | found = true; | 638 | found = true; |
638 | } | 639 | } |
639 | } | 640 | } |
640 | */ | 641 | */ |
641 | 642 | ||
642 | } | 643 | } |
643 | 644 | ||
644 | if ( found ) eventList.append( event ); | 645 | if ( found ) eventList.append( event ); |
645 | } else { | 646 | } else { |
646 | QDate s = event->dtStart().date(); | 647 | QDate s = event->dtStart().date(); |
647 | QDate e = event->dtEnd().date(); | 648 | QDate e = event->dtEnd().date(); |
648 | 649 | ||
649 | if ( inclusive ) { | 650 | if ( inclusive ) { |
650 | if ( s >= start && e <= end ) { | 651 | if ( s >= start && e <= end ) { |
651 | eventList.append( event ); | 652 | eventList.append( event ); |
652 | } | 653 | } |
653 | } else { | 654 | } else { |
654 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 655 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
655 | eventList.append( event ); | 656 | eventList.append( event ); |
656 | } | 657 | } |
657 | } | 658 | } |
658 | } | 659 | } |
659 | } | 660 | } |
660 | 661 | ||
661 | return eventList; | 662 | return eventList; |
662 | } | 663 | } |
663 | 664 | ||
664 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 665 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
665 | { | 666 | { |
666 | return rawEventsForDate( qdt.date() ); | 667 | return rawEventsForDate( qdt.date() ); |
667 | } | 668 | } |
668 | 669 | ||
669 | QPtrList<Event> CalendarLocal::rawEvents() | 670 | QPtrList<Event> CalendarLocal::rawEvents() |
670 | { | 671 | { |
671 | return mEventList; | 672 | return mEventList; |
672 | } | 673 | } |
673 | 674 | ||
674 | bool CalendarLocal::addJournal(Journal *journal) | 675 | bool CalendarLocal::addJournal(Journal *journal) |
675 | { | 676 | { |
676 | if ( journal->dtStart().isValid()) | 677 | if ( journal->dtStart().isValid()) |
677 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 678 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
678 | else | 679 | else |
679 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 680 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
680 | 681 | ||
681 | mJournalList.append(journal); | 682 | mJournalList.append(journal); |
682 | 683 | ||
683 | journal->registerObserver( this ); | 684 | journal->registerObserver( this ); |
684 | 685 | ||
685 | setModified( true ); | 686 | setModified( true ); |