summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-07-09 08:48:32 (UTC)
committer zautrix <zautrix>2005-07-09 08:48:32 (UTC)
commitf731dd9fc5b3f14c44d4de26eb5370a79c63887c (patch) (unidiff)
treee3d7b3929cc8819a5451bd04c9698bc0767e49b1
parente27ad31c6016152449bbdaf4f9f387fa61183c37 (diff)
downloadkdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.zip
kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.gz
kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.bz2
fixi
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp20
-rw-r--r--korganizer/calendarview.h1
-rw-r--r--korganizer/journalentry.cpp22
-rw-r--r--korganizer/journalentry.h3
-rw-r--r--korganizer/mainwindow.cpp2
-rw-r--r--libkcal/calendar.cpp3
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp75
-rw-r--r--libkcal/calendarlocal.h3
9 files changed, 127 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 940ea91..ccacc52 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -686,3449 +686,3469 @@ void CalendarView::nextConflict( bool all, bool allday )
686 skip = false; 686 skip = false;
687 if ( !all ) skip = ( allday != test2->doesFloat() ); 687 if ( !all ) skip = ( allday != test2->doesFloat() );
688 if ( !skip ) { 688 if ( !skip ) {
689 if ( !test2->isTagged() ) { 689 if ( !test2->isTagged() ) {
690 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) { 690 if ( test->isOverlapping ( test2, &retVal, &startDT ) ) {
691 //qDebug("overlap "); 691 //qDebug("overlap ");
692 if ( ! found ) { 692 if ( ! found ) {
693 if ( retVal >= startDT ) { 693 if ( retVal >= startDT ) {
694 conflict = retVal; 694 conflict = retVal;
695 cE = test; 695 cE = test;
696 cE2 = test2; 696 cE2 = test2;
697 found = true; 697 found = true;
698 } 698 }
699 } else { 699 } else {
700 if ( retVal >= startDT && retVal < conflict ) { 700 if ( retVal >= startDT && retVal < conflict ) {
701 conflict = retVal; 701 conflict = retVal;
702 cE = test; 702 cE = test;
703 cE2 = test2; 703 cE2 = test2;
704 } 704 }
705 } 705 }
706 } 706 }
707 } 707 }
708 } 708 }
709 test2 = testlist2.next(); 709 test2 = testlist2.next();
710 } 710 }
711 } 711 }
712 test->setTagged( true ); 712 test->setTagged( true );
713 test = testlist.next(); 713 test = testlist.next();
714 } 714 }
715 if ( found ) { 715 if ( found ) {
716 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 716 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
717 mViewManager->showDayView(); 717 mViewManager->showDayView();
718 mNavigator->slotDaySelect( conflict.date() ); 718 mNavigator->slotDaySelect( conflict.date() );
719 int hour = conflict.time().hour(); 719 int hour = conflict.time().hour();
720 mViewManager->agendaView()->setStartHour( hour ); 720 mViewManager->agendaView()->setStartHour( hour );
721 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) ); 721 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( cE->summary().left( 20 ) ).arg( cE2->summary().left( 20 ) ) );
722 return; 722 return;
723 } 723 }
724 724
725 topLevelWidget()->setCaption( i18n("No conflict found") ); 725 topLevelWidget()->setCaption( i18n("No conflict found") );
726 qDebug("No conflict found "); 726 qDebug("No conflict found ");
727 return; 727 return;
728} 728}
729 729
730void CalendarView::conflictAll() 730void CalendarView::conflictAll()
731{ 731{
732 nextConflict ( true, true ); 732 nextConflict ( true, true );
733} 733}
734void CalendarView::conflictAllday() 734void CalendarView::conflictAllday()
735{ 735{
736 nextConflict ( false, true ); 736 nextConflict ( false, true );
737} 737}
738void CalendarView::conflictNotAll() 738void CalendarView::conflictNotAll()
739{ 739{
740 nextConflict ( false, false ); 740 nextConflict ( false, false );
741} 741}
742 742
743void CalendarView::setCalReadOnly( int id, bool readO ) 743void CalendarView::setCalReadOnly( int id, bool readO )
744{ 744{
745 if ( readO ) { 745 if ( readO ) {
746 emit save(); 746 emit save();
747 } 747 }
748 mCalendar->setReadOnly( id, readO ); 748 mCalendar->setReadOnly( id, readO );
749} 749}
750void CalendarView::setScrollBarStep(int val ) 750void CalendarView::setScrollBarStep(int val )
751{ 751{
752#ifdef DESKTOP_VERSION 752#ifdef DESKTOP_VERSION
753 mDateScrollBar->setLineStep ( val ); 753 mDateScrollBar->setLineStep ( val );
754#endif 754#endif
755} 755}
756void CalendarView::scrollBarValue(int val ) 756void CalendarView::scrollBarValue(int val )
757{ 757{
758#ifdef DESKTOP_VERSION 758#ifdef DESKTOP_VERSION
759 if ( QApplication::desktop()->width() < 800 ) return; 759 if ( QApplication::desktop()->width() < 800 ) return;
760 static bool block = false; 760 static bool block = false;
761 if ( block ) return; 761 if ( block ) return;
762 block = true; 762 block = true;
763 int count = mNavigator->selectedDates().count(); 763 int count = mNavigator->selectedDates().count();
764 int day = mNavigator->selectedDates().first().dayOfYear(); 764 int day = mNavigator->selectedDates().first().dayOfYear();
765 int stepdays = val; 765 int stepdays = val;
766 if ( mDateScrollBar->lineStep () <= count ) { 766 if ( mDateScrollBar->lineStep () <= count ) {
767 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 767 //val = val/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
768 //qDebug("VAL %d ",val ); 768 //qDebug("VAL %d ",val );
769 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep(); 769 stepdays = (val-day)/mDateScrollBar->lineStep ()*mDateScrollBar->lineStep();
770 stepdays = day+stepdays; 770 stepdays = day+stepdays;
771 if ( stepdays < 0 ) stepdays = 0; 771 if ( stepdays < 0 ) stepdays = 0;
772 } 772 }
773 if ( stepdays == day ) { 773 if ( stepdays == day ) {
774 block = false; 774 block = false;
775 return; 775 return;
776 } 776 }
777 int year = mNavigator->selectedDates().first().year(); 777 int year = mNavigator->selectedDates().first().year();
778 QDate d ( year,1,1 ); 778 QDate d ( year,1,1 );
779 mNavigator->selectDates( d.addDays( stepdays-1) , count ); 779 mNavigator->selectDates( d.addDays( stepdays-1) , count );
780 block = false; 780 block = false;
781#endif 781#endif
782 782
783} 783}
784void CalendarView::updateView(const QDate &start, const QDate &end) 784void CalendarView::updateView(const QDate &start, const QDate &end)
785{ 785{
786#ifdef DESKTOP_VERSION 786#ifdef DESKTOP_VERSION
787 if ( ! mDateScrollBar->draggingSlider () ) { 787 if ( ! mDateScrollBar->draggingSlider () ) {
788 int dof = start.dayOfYear(); 788 int dof = start.dayOfYear();
789 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() ); 789 //qDebug("dof %d day %d val %d ", dof, start.dayOfYear(),mDateScrollBar->value() );
790 if ( dof != mDateScrollBar->value() ) { 790 if ( dof != mDateScrollBar->value() ) {
791 mDateScrollBar->blockSignals( true ); 791 mDateScrollBar->blockSignals( true );
792 mDateScrollBar->setValue( start.dayOfYear()); 792 mDateScrollBar->setValue( start.dayOfYear());
793 mDateScrollBar->blockSignals( false ); 793 mDateScrollBar->blockSignals( false );
794 } 794 }
795 } 795 }
796#endif 796#endif
797 mTodoList->updateView(); 797 mTodoList->updateView();
798 mViewManager->updateView(start, end); 798 mViewManager->updateView(start, end);
799 //mDateNavigator->updateView(); 799 //mDateNavigator->updateView();
800} 800}
801 801
802 802
803 803
804void CalendarView::checkFiles() 804void CalendarView::checkFiles()
805{ 805{
806 QString message; 806 QString message;
807 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 807 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
808 KopiCalendarFile * cal = calendars.first(); 808 KopiCalendarFile * cal = calendars.first();
809 while ( cal ) { 809 while ( cal ) {
810 if ( cal->mErrorOnLoad ) { 810 if ( cal->mErrorOnLoad ) {
811 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n"; 811 message += cal->mName +"\n"+KGlobal::formatMessage ( "(" +i18n( "Filepath: ")+ cal->mFileName+")" ,0 )+"\n";
812 } 812 }
813 cal = calendars.next(); 813 cal = calendars.next();
814 } 814 }
815 if ( !message.isEmpty() ) { 815 if ( !message.isEmpty() ) {
816 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); 816 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);
817 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed")); 817 KMessageBox::error(this,message, i18n("Loding of calendar(s) failed"));
818 } 818 }
819 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() )); 819 QTimer::singleShot( 2000, this, SLOT ( checkAlarms() ));
820} 820}
821void CalendarView::checkAlarms() 821void CalendarView::checkAlarms()
822{ 822{
823 823
824 824
825 KConfig *config = KOGlobals::config(); 825 KConfig *config = KOGlobals::config();
826 config->setGroup( "AppRun" ); 826 config->setGroup( "AppRun" );
827 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 827 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
828 int daysto = dt.daysTo( QDate::currentDate() ); 828 int daysto = dt.daysTo( QDate::currentDate() );
829 int days = config->readNumEntry( "LatestProgramStopDays" , daysto); 829 int days = config->readNumEntry( "LatestProgramStopDays" , daysto);
830 dt = dt.addDays( days ); 830 dt = dt.addDays( days );
831 int secto = dt.secsTo( QDateTime::currentDateTime() ); 831 int secto = dt.secsTo( QDateTime::currentDateTime() );
832 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30; 832 int secs = config->readNumEntry( "LatestProgramStopSecs" , secto) - 30;
833 //qDebug("KO: Reading program stop %d ", secs); 833 //qDebug("KO: Reading program stop %d ", secs);
834 //secs -= ( 3600 * 24*3 ); // debug only 834 //secs -= ( 3600 * 24*3 ); // debug only
835 QDateTime latest = dt.addSecs ( secs ); 835 QDateTime latest = dt.addSecs ( secs );
836 qDebug("KO: Last termination on %s ", latest.toString().latin1()); 836 qDebug("KO: Last termination on %s ", latest.toString().latin1());
837 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 837 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
838 QPtrList<Incidence> el = mCalendar->rawIncidences(); 838 QPtrList<Incidence> el = mCalendar->rawIncidences();
839 QPtrList<Incidence> al; 839 QPtrList<Incidence> al;
840 Incidence* inL = el.first(); 840 Incidence* inL = el.first();
841 QDateTime cur = QDateTime::currentDateTime().addSecs(-59); 841 QDateTime cur = QDateTime::currentDateTime().addSecs(-59);
842 qDebug("KO: Checking alarm until %s ", cur.toString().latin1()); 842 qDebug("KO: Checking alarm until %s ", cur.toString().latin1());
843 while ( inL ) { 843 while ( inL ) {
844 bool ok = false; 844 bool ok = false;
845 int offset = 0; 845 int offset = 0;
846 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ; 846 QDateTime next = inL->getNextAlarmDateTime(& ok, &offset, latest ) ;
847 if ( ok ) { 847 if ( ok ) {
848 //qDebug("OK %s",next.toString().latin1()); 848 //qDebug("OK %s",next.toString().latin1());
849 if ( next < cur ) { 849 if ( next < cur ) {
850 al.append( inL ); 850 al.append( inL );
851 //qDebug("found missed alarm: %s ", inL->summary().latin1() ); 851 //qDebug("found missed alarm: %s ", inL->summary().latin1() );
852 } 852 }
853 } 853 }
854 inL = el.next(); 854 inL = el.next();
855 } 855 }
856 if ( al.count() ) { 856 if ( al.count() ) {
857 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop ); 857 QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
858 dia->setCaption( i18n("KO/Pi: Missing alarms!") ); 858 dia->setCaption( i18n("KO/Pi: Missing alarms!") );
859 QVBoxLayout* lay = new QVBoxLayout( dia ); 859 QVBoxLayout* lay = new QVBoxLayout( dia );
860 lay->setSpacing( 0 ); 860 lay->setSpacing( 0 );
861 lay->setMargin( 0 ); 861 lay->setMargin( 0 );
862 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest ); 862 MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
863 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 863 connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
864 lay->addWidget( matb ); 864 lay->addWidget( matb );
865 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) { 865 if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
866 int wid = 210; 866 int wid = 210;
867 int x = QApplication::desktop()->width() - wid - 7; 867 int x = QApplication::desktop()->width() - wid - 7;
868 int y = QApplication::desktop()->height() - wid - 70; 868 int y = QApplication::desktop()->height() - wid - 70;
869 dia->setGeometry ( x,y,wid,wid); 869 dia->setGeometry ( x,y,wid,wid);
870 } else { 870 } else {
871 int si = 220; 871 int si = 220;
872 if ( QApplication::desktop()->width() > 470 ) 872 if ( QApplication::desktop()->width() > 470 )
873 si = 400; 873 si = 400;
874 dia->resize(si,si/2); 874 dia->resize(si,si/2);
875 } 875 }
876 dia->setBackgroundColor( QColor( 255, 255, 255 ) ); 876 dia->setBackgroundColor( QColor( 255, 255, 255 ) );
877 dia->show(); 877 dia->show();
878 878
879 } 879 }
880} 880}
881void CalendarView::showDay( QDate d ) 881void CalendarView::showDay( QDate d )
882{ 882{
883 dateNavigator()->blockSignals( true ); 883 dateNavigator()->blockSignals( true );
884 dateNavigator()->selectDate( d ); 884 dateNavigator()->selectDate( d );
885 dateNavigator()->blockSignals( false ); 885 dateNavigator()->blockSignals( false );
886 mViewManager->showDayView(); 886 mViewManager->showDayView();
887 //dateNavigator()->selectDate( d ); 887 //dateNavigator()->selectDate( d );
888} 888}
889void CalendarView::timerAlarm() 889void CalendarView::timerAlarm()
890{ 890{
891 //qDebug("CalendarView::timerAlarm() "); 891 //qDebug("CalendarView::timerAlarm() ");
892 computeAlarm(mAlarmNotification ); 892 computeAlarm(mAlarmNotification );
893} 893}
894 894
895void CalendarView::suspendAlarm() 895void CalendarView::suspendAlarm()
896{ 896{
897 //qDebug(" CalendarView::suspendAlarm() "); 897 //qDebug(" CalendarView::suspendAlarm() ");
898 computeAlarm(mSuspendAlarmNotification ); 898 computeAlarm(mSuspendAlarmNotification );
899 899
900} 900}
901 901
902void CalendarView::startAlarm( QString mess , QString filename) 902void CalendarView::startAlarm( QString mess , QString filename)
903{ 903{
904 904
905 topLevelWidget()->showNormal(); 905 topLevelWidget()->showNormal();
906 topLevelWidget()->setActiveWindow(); 906 topLevelWidget()->setActiveWindow();
907 topLevelWidget()->raise(); 907 topLevelWidget()->raise();
908 908
909 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount ); 909 mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
910 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) ); 910 QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
911 911
912} 912}
913 913
914void CalendarView::checkNextTimerAlarm() 914void CalendarView::checkNextTimerAlarm()
915{ 915{
916 mCalendar->checkAlarmForIncidence( 0, true ); 916 mCalendar->checkAlarmForIncidence( 0, true );
917} 917}
918 918
919void CalendarView::computeAlarm( QString msg ) 919void CalendarView::computeAlarm( QString msg )
920{ 920{
921 921
922 QString mess = msg; 922 QString mess = msg;
923 QString mAlarmMessage = mess.mid( 9 ); 923 QString mAlarmMessage = mess.mid( 9 );
924 QString filename = MainWindow::resourcePath(); 924 QString filename = MainWindow::resourcePath();
925 filename += "koalarm.wav"; 925 filename += "koalarm.wav";
926 QString tempfilename; 926 QString tempfilename;
927 if ( mess.left( 13 ) == "suspend_alarm") { 927 if ( mess.left( 13 ) == "suspend_alarm") {
928 bool error = false; 928 bool error = false;
929 int len = mess.mid( 13 ).find("+++"); 929 int len = mess.mid( 13 ).find("+++");
930 if ( len < 2 ) 930 if ( len < 2 )
931 error = true; 931 error = true;
932 else { 932 else {
933 tempfilename = mess.mid( 13, len ); 933 tempfilename = mess.mid( 13, len );
934 if ( !QFile::exists( tempfilename ) ) 934 if ( !QFile::exists( tempfilename ) )
935 error = true; 935 error = true;
936 } 936 }
937 if ( ! error ) { 937 if ( ! error ) {
938 filename = tempfilename; 938 filename = tempfilename;
939 } 939 }
940 mAlarmMessage = mess.mid( 13+len+3 ); 940 mAlarmMessage = mess.mid( 13+len+3 );
941 //qDebug("suspend file %s ",tempfilename.latin1() ); 941 //qDebug("suspend file %s ",tempfilename.latin1() );
942 startAlarm( mAlarmMessage, filename); 942 startAlarm( mAlarmMessage, filename);
943 return; 943 return;
944 } 944 }
945 if ( mess.left( 11 ) == "timer_alarm") { 945 if ( mess.left( 11 ) == "timer_alarm") {
946 //mTimerTime = 0; 946 //mTimerTime = 0;
947 startAlarm( mess.mid( 11 ), filename ); 947 startAlarm( mess.mid( 11 ), filename );
948 return; 948 return;
949 } 949 }
950 if ( mess.left( 10 ) == "proc_alarm") { 950 if ( mess.left( 10 ) == "proc_alarm") {
951 bool error = false; 951 bool error = false;
952 int len = mess.mid( 10 ).find("+++"); 952 int len = mess.mid( 10 ).find("+++");
953 if ( len < 2 ) 953 if ( len < 2 )
954 error = true; 954 error = true;
955 else { 955 else {
956 tempfilename = mess.mid( 10, len ); 956 tempfilename = mess.mid( 10, len );
957 if ( !QFile::exists( tempfilename ) ) 957 if ( !QFile::exists( tempfilename ) )
958 error = true; 958 error = true;
959 } 959 }
960 if ( error ) { 960 if ( error ) {
961 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 961 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
962 mAlarmMessage += mess.mid( 10+len+3+9 ); 962 mAlarmMessage += mess.mid( 10+len+3+9 );
963 } else { 963 } else {
964 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 964 //QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
965 //qDebug("-----system command %s ",tempfilename.latin1() ); 965 //qDebug("-----system command %s ",tempfilename.latin1() );
966#ifndef _WIN32_ 966#ifndef _WIN32_
967 if ( vfork () == 0 ) { 967 if ( vfork () == 0 ) {
968 execl ( tempfilename.latin1(), 0 ); 968 execl ( tempfilename.latin1(), 0 );
969 return; 969 return;
970 } 970 }
971#else 971#else
972 QProcess* p = new QProcess(); 972 QProcess* p = new QProcess();
973 p->addArgument( tempfilename.latin1() ); 973 p->addArgument( tempfilename.latin1() );
974 p->start(); 974 p->start();
975 return; 975 return;
976#endif 976#endif
977 977
978 return; 978 return;
979 } 979 }
980 980
981 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 981 //qDebug("+++++++system command %s ",tempfilename.latin1() );
982 } 982 }
983 if ( mess.left( 11 ) == "audio_alarm") { 983 if ( mess.left( 11 ) == "audio_alarm") {
984 bool error = false; 984 bool error = false;
985 int len = mess.mid( 11 ).find("+++"); 985 int len = mess.mid( 11 ).find("+++");
986 if ( len < 2 ) 986 if ( len < 2 )
987 error = true; 987 error = true;
988 else { 988 else {
989 tempfilename = mess.mid( 11, len ); 989 tempfilename = mess.mid( 11, len );
990 if ( !QFile::exists( tempfilename ) ) 990 if ( !QFile::exists( tempfilename ) )
991 error = true; 991 error = true;
992 } 992 }
993 if ( ! error ) { 993 if ( ! error ) {
994 filename = tempfilename; 994 filename = tempfilename;
995 } 995 }
996 mAlarmMessage = mess.mid( 11+len+3+9 ); 996 mAlarmMessage = mess.mid( 11+len+3+9 );
997 //qDebug("audio file command %s ",tempfilename.latin1() ); 997 //qDebug("audio file command %s ",tempfilename.latin1() );
998 } 998 }
999 if ( mess.left( 9 ) == "cal_alarm") { 999 if ( mess.left( 9 ) == "cal_alarm") {
1000 mAlarmMessage = mess.mid( 9 ) ; 1000 mAlarmMessage = mess.mid( 9 ) ;
1001 } 1001 }
1002 1002
1003 startAlarm( mAlarmMessage, filename ); 1003 startAlarm( mAlarmMessage, filename );
1004 1004
1005 1005
1006} 1006}
1007 1007
1008void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti ) 1008void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
1009{ 1009{
1010 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1010 //qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1011 1011
1012 mSuspendAlarmNotification = noti; 1012 mSuspendAlarmNotification = noti;
1013 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000; 1013 int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
1014 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000); 1014 //qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
1015 mSuspendTimer->start( ms , true ); 1015 mSuspendTimer->start( ms , true );
1016 1016
1017} 1017}
1018 1018
1019void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti ) 1019void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
1020{ 1020{
1021 mNextAlarmDateTime = qdt; 1021 mNextAlarmDateTime = qdt;
1022 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1022 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1023 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1023 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1024#ifndef DESKTOP_VERSION 1024#ifndef DESKTOP_VERSION
1025 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 1025 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
1026#endif 1026#endif
1027 return; 1027 return;
1028 } 1028 }
1029 int maxSec; 1029 int maxSec;
1030 //maxSec = 5; //testing only 1030 //maxSec = 5; //testing only
1031 maxSec = 86400+3600; // one day+1hour 1031 maxSec = 86400+3600; // one day+1hour
1032 mAlarmNotification = noti; 1032 mAlarmNotification = noti;
1033 int sec = QDateTime::currentDateTime().secsTo( qdt ); 1033 int sec = QDateTime::currentDateTime().secsTo( qdt );
1034 if ( sec > maxSec ) { 1034 if ( sec > maxSec ) {
1035 mRecheckAlarmTimer->start( maxSec * 1000 ); 1035 mRecheckAlarmTimer->start( maxSec * 1000 );
1036 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 1036 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
1037 return; 1037 return;
1038 } else { 1038 } else {
1039 mRecheckAlarmTimer->stop(); 1039 mRecheckAlarmTimer->stop();
1040 } 1040 }
1041 //qDebug("Alarm timer started with secs: %d ", sec); 1041 //qDebug("Alarm timer started with secs: %d ", sec);
1042 mAlarmTimer->start( sec *1000 , true ); 1042 mAlarmTimer->start( sec *1000 , true );
1043 1043
1044} 1044}
1045// called by mRecheckAlarmTimer to get next alarm 1045// called by mRecheckAlarmTimer to get next alarm
1046// we need this, because a QTimer has only a max range of 25 days 1046// we need this, because a QTimer has only a max range of 25 days
1047void CalendarView::recheckTimerAlarm() 1047void CalendarView::recheckTimerAlarm()
1048{ 1048{
1049 mAlarmTimer->stop(); 1049 mAlarmTimer->stop();
1050 mRecheckAlarmTimer->stop(); 1050 mRecheckAlarmTimer->stop();
1051 mCalendar->checkAlarmForIncidence( 0, true ); 1051 mCalendar->checkAlarmForIncidence( 0, true );
1052} 1052}
1053#ifndef DESKTOP_VERSION 1053#ifndef DESKTOP_VERSION
1054void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 1054void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
1055#else 1055#else
1056void CalendarView::removeAlarm(const QDateTime &, const QString & ) 1056void CalendarView::removeAlarm(const QDateTime &, const QString & )
1057#endif 1057#endif
1058{ 1058{
1059 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 1059 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
1060 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 1060 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
1061#ifndef DESKTOP_VERSION 1061#ifndef DESKTOP_VERSION
1062 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() ); 1062 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
1063#endif 1063#endif
1064 return; 1064 return;
1065 } 1065 }
1066 mAlarmTimer->stop(); 1066 mAlarmTimer->stop();
1067} 1067}
1068void CalendarView::selectWeekNum ( int num ) 1068void CalendarView::selectWeekNum ( int num )
1069{ 1069{
1070 dateNavigator()->blockSignals( true ); 1070 dateNavigator()->blockSignals( true );
1071 dateNavigator()->selectWeek( num ); 1071 dateNavigator()->selectWeek( num );
1072 dateNavigator()->blockSignals( false ); 1072 dateNavigator()->blockSignals( false );
1073 mViewManager->showWeekView(); 1073 mViewManager->showWeekView();
1074} 1074}
1075KOViewManager *CalendarView::viewManager() 1075KOViewManager *CalendarView::viewManager()
1076{ 1076{
1077 return mViewManager; 1077 return mViewManager;
1078} 1078}
1079 1079
1080KODialogManager *CalendarView::dialogManager() 1080KODialogManager *CalendarView::dialogManager()
1081{ 1081{
1082 return mDialogManager; 1082 return mDialogManager;
1083} 1083}
1084 1084
1085QDate CalendarView::startDate() 1085QDate CalendarView::startDate()
1086{ 1086{
1087 DateList dates = mNavigator->selectedDates(); 1087 DateList dates = mNavigator->selectedDates();
1088 1088
1089 return dates.first(); 1089 return dates.first();
1090} 1090}
1091 1091
1092QDate CalendarView::endDate() 1092QDate CalendarView::endDate()
1093{ 1093{
1094 DateList dates = mNavigator->selectedDates(); 1094 DateList dates = mNavigator->selectedDates();
1095 1095
1096 return dates.last(); 1096 return dates.last();
1097} 1097}
1098 1098
1099 1099
1100void CalendarView::createPrinter() 1100void CalendarView::createPrinter()
1101{ 1101{
1102#ifndef KORG_NOPRINTER 1102#ifndef KORG_NOPRINTER
1103 if (!mCalPrinter) { 1103 if (!mCalPrinter) {
1104 mCalPrinter = new CalPrinter(this, mCalendar); 1104 mCalPrinter = new CalPrinter(this, mCalendar);
1105 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 1105 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
1106 } 1106 }
1107#endif 1107#endif
1108} 1108}
1109 1109
1110 1110
1111//KOPrefs::instance()->mWriteBackFile 1111//KOPrefs::instance()->mWriteBackFile
1112//KOPrefs::instance()->mWriteBackExistingOnly 1112//KOPrefs::instance()->mWriteBackExistingOnly
1113 1113
1114// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 1114// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
1115// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 1115// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
1116// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 1116// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
1117// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 1117// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
1118// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 1118// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
1119// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 1119// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
1120 1120
1121int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 1121int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
1122{ 1122{
1123 1123
1124 // 0 equal 1124 // 0 equal
1125 // 1 take local 1125 // 1 take local
1126 // 2 take remote 1126 // 2 take remote
1127 // 3 cancel 1127 // 3 cancel
1128 QDateTime lastSync = mLastCalendarSync; 1128 QDateTime lastSync = mLastCalendarSync;
1129 QDateTime localMod = local->lastModified(); 1129 QDateTime localMod = local->lastModified();
1130 QDateTime remoteMod = remote->lastModified(); 1130 QDateTime remoteMod = remote->lastModified();
1131 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1131 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1132 bool remCh, locCh; 1132 bool remCh, locCh;
1133 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 1133 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
1134 //if ( remCh ) 1134 //if ( remCh )
1135 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 1135 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
1136 locCh = ( localMod > mLastCalendarSync ); 1136 locCh = ( localMod > mLastCalendarSync );
1137 if ( !remCh && ! locCh ) { 1137 if ( !remCh && ! locCh ) {
1138 //qDebug("both not changed "); 1138 //qDebug("both not changed ");
1139 lastSync = localMod.addDays(1); 1139 lastSync = localMod.addDays(1);
1140 if ( mode <= SYNC_PREF_ASK ) 1140 if ( mode <= SYNC_PREF_ASK )
1141 return 0; 1141 return 0;
1142 } else { 1142 } else {
1143 if ( locCh ) { 1143 if ( locCh ) {
1144 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 1144 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
1145 lastSync = localMod.addDays( -1 ); 1145 lastSync = localMod.addDays( -1 );
1146 if ( !remCh ) 1146 if ( !remCh )
1147 remoteMod = ( lastSync.addDays( -1 ) ); 1147 remoteMod = ( lastSync.addDays( -1 ) );
1148 } else { 1148 } else {
1149 //qDebug(" not loc changed "); 1149 //qDebug(" not loc changed ");
1150 lastSync = localMod.addDays( 1 ); 1150 lastSync = localMod.addDays( 1 );
1151 if ( remCh ) 1151 if ( remCh )
1152 remoteMod =( lastSync.addDays( 1 ) ); 1152 remoteMod =( lastSync.addDays( 1 ) );
1153 1153
1154 } 1154 }
1155 } 1155 }
1156 full = true; 1156 full = true;
1157 if ( mode < SYNC_PREF_ASK ) 1157 if ( mode < SYNC_PREF_ASK )
1158 mode = SYNC_PREF_ASK; 1158 mode = SYNC_PREF_ASK;
1159 } else { 1159 } else {
1160 if ( localMod == remoteMod ) 1160 if ( localMod == remoteMod )
1161 // if ( local->revision() == remote->revision() ) 1161 // if ( local->revision() == remote->revision() )
1162 return 0; 1162 return 0;
1163 1163
1164 } 1164 }
1165 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 1165 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
1166 1166
1167 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 1167 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
1168 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 1168 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
1169 //full = true; //debug only 1169 //full = true; //debug only
1170 if ( full ) { 1170 if ( full ) {
1171 bool equ = false; 1171 bool equ = false;
1172 if ( local->typeID() == eventID ) { 1172 if ( local->typeID() == eventID ) {
1173 equ = (*((Event*) local) == *((Event*) remote)); 1173 equ = (*((Event*) local) == *((Event*) remote));
1174 } 1174 }
1175 else if ( local->typeID() == todoID ) 1175 else if ( local->typeID() == todoID )
1176 equ = (*((Todo*) local) == (*(Todo*) remote)); 1176 equ = (*((Todo*) local) == (*(Todo*) remote));
1177 else if ( local->typeID() == journalID ) 1177 else if ( local->typeID() == journalID )
1178 equ = (*((Journal*) local) == *((Journal*) remote)); 1178 equ = (*((Journal*) local) == *((Journal*) remote));
1179 if ( equ ) { 1179 if ( equ ) {
1180 //qDebug("equal "); 1180 //qDebug("equal ");
1181 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1181 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1182 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1182 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1183 } 1183 }
1184 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1184 if ( mode < SYNC_PREF_FORCE_LOCAL )
1185 return 0; 1185 return 0;
1186 1186
1187 }//else //debug only 1187 }//else //debug only
1188 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1188 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1189 } 1189 }
1190 int result; 1190 int result;
1191 bool localIsNew; 1191 bool localIsNew;
1192 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); 1192 //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
1193 1193
1194 1194
1195 // ************************************************ 1195 // ************************************************
1196 // ************************************************ 1196 // ************************************************
1197 // ************************************************ 1197 // ************************************************
1198 // We may have that lastSync > remoteMod AND lastSync > localMod 1198 // We may have that lastSync > remoteMod AND lastSync > localMod
1199 // BUT remoteMod != localMod 1199 // BUT remoteMod != localMod
1200 1200
1201 1201
1202 if ( full && mode < SYNC_PREF_NEWEST ) 1202 if ( full && mode < SYNC_PREF_NEWEST )
1203 mode = SYNC_PREF_ASK; 1203 mode = SYNC_PREF_ASK;
1204 1204
1205 switch( mode ) { 1205 switch( mode ) {
1206 case SYNC_PREF_LOCAL: 1206 case SYNC_PREF_LOCAL:
1207 if ( lastSync > remoteMod ) 1207 if ( lastSync > remoteMod )
1208 return 1; 1208 return 1;
1209 if ( lastSync > localMod ) 1209 if ( lastSync > localMod )
1210 return 2; 1210 return 2;
1211 return 1; 1211 return 1;
1212 break; 1212 break;
1213 case SYNC_PREF_REMOTE: 1213 case SYNC_PREF_REMOTE:
1214 if ( lastSync > localMod ) 1214 if ( lastSync > localMod )
1215 return 2; 1215 return 2;
1216 if ( lastSync > remoteMod ) 1216 if ( lastSync > remoteMod )
1217 return 1; 1217 return 1;
1218 return 2; 1218 return 2;
1219 break; 1219 break;
1220 case SYNC_PREF_NEWEST: 1220 case SYNC_PREF_NEWEST:
1221 if ( localMod >= remoteMod ) 1221 if ( localMod >= remoteMod )
1222 return 1; 1222 return 1;
1223 else 1223 else
1224 return 2; 1224 return 2;
1225 break; 1225 break;
1226 case SYNC_PREF_ASK: 1226 case SYNC_PREF_ASK:
1227 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1227 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1228 if ( lastSync > remoteMod && lastSync > localMod) 1228 if ( lastSync > remoteMod && lastSync > localMod)
1229 return 0; 1229 return 0;
1230 if ( lastSync > remoteMod ) 1230 if ( lastSync > remoteMod )
1231 return 1; 1231 return 1;
1232 if ( lastSync > localMod ) 1232 if ( lastSync > localMod )
1233 return 2; 1233 return 2;
1234 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1234 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1235 localIsNew = localMod >= remoteMod; 1235 localIsNew = localMod >= remoteMod;
1236 if ( localIsNew ) 1236 if ( localIsNew )
1237 getEventViewerDialog()->setColorMode( 1 ); 1237 getEventViewerDialog()->setColorMode( 1 );
1238 else 1238 else
1239 getEventViewerDialog()->setColorMode( 2 ); 1239 getEventViewerDialog()->setColorMode( 2 );
1240 getEventViewerDialog()->setIncidence(local); 1240 getEventViewerDialog()->setIncidence(local);
1241 if ( localIsNew ) 1241 if ( localIsNew )
1242 getEventViewerDialog()->setColorMode( 2 ); 1242 getEventViewerDialog()->setColorMode( 2 );
1243 else 1243 else
1244 getEventViewerDialog()->setColorMode( 1 ); 1244 getEventViewerDialog()->setColorMode( 1 );
1245 getEventViewerDialog()->addIncidence(remote); 1245 getEventViewerDialog()->addIncidence(remote);
1246 getEventViewerDialog()->setColorMode( 0 ); 1246 getEventViewerDialog()->setColorMode( 0 );
1247 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1247 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1248 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1248 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1249 getEventViewerDialog()->showMe(); 1249 getEventViewerDialog()->showMe();
1250 result = getEventViewerDialog()->executeS( localIsNew ); 1250 result = getEventViewerDialog()->executeS( localIsNew );
1251 return result; 1251 return result;
1252 1252
1253 break; 1253 break;
1254 case SYNC_PREF_FORCE_LOCAL: 1254 case SYNC_PREF_FORCE_LOCAL:
1255 return 1; 1255 return 1;
1256 break; 1256 break;
1257 case SYNC_PREF_FORCE_REMOTE: 1257 case SYNC_PREF_FORCE_REMOTE:
1258 return 2; 1258 return 2;
1259 break; 1259 break;
1260 1260
1261 default: 1261 default:
1262 // SYNC_PREF_TAKE_BOTH not implemented 1262 // SYNC_PREF_TAKE_BOTH not implemented
1263 break; 1263 break;
1264 } 1264 }
1265 return 0; 1265 return 0;
1266} 1266}
1267Event* CalendarView::getLastSyncEvent() 1267Event* CalendarView::getLastSyncEvent()
1268{ 1268{
1269 Event* lse; 1269 Event* lse;
1270 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1270 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1271 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1271 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1272 if (!lse) { 1272 if (!lse) {
1273 lse = new Event(); 1273 lse = new Event();
1274 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1274 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1275 QString sum = ""; 1275 QString sum = "";
1276 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1276 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1277 sum = "E: "; 1277 sum = "E: ";
1278 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1278 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1279 lse->setDtStart( mLastCalendarSync ); 1279 lse->setDtStart( mLastCalendarSync );
1280 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1280 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1281 lse->setCategories( i18n("SyncEvent") ); 1281 lse->setCategories( i18n("SyncEvent") );
1282 lse->setReadOnly( true ); 1282 lse->setReadOnly( true );
1283 mCalendar->addEvent( lse ); 1283 mCalendar->addEvent( lse );
1284 } 1284 }
1285 1285
1286 return lse; 1286 return lse;
1287 1287
1288} 1288}
1289 1289
1290// we check, if the to delete event has a id for a profile 1290// we check, if the to delete event has a id for a profile
1291// if yes, we set this id in the profile to delete 1291// if yes, we set this id in the profile to delete
1292void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1292void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1293{ 1293{
1294 if ( lastSync.count() == 0 ) { 1294 if ( lastSync.count() == 0 ) {
1295 //qDebug(" lastSync.count() == 0"); 1295 //qDebug(" lastSync.count() == 0");
1296 return; 1296 return;
1297 } 1297 }
1298 if ( toDelete->typeID() == journalID ) 1298 if ( toDelete->typeID() == journalID )
1299 return; 1299 return;
1300 1300
1301 Event* eve = lastSync.first(); 1301 Event* eve = lastSync.first();
1302 1302
1303 while ( eve ) { 1303 while ( eve ) {
1304 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1304 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1305 if ( !id.isEmpty() ) { 1305 if ( !id.isEmpty() ) {
1306 QString des = eve->description(); 1306 QString des = eve->description();
1307 QString pref = "e"; 1307 QString pref = "e";
1308 if ( toDelete->typeID() == todoID ) 1308 if ( toDelete->typeID() == todoID )
1309 pref = "t"; 1309 pref = "t";
1310 des += pref+ id + ","; 1310 des += pref+ id + ",";
1311 eve->setReadOnly( false ); 1311 eve->setReadOnly( false );
1312 eve->setDescription( des ); 1312 eve->setDescription( des );
1313 //qDebug("setdes %s ", des.latin1()); 1313 //qDebug("setdes %s ", des.latin1());
1314 eve->setReadOnly( true ); 1314 eve->setReadOnly( true );
1315 } 1315 }
1316 eve = lastSync.next(); 1316 eve = lastSync.next();
1317 } 1317 }
1318 1318
1319} 1319}
1320void CalendarView::checkExternalId( Incidence * inc ) 1320void CalendarView::checkExternalId( Incidence * inc )
1321{ 1321{
1322 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1322 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1323 checkExternSyncEvent( lastSync, inc ); 1323 checkExternSyncEvent( lastSync, inc );
1324 1324
1325} 1325}
1326bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1326bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1327{ 1327{
1328 bool syncOK = true; 1328 bool syncOK = true;
1329 int addedEvent = 0; 1329 int addedEvent = 0;
1330 int addedEventR = 0; 1330 int addedEventR = 0;
1331 int deletedEventR = 0; 1331 int deletedEventR = 0;
1332 int deletedEventL = 0; 1332 int deletedEventL = 0;
1333 int changedLocal = 0; 1333 int changedLocal = 0;
1334 int changedRemote = 0; 1334 int changedRemote = 0;
1335 int filteredIN = 0; 1335 int filteredIN = 0;
1336 int filteredOUT = 0; 1336 int filteredOUT = 0;
1337 //QPtrList<Event> el = local->rawEvents(); 1337 //QPtrList<Event> el = local->rawEvents();
1338 Event* eventR; 1338 Event* eventR;
1339 QString uid; 1339 QString uid;
1340 int take; 1340 int take;
1341 Event* eventRSync; 1341 Event* eventRSync;
1342 Event* eventLSync; 1342 Event* eventLSync;
1343 clearAllViews(); 1343 clearAllViews();
1344 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1344 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1345 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1345 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1346 bool fullDateRange = false; 1346 bool fullDateRange = false;
1347 local->resetTempSyncStat(); 1347 local->resetTempSyncStat();
1348 mLastCalendarSync = QDateTime::currentDateTime(); 1348 mLastCalendarSync = QDateTime::currentDateTime();
1349 if ( mSyncManager->syncWithDesktop() ) { 1349 if ( mSyncManager->syncWithDesktop() ) {
1350 remote->resetPilotStat(1); 1350 remote->resetPilotStat(1);
1351 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1351 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1352 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1352 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1353 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1353 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1354 } else { 1354 } else {
1355 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1355 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1356 } 1356 }
1357 } 1357 }
1358 QDateTime modifiedCalendar = mLastCalendarSync; 1358 QDateTime modifiedCalendar = mLastCalendarSync;
1359 eventLSync = getLastSyncEvent(); 1359 eventLSync = getLastSyncEvent();
1360 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1360 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1361 if ( eventR ) { 1361 if ( eventR ) {
1362 eventRSync = (Event*) eventR->clone(); 1362 eventRSync = (Event*) eventR->clone();
1363 remote->deleteEvent(eventR ); 1363 remote->deleteEvent(eventR );
1364 1364
1365 } else { 1365 } else {
1366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1366 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1367 eventRSync = (Event*)eventLSync->clone(); 1367 eventRSync = (Event*)eventLSync->clone();
1368 } else { 1368 } else {
1369 fullDateRange = true; 1369 fullDateRange = true;
1370 eventRSync = new Event(); 1370 eventRSync = new Event();
1371 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1371 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1372 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1372 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1373 eventRSync->setDtStart( mLastCalendarSync ); 1373 eventRSync->setDtStart( mLastCalendarSync );
1374 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1374 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1375 eventRSync->setCategories( i18n("SyncEvent") ); 1375 eventRSync->setCategories( i18n("SyncEvent") );
1376 } 1376 }
1377 } 1377 }
1378 if ( eventLSync->dtStart() == mLastCalendarSync ) 1378 if ( eventLSync->dtStart() == mLastCalendarSync )
1379 fullDateRange = true; 1379 fullDateRange = true;
1380 1380
1381 if ( ! fullDateRange ) { 1381 if ( ! fullDateRange ) {
1382 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1382 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1383 1383
1384 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1384 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1385 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1385 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1386 fullDateRange = true; 1386 fullDateRange = true;
1387 } 1387 }
1388 } 1388 }
1389 if ( mSyncManager->syncWithDesktop() ) { 1389 if ( mSyncManager->syncWithDesktop() ) {
1390 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1390 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1391 } 1391 }
1392 if ( fullDateRange ) 1392 if ( fullDateRange )
1393 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1393 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1394 else 1394 else
1395 mLastCalendarSync = eventLSync->dtStart(); 1395 mLastCalendarSync = eventLSync->dtStart();
1396 // for resyncing if own file has changed 1396 // for resyncing if own file has changed
1397 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1397 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1398 mLastCalendarSync = loadedFileVersion; 1398 mLastCalendarSync = loadedFileVersion;
1399 //qDebug("setting mLastCalendarSync "); 1399 //qDebug("setting mLastCalendarSync ");
1400 } 1400 }
1401 //qDebug("*************************** "); 1401 //qDebug("*************************** ");
1402 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1402 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1403 QPtrList<Incidence> er = remote->rawIncidences(); 1403 QPtrList<Incidence> er = remote->rawIncidences();
1404 Incidence* inR = er.first(); 1404 Incidence* inR = er.first();
1405 Incidence* inL; 1405 Incidence* inL;
1406 QProgressBar bar( er.count(),0 ); 1406 QProgressBar bar( er.count(),0 );
1407 bar.setCaption (i18n("Syncing - close to abort!") ); 1407 bar.setCaption (i18n("Syncing - close to abort!") );
1408 1408
1409 // ************** setting up filter ************* 1409 // ************** setting up filter *************
1410 CalFilter *filterIN = 0; 1410 CalFilter *filterIN = 0;
1411 CalFilter *filterOUT = 0; 1411 CalFilter *filterOUT = 0;
1412 CalFilter *filter = mFilters.first(); 1412 CalFilter *filter = mFilters.first();
1413 while(filter) { 1413 while(filter) {
1414 if ( filter->name() == mSyncManager->mFilterInCal ) 1414 if ( filter->name() == mSyncManager->mFilterInCal )
1415 filterIN = filter; 1415 filterIN = filter;
1416 if ( filter->name() == mSyncManager->mFilterOutCal ) 1416 if ( filter->name() == mSyncManager->mFilterOutCal )
1417 filterOUT = filter; 1417 filterOUT = filter;
1418 filter = mFilters.next(); 1418 filter = mFilters.next();
1419 } 1419 }
1420 int w = 300; 1420 int w = 300;
1421 if ( QApplication::desktop()->width() < 320 ) 1421 if ( QApplication::desktop()->width() < 320 )
1422 w = 220; 1422 w = 220;
1423 int h = bar.sizeHint().height() ; 1423 int h = bar.sizeHint().height() ;
1424 int dw = QApplication::desktop()->width(); 1424 int dw = QApplication::desktop()->width();
1425 int dh = QApplication::desktop()->height(); 1425 int dh = QApplication::desktop()->height();
1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1427 bar.show(); 1427 bar.show();
1428 int modulo = (er.count()/10)+1; 1428 int modulo = (er.count()/10)+1;
1429 int incCounter = 0; 1429 int incCounter = 0;
1430 while ( inR ) { 1430 while ( inR ) {
1431 if ( ! bar.isVisible() ) 1431 if ( ! bar.isVisible() )
1432 return false; 1432 return false;
1433 if ( incCounter % modulo == 0 ) 1433 if ( incCounter % modulo == 0 )
1434 bar.setProgress( incCounter ); 1434 bar.setProgress( incCounter );
1435 ++incCounter; 1435 ++incCounter;
1436 uid = inR->uid(); 1436 uid = inR->uid();
1437 bool skipIncidence = false; 1437 bool skipIncidence = false;
1438 if ( uid.left(15) == QString("last-syncEvent-") ) 1438 if ( uid.left(15) == QString("last-syncEvent-") )
1439 skipIncidence = true; 1439 skipIncidence = true;
1440 QString idS; 1440 QString idS;
1441 qApp->processEvents(); 1441 qApp->processEvents();
1442 if ( !skipIncidence ) { 1442 if ( !skipIncidence ) {
1443 inL = local->incidence( uid ); 1443 inL = local->incidence( uid );
1444 if ( inL ) { // maybe conflict - same uid in both calendars 1444 if ( inL ) { // maybe conflict - same uid in both calendars
1445 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1445 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1446 //qDebug("take %d %s ", take, inL->summary().latin1()); 1446 //qDebug("take %d %s ", take, inL->summary().latin1());
1447 if ( take == 3 ) 1447 if ( take == 3 )
1448 return false; 1448 return false;
1449 if ( take == 1 ) {// take local ********************** 1449 if ( take == 1 ) {// take local **********************
1450 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1450 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1451 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1451 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1452 else 1452 else
1453 idS = inR->IDStr(); 1453 idS = inR->IDStr();
1454 int calID = inR->calID();
1454 remote->deleteIncidence( inR ); 1455 remote->deleteIncidence( inR );
1455 inR = inL->clone(); 1456 inR = inL->clone();
1457 inR->setCalID( calID );
1456 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1458 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1457 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1459 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1458 inR->setIDStr( idS ); 1460 inR->setIDStr( idS );
1459 remote->addIncidence( inR ); 1461 remote->addIncidence( inR );
1460 if ( mSyncManager->syncWithDesktop() ) 1462 if ( mSyncManager->syncWithDesktop() )
1461 inR->setPilotId( 2 ); 1463 inR->setPilotId( 2 );
1462 ++changedRemote; 1464 ++changedRemote;
1463 } else {// take remote ********************** 1465 } else {// take remote **********************
1464 idS = inL->IDStr(); 1466 idS = inL->IDStr();
1465 int pid = inL->pilotId(); 1467 int pid = inL->pilotId();
1468 int calID = inL->calID();
1466 local->deleteIncidence( inL ); 1469 local->deleteIncidence( inL );
1467 inL = inR->clone(); 1470 inL = inR->clone();
1471 inL->setCalID( calID );
1468 if ( mSyncManager->syncWithDesktop() ) 1472 if ( mSyncManager->syncWithDesktop() )
1469 inL->setPilotId( pid ); 1473 inL->setPilotId( pid );
1470 inL->setIDStr( idS ); 1474 inL->setIDStr( idS );
1471 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1475 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1472 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1476 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1473 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1477 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1474 } 1478 }
1475 local->addIncidence( inL ); 1479 local->addIncidence( inL );
1476 ++changedLocal; 1480 ++changedLocal;
1477 } 1481 }
1478 } 1482 }
1479 } else { // no conflict ********** add or delete remote 1483 } else { // no conflict ********** add or delete remote
1480 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1484 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1481 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1485 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1482 QString des = eventLSync->description(); 1486 QString des = eventLSync->description();
1483 QString pref = "e"; 1487 QString pref = "e";
1484 if ( inR->typeID() == todoID ) 1488 if ( inR->typeID() == todoID )
1485 pref = "t"; 1489 pref = "t";
1486 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1490 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1487 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1491 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1488 //remote->deleteIncidence( inR ); 1492 //remote->deleteIncidence( inR );
1489 ++deletedEventR; 1493 ++deletedEventR;
1490 } else { 1494 } else {
1491 inR->setLastModified( modifiedCalendar ); 1495 inR->setLastModified( modifiedCalendar );
1492 inL = inR->clone(); 1496 inL = inR->clone();
1493 inL->setIDStr( ":" ); 1497 inL->setIDStr( ":" );
1494 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1498 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1495 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1499 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1500
1501 inL->setCalID( 0 );// add to default cal
1496 local->addIncidence( inL ); 1502 local->addIncidence( inL );
1497 ++addedEvent; 1503 ++addedEvent;
1498 1504
1499 } 1505 }
1500 } else { 1506 } else {
1501 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1507 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1502 inR->setLastModified( modifiedCalendar ); 1508 inR->setLastModified( modifiedCalendar );
1503 inL = inR->clone(); 1509 inL = inR->clone();
1504 inL->setIDStr( ":" ); 1510 inL->setIDStr( ":" );
1511 inL->setCalID( 0 );// add to default cal
1505 local->addIncidence( inL ); 1512 local->addIncidence( inL );
1506 ++addedEvent; 1513 ++addedEvent;
1507 1514
1508 } else { 1515 } else {
1509 checkExternSyncEvent(eventRSyncSharp, inR); 1516 checkExternSyncEvent(eventRSyncSharp, inR);
1510 remote->deleteIncidence( inR ); 1517 remote->deleteIncidence( inR );
1511 ++deletedEventR; 1518 ++deletedEventR;
1512 } 1519 }
1513 } 1520 }
1514 } else { 1521 } else {
1515 ++filteredIN; 1522 ++filteredIN;
1516 } 1523 }
1517 } 1524 }
1518 } 1525 }
1519 inR = er.next(); 1526 inR = er.next();
1520 } 1527 }
1521 QPtrList<Incidence> el = local->rawIncidences(); 1528 QPtrList<Incidence> el = local->rawIncidences();
1522 inL = el.first(); 1529 inL = el.first();
1523 modulo = (el.count()/10)+1; 1530 modulo = (el.count()/10)+1;
1524 bar.setCaption (i18n("Add / remove events") ); 1531 bar.setCaption (i18n("Add / remove events") );
1525 bar.setTotalSteps ( el.count() ) ; 1532 bar.setTotalSteps ( el.count() ) ;
1526 bar.show(); 1533 bar.show();
1527 incCounter = 0; 1534 incCounter = 0;
1528 1535
1529 while ( inL ) { 1536 while ( inL ) {
1530 1537
1531 qApp->processEvents(); 1538 qApp->processEvents();
1532 if ( ! bar.isVisible() ) 1539 if ( ! bar.isVisible() )
1533 return false; 1540 return false;
1534 if ( incCounter % modulo == 0 ) 1541 if ( incCounter % modulo == 0 )
1535 bar.setProgress( incCounter ); 1542 bar.setProgress( incCounter );
1536 ++incCounter; 1543 ++incCounter;
1537 uid = inL->uid(); 1544 uid = inL->uid();
1538 bool skipIncidence = false; 1545 bool skipIncidence = false;
1539 if ( uid.left(15) == QString("last-syncEvent-") ) 1546 if ( uid.left(15) == QString("last-syncEvent-") )
1540 skipIncidence = true; 1547 skipIncidence = true;
1541 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1548 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1542 skipIncidence = true; 1549 skipIncidence = true;
1543 if ( !skipIncidence ) { 1550 if ( !skipIncidence ) {
1544 inR = remote->incidence( uid ); 1551 inR = remote->incidence( uid );
1545 if ( ! inR ) { 1552 if ( ! inR ) {
1546 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1553 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1547 // no conflict ********** add or delete local 1554 // no conflict ********** add or delete local
1548 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1555 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1549 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1556 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1550 checkExternSyncEvent(eventLSyncSharp, inL); 1557 checkExternSyncEvent(eventLSyncSharp, inL);
1551 local->deleteIncidence( inL ); 1558 local->deleteIncidence( inL );
1552 ++deletedEventL; 1559 ++deletedEventL;
1553 } else { 1560 } else {
1554 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1561 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1555 inL->removeID(mCurrentSyncDevice ); 1562 inL->removeID(mCurrentSyncDevice );
1556 ++addedEventR; 1563 ++addedEventR;
1557 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1564 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1558 inL->setLastModified( modifiedCalendar ); 1565 inL->setLastModified( modifiedCalendar );
1559 inR = inL->clone(); 1566 inR = inL->clone();
1560 inR->setIDStr( ":" ); 1567 inR->setIDStr( ":" );
1561 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1568 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1569 inR->setCalID( 0 );// add to default cal
1562 remote->addIncidence( inR ); 1570 remote->addIncidence( inR );
1563 } 1571 }
1564 } 1572 }
1565 } else { 1573 } else {
1566 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1574 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1567 checkExternSyncEvent(eventLSyncSharp, inL); 1575 checkExternSyncEvent(eventLSyncSharp, inL);
1568 local->deleteIncidence( inL ); 1576 local->deleteIncidence( inL );
1569 ++deletedEventL; 1577 ++deletedEventL;
1570 } else { 1578 } else {
1571 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1579 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1572 ++addedEventR; 1580 ++addedEventR;
1573 inL->setLastModified( modifiedCalendar ); 1581 inL->setLastModified( modifiedCalendar );
1574 inR = inL->clone(); 1582 inR = inL->clone();
1575 inR->setIDStr( ":" ); 1583 inR->setIDStr( ":" );
1584 inR->setCalID( 0 );// add to default cal
1576 remote->addIncidence( inR ); 1585 remote->addIncidence( inR );
1577 } 1586 }
1578 } 1587 }
1579 } 1588 }
1580 } else { 1589 } else {
1581 ++filteredOUT; 1590 ++filteredOUT;
1582 } 1591 }
1583 } 1592 }
1584 } 1593 }
1585 inL = el.next(); 1594 inL = el.next();
1586 } 1595 }
1587 int delFut = 0; 1596 int delFut = 0;
1588 int remRem = 0; 1597 int remRem = 0;
1589 if ( mSyncManager->mWriteBackInFuture ) { 1598 if ( mSyncManager->mWriteBackInFuture ) {
1590 er = remote->rawIncidences(); 1599 er = remote->rawIncidences();
1591 remRem = er.count(); 1600 remRem = er.count();
1592 inR = er.first(); 1601 inR = er.first();
1593 QDateTime dt; 1602 QDateTime dt;
1594 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1603 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1595 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1604 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1596 while ( inR ) { 1605 while ( inR ) {
1597 if ( inR->typeID() == todoID ) { 1606 if ( inR->typeID() == todoID ) {
1598 Todo * t = (Todo*)inR; 1607 Todo * t = (Todo*)inR;
1599 if ( t->hasDueDate() ) 1608 if ( t->hasDueDate() )
1600 dt = t->dtDue(); 1609 dt = t->dtDue();
1601 else 1610 else
1602 dt = cur.addSecs( 62 ); 1611 dt = cur.addSecs( 62 );
1603 } 1612 }
1604 else if (inR->typeID() == eventID ) { 1613 else if (inR->typeID() == eventID ) {
1605 bool ok; 1614 bool ok;
1606 dt = inR->getNextOccurence( cur, &ok ); 1615 dt = inR->getNextOccurence( cur, &ok );
1607 if ( !ok ) 1616 if ( !ok )
1608 dt = cur.addSecs( -62 ); 1617 dt = cur.addSecs( -62 );
1609 } 1618 }
1610 else 1619 else
1611 dt = inR->dtStart(); 1620 dt = inR->dtStart();
1612 if ( dt < cur || dt > end ) { 1621 if ( dt < cur || dt > end ) {
1613 remote->deleteIncidence( inR ); 1622 remote->deleteIncidence( inR );
1614 ++delFut; 1623 ++delFut;
1615 } 1624 }
1616 inR = er.next(); 1625 inR = er.next();
1617 } 1626 }
1618 } 1627 }
1619 bar.hide(); 1628 bar.hide();
1620 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1629 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1621 eventLSync->setReadOnly( false ); 1630 eventLSync->setReadOnly( false );
1622 eventLSync->setDtStart( mLastCalendarSync ); 1631 eventLSync->setDtStart( mLastCalendarSync );
1623 eventRSync->setDtStart( mLastCalendarSync ); 1632 eventRSync->setDtStart( mLastCalendarSync );
1624 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1633 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1625 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1634 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1626 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1635 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1627 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1636 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1628 eventLSync->setReadOnly( true ); 1637 eventLSync->setReadOnly( true );
1629 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1638 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1630 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1639 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1631 remote->addEvent( eventRSync ); 1640 remote->addEvent( eventRSync );
1632 else 1641 else
1633 delete eventRSync; 1642 delete eventRSync;
1634 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1643 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1635 QString mes; 1644 QString mes;
1636 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); 1645 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT );
1637 QString delmess; 1646 QString delmess;
1638 if ( delFut ) { 1647 if ( delFut ) {
1639 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); 1648 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut);
1640 mes += delmess; 1649 mes += delmess;
1641 } 1650 }
1642 mes = i18n("Local calendar changed!\n") +mes; 1651 mes = i18n("Local calendar changed!\n") +mes;
1643 mCalendar->checkAlarmForIncidence( 0, true ); 1652 mCalendar->checkAlarmForIncidence( 0, true );
1644 qDebug( mes ); 1653 qDebug( mes );
1645 if ( mSyncManager->mShowSyncSummary ) { 1654 if ( mSyncManager->mShowSyncSummary ) {
1646 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1655 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1647 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1656 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1648 qDebug("KO: WB cancelled "); 1657 qDebug("KO: WB cancelled ");
1649 mSyncManager->mWriteBackFile = false; 1658 mSyncManager->mWriteBackFile = false;
1650 return syncOK; 1659 return syncOK;
1651 } 1660 }
1652 } 1661 }
1653 return syncOK; 1662 return syncOK;
1654} 1663}
1655 1664
1656void CalendarView::setSyncDevice( QString s ) 1665void CalendarView::setSyncDevice( QString s )
1657{ 1666{
1658 mCurrentSyncDevice= s; 1667 mCurrentSyncDevice= s;
1659} 1668}
1660void CalendarView::setSyncName( QString s ) 1669void CalendarView::setSyncName( QString s )
1661{ 1670{
1662 mCurrentSyncName= s; 1671 mCurrentSyncName= s;
1663} 1672}
1664bool CalendarView::syncCalendar(QString filename, int mode) 1673bool CalendarView::syncCalendar(QString filename, int mode)
1665{ 1674{
1666 //qDebug("syncCalendar %s ", filename.latin1()); 1675 //qDebug("syncCalendar %s ", filename.latin1());
1667 mGlobalSyncMode = SYNC_MODE_NORMAL; 1676 mGlobalSyncMode = SYNC_MODE_NORMAL;
1668 CalendarLocal* calendar = new CalendarLocal(); 1677 CalendarLocal* calendar = new CalendarLocal();
1669 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1678 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1670 FileStorage* storage = new FileStorage( calendar ); 1679 FileStorage* storage = new FileStorage( calendar );
1671 bool syncOK = false; 1680 bool syncOK = false;
1672 storage->setFileName( filename ); 1681 storage->setFileName( filename );
1673 // qDebug("loading ... "); 1682 // qDebug("loading ... ");
1674 if ( storage->load() ) { 1683 if ( storage->load() ) {
1675 getEventViewerDialog()->setSyncMode( true ); 1684 getEventViewerDialog()->setSyncMode( true );
1676 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1685 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1677 getEventViewerDialog()->setSyncMode( false ); 1686 getEventViewerDialog()->setSyncMode( false );
1678 if ( syncOK ) { 1687 if ( syncOK ) {
1679 if ( mSyncManager->mWriteBackFile ) 1688 if ( mSyncManager->mWriteBackFile )
1680 { 1689 {
1681 storage->setSaveFormat( new ICalFormat() ); 1690 storage->setSaveFormat( new ICalFormat() );
1682 storage->save(); 1691 storage->save();
1683 } 1692 }
1684 } 1693 }
1685 setModified( true ); 1694 setModified( true );
1686 } 1695 }
1687 delete storage; 1696 delete storage;
1688 delete calendar; 1697 delete calendar;
1689 if ( syncOK ) 1698 if ( syncOK )
1690 updateView(); 1699 updateView();
1691 return syncOK; 1700 return syncOK;
1692} 1701}
1693 1702
1694void CalendarView::syncExternal( int mode ) 1703void CalendarView::syncExternal( int mode )
1695{ 1704{
1696 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1705 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1697 1706
1698 qApp->processEvents(); 1707 qApp->processEvents();
1699 CalendarLocal* calendar = new CalendarLocal(); 1708 CalendarLocal* calendar = new CalendarLocal();
1700 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1709 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1701 bool syncOK = false; 1710 bool syncOK = false;
1702 bool loadSuccess = false; 1711 bool loadSuccess = false;
1703 PhoneFormat* phoneFormat = 0; 1712 PhoneFormat* phoneFormat = 0;
1704 emit tempDisableBR(true); 1713 emit tempDisableBR(true);
1705#ifndef DESKTOP_VERSION 1714#ifndef DESKTOP_VERSION
1706 SharpFormat* sharpFormat = 0; 1715 SharpFormat* sharpFormat = 0;
1707 if ( mode == 0 ) { // sharp 1716 if ( mode == 0 ) { // sharp
1708 sharpFormat = new SharpFormat () ; 1717 sharpFormat = new SharpFormat () ;
1709 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1718 loadSuccess = sharpFormat->load( calendar, mCalendar );
1710 1719
1711 } else 1720 } else
1712#endif 1721#endif
1713 if ( mode == 1 ) { // phone 1722 if ( mode == 1 ) { // phone
1714 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1723 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1715 mSyncManager->mPhoneDevice, 1724 mSyncManager->mPhoneDevice,
1716 mSyncManager->mPhoneConnection, 1725 mSyncManager->mPhoneConnection,
1717 mSyncManager->mPhoneModel); 1726 mSyncManager->mPhoneModel);
1718 loadSuccess = phoneFormat->load( calendar,mCalendar); 1727 loadSuccess = phoneFormat->load( calendar,mCalendar);
1719 1728
1720 } else { 1729 } else {
1721 emit tempDisableBR(false); 1730 emit tempDisableBR(false);
1722 return; 1731 return;
1723 } 1732 }
1724 if ( loadSuccess ) { 1733 if ( loadSuccess ) {
1725 getEventViewerDialog()->setSyncMode( true ); 1734 getEventViewerDialog()->setSyncMode( true );
1726 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1735 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1727 getEventViewerDialog()->setSyncMode( false ); 1736 getEventViewerDialog()->setSyncMode( false );
1728 qApp->processEvents(); 1737 qApp->processEvents();
1729 if ( syncOK ) { 1738 if ( syncOK ) {
1730 if ( mSyncManager->mWriteBackFile ) 1739 if ( mSyncManager->mWriteBackFile )
1731 { 1740 {
1732 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1741 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1733 Incidence* inc = iL.first(); 1742 Incidence* inc = iL.first();
1734 if ( phoneFormat ) { 1743 if ( phoneFormat ) {
1735 while ( inc ) { 1744 while ( inc ) {
1736 inc->removeID(mCurrentSyncDevice); 1745 inc->removeID(mCurrentSyncDevice);
1737 inc = iL.next(); 1746 inc = iL.next();
1738 } 1747 }
1739 } 1748 }
1740#ifndef DESKTOP_VERSION 1749#ifndef DESKTOP_VERSION
1741 if ( sharpFormat ) 1750 if ( sharpFormat )
1742 sharpFormat->save(calendar); 1751 sharpFormat->save(calendar);
1743#endif 1752#endif
1744 if ( phoneFormat ) 1753 if ( phoneFormat )
1745 phoneFormat->save(calendar); 1754 phoneFormat->save(calendar);
1746 iL = calendar->rawIncidences(); 1755 iL = calendar->rawIncidences();
1747 inc = iL.first(); 1756 inc = iL.first();
1748 Incidence* loc; 1757 Incidence* loc;
1749 while ( inc ) { 1758 while ( inc ) {
1750 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1759 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1751 loc = mCalendar->incidence(inc->uid() ); 1760 loc = mCalendar->incidence(inc->uid() );
1752 if ( loc ) { 1761 if ( loc ) {
1753 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1762 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1754 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1763 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1755 } 1764 }
1756 } 1765 }
1757 inc = iL.next(); 1766 inc = iL.next();
1758 } 1767 }
1759 Incidence* lse = getLastSyncEvent(); 1768 Incidence* lse = getLastSyncEvent();
1760 if ( lse ) { 1769 if ( lse ) {
1761 lse->setReadOnly( false ); 1770 lse->setReadOnly( false );
1762 lse->setDescription( "" ); 1771 lse->setDescription( "" );
1763 lse->setReadOnly( true ); 1772 lse->setReadOnly( true );
1764 } 1773 }
1765 } 1774 }
1766 } else { 1775 } else {
1767 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1776 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1768 } 1777 }
1769 setModified( true ); 1778 setModified( true );
1770 } else { 1779 } else {
1771 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1780 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1772 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1781 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1773 question, i18n("Ok")) ; 1782 question, i18n("Ok")) ;
1774 1783
1775 } 1784 }
1776 delete calendar; 1785 delete calendar;
1777 updateView(); 1786 updateView();
1778 emit tempDisableBR(false); 1787 emit tempDisableBR(false);
1779 return ;//syncOK; 1788 return ;//syncOK;
1780 1789
1781} 1790}
1782 1791
1783bool CalendarView::importBday() 1792bool CalendarView::importBday()
1784{ 1793{
1785#ifndef KORG_NOKABC 1794#ifndef KORG_NOKABC
1786 1795
1787#ifdef DESKTOP_VERSION 1796#ifdef DESKTOP_VERSION
1788 int curCal = mCalendar->defaultCalendar(); 1797 int curCal = mCalendar->defaultCalendar();
1789 int bd = mCalEditView->getBirtdayID(); 1798 int bd = mCalEditView->getBirtdayID();
1790 if ( bd == 0 ) 1799 if ( bd == 0 )
1791 return false; 1800 return false;
1792 mCalendar->setDefaultCalendar( bd ); 1801 mCalendar->setDefaultCalendar( bd );
1793 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1802 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1794 KABC::AddressBook::Iterator it; 1803 KABC::AddressBook::Iterator it;
1795 int count = 0; 1804 int count = 0;
1796 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1805 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1797 ++count; 1806 ++count;
1798 } 1807 }
1799 QProgressBar bar(count,0 ); 1808 QProgressBar bar(count,0 );
1800 int w = 300; 1809 int w = 300;
1801 if ( QApplication::desktop()->width() < 320 ) 1810 if ( QApplication::desktop()->width() < 320 )
1802 w = 220; 1811 w = 220;
1803 int h = bar.sizeHint().height() ; 1812 int h = bar.sizeHint().height() ;
1804 int dw = QApplication::desktop()->width(); 1813 int dw = QApplication::desktop()->width();
1805 int dh = QApplication::desktop()->height(); 1814 int dh = QApplication::desktop()->height();
1806 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1815 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1807 bar.show(); 1816 bar.show();
1808 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1817 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1809 qApp->processEvents(); 1818 qApp->processEvents();
1810 count = 0; 1819 count = 0;
1811 int addCount = 0; 1820 int addCount = 0;
1812 KCal::Attendee* a = 0; 1821 KCal::Attendee* a = 0;
1813 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1822 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1814 if ( ! bar.isVisible() ) 1823 if ( ! bar.isVisible() )
1815 return false; 1824 return false;
1816 bar.setProgress( count++ ); 1825 bar.setProgress( count++ );
1817 qApp->processEvents(); 1826 qApp->processEvents();
1818 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1827 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1819 if ( (*it).birthday().date().isValid() ){ 1828 if ( (*it).birthday().date().isValid() ){
1820 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1829 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1821 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1830 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1822 ++addCount; 1831 ++addCount;
1823 } 1832 }
1824 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1833 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1825 if ( anni.isValid() ){ 1834 if ( anni.isValid() ){
1826 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1835 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1827 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1836 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1828 ++addCount; 1837 ++addCount;
1829 } 1838 }
1830 } 1839 }
1831 mCalendar->setDefaultCalendar( curCal ); 1840 mCalendar->setDefaultCalendar( curCal );
1832 updateView(); 1841 updateView();
1833 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1842 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1834#else //DESKTOP_VERSION 1843#else //DESKTOP_VERSION
1835 1844
1836 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1845 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1837 // the result should now arrive through method insertBirthdays 1846 // the result should now arrive through method insertBirthdays
1838 1847
1839#endif //DESKTOP_VERSION 1848#endif //DESKTOP_VERSION
1840 1849
1841#endif //KORG_NOKABC 1850#endif //KORG_NOKABC
1842 1851
1843 1852
1844 return true; 1853 return true;
1845} 1854}
1846 1855
1847// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1856// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1848void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1857void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1849 const QStringList& anniversaryList, const QStringList& realNameList, 1858 const QStringList& anniversaryList, const QStringList& realNameList,
1850 const QStringList& emailList, const QStringList& assembledNameList, 1859 const QStringList& emailList, const QStringList& assembledNameList,
1851 const QStringList& uidList) 1860 const QStringList& uidList)
1852{ 1861{
1853 1862
1854 //qDebug("KO::CalendarView::insertBirthdays"); 1863 //qDebug("KO::CalendarView::insertBirthdays");
1855 if (uid == this->name()) 1864 if (uid == this->name())
1856 { 1865 {
1857 int curCal = mCalendar->defaultCalendar(); 1866 int curCal = mCalendar->defaultCalendar();
1858 int bd = mCalEditView->getBirtdayID(); 1867 int bd = mCalEditView->getBirtdayID();
1859 if ( bd == 0 ) 1868 if ( bd == 0 )
1860 return; 1869 return;
1861 mCalendar->setDefaultCalendar( bd ); 1870 mCalendar->setDefaultCalendar( bd );
1862 1871
1863 1872
1864 int count = birthdayList.count(); 1873 int count = birthdayList.count();
1865 int addCount = 0; 1874 int addCount = 0;
1866 KCal::Attendee* a = 0; 1875 KCal::Attendee* a = 0;
1867 1876
1868 //qDebug("CalView 1 %i", count); 1877 //qDebug("CalView 1 %i", count);
1869 1878
1870 QProgressBar bar(count,0 ); 1879 QProgressBar bar(count,0 );
1871 int w = 300; 1880 int w = 300;
1872 if ( QApplication::desktop()->width() < 320 ) 1881 if ( QApplication::desktop()->width() < 320 )
1873 w = 220; 1882 w = 220;
1874 int h = bar.sizeHint().height() ; 1883 int h = bar.sizeHint().height() ;
1875 int dw = QApplication::desktop()->width(); 1884 int dw = QApplication::desktop()->width();
1876 int dh = QApplication::desktop()->height(); 1885 int dh = QApplication::desktop()->height();
1877 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1886 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1878 bar.show(); 1887 bar.show();
1879 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1888 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1880 qApp->processEvents(); 1889 qApp->processEvents();
1881 1890
1882 QDate birthday; 1891 QDate birthday;
1883 QDate anniversary; 1892 QDate anniversary;
1884 QString realName; 1893 QString realName;
1885 QString email; 1894 QString email;
1886 QString assembledName; 1895 QString assembledName;
1887 QString uid; 1896 QString uid;
1888 bool ok = true; 1897 bool ok = true;
1889 for ( int i = 0; i < count; i++) 1898 for ( int i = 0; i < count; i++)
1890 { 1899 {
1891 if ( ! bar.isVisible() ) 1900 if ( ! bar.isVisible() )
1892 return; 1901 return;
1893 bar.setProgress( i ); 1902 bar.setProgress( i );
1894 qApp->processEvents(); 1903 qApp->processEvents();
1895 1904
1896 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1905 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1897 if (!ok) { 1906 if (!ok) {
1898 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1907 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1899 } 1908 }
1900 1909
1901 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1910 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1902 if (!ok) { 1911 if (!ok) {
1903 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1912 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1904 } 1913 }
1905 realName = realNameList[i]; 1914 realName = realNameList[i];
1906 email = emailList[i]; 1915 email = emailList[i];
1907 assembledName = assembledNameList[i]; 1916 assembledName = assembledNameList[i];
1908 uid = uidList[i]; 1917 uid = uidList[i];
1909 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() ); 1918 //qDebug("insert birthday in KO/Pi: %s,%s,%s,%s: %s, %s", realName.latin1(), email.latin1(), assembledName.latin1(), uid.latin1(), birthdayList[i].latin1(), anniversaryList[i].latin1() );
1910 1919
1911 if ( birthday.isValid() ){ 1920 if ( birthday.isValid() ){
1912 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1921 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1913 KCal::Attendee::ReqParticipant,uid) ; 1922 KCal::Attendee::ReqParticipant,uid) ;
1914 if ( addAnniversary( birthday, assembledName, a, true ) ) 1923 if ( addAnniversary( birthday, assembledName, a, true ) )
1915 ++addCount; 1924 ++addCount;
1916 } 1925 }
1917 1926
1918 if ( anniversary.isValid() ){ 1927 if ( anniversary.isValid() ){
1919 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1928 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1920 KCal::Attendee::ReqParticipant,uid) ; 1929 KCal::Attendee::ReqParticipant,uid) ;
1921 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1930 if ( addAnniversary( anniversary, assembledName, a, false ) )
1922 ++addCount; 1931 ++addCount;
1923 } 1932 }
1924 } 1933 }
1925 1934
1926 mCalendar->setDefaultCalendar( curCal ); 1935 mCalendar->setDefaultCalendar( curCal );
1927 updateView(); 1936 updateView();
1928 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1937 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1929 1938
1930 } 1939 }
1931 1940
1932} 1941}
1933 1942
1934 1943
1935 1944
1936bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1945bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1937{ 1946{
1938 //qDebug("addAnni "); 1947 //qDebug("addAnni ");
1939 Event * ev = new Event(); 1948 Event * ev = new Event();
1940 ev->setOrganizer(KOPrefs::instance()->email()); 1949 ev->setOrganizer(KOPrefs::instance()->email());
1941 if ( a ) { 1950 if ( a ) {
1942 ev->addAttendee( a ); 1951 ev->addAttendee( a );
1943 } 1952 }
1944 QString kind; 1953 QString kind;
1945 if ( birthday ) { 1954 if ( birthday ) {
1946 kind = i18n( "Birthday" ); 1955 kind = i18n( "Birthday" );
1947 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1956 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1948 } 1957 }
1949 else { 1958 else {
1950 kind = i18n( "Anniversary" ); 1959 kind = i18n( "Anniversary" );
1951 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1960 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1952 } 1961 }
1953 ev->setCategories( kind ); 1962 ev->setCategories( kind );
1954 ev->setDtStart( QDateTime(date) ); 1963 ev->setDtStart( QDateTime(date) );
1955 ev->setDtEnd( QDateTime(date) ); 1964 ev->setDtEnd( QDateTime(date) );
1956 ev->setFloats( true ); 1965 ev->setFloats( true );
1957 Recurrence * rec = ev->recurrence(); 1966 Recurrence * rec = ev->recurrence();
1958 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1967 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1959 rec->addYearlyNum( date.month() ); 1968 rec->addYearlyNum( date.month() );
1960 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1969 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1961 delete ev; 1970 delete ev;
1962 return false; 1971 return false;
1963 } 1972 }
1964 return true; 1973 return true;
1965 1974
1966} 1975}
1967bool CalendarView::importQtopia( const QString &categories, 1976bool CalendarView::importQtopia( const QString &categories,
1968 const QString &datebook, 1977 const QString &datebook,
1969 const QString &todolist ) 1978 const QString &todolist )
1970{ 1979{
1971 1980
1972 QtopiaFormat qtopiaFormat; 1981 QtopiaFormat qtopiaFormat;
1973 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1982 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1974 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1983 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1975 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1984 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1976 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1985 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1977 1986
1978 updateView(); 1987 updateView();
1979 return true; 1988 return true;
1980 1989
1981#if 0 1990#if 0
1982 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1991 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1983 mCurrentSyncDevice = "qtopia-XML"; 1992 mCurrentSyncDevice = "qtopia-XML";
1984 if ( mSyncManager->mAskForPreferences ) 1993 if ( mSyncManager->mAskForPreferences )
1985 edit_sync_options(); 1994 edit_sync_options();
1986 qApp->processEvents(); 1995 qApp->processEvents();
1987 CalendarLocal* calendar = new CalendarLocal(); 1996 CalendarLocal* calendar = new CalendarLocal();
1988 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1997 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1989 bool syncOK = false; 1998 bool syncOK = false;
1990 QtopiaFormat qtopiaFormat; 1999 QtopiaFormat qtopiaFormat;
1991 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2000 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1992 bool loadOk = true; 2001 bool loadOk = true;
1993 if ( !categories.isEmpty() ) 2002 if ( !categories.isEmpty() )
1994 loadOk = qtopiaFormat.load( calendar, categories ); 2003 loadOk = qtopiaFormat.load( calendar, categories );
1995 if ( loadOk && !datebook.isEmpty() ) 2004 if ( loadOk && !datebook.isEmpty() )
1996 loadOk = qtopiaFormat.load( calendar, datebook ); 2005 loadOk = qtopiaFormat.load( calendar, datebook );
1997 if ( loadOk && !todolist.isEmpty() ) 2006 if ( loadOk && !todolist.isEmpty() )
1998 loadOk = qtopiaFormat.load( calendar, todolist ); 2007 loadOk = qtopiaFormat.load( calendar, todolist );
1999 2008
2000 if ( loadOk ) { 2009 if ( loadOk ) {
2001 getEventViewerDialog()->setSyncMode( true ); 2010 getEventViewerDialog()->setSyncMode( true );
2002 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2011 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2003 getEventViewerDialog()->setSyncMode( false ); 2012 getEventViewerDialog()->setSyncMode( false );
2004 qApp->processEvents(); 2013 qApp->processEvents();
2005 if ( syncOK ) { 2014 if ( syncOK ) {
2006 if ( mSyncManager->mWriteBackFile ) 2015 if ( mSyncManager->mWriteBackFile )
2007 { 2016 {
2008 // write back XML file 2017 // write back XML file
2009 2018
2010 } 2019 }
2011 setModified( true ); 2020 setModified( true );
2012 } 2021 }
2013 } else { 2022 } else {
2014 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2023 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2015 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2024 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2016 question, i18n("Ok")) ; 2025 question, i18n("Ok")) ;
2017 } 2026 }
2018 delete calendar; 2027 delete calendar;
2019 updateView(); 2028 updateView();
2020 return syncOK; 2029 return syncOK;
2021 2030
2022 2031
2023#endif 2032#endif
2024 2033
2025} 2034}
2026 2035
2027void CalendarView::setSyncEventsReadOnly() 2036void CalendarView::setSyncEventsReadOnly()
2028{ 2037{
2029 mCalendar->setSyncEventsReadOnly(); 2038 mCalendar->setSyncEventsReadOnly();
2030} 2039}
2031 2040
2032bool CalendarView::loadCalendars() 2041bool CalendarView::loadCalendars()
2033{ 2042{
2034 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2043 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2035 KopiCalendarFile * cal = calendars.first(); 2044 KopiCalendarFile * cal = calendars.first();
2036 mCalendar->setDefaultCalendar( 1 ); 2045 mCalendar->setDefaultCalendar( 1 );
2037 openCalendar( MainWindow::defaultFileName(), false ); 2046 openCalendar( MainWindow::defaultFileName(), false );
2038 cal = calendars.next(); 2047 cal = calendars.next();
2039 while ( cal ) { 2048 while ( cal ) {
2040 addCalendar( cal ); 2049 addCalendar( cal );
2041 cal = calendars.next(); 2050 cal = calendars.next();
2042 } 2051 }
2043 restoreCalendarSettings(); 2052 restoreCalendarSettings();
2044 return true; 2053 return true;
2045} 2054}
2046bool CalendarView::restoreCalendarSettings() 2055bool CalendarView::restoreCalendarSettings()
2047{ 2056{
2048 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2057 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2049 KopiCalendarFile * cal = calendars.first(); 2058 KopiCalendarFile * cal = calendars.first();
2050 while ( cal ) { 2059 while ( cal ) {
2051 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2060 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2052 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2061 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2053 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2062 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2054 if ( cal->isStandard ) 2063 if ( cal->isStandard )
2055 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2064 mCalendar->setDefaultCalendar( cal->mCalNumber );
2056 cal = calendars.next(); 2065 cal = calendars.next();
2057 } 2066 }
2058 setSyncEventsReadOnly(); 2067 setSyncEventsReadOnly();
2059 mCalendar->reInitAlarmSettings(); 2068 mCalendar->reInitAlarmSettings();
2060 updateUnmanagedViews(); 2069 updateUnmanagedViews();
2061 updateView(); 2070 updateView();
2062 return true; 2071 return true;
2063} 2072}
2064void CalendarView::addCalendarId( int id ) 2073void CalendarView::addCalendarId( int id )
2065{ 2074{
2066 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2075 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2067 if ( cal ) 2076 if ( cal )
2068 addCalendar( cal ); 2077 addCalendar( cal );
2069} 2078}
2070bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2079bool CalendarView::addCalendar( KopiCalendarFile * cal )
2071{ 2080{
2072 cal->mErrorOnLoad = false; 2081 cal->mErrorOnLoad = false;
2073 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2082 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2074 cal->mLoadDt = QDateTime::currentDateTime(); 2083 cal->mLoadDt = QDateTime::currentDateTime();
2075 return true; 2084 return true;
2076 } 2085 }
2077 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2086 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2078 cal->mErrorOnLoad = true; 2087 cal->mErrorOnLoad = true;
2079 return false; 2088 return false;
2080} 2089}
2081bool CalendarView::openCalendar(QString filename, bool merge) 2090bool CalendarView::openCalendar(QString filename, bool merge)
2082{ 2091{
2083 2092
2084 if (filename.isEmpty()) { 2093 if (filename.isEmpty()) {
2085 return false; 2094 return false;
2086 } 2095 }
2087 2096
2088 if (!QFile::exists(filename)) { 2097 if (!QFile::exists(filename)) {
2089 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2098 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2090 return false; 2099 return false;
2091 } 2100 }
2092 2101
2093 globalFlagBlockAgenda = 1; 2102 globalFlagBlockAgenda = 1;
2094 clearAllViews(); 2103 clearAllViews();
2095 if (!merge) { 2104 if (!merge) {
2096 mViewManager->setDocumentId( filename ); 2105 mViewManager->setDocumentId( filename );
2097 mCalendar->close(); 2106 mCalendar->close();
2098 } 2107 }
2099 mStorage->setFileName( filename ); 2108 mStorage->setFileName( filename );
2100 2109
2101 if ( mStorage->load() ) { 2110 if ( mStorage->load() ) {
2102 if ( merge ) ;//setModified( true ); 2111 if ( merge ) ;//setModified( true );
2103 else { 2112 else {
2104 //setModified( true ); 2113 //setModified( true );
2105 mViewManager->setDocumentId( filename ); 2114 mViewManager->setDocumentId( filename );
2106 mDialogManager->setDocumentId( filename ); 2115 mDialogManager->setDocumentId( filename );
2107 mTodoList->setDocumentId( filename ); 2116 mTodoList->setDocumentId( filename );
2108 } 2117 }
2109 globalFlagBlockAgenda = 2; 2118 globalFlagBlockAgenda = 2;
2110 // if ( getLastSyncEvent() ) 2119 // if ( getLastSyncEvent() )
2111 // getLastSyncEvent()->setReadOnly( true ); 2120 // getLastSyncEvent()->setReadOnly( true );
2112 mCalendar->reInitAlarmSettings(); 2121 mCalendar->reInitAlarmSettings();
2113 setSyncEventsReadOnly(); 2122 setSyncEventsReadOnly();
2114 updateUnmanagedViews(); 2123 updateUnmanagedViews();
2115 updateView(); 2124 updateView();
2116 if ( filename != MainWindow::defaultFileName() ) { 2125 if ( filename != MainWindow::defaultFileName() ) {
2117 saveCalendar( MainWindow::defaultFileName() ); 2126 saveCalendar( MainWindow::defaultFileName() );
2118 } else { 2127 } else {
2119 QFileInfo finf ( MainWindow::defaultFileName()); 2128 QFileInfo finf ( MainWindow::defaultFileName());
2120 if ( finf.exists() ) { 2129 if ( finf.exists() ) {
2121 setLoadedFileVersion( finf.lastModified () ); 2130 setLoadedFileVersion( finf.lastModified () );
2122 } 2131 }
2123 } 2132 }
2124 return true; 2133 return true;
2125 } else { 2134 } else {
2126 // while failing to load, the calendar object could 2135 // while failing to load, the calendar object could
2127 // have become partially populated. Clear it out. 2136 // have become partially populated. Clear it out.
2128 if ( !merge ) { 2137 if ( !merge ) {
2129 mCalendar->close(); 2138 mCalendar->close();
2130 mViewManager->setDocumentId( filename ); 2139 mViewManager->setDocumentId( filename );
2131 mDialogManager->setDocumentId( filename ); 2140 mDialogManager->setDocumentId( filename );
2132 mTodoList->setDocumentId( filename ); 2141 mTodoList->setDocumentId( filename );
2133 } 2142 }
2134 2143
2135 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2144 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2136 2145
2137 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2146 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2138 globalFlagBlockAgenda = 2; 2147 globalFlagBlockAgenda = 2;
2139 mCalendar->reInitAlarmSettings(); 2148 mCalendar->reInitAlarmSettings();
2140 setSyncEventsReadOnly(); 2149 setSyncEventsReadOnly();
2141 updateUnmanagedViews(); 2150 updateUnmanagedViews();
2142 updateView(); 2151 updateView();
2143 } 2152 }
2144 return false; 2153 return false;
2145} 2154}
2155void CalendarView::mergeFile( QString fn )
2156{
2157 clearAllViews();
2158 mCalendar->mergeCalendarFile( fn );
2159 mCalendar->reInitAlarmSettings();
2160 setSyncEventsReadOnly();
2161 updateUnmanagedViews();
2162 updateView();
2163}
2146void CalendarView::showOpenError() 2164void CalendarView::showOpenError()
2147{ 2165{
2148 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2166 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2149} 2167}
2150void CalendarView::setLoadedFileVersion(QDateTime dt) 2168void CalendarView::setLoadedFileVersion(QDateTime dt)
2151{ 2169{
2152 loadedFileVersion = dt; 2170 loadedFileVersion = dt;
2153} 2171}
2154bool CalendarView::checkFileChanged(QString fn) 2172bool CalendarView::checkFileChanged(QString fn)
2155{ 2173{
2156 QFileInfo finf ( fn ); 2174 QFileInfo finf ( fn );
2157 if ( !finf.exists() ) 2175 if ( !finf.exists() )
2158 return true; 2176 return true;
2159 QDateTime dt = finf.lastModified (); 2177 QDateTime dt = finf.lastModified ();
2160 if ( dt <= loadedFileVersion ) 2178 if ( dt <= loadedFileVersion )
2161 return false; 2179 return false;
2162 return true; 2180 return true;
2163 2181
2164} 2182}
2165void CalendarView::watchSavedFile() 2183void CalendarView::watchSavedFile()
2166{ 2184{
2167 QFileInfo finf ( MainWindow::defaultFileName()); 2185 QFileInfo finf ( MainWindow::defaultFileName());
2168 if ( !finf.exists() ) 2186 if ( !finf.exists() )
2169 return; 2187 return;
2170 QDateTime dt = finf.lastModified (); 2188 QDateTime dt = finf.lastModified ();
2171 if ( dt < loadedFileVersion ) { 2189 if ( dt < loadedFileVersion ) {
2172 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2190 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2173 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2191 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2174 return; 2192 return;
2175 } 2193 }
2176 loadedFileVersion = dt; 2194 loadedFileVersion = dt;
2177} 2195}
2178bool CalendarView::checkAllFileVersions() 2196bool CalendarView::checkAllFileVersions()
2179{ 2197{
2180 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2198 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2181 KopiCalendarFile * cal = calendars.first(); 2199 KopiCalendarFile * cal = calendars.first();
2182 mCalendar->setDefaultCalendar( 1 ); 2200 mCalendar->setDefaultCalendar( 1 );
2183 mCalendar->setDefaultCalendarEnabledOnly(); 2201 mCalendar->setDefaultCalendarEnabledOnly();
2184 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2202 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2185 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2203 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2186 restoreCalendarSettings(); 2204 restoreCalendarSettings();
2187 return false; 2205 return false;
2188 } 2206 }
2189 } 2207 }
2190 cal = calendars.next(); 2208 cal = calendars.next();
2191 QDateTime storeTemp = loadedFileVersion; 2209 QDateTime storeTemp = loadedFileVersion;
2192 while ( cal ) { 2210 while ( cal ) {
2193 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2211 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2194 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2212 mCalendar->setDefaultCalendar( cal->mCalNumber );
2195 mCalendar->setDefaultCalendarEnabledOnly(); 2213 mCalendar->setDefaultCalendarEnabledOnly();
2196 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2214 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2197 if ( !checkFileVersion(cal->mFileName )) { 2215 if ( !checkFileVersion(cal->mFileName )) {
2198 loadedFileVersion = storeTemp; 2216 loadedFileVersion = storeTemp;
2199 restoreCalendarSettings(); 2217 restoreCalendarSettings();
2200 return false; 2218 return false;
2201 } 2219 }
2202 } 2220 }
2203 cal = calendars.next(); 2221 cal = calendars.next();
2204 } 2222 }
2205 loadedFileVersion = storeTemp; 2223 loadedFileVersion = storeTemp;
2206 return true; 2224 return true;
2207} 2225}
2208bool CalendarView::checkFileVersion(QString fn) 2226bool CalendarView::checkFileVersion(QString fn)
2209{ 2227{
2210 QFileInfo finf ( fn ); 2228 QFileInfo finf ( fn );
2211 if ( !finf.exists() ) 2229 if ( !finf.exists() )
2212 return true; 2230 return true;
2213 QDateTime dt = finf.lastModified (); 2231 QDateTime dt = finf.lastModified ();
2214 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2232 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2215 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2233 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2216 if ( dt <= loadedFileVersion ) 2234 if ( dt <= loadedFileVersion )
2217 return true; 2235 return true;
2218 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2236 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\non disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(KGlobal::formatMessage(fn,0)).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2219 i18n("KO/Pi Warning"),i18n("Overwrite"), 2237 i18n("KO/Pi Warning"),i18n("Overwrite"),
2220 i18n("Sync+save")); 2238 i18n("Sync+save"));
2221 2239
2222 if ( km == KMessageBox::Cancel ) 2240 if ( km == KMessageBox::Cancel )
2223 return false; 2241 return false;
2224 if ( km == KMessageBox::Yes ) 2242 if ( km == KMessageBox::Yes )
2225 return true; 2243 return true;
2226 2244
2227 setSyncDevice("deleteaftersync" ); 2245 setSyncDevice("deleteaftersync" );
2228 mSyncManager->mAskForPreferences = true; 2246 mSyncManager->mAskForPreferences = true;
2229 mSyncManager->mSyncAlgoPrefs = 3; 2247 mSyncManager->mSyncAlgoPrefs = 3;
2230 mSyncManager->mWriteBackFile = false; 2248 mSyncManager->mWriteBackFile = false;
2231 mSyncManager->mWriteBackExistingOnly = false; 2249 mSyncManager->mWriteBackExistingOnly = false;
2232 mSyncManager->mShowSyncSummary = false; 2250 mSyncManager->mShowSyncSummary = false;
2233 syncCalendar( fn, 3 ); 2251 syncCalendar( fn, 3 );
2234 Event * e = getLastSyncEvent(); 2252 Event * e = getLastSyncEvent();
2235 if ( e ) 2253 if ( e )
2236 mCalendar->deleteEvent( e ); 2254 mCalendar->deleteEvent( e );
2237 return true; 2255 return true;
2238} 2256}
2239bool CalendarView::saveCalendars() 2257bool CalendarView::saveCalendars()
2240{ 2258{
2241 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2259 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2242 KopiCalendarFile * cal = calendars.first(); 2260 KopiCalendarFile * cal = calendars.first();
2243 mCalendar->setDefaultCalendar( 1 ); 2261 mCalendar->setDefaultCalendar( 1 );
2244 mCalendar->setDefaultCalendarEnabledOnly(); 2262 mCalendar->setDefaultCalendarEnabledOnly();
2245 saveCalendar( MainWindow::defaultFileName() ); 2263 saveCalendar( MainWindow::defaultFileName() );
2246 cal = calendars.next(); 2264 cal = calendars.next();
2247 while ( cal ) { 2265 while ( cal ) {
2248 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2266 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2249 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2267 mCalendar->setDefaultCalendar( cal->mCalNumber );
2250 mCalendar->setDefaultCalendarEnabledOnly(); 2268 mCalendar->setDefaultCalendarEnabledOnly();
2251 if ( saveCalendar( cal->mFileName ) ) 2269 if ( saveCalendar( cal->mFileName ) )
2252 cal->mLoadDt = QDateTime::currentDateTime(); 2270 cal->mLoadDt = QDateTime::currentDateTime();
2253 } 2271 }
2254 cal = calendars.next(); 2272 cal = calendars.next();
2255 } 2273 }
2256 restoreCalendarSettings(); 2274 restoreCalendarSettings();
2257 return true; 2275 return true;
2258} 2276}
2259bool CalendarView::saveCalendar( QString filename ) 2277bool CalendarView::saveCalendar( QString filename )
2260{ 2278{
2261 2279
2262 // Store back all unsaved data into calendar object 2280 // Store back all unsaved data into calendar object
2263 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2281 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2264 if ( mViewManager->currentView() ) 2282 if ( mViewManager->currentView() )
2265 mViewManager->currentView()->flushView(); 2283 mViewManager->currentView()->flushView();
2266 2284
2267 2285
2268 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2286 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2269 mStorage->setSaveFormat( new ICalFormat() ); 2287 mStorage->setSaveFormat( new ICalFormat() );
2270 mStorage->setFileName( filename ); 2288 mStorage->setFileName( filename );
2271 bool success; 2289 bool success;
2272 success = mStorage->save(); 2290 success = mStorage->save();
2273 if ( !success ) { 2291 if ( !success ) {
2274 return false; 2292 return false;
2275 } 2293 }
2276 if ( filename == MainWindow::defaultFileName() ) { 2294 if ( filename == MainWindow::defaultFileName() ) {
2277 setLoadedFileVersion( lfv ); 2295 setLoadedFileVersion( lfv );
2278 watchSavedFile(); 2296 watchSavedFile();
2279 } 2297 }
2280 return true; 2298 return true;
2281} 2299}
2282 2300
2283void CalendarView::closeCalendar() 2301void CalendarView::closeCalendar()
2284{ 2302{
2285 2303
2286 // child windows no longer valid 2304 // child windows no longer valid
2287 clearAllViews(); 2305 clearAllViews();
2288 emit closingDown(); 2306 emit closingDown();
2289 2307
2290 mCalendar->close(); 2308 mCalendar->close();
2291 setModified(false); 2309 setModified(false);
2292 updateView(); 2310 updateView();
2293} 2311}
2294 2312
2295void CalendarView::archiveCalendar() 2313void CalendarView::archiveCalendar()
2296{ 2314{
2297 mDialogManager->showArchiveDialog(); 2315 mDialogManager->showArchiveDialog();
2298} 2316}
2299 2317
2300 2318
2301void CalendarView::readSettings() 2319void CalendarView::readSettings()
2302{ 2320{
2303 2321
2304 2322
2305 // mViewManager->showAgendaView(); 2323 // mViewManager->showAgendaView();
2306 QString str; 2324 QString str;
2307 //qDebug("CalendarView::readSettings() "); 2325 //qDebug("CalendarView::readSettings() ");
2308 // read settings from the KConfig, supplying reasonable 2326 // read settings from the KConfig, supplying reasonable
2309 // defaults where none are to be found 2327 // defaults where none are to be found
2310 KConfig *config = KOGlobals::config(); 2328 KConfig *config = KOGlobals::config();
2311#ifndef KORG_NOSPLITTER 2329#ifndef KORG_NOSPLITTER
2312 config->setGroup("KOrganizer Geometry"); 2330 config->setGroup("KOrganizer Geometry");
2313 2331
2314 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2332 QValueList<int> sizes = config->readIntListEntry("Separator1");
2315 if (sizes.count() != 2) { 2333 if (sizes.count() != 2) {
2316 sizes << mDateNavigator->minimumSizeHint().width(); 2334 sizes << mDateNavigator->minimumSizeHint().width();
2317 sizes << 300; 2335 sizes << 300;
2318 } 2336 }
2319 mPanner->setSizes(sizes); 2337 mPanner->setSizes(sizes);
2320 2338
2321 sizes = config->readIntListEntry("Separator2"); 2339 sizes = config->readIntListEntry("Separator2");
2322 if ( ( mResourceView && sizes.count() == 4 ) || 2340 if ( ( mResourceView && sizes.count() == 4 ) ||
2323 ( !mResourceView && sizes.count() == 3 ) ) { 2341 ( !mResourceView && sizes.count() == 3 ) ) {
2324 mLeftSplitter->setSizes(sizes); 2342 mLeftSplitter->setSizes(sizes);
2325 } 2343 }
2326#endif 2344#endif
2327 globalFlagBlockAgenda = 1; 2345 globalFlagBlockAgenda = 1;
2328 mViewManager->showAgendaView(); 2346 mViewManager->showAgendaView();
2329 //mViewManager->readSettings( config ); 2347 //mViewManager->readSettings( config );
2330 mTodoList->restoreLayout(config,QString("Todo Layout")); 2348 mTodoList->restoreLayout(config,QString("Todo Layout"));
2331 readFilterSettings(config); 2349 readFilterSettings(config);
2332 2350
2333#ifdef DESKTOP_VERSION 2351#ifdef DESKTOP_VERSION
2334 config->setGroup("WidgetLayout"); 2352 config->setGroup("WidgetLayout");
2335 QStringList list; 2353 QStringList list;
2336 list = config->readListEntry("MainLayout"); 2354 list = config->readListEntry("MainLayout");
2337 int x,y,w,h; 2355 int x,y,w,h;
2338 if ( ! list.isEmpty() ) { 2356 if ( ! list.isEmpty() ) {
2339 x = list[0].toInt(); 2357 x = list[0].toInt();
2340 y = list[1].toInt(); 2358 y = list[1].toInt();
2341 w = list[2].toInt(); 2359 w = list[2].toInt();
2342 h = list[3].toInt(); 2360 h = list[3].toInt();
2343 KApplication::testCoords( &x,&y,&w,&h ); 2361 KApplication::testCoords( &x,&y,&w,&h );
2344 topLevelWidget()->setGeometry(x,y,w,h); 2362 topLevelWidget()->setGeometry(x,y,w,h);
2345 2363
2346 } else { 2364 } else {
2347 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2365 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2348 } 2366 }
2349 list = config->readListEntry("EditEventLayout"); 2367 list = config->readListEntry("EditEventLayout");
2350 if ( ! list.isEmpty() ) { 2368 if ( ! list.isEmpty() ) {
2351 x = list[0].toInt(); 2369 x = list[0].toInt();
2352 y = list[1].toInt(); 2370 y = list[1].toInt();
2353 w = list[2].toInt(); 2371 w = list[2].toInt();
2354 h = list[3].toInt(); 2372 h = list[3].toInt();
2355 KApplication::testCoords( &x,&y,&w,&h ); 2373 KApplication::testCoords( &x,&y,&w,&h );
2356 mEventEditor->setGeometry(x,y,w,h); 2374 mEventEditor->setGeometry(x,y,w,h);
2357 2375
2358 } 2376 }
2359 list = config->readListEntry("EditTodoLayout"); 2377 list = config->readListEntry("EditTodoLayout");
2360 if ( ! list.isEmpty() ) { 2378 if ( ! list.isEmpty() ) {
2361 x = list[0].toInt(); 2379 x = list[0].toInt();
2362 y = list[1].toInt(); 2380 y = list[1].toInt();
2363 w = list[2].toInt(); 2381 w = list[2].toInt();
2364 h = list[3].toInt(); 2382 h = list[3].toInt();
2365 KApplication::testCoords( &x,&y,&w,&h ); 2383 KApplication::testCoords( &x,&y,&w,&h );
2366 mTodoEditor->setGeometry(x,y,w,h); 2384 mTodoEditor->setGeometry(x,y,w,h);
2367 2385
2368 } 2386 }
2369 list = config->readListEntry("ViewerLayout"); 2387 list = config->readListEntry("ViewerLayout");
2370 if ( ! list.isEmpty() ) { 2388 if ( ! list.isEmpty() ) {
2371 x = list[0].toInt(); 2389 x = list[0].toInt();
2372 y = list[1].toInt(); 2390 y = list[1].toInt();
2373 w = list[2].toInt(); 2391 w = list[2].toInt();
2374 h = list[3].toInt(); 2392 h = list[3].toInt();
2375 KApplication::testCoords( &x,&y,&w,&h ); 2393 KApplication::testCoords( &x,&y,&w,&h );
2376 getEventViewerDialog()->setGeometry(x,y,w,h); 2394 getEventViewerDialog()->setGeometry(x,y,w,h);
2377 } 2395 }
2378#endif 2396#endif
2379 config->setGroup( "Views" ); 2397 config->setGroup( "Views" );
2380 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2398 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2381 2399
2382 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2400 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2383 2401
2384 int resetval = 0; 2402 int resetval = 0;
2385 int maxVal = 0; 2403 int maxVal = 0;
2386 if (sizes.count() != 3) { 2404 if (sizes.count() != 3) {
2387 if ( KOPrefs::instance()->mVerticalScreen ) { 2405 if ( KOPrefs::instance()->mVerticalScreen ) {
2388 resetval = mDateNavigator->sizeHint().width()+2; 2406 resetval = mDateNavigator->sizeHint().width()+2;
2389 } else { 2407 } else {
2390 resetval = mDateNavigator->sizeHint().height()+2; 2408 resetval = mDateNavigator->sizeHint().height()+2;
2391 } 2409 }
2392 } 2410 }
2393 if ( resetval ) { 2411 if ( resetval ) {
2394 sizes.clear(); 2412 sizes.clear();
2395 if ( KOPrefs::instance()->mVerticalScreen ) { 2413 if ( KOPrefs::instance()->mVerticalScreen ) {
2396 maxVal = QApplication::desktop()->width() -10; 2414 maxVal = QApplication::desktop()->width() -10;
2397 } else { 2415 } else {
2398 maxVal = QApplication::desktop()->height()-10; 2416 maxVal = QApplication::desktop()->height()-10;
2399 } 2417 }
2400 sizes << resetval; 2418 sizes << resetval;
2401 if ( maxVal < resetval + resetval) 2419 if ( maxVal < resetval + resetval)
2402 resetval = maxVal - resetval; 2420 resetval = maxVal - resetval;
2403 sizes << resetval; 2421 sizes << resetval;
2404 sizes << 100; 2422 sizes << 100;
2405 } 2423 }
2406 mLeftFrame->setSizes(sizes); 2424 mLeftFrame->setSizes(sizes);
2407 sizes = config->readIntListEntry("Main Splitter Frame"); 2425 sizes = config->readIntListEntry("Main Splitter Frame");
2408 resetval = 0; 2426 resetval = 0;
2409 maxVal = 0; 2427 maxVal = 0;
2410 if (sizes.count() != 2) { 2428 if (sizes.count() != 2) {
2411 if ( !KOPrefs::instance()->mVerticalScreen ) { 2429 if ( !KOPrefs::instance()->mVerticalScreen ) {
2412 resetval = mDateNavigator->sizeHint().width()+2; 2430 resetval = mDateNavigator->sizeHint().width()+2;
2413 } else { 2431 } else {
2414 resetval = mDateNavigator->sizeHint().height()+2; 2432 resetval = mDateNavigator->sizeHint().height()+2;
2415 } 2433 }
2416 } 2434 }
2417 if ( resetval ) { 2435 if ( resetval ) {
2418 sizes.clear(); 2436 sizes.clear();
2419 if ( !KOPrefs::instance()->mVerticalScreen ) { 2437 if ( !KOPrefs::instance()->mVerticalScreen ) {
2420 maxVal = QApplication::desktop()->width() -10; 2438 maxVal = QApplication::desktop()->width() -10;
2421 } else { 2439 } else {
2422 maxVal = QApplication::desktop()->height()-10; 2440 maxVal = QApplication::desktop()->height()-10;
2423 } 2441 }
2424 sizes << resetval; 2442 sizes << resetval;
2425 if ( maxVal < resetval + resetval) 2443 if ( maxVal < resetval + resetval)
2426 resetval = maxVal - resetval; 2444 resetval = maxVal - resetval;
2427 sizes << resetval; 2445 sizes << resetval;
2428 } 2446 }
2429 mMainFrame->setSizes(sizes); 2447 mMainFrame->setSizes(sizes);
2430 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2448 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2431 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2449 else if ( dateCount == 7 ) mNavigator->selectWeek();
2432 else mNavigator->selectDates( dateCount ); 2450 else mNavigator->selectDates( dateCount );
2433 // mViewManager->readSettings( config ); 2451 // mViewManager->readSettings( config );
2434 updateConfig(); 2452 updateConfig();
2435 globalFlagBlockAgenda = 2; 2453 globalFlagBlockAgenda = 2;
2436 mViewManager->readSettings( config ); 2454 mViewManager->readSettings( config );
2437 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2455 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2438} 2456}
2439 2457
2440void CalendarView::checkSuspendAlarm() 2458void CalendarView::checkSuspendAlarm()
2441{ 2459{
2442 if ( mSuspendTimer->isActive() ) { 2460 if ( mSuspendTimer->isActive() ) {
2443 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm")); 2461 KMessageBox::information( this, i18n("<b>WARNING:</b> There is a pending suspended alarm!"), i18n("Pending Suspend Alarm"));
2444 } 2462 }
2445} 2463}
2446void CalendarView::writeSettings() 2464void CalendarView::writeSettings()
2447{ 2465{
2448 // kdDebug() << "CalendarView::writeSettings" << endl; 2466 // kdDebug() << "CalendarView::writeSettings" << endl;
2449 2467
2450 KConfig *config = KOGlobals::config(); 2468 KConfig *config = KOGlobals::config();
2451 2469
2452 mViewManager->writeSettings( config ); 2470 mViewManager->writeSettings( config );
2453 mTodoList->saveLayout(config,QString("Todo Layout")); 2471 mTodoList->saveLayout(config,QString("Todo Layout"));
2454 mDialogManager->writeSettings( config ); 2472 mDialogManager->writeSettings( config );
2455 //KOPrefs::instance()->usrWriteConfig(); 2473 //KOPrefs::instance()->usrWriteConfig();
2456 KOPrefs::instance()->writeConfig(); 2474 KOPrefs::instance()->writeConfig();
2457 2475
2458 writeFilterSettings(config); 2476 writeFilterSettings(config);
2459 config->setGroup( "AppRun" ); 2477 config->setGroup( "AppRun" );
2460 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2478 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2461 int days = dt.daysTo( QDate::currentDate() ); 2479 int days = dt.daysTo( QDate::currentDate() );
2462 dt = dt.addDays( days ); 2480 dt = dt.addDays( days );
2463 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2481 int secs = dt.secsTo( QDateTime::currentDateTime() );
2464 config->writeEntry( "LatestProgramStopDays", days ); 2482 config->writeEntry( "LatestProgramStopDays", days );
2465 config->writeEntry( "LatestProgramStopSecs", secs ); 2483 config->writeEntry( "LatestProgramStopSecs", secs );
2466 //qDebug("KO: Writing stop time: %d ", secs); 2484 //qDebug("KO: Writing stop time: %d ", secs);
2467 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2485 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2468 //QDateTime latest = dt.addSecs ( secs ); 2486 //QDateTime latest = dt.addSecs ( secs );
2469 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2487 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2470 config->setGroup( "Views" ); 2488 config->setGroup( "Views" );
2471 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2489 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2472 2490
2473#if 0 2491#if 0
2474 qDebug("********************* "); 2492 qDebug("********************* ");
2475 qDebug("Testcode secsto "); 2493 qDebug("Testcode secsto ");
2476 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2494 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2477 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2495 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2478 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2496 int secsto = dt_nodaylight.secsTo( dt_daylight );
2479 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2497 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2480 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2498 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2481 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2499 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2482 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2500 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2483 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2501 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2484 qDebug("********************* testcode end"); 2502 qDebug("********************* testcode end");
2485 2503
2486#endif 2504#endif
2487 2505
2488 QValueList<int> listINT = mLeftFrame->sizes(); 2506 QValueList<int> listINT = mLeftFrame->sizes();
2489 config->writeEntry("Left Splitter Frame",listINT); 2507 config->writeEntry("Left Splitter Frame",listINT);
2490 QValueList<int> listINT2 = mMainFrame->sizes(); 2508 QValueList<int> listINT2 = mMainFrame->sizes();
2491 config->writeEntry("Main Splitter Frame",listINT2); 2509 config->writeEntry("Main Splitter Frame",listINT2);
2492#ifdef DESKTOP_VERSION 2510#ifdef DESKTOP_VERSION
2493 config->setGroup("WidgetLayout"); 2511 config->setGroup("WidgetLayout");
2494 QStringList list ;//= config->readListEntry("MainLayout"); 2512 QStringList list ;//= config->readListEntry("MainLayout");
2495 int x,y,w,h; 2513 int x,y,w,h;
2496 QWidget* wid; 2514 QWidget* wid;
2497 wid = topLevelWidget(); 2515 wid = topLevelWidget();
2498 x = wid->geometry().x(); 2516 x = wid->geometry().x();
2499 y = wid->geometry().y(); 2517 y = wid->geometry().y();
2500 w = wid->width(); 2518 w = wid->width();
2501 h = wid->height(); 2519 h = wid->height();
2502 list.clear(); 2520 list.clear();
2503 list << QString::number( x ); 2521 list << QString::number( x );
2504 list << QString::number( y ); 2522 list << QString::number( y );
2505 list << QString::number( w ); 2523 list << QString::number( w );
2506 list << QString::number( h ); 2524 list << QString::number( h );
2507 config->writeEntry("MainLayout",list ); 2525 config->writeEntry("MainLayout",list );
2508 2526
2509 wid = mEventEditor; 2527 wid = mEventEditor;
2510 x = wid->geometry().x(); 2528 x = wid->geometry().x();
2511 y = wid->geometry().y(); 2529 y = wid->geometry().y();
2512 w = wid->width(); 2530 w = wid->width();
2513 h = wid->height(); 2531 h = wid->height();
2514 list.clear(); 2532 list.clear();
2515 list << QString::number( x ); 2533 list << QString::number( x );
2516 list << QString::number( y ); 2534 list << QString::number( y );
2517 list << QString::number( w ); 2535 list << QString::number( w );
2518 list << QString::number( h ); 2536 list << QString::number( h );
2519 config->writeEntry("EditEventLayout",list ); 2537 config->writeEntry("EditEventLayout",list );
2520 2538
2521 wid = mTodoEditor; 2539 wid = mTodoEditor;
2522 x = wid->geometry().x(); 2540 x = wid->geometry().x();
2523 y = wid->geometry().y(); 2541 y = wid->geometry().y();
2524 w = wid->width(); 2542 w = wid->width();
2525 h = wid->height(); 2543 h = wid->height();
2526 list.clear(); 2544 list.clear();
2527 list << QString::number( x ); 2545 list << QString::number( x );
2528 list << QString::number( y ); 2546 list << QString::number( y );
2529 list << QString::number( w ); 2547 list << QString::number( w );
2530 list << QString::number( h ); 2548 list << QString::number( h );
2531 config->writeEntry("EditTodoLayout",list ); 2549 config->writeEntry("EditTodoLayout",list );
2532 wid = getEventViewerDialog(); 2550 wid = getEventViewerDialog();
2533 x = wid->geometry().x(); 2551 x = wid->geometry().x();
2534 y = wid->geometry().y(); 2552 y = wid->geometry().y();
2535 w = wid->width(); 2553 w = wid->width();
2536 h = wid->height(); 2554 h = wid->height();
2537 list.clear(); 2555 list.clear();
2538 list << QString::number( x ); 2556 list << QString::number( x );
2539 list << QString::number( y ); 2557 list << QString::number( y );
2540 list << QString::number( w ); 2558 list << QString::number( w );
2541 list << QString::number( h ); 2559 list << QString::number( h );
2542 config->writeEntry("ViewerLayout",list ); 2560 config->writeEntry("ViewerLayout",list );
2543 wid = mDialogManager->getSearchDialog(); 2561 wid = mDialogManager->getSearchDialog();
2544 if ( wid ) { 2562 if ( wid ) {
2545 x = wid->geometry().x(); 2563 x = wid->geometry().x();
2546 y = wid->geometry().y(); 2564 y = wid->geometry().y();
2547 w = wid->width(); 2565 w = wid->width();
2548 h = wid->height(); 2566 h = wid->height();
2549 list.clear(); 2567 list.clear();
2550 list << QString::number( x ); 2568 list << QString::number( x );
2551 list << QString::number( y ); 2569 list << QString::number( y );
2552 list << QString::number( w ); 2570 list << QString::number( w );
2553 list << QString::number( h ); 2571 list << QString::number( h );
2554 config->writeEntry("SearchLayout",list ); 2572 config->writeEntry("SearchLayout",list );
2555 } 2573 }
2556#endif 2574#endif
2557 2575
2558 2576
2559 config->sync(); 2577 config->sync();
2560} 2578}
2561 2579
2562void CalendarView::readFilterSettings(KConfig *config) 2580void CalendarView::readFilterSettings(KConfig *config)
2563{ 2581{
2564 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2582 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2565 2583
2566 mFilters.clear(); 2584 mFilters.clear();
2567 2585
2568 config->setGroup("General"); 2586 config->setGroup("General");
2569 QStringList filterList = config->readListEntry("CalendarFilters"); 2587 QStringList filterList = config->readListEntry("CalendarFilters");
2570 2588
2571 QStringList::ConstIterator it = filterList.begin(); 2589 QStringList::ConstIterator it = filterList.begin();
2572 QStringList::ConstIterator end = filterList.end(); 2590 QStringList::ConstIterator end = filterList.end();
2573 while(it != end) { 2591 while(it != end) {
2574 // kdDebug() << " filter: " << (*it) << endl; 2592 // kdDebug() << " filter: " << (*it) << endl;
2575 2593
2576 CalFilter *filter; 2594 CalFilter *filter;
2577 filter = new CalFilter(*it); 2595 filter = new CalFilter(*it);
2578 config->setGroup("Filter_" + (*it).utf8()); 2596 config->setGroup("Filter_" + (*it).utf8());
2579 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2597 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2580 filter->setCriteria(config->readNumEntry("Criteria",0)); 2598 filter->setCriteria(config->readNumEntry("Criteria",0));
2581 filter->setCategoryList(config->readListEntry("CategoryList")); 2599 filter->setCategoryList(config->readListEntry("CategoryList"));
2582 mFilters.append(filter); 2600 mFilters.append(filter);
2583 2601
2584 ++it; 2602 ++it;
2585 } 2603 }
2586 2604
2587 if (mFilters.count() == 0) { 2605 if (mFilters.count() == 0) {
2588 CalFilter *filter = new CalFilter(i18n("Default")); 2606 CalFilter *filter = new CalFilter(i18n("Default"));
2589 mFilters.append(filter); 2607 mFilters.append(filter);
2590 } 2608 }
2591 mFilterView->updateFilters(); 2609 mFilterView->updateFilters();
2592 config->setGroup("FilterView"); 2610 config->setGroup("FilterView");
2593 2611
2594 mFilterView->blockSignals(true); 2612 mFilterView->blockSignals(true);
2595 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2613 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2596 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2614 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2597 mFilterView->blockSignals(false); 2615 mFilterView->blockSignals(false);
2598 // We do it manually to avoid it being done twice by the above calls 2616 // We do it manually to avoid it being done twice by the above calls
2599 updateFilter(); 2617 updateFilter();
2600} 2618}
2601 2619
2602void CalendarView::writeFilterSettings(KConfig *config) 2620void CalendarView::writeFilterSettings(KConfig *config)
2603{ 2621{
2604 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2622 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2605 2623
2606 QStringList filterList; 2624 QStringList filterList;
2607 2625
2608 CalFilter *filter = mFilters.first(); 2626 CalFilter *filter = mFilters.first();
2609 while(filter) { 2627 while(filter) {
2610 // kdDebug() << " fn: " << filter->name() << endl; 2628 // kdDebug() << " fn: " << filter->name() << endl;
2611 filterList << filter->name(); 2629 filterList << filter->name();
2612 config->setGroup("Filter_" + filter->name().utf8()); 2630 config->setGroup("Filter_" + filter->name().utf8());
2613 config->writeEntry("Criteria",filter->criteria()); 2631 config->writeEntry("Criteria",filter->criteria());
2614 config->writeEntry("CategoryList",filter->categoryList()); 2632 config->writeEntry("CategoryList",filter->categoryList());
2615 filter = mFilters.next(); 2633 filter = mFilters.next();
2616 } 2634 }
2617 config->setGroup("General"); 2635 config->setGroup("General");
2618 config->writeEntry("CalendarFilters",filterList); 2636 config->writeEntry("CalendarFilters",filterList);
2619 2637
2620 config->setGroup("FilterView"); 2638 config->setGroup("FilterView");
2621 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2639 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2622 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2640 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2623} 2641}
2624 2642
2625 2643
2626void CalendarView::goToday() 2644void CalendarView::goToday()
2627{ 2645{
2628 if ( mViewManager->currentView()->isMonthView() ) 2646 if ( mViewManager->currentView()->isMonthView() )
2629 mNavigator->selectTodayMonth(); 2647 mNavigator->selectTodayMonth();
2630 else 2648 else
2631 mNavigator->selectToday(); 2649 mNavigator->selectToday();
2632} 2650}
2633 2651
2634void CalendarView::goNext() 2652void CalendarView::goNext()
2635{ 2653{
2636 mNavigator->selectNext(); 2654 mNavigator->selectNext();
2637} 2655}
2638 2656
2639void CalendarView::goPrevious() 2657void CalendarView::goPrevious()
2640{ 2658{
2641 mNavigator->selectPrevious(); 2659 mNavigator->selectPrevious();
2642} 2660}
2643void CalendarView::goNextMonth() 2661void CalendarView::goNextMonth()
2644{ 2662{
2645 mNavigator->selectNextMonth(); 2663 mNavigator->selectNextMonth();
2646} 2664}
2647 2665
2648void CalendarView::goPreviousMonth() 2666void CalendarView::goPreviousMonth()
2649{ 2667{
2650 mNavigator->selectPreviousMonth(); 2668 mNavigator->selectPreviousMonth();
2651} 2669}
2652 2670
2653void CalendarView::updateConfig() 2671void CalendarView::updateConfig()
2654{ 2672{
2655 if ( KOPrefs::instance()->mUseAppColors ) 2673 if ( KOPrefs::instance()->mUseAppColors )
2656 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2674 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2657 emit configChanged(); 2675 emit configChanged();
2658 mTodoList->updateConfig(); 2676 mTodoList->updateConfig();
2659 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2677 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2660 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2678 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2661 // To make the "fill window" configurations work 2679 // To make the "fill window" configurations work
2662 //mViewManager->raiseCurrentView(); 2680 //mViewManager->raiseCurrentView();
2663} 2681}
2664 2682
2665 2683
2666void CalendarView::eventChanged(Event *event) 2684void CalendarView::eventChanged(Event *event)
2667{ 2685{
2668 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2686 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2669 //updateUnmanagedViews(); 2687 //updateUnmanagedViews();
2670} 2688}
2671 2689
2672void CalendarView::eventAdded(Event *event) 2690void CalendarView::eventAdded(Event *event)
2673{ 2691{
2674 changeEventDisplay(event,KOGlobals::EVENTADDED); 2692 changeEventDisplay(event,KOGlobals::EVENTADDED);
2675} 2693}
2676 2694
2677void CalendarView::eventToBeDeleted(Event *) 2695void CalendarView::eventToBeDeleted(Event *)
2678{ 2696{
2679 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2697 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2680} 2698}
2681 2699
2682void CalendarView::eventDeleted() 2700void CalendarView::eventDeleted()
2683{ 2701{
2684 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2702 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2685} 2703}
2686void CalendarView::changeTodoDisplay(Todo *which, int action) 2704void CalendarView::changeTodoDisplay(Todo *which, int action)
2687{ 2705{
2688 changeIncidenceDisplay((Incidence *)which, action); 2706 changeIncidenceDisplay((Incidence *)which, action);
2689 mDateNavigator->updateView(); //LR 2707 mDateNavigator->updateView(); //LR
2690 //mDialogManager->updateSearchDialog(); 2708 //mDialogManager->updateSearchDialog();
2691 2709
2692 if (which) { 2710 if (which) {
2693 mViewManager->updateWNview(); 2711 mViewManager->updateWNview();
2694 //mTodoList->updateView(); 2712 //mTodoList->updateView();
2695 } 2713 }
2696 2714
2697} 2715}
2698 2716
2699void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2717void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2700{ 2718{
2701 updateUnmanagedViews(); 2719 updateUnmanagedViews();
2702 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2720 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2703 if ( action == KOGlobals::EVENTDELETED ) { //delete 2721 if ( action == KOGlobals::EVENTDELETED ) { //delete
2704 mCalendar->checkAlarmForIncidence( 0, true ); 2722 mCalendar->checkAlarmForIncidence( 0, true );
2705 if ( mEventViewerDialog ) 2723 if ( mEventViewerDialog )
2706 mEventViewerDialog->hide(); 2724 mEventViewerDialog->hide();
2707 } 2725 }
2708 else 2726 else
2709 mCalendar->checkAlarmForIncidence( which , false ); 2727 mCalendar->checkAlarmForIncidence( which , false );
2710} 2728}
2711 2729
2712// most of the changeEventDisplays() right now just call the view's 2730// most of the changeEventDisplays() right now just call the view's
2713// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2731// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2714void CalendarView::changeEventDisplay(Event *which, int action) 2732void CalendarView::changeEventDisplay(Event *which, int action)
2715{ 2733{
2716 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2734 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2717 changeIncidenceDisplay((Incidence *)which, action); 2735 changeIncidenceDisplay((Incidence *)which, action);
2718 static bool clearallviews = false; 2736 static bool clearallviews = false;
2719 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2737 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2720 if ( clearallviews ) { 2738 if ( clearallviews ) {
2721 clearAllViews(); 2739 clearAllViews();
2722 clearallviews = false; 2740 clearallviews = false;
2723 } 2741 }
2724 return; 2742 return;
2725 } 2743 }
2726 clearallviews = true; 2744 clearallviews = true;
2727 mDateNavigator->updateView(); 2745 mDateNavigator->updateView();
2728 //mDialogManager->updateSearchDialog(); 2746 //mDialogManager->updateSearchDialog();
2729 if (which) { 2747 if (which) {
2730 // If there is an event view visible update the display 2748 // If there is an event view visible update the display
2731 mViewManager->currentView()->changeEventDisplay(which,action); 2749 mViewManager->currentView()->changeEventDisplay(which,action);
2732 // TODO: check, if update needed 2750 // TODO: check, if update needed
2733 // if (which->getTodoStatus()) { 2751 // if (which->getTodoStatus()) {
2734 mTodoList->updateView(); 2752 mTodoList->updateView();
2735 if ( action != KOGlobals::EVENTDELETED ) { 2753 if ( action != KOGlobals::EVENTDELETED ) {
2736 mConflictingEvent = which ; 2754 mConflictingEvent = which ;
2737 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) ); 2755 QTimer::singleShot( 1000, this, SLOT ( checkConflictForEvent() ) );
2738 } 2756 }
2739 // } 2757 // }
2740 } else { 2758 } else {
2741 mViewManager->currentView()->updateView(); 2759 mViewManager->currentView()->updateView();
2742 } 2760 }
2743} 2761}
2744void CalendarView::checkConflictForEvent() 2762void CalendarView::checkConflictForEvent()
2745{ 2763{
2746 2764
2747 if (!KOPrefs::instance()->mConfirm) 2765 if (!KOPrefs::instance()->mConfirm)
2748 return; 2766 return;
2749 if ( ! mConflictingEvent ) return; 2767 if ( ! mConflictingEvent ) return;
2750 if ( mConflictingEvent->isHoliday() || mConflictingEvent->isBirthday() || mConflictingEvent->isAnniversary() ) { 2768 if ( mConflictingEvent->isHoliday() || mConflictingEvent->isBirthday() || mConflictingEvent->isAnniversary() ) {
2751 mConflictingEvent = 0; 2769 mConflictingEvent = 0;
2752 return; 2770 return;
2753 } 2771 }
2754 QPtrList<Event> testlist = mCalendar->events(); 2772 QPtrList<Event> testlist = mCalendar->events();
2755 Event * test = testlist.first(); 2773 Event * test = testlist.first();
2756 QDateTime conflict; 2774 QDateTime conflict;
2757 QDateTime retVal; 2775 QDateTime retVal;
2758 bool found = false; 2776 bool found = false;
2759 Event * cE = 0; 2777 Event * cE = 0;
2760 QDateTime current = QDateTime::currentDateTime(); 2778 QDateTime current = QDateTime::currentDateTime();
2761 while ( test ) { 2779 while ( test ) {
2762 if ( !test->doesFloat() ) { 2780 if ( !test->doesFloat() ) {
2763 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) { 2781 if ( mConflictingEvent->isOverlapping ( test, &retVal, &current ) ) {
2764 if ( ! found ) { 2782 if ( ! found ) {
2765 conflict = retVal; 2783 conflict = retVal;
2766 cE = test; 2784 cE = test;
2767 } else { 2785 } else {
2768 if ( retVal < conflict ) { 2786 if ( retVal < conflict ) {
2769 conflict = retVal; 2787 conflict = retVal;
2770 cE = test; 2788 cE = test;
2771 } 2789 }
2772 } 2790 }
2773 found = true; 2791 found = true;
2774 } 2792 }
2775 } 2793 }
2776 test = testlist.next(); 2794 test = testlist.next();
2777 } 2795 }
2778 if ( found ) { 2796 if ( found ) {
2779 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()) ) ; 2797 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()) ) ;
2780 qApp->processEvents(); 2798 qApp->processEvents();
2781 int km = KMessageBox::warningContinueCancel(this,mess, 2799 int km = KMessageBox::warningContinueCancel(this,mess,
2782 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!")); 2800 i18n("KO/Pi Conflict delected"),i18n("Show date"),i18n("No problem!"));
2783 if ( km != KMessageBox::Continue ) 2801 if ( km != KMessageBox::Continue )
2784 return; 2802 return;
2785 2803
2786 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 ) 2804 if ( mViewManager->currentView() != mViewManager->agendaView() || mNavigator->selectedDates().count() > 1 )
2787 mViewManager->showDayView(); 2805 mViewManager->showDayView();
2788 mNavigator->slotDaySelect( conflict.date() ); 2806 mNavigator->slotDaySelect( conflict.date() );
2789 int hour = conflict.time().hour(); 2807 int hour = conflict.time().hour();
2790 mViewManager->agendaView()->setStartHour( hour ); 2808 mViewManager->agendaView()->setStartHour( hour );
2791 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) ); 2809 topLevelWidget()->setCaption( i18n("Conflict %1 <-> %2"). arg( mConflictingEvent->summary().left( 20 ) ).arg( cE->summary().left( 20 ) ) );
2792 } 2810 }
2793 mConflictingEvent = 0; 2811 mConflictingEvent = 0;
2794 return; 2812 return;
2795 2813
2796} 2814}
2797 2815
2798void CalendarView::updateTodoViews() 2816void CalendarView::updateTodoViews()
2799{ 2817{
2800 mTodoList->updateView(); 2818 mTodoList->updateView();
2801 mViewManager->currentView()->updateView(); 2819 mViewManager->currentView()->updateView();
2802 2820
2803} 2821}
2804 2822
2805 2823
2806 2824
2807void CalendarView::clearAllViews() 2825void CalendarView::clearAllViews()
2808{ 2826{
2809 mTodoList->clearList(); 2827 mTodoList->clearList();
2810 mViewManager->clearAllViews(); 2828 mViewManager->clearAllViews();
2811 SearchDialog * sd = mDialogManager->getSearchDialog(); 2829 SearchDialog * sd = mDialogManager->getSearchDialog();
2812 if ( sd ) { 2830 if ( sd ) {
2813 KOListView* kol = sd->listview(); 2831 KOListView* kol = sd->listview();
2814 if ( kol ) 2832 if ( kol )
2815 kol->clearList(); 2833 kol->clearList();
2816 } 2834 }
2817} 2835}
2818void CalendarView::updateView() 2836void CalendarView::updateView()
2819{ 2837{
2820 static bool clearallviews = false; 2838 static bool clearallviews = false;
2821 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) { 2839 if ( KOPrefs::instance()->mGlobalUpdateDisabled ) {
2822 if ( clearallviews ) { 2840 if ( clearallviews ) {
2823 clearAllViews(); 2841 clearAllViews();
2824 clearallviews = false; 2842 clearallviews = false;
2825 } 2843 }
2826 return; 2844 return;
2827 } 2845 }
2828 clearallviews = true; 2846 clearallviews = true;
2829 DateList tmpList = mNavigator->selectedDates(); 2847 DateList tmpList = mNavigator->selectedDates();
2830 2848
2831 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2849 if ( KOPrefs::instance()->mHideNonStartedTodos )
2832 mTodoList->updateView(); 2850 mTodoList->updateView();
2833 // We assume that the navigator only selects consecutive days. 2851 // We assume that the navigator only selects consecutive days.
2834 updateView( tmpList.first(), tmpList.last() ); 2852 updateView( tmpList.first(), tmpList.last() );
2835} 2853}
2836 2854
2837void CalendarView::updateUnmanagedViews() 2855void CalendarView::updateUnmanagedViews()
2838{ 2856{
2839 mDateNavigator->updateDayMatrix(); 2857 mDateNavigator->updateDayMatrix();
2840} 2858}
2841 2859
2842int CalendarView::msgItemDelete(const QString name) 2860int CalendarView::msgItemDelete(const QString name)
2843{ 2861{
2844 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2862 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2845 i18n("This item will be\npermanently deleted."), 2863 i18n("This item will be\npermanently deleted."),
2846 i18n("KO/Pi Confirmation"),i18n("Delete")); 2864 i18n("KO/Pi Confirmation"),i18n("Delete"));
2847} 2865}
2848 2866
2849 2867
2850void CalendarView::edit_cut() 2868void CalendarView::edit_cut()
2851{ 2869{
2852 Event *anEvent=0; 2870 Event *anEvent=0;
2853 2871
2854 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2872 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2855 2873
2856 if (mViewManager->currentView()->isEventView()) { 2874 if (mViewManager->currentView()->isEventView()) {
2857 if ( incidence && incidence->typeID() == eventID ) { 2875 if ( incidence && incidence->typeID() == eventID ) {
2858 anEvent = static_cast<Event *>(incidence); 2876 anEvent = static_cast<Event *>(incidence);
2859 } 2877 }
2860 } 2878 }
2861 2879
2862 if (!anEvent) { 2880 if (!anEvent) {
2863 KNotifyClient::beep(); 2881 KNotifyClient::beep();
2864 return; 2882 return;
2865 } 2883 }
2866 DndFactory factory( mCalendar ); 2884 DndFactory factory( mCalendar );
2867 factory.cutIncidence(anEvent); 2885 factory.cutIncidence(anEvent);
2868 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2886 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2869} 2887}
2870 2888
2871void CalendarView::edit_copy() 2889void CalendarView::edit_copy()
2872{ 2890{
2873 Event *anEvent=0; 2891 Event *anEvent=0;
2874 2892
2875 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2893 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2876 2894
2877 if (mViewManager->currentView()->isEventView()) { 2895 if (mViewManager->currentView()->isEventView()) {
2878 if ( incidence && incidence->typeID() == eventID ) { 2896 if ( incidence && incidence->typeID() == eventID ) {
2879 anEvent = static_cast<Event *>(incidence); 2897 anEvent = static_cast<Event *>(incidence);
2880 } 2898 }
2881 } 2899 }
2882 2900
2883 if (!anEvent) { 2901 if (!anEvent) {
2884 KNotifyClient::beep(); 2902 KNotifyClient::beep();
2885 return; 2903 return;
2886 } 2904 }
2887 DndFactory factory( mCalendar ); 2905 DndFactory factory( mCalendar );
2888 factory.copyIncidence(anEvent); 2906 factory.copyIncidence(anEvent);
2889} 2907}
2890 2908
2891void CalendarView::edit_paste() 2909void CalendarView::edit_paste()
2892{ 2910{
2893 QDate date = mNavigator->selectedDates().first(); 2911 QDate date = mNavigator->selectedDates().first();
2894 2912
2895 DndFactory factory( mCalendar ); 2913 DndFactory factory( mCalendar );
2896 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2914 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2897 2915
2898 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2916 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2899} 2917}
2900void CalendarView::edit_global_options() 2918void CalendarView::edit_global_options()
2901{ 2919{
2902 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2920 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2903 emit save(); 2921 emit save();
2904 emit saveStopTimer(); 2922 emit saveStopTimer();
2905 mDialogManager->showGlobalOptionsDialog(); 2923 mDialogManager->showGlobalOptionsDialog();
2906 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2924 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2907 emit saveStopTimer(); 2925 emit saveStopTimer();
2908 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2926 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto shift the time of the events?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2909 i18n("Timezone settings"),i18n("Reload"))) { 2927 i18n("Timezone settings"),i18n("Reload"))) {
2910 qDebug("KO: TZ reload cancelled "); 2928 qDebug("KO: TZ reload cancelled ");
2911 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2929 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2912 return; 2930 return;
2913 } 2931 }
2914 qDebug("KO: Timezone change "); 2932 qDebug("KO: Timezone change ");
2915 loadCalendars(); 2933 loadCalendars();
2916 setModified(true); 2934 setModified(true);
2917 } 2935 }
2918 else 2936 else
2919 qDebug("KO: No tz change "); 2937 qDebug("KO: No tz change ");
2920} 2938}
2921void CalendarView::edit_options() 2939void CalendarView::edit_options()
2922{ 2940{
2923 mDialogManager->showOptionsDialog(); 2941 mDialogManager->showOptionsDialog();
2924} 2942}
2925 2943
2926 2944
2927void CalendarView::slotSelectPickerDate( QDate d) 2945void CalendarView::slotSelectPickerDate( QDate d)
2928{ 2946{
2929 mDateFrame->hide(); 2947 mDateFrame->hide();
2930 if ( mDatePickerMode == 1 ) { 2948 if ( mDatePickerMode == 1 ) {
2931 mNavigator->slotDaySelect( d ); 2949 mNavigator->slotDaySelect( d );
2932 } else if ( mDatePickerMode == 2 ) { 2950 } else if ( mDatePickerMode == 2 ) {
2933 if ( mMoveIncidence->typeID() == todoID ) { 2951 if ( mMoveIncidence->typeID() == todoID ) {
2934 Todo * to = (Todo *) mMoveIncidence; 2952 Todo * to = (Todo *) mMoveIncidence;
2935 QTime tim; 2953 QTime tim;
2936 int len = 0; 2954 int len = 0;
2937 if ( to->hasStartDate() && to->hasDueDate() ) 2955 if ( to->hasStartDate() && to->hasDueDate() )
2938 len = to->dtStart().secsTo( to->dtDue()); 2956 len = to->dtStart().secsTo( to->dtDue());
2939 if ( to->hasDueDate() ) 2957 if ( to->hasDueDate() )
2940 tim = to->dtDue().time(); 2958 tim = to->dtDue().time();
2941 else { 2959 else {
2942 tim = QTime ( 0,0,0 ); 2960 tim = QTime ( 0,0,0 );
2943 to->setFloats( true ); 2961 to->setFloats( true );
2944 to->setHasDueDate( true ); 2962 to->setHasDueDate( true );
2945 } 2963 }
2946 QDateTime dt ( d,tim ); 2964 QDateTime dt ( d,tim );
2947 to->setDtDue( dt ); 2965 to->setDtDue( dt );
2948 2966
2949 if ( to->hasStartDate() ) { 2967 if ( to->hasStartDate() ) {
2950 if ( len>0 ) 2968 if ( len>0 )
2951 to->setDtStart(to->dtDue().addSecs( -len )); 2969 to->setDtStart(to->dtDue().addSecs( -len ));
2952 else 2970 else
2953 if (to->dtStart() > to->dtDue() ) 2971 if (to->dtStart() > to->dtDue() )
2954 to->setDtStart(to->dtDue().addDays( -3 )); 2972 to->setDtStart(to->dtDue().addDays( -3 ));
2955 } 2973 }
2956 2974
2957 todoChanged( to ); 2975 todoChanged( to );
2958 } else if ( mMoveIncidence->typeID() == eventID ) { 2976 } else if ( mMoveIncidence->typeID() == eventID ) {
2959 if ( mMoveIncidence->doesRecur() ) { 2977 if ( mMoveIncidence->doesRecur() ) {
2960#if 0 2978#if 0
2961 // PENDING implement this 2979 // PENDING implement this
2962 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2980 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2963 mCalendar()->addIncidence( newInc ); 2981 mCalendar()->addIncidence( newInc );
2964 if ( mMoveIncidence->typeID() == todoID ) 2982 if ( mMoveIncidence->typeID() == todoID )
2965 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2983 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2966 else 2984 else
2967 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2985 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2968 mMoveIncidence = newInc; 2986 mMoveIncidence = newInc;
2969 2987
2970#endif 2988#endif
2971 } 2989 }
2972 QTime tim = mMoveIncidence->dtStart().time(); 2990 QTime tim = mMoveIncidence->dtStart().time();
2973 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2991 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2974 QDateTime dt ( d,tim ); 2992 QDateTime dt ( d,tim );
2975 mMoveIncidence->setDtStart( dt ); 2993 mMoveIncidence->setDtStart( dt );
2976 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2994 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2977 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2995 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2978 } else if ( mMoveIncidence->typeID() == journalID ) { 2996 } else if ( mMoveIncidence->typeID() == journalID ) {
2979 QTime tim = mMoveIncidence->dtStart().time(); 2997 QTime tim = mMoveIncidence->dtStart().time();
2980 QDateTime dt ( d,tim ); 2998 QDateTime dt ( d,tim );
2981 mMoveIncidence->setDtStart( dt ); 2999 mMoveIncidence->setDtStart( dt );
2982 updateView(); 3000 updateView();
2983 } 3001 }
2984 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 3002 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2985 } 3003 }
2986} 3004}
2987 3005
2988void CalendarView::removeCategories() 3006void CalendarView::removeCategories()
2989{ 3007{
2990 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3008 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2991 QStringList catList = KOPrefs::instance()->mCustomCategories; 3009 QStringList catList = KOPrefs::instance()->mCustomCategories;
2992 QStringList catIncList; 3010 QStringList catIncList;
2993 QStringList newCatList; 3011 QStringList newCatList;
2994 Incidence* inc = incList.first(); 3012 Incidence* inc = incList.first();
2995 uint i; 3013 uint i;
2996 while ( inc ) { 3014 while ( inc ) {
2997 newCatList.clear(); 3015 newCatList.clear();
2998 catIncList = inc->categories() ; 3016 catIncList = inc->categories() ;
2999 for( i = 0; i< catIncList.count(); ++i ) { 3017 for( i = 0; i< catIncList.count(); ++i ) {
3000 if ( catList.contains (catIncList[i])) 3018 if ( catList.contains (catIncList[i]))
3001 newCatList.append( catIncList[i] ); 3019 newCatList.append( catIncList[i] );
3002 } 3020 }
3003 newCatList.sort(); 3021 newCatList.sort();
3004 inc->setCategories( newCatList.join(",") ); 3022 inc->setCategories( newCatList.join(",") );
3005 inc = incList.next(); 3023 inc = incList.next();
3006 } 3024 }
3007} 3025}
3008 3026
3009int CalendarView::addCategories() 3027int CalendarView::addCategories()
3010{ 3028{
3011 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 3029 QPtrList<Incidence> incList = mCalendar->rawIncidences();
3012 QStringList catList = KOPrefs::instance()->mCustomCategories; 3030 QStringList catList = KOPrefs::instance()->mCustomCategories;
3013 QStringList catIncList; 3031 QStringList catIncList;
3014 Incidence* inc = incList.first(); 3032 Incidence* inc = incList.first();
3015 uint i; 3033 uint i;
3016 int count = 0; 3034 int count = 0;
3017 while ( inc ) { 3035 while ( inc ) {
3018 catIncList = inc->categories() ; 3036 catIncList = inc->categories() ;
3019 for( i = 0; i< catIncList.count(); ++i ) { 3037 for( i = 0; i< catIncList.count(); ++i ) {
3020 if ( !catList.contains (catIncList[i])) { 3038 if ( !catList.contains (catIncList[i])) {
3021 catList.append( catIncList[i] ); 3039 catList.append( catIncList[i] );
3022 //qDebug("add cat %s ", catIncList[i].latin1()); 3040 //qDebug("add cat %s ", catIncList[i].latin1());
3023 ++count; 3041 ++count;
3024 } 3042 }
3025 } 3043 }
3026 inc = incList.next(); 3044 inc = incList.next();
3027 } 3045 }
3028 catList.sort(); 3046 catList.sort();
3029 KOPrefs::instance()->mCustomCategories = catList; 3047 KOPrefs::instance()->mCustomCategories = catList;
3030 return count; 3048 return count;
3031} 3049}
3032 3050
3033void CalendarView::editCategories() 3051void CalendarView::editCategories()
3034{ 3052{
3035 qDebug("CalendarView::editCategories() "); 3053 qDebug("CalendarView::editCategories() ");
3036 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this ); 3054 KPIM::CategoryEditDialog ced (KOPrefs::instance(),this );
3037 ced.exec(); 3055 ced.exec();
3038} 3056}
3039void CalendarView::manageCategories() 3057void CalendarView::manageCategories()
3040{ 3058{
3041 KOCatPrefs* cp = new KOCatPrefs(); 3059 KOCatPrefs* cp = new KOCatPrefs();
3042 cp->show(); 3060 cp->show();
3043 int w =cp->sizeHint().width() ; 3061 int w =cp->sizeHint().width() ;
3044 int h = cp->sizeHint().height() ; 3062 int h = cp->sizeHint().height() ;
3045 int dw = QApplication::desktop()->width(); 3063 int dw = QApplication::desktop()->width();
3046 int dh = QApplication::desktop()->height(); 3064 int dh = QApplication::desktop()->height();
3047 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 3065 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
3048 if ( !cp->exec() ) { 3066 if ( !cp->exec() ) {
3049 delete cp; 3067 delete cp;
3050 return; 3068 return;
3051 } 3069 }
3052 int count = 0; 3070 int count = 0;
3053 if ( cp->addCat() ) { 3071 if ( cp->addCat() ) {
3054 count = addCategories(); 3072 count = addCategories();
3055 if ( count ) { 3073 if ( count ) {
3056 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 3074 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
3057 writeSettings(); 3075 writeSettings();
3058 } else 3076 } else
3059 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 3077 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
3060 } else { 3078 } else {
3061 removeCategories(); 3079 removeCategories();
3062 updateView(); 3080 updateView();
3063 } 3081 }
3064 delete cp; 3082 delete cp;
3065} 3083}
3066 3084
3067void CalendarView::beamIncidence(Incidence * Inc) 3085void CalendarView::beamIncidence(Incidence * Inc)
3068{ 3086{
3069 QPtrList<Incidence> delSel ; 3087 QPtrList<Incidence> delSel ;
3070 delSel.append(Inc); 3088 delSel.append(Inc);
3071 beamIncidenceList( delSel ); 3089 beamIncidenceList( delSel );
3072} 3090}
3073void CalendarView::beamCalendar() 3091void CalendarView::beamCalendar()
3074{ 3092{
3075 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 3093 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
3076 //qDebug("beamCalendar() "); 3094 //qDebug("beamCalendar() ");
3077 beamIncidenceList( delSel ); 3095 beamIncidenceList( delSel );
3078} 3096}
3079void CalendarView::beamFilteredCalendar() 3097void CalendarView::beamFilteredCalendar()
3080{ 3098{
3081 QPtrList<Incidence> delSel = mCalendar->incidences(); 3099 QPtrList<Incidence> delSel = mCalendar->incidences();
3082 //qDebug("beamFilteredCalendar() "); 3100 //qDebug("beamFilteredCalendar() ");
3083 beamIncidenceList( delSel ); 3101 beamIncidenceList( delSel );
3084} 3102}
3085void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 3103void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
3086{ 3104{
3087 3105
3088 KOBeamPrefs beamDialog; 3106 KOBeamPrefs beamDialog;
3089 if ( beamDialog.exec () == QDialog::Rejected ) 3107 if ( beamDialog.exec () == QDialog::Rejected )
3090 return; 3108 return;
3091#ifdef DESKTOP_VERSION 3109#ifdef DESKTOP_VERSION
3092 QString fn = locateLocal( "tmp", "kopibeamfile" ); 3110 QString fn = locateLocal( "tmp", "kopibeamfile" );
3093#else 3111#else
3094 QString fn = "/tmp/kopibeamfile"; 3112 QString fn = "/tmp/kopibeamfile";
3095#endif 3113#endif
3096 QString mes; 3114 QString mes;
3097 bool createbup = true; 3115 bool createbup = true;
3098 if ( createbup ) { 3116 if ( createbup ) {
3099 QString description = "\n"; 3117 QString description = "\n";
3100 CalendarLocal* cal = new CalendarLocal(); 3118 CalendarLocal* cal = new CalendarLocal();
3101 if ( beamDialog.beamLocal() ) 3119 if ( beamDialog.beamLocal() )
3102 cal->setLocalTime(); 3120 cal->setLocalTime();
3103 else 3121 else
3104 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 3122 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
3105 Incidence *incidence = delSel.first(); 3123 Incidence *incidence = delSel.first();
3106 bool addText = false; 3124 bool addText = false;
3107 if ( delSel.count() < 10 ) 3125 if ( delSel.count() < 10 )
3108 addText = true; 3126 addText = true;
3109 else { 3127 else {
3110 description.sprintf(i18n(" %d items?"),delSel.count() ); 3128 description.sprintf(i18n(" %d items?"),delSel.count() );
3111 } 3129 }
3112 while ( incidence ) { 3130 while ( incidence ) {
3113 Incidence *in = incidence->clone(); 3131 Incidence *in = incidence->clone();
3114 if ( ! in->summary().isEmpty() ) { 3132 if ( ! in->summary().isEmpty() ) {
3115 in->setDescription(""); 3133 in->setDescription("");
3116 } else { 3134 } else {
3117 in->setSummary( in->description().left(20)); 3135 in->setSummary( in->description().left(20));
3118 in->setDescription(""); 3136 in->setDescription("");
3119 } 3137 }
3120 if ( addText ) 3138 if ( addText )
3121 description += in->summary() + "\n"; 3139 description += in->summary() + "\n";
3122 cal->addIncidence( in ); 3140 cal->addIncidence( in );
3123 incidence = delSel.next(); 3141 incidence = delSel.next();
3124 } 3142 }
3125 if ( beamDialog.beamVcal() ) { 3143 if ( beamDialog.beamVcal() ) {
3126 fn += ".vcs"; 3144 fn += ".vcs";
3127 FileStorage storage( cal, fn, new VCalFormat ); 3145 FileStorage storage( cal, fn, new VCalFormat );
3128 storage.save(); 3146 storage.save();
3129 } else { 3147 } else {
3130 fn += ".ics"; 3148 fn += ".ics";
3131 FileStorage storage( cal, fn, new ICalFormat( ) ); 3149 FileStorage storage( cal, fn, new ICalFormat( ) );
3132 storage.save(); 3150 storage.save();
3133 } 3151 }
3134 delete cal; 3152 delete cal;
3135 mes = i18n("KO/Pi: Ready for beaming"); 3153 mes = i18n("KO/Pi: Ready for beaming");
3136 topLevelWidget()->setCaption(mes); 3154 topLevelWidget()->setCaption(mes);
3137 KApplication::convert2latin1( fn ); 3155 KApplication::convert2latin1( fn );
3138#ifndef DESKTOP_VERSION 3156#ifndef DESKTOP_VERSION
3139 Ir *ir = new Ir( this ); 3157 Ir *ir = new Ir( this );
3140 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 3158 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
3141 ir->send( fn, description, "text/x-vCalendar" ); 3159 ir->send( fn, description, "text/x-vCalendar" );
3142#endif 3160#endif
3143 } 3161 }
3144} 3162}
3145 3163
3146#ifndef DESKTOP_VERSION 3164#ifndef DESKTOP_VERSION
3147void CalendarView::beamDone( Ir *ir ) 3165void CalendarView::beamDone( Ir *ir )
3148{ 3166{
3149 delete ir; 3167 delete ir;
3150 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 3168 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
3151 topLevelWidget()->raise(); 3169 topLevelWidget()->raise();
3152} 3170}
3153#else 3171#else
3154void CalendarView::beamDone( Ir *){;} 3172void CalendarView::beamDone( Ir *){;}
3155#endif 3173#endif
3156void CalendarView::moveIncidence(Incidence * inc ) 3174void CalendarView::moveIncidence(Incidence * inc )
3157{ 3175{
3158 if ( !inc ) return; 3176 if ( !inc ) return;
3159 showDatePickerPopup(); 3177 showDatePickerPopup();
3160 mDatePickerMode = 2; 3178 mDatePickerMode = 2;
3161 mMoveIncidence = inc ; 3179 mMoveIncidence = inc ;
3162 QDate da; 3180 QDate da;
3163 if ( mMoveIncidence->typeID() == todoID ) { 3181 if ( mMoveIncidence->typeID() == todoID ) {
3164 Todo * to = (Todo *) mMoveIncidence; 3182 Todo * to = (Todo *) mMoveIncidence;
3165 if ( to->hasDueDate() ) 3183 if ( to->hasDueDate() )
3166 da = to->dtDue().date(); 3184 da = to->dtDue().date();
3167 else 3185 else
3168 da = QDate::currentDate(); 3186 da = QDate::currentDate();
3169 } else { 3187 } else {
3170 da = mMoveIncidence->dtStart().date(); 3188 da = mMoveIncidence->dtStart().date();
3171 } 3189 }
3172 //PENDING set date for recurring incidence to date of recurrence 3190 //PENDING set date for recurring incidence to date of recurrence
3173 //mMoveIncidenceOldDate; 3191 //mMoveIncidenceOldDate;
3174 mDatePicker->setDate( da ); 3192 mDatePicker->setDate( da );
3175} 3193}
3176void CalendarView::showDatePickerPopup() 3194void CalendarView::showDatePickerPopup()
3177{ 3195{
3178 if ( mDateFrame->isVisible() ) 3196 if ( mDateFrame->isVisible() )
3179 mDateFrame->hide(); 3197 mDateFrame->hide();
3180 else { 3198 else {
3181 int offX = 0, offY = 0; 3199 int offX = 0, offY = 0;
3182#ifdef DESKTOP_VERSION 3200#ifdef DESKTOP_VERSION
3183 int w =mDatePicker->sizeHint().width() ; 3201 int w =mDatePicker->sizeHint().width() ;
3184 int h = mDatePicker->sizeHint().height() ; 3202 int h = mDatePicker->sizeHint().height() ;
3185 int dw = topLevelWidget()->width(); 3203 int dw = topLevelWidget()->width();
3186 int dh = topLevelWidget()->height(); 3204 int dh = topLevelWidget()->height();
3187 offX = topLevelWidget()->x(); 3205 offX = topLevelWidget()->x();
3188 offY = topLevelWidget()->y(); 3206 offY = topLevelWidget()->y();
3189#else 3207#else
3190 int w =mDatePicker->sizeHint().width() ; 3208 int w =mDatePicker->sizeHint().width() ;
3191 int h = mDatePicker->sizeHint().height() ; 3209 int h = mDatePicker->sizeHint().height() ;
3192 int dw = QApplication::desktop()->width(); 3210 int dw = QApplication::desktop()->width();
3193 int dh = QApplication::desktop()->height(); 3211 int dh = QApplication::desktop()->height();
3194#endif 3212#endif
3195 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 3213 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
3196 mDateFrame->show(); 3214 mDateFrame->show();
3197 } 3215 }
3198} 3216}
3199void CalendarView::showDatePicker( ) 3217void CalendarView::showDatePicker( )
3200{ 3218{
3201 showDatePickerPopup(); 3219 showDatePickerPopup();
3202 mDatePickerMode = 1; 3220 mDatePickerMode = 1;
3203 mDatePicker->setDate( mNavigator->selectedDates().first() ); 3221 mDatePicker->setDate( mNavigator->selectedDates().first() );
3204} 3222}
3205 3223
3206void CalendarView::showEventEditor() 3224void CalendarView::showEventEditor()
3207{ 3225{
3208#ifdef DESKTOP_VERSION 3226#ifdef DESKTOP_VERSION
3209 int x,y,w,h; 3227 int x,y,w,h;
3210 x = mEventEditor->geometry().x(); 3228 x = mEventEditor->geometry().x();
3211 y = mEventEditor->geometry().y(); 3229 y = mEventEditor->geometry().y();
3212 w = mEventEditor->width(); 3230 w = mEventEditor->width();
3213 h = mEventEditor->height(); 3231 h = mEventEditor->height();
3214 mEventEditor->show(); 3232 mEventEditor->show();
3215 mEventEditor->setGeometry(x,y,w,h); 3233 mEventEditor->setGeometry(x,y,w,h);
3216#else 3234#else
3217 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 3235 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
3218 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3236 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3219 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 3237 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
3220 qApp->processEvents(); 3238 qApp->processEvents();
3221 delete mEventEditor; 3239 delete mEventEditor;
3222 mEventEditor = mDialogManager->getEventEditor(); 3240 mEventEditor = mDialogManager->getEventEditor();
3223 topLevelWidget()->setCaption( i18n("") ); 3241 topLevelWidget()->setCaption( i18n("") );
3224 } 3242 }
3225 mEventEditor->showMaximized(); 3243 mEventEditor->showMaximized();
3226#endif 3244#endif
3227} 3245}
3228void CalendarView::showTodoEditor() 3246void CalendarView::showTodoEditor()
3229{ 3247{
3230#ifdef DESKTOP_VERSION 3248#ifdef DESKTOP_VERSION
3231 int x,y,w,h; 3249 int x,y,w,h;
3232 x = mTodoEditor->geometry().x(); 3250 x = mTodoEditor->geometry().x();
3233 y = mTodoEditor->geometry().y(); 3251 y = mTodoEditor->geometry().y();
3234 w = mTodoEditor->width(); 3252 w = mTodoEditor->width();
3235 h = mTodoEditor->height(); 3253 h = mTodoEditor->height();
3236 mTodoEditor->show(); 3254 mTodoEditor->show();
3237 mTodoEditor->setGeometry(x,y,w,h); 3255 mTodoEditor->setGeometry(x,y,w,h);
3238#else 3256#else
3239 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 3257 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
3240 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 3258 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
3241 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 3259 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
3242 qApp->processEvents(); 3260 qApp->processEvents();
3243 delete mTodoEditor; 3261 delete mTodoEditor;
3244 mTodoEditor = mDialogManager->getTodoEditor(); 3262 mTodoEditor = mDialogManager->getTodoEditor();
3245 topLevelWidget()->setCaption( i18n("") ); 3263 topLevelWidget()->setCaption( i18n("") );
3246 } 3264 }
3247 mTodoEditor->showMaximized(); 3265 mTodoEditor->showMaximized();
3248#endif 3266#endif
3249} 3267}
3250 3268
3251void CalendarView::cloneIncidence() 3269void CalendarView::cloneIncidence()
3252{ 3270{
3253 Incidence *incidence = currentSelection(); 3271 Incidence *incidence = currentSelection();
3254 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3272 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3255 if ( incidence ) { 3273 if ( incidence ) {
3256 cloneIncidence(incidence); 3274 cloneIncidence(incidence);
3257 } 3275 }
3258} 3276}
3259void CalendarView::moveIncidence() 3277void CalendarView::moveIncidence()
3260{ 3278{
3261 Incidence *incidence = currentSelection(); 3279 Incidence *incidence = currentSelection();
3262 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3280 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3263 if ( incidence ) { 3281 if ( incidence ) {
3264 moveIncidence(incidence); 3282 moveIncidence(incidence);
3265 } 3283 }
3266} 3284}
3267void CalendarView::beamIncidence() 3285void CalendarView::beamIncidence()
3268{ 3286{
3269 Incidence *incidence = currentSelection(); 3287 Incidence *incidence = currentSelection();
3270 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3288 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3271 if ( incidence ) { 3289 if ( incidence ) {
3272 beamIncidence(incidence); 3290 beamIncidence(incidence);
3273 } 3291 }
3274} 3292}
3275void CalendarView::toggleCancelIncidence() 3293void CalendarView::toggleCancelIncidence()
3276{ 3294{
3277 Incidence *incidence = currentSelection(); 3295 Incidence *incidence = currentSelection();
3278 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3296 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3279 if ( incidence ) { 3297 if ( incidence ) {
3280 cancelIncidence(incidence); 3298 cancelIncidence(incidence);
3281 } 3299 }
3282} 3300}
3283 3301
3284 3302
3285void CalendarView::cancelIncidence(Incidence * inc ) 3303void CalendarView::cancelIncidence(Incidence * inc )
3286{ 3304{
3287 inc->setCancelled( ! inc->cancelled() ); 3305 inc->setCancelled( ! inc->cancelled() );
3288 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 3306 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
3289 updateView(); 3307 updateView();
3290} 3308}
3291void CalendarView::cloneIncidence(Incidence * orgInc ) 3309void CalendarView::cloneIncidence(Incidence * orgInc )
3292{ 3310{
3293 Incidence * newInc = orgInc->clone(); 3311 Incidence * newInc = orgInc->clone();
3294 newInc->recreate(); 3312 newInc->recreate();
3295 3313
3296 if ( newInc->typeID() == todoID ) { 3314 if ( newInc->typeID() == todoID ) {
3297 Todo* t = (Todo*) newInc; 3315 Todo* t = (Todo*) newInc;
3298 bool cloneSub = false; 3316 bool cloneSub = false;
3299 if ( orgInc->relations().count() ) { 3317 if ( orgInc->relations().count() ) {
3300 int result = KMessageBox::warningYesNoCancel(this, 3318 int result = KMessageBox::warningYesNoCancel(this,
3301 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ), 3319 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( KGlobal::formatMessage ( newInc->summary(),0 ) ),
3302 i18n("Todo has subtodos"), 3320 i18n("Todo has subtodos"),
3303 i18n("Yes"), 3321 i18n("Yes"),
3304 i18n("No")); 3322 i18n("No"));
3305 3323
3306 if ( result == KMessageBox::Cancel ) { 3324 if ( result == KMessageBox::Cancel ) {
3307 delete t; 3325 delete t;
3308 return; 3326 return;
3309 } 3327 }
3310 if (result == KMessageBox::Yes) cloneSub = true; 3328 if (result == KMessageBox::Yes) cloneSub = true;
3311 } 3329 }
3312 showTodoEditor(); 3330 showTodoEditor();
3313 mTodoEditor->editTodo( t ); 3331 mTodoEditor->editTodo( t );
3314 if ( mTodoEditor->exec() ) { 3332 if ( mTodoEditor->exec() ) {
3315 if ( cloneSub ) { 3333 if ( cloneSub ) {
3316 orgInc->cloneRelations( t ); 3334 orgInc->cloneRelations( t );
3317 mCalendar->addIncidenceBranch( t ); 3335 mCalendar->addIncidenceBranch( t );
3318 updateView(); 3336 updateView();
3319 3337
3320 } else { 3338 } else {
3321 mCalendar->addTodo( t ); 3339 mCalendar->addTodo( t );
3322 updateView(); 3340 updateView();
3323 } 3341 }
3324 } else { 3342 } else {
3325 delete t; 3343 delete t;
3326 } 3344 }
3327 } 3345 }
3328 else if ( newInc->typeID() == eventID ) { 3346 else if ( newInc->typeID() == eventID ) {
3329 Event* e = (Event*) newInc; 3347 Event* e = (Event*) newInc;
3330 showEventEditor(); 3348 showEventEditor();
3331 mEventEditor->editEvent( e ); 3349 mEventEditor->editEvent( e );
3332 if ( mEventEditor->exec() ) { 3350 if ( mEventEditor->exec() ) {
3333 mCalendar->addEvent( e ); 3351 mCalendar->addEvent( e );
3334 updateView(); 3352 updateView();
3335 } else { 3353 } else {
3336 delete e; 3354 delete e;
3337 } 3355 }
3338 } if ( newInc->typeID() == journalID ) { 3356 } if ( newInc->typeID() == journalID ) {
3339 mCalendar->addJournal( (Journal*) newInc ); 3357 mCalendar->addJournal( (Journal*) newInc );
3340 editJournal( (Journal*) newInc ); 3358 editJournal( (Journal*) newInc );
3341 } 3359 }
3342 setActiveWindow(); 3360 setActiveWindow();
3343} 3361}
3344 3362
3345void CalendarView::newEvent() 3363void CalendarView::newEvent()
3346{ 3364{
3347 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 3365 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
3348 KOAgendaView *aView = mViewManager->agendaView(); 3366 KOAgendaView *aView = mViewManager->agendaView();
3349 if (aView) { 3367 if (aView) {
3350 if (aView->selectionStart().isValid()) { 3368 if (aView->selectionStart().isValid()) {
3351 if (aView->selectedIsAllDay()) { 3369 if (aView->selectedIsAllDay()) {
3352 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 3370 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
3353 } else { 3371 } else {
3354 newEvent(aView->selectionStart(),aView->selectionEnd()); 3372 newEvent(aView->selectionStart(),aView->selectionEnd());
3355 } 3373 }
3356 return; 3374 return;
3357 } 3375 }
3358 } 3376 }
3359 3377
3360 QDate date = mNavigator->selectedDates().first(); 3378 QDate date = mNavigator->selectedDates().first();
3379#if 0
3361 QDateTime current = QDateTime::currentDateTime(); 3380 QDateTime current = QDateTime::currentDateTime();
3362 if ( date <= current.date() ) { 3381 if ( date <= current.date() ) {
3363 int hour = current.time().hour() +1; 3382 int hour = current.time().hour() +1;
3364 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 3383 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
3365 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3384 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3366 } else 3385 } else
3386#endif
3367 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 3387 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
3368 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 3388 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
3369 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 3389 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
3370} 3390}
3371 3391
3372void CalendarView::newEvent(QDateTime fh) 3392void CalendarView::newEvent(QDateTime fh)
3373{ 3393{
3374 newEvent(fh, 3394 newEvent(fh,
3375 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 3395 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
3376} 3396}
3377 3397
3378void CalendarView::newEvent(QDate dt) 3398void CalendarView::newEvent(QDate dt)
3379{ 3399{
3380 newEvent(QDateTime(dt, QTime(0,0,0)), 3400 newEvent(QDateTime(dt, QTime(0,0,0)),
3381 QDateTime(dt, QTime(0,0,0)), true); 3401 QDateTime(dt, QTime(0,0,0)), true);
3382} 3402}
3383void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 3403void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
3384{ 3404{
3385 newEvent(fromHint, toHint, false); 3405 newEvent(fromHint, toHint, false);
3386} 3406}
3387void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 3407void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
3388{ 3408{
3389 3409
3390 showEventEditor(); 3410 showEventEditor();
3391 mEventEditor->newEvent(fromHint,toHint,allDay); 3411 mEventEditor->newEvent(fromHint,toHint,allDay);
3392 if ( mFilterView->filtersEnabled() ) { 3412 if ( mFilterView->filtersEnabled() ) {
3393 CalFilter *filter = mFilterView->selectedFilter(); 3413 CalFilter *filter = mFilterView->selectedFilter();
3394 if (filter && filter->showCategories()) { 3414 if (filter && filter->showCategories()) {
3395 mEventEditor->setCategories(filter->categoryList().join(",") ); 3415 mEventEditor->setCategories(filter->categoryList().join(",") );
3396 } 3416 }
3397 if ( filter ) 3417 if ( filter )
3398 mEventEditor->setSecrecy( filter->getSecrecy() ); 3418 mEventEditor->setSecrecy( filter->getSecrecy() );
3399 } 3419 }
3400 mEventEditor->exec(); 3420 mEventEditor->exec();
3401 setActiveWindow(); 3421 setActiveWindow();
3402} 3422}
3403void CalendarView::todoAdded(Todo * t) 3423void CalendarView::todoAdded(Todo * t)
3404{ 3424{
3405 3425
3406 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 3426 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
3407 updateTodoViews(); 3427 updateTodoViews();
3408} 3428}
3409void CalendarView::todoChanged(Todo * t) 3429void CalendarView::todoChanged(Todo * t)
3410{ 3430{
3411 emit todoModified( t, 4 ); 3431 emit todoModified( t, 4 );
3412 // updateTodoViews(); 3432 // updateTodoViews();
3413} 3433}
3414void CalendarView::todoToBeDeleted(Todo *) 3434void CalendarView::todoToBeDeleted(Todo *)
3415{ 3435{
3416 //qDebug("todoToBeDeleted(Todo *) "); 3436 //qDebug("todoToBeDeleted(Todo *) ");
3417 updateTodoViews(); 3437 updateTodoViews();
3418} 3438}
3419void CalendarView::todoDeleted() 3439void CalendarView::todoDeleted()
3420{ 3440{
3421 //qDebug(" todoDeleted()"); 3441 //qDebug(" todoDeleted()");
3422 updateTodoViews(); 3442 updateTodoViews();
3423} 3443}
3424 3444
3425 3445
3426void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 3446void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
3427{ 3447{
3428 showTodoEditor(); 3448 showTodoEditor();
3429 mTodoEditor->newTodo(dt,0,allday); 3449 mTodoEditor->newTodo(dt,0,allday);
3430 if ( mFilterView->filtersEnabled() ) { 3450 if ( mFilterView->filtersEnabled() ) {
3431 CalFilter *filter = mFilterView->selectedFilter(); 3451 CalFilter *filter = mFilterView->selectedFilter();
3432 if (filter && filter->showCategories()) { 3452 if (filter && filter->showCategories()) {
3433 mTodoEditor->setCategories(filter->categoryList().join(",") ); 3453 mTodoEditor->setCategories(filter->categoryList().join(",") );
3434 } 3454 }
3435 if ( filter ) 3455 if ( filter )
3436 mTodoEditor->setSecrecy( filter->getSecrecy() ); 3456 mTodoEditor->setSecrecy( filter->getSecrecy() );
3437 } 3457 }
3438 mTodoEditor->exec(); 3458 mTodoEditor->exec();
3439 setActiveWindow(); 3459 setActiveWindow();
3440} 3460}
3441 3461
3442void CalendarView::newTodo() 3462void CalendarView::newTodo()
3443{ 3463{
3444 newTodoDateTime( QDateTime(),true ); 3464 newTodoDateTime( QDateTime(),true );
3445} 3465}
3446 3466
3447void CalendarView::newSubTodo() 3467void CalendarView::newSubTodo()
3448{ 3468{
3449 Todo *todo = selectedTodo(); 3469 Todo *todo = selectedTodo();
3450 if ( todo ) newSubTodo( todo ); 3470 if ( todo ) newSubTodo( todo );
3451} 3471}
3452 3472
3453void CalendarView::newSubTodo(Todo *parentEvent) 3473void CalendarView::newSubTodo(Todo *parentEvent)
3454{ 3474{
3455 3475
3456 showTodoEditor(); 3476 showTodoEditor();
3457 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 3477 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
3458 mTodoEditor->exec(); 3478 mTodoEditor->exec();
3459 setActiveWindow(); 3479 setActiveWindow();
3460} 3480}
3461 3481
3462void CalendarView::newFloatingEvent() 3482void CalendarView::newFloatingEvent()
3463{ 3483{
3464 DateList tmpList = mNavigator->selectedDates(); 3484 DateList tmpList = mNavigator->selectedDates();
3465 QDate date = tmpList.first(); 3485 QDate date = tmpList.first();
3466 3486
3467 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 3487 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
3468 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 3488 QDateTime( date, QTime( 12, 0, 0 ) ), true );
3469} 3489}
3470 3490
3471 3491
3472void CalendarView::editEvent( Event *event ) 3492void CalendarView::editEvent( Event *event )
3473{ 3493{
3474 3494
3475 if ( !event ) return; 3495 if ( !event ) return;
3476 if ( event->isReadOnly() ) { 3496 if ( event->isReadOnly() ) {
3477 showEvent( event ); 3497 showEvent( event );
3478 return; 3498 return;
3479 } 3499 }
3480 showEventEditor(); 3500 showEventEditor();
3481 mEventEditor->editEvent( event , mFlagEditDescription); 3501 mEventEditor->editEvent( event , mFlagEditDescription);
3482 mEventEditor->exec(); 3502 mEventEditor->exec();
3483 setActiveWindow(); 3503 setActiveWindow();
3484 3504
3485} 3505}
3486void CalendarView::editJournal( Journal *jour ) 3506void CalendarView::editJournal( Journal *jour )
3487{ 3507{
3488 if ( !jour ) return; 3508 if ( !jour ) return;
3489 mDialogManager->hideSearchDialog(); 3509 mDialogManager->hideSearchDialog();
3490 mViewManager->showJournalView(); 3510 mViewManager->showJournalView();
3491 mNavigator->slotDaySelect( jour->dtStart().date() ); 3511 mNavigator->slotDaySelect( jour->dtStart().date() );
3492} 3512}
3493void CalendarView::editTodo( Todo *todo ) 3513void CalendarView::editTodo( Todo *todo )
3494{ 3514{
3495 if ( !todo ) return; 3515 if ( !todo ) return;
3496 3516
3497 if ( todo->isReadOnly() ) { 3517 if ( todo->isReadOnly() ) {
3498 showTodo( todo ); 3518 showTodo( todo );
3499 return; 3519 return;
3500 } 3520 }
3501 showTodoEditor(); 3521 showTodoEditor();
3502 mTodoEditor->editTodo( todo ,mFlagEditDescription); 3522 mTodoEditor->editTodo( todo ,mFlagEditDescription);
3503 mTodoEditor->exec(); 3523 mTodoEditor->exec();
3504 setActiveWindow(); 3524 setActiveWindow();
3505 3525
3506} 3526}
3507 3527
3508KOEventViewerDialog* CalendarView::getEventViewerDialog() 3528KOEventViewerDialog* CalendarView::getEventViewerDialog()
3509{ 3529{
3510 if ( !mEventViewerDialog ) { 3530 if ( !mEventViewerDialog ) {
3511 mEventViewerDialog = new KOEventViewerDialog(0); 3531 mEventViewerDialog = new KOEventViewerDialog(0);
3512 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 3532 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
3513 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 3533 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
3514 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 3534 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
3515 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 3535 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
3516 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 3536 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
3517 viewManager(), SLOT( showAgendaView( bool ) ) ); 3537 viewManager(), SLOT( showAgendaView( bool ) ) );
3518 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 3538 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
3519 this, SLOT( slotViewerClosed() ) ); 3539 this, SLOT( slotViewerClosed() ) );
3520 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 3540 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
3521 this, SLOT( todoChanged(Todo *) ) ); 3541 this, SLOT( todoChanged(Todo *) ) );
3522 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) )); 3542 connect( mEventViewerDialog, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
3523 mEventViewerDialog->resize( 640, 480 ); 3543 mEventViewerDialog->resize( 640, 480 );
3524 3544
3525 } 3545 }
3526 return mEventViewerDialog; 3546 return mEventViewerDialog;
3527} 3547}
3528void CalendarView::showEvent(Event *event) 3548void CalendarView::showEvent(Event *event)
3529{ 3549{
3530 getEventViewerDialog()->setEvent(event); 3550 getEventViewerDialog()->setEvent(event);
3531 getEventViewerDialog()->showMe(); 3551 getEventViewerDialog()->showMe();
3532} 3552}
3533 3553
3534void CalendarView::showTodo(Todo *event) 3554void CalendarView::showTodo(Todo *event)
3535{ 3555{
3536 getEventViewerDialog()->setTodo(event); 3556 getEventViewerDialog()->setTodo(event);
3537 getEventViewerDialog()->showMe(); 3557 getEventViewerDialog()->showMe();
3538} 3558}
3539void CalendarView::showJournal( Journal *jour ) 3559void CalendarView::showJournal( Journal *jour )
3540{ 3560{
3541 getEventViewerDialog()->setJournal(jour); 3561 getEventViewerDialog()->setJournal(jour);
3542 getEventViewerDialog()->showMe(); 3562 getEventViewerDialog()->showMe();
3543 3563
3544} 3564}
3545// void CalendarView::todoModified (Todo *event, int changed) 3565// void CalendarView::todoModified (Todo *event, int changed)
3546// { 3566// {
3547// // if (mDialogList.find (event) != mDialogList.end ()) { 3567// // if (mDialogList.find (event) != mDialogList.end ()) {
3548// // kdDebug() << "Todo modified and open" << endl; 3568// // kdDebug() << "Todo modified and open" << endl;
3549// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 3569// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
3550// // temp->modified (changed); 3570// // temp->modified (changed);
3551 3571
3552// // } 3572// // }
3553 3573
3554// mViewManager->updateView(); 3574// mViewManager->updateView();
3555// } 3575// }
3556 3576
3557void CalendarView::appointment_show() 3577void CalendarView::appointment_show()
3558{ 3578{
3559 Event *anEvent = 0; 3579 Event *anEvent = 0;
3560 3580
3561 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3581 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3562 3582
3563 if (mViewManager->currentView()->isEventView()) { 3583 if (mViewManager->currentView()->isEventView()) {
3564 if ( incidence && incidence->typeID() == eventID ) { 3584 if ( incidence && incidence->typeID() == eventID ) {
3565 anEvent = static_cast<Event *>(incidence); 3585 anEvent = static_cast<Event *>(incidence);
3566 } 3586 }
3567 } 3587 }
3568 3588
3569 if (!anEvent) { 3589 if (!anEvent) {
3570 KNotifyClient::beep(); 3590 KNotifyClient::beep();
3571 return; 3591 return;
3572 } 3592 }
3573 3593
3574 showEvent(anEvent); 3594 showEvent(anEvent);
3575} 3595}
3576 3596
3577void CalendarView::appointment_edit() 3597void CalendarView::appointment_edit()
3578{ 3598{
3579 Event *anEvent = 0; 3599 Event *anEvent = 0;
3580 3600
3581 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3601 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3582 3602
3583 if (mViewManager->currentView()->isEventView()) { 3603 if (mViewManager->currentView()->isEventView()) {
3584 if ( incidence && incidence->typeID() == eventID ) { 3604 if ( incidence && incidence->typeID() == eventID ) {
3585 anEvent = static_cast<Event *>(incidence); 3605 anEvent = static_cast<Event *>(incidence);
3586 } 3606 }
3587 } 3607 }
3588 3608
3589 if (!anEvent) { 3609 if (!anEvent) {
3590 KNotifyClient::beep(); 3610 KNotifyClient::beep();
3591 return; 3611 return;
3592 } 3612 }
3593 3613
3594 editEvent(anEvent); 3614 editEvent(anEvent);
3595} 3615}
3596 3616
3597void CalendarView::appointment_delete() 3617void CalendarView::appointment_delete()
3598{ 3618{
3599 Event *anEvent = 0; 3619 Event *anEvent = 0;
3600 3620
3601 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3621 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3602 3622
3603 if (mViewManager->currentView()->isEventView()) { 3623 if (mViewManager->currentView()->isEventView()) {
3604 if ( incidence && incidence->typeID() == eventID ) { 3624 if ( incidence && incidence->typeID() == eventID ) {
3605 anEvent = static_cast<Event *>(incidence); 3625 anEvent = static_cast<Event *>(incidence);
3606 } 3626 }
3607 } 3627 }
3608 3628
3609 if (!anEvent) { 3629 if (!anEvent) {
3610 KNotifyClient::beep(); 3630 KNotifyClient::beep();
3611 return; 3631 return;
3612 } 3632 }
3613 3633
3614 deleteEvent(anEvent); 3634 deleteEvent(anEvent);
3615} 3635}
3616 3636
3617void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3637void CalendarView::todo_resub( Todo * parent, Todo * sub )
3618{ 3638{
3619 if (!sub) return; 3639 if (!sub) return;
3620 if ( sub->relatedTo() == parent ) 3640 if ( sub->relatedTo() == parent )
3621 return; 3641 return;
3622 sub->setRelatedTo(parent); 3642 sub->setRelatedTo(parent);
3623 sub->updated(); 3643 sub->updated();
3624 setModified(true); 3644 setModified(true);
3625 updateView(); 3645 updateView();
3626} 3646}
3627void CalendarView::todo_unsub(Todo *anTodo ) 3647void CalendarView::todo_unsub(Todo *anTodo )
3628{ 3648{
3629 todo_resub( 0, anTodo ); 3649 todo_resub( 0, anTodo );
3630} 3650}
3631 3651
3632void CalendarView::deleteTodo(Todo *todo) 3652void CalendarView::deleteTodo(Todo *todo)
3633{ 3653{
3634 if (!todo) { 3654 if (!todo) {
3635 KNotifyClient::beep(); 3655 KNotifyClient::beep();
3636 return; 3656 return;
3637 } 3657 }
3638 if (KOPrefs::instance()->mConfirm) { 3658 if (KOPrefs::instance()->mConfirm) {
3639 QString text = KGlobal::formatMessage ( todo->summary(),0 ); 3659 QString text = KGlobal::formatMessage ( todo->summary(),0 );
3640 if (!todo->relations().isEmpty()) { 3660 if (!todo->relations().isEmpty()) {
3641 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3661 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3642 3662
3643 } 3663 }
3644 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) { 3664 switch (msgItemDelete(i18n("Todo:") +"\n"+text)) {
3645 case KMessageBox::Continue: // OK 3665 case KMessageBox::Continue: // OK
3646 bool deleteT = false; 3666 bool deleteT = false;
3647 if (!todo->relations().isEmpty()) { 3667 if (!todo->relations().isEmpty()) {
3648 deleteT = removeCompletedSubTodos( todo ); 3668 deleteT = removeCompletedSubTodos( todo );
3649 } 3669 }
3650 // deleteT == true: todo already deleted in removeCompletedSubTodos 3670 // deleteT == true: todo already deleted in removeCompletedSubTodos
3651 if ( !deleteT ) { 3671 if ( !deleteT ) {
3652 checkExternalId( todo ); 3672 checkExternalId( todo );
3653 calendar()->deleteTodo(todo); 3673 calendar()->deleteTodo(todo);
3654 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3674 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3655 updateView(); 3675 updateView();
3656 } 3676 }
3657 break; 3677 break;
3658 } // switch 3678 } // switch
3659 } else { 3679 } else {
3660 checkExternalId( todo ); 3680 checkExternalId( todo );
3661 mCalendar->deleteTodo(todo); 3681 mCalendar->deleteTodo(todo);
3662 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3682 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3663 updateView(); 3683 updateView();
3664 } 3684 }
3665 3685
3666 emit updateSearchDialog(); 3686 emit updateSearchDialog();
3667} 3687}
3668void CalendarView::deleteJournal(Journal *jour) 3688void CalendarView::deleteJournal(Journal *jour)
3669{ 3689{
3670 if (!jour) { 3690 if (!jour) {
3671 KNotifyClient::beep(); 3691 KNotifyClient::beep();
3672 return; 3692 return;
3673 } 3693 }
3674 if (KOPrefs::instance()->mConfirm) { 3694 if (KOPrefs::instance()->mConfirm) {
3675 3695
3676 QString des; 3696 QString des;
3677 if ( !jour->summary().isEmpty() ) { 3697 if ( !jour->summary().isEmpty() ) {
3678 des = jour->summary(); 3698 des = jour->summary();
3679 } else { 3699 } else {
3680 des = jour->description().left(30); 3700 des = jour->description().left(30);
3681 des = des.simplifyWhiteSpace (); 3701 des = des.simplifyWhiteSpace ();
3682 des.replace (QRegExp ("\\n"),"" ); 3702 des.replace (QRegExp ("\\n"),"" );
3683 des.replace (QRegExp ("\\r"),"" ); 3703 des.replace (QRegExp ("\\r"),"" );
3684 } 3704 }
3685 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) { 3705 switch (msgItemDelete( i18n("Journal:") +"\n"+KGlobal::formatMessage ( des,0 ))) {
3686 case KMessageBox::Continue: // OK 3706 case KMessageBox::Continue: // OK
3687 calendar()->deleteJournal(jour); 3707 calendar()->deleteJournal(jour);
3688 updateView(); 3708 updateView();
3689 break; 3709 break;
3690 } // switch 3710 } // switch
3691 } else { 3711 } else {
3692 calendar()->deleteJournal(jour);; 3712 calendar()->deleteJournal(jour);;
3693 updateView(); 3713 updateView();
3694 } 3714 }
3695 emit updateSearchDialog(); 3715 emit updateSearchDialog();
3696} 3716}
3697 3717
3698void CalendarView::deleteEvent(Event *anEvent) 3718void CalendarView::deleteEvent(Event *anEvent)
3699{ 3719{
3700 if (!anEvent) { 3720 if (!anEvent) {
3701 KNotifyClient::beep(); 3721 KNotifyClient::beep();
3702 return; 3722 return;
3703 } 3723 }
3704 3724
3705 if (anEvent->recurrence()->doesRecur()) { 3725 if (anEvent->recurrence()->doesRecur()) {
3706 QDate itemDate = mViewManager->currentSelectionDate(); 3726 QDate itemDate = mViewManager->currentSelectionDate();
3707 int km; 3727 int km;
3708 if (!itemDate.isValid()) { 3728 if (!itemDate.isValid()) {
3709 //kdDebug() << "Date Not Valid" << endl; 3729 //kdDebug() << "Date Not Valid" << endl;
3710 if (KOPrefs::instance()->mConfirm) { 3730 if (KOPrefs::instance()->mConfirm) {
3711 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3731 km = KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3712 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3732 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3713 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3733 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3714 if ( km == KMessageBox::Continue ) 3734 if ( km == KMessageBox::Continue )
3715 km = KMessageBox::No; // No = all below 3735 km = KMessageBox::No; // No = all below
3716 } else 3736 } else
3717 km = KMessageBox::No; 3737 km = KMessageBox::No;
3718 } else { 3738 } else {
3719 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3739 km = KMessageBox::warningYesNoCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3720 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3740 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3721 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3741 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3722 i18n("KO/Pi Confirmation"),i18n("Current"), 3742 i18n("KO/Pi Confirmation"),i18n("Current"),
3723 i18n("All")); 3743 i18n("All"));
3724 } 3744 }
3725 switch(km) { 3745 switch(km) {
3726 3746
3727 case KMessageBox::No: // Continue // all 3747 case KMessageBox::No: // Continue // all
3728 //qDebug("KMessageBox::No "); 3748 //qDebug("KMessageBox::No ");
3729 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3749 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3730 schedule(Scheduler::Cancel,anEvent); 3750 schedule(Scheduler::Cancel,anEvent);
3731 3751
3732 checkExternalId( anEvent); 3752 checkExternalId( anEvent);
3733 mCalendar->deleteEvent(anEvent); 3753 mCalendar->deleteEvent(anEvent);
3734 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3754 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3735 break; 3755 break;
3736 3756
3737 // Disabled because it does not work 3757 // Disabled because it does not work
3738 //#if 0 3758 //#if 0
3739 case KMessageBox::Yes: // just this one 3759 case KMessageBox::Yes: // just this one
3740 //QDate qd = mNavigator->selectedDates().first(); 3760 //QDate qd = mNavigator->selectedDates().first();
3741 //if (!qd.isValid()) { 3761 //if (!qd.isValid()) {
3742 // kdDebug() << "no date selected, or invalid date" << endl; 3762 // kdDebug() << "no date selected, or invalid date" << endl;
3743 // KNotifyClient::beep(); 3763 // KNotifyClient::beep();
3744 // return; 3764 // return;
3745 //} 3765 //}
3746 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3766 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3747 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3767 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3748 anEvent->addExDate(itemDate); 3768 anEvent->addExDate(itemDate);
3749 int duration = anEvent->recurrence()->duration(); 3769 int duration = anEvent->recurrence()->duration();
3750 if ( duration > 0 ) { 3770 if ( duration > 0 ) {
3751 anEvent->recurrence()->setDuration( duration - 1 ); 3771 anEvent->recurrence()->setDuration( duration - 1 );
3752 } 3772 }
3753 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3773 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3754 } 3774 }
3755 break; 3775 break;
3756 //#endif 3776 //#endif
3757 } // switch 3777 } // switch
3758 } else { 3778 } else {
3759 if (KOPrefs::instance()->mConfirm) { 3779 if (KOPrefs::instance()->mConfirm) {
3760 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) + 3780 switch (KMessageBox::warningContinueCancel(this,KGlobal::formatMessage ( anEvent->summary(),0 ) +
3761 i18n("\nAre you sure you want\nto delete this event?"), 3781 i18n("\nAre you sure you want\nto delete this event?"),
3762 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3782 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3763 case KMessageBox::Continue: // OK 3783 case KMessageBox::Continue: // OK
3764 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3784 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3765 schedule(Scheduler::Cancel,anEvent); 3785 schedule(Scheduler::Cancel,anEvent);
3766 checkExternalId( anEvent); 3786 checkExternalId( anEvent);
3767 mCalendar->deleteEvent(anEvent); 3787 mCalendar->deleteEvent(anEvent);
3768 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3788 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3769 break; 3789 break;
3770 } // switch 3790 } // switch
3771 } else { 3791 } else {
3772 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3792 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3773 schedule(Scheduler::Cancel,anEvent); 3793 schedule(Scheduler::Cancel,anEvent);
3774 checkExternalId( anEvent); 3794 checkExternalId( anEvent);
3775 mCalendar->deleteEvent(anEvent); 3795 mCalendar->deleteEvent(anEvent);
3776 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3796 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3777 } 3797 }
3778 } // if-else 3798 } // if-else
3779 emit updateSearchDialog(); 3799 emit updateSearchDialog();
3780} 3800}
3781 3801
3782bool CalendarView::deleteEvent(const QString &uid) 3802bool CalendarView::deleteEvent(const QString &uid)
3783{ 3803{
3784 Event *ev = mCalendar->event(uid); 3804 Event *ev = mCalendar->event(uid);
3785 if (ev) { 3805 if (ev) {
3786 deleteEvent(ev); 3806 deleteEvent(ev);
3787 return true; 3807 return true;
3788 } else { 3808 } else {
3789 return false; 3809 return false;
3790 } 3810 }
3791} 3811}
3792 3812
3793/*****************************************************************************/ 3813/*****************************************************************************/
3794 3814
3795void CalendarView::action_mail() 3815void CalendarView::action_mail()
3796{ 3816{
3797#ifndef KORG_NOMAIL 3817#ifndef KORG_NOMAIL
3798 KOMailClient mailClient; 3818 KOMailClient mailClient;
3799 3819
3800 Incidence *incidence = currentSelection(); 3820 Incidence *incidence = currentSelection();
3801 3821
3802 if (!incidence) { 3822 if (!incidence) {
3803 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3823 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3804 return; 3824 return;
3805 } 3825 }
3806 if(incidence->attendeeCount() == 0 ) { 3826 if(incidence->attendeeCount() == 0 ) {
3807 KMessageBox::sorry(this, 3827 KMessageBox::sorry(this,
3808 i18n("Can't generate mail:\nNo attendees defined.\n")); 3828 i18n("Can't generate mail:\nNo attendees defined.\n"));
3809 return; 3829 return;
3810 } 3830 }
3811 3831
3812 CalendarLocal cal_tmp; 3832 CalendarLocal cal_tmp;
3813 Event *event = 0; 3833 Event *event = 0;
3814 Event *ev = 0; 3834 Event *ev = 0;
3815 if ( incidence && incidence->typeID() == eventID ) { 3835 if ( incidence && incidence->typeID() == eventID ) {
3816 event = static_cast<Event *>(incidence); 3836 event = static_cast<Event *>(incidence);
3817 ev = new Event(*event); 3837 ev = new Event(*event);
3818 cal_tmp.addEvent(ev); 3838 cal_tmp.addEvent(ev);
3819 } 3839 }
3820 ICalFormat mForm(); 3840 ICalFormat mForm();
3821 QString attachment = mForm.toString( &cal_tmp ); 3841 QString attachment = mForm.toString( &cal_tmp );
3822 if (ev) delete(ev); 3842 if (ev) delete(ev);
3823 3843
3824 mailClient.mailAttendees(currentSelection(), attachment); 3844 mailClient.mailAttendees(currentSelection(), attachment);
3825 3845
3826#endif 3846#endif
3827 3847
3828#if 0 3848#if 0
3829 Event *anEvent = 0; 3849 Event *anEvent = 0;
3830 if (mViewManager->currentView()->isEventView()) { 3850 if (mViewManager->currentView()->isEventView()) {
3831 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3851 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3832 } 3852 }
3833 3853
3834 if (!anEvent) { 3854 if (!anEvent) {
3835 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3855 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3836 return; 3856 return;
3837 } 3857 }
3838 if(anEvent->attendeeCount() == 0 ) { 3858 if(anEvent->attendeeCount() == 0 ) {
3839 KMessageBox::sorry(this, 3859 KMessageBox::sorry(this,
3840 i18n("Can't generate mail:\nNo attendees defined.\n")); 3860 i18n("Can't generate mail:\nNo attendees defined.\n"));
3841 return; 3861 return;
3842 } 3862 }
3843 3863
3844 mailobject.emailEvent(anEvent); 3864 mailobject.emailEvent(anEvent);
3845#endif 3865#endif
3846} 3866}
3847 3867
3848 3868
3849void CalendarView::schedule_publish(Incidence *incidence) 3869void CalendarView::schedule_publish(Incidence *incidence)
3850{ 3870{
3851 Event *event = 0; 3871 Event *event = 0;
3852 Todo *todo = 0; 3872 Todo *todo = 0;
3853 3873
3854 if (incidence == 0) { 3874 if (incidence == 0) {
3855 incidence = mViewManager->currentView()->selectedIncidences().first(); 3875 incidence = mViewManager->currentView()->selectedIncidences().first();
3856 if (incidence == 0) { 3876 if (incidence == 0) {
3857 incidence = mTodoList->selectedIncidences().first(); 3877 incidence = mTodoList->selectedIncidences().first();
3858 } 3878 }
3859 } 3879 }
3860 if ( incidence && incidence->typeID() == eventID ) { 3880 if ( incidence && incidence->typeID() == eventID ) {
3861 event = static_cast<Event *>(incidence); 3881 event = static_cast<Event *>(incidence);
3862 } else { 3882 } else {
3863 if ( incidence && incidence->typeID() == todoID ) { 3883 if ( incidence && incidence->typeID() == todoID ) {
3864 todo = static_cast<Todo *>(incidence); 3884 todo = static_cast<Todo *>(incidence);
3865 } 3885 }
3866 } 3886 }
3867 3887
3868 if (!event && !todo) { 3888 if (!event && !todo) {
3869 KMessageBox::sorry(this,i18n("No event selected.")); 3889 KMessageBox::sorry(this,i18n("No event selected."));
3870 return; 3890 return;
3871 } 3891 }
3872 3892
3873 PublishDialog *publishdlg = new PublishDialog(); 3893 PublishDialog *publishdlg = new PublishDialog();
3874 if (incidence->attendeeCount()>0) { 3894 if (incidence->attendeeCount()>0) {
3875 QPtrList<Attendee> attendees = incidence->attendees(); 3895 QPtrList<Attendee> attendees = incidence->attendees();
3876 attendees.first(); 3896 attendees.first();
3877 while ( attendees.current()!=0 ) { 3897 while ( attendees.current()!=0 ) {
3878 publishdlg->addAttendee(attendees.current()); 3898 publishdlg->addAttendee(attendees.current());
3879 attendees.next(); 3899 attendees.next();
3880 } 3900 }
3881 } 3901 }
3882 bool send = true; 3902 bool send = true;
3883 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3903 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3884 if ( publishdlg->exec() != QDialog::Accepted ) 3904 if ( publishdlg->exec() != QDialog::Accepted )
3885 send = false; 3905 send = false;
3886 } 3906 }
3887 if ( send ) { 3907 if ( send ) {
3888 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3908 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3889 if ( event ) { 3909 if ( event ) {
3890 Event *ev = new Event(*event); 3910 Event *ev = new Event(*event);
3891 ev->registerObserver(0); 3911 ev->registerObserver(0);
3892 ev->clearAttendees(); 3912 ev->clearAttendees();
3893 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3913 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3894 delete(ev); 3914 delete(ev);
3895 } 3915 }
3896 } else { 3916 } else {
3897 if ( todo ) { 3917 if ( todo ) {
3898 Todo *ev = new Todo(*todo); 3918 Todo *ev = new Todo(*todo);
3899 ev->registerObserver(0); 3919 ev->registerObserver(0);
3900 ev->clearAttendees(); 3920 ev->clearAttendees();
3901 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3921 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3902 delete(ev); 3922 delete(ev);
3903 } 3923 }
3904 } 3924 }
3905 } 3925 }
3906 } 3926 }
3907 delete publishdlg; 3927 delete publishdlg;
3908} 3928}
3909 3929
3910void CalendarView::schedule_request(Incidence *incidence) 3930void CalendarView::schedule_request(Incidence *incidence)
3911{ 3931{
3912 schedule(Scheduler::Request,incidence); 3932 schedule(Scheduler::Request,incidence);
3913} 3933}
3914 3934
3915void CalendarView::schedule_refresh(Incidence *incidence) 3935void CalendarView::schedule_refresh(Incidence *incidence)
3916{ 3936{
3917 schedule(Scheduler::Refresh,incidence); 3937 schedule(Scheduler::Refresh,incidence);
3918} 3938}
3919 3939
3920void CalendarView::schedule_cancel(Incidence *incidence) 3940void CalendarView::schedule_cancel(Incidence *incidence)
3921{ 3941{
3922 schedule(Scheduler::Cancel,incidence); 3942 schedule(Scheduler::Cancel,incidence);
3923} 3943}
3924 3944
3925void CalendarView::schedule_add(Incidence *incidence) 3945void CalendarView::schedule_add(Incidence *incidence)
3926{ 3946{
3927 schedule(Scheduler::Add,incidence); 3947 schedule(Scheduler::Add,incidence);
3928} 3948}
3929 3949
3930void CalendarView::schedule_reply(Incidence *incidence) 3950void CalendarView::schedule_reply(Incidence *incidence)
3931{ 3951{
3932 schedule(Scheduler::Reply,incidence); 3952 schedule(Scheduler::Reply,incidence);
3933} 3953}
3934 3954
3935void CalendarView::schedule_counter(Incidence *incidence) 3955void CalendarView::schedule_counter(Incidence *incidence)
3936{ 3956{
3937 schedule(Scheduler::Counter,incidence); 3957 schedule(Scheduler::Counter,incidence);
3938} 3958}
3939 3959
3940void CalendarView::schedule_declinecounter(Incidence *incidence) 3960void CalendarView::schedule_declinecounter(Incidence *incidence)
3941{ 3961{
3942 schedule(Scheduler::Declinecounter,incidence); 3962 schedule(Scheduler::Declinecounter,incidence);
3943} 3963}
3944 3964
3945void CalendarView::schedule_publish_freebusy(int daysToPublish) 3965void CalendarView::schedule_publish_freebusy(int daysToPublish)
3946{ 3966{
3947 QDateTime start = QDateTime::currentDateTime(); 3967 QDateTime start = QDateTime::currentDateTime();
3948 QDateTime end = start.addDays(daysToPublish); 3968 QDateTime end = start.addDays(daysToPublish);
3949 3969
3950 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3970 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3951 freebusy->setOrganizer(KOPrefs::instance()->email()); 3971 freebusy->setOrganizer(KOPrefs::instance()->email());
3952 3972
3953 3973
3954 PublishDialog *publishdlg = new PublishDialog(); 3974 PublishDialog *publishdlg = new PublishDialog();
3955 if ( publishdlg->exec() == QDialog::Accepted ) { 3975 if ( publishdlg->exec() == QDialog::Accepted ) {
3956 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3976 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3957 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3977 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3958 delete(freebusy); 3978 delete(freebusy);
3959 } 3979 }
3960 } 3980 }
3961 delete publishdlg; 3981 delete publishdlg;
3962} 3982}
3963 3983
3964void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3984void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3965{ 3985{
3966 Event *event = 0; 3986 Event *event = 0;
3967 Todo *todo = 0; 3987 Todo *todo = 0;
3968 3988
3969 if (incidence == 0) { 3989 if (incidence == 0) {
3970 incidence = mViewManager->currentView()->selectedIncidences().first(); 3990 incidence = mViewManager->currentView()->selectedIncidences().first();
3971 if (incidence == 0) { 3991 if (incidence == 0) {
3972 incidence = mTodoList->selectedIncidences().first(); 3992 incidence = mTodoList->selectedIncidences().first();
3973 } 3993 }
3974 } 3994 }
3975 if ( incidence && incidence->typeID() == eventID ) { 3995 if ( incidence && incidence->typeID() == eventID ) {
3976 event = static_cast<Event *>(incidence); 3996 event = static_cast<Event *>(incidence);
3977 } 3997 }
3978 if ( incidence && incidence->typeID() == todoID ) { 3998 if ( incidence && incidence->typeID() == todoID ) {
3979 todo = static_cast<Todo *>(incidence); 3999 todo = static_cast<Todo *>(incidence);
3980 } 4000 }
3981 4001
3982 if (!event && !todo) { 4002 if (!event && !todo) {
3983 KMessageBox::sorry(this,i18n("No event selected.")); 4003 KMessageBox::sorry(this,i18n("No event selected."));
3984 return; 4004 return;
3985 } 4005 }
3986 4006
3987 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 4007 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3988 KMessageBox::sorry(this,i18n("The event has no attendees.")); 4008 KMessageBox::sorry(this,i18n("The event has no attendees."));
3989 return; 4009 return;
3990 } 4010 }
3991 4011
3992 Event *ev = 0; 4012 Event *ev = 0;
3993 if (event) ev = new Event(*event); 4013 if (event) ev = new Event(*event);
3994 Todo *to = 0; 4014 Todo *to = 0;
3995 if (todo) to = new Todo(*todo); 4015 if (todo) to = new Todo(*todo);
3996 4016
3997 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 4017 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3998 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 4018 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3999 if (!me) { 4019 if (!me) {
4000 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 4020 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
4001 return; 4021 return;
4002 } 4022 }
4003 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 4023 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
4004 StatusDialog *statdlg = new StatusDialog(this); 4024 StatusDialog *statdlg = new StatusDialog(this);
4005 if (!statdlg->exec()==QDialog::Accepted) return; 4025 if (!statdlg->exec()==QDialog::Accepted) return;
4006 me->setStatus( statdlg->status() ); 4026 me->setStatus( statdlg->status() );
4007 delete(statdlg); 4027 delete(statdlg);
4008 } 4028 }
4009 Attendee *menew = new Attendee(*me); 4029 Attendee *menew = new Attendee(*me);
4010 if (ev) { 4030 if (ev) {
4011 ev->clearAttendees(); 4031 ev->clearAttendees();
4012 ev->addAttendee(menew,false); 4032 ev->addAttendee(menew,false);
4013 } else { 4033 } else {
4014 if (to) { 4034 if (to) {
4015 todo->clearAttendees(); 4035 todo->clearAttendees();
4016 todo->addAttendee(menew,false); 4036 todo->addAttendee(menew,false);
4017 } 4037 }
4018 } 4038 }
4019 } 4039 }
4020 4040
4021 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 4041 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
4022 if (ev) { 4042 if (ev) {
4023 if ( !dlg->addMessage(ev,method) ) delete(ev); 4043 if ( !dlg->addMessage(ev,method) ) delete(ev);
4024 } else { 4044 } else {
4025 if (to) { 4045 if (to) {
4026 if ( !dlg->addMessage(to,method) ) delete(to); 4046 if ( !dlg->addMessage(to,method) ) delete(to);
4027 } 4047 }
4028 } 4048 }
4029} 4049}
4030 4050
4031void CalendarView::openAddressbook() 4051void CalendarView::openAddressbook()
4032{ 4052{
4033 KRun::runCommand("kaddressbook"); 4053 KRun::runCommand("kaddressbook");
4034} 4054}
4035 4055
4036void CalendarView::setModified(bool modified) 4056void CalendarView::setModified(bool modified)
4037{ 4057{
4038 if ( modified ) 4058 if ( modified )
4039 emit signalmodified(); 4059 emit signalmodified();
4040 if (mModified != modified) { 4060 if (mModified != modified) {
4041 mModified = modified; 4061 mModified = modified;
4042 emit modifiedChanged(mModified); 4062 emit modifiedChanged(mModified);
4043 } 4063 }
4044} 4064}
4045 4065
4046bool CalendarView::isReadOnly() 4066bool CalendarView::isReadOnly()
4047{ 4067{
4048 return mReadOnly; 4068 return mReadOnly;
4049} 4069}
4050 4070
4051void CalendarView::setReadOnly(bool readOnly) 4071void CalendarView::setReadOnly(bool readOnly)
4052{ 4072{
4053 if (mReadOnly != readOnly) { 4073 if (mReadOnly != readOnly) {
4054 mReadOnly = readOnly; 4074 mReadOnly = readOnly;
4055 emit readOnlyChanged(mReadOnly); 4075 emit readOnlyChanged(mReadOnly);
4056 } 4076 }
4057} 4077}
4058 4078
4059bool CalendarView::isModified() 4079bool CalendarView::isModified()
4060{ 4080{
4061 return mModified; 4081 return mModified;
4062} 4082}
4063void CalendarView::slotprintSelInc() 4083void CalendarView::slotprintSelInc()
4064{ 4084{
4065 if ( currentSelection() == 0 ) { 4085 if ( currentSelection() == 0 ) {
4066 KMessageBox::sorry(this,i18n("There is nothing selected!")); 4086 KMessageBox::sorry(this,i18n("There is nothing selected!"));
4067 return; 4087 return;
4068 } 4088 }
4069 showIncidence(); 4089 showIncidence();
4070 getEventViewerDialog()->print(); 4090 getEventViewerDialog()->print();
4071 4091
4072} 4092}
4073void CalendarView::printSetup() 4093void CalendarView::printSetup()
4074{ 4094{
4075#ifndef KORG_NOPRINTER 4095#ifndef KORG_NOPRINTER
4076 createPrinter(); 4096 createPrinter();
4077 4097
4078 mCalPrinter->setupPrinter(); 4098 mCalPrinter->setupPrinter();
4079#endif 4099#endif
4080} 4100}
4081 4101
4082void CalendarView::print() 4102void CalendarView::print()
4083{ 4103{
4084#ifndef KORG_NOPRINTER 4104#ifndef KORG_NOPRINTER
4085 createPrinter(); 4105 createPrinter();
4086 4106
4087 DateList tmpDateList = mNavigator->selectedDates(); 4107 DateList tmpDateList = mNavigator->selectedDates();
4088 mCalPrinter->print(CalPrinter::Month, 4108 mCalPrinter->print(CalPrinter::Month,
4089 tmpDateList.first(), tmpDateList.last()); 4109 tmpDateList.first(), tmpDateList.last());
4090#endif 4110#endif
4091} 4111}
4092 4112
4093void CalendarView::printPreview() 4113void CalendarView::printPreview()
4094{ 4114{
4095#ifndef KORG_NOPRINTER 4115#ifndef KORG_NOPRINTER
4096 kdDebug() << "CalendarView::printPreview()" << endl; 4116 kdDebug() << "CalendarView::printPreview()" << endl;
4097 4117
4098 createPrinter(); 4118 createPrinter();
4099 4119
4100 DateList tmpDateList = mNavigator->selectedDates(); 4120 DateList tmpDateList = mNavigator->selectedDates();
4101 4121
4102 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 4122 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
4103 tmpDateList.last()); 4123 tmpDateList.last());
4104#endif 4124#endif
4105} 4125}
4106 4126
4107void CalendarView::exportICalendar() 4127void CalendarView::exportICalendar()
4108{ 4128{
4109 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 4129 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
4110 4130
4111 // Force correct extension 4131 // Force correct extension
4112 if (filename.right(4) != ".ics") filename += ".ics"; 4132 if (filename.right(4) != ".ics") filename += ".ics";
4113 4133
4114 FileStorage storage( mCalendar, filename, new ICalFormat() ); 4134 FileStorage storage( mCalendar, filename, new ICalFormat() );
4115 storage.save(); 4135 storage.save();
4116} 4136}
4117 4137
4118bool CalendarView::exportVCalendar( QString filename ) 4138bool CalendarView::exportVCalendar( QString filename )
4119{ 4139{
4120 if (mCalendar->journals().count() > 0) { 4140 if (mCalendar->journals().count() > 0) {
4121 int result = KMessageBox::warningContinueCancel(this, 4141 int result = KMessageBox::warningContinueCancel(this,
4122 i18n("The journal entries can not be\nexported to a vCalendar file."), 4142 i18n("The journal entries can not be\nexported to a vCalendar file."),
4123 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 4143 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
4124 true); 4144 true);
4125 if (result != KMessageBox::Continue) return false; 4145 if (result != KMessageBox::Continue) return false;
4126 } 4146 }
4127 4147
4128 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 4148 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
4129 4149
4130 // Force correct extension 4150 // Force correct extension
4131 if (filename.right(4) != ".vcs") filename += ".vcs"; 4151 if (filename.right(4) != ".vcs") filename += ".vcs";
4132 4152
4133 FileStorage storage( mCalendar, filename, new VCalFormat ); 4153 FileStorage storage( mCalendar, filename, new VCalFormat );
4134 return storage.save(); 4154 return storage.save();
diff --git a/korganizer/calendarview.h b/korganizer/calendarview.h
index 706d05d..799c297 100644
--- a/korganizer/calendarview.h
+++ b/korganizer/calendarview.h
@@ -1,666 +1,667 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2000, 2001 3 Copyright (c) 2000, 2001
4 Cornelius Schumacher <schumacher@kde.org> 4 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution. 22 without including the source code for Qt in the source distribution.
23*/ 23*/
24#ifndef CALENDARVIEW_H 24#ifndef CALENDARVIEW_H
25#define CALENDARVIEW_H 25#define CALENDARVIEW_H
26 26
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qwidget.h> 29#include <qwidget.h>
30#include <qptrlist.h> 30#include <qptrlist.h>
31#include <qvbox.h> 31#include <qvbox.h>
32#include <qmap.h> 32#include <qmap.h>
33#include <qscrollbar.h> 33#include <qscrollbar.h>
34#ifndef DESKTOP_VERSION 34#ifndef DESKTOP_VERSION
35#include <qtopia/ir.h> 35#include <qtopia/ir.h>
36#else 36#else
37#define Ir char 37#define Ir char
38#endif 38#endif
39#include <libkcal/calendar.h> 39#include <libkcal/calendar.h>
40#include <libkcal/scheduler.h> 40#include <libkcal/scheduler.h>
41#include <libkcal/calendarresources.h> 41#include <libkcal/calendarresources.h>
42#include <libkcal/resourcecalendar.h> 42#include <libkcal/resourcecalendar.h>
43#include <KDGanttMinimizeSplitter.h> 43#include <KDGanttMinimizeSplitter.h>
44 44
45#include <korganizer/calendarviewbase.h> 45#include <korganizer/calendarviewbase.h>
46 46
47#include <ksyncmanager.h> 47#include <ksyncmanager.h>
48//#include <koprefs.h> 48//#include <koprefs.h>
49 49
50class QWidgetStack; 50class QWidgetStack;
51class QSplitter; 51class QSplitter;
52class KopiCalendarFile; 52class KopiCalendarFile;
53class CalPrinter; 53class CalPrinter;
54class KOFilterView; 54class KOFilterView;
55class KOCalEditView; 55class KOCalEditView;
56class KOViewManager; 56class KOViewManager;
57class KODialogManager; 57class KODialogManager;
58class KOTodoView; 58class KOTodoView;
59class KDateNavigator; 59class KDateNavigator;
60class DateNavigatorContainer; 60class DateNavigatorContainer;
61class DateNavigator; 61class DateNavigator;
62class KOIncidenceEditor; 62class KOIncidenceEditor;
63class KDatePicker; 63class KDatePicker;
64class ResourceView; 64class ResourceView;
65class KOEventEditor; 65class KOEventEditor;
66class KOTodoEditor ; 66class KOTodoEditor ;
67class KOEventViewerDialog; 67class KOEventViewerDialog;
68class KOBeamPrefs; 68class KOBeamPrefs;
69class KSyncProfile; 69class KSyncProfile;
70class AlarmDialog; 70class AlarmDialog;
71class KCal::Attendee; 71class KCal::Attendee;
72 72
73namespace KCal { class FileStorage; } 73namespace KCal { class FileStorage; }
74 74
75using namespace KCal; 75using namespace KCal;
76 76
77/** 77/**
78 This is the main calendar widget. It provides the different vies on t he 78 This is the main calendar widget. It provides the different vies on t he
79 calendar data as well as the date navigator. It also handles synchronisation 79 calendar data as well as the date navigator. It also handles synchronisation
80 of the different views and controls the different dialogs like preferences, 80 of the different views and controls the different dialogs like preferences,
81 event editor, search dialog etc. 81 event editor, search dialog etc.
82 82
83 @short main calendar view widget 83 @short main calendar view widget
84 @author Cornelius Schumacher 84 @author Cornelius Schumacher
85*/ 85*/
86 86
87#include <qtextbrowser.h> 87#include <qtextbrowser.h>
88#include <qtextcodec.h> 88#include <qtextcodec.h>
89 89
90class MissedAlarmTextBrowser : public QTextBrowser { 90class MissedAlarmTextBrowser : public QTextBrowser {
91 Q_OBJECT 91 Q_OBJECT
92 public: 92 public:
93 MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms ,QDateTime start); 93 MissedAlarmTextBrowser(QWidget *parent, QPtrList<Incidence> alarms ,QDateTime start);
94 ~MissedAlarmTextBrowser(); 94 ~MissedAlarmTextBrowser();
95 void setSource(const QString & n); 95 void setSource(const QString & n);
96 96
97 private: 97 private:
98 Incidence * getNextInc(QDateTime start ); 98 Incidence * getNextInc(QDateTime start );
99 QPtrList<Incidence> mAlarms; 99 QPtrList<Incidence> mAlarms;
100 signals: 100 signals:
101 void showIncidence( QString uid); 101 void showIncidence( QString uid);
102}; 102};
103 103
104 104
105class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface 105class CalendarView : public KOrg::CalendarViewBase, public KCal::Calendar::Observer, public KSyncInterface
106{ 106{
107 Q_OBJECT 107 Q_OBJECT
108 public: 108 public:
109 /** 109 /**
110 Constructs a new calendar view widget. 110 Constructs a new calendar view widget.
111 111
112 @param calendar calendar document 112 @param calendar calendar document
113 @param parent parent window 113 @param parent parent window
114 @param name Qt internal widget object name 114 @param name Qt internal widget object name
115 */ 115 */
116 CalendarView( CalendarResources *calendar, QWidget *parent = 0, 116 CalendarView( CalendarResources *calendar, QWidget *parent = 0,
117 const char *name = 0 ); 117 const char *name = 0 );
118 CalendarView( Calendar *calendar, QWidget *parent = 0, 118 CalendarView( Calendar *calendar, QWidget *parent = 0,
119 const char *name = 0 ); 119 const char *name = 0 );
120 virtual ~CalendarView(); 120 virtual ~CalendarView();
121 121
122 Calendar *calendar() { return mCalendar; } 122 Calendar *calendar() { return mCalendar; }
123 123
124 KOViewManager *viewManager(); 124 KOViewManager *viewManager();
125 KODialogManager *dialogManager(); 125 KODialogManager *dialogManager();
126 126
127 QDate startDate(); 127 QDate startDate();
128 QDate endDate(); 128 QDate endDate();
129 129
130 QWidgetStack *viewStack(); 130 QWidgetStack *viewStack();
131 QWidget *leftFrame(); 131 QWidget *leftFrame();
132 132
133 DateNavigator *dateNavigator(); 133 DateNavigator *dateNavigator();
134 KDateNavigator *dateNavigatorWidget(); 134 KDateNavigator *dateNavigatorWidget();
135 135
136 void addView(KOrg::BaseView *); 136 void addView(KOrg::BaseView *);
137 void showView(KOrg::BaseView *); 137 void showView(KOrg::BaseView *);
138 KOEventViewerDialog* getEventViewerDialog(); 138 KOEventViewerDialog* getEventViewerDialog();
139 Incidence *currentSelection(); 139 Incidence *currentSelection();
140 void checkSuspendAlarm(); 140 void checkSuspendAlarm();
141 void mergeFile( QString fn );
141 142
142 signals: 143 signals:
143 void save (); 144 void save ();
144 void saveStopTimer (); 145 void saveStopTimer ();
145 void tempDisableBR(bool); 146 void tempDisableBR(bool);
146 /** This todo has been modified */ 147 /** This todo has been modified */
147 void todoModified(Todo *, int); 148 void todoModified(Todo *, int);
148 149
149 /** when change is made to options dialog, the topwidget will catch this 150 /** when change is made to options dialog, the topwidget will catch this
150 * and emit this signal which notifies all widgets which have registered 151 * and emit this signal which notifies all widgets which have registered
151 * for notification to update their settings. */ 152 * for notification to update their settings. */
152 void configChanged(); 153 void configChanged();
153 /** emitted when the topwidget is closing down, so that any attached 154 /** emitted when the topwidget is closing down, so that any attached
154 child windows can also close. */ 155 child windows can also close. */
155 void closingDown(); 156 void closingDown();
156 /** emitted right before we die */ 157 /** emitted right before we die */
157 void closed(QWidget *); 158 void closed(QWidget *);
158 159
159 /** Emitted when state of modified flag changes */ 160 /** Emitted when state of modified flag changes */
160 void modifiedChanged(bool); 161 void modifiedChanged(bool);
161 void signalmodified(); 162 void signalmodified();
162 163
163 /** Emitted when state of read-only flag changes */ 164 /** Emitted when state of read-only flag changes */
164 void readOnlyChanged(bool); 165 void readOnlyChanged(bool);
165 166
166 /** Emitted when the unit of navigation changes */ 167 /** Emitted when the unit of navigation changes */
167 void changeNavStringPrev(const QString &); 168 void changeNavStringPrev(const QString &);
168 void changeNavStringNext(const QString &); 169 void changeNavStringNext(const QString &);
169 170
170 /** Emitted when state of events selection has changed and user is organizer*/ 171 /** Emitted when state of events selection has changed and user is organizer*/
171 void organizerEventsSelected(bool); 172 void organizerEventsSelected(bool);
172 /** Emitted when state of events selection has changed and user is attendee*/ 173 /** Emitted when state of events selection has changed and user is attendee*/
173 void groupEventsSelected(bool); 174 void groupEventsSelected(bool);
174 /** 175 /**
175 Emitted when an incidence gets selected. If the selection is cleared the 176 Emitted when an incidence gets selected. If the selection is cleared the
176 signal is emitted with 0 as argument. 177 signal is emitted with 0 as argument.
177 */ 178 */
178 void incidenceSelected( Incidence * ); 179 void incidenceSelected( Incidence * );
179 /** Emitted, when a todoitem is selected or deselected. */ 180 /** Emitted, when a todoitem is selected or deselected. */
180 void todoSelected( bool ); 181 void todoSelected( bool );
181 182
182 /** 183 /**
183 Emitted, when clipboard content changes. Parameter indicates if paste 184 Emitted, when clipboard content changes. Parameter indicates if paste
184 is possible or not. 185 is possible or not.
185 */ 186 */
186 void pasteEnabled(bool); 187 void pasteEnabled(bool);
187 188
188 /** Emitted, when the number of incoming messages has changed. */ 189 /** Emitted, when the number of incoming messages has changed. */
189 void numIncomingChanged(int); 190 void numIncomingChanged(int);
190 191
191 /** Emitted, when the number of outgoing messages has changed. */ 192 /** Emitted, when the number of outgoing messages has changed. */
192 void numOutgoingChanged(int); 193 void numOutgoingChanged(int);
193 194
194 /** Send status message, which can e.g. be displayed in the status bar. */ 195 /** Send status message, which can e.g. be displayed in the status bar. */
195 void statusMessage(const QString &); 196 void statusMessage(const QString &);
196 197
197 void calendarViewExpanded( bool ); 198 void calendarViewExpanded( bool );
198 void updateSearchDialog(); 199 void updateSearchDialog();
199 void filtersUpdated(); 200 void filtersUpdated();
200 201
201 202
202 public slots: 203 public slots:
203 void nextConflict( bool all, bool allday ); 204 void nextConflict( bool all, bool allday );
204 void conflictAll(); 205 void conflictAll();
205 void conflictAllday(); 206 void conflictAllday();
206 void conflictNotAll(); 207 void conflictNotAll();
207 void setCalReadOnly( int id, bool readO ); 208 void setCalReadOnly( int id, bool readO );
208 void checkAlarms(); 209 void checkAlarms();
209 void checkFiles(); 210 void checkFiles();
210 void slotprintSelInc(); 211 void slotprintSelInc();
211 void showNextAlarms(); 212 void showNextAlarms();
212 void showOpenError(); 213 void showOpenError();
213 void watchSavedFile(); 214 void watchSavedFile();
214 void recheckTimerAlarm(); 215 void recheckTimerAlarm();
215 void checkNextTimerAlarm(); 216 void checkNextTimerAlarm();
216 void addAlarm(const QDateTime &qdt, const QString &noti ); 217 void addAlarm(const QDateTime &qdt, const QString &noti );
217 void addSuspendAlarm(const QDateTime &qdt, const QString &noti ); 218 void addSuspendAlarm(const QDateTime &qdt, const QString &noti );
218 void removeAlarm(const QDateTime &qdt, const QString &noti ); 219 void removeAlarm(const QDateTime &qdt, const QString &noti );
219 220
220 /** options dialog made a changed to the configuration. we catch this 221 /** options dialog made a changed to the configuration. we catch this
221 * and notify all widgets which need to update their configuration. */ 222 * and notify all widgets which need to update their configuration. */
222 void updateConfig(); 223 void updateConfig();
223 224
224 void insertBirthdays(const QString& uid, const QStringList& birthdayList, 225 void insertBirthdays(const QString& uid, const QStringList& birthdayList,
225 const QStringList& anniversaryList, const QStringList& realNameList, 226 const QStringList& anniversaryList, const QStringList& realNameList,
226 const QStringList& emailList, const QStringList& assembledNameList, 227 const QStringList& emailList, const QStringList& assembledNameList,
227 const QStringList& uidList); 228 const QStringList& uidList);
228 229
229 /** 230 /**
230 Load calendar from file \a filename. If \a merge is true, load 231 Load calendar from file \a filename. If \a merge is true, load
231 calendar into existing one, if it is false, clear calendar, before 232 calendar into existing one, if it is false, clear calendar, before
232 loading. Return true, if calendar could be successfully loaded. 233 loading. Return true, if calendar could be successfully loaded.
233 */ 234 */
234 bool openCalendar(QString filename, bool merge=false); 235 bool openCalendar(QString filename, bool merge=false);
235 bool loadCalendars(); 236 bool loadCalendars();
236 bool saveCalendars(); 237 bool saveCalendars();
237 bool restoreCalendarSettings(); 238 bool restoreCalendarSettings();
238 bool addCalendar( KopiCalendarFile * ); 239 bool addCalendar( KopiCalendarFile * );
239 void addCalendarId( int id ); 240 void addCalendarId( int id );
240 bool syncCalendar(QString filename,int mode = 0 ); 241 bool syncCalendar(QString filename,int mode = 0 );
241 242
242 /** 243 /**
243 Save calendar data to file. Return true if calendar could be 244 Save calendar data to file. Return true if calendar could be
244 successfully saved. 245 successfully saved.
245 */ 246 */
246 bool saveCalendar(QString filename); 247 bool saveCalendar(QString filename);
247 248
248 /** 249 /**
249 Close calendar. Clear calendar data and reset views to display an empty 250 Close calendar. Clear calendar data and reset views to display an empty
250 calendar. 251 calendar.
251 */ 252 */
252 void closeCalendar(); 253 void closeCalendar();
253 254
254 /** Archive old events of calendar */ 255 /** Archive old events of calendar */
255 void archiveCalendar(); 256 void archiveCalendar();
256 257
257 void showIncidence(); 258 void showIncidence();
258 void editIncidence(); 259 void editIncidence();
259 void editIncidenceDescription(); 260 void editIncidenceDescription();
260 void deleteIncidence(); 261 void deleteIncidence();
261 void cloneIncidence(); 262 void cloneIncidence();
262 void moveIncidence(); 263 void moveIncidence();
263 void beamIncidence(); 264 void beamIncidence();
264 void toggleCancelIncidence(); 265 void toggleCancelIncidence();
265 266
266 /** create an editeventwin with supplied date/time, and if bool is true, 267 /** create an editeventwin with supplied date/time, and if bool is true,
267 * make the event take all day. */ 268 * make the event take all day. */
268 void newEvent(QDateTime, QDateTime, bool allDay ); 269 void newEvent(QDateTime, QDateTime, bool allDay );
269 void newEvent(QDateTime, QDateTime); 270 void newEvent(QDateTime, QDateTime);
270 void newEvent(QDateTime fh); 271 void newEvent(QDateTime fh);
271 void newEvent(QDate dt); 272 void newEvent(QDate dt);
272 /** create new event without having a date hint. Takes current date as 273 /** create new event without having a date hint. Takes current date as
273 default hint. */ 274 default hint. */
274 void newEvent(); 275 void newEvent();
275 void newFloatingEvent(); 276 void newFloatingEvent();
276 277
277 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/ 278 /** Create a read-only viewer dialog for the supplied incidence. It calls the correct showXXX method*/
278 void showIncidence(Incidence *); 279 void showIncidence(Incidence *);
279 void showIncidence(QString uid); 280 void showIncidence(QString uid);
280 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/ 281 /** Create an editor for the supplied incidence. It calls the correct editXXX method*/
281 void editIncidence(Incidence *); 282 void editIncidence(Incidence *);
282 /** Delete the supplied incidence. It calls the correct deleteXXX method*/ 283 /** Delete the supplied incidence. It calls the correct deleteXXX method*/
283 void deleteIncidence(Incidence *); 284 void deleteIncidence(Incidence *);
284 void cloneIncidence(Incidence *); 285 void cloneIncidence(Incidence *);
285 void cancelIncidence(Incidence *); 286 void cancelIncidence(Incidence *);
286 /** Create an editor for the supplied event. */ 287 /** Create an editor for the supplied event. */
287 void editEvent(Event *); 288 void editEvent(Event *);
288 /** Delete the supplied event. */ 289 /** Delete the supplied event. */
289 void deleteEvent(Event *); 290 void deleteEvent(Event *);
290 /** Delete the event with the given unique ID. Returns false, if event wasn't 291 /** Delete the event with the given unique ID. Returns false, if event wasn't
291 found. */ 292 found. */
292 bool deleteEvent(const QString &uid); 293 bool deleteEvent(const QString &uid);
293 /** Create a read-only viewer dialog for the supplied event. */ 294 /** Create a read-only viewer dialog for the supplied event. */
294 void showEvent(Event *); 295 void showEvent(Event *);
295 296
296 void editJournal(Journal *); 297 void editJournal(Journal *);
297 void showJournal(Journal *); 298 void showJournal(Journal *);
298 void deleteJournal(Journal *); 299 void deleteJournal(Journal *);
299 /** Create an editor dialog for a todo */ 300 /** Create an editor dialog for a todo */
300 void editTodo(Todo *); 301 void editTodo(Todo *);
301 /** Create a read-only viewer dialog for the supplied todo */ 302 /** Create a read-only viewer dialog for the supplied todo */
302 void showTodo(Todo *); 303 void showTodo(Todo *);
303 /** create new todo */ 304 /** create new todo */
304 void newTodo(); 305 void newTodo();
305 void newTodoDateTime(QDateTime, bool allday); 306 void newTodoDateTime(QDateTime, bool allday);
306 /** create new todo with a parent todo */ 307 /** create new todo with a parent todo */
307 void newSubTodo(); 308 void newSubTodo();
308 /** create new todo with a parent todo */ 309 /** create new todo with a parent todo */
309 void newSubTodo(Todo *); 310 void newSubTodo(Todo *);
310 /** Delete todo */ 311 /** Delete todo */
311 void deleteTodo(Todo *); 312 void deleteTodo(Todo *);
312 313
313 314
314 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is 315 /** Check if clipboard contains vCalendar event. The signal pasteEnabled() is
315 * emitted as result. */ 316 * emitted as result. */
316 void checkClipboard(); 317 void checkClipboard();
317 318
318 /** using the KConfig associated with the kapp variable, read in the 319 /** using the KConfig associated with the kapp variable, read in the
319 * settings from the config file. 320 * settings from the config file.
320 */ 321 */
321 void readSettings(); 322 void readSettings();
322 323
323 /** write current state to config file. */ 324 /** write current state to config file. */
324 void writeSettings(); 325 void writeSettings();
325 326
326 /** read settings for calendar filters */ 327 /** read settings for calendar filters */
327 void readFilterSettings(KConfig *config); 328 void readFilterSettings(KConfig *config);
328 329
329 /** write settings for calendar filters */ 330 /** write settings for calendar filters */
330 void writeFilterSettings(KConfig *config); 331 void writeFilterSettings(KConfig *config);
331 332
332 /** passes on the message that an event has changed to the currently 333 /** passes on the message that an event has changed to the currently
333 * activated view so that it can make appropriate display changes. */ 334 * activated view so that it can make appropriate display changes. */
334 void changeEventDisplay(Event *, int); 335 void changeEventDisplay(Event *, int);
335 void changeIncidenceDisplay(Incidence *, int); 336 void changeIncidenceDisplay(Incidence *, int);
336 void changeTodoDisplay(Todo *, int); 337 void changeTodoDisplay(Todo *, int);
337 338
338 void eventAdded(Event *); 339 void eventAdded(Event *);
339 void eventChanged(Event *); 340 void eventChanged(Event *);
340 void eventToBeDeleted(Event *); 341 void eventToBeDeleted(Event *);
341 void eventDeleted(); 342 void eventDeleted();
342 343
343 void todoAdded(Todo *); 344 void todoAdded(Todo *);
344 void todoChanged(Todo *); 345 void todoChanged(Todo *);
345 void todoToBeDeleted(Todo *); 346 void todoToBeDeleted(Todo *);
346 void todoDeleted(); 347 void todoDeleted();
347 348
348 void updateView(const QDate &start, const QDate &end); 349 void updateView(const QDate &start, const QDate &end);
349 void updateView(); 350 void updateView();
350 void clearAllViews(); 351 void clearAllViews();
351 352
352 /** Full update of visible todo views */ 353 /** Full update of visible todo views */
353 void updateTodoViews(); 354 void updateTodoViews();
354 355
355 void updateUnmanagedViews(); 356 void updateUnmanagedViews();
356 357
357 /** cut the current appointment to the clipboard */ 358 /** cut the current appointment to the clipboard */
358 void edit_cut(); 359 void edit_cut();
359 360
360 /** copy the current appointment(s) to the clipboard */ 361 /** copy the current appointment(s) to the clipboard */
361 void edit_copy(); 362 void edit_copy();
362 363
363 /** paste the current vobject(s) in the clipboard buffer into calendar */ 364 /** paste the current vobject(s) in the clipboard buffer into calendar */
364 void edit_paste(); 365 void edit_paste();
365 366
366 /** edit viewing and configuration options. */ 367 /** edit viewing and configuration options. */
367 void edit_options(); 368 void edit_options();
368 void edit_global_options(); 369 void edit_global_options();
369 /** 370 /**
370 Functions for printing, previewing a print, and setting up printing 371 Functions for printing, previewing a print, and setting up printing
371 parameters. 372 parameters.
372 */ 373 */
373 void print(); 374 void print();
374 void printSetup(); 375 void printSetup();
375 void printPreview(); 376 void printPreview();
376 377
377 /** Export as iCalendar file */ 378 /** Export as iCalendar file */
378 void exportICalendar(); 379 void exportICalendar();
379 380
380 /** Export as vCalendar file */ 381 /** Export as vCalendar file */
381 bool exportVCalendar( QString fn); 382 bool exportVCalendar( QString fn);
382 383
383 /** pop up a dialog to show an existing appointment. */ 384 /** pop up a dialog to show an existing appointment. */
384 void appointment_show(); 385 void appointment_show();
385 /** 386 /**
386 * pop up an Appointment Dialog to edit an existing appointment.Get 387 * pop up an Appointment Dialog to edit an existing appointment.Get
387 * information on the appointment from the list of unique IDs that is 388 * information on the appointment from the list of unique IDs that is
388 * currently in the View, called currIds. 389 * currently in the View, called currIds.
389 */ 390 */
390 void appointment_edit(); 391 void appointment_edit();
391 /** 392 /**
392 * pop up dialog confirming deletion of currently selected event in the 393 * pop up dialog confirming deletion of currently selected event in the
393 * View. 394 * View.
394 */ 395 */
395 void appointment_delete(); 396 void appointment_delete();
396 397
397 /** mails the currently selected event to a particular user as a vCalendar 398 /** mails the currently selected event to a particular user as a vCalendar
398 attachment. */ 399 attachment. */
399 void action_mail(); 400 void action_mail();
400 401
401 /* frees a subtodo from it's relation */ 402 /* frees a subtodo from it's relation */
402 void todo_unsub( Todo * ); 403 void todo_unsub( Todo * );
403 void todo_resub( Todo * parent, Todo * sub ); 404 void todo_resub( Todo * parent, Todo * sub );
404 405
405 /** Take ownership of selected event. */ 406 /** Take ownership of selected event. */
406 void takeOverEvent(); 407 void takeOverEvent();
407 408
408 /** Take ownership of all events in calendar. */ 409 /** Take ownership of all events in calendar. */
409 void takeOverCalendar(); 410 void takeOverCalendar();
410 411
411 /** query whether or not the calendar is "dirty". */ 412 /** query whether or not the calendar is "dirty". */
412 bool isModified(); 413 bool isModified();
413 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */ 414 /** set the state of calendar. Modified means "dirty", i.e. needing a save. */
414 void setModified(bool modified=true); 415 void setModified(bool modified=true);
415 416
416 /** query if the calendar is read-only. */ 417 /** query if the calendar is read-only. */
417 bool isReadOnly(); 418 bool isReadOnly();
418 /** set state of calendar to read-only */ 419 /** set state of calendar to read-only */
419 void setReadOnly(bool readOnly=true); 420 void setReadOnly(bool readOnly=true);
420 421
421 void eventUpdated(Incidence *); 422 void eventUpdated(Incidence *);
422 423
423 /* iTIP scheduling actions */ 424 /* iTIP scheduling actions */
424 void schedule_publish(Incidence *incidence = 0); 425 void schedule_publish(Incidence *incidence = 0);
425 void schedule_request(Incidence *incidence = 0); 426 void schedule_request(Incidence *incidence = 0);
426 void schedule_refresh(Incidence *incidence = 0); 427 void schedule_refresh(Incidence *incidence = 0);
427 void schedule_cancel(Incidence *incidence = 0); 428 void schedule_cancel(Incidence *incidence = 0);
428 void schedule_add(Incidence *incidence = 0); 429 void schedule_add(Incidence *incidence = 0);
429 void schedule_reply(Incidence *incidence = 0); 430 void schedule_reply(Incidence *incidence = 0);
430 void schedule_counter(Incidence *incidence = 0); 431 void schedule_counter(Incidence *incidence = 0);
431 void schedule_declinecounter(Incidence *incidence = 0); 432 void schedule_declinecounter(Incidence *incidence = 0);
432 void schedule_publish_freebusy(int daysToPublish = 30); 433 void schedule_publish_freebusy(int daysToPublish = 30);
433 434
434 void openAddressbook(); 435 void openAddressbook();
435 436
436 void editFilters(); 437 void editFilters();
437 void toggleFilerEnabled(); 438 void toggleFilerEnabled();
438 QPtrList<CalFilter> filters(); 439 QPtrList<CalFilter> filters();
439 void toggleFilter(); 440 void toggleFilter();
440 void showFilter(bool visible); 441 void showFilter(bool visible);
441 void updateFilter(); 442 void updateFilter();
442 void filterEdited(); 443 void filterEdited();
443 void selectFilter( int ); 444 void selectFilter( int );
444 KOFilterView *filterView(); 445 KOFilterView *filterView();
445 446
446 void showIntro(); 447 void showIntro();
447 448
448 /** Move the curdatepient view date to today */ 449 /** Move the curdatepient view date to today */
449 void goToday(); 450 void goToday();
450 451
451 /** Move to the next date(s) in the current view */ 452 /** Move to the next date(s) in the current view */
452 void goNext(); 453 void goNext();
453 454
454 /** Move to the previous date(s) in the current view */ 455 /** Move to the previous date(s) in the current view */
455 void goPrevious(); 456 void goPrevious();
456 /** Move to the next date(s) in the current view */ 457 /** Move to the next date(s) in the current view */
457 void goNextMonth(); 458 void goNextMonth();
458 459
459 /** Move to the previous date(s) in the current view */ 460 /** Move to the previous date(s) in the current view */
460 void goPreviousMonth(); 461 void goPreviousMonth();
461 462
462 void toggleExpand(); 463 void toggleExpand();
463 void toggleDateNavigatorWidget(); 464 void toggleDateNavigatorWidget();
464 void toggleAllDaySize(); 465 void toggleAllDaySize();
465 466
466 /** Look for new messages in the inbox */ 467 /** Look for new messages in the inbox */
467 void lookForIncomingMessages(); 468 void lookForIncomingMessages();
468 /** Look for new messages in the outbox */ 469 /** Look for new messages in the outbox */
469 void lookForOutgoingMessages(); 470 void lookForOutgoingMessages();
470 471
471 void processMainViewSelection( Incidence * ); 472 void processMainViewSelection( Incidence * );
472 void processTodoListSelection( Incidence * ); 473 void processTodoListSelection( Incidence * );
473 474
474 void processIncidenceSelection( Incidence * ); 475 void processIncidenceSelection( Incidence * );
475 476
476 void purgeCompleted(); 477 void purgeCompleted();
477 bool removeCompletedSubTodos( Todo* ); 478 bool removeCompletedSubTodos( Todo* );
478 void slotCalendarChanged(); 479 void slotCalendarChanged();
479 bool importBday(); 480 bool importBday();
480 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday ); 481 bool addAnniversary( QDate data, QString name, KCal::Attendee* a , bool birthday );
481 bool importQtopia( const QString &categoriesFile, 482 bool importQtopia( const QString &categoriesFile,
482 const QString &datebookFile, 483 const QString &datebookFile,
483 const QString &tasklistFile ); 484 const QString &tasklistFile );
484 void syncExternal( int mode ); 485 void syncExternal( int mode );
485 void slotSelectPickerDate( QDate ) ; 486 void slotSelectPickerDate( QDate ) ;
486 void showDatePicker() ; 487 void showDatePicker() ;
487 void showDatePickerPopup() ; 488 void showDatePickerPopup() ;
488 void moveIncidence(Incidence *) ; 489 void moveIncidence(Incidence *) ;
489 void beamIncidence(Incidence *) ; 490 void beamIncidence(Incidence *) ;
490 void beamCalendar() ; 491 void beamCalendar() ;
491 void beamFilteredCalendar() ; 492 void beamFilteredCalendar() ;
492 void beamIncidenceList(QPtrList<Incidence>) ; 493 void beamIncidenceList(QPtrList<Incidence>) ;
493 void manageCategories(); 494 void manageCategories();
494 void editCategories(); 495 void editCategories();
495 int addCategories(); 496 int addCategories();
496 void removeCategories(); 497 void removeCategories();
497 void setSyncDevice( QString ); 498 void setSyncDevice( QString );
498 void setSyncName( QString ); 499 void setSyncName( QString );
499 void showDay( QDate ); 500 void showDay( QDate );
500 void undo_delete(); 501 void undo_delete();
501 protected slots: 502 protected slots:
502 void resetFocus(); 503 void resetFocus();
503 void scrollBarValue(int); 504 void scrollBarValue(int);
504 void slotViewerClosed(); 505 void slotViewerClosed();
505 void timerAlarm(); 506 void timerAlarm();
506 void suspendAlarm(); 507 void suspendAlarm();
507 void beamDone( Ir *ir ); 508 void beamDone( Ir *ir );
508 /** Select a view or adapt the current view to display the specified dates. */ 509 /** Select a view or adapt the current view to display the specified dates. */
509 void showDates( const KCal::DateList & ); 510 void showDates( const KCal::DateList & );
510 void selectWeekNum ( int ); 511 void selectWeekNum ( int );
511 void checkConflictForEvent(); 512 void checkConflictForEvent();
512 513
513 public: 514 public:
514 // show a standard warning 515 // show a standard warning
515 // returns KMsgBox::yesNoCancel() 516 // returns KMsgBox::yesNoCancel()
516 int msgCalModified(); 517 int msgCalModified();
517 virtual bool sync(KSyncManager* manager, QString filename, int mode); 518 virtual bool sync(KSyncManager* manager, QString filename, int mode);
518 519
519 virtual bool syncExternal(KSyncManager* manager, QString resource); 520 virtual bool syncExternal(KSyncManager* manager, QString resource);
520 virtual void removeSyncInfo( QString syncProfile); 521 virtual void removeSyncInfo( QString syncProfile);
521 void setSyncManager(KSyncManager* manager); 522 void setSyncManager(KSyncManager* manager);
522 void setLoadedFileVersion(QDateTime); 523 void setLoadedFileVersion(QDateTime);
523 bool checkFileVersion(QString fn); 524 bool checkFileVersion(QString fn);
524 bool checkAllFileVersions(); 525 bool checkAllFileVersions();
525 bool checkFileChanged(QString fn); 526 bool checkFileChanged(QString fn);
526 Event* getLastSyncEvent(); 527 Event* getLastSyncEvent();
527 /** Adapt navigation units correpsonding to step size of navigation of the 528 /** Adapt navigation units correpsonding to step size of navigation of the
528 * current view. 529 * current view.
529 */ 530 */
530 void adaptNavigationUnits(); 531 void adaptNavigationUnits();
531 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode ); 532 bool synchronizeCalendar( Calendar* local, Calendar* remote, int mode );
532 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false ); 533 int takeEvent( Incidence* local, Incidence* remote, int mode, bool full = false );
533 //Attendee* getYourAttendee(Event *event); 534 //Attendee* getYourAttendee(Event *event);
534 void setBlockShowDates( bool b ) { mBlockShowDates = b ;} 535 void setBlockShowDates( bool b ) { mBlockShowDates = b ;}
535 void setScrollBarStep(int val ); 536 void setScrollBarStep(int val );
536 537
537 protected: 538 protected:
538 Event *mConflictingEvent; 539 Event *mConflictingEvent;
539 void schedule(Scheduler::Method, Incidence *incidence = 0); 540 void schedule(Scheduler::Method, Incidence *incidence = 0);
540 541
541 // returns KMsgBox::OKCandel() 542 // returns KMsgBox::OKCandel()
542 int msgItemDelete(const QString name); 543 int msgItemDelete(const QString name);
543 void showEventEditor(); 544 void showEventEditor();
544 void showTodoEditor(); 545 void showTodoEditor();
545 Todo *selectedTodo(); 546 Todo *selectedTodo();
546 private: 547 private:
547#ifdef DESKTOP_VERSION 548#ifdef DESKTOP_VERSION
548 QScrollBar * mDateScrollBar; 549 QScrollBar * mDateScrollBar;
549#endif 550#endif
550 QDateTime mNextAlarmDateTime; 551 QDateTime mNextAlarmDateTime;
551 bool mViewerCallerIsSearchDialog; 552 bool mViewerCallerIsSearchDialog;
552 bool mBlockShowDates; 553 bool mBlockShowDates;
553 KSyncManager* mSyncManager; 554 KSyncManager* mSyncManager;
554 AlarmDialog * mAlarmDialog; 555 AlarmDialog * mAlarmDialog;
555 QString mAlarmNotification; 556 QString mAlarmNotification;
556 QString mSuspendAlarmNotification; 557 QString mSuspendAlarmNotification;
557 QTimer* mSuspendTimer; 558 QTimer* mSuspendTimer;
558 QTimer* mAlarmTimer; 559 QTimer* mAlarmTimer;
559 QTimer* mRecheckAlarmTimer; 560 QTimer* mRecheckAlarmTimer;
560 void computeAlarm( QString ); 561 void computeAlarm( QString );
561 void startAlarm( QString, QString ); 562 void startAlarm( QString, QString );
562 void setSyncEventsReadOnly(); 563 void setSyncEventsReadOnly();
563 564
564 QDateTime loadedFileVersion; 565 QDateTime loadedFileVersion;
565 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ); 566 void checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete );
566 void checkExternalId( Incidence * inc ); 567 void checkExternalId( Incidence * inc );
567 int mGlobalSyncMode; 568 int mGlobalSyncMode;
568 QString mCurrentSyncDevice; 569 QString mCurrentSyncDevice;
569 QString mCurrentSyncName; 570 QString mCurrentSyncName;
570 void init(); 571 void init();
571 int mDatePickerMode; 572 int mDatePickerMode;
572 bool mFlagEditDescription; 573 bool mFlagEditDescription;
573 QDateTime mLastCalendarSync; 574 QDateTime mLastCalendarSync;
574 void createPrinter(); 575 void createPrinter();
575 576
576 void calendarModified( bool, Calendar * ); 577 void calendarModified( bool, Calendar * );
577 578
578 CalPrinter *mCalPrinter; 579 CalPrinter *mCalPrinter;
579 580
580 QSplitter *mPanner; 581 QSplitter *mPanner;
581 QSplitter *mLeftSplitter; 582 QSplitter *mLeftSplitter;
582 KDGanttMinimizeSplitter *mLeftFrame, *mMainFrame; 583 KDGanttMinimizeSplitter *mLeftFrame, *mMainFrame;
583 QWidgetStack *mRightFrame; 584 QWidgetStack *mRightFrame;
584 585
585 KDatePicker* mDatePicker; 586 KDatePicker* mDatePicker;
586 QVBox* mDateFrame; 587 QVBox* mDateFrame;
587 588
588 DateNavigatorContainer *mDateNavigator; // widget showing small month view. 589 DateNavigatorContainer *mDateNavigator; // widget showing small month view.
589 590
590 KOFilterView *mFilterView; 591 KOFilterView *mFilterView;
591 KOCalEditView *mCalEditView; 592 KOCalEditView *mCalEditView;
592 593
593 ResourceView *mResourceView; 594 ResourceView *mResourceView;
594 595
595 // calendar object for this viewing instance 596 // calendar object for this viewing instance
596 Calendar *mCalendar; 597 Calendar *mCalendar;
597 598
598 CalendarResourceManager *mResourceManager; 599 CalendarResourceManager *mResourceManager;
599 600
600 FileStorage *mStorage; 601 FileStorage *mStorage;
601 602
602 DateNavigator *mNavigator; 603 DateNavigator *mNavigator;
603 604
604 KOViewManager *mViewManager; 605 KOViewManager *mViewManager;
605 KODialogManager *mDialogManager; 606 KODialogManager *mDialogManager;
606 607
607 // Calendar filters 608 // Calendar filters
608 QPtrList<CalFilter> mFilters; 609 QPtrList<CalFilter> mFilters;
609 610
610 // various housekeeping variables. 611 // various housekeeping variables.
611 bool mModified; // flag indicating if calendar is modified 612 bool mModified; // flag indicating if calendar is modified
612 bool mReadOnly; // flag indicating if calendar is read-only 613 bool mReadOnly; // flag indicating if calendar is read-only
613 QDate mSaveSingleDate; 614 QDate mSaveSingleDate;
614 615
615 Incidence *mSelectedIncidence; 616 Incidence *mSelectedIncidence;
616 Incidence *mMoveIncidence; 617 Incidence *mMoveIncidence;
617 QDate mMoveIncidenceOldDate; 618 QDate mMoveIncidenceOldDate;
618 KOTodoView *mTodoList; 619 KOTodoView *mTodoList;
619 KOEventEditor * mEventEditor; 620 KOEventEditor * mEventEditor;
620 KOTodoEditor * mTodoEditor; 621 KOTodoEditor * mTodoEditor;
621 KOEventViewerDialog * mEventViewerDialog; 622 KOEventViewerDialog * mEventViewerDialog;
622 void keyPressEvent ( QKeyEvent *e) ; 623 void keyPressEvent ( QKeyEvent *e) ;
623 //QMap<Incidence*,KOIncidenceEditor*> mDialogList; 624 //QMap<Incidence*,KOIncidenceEditor*> mDialogList;
624}; 625};
625 626
626 627
627class CalendarViewVisitor : public Incidence::Visitor 628class CalendarViewVisitor : public Incidence::Visitor
628{ 629{
629 public: 630 public:
630 CalendarViewVisitor() : mView( 0 ) {} 631 CalendarViewVisitor() : mView( 0 ) {}
631 632
632 bool act( Incidence *incidence, CalendarView *view ) 633 bool act( Incidence *incidence, CalendarView *view )
633 { 634 {
634 mView = view; 635 mView = view;
635 return incidence->accept( *this ); 636 return incidence->accept( *this );
636 } 637 }
637 638
638 protected: 639 protected:
639 CalendarView *mView; 640 CalendarView *mView;
640}; 641};
641 642
642class ShowIncidenceVisitor : public CalendarViewVisitor 643class ShowIncidenceVisitor : public CalendarViewVisitor
643{ 644{
644 protected: 645 protected:
645 bool visit( Event *event ) { mView->showEvent( event ); return true; } 646 bool visit( Event *event ) { mView->showEvent( event ); return true; }
646 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; } 647 bool visit( Todo *todo ) { mView->showTodo( todo ); return true; }
647 bool visit( Journal * j ) { mView->showJournal( j );return true; } 648 bool visit( Journal * j ) { mView->showJournal( j );return true; }
648}; 649};
649 650
650class EditIncidenceVisitor : public CalendarViewVisitor 651class EditIncidenceVisitor : public CalendarViewVisitor
651{ 652{
652 protected: 653 protected:
653 bool visit( Event *event ) { mView->editEvent( event ); return true; } 654 bool visit( Event *event ) { mView->editEvent( event ); return true; }
654 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; } 655 bool visit( Todo *todo ) { mView->editTodo( todo ); return true; }
655 bool visit( Journal *j ) { mView->editJournal( j); return true; } 656 bool visit( Journal *j ) { mView->editJournal( j); return true; }
656}; 657};
657 658
658class DeleteIncidenceVisitor : public CalendarViewVisitor 659class DeleteIncidenceVisitor : public CalendarViewVisitor
659{ 660{
660 protected: 661 protected:
661 bool visit( Event *event ) { mView->deleteEvent( event ); return true; } 662 bool visit( Event *event ) { mView->deleteEvent( event ); return true; }
662 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; } 663 bool visit( Todo *todo ) { mView->deleteTodo( todo ); return true; }
663 bool visit( Journal * j) {mView->deleteJournal( j ); return true; } 664 bool visit( Journal * j) {mView->deleteJournal( j ); return true; }
664}; 665};
665 666
666#endif 667#endif
diff --git a/korganizer/journalentry.cpp b/korganizer/journalentry.cpp
index b8a4cf2..f0e0f86 100644
--- a/korganizer/journalentry.cpp
+++ b/korganizer/journalentry.cpp
@@ -1,333 +1,353 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// 24//
25// Journal Entry 25// Journal Entry
26 26
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <qvbox.h> 29#include <qvbox.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qdir.h> 31#include <qdir.h>
32#include <qtextstream.h> 32#include <qtextstream.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include <qpixmap.h> 34#include <qpixmap.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qapplication.h> 36#include <qapplication.h>
37 37
38#include <kdebug.h> 38#include <kdebug.h>
39#include <kglobal.h> 39#include <kglobal.h>
40#include <klocale.h> 40#include <klocale.h>
41#include <ktextedit.h> 41#include <ktextedit.h>
42#include <kfiledialog.h> 42#include <kfiledialog.h>
43#include <kmessagebox.h> 43#include <kmessagebox.h>
44#include "koprefs.h" 44#include "koprefs.h"
45#include <klineedit.h> 45#include <klineedit.h>
46#include <kdialog.h> 46#include <kdialog.h>
47#include "kolocationbox.h" 47#include "kolocationbox.h"
48 48
49#include <libkcal/journal.h> 49#include <libkcal/journal.h>
50#include <libkcal/calendarresources.h> 50#include <libkcal/calendarresources.h>
51#include <libkcal/resourcecalendar.h> 51#include <libkcal/resourcecalendar.h>
52#include <kresources/resourceselectdialog.h> 52#include <kresources/resourceselectdialog.h>
53 53
54#include "journalentry.h" 54#include "journalentry.h"
55//#include "journalentry.moc" 55//#include "journalentry.moc"
56#ifndef DESKTOP_VERSION 56#ifndef DESKTOP_VERSION
57#include <qpe/qpeapplication.h> 57#include <qpe/qpeapplication.h>
58#endif 58#endif
59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) : 59JournalEntry::JournalEntry(Calendar *calendar,QWidget *parent) :
60 QFrame(parent) 60 QFrame(parent)
61{ 61{
62 62
63 int fac = 5; 63 int fac = 5;
64 heiHint = QApplication::desktop()->height(); 64 heiHint = QApplication::desktop()->height();
65 if ( heiHint > 800 ) 65 if ( heiHint > 800 )
66 fac += 2; 66 fac += 2;
67 heiHint = heiHint / fac; 67 heiHint = heiHint / fac;
68 68
69 showOnlyMode = false; 69 showOnlyMode = false;
70 mCalendar = calendar; 70 mCalendar = calendar;
71 mJournal = 0; 71 mJournal = 0;
72 visibleMode = true; 72 visibleMode = true;
73 QHBox * vb = new QHBox ( this ); 73 QHBox * vb = new QHBox ( this );
74 QPixmap iconp; 74 QPixmap iconp;
75 vb->setMargin ( KDialog::marginHint()-1 ); 75 vb->setMargin ( KDialog::marginHint()-1 );
76 QPushButton * toggleJournal = new QPushButton( vb ); 76 QPushButton * toggleJournal = new QPushButton( vb );
77 iconp = SmallIcon("1updownarrow"); 77 iconp = SmallIcon("1updownarrow");
78 toggleJournal->setPixmap (iconp ) ; 78 toggleJournal->setPixmap (iconp ) ;
79 vb->setStretchFactor (new QLabel(" "+i18n("Title: "),vb),1); 79 QLabel* textLabel = new QLabel(" "+i18n("Title: "),vb);
80 vb->setStretchFactor (textLabel,1);
80 vb->setStretchFactor( toggleJournal, 1 ); 81 vb->setStretchFactor( toggleJournal, 1 );
81 mTitle = new KOLocationBox(TRUE, vb, 30); 82 mTitle = new KOLocationBox(TRUE, vb, 30);
82 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); 83 mTitle->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
83 mCalendarBox = new QComboBox(vb); 84 mCalendarBox = new QComboBox(vb);
84 mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) ); 85 mCalendarBox->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding ,QSizePolicy::Fixed ,FALSE) );
85#ifndef DESKTOP_VERSION 86#ifndef DESKTOP_VERSION
86 mTitle->setSizeLimit( 8 ); 87 mTitle->setSizeLimit( 8 );
87 mCalendarBox->setSizeLimit( 8 ); 88 mCalendarBox->setSizeLimit( 8 );
88#endif 89#endif
89 vb->setStretchFactor ( mTitle, 8 ); 90 vb->setStretchFactor ( mTitle, 8 );
90 vb->setStretchFactor ( mCalendarBox, 3 ); 91 vb->setStretchFactor ( mCalendarBox, 3 );
91 //mTitleLabel->setMargin(0); 92 //mTitleLabel->setMargin(0);
92 //mTitleLabel->setAlignment(AlignCenter); 93 //mTitleLabel->setAlignment(AlignCenter);
93 QPushButton * loadTemplate = new QPushButton( vb ); 94 QPushButton * loadTemplate = new QPushButton( vb );
94 QPushButton * saveTemplate = new QPushButton( vb ); 95 QPushButton * saveTemplate = new QPushButton( vb );
95 if ( QApplication::desktop()->width() < 321 ) 96 if ( QApplication::desktop()->width() < 321 )
96 iconp = SmallIcon("fileexport16"); 97 iconp = SmallIcon("fileexport16");
97 else 98 else
98 iconp = SmallIcon("fileexport"); 99 iconp = SmallIcon("fileexport");
99 saveTemplate->setPixmap (iconp ) ; 100 saveTemplate->setPixmap (iconp ) ;
100 int size = saveTemplate->sizeHint().height(); 101 int size = saveTemplate->sizeHint().height();
101 if ( QApplication::desktop()->width() < 321 ) 102 if ( QApplication::desktop()->width() < 321 )
102 iconp = SmallIcon("fileimport16"); 103 iconp = SmallIcon("fileimport16");
103 else 104 else
104 iconp = SmallIcon("fileimport"); 105 iconp = SmallIcon("fileimport");
105 loadTemplate->setPixmap (iconp ) ; 106 loadTemplate->setPixmap (iconp ) ;
106 loadTemplate->setFixedSize( size, size ); 107 loadTemplate->setFixedSize( size, size );
107 saveTemplate->setFixedSize( size, size ); 108 saveTemplate->setFixedSize( size, size );
108 toggleJournal->setFixedSize( size , size ); 109 toggleJournal->setFixedSize( size , size );
109 mTitle->setFixedHeight( size+4); 110 mTitle->setFixedHeight( size+4);
110 mCalendarBox->setFixedHeight( size+4); 111 mCalendarBox->setFixedHeight( size+4);
111 mEditor = new KTextEdit(this); 112 mEditor = new KTextEdit(this);
112#ifndef DESKTOP_VERSION 113#ifndef DESKTOP_VERSION
113 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold ); 114 QPEApplication::setStylusOperation( mEditor, QPEApplication::RightOnHold );
114#endif 115#endif
116 mMaxWidDiff = 3*size - 2*frameWidth() - textLabel->sizeHint().width();
117 mDeskWid = QApplication::desktop()->width();
118 int maxwid = mDeskWid - mMaxWidDiff;
119 mTitle->setMaximumWidth( maxwid/2 +20 );
120 mCalendarBox->setMaximumWidth( maxwid/2 -20 );
115 mEditor->setWordWrap( KTextEdit::WidgetWidth ); 121 mEditor->setWordWrap( KTextEdit::WidgetWidth );
116 QBoxLayout *topLayout = new QVBoxLayout(this); 122 QBoxLayout *topLayout = new QVBoxLayout(this);
117 topLayout->addWidget(vb); 123 topLayout->addWidget(vb);
118 topLayout->addWidget(mEditor); 124 topLayout->addWidget(mEditor);
119 mEditor->installEventFilter(this); 125 mEditor->installEventFilter(this);
120 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) ); 126 connect( saveTemplate, SIGNAL( clicked() ), this , SLOT( slotSaveTemplate() ) );
121 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) ); 127 connect( loadTemplate, SIGNAL( clicked() ), this , SLOT( slotLoadTemplate() ) );
122 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) ); 128 connect( toggleJournal, SIGNAL( clicked() ), this , SLOT( toggleShowJournal() ) );
123 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 129 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
124 mTitle->lineEdit ()->setText(""); 130 mTitle->lineEdit ()->setText("");
125} 131}
126 132
127JournalEntry::~JournalEntry() 133JournalEntry::~JournalEntry()
128{ 134{
129 //qDebug("JournalEntry::~JournalEntry() "); 135 //qDebug("JournalEntry::~JournalEntry() ");
130} 136}
137void JournalEntry::resizeEvent(QResizeEvent* e )
138{
139#ifndef DESKTOP_VERSION
140 if ( mDeskWid != QApplication::desktop()->width() ) {
141 mDeskWid == QApplication::desktop()->width();
142 int maxwid = mDeskWid - mMaxWidDiff;
143 mTitle->setMaximumWidth( maxwid/2 +20 );
144 mCalendarBox->setMaximumWidth( maxwid/2 -20 );
145 }
146 setMaximumWidth( QApplication::desktop()->width() );
147 qDebug("MAXXX %d ", QApplication::desktop()->width());
148#endif
149 QFrame::resizeEvent( e );
150}
131QSize JournalEntry::sizeHint() const 151QSize JournalEntry::sizeHint() const
132{ 152{
133 return QSize ( 240, heiHint ); 153 return QSize ( 240, heiHint );
134} 154}
135void JournalEntry::slotSaveTemplate() 155void JournalEntry::slotSaveTemplate()
136{ 156{
137 QString fileName =locateLocal( "templates", "journals" ); 157 QString fileName =locateLocal( "templates", "journals" );
138 QDir t_dir; 158 QDir t_dir;
139 if ( !t_dir.exists(fileName) ) 159 if ( !t_dir.exists(fileName) )
140 t_dir.mkdir ( fileName ); 160 t_dir.mkdir ( fileName );
141 fileName += "/journal"; 161 fileName += "/journal";
142 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this ); 162 fileName = KFileDialog::getSaveFileName( fileName , i18n("Save as Journal template"), this );
143 if ( fileName.length() == 0 ) 163 if ( fileName.length() == 0 )
144 return; 164 return;
145 165
146 QFile fileIn( fileName ); 166 QFile fileIn( fileName );
147 if (!fileIn.open( IO_WriteOnly ) ) { 167 if (!fileIn.open( IO_WriteOnly ) ) {
148 KMessageBox::error( this, i18n("Error saving template file\n '%1'.") 168 KMessageBox::error( this, i18n("Error saving template file\n '%1'.")
149 .arg( fileName ) ); 169 .arg( fileName ) );
150 return; 170 return;
151 } 171 }
152 // QString text; 172 // QString text;
153 QTextStream tsIn( &fileIn ); 173 QTextStream tsIn( &fileIn );
154 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 174 tsIn.setCodec( QTextCodec::codecForName("utf8") );
155 tsIn << mEditor->text(); 175 tsIn << mEditor->text();
156 fileIn.close(); 176 fileIn.close();
157} 177}
158void JournalEntry::slotLoadTemplate() 178void JournalEntry::slotLoadTemplate()
159{ 179{
160 QString fileName =locateLocal( "templates", "journals" ); 180 QString fileName =locateLocal( "templates", "journals" );
161 QDir t_dir; 181 QDir t_dir;
162 if ( !t_dir.exists(fileName) ) 182 if ( !t_dir.exists(fileName) )
163 t_dir.mkdir ( fileName ); 183 t_dir.mkdir ( fileName );
164 fileName += "/journal"; 184 fileName += "/journal";
165 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this ); 185 fileName = KFileDialog::getOpenFileName( fileName , i18n("Insert Journal template"), this );
166 if ( fileName.length() == 0 ) 186 if ( fileName.length() == 0 )
167 return; 187 return;
168 QFile fileIn( fileName ); 188 QFile fileIn( fileName );
169 if (!fileIn.open( IO_ReadOnly ) ) { 189 if (!fileIn.open( IO_ReadOnly ) ) {
170 KMessageBox::error( this, i18n("Error loading template file\n '%1'.") 190 KMessageBox::error( this, i18n("Error loading template file\n '%1'.")
171 .arg( fileName ) ); 191 .arg( fileName ) );
172 return; 192 return;
173 } 193 }
174 QTextStream tsIn( &fileIn ); 194 QTextStream tsIn( &fileIn );
175 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 195 tsIn.setCodec( QTextCodec::codecForName("utf8") );
176 QString text = tsIn.read(); 196 QString text = tsIn.read();
177 fileIn.close(); 197 fileIn.close();
178 int line, col; 198 int line, col;
179 mEditor->getCursorPosition (& line, & col ); 199 mEditor->getCursorPosition (& line, & col );
180 mEditor-> insertAt ( text, line, col, true ); 200 mEditor-> insertAt ( text, line, col, true );
181 //mEditor->setIgnoreMark( true ); 201 //mEditor->setIgnoreMark( true );
182} 202}
183void JournalEntry::setDate(const QDate &date) 203void JournalEntry::setDate(const QDate &date)
184{ 204{
185 showOnlyMode = false; 205 showOnlyMode = false;
186 writeJournal(); 206 writeJournal();
187 mDate = date; 207 mDate = date;
188 fillCalendar( mCalendar->defaultCalendar() ); 208 fillCalendar( mCalendar->defaultCalendar() );
189} 209}
190void JournalEntry::fillCalendar( int setToID ) 210void JournalEntry::fillCalendar( int setToID )
191{ 211{
192 mCalendarBox->clear(); 212 mCalendarBox->clear();
193 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first(); 213 KopiCalendarFile * kkf = KOPrefs::instance()->mCalendars.first();
194 int std = 0; 214 int std = 0;
195 int count = 0; 215 int count = 0;
196 while ( kkf ) { 216 while ( kkf ) {
197 if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) { 217 if ( (!kkf->mErrorOnLoad &&! kkf->isReadOnly) || setToID == kkf->mCalNumber ) {
198 if ( setToID ) { 218 if ( setToID ) {
199 if ( kkf->mCalNumber == setToID ) 219 if ( kkf->mCalNumber == setToID )
200 std = count; 220 std = count;
201 } else { 221 } else {
202 if ( kkf->isStandard ) { 222 if ( kkf->isStandard ) {
203 std = count; 223 std = count;
204 } 224 }
205 } 225 }
206 ++count; 226 ++count;
207 mCalendarBox->insertItem( kkf->mName ); 227 mCalendarBox->insertItem( kkf->mName );
208 } 228 }
209 kkf = KOPrefs::instance()->mCalendars.next(); 229 kkf = KOPrefs::instance()->mCalendars.next();
210 } 230 }
211 mCalendarBox->setCurrentItem( std ); 231 mCalendarBox->setCurrentItem( std );
212} 232}
213 233
214void JournalEntry::toggleShowJournal() 234void JournalEntry::toggleShowJournal()
215{ 235{
216 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty()) 236 if (!mEditor->text().isEmpty() || !mTitle->currentText ().isEmpty())
217 flushEntry(); 237 flushEntry();
218 if ( showOnlyMode ) 238 if ( showOnlyMode )
219 emit showJournalOnly( 0 ); 239 emit showJournalOnly( 0 );
220 else { 240 else {
221 // we have to protect mJournal from deleting if mJournal has empty text 241 // we have to protect mJournal from deleting if mJournal has empty text
222 visibleMode = false; // set to true via :setShowOnly() 242 visibleMode = false; // set to true via :setShowOnly()
223 emit showJournalOnly( mJournal ); 243 emit showJournalOnly( mJournal );
224 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) ); 244 //QTimer::singleShot( 0, this, SLOT( setVisibleOn() ) );
225 } 245 }
226} 246}
227void JournalEntry::setVisibleOn() 247void JournalEntry::setVisibleOn()
228{ 248{
229 visibleMode = true; 249 visibleMode = true;
230} 250}
231void JournalEntry::setShowOnly() 251void JournalEntry::setShowOnly()
232{ 252{
233 showOnlyMode = true; 253 showOnlyMode = true;
234 if ( mTitle->currentText().isEmpty() ) 254 if ( mTitle->currentText().isEmpty() )
235 mTitle->setFocus(); 255 mTitle->setFocus();
236 else 256 else
237 mEditor->setFocus(); 257 mEditor->setFocus();
238} 258}
239void JournalEntry::setJournal(Journal *journal, bool saveJournal ) 259void JournalEntry::setJournal(Journal *journal, bool saveJournal )
240{ 260{
241 if ( saveJournal ) 261 if ( saveJournal )
242 writeJournal(); 262 writeJournal();
243 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 263 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
244 264
245 mJournal = journal; 265 mJournal = journal;
246 if ( journal->isReadOnly() ) 266 if ( journal->isReadOnly() )
247 mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")"); 267 mTitle->lineEdit ()->setText(mJournal->summary()+" ("+i18n("readonly")+")");
248 else 268 else
249 mTitle->lineEdit ()->setText(mJournal->summary()); 269 mTitle->lineEdit ()->setText(mJournal->summary());
250 mEditor->setText(mJournal->description()); 270 mEditor->setText(mJournal->description());
251 mTitle->setEnabled (!journal->isReadOnly() ); 271 mTitle->setEnabled (!journal->isReadOnly() );
252 mEditor->setReadOnly ( journal->isReadOnly() ); 272 mEditor->setReadOnly ( journal->isReadOnly() );
253 mCalendarBox->setEnabled (!journal->isReadOnly() ); 273 mCalendarBox->setEnabled (!journal->isReadOnly() );
254 fillCalendar( mJournal->calID() ); 274 fillCalendar( mJournal->calID() );
255} 275}
256 276
257Journal *JournalEntry::journal() const 277Journal *JournalEntry::journal() const
258{ 278{
259 return mJournal; 279 return mJournal;
260} 280}
261 281
262 282
263void JournalEntry::clear() 283void JournalEntry::clear()
264{ 284{
265 mJournal = 0; 285 mJournal = 0;
266 mEditor->setText(""); 286 mEditor->setText("");
267 mTitle->load( KOLocationBox::SUMMARYJOURNAL ); 287 mTitle->load( KOLocationBox::SUMMARYJOURNAL );
268 mTitle->lineEdit ()->setText(""); 288 mTitle->lineEdit ()->setText("");
269} 289}
270 290
271bool JournalEntry::eventFilter( QObject *o, QEvent *e ) 291bool JournalEntry::eventFilter( QObject *o, QEvent *e )
272{ 292{
273// kdDebug() << "JournalEntry::event received " << e->type() << endl; 293// kdDebug() << "JournalEntry::event received " << e->type() << endl;
274 294
275 if ( e->type() == QEvent::FocusOut ) { 295 if ( e->type() == QEvent::FocusOut ) {
276 writeJournal(); 296 writeJournal();
277 } 297 }
278 if ( e->type() == QEvent::KeyPress ) { 298 if ( e->type() == QEvent::KeyPress ) {
279 QKeyEvent * k = (QKeyEvent *) e; 299 QKeyEvent * k = (QKeyEvent *) e;
280 if ( k->state() == Qt::ControlButton ) { 300 if ( k->state() == Qt::ControlButton ) {
281 k->ignore(); 301 k->ignore();
282 //return true; 302 //return true;
283 } 303 }
284 } 304 }
285 305
286 return QFrame::eventFilter( o, e ); // standard event processing 306 return QFrame::eventFilter( o, e ); // standard event processing
287} 307}
288 308
289void JournalEntry::writeJournal() 309void JournalEntry::writeJournal()
290{ 310{
291 if ( !visibleMode ) return; 311 if ( !visibleMode ) return;
292 if ( !mTitle->isEnabled() ) return; 312 if ( !mTitle->isEnabled() ) return;
293 if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) { 313 if (mEditor->text().isEmpty() && mTitle->currentText().isEmpty()) {
294 if ( mJournal ) { 314 if ( mJournal ) {
295 Journal* j = mJournal; 315 Journal* j = mJournal;
296 mJournal = 0; 316 mJournal = 0;
297 bool conf = KOPrefs::instance()->mConfirm; 317 bool conf = KOPrefs::instance()->mConfirm;
298 KOPrefs::instance()->mConfirm = false; 318 KOPrefs::instance()->mConfirm = false;
299 emit deleteJournal(j); 319 emit deleteJournal(j);
300 KOPrefs::instance()->mConfirm = conf; 320 KOPrefs::instance()->mConfirm = conf;
301 } 321 }
302 return; 322 return;
303 } 323 }
304 324
305// kdDebug() << "JournalEntry::writeJournal()..." << endl; 325// kdDebug() << "JournalEntry::writeJournal()..." << endl;
306 326
307 if (!mJournal) { 327 if (!mJournal) {
308 mJournal = new Journal; 328 mJournal = new Journal;
309 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0))); 329 mJournal->setDtStart(QDateTime(mDate,QTime(0,0,0)));
310 mCalendar->addJournal(mJournal); 330 mCalendar->addJournal(mJournal);
311 } 331 }
312 if ( mJournal->description() != mEditor->text() ) { 332 if ( mJournal->description() != mEditor->text() ) {
313 mJournal->setDescription(mEditor->text()); 333 mJournal->setDescription(mEditor->text());
314 } 334 }
315 if ( mJournal->summary() != mTitle->currentText() ) { 335 if ( mJournal->summary() != mTitle->currentText() ) {
316 mJournal->setSummary(mTitle->currentText()); 336 mJournal->setSummary(mTitle->currentText());
317 mTitle->save(KOLocationBox::SUMMARYJOURNAL); 337 mTitle->save(KOLocationBox::SUMMARYJOURNAL);
318 } 338 }
319 int id = KOPrefs::instance()->getCalendarID( mCalendarBox->currentText() ); 339 int id = KOPrefs::instance()->getCalendarID( mCalendarBox->currentText() );
320 if ( mJournal->calID() != id ) { 340 if ( mJournal->calID() != id ) {
321 mJournal->setCalID( id ); 341 mJournal->setCalID( id );
322 } 342 }
323} 343}
324 344
325void JournalEntry::flushEntry() 345void JournalEntry::flushEntry()
326{ 346{
327 writeJournal(); 347 writeJournal();
328} 348}
329void JournalEntry::keyPressEvent ( QKeyEvent * e ) 349void JournalEntry::keyPressEvent ( QKeyEvent * e )
330{ 350{
331 e->ignore(); 351 e->ignore();
332 352
333} 353}
diff --git a/korganizer/journalentry.h b/korganizer/journalentry.h
index ed04b7c..a69846c 100644
--- a/korganizer/journalentry.h
+++ b/korganizer/journalentry.h
@@ -1,86 +1,89 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23#ifndef JOURNALENTRY_H 23#ifndef JOURNALENTRY_H
24#define JOURNALENTRY_H 24#define JOURNALENTRY_H
25// 25//
26// Widget showing one Journal entry 26// Widget showing one Journal entry
27 27
28#include <qframe.h> 28#include <qframe.h>
29 29
30#include <libkcal/calendar.h> 30#include <libkcal/calendar.h>
31 31
32class QLabel; 32class QLabel;
33class KTextEdit; 33class KTextEdit;
34class QComboBox; 34class QComboBox;
35class KLineEdit; 35class KLineEdit;
36class KOLocationBox; 36class KOLocationBox;
37 37
38using namespace KCal; 38using namespace KCal;
39 39
40class JournalEntry : public QFrame { 40class JournalEntry : public QFrame {
41 Q_OBJECT 41 Q_OBJECT
42 public: 42 public:
43 JournalEntry(Calendar *,QWidget *parent); 43 JournalEntry(Calendar *,QWidget *parent);
44 virtual ~JournalEntry(); 44 virtual ~JournalEntry();
45 45
46 void setJournal(Journal *, bool saveJournal = true ); 46 void setJournal(Journal *, bool saveJournal = true );
47 Journal *journal() const; 47 Journal *journal() const;
48 48
49 void setDate(const QDate &); 49 void setDate(const QDate &);
50 50
51 void clear(); 51 void clear();
52 52
53 void flushEntry(); 53 void flushEntry();
54 void setShowOnly(); 54 void setShowOnly();
55 QSize sizeHint() const; 55 QSize sizeHint() const;
56 void setVisibleMode( bool b ) { visibleMode = b;} 56 void setVisibleMode( bool b ) { visibleMode = b;}
57 void fillCalendar( int id = 0 ); 57 void fillCalendar( int id = 0 );
58 void resizeEvent(QResizeEvent* e ) ;
58 protected slots: 59 protected slots:
59 void slotSaveTemplate(); 60 void slotSaveTemplate();
60 void slotLoadTemplate(); 61 void slotLoadTemplate();
61 void toggleShowJournal(); 62 void toggleShowJournal();
62 void setVisibleOn(); 63 void setVisibleOn();
63 signals: 64 signals:
64 void deleteJournal(Journal *); 65 void deleteJournal(Journal *);
65 void newJournal(); 66 void newJournal();
66 void showJournalOnly( Journal * ); 67 void showJournalOnly( Journal * );
67 68
68 protected: 69 protected:
69 bool eventFilter( QObject *o, QEvent *e ); 70 bool eventFilter( QObject *o, QEvent *e );
70 71
71 void writeJournal(); 72 void writeJournal();
72 73
73 private: 74 private:
75 int mMaxWidDiff;
76 int mDeskWid;
74 bool visibleMode; 77 bool visibleMode;
75 bool showOnlyMode; 78 bool showOnlyMode;
76 Calendar *mCalendar; 79 Calendar *mCalendar;
77 Journal *mJournal; 80 Journal *mJournal;
78 QDate mDate; 81 QDate mDate;
79 void keyPressEvent ( QKeyEvent * ) ; 82 void keyPressEvent ( QKeyEvent * ) ;
80 QComboBox *mCalendarBox; 83 QComboBox *mCalendarBox;
81 KOLocationBox * mTitle; 84 KOLocationBox * mTitle;
82 KTextEdit *mEditor; 85 KTextEdit *mEditor;
83 int heiHint; 86 int heiHint;
84}; 87};
85 88
86#endif 89#endif
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 5249300..4bedb61 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1779,858 +1779,858 @@ void MainWindow::importOL()
1779#ifdef _OL_IMPORT_ 1779#ifdef _OL_IMPORT_
1780 mView->clearAllViews(); 1780 mView->clearAllViews();
1781 KOImportOLdialog *id = new KOImportOLdialog("Import from OL - select folder!" , mView->calendar(),this ); 1781 KOImportOLdialog *id = new KOImportOLdialog("Import from OL - select folder!" , mView->calendar(),this );
1782 id->exec(); 1782 id->exec();
1783 delete id; 1783 delete id;
1784 mView->calendar()->checkAlarmForIncidence( 0, true ); 1784 mView->calendar()->checkAlarmForIncidence( 0, true );
1785 mView->updateView(); 1785 mView->updateView();
1786#endif 1786#endif
1787} 1787}
1788void MainWindow::importBday() 1788void MainWindow::importBday()
1789{ 1789{
1790 int result = QMessageBox::warning( this, i18n("KO/Pi import information!"), 1790 int result = QMessageBox::warning( this, i18n("KO/Pi import information!"),
1791 i18n("When importing birthdays twice\nduplicated events will be ignored,\nif the event has not been\nchanged in KO/Pi!\n"), 1791 i18n("When importing birthdays twice\nduplicated events will be ignored,\nif the event has not been\nchanged in KO/Pi!\n"),
1792 i18n("Import!"), i18n("Cancel"), 0, 1792 i18n("Import!"), i18n("Cancel"), 0,
1793 0, 1 ); 1793 0, 1 );
1794 if ( result == 0 ) { 1794 if ( result == 0 ) {
1795 mView->importBday(); 1795 mView->importBday();
1796 1796
1797 } 1797 }
1798 1798
1799 1799
1800} 1800}
1801void MainWindow::importQtopia() 1801void MainWindow::importQtopia()
1802{ 1802{
1803 //#ifndef DESKTOP_VERSION 1803 //#ifndef DESKTOP_VERSION
1804 QString mess = i18n("When importing a calendar twice\nduplicated events will be ignored!\nYou can create a backup file with\nFile - Save Calendar Backup\nto revert importing"); 1804 QString mess = i18n("When importing a calendar twice\nduplicated events will be ignored!\nYou can create a backup file with\nFile - Save Calendar Backup\nto revert importing");
1805#ifdef DESKTOP_VERSION 1805#ifdef DESKTOP_VERSION
1806 mess += i18n("The content of the following files will be\nimported (located in your home directory (hd)):\n(hd)/Applications/datebook/datebook.xml\n(hd)/Applications/todolist/todolist.xml\nThe following category file will be used:\n(hd)/Settings/Categories.xml"); 1806 mess += i18n("The content of the following files will be\nimported (located in your home directory (hd)):\n(hd)/Applications/datebook/datebook.xml\n(hd)/Applications/todolist/todolist.xml\nThe following category file will be used:\n(hd)/Settings/Categories.xml");
1807#endif 1807#endif
1808 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mess, 1808 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mess,
1809 i18n("Import!"), i18n("Cancel"), 0, 1809 i18n("Import!"), i18n("Cancel"), 0,
1810 0, 1 ); 1810 0, 1 );
1811 if ( result == 0 ) { 1811 if ( result == 0 ) {
1812#ifndef DESKTOP_VERSION 1812#ifndef DESKTOP_VERSION
1813 QString datebook = Global::applicationFileName( "datebook", "datebook.xml"); 1813 QString datebook = Global::applicationFileName( "datebook", "datebook.xml");
1814 QString todolist = Global::applicationFileName( "todolist", "todolist.xml"); 1814 QString todolist = Global::applicationFileName( "todolist", "todolist.xml");
1815 QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml"; 1815 QString categories = QString( getenv( "HOME" ) ) + "/Settings/Categories.xml";
1816#else 1816#else
1817 QString datebook = QDir::homeDirPath()+ "/Applications/datebook/datebook.xml"; 1817 QString datebook = QDir::homeDirPath()+ "/Applications/datebook/datebook.xml";
1818 QString todolist = QDir::homeDirPath()+ "/Applications/todolist/todolist.xml"; 1818 QString todolist = QDir::homeDirPath()+ "/Applications/todolist/todolist.xml";
1819 QString categories = QDir::homeDirPath()+ "/Settings/Categories.xml"; 1819 QString categories = QDir::homeDirPath()+ "/Settings/Categories.xml";
1820#endif 1820#endif
1821 mView->importQtopia( categories, datebook, todolist ); 1821 mView->importQtopia( categories, datebook, todolist );
1822 } 1822 }
1823 mView->calendar()->reInitAlarmSettings(); 1823 mView->calendar()->reInitAlarmSettings();
1824#if 0 1824#if 0
1825 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 1825 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
1826 i18n("Not supported \non desktop!\n"), 1826 i18n("Not supported \non desktop!\n"),
1827 i18n("Ok"), i18n("Cancel"), 0, 1827 i18n("Ok"), i18n("Cancel"), 0,
1828 0, 1 ); 1828 0, 1 );
1829 1829
1830#endif 1830#endif
1831} 1831}
1832 1832
1833void MainWindow::saveOnClose() 1833void MainWindow::saveOnClose()
1834{ 1834{
1835 KOPrefs *p = KOPrefs::instance(); 1835 KOPrefs *p = KOPrefs::instance();
1836 p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal ); 1836 p->mToolBarHor = ( iconToolBar->orientation () == Qt:: Horizontal );
1837 p->mToolBarHorV = ( viewToolBar->orientation () == Qt:: Horizontal ); 1837 p->mToolBarHorV = ( viewToolBar->orientation () == Qt:: Horizontal );
1838 p->mToolBarHorN = ( navigatorToolBar->orientation () == Qt:: Horizontal ); 1838 p->mToolBarHorN = ( navigatorToolBar->orientation () == Qt:: Horizontal );
1839 if ( filterToolBar ) { 1839 if ( filterToolBar ) {
1840 p->mToolBarHorF = ( filterToolBar->orientation () == Qt:: Horizontal ); 1840 p->mToolBarHorF = ( filterToolBar->orientation () == Qt:: Horizontal );
1841 } 1841 }
1842#ifdef DESKTOP_VERSION 1842#ifdef DESKTOP_VERSION
1843 1843
1844 QPoint myP; 1844 QPoint myP;
1845 myP = mapFromGlobal( iconToolBar->mapToGlobal( QPoint( 0,0) ) ); 1845 myP = mapFromGlobal( iconToolBar->mapToGlobal( QPoint( 0,0) ) );
1846 if ( p->mToolBarHor ) 1846 if ( p->mToolBarHor )
1847 p->mToolBarUp = myP.y() > height()/2; 1847 p->mToolBarUp = myP.y() > height()/2;
1848 else 1848 else
1849 p->mToolBarUp = myP.x() > width()/2; 1849 p->mToolBarUp = myP.x() > width()/2;
1850 myP = mapFromGlobal( viewToolBar->mapToGlobal( QPoint( 0,0) ) ); 1850 myP = mapFromGlobal( viewToolBar->mapToGlobal( QPoint( 0,0) ) );
1851 if ( p->mToolBarHorV ) 1851 if ( p->mToolBarHorV )
1852 p->mToolBarUpV = myP.y() > height()/2; 1852 p->mToolBarUpV = myP.y() > height()/2;
1853 else 1853 else
1854 p->mToolBarUpV = myP.x() > width()/2 ; 1854 p->mToolBarUpV = myP.x() > width()/2 ;
1855 myP = mapFromGlobal( navigatorToolBar->mapToGlobal( QPoint( 0,0) ) ); 1855 myP = mapFromGlobal( navigatorToolBar->mapToGlobal( QPoint( 0,0) ) );
1856 if ( p->mToolBarHorN ) 1856 if ( p->mToolBarHorN )
1857 p->mToolBarUpN = myP.y() > height()/2; 1857 p->mToolBarUpN = myP.y() > height()/2;
1858 else 1858 else
1859 p->mToolBarUpN = myP.x() > width()/2 ; 1859 p->mToolBarUpN = myP.x() > width()/2 ;
1860 if ( filterToolBar ) { 1860 if ( filterToolBar ) {
1861 myP = mapFromGlobal( filterToolBar->mapToGlobal( QPoint( 0,0) ) ); 1861 myP = mapFromGlobal( filterToolBar->mapToGlobal( QPoint( 0,0) ) );
1862 if ( p->mToolBarHorF ) 1862 if ( p->mToolBarHorF )
1863 p->mToolBarUpF = myP.y() > height()/2; 1863 p->mToolBarUpF = myP.y() > height()/2;
1864 else 1864 else
1865 p->mToolBarUpF = myP.x() > width()/2 ; 1865 p->mToolBarUpF = myP.x() > width()/2 ;
1866 } 1866 }
1867#else 1867#else
1868 if ( p->mToolBarHor ) 1868 if ( p->mToolBarHor )
1869 p->mToolBarUp = iconToolBar->y() > height()/2; 1869 p->mToolBarUp = iconToolBar->y() > height()/2;
1870 else 1870 else
1871 p->mToolBarUp = iconToolBar->x() > width()/2; 1871 p->mToolBarUp = iconToolBar->x() > width()/2;
1872 if ( p->mToolBarHorV ) 1872 if ( p->mToolBarHorV )
1873 p->mToolBarUpV = viewToolBar->y() > height()/2; 1873 p->mToolBarUpV = viewToolBar->y() > height()/2;
1874 else 1874 else
1875 p->mToolBarUpV = viewToolBar->x() > width()/2 ; 1875 p->mToolBarUpV = viewToolBar->x() > width()/2 ;
1876 1876
1877 if ( p->mToolBarHorN ) 1877 if ( p->mToolBarHorN )
1878 p->mToolBarUpN = navigatorToolBar->y() > height()/2; 1878 p->mToolBarUpN = navigatorToolBar->y() > height()/2;
1879 else 1879 else
1880 p->mToolBarUpN = navigatorToolBar->x() > width()/2 ; 1880 p->mToolBarUpN = navigatorToolBar->x() > width()/2 ;
1881 if ( filterToolBar ) { 1881 if ( filterToolBar ) {
1882 if ( p->mToolBarHorF ) 1882 if ( p->mToolBarHorF )
1883 p->mToolBarUpF = filterToolBar->y() > height()/2; 1883 p->mToolBarUpF = filterToolBar->y() > height()/2;
1884 else 1884 else
1885 p->mToolBarUpF = filterToolBar->x() > width()/2 ; 1885 p->mToolBarUpF = filterToolBar->x() > width()/2 ;
1886 } 1886 }
1887#endif 1887#endif
1888 save(); 1888 save();
1889 mView->writeSettings(); 1889 mView->writeSettings();
1890 mView->checkSuspendAlarm(); 1890 mView->checkSuspendAlarm();
1891} 1891}
1892void MainWindow::slotModifiedChanged( bool ) 1892void MainWindow::slotModifiedChanged( bool )
1893{ 1893{
1894 if ( mBlockAtStartup ) 1894 if ( mBlockAtStartup )
1895 return; 1895 return;
1896 1896
1897 int msec; 1897 int msec;
1898 // we store the changes after 1 minute, 1898 // we store the changes after 1 minute,
1899 // and for safety reasons after 10 minutes again 1899 // and for safety reasons after 10 minutes again
1900 if ( !mSyncManager->blockSave() ) 1900 if ( !mSyncManager->blockSave() )
1901 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; 1901 msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000;
1902 else 1902 else
1903 msec = 1000 * 600; 1903 msec = 1000 * 600;
1904 mSaveTimer.start( msec, true ); // 1 minute 1904 mSaveTimer.start( msec, true ); // 1 minute
1905 qDebug("KO: Saving File in %d secs!", msec/1000); 1905 qDebug("KO: Saving File in %d secs!", msec/1000);
1906 mCalendarModifiedFlag = true; 1906 mCalendarModifiedFlag = true;
1907} 1907}
1908void MainWindow::saveStopTimer() 1908void MainWindow::saveStopTimer()
1909{ 1909{
1910 mSaveTimer.stop(); 1910 mSaveTimer.stop();
1911} 1911}
1912void MainWindow::backupAllFiles() 1912void MainWindow::backupAllFiles()
1913{ 1913{
1914 QDate reference ( 2000,1,1); 1914 QDate reference ( 2000,1,1);
1915 int daysTo = reference.daysTo ( QDate::currentDate() ); 1915 int daysTo = reference.daysTo ( QDate::currentDate() );
1916 setCaption(i18n("Creating backup ... please wait ..." )); 1916 setCaption(i18n("Creating backup ... please wait ..." ));
1917 qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate); 1917 qDebug("KO: Last backup was %d days ago ", daysTo - KOPrefs::instance()->mLastBackupDate);
1918 // we need the file path, the backup dir and the number of bups as param 1918 // we need the file path, the backup dir and the number of bups as param
1919 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir; 1919 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
1920 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir) 1920 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
1921 bupDir = KGlobalSettings::backupDataDir(); 1921 bupDir = KGlobalSettings::backupDataDir();
1922 int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); 1922 int retval = KApplication::createBackup( defaultFileName(), bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
1923 if ( retval == 0 ) { 1923 if ( retval == 0 ) {
1924 setCaption(i18n("Backup cancelled" )); 1924 setCaption(i18n("Backup cancelled" ));
1925 qDebug("KO: Backup cancelled. Will try again tomorrow "); 1925 qDebug("KO: Backup cancelled. Will try again tomorrow ");
1926 // retval == 0 : backup skipped for today, try again tomorrow 1926 // retval == 0 : backup skipped for today, try again tomorrow
1927 KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1; 1927 KOPrefs::instance()->mLastBackupDate = daysTo- KPimGlobalPrefs::instance()->mBackupDayCount+1;
1928 } else if ( retval == 1 ){ 1928 } else if ( retval == 1 ){
1929 qDebug("KO: Backup created."); 1929 qDebug("KO: Backup created.");
1930 // backup ok 1930 // backup ok
1931 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1931 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1932 KopiCalendarFile * cal = calendars.first(); 1932 KopiCalendarFile * cal = calendars.first();
1933 cal = calendars.next(); 1933 cal = calendars.next();
1934 while ( cal ) { 1934 while ( cal ) {
1935 if ( !cal->mErrorOnLoad ) { 1935 if ( !cal->mErrorOnLoad ) {
1936 KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers ); 1936 KApplication::createBackup( cal->mFileName, bupDir, KPimGlobalPrefs::instance()->mBackupNumbers );
1937 } 1937 }
1938 cal = calendars.next(); 1938 cal = calendars.next();
1939 } 1939 }
1940 KOPrefs::instance()->mLastBackupDate = daysTo; 1940 KOPrefs::instance()->mLastBackupDate = daysTo;
1941 setCaption(i18n("Backup succesfully finished" )); 1941 setCaption(i18n("Backup succesfully finished" ));
1942 } else if ( retval == 2 ){ 1942 } else if ( retval == 2 ){
1943 setCaption(i18n("Backup globally disabled" )); 1943 setCaption(i18n("Backup globally disabled" ));
1944 qDebug("KO: Backup globally cancelled."); 1944 qDebug("KO: Backup globally cancelled.");
1945 // backup globally cancelled 1945 // backup globally cancelled
1946 KPimGlobalPrefs::instance()->mBackupEnabled = false; 1946 KPimGlobalPrefs::instance()->mBackupEnabled = false;
1947 } 1947 }
1948 // retval == 3: do nothing, try again later 1948 // retval == 3: do nothing, try again later
1949} 1949}
1950void MainWindow::save() 1950void MainWindow::save()
1951{ 1951{
1952 1952
1953 if ( mView->viewManager()->journalView() ) 1953 if ( mView->viewManager()->journalView() )
1954 mView->viewManager()->journalView()->checkModified(); 1954 mView->viewManager()->journalView()->checkModified();
1955 if ( !mCalendarModifiedFlag ) { 1955 if ( !mCalendarModifiedFlag ) {
1956 qDebug("KO: Calendar not modified. Nothing saved."); 1956 qDebug("KO: Calendar not modified. Nothing saved.");
1957 return; 1957 return;
1958 } 1958 }
1959 if ( mSyncManager->blockSave() ) 1959 if ( mSyncManager->blockSave() )
1960 return; 1960 return;
1961 mSyncManager->setBlockSave(true); 1961 mSyncManager->setBlockSave(true);
1962 if ( mView->checkAllFileVersions() ) { 1962 if ( mView->checkAllFileVersions() ) {
1963 if ( KPimGlobalPrefs::instance()->mBackupEnabled ){ 1963 if ( KPimGlobalPrefs::instance()->mBackupEnabled ){
1964 QDate reference ( 2000,1,1); 1964 QDate reference ( 2000,1,1);
1965 int daysTo = reference.daysTo ( QDate::currentDate() ); 1965 int daysTo = reference.daysTo ( QDate::currentDate() );
1966 if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) { 1966 if ( daysTo - KPimGlobalPrefs::instance()->mBackupDayCount >= KOPrefs::instance()->mLastBackupDate ) {
1967 backupAllFiles(); 1967 backupAllFiles();
1968 } 1968 }
1969 ; // KPimGlobalPrefs::instance()->mLastBackupDate 1969 ; // KPimGlobalPrefs::instance()->mLastBackupDate
1970 } 1970 }
1971 QTime neededSaveTime = QDateTime::currentDateTime().time(); 1971 QTime neededSaveTime = QDateTime::currentDateTime().time();
1972 if ( !isMinimized () ) 1972 if ( !isMinimized () )
1973 setCaption(i18n("KO/Pi:Saving Data to File ..." )); 1973 setCaption(i18n("KO/Pi:Saving Data to File ..." ));
1974 qDebug("KO: Start saving data to file!"); 1974 qDebug("KO: Start saving data to file!");
1975 mView->saveCalendars(); 1975 mView->saveCalendars();
1976 mCalendarModifiedFlag = false; 1976 mCalendarModifiedFlag = false;
1977 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() ); 1977 int msNeeded = neededSaveTime.msecsTo( QDateTime::currentDateTime().time() );
1978 qDebug("KO: Needed %d ms for saving.",msNeeded ); 1978 qDebug("KO: Needed %d ms for saving.",msNeeded );
1979 QString savemes; 1979 QString savemes;
1980 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 ); 1980 savemes.sprintf(i18n("KO/Pi:File Saved. Needed %d sec, %d ms"),(msNeeded/1000)%100,msNeeded%1000 );
1981 if ( !isMinimized () ) 1981 if ( !isMinimized () )
1982 setCaption(savemes); 1982 setCaption(savemes);
1983 else 1983 else
1984 qDebug(savemes); 1984 qDebug(savemes);
1985 } else 1985 } else
1986 setCaption(i18n("Saving cancelled!")); 1986 setCaption(i18n("Saving cancelled!"));
1987 mSyncManager->setBlockSave( false ); 1987 mSyncManager->setBlockSave( false );
1988} 1988}
1989 1989
1990void MainWindow::keyReleaseEvent ( QKeyEvent * e) 1990void MainWindow::keyReleaseEvent ( QKeyEvent * e)
1991{ 1991{
1992 if ( !e->isAutoRepeat() ) { 1992 if ( !e->isAutoRepeat() ) {
1993 mFlagKeyPressed = false; 1993 mFlagKeyPressed = false;
1994 } 1994 }
1995} 1995}
1996void MainWindow::keyPressEvent ( QKeyEvent * e ) 1996void MainWindow::keyPressEvent ( QKeyEvent * e )
1997{ 1997{
1998 qApp->processEvents(); 1998 qApp->processEvents();
1999 if ( e->isAutoRepeat() && !mFlagKeyPressed ) { 1999 if ( e->isAutoRepeat() && !mFlagKeyPressed ) {
2000 e->ignore(); 2000 e->ignore();
2001 // qDebug(" ignore %d",e->isAutoRepeat() ); 2001 // qDebug(" ignore %d",e->isAutoRepeat() );
2002 return; 2002 return;
2003 } 2003 }
2004 if (! e->isAutoRepeat() ) 2004 if (! e->isAutoRepeat() )
2005 mFlagKeyPressed = true; 2005 mFlagKeyPressed = true;
2006 KOPrefs *p = KOPrefs::instance(); 2006 KOPrefs *p = KOPrefs::instance();
2007 bool showSelectedDates = false; 2007 bool showSelectedDates = false;
2008 int size; 2008 int size;
2009 int pro = 0; 2009 int pro = 0;
2010 //qDebug("MainWindow::keyPressEvent "); 2010 //qDebug("MainWindow::keyPressEvent ");
2011 switch ( e->key() ) { 2011 switch ( e->key() ) {
2012 case Qt::Key_Right: 2012 case Qt::Key_Right:
2013 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 2013 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
2014 mView->goNextMonth(); 2014 mView->goNextMonth();
2015 else 2015 else
2016 mView->goNext(); 2016 mView->goNext();
2017 showSelectedDates = true; 2017 showSelectedDates = true;
2018 break; 2018 break;
2019 case Qt::Key_Left: 2019 case Qt::Key_Left:
2020 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 2020 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
2021 mView->goPreviousMonth(); 2021 mView->goPreviousMonth();
2022 else 2022 else
2023 mView->goPrevious(); 2023 mView->goPrevious();
2024 showSelectedDates = true; 2024 showSelectedDates = true;
2025 break; 2025 break;
2026 case Qt::Key_Down: 2026 case Qt::Key_Down:
2027 mView->viewManager()->agendaView()->scrollOneHourDown(); 2027 mView->viewManager()->agendaView()->scrollOneHourDown();
2028 break; 2028 break;
2029 case Qt::Key_Up: 2029 case Qt::Key_Up:
2030 mView->viewManager()->agendaView()->scrollOneHourUp(); 2030 mView->viewManager()->agendaView()->scrollOneHourUp();
2031 break; 2031 break;
2032 case Qt::Key_K: 2032 case Qt::Key_K:
2033 mView->viewManager()->showMonthViewWeek(); 2033 mView->viewManager()->showMonthViewWeek();
2034 break; 2034 break;
2035 case Qt::Key_I: 2035 case Qt::Key_I:
2036 mView->showIncidence(); 2036 mView->showIncidence();
2037 break; 2037 break;
2038 case Qt::Key_Delete: 2038 case Qt::Key_Delete:
2039 case Qt::Key_Backspace: 2039 case Qt::Key_Backspace:
2040 mView->deleteIncidence(); 2040 mView->deleteIncidence();
2041 break; 2041 break;
2042 case Qt::Key_D: 2042 case Qt::Key_D:
2043 mView->viewManager()->showDayView(); 2043 mView->viewManager()->showDayView();
2044 showSelectedDates = true; 2044 showSelectedDates = true;
2045 break; 2045 break;
2046 case Qt::Key_O: 2046 case Qt::Key_O:
2047 mView->toggleFilerEnabled( ); 2047 mView->toggleFilerEnabled( );
2048 break; 2048 break;
2049 case Qt::Key_0: 2049 case Qt::Key_0:
2050 case Qt::Key_1: 2050 case Qt::Key_1:
2051 case Qt::Key_2: 2051 case Qt::Key_2:
2052 case Qt::Key_3: 2052 case Qt::Key_3:
2053 case Qt::Key_4: 2053 case Qt::Key_4:
2054 case Qt::Key_5: 2054 case Qt::Key_5:
2055 case Qt::Key_6: 2055 case Qt::Key_6:
2056 case Qt::Key_7: 2056 case Qt::Key_7:
2057 case Qt::Key_8: 2057 case Qt::Key_8:
2058 case Qt::Key_9: 2058 case Qt::Key_9:
2059 pro = e->key()-48; 2059 pro = e->key()-48;
2060 if ( pro == 0 ) 2060 if ( pro == 0 )
2061 pro = 10; 2061 pro = 10;
2062 if ( e->state() == Qt::ControlButton) 2062 if ( e->state() == Qt::ControlButton)
2063 pro += 10; 2063 pro += 10;
2064 break; 2064 break;
2065 case Qt::Key_M: 2065 case Qt::Key_M:
2066 mView->viewManager()->showMonthView(); 2066 mView->viewManager()->showMonthView();
2067 showSelectedDates = true; 2067 showSelectedDates = true;
2068 break; 2068 break;
2069 case Qt::Key_Insert: 2069 case Qt::Key_Insert:
2070 mView->newEvent(); 2070 mView->newEvent();
2071 break; 2071 break;
2072 case Qt::Key_S : 2072 case Qt::Key_S :
2073 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton) 2073 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton)
2074 mView->newSubTodo(); 2074 mView->newSubTodo();
2075 else 2075 else
2076 mView->dialogManager()->showSearchDialog(); 2076 mView->dialogManager()->showSearchDialog();
2077 break; 2077 break;
2078 case Qt::Key_Y : 2078 case Qt::Key_Y :
2079 case Qt::Key_Z : 2079 case Qt::Key_Z :
2080 mView->viewManager()->showWorkWeekView(); 2080 mView->viewManager()->showWorkWeekView();
2081 showSelectedDates = true; 2081 showSelectedDates = true;
2082 break; 2082 break;
2083 case Qt::Key_U : 2083 case Qt::Key_U :
2084 mView->viewManager()->showWeekView(); 2084 mView->viewManager()->showWeekView();
2085 showSelectedDates = true; 2085 showSelectedDates = true;
2086 break; 2086 break;
2087 case Qt::Key_H : 2087 case Qt::Key_H :
2088 keyBindings(); 2088 keyBindings();
2089 break; 2089 break;
2090 case Qt::Key_W: 2090 case Qt::Key_W:
2091 mView->viewManager()->showWhatsNextView(); 2091 mView->viewManager()->showWhatsNextView();
2092 break; 2092 break;
2093 case Qt::Key_L: 2093 case Qt::Key_L:
2094 mView->viewManager()->showListView(); 2094 mView->viewManager()->showListView();
2095 break; 2095 break;
2096 case Qt::Key_N: 2096 case Qt::Key_N:
2097 mView->viewManager()->showNextView(); 2097 mView->viewManager()->showNextView();
2098 break; 2098 break;
2099 case Qt::Key_V: 2099 case Qt::Key_V:
2100 mView->viewManager()->showTodoView(); 2100 mView->viewManager()->showTodoView();
2101 break; 2101 break;
2102 case Qt::Key_C: 2102 case Qt::Key_C:
2103 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() ); 2103 mView->viewManager()->agendaView()->setStartHour( QTime::currentTime ().hour() );
2104 break; 2104 break;
2105 case Qt::Key_P: 2105 case Qt::Key_P:
2106 mView->showDatePicker( ); 2106 mView->showDatePicker( );
2107 break; 2107 break;
2108 case Qt::Key_F: 2108 case Qt::Key_F:
2109 mView->editFilters(); 2109 mView->editFilters();
2110 break; 2110 break;
2111 case Qt::Key_R: 2111 case Qt::Key_R:
2112 mView->toggleFilter(); 2112 mView->toggleFilter();
2113 break; 2113 break;
2114 case Qt::Key_X: 2114 case Qt::Key_X:
2115 if ( e->state() == Qt::ControlButton ) 2115 if ( e->state() == Qt::ControlButton )
2116 mView->toggleDateNavigatorWidget(); 2116 mView->toggleDateNavigatorWidget();
2117 else { 2117 else {
2118 mView->viewManager()->showNextXView(); 2118 mView->viewManager()->showNextXView();
2119 showSelectedDates = true; 2119 showSelectedDates = true;
2120 } 2120 }
2121 break; 2121 break;
2122 case Qt::Key_Space: 2122 case Qt::Key_Space:
2123 mView->toggleExpand(); 2123 mView->toggleExpand();
2124 break; 2124 break;
2125 case Qt::Key_A: 2125 case Qt::Key_A:
2126 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton ) 2126 if ( e->state() == Qt::ControlButton || e->state() == Qt::ShiftButton )
2127 mView->showNextAlarms(); 2127 mView->showNextAlarms();
2128 else 2128 else
2129 mView->toggleAllDaySize(); 2129 mView->toggleAllDaySize();
2130 break; 2130 break;
2131 case Qt::Key_T: 2131 case Qt::Key_T:
2132 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 2132 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
2133 mView->newTodo(); 2133 mView->newTodo();
2134 else { 2134 else {
2135 mView->goToday(); 2135 mView->goToday();
2136 showSelectedDates = true; 2136 showSelectedDates = true;
2137 } 2137 }
2138 break; 2138 break;
2139 case Qt::Key_Q: 2139 case Qt::Key_Q:
2140 if ( e->state() == Qt::ControlButton ) 2140 if ( e->state() == Qt::ControlButton )
2141 mView->conflictNotAll(); 2141 mView->conflictNotAll();
2142 else if ( e->state() == Qt::ShiftButton ) 2142 else if ( e->state() == Qt::ShiftButton )
2143 mView->conflictAllday(); 2143 mView->conflictAllday();
2144 else 2144 else
2145 mView->conflictAll(); 2145 mView->conflictAll();
2146 break; 2146 break;
2147 case Qt::Key_J: 2147 case Qt::Key_J:
2148 mView->viewManager()->showJournalView(); 2148 mView->viewManager()->showJournalView();
2149 break; 2149 break;
2150 case Qt::Key_B: 2150 case Qt::Key_B:
2151 mView->editIncidenceDescription();; 2151 mView->editIncidenceDescription();;
2152 break; 2152 break;
2153 // case Qt::Key_Return: 2153 // case Qt::Key_Return:
2154 case Qt::Key_E: 2154 case Qt::Key_E:
2155 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) 2155 if ( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton )
2156 mView->newEvent(); 2156 mView->newEvent();
2157 else 2157 else
2158 mView->editIncidence(); 2158 mView->editIncidence();
2159 break; 2159 break;
2160 case Qt::Key_Plus: 2160 case Qt::Key_Plus:
2161 size = p->mHourSize +2; 2161 size = p->mHourSize +2;
2162 if ( size <= 22 ) 2162 if ( size <= 22 )
2163 configureAgenda( size ); 2163 configureAgenda( size );
2164 break; 2164 break;
2165 case Qt::Key_Minus: 2165 case Qt::Key_Minus:
2166 size = p->mHourSize - 2; 2166 size = p->mHourSize - 2;
2167 if ( size >= 4 ) 2167 if ( size >= 4 )
2168 configureAgenda( size ); 2168 configureAgenda( size );
2169 break; 2169 break;
2170 2170
2171 2171
2172 default: 2172 default:
2173 e->ignore(); 2173 e->ignore();
2174 } 2174 }
2175 if ( pro > 0 ) { 2175 if ( pro > 0 ) {
2176 selectFilter( pro+1 ); 2176 selectFilter( pro+1 );
2177 } 2177 }
2178 if ( showSelectedDates ) { 2178 if ( showSelectedDates ) {
2179 ;// setCaptionToDates(); 2179 ;// setCaptionToDates();
2180 } 2180 }
2181 2181
2182} 2182}
2183void MainWindow::fillFilterMenuTB() 2183void MainWindow::fillFilterMenuTB()
2184{ 2184{
2185 selectFilterMenuTB->clear(); 2185 selectFilterMenuTB->clear();
2186 selectFilterMenuTB->insertItem(i18n ( "Edit Filters" ), 0 ); 2186 selectFilterMenuTB->insertItem(i18n ( "Edit Filters" ), 0 );
2187 selectFilterMenuTB->insertSeparator(); 2187 selectFilterMenuTB->insertSeparator();
2188 selectFilterMenuTB->insertItem(i18n ( "No Filter" ), 1 ); 2188 selectFilterMenuTB->insertItem(i18n ( "No Filter" ), 1 );
2189 2189
2190 selectFilterMenuTB->insertSeparator(); 2190 selectFilterMenuTB->insertSeparator();
2191 QPtrList<CalFilter> fili = mView->filters(); 2191 QPtrList<CalFilter> fili = mView->filters();
2192 CalFilter *curfilter = mView->filterView()->selectedFilter(); 2192 CalFilter *curfilter = mView->filterView()->selectedFilter();
2193 CalFilter *filter = fili.first(); 2193 CalFilter *filter = fili.first();
2194 int iii = 2; 2194 int iii = 2;
2195 bool checkitem = mView->filterView()->filtersEnabled(); 2195 bool checkitem = mView->filterView()->filtersEnabled();
2196 while(filter) { 2196 while(filter) {
2197 selectFilterMenuTB->insertItem( filter->name(), iii ); 2197 selectFilterMenuTB->insertItem( filter->name(), iii );
2198 if ( filter == curfilter) 2198 if ( filter == curfilter)
2199 selectFilterMenuTB->setItemChecked( iii, checkitem ); 2199 selectFilterMenuTB->setItemChecked( iii, checkitem );
2200 filter = fili.next(); 2200 filter = fili.next();
2201 ++iii; 2201 ++iii;
2202 } 2202 }
2203 if ( !checkitem ) 2203 if ( !checkitem )
2204 selectFilterMenuTB->setItemChecked( 1, true ); 2204 selectFilterMenuTB->setItemChecked( 1, true );
2205 2205
2206 int x = 0; 2206 int x = 0;
2207 int y = iconToolBar->height(); 2207 int y = iconToolBar->height();
2208 int dX = 0; 2208 int dX = 0;
2209 int dY = 0; 2209 int dY = 0;
2210 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 2210 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
2211 if ( iconToolBar->y() > height()/2 ) { 2211 if ( iconToolBar->y() > height()/2 ) {
2212 dY = selectFilterMenuTB->sizeHint().height()+8; 2212 dY = selectFilterMenuTB->sizeHint().height()+8;
2213 y = 0; 2213 y = 0;
2214 } 2214 }
2215 } else { 2215 } else {
2216 if ( iconToolBar->x() > width()/2 ) { // right side 2216 if ( iconToolBar->x() > width()/2 ) { // right side
2217 x=0; 2217 x=0;
2218 dX= selectFilterMenuTB->sizeHint().width()+8; 2218 dX= selectFilterMenuTB->sizeHint().width()+8;
2219 y = 0; 2219 y = 0;
2220 } else { 2220 } else {
2221 x= iconToolBar->width(); 2221 x= iconToolBar->width();
2222 y = 0; 2222 y = 0;
2223 } 2223 }
2224 } 2224 }
2225 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() ); 2225 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() );
2226 selectFilterMenuTB->popup(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY))); 2226 selectFilterMenuTB->popup(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY)));
2227} 2227}
2228void MainWindow::fillFilterMenu() 2228void MainWindow::fillFilterMenu()
2229{ 2229{
2230 selectFilterMenu->clear(); 2230 selectFilterMenu->clear();
2231 selectFilterMenu->insertItem(i18n ( "Edit Filters" ), 0 ); 2231 selectFilterMenu->insertItem(i18n ( "Edit Filters" ), 0 );
2232 selectFilterMenu->insertSeparator(); 2232 selectFilterMenu->insertSeparator();
2233 selectFilterMenu->insertItem(i18n ( "No Filter" ), 1 ); 2233 selectFilterMenu->insertItem(i18n ( "No Filter" ), 1 );
2234 2234
2235 selectFilterMenu->insertSeparator(); 2235 selectFilterMenu->insertSeparator();
2236 QPtrList<CalFilter> fili = mView->filters(); 2236 QPtrList<CalFilter> fili = mView->filters();
2237 CalFilter *curfilter = mView->filterView()->selectedFilter(); 2237 CalFilter *curfilter = mView->filterView()->selectedFilter();
2238 CalFilter *filter = fili.first(); 2238 CalFilter *filter = fili.first();
2239 int iii = 2; 2239 int iii = 2;
2240 bool checkitem = mView->filterView()->filtersEnabled(); 2240 bool checkitem = mView->filterView()->filtersEnabled();
2241 while(filter) { 2241 while(filter) {
2242 selectFilterMenu->insertItem( filter->name(), iii ); 2242 selectFilterMenu->insertItem( filter->name(), iii );
2243 if ( filter == curfilter) 2243 if ( filter == curfilter)
2244 selectFilterMenu->setItemChecked( iii, checkitem ); 2244 selectFilterMenu->setItemChecked( iii, checkitem );
2245 filter = fili.next(); 2245 filter = fili.next();
2246 ++iii; 2246 ++iii;
2247 } 2247 }
2248 if ( !checkitem ) 2248 if ( !checkitem )
2249 selectFilterMenu->setItemChecked( 1, true ); 2249 selectFilterMenu->setItemChecked( 1, true );
2250} 2250}
2251void MainWindow::fillFilterMenuPopup() 2251void MainWindow::fillFilterMenuPopup()
2252{ 2252{
2253 filterPopupMenu->clear(); 2253 filterPopupMenu->clear();
2254 filterPopupMenu->insertItem(i18n ( "No Filter" ), 0 ); 2254 filterPopupMenu->insertItem(i18n ( "No Filter" ), 0 );
2255 2255
2256 filterPopupMenu->insertSeparator(); 2256 filterPopupMenu->insertSeparator();
2257 QPtrList<CalFilter> fili = mView->filters(); 2257 QPtrList<CalFilter> fili = mView->filters();
2258 CalFilter *curfilter = mView->filterView()->selectedFilter(); 2258 CalFilter *curfilter = mView->filterView()->selectedFilter();
2259 CalFilter *filter = fili.first(); 2259 CalFilter *filter = fili.first();
2260 int iii = 1; 2260 int iii = 1;
2261 bool checkitem = mView->filterView()->filtersEnabled(); 2261 bool checkitem = mView->filterView()->filtersEnabled();
2262 while(filter) { 2262 while(filter) {
2263 filterPopupMenu->insertItem( filter->name(), iii ); 2263 filterPopupMenu->insertItem( filter->name(), iii );
2264 if ( filter == curfilter) 2264 if ( filter == curfilter)
2265 filterPopupMenu->setItemChecked( iii, checkitem ); 2265 filterPopupMenu->setItemChecked( iii, checkitem );
2266 filter = fili.next(); 2266 filter = fili.next();
2267 ++iii; 2267 ++iii;
2268 } 2268 }
2269 if ( !checkitem ) 2269 if ( !checkitem )
2270 filterPopupMenu->setItemChecked( 0, true ); 2270 filterPopupMenu->setItemChecked( 0, true );
2271} 2271}
2272void MainWindow::selectFilter( int fil ) 2272void MainWindow::selectFilter( int fil )
2273{ 2273{
2274 2274
2275 if ( fil == 0 ) { 2275 if ( fil == 0 ) {
2276 mView->editFilters( ); 2276 mView->editFilters( );
2277 } else if ( fil == 1 ){ 2277 } else if ( fil == 1 ){
2278 if ( mView->filterView()->filtersEnabled() ) 2278 if ( mView->filterView()->filtersEnabled() )
2279 mView->toggleFilerEnabled( ); 2279 mView->toggleFilerEnabled( );
2280 } else { 2280 } else {
2281 if ( !mView->filterView()->filtersEnabled() ) { 2281 if ( !mView->filterView()->filtersEnabled() ) {
2282 mView->filterView()->blockSignals( true ); 2282 mView->filterView()->blockSignals( true );
2283 mView->toggleFilerEnabled( ); 2283 mView->toggleFilerEnabled( );
2284 mView->filterView()->blockSignals( false ); 2284 mView->filterView()->blockSignals( false );
2285 } 2285 }
2286 mView->selectFilter( fil-2 ); 2286 mView->selectFilter( fil-2 );
2287 } 2287 }
2288} 2288}
2289void MainWindow::updateFilterToolbar() 2289void MainWindow::updateFilterToolbar()
2290{ 2290{
2291 if ( filterMenubar ) { 2291 if ( filterMenubar ) {
2292 if ( !mView->filterView()->filtersEnabled() ) { 2292 if ( !mView->filterView()->filtersEnabled() ) {
2293 filterMenubar->changeItem( 0, i18n("No Filter") ); 2293 filterMenubar->changeItem( 0, i18n("No Filter") );
2294 } else { 2294 } else {
2295 CalFilter *curfilter = mView->filterView()->selectedFilter(); 2295 CalFilter *curfilter = mView->filterView()->selectedFilter();
2296 if ( curfilter ) { 2296 if ( curfilter ) {
2297 filterMenubar->changeItem( 0, curfilter->name() ); 2297 filterMenubar->changeItem( 0, curfilter->name() );
2298 } 2298 }
2299 } 2299 }
2300 } 2300 }
2301} 2301}
2302void MainWindow::selectFilterPopup( int fil ) 2302void MainWindow::selectFilterPopup( int fil )
2303{ 2303{
2304 selectFilter( fil + 1 ); 2304 selectFilter( fil + 1 );
2305 2305
2306} 2306}
2307void MainWindow::configureToolBar( int item ) 2307void MainWindow::configureToolBar( int item )
2308{ 2308{
2309 2309
2310 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) ); 2310 configureToolBarMenu->setItemChecked( item, !configureToolBarMenu-> isItemChecked ( item ) );
2311 KOPrefs *p = KOPrefs::instance(); 2311 KOPrefs *p = KOPrefs::instance();
2312 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 ); 2312 p-> mShowIconStretch= configureToolBarMenu->isItemChecked( 5 );
2313 p-> mShowIconOnetoolbar = configureToolBarMenu->isItemChecked( 6 ); 2313 p-> mShowIconOnetoolbar = configureToolBarMenu->isItemChecked( 6 );
2314 p-> mShowIconFilter = configureToolBarMenu->isItemChecked( 7 ); 2314 p-> mShowIconFilter = configureToolBarMenu->isItemChecked( 7 );
2315 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 ); 2315 p-> mShowIconNewEvent= configureToolBarMenu->isItemChecked( 10 );
2316 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 ); 2316 p->mShowIconNewTodo = configureToolBarMenu->isItemChecked( 20 );
2317 p->mShowIconNavigator = configureToolBarMenu->isItemChecked( 22 ); 2317 p->mShowIconNavigator = configureToolBarMenu->isItemChecked( 22 );
2318 p->mShowIconAllday = configureToolBarMenu->isItemChecked( 24 ); 2318 p->mShowIconAllday = configureToolBarMenu->isItemChecked( 24 );
2319 p->mShowIconFilterview = configureToolBarMenu->isItemChecked( 26 ); 2319 p->mShowIconFilterview = configureToolBarMenu->isItemChecked( 26 );
2320 p->mShowIconToggleFull = configureToolBarMenu->isItemChecked( 28 ); 2320 p->mShowIconToggleFull = configureToolBarMenu->isItemChecked( 28 );
2321 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 ); 2321 p-> mShowIconSearch= configureToolBarMenu->isItemChecked( 120 );
2322 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 ); 2322 p-> mShowIconList= configureToolBarMenu->isItemChecked( 30 );
2323 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 ); 2323 p-> mShowIconDay1= configureToolBarMenu->isItemChecked( 40 );
2324 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 ); 2324 p-> mShowIconDay5= configureToolBarMenu->isItemChecked( 50 );
2325 p-> mShowIconDay6= configureToolBarMenu->isItemChecked( 75 ); 2325 p-> mShowIconDay6= configureToolBarMenu->isItemChecked( 75 );
2326 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 ); 2326 p-> mShowIconDay7= configureToolBarMenu->isItemChecked( 60 );
2327 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 ); 2327 p-> mShowIconMonth= configureToolBarMenu->isItemChecked( 70 );
2328 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 ); 2328 p-> mShowIconTodoview= configureToolBarMenu->isItemChecked( 80 );
2329 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 ); 2329 p-> mShowIconBackFast= configureToolBarMenu->isItemChecked( 200 );
2330 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 ); 2330 p-> mShowIconBack = configureToolBarMenu->isItemChecked( 210 );
2331 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 ); 2331 p-> mShowIconToday= configureToolBarMenu->isItemChecked( 130 );
2332 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 ); 2332 p-> mShowIconForward= configureToolBarMenu->isItemChecked( 220 );
2333 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 ); 2333 p-> mShowIconForwardFast= configureToolBarMenu->isItemChecked( 230 );
2334 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 ); 2334 p-> mShowIconNextDays= configureToolBarMenu->isItemChecked( 100 );
2335 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 ); 2335 p-> mShowIconNext= configureToolBarMenu->isItemChecked( 110 );
2336 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 ); 2336 p-> mShowIconJournal= configureToolBarMenu->isItemChecked( 90 );
2337 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 ); 2337 p-> mShowIconWhatsThis= configureToolBarMenu->isItemChecked( 300 );
2338 p-> mShowIconWeekNum= configureToolBarMenu->isItemChecked( 400 ); 2338 p-> mShowIconWeekNum= configureToolBarMenu->isItemChecked( 400 );
2339 // initActions(); 2339 // initActions();
2340 setCaption ( i18n("Toolbar changes needs a restart!") ); 2340 setCaption ( i18n("Toolbar changes needs a restart!") );
2341} 2341}
2342void MainWindow::setCaption ( const QString & c ) 2342void MainWindow::setCaption ( const QString & c )
2343{ 2343{
2344 QString cap = c; 2344 QString cap = c;
2345 cap.replace( QRegExp("\n"), " " ); 2345 cap.replace( QRegExp("\n"), " " );
2346 cap = cap.stripWhiteSpace(); 2346 cap = cap.stripWhiteSpace();
2347 if ( cap.isEmpty() ) 2347 if ( cap.isEmpty() )
2348 cap = "KO/Pi"; 2348 cap = "KO/Pi";
2349 QWidget::setCaption( cap ); 2349 QWidget::setCaption( cap );
2350} 2350}
2351void MainWindow::setCaptionToDates() 2351void MainWindow::setCaptionToDates()
2352{ 2352{
2353 QString selDates; 2353 QString selDates;
2354 QDate date = mView->startDate(); 2354 QDate date = mView->startDate();
2355 if ( ! date.isValid() ) { 2355 if ( ! date.isValid() ) {
2356 setCaption(""); 2356 setCaption("");
2357 return; 2357 return;
2358 } 2358 }
2359 selDates = KGlobal::locale()->formatDate( date, true); 2359 selDates = KGlobal::locale()->formatDate( date, true);
2360 if (mView->startDate() < mView->endDate() ) 2360 if (mView->startDate() < mView->endDate() )
2361 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true); 2361 selDates += " - " + KGlobal::locale()->formatDate(mView->endDate(), true);
2362 else { 2362 else {
2363 QString addString; 2363 QString addString;
2364 if ( date == QDateTime::currentDateTime().date() ) 2364 if ( date == QDateTime::currentDateTime().date() )
2365 addString = i18n("Today"); 2365 addString = i18n("Today");
2366 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 2366 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
2367 addString = i18n("Tomorrow"); 2367 addString = i18n("Tomorrow");
2368 if ( !addString.isEmpty() ) 2368 if ( !addString.isEmpty() )
2369 selDates = addString+", "+selDates ; 2369 selDates = addString+", "+selDates ;
2370 } 2370 }
2371 setCaption( i18n("Dates: ") + selDates ); 2371 setCaption( i18n("Dates: ") + selDates );
2372 2372
2373} 2373}
2374void MainWindow::showConfigureAgenda( ) 2374void MainWindow::showConfigureAgenda( )
2375{ 2375{
2376 int iii; 2376 int iii;
2377 for ( iii = 1;iii<= 10 ;++iii ){ 2377 for ( iii = 1;iii<= 10 ;++iii ){
2378 configureAgendaMenu->setItemChecked( (iii+1)*2, false ); 2378 configureAgendaMenu->setItemChecked( (iii+1)*2, false );
2379 } 2379 }
2380 configureAgendaMenu->setItemChecked( (KOPrefs::instance()->mHourSize/2)*2, true ); 2380 configureAgendaMenu->setItemChecked( (KOPrefs::instance()->mHourSize/2)*2, true );
2381} 2381}
2382void MainWindow::configureAgenda( int item ) 2382void MainWindow::configureAgenda( int item )
2383{ 2383{
2384 if ( KOPrefs::instance()->mHourSize == item ) 2384 if ( KOPrefs::instance()->mHourSize == item )
2385 return; 2385 return;
2386 KOPrefs::instance()->mHourSize=item; 2386 KOPrefs::instance()->mHourSize=item;
2387 mView->viewManager()->agendaView()->updateConfig(); 2387 mView->viewManager()->agendaView()->updateConfig();
2388} 2388}
2389 2389
2390void MainWindow::saveCalendar() 2390void MainWindow::saveCalendar()
2391{ 2391{
2392 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir; 2392 QString bupDir = KPimGlobalPrefs::instance()->mBackupDatadir;
2393 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir) 2393 if ( KPimGlobalPrefs::instance()->mBackupUseDefaultDir)
2394 bupDir = KGlobalSettings::backupDataDir(); 2394 bupDir = KGlobalSettings::backupDataDir();
2395 bupDir = KGlobal::formatMessage ( bupDir, 0 ); 2395 bupDir = KGlobal::formatMessage ( bupDir, 0 );
2396 QString bupHint; 2396 QString bupHint;
2397 if ( !KPimGlobalPrefs::instance()->mBackupEnabled ) 2397 if ( !KPimGlobalPrefs::instance()->mBackupEnabled )
2398 bupHint = i18n("(Hint: You can enable automatic backup in the global settings!)"); 2398 bupHint = i18n("(Hint: You can enable automatic backup in the global settings!)");
2399 if ( KMessageBox::warningContinueCancel( this, i18n("This will <b>backup all calendar files</b> to the directory %1 %2").arg(bupDir).arg(bupHint),i18n("Information") ) != KMessageBox::Continue ) return; 2399 if ( KMessageBox::warningContinueCancel( this, i18n("This will <b>backup all calendar files</b> to the directory %1 %2").arg(bupDir).arg(bupHint),i18n("Information") ) != KMessageBox::Continue ) return;
2400 bool enabled = KPimGlobalPrefs::instance()->mBackupEnabled; 2400 bool enabled = KPimGlobalPrefs::instance()->mBackupEnabled;
2401 KPimGlobalPrefs::instance()->mBackupEnabled = false; 2401 KPimGlobalPrefs::instance()->mBackupEnabled = false;
2402 save(); 2402 save();
2403 KPimGlobalPrefs::instance()->mBackupEnabled = enabled; 2403 KPimGlobalPrefs::instance()->mBackupEnabled = enabled;
2404 backupAllFiles(); 2404 backupAllFiles();
2405} 2405}
2406void MainWindow::loadCalendar() 2406void MainWindow::loadCalendar()
2407{ 2407{
2408 2408
2409 2409
2410#if 0 2410#if 0
2411 QString fn = KOPrefs::instance()->mLastLoadFile; 2411 QString fn = KOPrefs::instance()->mLastLoadFile;
2412 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this ); 2412 fn = KFileDialog::getOpenFileName( fn, i18n("Load backup filename"), this );
2413 2413
2414 if ( fn == "" ) 2414 if ( fn == "" )
2415 return; 2415 return;
2416 QFileInfo info; 2416 QFileInfo info;
2417 info.setFile( fn ); 2417 info.setFile( fn );
2418 QString mess; 2418 QString mess;
2419 bool loadbup = true; 2419 bool loadbup = true;
2420 if ( info. exists() ) { 2420 if ( info. exists() ) {
2421 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2421 mess = i18n("Backup file from:\n%1\nLoading backup\nfile will delete\nyour current Data!\n").arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2422 int result = QMessageBox::warning( this, "KO/Pi: Warning!", 2422 int result = QMessageBox::warning( this, "KO/Pi: Warning!",
2423 mess, 2423 mess,
2424 i18n("Load!"), i18n("Cancel"), 0, 2424 i18n("Load!"), i18n("Cancel"), 0,
2425 0, 1 ); 2425 0, 1 );
2426 if ( result != 0 ) { 2426 if ( result != 0 ) {
2427 loadbup = false; 2427 loadbup = false;
2428 } 2428 }
2429 } else { 2429 } else {
2430 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2430 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2431 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0, 2431 i18n("Backup file\ndoes not exist!\nNothing loaded!"), 0, 0,
2432 0, 1 ); 2432 0, 1 );
2433 2433
2434 return; 2434 return;
2435 } 2435 }
2436 if ( loadbup ) { 2436 if ( loadbup ) {
2437 mView->openCalendar( fn ); 2437 mView->openCalendar( fn );
2438 KOPrefs::instance()->mLastLoadFile = fn; 2438 KOPrefs::instance()->mLastLoadFile = fn;
2439 mess = i18n("KO/Pi:Loaded %1").arg(fn) ; 2439 mess = i18n("KO/Pi:Loaded %1").arg(fn) ;
2440 setCaption(mess); 2440 setCaption(mess);
2441 } 2441 }
2442#endif 2442#endif
2443 2443
2444} 2444}
2445void MainWindow::quickImportIcal() 2445void MainWindow::quickImportIcal()
2446{ 2446{
2447 importFile( KOPrefs::instance()->mLastImportFile, false ); 2447 importFile( KOPrefs::instance()->mLastImportFile, false );
2448} 2448}
2449void MainWindow::importFile( QString fn, bool quick ) 2449void MainWindow::importFile( QString fn, bool quick )
2450{ 2450{
2451 QFileInfo info; 2451 QFileInfo info;
2452 info.setFile( fn ); 2452 info.setFile( fn );
2453 QString mess; 2453 QString mess;
2454 if ( !info. exists() ) { 2454 if ( !info. exists() ) {
2455 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30)); 2455 mess = i18n("Import file \n...%1\ndoes not exist!\nNothing imported!\n").arg(fn.right( 30));
2456 QMessageBox::warning( this, i18n("KO/Pi: Warning!"), 2456 QMessageBox::warning( this, i18n("KO/Pi: Warning!"),
2457 mess ); 2457 mess );
2458 return; 2458 return;
2459 } 2459 }
2460 int result = 0; 2460 int result = 0;
2461 if ( !quick ) { 2461 if ( !quick ) {
2462 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 2462 mess = i18n( "Import file \n...%1\nfrom:\n%2\nDuplicated entries\nwill not be imported!\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
2463 result = QMessageBox::warning( this, "KO/Pi: Warning!", 2463 result = QMessageBox::warning( this, "KO/Pi: Warning!",
2464 mess, 2464 mess,
2465 "Import", "Cancel", 0, 2465 "Import", "Cancel", 0,
2466 0, 1 ); 2466 0, 1 );
2467 } 2467 }
2468 if ( result == 0 ) { 2468 if ( result == 0 ) {
2469 if ( mView->openCalendar( fn, true )) { 2469 if ( mView->openCalendar( fn, true )) {
2470 KOPrefs::instance()->mLastImportFile = fn; 2470 KOPrefs::instance()->mLastImportFile = fn;
2471 setCaption(i18n("Imported file successfully")); 2471 setCaption(i18n("Imported file successfully"));
2472 } else { 2472 } else {
2473 setCaption(i18n("Error importing file")); 2473 setCaption(i18n("Error importing file"));
2474 } 2474 }
2475 } 2475 }
2476} 2476}
2477 2477
2478void MainWindow::importIcal() 2478void MainWindow::importIcal()
2479{ 2479{
2480 2480
2481 QString fn =KOPrefs::instance()->mLastImportFile; 2481 QString fn =KOPrefs::instance()->mLastImportFile;
2482 2482
2483 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this ); 2483 fn =KFileDialog:: getOpenFileName( fn, i18n("Import filename(*.ics/*.vcs)"), this );
2484 if ( fn == "" ) 2484 if ( fn == "" )
2485 return; 2485 return;
2486 importFile( fn, true ); 2486 importFile( fn, true );
2487 2487
2488} 2488}
2489 2489
2490void MainWindow::exportVCalendar() 2490void MainWindow::exportVCalendar()
2491{ 2491{
2492 QString fn = KOPrefs::instance()->mLastVcalFile; 2492 QString fn = KOPrefs::instance()->mLastVcalFile;
2493 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this ); 2493 fn = KFileDialog::getSaveFileName( fn, i18n("Export vcal filename(*.vcs)"), this );
2494 if ( fn == "" ) 2494 if ( fn == "" )
2495 return; 2495 return;
2496 QFileInfo info; 2496 QFileInfo info;
2497 info.setFile( fn ); 2497 info.setFile( fn );
2498 QString mes; 2498 QString mes;
2499 bool createbup = true; 2499 bool createbup = true;
2500 if ( info. exists() ) { 2500 if ( info. exists() ) {
2501 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) ); 2501 mes = i18n("Save file\nalready exists!\nOld save file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
2502 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes, 2502 int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
2503 i18n("Overwrite!"), i18n("Cancel"), 0, 2503 i18n("Overwrite!"), i18n("Cancel"), 0,
2504 0, 1 ); 2504 0, 1 );
2505 if ( result != 0 ) { 2505 if ( result != 0 ) {
2506 createbup = false; 2506 createbup = false;
2507 } 2507 }
2508 } 2508 }
2509 if ( createbup ) { 2509 if ( createbup ) {
2510 if ( mView->exportVCalendar( fn ) ) { 2510 if ( mView->exportVCalendar( fn ) ) {
2511 KOPrefs::instance()->mLastVcalFile = fn; 2511 KOPrefs::instance()->mLastVcalFile = fn;
2512 if ( fn.length() > 20 ) 2512 if ( fn.length() > 20 )
2513 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; 2513 mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ;
2514 else 2514 else
2515 mes = i18n("KO/Pi:Exported to %1").arg(fn ); 2515 mes = i18n("KO/Pi:Exported to %1").arg(fn );
2516 setCaption(mes); 2516 setCaption(mes);
2517 } 2517 }
2518 } 2518 }
2519 2519
2520} 2520}
2521QString MainWindow::sentSyncFile() 2521QString MainWindow::sentSyncFile()
2522{ 2522{
2523#ifdef DESKTOP_VERSION 2523#ifdef DESKTOP_VERSION
2524 return locateLocal( "tmp", "copysynccal.ics" ); 2524 return locateLocal( "tmp", "copysynccal.ics" );
2525#else 2525#else
2526 return QString( "/tmp/copysynccal.ics" ); 2526 return QString( "/tmp/copysynccal.ics" );
2527#endif 2527#endif
2528} 2528}
2529 2529
2530void MainWindow::syncFileRequest() 2530void MainWindow::syncFileRequest()
2531{ 2531{
2532 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2532 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2533 mSyncManager->slotSyncMenu( 999 ); 2533 mSyncManager->slotSyncMenu( 999 );
2534 } 2534 }
2535 2535
2536 setCaption(i18n("Saving Data to temp file ..." )); 2536 setCaption(i18n("Saving Data to temp file ..." ));
2537 mView->saveCalendar( sentSyncFile() ); 2537 mView->saveCalendar( sentSyncFile() );
2538 setCaption(i18n("Data saved to temp file!" )); 2538 setCaption(i18n("Data saved to temp file!" ));
2539 2539
2540} 2540}
2541void MainWindow::getFile( bool success ) 2541void MainWindow::getFile( bool success )
2542{ 2542{
2543 if ( ! success ) { 2543 if ( ! success ) {
2544 setCaption( i18n("Error receiving file. Nothing changed!") ); 2544 setCaption( i18n("Error receiving file. Nothing changed!") );
2545 return; 2545 return;
2546 } 2546 }
2547 mView->openCalendar( sentSyncFile() ); 2547 mView->mergeFile( sentSyncFile() );
2548 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) { 2548 if ( KOPrefs::instance()->mPassiveSyncWithDesktop ) {
2549 mSyncManager->slotSyncMenu( 999 ); 2549 mSyncManager->slotSyncMenu( 999 );
2550 } 2550 }
2551 setCaption( i18n("Pi-Sync successful!") ); 2551 setCaption( i18n("Pi-Sync successful!") );
2552} 2552}
2553void MainWindow::printListView() 2553void MainWindow::printListView()
2554{ 2554{
2555 2555
2556 QString message = i18n("You can make a printout of the <b>List View</b> and the list view in the <b>Search Dialog</b>! To do this, please go to the <b>List View/Search Dialog</b>. Right click on the list. Select in the popup menu the entry <b>Print complete list</b>. That prints the list as you see it. You can remove items from the list before printing without deleting the corresponding event/todo! Simply select all items you do not want to print out. Then right click on one of the items and choose <b>Hide selected items</b>. After that you can print the list without these items."); 2556 QString message = i18n("You can make a printout of the <b>List View</b> and the list view in the <b>Search Dialog</b>! To do this, please go to the <b>List View/Search Dialog</b>. Right click on the list. Select in the popup menu the entry <b>Print complete list</b>. That prints the list as you see it. You can remove items from the list before printing without deleting the corresponding event/todo! Simply select all items you do not want to print out. Then right click on one of the items and choose <b>Hide selected items</b>. After that you can print the list without these items.");
2557 2557
2558 KMessageBox::information( this, message); 2558 KMessageBox::information( this, message);
2559} 2559}
2560void MainWindow::printSel( ) 2560void MainWindow::printSel( )
2561{ 2561{
2562 mView->viewManager()->agendaView()->agenda()->printSelection(); 2562 mView->viewManager()->agendaView()->agenda()->printSelection();
2563} 2563}
2564 2564
2565void MainWindow::printCal() 2565void MainWindow::printCal()
2566{ 2566{
2567 mView->print();//mCp->showDialog(); 2567 mView->print();//mCp->showDialog();
2568} 2568}
2569 2569
2570 2570
2571#include "libkdepim/kdatepicker.h" 2571#include "libkdepim/kdatepicker.h"
2572#include <kdatetbl.h> 2572#include <kdatetbl.h>
2573 2573
2574void MainWindow::weekAction() 2574void MainWindow::weekAction()
2575{ 2575{
2576 int month; 2576 int month;
2577 KPopupFrame* popup = new KPopupFrame(this); 2577 KPopupFrame* popup = new KPopupFrame(this);
2578 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(popup); 2578 KDateInternalWeekPicker* picker = new KDateInternalWeekPicker(popup);
2579 // ----- 2579 // -----
2580 picker->resize(picker->sizeHint()); 2580 picker->resize(picker->sizeHint());
2581 popup->setMainWidget(picker); 2581 popup->setMainWidget(picker);
2582 picker->setFocus(); 2582 picker->setFocus();
2583 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int))); 2583 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
2584 int x = 0; 2584 int x = 0;
2585 int y = iconToolBar->height(); 2585 int y = iconToolBar->height();
2586 int dX = 0; 2586 int dX = 0;
2587 int dY = 0; 2587 int dY = 0;
2588 if ( iconToolBar->orientation () == Qt:: Horizontal ) { 2588 if ( iconToolBar->orientation () == Qt:: Horizontal ) {
2589 if ( iconToolBar->y() > height()/2 ) { 2589 if ( iconToolBar->y() > height()/2 ) {
2590 dY = picker->sizeHint().height()+8; 2590 dY = picker->sizeHint().height()+8;
2591 y = 0; 2591 y = 0;
2592 } 2592 }
2593 } else { 2593 } else {
2594 if ( iconToolBar->x() > width()/2 ) { // right side 2594 if ( iconToolBar->x() > width()/2 ) { // right side
2595 x=0; 2595 x=0;
2596 dX= picker->sizeHint().width()+8; 2596 dX= picker->sizeHint().width()+8;
2597 y = 0; 2597 y = 0;
2598 } else { 2598 } else {
2599 x= iconToolBar->width(); 2599 x= iconToolBar->width();
2600 y = 0; 2600 y = 0;
2601 } 2601 }
2602 } 2602 }
2603 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() ); 2603 //qDebug("dax %d dy %d %d %d ", dX, dY, iconToolBar->x(), iconToolBar->y() );
2604 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY)))) 2604 if(popup->exec(iconToolBar->mapToGlobal(QPoint(x,y)-QPoint( dX,dY))))
2605 { 2605 {
2606 month = picker->getResult(); 2606 month = picker->getResult();
2607 emit selectWeek ( month ); 2607 emit selectWeek ( month );
2608 //qDebug("weekSelected %d ", month); 2608 //qDebug("weekSelected %d ", month);
2609 } 2609 }
2610 delete popup; 2610 delete popup;
2611} 2611}
2612 2612
2613void MainWindow::hideEvent ( QHideEvent * ) 2613void MainWindow::hideEvent ( QHideEvent * )
2614{ 2614{
2615 QString message; 2615 QString message;
2616 QDateTime nextA = mCalendar->nextAlarmEventDateTime(); 2616 QDateTime nextA = mCalendar->nextAlarmEventDateTime();
2617 if ( nextA.isValid() ) { 2617 if ( nextA.isValid() ) {
2618 QString sum = mCalendar->nextSummary(); 2618 QString sum = mCalendar->nextSummary();
2619 2619
2620 message = i18n("%1 %2 - %3 (next event/todo with alarm)").arg( KGlobal::locale()->formatTime(nextA.time() , false)).arg(sum ).arg( KGlobal::locale()->formatDate(nextA.date() , false)); 2620 message = i18n("%1 %2 - %3 (next event/todo with alarm)").arg( KGlobal::locale()->formatTime(nextA.time() , false)).arg(sum ).arg( KGlobal::locale()->formatDate(nextA.date() , false));
2621 setCaption( message ); 2621 setCaption( message );
2622 } 2622 }
2623} 2623}
2624 2624
2625void MainWindow::resizeEvent( QResizeEvent* e) 2625void MainWindow::resizeEvent( QResizeEvent* e)
2626{ 2626{
2627#ifndef DESKTOP_VERSION 2627#ifndef DESKTOP_VERSION
2628 if ( !KOPrefs::instance()->mShowIconFilter && !KOPrefs::instance()->mShowIconOnetoolbar && QApplication::desktop()->width() > 320) { 2628 if ( !KOPrefs::instance()->mShowIconFilter && !KOPrefs::instance()->mShowIconOnetoolbar && QApplication::desktop()->width() > 320) {
2629 if (QApplication::desktop()->width() > QApplication::desktop()->height() ) 2629 if (QApplication::desktop()->width() > QApplication::desktop()->height() )
2630 filterToolBar->hide(); 2630 filterToolBar->hide();
2631 else 2631 else
2632 filterToolBar->show(); 2632 filterToolBar->show();
2633 } 2633 }
2634#endif 2634#endif
2635 QMainWindow::resizeEvent( e); 2635 QMainWindow::resizeEvent( e);
2636} 2636}
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index a662eeb..b7990d4 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,488 +1,489 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <stdlib.h> 22#include <stdlib.h>
23#include <time.h> 23#include <time.h>
24 24
25#include <kdebug.h> 25#include <kdebug.h>
26#include <kglobal.h> 26#include <kglobal.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29#include "exceptions.h" 29#include "exceptions.h"
30#include "calfilter.h" 30#include "calfilter.h"
31 31
32#include "calendar.h" 32#include "calendar.h"
33#include "syncdefines.h" 33#include "syncdefines.h"
34 34
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( " 00:00 Europe/London(UTC)" ); 41 setTimeZoneId( " 00:00 Europe/London(UTC)" );
42} 42}
43 43
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void Calendar::init()
52{ 52{
53 mObserver = 0; 53 mObserver = 0;
54 mNewObserver = false; 54 mNewObserver = false;
55 mUndoIncidence = 0; 55 mUndoIncidence = 0;
56 mDeleteIncidencesOnClose = true; 56 mDeleteIncidencesOnClose = true;
57 mModified = false; 57 mModified = false;
58 mDefaultCalendar = 1; 58 mDefaultCalendar = 1;
59 // Setup default filter, which does nothing 59 // Setup default filter, which does nothing
60 mDefaultFilter = new CalFilter; 60 mDefaultFilter = new CalFilter;
61 mFilter = mDefaultFilter; 61 mFilter = mDefaultFilter;
62 mFilter->setEnabled(false); 62 mFilter->setEnabled(false);
63 63
64 // initialize random numbers. This is a hack, and not 64 // initialize random numbers. This is a hack, and not
65 // even that good of one at that. 65 // even that good of one at that.
66// srandom(time(0)); 66// srandom(time(0));
67 67
68 // user information... 68 // user information...
69 setOwner(i18n("Unknown Name")); 69 setOwner(i18n("Unknown Name"));
70 setEmail(i18n("unknown@nowhere")); 70 setEmail(i18n("unknown@nowhere"));
71 71
72#if 0 72#if 0
73 tmpStr = KOPrefs::instance()->mTimeZone; 73 tmpStr = KOPrefs::instance()->mTimeZone;
74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 74// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
75 int dstSetting = KOPrefs::instance()->mDaylightSavings; 75 int dstSetting = KOPrefs::instance()->mDaylightSavings;
76 extern long int timezone; 76 extern long int timezone;
77 struct tm *now; 77 struct tm *now;
78 time_t curtime; 78 time_t curtime;
79 curtime = time(0); 79 curtime = time(0);
80 now = localtime(&curtime); 80 now = localtime(&curtime);
81 int hourOff = - ((timezone / 60) / 60); 81 int hourOff = - ((timezone / 60) / 60);
82 if (now->tm_isdst) 82 if (now->tm_isdst)
83 hourOff += 1; 83 hourOff += 1;
84 QString tzStr; 84 QString tzStr;
85 tzStr.sprintf("%.2d%.2d", 85 tzStr.sprintf("%.2d%.2d",
86 hourOff, 86 hourOff,
87 abs((timezone / 60) % 60)); 87 abs((timezone / 60) % 60));
88 88
89 // if no time zone was in the config file, write what we just discovered. 89 // if no time zone was in the config file, write what we just discovered.
90 if (tmpStr.isEmpty()) { 90 if (tmpStr.isEmpty()) {
91// KOPrefs::instance()->mTimeZone = tzStr; 91// KOPrefs::instance()->mTimeZone = tzStr;
92 } else { 92 } else {
93 tzStr = tmpStr; 93 tzStr = tmpStr;
94 } 94 }
95 95
96 // if daylight savings has changed since last load time, we need 96 // if daylight savings has changed since last load time, we need
97 // to rewrite these settings to the config file. 97 // to rewrite these settings to the config file.
98 if ((now->tm_isdst && !dstSetting) || 98 if ((now->tm_isdst && !dstSetting) ||
99 (!now->tm_isdst && dstSetting)) { 99 (!now->tm_isdst && dstSetting)) {
100 KOPrefs::instance()->mTimeZone = tzStr; 100 KOPrefs::instance()->mTimeZone = tzStr;
101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 101 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
102 } 102 }
103 103
104 setTimeZone(tzStr); 104 setTimeZone(tzStr);
105#endif 105#endif
106 106
107// KOPrefs::instance()->writeConfig(); 107// KOPrefs::instance()->writeConfig();
108} 108}
109 109
110Calendar::~Calendar() 110Calendar::~Calendar()
111{ 111{
112 delete mDefaultFilter; 112 delete mDefaultFilter;
113 if ( mUndoIncidence ) 113 if ( mUndoIncidence )
114 delete mUndoIncidence; 114 delete mUndoIncidence;
115} 115}
116void Calendar::setDontDeleteIncidencesOnClose () 116void Calendar::setDontDeleteIncidencesOnClose ()
117{ 117{
118 mDeleteIncidencesOnClose = false; 118 mDeleteIncidencesOnClose = false;
119} 119}
120void Calendar::setDefaultCalendar( int d ) 120void Calendar::setDefaultCalendar( int d )
121{ 121{
122 mDefaultCalendar = d; 122 mDefaultCalendar = d;
123} 123}
124int Calendar::defaultCalendar() 124int Calendar::defaultCalendar()
125{ 125{
126 return mDefaultCalendar; 126 return mDefaultCalendar;
127} 127}
128const QString &Calendar::getOwner() const 128const QString &Calendar::getOwner() const
129{ 129{
130 return mOwner; 130 return mOwner;
131} 131}
132 132
133bool Calendar::undoDeleteIncidence() 133bool Calendar::undoDeleteIncidence()
134{ 134{
135 if (!mUndoIncidence) 135 if (!mUndoIncidence)
136 return false; 136 return false;
137 addIncidence(mUndoIncidence); 137 addIncidence(mUndoIncidence);
138 mUndoIncidence = 0; 138 mUndoIncidence = 0;
139 return true; 139 return true;
140} 140}
141void Calendar::setOwner(const QString &os) 141void Calendar::setOwner(const QString &os)
142{ 142{
143 int i; 143 int i;
144 mOwner = os; 144 mOwner = os;
145 i = mOwner.find(','); 145 i = mOwner.find(',');
146 if (i != -1) 146 if (i != -1)
147 mOwner = mOwner.left(i); 147 mOwner = mOwner.left(i);
148 148
149 setModified( true ); 149 setModified( true );
150} 150}
151 151
152void Calendar::setTimeZone(const QString & tz) 152void Calendar::setTimeZone(const QString & tz)
153{ 153{
154 bool neg = FALSE; 154 bool neg = FALSE;
155 int hours, minutes; 155 int hours, minutes;
156 QString tmpStr(tz); 156 QString tmpStr(tz);
157 157
158 if (tmpStr.left(1) == "-") 158 if (tmpStr.left(1) == "-")
159 neg = TRUE; 159 neg = TRUE;
160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 160 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
161 tmpStr.remove(0, 1); 161 tmpStr.remove(0, 1);
162 hours = tmpStr.left(2).toInt(); 162 hours = tmpStr.left(2).toInt();
163 if (tmpStr.length() > 2) 163 if (tmpStr.length() > 2)
164 minutes = tmpStr.right(2).toInt(); 164 minutes = tmpStr.right(2).toInt();
165 else 165 else
166 minutes = 0; 166 minutes = 0;
167 mTimeZone = (60*hours+minutes); 167 mTimeZone = (60*hours+minutes);
168 if (neg) 168 if (neg)
169 mTimeZone = -mTimeZone; 169 mTimeZone = -mTimeZone;
170 mLocalTime = false; 170 mLocalTime = false;
171 171
172 setModified( true ); 172 setModified( true );
173} 173}
174 174
175QString Calendar::getTimeZoneStr() const 175QString Calendar::getTimeZoneStr() const
176{ 176{
177 if (mLocalTime) 177 if (mLocalTime)
178 return ""; 178 return "";
179 QString tmpStr; 179 QString tmpStr;
180 int hours = abs(mTimeZone / 60); 180 int hours = abs(mTimeZone / 60);
181 int minutes = abs(mTimeZone % 60); 181 int minutes = abs(mTimeZone % 60);
182 bool neg = mTimeZone < 0; 182 bool neg = mTimeZone < 0;
183 183
184 tmpStr.sprintf("%c%.2d%.2d", 184 tmpStr.sprintf("%c%.2d%.2d",
185 (neg ? '-' : '+'), 185 (neg ? '-' : '+'),
186 hours, minutes); 186 hours, minutes);
187 return tmpStr; 187 return tmpStr;
188} 188}
189 189
190void Calendar::setTimeZone(int tz) 190void Calendar::setTimeZone(int tz)
191{ 191{
192 mTimeZone = tz; 192 mTimeZone = tz;
193 mLocalTime = false; 193 mLocalTime = false;
194 194
195 setModified( true ); 195 setModified( true );
196} 196}
197 197
198int Calendar::getTimeZone() const 198int Calendar::getTimeZone() const
199{ 199{
200 return mTimeZone; 200 return mTimeZone;
201} 201}
202 202
203void Calendar::setTimeZoneId(const QString &id) 203void Calendar::setTimeZoneId(const QString &id)
204{ 204{
205 mTimeZoneId = id; 205 mTimeZoneId = id;
206 mLocalTime = false; 206 mLocalTime = false;
207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 207 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
208 if ( mTimeZone > 1000) 208 if ( mTimeZone > 1000)
209 setLocalTime(); 209 setLocalTime();
210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 210 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
211 setModified( true ); 211 setModified( true );
212} 212}
213 213
214QString Calendar::timeZoneId() const 214QString Calendar::timeZoneId() const
215{ 215{
216 return mTimeZoneId; 216 return mTimeZoneId;
217} 217}
218 218
219void Calendar::setLocalTime() 219void Calendar::setLocalTime()
220{ 220{
221 //qDebug("Calendar::setLocalTime() "); 221 //qDebug("Calendar::setLocalTime() ");
222 mLocalTime = true; 222 mLocalTime = true;
223 mTimeZone = 0; 223 mTimeZone = 0;
224 mTimeZoneId = ""; 224 mTimeZoneId = "";
225 225
226 setModified( true ); 226 setModified( true );
227} 227}
228 228
229bool Calendar::isLocalTime() const 229bool Calendar::isLocalTime() const
230{ 230{
231 return mLocalTime; 231 return mLocalTime;
232} 232}
233 233
234const QString &Calendar::getEmail() 234const QString &Calendar::getEmail()
235{ 235{
236 return mOwnerEmail; 236 return mOwnerEmail;
237} 237}
238 238
239void Calendar::setEmail(const QString &e) 239void Calendar::setEmail(const QString &e)
240{ 240{
241 mOwnerEmail = e; 241 mOwnerEmail = e;
242 242
243 setModified( true ); 243 setModified( true );
244} 244}
245 245
246void Calendar::setFilter(CalFilter *filter) 246void Calendar::setFilter(CalFilter *filter)
247{ 247{
248 mFilter = filter; 248 mFilter = filter;
249} 249}
250 250
251CalFilter *Calendar::filter() 251CalFilter *Calendar::filter()
252{ 252{
253 return mFilter; 253 return mFilter;
254} 254}
255 255
256QPtrList<Incidence> Calendar::incidences() 256QPtrList<Incidence> Calendar::incidences()
257{ 257{
258 QPtrList<Incidence> incidences; 258 QPtrList<Incidence> incidences;
259 259
260 Incidence *i; 260 Incidence *i;
261 261
262 QPtrList<Event> e = events(); 262 QPtrList<Event> e = events();
263 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 263 for( i = e.first(); i; i = e.next() ) incidences.append( i );
264 264
265 QPtrList<Todo> t = todos(); 265 QPtrList<Todo> t = todos();
266 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 266 for( i = t.first(); i; i = t.next() ) incidences.append( i );
267 267
268 QPtrList<Journal> j = journals(); 268 QPtrList<Journal> j = journals();
269 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 269 for( i = j.first(); i; i = j.next() ) incidences.append( i );
270 270
271 return incidences; 271 return incidences;
272} 272}
273 273
274void Calendar::resetPilotStat(int id ) 274void Calendar::resetPilotStat(int id )
275{ 275{
276 QPtrList<Incidence> incidences; 276 QPtrList<Incidence> incidences;
277 277
278 Incidence *i; 278 Incidence *i;
279 279
280 QPtrList<Event> e = rawEvents(); 280 QPtrList<Event> e = rawEvents();
281 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 281 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
282 282
283 QPtrList<Todo> t = rawTodos(); 283 QPtrList<Todo> t = rawTodos();
284 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 284 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
285 285
286 QPtrList<Journal> j = journals(); 286 QPtrList<Journal> j = journals();
287 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 287 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
288} 288}
289void Calendar::resetTempSyncStat() 289void Calendar::resetTempSyncStat()
290{ 290{
291 QPtrList<Incidence> incidences; 291 QPtrList<Incidence> incidences;
292 292
293 Incidence *i; 293 Incidence *i;
294 294
295 QPtrList<Event> e = rawEvents(); 295 QPtrList<Event> e = rawEvents();
296 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 296 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
297 297
298 QPtrList<Todo> t = rawTodos(); 298 QPtrList<Todo> t = rawTodos();
299 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 299 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
300 300
301 QPtrList<Journal> j = journals(); 301 QPtrList<Journal> j = journals();
302 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 302 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
303} 303}
304QPtrList<Incidence> Calendar::rawIncidences() 304QPtrList<Incidence> Calendar::rawIncidences()
305{ 305{
306 QPtrList<Incidence> incidences; 306 QPtrList<Incidence> incidences;
307 307
308 Incidence *i; 308 Incidence *i;
309 309
310 QPtrList<Event> e = rawEvents(); 310 QPtrList<Event> e = rawEvents();
311 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 311 for( i = e.first(); i; i = e.next() ) incidences.append( i );
312 312
313 QPtrList<Todo> t = rawTodos(); 313 QPtrList<Todo> t = rawTodos();
314 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 314 for( i = t.first(); i; i = t.next() ) incidences.append( i );
315 315
316 QPtrList<Journal> j = journals(); 316 QPtrList<Journal> j = journals();
317 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 317 for( i = j.first(); i; i = j.next() ) incidences.append( i );
318 318
319 return incidences; 319 return incidences;
320} 320}
321 321
322QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 322QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
323{ 323{
324 QPtrList<Event> el = rawEventsForDate(date,sorted); 324 QPtrList<Event> el = rawEventsForDate(date,sorted);
325 mFilter->apply(&el); 325 mFilter->apply(&el);
326 return el; 326 return el;
327} 327}
328 328
329QPtrList<Event> Calendar::events( const QDateTime &qdt ) 329QPtrList<Event> Calendar::events( const QDateTime &qdt )
330{ 330{
331 QPtrList<Event> el = rawEventsForDate(qdt); 331 QPtrList<Event> el = rawEventsForDate(qdt);
332 mFilter->apply(&el); 332 mFilter->apply(&el);
333 return el; 333 return el;
334} 334}
335 335
336QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 336QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
337 bool inclusive) 337 bool inclusive)
338{ 338{
339 QPtrList<Event> el = rawEvents(start,end,inclusive); 339 QPtrList<Event> el = rawEvents(start,end,inclusive);
340 mFilter->apply(&el); 340 mFilter->apply(&el);
341 return el; 341 return el;
342} 342}
343 343
344QPtrList<Event> Calendar::events() 344QPtrList<Event> Calendar::events()
345{ 345{
346 QPtrList<Event> el = rawEvents(); 346 QPtrList<Event> el = rawEvents();
347 mFilter->apply(&el); 347 mFilter->apply(&el);
348 return el; 348 return el;
349} 349}
350void Calendar::addIncidenceBranch(Incidence *i) 350void Calendar::addIncidenceBranch(Incidence *i)
351{ 351{
352 addIncidence( i ); 352 addIncidence( i );
353 Incidence * inc; 353 Incidence * inc;
354 QPtrList<Incidence> Relations = i->relations(); 354 QPtrList<Incidence> Relations = i->relations();
355 for (inc=Relations.first();inc;inc=Relations.next()) { 355 for (inc=Relations.first();inc;inc=Relations.next()) {
356 addIncidenceBranch( inc ); 356 addIncidenceBranch( inc );
357 } 357 }
358} 358}
359 359
360bool Calendar::addIncidence(Incidence *i) 360bool Calendar::addIncidence(Incidence *i)
361{ 361{
362 Incidence::AddVisitor<Calendar> v(this); 362 Incidence::AddVisitor<Calendar> v(this);
363 i->setCalID( mDefaultCalendar ); 363 if ( i->calID() == 0 )
364 i->setCalID( mDefaultCalendar );
364 i->setCalEnabled( true ); 365 i->setCalEnabled( true );
365 return i->accept(v); 366 return i->accept(v);
366} 367}
367void Calendar::deleteIncidence(Incidence *in) 368void Calendar::deleteIncidence(Incidence *in)
368{ 369{
369 if ( in->typeID() == eventID ) 370 if ( in->typeID() == eventID )
370 deleteEvent( (Event*) in ); 371 deleteEvent( (Event*) in );
371 else if ( in->typeID() == todoID ) 372 else if ( in->typeID() == todoID )
372 deleteTodo( (Todo*) in); 373 deleteTodo( (Todo*) in);
373 else if ( in->typeID() == journalID ) 374 else if ( in->typeID() == journalID )
374 deleteJournal( (Journal*) in ); 375 deleteJournal( (Journal*) in );
375} 376}
376 377
377Incidence* Calendar::incidence( const QString& uid ) 378Incidence* Calendar::incidence( const QString& uid )
378{ 379{
379 Incidence* i; 380 Incidence* i;
380 381
381 if( (i = todo( uid )) != 0 ) 382 if( (i = todo( uid )) != 0 )
382 return i; 383 return i;
383 if( (i = event( uid )) != 0 ) 384 if( (i = event( uid )) != 0 )
384 return i; 385 return i;
385 if( (i = journal( uid )) != 0 ) 386 if( (i = journal( uid )) != 0 )
386 return i; 387 return i;
387 388
388 return 0; 389 return 0;
389} 390}
390 391
391QPtrList<Todo> Calendar::todos() 392QPtrList<Todo> Calendar::todos()
392{ 393{
393 QPtrList<Todo> tl = rawTodos(); 394 QPtrList<Todo> tl = rawTodos();
394 mFilter->apply( &tl ); 395 mFilter->apply( &tl );
395 return tl; 396 return tl;
396} 397}
397 398
398// When this is called, the todo have already been added to the calendar. 399// When this is called, the todo have already been added to the calendar.
399// This method is only about linking related todos 400// This method is only about linking related todos
400void Calendar::setupRelations( Incidence *incidence ) 401void Calendar::setupRelations( Incidence *incidence )
401{ 402{
402 QString uid = incidence->uid(); 403 QString uid = incidence->uid();
403 //qDebug("Calendar::setupRelations "); 404 //qDebug("Calendar::setupRelations ");
404 // First, go over the list of orphans and see if this is their parent 405 // First, go over the list of orphans and see if this is their parent
405 while( Incidence* i = mOrphans[ uid ] ) { 406 while( Incidence* i = mOrphans[ uid ] ) {
406 mOrphans.remove( uid ); 407 mOrphans.remove( uid );
407 i->setRelatedTo( incidence ); 408 i->setRelatedTo( incidence );
408 incidence->addRelation( i ); 409 incidence->addRelation( i );
409 mOrphanUids.remove( i->uid() ); 410 mOrphanUids.remove( i->uid() );
410 } 411 }
411 412
412 // Now see about this incidences parent 413 // Now see about this incidences parent
413 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { 414 if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) {
414 // This incidence has a uid it is related to, but is not registered to it yet 415 // This incidence has a uid it is related to, but is not registered to it yet
415 // Try to find it 416 // Try to find it
416 Incidence* parent = this->incidence( incidence->relatedToUid() ); 417 Incidence* parent = this->incidence( incidence->relatedToUid() );
417 if( parent ) { 418 if( parent ) {
418 // Found it 419 // Found it
419 incidence->setRelatedTo( parent ); 420 incidence->setRelatedTo( parent );
420 parent->addRelation( incidence ); 421 parent->addRelation( incidence );
421 } else { 422 } else {
422 // Not found, put this in the mOrphans list 423 // Not found, put this in the mOrphans list
423 mOrphans.insert( incidence->relatedToUid(), incidence ); 424 mOrphans.insert( incidence->relatedToUid(), incidence );
424 mOrphanUids.insert( incidence->uid(), incidence ); 425 mOrphanUids.insert( incidence->uid(), incidence );
425 } 426 }
426 } 427 }
427} 428}
428 429
429// If a task with subtasks is deleted, move it's subtasks to the orphans list 430// If a task with subtasks is deleted, move it's subtasks to the orphans list
430void Calendar::removeRelations( Incidence *incidence ) 431void Calendar::removeRelations( Incidence *incidence )
431{ 432{
432 // qDebug("Calendar::removeRelations "); 433 // qDebug("Calendar::removeRelations ");
433 QString uid = incidence->uid(); 434 QString uid = incidence->uid();
434 435
435 QPtrList<Incidence> relations = incidence->relations(); 436 QPtrList<Incidence> relations = incidence->relations();
436 for( Incidence* i = relations.first(); i; i = relations.next() ) 437 for( Incidence* i = relations.first(); i; i = relations.next() )
437 if( !mOrphanUids.find( i->uid() ) ) { 438 if( !mOrphanUids.find( i->uid() ) ) {
438 mOrphans.insert( uid, i ); 439 mOrphans.insert( uid, i );
439 mOrphanUids.insert( i->uid(), i ); 440 mOrphanUids.insert( i->uid(), i );
440 i->setRelatedTo( 0 ); 441 i->setRelatedTo( 0 );
441 i->setRelatedToUid( uid ); 442 i->setRelatedToUid( uid );
442 } 443 }
443 444
444 // If this incidence is related to something else, tell that about it 445 // If this incidence is related to something else, tell that about it
445 if( incidence->relatedTo() ) 446 if( incidence->relatedTo() )
446 incidence->relatedTo()->removeRelation( incidence ); 447 incidence->relatedTo()->removeRelation( incidence );
447 448
448 // Remove this one from the orphans list 449 // Remove this one from the orphans list
449 if( mOrphanUids.remove( uid ) ) 450 if( mOrphanUids.remove( uid ) )
450 // This incidence is located in the orphans list - it should be removed 451 // This incidence is located in the orphans list - it should be removed
451 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { 452 if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) {
452 // Removing wasn't that easy 453 // Removing wasn't that easy
453 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { 454 for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) {
454 if( it.current()->uid() == uid ) { 455 if( it.current()->uid() == uid ) {
455 mOrphans.remove( it.currentKey() ); 456 mOrphans.remove( it.currentKey() );
456 break; 457 break;
457 } 458 }
458 } 459 }
459 } 460 }
460} 461}
461 462
462void Calendar::registerObserver( Observer *observer ) 463void Calendar::registerObserver( Observer *observer )
463{ 464{
464 mObserver = observer; 465 mObserver = observer;
465 mNewObserver = true; 466 mNewObserver = true;
466} 467}
467 468
468void Calendar::setModified( bool modified ) 469void Calendar::setModified( bool modified )
469{ 470{
470 if ( mObserver ) mObserver->calendarModified( modified, this ); 471 if ( mObserver ) mObserver->calendarModified( modified, this );
471 if ( modified != mModified || mNewObserver ) { 472 if ( modified != mModified || mNewObserver ) {
472 mNewObserver = false; 473 mNewObserver = false;
473 // if ( mObserver ) mObserver->calendarModified( modified, this ); 474 // if ( mObserver ) mObserver->calendarModified( modified, this );
474 mModified = modified; 475 mModified = modified;
475 } 476 }
476} 477}
477 478
478void Calendar::setLoadedProductId( const QString &id ) 479void Calendar::setLoadedProductId( const QString &id )
479{ 480{
480 mLoadedProductId = id; 481 mLoadedProductId = id;
481} 482}
482 483
483QString Calendar::loadedProductId() 484QString Calendar::loadedProductId()
484{ 485{
485 return mLoadedProductId; 486 return mLoadedProductId;
486} 487}
487 488
488//#include "calendar.moc" 489//#include "calendar.moc"
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4652fe5..14a1a45 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -1,377 +1,378 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#ifndef CALENDAR_H 22#ifndef CALENDAR_H
23#define CALENDAR_H 23#define CALENDAR_H
24 24
25#include <qobject.h> 25#include <qobject.h>
26#include <qstring.h> 26#include <qstring.h>
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qptrlist.h> 28#include <qptrlist.h>
29#include <qdict.h> 29#include <qdict.h>
30 30
31#include "customproperties.h" 31#include "customproperties.h"
32#include "event.h" 32#include "event.h"
33#include "todo.h" 33#include "todo.h"
34#include "journal.h" 34#include "journal.h"
35#include "calfilter.h" 35#include "calfilter.h"
36 36
37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ 37//#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */
38 38
39class KConfig; 39class KConfig;
40 40
41namespace KCal { 41namespace KCal {
42 42
43 43
44/** 44/**
45 This is the main "calendar" object class for KOrganizer. It holds 45 This is the main "calendar" object class for KOrganizer. It holds
46 information like all appointments/events, user information, etc. etc. 46 information like all appointments/events, user information, etc. etc.
47 one calendar is associated with each CalendarView (@see calendarview.h). 47 one calendar is associated with each CalendarView (@see calendarview.h).
48 This is an abstract base class defining the interface to a calendar. It is 48 This is an abstract base class defining the interface to a calendar. It is
49 implemented by subclasses like @see CalendarLocal, which use different 49 implemented by subclasses like @see CalendarLocal, which use different
50 methods to store and access the data. 50 methods to store and access the data.
51 51
52 Ownership of events etc. is handled by the following policy: As soon as an 52 Ownership of events etc. is handled by the following policy: As soon as an
53 event (or any other subclass of IncidenceBase) object is added to the 53 event (or any other subclass of IncidenceBase) object is added to the
54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes 54 Calendar by addEvent() it is owned by the Calendar object. The Calendar takes
55 care of deleting it. All Events returned by the query functions are returned 55 care of deleting it. All Events returned by the query functions are returned
56 as pointers, that means all changes to the returned events are immediately 56 as pointers, that means all changes to the returned events are immediately
57 visible in the Calendar. You shouldn't delete any Event object you get from 57 visible in the Calendar. You shouldn't delete any Event object you get from
58 Calendar. 58 Calendar.
59*/ 59*/
60class Calendar : public QObject, public CustomProperties, 60class Calendar : public QObject, public CustomProperties,
61 public IncidenceBase::Observer 61 public IncidenceBase::Observer
62{ 62{
63 Q_OBJECT 63 Q_OBJECT
64public: 64public:
65 Calendar(); 65 Calendar();
66 Calendar(const QString &timeZoneId); 66 Calendar(const QString &timeZoneId);
67 virtual ~Calendar(); 67 virtual ~Calendar();
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0;
79 virtual void setSyncEventsReadOnly() = 0; 80 virtual void setSyncEventsReadOnly() = 0;
80 virtual void stopAllTodos() = 0; 81 virtual void stopAllTodos() = 0;
81 82
82 /** 83 /**
83 Sync changes in memory to persistant storage. 84 Sync changes in memory to persistant storage.
84 */ 85 */
85 virtual void save() = 0; 86 virtual void save() = 0;
86 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 87 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
87 virtual void removeSyncInfo( QString syncProfile) = 0; 88 virtual void removeSyncInfo( QString syncProfile) = 0;
88 virtual bool isSaving() { return false; } 89 virtual bool isSaving() { return false; }
89 90
90 /** 91 /**
91 Return the owner of the calendar's full name. 92 Return the owner of the calendar's full name.
92 */ 93 */
93 const QString &getOwner() const; 94 const QString &getOwner() const;
94 /** 95 /**
95 Set the owner of the calendar. Should be owner's full name. 96 Set the owner of the calendar. Should be owner's full name.
96 */ 97 */
97 void setOwner( const QString &os ); 98 void setOwner( const QString &os );
98 /** 99 /**
99 Return the email address of the calendar owner. 100 Return the email address of the calendar owner.
100 */ 101 */
101 const QString &getEmail(); 102 const QString &getEmail();
102 /** 103 /**
103 Set the email address of the calendar owner. 104 Set the email address of the calendar owner.
104 */ 105 */
105 void setEmail( const QString & ); 106 void setEmail( const QString & );
106 107
107 /** 108 /**
108 Set time zone from a timezone string (e.g. -2:00) 109 Set time zone from a timezone string (e.g. -2:00)
109 */ 110 */
110 void setTimeZone( const QString &tz ); 111 void setTimeZone( const QString &tz );
111 /** 112 /**
112 Set time zone from a minutes value (e.g. -60) 113 Set time zone from a minutes value (e.g. -60)
113 */ 114 */
114 void setTimeZone( int tz ); 115 void setTimeZone( int tz );
115 /** 116 /**
116 Return time zone as offest in minutes. 117 Return time zone as offest in minutes.
117 */ 118 */
118 int getTimeZone() const; 119 int getTimeZone() const;
119 /** 120 /**
120 Compute an ISO 8601 format string from the time zone. 121 Compute an ISO 8601 format string from the time zone.
121 */ 122 */
122 QString getTimeZoneStr() const; 123 QString getTimeZoneStr() const;
123 /** 124 /**
124 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal 125 Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal
125 values). 126 values).
126 */ 127 */
127 void setTimeZoneId( const QString & ); 128 void setTimeZoneId( const QString & );
128 /** 129 /**
129 Return time zone id. 130 Return time zone id.
130 */ 131 */
131 QString timeZoneId() const; 132 QString timeZoneId() const;
132 /** 133 /**
133 Use local time, not UTC or a time zone. 134 Use local time, not UTC or a time zone.
134 */ 135 */
135 void setLocalTime(); 136 void setLocalTime();
136 /** 137 /**
137 Return whether local time is being used. 138 Return whether local time is being used.
138 */ 139 */
139 bool isLocalTime() const; 140 bool isLocalTime() const;
140 141
141 /** 142 /**
142 Add an incidence to calendar. 143 Add an incidence to calendar.
143 144
144 @return true on success, false on error. 145 @return true on success, false on error.
145 */ 146 */
146 virtual bool addIncidence( Incidence * ); 147 virtual bool addIncidence( Incidence * );
147 148
148 // Adds an incidence and all relatedto incidences to the cal 149 // Adds an incidence and all relatedto incidences to the cal
149 void addIncidenceBranch( Incidence * ); 150 void addIncidenceBranch( Incidence * );
150 /** 151 /**
151 Return filtered list of all incidences of this calendar. 152 Return filtered list of all incidences of this calendar.
152 */ 153 */
153 virtual QPtrList<Incidence> incidences(); 154 virtual QPtrList<Incidence> incidences();
154 155
155 /** 156 /**
156 Return unfiltered list of all incidences of this calendar. 157 Return unfiltered list of all incidences of this calendar.
157 */ 158 */
158 virtual QPtrList<Incidence> rawIncidences(); 159 virtual QPtrList<Incidence> rawIncidences();
159 160
160 /** 161 /**
161 Adds a Event to this calendar object. 162 Adds a Event to this calendar object.
162 @param anEvent a pointer to the event to add 163 @param anEvent a pointer to the event to add
163 164
164 @return true on success, false on error. 165 @return true on success, false on error.
165 */ 166 */
166 virtual bool addEventNoDup( Event *event ) = 0; 167 virtual bool addEventNoDup( Event *event ) = 0;
167 virtual bool addAnniversaryNoDup( Event *event ) = 0; 168 virtual bool addAnniversaryNoDup( Event *event ) = 0;
168 virtual bool addEvent( Event *anEvent ) = 0; 169 virtual bool addEvent( Event *anEvent ) = 0;
169 /** 170 /**
170 Delete event from calendar. 171 Delete event from calendar.
171 */ 172 */
172 virtual void deleteEvent( Event * ) = 0; 173 virtual void deleteEvent( Event * ) = 0;
173 /** 174 /**
174 Retrieves an event on the basis of the unique string ID. 175 Retrieves an event on the basis of the unique string ID.
175 */ 176 */
176 virtual Event *event( const QString &UniqueStr ) = 0; 177 virtual Event *event( const QString &UniqueStr ) = 0;
177 virtual Event *event( QString, QString ) = 0; 178 virtual Event *event( QString, QString ) = 0;
178 /** 179 /**
179 Builds and then returns a list of all events that match for the 180 Builds and then returns a list of all events that match for the
180 date specified. useful for dayView, etc. etc. 181 date specified. useful for dayView, etc. etc.
181 The calendar filter is applied. 182 The calendar filter is applied.
182 */ 183 */
183 QPtrList<Event> events( const QDate &date, bool sorted = false); 184 QPtrList<Event> events( const QDate &date, bool sorted = false);
184 /** 185 /**
185 Get events, which occur on the given date. 186 Get events, which occur on the given date.
186 The calendar filter is applied. 187 The calendar filter is applied.
187 */ 188 */
188 QPtrList<Event> events( const QDateTime &qdt ); 189 QPtrList<Event> events( const QDateTime &qdt );
189 /** 190 /**
190 Get events in a range of dates. If inclusive is set to true, only events 191 Get events in a range of dates. If inclusive is set to true, only events
191 are returned, which are completely included in the range. 192 are returned, which are completely included in the range.
192 The calendar filter is applied. 193 The calendar filter is applied.
193 */ 194 */
194 QPtrList<Event> events( const QDate &start, const QDate &end, 195 QPtrList<Event> events( const QDate &start, const QDate &end,
195 bool inclusive = false); 196 bool inclusive = false);
196 /** 197 /**
197 Return filtered list of all events in calendar. 198 Return filtered list of all events in calendar.
198 */ 199 */
199 virtual QPtrList<Event> events(); 200 virtual QPtrList<Event> events();
200 /** 201 /**
201 Return unfiltered list of all events in calendar. 202 Return unfiltered list of all events in calendar.
202 */ 203 */
203 virtual QPtrList<Event> rawEvents() = 0; 204 virtual QPtrList<Event> rawEvents() = 0;
204 205
205 /** 206 /**
206 Add a todo to the todolist. 207 Add a todo to the todolist.
207 208
208 @return true on success, false on error. 209 @return true on success, false on error.
209 */ 210 */
210 virtual bool addTodo( Todo *todo ) = 0; 211 virtual bool addTodo( Todo *todo ) = 0;
211 virtual bool addTodoNoDup( Todo *todo ) = 0; 212 virtual bool addTodoNoDup( Todo *todo ) = 0;
212 /** 213 /**
213 Remove a todo from the todolist. 214 Remove a todo from the todolist.
214 */ 215 */
215 virtual void deleteTodo( Todo * ) = 0; 216 virtual void deleteTodo( Todo * ) = 0;
216 virtual void deleteJournal( Journal * ) = 0; 217 virtual void deleteJournal( Journal * ) = 0;
217 /** 218 /**
218 Return filterd list of todos. 219 Return filterd list of todos.
219 */ 220 */
220 virtual QPtrList<Todo> todos(); 221 virtual QPtrList<Todo> todos();
221 /** 222 /**
222 Searches todolist for an event with this unique string identifier, 223 Searches todolist for an event with this unique string identifier,
223 returns a pointer or null. 224 returns a pointer or null.
224 */ 225 */
225 virtual Todo *todo( const QString &uid ) = 0; 226 virtual Todo *todo( const QString &uid ) = 0;
226 virtual Todo *todo( QString, QString ) = 0; 227 virtual Todo *todo( QString, QString ) = 0;
227 /** 228 /**
228 Returns list of todos due on the specified date. 229 Returns list of todos due on the specified date.
229 */ 230 */
230 virtual QPtrList<Todo> todos( const QDate &date ) = 0; 231 virtual QPtrList<Todo> todos( const QDate &date ) = 0;
231 /** 232 /**
232 Return unfiltered list of todos. 233 Return unfiltered list of todos.
233 */ 234 */
234 virtual QPtrList<Todo> rawTodos() = 0; 235 virtual QPtrList<Todo> rawTodos() = 0;
235 236
236 /** 237 /**
237 Add a Journal entry to calendar. 238 Add a Journal entry to calendar.
238 239
239 @return true on success, false on error. 240 @return true on success, false on error.
240 */ 241 */
241 virtual bool addJournal( Journal * ) = 0; 242 virtual bool addJournal( Journal * ) = 0;
242 /** 243 /**
243 Return Journal for given date. 244 Return Journal for given date.
244 */ 245 */
245 virtual Journal *journal( const QDate & ) = 0; 246 virtual Journal *journal( const QDate & ) = 0;
246 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; 247 virtual QPtrList<Journal> journals4Date( const QDate & ) = 0;
247 /** 248 /**
248 Return Journal with given UID. 249 Return Journal with given UID.
249 */ 250 */
250 virtual Journal *journal( const QString &UID ) = 0; 251 virtual Journal *journal( const QString &UID ) = 0;
251 /** 252 /**
252 Return list of all Journal entries. 253 Return list of all Journal entries.
253 */ 254 */
254 virtual QPtrList<Journal> journals() = 0; 255 virtual QPtrList<Journal> journals() = 0;
255 256
256 /** 257 /**
257 Searches all incidence types for an incidence with this unique 258 Searches all incidence types for an incidence with this unique
258 string identifier, returns a pointer or null. 259 string identifier, returns a pointer or null.
259 */ 260 */
260 Incidence* incidence( const QString&UID ); 261 Incidence* incidence( const QString&UID );
261 262
262 /** 263 /**
263 Setup relations for an incidence. 264 Setup relations for an incidence.
264 */ 265 */
265 virtual void setupRelations( Incidence * ); 266 virtual void setupRelations( Incidence * );
266 /** 267 /**
267 Remove all relations to an incidence 268 Remove all relations to an incidence
268 */ 269 */
269 virtual void removeRelations( Incidence * ); 270 virtual void removeRelations( Incidence * );
270 271
271 /** 272 /**
272 Set calendar filter, which filters events for the events() functions. 273 Set calendar filter, which filters events for the events() functions.
273 The Filter object is owned by the caller. 274 The Filter object is owned by the caller.
274 */ 275 */
275 void setFilter( CalFilter * ); 276 void setFilter( CalFilter * );
276 /** 277 /**
277 Return calendar filter. 278 Return calendar filter.
278 */ 279 */
279 CalFilter *filter(); 280 CalFilter *filter();
280 virtual QDateTime nextAlarm( int daysTo ) = 0; 281 virtual QDateTime nextAlarm( int daysTo ) = 0;
281 virtual QString nextSummary( ) const = 0; 282 virtual QString nextSummary( ) const = 0;
282 virtual void reInitAlarmSettings() = 0; 283 virtual void reInitAlarmSettings() = 0;
283 virtual QDateTime nextAlarmEventDateTime() const = 0; 284 virtual QDateTime nextAlarmEventDateTime() const = 0;
284 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; 285 virtual void checkAlarmForIncidence( Incidence *, bool ) = 0;
285 /** 286 /**
286 Return all alarms, which ocur in the given time interval. 287 Return all alarms, which ocur in the given time interval.
287 */ 288 */
288 virtual Alarm::List alarms( const QDateTime &from, 289 virtual Alarm::List alarms( const QDateTime &from,
289 const QDateTime &to ) = 0; 290 const QDateTime &to ) = 0;
290 291
291 class Observer { 292 class Observer {
292 public: 293 public:
293 virtual void calendarModified( bool, Calendar * ) = 0; 294 virtual void calendarModified( bool, Calendar * ) = 0;
294 }; 295 };
295 296
296 void registerObserver( Observer * ); 297 void registerObserver( Observer * );
297 298
298 void setModified( bool ); 299 void setModified( bool );
299 300
300 /** 301 /**
301 Set product id returned by loadedProductId(). This function is only 302 Set product id returned by loadedProductId(). This function is only
302 useful for the calendar loading code. 303 useful for the calendar loading code.
303 */ 304 */
304 void setLoadedProductId( const QString & ); 305 void setLoadedProductId( const QString & );
305 /** 306 /**
306 Return product id taken from file that has been loaded. Returns 307 Return product id taken from file that has been loaded. Returns
307 QString::null, if no calendar has been loaded. 308 QString::null, if no calendar has been loaded.
308 */ 309 */
309 QString loadedProductId(); 310 QString loadedProductId();
310 int defaultCalendar(); 311 int defaultCalendar();
311 void setDontDeleteIncidencesOnClose (); 312 void setDontDeleteIncidencesOnClose ();
312 public slots: 313 public slots:
313 void setDefaultCalendar( int ); 314 void setDefaultCalendar( int );
314 virtual void setCalendarEnabled( int id, bool enable ) = 0; 315 virtual void setCalendarEnabled( int id, bool enable ) = 0;
315 virtual void setAlarmEnabled( int id, bool enable ) = 0; 316 virtual void setAlarmEnabled( int id, bool enable ) = 0;
316 virtual void setReadOnly( int id, bool enable ) = 0; 317 virtual void setReadOnly( int id, bool enable ) = 0;
317 virtual void setDefaultCalendarEnabledOnly() = 0; 318 virtual void setDefaultCalendarEnabledOnly() = 0;
318 virtual void setCalendarRemove( int id ) = 0; 319 virtual void setCalendarRemove( int id ) = 0;
319 signals: 320 signals:
320 void calendarChanged(); 321 void calendarChanged();
321 void calendarSaved(); 322 void calendarSaved();
322 void calendarLoaded(); 323 void calendarLoaded();
323 void addAlarm(const QDateTime &qdt, const QString &noti ); 324 void addAlarm(const QDateTime &qdt, const QString &noti );
324 void removeAlarm(const QDateTime &qdt, const QString &noti ); 325 void removeAlarm(const QDateTime &qdt, const QString &noti );
325 326
326 protected: 327 protected:
327 /** 328 /**
328 Get unfiltered events, which occur on the given date. 329 Get unfiltered events, which occur on the given date.
329 */ 330 */
330 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; 331 virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0;
331 /** 332 /**
332 Get unfiltered events, which occur on the given date. 333 Get unfiltered events, which occur on the given date.
333 */ 334 */
334 virtual QPtrList<Event> rawEventsForDate( const QDate &date, 335 virtual QPtrList<Event> rawEventsForDate( const QDate &date,
335 bool sorted = false ) = 0; 336 bool sorted = false ) = 0;
336 /** 337 /**
337 Get events in a range of dates. If inclusive is set to true, only events 338 Get events in a range of dates. If inclusive is set to true, only events
338 are returned, which are completely included in the range. 339 are returned, which are completely included in the range.
339 */ 340 */
340 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 341 virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
341 bool inclusive = false ) = 0; 342 bool inclusive = false ) = 0;
342 343
343 Incidence *mNextAlarmIncidence; 344 Incidence *mNextAlarmIncidence;
344 Incidence *mUndoIncidence; 345 Incidence *mUndoIncidence;
345 int mDefaultCalendar; 346 int mDefaultCalendar;
346 bool mDeleteIncidencesOnClose; 347 bool mDeleteIncidencesOnClose;
347 348
348private: 349private:
349 void init(); 350 void init();
350 351
351 QString mOwner; // who the calendar belongs to 352 QString mOwner; // who the calendar belongs to
352 QString mOwnerEmail; // email address of the owner 353 QString mOwnerEmail; // email address of the owner
353 int mTimeZone; // timezone OFFSET from GMT (MINUTES) 354 int mTimeZone; // timezone OFFSET from GMT (MINUTES)
354 bool mLocalTime; // use local time, not UTC or a time zone 355 bool mLocalTime; // use local time, not UTC or a time zone
355 356
356 357
357 CalFilter *mFilter; 358 CalFilter *mFilter;
358 CalFilter *mDefaultFilter; 359 CalFilter *mDefaultFilter;
359 360
360 361
361 QString mTimeZoneId; 362 QString mTimeZoneId;
362 363
363 Observer *mObserver; 364 Observer *mObserver;
364 bool mNewObserver; 365 bool mNewObserver;
365 366
366 bool mModified; 367 bool mModified;
367 368
368 QString mLoadedProductId; 369 QString mLoadedProductId;
369 370
370 // This list is used to put together related todos 371 // This list is used to put together related todos
371 QDict<Incidence> mOrphans; 372 QDict<Incidence> mOrphans;
372 QDict<Incidence> mOrphanUids; 373 QDict<Incidence> mOrphanUids;
373}; 374};
374 375
375} 376}
376 377
377#endif 378#endif
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index cce798f..3e42ec0 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,838 +1,913 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <qptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
42 42
43// #ifndef DESKTOP_VERSION 43// #ifndef DESKTOP_VERSION
44// #include <qtopia/alarmserver.h> 44// #include <qtopia/alarmserver.h>
45// #endif 45// #endif
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 if ( mDeleteIncidencesOnClose ) 68 if ( mDeleteIncidencesOnClose )
69 close(); 69 close();
70} 70}
71bool CalendarLocal::mergeCalendarFile( QString name )
72{
73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar );
77 return true;
78 }
79 return false;
80}
81
82Incidence* CalendarLocal::incidenceForUid( const QString& uid )
83{
84 Todo *todo;;
85 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) {
88 if ( retVal ) {
89 if ( retVal->calID() > todo->calID() ) {
90 retVal = todo;
91 }
92 } else {
93 retVal = todo;
94 }
95 }
96 }
97 if ( retVal ) return retVal;
98 Event *event;
99 for ( event = mEventList.first(); event; event = mEventList.next() ) {
100 if ( event->uid() == uid ) {
101 if ( retVal ) {
102 if ( retVal->calID() > event->calID() ) {
103 retVal = event;
104 }
105 } else {
106 retVal = event;
107 }
108 }
109 }
110 if ( retVal ) return retVal;
111 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
112 if ( it->uid() == uid ) {
113 if ( retVal ) {
114 if ( retVal->calID() > it->calID() ) {
115 retVal = it;
116 }
117 } else {
118 retVal = it;
119 }
120 }
121 return retVal;
122}
123
124bool CalendarLocal::mergeCalendar( Calendar* remote )
125{
126 QPtrList<Incidence> er = remote->rawIncidences();
127 Incidence* inR = er.first();
128 Incidence* inL;
129 while ( inR ) {
130 inL = incidenceForUid( inR->uid() );
131 if ( inL ) {
132 int calID = inL->calID();
133 deleteIncidence( inL );
134 inL = inR->clone();
135 inL->setCalID( calID );
136 addIncidence( inL );
137 } else {
138 inL = inR->clone();
139 inL->setCalID( 0 );// add to default cal
140 addIncidence( inL );
141 }
142 inR = er.next();
143 }
144 return true;
145}
71bool CalendarLocal::addCalendarFile( QString name, int id ) 146bool CalendarLocal::addCalendarFile( QString name, int id )
72{ 147{
73 CalendarLocal calendar( timeZoneId() ); 148 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( id ); 149 calendar.setDefaultCalendar( id );
75 if ( calendar.load( name ) ) { 150 if ( calendar.load( name ) ) {
76 addCalendar( &calendar ); 151 addCalendar( &calendar );
77 return true; 152 return true;
78 } 153 }
79 return false; 154 return false;
80} 155}
81void CalendarLocal::setSyncEventsReadOnly() 156void CalendarLocal::setSyncEventsReadOnly()
82{ 157{
83 Event * ev; 158 Event * ev;
84 ev = mEventList.first(); 159 ev = mEventList.first();
85 while ( ev ) { 160 while ( ev ) {
86 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 161 if ( ev->uid().left(15) == QString("last-syncEvent-") )
87 ev->setReadOnly( true ); 162 ev->setReadOnly( true );
88 ev = mEventList.next(); 163 ev = mEventList.next();
89 } 164 }
90} 165}
91void CalendarLocal::addCalendar( Calendar* cal ) 166void CalendarLocal::addCalendar( Calendar* cal )
92{ 167{
93 cal->setDontDeleteIncidencesOnClose(); 168 cal->setDontDeleteIncidencesOnClose();
94 { 169 {
95 QPtrList<Event> EventList = cal->rawEvents(); 170 QPtrList<Event> EventList = cal->rawEvents();
96 Event * ev = EventList.first(); 171 Event * ev = EventList.first();
97 while ( ev ) { 172 while ( ev ) {
98 ev->unRegisterObserver( cal ); 173 ev->unRegisterObserver( cal );
99 ev->registerObserver( this ); 174 ev->registerObserver( this );
100 mEventList.append( ev ); 175 mEventList.append( ev );
101 ev = EventList.next(); 176 ev = EventList.next();
102 } 177 }
103 } 178 }
104 { 179 {
105 180
106 QPtrList<Todo> TodoList = cal->rawTodos(); 181 QPtrList<Todo> TodoList = cal->rawTodos();
107 Todo * ev = TodoList.first(); 182 Todo * ev = TodoList.first();
108 while ( ev ) { 183 while ( ev ) {
109 QString rel = ev->relatedToUid(); 184 QString rel = ev->relatedToUid();
110 if ( !rel.isEmpty() ){ 185 if ( !rel.isEmpty() ){
111 ev->setRelatedTo ( 0 ); 186 ev->setRelatedTo ( 0 );
112 ev->setRelatedToUid( rel ); 187 ev->setRelatedToUid( rel );
113 } 188 }
114 ev = TodoList.next(); 189 ev = TodoList.next();
115 } 190 }
116 //TodoList = cal->rawTodos(); 191 //TodoList = cal->rawTodos();
117 ev = TodoList.first(); 192 ev = TodoList.first();
118 while ( ev ) { 193 while ( ev ) {
119 ev->unRegisterObserver( cal ); 194 ev->unRegisterObserver( cal );
120 ev->registerObserver( this ); 195 ev->registerObserver( this );
121 mTodoList.append( ev ); 196 mTodoList.append( ev );
122 setupRelations( ev ); 197 setupRelations( ev );
123 ev = TodoList.next(); 198 ev = TodoList.next();
124 } 199 }
125 } 200 }
126 { 201 {
127 QPtrList<Journal> JournalList = cal->journals(); 202 QPtrList<Journal> JournalList = cal->journals();
128 Journal * ev = JournalList.first(); 203 Journal * ev = JournalList.first();
129 while ( ev ) { 204 while ( ev ) {
130 ev->unRegisterObserver( cal ); 205 ev->unRegisterObserver( cal );
131 ev->registerObserver( this ); 206 ev->registerObserver( this );
132 mJournalList.append( ev ); 207 mJournalList.append( ev );
133 ev = JournalList.next(); 208 ev = JournalList.next();
134 } 209 }
135 } 210 }
136 setModified( true ); 211 setModified( true );
137} 212}
138bool CalendarLocal::load( const QString &fileName ) 213bool CalendarLocal::load( const QString &fileName )
139{ 214{
140 FileStorage storage( this, fileName ); 215 FileStorage storage( this, fileName );
141 return storage.load(); 216 return storage.load();
142} 217}
143 218
144bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 219bool CalendarLocal::save( const QString &fileName, CalFormat *format )
145{ 220{
146 FileStorage storage( this, fileName, format ); 221 FileStorage storage( this, fileName, format );
147 return storage.save(); 222 return storage.save();
148} 223}
149 224
150void CalendarLocal::stopAllTodos() 225void CalendarLocal::stopAllTodos()
151{ 226{
152 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 227 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
153 it->setRunning( false ); 228 it->setRunning( false );
154 229
155} 230}
156void CalendarLocal::close() 231void CalendarLocal::close()
157{ 232{
158 233
159 Todo * i; 234 Todo * i;
160 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 235 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
161 236
162 mEventList.setAutoDelete( true ); 237 mEventList.setAutoDelete( true );
163 mTodoList.setAutoDelete( true ); 238 mTodoList.setAutoDelete( true );
164 mJournalList.setAutoDelete( false ); 239 mJournalList.setAutoDelete( false );
165 240
166 mEventList.clear(); 241 mEventList.clear();
167 mTodoList.clear(); 242 mTodoList.clear();
168 mJournalList.clear(); 243 mJournalList.clear();
169 244
170 mEventList.setAutoDelete( false ); 245 mEventList.setAutoDelete( false );
171 mTodoList.setAutoDelete( false ); 246 mTodoList.setAutoDelete( false );
172 mJournalList.setAutoDelete( false ); 247 mJournalList.setAutoDelete( false );
173 248
174 setModified( false ); 249 setModified( false );
175} 250}
176 251
177bool CalendarLocal::addAnniversaryNoDup( Event *event ) 252bool CalendarLocal::addAnniversaryNoDup( Event *event )
178{ 253{
179 QString cat; 254 QString cat;
180 bool isBirthday = true; 255 bool isBirthday = true;
181 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 256 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
182 isBirthday = false; 257 isBirthday = false;
183 cat = i18n( "Anniversary" ); 258 cat = i18n( "Anniversary" );
184 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 259 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
185 isBirthday = true; 260 isBirthday = true;
186 cat = i18n( "Birthday" ); 261 cat = i18n( "Birthday" );
187 } else { 262 } else {
188 qDebug("addAnniversaryNoDup called without fitting category! "); 263 qDebug("addAnniversaryNoDup called without fitting category! ");
189 return false; 264 return false;
190 } 265 }
191 Event * eve; 266 Event * eve;
192 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 267 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
193 if ( !(eve->categories().contains( cat ) )) 268 if ( !(eve->categories().contains( cat ) ))
194 continue; 269 continue;
195 // now we have an event with fitting category 270 // now we have an event with fitting category
196 if ( eve->dtStart().date() != event->dtStart().date() ) 271 if ( eve->dtStart().date() != event->dtStart().date() )
197 continue; 272 continue;
198 // now we have an event with fitting category+date 273 // now we have an event with fitting category+date
199 if ( eve->summary() != event->summary() ) 274 if ( eve->summary() != event->summary() )
200 continue; 275 continue;
201 // now we have an event with fitting category+date+summary 276 // now we have an event with fitting category+date+summary
202 return false; 277 return false;
203 } 278 }
204 return addEvent( event ); 279 return addEvent( event );
205 280
206} 281}
207bool CalendarLocal::addEventNoDup( Event *event ) 282bool CalendarLocal::addEventNoDup( Event *event )
208{ 283{
209 Event * eve; 284 Event * eve;
210 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 285 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
211 if ( *eve == *event ) { 286 if ( *eve == *event ) {
212 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 287 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
213 return false; 288 return false;
214 } 289 }
215 } 290 }
216 return addEvent( event ); 291 return addEvent( event );
217} 292}
218 293
219bool CalendarLocal::addEvent( Event *event ) 294bool CalendarLocal::addEvent( Event *event )
220{ 295{
221 insertEvent( event ); 296 insertEvent( event );
222 297
223 event->registerObserver( this ); 298 event->registerObserver( this );
224 299
225 setModified( true ); 300 setModified( true );
226 if ( event->calID() == 0 ) 301 if ( event->calID() == 0 )
227 event->setCalID( mDefaultCalendar ); 302 event->setCalID( mDefaultCalendar );
228 event->setCalEnabled( true ); 303 event->setCalEnabled( true );
229 304
230 return true; 305 return true;
231} 306}
232 307
233void CalendarLocal::deleteEvent( Event *event ) 308void CalendarLocal::deleteEvent( Event *event )
234{ 309{
235 if ( mUndoIncidence ) delete mUndoIncidence; 310 if ( mUndoIncidence ) delete mUndoIncidence;
236 mUndoIncidence = event->clone(); 311 mUndoIncidence = event->clone();
237 if ( mEventList.removeRef( event ) ) { 312 if ( mEventList.removeRef( event ) ) {
238 setModified( true ); 313 setModified( true );
239 } 314 }
240} 315}
241 316
242 317
243Event *CalendarLocal::event( const QString &uid ) 318Event *CalendarLocal::event( const QString &uid )
244{ 319{
245 Event *event; 320 Event *event;
246 Event *retVal = 0; 321 Event *retVal = 0;
247 for ( event = mEventList.first(); event; event = mEventList.next() ) { 322 for ( event = mEventList.first(); event; event = mEventList.next() ) {
248 if ( event->calEnabled() && event->uid() == uid ) { 323 if ( event->calEnabled() && event->uid() == uid ) {
249 if ( retVal ) { 324 if ( retVal ) {
250 if ( retVal->calID() > event->calID() ) { 325 if ( retVal->calID() > event->calID() ) {
251 retVal = event; 326 retVal = event;
252 } 327 }
253 } else { 328 } else {
254 retVal = event; 329 retVal = event;
255 } 330 }
256 } 331 }
257 } 332 }
258 return retVal; 333 return retVal;
259} 334}
260bool CalendarLocal::addTodoNoDup( Todo *todo ) 335bool CalendarLocal::addTodoNoDup( Todo *todo )
261{ 336{
262 Todo * eve; 337 Todo * eve;
263 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { 338 for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) {
264 if ( *eve == *todo ) { 339 if ( *eve == *todo ) {
265 //qDebug("duplicate todo found! not inserted! "); 340 //qDebug("duplicate todo found! not inserted! ");
266 return false; 341 return false;
267 } 342 }
268 } 343 }
269 return addTodo( todo ); 344 return addTodo( todo );
270} 345}
271bool CalendarLocal::addTodo( Todo *todo ) 346bool CalendarLocal::addTodo( Todo *todo )
272{ 347{
273 mTodoList.append( todo ); 348 mTodoList.append( todo );
274 349
275 todo->registerObserver( this ); 350 todo->registerObserver( this );
276 351
277 // Set up subtask relations 352 // Set up subtask relations
278 setupRelations( todo ); 353 setupRelations( todo );
279 354
280 setModified( true ); 355 setModified( true );
281 if ( todo->calID() == 0 ) 356 if ( todo->calID() == 0 )
282 todo->setCalID( mDefaultCalendar ); 357 todo->setCalID( mDefaultCalendar );
283 todo->setCalEnabled( true ); 358 todo->setCalEnabled( true );
284 return true; 359 return true;
285} 360}
286 361
287void CalendarLocal::deleteTodo( Todo *todo ) 362void CalendarLocal::deleteTodo( Todo *todo )
288{ 363{
289 // Handle orphaned children 364 // Handle orphaned children
290 if ( mUndoIncidence ) delete mUndoIncidence; 365 if ( mUndoIncidence ) delete mUndoIncidence;
291 removeRelations( todo ); 366 removeRelations( todo );
292 mUndoIncidence = todo->clone(); 367 mUndoIncidence = todo->clone();
293 368
294 if ( mTodoList.removeRef( todo ) ) { 369 if ( mTodoList.removeRef( todo ) ) {
295 setModified( true ); 370 setModified( true );
296 } 371 }
297} 372}
298 373
299QPtrList<Todo> CalendarLocal::rawTodos() 374QPtrList<Todo> CalendarLocal::rawTodos()
300{ 375{
301 QPtrList<Todo> el; 376 QPtrList<Todo> el;
302 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 377 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
303 if ( it->calEnabled() ) el.append( it ); 378 if ( it->calEnabled() ) el.append( it );
304 return el; 379 return el;
305} 380}
306Todo *CalendarLocal::todo( QString syncProf, QString id ) 381Todo *CalendarLocal::todo( QString syncProf, QString id )
307{ 382{
308 Todo *todo; 383 Todo *todo;
309 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 384 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
310 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 385 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
311 } 386 }
312 387
313 return 0; 388 return 0;
314} 389}
315void CalendarLocal::removeSyncInfo( QString syncProfile) 390void CalendarLocal::removeSyncInfo( QString syncProfile)
316{ 391{
317 QPtrList<Incidence> all = rawIncidences() ; 392 QPtrList<Incidence> all = rawIncidences() ;
318 Incidence *inc; 393 Incidence *inc;
319 for ( inc = all.first(); inc; inc = all.next() ) { 394 for ( inc = all.first(); inc; inc = all.next() ) {
320 inc->removeID( syncProfile ); 395 inc->removeID( syncProfile );
321 } 396 }
322 if ( syncProfile.isEmpty() ) { 397 if ( syncProfile.isEmpty() ) {
323 QPtrList<Event> el; 398 QPtrList<Event> el;
324 Event *todo; 399 Event *todo;
325 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 400 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
326 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 401 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
327 el.append( todo ); 402 el.append( todo );
328 } 403 }
329 for ( todo = el.first(); todo; todo = el.next() ) { 404 for ( todo = el.first(); todo; todo = el.next() ) {
330 deleteIncidence ( todo ); 405 deleteIncidence ( todo );
331 } 406 }
332 } else { 407 } else {
333 Event *lse = event( "last-syncEvent-"+ syncProfile); 408 Event *lse = event( "last-syncEvent-"+ syncProfile);
334 if ( lse ) 409 if ( lse )
335 deleteIncidence ( lse ); 410 deleteIncidence ( lse );
336 } 411 }
337} 412}
338QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 413QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
339{ 414{
340 QPtrList<Event> el; 415 QPtrList<Event> el;
341 Event *todo; 416 Event *todo;
342 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 417 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
343 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 418 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
344 if ( todo->summary().left(3) == "E: " ) 419 if ( todo->summary().left(3) == "E: " )
345 el.append( todo ); 420 el.append( todo );
346 } 421 }
347 422
348 return el; 423 return el;
349 424
350} 425}
351Event *CalendarLocal::event( QString syncProf, QString id ) 426Event *CalendarLocal::event( QString syncProf, QString id )
352{ 427{
353 Event *todo; 428 Event *todo;
354 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 429 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
355 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 430 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
356 } 431 }
357 432
358 return 0; 433 return 0;
359} 434}
360Todo *CalendarLocal::todo( const QString &uid ) 435Todo *CalendarLocal::todo( const QString &uid )
361{ 436{
362 Todo *todo;; 437 Todo *todo;;
363 Todo *retVal = 0; 438 Todo *retVal = 0;
364 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 439 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
365 if ( todo->calEnabled() && todo->uid() == uid ) { 440 if ( todo->calEnabled() && todo->uid() == uid ) {
366 if ( retVal ) { 441 if ( retVal ) {
367 if ( retVal->calID() > todo->calID() ) { 442 if ( retVal->calID() > todo->calID() ) {
368 retVal = todo; 443 retVal = todo;
369 } 444 }
370 } else { 445 } else {
371 retVal = todo; 446 retVal = todo;
372 } 447 }
373 } 448 }
374 } 449 }
375 return retVal; 450 return retVal;
376} 451}
377QString CalendarLocal::nextSummary() const 452QString CalendarLocal::nextSummary() const
378{ 453{
379 return mNextSummary; 454 return mNextSummary;
380} 455}
381QDateTime CalendarLocal::nextAlarmEventDateTime() const 456QDateTime CalendarLocal::nextAlarmEventDateTime() const
382{ 457{
383 return mNextAlarmEventDateTime; 458 return mNextAlarmEventDateTime;
384} 459}
385void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) 460void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
386{ 461{
387 //mNextAlarmIncidence 462 //mNextAlarmIncidence
388 //mNextAlarmDateTime 463 //mNextAlarmDateTime
389 //return mNextSummary; 464 //return mNextSummary;
390 //return mNextAlarmEventDateTime; 465 //return mNextAlarmEventDateTime;
391 bool newNextAlarm = false; 466 bool newNextAlarm = false;
392 bool computeNextAlarm = false; 467 bool computeNextAlarm = false;
393 bool ok; 468 bool ok;
394 int offset; 469 int offset;
395 QDateTime nextA; 470 QDateTime nextA;
396 // QString nextSum; 471 // QString nextSum;
397 //QDateTime nextEvent; 472 //QDateTime nextEvent;
398 if ( mNextAlarmIncidence == 0 || incidence == 0 ) { 473 if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
399 computeNextAlarm = true; 474 computeNextAlarm = true;
400 } else { 475 } else {
401 if ( ! deleted ) { 476 if ( ! deleted ) {
402 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 477 nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
403 if ( ok ) { 478 if ( ok ) {
404 if ( nextA < mNextAlarmDateTime ) { 479 if ( nextA < mNextAlarmDateTime ) {
405 deRegisterAlarm(); 480 deRegisterAlarm();
406 mNextAlarmDateTime = nextA; 481 mNextAlarmDateTime = nextA;
407 mNextSummary = incidence->summary(); 482 mNextSummary = incidence->summary();
408 mNextAlarmEventDateTime = nextA.addSecs(offset ) ; 483 mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
409 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 484 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
410 newNextAlarm = true; 485 newNextAlarm = true;
411 mNextAlarmIncidence = incidence; 486 mNextAlarmIncidence = incidence;
412 } else { 487 } else {
413 if ( incidence == mNextAlarmIncidence ) { 488 if ( incidence == mNextAlarmIncidence ) {
414 computeNextAlarm = true; 489 computeNextAlarm = true;
415 } 490 }
416 } 491 }
417 } else { 492 } else {
418 if ( mNextAlarmIncidence == incidence ) { 493 if ( mNextAlarmIncidence == incidence ) {
419 computeNextAlarm = true; 494 computeNextAlarm = true;
420 } 495 }
421 } 496 }
422 } else { // deleted 497 } else { // deleted
423 if ( incidence == mNextAlarmIncidence ) { 498 if ( incidence == mNextAlarmIncidence ) {
424 computeNextAlarm = true; 499 computeNextAlarm = true;
425 } 500 }
426 } 501 }
427 } 502 }
428 if ( computeNextAlarm ) { 503 if ( computeNextAlarm ) {
429 deRegisterAlarm(); 504 deRegisterAlarm();
430 nextA = nextAlarm( 1000 ); 505 nextA = nextAlarm( 1000 );
431 if (! mNextAlarmIncidence ) { 506 if (! mNextAlarmIncidence ) {
432 return; 507 return;
433 } 508 }
434 newNextAlarm = true; 509 newNextAlarm = true;
435 } 510 }
436 if ( newNextAlarm ) 511 if ( newNextAlarm )
437 registerAlarm(); 512 registerAlarm();
438} 513}
439QString CalendarLocal:: getAlarmNotification() 514QString CalendarLocal:: getAlarmNotification()
440{ 515{
441 QString ret; 516 QString ret;
442 // this should not happen 517 // this should not happen
443 if (! mNextAlarmIncidence ) 518 if (! mNextAlarmIncidence )
444 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; 519 return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
445 Alarm* alarm = mNextAlarmIncidence->alarms().first(); 520 Alarm* alarm = mNextAlarmIncidence->alarms().first();
446 if ( alarm->type() == Alarm::Procedure ) { 521 if ( alarm->type() == Alarm::Procedure ) {
447 ret = "proc_alarm" + alarm->programFile()+"+++"; 522 ret = "proc_alarm" + alarm->programFile()+"+++";
448 } else { 523 } else {
449 ret = "audio_alarm" +alarm->audioFile() +"+++"; 524 ret = "audio_alarm" +alarm->audioFile() +"+++";
450 } 525 }
451 ret += "cal_alarm"+ mNextSummary.left( 25 ); 526 ret += "cal_alarm"+ mNextSummary.left( 25 );
452 if ( mNextSummary.length() > 25 ) 527 if ( mNextSummary.length() > 25 )
453 ret += "\n" + mNextSummary.mid(25, 25 ); 528 ret += "\n" + mNextSummary.mid(25, 25 );
454 ret+= "\n"+mNextAlarmEventDateTimeString; 529 ret+= "\n"+mNextAlarmEventDateTimeString;
455 return ret; 530 return ret;
456} 531}
457void CalendarLocal::registerAlarm() 532void CalendarLocal::registerAlarm()
458{ 533{
459 mLastAlarmNotificationString = getAlarmNotification(); 534 mLastAlarmNotificationString = getAlarmNotification();
460 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); 535 // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
461 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 536 emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
462// #ifndef DESKTOP_VERSION 537// #ifndef DESKTOP_VERSION
463// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 538// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
464// #endif 539// #endif
465} 540}
466void CalendarLocal::deRegisterAlarm() 541void CalendarLocal::deRegisterAlarm()
467{ 542{
468 if ( mLastAlarmNotificationString.isNull() ) 543 if ( mLastAlarmNotificationString.isNull() )
469 return; 544 return;
470 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 545 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
471 546
472 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 547 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
473 mNextAlarmEventDateTime = QDateTime(); 548 mNextAlarmEventDateTime = QDateTime();
474// #ifndef DESKTOP_VERSION 549// #ifndef DESKTOP_VERSION
475// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 550// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
476// #endif 551// #endif
477} 552}
478 553
479QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 554QPtrList<Todo> CalendarLocal::todos( const QDate &date )
480{ 555{
481 QPtrList<Todo> todos; 556 QPtrList<Todo> todos;
482 557
483 Todo *todo; 558 Todo *todo;
484 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 559 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
485 if ( !todo->calEnabled() ) continue; 560 if ( !todo->calEnabled() ) continue;
486 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 561 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
487 todos.append( todo ); 562 todos.append( todo );
488 } 563 }
489 } 564 }
490 565
491 filter()->apply( &todos ); 566 filter()->apply( &todos );
492 return todos; 567 return todos;
493} 568}
494void CalendarLocal::reInitAlarmSettings() 569void CalendarLocal::reInitAlarmSettings()
495{ 570{
496 if ( !mNextAlarmIncidence ) { 571 if ( !mNextAlarmIncidence ) {
497 nextAlarm( 1000 ); 572 nextAlarm( 1000 );
498 } 573 }
499 deRegisterAlarm(); 574 deRegisterAlarm();
500 mNextAlarmIncidence = 0; 575 mNextAlarmIncidence = 0;
501 checkAlarmForIncidence( 0, false ); 576 checkAlarmForIncidence( 0, false );
502 577
503} 578}
504 579
505 580
506 581
507QDateTime CalendarLocal::nextAlarm( int daysTo ) 582QDateTime CalendarLocal::nextAlarm( int daysTo )
508{ 583{
509 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); 584 QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo );
510 QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); 585 QDateTime start = QDateTime::currentDateTime().addSecs( 30 );
511 QDateTime next; 586 QDateTime next;
512 Event *e; 587 Event *e;
513 bool ok; 588 bool ok;
514 bool found = false; 589 bool found = false;
515 int offset; 590 int offset;
516 mNextAlarmIncidence = 0; 591 mNextAlarmIncidence = 0;
517 for( e = mEventList.first(); e; e = mEventList.next() ) { 592 for( e = mEventList.first(); e; e = mEventList.next() ) {
518 if ( !e->calEnabled() ) continue; 593 if ( !e->calEnabled() ) continue;
519 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 594 next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
520 if ( ok ) { 595 if ( ok ) {
521 if ( next < nextA ) { 596 if ( next < nextA ) {
522 nextA = next; 597 nextA = next;
523 found = true; 598 found = true;
524 mNextSummary = e->summary(); 599 mNextSummary = e->summary();
525 mNextAlarmEventDateTime = next.addSecs(offset ) ; 600 mNextAlarmEventDateTime = next.addSecs(offset ) ;
526 mNextAlarmIncidence = (Incidence *) e; 601 mNextAlarmIncidence = (Incidence *) e;
527 } 602 }
528 } 603 }
529 } 604 }
530 Todo *t; 605 Todo *t;
531 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 606 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
532 if ( !t->calEnabled() ) continue; 607 if ( !t->calEnabled() ) continue;
533 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; 608 next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
534 if ( ok ) { 609 if ( ok ) {
535 if ( next < nextA ) { 610 if ( next < nextA ) {
536 nextA = next; 611 nextA = next;
537 found = true; 612 found = true;
538 mNextSummary = t->summary(); 613 mNextSummary = t->summary();
539 mNextAlarmEventDateTime = next.addSecs(offset ); 614 mNextAlarmEventDateTime = next.addSecs(offset );
540 mNextAlarmIncidence = (Incidence *) t; 615 mNextAlarmIncidence = (Incidence *) t;
541 } 616 }
542 } 617 }
543 } 618 }
544 if ( mNextAlarmIncidence ) { 619 if ( mNextAlarmIncidence ) {
545 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); 620 mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
546 mNextAlarmDateTime = nextA; 621 mNextAlarmDateTime = nextA;
547 } 622 }
548 return nextA; 623 return nextA;
549} 624}
550Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) 625Alarm::List CalendarLocal::alarmsTo( const QDateTime &to )
551{ 626{
552 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); 627 return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to );
553} 628}
554 629
555Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) 630Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
556{ 631{
557 632
558 Alarm::List alarms; 633 Alarm::List alarms;
559 634
560 Event *e; 635 Event *e;
561 636
562 for( e = mEventList.first(); e; e = mEventList.next() ) { 637 for( e = mEventList.first(); e; e = mEventList.next() ) {
563 if ( !e->calEnabled() ) continue; 638 if ( !e->calEnabled() ) continue;
564 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 639 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
565 else appendAlarms( alarms, e, from, to ); 640 else appendAlarms( alarms, e, from, to );
566 } 641 }
567 642
568 Todo *t; 643 Todo *t;
569 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 644 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
570 if ( !t->calEnabled() ) continue; 645 if ( !t->calEnabled() ) continue;
571 appendAlarms( alarms, t, from, to ); 646 appendAlarms( alarms, t, from, to );
572 } 647 }
573 648
574 return alarms; 649 return alarms;
575} 650}
576 651
577void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 652void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
578 const QDateTime &from, const QDateTime &to ) 653 const QDateTime &from, const QDateTime &to )
579{ 654{
580 QPtrList<Alarm> alarmList = incidence->alarms(); 655 QPtrList<Alarm> alarmList = incidence->alarms();
581 Alarm *alarm; 656 Alarm *alarm;
582 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 657 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
583// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 658// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
584// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 659// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
585 if ( alarm->enabled() ) { 660 if ( alarm->enabled() ) {
586 if ( alarm->time() >= from && alarm->time() <= to ) { 661 if ( alarm->time() >= from && alarm->time() <= to ) {
587 alarms.append( alarm ); 662 alarms.append( alarm );
588 } 663 }
589 } 664 }
590 } 665 }
591} 666}
592 667
593void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 668void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
594 Incidence *incidence, 669 Incidence *incidence,
595 const QDateTime &from, 670 const QDateTime &from,
596 const QDateTime &to ) 671 const QDateTime &to )
597{ 672{
598 673
599 QPtrList<Alarm> alarmList = incidence->alarms(); 674 QPtrList<Alarm> alarmList = incidence->alarms();
600 Alarm *alarm; 675 Alarm *alarm;
601 QDateTime qdt; 676 QDateTime qdt;
602 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 677 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
603 if (incidence->recursOn(from.date())) { 678 if (incidence->recursOn(from.date())) {
604 qdt.setTime(alarm->time().time()); 679 qdt.setTime(alarm->time().time());
605 qdt.setDate(from.date()); 680 qdt.setDate(from.date());
606 } 681 }
607 else qdt = alarm->time(); 682 else qdt = alarm->time();
608 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 683 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
609 if ( alarm->enabled() ) { 684 if ( alarm->enabled() ) {
610 if ( qdt >= from && qdt <= to ) { 685 if ( qdt >= from && qdt <= to ) {
611 alarms.append( alarm ); 686 alarms.append( alarm );
612 } 687 }
613 } 688 }
614 } 689 }
615} 690}
616 691
617 692
618/****************************** PROTECTED METHODS ****************************/ 693/****************************** PROTECTED METHODS ****************************/
619 694
620// after changes are made to an event, this should be called. 695// after changes are made to an event, this should be called.
621void CalendarLocal::update( IncidenceBase *incidence ) 696void CalendarLocal::update( IncidenceBase *incidence )
622{ 697{
623 incidence->setSyncStatus( Event::SYNCMOD ); 698 incidence->setSyncStatus( Event::SYNCMOD );
624 incidence->setLastModified( QDateTime::currentDateTime() ); 699 incidence->setLastModified( QDateTime::currentDateTime() );
625 // we should probably update the revision number here, 700 // we should probably update the revision number here,
626 // or internally in the Event itself when certain things change. 701 // or internally in the Event itself when certain things change.
627 // need to verify with ical documentation. 702 // need to verify with ical documentation.
628 703
629 setModified( true ); 704 setModified( true );
630} 705}
631 706
632void CalendarLocal::insertEvent( Event *event ) 707void CalendarLocal::insertEvent( Event *event )
633{ 708{
634 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 709 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
635} 710}
636 711
637 712
638QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 713QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
639{ 714{
640 QPtrList<Event> eventList; 715 QPtrList<Event> eventList;
641 716
642 Event *event; 717 Event *event;
643 for( event = mEventList.first(); event; event = mEventList.next() ) { 718 for( event = mEventList.first(); event; event = mEventList.next() ) {
644 if ( !event->calEnabled() ) continue; 719 if ( !event->calEnabled() ) continue;
645 if ( event->doesRecur() ) { 720 if ( event->doesRecur() ) {
646 if ( event->isMultiDay() ) { 721 if ( event->isMultiDay() ) {
647 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 722 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
648 int i; 723 int i;
649 for ( i = 0; i <= extraDays; i++ ) { 724 for ( i = 0; i <= extraDays; i++ ) {
650 if ( event->recursOn( qd.addDays( -i ) ) ) { 725 if ( event->recursOn( qd.addDays( -i ) ) ) {
651 eventList.append( event ); 726 eventList.append( event );
652 break; 727 break;
653 } 728 }
654 } 729 }
655 } else { 730 } else {
656 if ( event->recursOn( qd ) ) 731 if ( event->recursOn( qd ) )
657 eventList.append( event ); 732 eventList.append( event );
658 } 733 }
659 } else { 734 } else {
660 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 735 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
661 eventList.append( event ); 736 eventList.append( event );
662 } 737 }
663 } 738 }
664 } 739 }
665 740
666 if ( !sorted ) { 741 if ( !sorted ) {
667 return eventList; 742 return eventList;
668 } 743 }
669 744
670 // kdDebug(5800) << "Sorting events for date\n" << endl; 745 // kdDebug(5800) << "Sorting events for date\n" << endl;
671 // now, we have to sort it based on dtStart.time() 746 // now, we have to sort it based on dtStart.time()
672 QPtrList<Event> eventListSorted; 747 QPtrList<Event> eventListSorted;
673 Event *sortEvent; 748 Event *sortEvent;
674 for ( event = eventList.first(); event; event = eventList.next() ) { 749 for ( event = eventList.first(); event; event = eventList.next() ) {
675 sortEvent = eventListSorted.first(); 750 sortEvent = eventListSorted.first();
676 int i = 0; 751 int i = 0;
677 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 752 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
678 { 753 {
679 i++; 754 i++;
680 sortEvent = eventListSorted.next(); 755 sortEvent = eventListSorted.next();
681 } 756 }
682 eventListSorted.insert( i, event ); 757 eventListSorted.insert( i, event );
683 } 758 }
684 return eventListSorted; 759 return eventListSorted;
685} 760}
686 761
687 762
688QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 763QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
689 bool inclusive ) 764 bool inclusive )
690{ 765{
691 Event *event = 0; 766 Event *event = 0;
692 767
693 QPtrList<Event> eventList; 768 QPtrList<Event> eventList;
694 769
695 // Get non-recurring events 770 // Get non-recurring events
696 for( event = mEventList.first(); event; event = mEventList.next() ) { 771 for( event = mEventList.first(); event; event = mEventList.next() ) {
697 if ( !event->calEnabled() ) continue; 772 if ( !event->calEnabled() ) continue;
698 if ( event->doesRecur() ) { 773 if ( event->doesRecur() ) {
699 QDate rStart = event->dtStart().date(); 774 QDate rStart = event->dtStart().date();
700 bool found = false; 775 bool found = false;
701 if ( inclusive ) { 776 if ( inclusive ) {
702 if ( rStart >= start && rStart <= end ) { 777 if ( rStart >= start && rStart <= end ) {
703 // Start date of event is in range. Now check for end date. 778 // Start date of event is in range. Now check for end date.
704 // if duration is negative, event recurs forever, so do not include it. 779 // if duration is negative, event recurs forever, so do not include it.
705 if ( event->recurrence()->duration() == 0 ) { // End date set 780 if ( event->recurrence()->duration() == 0 ) { // End date set
706 QDate rEnd = event->recurrence()->endDate(); 781 QDate rEnd = event->recurrence()->endDate();
707 if ( rEnd >= start && rEnd <= end ) { // End date within range 782 if ( rEnd >= start && rEnd <= end ) { // End date within range
708 found = true; 783 found = true;
709 } 784 }
710 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 785 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
711 // TODO: Calculate end date from duration. Should be done in Event 786 // TODO: Calculate end date from duration. Should be done in Event
712 // For now exclude all events with a duration. 787 // For now exclude all events with a duration.
713 } 788 }
714 } 789 }
715 } else { 790 } else {
716 bool founOne; 791 bool founOne;
717 QDate next = event->getNextOccurence( start, &founOne ).date(); 792 QDate next = event->getNextOccurence( start, &founOne ).date();
718 if ( founOne ) { 793 if ( founOne ) {
719 if ( next <= end ) { 794 if ( next <= end ) {
720 found = true; 795 found = true;
721 } 796 }
722 } 797 }
723 798
724 /* 799 /*
725 // crap !!! 800 // crap !!!
726 if ( rStart <= end ) { // Start date not after range 801 if ( rStart <= end ) { // Start date not after range
727 if ( rStart >= start ) { // Start date within range 802 if ( rStart >= start ) { // Start date within range
728 found = true; 803 found = true;
729 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 804 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
730 found = true; 805 found = true;
731 } else if ( event->recurrence()->duration() == 0 ) { // End date set 806 } else if ( event->recurrence()->duration() == 0 ) { // End date set
732 QDate rEnd = event->recurrence()->endDate(); 807 QDate rEnd = event->recurrence()->endDate();
733 if ( rEnd >= start && rEnd <= end ) { // End date within range 808 if ( rEnd >= start && rEnd <= end ) { // End date within range
734 found = true; 809 found = true;
735 } 810 }
736 } else { // Duration set 811 } else { // Duration set
737 // TODO: Calculate end date from duration. Should be done in Event 812 // TODO: Calculate end date from duration. Should be done in Event
738 // For now include all events with a duration. 813 // For now include all events with a duration.
739 found = true; 814 found = true;
740 } 815 }
741 } 816 }
742 */ 817 */
743 818
744 } 819 }
745 820
746 if ( found ) eventList.append( event ); 821 if ( found ) eventList.append( event );
747 } else { 822 } else {
748 QDate s = event->dtStart().date(); 823 QDate s = event->dtStart().date();
749 QDate e = event->dtEnd().date(); 824 QDate e = event->dtEnd().date();
750 825
751 if ( inclusive ) { 826 if ( inclusive ) {
752 if ( s >= start && e <= end ) { 827 if ( s >= start && e <= end ) {
753 eventList.append( event ); 828 eventList.append( event );
754 } 829 }
755 } else { 830 } else {
756 if ( ( e >= start && s <= end ) ) { 831 if ( ( e >= start && s <= end ) ) {
757 eventList.append( event ); 832 eventList.append( event );
758 } 833 }
759 } 834 }
760 } 835 }
761 } 836 }
762 837
763 return eventList; 838 return eventList;
764} 839}
765 840
766QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 841QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
767{ 842{
768 return rawEventsForDate( qdt.date() ); 843 return rawEventsForDate( qdt.date() );
769} 844}
770 845
771QPtrList<Event> CalendarLocal::rawEvents() 846QPtrList<Event> CalendarLocal::rawEvents()
772{ 847{
773 QPtrList<Event> el; 848 QPtrList<Event> el;
774 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 849 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
775 if ( it->calEnabled() ) el.append( it ); 850 if ( it->calEnabled() ) el.append( it );
776 return el; 851 return el;
777} 852}
778 853
779bool CalendarLocal::addJournal(Journal *journal) 854bool CalendarLocal::addJournal(Journal *journal)
780{ 855{
781 mJournalList.append(journal); 856 mJournalList.append(journal);
782 857
783 journal->registerObserver( this ); 858 journal->registerObserver( this );
784 859
785 setModified( true ); 860 setModified( true );
786 if ( journal->calID() == 0 ) 861 if ( journal->calID() == 0 )
787 journal->setCalID( mDefaultCalendar ); 862 journal->setCalID( mDefaultCalendar );
788 journal->setCalEnabled( true ); 863 journal->setCalEnabled( true );
789 return true; 864 return true;
790} 865}
791 866
792void CalendarLocal::deleteJournal( Journal *journal ) 867void CalendarLocal::deleteJournal( Journal *journal )
793{ 868{
794 if ( mUndoIncidence ) delete mUndoIncidence; 869 if ( mUndoIncidence ) delete mUndoIncidence;
795 mUndoIncidence = journal->clone(); 870 mUndoIncidence = journal->clone();
796 mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); 871 mUndoIncidence->setSummary( mUndoIncidence->description().left(25));
797 if ( mJournalList.removeRef(journal) ) { 872 if ( mJournalList.removeRef(journal) ) {
798 setModified( true ); 873 setModified( true );
799 } 874 }
800} 875}
801 876
802QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 877QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
803{ 878{
804 QPtrList<Journal> el; 879 QPtrList<Journal> el;
805 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 880 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
806 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 881 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
807 return el; 882 return el;
808} 883}
809Journal *CalendarLocal::journal( const QDate &date ) 884Journal *CalendarLocal::journal( const QDate &date )
810{ 885{
811// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 886// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
812 887
813 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 888 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
814 if ( it->calEnabled() && it->dtStart().date() == date ) 889 if ( it->calEnabled() && it->dtStart().date() == date )
815 return it; 890 return it;
816 891
817 return 0; 892 return 0;
818} 893}
819 894
820Journal *CalendarLocal::journal( const QString &uid ) 895Journal *CalendarLocal::journal( const QString &uid )
821{ 896{
822 Journal * retVal = 0; 897 Journal * retVal = 0;
823 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 898 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
824 if ( it->calEnabled() && it->uid() == uid ) { 899 if ( it->calEnabled() && it->uid() == uid ) {
825 if ( retVal ) { 900 if ( retVal ) {
826 if ( retVal->calID() > it->calID() ) { 901 if ( retVal->calID() > it->calID() ) {
827 retVal = it; 902 retVal = it;
828 } 903 }
829 } else { 904 } else {
830 retVal = it; 905 retVal = it;
831 } 906 }
832 } 907 }
833 return retVal; 908 return retVal;
834} 909}
835 910
836QPtrList<Journal> CalendarLocal::journals() 911QPtrList<Journal> CalendarLocal::journals()
837{ 912{
838 QPtrList<Journal> el; 913 QPtrList<Journal> el;
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 98d16a3..23b0542 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -1,227 +1,230 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 1998 Preston Brown 4 Copyright (c) 1998 Preston Brown
5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> 5 Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_CALENDARLOCAL_H 22#ifndef KCAL_CALENDARLOCAL_H
23#define KCAL_CALENDARLOCAL_H 23#define KCAL_CALENDARLOCAL_H
24 24
25#include "calendar.h" 25#include "calendar.h"
26 26
27namespace KCal { 27namespace KCal {
28 28
29class CalFormat; 29class CalFormat;
30 30
31/** 31/**
32 This class provides a calendar stored as a local file. 32 This class provides a calendar stored as a local file.
33*/ 33*/
34class CalendarLocal : public Calendar 34class CalendarLocal : public Calendar
35{ 35{
36 public: 36 public:
37 /** 37 /**
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 bool mergeCalendarFile( QString name );
49 bool mergeCalendar( Calendar* cal );
50 Incidence* incidenceForUid( const QString& uid );
48 void setSyncEventsReadOnly(); 51 void setSyncEventsReadOnly();
49 void stopAllTodos(); 52 void stopAllTodos();
50 /** 53 /**
51 Loads a calendar on disk in vCalendar or iCalendar format into the current 54 Loads a calendar on disk in vCalendar or iCalendar format into the current
52 calendar. Any information already present is lost. 55 calendar. Any information already present is lost.
53 @return true, if successfull, false on error. 56 @return true, if successfull, false on error.
54 @param fileName the name of the calendar on disk. 57 @param fileName the name of the calendar on disk.
55 */ 58 */
56 bool load( const QString &fileName ); 59 bool load( const QString &fileName );
57 /** 60 /**
58 Writes out the calendar to disk in the specified \a format. 61 Writes out the calendar to disk in the specified \a format.
59 CalendarLocal takes ownership of the CalFormat object. 62 CalendarLocal takes ownership of the CalFormat object.
60 @return true, if successfull, false on error. 63 @return true, if successfull, false on error.
61 @param fileName the name of the file 64 @param fileName the name of the file
62 */ 65 */
63 bool save( const QString &fileName, CalFormat *format = 0 ); 66 bool save( const QString &fileName, CalFormat *format = 0 );
64 67
65 /** 68 /**
66 Clears out the current calendar, freeing all used memory etc. etc. 69 Clears out the current calendar, freeing all used memory etc. etc.
67 */ 70 */
68 void close(); 71 void close();
69 72
70 void save() {} 73 void save() {}
71 74
72 /** 75 /**
73 Add Event to calendar. 76 Add Event to calendar.
74 */ 77 */
75 void removeSyncInfo( QString syncProfile); 78 void removeSyncInfo( QString syncProfile);
76 bool addAnniversaryNoDup( Event *event ); 79 bool addAnniversaryNoDup( Event *event );
77 bool addEventNoDup( Event *event ); 80 bool addEventNoDup( Event *event );
78 bool addEvent( Event *event ); 81 bool addEvent( Event *event );
79 /** 82 /**
80 Deletes an event from this calendar. 83 Deletes an event from this calendar.
81 */ 84 */
82 void deleteEvent( Event *event ); 85 void deleteEvent( Event *event );
83 86
84 /** 87 /**
85 Retrieves an event on the basis of the unique string ID. 88 Retrieves an event on the basis of the unique string ID.
86 */ 89 */
87 Event *event( const QString &uid ); 90 Event *event( const QString &uid );
88 /** 91 /**
89 Return unfiltered list of all events in calendar. 92 Return unfiltered list of all events in calendar.
90 */ 93 */
91 QPtrList<Event> rawEvents(); 94 QPtrList<Event> rawEvents();
92 QPtrList<Event> getExternLastSyncEvents(); 95 QPtrList<Event> getExternLastSyncEvents();
93 /** 96 /**
94 Add a todo to the todolist. 97 Add a todo to the todolist.
95 */ 98 */
96 bool addTodo( Todo *todo ); 99 bool addTodo( Todo *todo );
97 bool addTodoNoDup( Todo *todo ); 100 bool addTodoNoDup( Todo *todo );
98 /** 101 /**
99 Remove a todo from the todolist. 102 Remove a todo from the todolist.
100 */ 103 */
101 void deleteTodo( Todo * ); 104 void deleteTodo( Todo * );
102 /** 105 /**
103 Searches todolist for an event with this unique string identifier, 106 Searches todolist for an event with this unique string identifier,
104 returns a pointer or null. 107 returns a pointer or null.
105 */ 108 */
106 Todo *todo( const QString &uid ); 109 Todo *todo( const QString &uid );
107 /** 110 /**
108 Return list of all todos. 111 Return list of all todos.
109 */ 112 */
110 QPtrList<Todo> rawTodos(); 113 QPtrList<Todo> rawTodos();
111 /** 114 /**
112 Returns list of todos due on the specified date. 115 Returns list of todos due on the specified date.
113 */ 116 */
114 QPtrList<Todo> todos( const QDate &date ); 117 QPtrList<Todo> todos( const QDate &date );
115 /** 118 /**
116 Return list of all todos. 119 Return list of all todos.
117 120
118 Workaround because compiler does not recognize function of base class. 121 Workaround because compiler does not recognize function of base class.
119 */ 122 */
120 QPtrList<Todo> todos() { return Calendar::todos(); } 123 QPtrList<Todo> todos() { return Calendar::todos(); }
121 124
122 /** 125 /**
123 Add a Journal entry to calendar. 126 Add a Journal entry to calendar.
124 */ 127 */
125 bool addJournal( Journal * ); 128 bool addJournal( Journal * );
126 /** 129 /**
127 Remove a Journal from the calendar. 130 Remove a Journal from the calendar.
128 */ 131 */
129 void deleteJournal( Journal * ); 132 void deleteJournal( Journal * );
130 /** 133 /**
131 Return Journal for given date. 134 Return Journal for given date.
132 */ 135 */
133 Journal *journal( const QDate & ); 136 Journal *journal( const QDate & );
134 QPtrList<Journal> journals4Date( const QDate & ); 137 QPtrList<Journal> journals4Date( const QDate & );
135 /** 138 /**
136 Return Journal with given UID. 139 Return Journal with given UID.
137 */ 140 */
138 Journal *journal( const QString &uid ); 141 Journal *journal( const QString &uid );
139 /** 142 /**
140 Return list of all Journals stored in calendar. 143 Return list of all Journals stored in calendar.
141 */ 144 */
142 QPtrList<Journal> journals(); 145 QPtrList<Journal> journals();
143 146
144 /** 147 /**
145 Return all alarms, which ocur in the given time interval. 148 Return all alarms, which ocur in the given time interval.
146 */ 149 */
147 Alarm::List alarms( const QDateTime &from, const QDateTime &to ); 150 Alarm::List alarms( const QDateTime &from, const QDateTime &to );
148 151
149 /** 152 /**
150 Return all alarms, which ocur before given date. 153 Return all alarms, which ocur before given date.
151 */ 154 */
152 Alarm::List alarmsTo( const QDateTime &to ); 155 Alarm::List alarmsTo( const QDateTime &to );
153 156
154 QDateTime nextAlarm( int daysTo ) ; 157 QDateTime nextAlarm( int daysTo ) ;
155 QDateTime nextAlarmEventDateTime() const; 158 QDateTime nextAlarmEventDateTime() const;
156 void checkAlarmForIncidence( Incidence *, bool deleted ) ; 159 void checkAlarmForIncidence( Incidence *, bool deleted ) ;
157 void registerAlarm(); 160 void registerAlarm();
158 void deRegisterAlarm(); 161 void deRegisterAlarm();
159 QString getAlarmNotification(); 162 QString getAlarmNotification();
160 QString nextSummary() const ; 163 QString nextSummary() const ;
161 /** 164 /**
162 This method should be called whenever a Event is modified directly 165 This method should be called whenever a Event is modified directly
163 via it's pointer. It makes sure that the calendar is internally 166 via it's pointer. It makes sure that the calendar is internally
164 consistent. 167 consistent.
165 */ 168 */
166 void update( IncidenceBase *incidence ); 169 void update( IncidenceBase *incidence );
167 170
168 /** 171 /**
169 Builds and then returns a list of all events that match for the 172 Builds and then returns a list of all events that match for the
170 date specified. useful for dayView, etc. etc. 173 date specified. useful for dayView, etc. etc.
171 */ 174 */
172 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); 175 QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false );
173 /** 176 /**
174 Get unfiltered events for date \a qdt. 177 Get unfiltered events for date \a qdt.
175 */ 178 */
176 QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); 179 QPtrList<Event> rawEventsForDate( const QDateTime &qdt );
177 /** 180 /**
178 Get unfiltered events in a range of dates. If inclusive is set to true, 181 Get unfiltered events in a range of dates. If inclusive is set to true,
179 only events are returned, which are completely included in the range. 182 only events are returned, which are completely included in the range.
180 */ 183 */
181 QPtrList<Event> rawEvents( const QDate &start, const QDate &end, 184 QPtrList<Event> rawEvents( const QDate &start, const QDate &end,
182 bool inclusive = false ); 185 bool inclusive = false );
183 Todo *todo( QString, QString ); 186 Todo *todo( QString, QString );
184 Event *event( QString, QString ); 187 Event *event( QString, QString );
185 188
186public slots: 189public slots:
187 void setCalendarEnabled( int id, bool enable ); 190 void setCalendarEnabled( int id, bool enable );
188 void setAlarmEnabled( int id, bool enable ); 191 void setAlarmEnabled( int id, bool enable );
189 void setReadOnly( int id, bool enable ); 192 void setReadOnly( int id, bool enable );
190 void setDefaultCalendarEnabledOnly(); 193 void setDefaultCalendarEnabledOnly();
191 void setCalendarRemove( int id ); 194 void setCalendarRemove( int id );
192 195
193 protected: 196 protected:
194 197
195 // Event* mNextAlarmEvent; 198 // Event* mNextAlarmEvent;
196 QString mNextSummary; 199 QString mNextSummary;
197 QString mNextAlarmEventDateTimeString; 200 QString mNextAlarmEventDateTimeString;
198 QString mLastAlarmNotificationString; 201 QString mLastAlarmNotificationString;
199 QDateTime mNextAlarmEventDateTime; 202 QDateTime mNextAlarmEventDateTime;
200 QDateTime mNextAlarmDateTime; 203 QDateTime mNextAlarmDateTime;
201 void reInitAlarmSettings(); 204 void reInitAlarmSettings();
202 205
203 /** Notification function of IncidenceBase::Observer. */ 206 /** Notification function of IncidenceBase::Observer. */
204 void incidenceUpdated( IncidenceBase *i ) { update( i ); } 207 void incidenceUpdated( IncidenceBase *i ) { update( i ); }
205 208
206 /** inserts an event into its "proper place" in the calendar. */ 209 /** inserts an event into its "proper place" in the calendar. */
207 void insertEvent( Event *event ); 210 void insertEvent( Event *event );
208 211
209 /** Append alarms of incidence in interval to list of alarms. */ 212 /** Append alarms of incidence in interval to list of alarms. */
210 void appendAlarms( Alarm::List &alarms, Incidence *incidence, 213 void appendAlarms( Alarm::List &alarms, Incidence *incidence,
211 const QDateTime &from, const QDateTime &to ); 214 const QDateTime &from, const QDateTime &to );
212 215
213 /** Append alarms of recurring events in interval to list of alarms. */ 216 /** Append alarms of recurring events in interval to list of alarms. */
214 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, 217 void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence,
215 const QDateTime &from, const QDateTime &to ); 218 const QDateTime &from, const QDateTime &to );
216 219
217 private: 220 private:
218 void init(); 221 void init();
219 222
220 QPtrList<Event> mEventList; 223 QPtrList<Event> mEventList;
221 QPtrList<Todo> mTodoList; 224 QPtrList<Todo> mTodoList;
222 QPtrList<Journal> mJournalList; 225 QPtrList<Journal> mJournalList;
223}; 226};
224 227
225} 228}
226 229
227#endif 230#endif