summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-07-10 20:11:56 (UTC)
committer zautrix <zautrix>2005-07-10 20:11:56 (UTC)
commitf06311e58cb5887fd673eb1c2c48acf7cd987ad9 (patch) (unidiff)
tree301c74302cdddaa3716d79117023228005ebd265 /korganizer
parentcb784d21ad22ab72a4e3231974f67816185675fd (diff)
downloadkdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.zip
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.gz
kdepimpi-f06311e58cb5887fd673eb1c2c48acf7cd987ad9.tar.bz2
smarter faster conflict search
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp72
1 files changed, 49 insertions, 23 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a9e402e..427d71b 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -630,133 +630,150 @@ void CalendarView::init()
630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) ); 630 connect( mSuspendTimer, SIGNAL( timeout () ), SLOT( suspendAlarm() ) );
631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) ); 631 connect( mAlarmTimer, SIGNAL( timeout () ), SLOT( timerAlarm() ) );
632 mAlarmDialog = new AlarmDialog( this ); 632 mAlarmDialog = new AlarmDialog( this );
633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) ); 633 connect( mAlarmDialog, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addSuspendAlarm(const QDateTime &, const QString & ) ) );
634 mAlarmDialog->setServerNotification( false ); 634 mAlarmDialog->setServerNotification( false );
635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime ); 635 mAlarmDialog->setSuspendTime( KOPrefs::instance()->mAlarmSuspendTime );
636 636
637 637
638#ifndef DESKTOP_VERSION 638#ifndef DESKTOP_VERSION
639//US listen for arriving address resultsets 639//US listen for arriving address resultsets
640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)), 640 connect(ExternalAppHandler::instance(), SIGNAL(receivedBirthdayListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)),
641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&))); 641 this, SLOT(insertBirthdays(const QString&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&, const QStringList&)));
642#endif 642#endif
643 mDateNavigator->setCalendar( mCalendar ); 643 mDateNavigator->setCalendar( mCalendar );
644} 644}
645 645
646 646
647CalendarView::~CalendarView() 647CalendarView::~CalendarView()
648{ 648{
649 // kdDebug() << "~CalendarView()" << endl; 649 // kdDebug() << "~CalendarView()" << endl;
650 //qDebug("CalendarView::~CalendarView() "); 650 //qDebug("CalendarView::~CalendarView() ");
651 delete mDialogManager; 651 delete mDialogManager;
652 delete mViewManager; 652 delete mViewManager;
653 delete mStorage; 653 delete mStorage;
654 delete mDateFrame ; 654 delete mDateFrame ;
655 delete mEventViewerDialog; 655 delete mEventViewerDialog;
656 //kdDebug() << "~CalendarView() done" << endl; 656 //kdDebug() << "~CalendarView() done" << endl;
657} 657}
658 658
659 659
660void CalendarView::nextConflict( bool all, bool allday ) 660void CalendarView::nextConflict( bool all, bool allday )
661{ 661{
662 662 static bool block = false;
663 if ( block ) return;
664 block = true;
663 QPtrList<Event> testlist = mCalendar->events(); 665 QPtrList<Event> testlist = mCalendar->events();
664 Event * test = testlist.first(); 666 Event * test = testlist.first();
665 while ( test ) { 667 while ( test ) {
666 test->setTagged( false ); 668 test->setTagged( false );
667 test = testlist.next(); 669 test = testlist.next();
668 } 670 }
669 QTime st ( 0,0,0); 671 QTime st ( 0,0,0);
670 if ( mViewManager->currentView() == mViewManager->agendaView() ) 672 if ( mViewManager->currentView() == mViewManager->agendaView() )
671 st = mViewManager->agendaView()->agenda()->getEndTime(); 673 st = mViewManager->agendaView()->agenda()->getEndTime();
672 //qDebug("time %s ", st.toString().latin1()); 674 //qDebug("time %s ", st.toString().latin1());
673 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); 675 QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st);
674 QDateTime conflict; 676 QDateTime conflict;
675 QDateTime retVal; 677 QDateTime retVal;
676 bool found = false; 678 bool found = false;
677 Event * cE = 0; 679 Event * cE = 0;
678 Event * cE2 = 0; 680 Event * cE2 = 0;
679 QPtrList<Event> testlist2 = testlist; 681 QPtrList<Event> testlist2 = testlist;
680 test = testlist.first(); 682 test = testlist.first();
681 bool skip = false; 683 bool skip = false;
682 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 684 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
685 //QTime tm;
686 //tm.start();
683 while ( test ) { 687 while ( test ) {
684 qApp->processEvents(); 688 qApp->processEvents();
685 skip = false; 689 skip = false;
686 if ( !all ) skip = ( allday != test->doesFloat() ); 690 if ( !all ) skip = ( allday != test->doesFloat() );
687 if ( !skip ) { 691 if ( !skip ) {
692 if ( found )
693 skip = !test->matchTime( &startDT, &conflict );
694 else
695 skip = !test->matchTime( &startDT, 0 );
696 }
697 if ( !skip ) {
688 Event * test2 = testlist2.first(); 698 Event * test2 = testlist2.first();
689 while ( test2 ) { 699 while ( test2 ) {
690 skip = false; 700 skip = test2->isTagged();
691 if ( !all ) skip = ( allday != test2->doesFloat() ); 701 if ( !skip && !all ) skip = ( allday != test2->doesFloat() );
702 if ( !skip ) {
703 if ( found )
704 skip = !test2->matchTime( &startDT, &conflict );
705 else
706 skip = !test2->matchTime( &startDT, 0 );
707 }
692 if ( !skip ) { 708 if ( !skip ) {
693 if ( !test2->isTagged() ) { 709 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
694 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 710 //qDebug("overlap ");
695 //qDebug("overlap "); 711 if ( ! found ) {
696 if ( ! found ) { 712 if ( retVal >= startDT ) {
697 if ( retVal >= startDT ) { 713 conflict = retVal;
698 conflict = retVal; 714 cE = test;
699 cE = test; 715 cE2 = test2;
700 cE2 = test2; 716 found = true;
701 found = true; 717 }
702 } 718 } else {
703 } else { 719 if ( retVal >= startDT && retVal < conflict ) {
704 if ( retVal >= startDT && retVal < conflict ) { 720 conflict = retVal;
705 conflict = retVal; 721 cE = test;
706 cE = test; 722 cE2 = test2;
707 cE2 = test2;
708 }
709 } 723 }
710 } 724 }
711 } 725 }
712 } 726 }
713 test2 = testlist2.next(); 727 test2 = testlist2.next();
714 } 728 }
715 } 729 }
716 test->setTagged( true ); 730 test->setTagged( true );
717 test = testlist.next(); 731 test = testlist.next();
718 } 732 }
733 //qDebug("Search time : %d", tm.elapsed());
719 if ( found ) { 734 if ( found ) {
720 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 735 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
721 mViewManager->showDayView(); 736 mViewManager->showDayView();
722 mNavigator->slotDaySelect( conflict.date() ); 737 mNavigator->slotDaySelect( conflict.date() );
723 int hour = conflict.time().hour(); 738 int hour = conflict.time().hour();
724 mViewManager->agendaView()->setStartHour( hour ); 739 mViewManager->agendaView()->setStartHour( hour );
725 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 740 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
741 block = false;
726 return; 742 return;
727 } 743 }
728 744
729 topLevelWidget()->setCaption( i18n("No conflict found") ); 745 topLevelWidget()->setCaption( i18n("No conflict found") );
730 qDebug("No conflict found "); 746 qDebug("No conflict found ");
747 block = false;
731 return; 748 return;
732} 749}
733 750
734void CalendarView::conflictAll() 751void CalendarView::conflictAll()
735{ 752{
736 nextConflict ( true, true ); 753 nextConflict ( true, true );
737} 754}
738void CalendarView::conflictAllday() 755void CalendarView::conflictAllday()
739{ 756{
740 nextConflict ( false, true ); 757 nextConflict ( false, true );
741} 758}
742void CalendarView::conflictNotAll() 759void CalendarView::conflictNotAll()
743{ 760{
744 nextConflict ( false, false ); 761 nextConflict ( false, false );
745} 762}
746 763
747void CalendarView::setCalReadOnly( int id, bool readO ) 764void CalendarView::setCalReadOnly( int id, bool readO )
748{ 765{
749 if ( readO ) { 766 if ( readO ) {
750 emit save(); 767 emit save();
751 } 768 }
752 mCalendar->setReadOnly( id, readO ); 769 mCalendar->setReadOnly( id, readO );
753} 770}
754void CalendarView::setScrollBarStep(int val ) 771void CalendarView::setScrollBarStep(int val )
755{ 772{
756#ifdef DESKTOP_VERSION 773#ifdef DESKTOP_VERSION
757 mDateScrollBar->setLineStep ( val ); 774 mDateScrollBar->setLineStep ( val );
758#endif 775#endif
759} 776}
760void CalendarView::scrollBarValue(int val ) 777void CalendarView::scrollBarValue(int val )
761{ 778{
762#ifdef DESKTOP_VERSION 779#ifdef DESKTOP_VERSION
@@ -2743,75 +2760,84 @@ void CalendarView::changeEventDisplay(Event *which, int action)
2743 static bool clearallviews = false; 2760 static bool clearallviews = false;
2744 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2761 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2745 if ( clearallviews ) { 2762 if ( clearallviews ) {
2746 clearAllViews(); 2763 clearAllViews();
2747 clearallviews = false; 2764 clearallviews = false;
2748 } 2765 }
2749 return; 2766 return;
2750 } 2767 }
2751 clearallviews = true; 2768 clearallviews = true;
2752 mDateNavigator->updateView(); 2769 mDateNavigator->updateView();
2753 //mDialogManager->updateSearchDialog(); 2770 //mDialogManager->updateSearchDialog();
2754 if (which) { 2771 if (which) {
2755 // If there is an event view visible update the display 2772 // If there is an event view visible update the display
2756 mViewManager->currentView()->changeEventDisplay(which,action); 2773 mViewManager->currentView()->changeEventDisplay(which,action);
2757 // TODO: check, if update needed 2774 // TODO: check, if update needed
2758 // if (which->getTodoStatus()) { 2775 // if (which->getTodoStatus()) {
2759 mTodoList->updateView(); 2776 mTodoList->updateView();
2760 if ( action != KOGlobals::EVENTDELETED ) { 2777 if ( action != KOGlobals::EVENTDELETED ) {
2761 mConflictingEvent = which ; 2778 mConflictingEvent = which ;
2762 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2779 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) );
2763 } 2780 }
2764 // } 2781 // }
2765 } else { 2782 } else {
2766 mViewManager->currentView()->updateView(); 2783 mViewManager->currentView()->updateView();
2767 } 2784 }
2768} 2785}
2769void CalendarView::checkConflictForEvent() 2786void CalendarView::checkConflictForEvent()
2770{ 2787{
2771 2788
2772 if (!KOPrefs::instance()->mConfirm) 2789 if (!KOPrefs::instance()->mConfirm)
2773 return; 2790 return;
2774 if ( ! mConflictingEvent ) return; 2791 if ( ! mConflictingEvent ) return;
2775 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); 2792 QDateTime current = QDateTime::currentDateTime();
2793 if ( ! mConflictingEvent->matchTime( &current, 0 ) ) {
2794 mConflictingEvent = 0;
2795 return;
2796 }
2776 QPtrList<Event> testlist = mCalendar->events(); 2797 QPtrList<Event> testlist = mCalendar->events();
2777 Event * test = testlist.first(); 2798 Event * test = testlist.first();
2778 QDateTime conflict; 2799 QDateTime conflict;
2779 QDateTime retVal; 2800 QDateTime retVal;
2780 bool found = false; 2801 bool found = false;
2781 Event * cE = 0; 2802 Event * cE = 0;
2782 QDateTime current = QDateTime::currentDateTime(); 2803 topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") );
2783 while ( test ) { 2804 while ( test ) {
2784 qApp->processEvents(); 2805 qApp->processEvents();
2785 if ( !test->doesFloat() ) { 2806 bool skip = false;
2807 if ( found )
2808 skip = !test->matchTime( &current, &conflict );
2809 else
2810 skip = !test->matchTime( &current, 0 );
2811 if ( !skip && !test->doesFloat() ) {
2786 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2812 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2787 if ( ! found ) { 2813 if ( ! found ) {
2788 conflict = retVal; 2814 conflict = retVal;
2789 cE = test; 2815 cE = test;
2790 } else { 2816 } else {
2791 if ( retVal < conflict ) { 2817 if ( retVal < conflict ) {
2792 conflict = retVal; 2818 conflict = retVal;
2793 cE = test; 2819 cE = test;
2794 } 2820 }
2795 } 2821 }
2796 found = true; 2822 found = true;
2797 } 2823 }
2798 } 2824 }
2799 test = testlist.next(); 2825 test = testlist.next();
2800 } 2826 }
2801 if ( found ) { 2827 if ( found ) {
2802 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ; 2828 QString mess = i18n("The event\n%1\nconflicts with event\n%2\nat date\n%3.\n").arg(KGlobal::formatMessage ( mConflictingEvent->summary(),0 ) ).arg( KGlobal::formatMessage ( cE->summary(),0 )).arg(KGlobal::locale()->formatDate(conflict.date()) ) ;
2803 qApp->processEvents(); 2829 qApp->processEvents();
2804 int km = KMessageBox::warningContinueCancel(this,mess, 2830 int km = KMessageBox::warningContinueCancel(this,mess,
2805 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2831 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2806 if ( km != KMessageBox::Continue ) 2832 if ( km != KMessageBox::Continue )
2807 return; 2833 return;
2808 2834
2809 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2835 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2810 mViewManager->showDayView(); 2836 mViewManager->showDayView();
2811 mNavigator->slotDaySelect( conflict.date() ); 2837 mNavigator->slotDaySelect( conflict.date() );
2812 int hour = conflict.time().hour(); 2838 int hour = conflict.time().hour();
2813 mViewManager->agendaView()->setStartHour( hour ); 2839 mViewManager->agendaView()->setStartHour( hour );
2814 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2840 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2815 } else 2841 } else
2816 topLevelWidget()->setCaption( i18n("No conflict found") ); 2842 topLevelWidget()->setCaption( i18n("No conflict found") );
2817 mConflictingEvent = 0; 2843 mConflictingEvent = 0;