-rw-r--r-- | kaddressbook/kabcore.cpp | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index cc8eb52..8776b53 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2660,26 +2660,26 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2660 | int addedAddresseeR = 0; | 2660 | int addedAddresseeR = 0; |
2661 | int deletedAddresseeR = 0; | 2661 | int deletedAddresseeR = 0; |
2662 | int deletedAddresseeL = 0; | 2662 | int deletedAddresseeL = 0; |
2663 | int changedLocal = 0; | 2663 | int changedLocal = 0; |
2664 | int changedRemote = 0; | 2664 | int changedRemote = 0; |
2665 | //QPtrList<Addressee> el = local->rawAddressees(); | 2665 | //QPtrList<Addressee> el = local->rawAddressees(); |
2666 | Addressee addresseeR; | 2666 | Addressee addresseeR; |
2667 | QString uid; | 2667 | QString uid; |
2668 | int take; | 2668 | int take; |
2669 | Addressee addresseeL; | 2669 | Addressee addresseeL; |
2670 | Addressee addresseeRSync; | 2670 | Addressee addresseeRSync; |
2671 | Addressee addresseeLSync; | 2671 | Addressee addresseeLSync; |
2672 | KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2672 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2673 | KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2673 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2674 | bool fullDateRange = false; | 2674 | bool fullDateRange = false; |
2675 | local->resetTempSyncStat(); | 2675 | local->resetTempSyncStat(); |
2676 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2676 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2677 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2677 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2678 | addresseeLSync = getLastSyncAddressee(); | 2678 | addresseeLSync = getLastSyncAddressee(); |
2679 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2679 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2680 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2680 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2681 | if ( !addresseeR.isEmpty() ) { | 2681 | if ( !addresseeR.isEmpty() ) { |
2682 | addresseeRSync = addresseeR; | 2682 | addresseeRSync = addresseeR; |
2683 | remote->removeAddressee(addresseeR ); | 2683 | remote->removeAddressee(addresseeR ); |
2684 | 2684 | ||
2685 | } else { | 2685 | } else { |
@@ -2700,25 +2700,25 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2700 | qDebug("FULLDATE 2"); | 2700 | qDebug("FULLDATE 2"); |
2701 | fullDateRange = true; | 2701 | fullDateRange = true; |
2702 | } | 2702 | } |
2703 | if ( ! fullDateRange ) { | 2703 | if ( ! fullDateRange ) { |
2704 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2704 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2705 | 2705 | ||
2706 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2706 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2707 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2707 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2708 | fullDateRange = true; | 2708 | fullDateRange = true; |
2709 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2709 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2710 | } | 2710 | } |
2711 | } | 2711 | } |
2712 | fullDateRange = true; // debug only! | 2712 | // fullDateRange = true; // debug only! |
2713 | if ( fullDateRange ) | 2713 | if ( fullDateRange ) |
2714 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2714 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2715 | else | 2715 | else |
2716 | mLastAddressbookSync = addresseeLSync.revision(); | 2716 | mLastAddressbookSync = addresseeLSync.revision(); |
2717 | // for resyncing if own file has changed | 2717 | // for resyncing if own file has changed |
2718 | // PENDING fixme later when implemented | 2718 | // PENDING fixme later when implemented |
2719 | #if 0 | 2719 | #if 0 |
2720 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2720 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2721 | mLastAddressbookSync = loadedFileVersion; | 2721 | mLastAddressbookSync = loadedFileVersion; |
2722 | qDebug("setting mLastAddressbookSync "); | 2722 | qDebug("setting mLastAddressbookSync "); |
2723 | } | 2723 | } |
2724 | #endif | 2724 | #endif |
@@ -2909,33 +2909,61 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2909 | } | 2909 | } |
2910 | 2910 | ||
2911 | bool KABCore::syncAB(QString filename, int mode) | 2911 | bool KABCore::syncAB(QString filename, int mode) |
2912 | { | 2912 | { |
2913 | 2913 | ||
2914 | //pending prepare addresseeview for output | 2914 | //pending prepare addresseeview for output |
2915 | //pending detect, if remote file has REV field. if not switch to external sync | 2915 | //pending detect, if remote file has REV field. if not switch to external sync |
2916 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2916 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2917 | AddressBook abLocal(filename,"syncContact"); | 2917 | AddressBook abLocal(filename,"syncContact"); |
2918 | bool syncOK = false; | 2918 | bool syncOK = false; |
2919 | if ( abLocal.load() ) { | 2919 | if ( abLocal.load() ) { |
2920 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); | 2920 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); |
2921 | AddressBook::Iterator it; | 2921 | 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 | |||
2939 | if ( external ) { | ||
2940 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | ||
2941 | AddressBook::Iterator it; | ||
2942 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2943 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | ||
2944 | (*it).computeCsum( mCurrentSyncDevice ); | ||
2945 | } | ||
2946 | } | ||
2947 | //AddressBook::Iterator it; | ||
2922 | //QStringList vcards; | 2948 | //QStringList vcards; |
2923 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2949 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2924 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2950 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2925 | //} | 2951 | //} |
2926 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2952 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2927 | if ( syncOK ) { | 2953 | if ( syncOK ) { |
2928 | if ( KABPrefs::instance()->mWriteBackFile ) | 2954 | if ( KABPrefs::instance()->mWriteBackFile ) |
2929 | { | 2955 | { |
2956 | if ( external ) | ||
2957 | abLocal.removeDeletedAddressees(); | ||
2930 | qDebug("saving remote AB "); | 2958 | qDebug("saving remote AB "); |
2931 | abLocal.saveAB(); | 2959 | abLocal.saveAB(); |
2932 | } | 2960 | } |
2933 | } | 2961 | } |
2934 | setModified(); | 2962 | setModified(); |
2935 | 2963 | ||
2936 | } | 2964 | } |
2937 | if ( syncOK ) | 2965 | if ( syncOK ) |
2938 | mViewManager->refreshView(); | 2966 | mViewManager->refreshView(); |
2939 | return syncOK; | 2967 | return syncOK; |
2940 | #if 0 | 2968 | #if 0 |
2941 | 2969 | ||