author | zautrix <zautrix> | 2005-11-28 01:23:02 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 01:23:02 (UTC) |
commit | e08811c2246f63b2b63f9db6b65701344460f3d7 (patch) (unidiff) | |
tree | d450f486a9472d80eb86f605237b828a0e7ffae6 /korganizer | |
parent | 854d4a0c686962cd73ac7418b5fbf4b2d73adab7 (diff) | |
download | kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.zip kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.gz kdepimpi-e08811c2246f63b2b63f9db6b65701344460f3d7.tar.bz2 |
ync
-rw-r--r-- | korganizer/calendarview.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 8d024c1..1800cf2 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp | |||
@@ -1351,672 +1351,687 @@ void CalendarView::selectWeekNum ( int num ) | |||
1351 | } | 1351 | } |
1352 | KOViewManager *CalendarView::viewManager() | 1352 | KOViewManager *CalendarView::viewManager() |
1353 | { | 1353 | { |
1354 | return mViewManager; | 1354 | return mViewManager; |
1355 | } | 1355 | } |
1356 | 1356 | ||
1357 | KODialogManager *CalendarView::dialogManager() | 1357 | KODialogManager *CalendarView::dialogManager() |
1358 | { | 1358 | { |
1359 | return mDialogManager; | 1359 | return mDialogManager; |
1360 | } | 1360 | } |
1361 | 1361 | ||
1362 | QDate CalendarView::startDate() | 1362 | QDate CalendarView::startDate() |
1363 | { | 1363 | { |
1364 | DateList dates = mNavigator->selectedDates(); | 1364 | DateList dates = mNavigator->selectedDates(); |
1365 | 1365 | ||
1366 | return dates.first(); | 1366 | return dates.first(); |
1367 | } | 1367 | } |
1368 | 1368 | ||
1369 | QDate CalendarView::endDate() | 1369 | QDate CalendarView::endDate() |
1370 | { | 1370 | { |
1371 | DateList dates = mNavigator->selectedDates(); | 1371 | DateList dates = mNavigator->selectedDates(); |
1372 | 1372 | ||
1373 | return dates.last(); | 1373 | return dates.last(); |
1374 | } | 1374 | } |
1375 | 1375 | ||
1376 | 1376 | ||
1377 | void CalendarView::createPrinter() | 1377 | void CalendarView::createPrinter() |
1378 | { | 1378 | { |
1379 | #ifndef KORG_NOPRINTER | 1379 | #ifndef KORG_NOPRINTER |
1380 | if (!mCalPrinter) { | 1380 | if (!mCalPrinter) { |
1381 | mCalPrinter = new CalPrinter(this, mCalendar); | 1381 | mCalPrinter = new CalPrinter(this, mCalendar); |
1382 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); | 1382 | connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig())); |
1383 | } | 1383 | } |
1384 | #endif | 1384 | #endif |
1385 | } | 1385 | } |
1386 | 1386 | ||
1387 | 1387 | ||
1388 | //KOPrefs::instance()->mWriteBackFile | 1388 | //KOPrefs::instance()->mWriteBackFile |
1389 | //KOPrefs::instance()->mWriteBackExistingOnly | 1389 | //KOPrefs::instance()->mWriteBackExistingOnly |
1390 | 1390 | ||
1391 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); | 1391 | // 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict")); |
1392 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); | 1392 | // 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict")); |
1393 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); | 1393 | // 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict")); |
1394 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); | 1394 | // 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict")); |
1395 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); | 1395 | // 4 syncPrefsGroup->addRadio(i18n("Force take local entry always")); |
1396 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); | 1396 | // 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always")); |
1397 | 1397 | ||
1398 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) | 1398 | int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full ) |
1399 | { | 1399 | { |
1400 | 1400 | ||
1401 | // 0 equal | 1401 | // 0 equal |
1402 | // 1 take local | 1402 | // 1 take local |
1403 | // 2 take remote | 1403 | // 2 take remote |
1404 | // 3 cancel | 1404 | // 3 cancel |
1405 | QDateTime lastSync = mLastCalendarSync; | 1405 | QDateTime lastSync = mLastCalendarSync; |
1406 | QDateTime localMod = local->lastModified(); | 1406 | QDateTime localMod = local->lastModified(); |
1407 | QDateTime remoteMod = remote->lastModified(); | 1407 | QDateTime remoteMod = remote->lastModified(); |
1408 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1408 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1409 | bool remCh, locCh; | 1409 | bool remCh, locCh; |
1410 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 1410 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
1411 | //if ( remCh ) | 1411 | //if ( remCh ) |
1412 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 1412 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
1413 | locCh = ( localMod > mLastCalendarSync ); | 1413 | locCh = ( localMod > mLastCalendarSync ); |
1414 | if ( !remCh && ! locCh ) { | 1414 | if ( !remCh && ! locCh ) { |
1415 | //qDebug("both not changed "); | 1415 | //qDebug("both not changed "); |
1416 | lastSync = localMod.addDays(1); | 1416 | lastSync = localMod.addDays(1); |
1417 | if ( mode <= SYNC_PREF_ASK ) | 1417 | if ( mode <= SYNC_PREF_ASK ) |
1418 | return 0; | 1418 | return 0; |
1419 | } else { | 1419 | } else { |
1420 | if ( locCh ) { | 1420 | if ( locCh ) { |
1421 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); | 1421 | //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); |
1422 | lastSync = localMod.addDays( -1 ); | 1422 | lastSync = localMod.addDays( -1 ); |
1423 | if ( !remCh ) | 1423 | if ( !remCh ) |
1424 | remoteMod = ( lastSync.addDays( -1 ) ); | 1424 | remoteMod = ( lastSync.addDays( -1 ) ); |
1425 | } else { | 1425 | } else { |
1426 | //qDebug(" not loc changed "); | 1426 | //qDebug(" not loc changed "); |
1427 | lastSync = localMod.addDays( 1 ); | 1427 | lastSync = localMod.addDays( 1 ); |
1428 | if ( remCh ) | 1428 | if ( remCh ) |
1429 | remoteMod =( lastSync.addDays( 1 ) ); | 1429 | remoteMod =( lastSync.addDays( 1 ) ); |
1430 | 1430 | ||
1431 | } | 1431 | } |
1432 | } | 1432 | } |
1433 | full = true; | 1433 | full = true; |
1434 | if ( mode < SYNC_PREF_ASK ) | 1434 | if ( mode < SYNC_PREF_ASK ) |
1435 | mode = SYNC_PREF_ASK; | 1435 | mode = SYNC_PREF_ASK; |
1436 | } else { | 1436 | } else { |
1437 | if ( localMod == remoteMod ) | 1437 | if ( localMod == remoteMod ) |
1438 | // if ( local->revision() == remote->revision() ) | 1438 | // if ( local->revision() == remote->revision() ) |
1439 | return 0; | 1439 | return 0; |
1440 | 1440 | ||
1441 | } | 1441 | } |
1442 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 1442 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
1443 | 1443 | ||
1444 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); | 1444 | //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); |
1445 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); | 1445 | //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); |
1446 | //full = true; //debug only | 1446 | //full = true; //debug only |
1447 | if ( full ) { | 1447 | if ( full ) { |
1448 | bool equ = false; | 1448 | bool equ = false; |
1449 | if ( local->typeID() == eventID ) { | 1449 | if ( local->typeID() == eventID ) { |
1450 | equ = (*((Event*) local) == *((Event*) remote)); | 1450 | equ = (*((Event*) local) == *((Event*) remote)); |
1451 | } | 1451 | } |
1452 | else if ( local->typeID() == todoID ) | 1452 | else if ( local->typeID() == todoID ) |
1453 | equ = (*((Todo*) local) == (*(Todo*) remote)); | 1453 | equ = (*((Todo*) local) == (*(Todo*) remote)); |
1454 | else if ( local->typeID() == journalID ) | 1454 | else if ( local->typeID() == journalID ) |
1455 | equ = (*((Journal*) local) == *((Journal*) remote)); | 1455 | equ = (*((Journal*) local) == *((Journal*) remote)); |
1456 | if ( equ ) { | 1456 | if ( equ ) { |
1457 | //qDebug("equal "); | 1457 | //qDebug("equal "); |
1458 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1458 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1459 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 1459 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
1460 | } | 1460 | } |
1461 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 1461 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
1462 | return 0; | 1462 | return 0; |
1463 | 1463 | ||
1464 | }//else //debug only | 1464 | }//else //debug only |
1465 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 1465 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
1466 | } | 1466 | } |
1467 | int result; | 1467 | int result; |
1468 | bool localIsNew; | 1468 | bool localIsNew; |
1469 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); | 1469 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); |
1470 | 1470 | ||
1471 | 1471 | ||
1472 | // ************************************************ | 1472 | // ************************************************ |
1473 | // ************************************************ | 1473 | // ************************************************ |
1474 | // ************************************************ | 1474 | // ************************************************ |
1475 | // We may have that lastSync > remoteMod AND lastSync > localMod | 1475 | // We may have that lastSync > remoteMod AND lastSync > localMod |
1476 | // BUT remoteMod != localMod | 1476 | // BUT remoteMod != localMod |
1477 | 1477 | ||
1478 | 1478 | ||
1479 | if ( full && mode < SYNC_PREF_NEWEST ) | 1479 | if ( full && mode < SYNC_PREF_NEWEST ) |
1480 | mode = SYNC_PREF_ASK; | 1480 | mode = SYNC_PREF_ASK; |
1481 | 1481 | ||
1482 | switch( mode ) { | 1482 | switch( mode ) { |
1483 | case SYNC_PREF_LOCAL: | 1483 | case SYNC_PREF_LOCAL: |
1484 | if ( lastSync > remoteMod ) | 1484 | if ( lastSync > remoteMod ) |
1485 | return 1; | 1485 | return 1; |
1486 | if ( lastSync > localMod ) | 1486 | if ( lastSync > localMod ) |
1487 | return 2; | 1487 | return 2; |
1488 | return 1; | 1488 | return 1; |
1489 | break; | 1489 | break; |
1490 | case SYNC_PREF_REMOTE: | 1490 | case SYNC_PREF_REMOTE: |
1491 | if ( lastSync > localMod ) | 1491 | if ( lastSync > localMod ) |
1492 | return 2; | 1492 | return 2; |
1493 | if ( lastSync > remoteMod ) | 1493 | if ( lastSync > remoteMod ) |
1494 | return 1; | 1494 | return 1; |
1495 | return 2; | 1495 | return 2; |
1496 | break; | 1496 | break; |
1497 | case SYNC_PREF_NEWEST: | 1497 | case SYNC_PREF_NEWEST: |
1498 | if ( localMod >= remoteMod ) | 1498 | if ( localMod >= remoteMod ) |
1499 | return 1; | 1499 | return 1; |
1500 | else | 1500 | else |
1501 | return 2; | 1501 | return 2; |
1502 | break; | 1502 | break; |
1503 | case SYNC_PREF_ASK: | 1503 | case SYNC_PREF_ASK: |
1504 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1504 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1505 | if ( lastSync > remoteMod && lastSync > localMod) | 1505 | if ( lastSync > remoteMod && lastSync > localMod) |
1506 | return 0; | 1506 | return 0; |
1507 | if ( lastSync > remoteMod ) | 1507 | if ( lastSync > remoteMod ) |
1508 | return 1; | 1508 | return 1; |
1509 | if ( lastSync > localMod ) | 1509 | if ( lastSync > localMod ) |
1510 | return 2; | 1510 | return 2; |
1511 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 1511 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
1512 | localIsNew = localMod >= remoteMod; | 1512 | localIsNew = localMod >= remoteMod; |
1513 | if ( localIsNew ) | 1513 | if ( localIsNew ) |
1514 | getEventViewerDialog()->setColorMode( 1 ); | 1514 | getEventViewerDialog()->setColorMode( 1 ); |
1515 | else | 1515 | else |
1516 | getEventViewerDialog()->setColorMode( 2 ); | 1516 | getEventViewerDialog()->setColorMode( 2 ); |
1517 | getEventViewerDialog()->setIncidence(local); | 1517 | getEventViewerDialog()->setIncidence(local); |
1518 | if ( localIsNew ) | 1518 | if ( localIsNew ) |
1519 | getEventViewerDialog()->setColorMode( 2 ); | 1519 | getEventViewerDialog()->setColorMode( 2 ); |
1520 | else | 1520 | else |
1521 | getEventViewerDialog()->setColorMode( 1 ); | 1521 | getEventViewerDialog()->setColorMode( 1 ); |
1522 | getEventViewerDialog()->addIncidence(remote); | 1522 | getEventViewerDialog()->addIncidence(remote); |
1523 | getEventViewerDialog()->setColorMode( 0 ); | 1523 | getEventViewerDialog()->setColorMode( 0 ); |
1524 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); | 1524 | //qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() ); |
1525 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); | 1525 | getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!")); |
1526 | getEventViewerDialog()->showMe(); | 1526 | getEventViewerDialog()->showMe(); |
1527 | result = getEventViewerDialog()->executeS( localIsNew ); | 1527 | result = getEventViewerDialog()->executeS( localIsNew ); |
1528 | return result; | 1528 | return result; |
1529 | 1529 | ||
1530 | break; | 1530 | break; |
1531 | case SYNC_PREF_FORCE_LOCAL: | 1531 | case SYNC_PREF_FORCE_LOCAL: |
1532 | return 1; | 1532 | return 1; |
1533 | break; | 1533 | break; |
1534 | case SYNC_PREF_FORCE_REMOTE: | 1534 | case SYNC_PREF_FORCE_REMOTE: |
1535 | return 2; | 1535 | return 2; |
1536 | break; | 1536 | break; |
1537 | 1537 | ||
1538 | default: | 1538 | default: |
1539 | // SYNC_PREF_TAKE_BOTH not implemented | 1539 | // SYNC_PREF_TAKE_BOTH not implemented |
1540 | break; | 1540 | break; |
1541 | } | 1541 | } |
1542 | return 0; | 1542 | return 0; |
1543 | } | 1543 | } |
1544 | Event* CalendarView::getLastSyncEvent() | 1544 | Event* CalendarView::getLastSyncEvent() |
1545 | { | 1545 | { |
1546 | Event* lse; | 1546 | Event* lse; |
1547 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 1547 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
1548 | mCalendar->setSyncEventsEnabled(); | 1548 | mCalendar->setSyncEventsEnabled(); |
1549 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); | 1549 | lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); |
1550 | if (!lse) { | 1550 | if (!lse) { |
1551 | qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); | 1551 | qDebug("KO: New last Syncevent created for local: %s",mCurrentSyncDevice.latin1() ); |
1552 | lse = new Event(); | 1552 | lse = new Event(); |
1553 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); | 1553 | lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); |
1554 | QString sum = ""; | 1554 | QString sum = ""; |
1555 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) | 1555 | if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) |
1556 | sum = "E: "; | 1556 | sum = "E: "; |
1557 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); | 1557 | lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); |
1558 | lse->setDtStart( mLastCalendarSync ); | 1558 | lse->setDtStart( mLastCalendarSync ); |
1559 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1559 | lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1560 | lse->setCategories( i18n("SyncEvent") ); | 1560 | lse->setCategories( i18n("SyncEvent") ); |
1561 | lse->setReadOnly( true ); | 1561 | lse->setReadOnly( true ); |
1562 | lse->setCalID( 1 ); | 1562 | lse->setCalID( 1 ); |
1563 | mCalendar->addEvent( lse ); | 1563 | mCalendar->addEvent( lse ); |
1564 | } else | 1564 | } else |
1565 | qDebug("KO: Last Syncevent on local found"); | 1565 | qDebug("KO: Last Syncevent on local found"); |
1566 | 1566 | ||
1567 | return lse; | 1567 | return lse; |
1568 | 1568 | ||
1569 | } | 1569 | } |
1570 | 1570 | ||
1571 | // we check, if the to delete event has a id for a profile | 1571 | // we check, if the to delete event has a id for a profile |
1572 | // if yes, we set this id in the profile to delete | 1572 | // if yes, we set this id in the profile to delete |
1573 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) | 1573 | void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete ) |
1574 | { | 1574 | { |
1575 | if ( lastSync.count() == 0 ) { | 1575 | if ( lastSync.count() == 0 ) { |
1576 | //qDebug(" lastSync.count() == 0"); | 1576 | //qDebug(" lastSync.count() == 0"); |
1577 | return; | 1577 | return; |
1578 | } | 1578 | } |
1579 | if ( toDelete->typeID() == journalID ) | 1579 | if ( toDelete->typeID() == journalID ) |
1580 | return; | 1580 | return; |
1581 | 1581 | ||
1582 | Event* eve = lastSync.first(); | 1582 | Event* eve = lastSync.first(); |
1583 | 1583 | ||
1584 | while ( eve ) { | 1584 | while ( eve ) { |
1585 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name | 1585 | QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name |
1586 | if ( !id.isEmpty() ) { | 1586 | if ( !id.isEmpty() ) { |
1587 | QString des = eve->description(); | 1587 | QString des = eve->description(); |
1588 | QString pref = "e"; | 1588 | QString pref = "e"; |
1589 | if ( toDelete->typeID() == todoID ) | 1589 | if ( toDelete->typeID() == todoID ) |
1590 | pref = "t"; | 1590 | pref = "t"; |
1591 | des += pref+ id + ","; | 1591 | des += pref+ id + ","; |
1592 | eve->setReadOnly( false ); | 1592 | eve->setReadOnly( false ); |
1593 | eve->setDescription( des ); | 1593 | eve->setDescription( des ); |
1594 | //qDebug("setdes %s ", des.latin1()); | 1594 | //qDebug("setdes %s ", des.latin1()); |
1595 | eve->setReadOnly( true ); | 1595 | eve->setReadOnly( true ); |
1596 | } | 1596 | } |
1597 | eve = lastSync.next(); | 1597 | eve = lastSync.next(); |
1598 | } | 1598 | } |
1599 | 1599 | ||
1600 | } | 1600 | } |
1601 | void CalendarView::checkExternalId( Incidence * inc ) | 1601 | void CalendarView::checkExternalId( Incidence * inc ) |
1602 | { | 1602 | { |
1603 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; | 1603 | QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ; |
1604 | checkExternSyncEvent( lastSync, inc ); | 1604 | checkExternSyncEvent( lastSync, inc ); |
1605 | 1605 | ||
1606 | } | 1606 | } |
1607 | // SSSSSSSSSSSSSSSSSSSSSS | ||
1607 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) | 1608 | bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode ) |
1608 | { | 1609 | { |
1609 | 1610 | ||
1610 | bool syncOK = true; | 1611 | bool syncOK = true; |
1611 | int addedEvent = 0; | 1612 | int addedEvent = 0; |
1612 | int addedEventR = 0; | 1613 | int addedEventR = 0; |
1613 | int deletedEventR = 0; | 1614 | int deletedEventR = 0; |
1614 | int deletedEventL = 0; | 1615 | int deletedEventL = 0; |
1615 | int changedLocal = 0; | 1616 | int changedLocal = 0; |
1616 | int changedRemote = 0; | 1617 | int changedRemote = 0; |
1617 | int filteredIN = 0; | 1618 | int filteredIN = 0; |
1618 | int filteredOUT = 0; | 1619 | int filteredOUT = 0; |
1619 | //QPtrList<Event> el = local->rawEvents(); | 1620 | //QPtrList<Event> el = local->rawEvents(); |
1620 | Event* eventR; | 1621 | Event* eventR; |
1621 | QString uid; | 1622 | QString uid; |
1622 | int take; | 1623 | int take; |
1623 | Event* eventRSync; | 1624 | Event* eventRSync; |
1624 | Event* eventLSync; | 1625 | Event* eventLSync; |
1625 | clearAllViews(); | 1626 | clearAllViews(); |
1626 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); | 1627 | QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents(); |
1627 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); | 1628 | QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents(); |
1628 | bool fullDateRange = false; | 1629 | bool fullDateRange = false; |
1629 | local->resetTempSyncStat(); | 1630 | local->resetTempSyncStat(); |
1630 | mLastCalendarSync = QDateTime::currentDateTime(); | 1631 | mLastCalendarSync = QDateTime::currentDateTime(); |
1631 | if ( mSyncManager->syncWithDesktop() ) { | 1632 | if ( mSyncManager->syncWithDesktop() ) { |
1632 | remote->resetPilotStat(1); | 1633 | remote->resetPilotStat(1); |
1633 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1634 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1634 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; | 1635 | mLastCalendarSync = KSyncManager::mRequestedSyncEvent; |
1635 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); | 1636 | qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() ); |
1636 | } else { | 1637 | } else { |
1637 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); | 1638 | qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); |
1638 | } | 1639 | } |
1639 | } | 1640 | } |
1640 | QDateTime modifiedCalendar = mLastCalendarSync; | 1641 | QDateTime modifiedCalendar = mLastCalendarSync; |
1641 | eventLSync = getLastSyncEvent(); | 1642 | eventLSync = getLastSyncEvent(); |
1642 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); | 1643 | eventR = remote->event("last-syncEvent-"+mCurrentSyncName ); |
1643 | if ( eventR ) { | 1644 | if ( eventR ) { |
1644 | qDebug("KO: Last-syncEvent on remote found "); | 1645 | qDebug("KO: Last-syncEvent on remote found "); |
1645 | eventRSync = (Event*) eventR->clone(); | 1646 | eventRSync = (Event*) eventR->clone(); |
1646 | remote->deleteEvent(eventR ); | 1647 | remote->deleteEvent(eventR ); |
1647 | 1648 | ||
1648 | } else { | 1649 | } else { |
1649 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { | 1650 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) { |
1650 | eventRSync = (Event*)eventLSync->clone(); | 1651 | eventRSync = (Event*)eventLSync->clone(); |
1651 | } else { | 1652 | } else { |
1652 | fullDateRange = true; | 1653 | fullDateRange = true; |
1653 | eventRSync = new Event(); | 1654 | eventRSync = new Event(); |
1654 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); | 1655 | eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event")); |
1655 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); | 1656 | eventRSync->setUid("last-syncEvent-"+mCurrentSyncName ); |
1656 | eventRSync->setDtStart( mLastCalendarSync ); | 1657 | eventRSync->setDtStart( mLastCalendarSync ); |
1657 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); | 1658 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); |
1658 | eventRSync->setCategories( i18n("SyncEvent") ); | 1659 | eventRSync->setCategories( i18n("SyncEvent") ); |
1659 | } | 1660 | } |
1660 | } | 1661 | } |
1661 | if ( eventLSync->dtStart() == mLastCalendarSync ) | 1662 | if ( eventLSync->dtStart() == mLastCalendarSync ) |
1662 | fullDateRange = true; | 1663 | fullDateRange = true; |
1663 | 1664 | ||
1664 | if ( ! fullDateRange ) { | 1665 | if ( ! fullDateRange ) { |
1665 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { | 1666 | if ( eventLSync->dtStart() != eventRSync->dtStart() ) { |
1666 | 1667 | ||
1667 | qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); | 1668 | qDebug("KO: Sync: Set fulldate to true! Local: %s --- Remote: %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() ); |
1668 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); | 1669 | //qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec()); |
1669 | fullDateRange = true; | 1670 | fullDateRange = true; |
1670 | } | 1671 | } |
1671 | } | 1672 | } |
1672 | if ( mSyncManager->syncWithDesktop() ) { | 1673 | if ( mSyncManager->syncWithDesktop() ) { |
1673 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); | 1674 | fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync ); |
1674 | } | 1675 | } |
1675 | if ( fullDateRange ) | 1676 | if ( fullDateRange ) |
1676 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); | 1677 | mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); |
1677 | else | 1678 | else |
1678 | mLastCalendarSync = eventLSync->dtStart(); | 1679 | mLastCalendarSync = eventLSync->dtStart(); |
1679 | // for resyncing if own file has changed | 1680 | // for resyncing if own file has changed |
1680 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 1681 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
1681 | mLastCalendarSync = loadedFileVersion; | 1682 | mLastCalendarSync = loadedFileVersion; |
1682 | //qDebug("setting mLastCalendarSync "); | 1683 | //qDebug("setting mLastCalendarSync "); |
1683 | } | 1684 | } |
1684 | //qDebug("*************************** "); | 1685 | //qDebug("*************************** "); |
1685 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); | 1686 | qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange); |
1686 | QPtrList<Incidence> er = remote->rawIncidences(); | 1687 | QPtrList<Incidence> er = remote->rawIncidences(); |
1687 | Incidence* inR = er.first(); | 1688 | Incidence* inR = er.first(); |
1688 | Incidence* inL; | 1689 | Incidence* inL; |
1689 | QProgressBar bar( er.count(),0 ); | 1690 | QProgressBar bar( er.count(),0 ); |
1690 | bar.setCaption (i18n("Syncing - close to abort!") ); | 1691 | bar.setCaption (i18n("Syncing - close to abort!") ); |
1691 | 1692 | ||
1692 | // ************** setting up filter ************* | 1693 | // ************** setting up filter ************* |
1693 | CalFilter *filterIN = 0; | 1694 | CalFilter *filterIN = 0; |
1694 | CalFilter *filterOUT = 0; | 1695 | CalFilter *filterOUT = 0; |
1695 | CalFilter *filter = mFilters.first(); | 1696 | CalFilter *filter = mFilters.first(); |
1696 | while(filter) { | 1697 | while(filter) { |
1697 | if ( filter->name() == mSyncManager->mFilterInCal ) | 1698 | if ( filter->name() == mSyncManager->mFilterInCal ) |
1698 | filterIN = filter; | 1699 | filterIN = filter; |
1699 | if ( filter->name() == mSyncManager->mFilterOutCal ) | 1700 | if ( filter->name() == mSyncManager->mFilterOutCal ) |
1700 | filterOUT = filter; | 1701 | filterOUT = filter; |
1701 | filter = mFilters.next(); | 1702 | filter = mFilters.next(); |
1702 | } | 1703 | } |
1703 | int w = 300; | 1704 | int w = 300; |
1704 | if ( QApplication::desktop()->width() < 320 ) | 1705 | if ( QApplication::desktop()->width() < 320 ) |
1705 | w = 220; | 1706 | w = 220; |
1706 | int h = bar.sizeHint().height() ; | 1707 | int h = bar.sizeHint().height() ; |
1707 | int dw = QApplication::desktop()->width(); | 1708 | int dw = QApplication::desktop()->width(); |
1708 | int dh = QApplication::desktop()->height(); | 1709 | int dh = QApplication::desktop()->height(); |
1709 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 1710 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
1710 | bar.show(); | 1711 | bar.show(); |
1711 | int modulo = (er.count()/10)+1; | 1712 | int modulo = (er.count()/10)+1; |
1712 | int incCounter = 0; | 1713 | int incCounter = 0; |
1713 | while ( inR ) { | 1714 | while ( inR ) { |
1714 | if ( ! bar.isVisible() ) | 1715 | if ( ! bar.isVisible() ) |
1715 | return false; | 1716 | return false; |
1716 | if ( incCounter % modulo == 0 ) | 1717 | if ( incCounter % modulo == 0 ) |
1717 | bar.setProgress( incCounter ); | 1718 | bar.setProgress( incCounter ); |
1718 | ++incCounter; | 1719 | ++incCounter; |
1719 | uid = inR->uid(); | 1720 | uid = inR->uid(); |
1720 | bool skipIncidence = false; | 1721 | bool skipIncidence = false; |
1721 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1722 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1722 | skipIncidence = true; | 1723 | skipIncidence = true; |
1723 | QString idS; | 1724 | QString idS; |
1724 | qApp->processEvents(); | 1725 | qApp->processEvents(); |
1725 | if ( !skipIncidence ) { | 1726 | if ( !skipIncidence ) { |
1726 | inL = local->incidenceForUid( uid , false , true ); | 1727 | int hasCalId = 0; |
1728 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | ||
1729 | if ( hasCalId && !inL ) | ||
1730 | inL = local->incidenceForUid( uid , false , true, &hasCalId ); | ||
1731 | else | ||
1732 | hasCalId = 0; | ||
1727 | if ( inL ) { // maybe conflict - same uid in both calendars | 1733 | if ( inL ) { // maybe conflict - same uid in both calendars |
1734 | if ( hasCalId ) | ||
1735 | qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1()); | ||
1728 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { | 1736 | if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) { |
1729 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 1737 | //qDebug("take %d %s ", take, inL->summary().latin1()); |
1730 | if ( take == 3 ) | 1738 | if ( take == 3 ) |
1731 | return false; | 1739 | return false; |
1732 | if ( take == 1 ) {// take local ********************** | 1740 | if ( take == 1 ) {// take local ********************** |
1733 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 1741 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
1734 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1742 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1735 | else | 1743 | else |
1736 | idS = inR->IDStr(); | 1744 | idS = inR->IDStr(); |
1737 | int calID = inR->calID(); | 1745 | int calID = inR->calID(); |
1738 | remote->deleteIncidence( inR ); | 1746 | remote->deleteIncidence( inR ); |
1739 | inR = inL->clone(); | 1747 | inR = inL->clone(); |
1740 | inR->setCalID_block( calID ); | 1748 | inR->setCalID_block( calID ); |
1741 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1749 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1742 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 1750 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
1743 | inR->setIDStr( idS ); | 1751 | inR->setIDStr( idS ); |
1744 | remote->addIncidence( inR ); | 1752 | remote->addIncidence( inR ); |
1745 | if ( mSyncManager->syncWithDesktop() ) | 1753 | if ( mSyncManager->syncWithDesktop() ) |
1746 | inR->setPilotId( 2 ); | 1754 | inR->setPilotId( 2 ); |
1747 | ++changedRemote; | 1755 | ++changedRemote; |
1748 | } else {// take remote ********************** | 1756 | } else {// take remote ********************** |
1749 | if ( !inL->isReadOnly() ) { | 1757 | if ( !inL->isReadOnly() ) { |
1750 | idS = inL->IDStr(); | 1758 | idS = inL->IDStr(); |
1751 | int pid = inL->pilotId(); | 1759 | int pid = inL->pilotId(); |
1752 | int calID = inL->calID(); | 1760 | int calID = inL->calID(); |
1761 | if ( hasCalId ) | ||
1762 | calID = hasCalId; | ||
1753 | local->deleteIncidence( inL ); | 1763 | local->deleteIncidence( inL ); |
1754 | inL = inR->clone(); | 1764 | inL = inR->clone(); |
1755 | inL->setCalID_block( calID ); | 1765 | inL->setCalID_block( calID ); |
1756 | if ( mSyncManager->syncWithDesktop() ) | 1766 | if ( mSyncManager->syncWithDesktop() ) |
1757 | inL->setPilotId( pid ); | 1767 | inL->setPilotId( pid ); |
1758 | inL->setIDStr( idS ); | 1768 | inL->setIDStr( idS ); |
1759 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1769 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1760 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1770 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1761 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1771 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1762 | } | 1772 | } |
1763 | local->addIncidence( inL ); | 1773 | local->addIncidence( inL ); |
1764 | ++changedLocal; | 1774 | ++changedLocal; |
1765 | } | 1775 | } |
1766 | } | 1776 | } |
1777 | } else { | ||
1778 | // take == 0; events equal | ||
1779 | if ( hasCalId ) | ||
1780 | qDebug("EV EQUALLLL **************************** "); | ||
1781 | |||
1767 | } | 1782 | } |
1768 | } else { // no conflict ********** add or delete remote | 1783 | } else { // no conflict ********** add or delete remote |
1769 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ | 1784 | if ( !filterIN || filterIN->filterCalendarItem( inR ) ){ |
1770 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1785 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1771 | QString des = eventLSync->description(); | 1786 | QString des = eventLSync->description(); |
1772 | QString pref = "e"; | 1787 | QString pref = "e"; |
1773 | if ( inR->typeID() == todoID ) | 1788 | if ( inR->typeID() == todoID ) |
1774 | pref = "t"; | 1789 | pref = "t"; |
1775 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 1790 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
1776 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 1791 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
1777 | //remote->deleteIncidence( inR ); | 1792 | //remote->deleteIncidence( inR ); |
1778 | ++deletedEventR; | 1793 | ++deletedEventR; |
1779 | } else { | 1794 | } else { |
1780 | inR->setLastModified( modifiedCalendar ); | 1795 | inR->setLastModified( modifiedCalendar ); |
1781 | inL = inR->clone(); | 1796 | inL = inR->clone(); |
1782 | inL->setIDStr( ":" ); | 1797 | inL->setIDStr( ":" ); |
1783 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 1798 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); |
1784 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); | 1799 | inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) ); |
1785 | 1800 | ||
1786 | inL->setCalID_block( 0 );// add to default cal | 1801 | inL->setCalID_block( 0 );// add to default cal |
1787 | local->addIncidence( inL ); | 1802 | local->addIncidence( inL ); |
1788 | ++addedEvent; | 1803 | ++addedEvent; |
1789 | 1804 | ||
1790 | } | 1805 | } |
1791 | } else { | 1806 | } else { |
1792 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { | 1807 | if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { |
1793 | inR->setLastModified( modifiedCalendar ); | 1808 | inR->setLastModified( modifiedCalendar ); |
1794 | inL = inR->clone(); | 1809 | inL = inR->clone(); |
1795 | inL->setIDStr( ":" ); | 1810 | inL->setIDStr( ":" ); |
1796 | inL->setCalID_block( 0 );// add to default cal | 1811 | inL->setCalID_block( 0 );// add to default cal |
1797 | local->addIncidence( inL ); | 1812 | local->addIncidence( inL ); |
1798 | ++addedEvent; | 1813 | ++addedEvent; |
1799 | 1814 | ||
1800 | } else { | 1815 | } else { |
1801 | checkExternSyncEvent(eventRSyncSharp, inR); | 1816 | checkExternSyncEvent(eventRSyncSharp, inR); |
1802 | remote->deleteIncidence( inR ); | 1817 | remote->deleteIncidence( inR ); |
1803 | ++deletedEventR; | 1818 | ++deletedEventR; |
1804 | } | 1819 | } |
1805 | } | 1820 | } |
1806 | } else { | 1821 | } else { |
1807 | ++filteredIN; | 1822 | ++filteredIN; |
1808 | } | 1823 | } |
1809 | } | 1824 | } |
1810 | } | 1825 | } |
1811 | inR = er.next(); | 1826 | inR = er.next(); |
1812 | } | 1827 | } |
1813 | QPtrList<Incidence> el = local->rawIncidences(); | 1828 | QPtrList<Incidence> el = local->rawIncidences(); |
1814 | inL = el.first(); | 1829 | inL = el.first(); |
1815 | modulo = (el.count()/10)+1; | 1830 | modulo = (el.count()/10)+1; |
1816 | bar.setCaption (i18n("Add / remove events") ); | 1831 | bar.setCaption (i18n("Add / remove events") ); |
1817 | bar.setTotalSteps ( el.count() ) ; | 1832 | bar.setTotalSteps ( el.count() ) ; |
1818 | bar.show(); | 1833 | bar.show(); |
1819 | incCounter = 0; | 1834 | incCounter = 0; |
1820 | 1835 | ||
1821 | while ( inL ) { | 1836 | while ( inL ) { |
1822 | 1837 | ||
1823 | qApp->processEvents(); | 1838 | qApp->processEvents(); |
1824 | if ( ! bar.isVisible() ) | 1839 | if ( ! bar.isVisible() ) |
1825 | return false; | 1840 | return false; |
1826 | if ( incCounter % modulo == 0 ) | 1841 | if ( incCounter % modulo == 0 ) |
1827 | bar.setProgress( incCounter ); | 1842 | bar.setProgress( incCounter ); |
1828 | ++incCounter; | 1843 | ++incCounter; |
1829 | uid = inL->uid(); | 1844 | uid = inL->uid(); |
1830 | bool skipIncidence = false; | 1845 | bool skipIncidence = false; |
1831 | if ( uid.left(15) == QString("last-syncEvent-") ) | 1846 | if ( uid.left(15) == QString("last-syncEvent-") ) |
1832 | skipIncidence = true; | 1847 | skipIncidence = true; |
1833 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) | 1848 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->typeID() == journalID ) |
1834 | skipIncidence = true; | 1849 | skipIncidence = true; |
1835 | if ( !skipIncidence ) { | 1850 | if ( !skipIncidence ) { |
1836 | inR = remote->incidenceForUid( uid , true, true ); | 1851 | inR = remote->incidenceForUid( uid , true, true ); |
1837 | if ( ! inR ) { | 1852 | if ( ! inR ) { |
1838 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ | 1853 | if ( !filterOUT || filterOUT->filterCalendarItem( inL ) ){ |
1839 | // no conflict ********** add or delete local | 1854 | // no conflict ********** add or delete local |
1840 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 1855 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
1841 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 1856 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
1842 | checkExternSyncEvent(eventLSyncSharp, inL); | 1857 | checkExternSyncEvent(eventLSyncSharp, inL); |
1843 | local->deleteIncidence( inL ); | 1858 | local->deleteIncidence( inL ); |
1844 | ++deletedEventL; | 1859 | ++deletedEventL; |
1845 | } else { | 1860 | } else { |
1846 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1861 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1847 | inL->removeID(mCurrentSyncDevice ); | 1862 | inL->removeID(mCurrentSyncDevice ); |
1848 | ++addedEventR; | 1863 | ++addedEventR; |
1849 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 1864 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); |
1850 | inL->setLastModified( modifiedCalendar ); | 1865 | inL->setLastModified( modifiedCalendar ); |
1851 | inR = inL->clone(); | 1866 | inR = inL->clone(); |
1852 | inR->setIDStr( ":" ); | 1867 | inR->setIDStr( ":" ); |
1853 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 1868 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
1854 | inR->setCalID_block( 0 );// add to default cal | 1869 | inR->setCalID_block( 0 );// add to default cal |
1855 | remote->addIncidence( inR ); | 1870 | remote->addIncidence( inR ); |
1856 | } | 1871 | } |
1857 | } | 1872 | } |
1858 | } else { | 1873 | } else { |
1859 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { | 1874 | if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { |
1860 | checkExternSyncEvent(eventLSyncSharp, inL); | 1875 | checkExternSyncEvent(eventLSyncSharp, inL); |
1861 | local->deleteIncidence( inL ); | 1876 | local->deleteIncidence( inL ); |
1862 | ++deletedEventL; | 1877 | ++deletedEventL; |
1863 | } else { | 1878 | } else { |
1864 | if ( ! mSyncManager->mWriteBackExistingOnly ) { | 1879 | if ( ! mSyncManager->mWriteBackExistingOnly ) { |
1865 | ++addedEventR; | 1880 | ++addedEventR; |
1866 | inL->setLastModified( modifiedCalendar ); | 1881 | inL->setLastModified( modifiedCalendar ); |
1867 | inR = inL->clone(); | 1882 | inR = inL->clone(); |
1868 | inR->setIDStr( ":" ); | 1883 | inR->setIDStr( ":" ); |
1869 | inR->setCalID_block( 0 );// add to default cal | 1884 | inR->setCalID_block( 0 );// add to default cal |
1870 | remote->addIncidence( inR ); | 1885 | remote->addIncidence( inR ); |
1871 | } | 1886 | } |
1872 | } | 1887 | } |
1873 | } | 1888 | } |
1874 | } else { | 1889 | } else { |
1875 | ++filteredOUT; | 1890 | ++filteredOUT; |
1876 | } | 1891 | } |
1877 | } | 1892 | } |
1878 | } | 1893 | } |
1879 | inL = el.next(); | 1894 | inL = el.next(); |
1880 | } | 1895 | } |
1881 | int delFut = 0; | 1896 | int delFut = 0; |
1882 | int remRem = 0; | 1897 | int remRem = 0; |
1883 | if ( mSyncManager->mWriteBackInFuture ) { | 1898 | if ( mSyncManager->mWriteBackInFuture ) { |
1884 | er = remote->rawIncidences(); | 1899 | er = remote->rawIncidences(); |
1885 | remRem = er.count(); | 1900 | remRem = er.count(); |
1886 | inR = er.first(); | 1901 | inR = er.first(); |
1887 | QDateTime dt; | 1902 | QDateTime dt; |
1888 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); | 1903 | QDateTime cur = QDateTime::currentDateTime().addDays( -(mSyncManager->mWriteBackInPast * 7) ); |
1889 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); | 1904 | QDateTime end = QDateTime::currentDateTime().addDays( (mSyncManager->mWriteBackInFuture ) *7 ); |
1890 | while ( inR ) { | 1905 | while ( inR ) { |
1891 | if ( inR->typeID() == todoID ) { | 1906 | if ( inR->typeID() == todoID ) { |
1892 | Todo * t = (Todo*)inR; | 1907 | Todo * t = (Todo*)inR; |
1893 | if ( t->hasDueDate() ) | 1908 | if ( t->hasDueDate() ) |
1894 | dt = t->dtDue(); | 1909 | dt = t->dtDue(); |
1895 | else | 1910 | else |
1896 | dt = cur.addSecs( 62 ); | 1911 | dt = cur.addSecs( 62 ); |
1897 | } | 1912 | } |
1898 | else if (inR->typeID() == eventID ) { | 1913 | else if (inR->typeID() == eventID ) { |
1899 | bool ok; | 1914 | bool ok; |
1900 | dt = inR->getNextOccurence( cur, &ok ); | 1915 | dt = inR->getNextOccurence( cur, &ok ); |
1901 | if ( !ok ) | 1916 | if ( !ok ) |
1902 | dt = cur.addSecs( -62 ); | 1917 | dt = cur.addSecs( -62 ); |
1903 | } | 1918 | } |
1904 | else | 1919 | else |
1905 | dt = inR->dtStart(); | 1920 | dt = inR->dtStart(); |
1906 | if ( dt < cur || dt > end ) { | 1921 | if ( dt < cur || dt > end ) { |
1907 | remote->deleteIncidence( inR ); | 1922 | remote->deleteIncidence( inR ); |
1908 | ++delFut; | 1923 | ++delFut; |
1909 | } | 1924 | } |
1910 | inR = er.next(); | 1925 | inR = er.next(); |
1911 | } | 1926 | } |
1912 | } | 1927 | } |
1913 | bar.hide(); | 1928 | bar.hide(); |
1914 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); | 1929 | mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); |
1915 | if ( mMultiResourceSync ) { | 1930 | if ( mMultiResourceSync ) { |
1916 | remote->removeSyncInfo( "" ); //all | 1931 | remote->removeSyncInfo( "" ); //all |
1917 | qDebug("KO: Remoing all sync info on remote "); | 1932 | qDebug("KO: Remoing all sync info on remote "); |
1918 | } else { | 1933 | } else { |
1919 | eventLSync->setReadOnly( false ); | 1934 | eventLSync->setReadOnly( false ); |
1920 | eventLSync->setDtStart( mLastCalendarSync ); | 1935 | eventLSync->setDtStart( mLastCalendarSync ); |
1921 | eventRSync->setDtStart( mLastCalendarSync ); | 1936 | eventRSync->setDtStart( mLastCalendarSync ); |
1922 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1937 | eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1923 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); | 1938 | eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); |
1924 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | 1939 | eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
1925 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | 1940 | eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); |
1926 | eventLSync->setReadOnly( true ); | 1941 | eventLSync->setReadOnly( true ); |
1927 | } | 1942 | } |
1928 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); | 1943 | qDebug("KO: Normal sync: %d ",mGlobalSyncMode == SYNC_MODE_NORMAL ); |
1929 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... | 1944 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL && !mSyncManager->syncWithDesktop() && !mMultiResourceSync ) // kde is abnormal... |
1930 | remote->addEvent( eventRSync ); | 1945 | remote->addEvent( eventRSync ); |
1931 | else | 1946 | else |
1932 | delete eventRSync; | 1947 | delete eventRSync; |
1933 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); | 1948 | qDebug("KO: Sync with desktop %d ",mSyncManager->syncWithDesktop() ); |
1934 | QString mes; | 1949 | QString mes; |
1935 | 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 ); | 1950 | 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 ); |
1936 | QString delmess; | 1951 | QString delmess; |
1937 | if ( delFut ) { | 1952 | if ( delFut ) { |
1938 | 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); | 1953 | 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); |
1939 | mes += delmess; | 1954 | mes += delmess; |
1940 | } | 1955 | } |
1941 | mes = i18n("Local calendar changed!\n") +mes; | 1956 | mes = i18n("Local calendar changed!\n") +mes; |
1942 | mCalendar->checkAlarmForIncidence( 0, true ); | 1957 | mCalendar->checkAlarmForIncidence( 0, true ); |
1943 | qDebug( mes ); | 1958 | qDebug( mes ); |
1944 | if ( mSyncManager->mShowSyncSummary ) { | 1959 | if ( mSyncManager->mShowSyncSummary ) { |
1945 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, | 1960 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, |
1946 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { | 1961 | i18n("KO/Pi Synchronization"),i18n("Write back"))) { |
1947 | qDebug("KO: WB cancelled "); | 1962 | qDebug("KO: WB cancelled "); |
1948 | mSyncManager->mWriteBackFile = false; | 1963 | mSyncManager->mWriteBackFile = false; |
1949 | return syncOK; | 1964 | return syncOK; |
1950 | } | 1965 | } |
1951 | } | 1966 | } |
1952 | return syncOK; | 1967 | return syncOK; |
1953 | } | 1968 | } |
1954 | 1969 | ||
1955 | void CalendarView::setSyncDevice( QString s ) | 1970 | void CalendarView::setSyncDevice( QString s ) |
1956 | { | 1971 | { |
1957 | mCurrentSyncDevice= s; | 1972 | mCurrentSyncDevice= s; |
1958 | } | 1973 | } |
1959 | void CalendarView::setSyncName( QString s ) | 1974 | void CalendarView::setSyncName( QString s ) |
1960 | { | 1975 | { |
1961 | mCurrentSyncName= s; | 1976 | mCurrentSyncName= s; |
1962 | } | 1977 | } |
1963 | bool CalendarView::syncCalendar(QString filename, int mode) | 1978 | bool CalendarView::syncCalendar(QString filename, int mode) |
1964 | { | 1979 | { |
1965 | //qDebug("syncCalendar %s ", filename.latin1()); | 1980 | //qDebug("syncCalendar %s ", filename.latin1()); |
1966 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 1981 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
1967 | CalendarLocal* calendar = new CalendarLocal(); | 1982 | CalendarLocal* calendar = new CalendarLocal(); |
1968 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 1983 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1969 | FileStorage* storage = new FileStorage( calendar ); | 1984 | FileStorage* storage = new FileStorage( calendar ); |
1970 | bool syncOK = false; | 1985 | bool syncOK = false; |
1971 | storage->setFileName( filename ); | 1986 | storage->setFileName( filename ); |
1972 | // qDebug("loading ... "); | 1987 | // qDebug("loading ... "); |
1973 | if ( storage->load() ) { | 1988 | if ( storage->load() ) { |
1974 | getEventViewerDialog()->setSyncMode( true ); | 1989 | getEventViewerDialog()->setSyncMode( true ); |
1975 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 1990 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
1976 | getEventViewerDialog()->setSyncMode( false ); | 1991 | getEventViewerDialog()->setSyncMode( false ); |
1977 | if ( syncOK ) { | 1992 | if ( syncOK ) { |
1978 | if ( mSyncManager->mWriteBackFile ) | 1993 | if ( mSyncManager->mWriteBackFile ) |
1979 | { | 1994 | { |
1980 | storage->setSaveFormat( new ICalFormat() ); | 1995 | storage->setSaveFormat( new ICalFormat() ); |
1981 | storage->save(); | 1996 | storage->save(); |
1982 | } | 1997 | } |
1983 | } | 1998 | } |
1984 | setModified( true ); | 1999 | setModified( true ); |
1985 | } | 2000 | } |
1986 | delete storage; | 2001 | delete storage; |
1987 | delete calendar; | 2002 | delete calendar; |
1988 | if ( syncOK ) | 2003 | if ( syncOK ) |
1989 | updateView(); | 2004 | updateView(); |
1990 | return syncOK; | 2005 | return syncOK; |
1991 | } | 2006 | } |
1992 | 2007 | ||
1993 | void CalendarView::syncExternal( int mode ) | 2008 | void CalendarView::syncExternal( int mode ) |
1994 | { | 2009 | { |
1995 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2010 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
1996 | qApp->processEvents(); | 2011 | qApp->processEvents(); |
1997 | CalendarLocal* calendar = new CalendarLocal(); | 2012 | CalendarLocal* calendar = new CalendarLocal(); |
1998 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); | 2013 | calendar->setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId); |
1999 | bool syncOK = false; | 2014 | bool syncOK = false; |
2000 | bool loadSuccess = false; | 2015 | bool loadSuccess = false; |
2001 | PhoneFormat* phoneFormat = 0; | 2016 | PhoneFormat* phoneFormat = 0; |
2002 | emit tempDisableBR(true); | 2017 | emit tempDisableBR(true); |
2003 | #ifndef DESKTOP_VERSION | 2018 | #ifndef DESKTOP_VERSION |
2004 | SharpFormat* sharpFormat = 0; | 2019 | SharpFormat* sharpFormat = 0; |
2005 | if ( mode == 0 ) { // sharp | 2020 | if ( mode == 0 ) { // sharp |
2006 | sharpFormat = new SharpFormat () ; | 2021 | sharpFormat = new SharpFormat () ; |
2007 | loadSuccess = sharpFormat->load( calendar, mCalendar ); | 2022 | loadSuccess = sharpFormat->load( calendar, mCalendar ); |
2008 | 2023 | ||
2009 | } else | 2024 | } else |
2010 | #endif | 2025 | #endif |
2011 | if ( mode == 1 ) { // phone | 2026 | if ( mode == 1 ) { // phone |
2012 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, | 2027 | phoneFormat = new PhoneFormat (mCurrentSyncDevice, |
2013 | mSyncManager->mPhoneDevice, | 2028 | mSyncManager->mPhoneDevice, |
2014 | mSyncManager->mPhoneConnection, | 2029 | mSyncManager->mPhoneConnection, |
2015 | mSyncManager->mPhoneModel); | 2030 | mSyncManager->mPhoneModel); |
2016 | loadSuccess = phoneFormat->load( calendar,mCalendar); | 2031 | loadSuccess = phoneFormat->load( calendar,mCalendar); |
2017 | 2032 | ||
2018 | } else { | 2033 | } else { |
2019 | emit tempDisableBR(false); | 2034 | emit tempDisableBR(false); |
2020 | return; | 2035 | return; |
2021 | } | 2036 | } |
2022 | if ( loadSuccess ) { | 2037 | if ( loadSuccess ) { |