summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Unidiff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 7ddbe23..363dc32 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1066,237 +1066,237 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1066 //remote->deleteIncidence( inR ); 1066 //remote->deleteIncidence( inR );
1067 ++deletedEventR; 1067 ++deletedEventR;
1068 } else { 1068 } else {
1069 inR->setLastModified( modifiedCalendar ); 1069 inR->setLastModified( modifiedCalendar );
1070 inL = inR->clone(); 1070 inL = inR->clone();
1071 inL->setIDStr( ":" ); 1071 inL->setIDStr( ":" );
1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1072 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1073 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1074 local->addIncidence( inL ); 1074 local->addIncidence( inL );
1075 ++addedEvent; 1075 ++addedEvent;
1076 } 1076 }
1077 } else { 1077 } else {
1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1078 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1079 inR->setLastModified( modifiedCalendar ); 1079 inR->setLastModified( modifiedCalendar );
1080 inL = inR->clone(); 1080 inL = inR->clone();
1081 inL->setIDStr( ":" ); 1081 inL->setIDStr( ":" );
1082 local->addIncidence( inL ); 1082 local->addIncidence( inL );
1083 ++addedEvent; 1083 ++addedEvent;
1084 } else { 1084 } else {
1085 checkExternSyncEvent(eventRSyncSharp, inR); 1085 checkExternSyncEvent(eventRSyncSharp, inR);
1086 remote->deleteIncidence( inR ); 1086 remote->deleteIncidence( inR );
1087 ++deletedEventR; 1087 ++deletedEventR;
1088 } 1088 }
1089 } 1089 }
1090 } 1090 }
1091 } 1091 }
1092 inR = er.next(); 1092 inR = er.next();
1093 } 1093 }
1094 QPtrList<Incidence> el = local->rawIncidences(); 1094 QPtrList<Incidence> el = local->rawIncidences();
1095 inL = el.first(); 1095 inL = el.first();
1096 modulo = (el.count()/10)+1; 1096 modulo = (el.count()/10)+1;
1097 bar.setCaption (i18n("Add / remove events") ); 1097 bar.setCaption (i18n("Add / remove events") );
1098 bar.setTotalSteps ( el.count() ) ; 1098 bar.setTotalSteps ( el.count() ) ;
1099 bar.show(); 1099 bar.show();
1100 incCounter = 0; 1100 incCounter = 0;
1101 1101
1102 while ( inL ) { 1102 while ( inL ) {
1103 1103
1104 qApp->processEvents(); 1104 qApp->processEvents();
1105 if ( ! bar.isVisible() ) 1105 if ( ! bar.isVisible() )
1106 return false; 1106 return false;
1107 if ( incCounter % modulo == 0 ) 1107 if ( incCounter % modulo == 0 )
1108 bar.setProgress( incCounter ); 1108 bar.setProgress( incCounter );
1109 ++incCounter; 1109 ++incCounter;
1110 uid = inL->uid(); 1110 uid = inL->uid();
1111 bool skipIncidence = false; 1111 bool skipIncidence = false;
1112 if ( uid.left(15) == QString("last-syncEvent-") ) 1112 if ( uid.left(15) == QString("last-syncEvent-") )
1113 skipIncidence = true; 1113 skipIncidence = true;
1114 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1114 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1115 skipIncidence = true; 1115 skipIncidence = true;
1116 if ( !skipIncidence ) { 1116 if ( !skipIncidence ) {
1117 inR = remote->incidence( uid ); 1117 inR = remote->incidence( uid );
1118 if ( ! inR ) { // no conflict ********** add or delete local 1118 if ( ! inR ) { // no conflict ********** add or delete local
1119 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1119 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1120 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1120 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1121 checkExternSyncEvent(eventLSyncSharp, inL); 1121 checkExternSyncEvent(eventLSyncSharp, inL);
1122 local->deleteIncidence( inL ); 1122 local->deleteIncidence( inL );
1123 ++deletedEventL; 1123 ++deletedEventL;
1124 } else { 1124 } else {
1125 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1125 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1126 inL->removeID(mCurrentSyncDevice ); 1126 inL->removeID(mCurrentSyncDevice );
1127 ++addedEventR; 1127 ++addedEventR;
1128 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1128 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1129 inL->setLastModified( modifiedCalendar ); 1129 inL->setLastModified( modifiedCalendar );
1130 inR = inL->clone(); 1130 inR = inL->clone();
1131 inR->setIDStr( ":" ); 1131 inR->setIDStr( ":" );
1132 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1132 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1133 remote->addIncidence( inR ); 1133 remote->addIncidence( inR );
1134 } 1134 }
1135 } 1135 }
1136 } else { 1136 } else {
1137 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1137 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1138 checkExternSyncEvent(eventLSyncSharp, inL); 1138 checkExternSyncEvent(eventLSyncSharp, inL);
1139 local->deleteIncidence( inL ); 1139 local->deleteIncidence( inL );
1140 ++deletedEventL; 1140 ++deletedEventL;
1141 } else { 1141 } else {
1142 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1142 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1143 ++addedEventR; 1143 ++addedEventR;
1144 inL->setLastModified( modifiedCalendar ); 1144 inL->setLastModified( modifiedCalendar );
1145 inR = inL->clone(); 1145 inR = inL->clone();
1146 inR->setIDStr( ":" ); 1146 inR->setIDStr( ":" );
1147 remote->addIncidence( inR ); 1147 remote->addIncidence( inR );
1148 } 1148 }
1149 } 1149 }
1150 } 1150 }
1151 } 1151 }
1152 } 1152 }
1153 inL = el.next(); 1153 inL = el.next();
1154 } 1154 }
1155 int delFut = 0; 1155 int delFut = 0;
1156 int remRem = 0; 1156 int remRem = 0;
1157 if ( mSyncManager->mWriteBackInFuture ) { 1157 if ( mSyncManager->mWriteBackInFuture ) {
1158 er = remote->rawIncidences(); 1158 er = remote->rawIncidences();
1159 remRem = er.count(); 1159 remRem = er.count();
1160 inR = er.first(); 1160 inR = er.first();
1161 QDateTime dt; 1161 QDateTime dt;
1162 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1162 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1163 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 ); 1163 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1164 while ( inR ) { 1164 while ( inR ) {
1165 if ( inR->type() == "Todo" ) { 1165 if ( inR->type() == "Todo" ) {
1166 Todo * t = (Todo*)inR; 1166 Todo * t = (Todo*)inR;
1167 if ( t->hasDueDate() ) 1167 if ( t->hasDueDate() )
1168 dt = t->dtDue(); 1168 dt = t->dtDue();
1169 else 1169 else
1170 dt = cur.addSecs( 62 ); 1170 dt = cur.addSecs( 62 );
1171 } 1171 }
1172 else if (inR->type() == "Event" ) { 1172 else if (inR->type() == "Event" ) {
1173 bool ok; 1173 bool ok;
1174 dt = inR->getNextOccurence( cur, &ok ); 1174 dt = inR->getNextOccurence( cur, &ok );
1175 if ( !ok ) 1175 if ( !ok )
1176 dt = cur.addSecs( -62 ); 1176 dt = cur.addSecs( -62 );
1177 } 1177 }
1178 else 1178 else
1179 dt = inR->dtStart(); 1179 dt = inR->dtStart();
1180 if ( dt < cur || dt > end ) { 1180 if ( dt < cur || dt > end ) {
1181 remote->deleteIncidence( inR ); 1181 remote->deleteIncidence( inR );
1182 ++delFut; 1182 ++delFut;
1183 } 1183 }
1184 inR = er.next(); 1184 inR = er.next();
1185 } 1185 }
1186 } 1186 }
1187 bar.hide(); 1187 bar.hide();
1188 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1188 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1189 eventLSync->setReadOnly( false ); 1189 eventLSync->setReadOnly( false );
1190 eventLSync->setDtStart( mLastCalendarSync ); 1190 eventLSync->setDtStart( mLastCalendarSync );
1191 eventRSync->setDtStart( mLastCalendarSync ); 1191 eventRSync->setDtStart( mLastCalendarSync );
1192 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1192 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1193 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1193 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1194 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1194 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1195 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1195 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1196 eventLSync->setReadOnly( true ); 1196 eventLSync->setReadOnly( true );
1197 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() ); 1197 qDebug("********** %d %d ", mGlobalSyncMode == SYNC_MODE_NORMAL, mSyncManager->syncWithDesktop() );
1198 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1198 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1199 remote->addEvent( eventRSync ); 1199 remote->addEvent( eventRSync );
1200 else 1200 else
1201 delete eventRSync; 1201 delete eventRSync;
1202 QString mes; 1202 QString mes;
1203 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 ); 1203 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 );
1204 QString delmess; 1204 QString delmess;
1205 if ( delFut ) { 1205 if ( delFut ) {
1206 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\nAfter skipping, remote has\n%d calendar/todo items."), delFut,mSyncManager->mWriteBackInFuture, remRem-delFut); 1206 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);
1207 mes += delmess; 1207 mes += delmess;
1208 } 1208 }
1209 mes = i18n("Local calendar changed!\n") +mes; 1209 mes = i18n("Local calendar changed!\n") +mes;
1210 mCalendar->checkAlarmForIncidence( 0, true ); 1210 mCalendar->checkAlarmForIncidence( 0, true );
1211 qDebug( mes ); 1211 qDebug( mes );
1212 if ( mSyncManager->mShowSyncSummary ) { 1212 if ( mSyncManager->mShowSyncSummary ) {
1213 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1213 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1214 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1214 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1215 qDebug("cancelled "); 1215 qDebug("cancelled ");
1216 return false; 1216 return false;
1217 } 1217 }
1218 } 1218 }
1219 return syncOK; 1219 return syncOK;
1220} 1220}
1221 1221
1222void CalendarView::setSyncDevice( QString s ) 1222void CalendarView::setSyncDevice( QString s )
1223{ 1223{
1224 mCurrentSyncDevice= s; 1224 mCurrentSyncDevice= s;
1225} 1225}
1226void CalendarView::setSyncName( QString s ) 1226void CalendarView::setSyncName( QString s )
1227{ 1227{
1228 mCurrentSyncName= s; 1228 mCurrentSyncName= s;
1229} 1229}
1230bool CalendarView::syncCalendar(QString filename, int mode) 1230bool CalendarView::syncCalendar(QString filename, int mode)
1231{ 1231{
1232 //qDebug("syncCalendar %s ", filename.latin1()); 1232 //qDebug("syncCalendar %s ", filename.latin1());
1233 mGlobalSyncMode = SYNC_MODE_NORMAL; 1233 mGlobalSyncMode = SYNC_MODE_NORMAL;
1234 CalendarLocal* calendar = new CalendarLocal(); 1234 CalendarLocal* calendar = new CalendarLocal();
1235 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1235 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1236 FileStorage* storage = new FileStorage( calendar ); 1236 FileStorage* storage = new FileStorage( calendar );
1237 bool syncOK = false; 1237 bool syncOK = false;
1238 storage->setFileName( filename ); 1238 storage->setFileName( filename );
1239 // qDebug("loading ... "); 1239 // qDebug("loading ... ");
1240 if ( storage->load() ) { 1240 if ( storage->load() ) {
1241 getEventViewerDialog()->setSyncMode( true ); 1241 getEventViewerDialog()->setSyncMode( true );
1242 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1242 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1243 getEventViewerDialog()->setSyncMode( false ); 1243 getEventViewerDialog()->setSyncMode( false );
1244 if ( syncOK ) { 1244 if ( syncOK ) {
1245 if ( mSyncManager->mWriteBackFile ) 1245 if ( mSyncManager->mWriteBackFile )
1246 { 1246 {
1247 storage->setSaveFormat( new ICalFormat() ); 1247 storage->setSaveFormat( new ICalFormat() );
1248 storage->save(); 1248 storage->save();
1249 } 1249 }
1250 } 1250 }
1251 setModified( true ); 1251 setModified( true );
1252 } 1252 }
1253 delete storage; 1253 delete storage;
1254 delete calendar; 1254 delete calendar;
1255 if ( syncOK ) 1255 if ( syncOK )
1256 updateView(); 1256 updateView();
1257 return syncOK; 1257 return syncOK;
1258} 1258}
1259 1259
1260void CalendarView::syncExternal( int mode ) 1260void CalendarView::syncExternal( int mode )
1261{ 1261{
1262 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1262 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1263 1263
1264 qApp->processEvents(); 1264 qApp->processEvents();
1265 CalendarLocal* calendar = new CalendarLocal(); 1265 CalendarLocal* calendar = new CalendarLocal();
1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1266 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1267 bool syncOK = false; 1267 bool syncOK = false;
1268 bool loadSuccess = false; 1268 bool loadSuccess = false;
1269 PhoneFormat* phoneFormat = 0; 1269 PhoneFormat* phoneFormat = 0;
1270 emit tempDisableBR(true); 1270 emit tempDisableBR(true);
1271#ifndef DESKTOP_VERSION 1271#ifndef DESKTOP_VERSION
1272 SharpFormat* sharpFormat = 0; 1272 SharpFormat* sharpFormat = 0;
1273 if ( mode == 0 ) { // sharp 1273 if ( mode == 0 ) { // sharp
1274 sharpFormat = new SharpFormat () ; 1274 sharpFormat = new SharpFormat () ;
1275 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1275 loadSuccess = sharpFormat->load( calendar, mCalendar );
1276 1276
1277 } else 1277 } else
1278#endif 1278#endif
1279 if ( mode == 1 ) { // phone 1279 if ( mode == 1 ) { // phone
1280 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1280 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1281 mSyncManager->mPhoneDevice, 1281 mSyncManager->mPhoneDevice,
1282 mSyncManager->mPhoneConnection, 1282 mSyncManager->mPhoneConnection,
1283 mSyncManager->mPhoneModel); 1283 mSyncManager->mPhoneModel);
1284 loadSuccess = phoneFormat->load( calendar,mCalendar); 1284 loadSuccess = phoneFormat->load( calendar,mCalendar);
1285 1285
1286 } else { 1286 } else {
1287 emit tempDisableBR(false); 1287 emit tempDisableBR(false);
1288 return; 1288 return;
1289 } 1289 }
1290 if ( loadSuccess ) { 1290 if ( loadSuccess ) {
1291 getEventViewerDialog()->setSyncMode( true ); 1291 getEventViewerDialog()->setSyncMode( true );
1292 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1292 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1293 getEventViewerDialog()->setSyncMode( false ); 1293 getEventViewerDialog()->setSyncMode( false );
1294 qApp->processEvents(); 1294 qApp->processEvents();
1295 if ( syncOK ) { 1295 if ( syncOK ) {
1296 if ( mSyncManager->mWriteBackFile ) 1296 if ( mSyncManager->mWriteBackFile )
1297 { 1297 {
1298 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1298 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1299 Incidence* inc = iL.first(); 1299 Incidence* inc = iL.first();
1300 if ( phoneFormat ) { 1300 if ( phoneFormat ) {
1301 while ( inc ) { 1301 while ( inc ) {
1302 inc->removeID(mCurrentSyncDevice); 1302 inc->removeID(mCurrentSyncDevice);