author | zautrix <zautrix> | 2004-09-19 20:14:28 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-19 20:14:28 (UTC) |
commit | afa28a62314117555d6b32291188eedd1a576284 (patch) (unidiff) | |
tree | ea97a247de30a7a34480bc395e1996ab99247361 /kaddressbook | |
parent | e0d8e062c9d8092e47dcadd88b30614ebff43c0c (diff) | |
download | kdepimpi-afa28a62314117555d6b32291188eedd1a576284.zip kdepimpi-afa28a62314117555d6b32291188eedd1a576284.tar.gz kdepimpi-afa28a62314117555d6b32291188eedd1a576284.tar.bz2 |
more AB sync
-rw-r--r-- | kaddressbook/kabcore.cpp | 87 |
1 files changed, 61 insertions, 26 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index d6482fb..b3d88de 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2563,462 +2563,497 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i | |||
2563 | } else { | 2563 | } else { |
2564 | if ( locCh ) { | 2564 | if ( locCh ) { |
2565 | //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2565 | //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2566 | lastSync = local->revision().addDays( -1 ); | 2566 | lastSync = local->revision().addDays( -1 ); |
2567 | if ( !remCh ) | 2567 | if ( !remCh ) |
2568 | remote->setRevision( lastSync.addDays( -1 ) ); | 2568 | remote->setRevision( lastSync.addDays( -1 ) ); |
2569 | } else { | 2569 | } else { |
2570 | //qDebug(" not loc changed "); | 2570 | //qDebug(" not loc changed "); |
2571 | lastSync = local->revision().addDays( 1 ); | 2571 | lastSync = local->revision().addDays( 1 ); |
2572 | if ( remCh ) | 2572 | if ( remCh ) |
2573 | remote->setRevision( lastSync.addDays( 1 ) ); | 2573 | remote->setRevision( lastSync.addDays( 1 ) ); |
2574 | 2574 | ||
2575 | } | 2575 | } |
2576 | } | 2576 | } |
2577 | full = true; | 2577 | full = true; |
2578 | if ( mode < SYNC_PREF_ASK ) | 2578 | if ( mode < SYNC_PREF_ASK ) |
2579 | mode = SYNC_PREF_ASK; | 2579 | mode = SYNC_PREF_ASK; |
2580 | } else { | 2580 | } else { |
2581 | if ( local->revision() == remote->revision() ) | 2581 | if ( local->revision() == remote->revision() ) |
2582 | return 0; | 2582 | return 0; |
2583 | 2583 | ||
2584 | } | 2584 | } |
2585 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2585 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2586 | 2586 | ||
2587 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); | 2587 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); |
2588 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2588 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2589 | //full = true; //debug only | 2589 | //full = true; //debug only |
2590 | if ( full ) { | 2590 | if ( full ) { |
2591 | bool equ = ( (*local) == (*remote) ); | 2591 | bool equ = ( (*local) == (*remote) ); |
2592 | if ( equ ) { | 2592 | if ( equ ) { |
2593 | //qDebug("equal "); | 2593 | //qDebug("equal "); |
2594 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2594 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2595 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2595 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2596 | } | 2596 | } |
2597 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2597 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2598 | return 0; | 2598 | return 0; |
2599 | 2599 | ||
2600 | }//else //debug only | 2600 | }//else //debug only |
2601 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2601 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2602 | } | 2602 | } |
2603 | int result; | 2603 | int result; |
2604 | bool localIsNew; | 2604 | bool localIsNew; |
2605 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2605 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2606 | 2606 | ||
2607 | if ( full && mode < SYNC_PREF_NEWEST ) | 2607 | if ( full && mode < SYNC_PREF_NEWEST ) |
2608 | mode = SYNC_PREF_ASK; | 2608 | mode = SYNC_PREF_ASK; |
2609 | 2609 | ||
2610 | switch( mode ) { | 2610 | switch( mode ) { |
2611 | case SYNC_PREF_LOCAL: | 2611 | case SYNC_PREF_LOCAL: |
2612 | if ( lastSync > remote->revision() ) | 2612 | if ( lastSync > remote->revision() ) |
2613 | return 1; | 2613 | return 1; |
2614 | if ( lastSync > local->revision() ) | 2614 | if ( lastSync > local->revision() ) |
2615 | return 2; | 2615 | return 2; |
2616 | return 1; | 2616 | return 1; |
2617 | break; | 2617 | break; |
2618 | case SYNC_PREF_REMOTE: | 2618 | case SYNC_PREF_REMOTE: |
2619 | if ( lastSync > remote->revision() ) | 2619 | if ( lastSync > remote->revision() ) |
2620 | return 1; | 2620 | return 1; |
2621 | if ( lastSync > local->revision() ) | 2621 | if ( lastSync > local->revision() ) |
2622 | return 2; | 2622 | return 2; |
2623 | return 2; | 2623 | return 2; |
2624 | break; | 2624 | break; |
2625 | case SYNC_PREF_NEWEST: | 2625 | case SYNC_PREF_NEWEST: |
2626 | if ( local->revision() > remote->revision() ) | 2626 | if ( local->revision() > remote->revision() ) |
2627 | return 1; | 2627 | return 1; |
2628 | else | 2628 | else |
2629 | return 2; | 2629 | return 2; |
2630 | break; | 2630 | break; |
2631 | case SYNC_PREF_ASK: | 2631 | case SYNC_PREF_ASK: |
2632 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); | 2632 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); |
2633 | if ( lastSync > remote->revision() ) | 2633 | if ( lastSync > remote->revision() ) |
2634 | return 1; | 2634 | return 1; |
2635 | if ( lastSync > local->revision() ) | 2635 | if ( lastSync > local->revision() ) |
2636 | return 2; | 2636 | return 2; |
2637 | localIsNew = local->revision() >= remote->revision(); | 2637 | localIsNew = local->revision() >= remote->revision(); |
2638 | //qDebug("conflict! ************************************** "); | 2638 | //qDebug("conflict! ************************************** "); |
2639 | { | 2639 | { |
2640 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2640 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2641 | result = acd.executeD(localIsNew); | 2641 | result = acd.executeD(localIsNew); |
2642 | return result; | 2642 | return result; |
2643 | } | 2643 | } |
2644 | break; | 2644 | break; |
2645 | case SYNC_PREF_FORCE_LOCAL: | 2645 | case SYNC_PREF_FORCE_LOCAL: |
2646 | return 1; | 2646 | return 1; |
2647 | break; | 2647 | break; |
2648 | case SYNC_PREF_FORCE_REMOTE: | 2648 | case SYNC_PREF_FORCE_REMOTE: |
2649 | return 2; | 2649 | return 2; |
2650 | break; | 2650 | break; |
2651 | 2651 | ||
2652 | default: | 2652 | default: |
2653 | // SYNC_PREF_TAKE_BOTH not implemented | 2653 | // SYNC_PREF_TAKE_BOTH not implemented |
2654 | break; | 2654 | break; |
2655 | } | 2655 | } |
2656 | return 0; | 2656 | return 0; |
2657 | } | 2657 | } |
2658 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2658 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2659 | { | 2659 | { |
2660 | bool syncOK = true; | 2660 | bool syncOK = true; |
2661 | int addedAddressee = 0; | 2661 | int addedAddressee = 0; |
2662 | int addedAddresseeR = 0; | 2662 | int addedAddresseeR = 0; |
2663 | int deletedAddresseeR = 0; | 2663 | int deletedAddresseeR = 0; |
2664 | int deletedAddresseeL = 0; | 2664 | int deletedAddresseeL = 0; |
2665 | int changedLocal = 0; | 2665 | int changedLocal = 0; |
2666 | int changedRemote = 0; | 2666 | int changedRemote = 0; |
2667 | //QPtrList<Addressee> el = local->rawAddressees(); | 2667 | //QPtrList<Addressee> el = local->rawAddressees(); |
2668 | Addressee addresseeR; | 2668 | Addressee addresseeR; |
2669 | QString uid; | 2669 | QString uid; |
2670 | int take; | 2670 | int take; |
2671 | Addressee addresseeL; | 2671 | Addressee addresseeL; |
2672 | Addressee addresseeRSync; | 2672 | Addressee addresseeRSync; |
2673 | Addressee addresseeLSync; | 2673 | Addressee addresseeLSync; |
2674 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2674 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2675 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2675 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2676 | bool fullDateRange = false; | 2676 | bool fullDateRange = false; |
2677 | local->resetTempSyncStat(); | 2677 | local->resetTempSyncStat(); |
2678 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2678 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2679 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2679 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2680 | addresseeLSync = getLastSyncAddressee(); | 2680 | addresseeLSync = getLastSyncAddressee(); |
2681 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2681 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2682 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2682 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2683 | if ( !addresseeR.isEmpty() ) { | 2683 | if ( !addresseeR.isEmpty() ) { |
2684 | addresseeRSync = addresseeR; | 2684 | addresseeRSync = addresseeR; |
2685 | remote->removeAddressee(addresseeR ); | 2685 | remote->removeAddressee(addresseeR ); |
2686 | 2686 | ||
2687 | } else { | 2687 | } else { |
2688 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2688 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2689 | addresseeRSync = addresseeLSync ; | 2689 | addresseeRSync = addresseeLSync ; |
2690 | } else { | 2690 | } else { |
2691 | qDebug("FULLDATE 1"); | 2691 | qDebug("FULLDATE 1"); |
2692 | fullDateRange = true; | 2692 | fullDateRange = true; |
2693 | Addressee newAdd; | 2693 | Addressee newAdd; |
2694 | addresseeRSync = newAdd; | 2694 | addresseeRSync = newAdd; |
2695 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2695 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2696 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2696 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2697 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2697 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2698 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2698 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2699 | } | 2699 | } |
2700 | } | 2700 | } |
2701 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2701 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2702 | qDebug("FULLDATE 2"); | 2702 | qDebug("FULLDATE 2"); |
2703 | fullDateRange = true; | 2703 | fullDateRange = true; |
2704 | } | 2704 | } |
2705 | if ( ! fullDateRange ) { | 2705 | if ( ! fullDateRange ) { |
2706 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2706 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2707 | 2707 | ||
2708 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2708 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2709 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2709 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2710 | fullDateRange = true; | 2710 | fullDateRange = true; |
2711 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2711 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2712 | } | 2712 | } |
2713 | } | 2713 | } |
2714 | // fullDateRange = true; // debug only! | 2714 | // fullDateRange = true; // debug only! |
2715 | if ( fullDateRange ) | 2715 | if ( fullDateRange ) |
2716 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2716 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2717 | else | 2717 | else |
2718 | mLastAddressbookSync = addresseeLSync.revision(); | 2718 | mLastAddressbookSync = addresseeLSync.revision(); |
2719 | // for resyncing if own file has changed | 2719 | // for resyncing if own file has changed |
2720 | // PENDING fixme later when implemented | 2720 | // PENDING fixme later when implemented |
2721 | #if 0 | 2721 | #if 0 |
2722 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2722 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2723 | mLastAddressbookSync = loadedFileVersion; | 2723 | mLastAddressbookSync = loadedFileVersion; |
2724 | qDebug("setting mLastAddressbookSync "); | 2724 | qDebug("setting mLastAddressbookSync "); |
2725 | } | 2725 | } |
2726 | #endif | 2726 | #endif |
2727 | 2727 | ||
2728 | //qDebug("*************************** "); | 2728 | //qDebug("*************************** "); |
2729 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2729 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2730 | QStringList er = remote->uidList(); | 2730 | QStringList er = remote->uidList(); |
2731 | Addressee inR ;//= er.first(); | 2731 | Addressee inR ;//= er.first(); |
2732 | Addressee inL; | 2732 | Addressee inL; |
2733 | QProgressBar bar( er.count(),0 ); | 2733 | QProgressBar bar( er.count(),0 ); |
2734 | bar.setCaption (i18n("Syncing - close to abort!") ); | 2734 | bar.setCaption (i18n("Syncing - close to abort!") ); |
2735 | 2735 | ||
2736 | int w = 300; | 2736 | int w = 300; |
2737 | if ( QApplication::desktop()->width() < 320 ) | 2737 | if ( QApplication::desktop()->width() < 320 ) |
2738 | w = 220; | 2738 | w = 220; |
2739 | int h = bar.sizeHint().height() ; | 2739 | int h = bar.sizeHint().height() ; |
2740 | int dw = QApplication::desktop()->width(); | 2740 | int dw = QApplication::desktop()->width(); |
2741 | int dh = QApplication::desktop()->height(); | 2741 | int dh = QApplication::desktop()->height(); |
2742 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2742 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2743 | bar.show(); | 2743 | bar.show(); |
2744 | int modulo = (er.count()/10)+1; | 2744 | int modulo = (er.count()/10)+1; |
2745 | int incCounter = 0; | 2745 | int incCounter = 0; |
2746 | while ( incCounter < er.count()) { | 2746 | while ( incCounter < er.count()) { |
2747 | if ( ! bar.isVisible() ) | 2747 | if ( ! bar.isVisible() ) |
2748 | return false; | 2748 | return false; |
2749 | if ( incCounter % modulo == 0 ) | 2749 | if ( incCounter % modulo == 0 ) |
2750 | bar.setProgress( incCounter ); | 2750 | bar.setProgress( incCounter ); |
2751 | uid = er[ incCounter ]; | 2751 | uid = er[ incCounter ]; |
2752 | bool skipIncidence = false; | 2752 | bool skipIncidence = false; |
2753 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2753 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2754 | skipIncidence = true; | 2754 | skipIncidence = true; |
2755 | QString idS; | 2755 | QString idS,OidS; |
2756 | qApp->processEvents(); | 2756 | qApp->processEvents(); |
2757 | if ( !skipIncidence ) { | 2757 | if ( !skipIncidence ) { |
2758 | inL = local->findByUid( uid ); | 2758 | inL = local->findByUid( uid ); |
2759 | inR = remote->findByUid( uid ); | 2759 | inR = remote->findByUid( uid ); |
2760 | //inL.setResource( 0 ); | 2760 | //inL.setResource( 0 ); |
2761 | //inR.setResource( 0 ); | 2761 | //inR.setResource( 0 ); |
2762 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2762 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2763 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2763 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2764 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2764 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2765 | if ( take == 3 ) | 2765 | if ( take == 3 ) |
2766 | return false; | 2766 | return false; |
2767 | if ( take == 1 ) {// take local | 2767 | if ( take == 1 ) {// take local |
2768 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2768 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2769 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2769 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2770 | local->insertAddressee( inL, false ); | 2770 | local->insertAddressee( inL, false ); |
2771 | idS = inR.externalUID(); | ||
2772 | OidS = inR.originalExternalUID(); | ||
2771 | } | 2773 | } |
2772 | else | 2774 | else |
2773 | idS = inR.IDStr(); | 2775 | idS = inR.IDStr(); |
2774 | remote->removeAddressee( inR ); | 2776 | remote->removeAddressee( inR ); |
2775 | inR = inL; | 2777 | inR = inL; |
2776 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2778 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2777 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 2779 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2780 | inR.setOriginalExternalUID( OidS ); | ||
2781 | inR.setExternalUID( idS ); | ||
2782 | } else { | ||
2778 | inR.setIDStr( idS ); | 2783 | inR.setIDStr( idS ); |
2784 | } | ||
2779 | inR.setResource( 0 ); | 2785 | inR.setResource( 0 ); |
2780 | remote->insertAddressee( inR , false); | 2786 | remote->insertAddressee( inR , false); |
2781 | ++changedRemote; | 2787 | ++changedRemote; |
2782 | } else { | 2788 | } else { // take == 2 take remote |
2783 | idS = inL.IDStr(); | 2789 | idS = inL.IDStr(); |
2784 | local->removeAddressee( inL ); | 2790 | local->removeAddressee( inL ); |
2785 | inL = inR; | 2791 | inL = inR; |
2786 | inL.setIDStr( idS ); | 2792 | inL.setIDStr( idS ); |
2787 | inL.setResource( 0 ); | 2793 | inL.setResource( 0 ); |
2788 | local->insertAddressee( inL , false ); | 2794 | local->insertAddressee( inL , false ); |
2789 | ++changedLocal; | 2795 | ++changedLocal; |
2790 | } | 2796 | } |
2791 | } | 2797 | } |
2792 | } else { // no conflict | 2798 | } else { // no conflict |
2793 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2799 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2794 | QString des = addresseeLSync.note(); | 2800 | QString des = addresseeLSync.note(); |
2795 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2801 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2796 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2802 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2797 | remote->insertAddressee( inR, false ); | 2803 | remote->insertAddressee( inR, false ); |
2798 | ++deletedAddresseeR; | 2804 | ++deletedAddresseeR; |
2799 | } else { | 2805 | } else { |
2800 | inR.setRevision( modifiedCalendar ); | 2806 | inR.setRevision( modifiedCalendar ); |
2801 | remote->insertAddressee( inR, false ); | 2807 | remote->insertAddressee( inR, false ); |
2802 | inL = inR; | 2808 | inL = inR; |
2803 | inL.setResource( 0 ); | 2809 | inL.setResource( 0 ); |
2804 | local->insertAddressee( inL , false); | 2810 | local->insertAddressee( inL , false); |
2805 | ++addedAddressee; | 2811 | ++addedAddressee; |
2806 | } | 2812 | } |
2807 | } else { | 2813 | } else { |
2808 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2814 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2809 | inR.setRevision( modifiedCalendar ); | 2815 | inR.setRevision( modifiedCalendar ); |
2810 | remote->insertAddressee( inR, false ); | 2816 | remote->insertAddressee( inR, false ); |
2811 | inR.setResource( 0 ); | 2817 | inR.setResource( 0 ); |
2812 | local->insertAddressee( inR, false ); | 2818 | local->insertAddressee( inR, false ); |
2813 | ++addedAddressee; | 2819 | ++addedAddressee; |
2814 | } else { | 2820 | } else { |
2815 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2821 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2816 | remote->removeAddressee( inR ); | 2822 | remote->removeAddressee( inR ); |
2817 | ++deletedAddresseeR; | 2823 | ++deletedAddresseeR; |
2818 | } | 2824 | } |
2819 | } | 2825 | } |
2820 | } | 2826 | } |
2821 | } | 2827 | } |
2822 | ++incCounter; | 2828 | ++incCounter; |
2823 | } | 2829 | } |
2824 | er.clear(); | 2830 | er.clear(); |
2825 | QStringList el = local->uidList(); | 2831 | QStringList el = local->uidList(); |
2826 | modulo = (el.count()/10)+1; | 2832 | modulo = (el.count()/10)+1; |
2827 | bar.setCaption (i18n("Add / remove addressees") ); | 2833 | bar.setCaption (i18n("Add / remove addressees") ); |
2828 | bar.setTotalSteps ( el.count() ) ; | 2834 | bar.setTotalSteps ( el.count() ) ; |
2829 | bar.show(); | 2835 | bar.show(); |
2830 | incCounter = 0; | 2836 | incCounter = 0; |
2831 | while ( incCounter < el.count()) { | 2837 | while ( incCounter < el.count()) { |
2832 | qApp->processEvents(); | 2838 | qApp->processEvents(); |
2833 | if ( ! bar.isVisible() ) | 2839 | if ( ! bar.isVisible() ) |
2834 | return false; | 2840 | return false; |
2835 | if ( incCounter % modulo == 0 ) | 2841 | if ( incCounter % modulo == 0 ) |
2836 | bar.setProgress( incCounter ); | 2842 | bar.setProgress( incCounter ); |
2837 | uid = el[ incCounter ]; | 2843 | uid = el[ incCounter ]; |
2838 | bool skipIncidence = false; | 2844 | bool skipIncidence = false; |
2839 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2845 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2840 | skipIncidence = true; | 2846 | skipIncidence = true; |
2841 | if ( !skipIncidence ) { | 2847 | if ( !skipIncidence ) { |
2842 | inL = local->findByUid( uid ); | 2848 | inL = local->findByUid( uid ); |
2843 | inR = remote->findByUid( uid ); | 2849 | inR = remote->findByUid( uid ); |
2844 | if ( inR.isEmpty() ) { | 2850 | if ( inR.isEmpty() ) { |
2845 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2851 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2846 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2852 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2847 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2853 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2848 | local->removeAddressee( inL ); | 2854 | local->removeAddressee( inL ); |
2849 | ++deletedAddresseeL; | 2855 | ++deletedAddresseeL; |
2850 | } else { | 2856 | } else { |
2851 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2857 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2852 | inL.removeID(mCurrentSyncDevice ); | 2858 | inL.removeID(mCurrentSyncDevice ); |
2853 | ++addedAddresseeR; | 2859 | ++addedAddresseeR; |
2854 | inL.setRevision( modifiedCalendar ); | 2860 | inL.setRevision( modifiedCalendar ); |
2855 | local->insertAddressee( inL, false ); | 2861 | local->insertAddressee( inL, false ); |
2856 | inR = inL; | 2862 | inR = inL; |
2857 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2863 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2858 | inR.setResource( 0 ); | 2864 | inR.setResource( 0 ); |
2859 | remote->insertAddressee( inR, false ); | 2865 | remote->insertAddressee( inR, false ); |
2860 | } | 2866 | } |
2861 | } | 2867 | } |
2862 | } else { | 2868 | } else { |
2863 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2864 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2870 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2865 | local->removeAddressee( inL ); | 2871 | local->removeAddressee( inL ); |
2866 | ++deletedAddresseeL; | 2872 | ++deletedAddresseeL; |
2867 | } else { | 2873 | } else { |
2868 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2874 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2869 | ++addedAddresseeR; | 2875 | ++addedAddresseeR; |
2870 | inL.setRevision( modifiedCalendar ); | 2876 | inL.setRevision( modifiedCalendar ); |
2871 | local->insertAddressee( inL, false ); | 2877 | local->insertAddressee( inL, false ); |
2872 | inR = inL; | 2878 | inR = inL; |
2873 | inR.setResource( 0 ); | 2879 | inR.setResource( 0 ); |
2874 | remote->insertAddressee( inR, false ); | 2880 | remote->insertAddressee( inR, false ); |
2875 | } | 2881 | } |
2876 | } | 2882 | } |
2877 | } | 2883 | } |
2878 | } | 2884 | } |
2879 | } | 2885 | } |
2880 | ++incCounter; | 2886 | ++incCounter; |
2881 | } | 2887 | } |
2882 | el.clear(); | 2888 | el.clear(); |
2883 | bar.hide(); | 2889 | bar.hide(); |
2884 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2890 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2885 | // get rid of micro seconds | 2891 | // get rid of micro seconds |
2886 | QTime t = mLastAddressbookSync.time(); | 2892 | QTime t = mLastAddressbookSync.time(); |
2887 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2893 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2888 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2894 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2889 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2895 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2890 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2896 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2891 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2897 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2892 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2898 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2893 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2899 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2894 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2900 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2895 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2901 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2896 | addresseeRSync.setNote( "" ) ; | 2902 | addresseeRSync.setNote( "" ) ; |
2897 | addresseeLSync.setNote( "" ); | 2903 | addresseeLSync.setNote( "" ); |
2898 | 2904 | ||
2899 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2905 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2900 | remote->insertAddressee( addresseeRSync, false ); | 2906 | remote->insertAddressee( addresseeRSync, false ); |
2901 | local->insertAddressee( addresseeLSync, false ); | 2907 | local->insertAddressee( addresseeLSync, false ); |
2902 | QString mes; | 2908 | QString mes; |
2903 | 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 ); | 2909 | 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 ); |
2904 | if ( KABPrefs::instance()->mShowSyncSummary ) { | 2910 | if ( KABPrefs::instance()->mShowSyncSummary ) { |
2905 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2911 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2906 | } | 2912 | } |
2907 | qDebug( mes ); | 2913 | qDebug( mes ); |
2908 | return syncOK; | 2914 | return syncOK; |
2909 | } | 2915 | } |
2910 | 2916 | ||
2911 | bool KABCore::syncAB(QString filename, int mode) | 2917 | bool KABCore::syncAB(QString filename, int mode) |
2912 | { | 2918 | { |
2913 | 2919 | ||
2914 | //pending prepare addresseeview for output | 2920 | //pending prepare addresseeview for output |
2915 | //pending detect, if remote file has REV field. if not switch to external sync | 2921 | //pending detect, if remote file has REV field. if not switch to external sync |
2916 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2922 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2917 | AddressBook abLocal(filename,"syncContact"); | 2923 | AddressBook abLocal(filename,"syncContact"); |
2918 | bool syncOK = false; | 2924 | bool syncOK = false; |
2919 | if ( abLocal.load() ) { | 2925 | if ( abLocal.load() ) { |
2920 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2926 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2921 | bool external = false; | 2927 | bool external = false; |
2922 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | ||
2923 | if ( ! lse.isEmpty() ) { | ||
2924 | if ( lse.familyName().left(4) == "!E: " ) | ||
2925 | external = true; | ||
2926 | } else { | ||
2927 | bool found = false; | ||
2928 | QDateTime dt( QDate( 2004,1,1)); | ||
2929 | AddressBook::Iterator it; | ||
2930 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2931 | if ( (*it).revision() != dt ) { | ||
2932 | found = true; | ||
2933 | break; | ||
2934 | } | ||
2935 | } | ||
2936 | external = ! found; | ||
2937 | } | ||
2938 | 2928 | ||
2939 | if ( external ) { | 2929 | if ( filename.right(4) == ".xml") { |
2940 | qDebug("Setting vcf mode to external "); | ||
2941 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2930 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2942 | AddressBook::Iterator it; | 2931 | AddressBook::Iterator it; |
2943 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2932 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2944 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2933 | (*it).setID( mCurrentSyncDevice, (*it).externalUID() ); |
2945 | (*it).computeCsum( mCurrentSyncDevice ); | 2934 | (*it).computeCsum( mCurrentSyncDevice ); |
2946 | } | 2935 | } |
2936 | abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); | ||
2937 | |||
2938 | } else { | ||
2939 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | ||
2940 | if ( ! lse.isEmpty() ) { | ||
2941 | if ( lse.familyName().left(4) == "!E: " ) | ||
2942 | external = true; | ||
2943 | } else { | ||
2944 | bool found = false; | ||
2945 | QDateTime dt( QDate( 2004,1,1)); | ||
2946 | AddressBook::Iterator it; | ||
2947 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2948 | if ( (*it).revision() != dt ) { | ||
2949 | found = true; | ||
2950 | break; | ||
2951 | } | ||
2952 | } | ||
2953 | external = ! found; | ||
2954 | } | ||
2955 | |||
2956 | if ( external ) { | ||
2957 | qDebug("Setting vcf mode to external "); | ||
2958 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | ||
2959 | AddressBook::Iterator it; | ||
2960 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2961 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | ||
2962 | (*it).computeCsum( mCurrentSyncDevice ); | ||
2963 | } | ||
2964 | } | ||
2947 | } | 2965 | } |
2948 | //AddressBook::Iterator it; | 2966 | //AddressBook::Iterator it; |
2949 | //QStringList vcards; | 2967 | //QStringList vcards; |
2950 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2968 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2951 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2969 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2952 | //} | 2970 | //} |
2953 | if ( filename.right(4) == ".xml") | ||
2954 | abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); | ||
2955 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2971 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2956 | if ( syncOK ) { | 2972 | if ( syncOK ) { |
2957 | if ( KABPrefs::instance()->mWriteBackFile ) | 2973 | if ( KABPrefs::instance()->mWriteBackFile ) |
2958 | { | 2974 | { |
2959 | if ( external ) | 2975 | if ( external && filename.right(4) != ".xml") |
2960 | abLocal.removeDeletedAddressees(); | 2976 | abLocal.removeDeletedAddressees(); |
2961 | qDebug("Saving remote AB "); | 2977 | qDebug("Saving remote AB "); |
2962 | abLocal.saveAB(); | 2978 | abLocal.saveAB(); |
2979 | if ( external && filename.right(4) == ".xml") { | ||
2980 | // afterwrite processing | ||
2981 | AddressBook::Iterator it; | ||
2982 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2983 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | ||
2984 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | ||
2985 | Addressee ad = mAddressBook->findByUid( ( (*it).uid() )); | ||
2986 | if ( ad.isEmpty() ) { | ||
2987 | qDebug("ERROR ad empty "); | ||
2988 | } else { | ||
2989 | (*it).computeCsum( mCurrentSyncDevice ); | ||
2990 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | ||
2991 | ad.setID( mCurrentSyncDevice, (*it).externalUID() ); | ||
2992 | ad.setCsum( mCurrentSyncDevice, (*it).getCsum( mCurrentSyncDevice ) ); | ||
2993 | mAddressBook->insertAddressee( ad ); | ||
2994 | } | ||
2995 | } | ||
2996 | } | ||
2997 | } | ||
2963 | } | 2998 | } |
2964 | } | 2999 | } |
2965 | setModified(); | 3000 | setModified(); |
2966 | 3001 | ||
2967 | } | 3002 | } |
2968 | if ( syncOK ) | 3003 | if ( syncOK ) |
2969 | mViewManager->refreshView(); | 3004 | mViewManager->refreshView(); |
2970 | return syncOK; | 3005 | return syncOK; |
2971 | #if 0 | 3006 | #if 0 |
2972 | 3007 | ||
2973 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 3008 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2974 | getEventViewerDialog()->setSyncMode( true ); | 3009 | getEventViewerDialog()->setSyncMode( true ); |
2975 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 3010 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2976 | getEventViewerDialog()->setSyncMode( false ); | 3011 | getEventViewerDialog()->setSyncMode( false ); |
2977 | if ( syncOK ) { | 3012 | if ( syncOK ) { |
2978 | if ( KOPrefs::instance()->mWriteBackFile ) | 3013 | if ( KOPrefs::instance()->mWriteBackFile ) |
2979 | { | 3014 | { |
2980 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 3015 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2981 | storage->save(); | 3016 | storage->save(); |
2982 | } | 3017 | } |
2983 | } | 3018 | } |
2984 | setModified(); | 3019 | setModified(); |
2985 | } | 3020 | } |
2986 | 3021 | ||
2987 | #endif | 3022 | #endif |
2988 | } | 3023 | } |
2989 | 3024 | ||
2990 | void KABCore::confSync() | 3025 | void KABCore::confSync() |
2991 | { | 3026 | { |
2992 | static KSyncPrefsDialog* sp = 0; | 3027 | static KSyncPrefsDialog* sp = 0; |
2993 | if ( ! sp ) { | 3028 | if ( ! sp ) { |
2994 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 3029 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
2995 | } | 3030 | } |
2996 | sp->usrReadConfig(); | 3031 | sp->usrReadConfig(); |
2997 | #ifndef DESKTOP_VERSION | 3032 | #ifndef DESKTOP_VERSION |
2998 | sp->showMaximized(); | 3033 | sp->showMaximized(); |
2999 | #else | 3034 | #else |
3000 | sp->show(); | 3035 | sp->show(); |
3001 | #endif | 3036 | #endif |
3002 | sp->exec(); | 3037 | sp->exec(); |
3003 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 3038 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
3004 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 3039 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
3005 | fillSyncMenu(); | 3040 | fillSyncMenu(); |
3006 | } | 3041 | } |
3007 | void KABCore::syncSharp() | 3042 | void KABCore::syncSharp() |
3008 | { | 3043 | { |
3009 | if ( mModified ) | 3044 | if ( mModified ) |
3010 | save(); | 3045 | save(); |
3011 | qDebug("pending syncSharp() "); | 3046 | qDebug("pending syncSharp() "); |
3012 | //mView->syncSharp(); | 3047 | //mView->syncSharp(); |
3013 | setModified(); | 3048 | setModified(); |
3014 | 3049 | ||
3015 | } | 3050 | } |
3016 | void KABCore::syncPhone() | 3051 | void KABCore::syncPhone() |
3017 | { | 3052 | { |
3018 | if ( mModified ) | 3053 | if ( mModified ) |
3019 | save(); | 3054 | save(); |
3020 | qDebug("pending syncPhone(); "); | 3055 | qDebug("pending syncPhone(); "); |
3021 | //mView->syncPhone(); | 3056 | //mView->syncPhone(); |
3022 | setModified(); | 3057 | setModified(); |
3023 | 3058 | ||
3024 | } | 3059 | } |