summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-01-17 12:39:45 (UTC)
committer zautrix <zautrix>2005-01-17 12:39:45 (UTC)
commitba5e5a22ad492f798b2626026cc1838b731e055b (patch) (unidiff)
treef8bdea9f3a7542371b5be6e5a30ba533889a2075
parent6b166ece0a576e9be9c71a61fab5424d75a9301f (diff)
downloadkdepimpi-ba5e5a22ad492f798b2626026cc1838b731e055b.zip
kdepimpi-ba5e5a22ad492f798b2626026cc1838b731e055b.tar.gz
kdepimpi-ba5e5a22ad492f798b2626026cc1838b731e055b.tar.bz2
more AB fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp79
1 files changed, 42 insertions, 37 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index aa04631..a480baf 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2771,64 +2771,66 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i
2771 localIsNew = localMod >= remoteMod; 2771 localIsNew = localMod >= remoteMod;
2772 //qDebug("conflict! ************************************** "); 2772 //qDebug("conflict! ************************************** ");
2773 { 2773 {
2774 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2774 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2775 result = acd.executeD(localIsNew); 2775 result = acd.executeD(localIsNew);
2776 return result; 2776 return result;
2777 } 2777 }
2778 break; 2778 break;
2779 case SYNC_PREF_FORCE_LOCAL: 2779 case SYNC_PREF_FORCE_LOCAL:
2780 return 1; 2780 return 1;
2781 break; 2781 break;
2782 case SYNC_PREF_FORCE_REMOTE: 2782 case SYNC_PREF_FORCE_REMOTE:
2783 return 2; 2783 return 2;
2784 break; 2784 break;
2785 2785
2786 default: 2786 default:
2787 // SYNC_PREF_TAKE_BOTH not implemented 2787 // SYNC_PREF_TAKE_BOTH not implemented
2788 break; 2788 break;
2789 } 2789 }
2790 return 0; 2790 return 0;
2791} 2791}
2792 2792
2793 2793
2794bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2794bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2795{ 2795{
2796 bool syncOK = true; 2796 bool syncOK = true;
2797 int addedAddressee = 0; 2797 int addedAddressee = 0;
2798 int addedAddresseeR = 0; 2798 int addedAddresseeR = 0;
2799 int deletedAddresseeR = 0; 2799 int deletedAddresseeR = 0;
2800 int deletedAddresseeL = 0; 2800 int deletedAddresseeL = 0;
2801 int changedLocal = 0; 2801 int changedLocal = 0;
2802 int changedRemote = 0; 2802 int changedRemote = 0;
2803 int filteredIN = 0;
2804 int filteredOUT = 0;
2803 2805
2804 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2806 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2805 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2807 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2806 2808
2807 //QPtrList<Addressee> el = local->rawAddressees(); 2809 //QPtrList<Addressee> el = local->rawAddressees();
2808 Addressee addresseeR; 2810 Addressee addresseeR;
2809 QString uid; 2811 QString uid;
2810 int take; 2812 int take;
2811 Addressee addresseeL; 2813 Addressee addresseeL;
2812 Addressee addresseeRSync; 2814 Addressee addresseeRSync;
2813 Addressee addresseeLSync; 2815 Addressee addresseeLSync;
2814 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2816 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2815 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2817 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2816 bool fullDateRange = false; 2818 bool fullDateRange = false;
2817 local->resetTempSyncStat(); 2819 local->resetTempSyncStat();
2818 mLastAddressbookSync = QDateTime::currentDateTime(); 2820 mLastAddressbookSync = QDateTime::currentDateTime();
2819 if ( syncManager->syncWithDesktop() ) { 2821 if ( syncManager->syncWithDesktop() ) {
2820 // remote->removeSyncInfo( QString());//remove all info 2822 // remote->removeSyncInfo( QString());//remove all info
2821 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2823 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2822 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2824 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2823 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2825 qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2824 } else { 2826 } else {
2825 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); 2827 qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
2826 } 2828 }
2827 } 2829 }
2828 QDateTime modifiedCalendar = mLastAddressbookSync; 2830 QDateTime modifiedCalendar = mLastAddressbookSync;
2829 addresseeLSync = getLastSyncAddressee(); 2831 addresseeLSync = getLastSyncAddressee();
2830 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2832 qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1());
2831 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2833 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2832 if ( !addresseeR.isEmpty() ) { 2834 if ( !addresseeR.isEmpty() ) {
2833 addresseeRSync = addresseeR; 2835 addresseeRSync = addresseeR;
2834 remote->removeAddressee(addresseeR ); 2836 remote->removeAddressee(addresseeR );
@@ -2960,156 +2962,159 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2960 } else { // no conflict ********** add or delete remote 2962 } else { // no conflict ********** add or delete remote
2961 if ( filterIN.name().isEmpty() || filterIN.filterAddressee( inR ) ) { 2963 if ( filterIN.name().isEmpty() || filterIN.filterAddressee( inR ) ) {
2962 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2964 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2963 QString des = addresseeLSync.note(); 2965 QString des = addresseeLSync.note();
2964 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2966 if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2965 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2967 inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2966 remote->insertAddressee( inR, false ); 2968 remote->insertAddressee( inR, false );
2967 ++deletedAddresseeR; 2969 ++deletedAddresseeR;
2968 } else { 2970 } else {
2969 inR.setRevision( modifiedCalendar ); 2971 inR.setRevision( modifiedCalendar );
2970 remote->insertAddressee( inR, false ); 2972 remote->insertAddressee( inR, false );
2971 inL = inR; 2973 inL = inR;
2972 inL.setIDStr( ":" ); 2974 inL.setIDStr( ":" );
2973 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2975 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2974 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2976 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2975 inL.setResource( 0 ); 2977 inL.setResource( 0 );
2976 local->insertAddressee( inL , false); 2978 local->insertAddressee( inL , false);
2977 ++addedAddressee; 2979 ++addedAddressee;
2978 } 2980 }
2979 } else { 2981 } else {
2980 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { 2982 if ( inR.revision() > mLastAddressbookSync || mode == 5 ) {
2981 inR.setRevision( modifiedCalendar ); 2983 inR.setRevision( modifiedCalendar );
2982 remote->insertAddressee( inR, false ); 2984 remote->insertAddressee( inR, false );
2983 inR.setResource( 0 ); 2985 inR.setResource( 0 );
2984 local->insertAddressee( inR, false ); 2986 local->insertAddressee( inR, false );
2985 ++addedAddressee; 2987 ++addedAddressee;
2986 } else { 2988 } else {
2987 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); 2989 // pending checkExternSyncAddressee(addresseeRSyncSharp, inR);
2988 remote->removeAddressee( inR ); 2990 remote->removeAddressee( inR );
2989 ++deletedAddresseeR; 2991 ++deletedAddresseeR;
2990 } 2992 }
2991 } 2993 }
2994 } else {
2995 ++filteredIN;
2992 } 2996 }
2993 } 2997 }
2994 } 2998 }
2995 ++incCounter; 2999 ++incCounter;
2996 } 3000 }
2997 er.clear(); 3001 er.clear();
2998 QStringList el = local->uidList(); 3002 QStringList el = local->uidList();
2999 modulo = (el.count()/10)+1; 3003 modulo = (el.count()/10)+1;
3000 3004
3001 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); 3005 syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count());
3002 incCounter = 0; 3006 incCounter = 0;
3003 while ( incCounter < el.count()) { 3007 while ( incCounter < el.count()) {
3004 qApp->processEvents(); 3008 qApp->processEvents();
3005 if (syncManager->isProgressBarCanceled()) 3009 if (syncManager->isProgressBarCanceled())
3006 return false; 3010 return false;
3007 if ( incCounter % modulo == 0 ) 3011 if ( incCounter % modulo == 0 )
3008 syncManager->showProgressBar(incCounter); 3012 syncManager->showProgressBar(incCounter);
3009 uid = el[ incCounter ]; 3013 uid = el[ incCounter ];
3010 bool skipIncidence = false; 3014 bool skipIncidence = false;
3011 if ( uid.left(19) == QString("last-syncAddressee-") ) 3015 if ( uid.left(19) == QString("last-syncAddressee-") )
3012 skipIncidence = true; 3016 skipIncidence = true;
3013 if ( ! skipIncidence ) {
3014 inL = local->findByUid( uid );
3015 if ( (!filterOUT.name().isEmpty()) && (! filterOUT.filterAddressee( inL ) ) )
3016 skipIncidence = true;
3017 }
3018 if ( !skipIncidence ) { 3017 if ( !skipIncidence ) {
3018 inL = local->findByUid( uid );
3019 if ( !inL.resource() || inL.resource()->includeInSync() ) { 3019 if ( !inL.resource() || inL.resource()->includeInSync() ) {
3020 inR = remote->findByUid( uid ); 3020 inR = remote->findByUid( uid );
3021 if ( inR.isEmpty() ) { // no conflict ********** add or delete local 3021 if ( inR.isEmpty() ){
3022 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 3022 if ( filterOUT.name().isEmpty() || filterOUT.filterAddressee( inL ) ) {
3023 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 3023 // no conflict ********** add or delete local
3024 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); 3024 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
3025 local->removeAddressee( inL ); 3025 if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
3026 ++deletedAddresseeL; 3026 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3027 } else { 3027 local->removeAddressee( inL );
3028 if ( ! syncManager->mWriteBackExistingOnly ) { 3028 ++deletedAddresseeL;
3029 inL.removeID(mCurrentSyncDevice ); 3029 } else {
3030 ++addedAddresseeR; 3030 if ( ! syncManager->mWriteBackExistingOnly ) {
3031 inL.setRevision( modifiedCalendar ); 3031 inL.removeID(mCurrentSyncDevice );
3032 local->insertAddressee( inL, false ); 3032 ++addedAddresseeR;
3033 inR = inL; 3033 inL.setRevision( modifiedCalendar );
3034 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); 3034 local->insertAddressee( inL, false );
3035 inR.setResource( 0 ); 3035 inR = inL;
3036 remote->insertAddressee( inR, false ); 3036 inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL );
3037 inR.setResource( 0 );
3038 remote->insertAddressee( inR, false );
3039 }
3037 } 3040 }
3038 }
3039 } else {
3040 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
3041 //qDebug("data %s ", inL.revision().toString().latin1());
3042 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3043 local->removeAddressee( inL );
3044 ++deletedAddresseeL;
3045 } else { 3041 } else {
3046 if ( ! syncManager->mWriteBackExistingOnly ) { 3042 if ( inL.revision() < mLastAddressbookSync && mode != 4 ) {
3047 ++addedAddresseeR; 3043 //qDebug("data %s ", inL.revision().toString().latin1());
3048 inL.setRevision( modifiedCalendar ); 3044 // pending checkExternSyncAddressee(addresseeLSyncSharp, inL);
3049 local->insertAddressee( inL, false ); 3045 local->removeAddressee( inL );
3050 inR = inL; 3046 ++deletedAddresseeL;
3051 inR.setIDStr( ":" ); 3047 } else {
3052 inR.setResource( 0 ); 3048 if ( ! syncManager->mWriteBackExistingOnly ) {
3053 remote->insertAddressee( inR, false ); 3049 ++addedAddresseeR;
3050 inL.setRevision( modifiedCalendar );
3051 local->insertAddressee( inL, false );
3052 inR = inL;
3053 inR.setIDStr( ":" );
3054 inR.setResource( 0 );
3055 remote->insertAddressee( inR, false );
3056 }
3054 } 3057 }
3055 } 3058 }
3059 } else {
3060 ++filteredOUT;
3056 } 3061 }
3057 } 3062 }
3058 } 3063 }
3059 } 3064 }
3060 ++incCounter; 3065 ++incCounter;
3061 } 3066 }
3062 el.clear(); 3067 el.clear();
3063 syncManager->hideProgressBar(); 3068 syncManager->hideProgressBar();
3064 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); 3069 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
3065 // get rid of micro seconds 3070 // get rid of micro seconds
3066 QTime t = mLastAddressbookSync.time(); 3071 QTime t = mLastAddressbookSync.time();
3067 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 3072 mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) );
3068 addresseeLSync.setRevision( mLastAddressbookSync ); 3073 addresseeLSync.setRevision( mLastAddressbookSync );
3069 addresseeRSync.setRevision( mLastAddressbookSync ); 3074 addresseeRSync.setRevision( mLastAddressbookSync );
3070 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; 3075 addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ;
3071 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); 3076 addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName );
3072 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; 3077 addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ;
3073 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); 3078 addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") );
3074 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; 3079 addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ;
3075 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); 3080 addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() );
3076 addresseeRSync.setNote( "" ) ; 3081 addresseeRSync.setNote( "" ) ;
3077 addresseeLSync.setNote( "" ); 3082 addresseeLSync.setNote( "" );
3078 3083
3079 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 3084 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
3080 remote->insertAddressee( addresseeRSync, false ); 3085 remote->insertAddressee( addresseeRSync, false );
3081 local->insertAddressee( addresseeLSync, false ); 3086 local->insertAddressee( addresseeLSync, false );
3082 QString mes; 3087 QString mes;
3083 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 ); 3088 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 %d incoming filtered out\n %d outgoing filtered out"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR, filteredIN, filteredOUT );
3084 qDebug( mes ); 3089 qDebug( mes );
3085 mes = i18n("Local addressbook changed!\n") +mes; 3090 mes = i18n("Local addressbook changed!\n") +mes;
3086 if ( syncManager->mShowSyncSummary ) { 3091 if ( syncManager->mShowSyncSummary ) {
3087 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes, 3092 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(this, mes,
3088 i18n("KA/Pi Synchronization"),i18n("Write back"))) { 3093 i18n("KA/Pi Synchronization"),i18n("Write back"))) {
3089 qDebug("cancelled "); 3094 qDebug("cancelled ");
3090 return false; 3095 return false;
3091 } 3096 }
3092 } 3097 }
3093 return syncOK; 3098 return syncOK;
3094} 3099}
3095 3100
3096 3101
3097//this is a overwritten callbackmethods from the syncinterface 3102//this is a overwritten callbackmethods from the syncinterface
3098bool KABCore::sync(KSyncManager* manager, QString filename, int mode) 3103bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
3099{ 3104{
3100 3105
3101 //pending prepare addresseeview for output 3106 //pending prepare addresseeview for output
3102 //pending detect, if remote file has REV field. if not switch to external sync 3107 //pending detect, if remote file has REV field. if not switch to external sync
3103 mGlobalSyncMode = SYNC_MODE_NORMAL; 3108 mGlobalSyncMode = SYNC_MODE_NORMAL;
3104 if ( manager != syncManager ) 3109 if ( manager != syncManager )
3105 qDebug("KABCore::sync:: ERROR! :: manager != syncManager "); 3110 qDebug("KABCore::sync:: ERROR! :: manager != syncManager ");
3106 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3111 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3107 3112
3108 AddressBook abLocal(filename,"syncContact"); 3113 AddressBook abLocal(filename,"syncContact");
3109 bool syncOK = false; 3114 bool syncOK = false;
3110 if ( abLocal.load() ) { 3115 if ( abLocal.load() ) {
3111 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); 3116 qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode );
3112 bool external = false; 3117 bool external = false;
3113 bool isXML = false; 3118 bool isXML = false;
3114 if ( filename.right(4) == ".xml") { 3119 if ( filename.right(4) == ".xml") {
3115 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3120 mGlobalSyncMode = SYNC_MODE_EXTERNAL;