-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 | |||
@@ -2752,7 +2752,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
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 ); |
@@ -2768,18 +2768,24 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
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; |
@@ -2854,7 +2860,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
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 | } |
@@ -2919,47 +2925,76 @@ bool KABCore::syncAB(QString filename, int mode) | |||
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(); |