-rw-r--r-- | kaddressbook/kabcore.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index bdc5bd8..c75b4bc 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2615,173 +2615,177 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2615 | int incCounter = 0; | 2615 | int incCounter = 0; |
2616 | while ( incCounter < er.count()) { | 2616 | while ( incCounter < er.count()) { |
2617 | if (syncManager->isProgressBarCanceled()) | 2617 | if (syncManager->isProgressBarCanceled()) |
2618 | return false; | 2618 | return false; |
2619 | if ( incCounter % modulo == 0 ) | 2619 | if ( incCounter % modulo == 0 ) |
2620 | syncManager->showProgressBar(incCounter); | 2620 | syncManager->showProgressBar(incCounter); |
2621 | 2621 | ||
2622 | uid = er[ incCounter ]; | 2622 | uid = er[ incCounter ]; |
2623 | bool skipIncidence = false; | 2623 | bool skipIncidence = false; |
2624 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2624 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2625 | skipIncidence = true; | 2625 | skipIncidence = true; |
2626 | QString idS,OidS; | 2626 | QString idS,OidS; |
2627 | qApp->processEvents(); | 2627 | qApp->processEvents(); |
2628 | if ( !skipIncidence ) { | 2628 | if ( !skipIncidence ) { |
2629 | inL = local->findByUid( uid ); | 2629 | inL = local->findByUid( uid ); |
2630 | inR = remote->findByUid( uid ); | 2630 | inR = remote->findByUid( uid ); |
2631 | //inL.setResource( 0 ); | 2631 | //inL.setResource( 0 ); |
2632 | //inR.setResource( 0 ); | 2632 | //inR.setResource( 0 ); |
2633 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2633 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2634 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2634 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2635 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2635 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2636 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2636 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2637 | if ( take == 3 ) | 2637 | if ( take == 3 ) |
2638 | return false; | 2638 | return false; |
2639 | if ( take == 1 ) {// take local | 2639 | if ( take == 1 ) {// take local ********************** |
2640 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2640 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2641 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2641 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2642 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2642 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2643 | local->insertAddressee( inL, false ); | 2643 | local->insertAddressee( inL, false ); |
2644 | idS = inR.externalUID(); | 2644 | idS = inR.externalUID(); |
2645 | OidS = inR.originalExternalUID(); | 2645 | OidS = inR.originalExternalUID(); |
2646 | } | 2646 | } |
2647 | else | 2647 | else |
2648 | idS = inR.IDStr(); | 2648 | idS = inR.IDStr(); |
2649 | remote->removeAddressee( inR ); | 2649 | remote->removeAddressee( inR ); |
2650 | inR = inL; | 2650 | inR = inL; |
2651 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2651 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2652 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2653 | inR.setOriginalExternalUID( OidS ); | 2653 | inR.setOriginalExternalUID( OidS ); |
2654 | inR.setExternalUID( idS ); | 2654 | inR.setExternalUID( idS ); |
2655 | if ( syncManager->syncWithDesktop() ) | 2655 | if ( syncManager->syncWithDesktop() ) |
2656 | inR.setIDStr("changed" ); | 2656 | inR.setIDStr("changed" ); |
2657 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); | 2657 | //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); |
2658 | } else { | 2658 | } else { |
2659 | inR.setIDStr( idS ); | 2659 | inR.setIDStr( idS ); |
2660 | } | 2660 | } |
2661 | inR.setResource( 0 ); | 2661 | inR.setResource( 0 ); |
2662 | remote->insertAddressee( inR , false); | 2662 | remote->insertAddressee( inR , false); |
2663 | ++changedRemote; | 2663 | ++changedRemote; |
2664 | } else { // take == 2 take remote | 2664 | } else { // take == 2 take remote ********************** |
2665 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2665 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2666 | if ( inR.revision().date().year() < 2004 ) | 2666 | if ( inR.revision().date().year() < 2004 ) |
2667 | inR.setRevision( modifiedCalendar ); | 2667 | inR.setRevision( modifiedCalendar ); |
2668 | } | 2668 | } |
2669 | idS = inL.IDStr(); | 2669 | idS = inL.IDStr(); |
2670 | local->removeAddressee( inL ); | 2670 | local->removeAddressee( inL ); |
2671 | inL = inR; | 2671 | inL = inR; |
2672 | inL.setIDStr( idS ); | 2672 | inL.setIDStr( idS ); |
2673 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2673 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2674 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2674 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2675 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2675 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2676 | } | 2676 | } |
2677 | inL.setResource( 0 ); | 2677 | inL.setResource( 0 ); |
2678 | local->insertAddressee( inL , false ); | 2678 | local->insertAddressee( inL , false ); |
2679 | ++changedLocal; | 2679 | ++changedLocal; |
2680 | } | 2680 | } |
2681 | } | 2681 | } |
2682 | } | 2682 | } |
2683 | } else { // no conflict | 2683 | } else { // no conflict ********** add or delete remote |
2684 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2684 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2685 | QString des = addresseeLSync.note(); | 2685 | QString des = addresseeLSync.note(); |
2686 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2686 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2688 | remote->insertAddressee( inR, false ); | 2688 | remote->insertAddressee( inR, false ); |
2689 | ++deletedAddresseeR; | 2689 | ++deletedAddresseeR; |
2690 | } else { | 2690 | } else { |
2691 | inR.setRevision( modifiedCalendar ); | 2691 | inR.setRevision( modifiedCalendar ); |
2692 | remote->insertAddressee( inR, false ); | 2692 | remote->insertAddressee( inR, false ); |
2693 | inL = inR; | 2693 | inL = inR; |
2694 | inL.setIDStr( ":" ); | ||
2695 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | ||
2696 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | ||
2694 | inL.setResource( 0 ); | 2697 | inL.setResource( 0 ); |
2695 | local->insertAddressee( inL , false); | 2698 | local->insertAddressee( inL , false); |
2696 | ++addedAddressee; | 2699 | ++addedAddressee; |
2697 | } | 2700 | } |
2698 | } else { | 2701 | } else { |
2699 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2702 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2700 | inR.setRevision( modifiedCalendar ); | 2703 | inR.setRevision( modifiedCalendar ); |
2701 | remote->insertAddressee( inR, false ); | 2704 | remote->insertAddressee( inR, false ); |
2702 | inR.setResource( 0 ); | 2705 | inR.setResource( 0 ); |
2703 | local->insertAddressee( inR, false ); | 2706 | local->insertAddressee( inR, false ); |
2704 | ++addedAddressee; | 2707 | ++addedAddressee; |
2705 | } else { | 2708 | } else { |
2706 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2709 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2707 | remote->removeAddressee( inR ); | 2710 | remote->removeAddressee( inR ); |
2708 | ++deletedAddresseeR; | 2711 | ++deletedAddresseeR; |
2709 | } | 2712 | } |
2710 | } | 2713 | } |
2711 | } | 2714 | } |
2712 | } | 2715 | } |
2713 | ++incCounter; | 2716 | ++incCounter; |
2714 | } | 2717 | } |
2715 | er.clear(); | 2718 | er.clear(); |
2716 | QStringList el = local->uidList(); | 2719 | QStringList el = local->uidList(); |
2717 | modulo = (el.count()/10)+1; | 2720 | modulo = (el.count()/10)+1; |
2718 | 2721 | ||
2719 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2722 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2720 | incCounter = 0; | 2723 | incCounter = 0; |
2721 | while ( incCounter < el.count()) { | 2724 | while ( incCounter < el.count()) { |
2722 | qApp->processEvents(); | 2725 | qApp->processEvents(); |
2723 | if (syncManager->isProgressBarCanceled()) | 2726 | if (syncManager->isProgressBarCanceled()) |
2724 | return false; | 2727 | return false; |
2725 | if ( incCounter % modulo == 0 ) | 2728 | if ( incCounter % modulo == 0 ) |
2726 | syncManager->showProgressBar(incCounter); | 2729 | syncManager->showProgressBar(incCounter); |
2727 | uid = el[ incCounter ]; | 2730 | uid = el[ incCounter ]; |
2728 | bool skipIncidence = false; | 2731 | bool skipIncidence = false; |
2729 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2732 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2730 | skipIncidence = true; | 2733 | skipIncidence = true; |
2731 | if ( !skipIncidence ) { | 2734 | if ( !skipIncidence ) { |
2732 | inL = local->findByUid( uid ); | 2735 | inL = local->findByUid( uid ); |
2733 | if ( !inL.resource() || inL.resource()->includeInSync() ) { | 2736 | if ( !inL.resource() || inL.resource()->includeInSync() ) { |
2734 | inR = remote->findByUid( uid ); | 2737 | inR = remote->findByUid( uid ); |
2735 | if ( inR.isEmpty() ) { | 2738 | if ( inR.isEmpty() ) { / no conflict ********** add or delete local |
2736 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2739 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2737 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2740 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2738 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2741 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2739 | local->removeAddressee( inL ); | 2742 | local->removeAddressee( inL ); |
2740 | ++deletedAddresseeL; | 2743 | ++deletedAddresseeL; |
2741 | } else { | 2744 | } else { |
2742 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2745 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2743 | inL.removeID(mCurrentSyncDevice ); | 2746 | inL.removeID(mCurrentSyncDevice ); |
2744 | ++addedAddresseeR; | 2747 | ++addedAddresseeR; |
2745 | inL.setRevision( modifiedCalendar ); | 2748 | inL.setRevision( modifiedCalendar ); |
2746 | local->insertAddressee( inL, false ); | 2749 | local->insertAddressee( inL, false ); |
2747 | inR = inL; | 2750 | inR = inL; |
2748 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2751 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2749 | inR.setResource( 0 ); | 2752 | inR.setResource( 0 ); |
2750 | remote->insertAddressee( inR, false ); | 2753 | remote->insertAddressee( inR, false ); |
2751 | } | 2754 | } |
2752 | } | 2755 | } |
2753 | } else { | 2756 | } else { |
2754 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2757 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2755 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2758 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2756 | local->removeAddressee( inL ); | 2759 | local->removeAddressee( inL ); |
2757 | ++deletedAddresseeL; | 2760 | ++deletedAddresseeL; |
2758 | } else { | 2761 | } else { |
2759 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2762 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2760 | ++addedAddresseeR; | 2763 | ++addedAddresseeR; |
2761 | inL.setRevision( modifiedCalendar ); | 2764 | inL.setRevision( modifiedCalendar ); |
2762 | local->insertAddressee( inL, false ); | 2765 | local->insertAddressee( inL, false ); |
2763 | inR = inL; | 2766 | inR = inL; |
2767 | inR.setIDStr( ":" ); | ||
2764 | inR.setResource( 0 ); | 2768 | inR.setResource( 0 ); |
2765 | remote->insertAddressee( inR, false ); | 2769 | remote->insertAddressee( inR, false ); |
2766 | } | 2770 | } |
2767 | } | 2771 | } |
2768 | } | 2772 | } |
2769 | } | 2773 | } |
2770 | } | 2774 | } |
2771 | } | 2775 | } |
2772 | ++incCounter; | 2776 | ++incCounter; |
2773 | } | 2777 | } |
2774 | el.clear(); | 2778 | el.clear(); |
2775 | syncManager->hideProgressBar(); | 2779 | syncManager->hideProgressBar(); |
2776 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2780 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2777 | // get rid of micro seconds | 2781 | // get rid of micro seconds |
2778 | QTime t = mLastAddressbookSync.time(); | 2782 | QTime t = mLastAddressbookSync.time(); |
2779 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2783 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2780 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2784 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2781 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2785 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2782 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2786 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2783 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2787 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2784 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2788 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2785 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2789 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2786 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2790 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2787 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2791 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |