summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2005-07-09 12:00:17 (UTC)
committer zautrix <zautrix>2005-07-09 12:00:17 (UTC)
commitfa0b6f9dae69ae7ac610b2bc97ca79b74d04f5e5 (patch) (unidiff)
treeb8d4b3cec0f447fb2930fe2ab9cd191bf7e015d0 /korganizer
parent2e2d9a949b8273ad52b09ffdf2c9250acfdbe6db (diff)
downloadkdepimpi-fa0b6f9dae69ae7ac610b2bc97ca79b74d04f5e5.zip
kdepimpi-fa0b6f9dae69ae7ac610b2bc97ca79b74d04f5e5.tar.gz
kdepimpi-fa0b6f9dae69ae7ac610b2bc97ca79b74d04f5e5.tar.bz2
fixx
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index a350c3b..7044e90 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -676,1645 +676,1647 @@ void CalendarView::nextConflict( bool all, bool allday )
676 Event * cE2 = 0; 676 Event * cE2 = 0;
677 QPtrList<Event> testlist2 = testlist; 677 QPtrList<Event> testlist2 = testlist;
678 test = testlist.first(); 678 test = testlist.first();
679 bool skip = false; 679 bool skip = false;
680 while ( test ) { 680 while ( test ) {
681 skip = false; 681 skip = false;
682 if ( !all ) skip = ( allday != test->doesFloat() ); 682 if ( !all ) skip = ( allday != test->doesFloat() );
683 if ( !skip ) { 683 if ( !skip ) {
684 Event * test2 = testlist2.first(); 684 Event * test2 = testlist2.first();
685 while ( test2 ) { 685 while ( test2 ) {
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 qDebug("last-syncEvent on remote found "); 1362 qDebug("last-syncEvent on remote found ");
1363 eventRSync = (Event*) eventR->clone(); 1363 eventRSync = (Event*) eventR->clone();
1364 remote->deleteEvent(eventR ); 1364 remote->deleteEvent(eventR );
1365 1365
1366 } else { 1366 } else {
1367 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1367 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1368 eventRSync = (Event*)eventLSync->clone(); 1368 eventRSync = (Event*)eventLSync->clone();
1369 } else { 1369 } else {
1370 fullDateRange = true; 1370 fullDateRange = true;
1371 eventRSync = new Event(); 1371 eventRSync = new Event();
1372 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1372 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1373 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1373 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1374 eventRSync->setDtStart( mLastCalendarSync ); 1374 eventRSync->setDtStart( mLastCalendarSync );
1375 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1375 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1376 eventRSync->setCategories( i18n("SyncEvent") ); 1376 eventRSync->setCategories( i18n("SyncEvent") );
1377 } 1377 }
1378 } 1378 }
1379 if ( eventLSync->dtStart() == mLastCalendarSync ) 1379 if ( eventLSync->dtStart() == mLastCalendarSync )
1380 fullDateRange = true; 1380 fullDateRange = true;
1381 1381
1382 if ( ! fullDateRange ) { 1382 if ( ! fullDateRange ) {
1383 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1383 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1384 1384
1385 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1385 qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1386 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1386 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1387 fullDateRange = true; 1387 fullDateRange = true;
1388 } 1388 }
1389 } 1389 }
1390 if ( mSyncManager->syncWithDesktop() ) { 1390 if ( mSyncManager->syncWithDesktop() ) {
1391 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1391 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1392 } 1392 }
1393 if ( fullDateRange ) 1393 if ( fullDateRange )
1394 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1394 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1395 else 1395 else
1396 mLastCalendarSync = eventLSync->dtStart(); 1396 mLastCalendarSync = eventLSync->dtStart();
1397 // for resyncing if own file has changed 1397 // for resyncing if own file has changed
1398 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1398 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1399 mLastCalendarSync = loadedFileVersion; 1399 mLastCalendarSync = loadedFileVersion;
1400 //qDebug("setting mLastCalendarSync "); 1400 //qDebug("setting mLastCalendarSync ");
1401 } 1401 }
1402 //qDebug("*************************** "); 1402 //qDebug("*************************** ");
1403 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1403 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1404 QPtrList<Incidence> er = remote->rawIncidences(); 1404 QPtrList<Incidence> er = remote->rawIncidences();
1405 Incidence* inR = er.first(); 1405 Incidence* inR = er.first();
1406 Incidence* inL; 1406 Incidence* inL;
1407 QProgressBar bar( er.count(),0 ); 1407 QProgressBar bar( er.count(),0 );
1408 bar.setCaption (i18n("Syncing - close to abort!") ); 1408 bar.setCaption (i18n("Syncing - close to abort!") );
1409 1409
1410 // ************** setting up filter ************* 1410 // ************** setting up filter *************
1411 CalFilter *filterIN = 0; 1411 CalFilter *filterIN = 0;
1412 CalFilter *filterOUT = 0; 1412 CalFilter *filterOUT = 0;
1413 CalFilter *filter = mFilters.first(); 1413 CalFilter *filter = mFilters.first();
1414 while(filter) { 1414 while(filter) {
1415 if ( filter->name() == mSyncManager->mFilterInCal ) 1415 if ( filter->name() == mSyncManager->mFilterInCal )
1416 filterIN = filter; 1416 filterIN = filter;
1417 if ( filter->name() == mSyncManager->mFilterOutCal ) 1417 if ( filter->name() == mSyncManager->mFilterOutCal )
1418 filterOUT = filter; 1418 filterOUT = filter;
1419 filter = mFilters.next(); 1419 filter = mFilters.next();
1420 } 1420 }
1421 int w = 300; 1421 int w = 300;
1422 if ( QApplication::desktop()->width() < 320 ) 1422 if ( QApplication::desktop()->width() < 320 )
1423 w = 220; 1423 w = 220;
1424 int h = bar.sizeHint().height() ; 1424 int h = bar.sizeHint().height() ;
1425 int dw = QApplication::desktop()->width(); 1425 int dw = QApplication::desktop()->width();
1426 int dh = QApplication::desktop()->height(); 1426 int dh = QApplication::desktop()->height();
1427 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1427 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1428 bar.show(); 1428 bar.show();
1429 int modulo = (er.count()/10)+1; 1429 int modulo = (er.count()/10)+1;
1430 int incCounter = 0; 1430 int incCounter = 0;
1431 while ( inR ) { 1431 while ( inR ) {
1432 if ( ! bar.isVisible() ) 1432 if ( ! bar.isVisible() )
1433 return false; 1433 return false;
1434 if ( incCounter % modulo == 0 ) 1434 if ( incCounter % modulo == 0 )
1435 bar.setProgress( incCounter ); 1435 bar.setProgress( incCounter );
1436 ++incCounter; 1436 ++incCounter;
1437 uid = inR->uid(); 1437 uid = inR->uid();
1438 bool skipIncidence = false; 1438 bool skipIncidence = false;
1439 if ( uid.left(15) == QString("last-syncEvent-") ) 1439 if ( uid.left(15) == QString("last-syncEvent-") )
1440 skipIncidence = true; 1440 skipIncidence = true;
1441 QString idS; 1441 QString idS;
1442 qApp->processEvents(); 1442 qApp->processEvents();
1443 if ( !skipIncidence ) { 1443 if ( !skipIncidence ) {
1444 inL = local->incidence( uid ); 1444 inL = local->incidenceForUid( uid , false );
1445 if ( inL ) { // maybe conflict - same uid in both calendars 1445 if ( inL ) { // maybe conflict - same uid in both calendars
1446 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1446 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1447 //qDebug("take %d %s ", take, inL->summary().latin1()); 1447 //qDebug("take %d %s ", take, inL->summary().latin1());
1448 if ( take == 3 ) 1448 if ( take == 3 )
1449 return false; 1449 return false;
1450 if ( take == 1 ) {// take local ********************** 1450 if ( take == 1 ) {// take local **********************
1451 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1451 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1452 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1452 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1453 else 1453 else
1454 idS = inR->IDStr(); 1454 idS = inR->IDStr();
1455 int calID = inR->calID(); 1455 int calID = inR->calID();
1456 remote->deleteIncidence( inR ); 1456 remote->deleteIncidence( inR );
1457 inR = inL->clone(); 1457 inR = inL->clone();
1458 inR->setCalID( calID ); 1458 inR->setCalID( calID );
1459 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1459 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1460 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1460 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1461 inR->setIDStr( idS ); 1461 inR->setIDStr( idS );
1462 remote->addIncidence( inR ); 1462 remote->addIncidence( inR );
1463 if ( mSyncManager->syncWithDesktop() ) 1463 if ( mSyncManager->syncWithDesktop() )
1464 inR->setPilotId( 2 ); 1464 inR->setPilotId( 2 );
1465 ++changedRemote; 1465 ++changedRemote;
1466 } else {// take remote ********************** 1466 } else {// take remote **********************
1467 idS = inL->IDStr(); 1467 if ( !inL->isReadOnly() ) {
1468 int pid = inL->pilotId(); 1468 idS = inL->IDStr();
1469 int calID = inL->calID(); 1469 int pid = inL->pilotId();
1470 local->deleteIncidence( inL ); 1470 int calID = inL->calID();
1471 inL = inR->clone(); 1471 local->deleteIncidence( inL );
1472 inL->setCalID( calID ); 1472 inL = inR->clone();
1473 if ( mSyncManager->syncWithDesktop() ) 1473 inL->setCalID( calID );
1474 inL->setPilotId( pid ); 1474 if ( mSyncManager->syncWithDesktop() )
1475 inL->setIDStr( idS ); 1475 inL->setPilotId( pid );
1476 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1476 inL->setIDStr( idS );
1477 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1477 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1478 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1478 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1479 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1480 }
1481 local->addIncidence( inL );
1482 ++changedLocal;
1479 } 1483 }
1480 local->addIncidence( inL );
1481 ++changedLocal;
1482 } 1484 }
1483 } 1485 }
1484 } else { // no conflict ********** add or delete remote 1486 } else { // no conflict ********** add or delete remote
1485 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1487 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1486 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1488 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1487 QString des = eventLSync->description(); 1489 QString des = eventLSync->description();
1488 QString pref = "e"; 1490 QString pref = "e";
1489 if ( inR->typeID() == todoID ) 1491 if ( inR->typeID() == todoID )
1490 pref = "t"; 1492 pref = "t";
1491 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1493 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1492 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1494 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1493 //remote->deleteIncidence( inR ); 1495 //remote->deleteIncidence( inR );
1494 ++deletedEventR; 1496 ++deletedEventR;
1495 } else { 1497 } else {
1496 inR->setLastModified( modifiedCalendar ); 1498 inR->setLastModified( modifiedCalendar );
1497 inL = inR->clone(); 1499 inL = inR->clone();
1498 inL->setIDStr( ":" ); 1500 inL->setIDStr( ":" );
1499 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1501 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1500 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1502 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1501 1503
1502 inL->setCalID( 0 );// add to default cal 1504 inL->setCalID( 0 );// add to default cal
1503 local->addIncidence( inL ); 1505 local->addIncidence( inL );
1504 ++addedEvent; 1506 ++addedEvent;
1505 1507
1506 } 1508 }
1507 } else { 1509 } else {
1508 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1510 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1509 inR->setLastModified( modifiedCalendar ); 1511 inR->setLastModified( modifiedCalendar );
1510 inL = inR->clone(); 1512 inL = inR->clone();
1511 inL->setIDStr( ":" ); 1513 inL->setIDStr( ":" );
1512 inL->setCalID( 0 );// add to default cal 1514 inL->setCalID( 0 );// add to default cal
1513 local->addIncidence( inL ); 1515 local->addIncidence( inL );
1514 ++addedEvent; 1516 ++addedEvent;
1515 1517
1516 } else { 1518 } else {
1517 checkExternSyncEvent(eventRSyncSharp, inR); 1519 checkExternSyncEvent(eventRSyncSharp, inR);
1518 remote->deleteIncidence( inR ); 1520 remote->deleteIncidence( inR );
1519 ++deletedEventR; 1521 ++deletedEventR;
1520 } 1522 }
1521 } 1523 }
1522 } else { 1524 } else {
1523 ++filteredIN; 1525 ++filteredIN;
1524 } 1526 }
1525 } 1527 }
1526 } 1528 }
1527 inR = er.next(); 1529 inR = er.next();
1528 } 1530 }
1529 QPtrList<Incidence> el = local->rawIncidences(); 1531 QPtrList<Incidence> el = local->rawIncidences();
1530 inL = el.first(); 1532 inL = el.first();
1531 modulo = (el.count()/10)+1; 1533 modulo = (el.count()/10)+1;
1532 bar.setCaption (i18n("Add / remove events") ); 1534 bar.setCaption (i18n("Add / remove events") );
1533 bar.setTotalSteps ( el.count() ) ; 1535 bar.setTotalSteps ( el.count() ) ;
1534 bar.show(); 1536 bar.show();
1535 incCounter = 0; 1537 incCounter = 0;
1536 1538
1537 while ( inL ) { 1539 while ( inL ) {
1538 1540
1539 qApp->processEvents(); 1541 qApp->processEvents();
1540 if ( ! bar.isVisible() ) 1542 if ( ! bar.isVisible() )
1541 return false; 1543 return false;
1542 if ( incCounter % modulo == 0 ) 1544 if ( incCounter % modulo == 0 )
1543 bar.setProgress( incCounter ); 1545 bar.setProgress( incCounter );
1544 ++incCounter; 1546 ++incCounter;
1545 uid = inL->uid(); 1547 uid = inL->uid();
1546 bool skipIncidence = false; 1548 bool skipIncidence = false;
1547 if ( uid.left(15) == QString("last-syncEvent-") ) 1549 if ( uid.left(15) == QString("last-syncEvent-") )
1548 skipIncidence = true; 1550 skipIncidence = true;
1549 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1551 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1550 skipIncidence = true; 1552 skipIncidence = true;
1551 if ( !skipIncidence ) { 1553 if ( !skipIncidence ) {
1552 inR = remote->incidence( uid ); 1554 inR = remote->incidenceForUid( uid , true );
1553 if ( ! inR ) { 1555 if ( ! inR ) {
1554 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1556 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1555 // no conflict ********** add or delete local 1557 // no conflict ********** add or delete local
1556 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1558 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1557 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1559 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1558 checkExternSyncEvent(eventLSyncSharp, inL); 1560 checkExternSyncEvent(eventLSyncSharp, inL);
1559 local->deleteIncidence( inL ); 1561 local->deleteIncidence( inL );
1560 ++deletedEventL; 1562 ++deletedEventL;
1561 } else { 1563 } else {
1562 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1564 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1563 inL->removeID(mCurrentSyncDevice ); 1565 inL->removeID(mCurrentSyncDevice );
1564 ++addedEventR; 1566 ++addedEventR;
1565 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1567 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1566 inL->setLastModified( modifiedCalendar ); 1568 inL->setLastModified( modifiedCalendar );
1567 inR = inL->clone(); 1569 inR = inL->clone();
1568 inR->setIDStr( ":" ); 1570 inR->setIDStr( ":" );
1569 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1571 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1570 inR->setCalID( 0 );// add to default cal 1572 inR->setCalID( 0 );// add to default cal
1571 remote->addIncidence( inR ); 1573 remote->addIncidence( inR );
1572 } 1574 }
1573 } 1575 }
1574 } else { 1576 } else {
1575 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1577 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1576 checkExternSyncEvent(eventLSyncSharp, inL); 1578 checkExternSyncEvent(eventLSyncSharp, inL);
1577 local->deleteIncidence( inL ); 1579 local->deleteIncidence( inL );
1578 ++deletedEventL; 1580 ++deletedEventL;
1579 } else { 1581 } else {
1580 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1582 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1581 ++addedEventR; 1583 ++addedEventR;
1582 inL->setLastModified( modifiedCalendar ); 1584 inL->setLastModified( modifiedCalendar );
1583 inR = inL->clone(); 1585 inR = inL->clone();
1584 inR->setIDStr( ":" ); 1586 inR->setIDStr( ":" );
1585 inR->setCalID( 0 );// add to default cal 1587 inR->setCalID( 0 );// add to default cal
1586 remote->addIncidence( inR ); 1588 remote->addIncidence( inR );
1587 } 1589 }
1588 } 1590 }
1589 } 1591 }
1590 } else { 1592 } else {
1591 ++filteredOUT; 1593 ++filteredOUT;
1592 } 1594 }
1593 } 1595 }
1594 } 1596 }
1595 inL = el.next(); 1597 inL = el.next();
1596 } 1598 }
1597 int delFut = 0; 1599 int delFut = 0;
1598 int remRem = 0; 1600 int remRem = 0;
1599 if ( mSyncManager->mWriteBackInFuture ) { 1601 if ( mSyncManager->mWriteBackInFuture ) {
1600 er = remote->rawIncidences(); 1602 er = remote->rawIncidences();
1601 remRem = er.count(); 1603 remRem = er.count();
1602 inR = er.first(); 1604 inR = er.first();
1603 QDateTime dt; 1605 QDateTime dt;
1604 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1606 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1605 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1607 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1606 while ( inR ) { 1608 while ( inR ) {
1607 if ( inR->typeID() == todoID ) { 1609 if ( inR->typeID() == todoID ) {
1608 Todo * t = (Todo*)inR; 1610 Todo * t = (Todo*)inR;
1609 if ( t->hasDueDate() ) 1611 if ( t->hasDueDate() )
1610 dt = t->dtDue(); 1612 dt = t->dtDue();
1611 else 1613 else
1612 dt = cur.addSecs( 62 ); 1614 dt = cur.addSecs( 62 );
1613 } 1615 }
1614 else if (inR->typeID() == eventID ) { 1616 else if (inR->typeID() == eventID ) {
1615 bool ok; 1617 bool ok;
1616 dt = inR->getNextOccurence( cur, &ok ); 1618 dt = inR->getNextOccurence( cur, &ok );
1617 if ( !ok ) 1619 if ( !ok )
1618 dt = cur.addSecs( -62 ); 1620 dt = cur.addSecs( -62 );
1619 } 1621 }
1620 else 1622 else
1621 dt = inR->dtStart(); 1623 dt = inR->dtStart();
1622 if ( dt < cur || dt > end ) { 1624 if ( dt < cur || dt > end ) {
1623 remote->deleteIncidence( inR ); 1625 remote->deleteIncidence( inR );
1624 ++delFut; 1626 ++delFut;
1625 } 1627 }
1626 inR = er.next(); 1628 inR = er.next();
1627 } 1629 }
1628 } 1630 }
1629 bar.hide(); 1631 bar.hide();
1630 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1632 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1631 eventLSync->setReadOnly( false ); 1633 eventLSync->setReadOnly( false );
1632 eventLSync->setDtStart( mLastCalendarSync ); 1634 eventLSync->setDtStart( mLastCalendarSync );
1633 eventRSync->setDtStart( mLastCalendarSync ); 1635 eventRSync->setDtStart( mLastCalendarSync );
1634 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1636 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1635 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1637 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1636 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1638 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1637 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1639 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1638 eventLSync->setReadOnly( true ); 1640 eventLSync->setReadOnly( true );
1639 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1641 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1640 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1642 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1641 remote->addEvent( eventRSync ); 1643 remote->addEvent( eventRSync );
1642 else 1644 else
1643 delete eventRSync; 1645 delete eventRSync;
1644 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1646 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1645 QString mes; 1647 QString mes;
1646 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 ); 1648 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 );
1647 QString delmess; 1649 QString delmess;
1648 if ( delFut ) { 1650 if ( delFut ) {
1649 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); 1651 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);
1650 mes += delmess; 1652 mes += delmess;
1651 } 1653 }
1652 mes = i18n("Local calendar changed!\n") +mes; 1654 mes = i18n("Local calendar changed!\n") +mes;
1653 mCalendar->checkAlarmForIncidence( 0, true ); 1655 mCalendar->checkAlarmForIncidence( 0, true );
1654 qDebug( mes ); 1656 qDebug( mes );
1655 if ( mSyncManager->mShowSyncSummary ) { 1657 if ( mSyncManager->mShowSyncSummary ) {
1656 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1658 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1657 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1659 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1658 qDebug("KO: WB cancelled "); 1660 qDebug("KO: WB cancelled ");
1659 mSyncManager->mWriteBackFile = false; 1661 mSyncManager->mWriteBackFile = false;
1660 return syncOK; 1662 return syncOK;
1661 } 1663 }
1662 } 1664 }
1663 return syncOK; 1665 return syncOK;
1664} 1666}
1665 1667
1666void CalendarView::setSyncDevice( QString s ) 1668void CalendarView::setSyncDevice( QString s )
1667{ 1669{
1668 mCurrentSyncDevice= s; 1670 mCurrentSyncDevice= s;
1669} 1671}
1670void CalendarView::setSyncName( QString s ) 1672void CalendarView::setSyncName( QString s )
1671{ 1673{
1672 mCurrentSyncName= s; 1674 mCurrentSyncName= s;
1673} 1675}
1674bool CalendarView::syncCalendar(QString filename, int mode) 1676bool CalendarView::syncCalendar(QString filename, int mode)
1675{ 1677{
1676 //qDebug("syncCalendar %s ", filename.latin1()); 1678 //qDebug("syncCalendar %s ", filename.latin1());
1677 mGlobalSyncMode = SYNC_MODE_NORMAL; 1679 mGlobalSyncMode = SYNC_MODE_NORMAL;
1678 CalendarLocal* calendar = new CalendarLocal(); 1680 CalendarLocal* calendar = new CalendarLocal();
1679 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1681 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1680 FileStorage* storage = new FileStorage( calendar ); 1682 FileStorage* storage = new FileStorage( calendar );
1681 bool syncOK = false; 1683 bool syncOK = false;
1682 storage->setFileName( filename ); 1684 storage->setFileName( filename );
1683 // qDebug("loading ... "); 1685 // qDebug("loading ... ");
1684 if ( storage->load() ) { 1686 if ( storage->load() ) {
1685 getEventViewerDialog()->setSyncMode( true ); 1687 getEventViewerDialog()->setSyncMode( true );
1686 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1688 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1687 getEventViewerDialog()->setSyncMode( false ); 1689 getEventViewerDialog()->setSyncMode( false );
1688 if ( syncOK ) { 1690 if ( syncOK ) {
1689 if ( mSyncManager->mWriteBackFile ) 1691 if ( mSyncManager->mWriteBackFile )
1690 { 1692 {
1691 storage->setSaveFormat( new ICalFormat() ); 1693 storage->setSaveFormat( new ICalFormat() );
1692 storage->save(); 1694 storage->save();
1693 } 1695 }
1694 } 1696 }
1695 setModified( true ); 1697 setModified( true );
1696 } 1698 }
1697 delete storage; 1699 delete storage;
1698 delete calendar; 1700 delete calendar;
1699 if ( syncOK ) 1701 if ( syncOK )
1700 updateView(); 1702 updateView();
1701 return syncOK; 1703 return syncOK;
1702} 1704}
1703 1705
1704void CalendarView::syncExternal( int mode ) 1706void CalendarView::syncExternal( int mode )
1705{ 1707{
1706 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1708 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1707 1709
1708 qApp->processEvents(); 1710 qApp->processEvents();
1709 CalendarLocal* calendar = new CalendarLocal(); 1711 CalendarLocal* calendar = new CalendarLocal();
1710 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1712 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1711 bool syncOK = false; 1713 bool syncOK = false;
1712 bool loadSuccess = false; 1714 bool loadSuccess = false;
1713 PhoneFormat* phoneFormat = 0; 1715 PhoneFormat* phoneFormat = 0;
1714 emit tempDisableBR(true); 1716 emit tempDisableBR(true);
1715#ifndef DESKTOP_VERSION 1717#ifndef DESKTOP_VERSION
1716 SharpFormat* sharpFormat = 0; 1718 SharpFormat* sharpFormat = 0;
1717 if ( mode == 0 ) { // sharp 1719 if ( mode == 0 ) { // sharp
1718 sharpFormat = new SharpFormat () ; 1720 sharpFormat = new SharpFormat () ;
1719 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1721 loadSuccess = sharpFormat->load( calendar, mCalendar );
1720 1722
1721 } else 1723 } else
1722#endif 1724#endif
1723 if ( mode == 1 ) { // phone 1725 if ( mode == 1 ) { // phone
1724 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1726 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1725 mSyncManager->mPhoneDevice, 1727 mSyncManager->mPhoneDevice,
1726 mSyncManager->mPhoneConnection, 1728 mSyncManager->mPhoneConnection,
1727 mSyncManager->mPhoneModel); 1729 mSyncManager->mPhoneModel);
1728 loadSuccess = phoneFormat->load( calendar,mCalendar); 1730 loadSuccess = phoneFormat->load( calendar,mCalendar);
1729 1731
1730 } else { 1732 } else {
1731 emit tempDisableBR(false); 1733 emit tempDisableBR(false);
1732 return; 1734 return;
1733 } 1735 }
1734 if ( loadSuccess ) { 1736 if ( loadSuccess ) {
1735 getEventViewerDialog()->setSyncMode( true ); 1737 getEventViewerDialog()->setSyncMode( true );
1736 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1738 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1737 getEventViewerDialog()->setSyncMode( false ); 1739 getEventViewerDialog()->setSyncMode( false );
1738 qApp->processEvents(); 1740 qApp->processEvents();
1739 if ( syncOK ) { 1741 if ( syncOK ) {
1740 if ( mSyncManager->mWriteBackFile ) 1742 if ( mSyncManager->mWriteBackFile )
1741 { 1743 {
1742 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1744 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1743 Incidence* inc = iL.first(); 1745 Incidence* inc = iL.first();
1744 if ( phoneFormat ) { 1746 if ( phoneFormat ) {
1745 while ( inc ) { 1747 while ( inc ) {
1746 inc->removeID(mCurrentSyncDevice); 1748 inc->removeID(mCurrentSyncDevice);
1747 inc = iL.next(); 1749 inc = iL.next();
1748 } 1750 }
1749 } 1751 }
1750#ifndef DESKTOP_VERSION 1752#ifndef DESKTOP_VERSION
1751 if ( sharpFormat ) 1753 if ( sharpFormat )
1752 sharpFormat->save(calendar); 1754 sharpFormat->save(calendar);
1753#endif 1755#endif
1754 if ( phoneFormat ) 1756 if ( phoneFormat )
1755 phoneFormat->save(calendar); 1757 phoneFormat->save(calendar);
1756 iL = calendar->rawIncidences(); 1758 iL = calendar->rawIncidences();
1757 inc = iL.first(); 1759 inc = iL.first();
1758 Incidence* loc; 1760 Incidence* loc;
1759 while ( inc ) { 1761 while ( inc ) {
1760 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1762 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1761 loc = mCalendar->incidence(inc->uid() ); 1763 loc = mCalendar->incidence(inc->uid() );
1762 if ( loc ) { 1764 if ( loc ) {
1763 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1765 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1764 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1766 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1765 } 1767 }
1766 } 1768 }
1767 inc = iL.next(); 1769 inc = iL.next();
1768 } 1770 }
1769 Incidence* lse = getLastSyncEvent(); 1771 Incidence* lse = getLastSyncEvent();
1770 if ( lse ) { 1772 if ( lse ) {
1771 lse->setReadOnly( false ); 1773 lse->setReadOnly( false );
1772 lse->setDescription( "" ); 1774 lse->setDescription( "" );
1773 lse->setReadOnly( true ); 1775 lse->setReadOnly( true );
1774 } 1776 }
1775 } 1777 }
1776 } else { 1778 } else {
1777 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1779 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1778 } 1780 }
1779 setModified( true ); 1781 setModified( true );
1780 } else { 1782 } else {
1781 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1783 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1782 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1784 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1783 question, i18n("Ok")) ; 1785 question, i18n("Ok")) ;
1784 1786
1785 } 1787 }
1786 delete calendar; 1788 delete calendar;
1787 updateView(); 1789 updateView();
1788 emit tempDisableBR(false); 1790 emit tempDisableBR(false);
1789 return ;//syncOK; 1791 return ;//syncOK;
1790 1792
1791} 1793}
1792 1794
1793bool CalendarView::importBday() 1795bool CalendarView::importBday()
1794{ 1796{
1795#ifndef KORG_NOKABC 1797#ifndef KORG_NOKABC
1796 1798
1797#ifdef DESKTOP_VERSION 1799#ifdef DESKTOP_VERSION
1798 int curCal = mCalendar->defaultCalendar(); 1800 int curCal = mCalendar->defaultCalendar();
1799 int bd = mCalEditView->getBirtdayID(); 1801 int bd = mCalEditView->getBirtdayID();
1800 if ( bd == 0 ) 1802 if ( bd == 0 )
1801 return false; 1803 return false;
1802 mCalendar->setDefaultCalendar( bd ); 1804 mCalendar->setDefaultCalendar( bd );
1803 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1805 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1804 KABC::AddressBook::Iterator it; 1806 KABC::AddressBook::Iterator it;
1805 int count = 0; 1807 int count = 0;
1806 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1808 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1807 ++count; 1809 ++count;
1808 } 1810 }
1809 QProgressBar bar(count,0 ); 1811 QProgressBar bar(count,0 );
1810 int w = 300; 1812 int w = 300;
1811 if ( QApplication::desktop()->width() < 320 ) 1813 if ( QApplication::desktop()->width() < 320 )
1812 w = 220; 1814 w = 220;
1813 int h = bar.sizeHint().height() ; 1815 int h = bar.sizeHint().height() ;
1814 int dw = QApplication::desktop()->width(); 1816 int dw = QApplication::desktop()->width();
1815 int dh = QApplication::desktop()->height(); 1817 int dh = QApplication::desktop()->height();
1816 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1818 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1817 bar.show(); 1819 bar.show();
1818 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1820 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1819 qApp->processEvents(); 1821 qApp->processEvents();
1820 count = 0; 1822 count = 0;
1821 int addCount = 0; 1823 int addCount = 0;
1822 KCal::Attendee* a = 0; 1824 KCal::Attendee* a = 0;
1823 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1825 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1824 if ( ! bar.isVisible() ) 1826 if ( ! bar.isVisible() )
1825 return false; 1827 return false;
1826 bar.setProgress( count++ ); 1828 bar.setProgress( count++ );
1827 qApp->processEvents(); 1829 qApp->processEvents();
1828 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1830 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1829 if ( (*it).birthday().date().isValid() ){ 1831 if ( (*it).birthday().date().isValid() ){
1830 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1832 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1831 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1833 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1832 ++addCount; 1834 ++addCount;
1833 } 1835 }
1834 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1836 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1835 if ( anni.isValid() ){ 1837 if ( anni.isValid() ){
1836 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1838 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1837 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1839 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1838 ++addCount; 1840 ++addCount;
1839 } 1841 }
1840 } 1842 }
1841 mCalendar->setDefaultCalendar( curCal ); 1843 mCalendar->setDefaultCalendar( curCal );
1842 updateView(); 1844 updateView();
1843 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1845 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1844#else //DESKTOP_VERSION 1846#else //DESKTOP_VERSION
1845 1847
1846 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1848 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1847 // the result should now arrive through method insertBirthdays 1849 // the result should now arrive through method insertBirthdays
1848 1850
1849#endif //DESKTOP_VERSION 1851#endif //DESKTOP_VERSION
1850 1852
1851#endif //KORG_NOKABC 1853#endif //KORG_NOKABC
1852 1854
1853 1855
1854 return true; 1856 return true;
1855} 1857}
1856 1858
1857// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1859// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1858void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1860void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1859 const QStringList& anniversaryList, const QStringList& realNameList, 1861 const QStringList& anniversaryList, const QStringList& realNameList,
1860 const QStringList& emailList, const QStringList& assembledNameList, 1862 const QStringList& emailList, const QStringList& assembledNameList,
1861 const QStringList& uidList) 1863 const QStringList& uidList)
1862{ 1864{
1863 1865
1864 //qDebug("KO::CalendarView::insertBirthdays"); 1866 //qDebug("KO::CalendarView::insertBirthdays");
1865 if (uid == this->name()) 1867 if (uid == this->name())
1866 { 1868 {
1867 int curCal = mCalendar->defaultCalendar(); 1869 int curCal = mCalendar->defaultCalendar();
1868 int bd = mCalEditView->getBirtdayID(); 1870 int bd = mCalEditView->getBirtdayID();
1869 if ( bd == 0 ) 1871 if ( bd == 0 )
1870 return; 1872 return;
1871 mCalendar->setDefaultCalendar( bd ); 1873 mCalendar->setDefaultCalendar( bd );
1872 1874
1873 1875
1874 int count = birthdayList.count(); 1876 int count = birthdayList.count();
1875 int addCount = 0; 1877 int addCount = 0;
1876 KCal::Attendee* a = 0; 1878 KCal::Attendee* a = 0;
1877 1879
1878 //qDebug("CalView 1 %i", count); 1880 //qDebug("CalView 1 %i", count);
1879 1881
1880 QProgressBar bar(count,0 ); 1882 QProgressBar bar(count,0 );
1881 int w = 300; 1883 int w = 300;
1882 if ( QApplication::desktop()->width() < 320 ) 1884 if ( QApplication::desktop()->width() < 320 )
1883 w = 220; 1885 w = 220;
1884 int h = bar.sizeHint().height() ; 1886 int h = bar.sizeHint().height() ;
1885 int dw = QApplication::desktop()->width(); 1887 int dw = QApplication::desktop()->width();
1886 int dh = QApplication::desktop()->height(); 1888 int dh = QApplication::desktop()->height();
1887 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1889 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1888 bar.show(); 1890 bar.show();
1889 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1891 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1890 qApp->processEvents(); 1892 qApp->processEvents();
1891 1893
1892 QDate birthday; 1894 QDate birthday;
1893 QDate anniversary; 1895 QDate anniversary;
1894 QString realName; 1896 QString realName;
1895 QString email; 1897 QString email;
1896 QString assembledName; 1898 QString assembledName;
1897 QString uid; 1899 QString uid;
1898 bool ok = true; 1900 bool ok = true;
1899 for ( int i = 0; i < count; i++) 1901 for ( int i = 0; i < count; i++)
1900 { 1902 {
1901 if ( ! bar.isVisible() ) 1903 if ( ! bar.isVisible() )
1902 return; 1904 return;
1903 bar.setProgress( i ); 1905 bar.setProgress( i );
1904 qApp->processEvents(); 1906 qApp->processEvents();
1905 1907
1906 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1908 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1907 if (!ok) { 1909 if (!ok) {
1908 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1910 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1909 } 1911 }
1910 1912
1911 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1913 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1912 if (!ok) { 1914 if (!ok) {
1913 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1915 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1914 } 1916 }
1915 realName = realNameList[i]; 1917 realName = realNameList[i];
1916 email = emailList[i]; 1918 email = emailList[i];
1917 assembledName = assembledNameList[i]; 1919 assembledName = assembledNameList[i];
1918 uid = uidList[i]; 1920 uid = uidList[i];
1919 //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() ); 1921 //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() );
1920 1922
1921 if ( birthday.isValid() ){ 1923 if ( birthday.isValid() ){
1922 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1924 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1923 KCal::Attendee::ReqParticipant,uid) ; 1925 KCal::Attendee::ReqParticipant,uid) ;
1924 if ( addAnniversary( birthday, assembledName, a, true ) ) 1926 if ( addAnniversary( birthday, assembledName, a, true ) )
1925 ++addCount; 1927 ++addCount;
1926 } 1928 }
1927 1929
1928 if ( anniversary.isValid() ){ 1930 if ( anniversary.isValid() ){
1929 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1931 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1930 KCal::Attendee::ReqParticipant,uid) ; 1932 KCal::Attendee::ReqParticipant,uid) ;
1931 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1933 if ( addAnniversary( anniversary, assembledName, a, false ) )
1932 ++addCount; 1934 ++addCount;
1933 } 1935 }
1934 } 1936 }
1935 1937
1936 mCalendar->setDefaultCalendar( curCal ); 1938 mCalendar->setDefaultCalendar( curCal );
1937 updateView(); 1939 updateView();
1938 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1940 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1939 1941
1940 } 1942 }
1941 1943
1942} 1944}
1943 1945
1944 1946
1945 1947
1946bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1948bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1947{ 1949{
1948 //qDebug("addAnni "); 1950 //qDebug("addAnni ");
1949 Event * ev = new Event(); 1951 Event * ev = new Event();
1950 ev->setOrganizer(KOPrefs::instance()->email()); 1952 ev->setOrganizer(KOPrefs::instance()->email());
1951 if ( a ) { 1953 if ( a ) {
1952 ev->addAttendee( a ); 1954 ev->addAttendee( a );
1953 } 1955 }
1954 QString kind; 1956 QString kind;
1955 if ( birthday ) { 1957 if ( birthday ) {
1956 kind = i18n( "Birthday" ); 1958 kind = i18n( "Birthday" );
1957 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1959 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1958 } 1960 }
1959 else { 1961 else {
1960 kind = i18n( "Anniversary" ); 1962 kind = i18n( "Anniversary" );
1961 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1963 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1962 } 1964 }
1963 ev->setCategories( kind ); 1965 ev->setCategories( kind );
1964 ev->setDtStart( QDateTime(date) ); 1966 ev->setDtStart( QDateTime(date) );
1965 ev->setDtEnd( QDateTime(date) ); 1967 ev->setDtEnd( QDateTime(date) );
1966 ev->setFloats( true ); 1968 ev->setFloats( true );
1967 Recurrence * rec = ev->recurrence(); 1969 Recurrence * rec = ev->recurrence();
1968 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1970 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1969 rec->addYearlyNum( date.month() ); 1971 rec->addYearlyNum( date.month() );
1970 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1972 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1971 delete ev; 1973 delete ev;
1972 return false; 1974 return false;
1973 } 1975 }
1974 return true; 1976 return true;
1975 1977
1976} 1978}
1977bool CalendarView::importQtopia( const QString &categories, 1979bool CalendarView::importQtopia( const QString &categories,
1978 const QString &datebook, 1980 const QString &datebook,
1979 const QString &todolist ) 1981 const QString &todolist )
1980{ 1982{
1981 1983
1982 QtopiaFormat qtopiaFormat; 1984 QtopiaFormat qtopiaFormat;
1983 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1985 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1984 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1986 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1985 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1987 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1986 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1988 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1987 1989
1988 updateView(); 1990 updateView();
1989 return true; 1991 return true;
1990 1992
1991#if 0 1993#if 0
1992 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1994 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1993 mCurrentSyncDevice = "qtopia-XML"; 1995 mCurrentSyncDevice = "qtopia-XML";
1994 if ( mSyncManager->mAskForPreferences ) 1996 if ( mSyncManager->mAskForPreferences )
1995 edit_sync_options(); 1997 edit_sync_options();
1996 qApp->processEvents(); 1998 qApp->processEvents();
1997 CalendarLocal* calendar = new CalendarLocal(); 1999 CalendarLocal* calendar = new CalendarLocal();
1998 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2000 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1999 bool syncOK = false; 2001 bool syncOK = false;
2000 QtopiaFormat qtopiaFormat; 2002 QtopiaFormat qtopiaFormat;
2001 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 2003 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
2002 bool loadOk = true; 2004 bool loadOk = true;
2003 if ( !categories.isEmpty() ) 2005 if ( !categories.isEmpty() )
2004 loadOk = qtopiaFormat.load( calendar, categories ); 2006 loadOk = qtopiaFormat.load( calendar, categories );
2005 if ( loadOk && !datebook.isEmpty() ) 2007 if ( loadOk && !datebook.isEmpty() )
2006 loadOk = qtopiaFormat.load( calendar, datebook ); 2008 loadOk = qtopiaFormat.load( calendar, datebook );
2007 if ( loadOk && !todolist.isEmpty() ) 2009 if ( loadOk && !todolist.isEmpty() )
2008 loadOk = qtopiaFormat.load( calendar, todolist ); 2010 loadOk = qtopiaFormat.load( calendar, todolist );
2009 2011
2010 if ( loadOk ) { 2012 if ( loadOk ) {
2011 getEventViewerDialog()->setSyncMode( true ); 2013 getEventViewerDialog()->setSyncMode( true );
2012 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 2014 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
2013 getEventViewerDialog()->setSyncMode( false ); 2015 getEventViewerDialog()->setSyncMode( false );
2014 qApp->processEvents(); 2016 qApp->processEvents();
2015 if ( syncOK ) { 2017 if ( syncOK ) {
2016 if ( mSyncManager->mWriteBackFile ) 2018 if ( mSyncManager->mWriteBackFile )
2017 { 2019 {
2018 // write back XML file 2020 // write back XML file
2019 2021
2020 } 2022 }
2021 setModified( true ); 2023 setModified( true );
2022 } 2024 }
2023 } else { 2025 } else {
2024 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 2026 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
2025 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 2027 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
2026 question, i18n("Ok")) ; 2028 question, i18n("Ok")) ;
2027 } 2029 }
2028 delete calendar; 2030 delete calendar;
2029 updateView(); 2031 updateView();
2030 return syncOK; 2032 return syncOK;
2031 2033
2032 2034
2033#endif 2035#endif
2034 2036
2035} 2037}
2036 2038
2037void CalendarView::setSyncEventsReadOnly() 2039void CalendarView::setSyncEventsReadOnly()
2038{ 2040{
2039 mCalendar->setSyncEventsReadOnly(); 2041 mCalendar->setSyncEventsReadOnly();
2040} 2042}
2041 2043
2042bool CalendarView::loadCalendars() 2044bool CalendarView::loadCalendars()
2043{ 2045{
2044 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2046 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2045 KopiCalendarFile * cal = calendars.first(); 2047 KopiCalendarFile * cal = calendars.first();
2046 mCalendar->setDefaultCalendar( 1 ); 2048 mCalendar->setDefaultCalendar( 1 );
2047 openCalendar( MainWindow::defaultFileName(), false ); 2049 openCalendar( MainWindow::defaultFileName(), false );
2048 cal = calendars.next(); 2050 cal = calendars.next();
2049 while ( cal ) { 2051 while ( cal ) {
2050 addCalendar( cal ); 2052 addCalendar( cal );
2051 cal = calendars.next(); 2053 cal = calendars.next();
2052 } 2054 }
2053 restoreCalendarSettings(); 2055 restoreCalendarSettings();
2054 return true; 2056 return true;
2055} 2057}
2056bool CalendarView::restoreCalendarSettings() 2058bool CalendarView::restoreCalendarSettings()
2057{ 2059{
2058 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2060 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2059 KopiCalendarFile * cal = calendars.first(); 2061 KopiCalendarFile * cal = calendars.first();
2060 while ( cal ) { 2062 while ( cal ) {
2061 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 2063 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
2062 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 2064 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
2063 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 2065 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
2064 if ( cal->isStandard ) 2066 if ( cal->isStandard )
2065 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2067 mCalendar->setDefaultCalendar( cal->mCalNumber );
2066 cal = calendars.next(); 2068 cal = calendars.next();
2067 } 2069 }
2068 setSyncEventsReadOnly(); 2070 setSyncEventsReadOnly();
2069 mCalendar->reInitAlarmSettings(); 2071 mCalendar->reInitAlarmSettings();
2070 updateUnmanagedViews(); 2072 updateUnmanagedViews();
2071 updateView(); 2073 updateView();
2072 return true; 2074 return true;
2073} 2075}
2074void CalendarView::addCalendarId( int id ) 2076void CalendarView::addCalendarId( int id )
2075{ 2077{
2076 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 2078 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
2077 if ( cal ) 2079 if ( cal )
2078 addCalendar( cal ); 2080 addCalendar( cal );
2079} 2081}
2080bool CalendarView::addCalendar( KopiCalendarFile * cal ) 2082bool CalendarView::addCalendar( KopiCalendarFile * cal )
2081{ 2083{
2082 cal->mErrorOnLoad = false; 2084 cal->mErrorOnLoad = false;
2083 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 2085 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
2084 cal->mLoadDt = QDateTime::currentDateTime(); 2086 cal->mLoadDt = QDateTime::currentDateTime();
2085 return true; 2087 return true;
2086 } 2088 }
2087 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() ); 2089 qDebug("KO: Error adding calendar file %s ",cal->mFileName.latin1() );
2088 cal->mErrorOnLoad = true; 2090 cal->mErrorOnLoad = true;
2089 return false; 2091 return false;
2090} 2092}
2091bool CalendarView::openCalendar(QString filename, bool merge) 2093bool CalendarView::openCalendar(QString filename, bool merge)
2092{ 2094{
2093 2095
2094 if (filename.isEmpty()) { 2096 if (filename.isEmpty()) {
2095 return false; 2097 return false;
2096 } 2098 }
2097 2099
2098 if (!QFile::exists(filename)) { 2100 if (!QFile::exists(filename)) {
2099 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 2101 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
2100 return false; 2102 return false;
2101 } 2103 }
2102 2104
2103 globalFlagBlockAgenda = 1; 2105 globalFlagBlockAgenda = 1;
2104 clearAllViews(); 2106 clearAllViews();
2105 if (!merge) { 2107 if (!merge) {
2106 mViewManager->setDocumentId( filename ); 2108 mViewManager->setDocumentId( filename );
2107 mCalendar->close(); 2109 mCalendar->close();
2108 } 2110 }
2109 mStorage->setFileName( filename ); 2111 mStorage->setFileName( filename );
2110 2112
2111 if ( mStorage->load() ) { 2113 if ( mStorage->load() ) {
2112 if ( merge ) ;//setModified( true ); 2114 if ( merge ) ;//setModified( true );
2113 else { 2115 else {
2114 //setModified( true ); 2116 //setModified( true );
2115 mViewManager->setDocumentId( filename ); 2117 mViewManager->setDocumentId( filename );
2116 mDialogManager->setDocumentId( filename ); 2118 mDialogManager->setDocumentId( filename );
2117 mTodoList->setDocumentId( filename ); 2119 mTodoList->setDocumentId( filename );
2118 } 2120 }
2119 globalFlagBlockAgenda = 2; 2121 globalFlagBlockAgenda = 2;
2120 // if ( getLastSyncEvent() ) 2122 // if ( getLastSyncEvent() )
2121 // getLastSyncEvent()->setReadOnly( true ); 2123 // getLastSyncEvent()->setReadOnly( true );
2122 mCalendar->reInitAlarmSettings(); 2124 mCalendar->reInitAlarmSettings();
2123 setSyncEventsReadOnly(); 2125 setSyncEventsReadOnly();
2124 updateUnmanagedViews(); 2126 updateUnmanagedViews();
2125 updateView(); 2127 updateView();
2126 if ( filename != MainWindow::defaultFileName() ) { 2128 if ( filename != MainWindow::defaultFileName() ) {
2127 saveCalendar( MainWindow::defaultFileName() ); 2129 saveCalendar( MainWindow::defaultFileName() );
2128 } else { 2130 } else {
2129 QFileInfo finf ( MainWindow::defaultFileName()); 2131 QFileInfo finf ( MainWindow::defaultFileName());
2130 if ( finf.exists() ) { 2132 if ( finf.exists() ) {
2131 setLoadedFileVersion( finf.lastModified () ); 2133 setLoadedFileVersion( finf.lastModified () );
2132 } 2134 }
2133 } 2135 }
2134 return true; 2136 return true;
2135 } else { 2137 } else {
2136 // while failing to load, the calendar object could 2138 // while failing to load, the calendar object could
2137 // have become partially populated. Clear it out. 2139 // have become partially populated. Clear it out.
2138 if ( !merge ) { 2140 if ( !merge ) {
2139 mCalendar->close(); 2141 mCalendar->close();
2140 mViewManager->setDocumentId( filename ); 2142 mViewManager->setDocumentId( filename );
2141 mDialogManager->setDocumentId( filename ); 2143 mDialogManager->setDocumentId( filename );
2142 mTodoList->setDocumentId( filename ); 2144 mTodoList->setDocumentId( filename );
2143 } 2145 }
2144 2146
2145 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 2147 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
2146 2148
2147 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 2149 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
2148 globalFlagBlockAgenda = 2; 2150 globalFlagBlockAgenda = 2;
2149 mCalendar->reInitAlarmSettings(); 2151 mCalendar->reInitAlarmSettings();
2150 setSyncEventsReadOnly(); 2152 setSyncEventsReadOnly();
2151 updateUnmanagedViews(); 2153 updateUnmanagedViews();
2152 updateView(); 2154 updateView();
2153 } 2155 }
2154 return false; 2156 return false;
2155} 2157}
2156void CalendarView::mergeFile( QString fn ) 2158void CalendarView::mergeFile( QString fn )
2157{ 2159{
2158 clearAllViews(); 2160 clearAllViews();
2159 mCalendar->mergeCalendarFile( fn ); 2161 mCalendar->mergeCalendarFile( fn );
2160 mCalendar->reInitAlarmSettings(); 2162 mCalendar->reInitAlarmSettings();
2161 setSyncEventsReadOnly(); 2163 setSyncEventsReadOnly();
2162 updateUnmanagedViews(); 2164 updateUnmanagedViews();
2163 updateView(); 2165 updateView();
2164} 2166}
2165void CalendarView::showOpenError() 2167void CalendarView::showOpenError()
2166{ 2168{
2167 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 2169 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
2168} 2170}
2169void CalendarView::setLoadedFileVersion(QDateTime dt) 2171void CalendarView::setLoadedFileVersion(QDateTime dt)
2170{ 2172{
2171 loadedFileVersion = dt; 2173 loadedFileVersion = dt;
2172} 2174}
2173bool CalendarView::checkFileChanged(QString fn) 2175bool CalendarView::checkFileChanged(QString fn)
2174{ 2176{
2175 QFileInfo finf ( fn ); 2177 QFileInfo finf ( fn );
2176 if ( !finf.exists() ) 2178 if ( !finf.exists() )
2177 return true; 2179 return true;
2178 QDateTime dt = finf.lastModified (); 2180 QDateTime dt = finf.lastModified ();
2179 if ( dt <= loadedFileVersion ) 2181 if ( dt <= loadedFileVersion )
2180 return false; 2182 return false;
2181 return true; 2183 return true;
2182 2184
2183} 2185}
2184void CalendarView::watchSavedFile() 2186void CalendarView::watchSavedFile()
2185{ 2187{
2186 QFileInfo finf ( MainWindow::defaultFileName()); 2188 QFileInfo finf ( MainWindow::defaultFileName());
2187 if ( !finf.exists() ) 2189 if ( !finf.exists() )
2188 return; 2190 return;
2189 QDateTime dt = finf.lastModified (); 2191 QDateTime dt = finf.lastModified ();
2190 if ( dt < loadedFileVersion ) { 2192 if ( dt < loadedFileVersion ) {
2191 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 2193 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
2192 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 2194 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
2193 return; 2195 return;
2194 } 2196 }
2195 loadedFileVersion = dt; 2197 loadedFileVersion = dt;
2196} 2198}
2197bool CalendarView::checkAllFileVersions() 2199bool CalendarView::checkAllFileVersions()
2198{ 2200{
2199 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2201 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2200 KopiCalendarFile * cal = calendars.first(); 2202 KopiCalendarFile * cal = calendars.first();
2201 mCalendar->setDefaultCalendar( 1 ); 2203 mCalendar->setDefaultCalendar( 1 );
2202 mCalendar->setDefaultCalendarEnabledOnly(); 2204 mCalendar->setDefaultCalendarEnabledOnly();
2203 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2205 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2204 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2206 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2205 restoreCalendarSettings(); 2207 restoreCalendarSettings();
2206 return false; 2208 return false;
2207 } 2209 }
2208 } 2210 }
2209 cal = calendars.next(); 2211 cal = calendars.next();
2210 QDateTime storeTemp = loadedFileVersion; 2212 QDateTime storeTemp = loadedFileVersion;
2211 while ( cal ) { 2213 while ( cal ) {
2212 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2214 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2213 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2215 mCalendar->setDefaultCalendar( cal->mCalNumber );
2214 mCalendar->setDefaultCalendarEnabledOnly(); 2216 mCalendar->setDefaultCalendarEnabledOnly();
2215 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2217 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2216 if ( !checkFileVersion(cal->mFileName )) { 2218 if ( !checkFileVersion(cal->mFileName )) {
2217 loadedFileVersion = storeTemp; 2219 loadedFileVersion = storeTemp;
2218 restoreCalendarSettings(); 2220 restoreCalendarSettings();
2219 return false; 2221 return false;
2220 } 2222 }
2221 } 2223 }
2222 cal = calendars.next(); 2224 cal = calendars.next();
2223 } 2225 }
2224 loadedFileVersion = storeTemp; 2226 loadedFileVersion = storeTemp;
2225 return true; 2227 return true;
2226} 2228}
2227bool CalendarView::checkFileVersion(QString fn) 2229bool CalendarView::checkFileVersion(QString fn)
2228{ 2230{
2229 QFileInfo finf ( fn ); 2231 QFileInfo finf ( fn );
2230 if ( !finf.exists() ) 2232 if ( !finf.exists() )
2231 return true; 2233 return true;
2232 QDateTime dt = finf.lastModified (); 2234 QDateTime dt = finf.lastModified ();
2233 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2235 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2234 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2236 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2235 if ( dt <= loadedFileVersion ) 2237 if ( dt <= loadedFileVersion )
2236 return true; 2238 return true;
2237 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)) , 2239 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)) ,
2238 i18n("KO/Pi Warning"),i18n("Overwrite"), 2240 i18n("KO/Pi Warning"),i18n("Overwrite"),
2239 i18n("Sync+save")); 2241 i18n("Sync+save"));
2240 2242
2241 if ( km == KMessageBox::Cancel ) 2243 if ( km == KMessageBox::Cancel )
2242 return false; 2244 return false;
2243 if ( km == KMessageBox::Yes ) 2245 if ( km == KMessageBox::Yes )
2244 return true; 2246 return true;
2245 2247
2246 setSyncDevice("deleteaftersync" ); 2248 setSyncDevice("deleteaftersync" );
2247 mSyncManager->mAskForPreferences = true; 2249 mSyncManager->mAskForPreferences = true;
2248 mSyncManager->mSyncAlgoPrefs = 3; 2250 mSyncManager->mSyncAlgoPrefs = 3;
2249 mSyncManager->mWriteBackFile = false; 2251 mSyncManager->mWriteBackFile = false;
2250 mSyncManager->mWriteBackExistingOnly = false; 2252 mSyncManager->mWriteBackExistingOnly = false;
2251 mSyncManager->mShowSyncSummary = false; 2253 mSyncManager->mShowSyncSummary = false;
2252 syncCalendar( fn, 3 ); 2254 syncCalendar( fn, 3 );
2253 Event * e = getLastSyncEvent(); 2255 Event * e = getLastSyncEvent();
2254 if ( e ) 2256 if ( e )
2255 mCalendar->deleteEvent( e ); 2257 mCalendar->deleteEvent( e );
2256 return true; 2258 return true;
2257} 2259}
2258bool CalendarView::saveCalendars() 2260bool CalendarView::saveCalendars()
2259{ 2261{
2260 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2262 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2261 KopiCalendarFile * cal = calendars.first(); 2263 KopiCalendarFile * cal = calendars.first();
2262 mCalendar->setDefaultCalendar( 1 ); 2264 mCalendar->setDefaultCalendar( 1 );
2263 mCalendar->setDefaultCalendarEnabledOnly(); 2265 mCalendar->setDefaultCalendarEnabledOnly();
2264 saveCalendar( MainWindow::defaultFileName() ); 2266 saveCalendar( MainWindow::defaultFileName() );
2265 cal = calendars.next(); 2267 cal = calendars.next();
2266 while ( cal ) { 2268 while ( cal ) {
2267 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2269 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2268 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2270 mCalendar->setDefaultCalendar( cal->mCalNumber );
2269 mCalendar->setDefaultCalendarEnabledOnly(); 2271 mCalendar->setDefaultCalendarEnabledOnly();
2270 if ( saveCalendar( cal->mFileName ) ) 2272 if ( saveCalendar( cal->mFileName ) )
2271 cal->mLoadDt = QDateTime::currentDateTime(); 2273 cal->mLoadDt = QDateTime::currentDateTime();
2272 } 2274 }
2273 cal = calendars.next(); 2275 cal = calendars.next();
2274 } 2276 }
2275 restoreCalendarSettings(); 2277 restoreCalendarSettings();
2276 return true; 2278 return true;
2277} 2279}
2278bool CalendarView::saveCalendar( QString filename ) 2280bool CalendarView::saveCalendar( QString filename )
2279{ 2281{
2280 2282
2281 // Store back all unsaved data into calendar object 2283 // Store back all unsaved data into calendar object
2282 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2284 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2283 if ( mViewManager->currentView() ) 2285 if ( mViewManager->currentView() )
2284 mViewManager->currentView()->flushView(); 2286 mViewManager->currentView()->flushView();
2285 2287
2286 2288
2287 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2289 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2288 mStorage->setSaveFormat( new ICalFormat() ); 2290 mStorage->setSaveFormat( new ICalFormat() );
2289 mStorage->setFileName( filename ); 2291 mStorage->setFileName( filename );
2290 bool success; 2292 bool success;
2291 success = mStorage->save(); 2293 success = mStorage->save();
2292 if ( !success ) { 2294 if ( !success ) {
2293 return false; 2295 return false;
2294 } 2296 }
2295 if ( filename == MainWindow::defaultFileName() ) { 2297 if ( filename == MainWindow::defaultFileName() ) {
2296 setLoadedFileVersion( lfv ); 2298 setLoadedFileVersion( lfv );
2297 watchSavedFile(); 2299 watchSavedFile();
2298 } 2300 }
2299 return true; 2301 return true;
2300} 2302}
2301 2303
2302void CalendarView::closeCalendar() 2304void CalendarView::closeCalendar()
2303{ 2305{
2304 2306
2305 // child windows no longer valid 2307 // child windows no longer valid
2306 clearAllViews(); 2308 clearAllViews();
2307 emit closingDown(); 2309 emit closingDown();
2308 2310
2309 mCalendar->close(); 2311 mCalendar->close();
2310 setModified(false); 2312 setModified(false);
2311 updateView(); 2313 updateView();
2312} 2314}
2313 2315
2314void CalendarView::archiveCalendar() 2316void CalendarView::archiveCalendar()
2315{ 2317{
2316 mDialogManager->showArchiveDialog(); 2318 mDialogManager->showArchiveDialog();
2317} 2319}
2318 2320
2319 2321
2320void CalendarView::readSettings() 2322void CalendarView::readSettings()