summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 13cf69b..a62145a 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -845,1537 +845,1537 @@ void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
845{ 845{
846 mNextAlarmDateTime = qdt; 846 mNextAlarmDateTime = qdt;
847 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 847 //qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
848 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 848 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
849#ifndef DESKTOP_VERSION 849#ifndef DESKTOP_VERSION
850 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() ); 850 AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
851#endif 851#endif
852 return; 852 return;
853 } 853 }
854 int maxSec; 854 int maxSec;
855 //maxSec = 5; //testing only 855 //maxSec = 5; //testing only
856 maxSec = 86400+3600; // one day+1hour 856 maxSec = 86400+3600; // one day+1hour
857 mAlarmNotification = noti; 857 mAlarmNotification = noti;
858 int sec = QDateTime::currentDateTime().secsTo( qdt ); 858 int sec = QDateTime::currentDateTime().secsTo( qdt );
859 if ( sec > maxSec ) { 859 if ( sec > maxSec ) {
860 mRecheckAlarmTimer->start( maxSec * 1000 ); 860 mRecheckAlarmTimer->start( maxSec * 1000 );
861 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec ); 861 // qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
862 return; 862 return;
863 } else { 863 } else {
864 mRecheckAlarmTimer->stop(); 864 mRecheckAlarmTimer->stop();
865 } 865 }
866 //qDebug("Alarm timer started with secs: %d ", sec); 866 //qDebug("Alarm timer started with secs: %d ", sec);
867 mAlarmTimer->start( sec *1000 , true ); 867 mAlarmTimer->start( sec *1000 , true );
868 868
869} 869}
870// called by mRecheckAlarmTimer to get next alarm 870// called by mRecheckAlarmTimer to get next alarm
871// we need this, because a QTimer has only a max range of 25 days 871// we need this, because a QTimer has only a max range of 25 days
872void CalendarView::recheckTimerAlarm() 872void CalendarView::recheckTimerAlarm()
873{ 873{
874 mAlarmTimer->stop(); 874 mAlarmTimer->stop();
875 mRecheckAlarmTimer->stop(); 875 mRecheckAlarmTimer->stop();
876 mCalendar->checkAlarmForIncidence( 0, true ); 876 mCalendar->checkAlarmForIncidence( 0, true );
877} 877}
878void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti ) 878void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
879{ 879{
880 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() ); 880 //qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
881 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 881 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
882#ifndef DESKTOP_VERSION 882#ifndef DESKTOP_VERSION
883 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() ); 883 AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.latin1() );
884#endif 884#endif
885 return; 885 return;
886 } 886 }
887 mAlarmTimer->stop(); 887 mAlarmTimer->stop();
888} 888}
889void CalendarView::selectWeekNum ( int num ) 889void CalendarView::selectWeekNum ( int num )
890{ 890{
891 dateNavigator()->blockSignals( true ); 891 dateNavigator()->blockSignals( true );
892 dateNavigator()->selectWeek( num ); 892 dateNavigator()->selectWeek( num );
893 dateNavigator()->blockSignals( false ); 893 dateNavigator()->blockSignals( false );
894 mViewManager->showWeekView(); 894 mViewManager->showWeekView();
895} 895}
896KOViewManager *CalendarView::viewManager() 896KOViewManager *CalendarView::viewManager()
897{ 897{
898 return mViewManager; 898 return mViewManager;
899} 899}
900 900
901KODialogManager *CalendarView::dialogManager() 901KODialogManager *CalendarView::dialogManager()
902{ 902{
903 return mDialogManager; 903 return mDialogManager;
904} 904}
905 905
906QDate CalendarView::startDate() 906QDate CalendarView::startDate()
907{ 907{
908 DateList dates = mNavigator->selectedDates(); 908 DateList dates = mNavigator->selectedDates();
909 909
910 return dates.first(); 910 return dates.first();
911} 911}
912 912
913QDate CalendarView::endDate() 913QDate CalendarView::endDate()
914{ 914{
915 DateList dates = mNavigator->selectedDates(); 915 DateList dates = mNavigator->selectedDates();
916 916
917 return dates.last(); 917 return dates.last();
918} 918}
919 919
920 920
921void CalendarView::createPrinter() 921void CalendarView::createPrinter()
922{ 922{
923#ifndef KORG_NOPRINTER 923#ifndef KORG_NOPRINTER
924 if (!mCalPrinter) { 924 if (!mCalPrinter) {
925 mCalPrinter = new CalPrinter(this, mCalendar); 925 mCalPrinter = new CalPrinter(this, mCalendar);
926 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); 926 connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
927 } 927 }
928#endif 928#endif
929} 929}
930 930
931 931
932//KOPrefs::instance()->mWriteBackFile 932//KOPrefs::instance()->mWriteBackFile
933//KOPrefs::instance()->mWriteBackExistingOnly 933//KOPrefs::instance()->mWriteBackExistingOnly
934 934
935// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); 935// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
936// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); 936// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
937// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); 937// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
938// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); 938// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
939// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); 939// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
940// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); 940// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
941 941
942int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) 942int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
943{ 943{
944 944
945 // 0 equal 945 // 0 equal
946 // 1 take local 946 // 1 take local
947 // 2 take remote 947 // 2 take remote
948 // 3 cancel 948 // 3 cancel
949 QDateTime lastSync = mLastCalendarSync; 949 QDateTime lastSync = mLastCalendarSync;
950 QDateTime localMod = local->lastModified(); 950 QDateTime localMod = local->lastModified();
951 QDateTime remoteMod = remote->lastModified(); 951 QDateTime remoteMod = remote->lastModified();
952 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 952 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
953 bool remCh, locCh; 953 bool remCh, locCh;
954 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 954 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
955 //if ( remCh ) 955 //if ( remCh )
956 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 956 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
957 locCh = ( localMod > mLastCalendarSync ); 957 locCh = ( localMod > mLastCalendarSync );
958 if ( !remCh && ! locCh ) { 958 if ( !remCh && ! locCh ) {
959 //qDebug("both not changed "); 959 //qDebug("both not changed ");
960 lastSync = localMod.addDays(1); 960 lastSync = localMod.addDays(1);
961 if ( mode <= SYNC_PREF_ASK ) 961 if ( mode <= SYNC_PREF_ASK )
962 return 0; 962 return 0;
963 } else { 963 } else {
964 if ( locCh ) { 964 if ( locCh ) {
965 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); 965 //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
966 lastSync = localMod.addDays( -1 ); 966 lastSync = localMod.addDays( -1 );
967 if ( !remCh ) 967 if ( !remCh )
968 remoteMod = ( lastSync.addDays( -1 ) ); 968 remoteMod = ( lastSync.addDays( -1 ) );
969 } else { 969 } else {
970 //qDebug(" not loc changed "); 970 //qDebug(" not loc changed ");
971 lastSync = localMod.addDays( 1 ); 971 lastSync = localMod.addDays( 1 );
972 if ( remCh ) 972 if ( remCh )
973 remoteMod =( lastSync.addDays( 1 ) ); 973 remoteMod =( lastSync.addDays( 1 ) );
974 974
975 } 975 }
976 } 976 }
977 full = true; 977 full = true;
978 if ( mode < SYNC_PREF_ASK ) 978 if ( mode < SYNC_PREF_ASK )
979 mode = SYNC_PREF_ASK; 979 mode = SYNC_PREF_ASK;
980 } else { 980 } else {
981 if ( localMod == remoteMod ) 981 if ( localMod == remoteMod )
982 // if ( local->revision() == remote->revision() ) 982 // if ( local->revision() == remote->revision() )
983 return 0; 983 return 0;
984 984
985 } 985 }
986 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); 986 // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
987 987
988 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); 988 //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
989 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); 989 //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
990 //full = true; //debug only 990 //full = true; //debug only
991 if ( full ) { 991 if ( full ) {
992 bool equ = false; 992 bool equ = false;
993 if ( local->typeID() == eventID ) { 993 if ( local->typeID() == eventID ) {
994 equ = (*((Event*) local) == *((Event*) remote)); 994 equ = (*((Event*) local) == *((Event*) remote));
995 } 995 }
996 else if ( local->typeID() == todoID ) 996 else if ( local->typeID() == todoID )
997 equ = (*((Todo*) local) == (*(Todo*) remote)); 997 equ = (*((Todo*) local) == (*(Todo*) remote));
998 else if ( local->typeID() == journalID ) 998 else if ( local->typeID() == journalID )
999 equ = (*((Journal*) local) == *((Journal*) remote)); 999 equ = (*((Journal*) local) == *((Journal*) remote));
1000 if ( equ ) { 1000 if ( equ ) {
1001 //qDebug("equal "); 1001 //qDebug("equal ");
1002 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1002 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1003 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 1003 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
1004 } 1004 }
1005 if ( mode < SYNC_PREF_FORCE_LOCAL ) 1005 if ( mode < SYNC_PREF_FORCE_LOCAL )
1006 return 0; 1006 return 0;
1007 1007
1008 }//else //debug only 1008 }//else //debug only
1009 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 1009 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
1010 } 1010 }
1011 int result; 1011 int result;
1012 bool localIsNew; 1012 bool localIsNew;
1013 //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() ); 1013 //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() );
1014 1014
1015 1015
1016 // ************************************************ 1016 // ************************************************
1017 // ************************************************ 1017 // ************************************************
1018 // ************************************************ 1018 // ************************************************
1019 // We may have that lastSync > remoteMod AND lastSync > localMod 1019 // We may have that lastSync > remoteMod AND lastSync > localMod
1020 // BUT remoteMod != localMod 1020 // BUT remoteMod != localMod
1021 1021
1022 1022
1023 if ( full && mode < SYNC_PREF_NEWEST ) 1023 if ( full && mode < SYNC_PREF_NEWEST )
1024 mode = SYNC_PREF_ASK; 1024 mode = SYNC_PREF_ASK;
1025 1025
1026 switch( mode ) { 1026 switch( mode ) {
1027 case SYNC_PREF_LOCAL: 1027 case SYNC_PREF_LOCAL:
1028 if ( lastSync > remoteMod ) 1028 if ( lastSync > remoteMod )
1029 return 1; 1029 return 1;
1030 if ( lastSync > localMod ) 1030 if ( lastSync > localMod )
1031 return 2; 1031 return 2;
1032 return 1; 1032 return 1;
1033 break; 1033 break;
1034 case SYNC_PREF_REMOTE: 1034 case SYNC_PREF_REMOTE:
1035 if ( lastSync > localMod ) 1035 if ( lastSync > localMod )
1036 return 2; 1036 return 2;
1037 if ( lastSync > remoteMod ) 1037 if ( lastSync > remoteMod )
1038 return 1; 1038 return 1;
1039 return 2; 1039 return 2;
1040 break; 1040 break;
1041 case SYNC_PREF_NEWEST: 1041 case SYNC_PREF_NEWEST:
1042 if ( localMod >= remoteMod ) 1042 if ( localMod >= remoteMod )
1043 return 1; 1043 return 1;
1044 else 1044 else
1045 return 2; 1045 return 2;
1046 break; 1046 break;
1047 case SYNC_PREF_ASK: 1047 case SYNC_PREF_ASK:
1048 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1048 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1049 if ( lastSync > remoteMod && lastSync > localMod) 1049 if ( lastSync > remoteMod && lastSync > localMod)
1050 return 0; 1050 return 0;
1051 if ( lastSync > remoteMod ) 1051 if ( lastSync > remoteMod )
1052 return 1; 1052 return 1;
1053 if ( lastSync > localMod ) 1053 if ( lastSync > localMod )
1054 return 2; 1054 return 2;
1055 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 1055 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
1056 localIsNew = localMod >= remoteMod; 1056 localIsNew = localMod >= remoteMod;
1057 if ( localIsNew ) 1057 if ( localIsNew )
1058 getEventViewerDialog()->setColorMode( 1 ); 1058 getEventViewerDialog()->setColorMode( 1 );
1059 else 1059 else
1060 getEventViewerDialog()->setColorMode( 2 ); 1060 getEventViewerDialog()->setColorMode( 2 );
1061 getEventViewerDialog()->setIncidence(local); 1061 getEventViewerDialog()->setIncidence(local);
1062 if ( localIsNew ) 1062 if ( localIsNew )
1063 getEventViewerDialog()->setColorMode( 2 ); 1063 getEventViewerDialog()->setColorMode( 2 );
1064 else 1064 else
1065 getEventViewerDialog()->setColorMode( 1 ); 1065 getEventViewerDialog()->setColorMode( 1 );
1066 getEventViewerDialog()->addIncidence(remote); 1066 getEventViewerDialog()->addIncidence(remote);
1067 getEventViewerDialog()->setColorMode( 0 ); 1067 getEventViewerDialog()->setColorMode( 0 );
1068 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); 1068 //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
1069 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); 1069 getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
1070 getEventViewerDialog()->showMe(); 1070 getEventViewerDialog()->showMe();
1071 result = getEventViewerDialog()->executeS( localIsNew ); 1071 result = getEventViewerDialog()->executeS( localIsNew );
1072 return result; 1072 return result;
1073 1073
1074 break; 1074 break;
1075 case SYNC_PREF_FORCE_LOCAL: 1075 case SYNC_PREF_FORCE_LOCAL:
1076 return 1; 1076 return 1;
1077 break; 1077 break;
1078 case SYNC_PREF_FORCE_REMOTE: 1078 case SYNC_PREF_FORCE_REMOTE:
1079 return 2; 1079 return 2;
1080 break; 1080 break;
1081 1081
1082 default: 1082 default:
1083 // SYNC_PREF_TAKE_BOTH not implemented 1083 // SYNC_PREF_TAKE_BOTH not implemented
1084 break; 1084 break;
1085 } 1085 }
1086 return 0; 1086 return 0;
1087} 1087}
1088Event* CalendarView::getLastSyncEvent() 1088Event* CalendarView::getLastSyncEvent()
1089{ 1089{
1090 Event* lse; 1090 Event* lse;
1091 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 1091 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
1092 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 1092 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
1093 if (!lse) { 1093 if (!lse) {
1094 lse = new Event(); 1094 lse = new Event();
1095 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 1095 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
1096 QString sum = ""; 1096 QString sum = "";
1097 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 1097 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
1098 sum = "E: "; 1098 sum = "E: ";
1099 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 1099 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
1100 lse->setDtStart( mLastCalendarSync ); 1100 lse->setDtStart( mLastCalendarSync );
1101 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1101 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1102 lse->setCategories( i18n("SyncEvent") ); 1102 lse->setCategories( i18n("SyncEvent") );
1103 lse->setReadOnly( true ); 1103 lse->setReadOnly( true );
1104 mCalendar->addEvent( lse ); 1104 mCalendar->addEvent( lse );
1105 } 1105 }
1106 1106
1107 return lse; 1107 return lse;
1108 1108
1109} 1109}
1110 1110
1111// we check, if the to delete event has a id for a profile 1111// we check, if the to delete event has a id for a profile
1112// if yes, we set this id in the profile to delete 1112// if yes, we set this id in the profile to delete
1113void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) 1113void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
1114{ 1114{
1115 if ( lastSync.count() == 0 ) { 1115 if ( lastSync.count() == 0 ) {
1116 //qDebug(" lastSync.count() == 0"); 1116 //qDebug(" lastSync.count() == 0");
1117 return; 1117 return;
1118 } 1118 }
1119 if ( toDelete->typeID() == journalID ) 1119 if ( toDelete->typeID() == journalID )
1120 return; 1120 return;
1121 1121
1122 Event* eve = lastSync.first(); 1122 Event* eve = lastSync.first();
1123 1123
1124 while ( eve ) { 1124 while ( eve ) {
1125 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 1125 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
1126 if ( !id.isEmpty() ) { 1126 if ( !id.isEmpty() ) {
1127 QString des = eve->description(); 1127 QString des = eve->description();
1128 QString pref = "e"; 1128 QString pref = "e";
1129 if ( toDelete->typeID() == todoID ) 1129 if ( toDelete->typeID() == todoID )
1130 pref = "t"; 1130 pref = "t";
1131 des += pref+ id + ","; 1131 des += pref+ id + ",";
1132 eve->setReadOnly( false ); 1132 eve->setReadOnly( false );
1133 eve->setDescription( des ); 1133 eve->setDescription( des );
1134 //qDebug("setdes %s ", des.latin1()); 1134 //qDebug("setdes %s ", des.latin1());
1135 eve->setReadOnly( true ); 1135 eve->setReadOnly( true );
1136 } 1136 }
1137 eve = lastSync.next(); 1137 eve = lastSync.next();
1138 } 1138 }
1139 1139
1140} 1140}
1141void CalendarView::checkExternalId( Incidence * inc ) 1141void CalendarView::checkExternalId( Incidence * inc )
1142{ 1142{
1143 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 1143 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
1144 checkExternSyncEvent( lastSync, inc ); 1144 checkExternSyncEvent( lastSync, inc );
1145 1145
1146} 1146}
1147bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 1147bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
1148{ 1148{
1149 bool syncOK = true; 1149 bool syncOK = true;
1150 int addedEvent = 0; 1150 int addedEvent = 0;
1151 int addedEventR = 0; 1151 int addedEventR = 0;
1152 int deletedEventR = 0; 1152 int deletedEventR = 0;
1153 int deletedEventL = 0; 1153 int deletedEventL = 0;
1154 int changedLocal = 0; 1154 int changedLocal = 0;
1155 int changedRemote = 0; 1155 int changedRemote = 0;
1156 int filteredIN = 0; 1156 int filteredIN = 0;
1157 int filteredOUT = 0; 1157 int filteredOUT = 0;
1158 //QPtrList<Event> el = local->rawEvents(); 1158 //QPtrList<Event> el = local->rawEvents();
1159 Event* eventR; 1159 Event* eventR;
1160 QString uid; 1160 QString uid;
1161 int take; 1161 int take;
1162 Event* eventL; 1162 Event* eventL;
1163 Event* eventRSync; 1163 Event* eventRSync;
1164 Event* eventLSync; 1164 Event* eventLSync;
1165 clearAllViews(); 1165 clearAllViews();
1166 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 1166 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
1167 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 1167 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
1168 bool fullDateRange = false; 1168 bool fullDateRange = false;
1169 local->resetTempSyncStat(); 1169 local->resetTempSyncStat();
1170 mLastCalendarSync = QDateTime::currentDateTime(); 1170 mLastCalendarSync = QDateTime::currentDateTime();
1171 if ( mSyncManager->syncWithDesktop() ) { 1171 if ( mSyncManager->syncWithDesktop() ) {
1172 remote->resetPilotStat(1); 1172 remote->resetPilotStat(1);
1173 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1173 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1174 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 1174 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
1175 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 1175 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
1176 } else { 1176 } else {
1177 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 1177 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
1178 } 1178 }
1179 } 1179 }
1180 QDateTime modifiedCalendar = mLastCalendarSync; 1180 QDateTime modifiedCalendar = mLastCalendarSync;
1181 eventLSync = getLastSyncEvent(); 1181 eventLSync = getLastSyncEvent();
1182 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 1182 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
1183 if ( eventR ) { 1183 if ( eventR ) {
1184 eventRSync = (Event*) eventR->clone(); 1184 eventRSync = (Event*) eventR->clone();
1185 remote->deleteEvent(eventR ); 1185 remote->deleteEvent(eventR );
1186 1186
1187 } else { 1187 } else {
1188 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 1188 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
1189 eventRSync = (Event*)eventLSync->clone(); 1189 eventRSync = (Event*)eventLSync->clone();
1190 } else { 1190 } else {
1191 fullDateRange = true; 1191 fullDateRange = true;
1192 eventRSync = new Event(); 1192 eventRSync = new Event();
1193 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 1193 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
1194 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 1194 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
1195 eventRSync->setDtStart( mLastCalendarSync ); 1195 eventRSync->setDtStart( mLastCalendarSync );
1196 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 1196 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1197 eventRSync->setCategories( i18n("SyncEvent") ); 1197 eventRSync->setCategories( i18n("SyncEvent") );
1198 } 1198 }
1199 } 1199 }
1200 if ( eventLSync->dtStart() == mLastCalendarSync ) 1200 if ( eventLSync->dtStart() == mLastCalendarSync )
1201 fullDateRange = true; 1201 fullDateRange = true;
1202 1202
1203 if ( ! fullDateRange ) { 1203 if ( ! fullDateRange ) {
1204 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1204 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1205 1205
1206 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1206 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1207 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1207 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1208 fullDateRange = true; 1208 fullDateRange = true;
1209 } 1209 }
1210 } 1210 }
1211 if ( mSyncManager->syncWithDesktop() ) { 1211 if ( mSyncManager->syncWithDesktop() ) {
1212 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1212 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1213 } 1213 }
1214 if ( fullDateRange ) 1214 if ( fullDateRange )
1215 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1215 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1216 else 1216 else
1217 mLastCalendarSync = eventLSync->dtStart(); 1217 mLastCalendarSync = eventLSync->dtStart();
1218 // for resyncing if own file has changed 1218 // for resyncing if own file has changed
1219 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1219 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1220 mLastCalendarSync = loadedFileVersion; 1220 mLastCalendarSync = loadedFileVersion;
1221 //qDebug("setting mLastCalendarSync "); 1221 //qDebug("setting mLastCalendarSync ");
1222 } 1222 }
1223 //qDebug("*************************** "); 1223 //qDebug("*************************** ");
1224 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1224 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1225 QPtrList<Incidence> er = remote->rawIncidences(); 1225 QPtrList<Incidence> er = remote->rawIncidences();
1226 Incidence* inR = er.first(); 1226 Incidence* inR = er.first();
1227 Incidence* inL; 1227 Incidence* inL;
1228 QProgressBar bar( er.count(),0 ); 1228 QProgressBar bar( er.count(),0 );
1229 bar.setCaption (i18n("Syncing - close to abort!") ); 1229 bar.setCaption (i18n("Syncing - close to abort!") );
1230 1230
1231 // ************** setting up filter ************* 1231 // ************** setting up filter *************
1232 CalFilter *filterIN = 0; 1232 CalFilter *filterIN = 0;
1233 CalFilter *filterOUT = 0; 1233 CalFilter *filterOUT = 0;
1234 CalFilter *filter = mFilters.first(); 1234 CalFilter *filter = mFilters.first();
1235 while(filter) { 1235 while(filter) {
1236 if ( filter->name() == mSyncManager->mFilterInCal ) 1236 if ( filter->name() == mSyncManager->mFilterInCal )
1237 filterIN = filter; 1237 filterIN = filter;
1238 if ( filter->name() == mSyncManager->mFilterOutCal ) 1238 if ( filter->name() == mSyncManager->mFilterOutCal )
1239 filterOUT = filter; 1239 filterOUT = filter;
1240 filter = mFilters.next(); 1240 filter = mFilters.next();
1241 } 1241 }
1242 int w = 300; 1242 int w = 300;
1243 if ( QApplication::desktop()->width() < 320 ) 1243 if ( QApplication::desktop()->width() < 320 )
1244 w = 220; 1244 w = 220;
1245 int h = bar.sizeHint().height() ; 1245 int h = bar.sizeHint().height() ;
1246 int dw = QApplication::desktop()->width(); 1246 int dw = QApplication::desktop()->width();
1247 int dh = QApplication::desktop()->height(); 1247 int dh = QApplication::desktop()->height();
1248 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1248 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1249 bar.show(); 1249 bar.show();
1250 int modulo = (er.count()/10)+1; 1250 int modulo = (er.count()/10)+1;
1251 int incCounter = 0; 1251 int incCounter = 0;
1252 while ( inR ) { 1252 while ( inR ) {
1253 if ( ! bar.isVisible() ) 1253 if ( ! bar.isVisible() )
1254 return false; 1254 return false;
1255 if ( incCounter % modulo == 0 ) 1255 if ( incCounter % modulo == 0 )
1256 bar.setProgress( incCounter ); 1256 bar.setProgress( incCounter );
1257 ++incCounter; 1257 ++incCounter;
1258 uid = inR->uid(); 1258 uid = inR->uid();
1259 bool skipIncidence = false; 1259 bool skipIncidence = false;
1260 if ( uid.left(15) == QString("last-syncEvent-") ) 1260 if ( uid.left(15) == QString("last-syncEvent-") )
1261 skipIncidence = true; 1261 skipIncidence = true;
1262 QString idS; 1262 QString idS;
1263 qApp->processEvents(); 1263 qApp->processEvents();
1264 if ( !skipIncidence ) { 1264 if ( !skipIncidence ) {
1265 inL = local->incidence( uid ); 1265 inL = local->incidence( uid );
1266 if ( inL ) { // maybe conflict - same uid in both calendars 1266 if ( inL ) { // maybe conflict - same uid in both calendars
1267 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1267 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1268 //qDebug("take %d %s ", take, inL->summary().latin1()); 1268 //qDebug("take %d %s ", take, inL->summary().latin1());
1269 if ( take == 3 ) 1269 if ( take == 3 )
1270 return false; 1270 return false;
1271 if ( take == 1 ) {// take local ********************** 1271 if ( take == 1 ) {// take local **********************
1272 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1272 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1273 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1273 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1274 else 1274 else
1275 idS = inR->IDStr(); 1275 idS = inR->IDStr();
1276 remote->deleteIncidence( inR ); 1276 remote->deleteIncidence( inR );
1277 inR = inL->clone(); 1277 inR = inL->clone();
1278 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1278 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1279 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1279 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1280 inR->setIDStr( idS ); 1280 inR->setIDStr( idS );
1281 remote->addIncidence( inR ); 1281 remote->addIncidence( inR );
1282 if ( mSyncManager->syncWithDesktop() ) 1282 if ( mSyncManager->syncWithDesktop() )
1283 inR->setPilotId( 2 ); 1283 inR->setPilotId( 2 );
1284 ++changedRemote; 1284 ++changedRemote;
1285 } else {// take remote ********************** 1285 } else {// take remote **********************
1286 idS = inL->IDStr(); 1286 idS = inL->IDStr();
1287 int pid = inL->pilotId(); 1287 int pid = inL->pilotId();
1288 local->deleteIncidence( inL ); 1288 local->deleteIncidence( inL );
1289 inL = inR->clone(); 1289 inL = inR->clone();
1290 if ( mSyncManager->syncWithDesktop() ) 1290 if ( mSyncManager->syncWithDesktop() )
1291 inL->setPilotId( pid ); 1291 inL->setPilotId( pid );
1292 inL->setIDStr( idS ); 1292 inL->setIDStr( idS );
1293 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1293 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1294 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1294 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1295 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1295 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1296 } 1296 }
1297 local->addIncidence( inL ); 1297 local->addIncidence( inL );
1298 ++changedLocal; 1298 ++changedLocal;
1299 } 1299 }
1300 } 1300 }
1301 } else { // no conflict ********** add or delete remote 1301 } else { // no conflict ********** add or delete remote
1302 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1302 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1303 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1303 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1304 QString des = eventLSync->description(); 1304 QString des = eventLSync->description();
1305 QString pref = "e"; 1305 QString pref = "e";
1306 if ( inR->typeID() == todoID ) 1306 if ( inR->typeID() == todoID )
1307 pref = "t"; 1307 pref = "t";
1308 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1308 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1309 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1309 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1310 //remote->deleteIncidence( inR ); 1310 //remote->deleteIncidence( inR );
1311 ++deletedEventR; 1311 ++deletedEventR;
1312 } else { 1312 } else {
1313 inR->setLastModified( modifiedCalendar ); 1313 inR->setLastModified( modifiedCalendar );
1314 inL = inR->clone(); 1314 inL = inR->clone();
1315 inL->setIDStr( ":" ); 1315 inL->setIDStr( ":" );
1316 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1316 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1317 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1317 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1318 local->addIncidence( inL ); 1318 local->addIncidence( inL );
1319 ++addedEvent; 1319 ++addedEvent;
1320 1320
1321 } 1321 }
1322 } else { 1322 } else {
1323 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1323 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1324 inR->setLastModified( modifiedCalendar ); 1324 inR->setLastModified( modifiedCalendar );
1325 inL = inR->clone(); 1325 inL = inR->clone();
1326 inL->setIDStr( ":" ); 1326 inL->setIDStr( ":" );
1327 local->addIncidence( inL ); 1327 local->addIncidence( inL );
1328 ++addedEvent; 1328 ++addedEvent;
1329 1329
1330 } else { 1330 } else {
1331 checkExternSyncEvent(eventRSyncSharp, inR); 1331 checkExternSyncEvent(eventRSyncSharp, inR);
1332 remote->deleteIncidence( inR ); 1332 remote->deleteIncidence( inR );
1333 ++deletedEventR; 1333 ++deletedEventR;
1334 } 1334 }
1335 } 1335 }
1336 } else { 1336 } else {
1337 ++filteredIN; 1337 ++filteredIN;
1338 } 1338 }
1339 } 1339 }
1340 } 1340 }
1341 inR = er.next(); 1341 inR = er.next();
1342 } 1342 }
1343 QPtrList<Incidence> el = local->rawIncidences(); 1343 QPtrList<Incidence> el = local->rawIncidences();
1344 inL = el.first(); 1344 inL = el.first();
1345 modulo = (el.count()/10)+1; 1345 modulo = (el.count()/10)+1;
1346 bar.setCaption (i18n("Add / remove events") ); 1346 bar.setCaption (i18n("Add / remove events") );
1347 bar.setTotalSteps ( el.count() ) ; 1347 bar.setTotalSteps ( el.count() ) ;
1348 bar.show(); 1348 bar.show();
1349 incCounter = 0; 1349 incCounter = 0;
1350 1350
1351 while ( inL ) { 1351 while ( inL ) {
1352 1352
1353 qApp->processEvents(); 1353 qApp->processEvents();
1354 if ( ! bar.isVisible() ) 1354 if ( ! bar.isVisible() )
1355 return false; 1355 return false;
1356 if ( incCounter % modulo == 0 ) 1356 if ( incCounter % modulo == 0 )
1357 bar.setProgress( incCounter ); 1357 bar.setProgress( incCounter );
1358 ++incCounter; 1358 ++incCounter;
1359 uid = inL->uid(); 1359 uid = inL->uid();
1360 bool skipIncidence = false; 1360 bool skipIncidence = false;
1361 if ( uid.left(15) == QString("last-syncEvent-") ) 1361 if ( uid.left(15) == QString("last-syncEvent-") )
1362 skipIncidence = true; 1362 skipIncidence = true;
1363 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1363 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1364 skipIncidence = true; 1364 skipIncidence = true;
1365 if ( !skipIncidence ) { 1365 if ( !skipIncidence ) {
1366 inR = remote->incidence( uid ); 1366 inR = remote->incidence( uid );
1367 if ( ! inR ) { 1367 if ( ! inR ) {
1368 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1368 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1369 // no conflict ********** add or delete local 1369 // no conflict ********** add or delete local
1370 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1370 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1371 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1371 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1372 checkExternSyncEvent(eventLSyncSharp, inL); 1372 checkExternSyncEvent(eventLSyncSharp, inL);
1373 local->deleteIncidence( inL ); 1373 local->deleteIncidence( inL );
1374 ++deletedEventL; 1374 ++deletedEventL;
1375 } else { 1375 } else {
1376 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1376 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1377 inL->removeID(mCurrentSyncDevice ); 1377 inL->removeID(mCurrentSyncDevice );
1378 ++addedEventR; 1378 ++addedEventR;
1379 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1379 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1380 inL->setLastModified( modifiedCalendar ); 1380 inL->setLastModified( modifiedCalendar );
1381 inR = inL->clone(); 1381 inR = inL->clone();
1382 inR->setIDStr( ":" ); 1382 inR->setIDStr( ":" );
1383 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1383 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1384 remote->addIncidence( inR ); 1384 remote->addIncidence( inR );
1385 } 1385 }
1386 } 1386 }
1387 } else { 1387 } else {
1388 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1388 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1389 checkExternSyncEvent(eventLSyncSharp, inL); 1389 checkExternSyncEvent(eventLSyncSharp, inL);
1390 local->deleteIncidence( inL ); 1390 local->deleteIncidence( inL );
1391 ++deletedEventL; 1391 ++deletedEventL;
1392 } else { 1392 } else {
1393 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1393 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1394 ++addedEventR; 1394 ++addedEventR;
1395 inL->setLastModified( modifiedCalendar ); 1395 inL->setLastModified( modifiedCalendar );
1396 inR = inL->clone(); 1396 inR = inL->clone();
1397 inR->setIDStr( ":" ); 1397 inR->setIDStr( ":" );
1398 remote->addIncidence( inR ); 1398 remote->addIncidence( inR );
1399 } 1399 }
1400 } 1400 }
1401 } 1401 }
1402 } else { 1402 } else {
1403 ++filteredOUT; 1403 ++filteredOUT;
1404 } 1404 }
1405 } 1405 }
1406 } 1406 }
1407 inL = el.next(); 1407 inL = el.next();
1408 } 1408 }
1409 int delFut = 0; 1409 int delFut = 0;
1410 int remRem = 0; 1410 int remRem = 0;
1411 if ( mSyncManager->mWriteBackInFuture ) { 1411 if ( mSyncManager->mWriteBackInFuture ) {
1412 er = remote->rawIncidences(); 1412 er = remote->rawIncidences();
1413 remRem = er.count(); 1413 remRem = er.count();
1414 inR = er.first(); 1414 inR = er.first();
1415 QDateTime dt; 1415 QDateTime dt;
1416 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1416 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1417 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1417 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1418 while ( inR ) { 1418 while ( inR ) {
1419 if ( inR->typeID() == todoID ) { 1419 if ( inR->typeID() == todoID ) {
1420 Todo * t = (Todo*)inR; 1420 Todo * t = (Todo*)inR;
1421 if ( t->hasDueDate() ) 1421 if ( t->hasDueDate() )
1422 dt = t->dtDue(); 1422 dt = t->dtDue();
1423 else 1423 else
1424 dt = cur.addSecs( 62 ); 1424 dt = cur.addSecs( 62 );
1425 } 1425 }
1426 else if (inR->typeID() == eventID ) { 1426 else if (inR->typeID() == eventID ) {
1427 bool ok; 1427 bool ok;
1428 dt = inR->getNextOccurence( cur, &ok ); 1428 dt = inR->getNextOccurence( cur, &ok );
1429 if ( !ok ) 1429 if ( !ok )
1430 dt = cur.addSecs( -62 ); 1430 dt = cur.addSecs( -62 );
1431 } 1431 }
1432 else 1432 else
1433 dt = inR->dtStart(); 1433 dt = inR->dtStart();
1434 if ( dt < cur || dt > end ) { 1434 if ( dt < cur || dt > end ) {
1435 remote->deleteIncidence( inR ); 1435 remote->deleteIncidence( inR );
1436 ++delFut; 1436 ++delFut;
1437 } 1437 }
1438 inR = er.next(); 1438 inR = er.next();
1439 } 1439 }
1440 } 1440 }
1441 bar.hide(); 1441 bar.hide();
1442 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1442 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1443 eventLSync->setReadOnly( false ); 1443 eventLSync->setReadOnly( false );
1444 eventLSync->setDtStart( mLastCalendarSync ); 1444 eventLSync->setDtStart( mLastCalendarSync );
1445 eventRSync->setDtStart( mLastCalendarSync ); 1445 eventRSync->setDtStart( mLastCalendarSync );
1446 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1446 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1447 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1447 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1448 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1448 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1449 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1449 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1450 eventLSync->setReadOnly( true ); 1450 eventLSync->setReadOnly( true );
1451 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1451 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1452 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1452 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1453 remote->addEvent( eventRSync ); 1453 remote->addEvent( eventRSync );
1454 else 1454 else
1455 delete eventRSync; 1455 delete eventRSync;
1456 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1456 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1457 QString mes; 1457 QString mes;
1458 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 ); 1458 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 );
1459 QString delmess; 1459 QString delmess;
1460 if ( delFut ) { 1460 if ( delFut ) {
1461 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); 1461 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);
1462 mes += delmess; 1462 mes += delmess;
1463 } 1463 }
1464 mes = i18n("Local calendar changed!\n") +mes; 1464 mes = i18n("Local calendar changed!\n") +mes;
1465 mCalendar->checkAlarmForIncidence( 0, true ); 1465 mCalendar->checkAlarmForIncidence( 0, true );
1466 qDebug( mes ); 1466 qDebug( mes );
1467 if ( mSyncManager->mShowSyncSummary ) { 1467 if ( mSyncManager->mShowSyncSummary ) {
1468 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1468 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1469 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1469 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1470 qDebug("KO: WB cancelled "); 1470 qDebug("KO: WB cancelled ");
1471 mSyncManager->mWriteBackFile = false; 1471 mSyncManager->mWriteBackFile = false;
1472 return syncOK; 1472 return syncOK;
1473 } 1473 }
1474 } 1474 }
1475 return syncOK; 1475 return syncOK;
1476} 1476}
1477 1477
1478void CalendarView::setSyncDevice( QString s ) 1478void CalendarView::setSyncDevice( QString s )
1479{ 1479{
1480 mCurrentSyncDevice= s; 1480 mCurrentSyncDevice= s;
1481} 1481}
1482void CalendarView::setSyncName( QString s ) 1482void CalendarView::setSyncName( QString s )
1483{ 1483{
1484 mCurrentSyncName= s; 1484 mCurrentSyncName= s;
1485} 1485}
1486bool CalendarView::syncCalendar(QString filename, int mode) 1486bool CalendarView::syncCalendar(QString filename, int mode)
1487{ 1487{
1488 //qDebug("syncCalendar %s ", filename.latin1()); 1488 //qDebug("syncCalendar %s ", filename.latin1());
1489 mGlobalSyncMode = SYNC_MODE_NORMAL; 1489 mGlobalSyncMode = SYNC_MODE_NORMAL;
1490 CalendarLocal* calendar = new CalendarLocal(); 1490 CalendarLocal* calendar = new CalendarLocal();
1491 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1491 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1492 FileStorage* storage = new FileStorage( calendar ); 1492 FileStorage* storage = new FileStorage( calendar );
1493 bool syncOK = false; 1493 bool syncOK = false;
1494 storage->setFileName( filename ); 1494 storage->setFileName( filename );
1495 // qDebug("loading ... "); 1495 // qDebug("loading ... ");
1496 if ( storage->load() ) { 1496 if ( storage->load() ) {
1497 getEventViewerDialog()->setSyncMode( true ); 1497 getEventViewerDialog()->setSyncMode( true );
1498 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1498 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1499 getEventViewerDialog()->setSyncMode( false ); 1499 getEventViewerDialog()->setSyncMode( false );
1500 if ( syncOK ) { 1500 if ( syncOK ) {
1501 if ( mSyncManager->mWriteBackFile ) 1501 if ( mSyncManager->mWriteBackFile )
1502 { 1502 {
1503 storage->setSaveFormat( new ICalFormat() ); 1503 storage->setSaveFormat( new ICalFormat() );
1504 storage->save(); 1504 storage->save();
1505 } 1505 }
1506 } 1506 }
1507 setModified( true ); 1507 setModified( true );
1508 } 1508 }
1509 delete storage; 1509 delete storage;
1510 delete calendar; 1510 delete calendar;
1511 if ( syncOK ) 1511 if ( syncOK )
1512 updateView(); 1512 updateView();
1513 return syncOK; 1513 return syncOK;
1514} 1514}
1515 1515
1516void CalendarView::syncExternal( int mode ) 1516void CalendarView::syncExternal( int mode )
1517{ 1517{
1518 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1518 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1519 1519
1520 qApp->processEvents(); 1520 qApp->processEvents();
1521 CalendarLocal* calendar = new CalendarLocal(); 1521 CalendarLocal* calendar = new CalendarLocal();
1522 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1522 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1523 bool syncOK = false; 1523 bool syncOK = false;
1524 bool loadSuccess = false; 1524 bool loadSuccess = false;
1525 PhoneFormat* phoneFormat = 0; 1525 PhoneFormat* phoneFormat = 0;
1526 emit tempDisableBR(true); 1526 emit tempDisableBR(true);
1527#ifndef DESKTOP_VERSION 1527#ifndef DESKTOP_VERSION
1528 SharpFormat* sharpFormat = 0; 1528 SharpFormat* sharpFormat = 0;
1529 if ( mode == 0 ) { // sharp 1529 if ( mode == 0 ) { // sharp
1530 sharpFormat = new SharpFormat () ; 1530 sharpFormat = new SharpFormat () ;
1531 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1531 loadSuccess = sharpFormat->load( calendar, mCalendar );
1532 1532
1533 } else 1533 } else
1534#endif 1534#endif
1535 if ( mode == 1 ) { // phone 1535 if ( mode == 1 ) { // phone
1536 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1536 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1537 mSyncManager->mPhoneDevice, 1537 mSyncManager->mPhoneDevice,
1538 mSyncManager->mPhoneConnection, 1538 mSyncManager->mPhoneConnection,
1539 mSyncManager->mPhoneModel); 1539 mSyncManager->mPhoneModel);
1540 loadSuccess = phoneFormat->load( calendar,mCalendar); 1540 loadSuccess = phoneFormat->load( calendar,mCalendar);
1541 1541
1542 } else { 1542 } else {
1543 emit tempDisableBR(false); 1543 emit tempDisableBR(false);
1544 return; 1544 return;
1545 } 1545 }
1546 if ( loadSuccess ) { 1546 if ( loadSuccess ) {
1547 getEventViewerDialog()->setSyncMode( true ); 1547 getEventViewerDialog()->setSyncMode( true );
1548 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1548 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1549 getEventViewerDialog()->setSyncMode( false ); 1549 getEventViewerDialog()->setSyncMode( false );
1550 qApp->processEvents(); 1550 qApp->processEvents();
1551 if ( syncOK ) { 1551 if ( syncOK ) {
1552 if ( mSyncManager->mWriteBackFile ) 1552 if ( mSyncManager->mWriteBackFile )
1553 { 1553 {
1554 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1554 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1555 Incidence* inc = iL.first(); 1555 Incidence* inc = iL.first();
1556 if ( phoneFormat ) { 1556 if ( phoneFormat ) {
1557 while ( inc ) { 1557 while ( inc ) {
1558 inc->removeID(mCurrentSyncDevice); 1558 inc->removeID(mCurrentSyncDevice);
1559 inc = iL.next(); 1559 inc = iL.next();
1560 } 1560 }
1561 } 1561 }
1562#ifndef DESKTOP_VERSION 1562#ifndef DESKTOP_VERSION
1563 if ( sharpFormat ) 1563 if ( sharpFormat )
1564 sharpFormat->save(calendar); 1564 sharpFormat->save(calendar);
1565#endif 1565#endif
1566 if ( phoneFormat ) 1566 if ( phoneFormat )
1567 phoneFormat->save(calendar); 1567 phoneFormat->save(calendar);
1568 iL = calendar->rawIncidences(); 1568 iL = calendar->rawIncidences();
1569 inc = iL.first(); 1569 inc = iL.first();
1570 Incidence* loc; 1570 Incidence* loc;
1571 while ( inc ) { 1571 while ( inc ) {
1572 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1572 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1573 loc = mCalendar->incidence(inc->uid() ); 1573 loc = mCalendar->incidence(inc->uid() );
1574 if ( loc ) { 1574 if ( loc ) {
1575 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1575 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1576 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1576 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1577 } 1577 }
1578 } 1578 }
1579 inc = iL.next(); 1579 inc = iL.next();
1580 } 1580 }
1581 Incidence* lse = getLastSyncEvent(); 1581 Incidence* lse = getLastSyncEvent();
1582 if ( lse ) { 1582 if ( lse ) {
1583 lse->setReadOnly( false ); 1583 lse->setReadOnly( false );
1584 lse->setDescription( "" ); 1584 lse->setDescription( "" );
1585 lse->setReadOnly( true ); 1585 lse->setReadOnly( true );
1586 } 1586 }
1587 } 1587 }
1588 } else { 1588 } else {
1589 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1589 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1590 } 1590 }
1591 setModified( true ); 1591 setModified( true );
1592 } else { 1592 } else {
1593 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1593 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1594 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1594 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1595 question, i18n("Ok")) ; 1595 question, i18n("Ok")) ;
1596 1596
1597 } 1597 }
1598 delete calendar; 1598 delete calendar;
1599 updateView(); 1599 updateView();
1600 emit tempDisableBR(false); 1600 emit tempDisableBR(false);
1601 return ;//syncOK; 1601 return ;//syncOK;
1602 1602
1603} 1603}
1604 1604
1605bool CalendarView::importBday() 1605bool CalendarView::importBday()
1606{ 1606{
1607#ifndef KORG_NOKABC 1607#ifndef KORG_NOKABC
1608 1608
1609#ifdef DESKTOP_VERSION 1609#ifdef DESKTOP_VERSION
1610 int curCal = mCalendar->defaultCalendar(); 1610 int curCal = mCalendar->defaultCalendar();
1611 int bd = mCalEditView->getBirtdayID(); 1611 int bd = mCalEditView->getBirtdayID();
1612 if ( bd == 0 ) 1612 if ( bd == 0 )
1613 return; 1613 return false;
1614 mCalendar->setDefaultCalendar( bd ); 1614 mCalendar->setDefaultCalendar( bd );
1615 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1615 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1616 KABC::AddressBook::Iterator it; 1616 KABC::AddressBook::Iterator it;
1617 int count = 0; 1617 int count = 0;
1618 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1618 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1619 ++count; 1619 ++count;
1620 } 1620 }
1621 QProgressBar bar(count,0 ); 1621 QProgressBar bar(count,0 );
1622 int w = 300; 1622 int w = 300;
1623 if ( QApplication::desktop()->width() < 320 ) 1623 if ( QApplication::desktop()->width() < 320 )
1624 w = 220; 1624 w = 220;
1625 int h = bar.sizeHint().height() ; 1625 int h = bar.sizeHint().height() ;
1626 int dw = QApplication::desktop()->width(); 1626 int dw = QApplication::desktop()->width();
1627 int dh = QApplication::desktop()->height(); 1627 int dh = QApplication::desktop()->height();
1628 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1628 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1629 bar.show(); 1629 bar.show();
1630 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1630 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1631 qApp->processEvents(); 1631 qApp->processEvents();
1632 count = 0; 1632 count = 0;
1633 int addCount = 0; 1633 int addCount = 0;
1634 KCal::Attendee* a = 0; 1634 KCal::Attendee* a = 0;
1635 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1635 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1636 if ( ! bar.isVisible() ) 1636 if ( ! bar.isVisible() )
1637 return false; 1637 return false;
1638 bar.setProgress( count++ ); 1638 bar.setProgress( count++ );
1639 qApp->processEvents(); 1639 qApp->processEvents();
1640 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1640 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1641 if ( (*it).birthday().date().isValid() ){ 1641 if ( (*it).birthday().date().isValid() ){
1642 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1642 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1643 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1643 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1644 ++addCount; 1644 ++addCount;
1645 } 1645 }
1646 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1646 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1647 if ( anni.isValid() ){ 1647 if ( anni.isValid() ){
1648 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1648 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1649 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1649 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1650 ++addCount; 1650 ++addCount;
1651 } 1651 }
1652 } 1652 }
1653 mCalendar->setDefaultCalendar( curCal ); 1653 mCalendar->setDefaultCalendar( curCal );
1654 updateView(); 1654 updateView();
1655 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1655 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1656#else //DESKTOP_VERSION 1656#else //DESKTOP_VERSION
1657 1657
1658 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1658 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1659 // the result should now arrive through method insertBirthdays 1659 // the result should now arrive through method insertBirthdays
1660 1660
1661#endif //DESKTOP_VERSION 1661#endif //DESKTOP_VERSION
1662 1662
1663#endif //KORG_NOKABC 1663#endif //KORG_NOKABC
1664 1664
1665 1665
1666 return true; 1666 return true;
1667} 1667}
1668 1668
1669// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1669// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1670void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1670void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1671 const QStringList& anniversaryList, const QStringList& realNameList, 1671 const QStringList& anniversaryList, const QStringList& realNameList,
1672 const QStringList& emailList, const QStringList& assembledNameList, 1672 const QStringList& emailList, const QStringList& assembledNameList,
1673 const QStringList& uidList) 1673 const QStringList& uidList)
1674{ 1674{
1675 1675
1676 //qDebug("KO::CalendarView::insertBirthdays"); 1676 //qDebug("KO::CalendarView::insertBirthdays");
1677 if (uid == this->name()) 1677 if (uid == this->name())
1678 { 1678 {
1679 int curCal = mCalendar->defaultCalendar(); 1679 int curCal = mCalendar->defaultCalendar();
1680 int bd = mCalEditView->getBirtdayID(); 1680 int bd = mCalEditView->getBirtdayID();
1681 if ( bd == 0 ) 1681 if ( bd == 0 )
1682 return; 1682 return;
1683 mCalendar->setDefaultCalendar( bd ); 1683 mCalendar->setDefaultCalendar( bd );
1684 1684
1685 1685
1686 int count = birthdayList.count(); 1686 int count = birthdayList.count();
1687 int addCount = 0; 1687 int addCount = 0;
1688 KCal::Attendee* a = 0; 1688 KCal::Attendee* a = 0;
1689 1689
1690 //qDebug("CalView 1 %i", count); 1690 //qDebug("CalView 1 %i", count);
1691 1691
1692 QProgressBar bar(count,0 ); 1692 QProgressBar bar(count,0 );
1693 int w = 300; 1693 int w = 300;
1694 if ( QApplication::desktop()->width() < 320 ) 1694 if ( QApplication::desktop()->width() < 320 )
1695 w = 220; 1695 w = 220;
1696 int h = bar.sizeHint().height() ; 1696 int h = bar.sizeHint().height() ;
1697 int dw = QApplication::desktop()->width(); 1697 int dw = QApplication::desktop()->width();
1698 int dh = QApplication::desktop()->height(); 1698 int dh = QApplication::desktop()->height();
1699 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1699 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1700 bar.show(); 1700 bar.show();
1701 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1701 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1702 qApp->processEvents(); 1702 qApp->processEvents();
1703 1703
1704 QDate birthday; 1704 QDate birthday;
1705 QDate anniversary; 1705 QDate anniversary;
1706 QString realName; 1706 QString realName;
1707 QString email; 1707 QString email;
1708 QString assembledName; 1708 QString assembledName;
1709 QString uid; 1709 QString uid;
1710 bool ok = true; 1710 bool ok = true;
1711 for ( int i = 0; i < count; i++) 1711 for ( int i = 0; i < count; i++)
1712 { 1712 {
1713 if ( ! bar.isVisible() ) 1713 if ( ! bar.isVisible() )
1714 return; 1714 return;
1715 bar.setProgress( i ); 1715 bar.setProgress( i );
1716 qApp->processEvents(); 1716 qApp->processEvents();
1717 1717
1718 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1718 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1719 if (!ok) { 1719 if (!ok) {
1720 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1720 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1721 } 1721 }
1722 1722
1723 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1723 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1724 if (!ok) { 1724 if (!ok) {
1725 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1725 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1726 } 1726 }
1727 realName = realNameList[i]; 1727 realName = realNameList[i];
1728 email = emailList[i]; 1728 email = emailList[i];
1729 assembledName = assembledNameList[i]; 1729 assembledName = assembledNameList[i];
1730 uid = uidList[i]; 1730 uid = uidList[i];
1731 //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() ); 1731 //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() );
1732 1732
1733 if ( birthday.isValid() ){ 1733 if ( birthday.isValid() ){
1734 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1734 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1735 KCal::Attendee::ReqParticipant,uid) ; 1735 KCal::Attendee::ReqParticipant,uid) ;
1736 if ( addAnniversary( birthday, assembledName, a, true ) ) 1736 if ( addAnniversary( birthday, assembledName, a, true ) )
1737 ++addCount; 1737 ++addCount;
1738 } 1738 }
1739 1739
1740 if ( anniversary.isValid() ){ 1740 if ( anniversary.isValid() ){
1741 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1741 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1742 KCal::Attendee::ReqParticipant,uid) ; 1742 KCal::Attendee::ReqParticipant,uid) ;
1743 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1743 if ( addAnniversary( anniversary, assembledName, a, false ) )
1744 ++addCount; 1744 ++addCount;
1745 } 1745 }
1746 } 1746 }
1747 1747
1748 mCalendar->setDefaultCalendar( curCal ); 1748 mCalendar->setDefaultCalendar( curCal );
1749 updateView(); 1749 updateView();
1750 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1750 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1751 1751
1752 } 1752 }
1753 1753
1754} 1754}
1755 1755
1756 1756
1757 1757
1758bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1758bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1759{ 1759{
1760 //qDebug("addAnni "); 1760 //qDebug("addAnni ");
1761 Event * ev = new Event(); 1761 Event * ev = new Event();
1762 ev->setOrganizer(KOPrefs::instance()->email()); 1762 ev->setOrganizer(KOPrefs::instance()->email());
1763 if ( a ) { 1763 if ( a ) {
1764 ev->addAttendee( a ); 1764 ev->addAttendee( a );
1765 } 1765 }
1766 QString kind; 1766 QString kind;
1767 if ( birthday ) { 1767 if ( birthday ) {
1768 kind = i18n( "Birthday" ); 1768 kind = i18n( "Birthday" );
1769 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1769 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1770 } 1770 }
1771 else { 1771 else {
1772 kind = i18n( "Anniversary" ); 1772 kind = i18n( "Anniversary" );
1773 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1773 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1774 } 1774 }
1775 ev->setCategories( kind ); 1775 ev->setCategories( kind );
1776 ev->setDtStart( QDateTime(date) ); 1776 ev->setDtStart( QDateTime(date) );
1777 ev->setDtEnd( QDateTime(date) ); 1777 ev->setDtEnd( QDateTime(date) );
1778 ev->setFloats( true ); 1778 ev->setFloats( true );
1779 Recurrence * rec = ev->recurrence(); 1779 Recurrence * rec = ev->recurrence();
1780 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1780 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1781 rec->addYearlyNum( date.month() ); 1781 rec->addYearlyNum( date.month() );
1782 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1782 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1783 delete ev; 1783 delete ev;
1784 return false; 1784 return false;
1785 } 1785 }
1786 return true; 1786 return true;
1787 1787
1788} 1788}
1789bool CalendarView::importQtopia( const QString &categories, 1789bool CalendarView::importQtopia( const QString &categories,
1790 const QString &datebook, 1790 const QString &datebook,
1791 const QString &todolist ) 1791 const QString &todolist )
1792{ 1792{
1793 1793
1794 QtopiaFormat qtopiaFormat; 1794 QtopiaFormat qtopiaFormat;
1795 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1795 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1796 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1796 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1797 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1797 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1798 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1798 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1799 1799
1800 updateView(); 1800 updateView();
1801 return true; 1801 return true;
1802 1802
1803#if 0 1803#if 0
1804 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1804 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1805 mCurrentSyncDevice = "qtopia-XML"; 1805 mCurrentSyncDevice = "qtopia-XML";
1806 if ( mSyncManager->mAskForPreferences ) 1806 if ( mSyncManager->mAskForPreferences )
1807 edit_sync_options(); 1807 edit_sync_options();
1808 qApp->processEvents(); 1808 qApp->processEvents();
1809 CalendarLocal* calendar = new CalendarLocal(); 1809 CalendarLocal* calendar = new CalendarLocal();
1810 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1810 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1811 bool syncOK = false; 1811 bool syncOK = false;
1812 QtopiaFormat qtopiaFormat; 1812 QtopiaFormat qtopiaFormat;
1813 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1813 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1814 bool loadOk = true; 1814 bool loadOk = true;
1815 if ( !categories.isEmpty() ) 1815 if ( !categories.isEmpty() )
1816 loadOk = qtopiaFormat.load( calendar, categories ); 1816 loadOk = qtopiaFormat.load( calendar, categories );
1817 if ( loadOk && !datebook.isEmpty() ) 1817 if ( loadOk && !datebook.isEmpty() )
1818 loadOk = qtopiaFormat.load( calendar, datebook ); 1818 loadOk = qtopiaFormat.load( calendar, datebook );
1819 if ( loadOk && !todolist.isEmpty() ) 1819 if ( loadOk && !todolist.isEmpty() )
1820 loadOk = qtopiaFormat.load( calendar, todolist ); 1820 loadOk = qtopiaFormat.load( calendar, todolist );
1821 1821
1822 if ( loadOk ) { 1822 if ( loadOk ) {
1823 getEventViewerDialog()->setSyncMode( true ); 1823 getEventViewerDialog()->setSyncMode( true );
1824 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1824 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1825 getEventViewerDialog()->setSyncMode( false ); 1825 getEventViewerDialog()->setSyncMode( false );
1826 qApp->processEvents(); 1826 qApp->processEvents();
1827 if ( syncOK ) { 1827 if ( syncOK ) {
1828 if ( mSyncManager->mWriteBackFile ) 1828 if ( mSyncManager->mWriteBackFile )
1829 { 1829 {
1830 // write back XML file 1830 // write back XML file
1831 1831
1832 } 1832 }
1833 setModified( true ); 1833 setModified( true );
1834 } 1834 }
1835 } else { 1835 } else {
1836 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1836 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1837 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1837 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1838 question, i18n("Ok")) ; 1838 question, i18n("Ok")) ;
1839 } 1839 }
1840 delete calendar; 1840 delete calendar;
1841 updateView(); 1841 updateView();
1842 return syncOK; 1842 return syncOK;
1843 1843
1844 1844
1845#endif 1845#endif
1846 1846
1847} 1847}
1848 1848
1849void CalendarView::setSyncEventsReadOnly() 1849void CalendarView::setSyncEventsReadOnly()
1850{ 1850{
1851 mCalendar->setSyncEventsReadOnly(); 1851 mCalendar->setSyncEventsReadOnly();
1852} 1852}
1853 1853
1854bool CalendarView::loadCalendars() 1854bool CalendarView::loadCalendars()
1855{ 1855{
1856 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1856 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1857 KopiCalendarFile * cal = calendars.first(); 1857 KopiCalendarFile * cal = calendars.first();
1858 mCalendar->setDefaultCalendar( 1 ); 1858 mCalendar->setDefaultCalendar( 1 );
1859 openCalendar( MainWindow::defaultFileName(), false ); 1859 openCalendar( MainWindow::defaultFileName(), false );
1860 cal = calendars.next(); 1860 cal = calendars.next();
1861 while ( cal ) { 1861 while ( cal ) {
1862 addCalendar( cal ); 1862 addCalendar( cal );
1863 cal = calendars.next(); 1863 cal = calendars.next();
1864 } 1864 }
1865 restoreCalendarSettings(); 1865 restoreCalendarSettings();
1866 return true; 1866 return true;
1867} 1867}
1868bool CalendarView::restoreCalendarSettings() 1868bool CalendarView::restoreCalendarSettings()
1869{ 1869{
1870 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1870 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1871 KopiCalendarFile * cal = calendars.first(); 1871 KopiCalendarFile * cal = calendars.first();
1872 while ( cal ) { 1872 while ( cal ) {
1873 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 1873 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
1874 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 1874 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
1875 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 1875 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
1876 if ( cal->isStandard ) 1876 if ( cal->isStandard )
1877 mCalendar->setDefaultCalendar( cal->mCalNumber ); 1877 mCalendar->setDefaultCalendar( cal->mCalNumber );
1878 cal = calendars.next(); 1878 cal = calendars.next();
1879 } 1879 }
1880 setSyncEventsReadOnly(); 1880 setSyncEventsReadOnly();
1881 mCalendar->reInitAlarmSettings(); 1881 mCalendar->reInitAlarmSettings();
1882 updateUnmanagedViews(); 1882 updateUnmanagedViews();
1883 updateView(); 1883 updateView();
1884 return true; 1884 return true;
1885} 1885}
1886void CalendarView::addCalendarId( int id ) 1886void CalendarView::addCalendarId( int id )
1887{ 1887{
1888 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 1888 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
1889 addCalendar( cal ); 1889 addCalendar( cal );
1890} 1890}
1891bool CalendarView::addCalendar( KopiCalendarFile * cal ) 1891bool CalendarView::addCalendar( KopiCalendarFile * cal )
1892{ 1892{
1893 cal->mErrorOnLoad = false; 1893 cal->mErrorOnLoad = false;
1894 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 1894 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
1895 cal->mLoadDt = QDateTime::currentDateTime(); 1895 cal->mLoadDt = QDateTime::currentDateTime();
1896 return true; 1896 return true;
1897 } 1897 }
1898 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); 1898 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() );
1899 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); 1899 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName));
1900 cal->mErrorOnLoad = true; 1900 cal->mErrorOnLoad = true;
1901 return false; 1901 return false;
1902} 1902}
1903bool CalendarView::openCalendar(QString filename, bool merge) 1903bool CalendarView::openCalendar(QString filename, bool merge)
1904{ 1904{
1905 1905
1906 if (filename.isEmpty()) { 1906 if (filename.isEmpty()) {
1907 return false; 1907 return false;
1908 } 1908 }
1909 1909
1910 if (!QFile::exists(filename)) { 1910 if (!QFile::exists(filename)) {
1911 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1911 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1912 return false; 1912 return false;
1913 } 1913 }
1914 1914
1915 globalFlagBlockAgenda = 1; 1915 globalFlagBlockAgenda = 1;
1916 clearAllViews(); 1916 clearAllViews();
1917 if (!merge) { 1917 if (!merge) {
1918 mViewManager->setDocumentId( filename ); 1918 mViewManager->setDocumentId( filename );
1919 mCalendar->close(); 1919 mCalendar->close();
1920 } 1920 }
1921 mStorage->setFileName( filename ); 1921 mStorage->setFileName( filename );
1922 1922
1923 if ( mStorage->load() ) { 1923 if ( mStorage->load() ) {
1924 if ( merge ) ;//setModified( true ); 1924 if ( merge ) ;//setModified( true );
1925 else { 1925 else {
1926 //setModified( true ); 1926 //setModified( true );
1927 mViewManager->setDocumentId( filename ); 1927 mViewManager->setDocumentId( filename );
1928 mDialogManager->setDocumentId( filename ); 1928 mDialogManager->setDocumentId( filename );
1929 mTodoList->setDocumentId( filename ); 1929 mTodoList->setDocumentId( filename );
1930 } 1930 }
1931 globalFlagBlockAgenda = 2; 1931 globalFlagBlockAgenda = 2;
1932 // if ( getLastSyncEvent() ) 1932 // if ( getLastSyncEvent() )
1933 // getLastSyncEvent()->setReadOnly( true ); 1933 // getLastSyncEvent()->setReadOnly( true );
1934 mCalendar->reInitAlarmSettings(); 1934 mCalendar->reInitAlarmSettings();
1935 setSyncEventsReadOnly(); 1935 setSyncEventsReadOnly();
1936 updateUnmanagedViews(); 1936 updateUnmanagedViews();
1937 updateView(); 1937 updateView();
1938 if ( filename != MainWindow::defaultFileName() ) { 1938 if ( filename != MainWindow::defaultFileName() ) {
1939 saveCalendar( MainWindow::defaultFileName() ); 1939 saveCalendar( MainWindow::defaultFileName() );
1940 } else { 1940 } else {
1941 QFileInfo finf ( MainWindow::defaultFileName()); 1941 QFileInfo finf ( MainWindow::defaultFileName());
1942 if ( finf.exists() ) { 1942 if ( finf.exists() ) {
1943 setLoadedFileVersion( finf.lastModified () ); 1943 setLoadedFileVersion( finf.lastModified () );
1944 } 1944 }
1945 } 1945 }
1946 return true; 1946 return true;
1947 } else { 1947 } else {
1948 // while failing to load, the calendar object could 1948 // while failing to load, the calendar object could
1949 // have become partially populated. Clear it out. 1949 // have become partially populated. Clear it out.
1950 if ( !merge ) { 1950 if ( !merge ) {
1951 mCalendar->close(); 1951 mCalendar->close();
1952 mViewManager->setDocumentId( filename ); 1952 mViewManager->setDocumentId( filename );
1953 mDialogManager->setDocumentId( filename ); 1953 mDialogManager->setDocumentId( filename );
1954 mTodoList->setDocumentId( filename ); 1954 mTodoList->setDocumentId( filename );
1955 } 1955 }
1956 1956
1957 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1957 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1958 1958
1959 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1959 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1960 globalFlagBlockAgenda = 2; 1960 globalFlagBlockAgenda = 2;
1961 mCalendar->reInitAlarmSettings(); 1961 mCalendar->reInitAlarmSettings();
1962 setSyncEventsReadOnly(); 1962 setSyncEventsReadOnly();
1963 updateUnmanagedViews(); 1963 updateUnmanagedViews();
1964 updateView(); 1964 updateView();
1965 } 1965 }
1966 return false; 1966 return false;
1967} 1967}
1968void CalendarView::showOpenError() 1968void CalendarView::showOpenError()
1969{ 1969{
1970 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1970 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1971} 1971}
1972void CalendarView::setLoadedFileVersion(QDateTime dt) 1972void CalendarView::setLoadedFileVersion(QDateTime dt)
1973{ 1973{
1974 loadedFileVersion = dt; 1974 loadedFileVersion = dt;
1975} 1975}
1976bool CalendarView::checkFileChanged(QString fn) 1976bool CalendarView::checkFileChanged(QString fn)
1977{ 1977{
1978 QFileInfo finf ( fn ); 1978 QFileInfo finf ( fn );
1979 if ( !finf.exists() ) 1979 if ( !finf.exists() )
1980 return true; 1980 return true;
1981 QDateTime dt = finf.lastModified (); 1981 QDateTime dt = finf.lastModified ();
1982 if ( dt <= loadedFileVersion ) 1982 if ( dt <= loadedFileVersion )
1983 return false; 1983 return false;
1984 return true; 1984 return true;
1985 1985
1986} 1986}
1987void CalendarView::watchSavedFile() 1987void CalendarView::watchSavedFile()
1988{ 1988{
1989 QFileInfo finf ( MainWindow::defaultFileName()); 1989 QFileInfo finf ( MainWindow::defaultFileName());
1990 if ( !finf.exists() ) 1990 if ( !finf.exists() )
1991 return; 1991 return;
1992 QDateTime dt = finf.lastModified (); 1992 QDateTime dt = finf.lastModified ();
1993 if ( dt < loadedFileVersion ) { 1993 if ( dt < loadedFileVersion ) {
1994 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1994 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1995 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1995 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1996 return; 1996 return;
1997 } 1997 }
1998 loadedFileVersion = dt; 1998 loadedFileVersion = dt;
1999} 1999}
2000bool CalendarView::checkAllFileVersions() 2000bool CalendarView::checkAllFileVersions()
2001{ 2001{
2002 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2002 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2003 KopiCalendarFile * cal = calendars.first(); 2003 KopiCalendarFile * cal = calendars.first();
2004 mCalendar->setDefaultCalendar( 1 ); 2004 mCalendar->setDefaultCalendar( 1 );
2005 mCalendar->setDefaultCalendarEnabledOnly(); 2005 mCalendar->setDefaultCalendarEnabledOnly();
2006 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2006 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2007 if ( !checkFileVersion(MainWindow::defaultFileName())) { 2007 if ( !checkFileVersion(MainWindow::defaultFileName())) {
2008 restoreCalendarSettings(); 2008 restoreCalendarSettings();
2009 return false; 2009 return false;
2010 } 2010 }
2011 } 2011 }
2012 cal = calendars.next(); 2012 cal = calendars.next();
2013 QDateTime storeTemp = loadedFileVersion; 2013 QDateTime storeTemp = loadedFileVersion;
2014 while ( cal ) { 2014 while ( cal ) {
2015 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2015 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2016 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2016 mCalendar->setDefaultCalendar( cal->mCalNumber );
2017 mCalendar->setDefaultCalendarEnabledOnly(); 2017 mCalendar->setDefaultCalendarEnabledOnly();
2018 loadedFileVersion = cal->mLoadDt.addSecs( 15 ); 2018 loadedFileVersion = cal->mLoadDt.addSecs( 15 );
2019 if ( !checkFileVersion(cal->mFileName )) { 2019 if ( !checkFileVersion(cal->mFileName )) {
2020 loadedFileVersion = storeTemp; 2020 loadedFileVersion = storeTemp;
2021 restoreCalendarSettings(); 2021 restoreCalendarSettings();
2022 return false; 2022 return false;
2023 } 2023 }
2024 } 2024 }
2025 cal = calendars.next(); 2025 cal = calendars.next();
2026 } 2026 }
2027 loadedFileVersion = storeTemp; 2027 loadedFileVersion = storeTemp;
2028 return true; 2028 return true;
2029} 2029}
2030bool CalendarView::checkFileVersion(QString fn) 2030bool CalendarView::checkFileVersion(QString fn)
2031{ 2031{
2032 QFileInfo finf ( fn ); 2032 QFileInfo finf ( fn );
2033 if ( !finf.exists() ) 2033 if ( !finf.exists() )
2034 return true; 2034 return true;
2035 QDateTime dt = finf.lastModified (); 2035 QDateTime dt = finf.lastModified ();
2036 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1()); 2036 qDebug("loaded file version %s %s", fn.latin1(), loadedFileVersion.toString().latin1());
2037 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1()); 2037 qDebug("file on disk version %s %s", fn.latin1(),dt.toString().latin1());
2038 if ( dt <= loadedFileVersion ) 2038 if ( dt <= loadedFileVersion )
2039 return true; 2039 return true;
2040 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 2040 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on 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(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
2041 i18n("KO/Pi Warning"),i18n("Overwrite"), 2041 i18n("KO/Pi Warning"),i18n("Overwrite"),
2042 i18n("Sync+save")); 2042 i18n("Sync+save"));
2043 2043
2044 if ( km == KMessageBox::Cancel ) 2044 if ( km == KMessageBox::Cancel )
2045 return false; 2045 return false;
2046 if ( km == KMessageBox::Yes ) 2046 if ( km == KMessageBox::Yes )
2047 return true; 2047 return true;
2048 2048
2049 setSyncDevice("deleteaftersync" ); 2049 setSyncDevice("deleteaftersync" );
2050 mSyncManager->mAskForPreferences = true; 2050 mSyncManager->mAskForPreferences = true;
2051 mSyncManager->mSyncAlgoPrefs = 3; 2051 mSyncManager->mSyncAlgoPrefs = 3;
2052 mSyncManager->mWriteBackFile = false; 2052 mSyncManager->mWriteBackFile = false;
2053 mSyncManager->mWriteBackExistingOnly = false; 2053 mSyncManager->mWriteBackExistingOnly = false;
2054 mSyncManager->mShowSyncSummary = false; 2054 mSyncManager->mShowSyncSummary = false;
2055 syncCalendar( fn, 3 ); 2055 syncCalendar( fn, 3 );
2056 Event * e = getLastSyncEvent(); 2056 Event * e = getLastSyncEvent();
2057 if ( e ) 2057 if ( e )
2058 mCalendar->deleteEvent( e ); 2058 mCalendar->deleteEvent( e );
2059 return true; 2059 return true;
2060} 2060}
2061bool CalendarView::saveCalendars() 2061bool CalendarView::saveCalendars()
2062{ 2062{
2063 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 2063 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
2064 KopiCalendarFile * cal = calendars.first(); 2064 KopiCalendarFile * cal = calendars.first();
2065 mCalendar->setDefaultCalendar( 1 ); 2065 mCalendar->setDefaultCalendar( 1 );
2066 mCalendar->setDefaultCalendarEnabledOnly(); 2066 mCalendar->setDefaultCalendarEnabledOnly();
2067 saveCalendar( MainWindow::defaultFileName() ); 2067 saveCalendar( MainWindow::defaultFileName() );
2068 cal = calendars.next(); 2068 cal = calendars.next();
2069 while ( cal ) { 2069 while ( cal ) {
2070 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { 2070 if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
2071 mCalendar->setDefaultCalendar( cal->mCalNumber ); 2071 mCalendar->setDefaultCalendar( cal->mCalNumber );
2072 mCalendar->setDefaultCalendarEnabledOnly(); 2072 mCalendar->setDefaultCalendarEnabledOnly();
2073 if ( saveCalendar( cal->mFileName ) ) 2073 if ( saveCalendar( cal->mFileName ) )
2074 cal->mLoadDt = QDateTime::currentDateTime(); 2074 cal->mLoadDt = QDateTime::currentDateTime();
2075 } 2075 }
2076 cal = calendars.next(); 2076 cal = calendars.next();
2077 } 2077 }
2078 restoreCalendarSettings(); 2078 restoreCalendarSettings();
2079 return true; 2079 return true;
2080} 2080}
2081bool CalendarView::saveCalendar( QString filename ) 2081bool CalendarView::saveCalendar( QString filename )
2082{ 2082{
2083 2083
2084 // Store back all unsaved data into calendar object 2084 // Store back all unsaved data into calendar object
2085 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 2085 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
2086 if ( mViewManager->currentView() ) 2086 if ( mViewManager->currentView() )
2087 mViewManager->currentView()->flushView(); 2087 mViewManager->currentView()->flushView();
2088 2088
2089 2089
2090 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 2090 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
2091 mStorage->setSaveFormat( new ICalFormat() ); 2091 mStorage->setSaveFormat( new ICalFormat() );
2092 mStorage->setFileName( filename ); 2092 mStorage->setFileName( filename );
2093 bool success; 2093 bool success;
2094 success = mStorage->save(); 2094 success = mStorage->save();
2095 if ( !success ) { 2095 if ( !success ) {
2096 return false; 2096 return false;
2097 } 2097 }
2098 if ( filename == MainWindow::defaultFileName() ) { 2098 if ( filename == MainWindow::defaultFileName() ) {
2099 setLoadedFileVersion( lfv ); 2099 setLoadedFileVersion( lfv );
2100 watchSavedFile(); 2100 watchSavedFile();
2101 } 2101 }
2102 return true; 2102 return true;
2103} 2103}
2104 2104
2105void CalendarView::closeCalendar() 2105void CalendarView::closeCalendar()
2106{ 2106{
2107 2107
2108 // child windows no longer valid 2108 // child windows no longer valid
2109 clearAllViews(); 2109 clearAllViews();
2110 emit closingDown(); 2110 emit closingDown();
2111 2111
2112 mCalendar->close(); 2112 mCalendar->close();
2113 setModified(false); 2113 setModified(false);
2114 updateView(); 2114 updateView();
2115} 2115}
2116 2116
2117void CalendarView::archiveCalendar() 2117void CalendarView::archiveCalendar()
2118{ 2118{
2119 mDialogManager->showArchiveDialog(); 2119 mDialogManager->showArchiveDialog();
2120} 2120}
2121 2121
2122 2122
2123void CalendarView::readSettings() 2123void CalendarView::readSettings()
2124{ 2124{
2125 2125
2126 2126
2127 // mViewManager->showAgendaView(); 2127 // mViewManager->showAgendaView();
2128 QString str; 2128 QString str;
2129 //qDebug("CalendarView::readSettings() "); 2129 //qDebug("CalendarView::readSettings() ");
2130 // read settings from the KConfig, supplying reasonable 2130 // read settings from the KConfig, supplying reasonable
2131 // defaults where none are to be found 2131 // defaults where none are to be found
2132 KConfig *config = KOGlobals::config(); 2132 KConfig *config = KOGlobals::config();
2133#ifndef KORG_NOSPLITTER 2133#ifndef KORG_NOSPLITTER
2134 config->setGroup("KOrganizer Geometry"); 2134 config->setGroup("KOrganizer Geometry");
2135 2135
2136 QValueList<int> sizes = config->readIntListEntry("Separator1"); 2136 QValueList<int> sizes = config->readIntListEntry("Separator1");
2137 if (sizes.count() != 2) { 2137 if (sizes.count() != 2) {
2138 sizes << mDateNavigator->minimumSizeHint().width(); 2138 sizes << mDateNavigator->minimumSizeHint().width();
2139 sizes << 300; 2139 sizes << 300;
2140 } 2140 }
2141 mPanner->setSizes(sizes); 2141 mPanner->setSizes(sizes);
2142 2142
2143 sizes = config->readIntListEntry("Separator2"); 2143 sizes = config->readIntListEntry("Separator2");
2144 if ( ( mResourceView && sizes.count() == 4 ) || 2144 if ( ( mResourceView && sizes.count() == 4 ) ||
2145 ( !mResourceView && sizes.count() == 3 ) ) { 2145 ( !mResourceView && sizes.count() == 3 ) ) {
2146 mLeftSplitter->setSizes(sizes); 2146 mLeftSplitter->setSizes(sizes);
2147 } 2147 }
2148#endif 2148#endif
2149 globalFlagBlockAgenda = 1; 2149 globalFlagBlockAgenda = 1;
2150 mViewManager->showAgendaView(); 2150 mViewManager->showAgendaView();
2151 //mViewManager->readSettings( config ); 2151 //mViewManager->readSettings( config );
2152 mTodoList->restoreLayout(config,QString("Todo Layout")); 2152 mTodoList->restoreLayout(config,QString("Todo Layout"));
2153 readFilterSettings(config); 2153 readFilterSettings(config);
2154 2154
2155#ifdef DESKTOP_VERSION 2155#ifdef DESKTOP_VERSION
2156 config->setGroup("WidgetLayout"); 2156 config->setGroup("WidgetLayout");
2157 QStringList list; 2157 QStringList list;
2158 list = config->readListEntry("MainLayout"); 2158 list = config->readListEntry("MainLayout");
2159 int x,y,w,h; 2159 int x,y,w,h;
2160 if ( ! list.isEmpty() ) { 2160 if ( ! list.isEmpty() ) {
2161 x = list[0].toInt(); 2161 x = list[0].toInt();
2162 y = list[1].toInt(); 2162 y = list[1].toInt();
2163 w = list[2].toInt(); 2163 w = list[2].toInt();
2164 h = list[3].toInt(); 2164 h = list[3].toInt();
2165 KApplication::testCoords( &x,&y,&w,&h ); 2165 KApplication::testCoords( &x,&y,&w,&h );
2166 topLevelWidget()->setGeometry(x,y,w,h); 2166 topLevelWidget()->setGeometry(x,y,w,h);
2167 2167
2168 } else { 2168 } else {
2169 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 2169 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
2170 } 2170 }
2171 list = config->readListEntry("EditEventLayout"); 2171 list = config->readListEntry("EditEventLayout");
2172 if ( ! list.isEmpty() ) { 2172 if ( ! list.isEmpty() ) {
2173 x = list[0].toInt(); 2173 x = list[0].toInt();
2174 y = list[1].toInt(); 2174 y = list[1].toInt();
2175 w = list[2].toInt(); 2175 w = list[2].toInt();
2176 h = list[3].toInt(); 2176 h = list[3].toInt();
2177 KApplication::testCoords( &x,&y,&w,&h ); 2177 KApplication::testCoords( &x,&y,&w,&h );
2178 mEventEditor->setGeometry(x,y,w,h); 2178 mEventEditor->setGeometry(x,y,w,h);
2179 2179
2180 } 2180 }
2181 list = config->readListEntry("EditTodoLayout"); 2181 list = config->readListEntry("EditTodoLayout");
2182 if ( ! list.isEmpty() ) { 2182 if ( ! list.isEmpty() ) {
2183 x = list[0].toInt(); 2183 x = list[0].toInt();
2184 y = list[1].toInt(); 2184 y = list[1].toInt();
2185 w = list[2].toInt(); 2185 w = list[2].toInt();
2186 h = list[3].toInt(); 2186 h = list[3].toInt();
2187 KApplication::testCoords( &x,&y,&w,&h ); 2187 KApplication::testCoords( &x,&y,&w,&h );
2188 mTodoEditor->setGeometry(x,y,w,h); 2188 mTodoEditor->setGeometry(x,y,w,h);
2189 2189
2190 } 2190 }
2191 list = config->readListEntry("ViewerLayout"); 2191 list = config->readListEntry("ViewerLayout");
2192 if ( ! list.isEmpty() ) { 2192 if ( ! list.isEmpty() ) {
2193 x = list[0].toInt(); 2193 x = list[0].toInt();
2194 y = list[1].toInt(); 2194 y = list[1].toInt();
2195 w = list[2].toInt(); 2195 w = list[2].toInt();
2196 h = list[3].toInt(); 2196 h = list[3].toInt();
2197 KApplication::testCoords( &x,&y,&w,&h ); 2197 KApplication::testCoords( &x,&y,&w,&h );
2198 getEventViewerDialog()->setGeometry(x,y,w,h); 2198 getEventViewerDialog()->setGeometry(x,y,w,h);
2199 } 2199 }
2200#endif 2200#endif
2201 config->setGroup( "Views" ); 2201 config->setGroup( "Views" );
2202 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 2202 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
2203 2203
2204 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 2204 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
2205 2205
2206 int resetval = 0; 2206 int resetval = 0;
2207 int maxVal = 0; 2207 int maxVal = 0;
2208 if (sizes.count() != 3) { 2208 if (sizes.count() != 3) {
2209 if ( KOPrefs::instance()->mVerticalScreen ) { 2209 if ( KOPrefs::instance()->mVerticalScreen ) {
2210 resetval = mDateNavigator->sizeHint().width()+2; 2210 resetval = mDateNavigator->sizeHint().width()+2;
2211 } else { 2211 } else {
2212 resetval = mDateNavigator->sizeHint().height()+2; 2212 resetval = mDateNavigator->sizeHint().height()+2;
2213 } 2213 }
2214 } 2214 }
2215 if ( resetval ) { 2215 if ( resetval ) {
2216 sizes.clear(); 2216 sizes.clear();
2217 if ( KOPrefs::instance()->mVerticalScreen ) { 2217 if ( KOPrefs::instance()->mVerticalScreen ) {
2218 maxVal = QApplication::desktop()->width() -10; 2218 maxVal = QApplication::desktop()->width() -10;
2219 } else { 2219 } else {
2220 maxVal = QApplication::desktop()->height()-10; 2220 maxVal = QApplication::desktop()->height()-10;
2221 } 2221 }
2222 sizes << resetval; 2222 sizes << resetval;
2223 if ( maxVal < resetval + resetval) 2223 if ( maxVal < resetval + resetval)
2224 resetval = maxVal - resetval; 2224 resetval = maxVal - resetval;
2225 sizes << resetval; 2225 sizes << resetval;
2226 sizes << 100; 2226 sizes << 100;
2227 } 2227 }
2228 mLeftFrame->setSizes(sizes); 2228 mLeftFrame->setSizes(sizes);
2229 sizes = config->readIntListEntry("Main Splitter Frame"); 2229 sizes = config->readIntListEntry("Main Splitter Frame");
2230 resetval = 0; 2230 resetval = 0;
2231 maxVal = 0; 2231 maxVal = 0;
2232 if (sizes.count() != 2) { 2232 if (sizes.count() != 2) {
2233 if ( !KOPrefs::instance()->mVerticalScreen ) { 2233 if ( !KOPrefs::instance()->mVerticalScreen ) {
2234 resetval = mDateNavigator->sizeHint().width()+2; 2234 resetval = mDateNavigator->sizeHint().width()+2;
2235 } else { 2235 } else {
2236 resetval = mDateNavigator->sizeHint().height()+2; 2236 resetval = mDateNavigator->sizeHint().height()+2;
2237 } 2237 }
2238 } 2238 }
2239 if ( resetval ) { 2239 if ( resetval ) {
2240 sizes.clear(); 2240 sizes.clear();
2241 if ( !KOPrefs::instance()->mVerticalScreen ) { 2241 if ( !KOPrefs::instance()->mVerticalScreen ) {
2242 maxVal = QApplication::desktop()->width() -10; 2242 maxVal = QApplication::desktop()->width() -10;
2243 } else { 2243 } else {
2244 maxVal = QApplication::desktop()->height()-10; 2244 maxVal = QApplication::desktop()->height()-10;
2245 } 2245 }
2246 sizes << resetval; 2246 sizes << resetval;
2247 if ( maxVal < resetval + resetval) 2247 if ( maxVal < resetval + resetval)
2248 resetval = maxVal - resetval; 2248 resetval = maxVal - resetval;
2249 sizes << resetval; 2249 sizes << resetval;
2250 } 2250 }
2251 mMainFrame->setSizes(sizes); 2251 mMainFrame->setSizes(sizes);
2252 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 2252 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
2253 else if ( dateCount == 7 ) mNavigator->selectWeek(); 2253 else if ( dateCount == 7 ) mNavigator->selectWeek();
2254 else mNavigator->selectDates( dateCount ); 2254 else mNavigator->selectDates( dateCount );
2255 // mViewManager->readSettings( config ); 2255 // mViewManager->readSettings( config );
2256 updateConfig(); 2256 updateConfig();
2257 globalFlagBlockAgenda = 2; 2257 globalFlagBlockAgenda = 2;
2258 mViewManager->readSettings( config ); 2258 mViewManager->readSettings( config );
2259 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 2259 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
2260} 2260}
2261 2261
2262 2262
2263void CalendarView::writeSettings() 2263void CalendarView::writeSettings()
2264{ 2264{
2265 // kdDebug() << "CalendarView::writeSettings" << endl; 2265 // kdDebug() << "CalendarView::writeSettings" << endl;
2266 2266
2267 KConfig *config = KOGlobals::config(); 2267 KConfig *config = KOGlobals::config();
2268 2268
2269 mViewManager->writeSettings( config ); 2269 mViewManager->writeSettings( config );
2270 mTodoList->saveLayout(config,QString("Todo Layout")); 2270 mTodoList->saveLayout(config,QString("Todo Layout"));
2271 mDialogManager->writeSettings( config ); 2271 mDialogManager->writeSettings( config );
2272 //KOPrefs::instance()->usrWriteConfig(); 2272 //KOPrefs::instance()->usrWriteConfig();
2273 KOPrefs::instance()->writeConfig(); 2273 KOPrefs::instance()->writeConfig();
2274 2274
2275 writeFilterSettings(config); 2275 writeFilterSettings(config);
2276 config->setGroup( "AppRun" ); 2276 config->setGroup( "AppRun" );
2277 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); 2277 QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) );
2278 int days = dt.daysTo( QDate::currentDate() ); 2278 int days = dt.daysTo( QDate::currentDate() );
2279 dt = dt.addDays( days ); 2279 dt = dt.addDays( days );
2280 int secs = dt.secsTo( QDateTime::currentDateTime() ); 2280 int secs = dt.secsTo( QDateTime::currentDateTime() );
2281 config->writeEntry( "LatestProgramStopDays", days ); 2281 config->writeEntry( "LatestProgramStopDays", days );
2282 config->writeEntry( "LatestProgramStopSecs", secs ); 2282 config->writeEntry( "LatestProgramStopSecs", secs );
2283 //qDebug("KO: Writing stop time: %d ", secs); 2283 //qDebug("KO: Writing stop time: %d ", secs);
2284 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); 2284 //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() );
2285 //QDateTime latest = dt.addSecs ( secs ); 2285 //QDateTime latest = dt.addSecs ( secs );
2286 //qDebug("KO: Termination on %s ", latest.toString().latin1()); 2286 //qDebug("KO: Termination on %s ", latest.toString().latin1());
2287 config->setGroup( "Views" ); 2287 config->setGroup( "Views" );
2288 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 2288 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
2289 2289
2290#if 0 2290#if 0
2291 qDebug("********************* "); 2291 qDebug("********************* ");
2292 qDebug("Testcode secsto "); 2292 qDebug("Testcode secsto ");
2293 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); 2293 QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) );
2294 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); 2294 QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) );
2295 int secsto = dt_nodaylight.secsTo( dt_daylight ); 2295 int secsto = dt_nodaylight.secsTo( dt_daylight );
2296 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); 2296 QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto );
2297 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); 2297 qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() );
2298 qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); 2298 qDebug("dt daylight %s ",dt_daylight.toString().latin1() );
2299 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); 2299 qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() );
2300 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); 2300 qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600);
2301 qDebug("********************* testcode end"); 2301 qDebug("********************* testcode end");
2302 2302
2303#endif 2303#endif
2304 2304
2305 QValueList<int> listINT = mLeftFrame->sizes(); 2305 QValueList<int> listINT = mLeftFrame->sizes();
2306 config->writeEntry("Left Splitter Frame",listINT); 2306 config->writeEntry("Left Splitter Frame",listINT);
2307 QValueList<int> listINT2 = mMainFrame->sizes(); 2307 QValueList<int> listINT2 = mMainFrame->sizes();
2308 config->writeEntry("Main Splitter Frame",listINT2); 2308 config->writeEntry("Main Splitter Frame",listINT2);
2309#ifdef DESKTOP_VERSION 2309#ifdef DESKTOP_VERSION
2310 config->setGroup("WidgetLayout"); 2310 config->setGroup("WidgetLayout");
2311 QStringList list ;//= config->readListEntry("MainLayout"); 2311 QStringList list ;//= config->readListEntry("MainLayout");
2312 int x,y,w,h; 2312 int x,y,w,h;
2313 QWidget* wid; 2313 QWidget* wid;
2314 wid = topLevelWidget(); 2314 wid = topLevelWidget();
2315 x = wid->geometry().x(); 2315 x = wid->geometry().x();
2316 y = wid->geometry().y(); 2316 y = wid->geometry().y();
2317 w = wid->width(); 2317 w = wid->width();
2318 h = wid->height(); 2318 h = wid->height();
2319 list.clear(); 2319 list.clear();
2320 list << QString::number( x ); 2320 list << QString::number( x );
2321 list << QString::number( y ); 2321 list << QString::number( y );
2322 list << QString::number( w ); 2322 list << QString::number( w );
2323 list << QString::number( h ); 2323 list << QString::number( h );
2324 config->writeEntry("MainLayout",list ); 2324 config->writeEntry("MainLayout",list );
2325 2325
2326 wid = mEventEditor; 2326 wid = mEventEditor;
2327 x = wid->geometry().x(); 2327 x = wid->geometry().x();
2328 y = wid->geometry().y(); 2328 y = wid->geometry().y();
2329 w = wid->width(); 2329 w = wid->width();
2330 h = wid->height(); 2330 h = wid->height();
2331 list.clear(); 2331 list.clear();
2332 list << QString::number( x ); 2332 list << QString::number( x );
2333 list << QString::number( y ); 2333 list << QString::number( y );
2334 list << QString::number( w ); 2334 list << QString::number( w );
2335 list << QString::number( h ); 2335 list << QString::number( h );
2336 config->writeEntry("EditEventLayout",list ); 2336 config->writeEntry("EditEventLayout",list );
2337 2337
2338 wid = mTodoEditor; 2338 wid = mTodoEditor;
2339 x = wid->geometry().x(); 2339 x = wid->geometry().x();
2340 y = wid->geometry().y(); 2340 y = wid->geometry().y();
2341 w = wid->width(); 2341 w = wid->width();
2342 h = wid->height(); 2342 h = wid->height();
2343 list.clear(); 2343 list.clear();
2344 list << QString::number( x ); 2344 list << QString::number( x );
2345 list << QString::number( y ); 2345 list << QString::number( y );
2346 list << QString::number( w ); 2346 list << QString::number( w );
2347 list << QString::number( h ); 2347 list << QString::number( h );
2348 config->writeEntry("EditTodoLayout",list ); 2348 config->writeEntry("EditTodoLayout",list );
2349 wid = getEventViewerDialog(); 2349 wid = getEventViewerDialog();
2350 x = wid->geometry().x(); 2350 x = wid->geometry().x();
2351 y = wid->geometry().y(); 2351 y = wid->geometry().y();
2352 w = wid->width(); 2352 w = wid->width();
2353 h = wid->height(); 2353 h = wid->height();
2354 list.clear(); 2354 list.clear();
2355 list << QString::number( x ); 2355 list << QString::number( x );
2356 list << QString::number( y ); 2356 list << QString::number( y );
2357 list << QString::number( w ); 2357 list << QString::number( w );
2358 list << QString::number( h ); 2358 list << QString::number( h );
2359 config->writeEntry("ViewerLayout",list ); 2359 config->writeEntry("ViewerLayout",list );
2360 wid = mDialogManager->getSearchDialog(); 2360 wid = mDialogManager->getSearchDialog();
2361 if ( wid ) { 2361 if ( wid ) {
2362 x = wid->geometry().x(); 2362 x = wid->geometry().x();
2363 y = wid->geometry().y(); 2363 y = wid->geometry().y();
2364 w = wid->width(); 2364 w = wid->width();
2365 h = wid->height(); 2365 h = wid->height();
2366 list.clear(); 2366 list.clear();
2367 list << QString::number( x ); 2367 list << QString::number( x );
2368 list << QString::number( y ); 2368 list << QString::number( y );
2369 list << QString::number( w ); 2369 list << QString::number( w );
2370 list << QString::number( h ); 2370 list << QString::number( h );
2371 config->writeEntry("SearchLayout",list ); 2371 config->writeEntry("SearchLayout",list );
2372 } 2372 }
2373#endif 2373#endif
2374 2374
2375 2375
2376 config->sync(); 2376 config->sync();
2377} 2377}
2378 2378
2379void CalendarView::readFilterSettings(KConfig *config) 2379void CalendarView::readFilterSettings(KConfig *config)
2380{ 2380{
2381 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2381 // kdDebug() << "CalendarView::readFilterSettings()" << endl;