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 bd7376a..904bbe2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -922,3230 +922,3230 @@ void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* t
922 } 922 }
923 if ( toDelete->type() == "Journal" ) 923 if ( toDelete->type() == "Journal" )
924 return; 924 return;
925 925
926 Event* eve = lastSync.first(); 926 Event* eve = lastSync.first();
927 927
928 while ( eve ) { 928 while ( eve ) {
929 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name 929 QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
930 if ( !id.isEmpty() ) { 930 if ( !id.isEmpty() ) {
931 QString des = eve->description(); 931 QString des = eve->description();
932 QString pref = "e"; 932 QString pref = "e";
933 if ( toDelete->type() == "Todo" ) 933 if ( toDelete->type() == "Todo" )
934 pref = "t"; 934 pref = "t";
935 des += pref+ id + ","; 935 des += pref+ id + ",";
936 eve->setReadOnly( false ); 936 eve->setReadOnly( false );
937 eve->setDescription( des ); 937 eve->setDescription( des );
938 //qDebug("setdes %s ", des.latin1()); 938 //qDebug("setdes %s ", des.latin1());
939 eve->setReadOnly( true ); 939 eve->setReadOnly( true );
940 } 940 }
941 eve = lastSync.next(); 941 eve = lastSync.next();
942 } 942 }
943 943
944} 944}
945void CalendarView::checkExternalId( Incidence * inc ) 945void CalendarView::checkExternalId( Incidence * inc )
946{ 946{
947 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; 947 QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
948 checkExternSyncEvent( lastSync, inc ); 948 checkExternSyncEvent( lastSync, inc );
949 949
950} 950}
951bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) 951bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
952{ 952{
953 bool syncOK = true; 953 bool syncOK = true;
954 int addedEvent = 0; 954 int addedEvent = 0;
955 int addedEventR = 0; 955 int addedEventR = 0;
956 int deletedEventR = 0; 956 int deletedEventR = 0;
957 int deletedEventL = 0; 957 int deletedEventL = 0;
958 int changedLocal = 0; 958 int changedLocal = 0;
959 int changedRemote = 0; 959 int changedRemote = 0;
960 int filteredIN = 0; 960 int filteredIN = 0;
961 int filteredOUT = 0; 961 int filteredOUT = 0;
962 //QPtrList<Event> el = local->rawEvents(); 962 //QPtrList<Event> el = local->rawEvents();
963 Event* eventR; 963 Event* eventR;
964 QString uid; 964 QString uid;
965 int take; 965 int take;
966 Event* eventL; 966 Event* eventL;
967 Event* eventRSync; 967 Event* eventRSync;
968 Event* eventLSync; 968 Event* eventLSync;
969 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); 969 QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
970 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); 970 QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
971 bool fullDateRange = false; 971 bool fullDateRange = false;
972 local->resetTempSyncStat(); 972 local->resetTempSyncStat();
973 mLastCalendarSync = QDateTime::currentDateTime(); 973 mLastCalendarSync = QDateTime::currentDateTime();
974 if ( mSyncManager->syncWithDesktop() ) { 974 if ( mSyncManager->syncWithDesktop() ) {
975 remote->resetPilotStat(1); 975 remote->resetPilotStat(1);
976 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 976 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
977 mLastCalendarSync = KSyncManager::mRequestedSyncEvent; 977 mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
978 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); 978 qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
979 } else { 979 } else {
980 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 980 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
981 } 981 }
982 } 982 }
983 QDateTime modifiedCalendar = mLastCalendarSync; 983 QDateTime modifiedCalendar = mLastCalendarSync;
984 eventLSync = getLastSyncEvent(); 984 eventLSync = getLastSyncEvent();
985 eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); 985 eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
986 if ( eventR ) { 986 if ( eventR ) {
987 eventRSync = (Event*) eventR->clone(); 987 eventRSync = (Event*) eventR->clone();
988 remote->deleteEvent(eventR ); 988 remote->deleteEvent(eventR );
989 989
990 } else { 990 } else {
991 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { 991 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
992 eventRSync = (Event*)eventLSync->clone(); 992 eventRSync = (Event*)eventLSync->clone();
993 } else { 993 } else {
994 fullDateRange = true; 994 fullDateRange = true;
995 eventRSync = new Event(); 995 eventRSync = new Event();
996 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); 996 eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
997 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); 997 eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
998 eventRSync->setDtStart( mLastCalendarSync ); 998 eventRSync->setDtStart( mLastCalendarSync );
999 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 999 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
1000 eventRSync->setCategories( i18n("SyncEvent") ); 1000 eventRSync->setCategories( i18n("SyncEvent") );
1001 } 1001 }
1002 } 1002 }
1003 if ( eventLSync->dtStart() == mLastCalendarSync ) 1003 if ( eventLSync->dtStart() == mLastCalendarSync )
1004 fullDateRange = true; 1004 fullDateRange = true;
1005 1005
1006 if ( ! fullDateRange ) { 1006 if ( ! fullDateRange ) {
1007 if ( eventLSync->dtStart() != eventRSync->dtStart() ) { 1007 if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
1008 1008
1009 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); 1009 // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
1010 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); 1010 //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
1011 fullDateRange = true; 1011 fullDateRange = true;
1012 } 1012 }
1013 } 1013 }
1014 if ( mSyncManager->syncWithDesktop() ) { 1014 if ( mSyncManager->syncWithDesktop() ) {
1015 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); 1015 fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
1016 } 1016 }
1017 if ( fullDateRange ) 1017 if ( fullDateRange )
1018 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 1018 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
1019 else 1019 else
1020 mLastCalendarSync = eventLSync->dtStart(); 1020 mLastCalendarSync = eventLSync->dtStart();
1021 // for resyncing if own file has changed 1021 // for resyncing if own file has changed
1022 if ( mCurrentSyncDevice == "deleteaftersync" ) { 1022 if ( mCurrentSyncDevice == "deleteaftersync" ) {
1023 mLastCalendarSync = loadedFileVersion; 1023 mLastCalendarSync = loadedFileVersion;
1024 //qDebug("setting mLastCalendarSync "); 1024 //qDebug("setting mLastCalendarSync ");
1025 } 1025 }
1026 //qDebug("*************************** "); 1026 //qDebug("*************************** ");
1027 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); 1027 qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
1028 QPtrList<Incidence> er = remote->rawIncidences(); 1028 QPtrList<Incidence> er = remote->rawIncidences();
1029 Incidence* inR = er.first(); 1029 Incidence* inR = er.first();
1030 Incidence* inL; 1030 Incidence* inL;
1031 QProgressBar bar( er.count(),0 ); 1031 QProgressBar bar( er.count(),0 );
1032 bar.setCaption (i18n("Syncing - close to abort!") ); 1032 bar.setCaption (i18n("Syncing - close to abort!") );
1033 1033
1034 // ************** setting up filter ************* 1034 // ************** setting up filter *************
1035 CalFilter *filterIN = 0; 1035 CalFilter *filterIN = 0;
1036 CalFilter *filterOUT = 0; 1036 CalFilter *filterOUT = 0;
1037 CalFilter *filter = mFilters.first(); 1037 CalFilter *filter = mFilters.first();
1038 while(filter) { 1038 while(filter) {
1039 if ( filter->name() == mSyncManager->mFilterInCal ) 1039 if ( filter->name() == mSyncManager->mFilterInCal )
1040 filterIN = filter; 1040 filterIN = filter;
1041 if ( filter->name() == mSyncManager->mFilterOutCal ) 1041 if ( filter->name() == mSyncManager->mFilterOutCal )
1042 filterOUT = filter; 1042 filterOUT = filter;
1043 filter = mFilters.next(); 1043 filter = mFilters.next();
1044 } 1044 }
1045 int w = 300; 1045 int w = 300;
1046 if ( QApplication::desktop()->width() < 320 ) 1046 if ( QApplication::desktop()->width() < 320 )
1047 w = 220; 1047 w = 220;
1048 int h = bar.sizeHint().height() ; 1048 int h = bar.sizeHint().height() ;
1049 int dw = QApplication::desktop()->width(); 1049 int dw = QApplication::desktop()->width();
1050 int dh = QApplication::desktop()->height(); 1050 int dh = QApplication::desktop()->height();
1051 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1051 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1052 bar.show(); 1052 bar.show();
1053 int modulo = (er.count()/10)+1; 1053 int modulo = (er.count()/10)+1;
1054 int incCounter = 0; 1054 int incCounter = 0;
1055 while ( inR ) { 1055 while ( inR ) {
1056 if ( ! bar.isVisible() ) 1056 if ( ! bar.isVisible() )
1057 return false; 1057 return false;
1058 if ( incCounter % modulo == 0 ) 1058 if ( incCounter % modulo == 0 )
1059 bar.setProgress( incCounter ); 1059 bar.setProgress( incCounter );
1060 ++incCounter; 1060 ++incCounter;
1061 uid = inR->uid(); 1061 uid = inR->uid();
1062 bool skipIncidence = false; 1062 bool skipIncidence = false;
1063 if ( uid.left(15) == QString("last-syncEvent-") ) 1063 if ( uid.left(15) == QString("last-syncEvent-") )
1064 skipIncidence = true; 1064 skipIncidence = true;
1065 QString idS; 1065 QString idS;
1066 qApp->processEvents(); 1066 qApp->processEvents();
1067 if ( !skipIncidence ) { 1067 if ( !skipIncidence ) {
1068 inL = local->incidence( uid ); 1068 inL = local->incidence( uid );
1069 if ( inL ) { // maybe conflict - same uid in both calendars 1069 if ( inL ) { // maybe conflict - same uid in both calendars
1070 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1070 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1071 //qDebug("take %d %s ", take, inL->summary().latin1()); 1071 //qDebug("take %d %s ", take, inL->summary().latin1());
1072 if ( take == 3 ) 1072 if ( take == 3 )
1073 return false; 1073 return false;
1074 if ( take == 1 ) {// take local ********************** 1074 if ( take == 1 ) {// take local **********************
1075 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1075 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1076 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1076 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1077 else 1077 else
1078 idS = inR->IDStr(); 1078 idS = inR->IDStr();
1079 remote->deleteIncidence( inR ); 1079 remote->deleteIncidence( inR );
1080 inR = inL->clone(); 1080 inR = inL->clone();
1081 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1081 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1082 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1082 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1083 inR->setIDStr( idS ); 1083 inR->setIDStr( idS );
1084 remote->addIncidence( inR ); 1084 remote->addIncidence( inR );
1085 if ( mSyncManager->syncWithDesktop() ) 1085 if ( mSyncManager->syncWithDesktop() )
1086 inR->setPilotId( 2 ); 1086 inR->setPilotId( 2 );
1087 ++changedRemote; 1087 ++changedRemote;
1088 } else {// take remote ********************** 1088 } else {// take remote **********************
1089 idS = inL->IDStr(); 1089 idS = inL->IDStr();
1090 int pid = inL->pilotId(); 1090 int pid = inL->pilotId();
1091 local->deleteIncidence( inL ); 1091 local->deleteIncidence( inL );
1092 inL = inR->clone(); 1092 inL = inR->clone();
1093 if ( mSyncManager->syncWithDesktop() ) 1093 if ( mSyncManager->syncWithDesktop() )
1094 inL->setPilotId( pid ); 1094 inL->setPilotId( pid );
1095 inL->setIDStr( idS ); 1095 inL->setIDStr( idS );
1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1096 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1097 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1097 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1098 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1098 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1099 } 1099 }
1100 local->addIncidence( inL ); 1100 local->addIncidence( inL );
1101 ++changedLocal; 1101 ++changedLocal;
1102 } 1102 }
1103 } 1103 }
1104 } else { // no conflict ********** add or delete remote 1104 } else { // no conflict ********** add or delete remote
1105 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1105 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1106 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1106 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1107 QString des = eventLSync->description(); 1107 QString des = eventLSync->description();
1108 QString pref = "e"; 1108 QString pref = "e";
1109 if ( inR->type() == "Todo" ) 1109 if ( inR->type() == "Todo" )
1110 pref = "t"; 1110 pref = "t";
1111 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1111 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1112 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1112 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1113 //remote->deleteIncidence( inR ); 1113 //remote->deleteIncidence( inR );
1114 ++deletedEventR; 1114 ++deletedEventR;
1115 } else { 1115 } else {
1116 inR->setLastModified( modifiedCalendar ); 1116 inR->setLastModified( modifiedCalendar );
1117 inL = inR->clone(); 1117 inL = inR->clone();
1118 inL->setIDStr( ":" ); 1118 inL->setIDStr( ":" );
1119 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1119 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1120 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1120 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1121 local->addIncidence( inL ); 1121 local->addIncidence( inL );
1122 ++addedEvent; 1122 ++addedEvent;
1123 1123
1124 } 1124 }
1125 } else { 1125 } else {
1126 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1126 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1127 inR->setLastModified( modifiedCalendar ); 1127 inR->setLastModified( modifiedCalendar );
1128 inL = inR->clone(); 1128 inL = inR->clone();
1129 inL->setIDStr( ":" ); 1129 inL->setIDStr( ":" );
1130 local->addIncidence( inL ); 1130 local->addIncidence( inL );
1131 ++addedEvent; 1131 ++addedEvent;
1132 1132
1133 } else { 1133 } else {
1134 checkExternSyncEvent(eventRSyncSharp, inR); 1134 checkExternSyncEvent(eventRSyncSharp, inR);
1135 remote->deleteIncidence( inR ); 1135 remote->deleteIncidence( inR );
1136 ++deletedEventR; 1136 ++deletedEventR;
1137 } 1137 }
1138 } 1138 }
1139 } else { 1139 } else {
1140 ++filteredIN; 1140 ++filteredIN;
1141 } 1141 }
1142 } 1142 }
1143 } 1143 }
1144 inR = er.next(); 1144 inR = er.next();
1145 } 1145 }
1146 QPtrList<Incidence> el = local->rawIncidences(); 1146 QPtrList<Incidence> el = local->rawIncidences();
1147 inL = el.first(); 1147 inL = el.first();
1148 modulo = (el.count()/10)+1; 1148 modulo = (el.count()/10)+1;
1149 bar.setCaption (i18n("Add / remove events") ); 1149 bar.setCaption (i18n("Add / remove events") );
1150 bar.setTotalSteps ( el.count() ) ; 1150 bar.setTotalSteps ( el.count() ) ;
1151 bar.show(); 1151 bar.show();
1152 incCounter = 0; 1152 incCounter = 0;
1153 1153
1154 while ( inL ) { 1154 while ( inL ) {
1155 1155
1156 qApp->processEvents(); 1156 qApp->processEvents();
1157 if ( ! bar.isVisible() ) 1157 if ( ! bar.isVisible() )
1158 return false; 1158 return false;
1159 if ( incCounter % modulo == 0 ) 1159 if ( incCounter % modulo == 0 )
1160 bar.setProgress( incCounter ); 1160 bar.setProgress( incCounter );
1161 ++incCounter; 1161 ++incCounter;
1162 uid = inL->uid(); 1162 uid = inL->uid();
1163 bool skipIncidence = false; 1163 bool skipIncidence = false;
1164 if ( uid.left(15) == QString("last-syncEvent-") ) 1164 if ( uid.left(15) == QString("last-syncEvent-") )
1165 skipIncidence = true; 1165 skipIncidence = true;
1166 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1166 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1167 skipIncidence = true; 1167 skipIncidence = true;
1168 if ( !skipIncidence ) { 1168 if ( !skipIncidence ) {
1169 inR = remote->incidence( uid ); 1169 inR = remote->incidence( uid );
1170 if ( ! inR ) { 1170 if ( ! inR ) {
1171 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1171 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1172 // no conflict ********** add or delete local 1172 // no conflict ********** add or delete local
1173 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1173 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1174 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1174 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1175 checkExternSyncEvent(eventLSyncSharp, inL); 1175 checkExternSyncEvent(eventLSyncSharp, inL);
1176 local->deleteIncidence( inL ); 1176 local->deleteIncidence( inL );
1177 ++deletedEventL; 1177 ++deletedEventL;
1178 } else { 1178 } else {
1179 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1179 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1180 inL->removeID(mCurrentSyncDevice ); 1180 inL->removeID(mCurrentSyncDevice );
1181 ++addedEventR; 1181 ++addedEventR;
1182 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1182 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1183 inL->setLastModified( modifiedCalendar ); 1183 inL->setLastModified( modifiedCalendar );
1184 inR = inL->clone(); 1184 inR = inL->clone();
1185 inR->setIDStr( ":" ); 1185 inR->setIDStr( ":" );
1186 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1186 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1187 remote->addIncidence( inR ); 1187 remote->addIncidence( inR );
1188 } 1188 }
1189 } 1189 }
1190 } else { 1190 } else {
1191 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1191 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1192 checkExternSyncEvent(eventLSyncSharp, inL); 1192 checkExternSyncEvent(eventLSyncSharp, inL);
1193 local->deleteIncidence( inL ); 1193 local->deleteIncidence( inL );
1194 ++deletedEventL; 1194 ++deletedEventL;
1195 } else { 1195 } else {
1196 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1196 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1197 ++addedEventR; 1197 ++addedEventR;
1198 inL->setLastModified( modifiedCalendar ); 1198 inL->setLastModified( modifiedCalendar );
1199 inR = inL->clone(); 1199 inR = inL->clone();
1200 inR->setIDStr( ":" ); 1200 inR->setIDStr( ":" );
1201 remote->addIncidence( inR ); 1201 remote->addIncidence( inR );
1202 } 1202 }
1203 } 1203 }
1204 } 1204 }
1205 } else { 1205 } else {
1206 ++filteredOUT; 1206 ++filteredOUT;
1207 } 1207 }
1208 } 1208 }
1209 } 1209 }
1210 inL = el.next(); 1210 inL = el.next();
1211 } 1211 }
1212 int delFut = 0; 1212 int delFut = 0;
1213 int remRem = 0; 1213 int remRem = 0;
1214 if ( mSyncManager->mWriteBackInFuture ) { 1214 if ( mSyncManager->mWriteBackInFuture ) {
1215 er = remote->rawIncidences(); 1215 er = remote->rawIncidences();
1216 remRem = er.count(); 1216 remRem = er.count();
1217 inR = er.first(); 1217 inR = er.first();
1218 QDateTime dt; 1218 QDateTime dt;
1219 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1219 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1220 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1220 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1221 while ( inR ) { 1221 while ( inR ) {
1222 if ( inR->type() == "Todo" ) { 1222 if ( inR->type() == "Todo" ) {
1223 Todo * t = (Todo*)inR; 1223 Todo * t = (Todo*)inR;
1224 if ( t->hasDueDate() ) 1224 if ( t->hasDueDate() )
1225 dt = t->dtDue(); 1225 dt = t->dtDue();
1226 else 1226 else
1227 dt = cur.addSecs( 62 ); 1227 dt = cur.addSecs( 62 );
1228 } 1228 }
1229 else if (inR->type() == "Event" ) { 1229 else if (inR->type() == "Event" ) {
1230 bool ok; 1230 bool ok;
1231 dt = inR->getNextOccurence( cur, &ok ); 1231 dt = inR->getNextOccurence( cur, &ok );
1232 if ( !ok ) 1232 if ( !ok )
1233 dt = cur.addSecs( -62 ); 1233 dt = cur.addSecs( -62 );
1234 } 1234 }
1235 else 1235 else
1236 dt = inR->dtStart(); 1236 dt = inR->dtStart();
1237 if ( dt < cur || dt > end ) { 1237 if ( dt < cur || dt > end ) {
1238 remote->deleteIncidence( inR ); 1238 remote->deleteIncidence( inR );
1239 ++delFut; 1239 ++delFut;
1240 } 1240 }
1241 inR = er.next(); 1241 inR = er.next();
1242 } 1242 }
1243 } 1243 }
1244 bar.hide(); 1244 bar.hide();
1245 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1245 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1246 eventLSync->setReadOnly( false ); 1246 eventLSync->setReadOnly( false );
1247 eventLSync->setDtStart( mLastCalendarSync ); 1247 eventLSync->setDtStart( mLastCalendarSync );
1248 eventRSync->setDtStart( mLastCalendarSync ); 1248 eventRSync->setDtStart( mLastCalendarSync );
1249 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1249 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1250 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1250 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1251 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1251 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1252 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1252 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1253 eventLSync->setReadOnly( true ); 1253 eventLSync->setReadOnly( true );
1254 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1254 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1255 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1255 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1256 remote->addEvent( eventRSync ); 1256 remote->addEvent( eventRSync );
1257 else 1257 else
1258 delete eventRSync; 1258 delete eventRSync;
1259 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1259 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1260 QString mes; 1260 QString mes;
1261 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 ); 1261 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 );
1262 QString delmess; 1262 QString delmess;
1263 if ( delFut ) { 1263 if ( delFut ) {
1264 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); 1264 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);
1265 mes += delmess; 1265 mes += delmess;
1266 } 1266 }
1267 mes = i18n("Local calendar changed!\n") +mes; 1267 mes = i18n("Local calendar changed!\n") +mes;
1268 mCalendar->checkAlarmForIncidence( 0, true ); 1268 mCalendar->checkAlarmForIncidence( 0, true );
1269 qDebug( mes ); 1269 qDebug( mes );
1270 if ( mSyncManager->mShowSyncSummary ) { 1270 if ( mSyncManager->mShowSyncSummary ) {
1271 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1271 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1272 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1272 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1273 qDebug("KO: WB cancelled "); 1273 qDebug("KO: WB cancelled ");
1274 mSyncManager->mWriteBackFile = false; 1274 mSyncManager->mWriteBackFile = false;
1275 return syncOK; 1275 return syncOK;
1276 } 1276 }
1277 } 1277 }
1278 return syncOK; 1278 return syncOK;
1279} 1279}
1280 1280
1281void CalendarView::setSyncDevice( QString s ) 1281void CalendarView::setSyncDevice( QString s )
1282{ 1282{
1283 mCurrentSyncDevice= s; 1283 mCurrentSyncDevice= s;
1284} 1284}
1285void CalendarView::setSyncName( QString s ) 1285void CalendarView::setSyncName( QString s )
1286{ 1286{
1287 mCurrentSyncName= s; 1287 mCurrentSyncName= s;
1288} 1288}
1289bool CalendarView::syncCalendar(QString filename, int mode) 1289bool CalendarView::syncCalendar(QString filename, int mode)
1290{ 1290{
1291 //qDebug("syncCalendar %s ", filename.latin1()); 1291 //qDebug("syncCalendar %s ", filename.latin1());
1292 mGlobalSyncMode = SYNC_MODE_NORMAL; 1292 mGlobalSyncMode = SYNC_MODE_NORMAL;
1293 CalendarLocal* calendar = new CalendarLocal(); 1293 CalendarLocal* calendar = new CalendarLocal();
1294 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1294 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1295 FileStorage* storage = new FileStorage( calendar ); 1295 FileStorage* storage = new FileStorage( calendar );
1296 bool syncOK = false; 1296 bool syncOK = false;
1297 storage->setFileName( filename ); 1297 storage->setFileName( filename );
1298 // qDebug("loading ... "); 1298 // qDebug("loading ... ");
1299 if ( storage->load() ) { 1299 if ( storage->load() ) {
1300 getEventViewerDialog()->setSyncMode( true ); 1300 getEventViewerDialog()->setSyncMode( true );
1301 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1301 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1302 getEventViewerDialog()->setSyncMode( false ); 1302 getEventViewerDialog()->setSyncMode( false );
1303 if ( syncOK ) { 1303 if ( syncOK ) {
1304 if ( mSyncManager->mWriteBackFile ) 1304 if ( mSyncManager->mWriteBackFile )
1305 { 1305 {
1306 storage->setSaveFormat( new ICalFormat() ); 1306 storage->setSaveFormat( new ICalFormat() );
1307 storage->save(); 1307 storage->save();
1308 } 1308 }
1309 } 1309 }
1310 setModified( true ); 1310 setModified( true );
1311 } 1311 }
1312 delete storage; 1312 delete storage;
1313 delete calendar; 1313 delete calendar;
1314 if ( syncOK ) 1314 if ( syncOK )
1315 updateView(); 1315 updateView();
1316 return syncOK; 1316 return syncOK;
1317} 1317}
1318 1318
1319void CalendarView::syncExternal( int mode ) 1319void CalendarView::syncExternal( int mode )
1320{ 1320{
1321 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1321 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1322 1322
1323 qApp->processEvents(); 1323 qApp->processEvents();
1324 CalendarLocal* calendar = new CalendarLocal(); 1324 CalendarLocal* calendar = new CalendarLocal();
1325 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1325 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1326 bool syncOK = false; 1326 bool syncOK = false;
1327 bool loadSuccess = false; 1327 bool loadSuccess = false;
1328 PhoneFormat* phoneFormat = 0; 1328 PhoneFormat* phoneFormat = 0;
1329 emit tempDisableBR(true); 1329 emit tempDisableBR(true);
1330#ifndef DESKTOP_VERSION 1330#ifndef DESKTOP_VERSION
1331 SharpFormat* sharpFormat = 0; 1331 SharpFormat* sharpFormat = 0;
1332 if ( mode == 0 ) { // sharp 1332 if ( mode == 0 ) { // sharp
1333 sharpFormat = new SharpFormat () ; 1333 sharpFormat = new SharpFormat () ;
1334 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1334 loadSuccess = sharpFormat->load( calendar, mCalendar );
1335 1335
1336 } else 1336 } else
1337#endif 1337#endif
1338 if ( mode == 1 ) { // phone 1338 if ( mode == 1 ) { // phone
1339 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1339 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1340 mSyncManager->mPhoneDevice, 1340 mSyncManager->mPhoneDevice,
1341 mSyncManager->mPhoneConnection, 1341 mSyncManager->mPhoneConnection,
1342 mSyncManager->mPhoneModel); 1342 mSyncManager->mPhoneModel);
1343 loadSuccess = phoneFormat->load( calendar,mCalendar); 1343 loadSuccess = phoneFormat->load( calendar,mCalendar);
1344 1344
1345 } else { 1345 } else {
1346 emit tempDisableBR(false); 1346 emit tempDisableBR(false);
1347 return; 1347 return;
1348 } 1348 }
1349 if ( loadSuccess ) { 1349 if ( loadSuccess ) {
1350 getEventViewerDialog()->setSyncMode( true ); 1350 getEventViewerDialog()->setSyncMode( true );
1351 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1351 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1352 getEventViewerDialog()->setSyncMode( false ); 1352 getEventViewerDialog()->setSyncMode( false );
1353 qApp->processEvents(); 1353 qApp->processEvents();
1354 if ( syncOK ) { 1354 if ( syncOK ) {
1355 if ( mSyncManager->mWriteBackFile ) 1355 if ( mSyncManager->mWriteBackFile )
1356 { 1356 {
1357 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1357 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1358 Incidence* inc = iL.first(); 1358 Incidence* inc = iL.first();
1359 if ( phoneFormat ) { 1359 if ( phoneFormat ) {
1360 while ( inc ) { 1360 while ( inc ) {
1361 inc->removeID(mCurrentSyncDevice); 1361 inc->removeID(mCurrentSyncDevice);
1362 inc = iL.next(); 1362 inc = iL.next();
1363 } 1363 }
1364 } 1364 }
1365#ifndef DESKTOP_VERSION 1365#ifndef DESKTOP_VERSION
1366 if ( sharpFormat ) 1366 if ( sharpFormat )
1367 sharpFormat->save(calendar); 1367 sharpFormat->save(calendar);
1368#endif 1368#endif
1369 if ( phoneFormat ) 1369 if ( phoneFormat )
1370 phoneFormat->save(calendar); 1370 phoneFormat->save(calendar);
1371 iL = calendar->rawIncidences(); 1371 iL = calendar->rawIncidences();
1372 inc = iL.first(); 1372 inc = iL.first();
1373 Incidence* loc; 1373 Incidence* loc;
1374 while ( inc ) { 1374 while ( inc ) {
1375 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1375 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1376 loc = mCalendar->incidence(inc->uid() ); 1376 loc = mCalendar->incidence(inc->uid() );
1377 if ( loc ) { 1377 if ( loc ) {
1378 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1378 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1379 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1379 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1380 } 1380 }
1381 } 1381 }
1382 inc = iL.next(); 1382 inc = iL.next();
1383 } 1383 }
1384 Incidence* lse = getLastSyncEvent(); 1384 Incidence* lse = getLastSyncEvent();
1385 if ( lse ) { 1385 if ( lse ) {
1386 lse->setReadOnly( false ); 1386 lse->setReadOnly( false );
1387 lse->setDescription( "" ); 1387 lse->setDescription( "" );
1388 lse->setReadOnly( true ); 1388 lse->setReadOnly( true );
1389 } 1389 }
1390 } 1390 }
1391 } else { 1391 } else {
1392 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1392 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1393 } 1393 }
1394 setModified( true ); 1394 setModified( true );
1395 } else { 1395 } else {
1396 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1396 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1397 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1397 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1398 question, i18n("Ok")) ; 1398 question, i18n("Ok")) ;
1399 1399
1400 } 1400 }
1401 delete calendar; 1401 delete calendar;
1402 updateView(); 1402 updateView();
1403 emit tempDisableBR(false); 1403 emit tempDisableBR(false);
1404 return ;//syncOK; 1404 return ;//syncOK;
1405 1405
1406} 1406}
1407 1407
1408bool CalendarView::importBday() 1408bool CalendarView::importBday()
1409{ 1409{
1410#ifndef KORG_NOKABC 1410#ifndef KORG_NOKABC
1411 1411
1412#ifdef DESKTOP_VERSION 1412#ifdef DESKTOP_VERSION
1413 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1413 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1414 KABC::AddressBook::Iterator it; 1414 KABC::AddressBook::Iterator it;
1415 int count = 0; 1415 int count = 0;
1416 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1416 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1417 ++count; 1417 ++count;
1418 } 1418 }
1419 QProgressBar bar(count,0 ); 1419 QProgressBar bar(count,0 );
1420 int w = 300; 1420 int w = 300;
1421 if ( QApplication::desktop()->width() < 320 ) 1421 if ( QApplication::desktop()->width() < 320 )
1422 w = 220; 1422 w = 220;
1423 int h = bar.sizeHint().height() ; 1423 int h = bar.sizeHint().height() ;
1424 int dw = QApplication::desktop()->width(); 1424 int dw = QApplication::desktop()->width();
1425 int dh = QApplication::desktop()->height(); 1425 int dh = QApplication::desktop()->height();
1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1426 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1427 bar.show(); 1427 bar.show();
1428 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1428 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1429 qApp->processEvents(); 1429 qApp->processEvents();
1430 count = 0; 1430 count = 0;
1431 int addCount = 0; 1431 int addCount = 0;
1432 KCal::Attendee* a = 0; 1432 KCal::Attendee* a = 0;
1433 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1433 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1434 if ( ! bar.isVisible() ) 1434 if ( ! bar.isVisible() )
1435 return false; 1435 return false;
1436 bar.setProgress( count++ ); 1436 bar.setProgress( count++ );
1437 qApp->processEvents(); 1437 qApp->processEvents();
1438 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1438 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1439 if ( (*it).birthday().date().isValid() ){ 1439 if ( (*it).birthday().date().isValid() ){
1440 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1440 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1441 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1441 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1442 ++addCount; 1442 ++addCount;
1443 } 1443 }
1444 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1444 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1445 if ( anni.isValid() ){ 1445 if ( anni.isValid() ){
1446 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1446 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1447 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1447 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1448 ++addCount; 1448 ++addCount;
1449 } 1449 }
1450 } 1450 }
1451 updateView(); 1451 updateView();
1452 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1452 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1453#else //DESKTOP_VERSION 1453#else //DESKTOP_VERSION
1454 1454
1455 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1455 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1456 // the result should now arrive through method insertBirthdays 1456 // the result should now arrive through method insertBirthdays
1457 1457
1458#endif //DESKTOP_VERSION 1458#endif //DESKTOP_VERSION
1459 1459
1460#endif //KORG_NOKABC 1460#endif //KORG_NOKABC
1461 1461
1462 1462
1463 return true; 1463 return true;
1464} 1464}
1465 1465
1466// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1466// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1467void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1467void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1468 const QStringList& anniversaryList, const QStringList& realNameList, 1468 const QStringList& anniversaryList, const QStringList& realNameList,
1469 const QStringList& emailList, const QStringList& assembledNameList, 1469 const QStringList& emailList, const QStringList& assembledNameList,
1470 const QStringList& uidList) 1470 const QStringList& uidList)
1471{ 1471{
1472 //qDebug("KO::CalendarView::insertBirthdays"); 1472 //qDebug("KO::CalendarView::insertBirthdays");
1473 if (uid == this->name()) 1473 if (uid == this->name())
1474 { 1474 {
1475 int count = birthdayList.count(); 1475 int count = birthdayList.count();
1476 int addCount = 0; 1476 int addCount = 0;
1477 KCal::Attendee* a = 0; 1477 KCal::Attendee* a = 0;
1478 1478
1479 //qDebug("CalView 1 %i", count); 1479 //qDebug("CalView 1 %i", count);
1480 1480
1481 QProgressBar bar(count,0 ); 1481 QProgressBar bar(count,0 );
1482 int w = 300; 1482 int w = 300;
1483 if ( QApplication::desktop()->width() < 320 ) 1483 if ( QApplication::desktop()->width() < 320 )
1484 w = 220; 1484 w = 220;
1485 int h = bar.sizeHint().height() ; 1485 int h = bar.sizeHint().height() ;
1486 int dw = QApplication::desktop()->width(); 1486 int dw = QApplication::desktop()->width();
1487 int dh = QApplication::desktop()->height(); 1487 int dh = QApplication::desktop()->height();
1488 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1488 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1489 bar.show(); 1489 bar.show();
1490 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1490 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1491 qApp->processEvents(); 1491 qApp->processEvents();
1492 1492
1493 QDate birthday; 1493 QDate birthday;
1494 QDate anniversary; 1494 QDate anniversary;
1495 QString realName; 1495 QString realName;
1496 QString email; 1496 QString email;
1497 QString assembledName; 1497 QString assembledName;
1498 QString uid; 1498 QString uid;
1499 bool ok = true; 1499 bool ok = true;
1500 for ( int i = 0; i < count; i++) 1500 for ( int i = 0; i < count; i++)
1501 { 1501 {
1502 if ( ! bar.isVisible() ) 1502 if ( ! bar.isVisible() )
1503 return; 1503 return;
1504 bar.setProgress( i ); 1504 bar.setProgress( i );
1505 qApp->processEvents(); 1505 qApp->processEvents();
1506 1506
1507 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1507 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1508 if (!ok) { 1508 if (!ok) {
1509 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1509 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1510 } 1510 }
1511 1511
1512 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1512 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1513 if (!ok) { 1513 if (!ok) {
1514 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1514 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1515 } 1515 }
1516 realName = realNameList[i]; 1516 realName = realNameList[i];
1517 email = emailList[i]; 1517 email = emailList[i];
1518 assembledName = assembledNameList[i]; 1518 assembledName = assembledNameList[i];
1519 uid = uidList[i]; 1519 uid = uidList[i];
1520 //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() ); 1520 //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() );
1521 1521
1522 if ( birthday.isValid() ){ 1522 if ( birthday.isValid() ){
1523 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1523 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1524 KCal::Attendee::ReqParticipant,uid) ; 1524 KCal::Attendee::ReqParticipant,uid) ;
1525 if ( addAnniversary( birthday, assembledName, a, true ) ) 1525 if ( addAnniversary( birthday, assembledName, a, true ) )
1526 ++addCount; 1526 ++addCount;
1527 } 1527 }
1528 1528
1529 if ( anniversary.isValid() ){ 1529 if ( anniversary.isValid() ){
1530 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1530 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1531 KCal::Attendee::ReqParticipant,uid) ; 1531 KCal::Attendee::ReqParticipant,uid) ;
1532 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1532 if ( addAnniversary( anniversary, assembledName, a, false ) )
1533 ++addCount; 1533 ++addCount;
1534 } 1534 }
1535 } 1535 }
1536 1536
1537 updateView(); 1537 updateView();
1538 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1538 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1539 1539
1540 } 1540 }
1541 1541
1542} 1542}
1543 1543
1544 1544
1545 1545
1546bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1546bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1547{ 1547{
1548 //qDebug("addAnni "); 1548 //qDebug("addAnni ");
1549 Event * ev = new Event(); 1549 Event * ev = new Event();
1550 ev->setOrganizer(KOPrefs::instance()->email()); 1550 ev->setOrganizer(KOPrefs::instance()->email());
1551 if ( a ) { 1551 if ( a ) {
1552 ev->addAttendee( a ); 1552 ev->addAttendee( a );
1553 } 1553 }
1554 QString kind; 1554 QString kind;
1555 if ( birthday ) { 1555 if ( birthday ) {
1556 kind = i18n( "Birthday" ); 1556 kind = i18n( "Birthday" );
1557 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1557 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1558 } 1558 }
1559 else { 1559 else {
1560 kind = i18n( "Anniversary" ); 1560 kind = i18n( "Anniversary" );
1561 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1561 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1562 } 1562 }
1563 ev->setCategories( kind ); 1563 ev->setCategories( kind );
1564 ev->setDtStart( QDateTime(date) ); 1564 ev->setDtStart( QDateTime(date) );
1565 ev->setDtEnd( QDateTime(date) ); 1565 ev->setDtEnd( QDateTime(date) );
1566 ev->setFloats( true ); 1566 ev->setFloats( true );
1567 Recurrence * rec = ev->recurrence(); 1567 Recurrence * rec = ev->recurrence();
1568 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1568 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1569 rec->addYearlyNum( date.month() ); 1569 rec->addYearlyNum( date.month() );
1570 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1570 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1571 delete ev; 1571 delete ev;
1572 return false; 1572 return false;
1573 } 1573 }
1574 return true; 1574 return true;
1575 1575
1576} 1576}
1577bool CalendarView::importQtopia( const QString &categories, 1577bool CalendarView::importQtopia( const QString &categories,
1578 const QString &datebook, 1578 const QString &datebook,
1579 const QString &todolist ) 1579 const QString &todolist )
1580{ 1580{
1581 1581
1582 QtopiaFormat qtopiaFormat; 1582 QtopiaFormat qtopiaFormat;
1583 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1583 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1584 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1584 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1585 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1585 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1586 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1586 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1587 1587
1588 updateView(); 1588 updateView();
1589 return true; 1589 return true;
1590 1590
1591#if 0 1591#if 0
1592 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1592 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1593 mCurrentSyncDevice = "qtopia-XML"; 1593 mCurrentSyncDevice = "qtopia-XML";
1594 if ( mSyncManager->mAskForPreferences ) 1594 if ( mSyncManager->mAskForPreferences )
1595 edit_sync_options(); 1595 edit_sync_options();
1596 qApp->processEvents(); 1596 qApp->processEvents();
1597 CalendarLocal* calendar = new CalendarLocal(); 1597 CalendarLocal* calendar = new CalendarLocal();
1598 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1598 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1599 bool syncOK = false; 1599 bool syncOK = false;
1600 QtopiaFormat qtopiaFormat; 1600 QtopiaFormat qtopiaFormat;
1601 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1601 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1602 bool loadOk = true; 1602 bool loadOk = true;
1603 if ( !categories.isEmpty() ) 1603 if ( !categories.isEmpty() )
1604 loadOk = qtopiaFormat.load( calendar, categories ); 1604 loadOk = qtopiaFormat.load( calendar, categories );
1605 if ( loadOk && !datebook.isEmpty() ) 1605 if ( loadOk && !datebook.isEmpty() )
1606 loadOk = qtopiaFormat.load( calendar, datebook ); 1606 loadOk = qtopiaFormat.load( calendar, datebook );
1607 if ( loadOk && !todolist.isEmpty() ) 1607 if ( loadOk && !todolist.isEmpty() )
1608 loadOk = qtopiaFormat.load( calendar, todolist ); 1608 loadOk = qtopiaFormat.load( calendar, todolist );
1609 1609
1610 if ( loadOk ) { 1610 if ( loadOk ) {
1611 getEventViewerDialog()->setSyncMode( true ); 1611 getEventViewerDialog()->setSyncMode( true );
1612 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1612 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1613 getEventViewerDialog()->setSyncMode( false ); 1613 getEventViewerDialog()->setSyncMode( false );
1614 qApp->processEvents(); 1614 qApp->processEvents();
1615 if ( syncOK ) { 1615 if ( syncOK ) {
1616 if ( mSyncManager->mWriteBackFile ) 1616 if ( mSyncManager->mWriteBackFile )
1617 { 1617 {
1618 // write back XML file 1618 // write back XML file
1619 1619
1620 } 1620 }
1621 setModified( true ); 1621 setModified( true );
1622 } 1622 }
1623 } else { 1623 } else {
1624 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1624 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1625 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1625 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1626 question, i18n("Ok")) ; 1626 question, i18n("Ok")) ;
1627 } 1627 }
1628 delete calendar; 1628 delete calendar;
1629 updateView(); 1629 updateView();
1630 return syncOK; 1630 return syncOK;
1631 1631
1632 1632
1633#endif 1633#endif
1634 1634
1635} 1635}
1636 1636
1637void CalendarView::setSyncEventsReadOnly() 1637void CalendarView::setSyncEventsReadOnly()
1638{ 1638{
1639 Event * ev; 1639 Event * ev;
1640 QPtrList<Event> eL = mCalendar->rawEvents(); 1640 QPtrList<Event> eL = mCalendar->rawEvents();
1641 ev = eL.first(); 1641 ev = eL.first();
1642 while ( ev ) { 1642 while ( ev ) {
1643 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1643 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1644 ev->setReadOnly( true ); 1644 ev->setReadOnly( true );
1645 ev = eL.next(); 1645 ev = eL.next();
1646 } 1646 }
1647} 1647}
1648bool CalendarView::openCalendar(QString filename, bool merge) 1648bool CalendarView::openCalendar(QString filename, bool merge)
1649{ 1649{
1650 1650
1651 if (filename.isEmpty()) { 1651 if (filename.isEmpty()) {
1652 return false; 1652 return false;
1653 } 1653 }
1654 1654
1655 if (!QFile::exists(filename)) { 1655 if (!QFile::exists(filename)) {
1656 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1656 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1657 return false; 1657 return false;
1658 } 1658 }
1659 1659
1660 globalFlagBlockAgenda = 1; 1660 globalFlagBlockAgenda = 1;
1661 if (!merge) mCalendar->close(); 1661 if (!merge) mCalendar->close();
1662 1662
1663 mStorage->setFileName( filename ); 1663 mStorage->setFileName( filename );
1664 1664
1665 if ( mStorage->load() ) { 1665 if ( mStorage->load() ) {
1666 if ( merge ) ;//setModified( true ); 1666 if ( merge ) ;//setModified( true );
1667 else { 1667 else {
1668 //setModified( true ); 1668 //setModified( true );
1669 mViewManager->setDocumentId( filename ); 1669 mViewManager->setDocumentId( filename );
1670 mDialogManager->setDocumentId( filename ); 1670 mDialogManager->setDocumentId( filename );
1671 mTodoList->setDocumentId( filename ); 1671 mTodoList->setDocumentId( filename );
1672 } 1672 }
1673 globalFlagBlockAgenda = 2; 1673 globalFlagBlockAgenda = 2;
1674 // if ( getLastSyncEvent() ) 1674 // if ( getLastSyncEvent() )
1675 // getLastSyncEvent()->setReadOnly( true ); 1675 // getLastSyncEvent()->setReadOnly( true );
1676 mCalendar->reInitAlarmSettings(); 1676 mCalendar->reInitAlarmSettings();
1677 setSyncEventsReadOnly(); 1677 setSyncEventsReadOnly();
1678 updateUnmanagedViews(); 1678 updateUnmanagedViews();
1679 updateView(); 1679 updateView();
1680 if ( filename != MainWindow::defaultFileName() ) { 1680 if ( filename != MainWindow::defaultFileName() ) {
1681 saveCalendar( MainWindow::defaultFileName() ); 1681 saveCalendar( MainWindow::defaultFileName() );
1682 } else { 1682 } else {
1683 QFileInfo finf ( MainWindow::defaultFileName()); 1683 QFileInfo finf ( MainWindow::defaultFileName());
1684 if ( finf.exists() ) { 1684 if ( finf.exists() ) {
1685 setLoadedFileVersion( finf.lastModified () ); 1685 setLoadedFileVersion( finf.lastModified () );
1686 } 1686 }
1687 } 1687 }
1688 return true; 1688 return true;
1689 } else { 1689 } else {
1690 // while failing to load, the calendar object could 1690 // while failing to load, the calendar object could
1691 // have become partially populated. Clear it out. 1691 // have become partially populated. Clear it out.
1692 if ( !merge ) { 1692 if ( !merge ) {
1693 mCalendar->close(); 1693 mCalendar->close();
1694 mViewManager->setDocumentId( filename ); 1694 mViewManager->setDocumentId( filename );
1695 mDialogManager->setDocumentId( filename ); 1695 mDialogManager->setDocumentId( filename );
1696 mTodoList->setDocumentId( filename ); 1696 mTodoList->setDocumentId( filename );
1697 } 1697 }
1698 1698
1699 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1699 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1700 1700
1701 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1701 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1702 globalFlagBlockAgenda = 2; 1702 globalFlagBlockAgenda = 2;
1703 mCalendar->reInitAlarmSettings(); 1703 mCalendar->reInitAlarmSettings();
1704 setSyncEventsReadOnly(); 1704 setSyncEventsReadOnly();
1705 updateUnmanagedViews(); 1705 updateUnmanagedViews();
1706 updateView(); 1706 updateView();
1707 } 1707 }
1708 return false; 1708 return false;
1709} 1709}
1710void CalendarView::showOpenError() 1710void CalendarView::showOpenError()
1711{ 1711{
1712 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1712 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1713} 1713}
1714void CalendarView::setLoadedFileVersion(QDateTime dt) 1714void CalendarView::setLoadedFileVersion(QDateTime dt)
1715{ 1715{
1716 loadedFileVersion = dt; 1716 loadedFileVersion = dt;
1717} 1717}
1718bool CalendarView::checkFileChanged(QString fn) 1718bool CalendarView::checkFileChanged(QString fn)
1719{ 1719{
1720 QFileInfo finf ( fn ); 1720 QFileInfo finf ( fn );
1721 if ( !finf.exists() ) 1721 if ( !finf.exists() )
1722 return true; 1722 return true;
1723 QDateTime dt = finf.lastModified (); 1723 QDateTime dt = finf.lastModified ();
1724 if ( dt <= loadedFileVersion ) 1724 if ( dt <= loadedFileVersion )
1725 return false; 1725 return false;
1726 return true; 1726 return true;
1727 1727
1728} 1728}
1729void CalendarView::watchSavedFile() 1729void CalendarView::watchSavedFile()
1730{ 1730{
1731 QFileInfo finf ( MainWindow::defaultFileName()); 1731 QFileInfo finf ( MainWindow::defaultFileName());
1732 if ( !finf.exists() ) 1732 if ( !finf.exists() )
1733 return; 1733 return;
1734 QDateTime dt = finf.lastModified (); 1734 QDateTime dt = finf.lastModified ();
1735 if ( dt < loadedFileVersion ) { 1735 if ( dt < loadedFileVersion ) {
1736 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1736 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1737 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1737 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1738 return; 1738 return;
1739 } 1739 }
1740 loadedFileVersion = dt; 1740 loadedFileVersion = dt;
1741} 1741}
1742 1742
1743bool CalendarView::checkFileVersion(QString fn) 1743bool CalendarView::checkFileVersion(QString fn)
1744{ 1744{
1745 QFileInfo finf ( fn ); 1745 QFileInfo finf ( fn );
1746 if ( !finf.exists() ) 1746 if ( !finf.exists() )
1747 return true; 1747 return true;
1748 QDateTime dt = finf.lastModified (); 1748 QDateTime dt = finf.lastModified ();
1749 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1749 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1750 //qDebug("file on disk version %s",dt.toString().latin1()); 1750 //qDebug("file on disk version %s",dt.toString().latin1());
1751 if ( dt <= loadedFileVersion ) 1751 if ( dt <= loadedFileVersion )
1752 return true; 1752 return true;
1753 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1753 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1754 i18n("KO/Pi Warning"),i18n("Overwrite"), 1754 i18n("KO/Pi Warning"),i18n("Overwrite"),
1755 i18n("Sync+save")); 1755 i18n("Sync+save"));
1756 1756
1757 if ( km == KMessageBox::Cancel ) 1757 if ( km == KMessageBox::Cancel )
1758 return false; 1758 return false;
1759 if ( km == KMessageBox::Yes ) 1759 if ( km == KMessageBox::Yes )
1760 return true; 1760 return true;
1761 1761
1762 setSyncDevice("deleteaftersync" ); 1762 setSyncDevice("deleteaftersync" );
1763 mSyncManager->mAskForPreferences = true; 1763 mSyncManager->mAskForPreferences = true;
1764 mSyncManager->mSyncAlgoPrefs = 3; 1764 mSyncManager->mSyncAlgoPrefs = 3;
1765 mSyncManager->mWriteBackFile = false; 1765 mSyncManager->mWriteBackFile = false;
1766 mSyncManager->mWriteBackExistingOnly = false; 1766 mSyncManager->mWriteBackExistingOnly = false;
1767 mSyncManager->mShowSyncSummary = false; 1767 mSyncManager->mShowSyncSummary = false;
1768 syncCalendar( fn, 3 ); 1768 syncCalendar( fn, 3 );
1769 Event * e = getLastSyncEvent(); 1769 Event * e = getLastSyncEvent();
1770 mCalendar->deleteEvent ( e ); 1770 mCalendar->deleteEvent ( e );
1771 updateView(); 1771 updateView();
1772 return true; 1772 return true;
1773} 1773}
1774 1774
1775bool CalendarView::saveCalendar( QString filename ) 1775bool CalendarView::saveCalendar( QString filename )
1776{ 1776{
1777 1777
1778 // Store back all unsaved data into calendar object 1778 // Store back all unsaved data into calendar object
1779 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1779 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1780 if ( mViewManager->currentView() ) 1780 if ( mViewManager->currentView() )
1781 mViewManager->currentView()->flushView(); 1781 mViewManager->currentView()->flushView();
1782 1782
1783 1783
1784 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); 1784 QDateTime lfv = QDateTime::currentDateTime().addSecs( -2);
1785 mStorage->setSaveFormat( new ICalFormat() ); 1785 mStorage->setSaveFormat( new ICalFormat() );
1786 mStorage->setFileName( filename ); 1786 mStorage->setFileName( filename );
1787 bool success; 1787 bool success;
1788 success = mStorage->save(); 1788 success = mStorage->save();
1789 if ( !success ) { 1789 if ( !success ) {
1790 return false; 1790 return false;
1791 } 1791 }
1792 if ( filename == MainWindow::defaultFileName() ) { 1792 if ( filename == MainWindow::defaultFileName() ) {
1793 setLoadedFileVersion( lfv ); 1793 setLoadedFileVersion( lfv );
1794 watchSavedFile(); 1794 watchSavedFile();
1795 } 1795 }
1796 return true; 1796 return true;
1797} 1797}
1798 1798
1799void CalendarView::closeCalendar() 1799void CalendarView::closeCalendar()
1800{ 1800{
1801 1801
1802 // child windows no longer valid 1802 // child windows no longer valid
1803 emit closingDown(); 1803 emit closingDown();
1804 1804
1805 mCalendar->close(); 1805 mCalendar->close();
1806 setModified(false); 1806 setModified(false);
1807 updateView(); 1807 updateView();
1808} 1808}
1809 1809
1810void CalendarView::archiveCalendar() 1810void CalendarView::archiveCalendar()
1811{ 1811{
1812 mDialogManager->showArchiveDialog(); 1812 mDialogManager->showArchiveDialog();
1813} 1813}
1814 1814
1815 1815
1816void CalendarView::readSettings() 1816void CalendarView::readSettings()
1817{ 1817{
1818 1818
1819 1819
1820 // mViewManager->showAgendaView(); 1820 // mViewManager->showAgendaView();
1821 QString str; 1821 QString str;
1822 //qDebug("CalendarView::readSettings() "); 1822 //qDebug("CalendarView::readSettings() ");
1823 // read settings from the KConfig, supplying reasonable 1823 // read settings from the KConfig, supplying reasonable
1824 // defaults where none are to be found 1824 // defaults where none are to be found
1825 KConfig *config = KOGlobals::config(); 1825 KConfig *config = KOGlobals::config();
1826#ifndef KORG_NOSPLITTER 1826#ifndef KORG_NOSPLITTER
1827 config->setGroup("KOrganizer Geometry"); 1827 config->setGroup("KOrganizer Geometry");
1828 1828
1829 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1829 QValueList<int> sizes = config->readIntListEntry("Separator1");
1830 if (sizes.count() != 2) { 1830 if (sizes.count() != 2) {
1831 sizes << mDateNavigator->minimumSizeHint().width(); 1831 sizes << mDateNavigator->minimumSizeHint().width();
1832 sizes << 300; 1832 sizes << 300;
1833 } 1833 }
1834 mPanner->setSizes(sizes); 1834 mPanner->setSizes(sizes);
1835 1835
1836 sizes = config->readIntListEntry("Separator2"); 1836 sizes = config->readIntListEntry("Separator2");
1837 if ( ( mResourceView && sizes.count() == 4 ) || 1837 if ( ( mResourceView && sizes.count() == 4 ) ||
1838 ( !mResourceView && sizes.count() == 3 ) ) { 1838 ( !mResourceView && sizes.count() == 3 ) ) {
1839 mLeftSplitter->setSizes(sizes); 1839 mLeftSplitter->setSizes(sizes);
1840 } 1840 }
1841#endif 1841#endif
1842 globalFlagBlockAgenda = 1; 1842 globalFlagBlockAgenda = 1;
1843 mViewManager->showAgendaView(); 1843 mViewManager->showAgendaView();
1844 //mViewManager->readSettings( config ); 1844 //mViewManager->readSettings( config );
1845 mTodoList->restoreLayout(config,QString("Todo Layout")); 1845 mTodoList->restoreLayout(config,QString("Todo Layout"));
1846 readFilterSettings(config); 1846 readFilterSettings(config);
1847 1847
1848#ifdef DESKTOP_VERSION 1848#ifdef DESKTOP_VERSION
1849 config->setGroup("WidgetLayout"); 1849 config->setGroup("WidgetLayout");
1850 QStringList list; 1850 QStringList list;
1851 list = config->readListEntry("MainLayout"); 1851 list = config->readListEntry("MainLayout");
1852 int x,y,w,h; 1852 int x,y,w,h;
1853 if ( ! list.isEmpty() ) { 1853 if ( ! list.isEmpty() ) {
1854 x = list[0].toInt(); 1854 x = list[0].toInt();
1855 y = list[1].toInt(); 1855 y = list[1].toInt();
1856 w = list[2].toInt(); 1856 w = list[2].toInt();
1857 h = list[3].toInt(); 1857 h = list[3].toInt();
1858 KApplication::testCoords( &x,&y,&w,&h ); 1858 KApplication::testCoords( &x,&y,&w,&h );
1859 topLevelWidget()->setGeometry(x,y,w,h); 1859 topLevelWidget()->setGeometry(x,y,w,h);
1860 1860
1861 } else { 1861 } else {
1862 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1862 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1863 } 1863 }
1864 list = config->readListEntry("EditEventLayout"); 1864 list = config->readListEntry("EditEventLayout");
1865 if ( ! list.isEmpty() ) { 1865 if ( ! list.isEmpty() ) {
1866 x = list[0].toInt(); 1866 x = list[0].toInt();
1867 y = list[1].toInt(); 1867 y = list[1].toInt();
1868 w = list[2].toInt(); 1868 w = list[2].toInt();
1869 h = list[3].toInt(); 1869 h = list[3].toInt();
1870 KApplication::testCoords( &x,&y,&w,&h ); 1870 KApplication::testCoords( &x,&y,&w,&h );
1871 mEventEditor->setGeometry(x,y,w,h); 1871 mEventEditor->setGeometry(x,y,w,h);
1872 1872
1873 } 1873 }
1874 list = config->readListEntry("EditTodoLayout"); 1874 list = config->readListEntry("EditTodoLayout");
1875 if ( ! list.isEmpty() ) { 1875 if ( ! list.isEmpty() ) {
1876 x = list[0].toInt(); 1876 x = list[0].toInt();
1877 y = list[1].toInt(); 1877 y = list[1].toInt();
1878 w = list[2].toInt(); 1878 w = list[2].toInt();
1879 h = list[3].toInt(); 1879 h = list[3].toInt();
1880 KApplication::testCoords( &x,&y,&w,&h ); 1880 KApplication::testCoords( &x,&y,&w,&h );
1881 mTodoEditor->setGeometry(x,y,w,h); 1881 mTodoEditor->setGeometry(x,y,w,h);
1882 1882
1883 } 1883 }
1884 list = config->readListEntry("ViewerLayout"); 1884 list = config->readListEntry("ViewerLayout");
1885 if ( ! list.isEmpty() ) { 1885 if ( ! list.isEmpty() ) {
1886 x = list[0].toInt(); 1886 x = list[0].toInt();
1887 y = list[1].toInt(); 1887 y = list[1].toInt();
1888 w = list[2].toInt(); 1888 w = list[2].toInt();
1889 h = list[3].toInt(); 1889 h = list[3].toInt();
1890 KApplication::testCoords( &x,&y,&w,&h ); 1890 KApplication::testCoords( &x,&y,&w,&h );
1891 getEventViewerDialog()->setGeometry(x,y,w,h); 1891 getEventViewerDialog()->setGeometry(x,y,w,h);
1892 } 1892 }
1893#endif 1893#endif
1894 config->setGroup( "Views" ); 1894 config->setGroup( "Views" );
1895 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1895 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1896 1896
1897 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); 1897 QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame");
1898 1898
1899 int resetval = 0; 1899 int resetval = 0;
1900 int maxVal = 0; 1900 int maxVal = 0;
1901 if (sizes.count() != 3) { 1901 if (sizes.count() != 3) {
1902 if ( KOPrefs::instance()->mVerticalScreen ) { 1902 if ( KOPrefs::instance()->mVerticalScreen ) {
1903 resetval = mDateNavigator->sizeHint().width()+2; 1903 resetval = mDateNavigator->sizeHint().width()+2;
1904 } else { 1904 } else {
1905 resetval = mDateNavigator->sizeHint().height()+2; 1905 resetval = mDateNavigator->sizeHint().height()+2;
1906 } 1906 }
1907 } 1907 }
1908 if ( resetval ) { 1908 if ( resetval ) {
1909 sizes.clear(); 1909 sizes.clear();
1910 if ( KOPrefs::instance()->mVerticalScreen ) { 1910 if ( KOPrefs::instance()->mVerticalScreen ) {
1911 maxVal = QApplication::desktop()->width() -10; 1911 maxVal = QApplication::desktop()->width() -10;
1912 } else { 1912 } else {
1913 maxVal = QApplication::desktop()->height()-10; 1913 maxVal = QApplication::desktop()->height()-10;
1914 } 1914 }
1915 sizes << resetval; 1915 sizes << resetval;
1916 if ( maxVal < resetval + resetval) 1916 if ( maxVal < resetval + resetval)
1917 resetval = maxVal - resetval; 1917 resetval = maxVal - resetval;
1918 sizes << resetval; 1918 sizes << resetval;
1919 sizes << 100; 1919 sizes << 100;
1920 } 1920 }
1921 mLeftFrame->setSizes(sizes); 1921 mLeftFrame->setSizes(sizes);
1922 sizes = config->readIntListEntry("Main Splitter Frame"); 1922 sizes = config->readIntListEntry("Main Splitter Frame");
1923 resetval = 0; 1923 resetval = 0;
1924 maxVal = 0; 1924 maxVal = 0;
1925 if (sizes.count() != 2) { 1925 if (sizes.count() != 2) {
1926 if ( !KOPrefs::instance()->mVerticalScreen ) { 1926 if ( !KOPrefs::instance()->mVerticalScreen ) {
1927 resetval = mDateNavigator->sizeHint().width()+2; 1927 resetval = mDateNavigator->sizeHint().width()+2;
1928 } else { 1928 } else {
1929 resetval = mDateNavigator->sizeHint().height()+2; 1929 resetval = mDateNavigator->sizeHint().height()+2;
1930 } 1930 }
1931 } 1931 }
1932 if ( resetval ) { 1932 if ( resetval ) {
1933 sizes.clear(); 1933 sizes.clear();
1934 if ( !KOPrefs::instance()->mVerticalScreen ) { 1934 if ( !KOPrefs::instance()->mVerticalScreen ) {
1935 maxVal = QApplication::desktop()->width() -10; 1935 maxVal = QApplication::desktop()->width() -10;
1936 } else { 1936 } else {
1937 maxVal = QApplication::desktop()->height()-10; 1937 maxVal = QApplication::desktop()->height()-10;
1938 } 1938 }
1939 sizes << resetval; 1939 sizes << resetval;
1940 if ( maxVal < resetval + resetval) 1940 if ( maxVal < resetval + resetval)
1941 resetval = maxVal - resetval; 1941 resetval = maxVal - resetval;
1942 sizes << resetval; 1942 sizes << resetval;
1943 } 1943 }
1944 mMainFrame->setSizes(sizes); 1944 mMainFrame->setSizes(sizes);
1945 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1945 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1946 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1946 else if ( dateCount == 7 ) mNavigator->selectWeek();
1947 else mNavigator->selectDates( dateCount ); 1947 else mNavigator->selectDates( dateCount );
1948 // mViewManager->readSettings( config ); 1948 // mViewManager->readSettings( config );
1949 updateConfig(); 1949 updateConfig();
1950 globalFlagBlockAgenda = 2; 1950 globalFlagBlockAgenda = 2;
1951 mViewManager->readSettings( config ); 1951 mViewManager->readSettings( config );
1952 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); 1952 QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) );
1953} 1953}
1954 1954
1955 1955
1956void CalendarView::writeSettings() 1956void CalendarView::writeSettings()
1957{ 1957{
1958 // kdDebug() << "CalendarView::writeSettings" << endl; 1958 // kdDebug() << "CalendarView::writeSettings" << endl;
1959 1959
1960 KConfig *config = KOGlobals::config(); 1960 KConfig *config = KOGlobals::config();
1961 1961
1962 mViewManager->writeSettings( config ); 1962 mViewManager->writeSettings( config );
1963 mTodoList->saveLayout(config,QString("Todo Layout")); 1963 mTodoList->saveLayout(config,QString("Todo Layout"));
1964 mDialogManager->writeSettings( config ); 1964 mDialogManager->writeSettings( config );
1965 //KOPrefs::instance()->usrWriteConfig(); 1965 //KOPrefs::instance()->usrWriteConfig();
1966 KOPrefs::instance()->writeConfig(); 1966 KOPrefs::instance()->writeConfig();
1967 1967
1968 writeFilterSettings(config); 1968 writeFilterSettings(config);
1969 1969
1970 config->setGroup( "Views" ); 1970 config->setGroup( "Views" );
1971 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1971 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1972 1972
1973 QValueList<int> listINT = mLeftFrame->sizes(); 1973 QValueList<int> listINT = mLeftFrame->sizes();
1974 config->writeEntry("Left Splitter Frame",listINT); 1974 config->writeEntry("Left Splitter Frame",listINT);
1975 QValueList<int> listINT2 = mMainFrame->sizes(); 1975 QValueList<int> listINT2 = mMainFrame->sizes();
1976 config->writeEntry("Main Splitter Frame",listINT2); 1976 config->writeEntry("Main Splitter Frame",listINT2);
1977#ifdef DESKTOP_VERSION 1977#ifdef DESKTOP_VERSION
1978 config->setGroup("WidgetLayout"); 1978 config->setGroup("WidgetLayout");
1979 QStringList list ;//= config->readListEntry("MainLayout"); 1979 QStringList list ;//= config->readListEntry("MainLayout");
1980 int x,y,w,h; 1980 int x,y,w,h;
1981 QWidget* wid; 1981 QWidget* wid;
1982 wid = topLevelWidget(); 1982 wid = topLevelWidget();
1983 x = wid->geometry().x(); 1983 x = wid->geometry().x();
1984 y = wid->geometry().y(); 1984 y = wid->geometry().y();
1985 w = wid->width(); 1985 w = wid->width();
1986 h = wid->height(); 1986 h = wid->height();
1987 list.clear(); 1987 list.clear();
1988 list << QString::number( x ); 1988 list << QString::number( x );
1989 list << QString::number( y ); 1989 list << QString::number( y );
1990 list << QString::number( w ); 1990 list << QString::number( w );
1991 list << QString::number( h ); 1991 list << QString::number( h );
1992 config->writeEntry("MainLayout",list ); 1992 config->writeEntry("MainLayout",list );
1993 1993
1994 wid = mEventEditor; 1994 wid = mEventEditor;
1995 x = wid->geometry().x(); 1995 x = wid->geometry().x();
1996 y = wid->geometry().y(); 1996 y = wid->geometry().y();
1997 w = wid->width(); 1997 w = wid->width();
1998 h = wid->height(); 1998 h = wid->height();
1999 list.clear(); 1999 list.clear();
2000 list << QString::number( x ); 2000 list << QString::number( x );
2001 list << QString::number( y ); 2001 list << QString::number( y );
2002 list << QString::number( w ); 2002 list << QString::number( w );
2003 list << QString::number( h ); 2003 list << QString::number( h );
2004 config->writeEntry("EditEventLayout",list ); 2004 config->writeEntry("EditEventLayout",list );
2005 2005
2006 wid = mTodoEditor; 2006 wid = mTodoEditor;
2007 x = wid->geometry().x(); 2007 x = wid->geometry().x();
2008 y = wid->geometry().y(); 2008 y = wid->geometry().y();
2009 w = wid->width(); 2009 w = wid->width();
2010 h = wid->height(); 2010 h = wid->height();
2011 list.clear(); 2011 list.clear();
2012 list << QString::number( x ); 2012 list << QString::number( x );
2013 list << QString::number( y ); 2013 list << QString::number( y );
2014 list << QString::number( w ); 2014 list << QString::number( w );
2015 list << QString::number( h ); 2015 list << QString::number( h );
2016 config->writeEntry("EditTodoLayout",list ); 2016 config->writeEntry("EditTodoLayout",list );
2017 wid = getEventViewerDialog(); 2017 wid = getEventViewerDialog();
2018 x = wid->geometry().x(); 2018 x = wid->geometry().x();
2019 y = wid->geometry().y(); 2019 y = wid->geometry().y();
2020 w = wid->width(); 2020 w = wid->width();
2021 h = wid->height(); 2021 h = wid->height();
2022 list.clear(); 2022 list.clear();
2023 list << QString::number( x ); 2023 list << QString::number( x );
2024 list << QString::number( y ); 2024 list << QString::number( y );
2025 list << QString::number( w ); 2025 list << QString::number( w );
2026 list << QString::number( h ); 2026 list << QString::number( h );
2027 config->writeEntry("ViewerLayout",list ); 2027 config->writeEntry("ViewerLayout",list );
2028 wid = mDialogManager->getSearchDialog(); 2028 wid = mDialogManager->getSearchDialog();
2029 if ( wid ) { 2029 if ( wid ) {
2030 x = wid->geometry().x(); 2030 x = wid->geometry().x();
2031 y = wid->geometry().y(); 2031 y = wid->geometry().y();
2032 w = wid->width(); 2032 w = wid->width();
2033 h = wid->height(); 2033 h = wid->height();
2034 list.clear(); 2034 list.clear();
2035 list << QString::number( x ); 2035 list << QString::number( x );
2036 list << QString::number( y ); 2036 list << QString::number( y );
2037 list << QString::number( w ); 2037 list << QString::number( w );
2038 list << QString::number( h ); 2038 list << QString::number( h );
2039 config->writeEntry("SearchLayout",list ); 2039 config->writeEntry("SearchLayout",list );
2040 } 2040 }
2041#endif 2041#endif
2042 2042
2043 2043
2044 config->sync(); 2044 config->sync();
2045} 2045}
2046 2046
2047void CalendarView::readFilterSettings(KConfig *config) 2047void CalendarView::readFilterSettings(KConfig *config)
2048{ 2048{
2049 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 2049 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
2050 2050
2051 mFilters.clear(); 2051 mFilters.clear();
2052 2052
2053 config->setGroup("General"); 2053 config->setGroup("General");
2054 QStringList filterList = config->readListEntry("CalendarFilters"); 2054 QStringList filterList = config->readListEntry("CalendarFilters");
2055 2055
2056 QStringList::ConstIterator it = filterList.begin(); 2056 QStringList::ConstIterator it = filterList.begin();
2057 QStringList::ConstIterator end = filterList.end(); 2057 QStringList::ConstIterator end = filterList.end();
2058 while(it != end) { 2058 while(it != end) {
2059 // kdDebug() << " filter: " << (*it) << endl; 2059 // kdDebug() << " filter: " << (*it) << endl;
2060 2060
2061 CalFilter *filter; 2061 CalFilter *filter;
2062 filter = new CalFilter(*it); 2062 filter = new CalFilter(*it);
2063 config->setGroup("Filter_" + (*it).utf8()); 2063 config->setGroup("Filter_" + (*it).utf8());
2064 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 2064 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
2065 filter->setCriteria(config->readNumEntry("Criteria",0)); 2065 filter->setCriteria(config->readNumEntry("Criteria",0));
2066 filter->setCategoryList(config->readListEntry("CategoryList")); 2066 filter->setCategoryList(config->readListEntry("CategoryList"));
2067 mFilters.append(filter); 2067 mFilters.append(filter);
2068 2068
2069 ++it; 2069 ++it;
2070 } 2070 }
2071 2071
2072 if (mFilters.count() == 0) { 2072 if (mFilters.count() == 0) {
2073 CalFilter *filter = new CalFilter(i18n("Default")); 2073 CalFilter *filter = new CalFilter(i18n("Default"));
2074 mFilters.append(filter); 2074 mFilters.append(filter);
2075 } 2075 }
2076 mFilterView->updateFilters(); 2076 mFilterView->updateFilters();
2077 config->setGroup("FilterView"); 2077 config->setGroup("FilterView");
2078 2078
2079 mFilterView->blockSignals(true); 2079 mFilterView->blockSignals(true);
2080 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 2080 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
2081 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 2081 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
2082 mFilterView->blockSignals(false); 2082 mFilterView->blockSignals(false);
2083 // We do it manually to avoid it being done twice by the above calls 2083 // We do it manually to avoid it being done twice by the above calls
2084 updateFilter(); 2084 updateFilter();
2085} 2085}
2086 2086
2087void CalendarView::writeFilterSettings(KConfig *config) 2087void CalendarView::writeFilterSettings(KConfig *config)
2088{ 2088{
2089 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 2089 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
2090 2090
2091 QStringList filterList; 2091 QStringList filterList;
2092 2092
2093 CalFilter *filter = mFilters.first(); 2093 CalFilter *filter = mFilters.first();
2094 while(filter) { 2094 while(filter) {
2095 // kdDebug() << " fn: " << filter->name() << endl; 2095 // kdDebug() << " fn: " << filter->name() << endl;
2096 filterList << filter->name(); 2096 filterList << filter->name();
2097 config->setGroup("Filter_" + filter->name().utf8()); 2097 config->setGroup("Filter_" + filter->name().utf8());
2098 config->writeEntry("Criteria",filter->criteria()); 2098 config->writeEntry("Criteria",filter->criteria());
2099 config->writeEntry("CategoryList",filter->categoryList()); 2099 config->writeEntry("CategoryList",filter->categoryList());
2100 filter = mFilters.next(); 2100 filter = mFilters.next();
2101 } 2101 }
2102 config->setGroup("General"); 2102 config->setGroup("General");
2103 config->writeEntry("CalendarFilters",filterList); 2103 config->writeEntry("CalendarFilters",filterList);
2104 2104
2105 config->setGroup("FilterView"); 2105 config->setGroup("FilterView");
2106 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 2106 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
2107 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 2107 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
2108} 2108}
2109 2109
2110 2110
2111void CalendarView::goToday() 2111void CalendarView::goToday()
2112{ 2112{
2113 if ( mViewManager->currentView()->isMonthView() ) 2113 if ( mViewManager->currentView()->isMonthView() )
2114 mNavigator->selectTodayMonth(); 2114 mNavigator->selectTodayMonth();
2115 else 2115 else
2116 mNavigator->selectToday(); 2116 mNavigator->selectToday();
2117} 2117}
2118 2118
2119void CalendarView::goNext() 2119void CalendarView::goNext()
2120{ 2120{
2121 mNavigator->selectNext(); 2121 mNavigator->selectNext();
2122} 2122}
2123 2123
2124void CalendarView::goPrevious() 2124void CalendarView::goPrevious()
2125{ 2125{
2126 mNavigator->selectPrevious(); 2126 mNavigator->selectPrevious();
2127} 2127}
2128void CalendarView::goNextMonth() 2128void CalendarView::goNextMonth()
2129{ 2129{
2130 mNavigator->selectNextMonth(); 2130 mNavigator->selectNextMonth();
2131} 2131}
2132 2132
2133void CalendarView::goPreviousMonth() 2133void CalendarView::goPreviousMonth()
2134{ 2134{
2135 mNavigator->selectPreviousMonth(); 2135 mNavigator->selectPreviousMonth();
2136} 2136}
2137void CalendarView::writeLocale() 2137void CalendarView::writeLocale()
2138{ 2138{
2139 //KPimGlobalPrefs::instance()->setGlobalConfig(); 2139 //KPimGlobalPrefs::instance()->setGlobalConfig();
2140#if 0 2140#if 0
2141 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 2141 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
2142 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 2142 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
2143 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 2143 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
2144 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 2144 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
2145 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 2145 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
2146 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 2146 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
2147 dummy = KOPrefs::instance()->mUserDateFormatShort; 2147 dummy = KOPrefs::instance()->mUserDateFormatShort;
2148 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 2148 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
2149 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 2149 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
2150 KOPrefs::instance()->mDaylightsavingStart, 2150 KOPrefs::instance()->mDaylightsavingStart,
2151 KOPrefs::instance()->mDaylightsavingEnd ); 2151 KOPrefs::instance()->mDaylightsavingEnd );
2152 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); 2152 KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId );
2153#endif 2153#endif
2154} 2154}
2155void CalendarView::updateConfig() 2155void CalendarView::updateConfig()
2156{ 2156{
2157 writeLocale(); 2157 writeLocale();
2158 if ( KOPrefs::instance()->mUseAppColors ) 2158 if ( KOPrefs::instance()->mUseAppColors )
2159 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 2159 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
2160 emit configChanged(); 2160 emit configChanged();
2161 mTodoList->updateConfig(); 2161 mTodoList->updateConfig();
2162 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 2162 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
2163 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2163 mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2164 // To make the "fill window" configurations work 2164 // To make the "fill window" configurations work
2165 //mViewManager->raiseCurrentView(); 2165 //mViewManager->raiseCurrentView();
2166} 2166}
2167 2167
2168 2168
2169void CalendarView::eventChanged(Event *event) 2169void CalendarView::eventChanged(Event *event)
2170{ 2170{
2171 changeEventDisplay(event,KOGlobals::EVENTEDITED); 2171 changeEventDisplay(event,KOGlobals::EVENTEDITED);
2172 //updateUnmanagedViews(); 2172 //updateUnmanagedViews();
2173} 2173}
2174 2174
2175void CalendarView::eventAdded(Event *event) 2175void CalendarView::eventAdded(Event *event)
2176{ 2176{
2177 changeEventDisplay(event,KOGlobals::EVENTADDED); 2177 changeEventDisplay(event,KOGlobals::EVENTADDED);
2178} 2178}
2179 2179
2180void CalendarView::eventToBeDeleted(Event *) 2180void CalendarView::eventToBeDeleted(Event *)
2181{ 2181{
2182 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; 2182 kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl;
2183} 2183}
2184 2184
2185void CalendarView::eventDeleted() 2185void CalendarView::eventDeleted()
2186{ 2186{
2187 changeEventDisplay(0,KOGlobals::EVENTDELETED); 2187 changeEventDisplay(0,KOGlobals::EVENTDELETED);
2188} 2188}
2189void CalendarView::changeTodoDisplay(Todo *which, int action) 2189void CalendarView::changeTodoDisplay(Todo *which, int action)
2190{ 2190{
2191 changeIncidenceDisplay((Incidence *)which, action); 2191 changeIncidenceDisplay((Incidence *)which, action);
2192 mDateNavigator->updateView(); //LR 2192 mDateNavigator->updateView(); //LR
2193 //mDialogManager->updateSearchDialog(); 2193 //mDialogManager->updateSearchDialog();
2194 2194
2195 if (which) { 2195 if (which) {
2196 mViewManager->updateWNview(); 2196 mViewManager->updateWNview();
2197 //mTodoList->updateView(); 2197 //mTodoList->updateView();
2198 } 2198 }
2199 2199
2200} 2200}
2201 2201
2202void CalendarView::changeIncidenceDisplay(Incidence *which, int action) 2202void CalendarView::changeIncidenceDisplay(Incidence *which, int action)
2203{ 2203{
2204 updateUnmanagedViews(); 2204 updateUnmanagedViews();
2205 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); 2205 //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action );
2206 if ( action == KOGlobals::EVENTDELETED ) { //delete 2206 if ( action == KOGlobals::EVENTDELETED ) { //delete
2207 mCalendar->checkAlarmForIncidence( 0, true ); 2207 mCalendar->checkAlarmForIncidence( 0, true );
2208 if ( mEventViewerDialog ) 2208 if ( mEventViewerDialog )
2209 mEventViewerDialog->hide(); 2209 mEventViewerDialog->hide();
2210 } 2210 }
2211 else 2211 else
2212 mCalendar->checkAlarmForIncidence( which , false ); 2212 mCalendar->checkAlarmForIncidence( which , false );
2213} 2213}
2214 2214
2215// most of the changeEventDisplays() right now just call the view's 2215// most of the changeEventDisplays() right now just call the view's
2216// total update mode, but they SHOULD be recoded to be more refresh-efficient. 2216// total update mode, but they SHOULD be recoded to be more refresh-efficient.
2217void CalendarView::changeEventDisplay(Event *which, int action) 2217void CalendarView::changeEventDisplay(Event *which, int action)
2218{ 2218{
2219 // kdDebug() << "CalendarView::changeEventDisplay" << endl; 2219 // kdDebug() << "CalendarView::changeEventDisplay" << endl;
2220 changeIncidenceDisplay((Incidence *)which, action); 2220 changeIncidenceDisplay((Incidence *)which, action);
2221 mDateNavigator->updateView(); 2221 mDateNavigator->updateView();
2222 //mDialogManager->updateSearchDialog(); 2222 //mDialogManager->updateSearchDialog();
2223 2223
2224 if (which) { 2224 if (which) {
2225 // If there is an event view visible update the display 2225 // If there is an event view visible update the display
2226 mViewManager->currentView()->changeEventDisplay(which,action); 2226 mViewManager->currentView()->changeEventDisplay(which,action);
2227 // TODO: check, if update needed 2227 // TODO: check, if update needed
2228 // if (which->getTodoStatus()) { 2228 // if (which->getTodoStatus()) {
2229 mTodoList->updateView(); 2229 mTodoList->updateView();
2230 // } 2230 // }
2231 } else { 2231 } else {
2232 mViewManager->currentView()->updateView(); 2232 mViewManager->currentView()->updateView();
2233 } 2233 }
2234} 2234}
2235 2235
2236 2236
2237void CalendarView::updateTodoViews() 2237void CalendarView::updateTodoViews()
2238{ 2238{
2239 mTodoList->updateView(); 2239 mTodoList->updateView();
2240 mViewManager->currentView()->updateView(); 2240 mViewManager->currentView()->updateView();
2241 2241
2242} 2242}
2243 2243
2244 2244
2245void CalendarView::updateView(const QDate &start, const QDate &end) 2245void CalendarView::updateView(const QDate &start, const QDate &end)
2246{ 2246{
2247 mTodoList->updateView(); 2247 mTodoList->updateView();
2248 mViewManager->updateView(start, end); 2248 mViewManager->updateView(start, end);
2249 //mDateNavigator->updateView(); 2249 //mDateNavigator->updateView();
2250} 2250}
2251 2251
2252void CalendarView::updateView() 2252void CalendarView::updateView()
2253{ 2253{
2254 DateList tmpList = mNavigator->selectedDates(); 2254 DateList tmpList = mNavigator->selectedDates();
2255 2255
2256 if ( KOPrefs::instance()->mHideNonStartedTodos ) 2256 if ( KOPrefs::instance()->mHideNonStartedTodos )
2257 mTodoList->updateView(); 2257 mTodoList->updateView();
2258 // We assume that the navigator only selects consecutive days. 2258 // We assume that the navigator only selects consecutive days.
2259 updateView( tmpList.first(), tmpList.last() ); 2259 updateView( tmpList.first(), tmpList.last() );
2260} 2260}
2261 2261
2262void CalendarView::updateUnmanagedViews() 2262void CalendarView::updateUnmanagedViews()
2263{ 2263{
2264 mDateNavigator->updateDayMatrix(); 2264 mDateNavigator->updateDayMatrix();
2265} 2265}
2266 2266
2267int CalendarView::msgItemDelete(const QString name) 2267int CalendarView::msgItemDelete(const QString name)
2268{ 2268{
2269 return KMessageBox::warningContinueCancel(this,name +"\n\n"+ 2269 return KMessageBox::warningContinueCancel(this,name +"\n\n"+
2270 i18n("This item will be\npermanently deleted."), 2270 i18n("This item will be\npermanently deleted."),
2271 i18n("KO/Pi Confirmation"),i18n("Delete")); 2271 i18n("KO/Pi Confirmation"),i18n("Delete"));
2272} 2272}
2273 2273
2274 2274
2275void CalendarView::edit_cut() 2275void CalendarView::edit_cut()
2276{ 2276{
2277 Event *anEvent=0; 2277 Event *anEvent=0;
2278 2278
2279 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2279 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2280 2280
2281 if (mViewManager->currentView()->isEventView()) { 2281 if (mViewManager->currentView()->isEventView()) {
2282 if ( incidence && incidence->type() == "Event" ) { 2282 if ( incidence && incidence->type() == "Event" ) {
2283 anEvent = static_cast<Event *>(incidence); 2283 anEvent = static_cast<Event *>(incidence);
2284 } 2284 }
2285 } 2285 }
2286 2286
2287 if (!anEvent) { 2287 if (!anEvent) {
2288 KNotifyClient::beep(); 2288 KNotifyClient::beep();
2289 return; 2289 return;
2290 } 2290 }
2291 DndFactory factory( mCalendar ); 2291 DndFactory factory( mCalendar );
2292 factory.cutIncidence(anEvent); 2292 factory.cutIncidence(anEvent);
2293 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 2293 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
2294} 2294}
2295 2295
2296void CalendarView::edit_copy() 2296void CalendarView::edit_copy()
2297{ 2297{
2298 Event *anEvent=0; 2298 Event *anEvent=0;
2299 2299
2300 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2300 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2301 2301
2302 if (mViewManager->currentView()->isEventView()) { 2302 if (mViewManager->currentView()->isEventView()) {
2303 if ( incidence && incidence->type() == "Event" ) { 2303 if ( incidence && incidence->type() == "Event" ) {
2304 anEvent = static_cast<Event *>(incidence); 2304 anEvent = static_cast<Event *>(incidence);
2305 } 2305 }
2306 } 2306 }
2307 2307
2308 if (!anEvent) { 2308 if (!anEvent) {
2309 KNotifyClient::beep(); 2309 KNotifyClient::beep();
2310 return; 2310 return;
2311 } 2311 }
2312 DndFactory factory( mCalendar ); 2312 DndFactory factory( mCalendar );
2313 factory.copyIncidence(anEvent); 2313 factory.copyIncidence(anEvent);
2314} 2314}
2315 2315
2316void CalendarView::edit_paste() 2316void CalendarView::edit_paste()
2317{ 2317{
2318 QDate date = mNavigator->selectedDates().first(); 2318 QDate date = mNavigator->selectedDates().first();
2319 2319
2320 DndFactory factory( mCalendar ); 2320 DndFactory factory( mCalendar );
2321 Event *pastedEvent = (Event *)factory.pasteIncidence( date ); 2321 Event *pastedEvent = (Event *)factory.pasteIncidence( date );
2322 2322
2323 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); 2323 changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED );
2324} 2324}
2325 2325
2326void CalendarView::edit_options() 2326void CalendarView::edit_options()
2327{ 2327{
2328 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; 2328 QString tz = KPimGlobalPrefs::instance()->mTimeZoneId;
2329 emit save(); 2329 emit save();
2330 emit saveStopTimer(); 2330 emit saveStopTimer();
2331 mDialogManager->showOptionsDialog(); 2331 mDialogManager->showOptionsDialog();
2332 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { 2332 if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) {
2333 emit saveStopTimer(); 2333 emit saveStopTimer();
2334 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"), 2334 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, i18n("The timezone has changed!\nShould the calendar be reloaded\nto apply timezone changes?\nPlease read Menu: Help->FAQ:\n\"How do I change the timezone?\"\nas well!"),
2335 i18n("Timezone settings"),i18n("Reload"))) { 2335 i18n("Timezone settings"),i18n("Reload"))) {
2336 qDebug("KO: TZ reload cancelled "); 2336 qDebug("KO: TZ reload cancelled ");
2337 return; 2337 return;
2338 } 2338 }
2339 qDebug("KO: Timezone change "); 2339 qDebug("KO: Timezone change ");
2340 openCalendar( MainWindow::defaultFileName() ); 2340 openCalendar( MainWindow::defaultFileName() );
2341 setModified(true); 2341 setModified(true);
2342 } 2342 }
2343 else 2343 else
2344 qDebug("KO: No tz change "); 2344 qDebug("KO: No tz change ");
2345 2345
2346} 2346}
2347 2347
2348 2348
2349void CalendarView::slotSelectPickerDate( QDate d) 2349void CalendarView::slotSelectPickerDate( QDate d)
2350{ 2350{
2351 mDateFrame->hide(); 2351 mDateFrame->hide();
2352 if ( mDatePickerMode == 1 ) { 2352 if ( mDatePickerMode == 1 ) {
2353 mNavigator->slotDaySelect( d ); 2353 mNavigator->slotDaySelect( d );
2354 } else if ( mDatePickerMode == 2 ) { 2354 } else if ( mDatePickerMode == 2 ) {
2355 if ( mMoveIncidence->type() == "Todo" ) { 2355 if ( mMoveIncidence->type() == "Todo" ) {
2356 Todo * to = (Todo *) mMoveIncidence; 2356 Todo * to = (Todo *) mMoveIncidence;
2357 QTime tim; 2357 QTime tim;
2358 int len = 0; 2358 int len = 0;
2359 if ( to->hasStartDate() && to->hasDueDate() ) 2359 if ( to->hasStartDate() && to->hasDueDate() )
2360 len = to->dtStart().secsTo( to->dtDue()); 2360 len = to->dtStart().secsTo( to->dtDue());
2361 if ( to->hasDueDate() ) 2361 if ( to->hasDueDate() )
2362 tim = to->dtDue().time(); 2362 tim = to->dtDue().time();
2363 else { 2363 else {
2364 tim = QTime ( 0,0,0 ); 2364 tim = QTime ( 0,0,0 );
2365 to->setFloats( true ); 2365 to->setFloats( true );
2366 to->setHasDueDate( true ); 2366 to->setHasDueDate( true );
2367 } 2367 }
2368 QDateTime dt ( d,tim ); 2368 QDateTime dt ( d,tim );
2369 to->setDtDue( dt ); 2369 to->setDtDue( dt );
2370 2370
2371 if ( to->hasStartDate() ) { 2371 if ( to->hasStartDate() ) {
2372 if ( len>0 ) 2372 if ( len>0 )
2373 to->setDtStart(to->dtDue().addSecs( -len )); 2373 to->setDtStart(to->dtDue().addSecs( -len ));
2374 else 2374 else
2375 if (to->dtStart() > to->dtDue() ) 2375 if (to->dtStart() > to->dtDue() )
2376 to->setDtStart(to->dtDue().addDays( -3 )); 2376 to->setDtStart(to->dtDue().addDays( -3 ));
2377 } 2377 }
2378 2378
2379 todoChanged( to ); 2379 todoChanged( to );
2380 } else { 2380 } else {
2381 if ( mMoveIncidence->doesRecur() ) { 2381 if ( mMoveIncidence->doesRecur() ) {
2382#if 0 2382#if 0
2383 // PENDING implement this 2383 // PENDING implement this
2384 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); 2384 Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate );
2385 mCalendar()->addIncidence( newInc ); 2385 mCalendar()->addIncidence( newInc );
2386 if ( mMoveIncidence->type() == "Todo" ) 2386 if ( mMoveIncidence->type() == "Todo" )
2387 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); 2387 emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED );
2388 else 2388 else
2389 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); 2389 emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED);
2390 mMoveIncidence = newInc; 2390 mMoveIncidence = newInc;
2391 2391
2392#endif 2392#endif
2393 } 2393 }
2394 QTime tim = mMoveIncidence->dtStart().time(); 2394 QTime tim = mMoveIncidence->dtStart().time();
2395 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); 2395 int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd());
2396 QDateTime dt ( d,tim ); 2396 QDateTime dt ( d,tim );
2397 mMoveIncidence->setDtStart( dt ); 2397 mMoveIncidence->setDtStart( dt );
2398 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); 2398 ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) );
2399 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); 2399 changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED);
2400 } 2400 }
2401 2401
2402 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); 2402 mMoveIncidence->setRevision( mMoveIncidence->revision()+1 );
2403 } 2403 }
2404} 2404}
2405 2405
2406void CalendarView::removeCategories() 2406void CalendarView::removeCategories()
2407{ 2407{
2408 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2408 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2409 QStringList catList = KOPrefs::instance()->mCustomCategories; 2409 QStringList catList = KOPrefs::instance()->mCustomCategories;
2410 QStringList catIncList; 2410 QStringList catIncList;
2411 QStringList newCatList; 2411 QStringList newCatList;
2412 Incidence* inc = incList.first(); 2412 Incidence* inc = incList.first();
2413 int i; 2413 int i;
2414 int count = 0; 2414 int count = 0;
2415 while ( inc ) { 2415 while ( inc ) {
2416 newCatList.clear(); 2416 newCatList.clear();
2417 catIncList = inc->categories() ; 2417 catIncList = inc->categories() ;
2418 for( i = 0; i< catIncList.count(); ++i ) { 2418 for( i = 0; i< catIncList.count(); ++i ) {
2419 if ( catList.contains (catIncList[i])) 2419 if ( catList.contains (catIncList[i]))
2420 newCatList.append( catIncList[i] ); 2420 newCatList.append( catIncList[i] );
2421 } 2421 }
2422 newCatList.sort(); 2422 newCatList.sort();
2423 inc->setCategories( newCatList.join(",") ); 2423 inc->setCategories( newCatList.join(",") );
2424 inc = incList.next(); 2424 inc = incList.next();
2425 } 2425 }
2426} 2426}
2427 2427
2428int CalendarView::addCategories() 2428int CalendarView::addCategories()
2429{ 2429{
2430 QPtrList<Incidence> incList = mCalendar->rawIncidences(); 2430 QPtrList<Incidence> incList = mCalendar->rawIncidences();
2431 QStringList catList = KOPrefs::instance()->mCustomCategories; 2431 QStringList catList = KOPrefs::instance()->mCustomCategories;
2432 QStringList catIncList; 2432 QStringList catIncList;
2433 Incidence* inc = incList.first(); 2433 Incidence* inc = incList.first();
2434 int i; 2434 int i;
2435 int count = 0; 2435 int count = 0;
2436 while ( inc ) { 2436 while ( inc ) {
2437 catIncList = inc->categories() ; 2437 catIncList = inc->categories() ;
2438 for( i = 0; i< catIncList.count(); ++i ) { 2438 for( i = 0; i< catIncList.count(); ++i ) {
2439 if ( !catList.contains (catIncList[i])) { 2439 if ( !catList.contains (catIncList[i])) {
2440 catList.append( catIncList[i] ); 2440 catList.append( catIncList[i] );
2441 //qDebug("add cat %s ", catIncList[i].latin1()); 2441 //qDebug("add cat %s ", catIncList[i].latin1());
2442 ++count; 2442 ++count;
2443 } 2443 }
2444 } 2444 }
2445 inc = incList.next(); 2445 inc = incList.next();
2446 } 2446 }
2447 catList.sort(); 2447 catList.sort();
2448 KOPrefs::instance()->mCustomCategories = catList; 2448 KOPrefs::instance()->mCustomCategories = catList;
2449 return count; 2449 return count;
2450} 2450}
2451 2451
2452void CalendarView::manageCategories() 2452void CalendarView::manageCategories()
2453{ 2453{
2454 KOCatPrefs* cp = new KOCatPrefs(); 2454 KOCatPrefs* cp = new KOCatPrefs();
2455 cp->show(); 2455 cp->show();
2456 int w =cp->sizeHint().width() ; 2456 int w =cp->sizeHint().width() ;
2457 int h = cp->sizeHint().height() ; 2457 int h = cp->sizeHint().height() ;
2458 int dw = QApplication::desktop()->width(); 2458 int dw = QApplication::desktop()->width();
2459 int dh = QApplication::desktop()->height(); 2459 int dh = QApplication::desktop()->height();
2460 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 2460 cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
2461 if ( !cp->exec() ) { 2461 if ( !cp->exec() ) {
2462 delete cp; 2462 delete cp;
2463 return; 2463 return;
2464 } 2464 }
2465 int count = 0; 2465 int count = 0;
2466 if ( cp->addCat() ) { 2466 if ( cp->addCat() ) {
2467 count = addCategories(); 2467 count = addCategories();
2468 if ( count ) { 2468 if ( count ) {
2469 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); 2469 topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! "));
2470 writeSettings(); 2470 writeSettings();
2471 } else 2471 } else
2472 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); 2472 topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! "));
2473 } else { 2473 } else {
2474 removeCategories(); 2474 removeCategories();
2475 updateView(); 2475 updateView();
2476 } 2476 }
2477 delete cp; 2477 delete cp;
2478} 2478}
2479 2479
2480void CalendarView::beamIncidence(Incidence * Inc) 2480void CalendarView::beamIncidence(Incidence * Inc)
2481{ 2481{
2482 QPtrList<Incidence> delSel ; 2482 QPtrList<Incidence> delSel ;
2483 delSel.append(Inc); 2483 delSel.append(Inc);
2484 beamIncidenceList( delSel ); 2484 beamIncidenceList( delSel );
2485} 2485}
2486void CalendarView::beamCalendar() 2486void CalendarView::beamCalendar()
2487{ 2487{
2488 QPtrList<Incidence> delSel = mCalendar->rawIncidences(); 2488 QPtrList<Incidence> delSel = mCalendar->rawIncidences();
2489 //qDebug("beamCalendar() "); 2489 //qDebug("beamCalendar() ");
2490 beamIncidenceList( delSel ); 2490 beamIncidenceList( delSel );
2491} 2491}
2492void CalendarView::beamFilteredCalendar() 2492void CalendarView::beamFilteredCalendar()
2493{ 2493{
2494 QPtrList<Incidence> delSel = mCalendar->incidences(); 2494 QPtrList<Incidence> delSel = mCalendar->incidences();
2495 //qDebug("beamFilteredCalendar() "); 2495 //qDebug("beamFilteredCalendar() ");
2496 beamIncidenceList( delSel ); 2496 beamIncidenceList( delSel );
2497} 2497}
2498void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) 2498void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel )
2499{ 2499{
2500 if ( beamDialog->exec () == QDialog::Rejected ) 2500 if ( beamDialog->exec () == QDialog::Rejected )
2501 return; 2501 return;
2502#ifdef DESKTOP_VERSION 2502#ifdef DESKTOP_VERSION
2503 QString fn = locateLocal( "tmp", "kopibeamfile" ); 2503 QString fn = locateLocal( "tmp", "kopibeamfile" );
2504#else 2504#else
2505 QString fn = "/tmp/kopibeamfile"; 2505 QString fn = "/tmp/kopibeamfile";
2506#endif 2506#endif
2507 QString mes; 2507 QString mes;
2508 bool createbup = true; 2508 bool createbup = true;
2509 if ( createbup ) { 2509 if ( createbup ) {
2510 QString description = "\n"; 2510 QString description = "\n";
2511 CalendarLocal* cal = new CalendarLocal(); 2511 CalendarLocal* cal = new CalendarLocal();
2512 if ( beamDialog->beamLocal() ) 2512 if ( beamDialog->beamLocal() )
2513 cal->setLocalTime(); 2513 cal->setLocalTime();
2514 else 2514 else
2515 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 2515 cal->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
2516 Incidence *incidence = delSel.first(); 2516 Incidence *incidence = delSel.first();
2517 bool addText = false; 2517 bool addText = false;
2518 if ( delSel.count() < 10 ) 2518 if ( delSel.count() < 10 )
2519 addText = true; 2519 addText = true;
2520 else { 2520 else {
2521 description.sprintf(i18n(" %d items?"),delSel.count() ); 2521 description.sprintf(i18n(" %d items?"),delSel.count() );
2522 } 2522 }
2523 while ( incidence ) { 2523 while ( incidence ) {
2524 Incidence *in = incidence->clone(); 2524 Incidence *in = incidence->clone();
2525 if ( ! in->summary().isEmpty() ) { 2525 if ( ! in->summary().isEmpty() ) {
2526 in->setDescription(""); 2526 in->setDescription("");
2527 } else { 2527 } else {
2528 in->setSummary( in->description().left(20)); 2528 in->setSummary( in->description().left(20));
2529 in->setDescription(""); 2529 in->setDescription("");
2530 } 2530 }
2531 if ( addText ) 2531 if ( addText )
2532 description += in->summary() + "\n"; 2532 description += in->summary() + "\n";
2533 cal->addIncidence( in ); 2533 cal->addIncidence( in );
2534 incidence = delSel.next(); 2534 incidence = delSel.next();
2535 } 2535 }
2536 if ( beamDialog->beamVcal() ) { 2536 if ( beamDialog->beamVcal() ) {
2537 fn += ".vcs"; 2537 fn += ".vcs";
2538 FileStorage storage( cal, fn, new VCalFormat ); 2538 FileStorage storage( cal, fn, new VCalFormat );
2539 storage.save(); 2539 storage.save();
2540 } else { 2540 } else {
2541 fn += ".ics"; 2541 fn += ".ics";
2542 FileStorage storage( cal, fn, new ICalFormat( ) ); 2542 FileStorage storage( cal, fn, new ICalFormat( ) );
2543 storage.save(); 2543 storage.save();
2544 } 2544 }
2545 delete cal; 2545 delete cal;
2546 mes = i18n("KO/Pi: Ready for beaming"); 2546 mes = i18n("KO/Pi: Ready for beaming");
2547 topLevelWidget()->setCaption(mes); 2547 topLevelWidget()->setCaption(mes);
2548 KApplication::convert2latin1( fn ); 2548 KApplication::convert2latin1( fn );
2549#ifndef DESKTOP_VERSION 2549#ifndef DESKTOP_VERSION
2550 Ir *ir = new Ir( this ); 2550 Ir *ir = new Ir( this );
2551 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) ); 2551 connect( ir, SIGNAL( done( Ir * ) ), this, SLOT( beamDone( Ir * ) ) );
2552 ir->send( fn, description, "text/x-vCalendar" ); 2552 ir->send( fn, description, "text/x-vCalendar" );
2553#endif 2553#endif
2554 } 2554 }
2555} 2555}
2556void CalendarView::beamDone( Ir *ir ) 2556void CalendarView::beamDone( Ir *ir )
2557{ 2557{
2558#ifndef DESKTOP_VERSION 2558#ifndef DESKTOP_VERSION
2559 delete ir; 2559 delete ir;
2560#endif 2560#endif
2561 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") ); 2561 topLevelWidget()->setCaption( i18n("KO/Pi: Beaming done.") );
2562 topLevelWidget()->raise(); 2562 topLevelWidget()->raise();
2563} 2563}
2564 2564
2565void CalendarView::moveIncidence(Incidence * inc ) 2565void CalendarView::moveIncidence(Incidence * inc )
2566{ 2566{
2567 if ( !inc ) return; 2567 if ( !inc ) return;
2568 showDatePickerPopup(); 2568 showDatePickerPopup();
2569 mDatePickerMode = 2; 2569 mDatePickerMode = 2;
2570 mMoveIncidence = inc ; 2570 mMoveIncidence = inc ;
2571 QDate da; 2571 QDate da;
2572 if ( mMoveIncidence->type() == "Todo" ) { 2572 if ( mMoveIncidence->type() == "Todo" ) {
2573 Todo * to = (Todo *) mMoveIncidence; 2573 Todo * to = (Todo *) mMoveIncidence;
2574 if ( to->hasDueDate() ) 2574 if ( to->hasDueDate() )
2575 da = to->dtDue().date(); 2575 da = to->dtDue().date();
2576 else 2576 else
2577 da = QDate::currentDate(); 2577 da = QDate::currentDate();
2578 } else { 2578 } else {
2579 da = mMoveIncidence->dtStart().date(); 2579 da = mMoveIncidence->dtStart().date();
2580 } 2580 }
2581 //PENDING set date for recurring incidence to date of recurrence 2581 //PENDING set date for recurring incidence to date of recurrence
2582 //mMoveIncidenceOldDate; 2582 //mMoveIncidenceOldDate;
2583 mDatePicker->setDate( da ); 2583 mDatePicker->setDate( da );
2584} 2584}
2585void CalendarView::showDatePickerPopup() 2585void CalendarView::showDatePickerPopup()
2586{ 2586{
2587 if ( mDateFrame->isVisible() ) 2587 if ( mDateFrame->isVisible() )
2588 mDateFrame->hide(); 2588 mDateFrame->hide();
2589 else { 2589 else {
2590 int offX = 0, offY = 0; 2590 int offX = 0, offY = 0;
2591#ifdef DESKTOP_VERSION 2591#ifdef DESKTOP_VERSION
2592 int w =mDatePicker->sizeHint().width() ; 2592 int w =mDatePicker->sizeHint().width() ;
2593 int h = mDatePicker->sizeHint().height() ; 2593 int h = mDatePicker->sizeHint().height() ;
2594 int dw = topLevelWidget()->width(); 2594 int dw = topLevelWidget()->width();
2595 int dh = topLevelWidget()->height(); 2595 int dh = topLevelWidget()->height();
2596 offX = topLevelWidget()->x(); 2596 offX = topLevelWidget()->x();
2597 offY = topLevelWidget()->y(); 2597 offY = topLevelWidget()->y();
2598#else 2598#else
2599 int w =mDatePicker->sizeHint().width() ; 2599 int w =mDatePicker->sizeHint().width() ;
2600 int h = mDatePicker->sizeHint().height() ; 2600 int h = mDatePicker->sizeHint().height() ;
2601 int dw = QApplication::desktop()->width(); 2601 int dw = QApplication::desktop()->width();
2602 int dh = QApplication::desktop()->height(); 2602 int dh = QApplication::desktop()->height();
2603#endif 2603#endif
2604 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h ); 2604 mDateFrame->setGeometry( (dw-w)/2+offX, (dh - h )/2+offY ,w,h );
2605 mDateFrame->show(); 2605 mDateFrame->show();
2606 } 2606 }
2607} 2607}
2608void CalendarView::showDatePicker( ) 2608void CalendarView::showDatePicker( )
2609{ 2609{
2610 showDatePickerPopup(); 2610 showDatePickerPopup();
2611 mDatePickerMode = 1; 2611 mDatePickerMode = 1;
2612 mDatePicker->setDate( mNavigator->selectedDates().first() ); 2612 mDatePicker->setDate( mNavigator->selectedDates().first() );
2613} 2613}
2614 2614
2615void CalendarView::showEventEditor() 2615void CalendarView::showEventEditor()
2616{ 2616{
2617#ifdef DESKTOP_VERSION 2617#ifdef DESKTOP_VERSION
2618 int x,y,w,h; 2618 int x,y,w,h;
2619 x = mEventEditor->geometry().x(); 2619 x = mEventEditor->geometry().x();
2620 y = mEventEditor->geometry().y(); 2620 y = mEventEditor->geometry().y();
2621 w = mEventEditor->width(); 2621 w = mEventEditor->width();
2622 h = mEventEditor->height(); 2622 h = mEventEditor->height();
2623 mEventEditor->show(); 2623 mEventEditor->show();
2624 mEventEditor->setGeometry(x,y,w,h); 2624 mEventEditor->setGeometry(x,y,w,h);
2625#else 2625#else
2626 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) { 2626 if ( mEventEditor->width() < QApplication::desktop()->width() -60 || mEventEditor->width() > QApplication::desktop()->width() ) {
2627 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2627 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2628 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() ); 2628 qDebug("KO: CalendarView: recreate mEventEditor %d %d", mEventEditor->width(), QApplication::desktop()->width() );
2629 qApp->processEvents(); 2629 qApp->processEvents();
2630 delete mEventEditor; 2630 delete mEventEditor;
2631 mEventEditor = mDialogManager->getEventEditor(); 2631 mEventEditor = mDialogManager->getEventEditor();
2632 topLevelWidget()->setCaption( i18n("") ); 2632 topLevelWidget()->setCaption( i18n("") );
2633 } 2633 }
2634 mEventEditor->showMaximized(); 2634 mEventEditor->showMaximized();
2635#endif 2635#endif
2636} 2636}
2637void CalendarView::showTodoEditor() 2637void CalendarView::showTodoEditor()
2638{ 2638{
2639#ifdef DESKTOP_VERSION 2639#ifdef DESKTOP_VERSION
2640 int x,y,w,h; 2640 int x,y,w,h;
2641 x = mTodoEditor->geometry().x(); 2641 x = mTodoEditor->geometry().x();
2642 y = mTodoEditor->geometry().y(); 2642 y = mTodoEditor->geometry().y();
2643 w = mTodoEditor->width(); 2643 w = mTodoEditor->width();
2644 h = mTodoEditor->height(); 2644 h = mTodoEditor->height();
2645 mTodoEditor->show(); 2645 mTodoEditor->show();
2646 mTodoEditor->setGeometry(x,y,w,h); 2646 mTodoEditor->setGeometry(x,y,w,h);
2647#else 2647#else
2648 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) { 2648 if ( mTodoEditor->width() < QApplication::desktop()->width() -60|| mTodoEditor->width() > QApplication::desktop()->width() ) {
2649 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") ); 2649 topLevelWidget()->setCaption( i18n("Recreating edit dialog. Please wait...") );
2650 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() ); 2650 qDebug("KO: CalendarView: recreate mTodoEditor %d %d ", mTodoEditor->width() ,QApplication::desktop()->width() );
2651 qApp->processEvents(); 2651 qApp->processEvents();
2652 delete mTodoEditor; 2652 delete mTodoEditor;
2653 mTodoEditor = mDialogManager->getTodoEditor(); 2653 mTodoEditor = mDialogManager->getTodoEditor();
2654 topLevelWidget()->setCaption( i18n("") ); 2654 topLevelWidget()->setCaption( i18n("") );
2655 } 2655 }
2656 mTodoEditor->showMaximized(); 2656 mTodoEditor->showMaximized();
2657#endif 2657#endif
2658} 2658}
2659 2659
2660void CalendarView::cloneIncidence() 2660void CalendarView::cloneIncidence()
2661{ 2661{
2662 Incidence *incidence = currentSelection(); 2662 Incidence *incidence = currentSelection();
2663 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2663 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2664 if ( incidence ) { 2664 if ( incidence ) {
2665 cloneIncidence(incidence); 2665 cloneIncidence(incidence);
2666 } 2666 }
2667} 2667}
2668void CalendarView::moveIncidence() 2668void CalendarView::moveIncidence()
2669{ 2669{
2670 Incidence *incidence = currentSelection(); 2670 Incidence *incidence = currentSelection();
2671 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2671 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2672 if ( incidence ) { 2672 if ( incidence ) {
2673 moveIncidence(incidence); 2673 moveIncidence(incidence);
2674 } 2674 }
2675} 2675}
2676void CalendarView::beamIncidence() 2676void CalendarView::beamIncidence()
2677{ 2677{
2678 Incidence *incidence = currentSelection(); 2678 Incidence *incidence = currentSelection();
2679 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2679 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2680 if ( incidence ) { 2680 if ( incidence ) {
2681 beamIncidence(incidence); 2681 beamIncidence(incidence);
2682 } 2682 }
2683} 2683}
2684void CalendarView::toggleCancelIncidence() 2684void CalendarView::toggleCancelIncidence()
2685{ 2685{
2686 Incidence *incidence = currentSelection(); 2686 Incidence *incidence = currentSelection();
2687 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 2687 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
2688 if ( incidence ) { 2688 if ( incidence ) {
2689 cancelIncidence(incidence); 2689 cancelIncidence(incidence);
2690 } 2690 }
2691} 2691}
2692 2692
2693 2693
2694void CalendarView::cancelIncidence(Incidence * inc ) 2694void CalendarView::cancelIncidence(Incidence * inc )
2695{ 2695{
2696 inc->setCancelled( ! inc->cancelled() ); 2696 inc->setCancelled( ! inc->cancelled() );
2697 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED ); 2697 changeIncidenceDisplay( inc,KOGlobals::EVENTEDITED );
2698 updateView(); 2698 updateView();
2699} 2699}
2700void CalendarView::cloneIncidence(Incidence * orgInc ) 2700void CalendarView::cloneIncidence(Incidence * orgInc )
2701{ 2701{
2702 Incidence * newInc = orgInc->clone(); 2702 Incidence * newInc = orgInc->clone();
2703 newInc->recreate(); 2703 newInc->recreate();
2704 2704
2705 if ( newInc->type() == "Todo" ) { 2705 if ( newInc->type() == "Todo" ) {
2706 Todo* t = (Todo*) newInc; 2706 Todo* t = (Todo*) newInc;
2707 bool cloneSub = false; 2707 bool cloneSub = false;
2708 if ( orgInc->relations().count() ) { 2708 if ( orgInc->relations().count() ) {
2709 int result = KMessageBox::warningYesNoCancel(this, 2709 int result = KMessageBox::warningYesNoCancel(this,
2710 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ), 2710 i18n("The todo\n%1\nwill be cloned!\nIt has subtodos!\nDo you want to clone\nall subtodos as well?").arg( newInc->summary().left ( 25 ) ),
2711 i18n("Todo has subtodos"), 2711 i18n("Todo has subtodos"),
2712 i18n("Yes"), 2712 i18n("Yes"),
2713 i18n("No")); 2713 i18n("No"));
2714 2714
2715 if ( result == KMessageBox::Cancel ) { 2715 if ( result == KMessageBox::Cancel ) {
2716 delete t; 2716 delete t;
2717 return; 2717 return;
2718 } 2718 }
2719 if (result == KMessageBox::Yes) cloneSub = true; 2719 if (result == KMessageBox::Yes) cloneSub = true;
2720 } 2720 }
2721 showTodoEditor(); 2721 showTodoEditor();
2722 mTodoEditor->editTodo( t ); 2722 mTodoEditor->editTodo( t );
2723 if ( mTodoEditor->exec() ) { 2723 if ( mTodoEditor->exec() ) {
2724 if ( cloneSub ) { 2724 if ( cloneSub ) {
2725 orgInc->cloneRelations( t ); 2725 orgInc->cloneRelations( t );
2726 mCalendar->addIncidenceBranch( t ); 2726 mCalendar->addIncidenceBranch( t );
2727 updateView(); 2727 updateView();
2728 2728
2729 } else { 2729 } else {
2730 mCalendar->addTodo( t ); 2730 mCalendar->addTodo( t );
2731 updateView(); 2731 updateView();
2732 } 2732 }
2733 } else { 2733 } else {
2734 delete t; 2734 delete t;
2735 } 2735 }
2736 } 2736 }
2737 else { 2737 else {
2738 Event* e = (Event*) newInc; 2738 Event* e = (Event*) newInc;
2739 showEventEditor(); 2739 showEventEditor();
2740 mEventEditor->editEvent( e ); 2740 mEventEditor->editEvent( e );
2741 if ( mEventEditor->exec() ) { 2741 if ( mEventEditor->exec() ) {
2742 mCalendar->addEvent( e ); 2742 mCalendar->addEvent( e );
2743 updateView(); 2743 updateView();
2744 } else { 2744 } else {
2745 delete e; 2745 delete e;
2746 } 2746 }
2747 } 2747 }
2748 setActiveWindow(); 2748 setActiveWindow();
2749} 2749}
2750 2750
2751void CalendarView::newEvent() 2751void CalendarView::newEvent()
2752{ 2752{
2753 // TODO: Replace this code by a common eventDurationHint of KOBaseView. 2753 // TODO: Replace this code by a common eventDurationHint of KOBaseView.
2754 KOAgendaView *aView = mViewManager->agendaView(); 2754 KOAgendaView *aView = mViewManager->agendaView();
2755 if (aView) { 2755 if (aView) {
2756 if (aView->selectionStart().isValid()) { 2756 if (aView->selectionStart().isValid()) {
2757 if (aView->selectedIsAllDay()) { 2757 if (aView->selectedIsAllDay()) {
2758 newEvent(aView->selectionStart(),aView->selectionEnd(),true); 2758 newEvent(aView->selectionStart(),aView->selectionEnd(),true);
2759 } else { 2759 } else {
2760 newEvent(aView->selectionStart(),aView->selectionEnd()); 2760 newEvent(aView->selectionStart(),aView->selectionEnd());
2761 } 2761 }
2762 return; 2762 return;
2763 } 2763 }
2764 } 2764 }
2765 2765
2766 QDate date = mNavigator->selectedDates().first(); 2766 QDate date = mNavigator->selectedDates().first();
2767 QDateTime current = QDateTime::currentDateTime(); 2767 QDateTime current = QDateTime::currentDateTime();
2768 if ( date <= current.date() ) { 2768 if ( date <= current.date() ) {
2769 int hour = current.time().hour() +1; 2769 int hour = current.time().hour() +1;
2770 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ), 2770 newEvent( QDateTime( current.date(), QTime( hour, 0, 0 ) ),
2771 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2771 QDateTime( current.date(), QTime( hour+ KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2772 } else 2772 } else
2773 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ), 2773 newEvent( QDateTime( date, QTime( KOPrefs::instance()->mStartTime, 0, 0 ) ),
2774 QDateTime( date, QTime( KOPrefs::instance()->mStartTime + 2774 QDateTime( date, QTime( KOPrefs::instance()->mStartTime +
2775 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) ); 2775 KOPrefs::instance()->mDefaultDuration, 0, 0 ) ) );
2776} 2776}
2777 2777
2778void CalendarView::newEvent(QDateTime fh) 2778void CalendarView::newEvent(QDateTime fh)
2779{ 2779{
2780 newEvent(fh, 2780 newEvent(fh,
2781 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration))); 2781 QDateTime(fh.addSecs(3600*KOPrefs::instance()->mDefaultDuration)));
2782} 2782}
2783 2783
2784void CalendarView::newEvent(QDate dt) 2784void CalendarView::newEvent(QDate dt)
2785{ 2785{
2786 newEvent(QDateTime(dt, QTime(0,0,0)), 2786 newEvent(QDateTime(dt, QTime(0,0,0)),
2787 QDateTime(dt, QTime(0,0,0)), true); 2787 QDateTime(dt, QTime(0,0,0)), true);
2788} 2788}
2789void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint) 2789void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint)
2790{ 2790{
2791 newEvent(fromHint, toHint, false); 2791 newEvent(fromHint, toHint, false);
2792} 2792}
2793void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay) 2793void CalendarView::newEvent(QDateTime fromHint, QDateTime toHint, bool allDay)
2794{ 2794{
2795 2795
2796 showEventEditor(); 2796 showEventEditor();
2797 mEventEditor->newEvent(fromHint,toHint,allDay); 2797 mEventEditor->newEvent(fromHint,toHint,allDay);
2798 if ( mFilterView->filtersEnabled() ) { 2798 if ( mFilterView->filtersEnabled() ) {
2799 CalFilter *filter = mFilterView->selectedFilter(); 2799 CalFilter *filter = mFilterView->selectedFilter();
2800 if (filter && filter->showCategories()) { 2800 if (filter && filter->showCategories()) {
2801 mEventEditor->setCategories(filter->categoryList().join(",") ); 2801 mEventEditor->setCategories(filter->categoryList().join(",") );
2802 } 2802 }
2803 if ( filter ) 2803 if ( filter )
2804 mEventEditor->setSecrecy( filter->getSecrecy() ); 2804 mEventEditor->setSecrecy( filter->getSecrecy() );
2805 } 2805 }
2806 mEventEditor->exec(); 2806 mEventEditor->exec();
2807 setActiveWindow(); 2807 setActiveWindow();
2808} 2808}
2809void CalendarView::todoAdded(Todo * t) 2809void CalendarView::todoAdded(Todo * t)
2810{ 2810{
2811 2811
2812 changeTodoDisplay ( t ,KOGlobals::EVENTADDED); 2812 changeTodoDisplay ( t ,KOGlobals::EVENTADDED);
2813 updateTodoViews(); 2813 updateTodoViews();
2814} 2814}
2815void CalendarView::todoChanged(Todo * t) 2815void CalendarView::todoChanged(Todo * t)
2816{ 2816{
2817 emit todoModified( t, 4 ); 2817 emit todoModified( t, 4 );
2818 // updateTodoViews(); 2818 // updateTodoViews();
2819} 2819}
2820void CalendarView::todoToBeDeleted(Todo *) 2820void CalendarView::todoToBeDeleted(Todo *)
2821{ 2821{
2822 //qDebug("todoToBeDeleted(Todo *) "); 2822 //qDebug("todoToBeDeleted(Todo *) ");
2823 updateTodoViews(); 2823 updateTodoViews();
2824} 2824}
2825void CalendarView::todoDeleted() 2825void CalendarView::todoDeleted()
2826{ 2826{
2827 //qDebug(" todoDeleted()"); 2827 //qDebug(" todoDeleted()");
2828 updateTodoViews(); 2828 updateTodoViews();
2829} 2829}
2830 2830
2831 2831
2832void CalendarView::newTodoDateTime( QDateTime dt, bool allday ) 2832void CalendarView::newTodoDateTime( QDateTime dt, bool allday )
2833{ 2833{
2834 showTodoEditor(); 2834 showTodoEditor();
2835 mTodoEditor->newTodo(dt,0,allday); 2835 mTodoEditor->newTodo(dt,0,allday);
2836 if ( mFilterView->filtersEnabled() ) { 2836 if ( mFilterView->filtersEnabled() ) {
2837 CalFilter *filter = mFilterView->selectedFilter(); 2837 CalFilter *filter = mFilterView->selectedFilter();
2838 if (filter && filter->showCategories()) { 2838 if (filter && filter->showCategories()) {
2839 mTodoEditor->setCategories(filter->categoryList().join(",") ); 2839 mTodoEditor->setCategories(filter->categoryList().join(",") );
2840 } 2840 }
2841 if ( filter ) 2841 if ( filter )
2842 mTodoEditor->setSecrecy( filter->getSecrecy() ); 2842 mTodoEditor->setSecrecy( filter->getSecrecy() );
2843 } 2843 }
2844 mTodoEditor->exec(); 2844 mTodoEditor->exec();
2845 setActiveWindow(); 2845 setActiveWindow();
2846} 2846}
2847 2847
2848void CalendarView::newTodo() 2848void CalendarView::newTodo()
2849{ 2849{
2850 newTodoDateTime( QDateTime(),true ); 2850 newTodoDateTime( QDateTime(),true );
2851} 2851}
2852 2852
2853void CalendarView::newSubTodo() 2853void CalendarView::newSubTodo()
2854{ 2854{
2855 Todo *todo = selectedTodo(); 2855 Todo *todo = selectedTodo();
2856 if ( todo ) newSubTodo( todo ); 2856 if ( todo ) newSubTodo( todo );
2857} 2857}
2858 2858
2859void CalendarView::newSubTodo(Todo *parentEvent) 2859void CalendarView::newSubTodo(Todo *parentEvent)
2860{ 2860{
2861 2861
2862 showTodoEditor(); 2862 showTodoEditor();
2863 mTodoEditor->newTodo(QDateTime(),parentEvent,true); 2863 mTodoEditor->newTodo(QDateTime(),parentEvent,true);
2864 mTodoEditor->exec(); 2864 mTodoEditor->exec();
2865 setActiveWindow(); 2865 setActiveWindow();
2866} 2866}
2867 2867
2868void CalendarView::newFloatingEvent() 2868void CalendarView::newFloatingEvent()
2869{ 2869{
2870 DateList tmpList = mNavigator->selectedDates(); 2870 DateList tmpList = mNavigator->selectedDates();
2871 QDate date = tmpList.first(); 2871 QDate date = tmpList.first();
2872 2872
2873 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ), 2873 newEvent( QDateTime( date, QTime( 12, 0, 0 ) ),
2874 QDateTime( date, QTime( 12, 0, 0 ) ), true ); 2874 QDateTime( date, QTime( 12, 0, 0 ) ), true );
2875} 2875}
2876 2876
2877 2877
2878void CalendarView::editEvent( Event *event ) 2878void CalendarView::editEvent( Event *event )
2879{ 2879{
2880 2880
2881 if ( !event ) return; 2881 if ( !event ) return;
2882 if ( event->isReadOnly() ) { 2882 if ( event->isReadOnly() ) {
2883 showEvent( event ); 2883 showEvent( event );
2884 return; 2884 return;
2885 } 2885 }
2886 showEventEditor(); 2886 showEventEditor();
2887 mEventEditor->editEvent( event , mFlagEditDescription); 2887 mEventEditor->editEvent( event , mFlagEditDescription);
2888 mEventEditor->exec(); 2888 mEventEditor->exec();
2889 setActiveWindow(); 2889 setActiveWindow();
2890 2890
2891} 2891}
2892void CalendarView::editJournal( Journal *jour ) 2892void CalendarView::editJournal( Journal *jour )
2893{ 2893{
2894 if ( !jour ) return; 2894 if ( !jour ) return;
2895 mDialogManager->hideSearchDialog(); 2895 mDialogManager->hideSearchDialog();
2896 mViewManager->showJournalView(); 2896 mViewManager->showJournalView();
2897 mNavigator->slotDaySelect( jour->dtStart().date() ); 2897 mNavigator->slotDaySelect( jour->dtStart().date() );
2898} 2898}
2899void CalendarView::editTodo( Todo *todo ) 2899void CalendarView::editTodo( Todo *todo )
2900{ 2900{
2901 if ( !todo ) return; 2901 if ( !todo ) return;
2902 2902
2903 if ( todo->isReadOnly() ) { 2903 if ( todo->isReadOnly() ) {
2904 showTodo( todo ); 2904 showTodo( todo );
2905 return; 2905 return;
2906 } 2906 }
2907 showTodoEditor(); 2907 showTodoEditor();
2908 mTodoEditor->editTodo( todo ,mFlagEditDescription); 2908 mTodoEditor->editTodo( todo ,mFlagEditDescription);
2909 mTodoEditor->exec(); 2909 mTodoEditor->exec();
2910 setActiveWindow(); 2910 setActiveWindow();
2911 2911
2912} 2912}
2913 2913
2914KOEventViewerDialog* CalendarView::getEventViewerDialog() 2914KOEventViewerDialog* CalendarView::getEventViewerDialog()
2915{ 2915{
2916 if ( !mEventViewerDialog ) { 2916 if ( !mEventViewerDialog ) {
2917 mEventViewerDialog = new KOEventViewerDialog(0); 2917 mEventViewerDialog = new KOEventViewerDialog(0);
2918 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) ); 2918 connect( mEventViewerDialog, SIGNAL( editIncidence( Incidence* )), this, SLOT(editIncidence( Incidence* ) ) );
2919 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig())); 2919 connect( this, SIGNAL(configChanged()), mEventViewerDialog, SLOT(updateConfig()));
2920 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)), 2920 connect( mEventViewerDialog, SIGNAL(jumpToTime( const QDate &)),
2921 dateNavigator(), SLOT( selectWeek( const QDate & ) ) ); 2921 dateNavigator(), SLOT( selectWeek( const QDate & ) ) );
2922 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ), 2922 connect( mEventViewerDialog, SIGNAL(showAgendaView( bool ) ),
2923 viewManager(), SLOT( showAgendaView( bool ) ) ); 2923 viewManager(), SLOT( showAgendaView( bool ) ) );
2924 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()), 2924 connect( mEventViewerDialog, SIGNAL(signalViewerClosed()),
2925 this, SLOT( slotViewerClosed() ) ); 2925 this, SLOT( slotViewerClosed() ) );
2926 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ), 2926 connect( mEventViewerDialog, SIGNAL( todoCompleted(Todo *) ),
2927 this, SLOT( todoChanged(Todo *) ) ); 2927 this, SLOT( todoChanged(Todo *) ) );
2928 mEventViewerDialog->resize( 640, 480 ); 2928 mEventViewerDialog->resize( 640, 480 );
2929 2929
2930 } 2930 }
2931 return mEventViewerDialog; 2931 return mEventViewerDialog;
2932} 2932}
2933void CalendarView::showEvent(Event *event) 2933void CalendarView::showEvent(Event *event)
2934{ 2934{
2935 getEventViewerDialog()->setEvent(event); 2935 getEventViewerDialog()->setEvent(event);
2936 getEventViewerDialog()->showMe(); 2936 getEventViewerDialog()->showMe();
2937} 2937}
2938 2938
2939void CalendarView::showTodo(Todo *event) 2939void CalendarView::showTodo(Todo *event)
2940{ 2940{
2941 getEventViewerDialog()->setTodo(event); 2941 getEventViewerDialog()->setTodo(event);
2942 getEventViewerDialog()->showMe(); 2942 getEventViewerDialog()->showMe();
2943} 2943}
2944void CalendarView::showJournal( Journal *jour ) 2944void CalendarView::showJournal( Journal *jour )
2945{ 2945{
2946 getEventViewerDialog()->setJournal(jour); 2946 getEventViewerDialog()->setJournal(jour);
2947 getEventViewerDialog()->showMe(); 2947 getEventViewerDialog()->showMe();
2948 2948
2949} 2949}
2950// void CalendarView::todoModified (Todo *event, int changed) 2950// void CalendarView::todoModified (Todo *event, int changed)
2951// { 2951// {
2952// // if (mDialogList.find (event) != mDialogList.end ()) { 2952// // if (mDialogList.find (event) != mDialogList.end ()) {
2953// // kdDebug() << "Todo modified and open" << endl; 2953// // kdDebug() << "Todo modified and open" << endl;
2954// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event]; 2954// // KOTodoEditor* temp = (KOTodoEditor *) mDialogList[event];
2955// // temp->modified (changed); 2955// // temp->modified (changed);
2956 2956
2957// // } 2957// // }
2958 2958
2959// mViewManager->updateView(); 2959// mViewManager->updateView();
2960// } 2960// }
2961 2961
2962void CalendarView::appointment_show() 2962void CalendarView::appointment_show()
2963{ 2963{
2964 Event *anEvent = 0; 2964 Event *anEvent = 0;
2965 2965
2966 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2966 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2967 2967
2968 if (mViewManager->currentView()->isEventView()) { 2968 if (mViewManager->currentView()->isEventView()) {
2969 if ( incidence && incidence->type() == "Event" ) { 2969 if ( incidence && incidence->type() == "Event" ) {
2970 anEvent = static_cast<Event *>(incidence); 2970 anEvent = static_cast<Event *>(incidence);
2971 } 2971 }
2972 } 2972 }
2973 2973
2974 if (!anEvent) { 2974 if (!anEvent) {
2975 KNotifyClient::beep(); 2975 KNotifyClient::beep();
2976 return; 2976 return;
2977 } 2977 }
2978 2978
2979 showEvent(anEvent); 2979 showEvent(anEvent);
2980} 2980}
2981 2981
2982void CalendarView::appointment_edit() 2982void CalendarView::appointment_edit()
2983{ 2983{
2984 Event *anEvent = 0; 2984 Event *anEvent = 0;
2985 2985
2986 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 2986 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
2987 2987
2988 if (mViewManager->currentView()->isEventView()) { 2988 if (mViewManager->currentView()->isEventView()) {
2989 if ( incidence && incidence->type() == "Event" ) { 2989 if ( incidence && incidence->type() == "Event" ) {
2990 anEvent = static_cast<Event *>(incidence); 2990 anEvent = static_cast<Event *>(incidence);
2991 } 2991 }
2992 } 2992 }
2993 2993
2994 if (!anEvent) { 2994 if (!anEvent) {
2995 KNotifyClient::beep(); 2995 KNotifyClient::beep();
2996 return; 2996 return;
2997 } 2997 }
2998 2998
2999 editEvent(anEvent); 2999 editEvent(anEvent);
3000} 3000}
3001 3001
3002void CalendarView::appointment_delete() 3002void CalendarView::appointment_delete()
3003{ 3003{
3004 Event *anEvent = 0; 3004 Event *anEvent = 0;
3005 3005
3006 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); 3006 Incidence *incidence = mViewManager->currentView()->selectedIncidences().first();
3007 3007
3008 if (mViewManager->currentView()->isEventView()) { 3008 if (mViewManager->currentView()->isEventView()) {
3009 if ( incidence && incidence->type() == "Event" ) { 3009 if ( incidence && incidence->type() == "Event" ) {
3010 anEvent = static_cast<Event *>(incidence); 3010 anEvent = static_cast<Event *>(incidence);
3011 } 3011 }
3012 } 3012 }
3013 3013
3014 if (!anEvent) { 3014 if (!anEvent) {
3015 KNotifyClient::beep(); 3015 KNotifyClient::beep();
3016 return; 3016 return;
3017 } 3017 }
3018 3018
3019 deleteEvent(anEvent); 3019 deleteEvent(anEvent);
3020} 3020}
3021 3021
3022void CalendarView::todo_resub( Todo * parent, Todo * sub ) 3022void CalendarView::todo_resub( Todo * parent, Todo * sub )
3023{ 3023{
3024 if (!sub) return; 3024 if (!sub) return;
3025 if ( sub->relatedTo() == parent ) 3025 if ( sub->relatedTo() == parent )
3026 return; 3026 return;
3027 sub->setRelatedTo(parent); 3027 sub->setRelatedTo(parent);
3028 sub->updated(); 3028 sub->updated();
3029 setModified(true); 3029 setModified(true);
3030 updateView(); 3030 updateView();
3031} 3031}
3032void CalendarView::todo_unsub(Todo *anTodo ) 3032void CalendarView::todo_unsub(Todo *anTodo )
3033{ 3033{
3034 todo_resub( 0, anTodo ); 3034 todo_resub( 0, anTodo );
3035} 3035}
3036 3036
3037void CalendarView::deleteTodo(Todo *todo) 3037void CalendarView::deleteTodo(Todo *todo)
3038{ 3038{
3039 if (!todo) { 3039 if (!todo) {
3040 KNotifyClient::beep(); 3040 KNotifyClient::beep();
3041 return; 3041 return;
3042 } 3042 }
3043 if (KOPrefs::instance()->mConfirm) { 3043 if (KOPrefs::instance()->mConfirm) {
3044 QString text = todo->summary().left(20); 3044 QString text = todo->summary().left(20);
3045 if (!todo->relations().isEmpty()) { 3045 if (!todo->relations().isEmpty()) {
3046 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!"); 3046 text += i18n("\nhas sub-todos.\nAll completed sub-todos\nwill be deleted as well!");
3047 3047
3048 } 3048 }
3049 switch (msgItemDelete(text)) { 3049 switch (msgItemDelete(text)) {
3050 case KMessageBox::Continue: // OK 3050 case KMessageBox::Continue: // OK
3051 bool deleteT = false; 3051 bool deleteT = false;
3052 if (!todo->relations().isEmpty()) { 3052 if (!todo->relations().isEmpty()) {
3053 deleteT = removeCompletedSubTodos( todo ); 3053 deleteT = removeCompletedSubTodos( todo );
3054 } 3054 }
3055 // deleteT == true: todo already deleted in removeCompletedSubTodos 3055 // deleteT == true: todo already deleted in removeCompletedSubTodos
3056 if ( !deleteT ) { 3056 if ( !deleteT ) {
3057 checkExternalId( todo ); 3057 checkExternalId( todo );
3058 calendar()->deleteTodo(todo); 3058 calendar()->deleteTodo(todo);
3059 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3059 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3060 updateView(); 3060 updateView();
3061 } 3061 }
3062 break; 3062 break;
3063 } // switch 3063 } // switch
3064 } else { 3064 } else {
3065 checkExternalId( todo ); 3065 checkExternalId( todo );
3066 mCalendar->deleteTodo(todo); 3066 mCalendar->deleteTodo(todo);
3067 changeTodoDisplay( todo,KOGlobals::EVENTDELETED ); 3067 changeTodoDisplay( todo,KOGlobals::EVENTDELETED );
3068 updateView(); 3068 updateView();
3069 } 3069 }
3070 3070
3071 emit updateSearchDialog(); 3071 emit updateSearchDialog();
3072} 3072}
3073void CalendarView::deleteJournal(Journal *jour) 3073void CalendarView::deleteJournal(Journal *jour)
3074{ 3074{
3075 if (!jour) { 3075 if (!jour) {
3076 KNotifyClient::beep(); 3076 KNotifyClient::beep();
3077 return; 3077 return;
3078 } 3078 }
3079 if (KOPrefs::instance()->mConfirm) { 3079 if (KOPrefs::instance()->mConfirm) {
3080 switch (msgItemDelete( jour->description().left(20))) { 3080 switch (msgItemDelete( jour->description().left(20))) {
3081 case KMessageBox::Continue: // OK 3081 case KMessageBox::Continue: // OK
3082 calendar()->deleteJournal(jour); 3082 calendar()->deleteJournal(jour);
3083 updateView(); 3083 updateView();
3084 break; 3084 break;
3085 } // switch 3085 } // switch
3086 } else { 3086 } else {
3087 calendar()->deleteJournal(jour);; 3087 calendar()->deleteJournal(jour);;
3088 updateView(); 3088 updateView();
3089 } 3089 }
3090 emit updateSearchDialog(); 3090 emit updateSearchDialog();
3091} 3091}
3092 3092
3093void CalendarView::deleteEvent(Event *anEvent) 3093void CalendarView::deleteEvent(Event *anEvent)
3094{ 3094{
3095 if (!anEvent) { 3095 if (!anEvent) {
3096 KNotifyClient::beep(); 3096 KNotifyClient::beep();
3097 return; 3097 return;
3098 } 3098 }
3099 3099
3100 if (anEvent->recurrence()->doesRecur()) { 3100 if (anEvent->recurrence()->doesRecur()) {
3101 QDate itemDate = mViewManager->currentSelectionDate(); 3101 QDate itemDate = mViewManager->currentSelectionDate();
3102 int km; 3102 int km;
3103 if (!itemDate.isValid()) { 3103 if (!itemDate.isValid()) {
3104 //kdDebug() << "Date Not Valid" << endl; 3104 //kdDebug() << "Date Not Valid" << endl;
3105 if (KOPrefs::instance()->mConfirm) { 3105 if (KOPrefs::instance()->mConfirm) {
3106 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3106 km = KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3107 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"), 3107 i18n("\nThis event recurs\nover multiple dates.\nAre you sure you want\nto delete this event\nand all its recurrences?"),
3108 i18n("KO/Pi Confirmation"),i18n("Delete All")); 3108 i18n("KO/Pi Confirmation"),i18n("Delete All"));
3109 if ( km == KMessageBox::Continue ) 3109 if ( km == KMessageBox::Continue )
3110 km = KMessageBox::No; // No = all below 3110 km = KMessageBox::No; // No = all below
3111 } else 3111 } else
3112 km = KMessageBox::No; 3112 km = KMessageBox::No;
3113 } else { 3113 } else {
3114 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) + 3114 km = KMessageBox::warningYesNoCancel(this,anEvent->summary().left(25) +
3115 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+ 3115 i18n("\nThis event recurs\nover multiple dates.\nDo you want to delete\nall it's recurrences,\nor only the current one on:\n")+
3116 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"), 3116 KGlobal::locale()->formatDate(itemDate)+i18n(" ?\n\nDelete:\n"),
3117 i18n("KO/Pi Confirmation"),i18n("Current"), 3117 i18n("KO/Pi Confirmation"),i18n("Current"),
3118 i18n("All")); 3118 i18n("All"));
3119 } 3119 }
3120 switch(km) { 3120 switch(km) {
3121 3121
3122 case KMessageBox::No: // Continue // all 3122 case KMessageBox::No: // Continue // all
3123 //qDebug("KMessageBox::No "); 3123 //qDebug("KMessageBox::No ");
3124 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3124 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3125 schedule(Scheduler::Cancel,anEvent); 3125 schedule(Scheduler::Cancel,anEvent);
3126 3126
3127 checkExternalId( anEvent); 3127 checkExternalId( anEvent);
3128 mCalendar->deleteEvent(anEvent); 3128 mCalendar->deleteEvent(anEvent);
3129 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED); 3129 changeEventDisplay(anEvent,KOGlobals::EVENTDELETED);
3130 break; 3130 break;
3131 3131
3132 // Disabled because it does not work 3132 // Disabled because it does not work
3133 //#if 0 3133 //#if 0
3134 case KMessageBox::Yes: // just this one 3134 case KMessageBox::Yes: // just this one
3135 //QDate qd = mNavigator->selectedDates().first(); 3135 //QDate qd = mNavigator->selectedDates().first();
3136 //if (!qd.isValid()) { 3136 //if (!qd.isValid()) {
3137 // kdDebug() << "no date selected, or invalid date" << endl; 3137 // kdDebug() << "no date selected, or invalid date" << endl;
3138 // KNotifyClient::beep(); 3138 // KNotifyClient::beep();
3139 // return; 3139 // return;
3140 //} 3140 //}
3141 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1); 3141 //while (!anEvent->recursOn(qd)) qd = qd.addDays(1);
3142 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) { 3142 if (itemDate!=QDate(1,1,1) || itemDate.isValid()) {
3143 anEvent->addExDate(itemDate); 3143 anEvent->addExDate(itemDate);
3144 int duration = anEvent->recurrence()->duration(); 3144 int duration = anEvent->recurrence()->duration();
3145 if ( duration > 0 ) { 3145 if ( duration > 0 ) {
3146 anEvent->recurrence()->setDuration( duration - 1 ); 3146 anEvent->recurrence()->setDuration( duration - 1 );
3147 } 3147 }
3148 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED); 3148 changeEventDisplay(anEvent, KOGlobals::EVENTEDITED);
3149 } 3149 }
3150 break; 3150 break;
3151 //#endif 3151 //#endif
3152 } // switch 3152 } // switch
3153 } else { 3153 } else {
3154 if (KOPrefs::instance()->mConfirm) { 3154 if (KOPrefs::instance()->mConfirm) {
3155 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) + 3155 switch (KMessageBox::warningContinueCancel(this,anEvent->summary().left(25) +
3156 i18n("\nAre you sure you want\nto delete this event?"), 3156 i18n("\nAre you sure you want\nto delete this event?"),
3157 i18n("KO/Pi Confirmation"),i18n("Delete"))) { 3157 i18n("KO/Pi Confirmation"),i18n("Delete"))) {
3158 case KMessageBox::Continue: // OK 3158 case KMessageBox::Continue: // OK
3159 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3159 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3160 schedule(Scheduler::Cancel,anEvent); 3160 schedule(Scheduler::Cancel,anEvent);
3161 checkExternalId( anEvent); 3161 checkExternalId( anEvent);
3162 mCalendar->deleteEvent(anEvent); 3162 mCalendar->deleteEvent(anEvent);
3163 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3163 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3164 break; 3164 break;
3165 } // switch 3165 } // switch
3166 } else { 3166 } else {
3167 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0) 3167 if (anEvent->organizer()==KOPrefs::instance()->email() && anEvent->attendeeCount()>0)
3168 schedule(Scheduler::Cancel,anEvent); 3168 schedule(Scheduler::Cancel,anEvent);
3169 checkExternalId( anEvent); 3169 checkExternalId( anEvent);
3170 mCalendar->deleteEvent(anEvent); 3170 mCalendar->deleteEvent(anEvent);
3171 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); 3171 changeEventDisplay(anEvent, KOGlobals::EVENTDELETED);
3172 } 3172 }
3173 } // if-else 3173 } // if-else
3174 emit updateSearchDialog(); 3174 emit updateSearchDialog();
3175} 3175}
3176 3176
3177bool CalendarView::deleteEvent(const QString &uid) 3177bool CalendarView::deleteEvent(const QString &uid)
3178{ 3178{
3179 Event *ev = mCalendar->event(uid); 3179 Event *ev = mCalendar->event(uid);
3180 if (ev) { 3180 if (ev) {
3181 deleteEvent(ev); 3181 deleteEvent(ev);
3182 return true; 3182 return true;
3183 } else { 3183 } else {
3184 return false; 3184 return false;
3185 } 3185 }
3186} 3186}
3187 3187
3188/*****************************************************************************/ 3188/*****************************************************************************/
3189 3189
3190void CalendarView::action_mail() 3190void CalendarView::action_mail()
3191{ 3191{
3192#ifndef KORG_NOMAIL 3192#ifndef KORG_NOMAIL
3193 KOMailClient mailClient; 3193 KOMailClient mailClient;
3194 3194
3195 Incidence *incidence = currentSelection(); 3195 Incidence *incidence = currentSelection();
3196 3196
3197 if (!incidence) { 3197 if (!incidence) {
3198 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3198 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3199 return; 3199 return;
3200 } 3200 }
3201 if(incidence->attendeeCount() == 0 ) { 3201 if(incidence->attendeeCount() == 0 ) {
3202 KMessageBox::sorry(this, 3202 KMessageBox::sorry(this,
3203 i18n("Can't generate mail:\nNo attendees defined.\n")); 3203 i18n("Can't generate mail:\nNo attendees defined.\n"));
3204 return; 3204 return;
3205 } 3205 }
3206 3206
3207 CalendarLocal cal_tmp; 3207 CalendarLocal cal_tmp;
3208 Event *event = 0; 3208 Event *event = 0;
3209 Event *ev = 0; 3209 Event *ev = 0;
3210 if ( incidence && incidence->type() == "Event" ) { 3210 if ( incidence && incidence->type() == "Event" ) {
3211 event = static_cast<Event *>(incidence); 3211 event = static_cast<Event *>(incidence);
3212 ev = new Event(*event); 3212 ev = new Event(*event);
3213 cal_tmp.addEvent(ev); 3213 cal_tmp.addEvent(ev);
3214 } 3214 }
3215 ICalFormat mForm(); 3215 ICalFormat mForm();
3216 QString attachment = mForm.toString( &cal_tmp ); 3216 QString attachment = mForm.toString( &cal_tmp );
3217 if (ev) delete(ev); 3217 if (ev) delete(ev);
3218 3218
3219 mailClient.mailAttendees(currentSelection(), attachment); 3219 mailClient.mailAttendees(currentSelection(), attachment);
3220 3220
3221#endif 3221#endif
3222 3222
3223#if 0 3223#if 0
3224 Event *anEvent = 0; 3224 Event *anEvent = 0;
3225 if (mViewManager->currentView()->isEventView()) { 3225 if (mViewManager->currentView()->isEventView()) {
3226 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first()); 3226 anEvent = dynamic_cast<Event *>((mViewManager->currentView()->selectedIncidences()).first());
3227 } 3227 }
3228 3228
3229 if (!anEvent) { 3229 if (!anEvent) {
3230 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected.")); 3230 KMessageBox::sorry(this,i18n("Can't generate mail:\nNo event selected."));
3231 return; 3231 return;
3232 } 3232 }
3233 if(anEvent->attendeeCount() == 0 ) { 3233 if(anEvent->attendeeCount() == 0 ) {
3234 KMessageBox::sorry(this, 3234 KMessageBox::sorry(this,
3235 i18n("Can't generate mail:\nNo attendees defined.\n")); 3235 i18n("Can't generate mail:\nNo attendees defined.\n"));
3236 return; 3236 return;
3237 } 3237 }
3238 3238
3239 mailobject.emailEvent(anEvent); 3239 mailobject.emailEvent(anEvent);
3240#endif 3240#endif
3241} 3241}
3242 3242
3243 3243
3244void CalendarView::schedule_publish(Incidence *incidence) 3244void CalendarView::schedule_publish(Incidence *incidence)
3245{ 3245{
3246 Event *event = 0; 3246 Event *event = 0;
3247 Todo *todo = 0; 3247 Todo *todo = 0;
3248 3248
3249 if (incidence == 0) { 3249 if (incidence == 0) {
3250 incidence = mViewManager->currentView()->selectedIncidences().first(); 3250 incidence = mViewManager->currentView()->selectedIncidences().first();
3251 if (incidence == 0) { 3251 if (incidence == 0) {
3252 incidence = mTodoList->selectedIncidences().first(); 3252 incidence = mTodoList->selectedIncidences().first();
3253 } 3253 }
3254 } 3254 }
3255 if ( incidence && incidence->type() == "Event" ) { 3255 if ( incidence && incidence->type() == "Event" ) {
3256 event = static_cast<Event *>(incidence); 3256 event = static_cast<Event *>(incidence);
3257 } else { 3257 } else {
3258 if ( incidence && incidence->type() == "Todo" ) { 3258 if ( incidence && incidence->type() == "Todo" ) {
3259 todo = static_cast<Todo *>(incidence); 3259 todo = static_cast<Todo *>(incidence);
3260 } 3260 }
3261 } 3261 }
3262 3262
3263 if (!event && !todo) { 3263 if (!event && !todo) {
3264 KMessageBox::sorry(this,i18n("No event selected.")); 3264 KMessageBox::sorry(this,i18n("No event selected."));
3265 return; 3265 return;
3266 } 3266 }
3267 3267
3268 PublishDialog *publishdlg = new PublishDialog(); 3268 PublishDialog *publishdlg = new PublishDialog();
3269 if (incidence->attendeeCount()>0) { 3269 if (incidence->attendeeCount()>0) {
3270 QPtrList<Attendee> attendees = incidence->attendees(); 3270 QPtrList<Attendee> attendees = incidence->attendees();
3271 attendees.first(); 3271 attendees.first();
3272 while ( attendees.current()!=0 ) { 3272 while ( attendees.current()!=0 ) {
3273 publishdlg->addAttendee(attendees.current()); 3273 publishdlg->addAttendee(attendees.current());
3274 attendees.next(); 3274 attendees.next();
3275 } 3275 }
3276 } 3276 }
3277 bool send = true; 3277 bool send = true;
3278 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) { 3278 if ( KOPrefs::instance()->mMailClient == KOPrefs::MailClientSendmail ) {
3279 if ( publishdlg->exec() != QDialog::Accepted ) 3279 if ( publishdlg->exec() != QDialog::Accepted )
3280 send = false; 3280 send = false;
3281 } 3281 }
3282 if ( send ) { 3282 if ( send ) {
3283 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3283 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3284 if ( event ) { 3284 if ( event ) {
3285 Event *ev = new Event(*event); 3285 Event *ev = new Event(*event);
3286 ev->registerObserver(0); 3286 ev->registerObserver(0);
3287 ev->clearAttendees(); 3287 ev->clearAttendees();
3288 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3288 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3289 delete(ev); 3289 delete(ev);
3290 } 3290 }
3291 } else { 3291 } else {
3292 if ( todo ) { 3292 if ( todo ) {
3293 Todo *ev = new Todo(*todo); 3293 Todo *ev = new Todo(*todo);
3294 ev->registerObserver(0); 3294 ev->registerObserver(0);
3295 ev->clearAttendees(); 3295 ev->clearAttendees();
3296 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) { 3296 if (!dlg->addMessage(ev,Scheduler::Publish,publishdlg->addresses())) {
3297 delete(ev); 3297 delete(ev);
3298 } 3298 }
3299 } 3299 }
3300 } 3300 }
3301 } 3301 }
3302 delete publishdlg; 3302 delete publishdlg;
3303} 3303}
3304 3304
3305void CalendarView::schedule_request(Incidence *incidence) 3305void CalendarView::schedule_request(Incidence *incidence)
3306{ 3306{
3307 schedule(Scheduler::Request,incidence); 3307 schedule(Scheduler::Request,incidence);
3308} 3308}
3309 3309
3310void CalendarView::schedule_refresh(Incidence *incidence) 3310void CalendarView::schedule_refresh(Incidence *incidence)
3311{ 3311{
3312 schedule(Scheduler::Refresh,incidence); 3312 schedule(Scheduler::Refresh,incidence);
3313} 3313}
3314 3314
3315void CalendarView::schedule_cancel(Incidence *incidence) 3315void CalendarView::schedule_cancel(Incidence *incidence)
3316{ 3316{
3317 schedule(Scheduler::Cancel,incidence); 3317 schedule(Scheduler::Cancel,incidence);
3318} 3318}
3319 3319
3320void CalendarView::schedule_add(Incidence *incidence) 3320void CalendarView::schedule_add(Incidence *incidence)
3321{ 3321{
3322 schedule(Scheduler::Add,incidence); 3322 schedule(Scheduler::Add,incidence);
3323} 3323}
3324 3324
3325void CalendarView::schedule_reply(Incidence *incidence) 3325void CalendarView::schedule_reply(Incidence *incidence)
3326{ 3326{
3327 schedule(Scheduler::Reply,incidence); 3327 schedule(Scheduler::Reply,incidence);
3328} 3328}
3329 3329
3330void CalendarView::schedule_counter(Incidence *incidence) 3330void CalendarView::schedule_counter(Incidence *incidence)
3331{ 3331{
3332 schedule(Scheduler::Counter,incidence); 3332 schedule(Scheduler::Counter,incidence);
3333} 3333}
3334 3334
3335void CalendarView::schedule_declinecounter(Incidence *incidence) 3335void CalendarView::schedule_declinecounter(Incidence *incidence)
3336{ 3336{
3337 schedule(Scheduler::Declinecounter,incidence); 3337 schedule(Scheduler::Declinecounter,incidence);
3338} 3338}
3339 3339
3340void CalendarView::schedule_publish_freebusy(int daysToPublish) 3340void CalendarView::schedule_publish_freebusy(int daysToPublish)
3341{ 3341{
3342 QDateTime start = QDateTime::currentDateTime(); 3342 QDateTime start = QDateTime::currentDateTime();
3343 QDateTime end = start.addDays(daysToPublish); 3343 QDateTime end = start.addDays(daysToPublish);
3344 3344
3345 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end); 3345 FreeBusy *freebusy = new FreeBusy(mCalendar, start, end);
3346 freebusy->setOrganizer(KOPrefs::instance()->email()); 3346 freebusy->setOrganizer(KOPrefs::instance()->email());
3347 3347
3348 3348
3349 PublishDialog *publishdlg = new PublishDialog(); 3349 PublishDialog *publishdlg = new PublishDialog();
3350 if ( publishdlg->exec() == QDialog::Accepted ) { 3350 if ( publishdlg->exec() == QDialog::Accepted ) {
3351 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3351 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3352 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) { 3352 if (!dlg->addMessage(freebusy,Scheduler::Publish,publishdlg->addresses())) {
3353 delete(freebusy); 3353 delete(freebusy);
3354 } 3354 }
3355 } 3355 }
3356 delete publishdlg; 3356 delete publishdlg;
3357} 3357}
3358 3358
3359void CalendarView::schedule(Scheduler::Method method, Incidence *incidence) 3359void CalendarView::schedule(Scheduler::Method method, Incidence *incidence)
3360{ 3360{
3361 Event *event = 0; 3361 Event *event = 0;
3362 Todo *todo = 0; 3362 Todo *todo = 0;
3363 3363
3364 if (incidence == 0) { 3364 if (incidence == 0) {
3365 incidence = mViewManager->currentView()->selectedIncidences().first(); 3365 incidence = mViewManager->currentView()->selectedIncidences().first();
3366 if (incidence == 0) { 3366 if (incidence == 0) {
3367 incidence = mTodoList->selectedIncidences().first(); 3367 incidence = mTodoList->selectedIncidences().first();
3368 } 3368 }
3369 } 3369 }
3370 if ( incidence && incidence->type() == "Event" ) { 3370 if ( incidence && incidence->type() == "Event" ) {
3371 event = static_cast<Event *>(incidence); 3371 event = static_cast<Event *>(incidence);
3372 } 3372 }
3373 if ( incidence && incidence->type() == "Todo" ) { 3373 if ( incidence && incidence->type() == "Todo" ) {
3374 todo = static_cast<Todo *>(incidence); 3374 todo = static_cast<Todo *>(incidence);
3375 } 3375 }
3376 3376
3377 if (!event && !todo) { 3377 if (!event && !todo) {
3378 KMessageBox::sorry(this,i18n("No event selected.")); 3378 KMessageBox::sorry(this,i18n("No event selected."));
3379 return; 3379 return;
3380 } 3380 }
3381 3381
3382 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) { 3382 if( incidence->attendeeCount() == 0 && method != Scheduler::Publish ) {
3383 KMessageBox::sorry(this,i18n("The event has no attendees.")); 3383 KMessageBox::sorry(this,i18n("The event has no attendees."));
3384 return; 3384 return;
3385 } 3385 }
3386 3386
3387 Event *ev = 0; 3387 Event *ev = 0;
3388 if (event) ev = new Event(*event); 3388 if (event) ev = new Event(*event);
3389 Todo *to = 0; 3389 Todo *to = 0;
3390 if (todo) to = new Todo(*todo); 3390 if (todo) to = new Todo(*todo);
3391 3391
3392 if (method == Scheduler::Reply || method == Scheduler::Refresh) { 3392 if (method == Scheduler::Reply || method == Scheduler::Refresh) {
3393 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email()); 3393 Attendee *me = incidence->attendeeByMails(KOPrefs::instance()->mAdditionalMails,KOPrefs::instance()->email());
3394 if (!me) { 3394 if (!me) {
3395 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails.")); 3395 KMessageBox::sorry(this,i18n("Could not find your attendee entry.\nPlease check the emails."));
3396 return; 3396 return;
3397 } 3397 }
3398 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) { 3398 if (me->status()==Attendee::NeedsAction && me->RSVP() && method==Scheduler::Reply) {
3399 StatusDialog *statdlg = new StatusDialog(this); 3399 StatusDialog *statdlg = new StatusDialog(this);
3400 if (!statdlg->exec()==QDialog::Accepted) return; 3400 if (!statdlg->exec()==QDialog::Accepted) return;
3401 me->setStatus( statdlg->status() ); 3401 me->setStatus( statdlg->status() );
3402 delete(statdlg); 3402 delete(statdlg);
3403 } 3403 }
3404 Attendee *menew = new Attendee(*me); 3404 Attendee *menew = new Attendee(*me);
3405 if (ev) { 3405 if (ev) {
3406 ev->clearAttendees(); 3406 ev->clearAttendees();
3407 ev->addAttendee(menew,false); 3407 ev->addAttendee(menew,false);
3408 } else { 3408 } else {
3409 if (to) { 3409 if (to) {
3410 todo->clearAttendees(); 3410 todo->clearAttendees();
3411 todo->addAttendee(menew,false); 3411 todo->addAttendee(menew,false);
3412 } 3412 }
3413 } 3413 }
3414 } 3414 }
3415 3415
3416 OutgoingDialog *dlg = mDialogManager->outgoingDialog(); 3416 OutgoingDialog *dlg = mDialogManager->outgoingDialog();
3417 if (ev) { 3417 if (ev) {
3418 if ( !dlg->addMessage(ev,method) ) delete(ev); 3418 if ( !dlg->addMessage(ev,method) ) delete(ev);
3419 } else { 3419 } else {
3420 if (to) { 3420 if (to) {
3421 if ( !dlg->addMessage(to,method) ) delete(to); 3421 if ( !dlg->addMessage(to,method) ) delete(to);
3422 } 3422 }
3423 } 3423 }
3424} 3424}
3425 3425
3426void CalendarView::openAddressbook() 3426void CalendarView::openAddressbook()
3427{ 3427{
3428 KRun::runCommand("kaddressbook"); 3428 KRun::runCommand("kaddressbook");
3429} 3429}
3430 3430
3431void CalendarView::setModified(bool modified) 3431void CalendarView::setModified(bool modified)
3432{ 3432{
3433 if ( modified ) 3433 if ( modified )
3434 emit signalmodified(); 3434 emit signalmodified();
3435 if (mModified != modified) { 3435 if (mModified != modified) {
3436 mModified = modified; 3436 mModified = modified;
3437 emit modifiedChanged(mModified); 3437 emit modifiedChanged(mModified);
3438 } 3438 }
3439} 3439}
3440 3440
3441bool CalendarView::isReadOnly() 3441bool CalendarView::isReadOnly()
3442{ 3442{
3443 return mReadOnly; 3443 return mReadOnly;
3444} 3444}
3445 3445
3446void CalendarView::setReadOnly(bool readOnly) 3446void CalendarView::setReadOnly(bool readOnly)
3447{ 3447{
3448 if (mReadOnly != readOnly) { 3448 if (mReadOnly != readOnly) {
3449 mReadOnly = readOnly; 3449 mReadOnly = readOnly;
3450 emit readOnlyChanged(mReadOnly); 3450 emit readOnlyChanged(mReadOnly);
3451 } 3451 }
3452} 3452}
3453 3453
3454bool CalendarView::isModified() 3454bool CalendarView::isModified()
3455{ 3455{
3456 return mModified; 3456 return mModified;
3457} 3457}
3458void CalendarView::slotprintSelInc() 3458void CalendarView::slotprintSelInc()
3459{ 3459{
3460 if ( currentSelection() == 0 ) { 3460 if ( currentSelection() == 0 ) {
3461 KMessageBox::sorry(this,i18n("There is nothing selected!")); 3461 KMessageBox::sorry(this,i18n("There is nothing selected!"));
3462 return; 3462 return;
3463 } 3463 }
3464 showIncidence(); 3464 showIncidence();
3465 getEventViewerDialog()->print(); 3465 getEventViewerDialog()->print();
3466 3466
3467} 3467}
3468void CalendarView::printSetup() 3468void CalendarView::printSetup()
3469{ 3469{
3470#ifndef KORG_NOPRINTER 3470#ifndef KORG_NOPRINTER
3471 createPrinter(); 3471 createPrinter();
3472 3472
3473 mCalPrinter->setupPrinter(); 3473 mCalPrinter->setupPrinter();
3474#endif 3474#endif
3475} 3475}
3476 3476
3477void CalendarView::print() 3477void CalendarView::print()
3478{ 3478{
3479#ifndef KORG_NOPRINTER 3479#ifndef KORG_NOPRINTER
3480 createPrinter(); 3480 createPrinter();
3481 3481
3482 DateList tmpDateList = mNavigator->selectedDates(); 3482 DateList tmpDateList = mNavigator->selectedDates();
3483 mCalPrinter->print(CalPrinter::Month, 3483 mCalPrinter->print(CalPrinter::Month,
3484 tmpDateList.first(), tmpDateList.last()); 3484 tmpDateList.first(), tmpDateList.last());
3485#endif 3485#endif
3486} 3486}
3487 3487
3488void CalendarView::printPreview() 3488void CalendarView::printPreview()
3489{ 3489{
3490#ifndef KORG_NOPRINTER 3490#ifndef KORG_NOPRINTER
3491 kdDebug() << "CalendarView::printPreview()" << endl; 3491 kdDebug() << "CalendarView::printPreview()" << endl;
3492 3492
3493 createPrinter(); 3493 createPrinter();
3494 3494
3495 DateList tmpDateList = mNavigator->selectedDates(); 3495 DateList tmpDateList = mNavigator->selectedDates();
3496 3496
3497 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(), 3497 mViewManager->currentView()->printPreview(mCalPrinter,tmpDateList.first(),
3498 tmpDateList.last()); 3498 tmpDateList.last());
3499#endif 3499#endif
3500} 3500}
3501 3501
3502void CalendarView::exportICalendar() 3502void CalendarView::exportICalendar()
3503{ 3503{
3504 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this); 3504 QString filename = KFileDialog::getSaveFileName("icalout.ics",i18n("*.ics|ICalendars"),this);
3505 3505
3506 // Force correct extension 3506 // Force correct extension
3507 if (filename.right(4) != ".ics") filename += ".ics"; 3507 if (filename.right(4) != ".ics") filename += ".ics";
3508 3508
3509 FileStorage storage( mCalendar, filename, new ICalFormat() ); 3509 FileStorage storage( mCalendar, filename, new ICalFormat() );
3510 storage.save(); 3510 storage.save();
3511} 3511}
3512 3512
3513bool CalendarView::exportVCalendar( QString filename ) 3513bool CalendarView::exportVCalendar( QString filename )
3514{ 3514{
3515 if (mCalendar->journals().count() > 0) { 3515 if (mCalendar->journals().count() > 0) {
3516 int result = KMessageBox::warningContinueCancel(this, 3516 int result = KMessageBox::warningContinueCancel(this,
3517 i18n("The journal entries can not be\nexported to a vCalendar file."), 3517 i18n("The journal entries can not be\nexported to a vCalendar file."),
3518 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"), 3518 i18n("Data Loss Warning"),i18n("Proceed"),i18n("Cancel"),
3519 true); 3519 true);
3520 if (result != KMessageBox::Continue) return false; 3520 if (result != KMessageBox::Continue) return false;
3521 } 3521 }
3522 3522
3523 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this); 3523 //QString filename = KFileDialog::getSaveFileName("vcalout.vcs",i18n("*.vcs|VCalendars"),this);
3524 3524
3525 // Force correct extension 3525 // Force correct extension
3526 if (filename.right(4) != ".vcs") filename += ".vcs"; 3526 if (filename.right(4) != ".vcs") filename += ".vcs";
3527 3527
3528 FileStorage storage( mCalendar, filename, new VCalFormat ); 3528 FileStorage storage( mCalendar, filename, new VCalFormat );
3529 return storage.save(); 3529 return storage.save();
3530 3530
3531} 3531}
3532 3532
3533void CalendarView::eventUpdated(Incidence *) 3533void CalendarView::eventUpdated(Incidence *)
3534{ 3534{
3535 setModified(); 3535 setModified();
3536 // Don't call updateView here. The code, which has caused the update of the 3536 // Don't call updateView here. The code, which has caused the update of the
3537 // event is responsible for updating the view. 3537 // event is responsible for updating the view.
3538 // updateView(); 3538 // updateView();
3539} 3539}
3540 3540
3541void CalendarView::adaptNavigationUnits() 3541void CalendarView::adaptNavigationUnits()
3542{ 3542{
3543 if (mViewManager->currentView()->isEventView()) { 3543 if (mViewManager->currentView()->isEventView()) {
3544 int days = mViewManager->currentView()->currentDateCount(); 3544 int days = mViewManager->currentView()->currentDateCount();
3545 if (days == 1) { 3545 if (days == 1) {
3546 emit changeNavStringPrev(i18n("&Previous Day")); 3546 emit changeNavStringPrev(i18n("&Previous Day"));
3547 emit changeNavStringNext(i18n("&Next Day")); 3547 emit changeNavStringNext(i18n("&Next Day"));
3548 } else { 3548 } else {
3549 emit changeNavStringPrev(i18n("&Previous Week")); 3549 emit changeNavStringPrev(i18n("&Previous Week"));
3550 emit changeNavStringNext(i18n("&Next Week")); 3550 emit changeNavStringNext(i18n("&Next Week"));
3551 } 3551 }
3552 } 3552 }
3553} 3553}
3554 3554
3555void CalendarView::processMainViewSelection( Incidence *incidence ) 3555void CalendarView::processMainViewSelection( Incidence *incidence )
3556{ 3556{
3557 if ( incidence ) mTodoList->clearSelection(); 3557 if ( incidence ) mTodoList->clearSelection();
3558 processIncidenceSelection( incidence ); 3558 processIncidenceSelection( incidence );
3559} 3559}
3560 3560
3561void CalendarView::processTodoListSelection( Incidence *incidence ) 3561void CalendarView::processTodoListSelection( Incidence *incidence )
3562{ 3562{
3563 if ( incidence && mViewManager->currentView() ) { 3563 if ( incidence && mViewManager->currentView() ) {
3564 mViewManager->currentView()->clearSelection(); 3564 mViewManager->currentView()->clearSelection();
3565 } 3565 }
3566 processIncidenceSelection( incidence ); 3566 processIncidenceSelection( incidence );
3567} 3567}
3568 3568
3569void CalendarView::processIncidenceSelection( Incidence *incidence ) 3569void CalendarView::processIncidenceSelection( Incidence *incidence )
3570{ 3570{
3571 if ( incidence == mSelectedIncidence ) return; 3571 if ( incidence == mSelectedIncidence ) return;
3572 3572
3573 mSelectedIncidence = incidence; 3573 mSelectedIncidence = incidence;
3574 3574
3575 emit incidenceSelected( mSelectedIncidence ); 3575 emit incidenceSelected( mSelectedIncidence );
3576 3576
3577 if ( incidence && incidence->type() == "Event" ) { 3577 if ( incidence && incidence->type() == "Event" ) {
3578 Event *event = static_cast<Event *>( incidence ); 3578 Event *event = static_cast<Event *>( incidence );
3579 if ( event->organizer() == KOPrefs::instance()->email() ) { 3579 if ( event->organizer() == KOPrefs::instance()->email() ) {
3580 emit organizerEventsSelected( true ); 3580 emit organizerEventsSelected( true );
3581 } else { 3581 } else {
3582 emit organizerEventsSelected(false); 3582 emit organizerEventsSelected(false);
3583 } 3583 }
3584 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3584 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3585 KOPrefs::instance()->email() ) ) { 3585 KOPrefs::instance()->email() ) ) {
3586 emit groupEventsSelected( true ); 3586 emit groupEventsSelected( true );
3587 } else { 3587 } else {
3588 emit groupEventsSelected(false); 3588 emit groupEventsSelected(false);
3589 } 3589 }
3590 return; 3590 return;
3591 } else { 3591 } else {
3592 if ( incidence && incidence->type() == "Todo" ) { 3592 if ( incidence && incidence->type() == "Todo" ) {
3593 emit todoSelected( true ); 3593 emit todoSelected( true );
3594 Todo *event = static_cast<Todo *>( incidence ); 3594 Todo *event = static_cast<Todo *>( incidence );
3595 if ( event->organizer() == KOPrefs::instance()->email() ) { 3595 if ( event->organizer() == KOPrefs::instance()->email() ) {
3596 emit organizerEventsSelected( true ); 3596 emit organizerEventsSelected( true );
3597 } else { 3597 } else {
3598 emit organizerEventsSelected(false); 3598 emit organizerEventsSelected(false);
3599 } 3599 }
3600 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails, 3600 if (event->attendeeByMails( KOPrefs::instance()->mAdditionalMails,
3601 KOPrefs::instance()->email() ) ) { 3601 KOPrefs::instance()->email() ) ) {
3602 emit groupEventsSelected( true ); 3602 emit groupEventsSelected( true );
3603 } else { 3603 } else {
3604 emit groupEventsSelected(false); 3604 emit groupEventsSelected(false);
3605 } 3605 }
3606 return; 3606 return;
3607 } else { 3607 } else {
3608 emit todoSelected( false ); 3608 emit todoSelected( false );
3609 emit organizerEventsSelected(false); 3609 emit organizerEventsSelected(false);
3610 emit groupEventsSelected(false); 3610 emit groupEventsSelected(false);
3611 } 3611 }
3612 return; 3612 return;
3613 } 3613 }
3614 3614
3615 /* if ( incidence && incidence->type() == "Todo" ) { 3615 /* if ( incidence && incidence->type() == "Todo" ) {
3616 emit todoSelected( true ); 3616 emit todoSelected( true );
3617 } else { 3617 } else {
3618 emit todoSelected( false ); 3618 emit todoSelected( false );
3619 }*/ 3619 }*/
3620} 3620}
3621 3621
3622 3622
3623void CalendarView::checkClipboard() 3623void CalendarView::checkClipboard()
3624{ 3624{
3625#ifndef KORG_NODND 3625#ifndef KORG_NODND
3626 if (ICalDrag::canDecode(QApplication::clipboard()->data())) { 3626 if (ICalDrag::canDecode(QApplication::clipboard()->data())) {
3627 emit pasteEnabled(true); 3627 emit pasteEnabled(true);
3628 } else { 3628 } else {
3629 emit pasteEnabled(false); 3629 emit pasteEnabled(false);
3630 } 3630 }
3631#endif 3631#endif
3632} 3632}
3633 3633
3634void CalendarView::showDates(const DateList &selectedDates) 3634void CalendarView::showDates(const DateList &selectedDates)
3635{ 3635{
3636 // kdDebug() << "CalendarView::selectDates()" << endl; 3636 // kdDebug() << "CalendarView::selectDates()" << endl;
3637 3637
3638 3638
3639 if ( !mBlockShowDates ) { 3639 if ( !mBlockShowDates ) {
3640 if ( mViewManager->currentView() ) { 3640 if ( mViewManager->currentView() ) {
3641 updateView( selectedDates.first(), selectedDates.last() ); 3641 updateView( selectedDates.first(), selectedDates.last() );
3642 } else { 3642 } else {
3643 mViewManager->showAgendaView(); 3643 mViewManager->showAgendaView();
3644 } 3644 }
3645 } 3645 }
3646 3646
3647 QDate date = selectedDates.first(); 3647 QDate date = selectedDates.first();
3648 if ( ! date.isValid() ) { 3648 if ( ! date.isValid() ) {
3649 topLevelWidget()->setCaption(""); 3649 topLevelWidget()->setCaption("");
3650 return; 3650 return;
3651 } 3651 }
3652 3652
3653 QString selDates; 3653 QString selDates;
3654 selDates = KGlobal::locale()->formatDate( date, true); 3654 selDates = KGlobal::locale()->formatDate( date, true);
3655 if (selectedDates.first() < selectedDates.last() ) 3655 if (selectedDates.first() < selectedDates.last() )
3656 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true); 3656 selDates += " - " + KGlobal::locale()->formatDate( selectedDates.last(),true);
3657 else { 3657 else {
3658 QString addString; 3658 QString addString;
3659 if ( date == QDateTime::currentDateTime().date() ) 3659 if ( date == QDateTime::currentDateTime().date() )
3660 addString = i18n("Today"); 3660 addString = i18n("Today");
3661 else if ( date == QDateTime::currentDateTime().date().addDays(1) ) 3661 else if ( date == QDateTime::currentDateTime().date().addDays(1) )
3662 addString = i18n("Tomorrow"); 3662 addString = i18n("Tomorrow");
3663 else if ( date == QDateTime::currentDateTime().date().addDays(-1) ) 3663 else if ( date == QDateTime::currentDateTime().date().addDays(-1) )
3664 addString = i18n("Yesterday"); 3664 addString = i18n("Yesterday");
3665 else if ( date == QDateTime::currentDateTime().date().addDays(-2) ) 3665 else if ( date == QDateTime::currentDateTime().date().addDays(-2) )
3666 addString = i18n("Day before yesterday"); 3666 addString = i18n("Day before yesterday");
3667 else if ( date == QDateTime::currentDateTime().date().addDays(2) ) 3667 else if ( date == QDateTime::currentDateTime().date().addDays(2) )
3668 addString = i18n("Day after tomorrow"); 3668 addString = i18n("Day after tomorrow");
3669 if ( !addString.isEmpty() ) { 3669 if ( !addString.isEmpty() ) {
3670 topLevelWidget()->setCaption( addString+", " + selDates ); 3670 topLevelWidget()->setCaption( addString+", " + selDates );
3671 return; 3671 return;
3672 } 3672 }
3673 } 3673 }
3674 topLevelWidget()->setCaption( i18n("Dates: ") + selDates ); 3674 topLevelWidget()->setCaption( i18n("Dates: ") + selDates );
3675 3675
3676} 3676}
3677 3677
3678QPtrList<CalFilter> CalendarView::filters() 3678QPtrList<CalFilter> CalendarView::filters()
3679{ 3679{
3680 return mFilters; 3680 return mFilters;
3681 3681
3682} 3682}
3683void CalendarView::editFilters() 3683void CalendarView::editFilters()
3684{ 3684{
3685 // kdDebug() << "CalendarView::editFilters()" << endl; 3685 // kdDebug() << "CalendarView::editFilters()" << endl;
3686 3686
3687 CalFilter *filter = mFilters.first(); 3687 CalFilter *filter = mFilters.first();
3688 while(filter) { 3688 while(filter) {
3689 kdDebug() << " Filter: " << filter->name() << endl; 3689 kdDebug() << " Filter: " << filter->name() << endl;
3690 filter = mFilters.next(); 3690 filter = mFilters.next();
3691 } 3691 }
3692 3692
3693 mDialogManager->showFilterEditDialog(&mFilters); 3693 mDialogManager->showFilterEditDialog(&mFilters);
3694} 3694}
3695void CalendarView::toggleFilter() 3695void CalendarView::toggleFilter()
3696{ 3696{
3697 showFilter(! mFilterView->isVisible()); 3697 showFilter(! mFilterView->isVisible());
3698} 3698}
3699 3699
3700KOFilterView *CalendarView::filterView() 3700KOFilterView *CalendarView::filterView()
3701{ 3701{
3702 return mFilterView; 3702 return mFilterView;
3703} 3703}
3704void CalendarView::selectFilter( int fil ) 3704void CalendarView::selectFilter( int fil )
3705{ 3705{
3706 mFilterView->setSelectedFilter( fil ); 3706 mFilterView->setSelectedFilter( fil );
3707} 3707}
3708void CalendarView::showFilter(bool visible) 3708void CalendarView::showFilter(bool visible)
3709{ 3709{
3710 if (visible) mFilterView->show(); 3710 if (visible) mFilterView->show();
3711 else mFilterView->hide(); 3711 else mFilterView->hide();
3712} 3712}
3713void CalendarView::toggleFilerEnabled( ) 3713void CalendarView::toggleFilerEnabled( )
3714{ 3714{
3715 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() ); 3715 mFilterView->setFiltersEnabled ( !mFilterView->filtersEnabled() );
3716 if ( !mFilterView->filtersEnabled() ) 3716 if ( !mFilterView->filtersEnabled() )
3717 topLevelWidget()->setCaption( i18n("Filter disabled ") ); 3717 topLevelWidget()->setCaption( i18n("Filter disabled ") );
3718 3718
3719} 3719}
3720void CalendarView::updateFilter() 3720void CalendarView::updateFilter()
3721{ 3721{
3722 CalFilter *filter = mFilterView->selectedFilter(); 3722 CalFilter *filter = mFilterView->selectedFilter();
3723 if (filter) { 3723 if (filter) {
3724 QString mess; 3724 QString mess;
3725 if (mFilterView->filtersEnabled()) { 3725 if (mFilterView->filtersEnabled()) {
3726 mess = i18n("Filter selected: ")+filter->name(); 3726 mess = i18n("Filter selected: ")+filter->name();
3727 filter->setEnabled(true); 3727 filter->setEnabled(true);
3728 } 3728 }
3729 else filter->setEnabled(false); 3729 else filter->setEnabled(false);
3730 mCalendar->setFilter(filter); 3730 mCalendar->setFilter(filter);
3731 updateView(); 3731 updateView();
3732 if ( !mess.isEmpty() ) 3732 if ( !mess.isEmpty() )
3733 topLevelWidget()->setCaption( mess ); 3733 topLevelWidget()->setCaption( mess );
3734 3734
3735 } 3735 }
3736} 3736}
3737 3737
3738void CalendarView::filterEdited() 3738void CalendarView::filterEdited()
3739{ 3739{
3740 mFilterView->updateFilters(); 3740 mFilterView->updateFilters();
3741 updateFilter(); 3741 updateFilter();
3742 writeSettings(); 3742 writeSettings();
3743} 3743}
3744 3744
3745 3745
3746void CalendarView::takeOverEvent() 3746void CalendarView::takeOverEvent()
3747{ 3747{
3748 Incidence *incidence = currentSelection(); 3748 Incidence *incidence = currentSelection();
3749 3749
3750 if (!incidence) return; 3750 if (!incidence) return;
3751 3751
3752 incidence->setOrganizer(KOPrefs::instance()->email()); 3752 incidence->setOrganizer(KOPrefs::instance()->email());
3753 incidence->recreate(); 3753 incidence->recreate();
3754 incidence->setReadOnly(false); 3754 incidence->setReadOnly(false);
3755 3755
3756 updateView(); 3756 updateView();
3757} 3757}
3758 3758
3759void CalendarView::takeOverCalendar() 3759void CalendarView::takeOverCalendar()
3760{ 3760{
3761 // TODO: Create Calendar::allIncidences() function and use it here 3761 // TODO: Create Calendar::allIncidences() function and use it here
3762 3762
3763 QPtrList<Event> events = mCalendar->events(); 3763 QPtrList<Event> events = mCalendar->events();
3764 for(uint i=0; i<events.count(); ++i) { 3764 for(uint i=0; i<events.count(); ++i) {
3765 events.at(i)->setOrganizer(KOPrefs::instance()->email()); 3765 events.at(i)->setOrganizer(KOPrefs::instance()->email());
3766 events.at(i)->recreate(); 3766 events.at(i)->recreate();
3767 events.at(i)->setReadOnly(false); 3767 events.at(i)->setReadOnly(false);
3768 } 3768 }
3769 3769
3770 QPtrList<Todo> todos = mCalendar->todos(); 3770 QPtrList<Todo> todos = mCalendar->todos();
3771 for(uint i=0; i<todos.count(); ++i) { 3771 for(uint i=0; i<todos.count(); ++i) {
3772 todos.at(i)->setOrganizer(KOPrefs::instance()->email()); 3772 todos.at(i)->setOrganizer(KOPrefs::instance()->email());
3773 todos.at(i)->recreate(); 3773 todos.at(i)->recreate();
3774 todos.at(i)->setReadOnly(false); 3774 todos.at(i)->setReadOnly(false);
3775 } 3775 }
3776 3776
3777 QPtrList<Journal> journals = mCalendar->journals(); 3777 QPtrList<Journal> journals = mCalendar->journals();
3778 for(uint i=0; i<journals.count(); ++i) { 3778 for(uint i=0; i<journals.count(); ++i) {
3779 journals.at(i)->setOrganizer(KOPrefs::instance()->email()); 3779 journals.at(i)->setOrganizer(KOPrefs::instance()->email());
3780 journals.at(i)->recreate(); 3780 journals.at(i)->recreate();
3781 journals.at(i)->setReadOnly(false); 3781 journals.at(i)->setReadOnly(false);
3782 } 3782 }
3783 3783
3784 updateView(); 3784 updateView();
3785} 3785}
3786 3786
3787void CalendarView::showIntro() 3787void CalendarView::showIntro()
3788{ 3788{
3789 kdDebug() << "To be implemented." << endl; 3789 kdDebug() << "To be implemented." << endl;
3790} 3790}
3791 3791
3792QWidgetStack *CalendarView::viewStack() 3792QWidgetStack *CalendarView::viewStack()
3793{ 3793{
3794 return mRightFrame; 3794 return mRightFrame;
3795} 3795}
3796 3796
3797QWidget *CalendarView::leftFrame() 3797QWidget *CalendarView::leftFrame()
3798{ 3798{
3799 return ( QWidget *)mLeftFrame; 3799 return ( QWidget *)mLeftFrame;
3800} 3800}
3801 3801
3802DateNavigator *CalendarView::dateNavigator() 3802DateNavigator *CalendarView::dateNavigator()
3803{ 3803{
3804 return mNavigator; 3804 return mNavigator;
3805} 3805}
3806 3806
3807KDateNavigator* CalendarView::dateNavigatorWidget() 3807KDateNavigator* CalendarView::dateNavigatorWidget()
3808{ 3808{
3809 return mDateNavigator->navigatorView(); 3809 return mDateNavigator->navigatorView();
3810} 3810}
3811void CalendarView::toggleDateNavigatorWidget() 3811void CalendarView::toggleDateNavigatorWidget()
3812{ 3812{
3813 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ; 3813 KOPrefs::instance()->mShowDateNavigator = !KOPrefs::instance()->mShowDateNavigator ;
3814 3814
3815 if (!KOPrefs::instance()->mShowDateNavigator ) 3815 if (!KOPrefs::instance()->mShowDateNavigator )
3816 mDateNavigator->hide(); 3816 mDateNavigator->hide();
3817 else 3817 else
3818 mDateNavigator->show(); 3818 mDateNavigator->show();
3819} 3819}
3820void CalendarView::addView(KOrg::BaseView *view) 3820void CalendarView::addView(KOrg::BaseView *view)
3821{ 3821{
3822 mViewManager->addView(view); 3822 mViewManager->addView(view);
3823} 3823}
3824 3824
3825void CalendarView::showView(KOrg::BaseView *view) 3825void CalendarView::showView(KOrg::BaseView *view)
3826{ 3826{
3827 mViewManager->showView(view, mLeftFrame->isVisible()); 3827 mViewManager->showView(view, mLeftFrame->isVisible());
3828} 3828}
3829 3829
3830Incidence *CalendarView::currentSelection() 3830Incidence *CalendarView::currentSelection()
3831{ 3831{
3832 return mViewManager->currentSelection(); 3832 return mViewManager->currentSelection();
3833} 3833}
3834void CalendarView::toggleAllDaySize() 3834void CalendarView::toggleAllDaySize()
3835{ 3835{
3836 /* 3836 /*
3837 if ( KOPrefs::instance()->mAllDaySize > 47 ) 3837 if ( KOPrefs::instance()->mAllDaySize > 47 )
3838 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2; 3838 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize /2;
3839 else 3839 else
3840 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2; 3840 KOPrefs::instance()->mAllDaySize = KOPrefs::instance()->mAllDaySize *2;
3841 */ 3841 */
3842 viewManager()->agendaView()->toggleAllDay(); 3842 viewManager()->agendaView()->toggleAllDay();
3843} 3843}
3844void CalendarView::toggleExpand() 3844void CalendarView::toggleExpand()
3845{ 3845{
3846 // if ( mLeftFrame->isHidden() ) { 3846 // if ( mLeftFrame->isHidden() ) {
3847 // mLeftFrame->show(); 3847 // mLeftFrame->show();
3848 // emit calendarViewExpanded( false ); 3848 // emit calendarViewExpanded( false );
3849 // } else { 3849 // } else {
3850 // mLeftFrame->hide(); 3850 // mLeftFrame->hide();
3851 // emit calendarViewExpanded( true ); 3851 // emit calendarViewExpanded( true );
3852 // } 3852 // }
3853 //qDebug(" CalendarView::toggleExpand()"); 3853 //qDebug(" CalendarView::toggleExpand()");
3854 globalFlagBlockAgenda = 1; 3854 globalFlagBlockAgenda = 1;
3855 emit calendarViewExpanded( !mLeftFrame->isHidden() ); 3855 emit calendarViewExpanded( !mLeftFrame->isHidden() );
3856 globalFlagBlockAgenda = 5; 3856 globalFlagBlockAgenda = 5;
3857 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() ); 3857 mViewManager->raiseCurrentView( !mLeftFrame->isHidden() );
3858 //mViewManager->showView( 0, true ); 3858 //mViewManager->showView( 0, true );
3859} 3859}
3860 3860
3861void CalendarView::calendarModified( bool modified, Calendar * ) 3861void CalendarView::calendarModified( bool modified, Calendar * )
3862{ 3862{
3863 setModified( modified ); 3863 setModified( modified );
3864} 3864}
3865 3865
3866Todo *CalendarView::selectedTodo() 3866Todo *CalendarView::selectedTodo()
3867{ 3867{
3868 Incidence *incidence = currentSelection(); 3868 Incidence *incidence = currentSelection();
3869 if ( incidence && incidence->type() == "Todo" ) { 3869 if ( incidence && incidence->type() == "Todo" ) {
3870 return static_cast<Todo *>( incidence ); 3870 return static_cast<Todo *>( incidence );
3871 } 3871 }
3872 3872
3873 incidence = mTodoList->selectedIncidences().first(); 3873 incidence = mTodoList->selectedIncidences().first();
3874 if ( incidence && incidence->type() == "Todo" ) { 3874 if ( incidence && incidence->type() == "Todo" ) {
3875 return static_cast<Todo *>( incidence ); 3875 return static_cast<Todo *>( incidence );
3876 } 3876 }
3877 3877
3878 return 0; 3878 return 0;
3879} 3879}
3880 3880
3881void CalendarView::dialogClosing(Incidence *in) 3881void CalendarView::dialogClosing(Incidence *in)
3882{ 3882{
3883 // mDialogList.remove(in); 3883 // mDialogList.remove(in);
3884} 3884}
3885 3885
3886void CalendarView::showIncidence() 3886void CalendarView::showIncidence()
3887{ 3887{
3888 mViewerCallerIsSearchDialog = false; 3888 mViewerCallerIsSearchDialog = false;
3889 Incidence *incidence = currentSelection(); 3889 Incidence *incidence = currentSelection();
3890 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3890 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3891 if ( incidence ) { 3891 if ( incidence ) {
3892 ShowIncidenceVisitor v; 3892 ShowIncidenceVisitor v;
3893 v.act( incidence, this ); 3893 v.act( incidence, this );
3894 } 3894 }
3895} 3895}
3896void CalendarView::editIncidenceDescription() 3896void CalendarView::editIncidenceDescription()
3897{ 3897{
3898 mFlagEditDescription = true; 3898 mFlagEditDescription = true;
3899 editIncidence(); 3899 editIncidence();
3900 mFlagEditDescription = false; 3900 mFlagEditDescription = false;
3901} 3901}
3902void CalendarView::editIncidence() 3902void CalendarView::editIncidence()
3903{ 3903{
3904 // qDebug("editIncidence() "); 3904 // qDebug("editIncidence() ");
3905 Incidence *incidence = currentSelection(); 3905 Incidence *incidence = currentSelection();
3906 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3906 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3907 if ( incidence ) { 3907 if ( incidence ) {
3908 EditIncidenceVisitor v; 3908 EditIncidenceVisitor v;
3909 v.act( incidence, this ); 3909 v.act( incidence, this );
3910 } 3910 }
3911} 3911}
3912 3912
3913void CalendarView::deleteIncidence() 3913void CalendarView::deleteIncidence()
3914{ 3914{
3915 Incidence *incidence = currentSelection(); 3915 Incidence *incidence = currentSelection();
3916 if ( !incidence ) incidence = mTodoList->selectedIncidences().first(); 3916 if ( !incidence ) incidence = mTodoList->selectedIncidences().first();
3917 if ( incidence ) { 3917 if ( incidence ) {
3918 deleteIncidence(incidence); 3918 deleteIncidence(incidence);
3919 } 3919 }
3920} 3920}
3921 3921
3922void CalendarView::showIncidence(Incidence *incidence) 3922void CalendarView::showIncidence(Incidence *incidence)
3923{ 3923{
3924 mViewerCallerIsSearchDialog = false; 3924 mViewerCallerIsSearchDialog = false;
3925 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() ); 3925 //qDebug("%x %x ",sender (), mDialogManager->getSearchDialog() );
3926 if ( sender() && mDialogManager->getSearchDialog() ) { 3926 if ( sender() && mDialogManager->getSearchDialog() ) {
3927 if ( sender () == mDialogManager->getSearchDialog()->listview() ) { 3927 if ( sender () == mDialogManager->getSearchDialog()->listview() ) {
3928 mViewerCallerIsSearchDialog = true; 3928 mViewerCallerIsSearchDialog = true;
3929 } 3929 }
3930 } 3930 }
3931 if ( incidence ) { 3931 if ( incidence ) {
3932 ShowIncidenceVisitor v; 3932 ShowIncidenceVisitor v;
3933 v.act( incidence, this ); 3933 v.act( incidence, this );
3934 } 3934 }
3935} 3935}
3936 3936
3937void CalendarView::editIncidence(Incidence *incidence) 3937void CalendarView::editIncidence(Incidence *incidence)
3938{ 3938{
3939 if ( incidence ) { 3939 if ( incidence ) {
3940 3940
3941 EditIncidenceVisitor v; 3941 EditIncidenceVisitor v;
3942 v.act( incidence, this ); 3942 v.act( incidence, this );
3943 3943
3944 } 3944 }
3945} 3945}
3946 3946
3947void CalendarView::deleteIncidence(Incidence *incidence) 3947void CalendarView::deleteIncidence(Incidence *incidence)
3948{ 3948{
3949 //qDebug(" CalendarView::deleteIncidence "); 3949 //qDebug(" CalendarView::deleteIncidence ");
3950 if ( incidence ) { 3950 if ( incidence ) {
3951 DeleteIncidenceVisitor v; 3951 DeleteIncidenceVisitor v;
3952 v.act( incidence, this ); 3952 v.act( incidence, this );
3953 } 3953 }
3954} 3954}
3955 3955
3956 3956
3957void CalendarView::lookForOutgoingMessages() 3957void CalendarView::lookForOutgoingMessages()
3958{ 3958{
3959 OutgoingDialog *ogd = mDialogManager->outgoingDialog(); 3959 OutgoingDialog *ogd = mDialogManager->outgoingDialog();
3960 ogd->loadMessages(); 3960 ogd->loadMessages();
3961} 3961}
3962 3962
3963void CalendarView::lookForIncomingMessages() 3963void CalendarView::lookForIncomingMessages()
3964{ 3964{
3965 IncomingDialog *icd = mDialogManager->incomingDialog(); 3965 IncomingDialog *icd = mDialogManager->incomingDialog();
3966 icd->retrieve(); 3966 icd->retrieve();
3967} 3967}
3968 3968
3969bool CalendarView::removeCompletedSubTodos( Todo* t ) 3969bool CalendarView::removeCompletedSubTodos( Todo* t )
3970{ 3970{
3971 bool deleteTodo = true; 3971 bool deleteTodo = true;
3972 QPtrList<Incidence> subTodos; 3972 QPtrList<Incidence> subTodos;
3973 Incidence *aTodo; 3973 Incidence *aTodo;
3974 subTodos = t->relations(); 3974 subTodos = t->relations();
3975 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) { 3975 for (aTodo = subTodos.first(); aTodo; aTodo = subTodos.next()) {
3976 if (! removeCompletedSubTodos( (Todo*) aTodo )) 3976 if (! removeCompletedSubTodos( (Todo*) aTodo ))
3977 deleteTodo = false; 3977 deleteTodo = false;
3978 } 3978 }
3979 if ( deleteTodo ) { 3979 if ( deleteTodo ) {
3980 if ( t->isCompleted() && !t->doesRecur()) { 3980 if ( t->isCompleted() && !t->doesRecur()) {
3981 checkExternalId( t ); 3981 checkExternalId( t );
3982 mCalendar->deleteTodo( t ); 3982 mCalendar->deleteTodo( t );
3983 changeTodoDisplay( t,KOGlobals::EVENTDELETED ); 3983 changeTodoDisplay( t,KOGlobals::EVENTDELETED );
3984 } 3984 }
3985 else 3985 else
3986 deleteTodo = false; 3986 deleteTodo = false;
3987 } 3987 }
3988 return deleteTodo; 3988 return deleteTodo;
3989 3989
3990} 3990}
3991void CalendarView::purgeCompleted() 3991void CalendarView::purgeCompleted()
3992{ 3992{
3993 int result = KMessageBox::warningContinueCancel(this, 3993 int result = KMessageBox::warningContinueCancel(this,
3994 i18n("Delete all\ncompleted To-Dos?"),i18n("Purge To-Dos"),i18n("Purge")); 3994 i18n("Delete all completed todos?\n(Completed recurring todos\nwill not be deleted!)"),i18n("Purge Todos"),i18n("Purge"));
3995 3995
3996 if (result == KMessageBox::Continue) { 3996 if (result == KMessageBox::Continue) {
3997 3997
3998 QPtrList<Todo> todoCal; 3998 QPtrList<Todo> todoCal;
3999 QPtrList<Todo> rootTodos; 3999 QPtrList<Todo> rootTodos;
4000 //QPtrList<Incidence> rel; 4000 //QPtrList<Incidence> rel;
4001 Todo *aTodo;//, *rTodo; 4001 Todo *aTodo;//, *rTodo;
4002 Incidence *rIncidence; 4002 Incidence *rIncidence;
4003 bool childDelete = false; 4003 bool childDelete = false;
4004 bool deletedOne = true; 4004 bool deletedOne = true;
4005 todoCal = calendar()->todos(); 4005 todoCal = calendar()->todos();
4006 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) { 4006 for (aTodo = todoCal.first(); aTodo; aTodo = todoCal.next()) {
4007 if ( !aTodo->relatedTo() ) 4007 if ( !aTodo->relatedTo() )
4008 rootTodos.append( aTodo ); 4008 rootTodos.append( aTodo );
4009 } 4009 }
4010 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) { 4010 for (aTodo = rootTodos.first(); aTodo; aTodo = rootTodos.next()) {
4011 removeCompletedSubTodos( aTodo ); 4011 removeCompletedSubTodos( aTodo );
4012 } 4012 }
4013 4013
4014 updateView(); 4014 updateView();
4015 } 4015 }
4016} 4016}
4017 4017
4018void CalendarView::slotCalendarChanged() 4018void CalendarView::slotCalendarChanged()
4019{ 4019{
4020 ; 4020 ;
4021} 4021}
4022 4022
4023void CalendarView::keyPressEvent ( QKeyEvent *e) 4023void CalendarView::keyPressEvent ( QKeyEvent *e)
4024{ 4024{
4025 //qDebug(" alendarView::keyPressEvent "); 4025 //qDebug(" alendarView::keyPressEvent ");
4026 e->ignore(); 4026 e->ignore();
4027} 4027}
4028 4028
4029 4029
4030bool CalendarView::sync(KSyncManager* manager, QString filename, int mode) 4030bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
4031{ 4031{
4032 // mSyncManager = manager; 4032 // mSyncManager = manager;
4033 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) { 4033 if ( filename == QDir::homeDirPath ()+"/.kdecalendardump.ics" ) {
4034 qDebug("KO: SyncKDE request detected!"); 4034 qDebug("KO: SyncKDE request detected!");
4035 } 4035 }
4036 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4036 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4037 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4037 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4038 return syncCalendar( filename, mode ); 4038 return syncCalendar( filename, mode );
4039} 4039}
4040bool CalendarView::syncExternal(KSyncManager* manager, QString resource) 4040bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
4041{ 4041{
4042 //mSyncManager = manager; 4042 //mSyncManager = manager;
4043 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice(); 4043 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
4044 mCurrentSyncName = mSyncManager->getCurrentSyncName(); 4044 mCurrentSyncName = mSyncManager->getCurrentSyncName();
4045 if ( resource == "sharp" ) 4045 if ( resource == "sharp" )
4046 syncExternal( 0 ); 4046 syncExternal( 0 );
4047 if ( resource == "phone" ) 4047 if ( resource == "phone" )
4048 syncExternal( 1 ); 4048 syncExternal( 1 );
4049 // pending setmodified 4049 // pending setmodified
4050 return true; 4050 return true;
4051} 4051}
4052void CalendarView::setSyncManager(KSyncManager* manager) 4052void CalendarView::setSyncManager(KSyncManager* manager)
4053{ 4053{
4054 mSyncManager = manager; 4054 mSyncManager = manager;
4055} 4055}
4056 4056
4057void CalendarView::removeSyncInfo( QString syncProfile) 4057void CalendarView::removeSyncInfo( QString syncProfile)
4058{ 4058{
4059 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1()); 4059 qDebug("KO: removeSyncInfo for profile %s ", syncProfile.latin1());
4060 mCalendar->removeSyncInfo( syncProfile ); 4060 mCalendar->removeSyncInfo( syncProfile );
4061 4061
4062} 4062}
4063 4063
4064void CalendarView::undo_delete() 4064void CalendarView::undo_delete()
4065{ 4065{
4066 //qDebug("undo_delete() "); 4066 //qDebug("undo_delete() ");
4067 Incidence* undo = mCalendar->undoIncidence(); 4067 Incidence* undo = mCalendar->undoIncidence();
4068 if ( !undo ) { 4068 if ( !undo ) {
4069 KMessageBox::sorry(this,i18n("There is nothing to undo!"), 4069 KMessageBox::sorry(this,i18n("There is nothing to undo!"),
4070 i18n("KO/Pi")); 4070 i18n("KO/Pi"));
4071 return; 4071 return;
4072 } 4072 }
4073 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) + 4073 if ( KMessageBox::Continue ==KMessageBox::warningContinueCancel(this,undo->summary().left(25) +
4074 i18n("\nAre you sure you want\nto restore this?"), 4074 i18n("\nAre you sure you want\nto restore this?"),
4075 i18n("KO/Pi Confirmation"),i18n("Restore"))) { 4075 i18n("KO/Pi Confirmation"),i18n("Restore"))) {
4076 mCalendar->undoDeleteIncidence(); 4076 mCalendar->undoDeleteIncidence();
4077 updateView(); 4077 updateView();
4078 } 4078 }
4079} 4079}
4080 4080
4081void CalendarView::slotViewerClosed() 4081void CalendarView::slotViewerClosed()
4082{ 4082{
4083 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) ); 4083 QTimer::singleShot( 50, this, SLOT ( resetFocus() ) );
4084} 4084}
4085 4085
4086void CalendarView::resetFocus() 4086void CalendarView::resetFocus()
4087{ 4087{
4088 if ( mViewerCallerIsSearchDialog ) { 4088 if ( mViewerCallerIsSearchDialog ) {
4089 if ( mDialogManager->getSearchDialog()->isVisible() ){ 4089 if ( mDialogManager->getSearchDialog()->isVisible() ){
4090 mDialogManager->getSearchDialog()->raise(); 4090 mDialogManager->getSearchDialog()->raise();
4091 mDialogManager->getSearchDialog()->setActiveWindow(); 4091 mDialogManager->getSearchDialog()->setActiveWindow();
4092 mDialogManager->getSearchDialog()->listview()->resetFocus(); 4092 mDialogManager->getSearchDialog()->listview()->resetFocus();
4093 } else 4093 } else
4094 mViewerCallerIsSearchDialog = false; 4094 mViewerCallerIsSearchDialog = false;
4095 } 4095 }
4096 if ( !mViewerCallerIsSearchDialog ) { 4096 if ( !mViewerCallerIsSearchDialog ) {
4097 //mViewManager->currentView()->setFocus(); 4097 //mViewManager->currentView()->setFocus();
4098 //qDebug("sssssssssssssssset focus "); 4098 //qDebug("sssssssssssssssset focus ");
4099 topLevelWidget()->raise(); 4099 topLevelWidget()->raise();
4100 setActiveWindow(); 4100 setActiveWindow();
4101 //setFocus(); 4101 //setFocus();
4102 } 4102 }
4103 mViewerCallerIsSearchDialog = false; 4103 mViewerCallerIsSearchDialog = false;
4104} 4104}
4105 4105
4106void CalendarView::showNextAlarms() 4106void CalendarView::showNextAlarms()
4107{ 4107{
4108 QString message; 4108 QString message;
4109 QDateTime nextAl = mCalendar->nextAlarmEventDateTime(); 4109 QDateTime nextAl = mCalendar->nextAlarmEventDateTime();
4110 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) { 4110 if ( nextAl.isValid() && mNextAlarmDateTime > QDateTime::currentDateTime() ) {
4111 QString sum = mCalendar->nextSummary(); 4111 QString sum = mCalendar->nextSummary();
4112 QDateTime nextA = mNextAlarmDateTime; 4112 QDateTime nextA = mNextAlarmDateTime;
4113 QDateTime cur = QDateTime::currentDateTime(); 4113 QDateTime cur = QDateTime::currentDateTime();
4114 int secs = cur.secsTo( nextA ); 4114 int secs = cur.secsTo( nextA );
4115 int min = secs /60; 4115 int min = secs /60;
4116 int hours = min /60; 4116 int hours = min /60;
4117 min = min % 60; 4117 min = min % 60;
4118 int days = hours /24; 4118 int days = hours /24;
4119 hours = hours % 24; 4119 hours = hours % 24;
4120 4120
4121 //message = i18n("The next alarm is in:\n"); 4121 //message = i18n("The next alarm is in:\n");
4122 if ( days > 1 ) 4122 if ( days > 1 )
4123 message += i18n("%1 days\n").arg( days ); 4123 message += i18n("%1 days\n").arg( days );
4124 else if ( days == 1 ) 4124 else if ( days == 1 )
4125 message += i18n("1 day\n"); 4125 message += i18n("1 day\n");
4126 if ( hours > 1 ) 4126 if ( hours > 1 )
4127 message += i18n("%1 hours\n").arg( hours ); 4127 message += i18n("%1 hours\n").arg( hours );
4128 else if ( hours == 1 ) 4128 else if ( hours == 1 )
4129 message += i18n("1 hour\n"); 4129 message += i18n("1 hour\n");
4130 if ( min > 1 ) 4130 if ( min > 1 )
4131 message += i18n("%1 minutes\n").arg( min ); 4131 message += i18n("%1 minutes\n").arg( min );
4132 else if ( min == 1 ) 4132 else if ( min == 1 )
4133 message += i18n("1 minute\n"); 4133 message += i18n("1 minute\n");
4134 if ( message.isEmpty() ) 4134 if ( message.isEmpty() )
4135 message = i18n("The next alarm is in\nless than one minute!"); 4135 message = i18n("The next alarm is in\nless than one minute!");
4136 else 4136 else
4137 message = i18n("The next alarm is in:\n") + message; 4137 message = i18n("The next alarm is in:\n") + message;
4138 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ; 4138 message += i18n("\n(%1)\n\n%2\n(%3)\n").arg( KGlobal::locale()->formatDateTime(nextA , false)).arg(sum ).arg( KGlobal::locale()->formatDateTime(nextAl , false)) ;
4139 } else { 4139 } else {
4140 message = i18n("There is no next alarm."); 4140 message = i18n("There is no next alarm.");
4141 4141
4142 } 4142 }
4143#ifdef DESKTOP_VERSION 4143#ifdef DESKTOP_VERSION
4144 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) { 4144 if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
4145 message += i18n("\nThe internal alarm notification is disabled!\n"); 4145 message += i18n("\nThe internal alarm notification is disabled!\n");
4146 message += i18n("Enable it in the settings menu, TAB alarm."); 4146 message += i18n("Enable it in the settings menu, TAB alarm.");
4147 } 4147 }
4148 4148
4149#endif 4149#endif
4150 KMessageBox::information( this, message); 4150 KMessageBox::information( this, message);
4151} 4151}