-rw-r--r-- | korganizer/calendarview.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index b0be340..dd4ea41 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1093,1740 +1093,1743 @@ Event* CalendarView::getLastSyncEvent() | |||
1093 | lse = new Event(); | 1093 | lse = new Event(); |
1094 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1094 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1095 | QString sum = ""; | 1095 | QString sum = ""; |
1096 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1096 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1097 | sum = "E: "; | 1097 | sum = "E: "; |
1098 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1098 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1099 | lse->setDtStart( mLastCalendarSync ); | 1099 | lse->setDtStart( mLastCalendarSync ); |
1100 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1100 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1101 | lse->setCategories( i18n("SyncEvent") ); | 1101 | lse->setCategories( i18n("SyncEvent") ); |
1102 | lse->setReadOnly( true ); | 1102 | lse->setReadOnly( true ); |
1103 | mCalendar->addEvent( lse ); | 1103 | mCalendar->addEvent( lse ); |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | return lse; | 1106 | return lse; |
1107 | 1107 | ||
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | // we check, if the to delete event has a id for a profile | 1110 | // we check, if the to delete event has a id for a profile |
1111 | // if yes, we set this id in the profile to delete | 1111 | // if yes, we set this id in the profile to delete |
1112 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1112 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1113 | { | 1113 | { |
1114 | if ( lastSync.count() == 0 ) { | 1114 | if ( lastSync.count() == 0 ) { |
1115 | //qDebug(" lastSync.count() == 0"); | 1115 | //qDebug(" lastSync.count() == 0"); |
1116 | return; | 1116 | return; |
1117 | } | 1117 | } |
1118 | if ( toDelete->typeID() == journalID ) | 1118 | if ( toDelete->typeID() == journalID ) |
1119 | return; | 1119 | return; |
1120 | 1120 | ||
1121 | Event* eve = lastSync.first(); | 1121 | Event* eve = lastSync.first(); |
1122 | 1122 | ||
1123 | while ( eve ) { | 1123 | while ( eve ) { |
1124 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1124 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1125 | if ( !id.isEmpty() ) { | 1125 | if ( !id.isEmpty() ) { |
1126 | QString des = eve->description(); | 1126 | QString des = eve->description(); |
1127 | QString pref = "e"; | 1127 | QString pref = "e"; |
1128 | if ( toDelete->typeID() == todoID ) | 1128 | if ( toDelete->typeID() == todoID ) |
1129 | pref = "t"; | 1129 | pref = "t"; |
1130 | des += pref+ id + ","; | 1130 | des += pref+ id + ","; |
1131 | eve->setReadOnly( false ); | 1131 | eve->setReadOnly( false ); |
1132 | eve->setDescription( des ); | 1132 | eve->setDescription( des ); |
1133 | //qDebug("setdes %s ", des.latin1()); | 1133 | //qDebug("setdes %s ", des.latin1()); |
1134 | eve->setReadOnly( true ); | 1134 | eve->setReadOnly( true ); |
1135 | } | 1135 | } |
1136 | eve = lastSync.next(); | 1136 | eve = lastSync.next(); |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | } | 1139 | } |
1140 | void CalendarView::checkExternalId( Incidence * inc ) | 1140 | void CalendarView::checkExternalId( Incidence * inc ) |
1141 | { | 1141 | { |
1142 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1142 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1143 | checkExternSyncEvent( lastSync, inc ); | 1143 | checkExternSyncEvent( lastSync, inc ); |
1144 | 1144 | ||
1145 | } | 1145 | } |
1146 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1146 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1147 | { | 1147 | { |
1148 | bool syncOK = true; | 1148 | bool syncOK = true; |
1149 | int addedEvent = 0; | 1149 | int addedEvent = 0; |
1150 | int addedEventR = 0; | 1150 | int addedEventR = 0; |
1151 | int deletedEventR = 0; | 1151 | int deletedEventR = 0; |
1152 | int deletedEventL = 0; | 1152 | int deletedEventL = 0; |
1153 | int changedLocal = 0; | 1153 | int changedLocal = 0; |
1154 | int changedRemote = 0; | 1154 | int changedRemote = 0; |
1155 | int filteredIN = 0; | 1155 | int filteredIN = 0; |
1156 | int filteredOUT = 0; | 1156 | int filteredOUT = 0; |
1157 | //QPtrList<Event> el = local->rawEvents(); | 1157 | //QPtrList<Event> el = local->rawEvents(); |
1158 | Event* eventR; | 1158 | Event* eventR; |
1159 | QString uid; | 1159 | QString uid; |
1160 | int take; | 1160 | int take; |
1161 | Event* eventL; | 1161 | Event* eventL; |
1162 | Event* eventRSync; | 1162 | Event* eventRSync; |
1163 | Event* eventLSync; | 1163 | Event* eventLSync; |
1164 | clearAllViews(); | 1164 | clearAllViews(); |
1165 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 1165 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
1166 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 1166 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
1167 | bool fullDateRange = false; | 1167 | bool fullDateRange = false; |
1168 | local->resetTempSyncStat(); | 1168 | local->resetTempSyncStat(); |
1169 | mLastCalendarSync = QDateTime::currentDateTime(); | 1169 | mLastCalendarSync = QDateTime::currentDateTime(); |
1170 | if ( mSyncManager->syncWithDesktop() ) { | 1170 | if ( mSyncManager->syncWithDesktop() ) { |
1171 | remote->resetPilotStat(1); | 1171 | remote->resetPilotStat(1); |
1172 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1172 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1173 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 1173 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
1174 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 1174 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
1175 | } else { | 1175 | } else { |
1176 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 1176 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
1177 | } | 1177 | } |
1178 | } | 1178 | } |
1179 | QDateTime modifiedCalendar = mLastCalendarSync; | 1179 | QDateTime modifiedCalendar = mLastCalendarSync; |
1180 | eventLSync = getLastSyncEvent(); | 1180 | eventLSync = getLastSyncEvent(); |
1181 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 1181 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
1182 | if ( eventR ) { | 1182 | if ( eventR ) { |
1183 | eventRSync = (Event*) eventR->clone(); | 1183 | eventRSync = (Event*) eventR->clone(); |
1184 | remote->deleteEvent(eventR ); | 1184 | remote->deleteEvent(eventR ); |
1185 | 1185 | ||
1186 | } else { | 1186 | } else { |
1187 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 1187 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
1188 | eventRSync = (Event*)eventLSync->clone(); | 1188 | eventRSync = (Event*)eventLSync->clone(); |
1189 | } else { | 1189 | } else { |
1190 | fullDateRange = true; | 1190 | fullDateRange = true; |
1191 | eventRSync = new Event(); | 1191 | eventRSync = new Event(); |
1192 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 1192 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
1193 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 1193 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
1194 | eventRSync->setDtStart( mLastCalendarSync ); | 1194 | eventRSync->setDtStart( mLastCalendarSync ); |
1195 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1195 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1196 | eventRSync->setCategories( i18n("SyncEvent") ); | 1196 | eventRSync->setCategories( i18n("SyncEvent") ); |
1197 | } | 1197 | } |
1198 | } | 1198 | } |
1199 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 1199 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
1200 | fullDateRange = true; | 1200 | fullDateRange = true; |
1201 | 1201 | ||
1202 | if ( ! fullDateRange ) { | 1202 | if ( ! fullDateRange ) { |
1203 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 1203 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
1204 | 1204 | ||
1205 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 1205 | // qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
1206 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 1206 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
1207 | fullDateRange = true; | 1207 | fullDateRange = true; |
1208 | } | 1208 | } |
1209 | } | 1209 | } |
1210 | if ( mSyncManager->syncWithDesktop() ) { | 1210 | if ( mSyncManager->syncWithDesktop() ) { |
1211 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 1211 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
1212 | } | 1212 | } |
1213 | if ( fullDateRange ) | 1213 | if ( fullDateRange ) |
1214 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 1214 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
1215 | else | 1215 | else |
1216 | mLastCalendarSync = eventLSync->dtStart(); | 1216 | mLastCalendarSync = eventLSync->dtStart(); |
1217 | // for resyncing if own file has changed | 1217 | // for resyncing if own file has changed |
1218 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 1218 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
1219 | mLastCalendarSync = loadedFileVersion; | 1219 | mLastCalendarSync = loadedFileVersion; |
1220 | //qDebug("setting mLastCalendarSync "); | 1220 | //qDebug("setting mLastCalendarSync "); |
1221 | } | 1221 | } |
1222 | //qDebug("*************************** "); | 1222 | //qDebug("*************************** "); |
1223 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 1223 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
1224 | QPtrList<Incidence> er = remote->rawIncidences(); | 1224 | QPtrList<Incidence> er = remote->rawIncidences(); |
1225 | Incidence* inR = er.first(); | 1225 | Incidence* inR = er.first(); |
1226 | Incidence* inL; | 1226 | Incidence* inL; |
1227 | QProgressBar bar( er.count(),0 ); | 1227 | QProgressBar bar( er.count(),0 ); |
1228 | bar.setCaption (i18n("Syncing - close to abort!") ); | 1228 | bar.setCaption (i18n("Syncing - close to abort!") ); |
1229 | 1229 | ||
1230 | // ************** setting up filter ************* | 1230 | // ************** setting up filter ************* |
1231 | CalFilter *filterIN = 0; | 1231 | CalFilter *filterIN = 0; |
1232 | CalFilter *filterOUT = 0; | 1232 | CalFilter *filterOUT = 0; |
1233 | CalFilter *filter = mFilters.first(); | 1233 | CalFilter *filter = mFilters.first(); |
1234 | while(filter) { | 1234 | while(filter) { |
1235 | if ( filter->name() == mSyncManager->mFilterInCal ) | 1235 | if ( filter->name() == mSyncManager->mFilterInCal ) |
1236 | filterIN = filter; | 1236 | filterIN = filter; |
1237 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 1237 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
1238 | filterOUT = filter; | 1238 | filterOUT = filter; |
1239 | filter = mFilters.next(); | 1239 | filter = mFilters.next(); |
1240 | } | 1240 | } |
1241 | int w = 300; | 1241 | int w = 300; |
1242 | if ( QApplication::desktop()->width() < 320 ) | 1242 | if ( QApplication::desktop()->width() < 320 ) |
1243 | w = 220; | 1243 | w = 220; |
1244 | int h = bar.sizeHint().height() ; | 1244 | int h = bar.sizeHint().height() ; |
1245 | int dw = QApplication::desktop()->width(); | 1245 | int dw = QApplication::desktop()->width(); |
1246 | int dh = QApplication::desktop()->height(); | 1246 | int dh = QApplication::desktop()->height(); |
1247 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1247 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1248 | bar.show(); | 1248 | bar.show(); |
1249 | int modulo = (er.count()/10)+1; | 1249 | int modulo = (er.count()/10)+1; |
1250 | int incCounter = 0; | 1250 | int incCounter = 0; |
1251 | while ( inR ) { | 1251 | while ( inR ) { |
1252 | if ( ! bar.isVisible() ) | 1252 | if ( ! bar.isVisible() ) |
1253 | return false; | 1253 | return false; |
1254 | if ( incCounter % modulo == 0 ) | 1254 | if ( incCounter % modulo == 0 ) |
1255 | bar.setProgress( incCounter ); | 1255 | bar.setProgress( incCounter ); |
1256 | ++incCounter; | 1256 | ++incCounter; |
1257 | uid = inR->uid(); | 1257 | uid = inR->uid(); |
1258 | bool skipIncidence = false; | 1258 | bool skipIncidence = false; |
1259 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1259 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1260 | skipIncidence = true; | 1260 | skipIncidence = true; |
1261 | QString idS; | 1261 | QString idS; |
1262 | qApp->processEvents(); | 1262 | qApp->processEvents(); |
1263 | if ( !skipIncidence ) { | 1263 | if ( !skipIncidence ) { |
1264 | inL = local->incidence( uid ); | 1264 | inL = local->incidence( uid ); |
1265 | if ( inL ) { // maybe conflict - same uid in both calendars | 1265 | if ( inL ) { // maybe conflict - same uid in both calendars |
1266 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1266 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1267 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1267 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1268 | if ( take == 3 ) | 1268 | if ( take == 3 ) |
1269 | return false; | 1269 | return false; |
1270 | if ( take == 1 ) {// take local ********************** | 1270 | if ( take == 1 ) {// take local ********************** |
1271 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1271 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1272 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1272 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1273 | else | 1273 | else |
1274 | idS = inR->IDStr(); | 1274 | idS = inR->IDStr(); |
1275 | remote->deleteIncidence( inR ); | 1275 | remote->deleteIncidence( inR ); |
1276 | inR = inL->clone(); | 1276 | inR = inL->clone(); |
1277 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1277 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1278 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1278 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1279 | inR->setIDStr( idS ); | 1279 | inR->setIDStr( idS ); |
1280 | remote->addIncidence( inR ); | 1280 | remote->addIncidence( inR ); |
1281 | if ( mSyncManager->syncWithDesktop() ) | 1281 | if ( mSyncManager->syncWithDesktop() ) |
1282 | inR->setPilotId( 2 ); | 1282 | inR->setPilotId( 2 ); |
1283 | ++changedRemote; | 1283 | ++changedRemote; |
1284 | } else {// take remote ********************** | 1284 | } else {// take remote ********************** |
1285 | idS = inL->IDStr(); | 1285 | idS = inL->IDStr(); |
1286 | int pid = inL->pilotId(); | 1286 | int pid = inL->pilotId(); |
1287 | local->deleteIncidence( inL ); | 1287 | local->deleteIncidence( inL ); |
1288 | inL = inR->clone(); | 1288 | inL = inR->clone(); |
1289 | if ( mSyncManager->syncWithDesktop() ) | 1289 | if ( mSyncManager->syncWithDesktop() ) |
1290 | inL->setPilotId( pid ); | 1290 | inL->setPilotId( pid ); |
1291 | inL->setIDStr( idS ); | 1291 | inL->setIDStr( idS ); |
1292 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1292 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1293 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1293 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1294 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1294 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1295 | } | 1295 | } |
1296 | local->addIncidence( inL ); | 1296 | local->addIncidence( inL ); |
1297 | ++changedLocal; | 1297 | ++changedLocal; |
1298 | } | 1298 | } |
1299 | } | 1299 | } |
1300 | } else { // no conflict ********** add or delete remote | 1300 | } else { // no conflict ********** add or delete remote |
1301 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1301 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1302 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1302 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1303 | QString des = eventLSync->description(); | 1303 | QString des = eventLSync->description(); |
1304 | QString pref = "e"; | 1304 | QString pref = "e"; |
1305 | if ( inR->typeID() == todoID ) | 1305 | if ( inR->typeID() == todoID ) |
1306 | pref = "t"; | 1306 | pref = "t"; |
1307 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1307 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1308 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1308 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1309 | //remote->deleteIncidence( inR ); | 1309 | //remote->deleteIncidence( inR ); |
1310 | ++deletedEventR; | 1310 | ++deletedEventR; |
1311 | } else { | 1311 | } else { |
1312 | inR->setLastModified( modifiedCalendar ); | 1312 | inR->setLastModified( modifiedCalendar ); |
1313 | inL = inR->clone(); | 1313 | inL = inR->clone(); |
1314 | inL->setIDStr( ":" ); | 1314 | inL->setIDStr( ":" ); |
1315 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1315 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1316 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1316 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1317 | local->addIncidence( inL ); | 1317 | local->addIncidence( inL ); |
1318 | ++addedEvent; | 1318 | ++addedEvent; |
1319 | 1319 | ||
1320 | } | 1320 | } |
1321 | } else { | 1321 | } else { |
1322 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1322 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1323 | inR->setLastModified( modifiedCalendar ); | 1323 | inR->setLastModified( modifiedCalendar ); |
1324 | inL = inR->clone(); | 1324 | inL = inR->clone(); |
1325 | inL->setIDStr( ":" ); | 1325 | inL->setIDStr( ":" ); |
1326 | local->addIncidence( inL ); | 1326 | local->addIncidence( inL ); |
1327 | ++addedEvent; | 1327 | ++addedEvent; |
1328 | 1328 | ||
1329 | } else { | 1329 | } else { |
1330 | checkExternSyncEvent(eventRSyncSharp, inR); | 1330 | checkExternSyncEvent(eventRSyncSharp, inR); |
1331 | remote->deleteIncidence( inR ); | 1331 | remote->deleteIncidence( inR ); |
1332 | ++deletedEventR; | 1332 | ++deletedEventR; |
1333 | } | 1333 | } |
1334 | } | 1334 | } |
1335 | } else { | 1335 | } else { |
1336 | ++filteredIN; | 1336 | ++filteredIN; |
1337 | } | 1337 | } |
1338 | } | 1338 | } |
1339 | } | 1339 | } |
1340 | inR = er.next(); | 1340 | inR = er.next(); |
1341 | } | 1341 | } |
1342 | QPtrList<Incidence> el = local->rawIncidences(); | 1342 | QPtrList<Incidence> el = local->rawIncidences(); |
1343 | inL = el.first(); | 1343 | inL = el.first(); |
1344 | modulo = (el.count()/10)+1; | 1344 | modulo = (el.count()/10)+1; |
1345 | bar.setCaption (i18n("Add / remove events") ); | 1345 | bar.setCaption (i18n("Add / remove events") ); |
1346 | bar.setTotalSteps ( el.count() ) ; | 1346 | bar.setTotalSteps ( el.count() ) ; |
1347 | bar.show(); | 1347 | bar.show(); |
1348 | incCounter = 0; | 1348 | incCounter = 0; |
1349 | 1349 | ||
1350 | while ( inL ) { | 1350 | while ( inL ) { |
1351 | 1351 | ||
1352 | qApp->processEvents(); | 1352 | qApp->processEvents(); |
1353 | if ( ! bar.isVisible() ) | 1353 | if ( ! bar.isVisible() ) |
1354 | return false; | 1354 | return false; |
1355 | if ( incCounter % modulo == 0 ) | 1355 | if ( incCounter % modulo == 0 ) |
1356 | bar.setProgress( incCounter ); | 1356 | bar.setProgress( incCounter ); |
1357 | ++incCounter; | 1357 | ++incCounter; |
1358 | uid = inL->uid(); | 1358 | uid = inL->uid(); |
1359 | bool skipIncidence = false; | 1359 | bool skipIncidence = false; |
1360 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1360 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1361 | skipIncidence = true; | 1361 | skipIncidence = true; |
1362 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) | 1362 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) |
1363 | skipIncidence = true; | 1363 | skipIncidence = true; |
1364 | if ( !skipIncidence ) { | 1364 | if ( !skipIncidence ) { |
1365 | inR = remote->incidence( uid ); | 1365 | inR = remote->incidence( uid ); |
1366 | if ( ! inR ) { | 1366 | if ( ! inR ) { |
1367 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1367 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1368 | // no conflict ********** add or delete local | 1368 | // no conflict ********** add or delete local |
1369 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1369 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1370 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1370 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1371 | checkExternSyncEvent(eventLSyncSharp, inL); | 1371 | checkExternSyncEvent(eventLSyncSharp, inL); |
1372 | local->deleteIncidence( inL ); | 1372 | local->deleteIncidence( inL ); |
1373 | ++deletedEventL; | 1373 | ++deletedEventL; |
1374 | } else { | 1374 | } else { |
1375 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1375 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1376 | inL->removeID(mCurrentSyncDevice ); | 1376 | inL->removeID(mCurrentSyncDevice ); |
1377 | ++addedEventR; | 1377 | ++addedEventR; |
1378 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1378 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1379 | inL->setLastModified( modifiedCalendar ); | 1379 | inL->setLastModified( modifiedCalendar ); |
1380 | inR = inL->clone(); | 1380 | inR = inL->clone(); |
1381 | inR->setIDStr( ":" ); | 1381 | inR->setIDStr( ":" ); |
1382 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1382 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1383 | remote->addIncidence( inR ); | 1383 | remote->addIncidence( inR ); |
1384 | } | 1384 | } |
1385 | } | 1385 | } |
1386 | } else { | 1386 | } else { |
1387 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1387 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1388 | checkExternSyncEvent(eventLSyncSharp, inL); | 1388 | checkExternSyncEvent(eventLSyncSharp, inL); |
1389 | local->deleteIncidence( inL ); | 1389 | local->deleteIncidence( inL ); |
1390 | ++deletedEventL; | 1390 | ++deletedEventL; |
1391 | } else { | 1391 | } else { |
1392 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1392 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1393 | ++addedEventR; | 1393 | ++addedEventR; |
1394 | inL->setLastModified( modifiedCalendar ); | 1394 | inL->setLastModified( modifiedCalendar ); |
1395 | inR = inL->clone(); | 1395 | inR = inL->clone(); |
1396 | inR->setIDStr( ":" ); | 1396 | inR->setIDStr( ":" ); |
1397 | remote->addIncidence( inR ); | 1397 | remote->addIncidence( inR ); |
1398 | } | 1398 | } |
1399 | } | 1399 | } |
1400 | } | 1400 | } |
1401 | } else { | 1401 | } else { |
1402 | ++filteredOUT; | 1402 | ++filteredOUT; |
1403 | } | 1403 | } |
1404 | } | 1404 | } |
1405 | } | 1405 | } |
1406 | inL = el.next(); | 1406 | inL = el.next(); |
1407 | } | 1407 | } |
1408 | int delFut = 0; | 1408 | int delFut = 0; |
1409 | int remRem = 0; | 1409 | int remRem = 0; |
1410 | if ( mSyncManager->mWriteBackInFuture ) { | 1410 | if ( mSyncManager->mWriteBackInFuture ) { |
1411 | er = remote->rawIncidences(); | 1411 | er = remote->rawIncidences(); |
1412 | remRem = er.count(); | 1412 | remRem = er.count(); |
1413 | inR = er.first(); | 1413 | inR = er.first(); |
1414 | QDateTime dt; | 1414 | QDateTime dt; |
1415 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1415 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1416 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1416 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1417 | while ( inR ) { | 1417 | while ( inR ) { |
1418 | if ( inR->typeID() == todoID ) { | 1418 | if ( inR->typeID() == todoID ) { |
1419 | Todo * t = (Todo*)inR; | 1419 | Todo * t = (Todo*)inR; |
1420 | if ( t->hasDueDate() ) | 1420 | if ( t->hasDueDate() ) |
1421 | dt = t->dtDue(); | 1421 | dt = t->dtDue(); |
1422 | else | 1422 | else |
1423 | dt = cur.addSecs( 62 ); | 1423 | dt = cur.addSecs( 62 ); |
1424 | } | 1424 | } |
1425 | else if (inR->typeID() == eventID ) { | 1425 | else if (inR->typeID() == eventID ) { |
1426 | bool ok; | 1426 | bool ok; |
1427 | dt = inR->getNextOccurence( cur, &ok ); | 1427 | dt = inR->getNextOccurence( cur, &ok ); |
1428 | if ( !ok ) | 1428 | if ( !ok ) |
1429 | dt = cur.addSecs( -62 ); | 1429 | dt = cur.addSecs( -62 ); |
1430 | } | 1430 | } |
1431 | else | 1431 | else |
1432 | dt = inR->dtStart(); | 1432 | dt = inR->dtStart(); |
1433 | if ( dt < cur || dt > end ) { | 1433 | if ( dt < cur || dt > end ) { |
1434 | remote->deleteIncidence( inR ); | 1434 | remote->deleteIncidence( inR ); |
1435 | ++delFut; | 1435 | ++delFut; |
1436 | } | 1436 | } |
1437 | inR = er.next(); | 1437 | inR = er.next(); |
1438 | } | 1438 | } |
1439 | } | 1439 | } |
1440 | bar.hide(); | 1440 | bar.hide(); |
1441 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1441 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1442 | eventLSync->setReadOnly( false ); | 1442 | eventLSync->setReadOnly( false ); |
1443 | eventLSync->setDtStart( mLastCalendarSync ); | 1443 | eventLSync->setDtStart( mLastCalendarSync ); |
1444 | eventRSync->setDtStart( mLastCalendarSync ); | 1444 | eventRSync->setDtStart( mLastCalendarSync ); |
1445 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1445 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1446 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1446 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1447 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1447 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1448 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1448 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1449 | eventLSync->setReadOnly( true ); | 1449 | eventLSync->setReadOnly( true ); |
1450 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1450 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1451 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... | 1451 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... |
1452 | remote->addEvent( eventRSync ); | 1452 | remote->addEvent( eventRSync ); |
1453 | else | 1453 | else |
1454 | delete eventRSync; | 1454 | delete eventRSync; |
1455 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1455 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1456 | QString mes; | 1456 | QString mes; |
1457 | 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 ); | 1457 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n %d incoming filtered out\n %d outgoing filtered out\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR, filteredIN, filteredOUT ); |
1458 | QString delmess; | 1458 | QString delmess; |
1459 | if ( delFut ) { | 1459 | if ( delFut ) { |
1460 | 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); | 1460 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are more\nthan %d weeks in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInPast,mSyncManager->mWriteBackInFuture, remRem-delFut); |
1461 | mes += delmess; | 1461 | mes += delmess; |
1462 | } | 1462 | } |
1463 | mes = i18n("Local calendar changed!\n") +mes; | 1463 | mes = i18n("Local calendar changed!\n") +mes; |
1464 | mCalendar->checkAlarmForIncidence( 0, true ); | 1464 | mCalendar->checkAlarmForIncidence( 0, true ); |
1465 | qDebug( mes ); | 1465 | qDebug( mes ); |
1466 | if ( mSyncManager->mShowSyncSummary ) { | 1466 | if ( mSyncManager->mShowSyncSummary ) { |
1467 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1467 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1468 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1468 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1469 | qDebug("KO: WB cancelled "); | 1469 | qDebug("KO: WB cancelled "); |
1470 | mSyncManager->mWriteBackFile = false; | 1470 | mSyncManager->mWriteBackFile = false; |
1471 | return syncOK; | 1471 | return syncOK; |
1472 | } | 1472 | } |
1473 | } | 1473 | } |
1474 | return syncOK; | 1474 | return syncOK; |
1475 | } | 1475 | } |
1476 | 1476 | ||
1477 | void CalendarView::setSyncDevice( QString s ) | 1477 | void CalendarView::setSyncDevice( QString s ) |
1478 | { | 1478 | { |
1479 | mCurrentSyncDevice= s; | 1479 | mCurrentSyncDevice= s; |
1480 | } | 1480 | } |
1481 | void CalendarView::setSyncName( QString s ) | 1481 | void CalendarView::setSyncName( QString s ) |
1482 | { | 1482 | { |
1483 | mCurrentSyncName= s; | 1483 | mCurrentSyncName= s; |
1484 | } | 1484 | } |
1485 | bool CalendarView::syncCalendar(QString filename, int mode) | 1485 | bool CalendarView::syncCalendar(QString filename, int mode) |
1486 | { | 1486 | { |
1487 | //qDebug("syncCalendar %s ", filename.latin1()); | 1487 | //qDebug("syncCalendar %s ", filename.latin1()); |
1488 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1488 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1489 | CalendarLocal* calendar = new CalendarLocal(); | 1489 | CalendarLocal* calendar = new CalendarLocal(); |
1490 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1490 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1491 | FileStorage* storage = new FileStorage( calendar ); | 1491 | FileStorage* storage = new FileStorage( calendar ); |
1492 | bool syncOK = false; | 1492 | bool syncOK = false; |
1493 | storage->setFileName( filename ); | 1493 | storage->setFileName( filename ); |
1494 | // qDebug("loading ... "); | 1494 | // qDebug("loading ... "); |
1495 | if ( storage->load() ) { | 1495 | if ( storage->load() ) { |
1496 | getEventViewerDialog()->setSyncMode( true ); | 1496 | getEventViewerDialog()->setSyncMode( true ); |
1497 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1497 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1498 | getEventViewerDialog()->setSyncMode( false ); | 1498 | getEventViewerDialog()->setSyncMode( false ); |
1499 | if ( syncOK ) { | 1499 | if ( syncOK ) { |
1500 | if ( mSyncManager->mWriteBackFile ) | 1500 | if ( mSyncManager->mWriteBackFile ) |
1501 | { | 1501 | { |
1502 | storage->setSaveFormat( new ICalFormat() ); | 1502 | storage->setSaveFormat( new ICalFormat() ); |
1503 | storage->save(); | 1503 | storage->save(); |
1504 | } | 1504 | } |
1505 | } | 1505 | } |
1506 | setModified( true ); | 1506 | setModified( true ); |
1507 | } | 1507 | } |
1508 | delete storage; | 1508 | delete storage; |
1509 | delete calendar; | 1509 | delete calendar; |
1510 | if ( syncOK ) | 1510 | if ( syncOK ) |
1511 | updateView(); | 1511 | updateView(); |
1512 | return syncOK; | 1512 | return syncOK; |
1513 | } | 1513 | } |
1514 | 1514 | ||
1515 | void CalendarView::syncExternal( int mode ) | 1515 | void CalendarView::syncExternal( int mode ) |
1516 | { | 1516 | { |
1517 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1517 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1518 | 1518 | ||
1519 | qApp->processEvents(); | 1519 | qApp->processEvents(); |
1520 | CalendarLocal* calendar = new CalendarLocal(); | 1520 | CalendarLocal* calendar = new CalendarLocal(); |
1521 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1521 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1522 | bool syncOK = false; | 1522 | bool syncOK = false; |
1523 | bool loadSuccess = false; | 1523 | bool loadSuccess = false; |
1524 | PhoneFormat* phoneFormat = 0; | 1524 | PhoneFormat* phoneFormat = 0; |
1525 | emit tempDisableBR(true); | 1525 | emit tempDisableBR(true); |
1526 | #ifndef DESKTOP_VERSION | 1526 | #ifndef DESKTOP_VERSION |
1527 | SharpFormat* sharpFormat = 0; | 1527 | SharpFormat* sharpFormat = 0; |
1528 | if ( mode == 0 ) { // sharp | 1528 | if ( mode == 0 ) { // sharp |
1529 | sharpFormat = new SharpFormat () ; | 1529 | sharpFormat = new SharpFormat () ; |
1530 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1530 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1531 | 1531 | ||
1532 | } else | 1532 | } else |
1533 | #endif | 1533 | #endif |
1534 | if ( mode == 1 ) { // phone | 1534 | if ( mode == 1 ) { // phone |
1535 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1535 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1536 | mSyncManager->mPhoneDevice, | 1536 | mSyncManager->mPhoneDevice, |
1537 | mSyncManager->mPhoneConnection, | 1537 | mSyncManager->mPhoneConnection, |
1538 | mSyncManager->mPhoneModel); | 1538 | mSyncManager->mPhoneModel); |
1539 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1539 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1540 | 1540 | ||
1541 | } else { | 1541 | } else { |
1542 | emit tempDisableBR(false); | 1542 | emit tempDisableBR(false); |
1543 | return; | 1543 | return; |
1544 | } | 1544 | } |
1545 | if ( loadSuccess ) { | 1545 | if ( loadSuccess ) { |
1546 | getEventViewerDialog()->setSyncMode( true ); | 1546 | getEventViewerDialog()->setSyncMode( true ); |
1547 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1547 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1548 | getEventViewerDialog()->setSyncMode( false ); | 1548 | getEventViewerDialog()->setSyncMode( false ); |
1549 | qApp->processEvents(); | 1549 | qApp->processEvents(); |
1550 | if ( syncOK ) { | 1550 | if ( syncOK ) { |
1551 | if ( mSyncManager->mWriteBackFile ) | 1551 | if ( mSyncManager->mWriteBackFile ) |
1552 | { | 1552 | { |
1553 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1553 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1554 | Incidence* inc = iL.first(); | 1554 | Incidence* inc = iL.first(); |
1555 | if ( phoneFormat ) { | 1555 | if ( phoneFormat ) { |
1556 | while ( inc ) { | 1556 | while ( inc ) { |
1557 | inc->removeID(mCurrentSyncDevice); | 1557 | inc->removeID(mCurrentSyncDevice); |
1558 | inc = iL.next(); | 1558 | inc = iL.next(); |
1559 | } | 1559 | } |
1560 | } | 1560 | } |
1561 | #ifndef DESKTOP_VERSION | 1561 | #ifndef DESKTOP_VERSION |
1562 | if ( sharpFormat ) | 1562 | if ( sharpFormat ) |
1563 | sharpFormat->save(calendar); | 1563 | sharpFormat->save(calendar); |
1564 | #endif | 1564 | #endif |
1565 | if ( phoneFormat ) | 1565 | if ( phoneFormat ) |
1566 | phoneFormat->save(calendar); | 1566 | phoneFormat->save(calendar); |
1567 | iL = calendar->rawIncidences(); | 1567 | iL = calendar->rawIncidences(); |
1568 | inc = iL.first(); | 1568 | inc = iL.first(); |
1569 | Incidence* loc; | 1569 | Incidence* loc; |
1570 | while ( inc ) { | 1570 | while ( inc ) { |
1571 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1571 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1572 | loc = mCalendar->incidence(inc->uid() ); | 1572 | loc = mCalendar->incidence(inc->uid() ); |
1573 | if ( loc ) { | 1573 | if ( loc ) { |
1574 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1574 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1575 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1575 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1576 | } | 1576 | } |
1577 | } | 1577 | } |
1578 | inc = iL.next(); | 1578 | inc = iL.next(); |
1579 | } | 1579 | } |
1580 | Incidence* lse = getLastSyncEvent(); | 1580 | Incidence* lse = getLastSyncEvent(); |
1581 | if ( lse ) { | 1581 | if ( lse ) { |
1582 | lse->setReadOnly( false ); | 1582 | lse->setReadOnly( false ); |
1583 | lse->setDescription( "" ); | 1583 | lse->setDescription( "" ); |
1584 | lse->setReadOnly( true ); | 1584 | lse->setReadOnly( true ); |
1585 | } | 1585 | } |
1586 | } | 1586 | } |
1587 | } else { | 1587 | } else { |
1588 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 1588 | topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
1589 | } | 1589 | } |
1590 | setModified( true ); | 1590 | setModified( true ); |
1591 | } else { | 1591 | } else { |
1592 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1592 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1593 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1593 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1594 | question, i18n("Ok")) ; | 1594 | question, i18n("Ok")) ; |
1595 | 1595 | ||
1596 | } | 1596 | } |
1597 | delete calendar; | 1597 | delete calendar; |
1598 | updateView(); | 1598 | updateView(); |
1599 | emit tempDisableBR(false); | 1599 | emit tempDisableBR(false); |
1600 | return ;//syncOK; | 1600 | return ;//syncOK; |
1601 | 1601 | ||
1602 | } | 1602 | } |
1603 | 1603 | ||
1604 | bool CalendarView::importBday() | 1604 | bool CalendarView::importBday() |
1605 | { | 1605 | { |
1606 | #ifndef KORG_NOKABC | 1606 | #ifndef KORG_NOKABC |
1607 | 1607 | ||
1608 | #ifdef DESKTOP_VERSION | 1608 | #ifdef DESKTOP_VERSION |
1609 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1609 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1610 | KABC::AddressBook::Iterator it; | 1610 | KABC::AddressBook::Iterator it; |
1611 | int count = 0; | 1611 | int count = 0; |
1612 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1612 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1613 | ++count; | 1613 | ++count; |
1614 | } | 1614 | } |
1615 | QProgressBar bar(count,0 ); | 1615 | QProgressBar bar(count,0 ); |
1616 | int w = 300; | 1616 | int w = 300; |
1617 | if ( QApplication::desktop()->width() < 320 ) | 1617 | if ( QApplication::desktop()->width() < 320 ) |
1618 | w = 220; | 1618 | w = 220; |
1619 | int h = bar.sizeHint().height() ; | 1619 | int h = bar.sizeHint().height() ; |
1620 | int dw = QApplication::desktop()->width(); | 1620 | int dw = QApplication::desktop()->width(); |
1621 | int dh = QApplication::desktop()->height(); | 1621 | int dh = QApplication::desktop()->height(); |
1622 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1622 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1623 | bar.show(); | 1623 | bar.show(); |
1624 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1624 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1625 | qApp->processEvents(); | 1625 | qApp->processEvents(); |
1626 | count = 0; | 1626 | count = 0; |
1627 | int addCount = 0; | 1627 | int addCount = 0; |
1628 | KCal::Attendee* a = 0; | 1628 | KCal::Attendee* a = 0; |
1629 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1629 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1630 | if ( ! bar.isVisible() ) | 1630 | if ( ! bar.isVisible() ) |
1631 | return false; | 1631 | return false; |
1632 | bar.setProgress( count++ ); | 1632 | bar.setProgress( count++ ); |
1633 | qApp->processEvents(); | 1633 | qApp->processEvents(); |
1634 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1634 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1635 | if ( (*it).birthday().date().isValid() ){ | 1635 | if ( (*it).birthday().date().isValid() ){ |
1636 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1636 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1637 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1637 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1638 | ++addCount; | 1638 | ++addCount; |
1639 | } | 1639 | } |
1640 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1640 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1641 | if ( anni.isValid() ){ | 1641 | if ( anni.isValid() ){ |
1642 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1642 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1643 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1643 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1644 | ++addCount; | 1644 | ++addCount; |
1645 | } | 1645 | } |
1646 | } | 1646 | } |
1647 | updateView(); | 1647 | updateView(); |
1648 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1648 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1649 | #else //DESKTOP_VERSION | 1649 | #else //DESKTOP_VERSION |
1650 | 1650 | ||
1651 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 1651 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
1652 | // the result should now arrive through method insertBirthdays | 1652 | // the result should now arrive through method insertBirthdays |
1653 | 1653 | ||
1654 | #endif //DESKTOP_VERSION | 1654 | #endif //DESKTOP_VERSION |
1655 | 1655 | ||
1656 | #endif //KORG_NOKABC | 1656 | #endif //KORG_NOKABC |
1657 | 1657 | ||
1658 | 1658 | ||
1659 | return true; | 1659 | return true; |
1660 | } | 1660 | } |
1661 | 1661 | ||
1662 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 1662 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
1663 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 1663 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
1664 | const QStringList& anniversaryList, const QStringList& realNameList, | 1664 | const QStringList& anniversaryList, const QStringList& realNameList, |
1665 | const QStringList& emailList, const QStringList& assembledNameList, | 1665 | const QStringList& emailList, const QStringList& assembledNameList, |
1666 | const QStringList& uidList) | 1666 | const QStringList& uidList) |
1667 | { | 1667 | { |
1668 | //qDebug("KO::CalendarView::insertBirthdays"); | 1668 | //qDebug("KO::CalendarView::insertBirthdays"); |
1669 | if (uid == this->name()) | 1669 | if (uid == this->name()) |
1670 | { | 1670 | { |
1671 | int count = birthdayList.count(); | 1671 | int count = birthdayList.count(); |
1672 | int addCount = 0; | 1672 | int addCount = 0; |
1673 | KCal::Attendee* a = 0; | 1673 | KCal::Attendee* a = 0; |
1674 | 1674 | ||
1675 | //qDebug("CalView 1 %i", count); | 1675 | //qDebug("CalView 1 %i", count); |
1676 | 1676 | ||
1677 | QProgressBar bar(count,0 ); | 1677 | QProgressBar bar(count,0 ); |
1678 | int w = 300; | 1678 | int w = 300; |
1679 | if ( QApplication::desktop()->width() < 320 ) | 1679 | if ( QApplication::desktop()->width() < 320 ) |
1680 | w = 220; | 1680 | w = 220; |
1681 | int h = bar.sizeHint().height() ; | 1681 | int h = bar.sizeHint().height() ; |
1682 | int dw = QApplication::desktop()->width(); | 1682 | int dw = QApplication::desktop()->width(); |
1683 | int dh = QApplication::desktop()->height(); | 1683 | int dh = QApplication::desktop()->height(); |
1684 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1684 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1685 | bar.show(); | 1685 | bar.show(); |
1686 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 1686 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
1687 | qApp->processEvents(); | 1687 | qApp->processEvents(); |
1688 | 1688 | ||
1689 | QDate birthday; | 1689 | QDate birthday; |
1690 | QDate anniversary; | 1690 | QDate anniversary; |
1691 | QString realName; | 1691 | QString realName; |
1692 | QString email; | 1692 | QString email; |
1693 | QString assembledName; | 1693 | QString assembledName; |
1694 | QString uid; | 1694 | QString uid; |
1695 | bool ok = true; | 1695 | bool ok = true; |
1696 | for ( int i = 0; i < count; i++) | 1696 | for ( int i = 0; i < count; i++) |
1697 | { | 1697 | { |
1698 | if ( ! bar.isVisible() ) | 1698 | if ( ! bar.isVisible() ) |
1699 | return; | 1699 | return; |
1700 | bar.setProgress( i ); | 1700 | bar.setProgress( i ); |
1701 | qApp->processEvents(); | 1701 | qApp->processEvents(); |
1702 | 1702 | ||
1703 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 1703 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
1704 | if (!ok) { | 1704 | if (!ok) { |
1705 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 1705 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
1706 | } | 1706 | } |
1707 | 1707 | ||
1708 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 1708 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
1709 | if (!ok) { | 1709 | if (!ok) { |
1710 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 1710 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
1711 | } | 1711 | } |
1712 | realName = realNameList[i]; | 1712 | realName = realNameList[i]; |
1713 | email = emailList[i]; | 1713 | email = emailList[i]; |
1714 | assembledName = assembledNameList[i]; | 1714 | assembledName = assembledNameList[i]; |
1715 | uid = uidList[i]; | 1715 | uid = uidList[i]; |
1716 | //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() ); | 1716 | //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() ); |
1717 | 1717 | ||
1718 | if ( birthday.isValid() ){ | 1718 | if ( birthday.isValid() ){ |
1719 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1719 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1720 | KCal::Attendee::ReqParticipant,uid) ; | 1720 | KCal::Attendee::ReqParticipant,uid) ; |
1721 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 1721 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
1722 | ++addCount; | 1722 | ++addCount; |
1723 | } | 1723 | } |
1724 | 1724 | ||
1725 | if ( anniversary.isValid() ){ | 1725 | if ( anniversary.isValid() ){ |
1726 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1726 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1727 | KCal::Attendee::ReqParticipant,uid) ; | 1727 | KCal::Attendee::ReqParticipant,uid) ; |
1728 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 1728 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
1729 | ++addCount; | 1729 | ++addCount; |
1730 | } | 1730 | } |
1731 | } | 1731 | } |
1732 | 1732 | ||
1733 | updateView(); | 1733 | updateView(); |
1734 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1734 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1735 | 1735 | ||
1736 | } | 1736 | } |
1737 | 1737 | ||
1738 | } | 1738 | } |
1739 | 1739 | ||
1740 | 1740 | ||
1741 | 1741 | ||
1742 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1742 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1743 | { | 1743 | { |
1744 | //qDebug("addAnni "); | 1744 | //qDebug("addAnni "); |
1745 | Event * ev = new Event(); | 1745 | Event * ev = new Event(); |
1746 | ev->setOrganizer(KOPrefs::instance()->email()); | 1746 | ev->setOrganizer(KOPrefs::instance()->email()); |
1747 | if ( a ) { | 1747 | if ( a ) { |
1748 | ev->addAttendee( a ); | 1748 | ev->addAttendee( a ); |
1749 | } | 1749 | } |
1750 | QString kind; | 1750 | QString kind; |
1751 | if ( birthday ) { | 1751 | if ( birthday ) { |
1752 | kind = i18n( "Birthday" ); | 1752 | kind = i18n( "Birthday" ); |
1753 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); | 1753 | ev->setSummary( name + " (" + QString::number(date.year()) +")"); |
1754 | } | 1754 | } |
1755 | else { | 1755 | else { |
1756 | kind = i18n( "Anniversary" ); | 1756 | kind = i18n( "Anniversary" ); |
1757 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); | 1757 | ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); |
1758 | } | 1758 | } |
1759 | ev->setCategories( kind ); | 1759 | ev->setCategories( kind ); |
1760 | ev->setDtStart( QDateTime(date) ); | 1760 | ev->setDtStart( QDateTime(date) ); |
1761 | ev->setDtEnd( QDateTime(date) ); | 1761 | ev->setDtEnd( QDateTime(date) ); |
1762 | ev->setFloats( true ); | 1762 | ev->setFloats( true ); |
1763 | Recurrence * rec = ev->recurrence(); | 1763 | Recurrence * rec = ev->recurrence(); |
1764 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1764 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1765 | rec->addYearlyNum( date.month() ); | 1765 | rec->addYearlyNum( date.month() ); |
1766 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1766 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1767 | delete ev; | 1767 | delete ev; |
1768 | return false; | 1768 | return false; |
1769 | } | 1769 | } |
1770 | return true; | 1770 | return true; |
1771 | 1771 | ||
1772 | } | 1772 | } |
1773 | bool CalendarView::importQtopia( const QString &categories, | 1773 | bool CalendarView::importQtopia( const QString &categories, |
1774 | const QString &datebook, | 1774 | const QString &datebook, |
1775 | const QString &todolist ) | 1775 | const QString &todolist ) |
1776 | { | 1776 | { |
1777 | 1777 | ||
1778 | QtopiaFormat qtopiaFormat; | 1778 | QtopiaFormat qtopiaFormat; |
1779 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1779 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1780 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1780 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1781 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1781 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1782 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1782 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1783 | 1783 | ||
1784 | updateView(); | 1784 | updateView(); |
1785 | return true; | 1785 | return true; |
1786 | 1786 | ||
1787 | #if 0 | 1787 | #if 0 |
1788 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1788 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1789 | mCurrentSyncDevice = "qtopia-XML"; | 1789 | mCurrentSyncDevice = "qtopia-XML"; |
1790 | if ( mSyncManager->mAskForPreferences ) | 1790 | if ( mSyncManager->mAskForPreferences ) |
1791 | edit_sync_options(); | 1791 | edit_sync_options(); |
1792 | qApp->processEvents(); | 1792 | qApp->processEvents(); |
1793 | CalendarLocal* calendar = new CalendarLocal(); | 1793 | CalendarLocal* calendar = new CalendarLocal(); |
1794 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1794 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1795 | bool syncOK = false; | 1795 | bool syncOK = false; |
1796 | QtopiaFormat qtopiaFormat; | 1796 | QtopiaFormat qtopiaFormat; |
1797 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1797 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1798 | bool loadOk = true; | 1798 | bool loadOk = true; |
1799 | if ( !categories.isEmpty() ) | 1799 | if ( !categories.isEmpty() ) |
1800 | loadOk = qtopiaFormat.load( calendar, categories ); | 1800 | loadOk = qtopiaFormat.load( calendar, categories ); |
1801 | if ( loadOk && !datebook.isEmpty() ) | 1801 | if ( loadOk && !datebook.isEmpty() ) |
1802 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1802 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1803 | if ( loadOk && !todolist.isEmpty() ) | 1803 | if ( loadOk && !todolist.isEmpty() ) |
1804 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1804 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1805 | 1805 | ||
1806 | if ( loadOk ) { | 1806 | if ( loadOk ) { |
1807 | getEventViewerDialog()->setSyncMode( true ); | 1807 | getEventViewerDialog()->setSyncMode( true ); |
1808 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); | 1808 | syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); |
1809 | getEventViewerDialog()->setSyncMode( false ); | 1809 | getEventViewerDialog()->setSyncMode( false ); |
1810 | qApp->processEvents(); | 1810 | qApp->processEvents(); |
1811 | if ( syncOK ) { | 1811 | if ( syncOK ) { |
1812 | if ( mSyncManager->mWriteBackFile ) | 1812 | if ( mSyncManager->mWriteBackFile ) |
1813 | { | 1813 | { |
1814 | // write back XML file | 1814 | // write back XML file |
1815 | 1815 | ||
1816 | } | 1816 | } |
1817 | setModified( true ); | 1817 | setModified( true ); |
1818 | } | 1818 | } |
1819 | } else { | 1819 | } else { |
1820 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1820 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1821 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1821 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1822 | question, i18n("Ok")) ; | 1822 | question, i18n("Ok")) ; |
1823 | } | 1823 | } |
1824 | delete calendar; | 1824 | delete calendar; |
1825 | updateView(); | 1825 | updateView(); |
1826 | return syncOK; | 1826 | return syncOK; |
1827 | 1827 | ||
1828 | 1828 | ||
1829 | #endif | 1829 | #endif |
1830 | 1830 | ||
1831 | } | 1831 | } |
1832 | 1832 | ||
1833 | void CalendarView::setSyncEventsReadOnly() | 1833 | void CalendarView::setSyncEventsReadOnly() |
1834 | { | 1834 | { |
1835 | Event * ev; | 1835 | Event * ev; |
1836 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1836 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1837 | ev = eL.first(); | 1837 | ev = eL.first(); |
1838 | while ( ev ) { | 1838 | while ( ev ) { |
1839 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1839 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1840 | ev->setReadOnly( true ); | 1840 | ev->setReadOnly( true ); |
1841 | ev = eL.next(); | 1841 | ev = eL.next(); |
1842 | } | 1842 | } |
1843 | } | 1843 | } |
1844 | 1844 | ||
1845 | bool CalendarView::loadCalendars() | 1845 | bool CalendarView::loadCalendars() |
1846 | { | 1846 | { |
1847 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1847 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1848 | KopiCalendarFile * cal = calendars.first(); | 1848 | KopiCalendarFile * cal = calendars.first(); |
1849 | mCalendar->setDefaultCalendar( 1 ); | 1849 | mCalendar->setDefaultCalendar( 1 ); |
1850 | openCalendar( MainWindow::defaultFileName(), false ); | 1850 | openCalendar( MainWindow::defaultFileName(), false ); |
1851 | cal = calendars.next(); | 1851 | cal = calendars.next(); |
1852 | while ( cal ) { | 1852 | while ( cal ) { |
1853 | addCalendar( cal ); | 1853 | addCalendar( cal ); |
1854 | cal = calendars.next(); | 1854 | cal = calendars.next(); |
1855 | } | 1855 | } |
1856 | restoreCalendarSettings(); | 1856 | restoreCalendarSettings(); |
1857 | mCalendar->reInitAlarmSettings(); | 1857 | mCalendar->reInitAlarmSettings(); |
1858 | setSyncEventsReadOnly(); | 1858 | setSyncEventsReadOnly(); |
1859 | updateUnmanagedViews(); | 1859 | updateUnmanagedViews(); |
1860 | updateView(); | 1860 | updateView(); |
1861 | return true; | ||
1861 | } | 1862 | } |
1862 | bool CalendarView::restoreCalendarSettings() | 1863 | bool CalendarView::restoreCalendarSettings() |
1863 | { | 1864 | { |
1864 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1865 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1865 | KopiCalendarFile * cal = calendars.first(); | 1866 | KopiCalendarFile * cal = calendars.first(); |
1866 | while ( cal ) { | 1867 | while ( cal ) { |
1867 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); | 1868 | mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); |
1868 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); | 1869 | mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); |
1869 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); | 1870 | mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); |
1870 | if ( cal->isStandard ) | 1871 | if ( cal->isStandard ) |
1871 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 1872 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
1872 | cal = calendars.next(); | 1873 | cal = calendars.next(); |
1873 | } | 1874 | } |
1875 | return true; | ||
1874 | } | 1876 | } |
1875 | void CalendarView::addCalendarId( int id ) | 1877 | void CalendarView::addCalendarId( int id ) |
1876 | { | 1878 | { |
1877 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); | 1879 | KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); |
1878 | addCalendar( cal ); | 1880 | addCalendar( cal ); |
1879 | } | 1881 | } |
1880 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) | 1882 | bool CalendarView::addCalendar( KopiCalendarFile * cal ) |
1881 | { | 1883 | { |
1882 | cal->mErrorOnLoad = false; | 1884 | cal->mErrorOnLoad = false; |
1883 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { | 1885 | if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { |
1884 | cal->mLoadDt = QDateTime::currentDateTime(); | 1886 | cal->mLoadDt = QDateTime::currentDateTime(); |
1885 | return true; | 1887 | return true; |
1886 | } | 1888 | } |
1887 | qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); | 1889 | qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); |
1888 | KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); | 1890 | KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); |
1889 | cal->mErrorOnLoad = true; | 1891 | cal->mErrorOnLoad = true; |
1890 | return false; | 1892 | return false; |
1891 | } | 1893 | } |
1892 | bool CalendarView::openCalendar(QString filename, bool merge) | 1894 | bool CalendarView::openCalendar(QString filename, bool merge) |
1893 | { | 1895 | { |
1894 | 1896 | ||
1895 | if (filename.isEmpty()) { | 1897 | if (filename.isEmpty()) { |
1896 | return false; | 1898 | return false; |
1897 | } | 1899 | } |
1898 | 1900 | ||
1899 | if (!QFile::exists(filename)) { | 1901 | if (!QFile::exists(filename)) { |
1900 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1902 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1901 | return false; | 1903 | return false; |
1902 | } | 1904 | } |
1903 | 1905 | ||
1904 | globalFlagBlockAgenda = 1; | 1906 | globalFlagBlockAgenda = 1; |
1905 | clearAllViews(); | 1907 | clearAllViews(); |
1906 | if (!merge) { | 1908 | if (!merge) { |
1907 | mViewManager->setDocumentId( filename ); | 1909 | mViewManager->setDocumentId( filename ); |
1908 | mCalendar->close(); | 1910 | mCalendar->close(); |
1909 | } | 1911 | } |
1910 | mStorage->setFileName( filename ); | 1912 | mStorage->setFileName( filename ); |
1911 | 1913 | ||
1912 | if ( mStorage->load() ) { | 1914 | if ( mStorage->load() ) { |
1913 | if ( merge ) ;//setModified( true ); | 1915 | if ( merge ) ;//setModified( true ); |
1914 | else { | 1916 | else { |
1915 | //setModified( true ); | 1917 | //setModified( true ); |
1916 | mViewManager->setDocumentId( filename ); | 1918 | mViewManager->setDocumentId( filename ); |
1917 | mDialogManager->setDocumentId( filename ); | 1919 | mDialogManager->setDocumentId( filename ); |
1918 | mTodoList->setDocumentId( filename ); | 1920 | mTodoList->setDocumentId( filename ); |
1919 | } | 1921 | } |
1920 | globalFlagBlockAgenda = 2; | 1922 | globalFlagBlockAgenda = 2; |
1921 | // if ( getLastSyncEvent() ) | 1923 | // if ( getLastSyncEvent() ) |
1922 | // getLastSyncEvent()->setReadOnly( true ); | 1924 | // getLastSyncEvent()->setReadOnly( true ); |
1923 | mCalendar->reInitAlarmSettings(); | 1925 | mCalendar->reInitAlarmSettings(); |
1924 | setSyncEventsReadOnly(); | 1926 | setSyncEventsReadOnly(); |
1925 | updateUnmanagedViews(); | 1927 | updateUnmanagedViews(); |
1926 | updateView(); | 1928 | updateView(); |
1927 | if ( filename != MainWindow::defaultFileName() ) { | 1929 | if ( filename != MainWindow::defaultFileName() ) { |
1928 | saveCalendar( MainWindow::defaultFileName() ); | 1930 | saveCalendar( MainWindow::defaultFileName() ); |
1929 | } else { | 1931 | } else { |
1930 | QFileInfo finf ( MainWindow::defaultFileName()); | 1932 | QFileInfo finf ( MainWindow::defaultFileName()); |
1931 | if ( finf.exists() ) { | 1933 | if ( finf.exists() ) { |
1932 | setLoadedFileVersion( finf.lastModified () ); | 1934 | setLoadedFileVersion( finf.lastModified () ); |
1933 | } | 1935 | } |
1934 | } | 1936 | } |
1935 | return true; | 1937 | return true; |
1936 | } else { | 1938 | } else { |
1937 | // while failing to load, the calendar object could | 1939 | // while failing to load, the calendar object could |
1938 | // have become partially populated. Clear it out. | 1940 | // have become partially populated. Clear it out. |
1939 | if ( !merge ) { | 1941 | if ( !merge ) { |
1940 | mCalendar->close(); | 1942 | mCalendar->close(); |
1941 | mViewManager->setDocumentId( filename ); | 1943 | mViewManager->setDocumentId( filename ); |
1942 | mDialogManager->setDocumentId( filename ); | 1944 | mDialogManager->setDocumentId( filename ); |
1943 | mTodoList->setDocumentId( filename ); | 1945 | mTodoList->setDocumentId( filename ); |
1944 | } | 1946 | } |
1945 | 1947 | ||
1946 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1948 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1947 | 1949 | ||
1948 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 1950 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
1949 | globalFlagBlockAgenda = 2; | 1951 | globalFlagBlockAgenda = 2; |
1950 | mCalendar->reInitAlarmSettings(); | 1952 | mCalendar->reInitAlarmSettings(); |
1951 | setSyncEventsReadOnly(); | 1953 | setSyncEventsReadOnly(); |
1952 | updateUnmanagedViews(); | 1954 | updateUnmanagedViews(); |
1953 | updateView(); | 1955 | updateView(); |
1954 | } | 1956 | } |
1955 | return false; | 1957 | return false; |
1956 | } | 1958 | } |
1957 | void CalendarView::showOpenError() | 1959 | void CalendarView::showOpenError() |
1958 | { | 1960 | { |
1959 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 1961 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
1960 | } | 1962 | } |
1961 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1963 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1962 | { | 1964 | { |
1963 | loadedFileVersion = dt; | 1965 | loadedFileVersion = dt; |
1964 | } | 1966 | } |
1965 | bool CalendarView::checkFileChanged(QString fn) | 1967 | bool CalendarView::checkFileChanged(QString fn) |
1966 | { | 1968 | { |
1967 | QFileInfo finf ( fn ); | 1969 | QFileInfo finf ( fn ); |
1968 | if ( !finf.exists() ) | 1970 | if ( !finf.exists() ) |
1969 | return true; | 1971 | return true; |
1970 | QDateTime dt = finf.lastModified (); | 1972 | QDateTime dt = finf.lastModified (); |
1971 | if ( dt <= loadedFileVersion ) | 1973 | if ( dt <= loadedFileVersion ) |
1972 | return false; | 1974 | return false; |
1973 | return true; | 1975 | return true; |
1974 | 1976 | ||
1975 | } | 1977 | } |
1976 | void CalendarView::watchSavedFile() | 1978 | void CalendarView::watchSavedFile() |
1977 | { | 1979 | { |
1978 | QFileInfo finf ( MainWindow::defaultFileName()); | 1980 | QFileInfo finf ( MainWindow::defaultFileName()); |
1979 | if ( !finf.exists() ) | 1981 | if ( !finf.exists() ) |
1980 | return; | 1982 | return; |
1981 | QDateTime dt = finf.lastModified (); | 1983 | QDateTime dt = finf.lastModified (); |
1982 | if ( dt < loadedFileVersion ) { | 1984 | if ( dt < loadedFileVersion ) { |
1983 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 1985 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
1984 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 1986 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
1985 | return; | 1987 | return; |
1986 | } | 1988 | } |
1987 | loadedFileVersion = dt; | 1989 | loadedFileVersion = dt; |
1988 | } | 1990 | } |
1989 | bool CalendarView::checkAllFileVersions() | 1991 | bool CalendarView::checkAllFileVersions() |
1990 | { | 1992 | { |
1991 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 1993 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
1992 | KopiCalendarFile * cal = calendars.first(); | 1994 | KopiCalendarFile * cal = calendars.first(); |
1993 | mCalendar->setDefaultCalendar( 1 ); | 1995 | mCalendar->setDefaultCalendar( 1 ); |
1994 | mCalendar->setDefaultCalendarEnabledOnly(); | 1996 | mCalendar->setDefaultCalendarEnabledOnly(); |
1995 | if ( !checkFileVersion(MainWindow::defaultFileName())) | 1997 | if ( !checkFileVersion(MainWindow::defaultFileName())) |
1996 | return false; | 1998 | return false; |
1997 | cal = calendars.next(); | 1999 | cal = calendars.next(); |
1998 | QDateTime storeTemp = loadedFileVersion; | 2000 | QDateTime storeTemp = loadedFileVersion; |
1999 | while ( cal ) { | 2001 | while ( cal ) { |
2000 | if ( !cal->mErrorOnLoad ) { | 2002 | if ( !cal->mErrorOnLoad ) { |
2001 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2003 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2002 | mCalendar->setDefaultCalendarEnabledOnly(); | 2004 | mCalendar->setDefaultCalendarEnabledOnly(); |
2003 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); | 2005 | loadedFileVersion = cal->mLoadDt.addSecs( 15 ); |
2004 | if ( !checkFileVersion(cal->mFileName )) { | 2006 | if ( !checkFileVersion(cal->mFileName )) { |
2005 | loadedFileVersion = storeTemp; | 2007 | loadedFileVersion = storeTemp; |
2006 | updateView(); | 2008 | updateView(); |
2007 | return false; | 2009 | return false; |
2008 | } | 2010 | } |
2009 | } | 2011 | } |
2010 | cal = calendars.next(); | 2012 | cal = calendars.next(); |
2011 | } | 2013 | } |
2012 | loadedFileVersion = storeTemp; | 2014 | loadedFileVersion = storeTemp; |
2013 | updateView(); | 2015 | updateView(); |
2014 | return true; | 2016 | return true; |
2015 | } | 2017 | } |
2016 | bool CalendarView::checkFileVersion(QString fn) | 2018 | bool CalendarView::checkFileVersion(QString fn) |
2017 | { | 2019 | { |
2018 | QFileInfo finf ( fn ); | 2020 | QFileInfo finf ( fn ); |
2019 | if ( !finf.exists() ) | 2021 | if ( !finf.exists() ) |
2020 | return true; | 2022 | return true; |
2021 | QDateTime dt = finf.lastModified (); | 2023 | QDateTime dt = finf.lastModified (); |
2022 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 2024 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
2023 | //qDebug("file on disk version %s",dt.toString().latin1()); | 2025 | //qDebug("file on disk version %s",dt.toString().latin1()); |
2024 | if ( dt <= loadedFileVersion ) | 2026 | if ( dt <= loadedFileVersion ) |
2025 | return true; | 2027 | return true; |
2026 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , | 2028 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file\n%1\n on disk has changed!\nFile size: %2 bytes.\nLast modified: %3\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg(fn).arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , |
2027 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 2029 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
2028 | i18n("Sync+save")); | 2030 | i18n("Sync+save")); |
2029 | 2031 | ||
2030 | if ( km == KMessageBox::Cancel ) | 2032 | if ( km == KMessageBox::Cancel ) |
2031 | return false; | 2033 | return false; |
2032 | if ( km == KMessageBox::Yes ) | 2034 | if ( km == KMessageBox::Yes ) |
2033 | return true; | 2035 | return true; |
2034 | 2036 | ||
2035 | setSyncDevice("deleteaftersync" ); | 2037 | setSyncDevice("deleteaftersync" ); |
2036 | mSyncManager->mAskForPreferences = true; | 2038 | mSyncManager->mAskForPreferences = true; |
2037 | mSyncManager->mSyncAlgoPrefs = 3; | 2039 | mSyncManager->mSyncAlgoPrefs = 3; |
2038 | mSyncManager->mWriteBackFile = false; | 2040 | mSyncManager->mWriteBackFile = false; |
2039 | mSyncManager->mWriteBackExistingOnly = false; | 2041 | mSyncManager->mWriteBackExistingOnly = false; |
2040 | mSyncManager->mShowSyncSummary = false; | 2042 | mSyncManager->mShowSyncSummary = false; |
2041 | syncCalendar( fn, 3 ); | 2043 | syncCalendar( fn, 3 ); |
2042 | Event * e = getLastSyncEvent(); | 2044 | Event * e = getLastSyncEvent(); |
2043 | if ( e ) | 2045 | if ( e ) |
2044 | mCalendar->deleteEvent( e ); | 2046 | mCalendar->deleteEvent( e ); |
2045 | return true; | 2047 | return true; |
2046 | } | 2048 | } |
2047 | bool CalendarView::saveCalendars() | 2049 | bool CalendarView::saveCalendars() |
2048 | { | 2050 | { |
2049 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; | 2051 | QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; |
2050 | KopiCalendarFile * cal = calendars.first(); | 2052 | KopiCalendarFile * cal = calendars.first(); |
2051 | mCalendar->setDefaultCalendar( 1 ); | 2053 | mCalendar->setDefaultCalendar( 1 ); |
2052 | mCalendar->setDefaultCalendarEnabledOnly(); | 2054 | mCalendar->setDefaultCalendarEnabledOnly(); |
2053 | saveCalendar( MainWindow::defaultFileName() ); | 2055 | saveCalendar( MainWindow::defaultFileName() ); |
2054 | cal = calendars.next(); | 2056 | cal = calendars.next(); |
2055 | while ( cal ) { | 2057 | while ( cal ) { |
2056 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { | 2058 | if ( !cal->isReadOnly && !cal->mErrorOnLoad ) { |
2057 | mCalendar->setDefaultCalendar( cal->mCalNumber ); | 2059 | mCalendar->setDefaultCalendar( cal->mCalNumber ); |
2058 | mCalendar->setDefaultCalendarEnabledOnly(); | 2060 | mCalendar->setDefaultCalendarEnabledOnly(); |
2059 | if ( saveCalendar( cal->mFileName ) ) | 2061 | if ( saveCalendar( cal->mFileName ) ) |
2060 | cal->mLoadDt = QDateTime::currentDateTime(); | 2062 | cal->mLoadDt = QDateTime::currentDateTime(); |
2061 | } | 2063 | } |
2062 | cal = calendars.next(); | 2064 | cal = calendars.next(); |
2063 | } | 2065 | } |
2064 | restoreCalendarSettings(); | 2066 | restoreCalendarSettings(); |
2067 | return true; | ||
2065 | } | 2068 | } |
2066 | bool CalendarView::saveCalendar( QString filename ) | 2069 | bool CalendarView::saveCalendar( QString filename ) |
2067 | { | 2070 | { |
2068 | 2071 | ||
2069 | // Store back all unsaved data into calendar object | 2072 | // Store back all unsaved data into calendar object |
2070 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 2073 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
2071 | if ( mViewManager->currentView() ) | 2074 | if ( mViewManager->currentView() ) |
2072 | mViewManager->currentView()->flushView(); | 2075 | mViewManager->currentView()->flushView(); |
2073 | 2076 | ||
2074 | 2077 | ||
2075 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); | 2078 | QDateTime lfv = QDateTime::currentDateTime().addSecs( -2); |
2076 | mStorage->setSaveFormat( new ICalFormat() ); | 2079 | mStorage->setSaveFormat( new ICalFormat() ); |
2077 | mStorage->setFileName( filename ); | 2080 | mStorage->setFileName( filename ); |
2078 | bool success; | 2081 | bool success; |
2079 | success = mStorage->save(); | 2082 | success = mStorage->save(); |
2080 | if ( !success ) { | 2083 | if ( !success ) { |
2081 | return false; | 2084 | return false; |
2082 | } | 2085 | } |
2083 | if ( filename == MainWindow::defaultFileName() ) { | 2086 | if ( filename == MainWindow::defaultFileName() ) { |
2084 | setLoadedFileVersion( lfv ); | 2087 | setLoadedFileVersion( lfv ); |
2085 | watchSavedFile(); | 2088 | watchSavedFile(); |
2086 | } | 2089 | } |
2087 | return true; | 2090 | return true; |
2088 | } | 2091 | } |
2089 | 2092 | ||
2090 | void CalendarView::closeCalendar() | 2093 | void CalendarView::closeCalendar() |
2091 | { | 2094 | { |
2092 | 2095 | ||
2093 | // child windows no longer valid | 2096 | // child windows no longer valid |
2094 | clearAllViews(); | 2097 | clearAllViews(); |
2095 | emit closingDown(); | 2098 | emit closingDown(); |
2096 | 2099 | ||
2097 | mCalendar->close(); | 2100 | mCalendar->close(); |
2098 | setModified(false); | 2101 | setModified(false); |
2099 | updateView(); | 2102 | updateView(); |
2100 | } | 2103 | } |
2101 | 2104 | ||
2102 | void CalendarView::archiveCalendar() | 2105 | void CalendarView::archiveCalendar() |
2103 | { | 2106 | { |
2104 | mDialogManager->showArchiveDialog(); | 2107 | mDialogManager->showArchiveDialog(); |
2105 | } | 2108 | } |
2106 | 2109 | ||
2107 | 2110 | ||
2108 | void CalendarView::readSettings() | 2111 | void CalendarView::readSettings() |
2109 | { | 2112 | { |
2110 | 2113 | ||
2111 | 2114 | ||
2112 | // mViewManager->showAgendaView(); | 2115 | // mViewManager->showAgendaView(); |
2113 | QString str; | 2116 | QString str; |
2114 | //qDebug("CalendarView::readSettings() "); | 2117 | //qDebug("CalendarView::readSettings() "); |
2115 | // read settings from the KConfig, supplying reasonable | 2118 | // read settings from the KConfig, supplying reasonable |
2116 | // defaults where none are to be found | 2119 | // defaults where none are to be found |
2117 | KConfig *config = KOGlobals::config(); | 2120 | KConfig *config = KOGlobals::config(); |
2118 | #ifndef KORG_NOSPLITTER | 2121 | #ifndef KORG_NOSPLITTER |
2119 | config->setGroup("KOrganizer Geometry"); | 2122 | config->setGroup("KOrganizer Geometry"); |
2120 | 2123 | ||
2121 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 2124 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
2122 | if (sizes.count() != 2) { | 2125 | if (sizes.count() != 2) { |
2123 | sizes << mDateNavigator->minimumSizeHint().width(); | 2126 | sizes << mDateNavigator->minimumSizeHint().width(); |
2124 | sizes << 300; | 2127 | sizes << 300; |
2125 | } | 2128 | } |
2126 | mPanner->setSizes(sizes); | 2129 | mPanner->setSizes(sizes); |
2127 | 2130 | ||
2128 | sizes = config->readIntListEntry("Separator2"); | 2131 | sizes = config->readIntListEntry("Separator2"); |
2129 | if ( ( mResourceView && sizes.count() == 4 ) || | 2132 | if ( ( mResourceView && sizes.count() == 4 ) || |
2130 | ( !mResourceView && sizes.count() == 3 ) ) { | 2133 | ( !mResourceView && sizes.count() == 3 ) ) { |
2131 | mLeftSplitter->setSizes(sizes); | 2134 | mLeftSplitter->setSizes(sizes); |
2132 | } | 2135 | } |
2133 | #endif | 2136 | #endif |
2134 | globalFlagBlockAgenda = 1; | 2137 | globalFlagBlockAgenda = 1; |
2135 | mViewManager->showAgendaView(); | 2138 | mViewManager->showAgendaView(); |
2136 | //mViewManager->readSettings( config ); | 2139 | //mViewManager->readSettings( config ); |
2137 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 2140 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
2138 | readFilterSettings(config); | 2141 | readFilterSettings(config); |
2139 | 2142 | ||
2140 | #ifdef DESKTOP_VERSION | 2143 | #ifdef DESKTOP_VERSION |
2141 | config->setGroup("WidgetLayout"); | 2144 | config->setGroup("WidgetLayout"); |
2142 | QStringList list; | 2145 | QStringList list; |
2143 | list = config->readListEntry("MainLayout"); | 2146 | list = config->readListEntry("MainLayout"); |
2144 | int x,y,w,h; | 2147 | int x,y,w,h; |
2145 | if ( ! list.isEmpty() ) { | 2148 | if ( ! list.isEmpty() ) { |
2146 | x = list[0].toInt(); | 2149 | x = list[0].toInt(); |
2147 | y = list[1].toInt(); | 2150 | y = list[1].toInt(); |
2148 | w = list[2].toInt(); | 2151 | w = list[2].toInt(); |
2149 | h = list[3].toInt(); | 2152 | h = list[3].toInt(); |
2150 | KApplication::testCoords( &x,&y,&w,&h ); | 2153 | KApplication::testCoords( &x,&y,&w,&h ); |
2151 | topLevelWidget()->setGeometry(x,y,w,h); | 2154 | topLevelWidget()->setGeometry(x,y,w,h); |
2152 | 2155 | ||
2153 | } else { | 2156 | } else { |
2154 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 2157 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
2155 | } | 2158 | } |
2156 | list = config->readListEntry("EditEventLayout"); | 2159 | list = config->readListEntry("EditEventLayout"); |
2157 | if ( ! list.isEmpty() ) { | 2160 | if ( ! list.isEmpty() ) { |
2158 | x = list[0].toInt(); | 2161 | x = list[0].toInt(); |
2159 | y = list[1].toInt(); | 2162 | y = list[1].toInt(); |
2160 | w = list[2].toInt(); | 2163 | w = list[2].toInt(); |
2161 | h = list[3].toInt(); | 2164 | h = list[3].toInt(); |
2162 | KApplication::testCoords( &x,&y,&w,&h ); | 2165 | KApplication::testCoords( &x,&y,&w,&h ); |
2163 | mEventEditor->setGeometry(x,y,w,h); | 2166 | mEventEditor->setGeometry(x,y,w,h); |
2164 | 2167 | ||
2165 | } | 2168 | } |
2166 | list = config->readListEntry("EditTodoLayout"); | 2169 | list = config->readListEntry("EditTodoLayout"); |
2167 | if ( ! list.isEmpty() ) { | 2170 | if ( ! list.isEmpty() ) { |
2168 | x = list[0].toInt(); | 2171 | x = list[0].toInt(); |
2169 | y = list[1].toInt(); | 2172 | y = list[1].toInt(); |
2170 | w = list[2].toInt(); | 2173 | w = list[2].toInt(); |
2171 | h = list[3].toInt(); | 2174 | h = list[3].toInt(); |
2172 | KApplication::testCoords( &x,&y,&w,&h ); | 2175 | KApplication::testCoords( &x,&y,&w,&h ); |
2173 | mTodoEditor->setGeometry(x,y,w,h); | 2176 | mTodoEditor->setGeometry(x,y,w,h); |
2174 | 2177 | ||
2175 | } | 2178 | } |
2176 | list = config->readListEntry("ViewerLayout"); | 2179 | list = config->readListEntry("ViewerLayout"); |
2177 | if ( ! list.isEmpty() ) { | 2180 | if ( ! list.isEmpty() ) { |
2178 | x = list[0].toInt(); | 2181 | x = list[0].toInt(); |
2179 | y = list[1].toInt(); | 2182 | y = list[1].toInt(); |
2180 | w = list[2].toInt(); | 2183 | w = list[2].toInt(); |
2181 | h = list[3].toInt(); | 2184 | h = list[3].toInt(); |
2182 | KApplication::testCoords( &x,&y,&w,&h ); | 2185 | KApplication::testCoords( &x,&y,&w,&h ); |
2183 | getEventViewerDialog()->setGeometry(x,y,w,h); | 2186 | getEventViewerDialog()->setGeometry(x,y,w,h); |
2184 | } | 2187 | } |
2185 | #endif | 2188 | #endif |
2186 | config->setGroup( "Views" ); | 2189 | config->setGroup( "Views" ); |
2187 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 2190 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
2188 | 2191 | ||
2189 | QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); | 2192 | QValueList<int> sizes = config->readIntListEntry("Left Splitter Frame"); |
2190 | 2193 | ||
2191 | int resetval = 0; | 2194 | int resetval = 0; |
2192 | int maxVal = 0; | 2195 | int maxVal = 0; |
2193 | if (sizes.count() != 3) { | 2196 | if (sizes.count() != 3) { |
2194 | if ( KOPrefs::instance()->mVerticalScreen ) { | 2197 | if ( KOPrefs::instance()->mVerticalScreen ) { |
2195 | resetval = mDateNavigator->sizeHint().width()+2; | 2198 | resetval = mDateNavigator->sizeHint().width()+2; |
2196 | } else { | 2199 | } else { |
2197 | resetval = mDateNavigator->sizeHint().height()+2; | 2200 | resetval = mDateNavigator->sizeHint().height()+2; |
2198 | } | 2201 | } |
2199 | } | 2202 | } |
2200 | if ( resetval ) { | 2203 | if ( resetval ) { |
2201 | sizes.clear(); | 2204 | sizes.clear(); |
2202 | if ( KOPrefs::instance()->mVerticalScreen ) { | 2205 | if ( KOPrefs::instance()->mVerticalScreen ) { |
2203 | maxVal = QApplication::desktop()->width() -10; | 2206 | maxVal = QApplication::desktop()->width() -10; |
2204 | } else { | 2207 | } else { |
2205 | maxVal = QApplication::desktop()->height()-10; | 2208 | maxVal = QApplication::desktop()->height()-10; |
2206 | } | 2209 | } |
2207 | sizes << resetval; | 2210 | sizes << resetval; |
2208 | if ( maxVal < resetval + resetval) | 2211 | if ( maxVal < resetval + resetval) |
2209 | resetval = maxVal - resetval; | 2212 | resetval = maxVal - resetval; |
2210 | sizes << resetval; | 2213 | sizes << resetval; |
2211 | sizes << 100; | 2214 | sizes << 100; |
2212 | } | 2215 | } |
2213 | mLeftFrame->setSizes(sizes); | 2216 | mLeftFrame->setSizes(sizes); |
2214 | sizes = config->readIntListEntry("Main Splitter Frame"); | 2217 | sizes = config->readIntListEntry("Main Splitter Frame"); |
2215 | resetval = 0; | 2218 | resetval = 0; |
2216 | maxVal = 0; | 2219 | maxVal = 0; |
2217 | if (sizes.count() != 2) { | 2220 | if (sizes.count() != 2) { |
2218 | if ( !KOPrefs::instance()->mVerticalScreen ) { | 2221 | if ( !KOPrefs::instance()->mVerticalScreen ) { |
2219 | resetval = mDateNavigator->sizeHint().width()+2; | 2222 | resetval = mDateNavigator->sizeHint().width()+2; |
2220 | } else { | 2223 | } else { |
2221 | resetval = mDateNavigator->sizeHint().height()+2; | 2224 | resetval = mDateNavigator->sizeHint().height()+2; |
2222 | } | 2225 | } |
2223 | } | 2226 | } |
2224 | if ( resetval ) { | 2227 | if ( resetval ) { |
2225 | sizes.clear(); | 2228 | sizes.clear(); |
2226 | if ( !KOPrefs::instance()->mVerticalScreen ) { | 2229 | if ( !KOPrefs::instance()->mVerticalScreen ) { |
2227 | maxVal = QApplication::desktop()->width() -10; | 2230 | maxVal = QApplication::desktop()->width() -10; |
2228 | } else { | 2231 | } else { |
2229 | maxVal = QApplication::desktop()->height()-10; | 2232 | maxVal = QApplication::desktop()->height()-10; |
2230 | } | 2233 | } |
2231 | sizes << resetval; | 2234 | sizes << resetval; |
2232 | if ( maxVal < resetval + resetval) | 2235 | if ( maxVal < resetval + resetval) |
2233 | resetval = maxVal - resetval; | 2236 | resetval = maxVal - resetval; |
2234 | sizes << resetval; | 2237 | sizes << resetval; |
2235 | } | 2238 | } |
2236 | mMainFrame->setSizes(sizes); | 2239 | mMainFrame->setSizes(sizes); |
2237 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 2240 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
2238 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 2241 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
2239 | else mNavigator->selectDates( dateCount ); | 2242 | else mNavigator->selectDates( dateCount ); |
2240 | // mViewManager->readSettings( config ); | 2243 | // mViewManager->readSettings( config ); |
2241 | updateConfig(); | 2244 | updateConfig(); |
2242 | globalFlagBlockAgenda = 2; | 2245 | globalFlagBlockAgenda = 2; |
2243 | mViewManager->readSettings( config ); | 2246 | mViewManager->readSettings( config ); |
2244 | QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); | 2247 | QTimer::singleShot( 1, mDateNavigator, SLOT ( setResizeEnabled() ) ); |
2245 | } | 2248 | } |
2246 | 2249 | ||
2247 | 2250 | ||
2248 | void CalendarView::writeSettings() | 2251 | void CalendarView::writeSettings() |
2249 | { | 2252 | { |
2250 | // kdDebug() << "CalendarView::writeSettings" << endl; | 2253 | // kdDebug() << "CalendarView::writeSettings" << endl; |
2251 | 2254 | ||
2252 | KConfig *config = KOGlobals::config(); | 2255 | KConfig *config = KOGlobals::config(); |
2253 | 2256 | ||
2254 | mViewManager->writeSettings( config ); | 2257 | mViewManager->writeSettings( config ); |
2255 | mTodoList->saveLayout(config,QString("Todo Layout")); | 2258 | mTodoList->saveLayout(config,QString("Todo Layout")); |
2256 | mDialogManager->writeSettings( config ); | 2259 | mDialogManager->writeSettings( config ); |
2257 | //KOPrefs::instance()->usrWriteConfig(); | 2260 | //KOPrefs::instance()->usrWriteConfig(); |
2258 | KOPrefs::instance()->writeConfig(); | 2261 | KOPrefs::instance()->writeConfig(); |
2259 | 2262 | ||
2260 | writeFilterSettings(config); | 2263 | writeFilterSettings(config); |
2261 | config->setGroup( "AppRun" ); | 2264 | config->setGroup( "AppRun" ); |
2262 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); | 2265 | QDateTime dt ( QDate (2005,1,1), QTime( 0,0,0 ) ); |
2263 | int days = dt.daysTo( QDate::currentDate() ); | 2266 | int days = dt.daysTo( QDate::currentDate() ); |
2264 | dt = dt.addDays( days ); | 2267 | dt = dt.addDays( days ); |
2265 | int secs = dt.secsTo( QDateTime::currentDateTime() ); | 2268 | int secs = dt.secsTo( QDateTime::currentDateTime() ); |
2266 | config->writeEntry( "LatestProgramStopDays", days ); | 2269 | config->writeEntry( "LatestProgramStopDays", days ); |
2267 | config->writeEntry( "LatestProgramStopSecs", secs ); | 2270 | config->writeEntry( "LatestProgramStopSecs", secs ); |
2268 | //qDebug("KO: Writing stop time: %d ", secs); | 2271 | //qDebug("KO: Writing stop time: %d ", secs); |
2269 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); | 2272 | //qDebug("KO: Current Time %s ",QDateTime::currentDateTime().toString().latin1() ); |
2270 | //QDateTime latest = dt.addSecs ( secs ); | 2273 | //QDateTime latest = dt.addSecs ( secs ); |
2271 | //qDebug("KO: Termination on %s ", latest.toString().latin1()); | 2274 | //qDebug("KO: Termination on %s ", latest.toString().latin1()); |
2272 | config->setGroup( "Views" ); | 2275 | config->setGroup( "Views" ); |
2273 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); | 2276 | config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); |
2274 | 2277 | ||
2275 | #if 0 | 2278 | #if 0 |
2276 | qDebug("********************* "); | 2279 | qDebug("********************* "); |
2277 | qDebug("Testcode secsto "); | 2280 | qDebug("Testcode secsto "); |
2278 | QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); | 2281 | QDateTime dt_nodaylight ( QDate (2005,3,26), QTime( 0,0,0 ) ); |
2279 | QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); | 2282 | QDateTime dt_daylight ( QDate (2005,3,29), QTime( 0,0,0 ) ); |
2280 | int secsto = dt_nodaylight.secsTo( dt_daylight ); | 2283 | int secsto = dt_nodaylight.secsTo( dt_daylight ); |
2281 | QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); | 2284 | QDateTime dt_daylight_wrong = dt_nodaylight.addSecs( secsto ); |
2282 | qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); | 2285 | qDebug("dt nodaylight %s ",dt_nodaylight.toString().latin1() ); |
2283 | qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); | 2286 | qDebug("dt daylight %s ",dt_daylight.toString().latin1() ); |
2284 | qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); | 2287 | qDebug("dt daylight_wrong %s ",dt_daylight_wrong.toString().latin1() ); |
2285 | qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); | 2288 | qDebug("Computed secsTo %d . in minutes: %d . in hours: %d ", secsto, secsto/60, secsto/3600); |
2286 | qDebug("********************* testcode end"); | 2289 | qDebug("********************* testcode end"); |
2287 | 2290 | ||
2288 | #endif | 2291 | #endif |
2289 | 2292 | ||
2290 | QValueList<int> listINT = mLeftFrame->sizes(); | 2293 | QValueList<int> listINT = mLeftFrame->sizes(); |
2291 | config->writeEntry("Left Splitter Frame",listINT); | 2294 | config->writeEntry("Left Splitter Frame",listINT); |
2292 | QValueList<int> listINT2 = mMainFrame->sizes(); | 2295 | QValueList<int> listINT2 = mMainFrame->sizes(); |
2293 | config->writeEntry("Main Splitter Frame",listINT2); | 2296 | config->writeEntry("Main Splitter Frame",listINT2); |
2294 | #ifdef DESKTOP_VERSION | 2297 | #ifdef DESKTOP_VERSION |
2295 | config->setGroup("WidgetLayout"); | 2298 | config->setGroup("WidgetLayout"); |
2296 | QStringList list ;//= config->readListEntry("MainLayout"); | 2299 | QStringList list ;//= config->readListEntry("MainLayout"); |
2297 | int x,y,w,h; | 2300 | int x,y,w,h; |
2298 | QWidget* wid; | 2301 | QWidget* wid; |
2299 | wid = topLevelWidget(); | 2302 | wid = topLevelWidget(); |
2300 | x = wid->geometry().x(); | 2303 | x = wid->geometry().x(); |
2301 | y = wid->geometry().y(); | 2304 | y = wid->geometry().y(); |
2302 | w = wid->width(); | 2305 | w = wid->width(); |
2303 | h = wid->height(); | 2306 | h = wid->height(); |
2304 | list.clear(); | 2307 | list.clear(); |
2305 | list << QString::number( x ); | 2308 | list << QString::number( x ); |
2306 | list << QString::number( y ); | 2309 | list << QString::number( y ); |
2307 | list << QString::number( w ); | 2310 | list << QString::number( w ); |
2308 | list << QString::number( h ); | 2311 | list << QString::number( h ); |
2309 | config->writeEntry("MainLayout",list ); | 2312 | config->writeEntry("MainLayout",list ); |
2310 | 2313 | ||
2311 | wid = mEventEditor; | 2314 | wid = mEventEditor; |
2312 | x = wid->geometry().x(); | 2315 | x = wid->geometry().x(); |
2313 | y = wid->geometry().y(); | 2316 | y = wid->geometry().y(); |
2314 | w = wid->width(); | 2317 | w = wid->width(); |
2315 | h = wid->height(); | 2318 | h = wid->height(); |
2316 | list.clear(); | 2319 | list.clear(); |
2317 | list << QString::number( x ); | 2320 | list << QString::number( x ); |
2318 | list << QString::number( y ); | 2321 | list << QString::number( y ); |
2319 | list << QString::number( w ); | 2322 | list << QString::number( w ); |
2320 | list << QString::number( h ); | 2323 | list << QString::number( h ); |
2321 | config->writeEntry("EditEventLayout",list ); | 2324 | config->writeEntry("EditEventLayout",list ); |
2322 | 2325 | ||
2323 | wid = mTodoEditor; | 2326 | wid = mTodoEditor; |
2324 | x = wid->geometry().x(); | 2327 | x = wid->geometry().x(); |
2325 | y = wid->geometry().y(); | 2328 | y = wid->geometry().y(); |
2326 | w = wid->width(); | 2329 | w = wid->width(); |
2327 | h = wid->height(); | 2330 | h = wid->height(); |
2328 | list.clear(); | 2331 | list.clear(); |
2329 | list << QString::number( x ); | 2332 | list << QString::number( x ); |
2330 | list << QString::number( y ); | 2333 | list << QString::number( y ); |
2331 | list << QString::number( w ); | 2334 | list << QString::number( w ); |
2332 | list << QString::number( h ); | 2335 | list << QString::number( h ); |
2333 | config->writeEntry("EditTodoLayout",list ); | 2336 | config->writeEntry("EditTodoLayout",list ); |
2334 | wid = getEventViewerDialog(); | 2337 | wid = getEventViewerDialog(); |
2335 | x = wid->geometry().x(); | 2338 | x = wid->geometry().x(); |
2336 | y = wid->geometry().y(); | 2339 | y = wid->geometry().y(); |
2337 | w = wid->width(); | 2340 | w = wid->width(); |
2338 | h = wid->height(); | 2341 | h = wid->height(); |
2339 | list.clear(); | 2342 | list.clear(); |
2340 | list << QString::number( x ); | 2343 | list << QString::number( x ); |
2341 | list << QString::number( y ); | 2344 | list << QString::number( y ); |
2342 | list << QString::number( w ); | 2345 | list << QString::number( w ); |
2343 | list << QString::number( h ); | 2346 | list << QString::number( h ); |
2344 | config->writeEntry("ViewerLayout",list ); | 2347 | config->writeEntry("ViewerLayout",list ); |
2345 | wid = mDialogManager->getSearchDialog(); | 2348 | wid = mDialogManager->getSearchDialog(); |
2346 | if ( wid ) { | 2349 | if ( wid ) { |
2347 | x = wid->geometry().x(); | 2350 | x = wid->geometry().x(); |
2348 | y = wid->geometry().y(); | 2351 | y = wid->geometry().y(); |
2349 | w = wid->width(); | 2352 | w = wid->width(); |
2350 | h = wid->height(); | 2353 | h = wid->height(); |
2351 | list.clear(); | 2354 | list.clear(); |
2352 | list << QString::number( x ); | 2355 | list << QString::number( x ); |
2353 | list << QString::number( y ); | 2356 | list << QString::number( y ); |
2354 | list << QString::number( w ); | 2357 | list << QString::number( w ); |
2355 | list << QString::number( h ); | 2358 | list << QString::number( h ); |
2356 | config->writeEntry("SearchLayout",list ); | 2359 | config->writeEntry("SearchLayout",list ); |
2357 | } | 2360 | } |
2358 | #endif | 2361 | #endif |
2359 | 2362 | ||
2360 | 2363 | ||
2361 | config->sync(); | 2364 | config->sync(); |
2362 | } | 2365 | } |
2363 | 2366 | ||
2364 | void CalendarView::readFilterSettings(KConfig *config) | 2367 | void CalendarView::readFilterSettings(KConfig *config) |
2365 | { | 2368 | { |
2366 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; | 2369 | // kdDebug() << "CalendarView::readFilterSettings()" << endl; |
2367 | 2370 | ||
2368 | mFilters.clear(); | 2371 | mFilters.clear(); |
2369 | 2372 | ||
2370 | config->setGroup("General"); | 2373 | config->setGroup("General"); |
2371 | QStringList filterList = config->readListEntry("CalendarFilters"); | 2374 | QStringList filterList = config->readListEntry("CalendarFilters"); |
2372 | 2375 | ||
2373 | QStringList::ConstIterator it = filterList.begin(); | 2376 | QStringList::ConstIterator it = filterList.begin(); |
2374 | QStringList::ConstIterator end = filterList.end(); | 2377 | QStringList::ConstIterator end = filterList.end(); |
2375 | while(it != end) { | 2378 | while(it != end) { |
2376 | // kdDebug() << " filter: " << (*it) << endl; | 2379 | // kdDebug() << " filter: " << (*it) << endl; |
2377 | 2380 | ||
2378 | CalFilter *filter; | 2381 | CalFilter *filter; |
2379 | filter = new CalFilter(*it); | 2382 | filter = new CalFilter(*it); |
2380 | config->setGroup("Filter_" + (*it).utf8()); | 2383 | config->setGroup("Filter_" + (*it).utf8()); |
2381 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); | 2384 | //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); |
2382 | filter->setCriteria(config->readNumEntry("Criteria",0)); | 2385 | filter->setCriteria(config->readNumEntry("Criteria",0)); |
2383 | filter->setCategoryList(config->readListEntry("CategoryList")); | 2386 | filter->setCategoryList(config->readListEntry("CategoryList")); |
2384 | mFilters.append(filter); | 2387 | mFilters.append(filter); |
2385 | 2388 | ||
2386 | ++it; | 2389 | ++it; |
2387 | } | 2390 | } |
2388 | 2391 | ||
2389 | if (mFilters.count() == 0) { | 2392 | if (mFilters.count() == 0) { |
2390 | CalFilter *filter = new CalFilter(i18n("Default")); | 2393 | CalFilter *filter = new CalFilter(i18n("Default")); |
2391 | mFilters.append(filter); | 2394 | mFilters.append(filter); |
2392 | } | 2395 | } |
2393 | mFilterView->updateFilters(); | 2396 | mFilterView->updateFilters(); |
2394 | config->setGroup("FilterView"); | 2397 | config->setGroup("FilterView"); |
2395 | 2398 | ||
2396 | mFilterView->blockSignals(true); | 2399 | mFilterView->blockSignals(true); |
2397 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); | 2400 | mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); |
2398 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); | 2401 | mFilterView->setSelectedFilter(config->readEntry("Current Filter")); |
2399 | mFilterView->blockSignals(false); | 2402 | mFilterView->blockSignals(false); |
2400 | // We do it manually to avoid it being done twice by the above calls | 2403 | // We do it manually to avoid it being done twice by the above calls |
2401 | updateFilter(); | 2404 | updateFilter(); |
2402 | } | 2405 | } |
2403 | 2406 | ||
2404 | void CalendarView::writeFilterSettings(KConfig *config) | 2407 | void CalendarView::writeFilterSettings(KConfig *config) |
2405 | { | 2408 | { |
2406 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; | 2409 | // kdDebug() << "CalendarView::writeFilterSettings()" << endl; |
2407 | 2410 | ||
2408 | QStringList filterList; | 2411 | QStringList filterList; |
2409 | 2412 | ||
2410 | CalFilter *filter = mFilters.first(); | 2413 | CalFilter *filter = mFilters.first(); |
2411 | while(filter) { | 2414 | while(filter) { |
2412 | // kdDebug() << " fn: " << filter->name() << endl; | 2415 | // kdDebug() << " fn: " << filter->name() << endl; |
2413 | filterList << filter->name(); | 2416 | filterList << filter->name(); |
2414 | config->setGroup("Filter_" + filter->name().utf8()); | 2417 | config->setGroup("Filter_" + filter->name().utf8()); |
2415 | config->writeEntry("Criteria",filter->criteria()); | 2418 | config->writeEntry("Criteria",filter->criteria()); |
2416 | config->writeEntry("CategoryList",filter->categoryList()); | 2419 | config->writeEntry("CategoryList",filter->categoryList()); |
2417 | filter = mFilters.next(); | 2420 | filter = mFilters.next(); |
2418 | } | 2421 | } |
2419 | config->setGroup("General"); | 2422 | config->setGroup("General"); |
2420 | config->writeEntry("CalendarFilters",filterList); | 2423 | config->writeEntry("CalendarFilters",filterList); |
2421 | 2424 | ||
2422 | config->setGroup("FilterView"); | 2425 | config->setGroup("FilterView"); |
2423 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); | 2426 | config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); |
2424 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); | 2427 | config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); |
2425 | } | 2428 | } |
2426 | 2429 | ||
2427 | 2430 | ||
2428 | void CalendarView::goToday() | 2431 | void CalendarView::goToday() |
2429 | { | 2432 | { |
2430 | if ( mViewManager->currentView()->isMonthView() ) | 2433 | if ( mViewManager->currentView()->isMonthView() ) |
2431 | mNavigator->selectTodayMonth(); | 2434 | mNavigator->selectTodayMonth(); |
2432 | else | 2435 | else |
2433 | mNavigator->selectToday(); | 2436 | mNavigator->selectToday(); |
2434 | } | 2437 | } |
2435 | 2438 | ||
2436 | void CalendarView::goNext() | 2439 | void CalendarView::goNext() |
2437 | { | 2440 | { |
2438 | mNavigator->selectNext(); | 2441 | mNavigator->selectNext(); |
2439 | } | 2442 | } |
2440 | 2443 | ||
2441 | void CalendarView::goPrevious() | 2444 | void CalendarView::goPrevious() |
2442 | { | 2445 | { |
2443 | mNavigator->selectPrevious(); | 2446 | mNavigator->selectPrevious(); |
2444 | } | 2447 | } |
2445 | void CalendarView::goNextMonth() | 2448 | void CalendarView::goNextMonth() |
2446 | { | 2449 | { |
2447 | mNavigator->selectNextMonth(); | 2450 | mNavigator->selectNextMonth(); |
2448 | } | 2451 | } |
2449 | 2452 | ||
2450 | void CalendarView::goPreviousMonth() | 2453 | void CalendarView::goPreviousMonth() |
2451 | { | 2454 | { |
2452 | mNavigator->selectPreviousMonth(); | 2455 | mNavigator->selectPreviousMonth(); |
2453 | } | 2456 | } |
2454 | void CalendarView::writeLocale() | 2457 | void CalendarView::writeLocale() |
2455 | { | 2458 | { |
2456 | //KPimGlobalPrefs::instance()->setGlobalConfig(); | 2459 | //KPimGlobalPrefs::instance()->setGlobalConfig(); |
2457 | #if 0 | 2460 | #if 0 |
2458 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); | 2461 | KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); |
2459 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); | 2462 | KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); |
2460 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); | 2463 | KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); |
2461 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); | 2464 | KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); |
2462 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; | 2465 | QString dummy = KOPrefs::instance()->mUserDateFormatLong; |
2463 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); | 2466 | KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); |
2464 | dummy = KOPrefs::instance()->mUserDateFormatShort; | 2467 | dummy = KOPrefs::instance()->mUserDateFormatShort; |
2465 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); | 2468 | KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); |
2466 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, | 2469 | KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, |
2467 | KOPrefs::instance()->mDaylightsavingStart, | 2470 | KOPrefs::instance()->mDaylightsavingStart, |
2468 | KOPrefs::instance()->mDaylightsavingEnd ); | 2471 | KOPrefs::instance()->mDaylightsavingEnd ); |
2469 | KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); | 2472 | KGlobal::locale()->setTimezone( KPimGlobalPrefs::instance()->mTimeZoneId ); |
2470 | #endif | 2473 | #endif |
2471 | } | 2474 | } |
2472 | void CalendarView::updateConfig() | 2475 | void CalendarView::updateConfig() |
2473 | { | 2476 | { |
2474 | writeLocale(); | 2477 | writeLocale(); |
2475 | if ( KOPrefs::instance()->mUseAppColors ) | 2478 | if ( KOPrefs::instance()->mUseAppColors ) |
2476 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); | 2479 | QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); |
2477 | emit configChanged(); | 2480 | emit configChanged(); |
2478 | mTodoList->updateConfig(); | 2481 | mTodoList->updateConfig(); |
2479 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); | 2482 | // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); |
2480 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2483 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
2481 | // To make the "fill window" configurations work | 2484 | // To make the "fill window" configurations work |
2482 | //mViewManager->raiseCurrentView(); | 2485 | //mViewManager->raiseCurrentView(); |
2483 | } | 2486 | } |
2484 | 2487 | ||
2485 | 2488 | ||
2486 | void CalendarView::eventChanged(Event *event) | 2489 | void CalendarView::eventChanged(Event *event) |
2487 | { | 2490 | { |
2488 | changeEventDisplay(event,KOGlobals::EVENTEDITED); | 2491 | changeEventDisplay(event,KOGlobals::EVENTEDITED); |
2489 | //updateUnmanagedViews(); | 2492 | //updateUnmanagedViews(); |
2490 | } | 2493 | } |
2491 | 2494 | ||
2492 | void CalendarView::eventAdded(Event *event) | 2495 | void CalendarView::eventAdded(Event *event) |
2493 | { | 2496 | { |
2494 | changeEventDisplay(event,KOGlobals::EVENTADDED); | 2497 | changeEventDisplay(event,KOGlobals::EVENTADDED); |
2495 | } | 2498 | } |
2496 | 2499 | ||
2497 | void CalendarView::eventToBeDeleted(Event *) | 2500 | void CalendarView::eventToBeDeleted(Event *) |
2498 | { | 2501 | { |
2499 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; | 2502 | kdDebug() << "CalendarView::eventToBeDeleted(): to be implemented" << endl; |
2500 | } | 2503 | } |
2501 | 2504 | ||
2502 | void CalendarView::eventDeleted() | 2505 | void CalendarView::eventDeleted() |
2503 | { | 2506 | { |
2504 | changeEventDisplay(0,KOGlobals::EVENTDELETED); | 2507 | changeEventDisplay(0,KOGlobals::EVENTDELETED); |
2505 | } | 2508 | } |
2506 | void CalendarView::changeTodoDisplay(Todo *which, int action) | 2509 | void CalendarView::changeTodoDisplay(Todo *which, int action) |
2507 | { | 2510 | { |
2508 | changeIncidenceDisplay((Incidence *)which, action); | 2511 | changeIncidenceDisplay((Incidence *)which, action); |
2509 | mDateNavigator->updateView(); //LR | 2512 | mDateNavigator->updateView(); //LR |
2510 | //mDialogManager->updateSearchDialog(); | 2513 | //mDialogManager->updateSearchDialog(); |
2511 | 2514 | ||
2512 | if (which) { | 2515 | if (which) { |
2513 | mViewManager->updateWNview(); | 2516 | mViewManager->updateWNview(); |
2514 | //mTodoList->updateView(); | 2517 | //mTodoList->updateView(); |
2515 | } | 2518 | } |
2516 | 2519 | ||
2517 | } | 2520 | } |
2518 | 2521 | ||
2519 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) | 2522 | void CalendarView::changeIncidenceDisplay(Incidence *which, int action) |
2520 | { | 2523 | { |
2521 | updateUnmanagedViews(); | 2524 | updateUnmanagedViews(); |
2522 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); | 2525 | //qDebug(" CalendarView::changeIncidenceDisplay++++++++++++++++++++++++++ %d %d ",which, action ); |
2523 | if ( action == KOGlobals::EVENTDELETED ) { //delete | 2526 | if ( action == KOGlobals::EVENTDELETED ) { //delete |
2524 | mCalendar->checkAlarmForIncidence( 0, true ); | 2527 | mCalendar->checkAlarmForIncidence( 0, true ); |
2525 | if ( mEventViewerDialog ) | 2528 | if ( mEventViewerDialog ) |
2526 | mEventViewerDialog->hide(); | 2529 | mEventViewerDialog->hide(); |
2527 | } | 2530 | } |
2528 | else | 2531 | else |
2529 | mCalendar->checkAlarmForIncidence( which , false ); | 2532 | mCalendar->checkAlarmForIncidence( which , false ); |
2530 | } | 2533 | } |
2531 | 2534 | ||
2532 | // most of the changeEventDisplays() right now just call the view's | 2535 | // most of the changeEventDisplays() right now just call the view's |
2533 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. | 2536 | // total update mode, but they SHOULD be recoded to be more refresh-efficient. |
2534 | void CalendarView::changeEventDisplay(Event *which, int action) | 2537 | void CalendarView::changeEventDisplay(Event *which, int action) |
2535 | { | 2538 | { |
2536 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; | 2539 | // kdDebug() << "CalendarView::changeEventDisplay" << endl; |
2537 | changeIncidenceDisplay((Incidence *)which, action); | 2540 | changeIncidenceDisplay((Incidence *)which, action); |
2538 | mDateNavigator->updateView(); | 2541 | mDateNavigator->updateView(); |
2539 | //mDialogManager->updateSearchDialog(); | 2542 | //mDialogManager->updateSearchDialog(); |
2540 | 2543 | ||
2541 | if (which) { | 2544 | if (which) { |
2542 | // If there is an event view visible update the display | 2545 | // If there is an event view visible update the display |
2543 | mViewManager->currentView()->changeEventDisplay(which,action); | 2546 | mViewManager->currentView()->changeEventDisplay(which,action); |
2544 | // TODO: check, if update needed | 2547 | // TODO: check, if update needed |
2545 | // if (which->getTodoStatus()) { | 2548 | // if (which->getTodoStatus()) { |
2546 | mTodoList->updateView(); | 2549 | mTodoList->updateView(); |
2547 | // } | 2550 | // } |
2548 | } else { | 2551 | } else { |
2549 | mViewManager->currentView()->updateView(); | 2552 | mViewManager->currentView()->updateView(); |
2550 | } | 2553 | } |
2551 | } | 2554 | } |
2552 | 2555 | ||
2553 | 2556 | ||
2554 | void CalendarView::updateTodoViews() | 2557 | void CalendarView::updateTodoViews() |
2555 | { | 2558 | { |
2556 | mTodoList->updateView(); | 2559 | mTodoList->updateView(); |
2557 | mViewManager->currentView()->updateView(); | 2560 | mViewManager->currentView()->updateView(); |
2558 | 2561 | ||
2559 | } | 2562 | } |
2560 | 2563 | ||
2561 | 2564 | ||
2562 | void CalendarView::updateView(const QDate &start, const QDate &end) | 2565 | void CalendarView::updateView(const QDate &start, const QDate &end) |
2563 | { | 2566 | { |
2564 | mTodoList->updateView(); | 2567 | mTodoList->updateView(); |
2565 | mViewManager->updateView(start, end); | 2568 | mViewManager->updateView(start, end); |
2566 | //mDateNavigator->updateView(); | 2569 | //mDateNavigator->updateView(); |
2567 | } | 2570 | } |
2568 | 2571 | ||
2569 | void CalendarView::clearAllViews() | 2572 | void CalendarView::clearAllViews() |
2570 | { | 2573 | { |
2571 | mTodoList->clearList(); | 2574 | mTodoList->clearList(); |
2572 | mViewManager->clearAllViews(); | 2575 | mViewManager->clearAllViews(); |
2573 | SearchDialog * sd = mDialogManager->getSearchDialog(); | 2576 | SearchDialog * sd = mDialogManager->getSearchDialog(); |
2574 | if ( sd ) { | 2577 | if ( sd ) { |
2575 | KOListView* kol = sd->listview(); | 2578 | KOListView* kol = sd->listview(); |
2576 | if ( kol ) | 2579 | if ( kol ) |
2577 | kol->clearList(); | 2580 | kol->clearList(); |
2578 | } | 2581 | } |
2579 | } | 2582 | } |
2580 | void CalendarView::updateView() | 2583 | void CalendarView::updateView() |
2581 | { | 2584 | { |
2582 | DateList tmpList = mNavigator->selectedDates(); | 2585 | DateList tmpList = mNavigator->selectedDates(); |
2583 | 2586 | ||
2584 | if ( KOPrefs::instance()->mHideNonStartedTodos ) | 2587 | if ( KOPrefs::instance()->mHideNonStartedTodos ) |
2585 | mTodoList->updateView(); | 2588 | mTodoList->updateView(); |
2586 | // We assume that the navigator only selects consecutive days. | 2589 | // We assume that the navigator only selects consecutive days. |
2587 | updateView( tmpList.first(), tmpList.last() ); | 2590 | updateView( tmpList.first(), tmpList.last() ); |
2588 | } | 2591 | } |
2589 | 2592 | ||
2590 | void CalendarView::updateUnmanagedViews() | 2593 | void CalendarView::updateUnmanagedViews() |
2591 | { | 2594 | { |
2592 | mDateNavigator->updateDayMatrix(); | 2595 | mDateNavigator->updateDayMatrix(); |
2593 | } | 2596 | } |
2594 | 2597 | ||
2595 | int CalendarView::msgItemDelete(const QString name) | 2598 | int CalendarView::msgItemDelete(const QString name) |
2596 | { | 2599 | { |
2597 | return KMessageBox::warningContinueCancel(this,name +"\n\n"+ | 2600 | return KMessageBox::warningContinueCancel(this,name +"\n\n"+ |
2598 | i18n("This item will be\npermanently deleted."), | 2601 | i18n("This item will be\npermanently deleted."), |
2599 | i18n("KO/Pi Confirmation"),i18n("Delete")); | 2602 | i18n("KO/Pi Confirmation"),i18n("Delete")); |
2600 | } | 2603 | } |
2601 | 2604 | ||
2602 | 2605 | ||
2603 | void CalendarView::edit_cut() | 2606 | void CalendarView::edit_cut() |
2604 | { | 2607 | { |
2605 | Event *anEvent=0; | 2608 | Event *anEvent=0; |
2606 | 2609 | ||
2607 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2610 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2608 | 2611 | ||
2609 | if (mViewManager->currentView()->isEventView()) { | 2612 | if (mViewManager->currentView()->isEventView()) { |
2610 | if ( incidence && incidence->typeID() == eventID ) { | 2613 | if ( incidence && incidence->typeID() == eventID ) { |
2611 | anEvent = static_cast<Event *>(incidence); | 2614 | anEvent = static_cast<Event *>(incidence); |
2612 | } | 2615 | } |
2613 | } | 2616 | } |
2614 | 2617 | ||
2615 | if (!anEvent) { | 2618 | if (!anEvent) { |
2616 | KNotifyClient::beep(); | 2619 | KNotifyClient::beep(); |
2617 | return; | 2620 | return; |
2618 | } | 2621 | } |
2619 | DndFactory factory( mCalendar ); | 2622 | DndFactory factory( mCalendar ); |
2620 | factory.cutIncidence(anEvent); | 2623 | factory.cutIncidence(anEvent); |
2621 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); | 2624 | changeEventDisplay(anEvent, KOGlobals::EVENTDELETED); |
2622 | } | 2625 | } |
2623 | 2626 | ||
2624 | void CalendarView::edit_copy() | 2627 | void CalendarView::edit_copy() |
2625 | { | 2628 | { |
2626 | Event *anEvent=0; | 2629 | Event *anEvent=0; |
2627 | 2630 | ||
2628 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); | 2631 | Incidence *incidence = mViewManager->currentView()->selectedIncidences().first(); |
2629 | 2632 | ||
2630 | if (mViewManager->currentView()->isEventView()) { | 2633 | if (mViewManager->currentView()->isEventView()) { |
2631 | if ( incidence && incidence->typeID() == eventID ) { | 2634 | if ( incidence && incidence->typeID() == eventID ) { |
2632 | anEvent = static_cast<Event *>(incidence); | 2635 | anEvent = static_cast<Event *>(incidence); |
2633 | } | 2636 | } |
2634 | } | 2637 | } |
2635 | 2638 | ||
2636 | if (!anEvent) { | 2639 | if (!anEvent) { |
2637 | KNotifyClient::beep(); | 2640 | KNotifyClient::beep(); |
2638 | return; | 2641 | return; |
2639 | } | 2642 | } |
2640 | DndFactory factory( mCalendar ); | 2643 | DndFactory factory( mCalendar ); |
2641 | factory.copyIncidence(anEvent); | 2644 | factory.copyIncidence(anEvent); |
2642 | } | 2645 | } |
2643 | 2646 | ||
2644 | void CalendarView::edit_paste() | 2647 | void CalendarView::edit_paste() |
2645 | { | 2648 | { |
2646 | QDate date = mNavigator->selectedDates().first(); | 2649 | QDate date = mNavigator->selectedDates().first(); |
2647 | 2650 | ||
2648 | DndFactory factory( mCalendar ); | 2651 | DndFactory factory( mCalendar ); |
2649 | Event *pastedEvent = (Event *)factory.pasteIncidence( date ); | 2652 | Event *pastedEvent = (Event *)factory.pasteIncidence( date ); |
2650 | 2653 | ||
2651 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); | 2654 | changeEventDisplay( pastedEvent, KOGlobals::EVENTADDED ); |
2652 | } | 2655 | } |
2653 | void CalendarView::edit_global_options() | 2656 | void CalendarView::edit_global_options() |
2654 | { | 2657 | { |
2655 | QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; | 2658 | QString tz = KPimGlobalPrefs::instance()->mTimeZoneId; |
2656 | emit save(); | 2659 | emit save(); |
2657 | emit saveStopTimer(); | 2660 | emit saveStopTimer(); |
2658 | mDialogManager->showGlobalOptionsDialog(); | 2661 | mDialogManager->showGlobalOptionsDialog(); |
2659 | if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { | 2662 | if ( tz != KPimGlobalPrefs::instance()->mTimeZoneId) { |
2660 | emit saveStopTimer(); | 2663 | emit saveStopTimer(); |
2661 | 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!"), | 2664 | 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!"), |
2662 | i18n("Timezone settings"),i18n("Reload"))) { | 2665 | i18n("Timezone settings"),i18n("Reload"))) { |
2663 | qDebug("KO: TZ reload cancelled "); | 2666 | qDebug("KO: TZ reload cancelled "); |
2664 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2667 | mCalendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
2665 | return; | 2668 | return; |
2666 | } | 2669 | } |
2667 | qDebug("KO: Timezone change "); | 2670 | qDebug("KO: Timezone change "); |
2668 | openCalendar( MainWindow::defaultFileName() ); | 2671 | openCalendar( MainWindow::defaultFileName() ); |
2669 | setModified(true); | 2672 | setModified(true); |
2670 | } | 2673 | } |
2671 | else | 2674 | else |
2672 | qDebug("KO: No tz change "); | 2675 | qDebug("KO: No tz change "); |
2673 | } | 2676 | } |
2674 | void CalendarView::edit_options() | 2677 | void CalendarView::edit_options() |
2675 | { | 2678 | { |
2676 | mDialogManager->showOptionsDialog(); | 2679 | mDialogManager->showOptionsDialog(); |
2677 | } | 2680 | } |
2678 | 2681 | ||
2679 | 2682 | ||
2680 | void CalendarView::slotSelectPickerDate( QDate d) | 2683 | void CalendarView::slotSelectPickerDate( QDate d) |
2681 | { | 2684 | { |
2682 | mDateFrame->hide(); | 2685 | mDateFrame->hide(); |
2683 | if ( mDatePickerMode == 1 ) { | 2686 | if ( mDatePickerMode == 1 ) { |
2684 | mNavigator->slotDaySelect( d ); | 2687 | mNavigator->slotDaySelect( d ); |
2685 | } else if ( mDatePickerMode == 2 ) { | 2688 | } else if ( mDatePickerMode == 2 ) { |
2686 | if ( mMoveIncidence->typeID() == todoID ) { | 2689 | if ( mMoveIncidence->typeID() == todoID ) { |
2687 | Todo * to = (Todo *) mMoveIncidence; | 2690 | Todo * to = (Todo *) mMoveIncidence; |
2688 | QTime tim; | 2691 | QTime tim; |
2689 | int len = 0; | 2692 | int len = 0; |
2690 | if ( to->hasStartDate() && to->hasDueDate() ) | 2693 | if ( to->hasStartDate() && to->hasDueDate() ) |
2691 | len = to->dtStart().secsTo( to->dtDue()); | 2694 | len = to->dtStart().secsTo( to->dtDue()); |
2692 | if ( to->hasDueDate() ) | 2695 | if ( to->hasDueDate() ) |
2693 | tim = to->dtDue().time(); | 2696 | tim = to->dtDue().time(); |
2694 | else { | 2697 | else { |
2695 | tim = QTime ( 0,0,0 ); | 2698 | tim = QTime ( 0,0,0 ); |
2696 | to->setFloats( true ); | 2699 | to->setFloats( true ); |
2697 | to->setHasDueDate( true ); | 2700 | to->setHasDueDate( true ); |
2698 | } | 2701 | } |
2699 | QDateTime dt ( d,tim ); | 2702 | QDateTime dt ( d,tim ); |
2700 | to->setDtDue( dt ); | 2703 | to->setDtDue( dt ); |
2701 | 2704 | ||
2702 | if ( to->hasStartDate() ) { | 2705 | if ( to->hasStartDate() ) { |
2703 | if ( len>0 ) | 2706 | if ( len>0 ) |
2704 | to->setDtStart(to->dtDue().addSecs( -len )); | 2707 | to->setDtStart(to->dtDue().addSecs( -len )); |
2705 | else | 2708 | else |
2706 | if (to->dtStart() > to->dtDue() ) | 2709 | if (to->dtStart() > to->dtDue() ) |
2707 | to->setDtStart(to->dtDue().addDays( -3 )); | 2710 | to->setDtStart(to->dtDue().addDays( -3 )); |
2708 | } | 2711 | } |
2709 | 2712 | ||
2710 | todoChanged( to ); | 2713 | todoChanged( to ); |
2711 | } else { | 2714 | } else { |
2712 | if ( mMoveIncidence->doesRecur() ) { | 2715 | if ( mMoveIncidence->doesRecur() ) { |
2713 | #if 0 | 2716 | #if 0 |
2714 | // PENDING implement this | 2717 | // PENDING implement this |
2715 | Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); | 2718 | Incidence* newInc = mMoveIncidence->recreateCloneException( mMoveIncidenceOldDate ); |
2716 | mCalendar()->addIncidence( newInc ); | 2719 | mCalendar()->addIncidence( newInc ); |
2717 | if ( mMoveIncidence->typeID() == todoID ) | 2720 | if ( mMoveIncidence->typeID() == todoID ) |
2718 | emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); | 2721 | emit todoMoved((Todo*)mMoveIncidence, KOGlobals::EVENTEDITED ); |
2719 | else | 2722 | else |
2720 | emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); | 2723 | emit incidenceChanged(mMoveIncidence, KOGlobals::EVENTEDITED); |
2721 | mMoveIncidence = newInc; | 2724 | mMoveIncidence = newInc; |
2722 | 2725 | ||
2723 | #endif | 2726 | #endif |
2724 | } | 2727 | } |
2725 | QTime tim = mMoveIncidence->dtStart().time(); | 2728 | QTime tim = mMoveIncidence->dtStart().time(); |
2726 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); | 2729 | int secs = mMoveIncidence->dtStart().secsTo( mMoveIncidence->dtEnd()); |
2727 | QDateTime dt ( d,tim ); | 2730 | QDateTime dt ( d,tim ); |
2728 | mMoveIncidence->setDtStart( dt ); | 2731 | mMoveIncidence->setDtStart( dt ); |
2729 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); | 2732 | ((Event*)mMoveIncidence)->setDtEnd( dt.addSecs( secs ) ); |
2730 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); | 2733 | changeEventDisplay((Event*)mMoveIncidence, KOGlobals::EVENTEDITED); |
2731 | } | 2734 | } |
2732 | 2735 | ||
2733 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); | 2736 | mMoveIncidence->setRevision( mMoveIncidence->revision()+1 ); |
2734 | } | 2737 | } |
2735 | } | 2738 | } |
2736 | 2739 | ||
2737 | void CalendarView::removeCategories() | 2740 | void CalendarView::removeCategories() |
2738 | { | 2741 | { |
2739 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2742 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2740 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2743 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2741 | QStringList catIncList; | 2744 | QStringList catIncList; |
2742 | QStringList newCatList; | 2745 | QStringList newCatList; |
2743 | Incidence* inc = incList.first(); | 2746 | Incidence* inc = incList.first(); |
2744 | int i; | 2747 | int i; |
2745 | int count = 0; | 2748 | int count = 0; |
2746 | while ( inc ) { | 2749 | while ( inc ) { |
2747 | newCatList.clear(); | 2750 | newCatList.clear(); |
2748 | catIncList = inc->categories() ; | 2751 | catIncList = inc->categories() ; |
2749 | for( i = 0; i< catIncList.count(); ++i ) { | 2752 | for( i = 0; i< catIncList.count(); ++i ) { |
2750 | if ( catList.contains (catIncList[i])) | 2753 | if ( catList.contains (catIncList[i])) |
2751 | newCatList.append( catIncList[i] ); | 2754 | newCatList.append( catIncList[i] ); |
2752 | } | 2755 | } |
2753 | newCatList.sort(); | 2756 | newCatList.sort(); |
2754 | inc->setCategories( newCatList.join(",") ); | 2757 | inc->setCategories( newCatList.join(",") ); |
2755 | inc = incList.next(); | 2758 | inc = incList.next(); |
2756 | } | 2759 | } |
2757 | } | 2760 | } |
2758 | 2761 | ||
2759 | int CalendarView::addCategories() | 2762 | int CalendarView::addCategories() |
2760 | { | 2763 | { |
2761 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); | 2764 | QPtrList<Incidence> incList = mCalendar->rawIncidences(); |
2762 | QStringList catList = KOPrefs::instance()->mCustomCategories; | 2765 | QStringList catList = KOPrefs::instance()->mCustomCategories; |
2763 | QStringList catIncList; | 2766 | QStringList catIncList; |
2764 | Incidence* inc = incList.first(); | 2767 | Incidence* inc = incList.first(); |
2765 | int i; | 2768 | int i; |
2766 | int count = 0; | 2769 | int count = 0; |
2767 | while ( inc ) { | 2770 | while ( inc ) { |
2768 | catIncList = inc->categories() ; | 2771 | catIncList = inc->categories() ; |
2769 | for( i = 0; i< catIncList.count(); ++i ) { | 2772 | for( i = 0; i< catIncList.count(); ++i ) { |
2770 | if ( !catList.contains (catIncList[i])) { | 2773 | if ( !catList.contains (catIncList[i])) { |
2771 | catList.append( catIncList[i] ); | 2774 | catList.append( catIncList[i] ); |
2772 | //qDebug("add cat %s ", catIncList[i].latin1()); | 2775 | //qDebug("add cat %s ", catIncList[i].latin1()); |
2773 | ++count; | 2776 | ++count; |
2774 | } | 2777 | } |
2775 | } | 2778 | } |
2776 | inc = incList.next(); | 2779 | inc = incList.next(); |
2777 | } | 2780 | } |
2778 | catList.sort(); | 2781 | catList.sort(); |
2779 | KOPrefs::instance()->mCustomCategories = catList; | 2782 | KOPrefs::instance()->mCustomCategories = catList; |
2780 | return count; | 2783 | return count; |
2781 | } | 2784 | } |
2782 | 2785 | ||
2783 | void CalendarView::manageCategories() | 2786 | void CalendarView::manageCategories() |
2784 | { | 2787 | { |
2785 | KOCatPrefs* cp = new KOCatPrefs(); | 2788 | KOCatPrefs* cp = new KOCatPrefs(); |
2786 | cp->show(); | 2789 | cp->show(); |
2787 | int w =cp->sizeHint().width() ; | 2790 | int w =cp->sizeHint().width() ; |
2788 | int h = cp->sizeHint().height() ; | 2791 | int h = cp->sizeHint().height() ; |
2789 | int dw = QApplication::desktop()->width(); | 2792 | int dw = QApplication::desktop()->width(); |
2790 | int dh = QApplication::desktop()->height(); | 2793 | int dh = QApplication::desktop()->height(); |
2791 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2794 | cp->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2792 | if ( !cp->exec() ) { | 2795 | if ( !cp->exec() ) { |
2793 | delete cp; | 2796 | delete cp; |
2794 | return; | 2797 | return; |
2795 | } | 2798 | } |
2796 | int count = 0; | 2799 | int count = 0; |
2797 | if ( cp->addCat() ) { | 2800 | if ( cp->addCat() ) { |
2798 | count = addCategories(); | 2801 | count = addCategories(); |
2799 | if ( count ) { | 2802 | if ( count ) { |
2800 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); | 2803 | topLevelWidget()->setCaption(QString::number( count )+ i18n(" Categories added to list! ")); |
2801 | writeSettings(); | 2804 | writeSettings(); |
2802 | } else | 2805 | } else |
2803 | topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); | 2806 | topLevelWidget()->setCaption(QString::number( 0 )+ i18n(" Categories added to list! ")); |
2804 | } else { | 2807 | } else { |
2805 | removeCategories(); | 2808 | removeCategories(); |
2806 | updateView(); | 2809 | updateView(); |
2807 | } | 2810 | } |
2808 | delete cp; | 2811 | delete cp; |
2809 | } | 2812 | } |
2810 | 2813 | ||
2811 | void CalendarView::beamIncidence(Incidence * Inc) | 2814 | void CalendarView::beamIncidence(Incidence * Inc) |
2812 | { | 2815 | { |
2813 | QPtrList<Incidence> delSel ; | 2816 | QPtrList<Incidence> delSel ; |
2814 | delSel.append(Inc); | 2817 | delSel.append(Inc); |
2815 | beamIncidenceList( delSel ); | 2818 | beamIncidenceList( delSel ); |
2816 | } | 2819 | } |
2817 | void CalendarView::beamCalendar() | 2820 | void CalendarView::beamCalendar() |
2818 | { | 2821 | { |
2819 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); | 2822 | QPtrList<Incidence> delSel = mCalendar->rawIncidences(); |
2820 | //qDebug("beamCalendar() "); | 2823 | //qDebug("beamCalendar() "); |
2821 | beamIncidenceList( delSel ); | 2824 | beamIncidenceList( delSel ); |
2822 | } | 2825 | } |
2823 | void CalendarView::beamFilteredCalendar() | 2826 | void CalendarView::beamFilteredCalendar() |
2824 | { | 2827 | { |
2825 | QPtrList<Incidence> delSel = mCalendar->incidences(); | 2828 | QPtrList<Incidence> delSel = mCalendar->incidences(); |
2826 | //qDebug("beamFilteredCalendar() "); | 2829 | //qDebug("beamFilteredCalendar() "); |
2827 | beamIncidenceList( delSel ); | 2830 | beamIncidenceList( delSel ); |
2828 | } | 2831 | } |
2829 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) | 2832 | void CalendarView::beamIncidenceList(QPtrList<Incidence> delSel ) |
2830 | { | 2833 | { |
2831 | if ( beamDialog->exec () == QDialog::Rejected ) | 2834 | if ( beamDialog->exec () == QDialog::Rejected ) |
2832 | return; | 2835 | return; |