-rw-r--r-- | korganizer/calendarview.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index a9d42f0..28649d9 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -584,513 +584,517 @@ void CalendarView::init() | |||
584 | this, SLOT ( todo_unsub( Todo * ) ) ); | 584 | this, SLOT ( todo_unsub( Todo * ) ) ); |
585 | 585 | ||
586 | connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), | 586 | connect( mTodoList, SIGNAL( reparentTodoSignal( Todo *,Todo * ) ), |
587 | this, SLOT ( todo_resub( Todo *,Todo * ) ) ); | 587 | this, SLOT ( todo_resub( Todo *,Todo * ) ) ); |
588 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, | 588 | connect( this, SIGNAL( todoModified( Todo *, int )), mTodoList, |
589 | SLOT( updateTodo( Todo *, int ) ) ); | 589 | SLOT( updateTodo( Todo *, int ) ) ); |
590 | connect( this, SIGNAL( todoModified( Todo *, int )), this, | 590 | connect( this, SIGNAL( todoModified( Todo *, int )), this, |
591 | SLOT( changeTodoDisplay( Todo *, int ) ) ); | 591 | SLOT( changeTodoDisplay( Todo *, int ) ) ); |
592 | 592 | ||
593 | 593 | ||
594 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); | 594 | connect( mFilterView, SIGNAL( filterChanged() ), SLOT( updateFilter() ) ); |
595 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); | 595 | connect( mFilterView, SIGNAL( editFilters() ), SLOT( editFilters() ) ); |
596 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); | 596 | connect( mCalendar, SIGNAL( addAlarm(const QDateTime &, const QString & ) ), SLOT( addAlarm(const QDateTime &, const QString & ) ) ); |
597 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); | 597 | connect( mCalendar, SIGNAL( removeAlarm(const QDateTime &, const QString & ) ), SLOT( removeAlarm(const QDateTime &, const QString & ) ) ); |
598 | 598 | ||
599 | 599 | ||
600 | 600 | ||
601 | 601 | ||
602 | 602 | ||
603 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), | 603 | connect(QApplication::clipboard(),SIGNAL(dataChanged()), |
604 | SLOT(checkClipboard())); | 604 | SLOT(checkClipboard())); |
605 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), | 605 | connect( mTodoList,SIGNAL( incidenceSelected( Incidence * ) ), |
606 | SLOT( processTodoListSelection( Incidence * ) ) ); | 606 | SLOT( processTodoListSelection( Incidence * ) ) ); |
607 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); | 607 | connect(mTodoList,SIGNAL(isModified(bool)),SLOT(setModified(bool))); |
608 | 608 | ||
609 | // kdDebug() << "CalendarView::CalendarView() done" << endl; | 609 | // kdDebug() << "CalendarView::CalendarView() done" << endl; |
610 | 610 | ||
611 | mDateFrame = new QVBox(0,0,WType_Popup); | 611 | mDateFrame = new QVBox(0,0,WType_Popup); |
612 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); | 612 | //mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised); |
613 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); | 613 | mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised ); |
614 | mDateFrame->setLineWidth(3); | 614 | mDateFrame->setLineWidth(3); |
615 | mDateFrame->hide(); | 615 | mDateFrame->hide(); |
616 | mDateFrame->setCaption( i18n( "Pick a date to display")); | 616 | mDateFrame->setCaption( i18n( "Pick a date to display")); |
617 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); | 617 | mDatePicker = new KDatePicker ( mDateFrame , QDate::currentDate() ); |
618 | 618 | ||
619 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); | 619 | connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(slotSelectPickerDate(QDate))); |
620 | 620 | ||
621 | mEventEditor = mDialogManager->getEventEditor(); | 621 | mEventEditor = mDialogManager->getEventEditor(); |
622 | mTodoEditor = mDialogManager->getTodoEditor(); | 622 | mTodoEditor = mDialogManager->getTodoEditor(); |
623 | 623 | ||
624 | mFlagEditDescription = false; | 624 | mFlagEditDescription = false; |
625 | 625 | ||
626 | mSuspendTimer = new QTimer( this ); | 626 | mSuspendTimer = new QTimer( this ); |
627 | mAlarmTimer = new QTimer( this ); | 627 | mAlarmTimer = new QTimer( this ); |
628 | mRecheckAlarmTimer = new QTimer( this ); | 628 | mRecheckAlarmTimer = new QTimer( this ); |
629 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); | 629 | connect( mRecheckAlarmTimer, SIGNAL( timeout () ), SLOT( recheckTimerAlarm() ) ); |
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 | ||
647 | CalendarView::~CalendarView() | 647 | CalendarView::~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 | ||
660 | void CalendarView::nextConflict( bool all, bool allday ) | 660 | void CalendarView::nextConflict( bool all, bool allday ) |
661 | { | 661 | { |
662 | static bool block = false; | 662 | static bool block = false; |
663 | if ( block ) return; | 663 | if ( block ) return; |
664 | block = true; | 664 | block = true; |
665 | QPtrList<Event> testlist = mCalendar->events(); | 665 | QPtrList<Event> testlist = mCalendar->events(); |
666 | Event * test = testlist.first(); | 666 | Event * test = testlist.first(); |
667 | while ( test ) { | 667 | while ( test ) { |
668 | test->setTagged( false ); | 668 | test->setTagged( false ); |
669 | test = testlist.next(); | 669 | test = testlist.next(); |
670 | } | 670 | } |
671 | QTime st ( 0,0,0); | 671 | QTime st ( 0,0,0); |
672 | if ( mViewManager->currentView() == mViewManager->agendaView() ) | 672 | if ( mViewManager->currentView() == mViewManager->agendaView() ) |
673 | st = mViewManager->agendaView()->agenda()->getEndTime(); | 673 | st = mViewManager->agendaView()->agenda()->getEndTime(); |
674 | //qDebug("time %s ", st.toString().latin1()); | 674 | //qDebug("time %s ", st.toString().latin1()); |
675 | QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); | 675 | QDateTime startDT = QDateTime (mNavigator->selectedDates().first(),st); |
676 | QDateTime conflict; | 676 | QDateTime conflict; |
677 | QDateTime retVal; | 677 | QDateTime retVal; |
678 | bool found = false; | 678 | bool found = false; |
679 | Event * cE = 0; | 679 | Event * cE = 0; |
680 | Event * cE2 = 0; | 680 | Event * cE2 = 0; |
681 | QPtrList<Event> testlist2 = testlist; | 681 | QPtrList<Event> testlist2 = testlist; |
682 | test = testlist.first(); | 682 | test = testlist.first(); |
683 | bool skip = false; | 683 | bool skip = false; |
684 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); | 684 | topLevelWidget()->setCaption( i18n("Checking conflicts ... please wait") ); |
685 | //QTime tm; | 685 | //QTime tm; |
686 | //tm.start(); | 686 | //tm.start(); |
687 | while ( test ) { | 687 | while ( test ) { |
688 | qApp->processEvents(); | 688 | qApp->processEvents(); |
689 | skip = false; | 689 | skip = false; |
690 | if ( !all ) skip = ( allday != test->doesFloat() ); | 690 | if ( !all ) skip = ( allday != test->doesFloat() ); |
691 | if ( !skip ) { | 691 | if ( !skip ) { |
692 | if ( found ) | 692 | if ( found ) |
693 | skip = !test->matchTime( &startDT, &conflict ); | 693 | skip = !test->matchTime( &startDT, &conflict ); |
694 | else | 694 | else |
695 | skip = !test->matchTime( &startDT, 0 ); | 695 | skip = !test->matchTime( &startDT, 0 ); |
696 | } | 696 | } |
697 | if ( !skip ) { | 697 | if ( !skip ) { |
698 | Event * test2 = testlist2.first(); | 698 | Event * test2 = testlist2.first(); |
699 | while ( test2 ) { | 699 | while ( test2 ) { |
700 | skip = test2->isTagged(); | 700 | skip = test2->isTagged(); |
701 | if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); | 701 | if ( !skip && !all ) skip = ( allday != test2->doesFloat() ); |
702 | if ( !skip ) { | 702 | if ( !skip ) { |
703 | if ( found ) | 703 | if ( found ) |
704 | skip = !test2->matchTime( &startDT, &conflict ); | 704 | skip = !test2->matchTime( &startDT, &conflict ); |
705 | else | 705 | else |
706 | skip = !test2->matchTime( &startDT, 0 ); | 706 | skip = !test2->matchTime( &startDT, 0 ); |
707 | } | 707 | } |
708 | if ( !skip ) { | 708 | if ( !skip ) { |
709 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { | 709 | if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { |
710 | //qDebug("overlap "); | 710 | //qDebug("overlap "); |
711 | if ( ! found ) { | 711 | if ( ! found ) { |
712 | if ( retVal >= startDT ) { | 712 | if ( retVal >= startDT ) { |
713 | conflict = retVal; | 713 | conflict = retVal; |
714 | cE = test; | 714 | cE = test; |
715 | cE2 = test2; | 715 | cE2 = test2; |
716 | found = true; | 716 | found = true; |
717 | } | 717 | } |
718 | } else { | 718 | } else { |
719 | if ( retVal >= startDT && retVal < conflict ) { | 719 | if ( retVal >= startDT && retVal < conflict ) { |
720 | conflict = retVal; | 720 | conflict = retVal; |
721 | cE = test; | 721 | cE = test; |
722 | cE2 = test2; | 722 | cE2 = test2; |
723 | } | 723 | } |
724 | } | 724 | } |
725 | } | 725 | } |
726 | } | 726 | } |
727 | test2 = testlist2.next(); | 727 | test2 = testlist2.next(); |
728 | } | 728 | } |
729 | } | 729 | } |
730 | test->setTagged( true ); | 730 | test->setTagged( true ); |
731 | test = testlist.next(); | 731 | test = testlist.next(); |
732 | } | 732 | } |
733 | //qDebug("Search time : %d", tm.elapsed()); | 733 | //qDebug("Search time : %d", tm.elapsed()); |
734 | if ( found ) { | 734 | if ( found ) { |
735 | if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) | 735 | if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) |
736 | mViewManager->showDayView(); | 736 | mViewManager->showDayView(); |
737 | mNavigator->slotDaySelect( conflict.date() ); | 737 | mNavigator->slotDaySelect( conflict.date() ); |
738 | int hour = conflict.time().hour(); | 738 | int hour = conflict.time().hour(); |
739 | mViewManager->agendaView()->setStartHour( hour ); | 739 | mViewManager->agendaView()->setStartHour( hour ); |
740 | 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; | 741 | block = false; |
742 | return; | 742 | return; |
743 | } | 743 | } |
744 | 744 | ||
745 | topLevelWidget()->setCaption( i18n("No conflict found") ); | 745 | topLevelWidget()->setCaption( i18n("No conflict found") ); |
746 | //qDebug("No conflict found "); | 746 | //qDebug("No conflict found "); |
747 | block = false; | 747 | block = false; |
748 | return; | 748 | return; |
749 | } | 749 | } |
750 | 750 | ||
751 | void CalendarView::conflictAll() | 751 | void CalendarView::conflictAll() |
752 | { | 752 | { |
753 | nextConflict ( true, true ); | 753 | nextConflict ( true, true ); |
754 | } | 754 | } |
755 | void CalendarView::conflictAllday() | 755 | void CalendarView::conflictAllday() |
756 | { | 756 | { |
757 | nextConflict ( false, true ); | 757 | nextConflict ( false, true ); |
758 | } | 758 | } |
759 | void CalendarView::conflictNotAll() | 759 | void CalendarView::conflictNotAll() |
760 | { | 760 | { |
761 | nextConflict ( false, false ); | 761 | nextConflict ( false, false ); |
762 | } | 762 | } |
763 | 763 | ||
764 | void CalendarView::setCalReadOnly( int id, bool readO ) | 764 | void CalendarView::setCalReadOnly( int id, bool readO ) |
765 | { | 765 | { |
766 | if ( readO ) { | 766 | if ( readO ) { |
767 | emit save(); | 767 | emit save(); |
768 | } | 768 | } |
769 | mCalendar->setReadOnly( id, readO ); | 769 | mCalendar->setReadOnly( id, readO ); |
770 | } | 770 | } |
771 | void CalendarView::setScrollBarStep(int val ) | 771 | void CalendarView::setScrollBarStep(int val ) |
772 | { | 772 | { |
773 | #ifdef DESKTOP_VERSION | 773 | #ifdef DESKTOP_VERSION |
774 | mDateScrollBar->setLineStep ( val ); | 774 | mDateScrollBar->setLineStep ( val ); |
775 | #endif | 775 | #endif |
776 | } | 776 | } |
777 | void CalendarView::scrollBarValue(int val ) | 777 | void CalendarView::scrollBarValue(int val ) |
778 | { | 778 | { |
779 | #ifdef DESKTOP_VERSION | 779 | #ifdef DESKTOP_VERSION |
780 | if ( QApplication::desktop()->width() < 800 ) return; | 780 | if ( QApplication::desktop()->width() < 800 ) return; |
781 | static bool block = false; | 781 | static bool block = false; |
782 | if ( block ) return; | 782 | if ( block ) return; |
783 | block = true; | 783 | block = true; |
784 | int count = mNavigator->selectedDates().count(); | 784 | int count = mNavigator->selectedDates().count(); |
785 | int day = mNavigator->selectedDates().first().dayOfYear(); | 785 | int day = mNavigator->selectedDates().first().dayOfYear(); |
786 | int stepdays = val; | 786 | int stepdays = val; |
787 | if ( mDateScrollBar->lineStep () <= count ) { | 787 | if ( mDateScrollBar->lineStep () <= count ) { |
788 | //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); | 788 | //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); |
789 | //qDebug("VAL %d ",val ); | 789 | //qDebug("VAL %d ",val ); |
790 | stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); | 790 | stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); |
791 | stepdays = day+stepdays; | 791 | stepdays = day+stepdays; |
792 | if ( stepdays < 0 ) stepdays = 0; | 792 | if ( stepdays < 0 ) stepdays = 0; |
793 | } | 793 | } |
794 | if ( stepdays == day ) { | 794 | if ( stepdays == day ) { |
795 | block = false; | 795 | block = false; |
796 | return; | 796 | return; |
797 | } | 797 | } |
798 | int year = mNavigator->selectedDates().first().year(); | 798 | int year = mNavigator->selectedDates().first().year(); |
799 | QDate d ( year,1,1 ); | 799 | QDate d ( year,1,1 ); |
800 | mNavigator->selectDates( d.addDays( stepdays-1) , count ); | 800 | mNavigator->selectDates( d.addDays( stepdays-1) , count ); |
801 | block = false; | 801 | block = false; |
802 | #endif | 802 | #endif |
803 | 803 | ||
804 | } | 804 | } |
805 | void CalendarView::updateView(const QDate &start, const QDate &end) | 805 | void CalendarView::updateView(const QDate &start, const QDate &end) |
806 | { | 806 | { |
807 | #ifdef DESKTOP_VERSION | 807 | #ifdef DESKTOP_VERSION |
808 | if ( ! mDateScrollBar->draggingSlider () ) { | 808 | if ( ! mDateScrollBar->draggingSlider () ) { |
809 | int dof = start.dayOfYear(); | 809 | int dof = start.dayOfYear(); |
810 | //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); | 810 | //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); |
811 | if ( dof != mDateScrollBar->value() ) { | 811 | if ( dof != mDateScrollBar->value() ) { |
812 | mDateScrollBar->blockSignals( true ); | 812 | mDateScrollBar->blockSignals( true ); |
813 | mDateScrollBar->setValue( start.dayOfYear()); | 813 | mDateScrollBar->setValue( start.dayOfYear()); |
814 | mDateScrollBar->blockSignals( false ); | 814 | mDateScrollBar->blockSignals( false ); |
815 | } | 815 | } |
816 | } | 816 | } |
817 | #endif | 817 | #endif |
818 | mTodoList->updateView(); | 818 | mTodoList->updateView(); |
819 | mViewManager->updateView(start, end); | 819 | mViewManager->updateView(start, end); |
820 | //mDateNavigator->updateView(); | 820 | //mDateNavigator->updateView(); |
821 | } | 821 | } |
822 | 822 | ||
823 | 823 | ||
824 | 824 | ||
825 | void CalendarView::checkFiles() | 825 | void CalendarView::checkFiles() |
826 | { | 826 | { |
827 | QString message; | 827 | QString message; |
828 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 828 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
829 | KopiCalendarFile * cal = calendars.first(); | 829 | KopiCalendarFile * cal = calendars.first(); |
830 | while ( cal ) { | 830 | while ( cal ) { |
831 | if ( cal->mErrorOnLoad ) { | 831 | if ( cal->mErrorOnLoad ) { |
832 | message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; | 832 | message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; |
833 | } | 833 | } |
834 | cal = calendars.next(); | 834 | cal = calendars.next(); |
835 | } | 835 | } |
836 | if ( !message.isEmpty() ) { | 836 | if ( !message.isEmpty() ) { |
837 | message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); | 837 | message = KGlobal::formatMessage( i18n("Calendar(s) not loaded:"),0 )+"\n" + message +KGlobal::formatMessage(i18n("You can try to reload the calendar in the Resource View!"),0); |
838 | KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); | 838 | KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); |
839 | } | 839 | } |
840 | QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); | 840 | static bool firstTime = true; |
841 | if ( firstTime ) { | ||
842 | firstTime = false; | ||
843 | QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); | ||
844 | } | ||
841 | } | 845 | } |
842 | void CalendarView::checkAlarms() | 846 | void CalendarView::checkAlarms() |
843 | { | 847 | { |
844 | 848 | ||
845 | 849 | ||
846 | KConfig *config = KOGlobals::config(); | 850 | KConfig *config = KOGlobals::config(); |
847 | config->setGroup( "AppRun" ); | 851 | config->setGroup( "AppRun" ); |
848 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); | 852 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); |
849 | int daysto = dt.daysTo( QDate::currentDate() ); | 853 | int daysto = dt.daysTo( QDate::currentDate() ); |
850 | int days = config->readNumEntry( "LatestProgramStopDays" , daysto); | 854 | int days = config->readNumEntry( "LatestProgramStopDays" , daysto); |
851 | dt = dt.addDays( days ); | 855 | dt = dt.addDays( days ); |
852 | int secto = dt.secsTo( QDateTime::currentDateTime() ); | 856 | int secto = dt.secsTo( QDateTime::currentDateTime() ); |
853 | int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; | 857 | int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; |
854 | //qDebug("KO: Reading program stop %d ", secs); | 858 | //qDebug("KO: Reading program stop %d ", secs); |
855 | //secs -= ( 3600 * 24*3 ); // debug only | 859 | //secs -= ( 3600 * 24*3 ); // debug only |
856 | QDateTime latest = dt.addSecs ( secs ); | 860 | QDateTime latest = dt.addSecs ( secs ); |
857 | qDebug("KO: Last termination on %s ", latest.toString().latin1()); | 861 | qDebug("KO: Last termination on %s ", latest.toString().latin1()); |
858 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); | 862 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); |
859 | QPtrList<Incidence> el = mCalendar->rawIncidences(); | 863 | QPtrList<Incidence> el = mCalendar->rawIncidences(); |
860 | QPtrList<Incidence> al; | 864 | QPtrList<Incidence> al; |
861 | Incidence* inL = el.first(); | 865 | Incidence* inL = el.first(); |
862 | QDateTime cur = QDateTime::currentDateTime().addSecs(-59); | 866 | QDateTime cur = QDateTime::currentDateTime().addSecs(-59); |
863 | qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); | 867 | qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); |
864 | while ( inL ) { | 868 | while ( inL ) { |
865 | bool ok = false; | 869 | bool ok = false; |
866 | int offset = 0; | 870 | int offset = 0; |
867 | QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; | 871 | QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; |
868 | if ( ok ) { | 872 | if ( ok ) { |
869 | //qDebug("OK %s",next.toString().latin1()); | 873 | //qDebug("OK %s",next.toString().latin1()); |
870 | if ( next < cur ) { | 874 | if ( next < cur ) { |
871 | al.append( inL ); | 875 | al.append( inL ); |
872 | //qDebug("found missed alarm: %s ", inL->summary().latin1() ); | 876 | //qDebug("found missed alarm: %s ", inL->summary().latin1() ); |
873 | } | 877 | } |
874 | } | 878 | } |
875 | inL = el.next(); | 879 | inL = el.next(); |
876 | } | 880 | } |
877 | if ( al.count() ) { | 881 | if ( al.count() ) { |
878 | QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); | 882 | QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); |
879 | dia->setCaption( i18n("KO/Pi: Missing alarms!") ); | 883 | dia->setCaption( i18n("KO/Pi: Missing alarms!") ); |
880 | QVBoxLayout* lay = new QVBoxLayout( dia ); | 884 | QVBoxLayout* lay = new QVBoxLayout( dia ); |
881 | lay->setSpacing( 0 ); | 885 | lay->setSpacing( 0 ); |
882 | lay->setMargin( 0 ); | 886 | lay->setMargin( 0 ); |
883 | MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); | 887 | MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); |
884 | connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); | 888 | connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); |
885 | lay->addWidget( matb ); | 889 | lay->addWidget( matb ); |
886 | if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { | 890 | if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { |
887 | int wid = 210; | 891 | int wid = 210; |
888 | int x = QApplication::desktop()->width() - wid - 7; | 892 | int x = QApplication::desktop()->width() - wid - 7; |
889 | int y = QApplication::desktop()->height() - wid - 70; | 893 | int y = QApplication::desktop()->height() - wid - 70; |
890 | dia->setGeometry ( x,y,wid,wid); | 894 | dia->setGeometry ( x,y,wid,wid); |
891 | } else { | 895 | } else { |
892 | int si = 220; | 896 | int si = 220; |
893 | if ( QApplication::desktop()->width() > 470 ) | 897 | if ( QApplication::desktop()->width() > 470 ) |
894 | si = 400; | 898 | si = 400; |
895 | dia->resize(si,si/2); | 899 | dia->resize(si,si/2); |
896 | } | 900 | } |
897 | dia->setBackgroundColor( QColor( 255, 255, 255 ) ); | 901 | dia->setBackgroundColor( QColor( 255, 255, 255 ) ); |
898 | dia->show(); | 902 | dia->show(); |
899 | 903 | ||
900 | } | 904 | } |
901 | } | 905 | } |
902 | void CalendarView::showDay( QDate d ) | 906 | void CalendarView::showDay( QDate d ) |
903 | { | 907 | { |
904 | dateNavigator()->blockSignals( true ); | 908 | dateNavigator()->blockSignals( true ); |
905 | dateNavigator()->selectDate( d ); | 909 | dateNavigator()->selectDate( d ); |
906 | dateNavigator()->blockSignals( false ); | 910 | dateNavigator()->blockSignals( false ); |
907 | mViewManager->showDayView(); | 911 | mViewManager->showDayView(); |
908 | //dateNavigator()->selectDate( d ); | 912 | //dateNavigator()->selectDate( d ); |
909 | } | 913 | } |
910 | void CalendarView::timerAlarm() | 914 | void CalendarView::timerAlarm() |
911 | { | 915 | { |
912 | //qDebug("CalendarView::timerAlarm() "); | 916 | //qDebug("CalendarView::timerAlarm() "); |
913 | computeAlarm(mAlarmNotification ); | 917 | computeAlarm(mAlarmNotification ); |
914 | } | 918 | } |
915 | 919 | ||
916 | void CalendarView::suspendAlarm() | 920 | void CalendarView::suspendAlarm() |
917 | { | 921 | { |
918 | //qDebug(" CalendarView::suspendAlarm() "); | 922 | //qDebug(" CalendarView::suspendAlarm() "); |
919 | computeAlarm(mSuspendAlarmNotification ); | 923 | computeAlarm(mSuspendAlarmNotification ); |
920 | 924 | ||
921 | } | 925 | } |
922 | 926 | ||
923 | void CalendarView::startAlarm( QString mess , QString filename) | 927 | void CalendarView::startAlarm( QString mess , QString filename) |
924 | { | 928 | { |
925 | 929 | ||
926 | topLevelWidget()->showNormal(); | 930 | topLevelWidget()->showNormal(); |
927 | topLevelWidget()->setActiveWindow(); | 931 | topLevelWidget()->setActiveWindow(); |
928 | topLevelWidget()->raise(); | 932 | topLevelWidget()->raise(); |
929 | 933 | ||
930 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); | 934 | mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); |
931 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); | 935 | QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); |
932 | 936 | ||
933 | } | 937 | } |
934 | 938 | ||
935 | void CalendarView::checkNextTimerAlarm() | 939 | void CalendarView::checkNextTimerAlarm() |
936 | { | 940 | { |
937 | mCalendar->checkAlarmForIncidence( 0, true ); | 941 | mCalendar->checkAlarmForIncidence( 0, true ); |
938 | } | 942 | } |
939 | 943 | ||
940 | void CalendarView::computeAlarm( QString msg ) | 944 | void CalendarView::computeAlarm( QString msg ) |
941 | { | 945 | { |
942 | 946 | ||
943 | QString mess = msg; | 947 | QString mess = msg; |
944 | QString mAlarmMessage = mess.mid( 9 ); | 948 | QString mAlarmMessage = mess.mid( 9 ); |
945 | QString filename = MainWindow::resourcePath(); | 949 | QString filename = MainWindow::resourcePath(); |
946 | filename += "koalarm.wav"; | 950 | filename += "koalarm.wav"; |
947 | QString tempfilename; | 951 | QString tempfilename; |
948 | if ( mess.left( 13 ) == "suspend_alarm") { | 952 | if ( mess.left( 13 ) == "suspend_alarm") { |
949 | bool error = false; | 953 | bool error = false; |
950 | int len = mess.mid( 13 ).find("+++"); | 954 | int len = mess.mid( 13 ).find("+++"); |
951 | if ( len < 2 ) | 955 | if ( len < 2 ) |
952 | error = true; | 956 | error = true; |
953 | else { | 957 | else { |
954 | tempfilename = mess.mid( 13, len ); | 958 | tempfilename = mess.mid( 13, len ); |
955 | if ( !QFile::exists( tempfilename ) ) | 959 | if ( !QFile::exists( tempfilename ) ) |
956 | error = true; | 960 | error = true; |
957 | } | 961 | } |
958 | if ( ! error ) { | 962 | if ( ! error ) { |
959 | filename = tempfilename; | 963 | filename = tempfilename; |
960 | } | 964 | } |
961 | mAlarmMessage = mess.mid( 13+len+3 ); | 965 | mAlarmMessage = mess.mid( 13+len+3 ); |
962 | //qDebug("suspend file %s ",tempfilename.latin1() ); | 966 | //qDebug("suspend file %s ",tempfilename.latin1() ); |
963 | startAlarm( mAlarmMessage, filename); | 967 | startAlarm( mAlarmMessage, filename); |
964 | return; | 968 | return; |
965 | } | 969 | } |
966 | if ( mess.left( 11 ) == "timer_alarm") { | 970 | if ( mess.left( 11 ) == "timer_alarm") { |
967 | //mTimerTime = 0; | 971 | //mTimerTime = 0; |
968 | startAlarm( mess.mid( 11 ), filename ); | 972 | startAlarm( mess.mid( 11 ), filename ); |
969 | return; | 973 | return; |
970 | } | 974 | } |
971 | if ( mess.left( 10 ) == "proc_alarm") { | 975 | if ( mess.left( 10 ) == "proc_alarm") { |
972 | bool error = false; | 976 | bool error = false; |
973 | int len = mess.mid( 10 ).find("+++"); | 977 | int len = mess.mid( 10 ).find("+++"); |
974 | if ( len < 2 ) | 978 | if ( len < 2 ) |
975 | error = true; | 979 | error = true; |
976 | else { | 980 | else { |
977 | tempfilename = mess.mid( 10, len ); | 981 | tempfilename = mess.mid( 10, len ); |
978 | if ( !QFile::exists( tempfilename ) ) | 982 | if ( !QFile::exists( tempfilename ) ) |
979 | error = true; | 983 | error = true; |
980 | } | 984 | } |
981 | if ( error ) { | 985 | if ( error ) { |
982 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; | 986 | mAlarmMessage = "Procedure Alarm\nError - File not found\n"; |
983 | mAlarmMessage += mess.mid( 10+len+3+9 ); | 987 | mAlarmMessage += mess.mid( 10+len+3+9 ); |
984 | } else { | 988 | } else { |
985 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); | 989 | //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); |
986 | //qDebug("-----system command %s ",tempfilename.latin1() ); | 990 | //qDebug("-----system command %s ",tempfilename.latin1() ); |
987 | #ifndef _WIN32_ | 991 | #ifndef _WIN32_ |
988 | if ( vfork () == 0 ) { | 992 | if ( vfork () == 0 ) { |
989 | execl ( tempfilename.latin1(), 0 ); | 993 | execl ( tempfilename.latin1(), 0 ); |
990 | return; | 994 | return; |
991 | } | 995 | } |
992 | #else | 996 | #else |
993 | QProcess* p = new QProcess(); | 997 | QProcess* p = new QProcess(); |
994 | p->addArgument( tempfilename.latin1() ); | 998 | p->addArgument( tempfilename.latin1() ); |
995 | p->start(); | 999 | p->start(); |
996 | return; | 1000 | return; |
997 | #endif | 1001 | #endif |
998 | 1002 | ||
999 | return; | 1003 | return; |
1000 | } | 1004 | } |
1001 | 1005 | ||
1002 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); | 1006 | //qDebug("+++++++system command %s ",tempfilename.latin1() ); |
1003 | } | 1007 | } |
1004 | if ( mess.left( 11 ) == "audio_alarm") { | 1008 | if ( mess.left( 11 ) == "audio_alarm") { |
1005 | bool error = false; | 1009 | bool error = false; |
1006 | int len = mess.mid( 11 ).find("+++"); | 1010 | int len = mess.mid( 11 ).find("+++"); |
1007 | if ( len < 2 ) | 1011 | if ( len < 2 ) |
1008 | error = true; | 1012 | error = true; |
1009 | else { | 1013 | else { |
1010 | tempfilename = mess.mid( 11, len ); | 1014 | tempfilename = mess.mid( 11, len ); |
1011 | if ( !QFile::exists( tempfilename ) ) | 1015 | if ( !QFile::exists( tempfilename ) ) |
1012 | error = true; | 1016 | error = true; |
1013 | } | 1017 | } |
1014 | if ( ! error ) { | 1018 | if ( ! error ) { |
1015 | filename = tempfilename; | 1019 | filename = tempfilename; |
1016 | } | 1020 | } |
1017 | mAlarmMessage = mess.mid( 11+len+3+9 ); | 1021 | mAlarmMessage = mess.mid( 11+len+3+9 ); |
1018 | //qDebug("audio file command %s ",tempfilename.latin1() ); | 1022 | //qDebug("audio file command %s ",tempfilename.latin1() ); |
1019 | } | 1023 | } |
1020 | if ( mess.left( 9 ) == "cal_alarm") { | 1024 | if ( mess.left( 9 ) == "cal_alarm") { |
1021 | mAlarmMessage = mess.mid( 9 ) ; | 1025 | mAlarmMessage = mess.mid( 9 ) ; |
1022 | } | 1026 | } |
1023 | 1027 | ||
1024 | startAlarm( mAlarmMessage, filename ); | 1028 | startAlarm( mAlarmMessage, filename ); |
1025 | 1029 | ||
1026 | 1030 | ||
1027 | } | 1031 | } |
1028 | 1032 | ||
1029 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) | 1033 | void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString ¬i ) |
1030 | { | 1034 | { |
1031 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1035 | //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1032 | 1036 | ||
1033 | mSuspendAlarmNotification = noti; | 1037 | mSuspendAlarmNotification = noti; |
1034 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; | 1038 | int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; |
1035 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); | 1039 | //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); |
1036 | mSuspendTimer->start( ms , true ); | 1040 | mSuspendTimer->start( ms , true ); |
1037 | 1041 | ||
1038 | } | 1042 | } |
1039 | 1043 | ||
1040 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) | 1044 | void CalendarView::addAlarm(const QDateTime &qdt, const QString ¬i ) |
1041 | { | 1045 | { |
1042 | mNextAlarmDateTime = qdt; | 1046 | mNextAlarmDateTime = qdt; |
1043 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1047 | //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1044 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1048 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1045 | #ifndef DESKTOP_VERSION | 1049 | #ifndef DESKTOP_VERSION |
1046 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); | 1050 | AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); |
1047 | #endif | 1051 | #endif |
1048 | return; | 1052 | return; |
1049 | } | 1053 | } |
1050 | int maxSec; | 1054 | int maxSec; |
1051 | //maxSec = 5; //testing only | 1055 | //maxSec = 5; //testing only |
1052 | maxSec = 86400+3600; // one day+1hour | 1056 | maxSec = 86400+3600; // one day+1hour |
1053 | mAlarmNotification = noti; | 1057 | mAlarmNotification = noti; |
1054 | int sec = QDateTime::currentDateTime().secsTo( qdt ); | 1058 | int sec = QDateTime::currentDateTime().secsTo( qdt ); |
1055 | if ( sec > maxSec ) { | 1059 | if ( sec > maxSec ) { |
1056 | mRecheckAlarmTimer->start( maxSec * 1000 ); | 1060 | mRecheckAlarmTimer->start( maxSec * 1000 ); |
1057 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); | 1061 | // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); |
1058 | return; | 1062 | return; |
1059 | } else { | 1063 | } else { |
1060 | mRecheckAlarmTimer->stop(); | 1064 | mRecheckAlarmTimer->stop(); |
1061 | } | 1065 | } |
1062 | //qDebug("Alarm timer started with secs: %d ", sec); | 1066 | //qDebug("Alarm timer started with secs: %d ", sec); |
1063 | mAlarmTimer->start( sec *1000 , true ); | 1067 | mAlarmTimer->start( sec *1000 , true ); |
1064 | 1068 | ||
1065 | } | 1069 | } |
1066 | // called by mRecheckAlarmTimer to get next alarm | 1070 | // called by mRecheckAlarmTimer to get next alarm |
1067 | // we need this, because a QTimer has only a max range of 25 days | 1071 | // we need this, because a QTimer has only a max range of 25 days |
1068 | void CalendarView::recheckTimerAlarm() | 1072 | void CalendarView::recheckTimerAlarm() |
1069 | { | 1073 | { |
1070 | mAlarmTimer->stop(); | 1074 | mAlarmTimer->stop(); |
1071 | mRecheckAlarmTimer->stop(); | 1075 | mRecheckAlarmTimer->stop(); |
1072 | mCalendar->checkAlarmForIncidence( 0, true ); | 1076 | mCalendar->checkAlarmForIncidence( 0, true ); |
1073 | } | 1077 | } |
1074 | #ifndef DESKTOP_VERSION | 1078 | #ifndef DESKTOP_VERSION |
1075 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) | 1079 | void CalendarView::removeAlarm(const QDateTime &qdt, const QString ¬i ) |
1076 | #else | 1080 | #else |
1077 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) | 1081 | void CalendarView::removeAlarm(const QDateTime &, const QString & ) |
1078 | #endif | 1082 | #endif |
1079 | { | 1083 | { |
1080 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); | 1084 | //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); |
1081 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { | 1085 | if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { |
1082 | #ifndef DESKTOP_VERSION | 1086 | #ifndef DESKTOP_VERSION |
1083 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); | 1087 | AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); |
1084 | #endif | 1088 | #endif |
1085 | return; | 1089 | return; |
1086 | } | 1090 | } |
1087 | mAlarmTimer->stop(); | 1091 | mAlarmTimer->stop(); |
1088 | } | 1092 | } |
1089 | void CalendarView::selectWeekNum ( int num ) | 1093 | void CalendarView::selectWeekNum ( int num ) |
1090 | { | 1094 | { |
1091 | dateNavigator()->blockSignals( true ); | 1095 | dateNavigator()->blockSignals( true ); |
1092 | dateNavigator()->selectWeek( num ); | 1096 | dateNavigator()->selectWeek( num ); |
1093 | dateNavigator()->blockSignals( false ); | 1097 | dateNavigator()->blockSignals( false ); |
1094 | mViewManager->showWeekView(); | 1098 | mViewManager->showWeekView(); |
1095 | } | 1099 | } |
1096 | KOViewManager *CalendarView::viewManager() | 1100 | KOViewManager *CalendarView::viewManager() |