summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Unidiff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index cfd9290..d5d31e2 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1079,223 +1079,236 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1079 incCounter = 0; 1079 incCounter = 0;
1080 1080
1081 while ( inL ) { 1081 while ( inL ) {
1082 1082
1083 qApp->processEvents(); 1083 qApp->processEvents();
1084 if ( ! bar.isVisible() ) 1084 if ( ! bar.isVisible() )
1085 return false; 1085 return false;
1086 if ( incCounter % modulo == 0 ) 1086 if ( incCounter % modulo == 0 )
1087 bar.setProgress( incCounter ); 1087 bar.setProgress( incCounter );
1088 ++incCounter; 1088 ++incCounter;
1089 uid = inL->uid(); 1089 uid = inL->uid();
1090 bool skipIncidence = false; 1090 bool skipIncidence = false;
1091 if ( uid.left(15) == QString("last-syncEvent-") ) 1091 if ( uid.left(15) == QString("last-syncEvent-") )
1092 skipIncidence = true; 1092 skipIncidence = true;
1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) 1093 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
1094 skipIncidence = true; 1094 skipIncidence = true;
1095 if ( !skipIncidence ) { 1095 if ( !skipIncidence ) {
1096 inR = remote->incidence( uid ); 1096 inR = remote->incidence( uid );
1097 if ( ! inR ) { 1097 if ( ! inR ) {
1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1098 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1099 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1100 local->deleteIncidence( inL ); 1100 local->deleteIncidence( inL );
1101 ++deletedEventL; 1101 ++deletedEventL;
1102 } else { 1102 } else {
1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1103 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1104 inL->removeID(mCurrentSyncDevice ); 1104 inL->removeID(mCurrentSyncDevice );
1105 ++addedEventR; 1105 ++addedEventR;
1106 inL->setLastModified( modifiedCalendar ); 1106 inL->setLastModified( modifiedCalendar );
1107 remote->addIncidence( inL->clone() ); 1107 remote->addIncidence( inL->clone() );
1108 } 1108 }
1109 } 1109 }
1110 } else { 1110 } else {
1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1111 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1112 checkExternSyncEvent(eventLSyncSharp, inL); 1112 checkExternSyncEvent(eventLSyncSharp, inL);
1113 local->deleteIncidence( inL ); 1113 local->deleteIncidence( inL );
1114 ++deletedEventL; 1114 ++deletedEventL;
1115 } else { 1115 } else {
1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1116 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1117 ++addedEventR; 1117 ++addedEventR;
1118 inL->setLastModified( modifiedCalendar ); 1118 inL->setLastModified( modifiedCalendar );
1119 remote->addIncidence( inL->clone() ); 1119 remote->addIncidence( inL->clone() );
1120 } 1120 }
1121 } 1121 }
1122 } 1122 }
1123 } 1123 }
1124 } 1124 }
1125 inL = el.next(); 1125 inL = el.next();
1126 } 1126 }
1127 int delFut = 0;
1127 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1128 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1128 er = remote->rawIncidences(); 1129 er = remote->rawIncidences();
1129 inR = er.first(); 1130 inR = er.first();
1130 QDateTime dt; 1131 QDateTime dt;
1131 QDateTime cur = QDateTime::currentDateTime(); 1132 QDateTime cur = QDateTime::currentDateTime();
1132 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); 1133 QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 );
1133 while ( inR ) { 1134 while ( inR ) {
1134 if ( inR->type() == "Todo" ) { 1135 if ( inR->type() == "Todo" ) {
1135 Todo * t = (Todo*)inR; 1136 Todo * t = (Todo*)inR;
1136 if ( t->hasDueDate() ) 1137 if ( t->hasDueDate() )
1137 dt = t->dtDue(); 1138 dt = t->dtDue();
1138 else 1139 else
1139 dt = cur.addSecs( 62 ); 1140 dt = cur.addSecs( 62 );
1140 } 1141 }
1141 else dt = inR->dtStart(); 1142 else if (inR->type() == "Event" ) {
1142 if ( dt < cur || dt > end ) 1143 bool ok;
1144 dt = inR->getNextOccurence( cur, &ok );
1145 if ( !ok )
1146 dt = cur.addSecs( -62 );
1147 }
1148 else
1149 dt = inR->dtStart();
1150 if ( dt < cur || dt > end ) {
1143 remote->deleteIncidence( inR ); 1151 remote->deleteIncidence( inR );
1152 ++delFut;
1153 }
1144 inR = er.next(); 1154 inR = er.next();
1145 } 1155 }
1146 } 1156 }
1147 bar.hide(); 1157 bar.hide();
1148 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1158 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1149 eventLSync->setReadOnly( false ); 1159 eventLSync->setReadOnly( false );
1150 eventLSync->setDtStart( mLastCalendarSync ); 1160 eventLSync->setDtStart( mLastCalendarSync );
1151 eventRSync->setDtStart( mLastCalendarSync ); 1161 eventRSync->setDtStart( mLastCalendarSync );
1152 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1162 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1153 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1163 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1154 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1164 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1155 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1165 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1156 eventLSync->setReadOnly( true ); 1166 eventLSync->setReadOnly( true );
1157 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1167 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1158 remote->addEvent( eventRSync ); 1168 remote->addEvent( eventRSync );
1159 QString mes; 1169 QString mes;
1160 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 ); 1170 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 );
1171 QString delmess;
1172 if ( delFut ) {
1173 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 );
1174 mes += delmess;
1175 }
1161 if ( KOPrefs::instance()->mShowSyncSummary ) { 1176 if ( KOPrefs::instance()->mShowSyncSummary ) {
1162 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1177 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1163 } 1178 }
1164 qDebug( mes ); 1179 qDebug( mes );
1165 mCalendar->checkAlarmForIncidence( 0, true ); 1180 mCalendar->checkAlarmForIncidence( 0, true );
1166 return syncOK; 1181 return syncOK;
1167} 1182}
1168 1183
1169void CalendarView::setSyncDevice( QString s ) 1184void CalendarView::setSyncDevice( QString s )
1170{ 1185{
1171 mCurrentSyncDevice= s; 1186 mCurrentSyncDevice= s;
1172} 1187}
1173void CalendarView::setSyncName( QString s ) 1188void CalendarView::setSyncName( QString s )
1174{ 1189{
1175 mCurrentSyncName= s; 1190 mCurrentSyncName= s;
1176} 1191}
1177bool CalendarView::syncCalendar(QString filename, int mode) 1192bool CalendarView::syncCalendar(QString filename, int mode)
1178{ 1193{
1179 mGlobalSyncMode = SYNC_MODE_NORMAL; 1194 mGlobalSyncMode = SYNC_MODE_NORMAL;
1180 CalendarLocal* calendar = new CalendarLocal(); 1195 CalendarLocal* calendar = new CalendarLocal();
1181 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1196 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1182 FileStorage* storage = new FileStorage( calendar ); 1197 FileStorage* storage = new FileStorage( calendar );
1183 bool syncOK = false; 1198 bool syncOK = false;
1184 storage->setFileName( filename ); 1199 storage->setFileName( filename );
1185 // qDebug("loading ... "); 1200 // qDebug("loading ... ");
1186 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 1201 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
1187 getEventViewerDialog()->setSyncMode( true ); 1202 getEventViewerDialog()->setSyncMode( true );
1188 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1203 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1189 getEventViewerDialog()->setSyncMode( false ); 1204 getEventViewerDialog()->setSyncMode( false );
1190 if ( syncOK ) { 1205 if ( syncOK ) {
1191 if ( KOPrefs::instance()->mWriteBackFile ) 1206 if ( KOPrefs::instance()->mWriteBackFile )
1192 { 1207 {
1193 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 1208 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
1194 storage->save(); 1209 storage->save();
1195 } 1210 }
1196 } 1211 }
1197 setModified( true ); 1212 setModified( true );
1198 } 1213 }
1199 delete storage; 1214 delete storage;
1200 delete calendar; 1215 delete calendar;
1201 if ( syncOK ) 1216 if ( syncOK )
1202 updateView(); 1217 updateView();
1203 return syncOK; 1218 return syncOK;
1204} 1219}
1205void CalendarView::syncPhone() 1220void CalendarView::syncPhone()
1206{ 1221{
1207 syncExternal( 1 ); 1222 syncExternal( 1 );
1208} 1223}
1209void CalendarView::syncExternal( int mode ) 1224void CalendarView::syncExternal( int mode )
1210{ 1225{
1211 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1226 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1212 //mCurrentSyncDevice = "sharp-DTM"; 1227 //mCurrentSyncDevice = "sharp-DTM";
1213 if ( KOPrefs::instance()->mAskForPreferences ) 1228 if ( KOPrefs::instance()->mAskForPreferences )
1214 edit_sync_options(); 1229 edit_sync_options();
1215 qApp->processEvents(); 1230 qApp->processEvents();
1216 CalendarLocal* calendar = new CalendarLocal(); 1231 CalendarLocal* calendar = new CalendarLocal();
1217 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1232 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1218 bool syncOK = false; 1233 bool syncOK = false;
1219 bool loadSuccess = false; 1234 bool loadSuccess = false;
1220 PhoneFormat* phoneFormat = 0; 1235 PhoneFormat* phoneFormat = 0;
1221#ifndef DESKTOP_VERSION 1236#ifndef DESKTOP_VERSION
1222 SharpFormat* sharpFormat = 0; 1237 SharpFormat* sharpFormat = 0;
1223 if ( mode == 0 ) { // sharp 1238 if ( mode == 0 ) { // sharp
1224 sharpFormat = new SharpFormat () ; 1239 sharpFormat = new SharpFormat () ;
1225 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1240 loadSuccess = sharpFormat->load( calendar, mCalendar );
1226 1241
1227 } else 1242 } else
1228#endif 1243#endif
1229 if ( mode == 1 ) { // phone 1244 if ( mode == 1 ) { // phone
1230 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1245 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1231 KOPrefs::instance()->mPhoneDevice, 1246 KOPrefs::instance()->mPhoneDevice,
1232 KOPrefs::instance()->mPhoneConnection, 1247 KOPrefs::instance()->mPhoneConnection,
1233 KOPrefs::instance()->mPhoneModel); 1248 KOPrefs::instance()->mPhoneModel);
1234 loadSuccess = phoneFormat->load( calendar,mCalendar); 1249 loadSuccess = phoneFormat->load( calendar,mCalendar);
1235 1250
1236 } else 1251 } else
1237 return; 1252 return;
1238 if ( loadSuccess ) { 1253 if ( loadSuccess ) {
1239 getEventViewerDialog()->setSyncMode( true ); 1254 getEventViewerDialog()->setSyncMode( true );
1240 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1255 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1241 getEventViewerDialog()->setSyncMode( false ); 1256 getEventViewerDialog()->setSyncMode( false );
1242 qApp->processEvents(); 1257 qApp->processEvents();
1243 if ( syncOK ) { 1258 if ( syncOK ) {
1244 if ( KOPrefs::instance()->mWriteBackFile ) 1259 if ( KOPrefs::instance()->mWriteBackFile )
1245 { 1260 {
1246 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1261 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1247 Incidence* inc = iL.first(); 1262 Incidence* inc = iL.first();
1248 /* obsolete
1249 while ( inc ) { 1263 while ( inc ) {
1250 inc->setZaurusStat( inc->revision () ); 1264 inc->removeID(mCurrentSyncDevice);
1251 inc = iL.next(); 1265 inc = iL.next();
1252 } 1266 }
1253 */
1254#ifndef DESKTOP_VERSION 1267#ifndef DESKTOP_VERSION
1255 if ( sharpFormat ) 1268 if ( sharpFormat )
1256 sharpFormat->save(calendar); 1269 sharpFormat->save(calendar);
1257#endif 1270#endif
1258 if ( phoneFormat ) 1271 if ( phoneFormat )
1259 phoneFormat->save(calendar); 1272 phoneFormat->save(calendar);
1260 iL = calendar->rawIncidences(); 1273 iL = calendar->rawIncidences();
1261 inc = iL.first(); 1274 inc = iL.first();
1262 Incidence* loc; 1275 Incidence* loc;
1263 while ( inc ) { 1276 while ( inc ) {
1264 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1277 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1265 loc = mCalendar->incidence(inc->uid() ); 1278 loc = mCalendar->incidence(inc->uid() );
1266 if ( loc ) { 1279 if ( loc ) {
1267 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1280 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1268 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1281 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1269 } 1282 }
1270 } 1283 }
1271 inc = iL.next(); 1284 inc = iL.next();
1272 } 1285 }
1273 Incidence* lse = getLastSyncEvent(); 1286 Incidence* lse = getLastSyncEvent();
1274 if ( lse ) { 1287 if ( lse ) {
1275 lse->setReadOnly( false ); 1288 lse->setReadOnly( false );
1276 lse->setDescription( "" ); 1289 lse->setDescription( "" );
1277 lse->setReadOnly( true ); 1290 lse->setReadOnly( true );
1278 } 1291 }
1279 } 1292 }
1280 } 1293 }
1281 setModified( true ); 1294 setModified( true );
1282 } else { 1295 } else {
1283 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1296 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1284 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1297 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1285 question, i18n("Ok")) ; 1298 question, i18n("Ok")) ;
1286 1299
1287 } 1300 }
1288 delete calendar; 1301 delete calendar;
1289 updateView(); 1302 updateView();
1290 return ;//syncOK; 1303 return ;//syncOK;
1291 1304
1292} 1305}
1293void CalendarView::syncSharp() 1306void CalendarView::syncSharp()
1294{ 1307{
1295 syncExternal( 0 ); 1308 syncExternal( 0 );
1296 1309
1297} 1310}
1298 1311
1299 1312
1300#include <kabc/stdaddressbook.h> 1313#include <kabc/stdaddressbook.h>
1301bool CalendarView::importBday() 1314bool CalendarView::importBday()