summaryrefslogtreecommitdiffabout
path: root/korganizer
Unidiff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 13cf69b..a62145a 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1229,769 +1229,769 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1229 bar.setCaption (i18n("Syncing - close to abort!") ); 1229 bar.setCaption (i18n("Syncing - close to abort!") );
1230 1230
1231 // ************** setting up filter ************* 1231 // ************** setting up filter *************
1232 CalFilter *filterIN = 0; 1232 CalFilter *filterIN = 0;
1233 CalFilter *filterOUT = 0; 1233 CalFilter *filterOUT = 0;
1234 CalFilter *filter = mFilters.first(); 1234 CalFilter *filter = mFilters.first();
1235 while(filter) { 1235 while(filter) {
1236 if ( filter->name() == mSyncManager->mFilterInCal ) 1236 if ( filter->name() == mSyncManager->mFilterInCal )
1237 filterIN = filter; 1237 filterIN = filter;
1238 if ( filter->name() == mSyncManager->mFilterOutCal ) 1238 if ( filter->name() == mSyncManager->mFilterOutCal )
1239 filterOUT = filter; 1239 filterOUT = filter;
1240 filter = mFilters.next(); 1240 filter = mFilters.next();
1241 } 1241 }
1242 int w = 300; 1242 int w = 300;
1243 if ( QApplication::desktop()->width() < 320 ) 1243 if ( QApplication::desktop()->width() < 320 )
1244 w = 220; 1244 w = 220;
1245 int h = bar.sizeHint().height() ; 1245 int h = bar.sizeHint().height() ;
1246 int dw = QApplication::desktop()->width(); 1246 int dw = QApplication::desktop()->width();
1247 int dh = QApplication::desktop()->height(); 1247 int dh = QApplication::desktop()->height();
1248 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1248 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1249 bar.show(); 1249 bar.show();
1250 int modulo = (er.count()/10)+1; 1250 int modulo = (er.count()/10)+1;
1251 int incCounter = 0; 1251 int incCounter = 0;
1252 while ( inR ) { 1252 while ( inR ) {
1253 if ( ! bar.isVisible() ) 1253 if ( ! bar.isVisible() )
1254 return false; 1254 return false;
1255 if ( incCounter % modulo == 0 ) 1255 if ( incCounter % modulo == 0 )
1256 bar.setProgress( incCounter ); 1256 bar.setProgress( incCounter );
1257 ++incCounter; 1257 ++incCounter;
1258 uid = inR->uid(); 1258 uid = inR->uid();
1259 bool skipIncidence = false; 1259 bool skipIncidence = false;
1260 if ( uid.left(15) == QString("last-syncEvent-") ) 1260 if ( uid.left(15) == QString("last-syncEvent-") )
1261 skipIncidence = true; 1261 skipIncidence = true;
1262 QString idS; 1262 QString idS;
1263 qApp->processEvents(); 1263 qApp->processEvents();
1264 if ( !skipIncidence ) { 1264 if ( !skipIncidence ) {
1265 inL = local->incidence( uid ); 1265 inL = local->incidence( uid );
1266 if ( inL ) { // maybe conflict - same uid in both calendars 1266 if ( inL ) { // maybe conflict - same uid in both calendars
1267 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { 1267 if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
1268 //qDebug("take %d %s ", take, inL->summary().latin1()); 1268 //qDebug("take %d %s ", take, inL->summary().latin1());
1269 if ( take == 3 ) 1269 if ( take == 3 )
1270 return false; 1270 return false;
1271 if ( take == 1 ) {// take local ********************** 1271 if ( take == 1 ) {// take local **********************
1272 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 1272 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
1273 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1273 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1274 else 1274 else
1275 idS = inR->IDStr(); 1275 idS = inR->IDStr();
1276 remote->deleteIncidence( inR ); 1276 remote->deleteIncidence( inR );
1277 inR = inL->clone(); 1277 inR = inL->clone();
1278 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1278 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1279 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) 1279 if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
1280 inR->setIDStr( idS ); 1280 inR->setIDStr( idS );
1281 remote->addIncidence( inR ); 1281 remote->addIncidence( inR );
1282 if ( mSyncManager->syncWithDesktop() ) 1282 if ( mSyncManager->syncWithDesktop() )
1283 inR->setPilotId( 2 ); 1283 inR->setPilotId( 2 );
1284 ++changedRemote; 1284 ++changedRemote;
1285 } else {// take remote ********************** 1285 } else {// take remote **********************
1286 idS = inL->IDStr(); 1286 idS = inL->IDStr();
1287 int pid = inL->pilotId(); 1287 int pid = inL->pilotId();
1288 local->deleteIncidence( inL ); 1288 local->deleteIncidence( inL );
1289 inL = inR->clone(); 1289 inL = inR->clone();
1290 if ( mSyncManager->syncWithDesktop() ) 1290 if ( mSyncManager->syncWithDesktop() )
1291 inL->setPilotId( pid ); 1291 inL->setPilotId( pid );
1292 inL->setIDStr( idS ); 1292 inL->setIDStr( idS );
1293 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1293 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1294 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1294 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1295 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1295 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1296 } 1296 }
1297 local->addIncidence( inL ); 1297 local->addIncidence( inL );
1298 ++changedLocal; 1298 ++changedLocal;
1299 } 1299 }
1300 } 1300 }
1301 } else { // no conflict ********** add or delete remote 1301 } else { // no conflict ********** add or delete remote
1302 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ 1302 if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
1303 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1303 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1304 QString des = eventLSync->description(); 1304 QString des = eventLSync->description();
1305 QString pref = "e"; 1305 QString pref = "e";
1306 if ( inR->typeID() == todoID ) 1306 if ( inR->typeID() == todoID )
1307 pref = "t"; 1307 pref = "t";
1308 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 1308 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
1309 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 1309 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
1310 //remote->deleteIncidence( inR ); 1310 //remote->deleteIncidence( inR );
1311 ++deletedEventR; 1311 ++deletedEventR;
1312 } else { 1312 } else {
1313 inR->setLastModified( modifiedCalendar ); 1313 inR->setLastModified( modifiedCalendar );
1314 inL = inR->clone(); 1314 inL = inR->clone();
1315 inL->setIDStr( ":" ); 1315 inL->setIDStr( ":" );
1316 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); 1316 inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
1317 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); 1317 inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
1318 local->addIncidence( inL ); 1318 local->addIncidence( inL );
1319 ++addedEvent; 1319 ++addedEvent;
1320 1320
1321 } 1321 }
1322 } else { 1322 } else {
1323 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 1323 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
1324 inR->setLastModified( modifiedCalendar ); 1324 inR->setLastModified( modifiedCalendar );
1325 inL = inR->clone(); 1325 inL = inR->clone();
1326 inL->setIDStr( ":" ); 1326 inL->setIDStr( ":" );
1327 local->addIncidence( inL ); 1327 local->addIncidence( inL );
1328 ++addedEvent; 1328 ++addedEvent;
1329 1329
1330 } else { 1330 } else {
1331 checkExternSyncEvent(eventRSyncSharp, inR); 1331 checkExternSyncEvent(eventRSyncSharp, inR);
1332 remote->deleteIncidence( inR ); 1332 remote->deleteIncidence( inR );
1333 ++deletedEventR; 1333 ++deletedEventR;
1334 } 1334 }
1335 } 1335 }
1336 } else { 1336 } else {
1337 ++filteredIN; 1337 ++filteredIN;
1338 } 1338 }
1339 } 1339 }
1340 } 1340 }
1341 inR = er.next(); 1341 inR = er.next();
1342 } 1342 }
1343 QPtrList<Incidence> el = local->rawIncidences(); 1343 QPtrList<Incidence> el = local->rawIncidences();
1344 inL = el.first(); 1344 inL = el.first();
1345 modulo = (el.count()/10)+1; 1345 modulo = (el.count()/10)+1;
1346 bar.setCaption (i18n("Add / remove events") ); 1346 bar.setCaption (i18n("Add / remove events") );
1347 bar.setTotalSteps ( el.count() ) ; 1347 bar.setTotalSteps ( el.count() ) ;
1348 bar.show(); 1348 bar.show();
1349 incCounter = 0; 1349 incCounter = 0;
1350 1350
1351 while ( inL ) { 1351 while ( inL ) {
1352 1352
1353 qApp->processEvents(); 1353 qApp->processEvents();
1354 if ( ! bar.isVisible() ) 1354 if ( ! bar.isVisible() )
1355 return false; 1355 return false;
1356 if ( incCounter % modulo == 0 ) 1356 if ( incCounter % modulo == 0 )
1357 bar.setProgress( incCounter ); 1357 bar.setProgress( incCounter );
1358 ++incCounter; 1358 ++incCounter;
1359 uid = inL->uid(); 1359 uid = inL->uid();
1360 bool skipIncidence = false; 1360 bool skipIncidence = false;
1361 if ( uid.left(15) == QString("last-syncEvent-") ) 1361 if ( uid.left(15) == QString("last-syncEvent-") )
1362 skipIncidence = true; 1362 skipIncidence = true;
1363 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) 1363 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID )
1364 skipIncidence = true; 1364 skipIncidence = true;
1365 if ( !skipIncidence ) { 1365 if ( !skipIncidence ) {
1366 inR = remote->incidence( uid ); 1366 inR = remote->incidence( uid );
1367 if ( ! inR ) { 1367 if ( ! inR ) {
1368 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ 1368 if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){
1369 // no conflict ********** add or delete local 1369 // no conflict ********** add or delete local
1370 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1370 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1371 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1371 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1372 checkExternSyncEvent(eventLSyncSharp, inL); 1372 checkExternSyncEvent(eventLSyncSharp, inL);
1373 local->deleteIncidence( inL ); 1373 local->deleteIncidence( inL );
1374 ++deletedEventL; 1374 ++deletedEventL;
1375 } else { 1375 } else {
1376 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1376 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1377 inL->removeID(mCurrentSyncDevice ); 1377 inL->removeID(mCurrentSyncDevice );
1378 ++addedEventR; 1378 ++addedEventR;
1379 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1379 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1380 inL->setLastModified( modifiedCalendar ); 1380 inL->setLastModified( modifiedCalendar );
1381 inR = inL->clone(); 1381 inR = inL->clone();
1382 inR->setIDStr( ":" ); 1382 inR->setIDStr( ":" );
1383 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1383 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
1384 remote->addIncidence( inR ); 1384 remote->addIncidence( inR );
1385 } 1385 }
1386 } 1386 }
1387 } else { 1387 } else {
1388 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1388 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1389 checkExternSyncEvent(eventLSyncSharp, inL); 1389 checkExternSyncEvent(eventLSyncSharp, inL);
1390 local->deleteIncidence( inL ); 1390 local->deleteIncidence( inL );
1391 ++deletedEventL; 1391 ++deletedEventL;
1392 } else { 1392 } else {
1393 if ( ! mSyncManager->mWriteBackExistingOnly ) { 1393 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1394 ++addedEventR; 1394 ++addedEventR;
1395 inL->setLastModified( modifiedCalendar ); 1395 inL->setLastModified( modifiedCalendar );
1396 inR = inL->clone(); 1396 inR = inL->clone();
1397 inR->setIDStr( ":" ); 1397 inR->setIDStr( ":" );
1398 remote->addIncidence( inR ); 1398 remote->addIncidence( inR );
1399 } 1399 }
1400 } 1400 }
1401 } 1401 }
1402 } else { 1402 } else {
1403 ++filteredOUT; 1403 ++filteredOUT;
1404 } 1404 }
1405 } 1405 }
1406 } 1406 }
1407 inL = el.next(); 1407 inL = el.next();
1408 } 1408 }
1409 int delFut = 0; 1409 int delFut = 0;
1410 int remRem = 0; 1410 int remRem = 0;
1411 if ( mSyncManager->mWriteBackInFuture ) { 1411 if ( mSyncManager->mWriteBackInFuture ) {
1412 er = remote->rawIncidences(); 1412 er = remote->rawIncidences();
1413 remRem = er.count(); 1413 remRem = er.count();
1414 inR = er.first(); 1414 inR = er.first();
1415 QDateTime dt; 1415 QDateTime dt;
1416 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); 1416 QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) );
1417 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); 1417 QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 );
1418 while ( inR ) { 1418 while ( inR ) {
1419 if ( inR->typeID() == todoID ) { 1419 if ( inR->typeID() == todoID ) {
1420 Todo * t = (Todo*)inR; 1420 Todo * t = (Todo*)inR;
1421 if ( t->hasDueDate() ) 1421 if ( t->hasDueDate() )
1422 dt = t->dtDue(); 1422 dt = t->dtDue();
1423 else 1423 else
1424 dt = cur.addSecs( 62 ); 1424 dt = cur.addSecs( 62 );
1425 } 1425 }
1426 else if (inR->typeID() == eventID ) { 1426 else if (inR->typeID() == eventID ) {
1427 bool ok; 1427 bool ok;
1428 dt = inR->getNextOccurence( cur, &ok ); 1428 dt = inR->getNextOccurence( cur, &ok );
1429 if ( !ok ) 1429 if ( !ok )
1430 dt = cur.addSecs( -62 ); 1430 dt = cur.addSecs( -62 );
1431 } 1431 }
1432 else 1432 else
1433 dt = inR->dtStart(); 1433 dt = inR->dtStart();
1434 if ( dt < cur || dt > end ) { 1434 if ( dt < cur || dt > end ) {
1435 remote->deleteIncidence( inR ); 1435 remote->deleteIncidence( inR );
1436 ++delFut; 1436 ++delFut;
1437 } 1437 }
1438 inR = er.next(); 1438 inR = er.next();
1439 } 1439 }
1440 } 1440 }
1441 bar.hide(); 1441 bar.hide();
1442 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1442 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1443 eventLSync->setReadOnly( false ); 1443 eventLSync->setReadOnly( false );
1444 eventLSync->setDtStart( mLastCalendarSync ); 1444 eventLSync->setDtStart( mLastCalendarSync );
1445 eventRSync->setDtStart( mLastCalendarSync ); 1445 eventRSync->setDtStart( mLastCalendarSync );
1446 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1446 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1447 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1447 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1448 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1448 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1449 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1449 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1450 eventLSync->setReadOnly( true ); 1450 eventLSync->setReadOnly( true );
1451 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); 1451 qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL );
1452 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal... 1452 if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop()) // kde is abnormal...
1453 remote->addEvent( eventRSync ); 1453 remote->addEvent( eventRSync );
1454 else 1454 else
1455 delete eventRSync; 1455 delete eventRSync;
1456 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); 1456 qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() );
1457 QString mes; 1457 QString mes;
1458 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 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 );
1459 QString delmess; 1459 QString delmess;
1460 if ( delFut ) { 1460 if ( delFut ) {
1461 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 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);
1462 mes += delmess; 1462 mes += delmess;
1463 } 1463 }
1464 mes = i18n("Local calendar changed!\n") +mes; 1464 mes = i18n("Local calendar changed!\n") +mes;
1465 mCalendar->checkAlarmForIncidence( 0, true ); 1465 mCalendar->checkAlarmForIncidence( 0, true );
1466 qDebug( mes ); 1466 qDebug( mes );
1467 if ( mSyncManager->mShowSyncSummary ) { 1467 if ( mSyncManager->mShowSyncSummary ) {
1468 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 1468 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
1469 i18n("KO/Pi Synchronization"),i18n("Write back"))) { 1469 i18n("KO/Pi Synchronization"),i18n("Write back"))) {
1470 qDebug("KO: WB cancelled "); 1470 qDebug("KO: WB cancelled ");
1471 mSyncManager->mWriteBackFile = false; 1471 mSyncManager->mWriteBackFile = false;
1472 return syncOK; 1472 return syncOK;
1473 } 1473 }
1474 } 1474 }
1475 return syncOK; 1475 return syncOK;
1476} 1476}
1477 1477
1478void CalendarView::setSyncDevice( QString s ) 1478void CalendarView::setSyncDevice( QString s )
1479{ 1479{
1480 mCurrentSyncDevice= s; 1480 mCurrentSyncDevice= s;
1481} 1481}
1482void CalendarView::setSyncName( QString s ) 1482void CalendarView::setSyncName( QString s )
1483{ 1483{
1484 mCurrentSyncName= s; 1484 mCurrentSyncName= s;
1485} 1485}
1486bool CalendarView::syncCalendar(QString filename, int mode) 1486bool CalendarView::syncCalendar(QString filename, int mode)
1487{ 1487{
1488 //qDebug("syncCalendar %s ", filename.latin1()); 1488 //qDebug("syncCalendar %s ", filename.latin1());
1489 mGlobalSyncMode = SYNC_MODE_NORMAL; 1489 mGlobalSyncMode = SYNC_MODE_NORMAL;
1490 CalendarLocal* calendar = new CalendarLocal(); 1490 CalendarLocal* calendar = new CalendarLocal();
1491 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1491 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1492 FileStorage* storage = new FileStorage( calendar ); 1492 FileStorage* storage = new FileStorage( calendar );
1493 bool syncOK = false; 1493 bool syncOK = false;
1494 storage->setFileName( filename ); 1494 storage->setFileName( filename );
1495 // qDebug("loading ... "); 1495 // qDebug("loading ... ");
1496 if ( storage->load() ) { 1496 if ( storage->load() ) {
1497 getEventViewerDialog()->setSyncMode( true ); 1497 getEventViewerDialog()->setSyncMode( true );
1498 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1498 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1499 getEventViewerDialog()->setSyncMode( false ); 1499 getEventViewerDialog()->setSyncMode( false );
1500 if ( syncOK ) { 1500 if ( syncOK ) {
1501 if ( mSyncManager->mWriteBackFile ) 1501 if ( mSyncManager->mWriteBackFile )
1502 { 1502 {
1503 storage->setSaveFormat( new ICalFormat() ); 1503 storage->setSaveFormat( new ICalFormat() );
1504 storage->save(); 1504 storage->save();
1505 } 1505 }
1506 } 1506 }
1507 setModified( true ); 1507 setModified( true );
1508 } 1508 }
1509 delete storage; 1509 delete storage;
1510 delete calendar; 1510 delete calendar;
1511 if ( syncOK ) 1511 if ( syncOK )
1512 updateView(); 1512 updateView();
1513 return syncOK; 1513 return syncOK;
1514} 1514}
1515 1515
1516void CalendarView::syncExternal( int mode ) 1516void CalendarView::syncExternal( int mode )
1517{ 1517{
1518 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1518 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1519 1519
1520 qApp->processEvents(); 1520 qApp->processEvents();
1521 CalendarLocal* calendar = new CalendarLocal(); 1521 CalendarLocal* calendar = new CalendarLocal();
1522 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1522 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1523 bool syncOK = false; 1523 bool syncOK = false;
1524 bool loadSuccess = false; 1524 bool loadSuccess = false;
1525 PhoneFormat* phoneFormat = 0; 1525 PhoneFormat* phoneFormat = 0;
1526 emit tempDisableBR(true); 1526 emit tempDisableBR(true);
1527#ifndef DESKTOP_VERSION 1527#ifndef DESKTOP_VERSION
1528 SharpFormat* sharpFormat = 0; 1528 SharpFormat* sharpFormat = 0;
1529 if ( mode == 0 ) { // sharp 1529 if ( mode == 0 ) { // sharp
1530 sharpFormat = new SharpFormat () ; 1530 sharpFormat = new SharpFormat () ;
1531 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1531 loadSuccess = sharpFormat->load( calendar, mCalendar );
1532 1532
1533 } else 1533 } else
1534#endif 1534#endif
1535 if ( mode == 1 ) { // phone 1535 if ( mode == 1 ) { // phone
1536 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1536 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1537 mSyncManager->mPhoneDevice, 1537 mSyncManager->mPhoneDevice,
1538 mSyncManager->mPhoneConnection, 1538 mSyncManager->mPhoneConnection,
1539 mSyncManager->mPhoneModel); 1539 mSyncManager->mPhoneModel);
1540 loadSuccess = phoneFormat->load( calendar,mCalendar); 1540 loadSuccess = phoneFormat->load( calendar,mCalendar);
1541 1541
1542 } else { 1542 } else {
1543 emit tempDisableBR(false); 1543 emit tempDisableBR(false);
1544 return; 1544 return;
1545 } 1545 }
1546 if ( loadSuccess ) { 1546 if ( loadSuccess ) {
1547 getEventViewerDialog()->setSyncMode( true ); 1547 getEventViewerDialog()->setSyncMode( true );
1548 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1548 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1549 getEventViewerDialog()->setSyncMode( false ); 1549 getEventViewerDialog()->setSyncMode( false );
1550 qApp->processEvents(); 1550 qApp->processEvents();
1551 if ( syncOK ) { 1551 if ( syncOK ) {
1552 if ( mSyncManager->mWriteBackFile ) 1552 if ( mSyncManager->mWriteBackFile )
1553 { 1553 {
1554 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1554 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1555 Incidence* inc = iL.first(); 1555 Incidence* inc = iL.first();
1556 if ( phoneFormat ) { 1556 if ( phoneFormat ) {
1557 while ( inc ) { 1557 while ( inc ) {
1558 inc->removeID(mCurrentSyncDevice); 1558 inc->removeID(mCurrentSyncDevice);
1559 inc = iL.next(); 1559 inc = iL.next();
1560 } 1560 }
1561 } 1561 }
1562#ifndef DESKTOP_VERSION 1562#ifndef DESKTOP_VERSION
1563 if ( sharpFormat ) 1563 if ( sharpFormat )
1564 sharpFormat->save(calendar); 1564 sharpFormat->save(calendar);
1565#endif 1565#endif
1566 if ( phoneFormat ) 1566 if ( phoneFormat )
1567 phoneFormat->save(calendar); 1567 phoneFormat->save(calendar);
1568 iL = calendar->rawIncidences(); 1568 iL = calendar->rawIncidences();
1569 inc = iL.first(); 1569 inc = iL.first();
1570 Incidence* loc; 1570 Incidence* loc;
1571 while ( inc ) { 1571 while ( inc ) {
1572 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1572 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1573 loc = mCalendar->incidence(inc->uid() ); 1573 loc = mCalendar->incidence(inc->uid() );
1574 if ( loc ) { 1574 if ( loc ) {
1575 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1575 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1576 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1576 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1577 } 1577 }
1578 } 1578 }
1579 inc = iL.next(); 1579 inc = iL.next();
1580 } 1580 }
1581 Incidence* lse = getLastSyncEvent(); 1581 Incidence* lse = getLastSyncEvent();
1582 if ( lse ) { 1582 if ( lse ) {
1583 lse->setReadOnly( false ); 1583 lse->setReadOnly( false );
1584 lse->setDescription( "" ); 1584 lse->setDescription( "" );
1585 lse->setReadOnly( true ); 1585 lse->setReadOnly( true );
1586 } 1586 }
1587 } 1587 }
1588 } else { 1588 } else {
1589 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 1589 topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
1590 } 1590 }
1591 setModified( true ); 1591 setModified( true );
1592 } else { 1592 } else {
1593 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1593 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1594 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1594 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1595 question, i18n("Ok")) ; 1595 question, i18n("Ok")) ;
1596 1596
1597 } 1597 }
1598 delete calendar; 1598 delete calendar;
1599 updateView(); 1599 updateView();
1600 emit tempDisableBR(false); 1600 emit tempDisableBR(false);
1601 return ;//syncOK; 1601 return ;//syncOK;
1602 1602
1603} 1603}
1604 1604
1605bool CalendarView::importBday() 1605bool CalendarView::importBday()
1606{ 1606{
1607#ifndef KORG_NOKABC 1607#ifndef KORG_NOKABC
1608 1608
1609#ifdef DESKTOP_VERSION 1609#ifdef DESKTOP_VERSION
1610 int curCal = mCalendar->defaultCalendar(); 1610 int curCal = mCalendar->defaultCalendar();
1611 int bd = mCalEditView->getBirtdayID(); 1611 int bd = mCalEditView->getBirtdayID();
1612 if ( bd == 0 ) 1612 if ( bd == 0 )
1613 return; 1613 return false;
1614 mCalendar->setDefaultCalendar( bd ); 1614 mCalendar->setDefaultCalendar( bd );
1615 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1615 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1616 KABC::AddressBook::Iterator it; 1616 KABC::AddressBook::Iterator it;
1617 int count = 0; 1617 int count = 0;
1618 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1618 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1619 ++count; 1619 ++count;
1620 } 1620 }
1621 QProgressBar bar(count,0 ); 1621 QProgressBar bar(count,0 );
1622 int w = 300; 1622 int w = 300;
1623 if ( QApplication::desktop()->width() < 320 ) 1623 if ( QApplication::desktop()->width() < 320 )
1624 w = 220; 1624 w = 220;
1625 int h = bar.sizeHint().height() ; 1625 int h = bar.sizeHint().height() ;
1626 int dw = QApplication::desktop()->width(); 1626 int dw = QApplication::desktop()->width();
1627 int dh = QApplication::desktop()->height(); 1627 int dh = QApplication::desktop()->height();
1628 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1628 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1629 bar.show(); 1629 bar.show();
1630 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1630 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1631 qApp->processEvents(); 1631 qApp->processEvents();
1632 count = 0; 1632 count = 0;
1633 int addCount = 0; 1633 int addCount = 0;
1634 KCal::Attendee* a = 0; 1634 KCal::Attendee* a = 0;
1635 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1635 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1636 if ( ! bar.isVisible() ) 1636 if ( ! bar.isVisible() )
1637 return false; 1637 return false;
1638 bar.setProgress( count++ ); 1638 bar.setProgress( count++ );
1639 qApp->processEvents(); 1639 qApp->processEvents();
1640 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1640 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1641 if ( (*it).birthday().date().isValid() ){ 1641 if ( (*it).birthday().date().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( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1643 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1644 ++addCount; 1644 ++addCount;
1645 } 1645 }
1646 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1646 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1647 if ( anni.isValid() ){ 1647 if ( anni.isValid() ){
1648 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1648 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1649 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1649 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1650 ++addCount; 1650 ++addCount;
1651 } 1651 }
1652 } 1652 }
1653 mCalendar->setDefaultCalendar( curCal ); 1653 mCalendar->setDefaultCalendar( curCal );
1654 updateView(); 1654 updateView();
1655 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1655 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1656#else //DESKTOP_VERSION 1656#else //DESKTOP_VERSION
1657 1657
1658 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/); 1658 ExternalAppHandler::instance()->requestBirthdayListFromKAPI("QPE/Application/kopi", this->name() /* name is here the unique uid*/);
1659 // the result should now arrive through method insertBirthdays 1659 // the result should now arrive through method insertBirthdays
1660 1660
1661#endif //DESKTOP_VERSION 1661#endif //DESKTOP_VERSION
1662 1662
1663#endif //KORG_NOKABC 1663#endif //KORG_NOKABC
1664 1664
1665 1665
1666 return true; 1666 return true;
1667} 1667}
1668 1668
1669// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI 1669// This method will be called from Ka/Pi as a response to requestBirthdayListFromKAPI
1670void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList, 1670void CalendarView::insertBirthdays(const QString& uid, const QStringList& birthdayList,
1671 const QStringList& anniversaryList, const QStringList& realNameList, 1671 const QStringList& anniversaryList, const QStringList& realNameList,
1672 const QStringList& emailList, const QStringList& assembledNameList, 1672 const QStringList& emailList, const QStringList& assembledNameList,
1673 const QStringList& uidList) 1673 const QStringList& uidList)
1674{ 1674{
1675 1675
1676 //qDebug("KO::CalendarView::insertBirthdays"); 1676 //qDebug("KO::CalendarView::insertBirthdays");
1677 if (uid == this->name()) 1677 if (uid == this->name())
1678 { 1678 {
1679 int curCal = mCalendar->defaultCalendar(); 1679 int curCal = mCalendar->defaultCalendar();
1680 int bd = mCalEditView->getBirtdayID(); 1680 int bd = mCalEditView->getBirtdayID();
1681 if ( bd == 0 ) 1681 if ( bd == 0 )
1682 return; 1682 return;
1683 mCalendar->setDefaultCalendar( bd ); 1683 mCalendar->setDefaultCalendar( bd );
1684 1684
1685 1685
1686 int count = birthdayList.count(); 1686 int count = birthdayList.count();
1687 int addCount = 0; 1687 int addCount = 0;
1688 KCal::Attendee* a = 0; 1688 KCal::Attendee* a = 0;
1689 1689
1690 //qDebug("CalView 1 %i", count); 1690 //qDebug("CalView 1 %i", count);
1691 1691
1692 QProgressBar bar(count,0 ); 1692 QProgressBar bar(count,0 );
1693 int w = 300; 1693 int w = 300;
1694 if ( QApplication::desktop()->width() < 320 ) 1694 if ( QApplication::desktop()->width() < 320 )
1695 w = 220; 1695 w = 220;
1696 int h = bar.sizeHint().height() ; 1696 int h = bar.sizeHint().height() ;
1697 int dw = QApplication::desktop()->width(); 1697 int dw = QApplication::desktop()->width();
1698 int dh = QApplication::desktop()->height(); 1698 int dh = QApplication::desktop()->height();
1699 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1699 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1700 bar.show(); 1700 bar.show();
1701 bar.setCaption (i18n("inserting birthdays - close to abort!") ); 1701 bar.setCaption (i18n("inserting birthdays - close to abort!") );
1702 qApp->processEvents(); 1702 qApp->processEvents();
1703 1703
1704 QDate birthday; 1704 QDate birthday;
1705 QDate anniversary; 1705 QDate anniversary;
1706 QString realName; 1706 QString realName;
1707 QString email; 1707 QString email;
1708 QString assembledName; 1708 QString assembledName;
1709 QString uid; 1709 QString uid;
1710 bool ok = true; 1710 bool ok = true;
1711 for ( int i = 0; i < count; i++) 1711 for ( int i = 0; i < count; i++)
1712 { 1712 {
1713 if ( ! bar.isVisible() ) 1713 if ( ! bar.isVisible() )
1714 return; 1714 return;
1715 bar.setProgress( i ); 1715 bar.setProgress( i );
1716 qApp->processEvents(); 1716 qApp->processEvents();
1717 1717
1718 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok); 1718 birthday = KGlobal::locale()->readDate(birthdayList[i], KLocale::ISODate, &ok);
1719 if (!ok) { 1719 if (!ok) {
1720 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1()); 1720 ;//qDebug("CalendarView::insertBirthdays found invalid birthday: %s",birthdayList[i].latin1());
1721 } 1721 }
1722 1722
1723 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok); 1723 anniversary = KGlobal::locale()->readDate(anniversaryList[i], KLocale::ISODate, &ok);
1724 if (!ok) { 1724 if (!ok) {
1725 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1()); 1725 ;//qDebug("CalendarView::insertBirthdays found invalid anniversary: %s",anniversaryList[i].latin1());
1726 } 1726 }
1727 realName = realNameList[i]; 1727 realName = realNameList[i];
1728 email = emailList[i]; 1728 email = emailList[i];
1729 assembledName = assembledNameList[i]; 1729 assembledName = assembledNameList[i];
1730 uid = uidList[i]; 1730 uid = uidList[i];
1731 //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() ); 1731 //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() );
1732 1732
1733 if ( birthday.isValid() ){ 1733 if ( birthday.isValid() ){
1734 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1734 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1735 KCal::Attendee::ReqParticipant,uid) ; 1735 KCal::Attendee::ReqParticipant,uid) ;
1736 if ( addAnniversary( birthday, assembledName, a, true ) ) 1736 if ( addAnniversary( birthday, assembledName, a, true ) )
1737 ++addCount; 1737 ++addCount;
1738 } 1738 }
1739 1739
1740 if ( anniversary.isValid() ){ 1740 if ( anniversary.isValid() ){
1741 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction, 1741 a = new KCal::Attendee( realName, email,false,KCal::Attendee::NeedsAction,
1742 KCal::Attendee::ReqParticipant,uid) ; 1742 KCal::Attendee::ReqParticipant,uid) ;
1743 if ( addAnniversary( anniversary, assembledName, a, false ) ) 1743 if ( addAnniversary( anniversary, assembledName, a, false ) )
1744 ++addCount; 1744 ++addCount;
1745 } 1745 }
1746 } 1746 }
1747 1747
1748 mCalendar->setDefaultCalendar( curCal ); 1748 mCalendar->setDefaultCalendar( curCal );
1749 updateView(); 1749 updateView();
1750 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1750 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1751 1751
1752 } 1752 }
1753 1753
1754} 1754}
1755 1755
1756 1756
1757 1757
1758bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1758bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1759{ 1759{
1760 //qDebug("addAnni "); 1760 //qDebug("addAnni ");
1761 Event * ev = new Event(); 1761 Event * ev = new Event();
1762 ev->setOrganizer(KOPrefs::instance()->email()); 1762 ev->setOrganizer(KOPrefs::instance()->email());
1763 if ( a ) { 1763 if ( a ) {
1764 ev->addAttendee( a ); 1764 ev->addAttendee( a );
1765 } 1765 }
1766 QString kind; 1766 QString kind;
1767 if ( birthday ) { 1767 if ( birthday ) {
1768 kind = i18n( "Birthday" ); 1768 kind = i18n( "Birthday" );
1769 ev->setSummary( name + " (" + QString::number(date.year()) +")"); 1769 ev->setSummary( name + " (" + QString::number(date.year()) +")");
1770 } 1770 }
1771 else { 1771 else {
1772 kind = i18n( "Anniversary" ); 1772 kind = i18n( "Anniversary" );
1773 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind ); 1773 ev->setSummary( name + " (" + QString::number(date.year()) +") " + kind );
1774 } 1774 }
1775 ev->setCategories( kind ); 1775 ev->setCategories( kind );
1776 ev->setDtStart( QDateTime(date) ); 1776 ev->setDtStart( QDateTime(date) );
1777 ev->setDtEnd( QDateTime(date) ); 1777 ev->setDtEnd( QDateTime(date) );
1778 ev->setFloats( true ); 1778 ev->setFloats( true );
1779 Recurrence * rec = ev->recurrence(); 1779 Recurrence * rec = ev->recurrence();
1780 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1780 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1781 rec->addYearlyNum( date.month() ); 1781 rec->addYearlyNum( date.month() );
1782 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1782 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1783 delete ev; 1783 delete ev;
1784 return false; 1784 return false;
1785 } 1785 }
1786 return true; 1786 return true;
1787 1787
1788} 1788}
1789bool CalendarView::importQtopia( const QString &categories, 1789bool CalendarView::importQtopia( const QString &categories,
1790 const QString &datebook, 1790 const QString &datebook,
1791 const QString &todolist ) 1791 const QString &todolist )
1792{ 1792{
1793 1793
1794 QtopiaFormat qtopiaFormat; 1794 QtopiaFormat qtopiaFormat;
1795 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1795 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1796 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1796 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1797 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1797 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1798 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1798 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1799 1799
1800 updateView(); 1800 updateView();
1801 return true; 1801 return true;
1802 1802
1803#if 0 1803#if 0
1804 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1804 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1805 mCurrentSyncDevice = "qtopia-XML"; 1805 mCurrentSyncDevice = "qtopia-XML";
1806 if ( mSyncManager->mAskForPreferences ) 1806 if ( mSyncManager->mAskForPreferences )
1807 edit_sync_options(); 1807 edit_sync_options();
1808 qApp->processEvents(); 1808 qApp->processEvents();
1809 CalendarLocal* calendar = new CalendarLocal(); 1809 CalendarLocal* calendar = new CalendarLocal();
1810 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); 1810 calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
1811 bool syncOK = false; 1811 bool syncOK = false;
1812 QtopiaFormat qtopiaFormat; 1812 QtopiaFormat qtopiaFormat;
1813 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1813 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1814 bool loadOk = true; 1814 bool loadOk = true;
1815 if ( !categories.isEmpty() ) 1815 if ( !categories.isEmpty() )
1816 loadOk = qtopiaFormat.load( calendar, categories ); 1816 loadOk = qtopiaFormat.load( calendar, categories );
1817 if ( loadOk && !datebook.isEmpty() ) 1817 if ( loadOk && !datebook.isEmpty() )
1818 loadOk = qtopiaFormat.load( calendar, datebook ); 1818 loadOk = qtopiaFormat.load( calendar, datebook );
1819 if ( loadOk && !todolist.isEmpty() ) 1819 if ( loadOk && !todolist.isEmpty() )
1820 loadOk = qtopiaFormat.load( calendar, todolist ); 1820 loadOk = qtopiaFormat.load( calendar, todolist );
1821 1821
1822 if ( loadOk ) { 1822 if ( loadOk ) {
1823 getEventViewerDialog()->setSyncMode( true ); 1823 getEventViewerDialog()->setSyncMode( true );
1824 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs ); 1824 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1825 getEventViewerDialog()->setSyncMode( false ); 1825 getEventViewerDialog()->setSyncMode( false );
1826 qApp->processEvents(); 1826 qApp->processEvents();
1827 if ( syncOK ) { 1827 if ( syncOK ) {
1828 if ( mSyncManager->mWriteBackFile ) 1828 if ( mSyncManager->mWriteBackFile )
1829 { 1829 {
1830 // write back XML file 1830 // write back XML file
1831 1831
1832 } 1832 }
1833 setModified( true ); 1833 setModified( true );
1834 } 1834 }
1835 } else { 1835 } else {
1836 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1836 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1837 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1837 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1838 question, i18n("Ok")) ; 1838 question, i18n("Ok")) ;
1839 } 1839 }
1840 delete calendar; 1840 delete calendar;
1841 updateView(); 1841 updateView();
1842 return syncOK; 1842 return syncOK;
1843 1843
1844 1844
1845#endif 1845#endif
1846 1846
1847} 1847}
1848 1848
1849void CalendarView::setSyncEventsReadOnly() 1849void CalendarView::setSyncEventsReadOnly()
1850{ 1850{
1851 mCalendar->setSyncEventsReadOnly(); 1851 mCalendar->setSyncEventsReadOnly();
1852} 1852}
1853 1853
1854bool CalendarView::loadCalendars() 1854bool CalendarView::loadCalendars()
1855{ 1855{
1856 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1856 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1857 KopiCalendarFile * cal = calendars.first(); 1857 KopiCalendarFile * cal = calendars.first();
1858 mCalendar->setDefaultCalendar( 1 ); 1858 mCalendar->setDefaultCalendar( 1 );
1859 openCalendar( MainWindow::defaultFileName(), false ); 1859 openCalendar( MainWindow::defaultFileName(), false );
1860 cal = calendars.next(); 1860 cal = calendars.next();
1861 while ( cal ) { 1861 while ( cal ) {
1862 addCalendar( cal ); 1862 addCalendar( cal );
1863 cal = calendars.next(); 1863 cal = calendars.next();
1864 } 1864 }
1865 restoreCalendarSettings(); 1865 restoreCalendarSettings();
1866 return true; 1866 return true;
1867} 1867}
1868bool CalendarView::restoreCalendarSettings() 1868bool CalendarView::restoreCalendarSettings()
1869{ 1869{
1870 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars; 1870 QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
1871 KopiCalendarFile * cal = calendars.first(); 1871 KopiCalendarFile * cal = calendars.first();
1872 while ( cal ) { 1872 while ( cal ) {
1873 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled ); 1873 mCalendar->setCalendarEnabled( cal->mCalNumber,cal->isEnabled );
1874 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled ); 1874 mCalendar->setAlarmEnabled( cal->mCalNumber, cal->isAlarmEnabled );
1875 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly ); 1875 mCalendar->setReadOnly( cal->mCalNumber, cal->isReadOnly );
1876 if ( cal->isStandard ) 1876 if ( cal->isStandard )
1877 mCalendar->setDefaultCalendar( cal->mCalNumber ); 1877 mCalendar->setDefaultCalendar( cal->mCalNumber );
1878 cal = calendars.next(); 1878 cal = calendars.next();
1879 } 1879 }
1880 setSyncEventsReadOnly(); 1880 setSyncEventsReadOnly();
1881 mCalendar->reInitAlarmSettings(); 1881 mCalendar->reInitAlarmSettings();
1882 updateUnmanagedViews(); 1882 updateUnmanagedViews();
1883 updateView(); 1883 updateView();
1884 return true; 1884 return true;
1885} 1885}
1886void CalendarView::addCalendarId( int id ) 1886void CalendarView::addCalendarId( int id )
1887{ 1887{
1888 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id ); 1888 KopiCalendarFile * cal = KOPrefs::instance()->getCalendar( id );
1889 addCalendar( cal ); 1889 addCalendar( cal );
1890} 1890}
1891bool CalendarView::addCalendar( KopiCalendarFile * cal ) 1891bool CalendarView::addCalendar( KopiCalendarFile * cal )
1892{ 1892{
1893 cal->mErrorOnLoad = false; 1893 cal->mErrorOnLoad = false;
1894 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) { 1894 if ( mCalendar->addCalendarFile( cal->mFileName, cal->mCalNumber )) {
1895 cal->mLoadDt = QDateTime::currentDateTime(); 1895 cal->mLoadDt = QDateTime::currentDateTime();
1896 return true; 1896 return true;
1897 } 1897 }
1898 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() ); 1898 qDebug("KO: Error adding calendar file %1 ",cal->mFileName.latin1() );
1899 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName)); 1899 KMessageBox::error(this,i18n("Error loading calendar file\n%1.").arg(cal->mFileName));
1900 cal->mErrorOnLoad = true; 1900 cal->mErrorOnLoad = true;
1901 return false; 1901 return false;
1902} 1902}
1903bool CalendarView::openCalendar(QString filename, bool merge) 1903bool CalendarView::openCalendar(QString filename, bool merge)
1904{ 1904{
1905 1905
1906 if (filename.isEmpty()) { 1906 if (filename.isEmpty()) {
1907 return false; 1907 return false;
1908 } 1908 }
1909 1909
1910 if (!QFile::exists(filename)) { 1910 if (!QFile::exists(filename)) {
1911 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1911 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1912 return false; 1912 return false;
1913 } 1913 }
1914 1914
1915 globalFlagBlockAgenda = 1; 1915 globalFlagBlockAgenda = 1;
1916 clearAllViews(); 1916 clearAllViews();
1917 if (!merge) { 1917 if (!merge) {
1918 mViewManager->setDocumentId( filename ); 1918 mViewManager->setDocumentId( filename );
1919 mCalendar->close(); 1919 mCalendar->close();
1920 } 1920 }
1921 mStorage->setFileName( filename ); 1921 mStorage->setFileName( filename );
1922 1922
1923 if ( mStorage->load() ) { 1923 if ( mStorage->load() ) {
1924 if ( merge ) ;//setModified( true ); 1924 if ( merge ) ;//setModified( true );
1925 else { 1925 else {
1926 //setModified( true ); 1926 //setModified( true );
1927 mViewManager->setDocumentId( filename ); 1927 mViewManager->setDocumentId( filename );
1928 mDialogManager->setDocumentId( filename ); 1928 mDialogManager->setDocumentId( filename );
1929 mTodoList->setDocumentId( filename ); 1929 mTodoList->setDocumentId( filename );
1930 } 1930 }
1931 globalFlagBlockAgenda = 2; 1931 globalFlagBlockAgenda = 2;
1932 // if ( getLastSyncEvent() ) 1932 // if ( getLastSyncEvent() )
1933 // getLastSyncEvent()->setReadOnly( true ); 1933 // getLastSyncEvent()->setReadOnly( true );
1934 mCalendar->reInitAlarmSettings(); 1934 mCalendar->reInitAlarmSettings();
1935 setSyncEventsReadOnly(); 1935 setSyncEventsReadOnly();
1936 updateUnmanagedViews(); 1936 updateUnmanagedViews();
1937 updateView(); 1937 updateView();
1938 if ( filename != MainWindow::defaultFileName() ) { 1938 if ( filename != MainWindow::defaultFileName() ) {
1939 saveCalendar( MainWindow::defaultFileName() ); 1939 saveCalendar( MainWindow::defaultFileName() );
1940 } else { 1940 } else {
1941 QFileInfo finf ( MainWindow::defaultFileName()); 1941 QFileInfo finf ( MainWindow::defaultFileName());
1942 if ( finf.exists() ) { 1942 if ( finf.exists() ) {
1943 setLoadedFileVersion( finf.lastModified () ); 1943 setLoadedFileVersion( finf.lastModified () );
1944 } 1944 }
1945 } 1945 }
1946 return true; 1946 return true;
1947 } else { 1947 } else {
1948 // while failing to load, the calendar object could 1948 // while failing to load, the calendar object could
1949 // have become partially populated. Clear it out. 1949 // have become partially populated. Clear it out.
1950 if ( !merge ) { 1950 if ( !merge ) {
1951 mCalendar->close(); 1951 mCalendar->close();
1952 mViewManager->setDocumentId( filename ); 1952 mViewManager->setDocumentId( filename );
1953 mDialogManager->setDocumentId( filename ); 1953 mDialogManager->setDocumentId( filename );
1954 mTodoList->setDocumentId( filename ); 1954 mTodoList->setDocumentId( filename );
1955 } 1955 }
1956 1956
1957 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1957 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1958 1958
1959 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1959 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1960 globalFlagBlockAgenda = 2; 1960 globalFlagBlockAgenda = 2;
1961 mCalendar->reInitAlarmSettings(); 1961 mCalendar->reInitAlarmSettings();
1962 setSyncEventsReadOnly(); 1962 setSyncEventsReadOnly();
1963 updateUnmanagedViews(); 1963 updateUnmanagedViews();
1964 updateView(); 1964 updateView();
1965 } 1965 }
1966 return false; 1966 return false;
1967} 1967}
1968void CalendarView::showOpenError() 1968void CalendarView::showOpenError()
1969{ 1969{
1970 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1970 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1971} 1971}
1972void CalendarView::setLoadedFileVersion(QDateTime dt) 1972void CalendarView::setLoadedFileVersion(QDateTime dt)
1973{ 1973{
1974 loadedFileVersion = dt; 1974 loadedFileVersion = dt;
1975} 1975}
1976bool CalendarView::checkFileChanged(QString fn) 1976bool CalendarView::checkFileChanged(QString fn)
1977{ 1977{
1978 QFileInfo finf ( fn ); 1978 QFileInfo finf ( fn );
1979 if ( !finf.exists() ) 1979 if ( !finf.exists() )
1980 return true; 1980 return true;
1981 QDateTime dt = finf.lastModified (); 1981 QDateTime dt = finf.lastModified ();
1982 if ( dt <= loadedFileVersion ) 1982 if ( dt <= loadedFileVersion )
1983 return false; 1983 return false;
1984 return true; 1984 return true;
1985 1985
1986} 1986}
1987void CalendarView::watchSavedFile() 1987void CalendarView::watchSavedFile()
1988{ 1988{
1989 QFileInfo finf ( MainWindow::defaultFileName()); 1989 QFileInfo finf ( MainWindow::defaultFileName());
1990 if ( !finf.exists() ) 1990 if ( !finf.exists() )
1991 return; 1991 return;
1992 QDateTime dt = finf.lastModified (); 1992 QDateTime dt = finf.lastModified ();
1993 if ( dt < loadedFileVersion ) { 1993 if ( dt < loadedFileVersion ) {
1994 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1()); 1994 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1995 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1995 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1996 return; 1996 return;
1997 } 1997 }