author | zautrix <zautrix> | 2004-10-07 08:21:07 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 08:21:07 (UTC) |
commit | 9345818e9c291130691288e4b065190259eb4e01 (patch) (unidiff) | |
tree | 860b8666dc71fc34819e380bda48ec3427aee822 | |
parent | f1699230250cdfb37216121257196b5be9f094fa (diff) | |
download | kdepimpi-9345818e9c291130691288e4b065190259eb4e01.zip kdepimpi-9345818e9c291130691288e4b065190259eb4e01.tar.gz kdepimpi-9345818e9c291130691288e4b065190259eb4e01.tar.bz2 |
did I chanhe something?
-rw-r--r-- | korganizer/calendarview.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index d71ea08..1d62046 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1051,774 +1051,774 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int | |||
1051 | } | 1051 | } |
1052 | local->addIncidence( inL ); | 1052 | local->addIncidence( inL ); |
1053 | ++changedLocal; | 1053 | ++changedLocal; |
1054 | } | 1054 | } |
1055 | } | 1055 | } |
1056 | } else { // no conflict | 1056 | } else { // no conflict |
1057 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1057 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1058 | QString des = eventLSync->description(); | 1058 | QString des = eventLSync->description(); |
1059 | QString pref = "e"; | 1059 | QString pref = "e"; |
1060 | if ( inR->type() == "Todo" ) | 1060 | if ( inR->type() == "Todo" ) |
1061 | pref = "t"; | 1061 | pref = "t"; |
1062 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1062 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1063 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1063 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1064 | //remote->deleteIncidence( inR ); | 1064 | //remote->deleteIncidence( inR ); |
1065 | ++deletedEventR; | 1065 | ++deletedEventR; |
1066 | } else { | 1066 | } else { |
1067 | inR->setLastModified( modifiedCalendar ); | 1067 | inR->setLastModified( modifiedCalendar ); |
1068 | inL = inR->clone(); | 1068 | inL = inR->clone(); |
1069 | local->addIncidence( inL ); | 1069 | local->addIncidence( inL ); |
1070 | ++addedEvent; | 1070 | ++addedEvent; |
1071 | } | 1071 | } |
1072 | } else { | 1072 | } else { |
1073 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1073 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1074 | inR->setLastModified( modifiedCalendar ); | 1074 | inR->setLastModified( modifiedCalendar ); |
1075 | local->addIncidence( inR->clone() ); | 1075 | local->addIncidence( inR->clone() ); |
1076 | ++addedEvent; | 1076 | ++addedEvent; |
1077 | } else { | 1077 | } else { |
1078 | checkExternSyncEvent(eventRSyncSharp, inR); | 1078 | checkExternSyncEvent(eventRSyncSharp, inR); |
1079 | remote->deleteIncidence( inR ); | 1079 | remote->deleteIncidence( inR ); |
1080 | ++deletedEventR; | 1080 | ++deletedEventR; |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | } | 1083 | } |
1084 | } | 1084 | } |
1085 | inR = er.next(); | 1085 | inR = er.next(); |
1086 | } | 1086 | } |
1087 | QPtrList<Incidence> el = local->rawIncidences(); | 1087 | QPtrList<Incidence> el = local->rawIncidences(); |
1088 | inL = el.first(); | 1088 | inL = el.first(); |
1089 | modulo = (el.count()/10)+1; | 1089 | modulo = (el.count()/10)+1; |
1090 | bar.setCaption (i18n("Add / remove events") ); | 1090 | bar.setCaption (i18n("Add / remove events") ); |
1091 | bar.setTotalSteps ( el.count() ) ; | 1091 | bar.setTotalSteps ( el.count() ) ; |
1092 | bar.show(); | 1092 | bar.show(); |
1093 | incCounter = 0; | 1093 | incCounter = 0; |
1094 | 1094 | ||
1095 | while ( inL ) { | 1095 | while ( inL ) { |
1096 | 1096 | ||
1097 | qApp->processEvents(); | 1097 | qApp->processEvents(); |
1098 | if ( ! bar.isVisible() ) | 1098 | if ( ! bar.isVisible() ) |
1099 | return false; | 1099 | return false; |
1100 | if ( incCounter % modulo == 0 ) | 1100 | if ( incCounter % modulo == 0 ) |
1101 | bar.setProgress( incCounter ); | 1101 | bar.setProgress( incCounter ); |
1102 | ++incCounter; | 1102 | ++incCounter; |
1103 | uid = inL->uid(); | 1103 | uid = inL->uid(); |
1104 | bool skipIncidence = false; | 1104 | bool skipIncidence = false; |
1105 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1105 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1106 | skipIncidence = true; | 1106 | skipIncidence = true; |
1107 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 1107 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) |
1108 | skipIncidence = true; | 1108 | skipIncidence = true; |
1109 | if ( !skipIncidence ) { | 1109 | if ( !skipIncidence ) { |
1110 | inR = remote->incidence( uid ); | 1110 | inR = remote->incidence( uid ); |
1111 | if ( ! inR ) { | 1111 | if ( ! inR ) { |
1112 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1112 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1113 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1113 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1114 | checkExternSyncEvent(eventLSyncSharp, inL); | 1114 | checkExternSyncEvent(eventLSyncSharp, inL); |
1115 | local->deleteIncidence( inL ); | 1115 | local->deleteIncidence( inL ); |
1116 | ++deletedEventL; | 1116 | ++deletedEventL; |
1117 | } else { | 1117 | } else { |
1118 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1118 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1119 | inL->removeID(mCurrentSyncDevice ); | 1119 | inL->removeID(mCurrentSyncDevice ); |
1120 | ++addedEventR; | 1120 | ++addedEventR; |
1121 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1121 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1122 | inL->setLastModified( modifiedCalendar ); | 1122 | inL->setLastModified( modifiedCalendar ); |
1123 | inR = inL->clone(); | 1123 | inR = inL->clone(); |
1124 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1124 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1125 | remote->addIncidence( inR ); | 1125 | remote->addIncidence( inR ); |
1126 | } | 1126 | } |
1127 | } | 1127 | } |
1128 | } else { | 1128 | } else { |
1129 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1129 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1130 | checkExternSyncEvent(eventLSyncSharp, inL); | 1130 | checkExternSyncEvent(eventLSyncSharp, inL); |
1131 | local->deleteIncidence( inL ); | 1131 | local->deleteIncidence( inL ); |
1132 | ++deletedEventL; | 1132 | ++deletedEventL; |
1133 | } else { | 1133 | } else { |
1134 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 1134 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { |
1135 | ++addedEventR; | 1135 | ++addedEventR; |
1136 | inL->setLastModified( modifiedCalendar ); | 1136 | inL->setLastModified( modifiedCalendar ); |
1137 | remote->addIncidence( inL->clone() ); | 1137 | remote->addIncidence( inL->clone() ); |
1138 | } | 1138 | } |
1139 | } | 1139 | } |
1140 | } | 1140 | } |
1141 | } | 1141 | } |
1142 | } | 1142 | } |
1143 | inL = el.next(); | 1143 | inL = el.next(); |
1144 | } | 1144 | } |
1145 | int delFut = 0; | 1145 | int delFut = 0; |
1146 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 1146 | if ( KOPrefs::instance()->mWriteBackInFuture ) { |
1147 | er = remote->rawIncidences(); | 1147 | er = remote->rawIncidences(); |
1148 | inR = er.first(); | 1148 | inR = er.first(); |
1149 | QDateTime dt; | 1149 | QDateTime dt; |
1150 | QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); | 1150 | QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); |
1151 | QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); | 1151 | QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); |
1152 | while ( inR ) { | 1152 | while ( inR ) { |
1153 | if ( inR->type() == "Todo" ) { | 1153 | if ( inR->type() == "Todo" ) { |
1154 | Todo * t = (Todo*)inR; | 1154 | Todo * t = (Todo*)inR; |
1155 | if ( t->hasDueDate() ) | 1155 | if ( t->hasDueDate() ) |
1156 | dt = t->dtDue(); | 1156 | dt = t->dtDue(); |
1157 | else | 1157 | else |
1158 | dt = cur.addSecs( 62 ); | 1158 | dt = cur.addSecs( 62 ); |
1159 | } | 1159 | } |
1160 | else if (inR->type() == "Event" ) { | 1160 | else if (inR->type() == "Event" ) { |
1161 | bool ok; | 1161 | bool ok; |
1162 | dt = inR->getNextOccurence( cur, &ok ); | 1162 | dt = inR->getNextOccurence( cur, &ok ); |
1163 | if ( !ok ) | 1163 | if ( !ok ) |
1164 | dt = cur.addSecs( -62 ); | 1164 | dt = cur.addSecs( -62 ); |
1165 | } | 1165 | } |
1166 | else | 1166 | else |
1167 | dt = inR->dtStart(); | 1167 | dt = inR->dtStart(); |
1168 | if ( dt < cur || dt > end ) { | 1168 | if ( dt < cur || dt > end ) { |
1169 | remote->deleteIncidence( inR ); | 1169 | remote->deleteIncidence( inR ); |
1170 | ++delFut; | 1170 | ++delFut; |
1171 | } | 1171 | } |
1172 | inR = er.next(); | 1172 | inR = er.next(); |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | bar.hide(); | 1175 | bar.hide(); |
1176 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1176 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1177 | eventLSync->setReadOnly( false ); | 1177 | eventLSync->setReadOnly( false ); |
1178 | eventLSync->setDtStart( mLastCalendarSync ); | 1178 | eventLSync->setDtStart( mLastCalendarSync ); |
1179 | eventRSync->setDtStart( mLastCalendarSync ); | 1179 | eventRSync->setDtStart( mLastCalendarSync ); |
1180 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1180 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1181 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1181 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1182 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1182 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1183 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1183 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1184 | eventLSync->setReadOnly( true ); | 1184 | eventLSync->setReadOnly( true ); |
1185 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 1185 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
1186 | remote->addEvent( eventRSync ); | 1186 | remote->addEvent( eventRSync ); |
1187 | QString mes; | 1187 | QString mes; |
1188 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); | 1188 | 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"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); |
1189 | QString delmess; | 1189 | QString delmess; |
1190 | if ( delFut ) { | 1190 | if ( delFut ) { |
1191 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); | 1191 | delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); |
1192 | mes += delmess; | 1192 | mes += delmess; |
1193 | } | 1193 | } |
1194 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 1194 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
1195 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 1195 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
1196 | } | 1196 | } |
1197 | qDebug( mes ); | 1197 | qDebug( mes ); |
1198 | mCalendar->checkAlarmForIncidence( 0, true ); | 1198 | mCalendar->checkAlarmForIncidence( 0, true ); |
1199 | return syncOK; | 1199 | return syncOK; |
1200 | } | 1200 | } |
1201 | 1201 | ||
1202 | void CalendarView::setSyncDevice( QString s ) | 1202 | void CalendarView::setSyncDevice( QString s ) |
1203 | { | 1203 | { |
1204 | mCurrentSyncDevice= s; | 1204 | mCurrentSyncDevice= s; |
1205 | } | 1205 | } |
1206 | void CalendarView::setSyncName( QString s ) | 1206 | void CalendarView::setSyncName( QString s ) |
1207 | { | 1207 | { |
1208 | mCurrentSyncName= s; | 1208 | mCurrentSyncName= s; |
1209 | } | 1209 | } |
1210 | bool CalendarView::syncCalendar(QString filename, int mode) | 1210 | bool CalendarView::syncCalendar(QString filename, int mode) |
1211 | { | 1211 | { |
1212 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1212 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1213 | CalendarLocal* calendar = new CalendarLocal(); | 1213 | CalendarLocal* calendar = new CalendarLocal(); |
1214 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1214 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1215 | FileStorage* storage = new FileStorage( calendar ); | 1215 | FileStorage* storage = new FileStorage( calendar ); |
1216 | bool syncOK = false; | 1216 | bool syncOK = false; |
1217 | storage->setFileName( filename ); | 1217 | storage->setFileName( filename ); |
1218 | // qDebug("loading ... "); | 1218 | // qDebug("loading ... "); |
1219 | if ( storage->load() ) { | 1219 | if ( storage->load() ) { |
1220 | getEventViewerDialog()->setSyncMode( true ); | 1220 | getEventViewerDialog()->setSyncMode( true ); |
1221 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1221 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1222 | getEventViewerDialog()->setSyncMode( false ); | 1222 | getEventViewerDialog()->setSyncMode( false ); |
1223 | if ( syncOK ) { | 1223 | if ( syncOK ) { |
1224 | if ( KOPrefs::instance()->mWriteBackFile ) | 1224 | if ( KOPrefs::instance()->mWriteBackFile ) |
1225 | { | 1225 | { |
1226 | storage->setSaveFormat( new ICalFormat() ); | 1226 | storage->setSaveFormat( new ICalFormat() ); |
1227 | storage->save(); | 1227 | storage->save(); |
1228 | } | 1228 | } |
1229 | } | 1229 | } |
1230 | setModified( true ); | 1230 | setModified( true ); |
1231 | } | 1231 | } |
1232 | delete storage; | 1232 | delete storage; |
1233 | delete calendar; | 1233 | delete calendar; |
1234 | if ( syncOK ) | 1234 | if ( syncOK ) |
1235 | updateView(); | 1235 | updateView(); |
1236 | return syncOK; | 1236 | return syncOK; |
1237 | } | 1237 | } |
1238 | void CalendarView::syncPhone() | 1238 | void CalendarView::syncPhone() |
1239 | { | 1239 | { |
1240 | syncExternal( 1 ); | 1240 | syncExternal( 1 ); |
1241 | } | 1241 | } |
1242 | void CalendarView::syncExternal( int mode ) | 1242 | void CalendarView::syncExternal( int mode ) |
1243 | { | 1243 | { |
1244 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 1244 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1245 | //mCurrentSyncDevice = "sharp-DTM"; | 1245 | //mCurrentSyncDevice = "sharp-DTM"; |
1246 | if ( KOPrefs::instance()->mAskForPreferences ) | 1246 | if ( KOPrefs::instance()->mAskForPreferences ) |
1247 | edit_sync_options(); | 1247 | edit_sync_options(); |
1248 | qApp->processEvents(); | 1248 | qApp->processEvents(); |
1249 | CalendarLocal* calendar = new CalendarLocal(); | 1249 | CalendarLocal* calendar = new CalendarLocal(); |
1250 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1250 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1251 | bool syncOK = false; | 1251 | bool syncOK = false; |
1252 | bool loadSuccess = false; | 1252 | bool loadSuccess = false; |
1253 | PhoneFormat* phoneFormat = 0; | 1253 | PhoneFormat* phoneFormat = 0; |
1254 | #ifndef DESKTOP_VERSION | 1254 | #ifndef DESKTOP_VERSION |
1255 | SharpFormat* sharpFormat = 0; | 1255 | SharpFormat* sharpFormat = 0; |
1256 | if ( mode == 0 ) { // sharp | 1256 | if ( mode == 0 ) { // sharp |
1257 | sharpFormat = new SharpFormat () ; | 1257 | sharpFormat = new SharpFormat () ; |
1258 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 1258 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
1259 | 1259 | ||
1260 | } else | 1260 | } else |
1261 | #endif | 1261 | #endif |
1262 | if ( mode == 1 ) { // phone | 1262 | if ( mode == 1 ) { // phone |
1263 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 1263 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
1264 | KOPrefs::instance()->mPhoneDevice, | 1264 | KOPrefs::instance()->mPhoneDevice, |
1265 | KOPrefs::instance()->mPhoneConnection, | 1265 | KOPrefs::instance()->mPhoneConnection, |
1266 | KOPrefs::instance()->mPhoneModel); | 1266 | KOPrefs::instance()->mPhoneModel); |
1267 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 1267 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
1268 | 1268 | ||
1269 | } else | 1269 | } else |
1270 | return; | 1270 | return; |
1271 | if ( loadSuccess ) { | 1271 | if ( loadSuccess ) { |
1272 | getEventViewerDialog()->setSyncMode( true ); | 1272 | getEventViewerDialog()->setSyncMode( true ); |
1273 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1273 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1274 | getEventViewerDialog()->setSyncMode( false ); | 1274 | getEventViewerDialog()->setSyncMode( false ); |
1275 | qApp->processEvents(); | 1275 | qApp->processEvents(); |
1276 | if ( syncOK ) { | 1276 | if ( syncOK ) { |
1277 | if ( KOPrefs::instance()->mWriteBackFile ) | 1277 | if ( KOPrefs::instance()->mWriteBackFile ) |
1278 | { | 1278 | { |
1279 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); | 1279 | QPtrList<Incidence> iL = mCalendar->rawIncidences(); |
1280 | Incidence* inc = iL.first(); | 1280 | Incidence* inc = iL.first(); |
1281 | if ( phoneFormat ) { | 1281 | if ( phoneFormat ) { |
1282 | while ( inc ) { | 1282 | while ( inc ) { |
1283 | inc->removeID(mCurrentSyncDevice); | 1283 | inc->removeID(mCurrentSyncDevice); |
1284 | inc = iL.next(); | 1284 | inc = iL.next(); |
1285 | } | 1285 | } |
1286 | } | 1286 | } |
1287 | #ifndef DESKTOP_VERSION | 1287 | #ifndef DESKTOP_VERSION |
1288 | if ( sharpFormat ) | 1288 | if ( sharpFormat ) |
1289 | sharpFormat->save(calendar); | 1289 | sharpFormat->save(calendar); |
1290 | #endif | 1290 | #endif |
1291 | if ( phoneFormat ) | 1291 | if ( phoneFormat ) |
1292 | phoneFormat->save(calendar); | 1292 | phoneFormat->save(calendar); |
1293 | iL = calendar->rawIncidences(); | 1293 | iL = calendar->rawIncidences(); |
1294 | inc = iL.first(); | 1294 | inc = iL.first(); |
1295 | Incidence* loc; | 1295 | Incidence* loc; |
1296 | while ( inc ) { | 1296 | while ( inc ) { |
1297 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { | 1297 | if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { |
1298 | loc = mCalendar->incidence(inc->uid() ); | 1298 | loc = mCalendar->incidence(inc->uid() ); |
1299 | if ( loc ) { | 1299 | if ( loc ) { |
1300 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); | 1300 | loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); |
1301 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); | 1301 | loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); |
1302 | } | 1302 | } |
1303 | } | 1303 | } |
1304 | inc = iL.next(); | 1304 | inc = iL.next(); |
1305 | } | 1305 | } |
1306 | Incidence* lse = getLastSyncEvent(); | 1306 | Incidence* lse = getLastSyncEvent(); |
1307 | if ( lse ) { | 1307 | if ( lse ) { |
1308 | lse->setReadOnly( false ); | 1308 | lse->setReadOnly( false ); |
1309 | lse->setDescription( "" ); | 1309 | lse->setDescription( "" ); |
1310 | lse->setReadOnly( true ); | 1310 | lse->setReadOnly( true ); |
1311 | } | 1311 | } |
1312 | } | 1312 | } |
1313 | } | 1313 | } |
1314 | setModified( true ); | 1314 | setModified( true ); |
1315 | } else { | 1315 | } else { |
1316 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; | 1316 | QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; |
1317 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), | 1317 | QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), |
1318 | question, i18n("Ok")) ; | 1318 | question, i18n("Ok")) ; |
1319 | 1319 | ||
1320 | } | 1320 | } |
1321 | delete calendar; | 1321 | delete calendar; |
1322 | updateView(); | 1322 | updateView(); |
1323 | return ;//syncOK; | 1323 | return ;//syncOK; |
1324 | 1324 | ||
1325 | } | 1325 | } |
1326 | void CalendarView::syncSharp() | 1326 | void CalendarView::syncSharp() |
1327 | { | 1327 | { |
1328 | syncExternal( 0 ); | 1328 | syncExternal( 0 ); |
1329 | 1329 | ||
1330 | } | 1330 | } |
1331 | 1331 | ||
1332 | 1332 | ||
1333 | //#include <kabc/stdaddressbook.h> | 1333 | //#include <kabc/stdaddressbook.h> |
1334 | bool CalendarView::importBday() | 1334 | bool CalendarView::importBday() |
1335 | { | 1335 | { |
1336 | #ifndef KORG_NOKABC | 1336 | #ifndef KORG_NOKABC |
1337 | 1337 | ||
1338 | #ifdef DESKTOP_VERSION | 1338 | #ifdef DESKTOP_VERSION |
1339 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); | 1339 | KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); |
1340 | KABC::AddressBook::Iterator it; | 1340 | KABC::AddressBook::Iterator it; |
1341 | int count = 0; | 1341 | int count = 0; |
1342 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1342 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1343 | ++count; | 1343 | ++count; |
1344 | } | 1344 | } |
1345 | QProgressBar bar(count,0 ); | 1345 | QProgressBar bar(count,0 ); |
1346 | int w = 300; | 1346 | int w = 300; |
1347 | if ( QApplication::desktop()->width() < 320 ) | 1347 | if ( QApplication::desktop()->width() < 320 ) |
1348 | w = 220; | 1348 | w = 220; |
1349 | int h = bar.sizeHint().height() ; | 1349 | int h = bar.sizeHint().height() ; |
1350 | int dw = QApplication::desktop()->width(); | 1350 | int dw = QApplication::desktop()->width(); |
1351 | int dh = QApplication::desktop()->height(); | 1351 | int dh = QApplication::desktop()->height(); |
1352 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1352 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1353 | bar.show(); | 1353 | bar.show(); |
1354 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); | 1354 | bar.setCaption (i18n("Reading addressbook - close to abort!") ); |
1355 | qApp->processEvents(); | 1355 | qApp->processEvents(); |
1356 | count = 0; | 1356 | count = 0; |
1357 | int addCount = 0; | 1357 | int addCount = 0; |
1358 | KCal::Attendee* a = 0; | 1358 | KCal::Attendee* a = 0; |
1359 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { | 1359 | for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { |
1360 | if ( ! bar.isVisible() ) | 1360 | if ( ! bar.isVisible() ) |
1361 | return false; | 1361 | return false; |
1362 | bar.setProgress( count++ ); | 1362 | bar.setProgress( count++ ); |
1363 | qApp->processEvents(); | 1363 | qApp->processEvents(); |
1364 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); | 1364 | //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); |
1365 | if ( (*it).birthday().date().isValid() ){ | 1365 | if ( (*it).birthday().date().isValid() ){ |
1366 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1366 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1367 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) | 1367 | if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) |
1368 | ++addCount; | 1368 | ++addCount; |
1369 | } | 1369 | } |
1370 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); | 1370 | QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); |
1371 | if ( anni.isValid() ){ | 1371 | if ( anni.isValid() ){ |
1372 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; | 1372 | a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; |
1373 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) | 1373 | if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) |
1374 | ++addCount; | 1374 | ++addCount; |
1375 | } | 1375 | } |
1376 | } | 1376 | } |
1377 | updateView(); | 1377 | updateView(); |
1378 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1378 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1379 | #else //DESKTOP_VERSION | 1379 | #else //DESKTOP_VERSION |
1380 | 1380 | ||
1381 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); | 1381 | ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); |
1382 | // the result should now arrive through method insertBirthdays | 1382 | // the result should now arrive through method insertBirthdays |
1383 | 1383 | ||
1384 | #endif //DESKTOP_VERSION | 1384 | #endif //DESKTOP_VERSION |
1385 | 1385 | ||
1386 | #endif //KORG_NOKABC | 1386 | #endif //KORG_NOKABC |
1387 | 1387 | ||
1388 | 1388 | ||
1389 | return true; | 1389 | return true; |
1390 | } | 1390 | } |
1391 | 1391 | ||
1392 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI | 1392 | // This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI |
1393 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, | 1393 | void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, |
1394 | const QStringList& anniversaryList, const QStringList& realNameList, | 1394 | const QStringList& anniversaryList, const QStringList& realNameList, |
1395 | const QStringList& emailList, const QStringList& assembledNameList, | 1395 | const QStringList& emailList, const QStringList& assembledNameList, |
1396 | const QStringList& uidList) | 1396 | const QStringList& uidList) |
1397 | { | 1397 | { |
1398 | qDebug("CalendarView::insertBirthdays"); | 1398 | qDebug("CalendarView::insertBirthdays"); |
1399 | if (uid == this->name()) | 1399 | if (uid == this->name()) |
1400 | { | 1400 | { |
1401 | int count = birthdayList.count(); | 1401 | int count = birthdayList.count(); |
1402 | int addCount = 0; | 1402 | int addCount = 0; |
1403 | KCal::Attendee* a = 0; | 1403 | KCal::Attendee* a = 0; |
1404 | 1404 | ||
1405 | qDebug("CalView 1 %i", count); | 1405 | qDebug("CalView 1 %i", count); |
1406 | 1406 | ||
1407 | QProgressBar bar(count,0 ); | 1407 | QProgressBar bar(count,0 ); |
1408 | int w = 300; | 1408 | int w = 300; |
1409 | if ( QApplication::desktop()->width() < 320 ) | 1409 | if ( QApplication::desktop()->width() < 320 ) |
1410 | w = 220; | 1410 | w = 220; |
1411 | int h = bar.sizeHint().height() ; | 1411 | int h = bar.sizeHint().height() ; |
1412 | int dw = QApplication::desktop()->width(); | 1412 | int dw = QApplication::desktop()->width(); |
1413 | int dh = QApplication::desktop()->height(); | 1413 | int dh = QApplication::desktop()->height(); |
1414 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1414 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1415 | bar.show(); | 1415 | bar.show(); |
1416 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); | 1416 | bar.setCaption (i18n("inserting birthdays - close to abort!") ); |
1417 | qApp->processEvents(); | 1417 | qApp->processEvents(); |
1418 | 1418 | ||
1419 | QDate birthday; | 1419 | QDate birthday; |
1420 | QDate anniversary; | 1420 | QDate anniversary; |
1421 | QString realName; | 1421 | QString realName; |
1422 | QString email; | 1422 | QString email; |
1423 | QString assembledName; | 1423 | QString assembledName; |
1424 | QString uid; | 1424 | QString uid; |
1425 | bool ok = true; | 1425 | bool ok = true; |
1426 | for ( int i = 0; i < count; i++) | 1426 | for ( int i = 0; i < count; i++) |
1427 | { | 1427 | { |
1428 | if ( ! bar.isVisible() ) | 1428 | if ( ! bar.isVisible() ) |
1429 | return; | 1429 | return; |
1430 | bar.setProgress( i ); | 1430 | bar.setProgress( i ); |
1431 | qApp->processEvents(); | 1431 | qApp->processEvents(); |
1432 | 1432 | ||
1433 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); | 1433 | birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); |
1434 | if (!ok) { | 1434 | if (!ok) { |
1435 | ; //qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); | 1435 | ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); |
1436 | } | 1436 | } |
1437 | 1437 | ||
1438 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); | 1438 | anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); |
1439 | if (!ok) { | 1439 | if (!ok) { |
1440 | ;// qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); | 1440 | ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); |
1441 | } | 1441 | } |
1442 | realName = realNameList[i]; | 1442 | realName = realNameList[i]; |
1443 | email = emailList[i]; | 1443 | email = emailList[i]; |
1444 | assembledName = assembledNameList[i]; | 1444 | assembledName = assembledNameList[i]; |
1445 | uid = uidList[i]; | 1445 | uid = uidList[i]; |
1446 | //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() ); | 1446 | //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() ); |
1447 | 1447 | ||
1448 | if ( birthday.isValid() ){ | 1448 | if ( birthday.isValid() ){ |
1449 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1449 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1450 | KCal::Attendee::ReqParticipant,uid) ; | 1450 | KCal::Attendee::ReqParticipant,uid) ; |
1451 | if ( addAnniversary( birthday, assembledName, a, true ) ) | 1451 | if ( addAnniversary( birthday, assembledName, a, true ) ) |
1452 | ++addCount; | 1452 | ++addCount; |
1453 | } | 1453 | } |
1454 | 1454 | ||
1455 | if ( anniversary.isValid() ){ | 1455 | if ( anniversary.isValid() ){ |
1456 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, | 1456 | a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, |
1457 | KCal::Attendee::ReqParticipant,uid) ; | 1457 | KCal::Attendee::ReqParticipant,uid) ; |
1458 | if ( addAnniversary( anniversary, assembledName, a, false ) ) | 1458 | if ( addAnniversary( anniversary, assembledName, a, false ) ) |
1459 | ++addCount; | 1459 | ++addCount; |
1460 | } | 1460 | } |
1461 | } | 1461 | } |
1462 | 1462 | ||
1463 | updateView(); | 1463 | updateView(); |
1464 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); | 1464 | topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); |
1465 | 1465 | ||
1466 | } | 1466 | } |
1467 | 1467 | ||
1468 | } | 1468 | } |
1469 | 1469 | ||
1470 | 1470 | ||
1471 | 1471 | ||
1472 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) | 1472 | bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) |
1473 | { | 1473 | { |
1474 | //qDebug("addAnni "); | 1474 | //qDebug("addAnni "); |
1475 | Event * ev = new Event(); | 1475 | Event * ev = new Event(); |
1476 | if ( a ) { | 1476 | if ( a ) { |
1477 | ev->addAttendee( a ); | 1477 | ev->addAttendee( a ); |
1478 | } | 1478 | } |
1479 | QString kind; | 1479 | QString kind; |
1480 | if ( birthday ) | 1480 | if ( birthday ) |
1481 | kind = i18n( "Birthday" ); | 1481 | kind = i18n( "Birthday" ); |
1482 | else | 1482 | else |
1483 | kind = i18n( "Anniversary" ); | 1483 | kind = i18n( "Anniversary" ); |
1484 | ev->setSummary( name + " - " + kind ); | 1484 | ev->setSummary( name + " - " + kind ); |
1485 | ev->setOrganizer( "nobody@nowhere" ); | 1485 | ev->setOrganizer( "nobody@nowhere" ); |
1486 | ev->setCategories( kind ); | 1486 | ev->setCategories( kind ); |
1487 | ev->setDtStart( QDateTime(date) ); | 1487 | ev->setDtStart( QDateTime(date) ); |
1488 | ev->setDtEnd( QDateTime(date) ); | 1488 | ev->setDtEnd( QDateTime(date) ); |
1489 | ev->setFloats( true ); | 1489 | ev->setFloats( true ); |
1490 | Recurrence * rec = ev->recurrence(); | 1490 | Recurrence * rec = ev->recurrence(); |
1491 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); | 1491 | rec->setYearly(Recurrence::rYearlyMonth,1,-1); |
1492 | rec->addYearlyNum( date.month() ); | 1492 | rec->addYearlyNum( date.month() ); |
1493 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { | 1493 | if ( !mCalendar->addAnniversaryNoDup( ev ) ) { |
1494 | delete ev; | 1494 | delete ev; |
1495 | return false; | 1495 | return false; |
1496 | } | 1496 | } |
1497 | return true; | 1497 | return true; |
1498 | 1498 | ||
1499 | } | 1499 | } |
1500 | bool CalendarView::importQtopia( const QString &categories, | 1500 | bool CalendarView::importQtopia( const QString &categories, |
1501 | const QString &datebook, | 1501 | const QString &datebook, |
1502 | const QString &todolist ) | 1502 | const QString &todolist ) |
1503 | { | 1503 | { |
1504 | 1504 | ||
1505 | QtopiaFormat qtopiaFormat; | 1505 | QtopiaFormat qtopiaFormat; |
1506 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1506 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1507 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); | 1507 | if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); |
1508 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); | 1508 | if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); |
1509 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); | 1509 | if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); |
1510 | 1510 | ||
1511 | updateView(); | 1511 | updateView(); |
1512 | return true; | 1512 | return true; |
1513 | 1513 | ||
1514 | #if 0 | 1514 | #if 0 |
1515 | mGlobalSyncMode = SYNC_MODE_QTOPIA; | 1515 | mGlobalSyncMode = SYNC_MODE_QTOPIA; |
1516 | mCurrentSyncDevice = "qtopia-XML"; | 1516 | mCurrentSyncDevice = "qtopia-XML"; |
1517 | if ( KOPrefs::instance()->mAskForPreferences ) | 1517 | if ( KOPrefs::instance()->mAskForPreferences ) |
1518 | edit_sync_options(); | 1518 | edit_sync_options(); |
1519 | qApp->processEvents(); | 1519 | qApp->processEvents(); |
1520 | CalendarLocal* calendar = new CalendarLocal(); | 1520 | CalendarLocal* calendar = new CalendarLocal(); |
1521 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); | 1521 | calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); |
1522 | bool syncOK = false; | 1522 | bool syncOK = false; |
1523 | QtopiaFormat qtopiaFormat; | 1523 | QtopiaFormat qtopiaFormat; |
1524 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); | 1524 | qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); |
1525 | bool loadOk = true; | 1525 | bool loadOk = true; |
1526 | if ( !categories.isEmpty() ) | 1526 | if ( !categories.isEmpty() ) |
1527 | loadOk = qtopiaFormat.load( calendar, categories ); | 1527 | loadOk = qtopiaFormat.load( calendar, categories ); |
1528 | if ( loadOk && !datebook.isEmpty() ) | 1528 | if ( loadOk && !datebook.isEmpty() ) |
1529 | loadOk = qtopiaFormat.load( calendar, datebook ); | 1529 | loadOk = qtopiaFormat.load( calendar, datebook ); |
1530 | if ( loadOk && !todolist.isEmpty() ) | 1530 | if ( loadOk && !todolist.isEmpty() ) |
1531 | loadOk = qtopiaFormat.load( calendar, todolist ); | 1531 | loadOk = qtopiaFormat.load( calendar, todolist ); |
1532 | 1532 | ||
1533 | if ( loadOk ) { | 1533 | if ( loadOk ) { |
1534 | getEventViewerDialog()->setSyncMode( true ); | 1534 | getEventViewerDialog()->setSyncMode( true ); |
1535 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); | 1535 | syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); |
1536 | getEventViewerDialog()->setSyncMode( false ); | 1536 | getEventViewerDialog()->setSyncMode( false ); |
1537 | qApp->processEvents(); | 1537 | qApp->processEvents(); |
1538 | if ( syncOK ) { | 1538 | if ( syncOK ) { |
1539 | if ( KOPrefs::instance()->mWriteBackFile ) | 1539 | if ( KOPrefs::instance()->mWriteBackFile ) |
1540 | { | 1540 | { |
1541 | // write back XML file | 1541 | // write back XML file |
1542 | 1542 | ||
1543 | } | 1543 | } |
1544 | setModified( true ); | 1544 | setModified( true ); |
1545 | } | 1545 | } |
1546 | } else { | 1546 | } else { |
1547 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; | 1547 | QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; |
1548 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), | 1548 | QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), |
1549 | question, i18n("Ok")) ; | 1549 | question, i18n("Ok")) ; |
1550 | } | 1550 | } |
1551 | delete calendar; | 1551 | delete calendar; |
1552 | updateView(); | 1552 | updateView(); |
1553 | return syncOK; | 1553 | return syncOK; |
1554 | 1554 | ||
1555 | 1555 | ||
1556 | #endif | 1556 | #endif |
1557 | 1557 | ||
1558 | } | 1558 | } |
1559 | 1559 | ||
1560 | void CalendarView::setSyncEventsReadOnly() | 1560 | void CalendarView::setSyncEventsReadOnly() |
1561 | { | 1561 | { |
1562 | Event * ev; | 1562 | Event * ev; |
1563 | QPtrList<Event> eL = mCalendar->rawEvents(); | 1563 | QPtrList<Event> eL = mCalendar->rawEvents(); |
1564 | ev = eL.first(); | 1564 | ev = eL.first(); |
1565 | while ( ev ) { | 1565 | while ( ev ) { |
1566 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 1566 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
1567 | ev->setReadOnly( true ); | 1567 | ev->setReadOnly( true ); |
1568 | ev = eL.next(); | 1568 | ev = eL.next(); |
1569 | } | 1569 | } |
1570 | } | 1570 | } |
1571 | bool CalendarView::openCalendar(QString filename, bool merge) | 1571 | bool CalendarView::openCalendar(QString filename, bool merge) |
1572 | { | 1572 | { |
1573 | 1573 | ||
1574 | if (filename.isEmpty()) { | 1574 | if (filename.isEmpty()) { |
1575 | return false; | 1575 | return false; |
1576 | } | 1576 | } |
1577 | 1577 | ||
1578 | if (!QFile::exists(filename)) { | 1578 | if (!QFile::exists(filename)) { |
1579 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); | 1579 | KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); |
1580 | return false; | 1580 | return false; |
1581 | } | 1581 | } |
1582 | 1582 | ||
1583 | globalFlagBlockAgenda = 1; | 1583 | globalFlagBlockAgenda = 1; |
1584 | if (!merge) mCalendar->close(); | 1584 | if (!merge) mCalendar->close(); |
1585 | 1585 | ||
1586 | mStorage->setFileName( filename ); | 1586 | mStorage->setFileName( filename ); |
1587 | 1587 | ||
1588 | if ( mStorage->load() ) { | 1588 | if ( mStorage->load() ) { |
1589 | if ( merge ) ;//setModified( true ); | 1589 | if ( merge ) ;//setModified( true ); |
1590 | else { | 1590 | else { |
1591 | //setModified( true ); | 1591 | //setModified( true ); |
1592 | mViewManager->setDocumentId( filename ); | 1592 | mViewManager->setDocumentId( filename ); |
1593 | mDialogManager->setDocumentId( filename ); | 1593 | mDialogManager->setDocumentId( filename ); |
1594 | mTodoList->setDocumentId( filename ); | 1594 | mTodoList->setDocumentId( filename ); |
1595 | } | 1595 | } |
1596 | globalFlagBlockAgenda = 2; | 1596 | globalFlagBlockAgenda = 2; |
1597 | // if ( getLastSyncEvent() ) | 1597 | // if ( getLastSyncEvent() ) |
1598 | // getLastSyncEvent()->setReadOnly( true ); | 1598 | // getLastSyncEvent()->setReadOnly( true ); |
1599 | mCalendar->reInitAlarmSettings(); | 1599 | mCalendar->reInitAlarmSettings(); |
1600 | setSyncEventsReadOnly(); | 1600 | setSyncEventsReadOnly(); |
1601 | updateUnmanagedViews(); | 1601 | updateUnmanagedViews(); |
1602 | updateView(); | 1602 | updateView(); |
1603 | setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 )); | 1603 | setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 )); |
1604 | if ( filename != MainWindow::defaultFileName() ) { | 1604 | if ( filename != MainWindow::defaultFileName() ) { |
1605 | saveCalendar( MainWindow::defaultFileName() ); | 1605 | saveCalendar( MainWindow::defaultFileName() ); |
1606 | watchSavedFile(); | 1606 | watchSavedFile(); |
1607 | } | 1607 | } |
1608 | return true; | 1608 | return true; |
1609 | } else { | 1609 | } else { |
1610 | // while failing to load, the calendar object could | 1610 | // while failing to load, the calendar object could |
1611 | // have become partially populated. Clear it out. | 1611 | // have become partially populated. Clear it out. |
1612 | if ( !merge ) { | 1612 | if ( !merge ) { |
1613 | mCalendar->close(); | 1613 | mCalendar->close(); |
1614 | mViewManager->setDocumentId( filename ); | 1614 | mViewManager->setDocumentId( filename ); |
1615 | mDialogManager->setDocumentId( filename ); | 1615 | mDialogManager->setDocumentId( filename ); |
1616 | mTodoList->setDocumentId( filename ); | 1616 | mTodoList->setDocumentId( filename ); |
1617 | } | 1617 | } |
1618 | 1618 | ||
1619 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); | 1619 | //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); |
1620 | 1620 | ||
1621 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); | 1621 | QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); |
1622 | globalFlagBlockAgenda = 2; | 1622 | globalFlagBlockAgenda = 2; |
1623 | mCalendar->reInitAlarmSettings(); | 1623 | mCalendar->reInitAlarmSettings(); |
1624 | setSyncEventsReadOnly(); | 1624 | setSyncEventsReadOnly(); |
1625 | updateUnmanagedViews(); | 1625 | updateUnmanagedViews(); |
1626 | updateView(); | 1626 | updateView(); |
1627 | } | 1627 | } |
1628 | return false; | 1628 | return false; |
1629 | } | 1629 | } |
1630 | void CalendarView::showOpenError() | 1630 | void CalendarView::showOpenError() |
1631 | { | 1631 | { |
1632 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); | 1632 | KMessageBox::error(this,i18n("Couldn't load calendar\n.")); |
1633 | } | 1633 | } |
1634 | void CalendarView::setLoadedFileVersion(QDateTime dt) | 1634 | void CalendarView::setLoadedFileVersion(QDateTime dt) |
1635 | { | 1635 | { |
1636 | loadedFileVersion = dt; | 1636 | loadedFileVersion = dt; |
1637 | } | 1637 | } |
1638 | bool CalendarView::checkFileChanged(QString fn) | 1638 | bool CalendarView::checkFileChanged(QString fn) |
1639 | { | 1639 | { |
1640 | QFileInfo finf ( fn ); | 1640 | QFileInfo finf ( fn ); |
1641 | if ( !finf.exists() ) | 1641 | if ( !finf.exists() ) |
1642 | return true; | 1642 | return true; |
1643 | QDateTime dt = finf.lastModified (); | 1643 | QDateTime dt = finf.lastModified (); |
1644 | if ( dt <= loadedFileVersion ) | 1644 | if ( dt <= loadedFileVersion ) |
1645 | return false; | 1645 | return false; |
1646 | return true; | 1646 | return true; |
1647 | 1647 | ||
1648 | } | 1648 | } |
1649 | void CalendarView::watchSavedFile() | 1649 | void CalendarView::watchSavedFile() |
1650 | { | 1650 | { |
1651 | QFileInfo finf ( MainWindow::defaultFileName()); | 1651 | QFileInfo finf ( MainWindow::defaultFileName()); |
1652 | if ( !finf.exists() ) | 1652 | if ( !finf.exists() ) |
1653 | return; | 1653 | return; |
1654 | QDateTime dt = finf.lastModified (); | 1654 | QDateTime dt = finf.lastModified (); |
1655 | if ( dt < loadedFileVersion ) { | 1655 | if ( dt < loadedFileVersion ) { |
1656 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); | 1656 | //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); |
1657 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); | 1657 | QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); |
1658 | return; | 1658 | return; |
1659 | } | 1659 | } |
1660 | loadedFileVersion = dt; | 1660 | loadedFileVersion = dt; |
1661 | } | 1661 | } |
1662 | 1662 | ||
1663 | bool CalendarView::checkFileVersion(QString fn) | 1663 | bool CalendarView::checkFileVersion(QString fn) |
1664 | { | 1664 | { |
1665 | QFileInfo finf ( fn ); | 1665 | QFileInfo finf ( fn ); |
1666 | if ( !finf.exists() ) | 1666 | if ( !finf.exists() ) |
1667 | return true; | 1667 | return true; |
1668 | QDateTime dt = finf.lastModified (); | 1668 | QDateTime dt = finf.lastModified (); |
1669 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); | 1669 | //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); |
1670 | //qDebug("file on disk version %s",dt.toString().latin1()); | 1670 | //qDebug("file on disk version %s",dt.toString().latin1()); |
1671 | if ( dt <= loadedFileVersion ) | 1671 | if ( dt <= loadedFileVersion ) |
1672 | return true; | 1672 | return true; |
1673 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , | 1673 | int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , |
1674 | i18n("KO/Pi Warning"),i18n("Overwrite"), | 1674 | i18n("KO/Pi Warning"),i18n("Overwrite"), |
1675 | i18n("Sync+save")); | 1675 | i18n("Sync+save")); |
1676 | 1676 | ||
1677 | if ( km == KMessageBox::Cancel ) | 1677 | if ( km == KMessageBox::Cancel ) |
1678 | return false; | 1678 | return false; |
1679 | if ( km == KMessageBox::Yes ) | 1679 | if ( km == KMessageBox::Yes ) |
1680 | return true; | 1680 | return true; |
1681 | 1681 | ||
1682 | setSyncDevice("deleteaftersync" ); | 1682 | setSyncDevice("deleteaftersync" ); |
1683 | KOPrefs::instance()->mAskForPreferences = true; | 1683 | KOPrefs::instance()->mAskForPreferences = true; |
1684 | KOPrefs::instance()->mSyncAlgoPrefs = 3; | 1684 | KOPrefs::instance()->mSyncAlgoPrefs = 3; |
1685 | KOPrefs::instance()->mWriteBackFile = false; | 1685 | KOPrefs::instance()->mWriteBackFile = false; |
1686 | KOPrefs::instance()->mWriteBackExistingOnly = false; | 1686 | KOPrefs::instance()->mWriteBackExistingOnly = false; |
1687 | KOPrefs::instance()->mShowSyncSummary = false; | 1687 | KOPrefs::instance()->mShowSyncSummary = false; |
1688 | syncCalendar( fn, 3 ); | 1688 | syncCalendar( fn, 3 ); |
1689 | Event * e = getLastSyncEvent(); | 1689 | Event * e = getLastSyncEvent(); |
1690 | mCalendar->deleteEvent ( e ); | 1690 | mCalendar->deleteEvent ( e ); |
1691 | updateView(); | 1691 | updateView(); |
1692 | return true; | 1692 | return true; |
1693 | } | 1693 | } |
1694 | 1694 | ||
1695 | bool CalendarView::saveCalendar( QString filename ) | 1695 | bool CalendarView::saveCalendar( QString filename ) |
1696 | { | 1696 | { |
1697 | 1697 | ||
1698 | // Store back all unsaved data into calendar object | 1698 | // Store back all unsaved data into calendar object |
1699 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); | 1699 | // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); |
1700 | if ( mViewManager->currentView() ) | 1700 | if ( mViewManager->currentView() ) |
1701 | mViewManager->currentView()->flushView(); | 1701 | mViewManager->currentView()->flushView(); |
1702 | 1702 | ||
1703 | //mStorage->setFileName( filename ); | 1703 | //mStorage->setFileName( filename ); |
1704 | 1704 | ||
1705 | mStorage->setSaveFormat( new ICalFormat() ); | 1705 | mStorage->setSaveFormat( new ICalFormat() ); |
1706 | mStorage->setFileName( filename ); | 1706 | mStorage->setFileName( filename ); |
1707 | bool success; | 1707 | bool success; |
1708 | success = mStorage->save(); | 1708 | success = mStorage->save(); |
1709 | if ( !success ) { | 1709 | if ( !success ) { |
1710 | return false; | 1710 | return false; |
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | return true; | 1713 | return true; |
1714 | } | 1714 | } |
1715 | 1715 | ||
1716 | void CalendarView::closeCalendar() | 1716 | void CalendarView::closeCalendar() |
1717 | { | 1717 | { |
1718 | 1718 | ||
1719 | // child windows no longer valid | 1719 | // child windows no longer valid |
1720 | emit closingDown(); | 1720 | emit closingDown(); |
1721 | 1721 | ||
1722 | mCalendar->close(); | 1722 | mCalendar->close(); |
1723 | setModified(false); | 1723 | setModified(false); |
1724 | updateView(); | 1724 | updateView(); |
1725 | } | 1725 | } |
1726 | 1726 | ||
1727 | void CalendarView::archiveCalendar() | 1727 | void CalendarView::archiveCalendar() |
1728 | { | 1728 | { |
1729 | mDialogManager->showArchiveDialog(); | 1729 | mDialogManager->showArchiveDialog(); |
1730 | } | 1730 | } |
1731 | 1731 | ||
1732 | 1732 | ||
1733 | void CalendarView::readSettings() | 1733 | void CalendarView::readSettings() |
1734 | { | 1734 | { |
1735 | 1735 | ||
1736 | 1736 | ||
1737 | // mViewManager->showAgendaView(); | 1737 | // mViewManager->showAgendaView(); |
1738 | QString str; | 1738 | QString str; |
1739 | //qDebug("CalendarView::readSettings() "); | 1739 | //qDebug("CalendarView::readSettings() "); |
1740 | // read settings from the KConfig, supplying reasonable | 1740 | // read settings from the KConfig, supplying reasonable |
1741 | // defaults where none are to be found | 1741 | // defaults where none are to be found |
1742 | KConfig *config = KOGlobals::config(); | 1742 | KConfig *config = KOGlobals::config(); |
1743 | #ifndef KORG_NOSPLITTER | 1743 | #ifndef KORG_NOSPLITTER |
1744 | config->setGroup("KOrganizer Geometry"); | 1744 | config->setGroup("KOrganizer Geometry"); |
1745 | 1745 | ||
1746 | QValueList<int> sizes = config->readIntListEntry("Separator1"); | 1746 | QValueList<int> sizes = config->readIntListEntry("Separator1"); |
1747 | if (sizes.count() != 2) { | 1747 | if (sizes.count() != 2) { |
1748 | sizes << mDateNavigator->minimumSizeHint().width(); | 1748 | sizes << mDateNavigator->minimumSizeHint().width(); |
1749 | sizes << 300; | 1749 | sizes << 300; |
1750 | } | 1750 | } |
1751 | mPanner->setSizes(sizes); | 1751 | mPanner->setSizes(sizes); |
1752 | 1752 | ||
1753 | sizes = config->readIntListEntry("Separator2"); | 1753 | sizes = config->readIntListEntry("Separator2"); |
1754 | if ( ( mResourceView && sizes.count() == 4 ) || | 1754 | if ( ( mResourceView && sizes.count() == 4 ) || |
1755 | ( !mResourceView && sizes.count() == 3 ) ) { | 1755 | ( !mResourceView && sizes.count() == 3 ) ) { |
1756 | mLeftSplitter->setSizes(sizes); | 1756 | mLeftSplitter->setSizes(sizes); |
1757 | } | 1757 | } |
1758 | #endif | 1758 | #endif |
1759 | globalFlagBlockAgenda = 1; | 1759 | globalFlagBlockAgenda = 1; |
1760 | mViewManager->showAgendaView(); | 1760 | mViewManager->showAgendaView(); |
1761 | //mViewManager->readSettings( config ); | 1761 | //mViewManager->readSettings( config ); |
1762 | mTodoList->restoreLayout(config,QString("Todo Layout")); | 1762 | mTodoList->restoreLayout(config,QString("Todo Layout")); |
1763 | readFilterSettings(config); | 1763 | readFilterSettings(config); |
1764 | config->setGroup( "Views" ); | 1764 | config->setGroup( "Views" ); |
1765 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); | 1765 | int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); |
1766 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); | 1766 | if ( dateCount == 5 ) mNavigator->selectWorkWeek(); |
1767 | else if ( dateCount == 7 ) mNavigator->selectWeek(); | 1767 | else if ( dateCount == 7 ) mNavigator->selectWeek(); |
1768 | else mNavigator->selectDates( dateCount ); | 1768 | else mNavigator->selectDates( dateCount ); |
1769 | // mViewManager->readSettings( config ); | 1769 | // mViewManager->readSettings( config ); |
1770 | updateConfig(); | 1770 | updateConfig(); |
1771 | globalFlagBlockAgenda = 2; | 1771 | globalFlagBlockAgenda = 2; |
1772 | mViewManager->readSettings( config ); | 1772 | mViewManager->readSettings( config ); |
1773 | #ifdef DESKTOP_VERSION | 1773 | #ifdef DESKTOP_VERSION |
1774 | config->setGroup("WidgetLayout"); | 1774 | config->setGroup("WidgetLayout"); |
1775 | QStringList list; | 1775 | QStringList list; |
1776 | list = config->readListEntry("MainLayout"); | 1776 | list = config->readListEntry("MainLayout"); |
1777 | int x,y,w,h; | 1777 | int x,y,w,h; |
1778 | if ( ! list.isEmpty() ) { | 1778 | if ( ! list.isEmpty() ) { |
1779 | x = list[0].toInt(); | 1779 | x = list[0].toInt(); |
1780 | y = list[1].toInt(); | 1780 | y = list[1].toInt(); |
1781 | w = list[2].toInt(); | 1781 | w = list[2].toInt(); |
1782 | h = list[3].toInt(); | 1782 | h = list[3].toInt(); |
1783 | topLevelWidget()->setGeometry(x,y,w,h); | 1783 | topLevelWidget()->setGeometry(x,y,w,h); |
1784 | 1784 | ||
1785 | } else { | 1785 | } else { |
1786 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); | 1786 | topLevelWidget()->setGeometry( 40 ,40 , 640, 440); |
1787 | } | 1787 | } |
1788 | list = config->readListEntry("EditEventLayout"); | 1788 | list = config->readListEntry("EditEventLayout"); |
1789 | if ( ! list.isEmpty() ) { | 1789 | if ( ! list.isEmpty() ) { |
1790 | x = list[0].toInt(); | 1790 | x = list[0].toInt(); |
1791 | y = list[1].toInt(); | 1791 | y = list[1].toInt(); |
1792 | w = list[2].toInt(); | 1792 | w = list[2].toInt(); |
1793 | h = list[3].toInt(); | 1793 | h = list[3].toInt(); |
1794 | mEventEditor->setGeometry(x,y,w,h); | 1794 | mEventEditor->setGeometry(x,y,w,h); |
1795 | 1795 | ||
1796 | } | 1796 | } |
1797 | list = config->readListEntry("EditTodoLayout"); | 1797 | list = config->readListEntry("EditTodoLayout"); |
1798 | if ( ! list.isEmpty() ) { | 1798 | if ( ! list.isEmpty() ) { |
1799 | x = list[0].toInt(); | 1799 | x = list[0].toInt(); |
1800 | y = list[1].toInt(); | 1800 | y = list[1].toInt(); |
1801 | w = list[2].toInt(); | 1801 | w = list[2].toInt(); |
1802 | h = list[3].toInt(); | 1802 | h = list[3].toInt(); |
1803 | mTodoEditor->setGeometry(x,y,w,h); | 1803 | mTodoEditor->setGeometry(x,y,w,h); |
1804 | 1804 | ||
1805 | } | 1805 | } |
1806 | list = config->readListEntry("ViewerLayout"); | 1806 | list = config->readListEntry("ViewerLayout"); |
1807 | if ( ! list.isEmpty() ) { | 1807 | if ( ! list.isEmpty() ) { |
1808 | x = list[0].toInt(); | 1808 | x = list[0].toInt(); |
1809 | y = list[1].toInt(); | 1809 | y = list[1].toInt(); |
1810 | w = list[2].toInt(); | 1810 | w = list[2].toInt(); |
1811 | h = list[3].toInt(); | 1811 | h = list[3].toInt(); |
1812 | getEventViewerDialog()->setGeometry(x,y,w,h); | 1812 | getEventViewerDialog()->setGeometry(x,y,w,h); |
1813 | } | 1813 | } |
1814 | #endif | 1814 | #endif |
1815 | 1815 | ||
1816 | } | 1816 | } |
1817 | 1817 | ||
1818 | 1818 | ||
1819 | void CalendarView::writeSettings() | 1819 | void CalendarView::writeSettings() |
1820 | { | 1820 | { |
1821 | // kdDebug() << "CalendarView::writeSettings" << endl; | 1821 | // kdDebug() << "CalendarView::writeSettings" << endl; |
1822 | 1822 | ||
1823 | KConfig *config = KOGlobals::config(); | 1823 | KConfig *config = KOGlobals::config(); |
1824 | 1824 | ||