summaryrefslogtreecommitdiffabout
path: root/kaddressbook
authorzautrix <zautrix>2004-10-07 12:19:25 (UTC)
committer zautrix <zautrix>2004-10-07 12:19:25 (UTC)
commit826dc960353e47a60aba13916189c45ef3392c1e (patch) (unidiff)
tree52ef4058d7a1fa8d77e678391ed9165009634182 /kaddressbook
parent43c82cc5393522d2c34f34a4339cb6a1d1c6c555 (diff)
downloadkdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.zip
kdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.tar.gz
kdepimpi-826dc960353e47a60aba13916189c45ef3392c1e.tar.bz2
sync fixes
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index fa80f5c..12502b0 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2477,411 +2477,411 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
2477bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2477bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2478{ 2478{
2479 bool syncOK = true; 2479 bool syncOK = true;
2480 int addedAddressee = 0; 2480 int addedAddressee = 0;
2481 int addedAddresseeR = 0; 2481 int addedAddresseeR = 0;
2482 int deletedAddresseeR = 0; 2482 int deletedAddresseeR = 0;
2483 int deletedAddresseeL = 0; 2483 int deletedAddresseeL = 0;
2484 int changedLocal = 0; 2484 int changedLocal = 0;
2485 int changedRemote = 0; 2485 int changedRemote = 0;
2486 2486
2487 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2487 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2488 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2488 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2489 2489
2490 //QPtrList<Addressee> el = local->rawAddressees(); 2490 //QPtrList<Addressee> el = local->rawAddressees();
2491 Addressee addresseeR; 2491 Addressee addresseeR;
2492 QString uid; 2492 QString uid;
2493 int take; 2493 int take;
2494 Addressee addresseeL; 2494 Addressee addresseeL;
2495 Addressee addresseeRSync; 2495 Addressee addresseeRSync;
2496 Addressee addresseeLSync; 2496 Addressee addresseeLSync;
2497 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2497 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2498 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2498 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2499 bool fullDateRange = false; 2499 bool fullDateRange = false;
2500 local->resetTempSyncStat(); 2500 local->resetTempSyncStat();
2501 mLastAddressbookSync = QDateTime::currentDateTime(); 2501 mLastAddressbookSync = QDateTime::currentDateTime();
2502 QDateTime modifiedCalendar = mLastAddressbookSync;; 2502 QDateTime modifiedCalendar = mLastAddressbookSync;;
2503 addresseeLSync = getLastSyncAddressee(); 2503 addresseeLSync = getLastSyncAddressee();
2504 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2504 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2505 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2505 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2506 if ( !addresseeR.isEmpty() ) { 2506 if ( !addresseeR.isEmpty() ) {
2507 addresseeRSync = addresseeR; 2507 addresseeRSync = addresseeR;
2508 remote->removeAddressee(addresseeR ); 2508 remote->removeAddressee(addresseeR );
2509 2509
2510 } else { 2510 } else {
2511 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2511 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2512 addresseeRSync = addresseeLSync ; 2512 addresseeRSync = addresseeLSync ;
2513 } else { 2513 } else {
2514 qDebug("FULLDATE 1"); 2514 qDebug("FULLDATE 1");
2515 fullDateRange = true; 2515 fullDateRange = true;
2516 Addressee newAdd; 2516 Addressee newAdd;
2517 addresseeRSync = newAdd; 2517 addresseeRSync = newAdd;
2518 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2518 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2519 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2519 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2520 addresseeRSync.setRevision( mLastAddressbookSync ); 2520 addresseeRSync.setRevision( mLastAddressbookSync );
2521 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2521 addresseeRSync.setCategories( i18n("SyncAddressee") );
2522 } 2522 }
2523 } 2523 }
2524 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2524 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2525 qDebug("FULLDATE 2"); 2525 qDebug("FULLDATE 2");
2526 fullDateRange = true; 2526 fullDateRange = true;
2527 } 2527 }
2528 if ( ! fullDateRange ) { 2528 if ( ! fullDateRange ) {
2529 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2529 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2530 2530
2531 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2531 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2532 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2532 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2533 fullDateRange = true; 2533 fullDateRange = true;
2534 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2534 qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2535 } 2535 }
2536 } 2536 }
2537 // fullDateRange = true; // debug only! 2537 // fullDateRange = true; // debug only!
2538 if ( fullDateRange ) 2538 if ( fullDateRange )
2539 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2539 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2540 else 2540 else
2541 mLastAddressbookSync = addresseeLSync.revision(); 2541 mLastAddressbookSync = addresseeLSync.revision();
2542 // for resyncing if own file has changed 2542 // for resyncing if own file has changed
2543 // PENDING fixme later when implemented 2543 // PENDING fixme later when implemented
2544#if 0 2544#if 0
2545 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2545 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2546 mLastAddressbookSync = loadedFileVersion; 2546 mLastAddressbookSync = loadedFileVersion;
2547 qDebug("setting mLastAddressbookSync "); 2547 qDebug("setting mLastAddressbookSync ");
2548 } 2548 }
2549#endif 2549#endif
2550 2550
2551 //qDebug("*************************** "); 2551 //qDebug("*************************** ");
2552 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2552 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2553 QStringList er = remote->uidList(); 2553 QStringList er = remote->uidList();
2554 Addressee inR ;//= er.first(); 2554 Addressee inR ;//= er.first();
2555 Addressee inL; 2555 Addressee inL;
2556 2556
2557 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2557 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2558 2558
2559 int modulo = (er.count()/10)+1; 2559 int modulo = (er.count()/10)+1;
2560 int incCounter = 0; 2560 int incCounter = 0;
2561 while ( incCounter < er.count()) { 2561 while ( incCounter < er.count()) {
2562 if (syncManager->isProgressBarCanceled()) 2562 if (syncManager->isProgressBarCanceled())
2563 return false; 2563 return false;
2564 if ( incCounter % modulo == 0 ) 2564 if ( incCounter % modulo == 0 )
2565 syncManager->showProgressBar(incCounter); 2565 syncManager->showProgressBar(incCounter);
2566 2566
2567 uid = er[ incCounter ]; 2567 uid = er[ incCounter ];
2568 bool skipIncidence = false; 2568 bool skipIncidence = false;
2569 if ( uid.left(19) == QString("last-syncAddressee-") ) 2569 if ( uid.left(19) == QString("last-syncAddressee-") )
2570 skipIncidence = true; 2570 skipIncidence = true;
2571 QString idS,OidS; 2571 QString idS,OidS;
2572 qApp->processEvents(); 2572 qApp->processEvents();
2573 if ( !skipIncidence ) { 2573 if ( !skipIncidence ) {
2574 inL = local->findByUid( uid ); 2574 inL = local->findByUid( uid );
2575 inR = remote->findByUid( uid ); 2575 inR = remote->findByUid( uid );
2576 //inL.setResource( 0 ); 2576 //inL.setResource( 0 );
2577 //inR.setResource( 0 ); 2577 //inR.setResource( 0 );
2578 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2578 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2579 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { 2579 if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) {
2580 //qDebug("take %d %s ", take, inL.summary().latin1()); 2580 //qDebug("take %d %s ", take, inL.summary().latin1());
2581 if ( take == 3 ) 2581 if ( take == 3 )
2582 return false; 2582 return false;
2583 if ( take == 1 ) {// take local 2583 if ( take == 1 ) {// take local
2584 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2584 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2585 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2585 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2586 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2586 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2587 local->insertAddressee( inL, false ); 2587 local->insertAddressee( inL, false );
2588 idS = inR.externalUID(); 2588 idS = inR.externalUID();
2589 OidS = inR.originalExternalUID(); 2589 OidS = inR.originalExternalUID();
2590 } 2590 }
2591 else 2591 else
2592 idS = inR.IDStr(); 2592 idS = inR.IDStr();
2593 remote->removeAddressee( inR ); 2593 remote->removeAddressee( inR );
2594 inR = inL; 2594 inR = inL;
2595 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2595 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2596 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2597 inR.setOriginalExternalUID( OidS ); 2597 inR.setOriginalExternalUID( OidS );
2598 inR.setExternalUID( idS ); 2598 inR.setExternalUID( idS );
2599 } else { 2599 } else {
2600 inR.setIDStr( idS ); 2600 inR.setIDStr( idS );
2601 } 2601 }
2602 inR.setResource( 0 ); 2602 inR.setResource( 0 );
2603 remote->insertAddressee( inR , false); 2603 remote->insertAddressee( inR , false);
2604 ++changedRemote; 2604 ++changedRemote;
2605 } else { // take == 2 take remote 2605 } else { // take == 2 take remote
2606 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2606 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2607 if ( inR.revision().date().year() < 2004 ) 2607 if ( inR.revision().date().year() < 2004 )
2608 inR.setRevision( modifiedCalendar ); 2608 inR.setRevision( modifiedCalendar );
2609 } 2609 }
2610 idS = inL.IDStr(); 2610 idS = inL.IDStr();
2611 local->removeAddressee( inL ); 2611 local->removeAddressee( inL );
2612 inL = inR; 2612 inL = inR;
2613 inL.setIDStr( idS ); 2613 inL.setIDStr( idS );
2614 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2614 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2615 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2615 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2616 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2616 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2617 } 2617 }
2618 inL.setResource( 0 ); 2618 inL.setResource( 0 );
2619 local->insertAddressee( inL , false ); 2619 local->insertAddressee( inL , false );
2620 ++changedLocal; 2620 ++changedLocal;
2621 } 2621 }
2622 } 2622 }
2623 } else { // no conflict 2623 } else { // no conflict
2624 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2624 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2625 QString des = addresseeLSync.note(); 2625 QString des = addresseeLSync.note();
2626 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2626 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2627 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2627 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2628 remote->insertAddressee( inR, false ); 2628 remote->insertAddressee( inR, false );
2629 ++deletedAddresseeR; 2629 ++deletedAddresseeR;
2630 } else { 2630 } else {
2631 inR.setRevision( modifiedCalendar ); 2631 inR.setRevision( modifiedCalendar );
2632 remote->insertAddressee( inR, false ); 2632 remote->insertAddressee( inR, false );
2633 inL = inR; 2633 inL = inR;
2634 inL.setResource( 0 ); 2634 inL.setResource( 0 );
2635 local->insertAddressee( inL , false); 2635 local->insertAddressee( inL , false);
2636 ++addedAddressee; 2636 ++addedAddressee;
2637 } 2637 }
2638 } else { 2638 } else {
2639 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2639 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2640 inR.setRevision( modifiedCalendar ); 2640 inR.setRevision( modifiedCalendar );
2641 remote->insertAddressee( inR, false ); 2641 remote->insertAddressee( inR, false );
2642 inR.setResource( 0 ); 2642 inR.setResource( 0 );
2643 local->insertAddressee( inR, false ); 2643 local->insertAddressee( inR, false );
2644 ++addedAddressee; 2644 ++addedAddressee;
2645 } else { 2645 } else {
2646 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2646 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2647 remote->removeAddressee( inR ); 2647 remote->removeAddressee( inR );
2648 ++deletedAddresseeR; 2648 ++deletedAddresseeR;
2649 } 2649 }
2650 } 2650 }
2651 } 2651 }
2652 } 2652 }
2653 ++incCounter; 2653 ++incCounter;
2654 } 2654 }
2655 er.clear(); 2655 er.clear();
2656 QStringList el = local->uidList(); 2656 QStringList el = local->uidList();
2657 modulo = (el.count()/10)+1; 2657 modulo = (el.count()/10)+1;
2658 2658
2659 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 2659 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
2660 incCounter = 0; 2660 incCounter = 0;
2661 while ( incCounter < el.count()) { 2661 while ( incCounter < el.count()) {
2662 qApp->processEvents(); 2662 qApp->processEvents();
2663 if (syncManager->isProgressBarCanceled()) 2663 if (syncManager->isProgressBarCanceled())
2664 return false; 2664 return false;
2665 if ( incCounter % modulo == 0 ) 2665 if ( incCounter % modulo == 0 )
2666 syncManager->showProgressBar(incCounter); 2666 syncManager->showProgressBar(incCounter);
2667 uid = el[ incCounter ]; 2667 uid = el[ incCounter ];
2668 bool skipIncidence = false; 2668 bool skipIncidence = false;
2669 if ( uid.left(19) == QString("last-syncAddressee-") ) 2669 if ( uid.left(19) == QString("last-syncAddressee-") )
2670 skipIncidence = true; 2670 skipIncidence = true;
2671 if ( !skipIncidence ) { 2671 if ( !skipIncidence ) {
2672 inL = local->findByUid( uid ); 2672 inL = local->findByUid( uid );
2673 inR = remote->findByUid( uid ); 2673 inR = remote->findByUid( uid );
2674 if ( inR.isEmpty() ) { 2674 if ( inR.isEmpty() ) {
2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2675 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2676 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 2676 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
2677 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2677 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2678 local->removeAddressee( inL ); 2678 local->removeAddressee( inL );
2679 ++deletedAddresseeL; 2679 ++deletedAddresseeL;
2680 } else { 2680 } else {
2681 if ( ! syncManager->mWriteBackExistingOnly ) { 2681 if ( ! syncManager->mWriteBackExistingOnly ) {
2682 inL.removeID(mCurrentSyncDevice ); 2682 inL.removeID(mCurrentSyncDevice );
2683 ++addedAddresseeR; 2683 ++addedAddresseeR;
2684 inL.setRevision( modifiedCalendar ); 2684 inL.setRevision( modifiedCalendar );
2685 local->insertAddressee( inL, false ); 2685 local->insertAddressee( inL, false );
2686 inR = inL; 2686 inR = inL;
2687 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 2687 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
2688 inR.setResource( 0 ); 2688 inR.setResource( 0 );
2689 remote->insertAddressee( inR, false ); 2689 remote->insertAddressee( inR, false );
2690 } 2690 }
2691 } 2691 }
2692 } else { 2692 } else {
2693 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { 2693 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
2694 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 2694 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
2695 local->removeAddressee( inL ); 2695 local->removeAddressee( inL );
2696 ++deletedAddresseeL; 2696 ++deletedAddresseeL;
2697 } else { 2697 } else {
2698 if ( ! syncManager->mWriteBackExistingOnly ) { 2698 if ( ! syncManager->mWriteBackExistingOnly ) {
2699 ++addedAddresseeR; 2699 ++addedAddresseeR;
2700 inL.setRevision( modifiedCalendar ); 2700 inL.setRevision( modifiedCalendar );
2701 local->insertAddressee( inL, false ); 2701 local->insertAddressee( inL, false );
2702 inR = inL; 2702 inR = inL;
2703 inR.setResource( 0 ); 2703 inR.setResource( 0 );
2704 remote->insertAddressee( inR, false ); 2704 remote->insertAddressee( inR, false );
2705 } 2705 }
2706 } 2706 }
2707 } 2707 }
2708 } 2708 }
2709 } 2709 }
2710 ++incCounter; 2710 ++incCounter;
2711 } 2711 }
2712 el.clear(); 2712 el.clear();
2713 syncManager->hideProgressBar(); 2713 syncManager->hideProgressBar();
2714 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 2714 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2715 // get rid of micro seconds 2715 // get rid of micro seconds
2716 QTime t = mLastAddressbookSync.time(); 2716 QTime t = mLastAddressbookSync.time();
2717 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 2717 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
2718 addresseeLSync.setRevision( mLastAddressbookSync ); 2718 addresseeLSync.setRevision( mLastAddressbookSync );
2719 addresseeRSync.setRevision( mLastAddressbookSync ); 2719 addresseeRSync.setRevision( mLastAddressbookSync );
2720 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 2720 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
2721 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 2721 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
2722 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 2722 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
2723 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 2723 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
2724 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 2724 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
2725 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 2725 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
2726 addresseeRSync.setNote( "" ) ; 2726 addresseeRSync.setNote( "" ) ;
2727 addresseeLSync.setNote( "" ); 2727 addresseeLSync.setNote( "" );
2728 2728
2729 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2729 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2730 remote->insertAddressee( addresseeRSync, false ); 2730 remote->insertAddressee( addresseeRSync, false );
2731 local->insertAddressee( addresseeLSync, false ); 2731 local->insertAddressee( addresseeLSync, false );
2732 QString mes; 2732 QString mes;
2733 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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); 2733 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"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR );
2734 if ( syncManager->mShowSyncSummary ) { 2734 if ( syncManager->mShowSyncSummary ) {
2735 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); 2735 KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") );
2736 } 2736 }
2737 qDebug( mes ); 2737 qDebug( mes );
2738 return syncOK; 2738 return syncOK;
2739} 2739}
2740 2740
2741 2741
2742//this is a overwritten callbackmethods from the syncinterface 2742//this is a overwritten callbackmethods from the syncinterface
2743bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 2743bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
2744{ 2744{
2745 2745
2746 //pending prepare addresseeview for output 2746 //pending prepare addresseeview for output
2747 //pending detect, if remote file has REV field. if not switch to external sync 2747 //pending detect, if remote file has REV field. if not switch to external sync
2748 mGlobalSyncMode = SYNC_MODE_NORMAL; 2748 mGlobalSyncMode = SYNC_MODE_NORMAL;
2749 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2749 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2750 2750
2751 AddressBook abLocal(filename,"syncContact"); 2751 AddressBook abLocal(filename,"syncContact");
2752 bool syncOK = false; 2752 bool syncOK = false;
2753 if ( abLocal.load() ) { 2753 if ( abLocal.load() ) {
2754 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 2754 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
2755 bool external = false; 2755 bool external = false;
2756 bool isXML = false; 2756 bool isXML = false;
2757 if ( filename.right(4) == ".xml") { 2757 if ( filename.right(4) == ".xml") {
2758 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2758 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2759 isXML = true; 2759 isXML = true;
2760 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2760 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2761 } else { 2761 } else {
2762 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2762 Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2763 if ( ! lse.isEmpty() ) { 2763 if ( ! lse.isEmpty() ) {
2764 if ( lse.familyName().left(4) == "!E: " ) 2764 if ( lse.familyName().left(4) == "!E: " )
2765 external = true; 2765 external = true;
2766 } else { 2766 } else {
2767 bool found = false; 2767 bool found = false;
2768 AddressBook::Iterator it; 2768 AddressBook::Iterator it;
2769 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2769 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2770 if ( (*it).revision().date().year() > 2003 ) { 2770 if ( (*it).revision().date().year() > 2003 ) {
2771 found = true; 2771 found = true;
2772 break; 2772 break;
2773 } 2773 }
2774 } 2774 }
2775 external = ! found; 2775 external = ! found;
2776 } 2776 }
2777 2777
2778 if ( external ) { 2778 if ( external ) {
2779 qDebug("Setting vcf mode to external "); 2779 qDebug("Setting vcf mode to external ");
2780 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2780 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2781 AddressBook::Iterator it; 2781 AddressBook::Iterator it;
2782 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2782 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2783 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 2783 (*it).setID( mCurrentSyncDevice, (*it).uid() );
2784 (*it).computeCsum( mCurrentSyncDevice ); 2784 (*it).computeCsum( mCurrentSyncDevice );
2785 } 2785 }
2786 } 2786 }
2787 } 2787 }
2788 //AddressBook::Iterator it; 2788 //AddressBook::Iterator it;
2789 //QStringList vcards; 2789 //QStringList vcards;
2790 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 2790 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
2791 // qDebug("Name %s ", (*it).familyName().latin1()); 2791 // qDebug("Name %s ", (*it).familyName().latin1());
2792 //} 2792 //}
2793 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 2793 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
2794 if ( syncOK ) { 2794 if ( syncOK ) {
2795 if ( syncManager->mWriteBackFile ) 2795 if ( syncManager->mWriteBackFile )
2796 { 2796 {
2797 if ( external ) 2797 if ( external )
2798 abLocal.removeSyncAddressees( !isXML); 2798 abLocal.removeSyncAddressees( !isXML);
2799 qDebug("Saving remote AB "); 2799 qDebug("Saving remote AB ");
2800 abLocal.saveAB(); 2800 abLocal.saveAB();
2801 if ( isXML ) { 2801 if ( isXML ) {
2802 // afterwrite processing 2802 // afterwrite processing
2803 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2803 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2804 } 2804 }
2805 } 2805 }
2806 } 2806 }
2807 setModified(); 2807 setModified();
2808 2808
2809 } 2809 }
2810 if ( syncOK ) 2810 if ( syncOK )
2811 mViewManager->refreshView(); 2811 mViewManager->refreshView();
2812 return syncOK; 2812 return syncOK;
2813#if 0 2813#if 0
2814 2814
2815 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { 2815 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) {
2816 getEventViewerDialog()->setSyncMode( true ); 2816 getEventViewerDialog()->setSyncMode( true );
2817 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 2817 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
2818 getEventViewerDialog()->setSyncMode( false ); 2818 getEventViewerDialog()->setSyncMode( false );
2819 if ( syncOK ) { 2819 if ( syncOK ) {
2820 if ( KOPrefs::instance()->mWriteBackFile ) 2820 if ( KOPrefs::instance()->mWriteBackFile )
2821 { 2821 {
2822 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); 2822 storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) );
2823 storage->save(); 2823 storage->save();
2824 } 2824 }
2825 } 2825 }
2826 setModified(); 2826 setModified();
2827 } 2827 }
2828 2828
2829#endif 2829#endif
2830} 2830}
2831 2831
2832 2832
2833//this is a overwritten callbackmethods from the syncinterface 2833//this is a overwritten callbackmethods from the syncinterface
2834bool KABCore::syncExternal(KSyncManager* manager, QString resource) 2834bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2835{ 2835{
2836 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 2836 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
2837 2837
2838 AddressBook abLocal( resource,"syncContact"); 2838 AddressBook abLocal( resource,"syncContact");
2839 bool syncOK = false; 2839 bool syncOK = false;
2840 if ( abLocal.load() ) { 2840 if ( abLocal.load() ) {
2841 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2841 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
2842 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2842 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2843 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2843 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice );
2844 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2844 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2845 if ( syncOK ) { 2845 if ( syncOK ) {
2846 if ( syncManager->mWriteBackFile ) { 2846 if ( syncManager->mWriteBackFile ) {
2847 abLocal.saveAB(); 2847 abLocal.saveAB();
2848 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2848 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2849 } 2849 }
2850 } 2850 }
2851 setModified(); 2851 setModified();
2852 } 2852 }
2853 if ( syncOK ) 2853 if ( syncOK )
2854 mViewManager->refreshView(); 2854 mViewManager->refreshView();
2855 return syncOK; 2855 return syncOK;
2856 2856
2857} 2857}
2858 2858
2859void KABCore::getFile( bool success ) 2859void KABCore::getFile( bool success )
2860{ 2860{
2861 qDebug("KABCore::getFile ");
2862 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); 2861 QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
2863 if ( ! success ) { 2862 if ( ! success ) {
2864 setCaption( i18n("Error receiving file. Nothing changed!") ); 2863 setCaption( i18n("Error receiving file. Nothing changed!") );
2865 return; 2864 return;
2866 } 2865 }
2867 mAddressBook->importFromFile( sentSyncFile() ); 2866 mAddressBook->importFromFile( sentSyncFile() );
2868 topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 2867 topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
2868 mViewManager->refreshView();
2869} 2869}
2870void KABCore::syncFileRequest() 2870void KABCore::syncFileRequest()
2871{ 2871{
2872 mAddressBook->export2File( sentSyncFile() ); 2872 mAddressBook->export2File( sentSyncFile() );
2873} 2873}
2874QString KABCore::sentSyncFile() 2874QString KABCore::sentSyncFile()
2875{ 2875{
2876#ifdef _WIN32_ 2876#ifdef _WIN32_
2877 return locateLocal( "tmp", "copysyncab.vcf" ); 2877 return locateLocal( "tmp", "copysyncab.vcf" );
2878#else 2878#else
2879 return QString( "/tmp/copysyncab.vcf" ); 2879 return QString( "/tmp/copysyncab.vcf" );
2880#endif 2880#endif
2881} 2881}
2882 2882
2883void KABCore::setCaptionBack() 2883void KABCore::setCaptionBack()
2884{ 2884{
2885 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 2885 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
2886} 2886}
2887 2887