author | zautrix <zautrix> | 2004-09-19 20:27:44 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-19 20:27:44 (UTC) |
commit | 3da2cfeab2edbe64a17251662e56668fe143f7a3 (patch) (unidiff) | |
tree | 37e8d4445fca84bd4e93af38c96c5c489f9cbca8 /kaddressbook | |
parent | afa28a62314117555d6b32291188eedd1a576284 (diff) | |
download | kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.zip kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.tar.gz kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.tar.bz2 |
more AB sync
-rw-r--r-- | kaddressbook/kabcore.cpp | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index b3d88de..8f3ca9b 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2867,193 +2867,172 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2867 | } | 2867 | } |
2868 | } else { | 2868 | } else { |
2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2869 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2870 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2870 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2871 | local->removeAddressee( inL ); | 2871 | local->removeAddressee( inL ); |
2872 | ++deletedAddresseeL; | 2872 | ++deletedAddresseeL; |
2873 | } else { | 2873 | } else { |
2874 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { | 2874 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2875 | ++addedAddresseeR; | 2875 | ++addedAddresseeR; |
2876 | inL.setRevision( modifiedCalendar ); | 2876 | inL.setRevision( modifiedCalendar ); |
2877 | local->insertAddressee( inL, false ); | 2877 | local->insertAddressee( inL, false ); |
2878 | inR = inL; | 2878 | inR = inL; |
2879 | inR.setResource( 0 ); | 2879 | inR.setResource( 0 ); |
2880 | remote->insertAddressee( inR, false ); | 2880 | remote->insertAddressee( inR, false ); |
2881 | } | 2881 | } |
2882 | } | 2882 | } |
2883 | } | 2883 | } |
2884 | } | 2884 | } |
2885 | } | 2885 | } |
2886 | ++incCounter; | 2886 | ++incCounter; |
2887 | } | 2887 | } |
2888 | el.clear(); | 2888 | el.clear(); |
2889 | bar.hide(); | 2889 | bar.hide(); |
2890 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2890 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2891 | // get rid of micro seconds | 2891 | // get rid of micro seconds |
2892 | QTime t = mLastAddressbookSync.time(); | 2892 | QTime t = mLastAddressbookSync.time(); |
2893 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2893 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2894 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2894 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2895 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2895 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2896 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2896 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2897 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2897 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2898 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2898 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2899 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2899 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2900 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2900 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2901 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2901 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2902 | addresseeRSync.setNote( "" ) ; | 2902 | addresseeRSync.setNote( "" ) ; |
2903 | addresseeLSync.setNote( "" ); | 2903 | addresseeLSync.setNote( "" ); |
2904 | 2904 | ||
2905 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2905 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2906 | remote->insertAddressee( addresseeRSync, false ); | 2906 | remote->insertAddressee( addresseeRSync, false ); |
2907 | local->insertAddressee( addresseeLSync, false ); | 2907 | local->insertAddressee( addresseeLSync, false ); |
2908 | QString mes; | 2908 | QString mes; |
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 ); | 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 ); |
2910 | if ( KABPrefs::instance()->mShowSyncSummary ) { | 2910 | if ( KABPrefs::instance()->mShowSyncSummary ) { |
2911 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2911 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2912 | } | 2912 | } |
2913 | qDebug( mes ); | 2913 | qDebug( mes ); |
2914 | return syncOK; | 2914 | return syncOK; |
2915 | } | 2915 | } |
2916 | 2916 | ||
2917 | bool KABCore::syncAB(QString filename, int mode) | 2917 | bool KABCore::syncAB(QString filename, int mode) |
2918 | { | 2918 | { |
2919 | 2919 | ||
2920 | //pending prepare addresseeview for output | 2920 | //pending prepare addresseeview for output |
2921 | //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 |
2922 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2922 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2923 | AddressBook abLocal(filename,"syncContact"); | 2923 | AddressBook abLocal(filename,"syncContact"); |
2924 | bool syncOK = false; | 2924 | bool syncOK = false; |
2925 | if ( abLocal.load() ) { | 2925 | if ( abLocal.load() ) { |
2926 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2926 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2927 | bool external = false; | 2927 | bool external = false; |
2928 | 2928 | ||
2929 | if ( filename.right(4) == ".xml") { | 2929 | if ( filename.right(4) == ".xml") { |
2930 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2930 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2931 | AddressBook::Iterator it; | 2931 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2932 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | ||
2933 | (*it).setID( mCurrentSyncDevice, (*it).externalUID() ); | ||
2934 | (*it).computeCsum( mCurrentSyncDevice ); | ||
2935 | } | ||
2936 | abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); | ||
2937 | |||
2938 | } else { | 2932 | } else { |
2939 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2933 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2940 | if ( ! lse.isEmpty() ) { | 2934 | if ( ! lse.isEmpty() ) { |
2941 | if ( lse.familyName().left(4) == "!E: " ) | 2935 | if ( lse.familyName().left(4) == "!E: " ) |
2942 | external = true; | 2936 | external = true; |
2943 | } else { | 2937 | } else { |
2944 | bool found = false; | 2938 | bool found = false; |
2945 | QDateTime dt( QDate( 2004,1,1)); | 2939 | QDateTime dt( QDate( 2004,1,1)); |
2946 | AddressBook::Iterator it; | 2940 | AddressBook::Iterator it; |
2947 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2941 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2948 | if ( (*it).revision() != dt ) { | 2942 | if ( (*it).revision() != dt ) { |
2949 | found = true; | 2943 | found = true; |
2950 | break; | 2944 | break; |
2951 | } | 2945 | } |
2952 | } | 2946 | } |
2953 | external = ! found; | 2947 | external = ! found; |
2954 | } | 2948 | } |
2955 | 2949 | ||
2956 | if ( external ) { | 2950 | if ( external ) { |
2957 | qDebug("Setting vcf mode to external "); | 2951 | qDebug("Setting vcf mode to external "); |
2958 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2952 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2959 | AddressBook::Iterator it; | 2953 | AddressBook::Iterator it; |
2960 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2954 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2961 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2955 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2962 | (*it).computeCsum( mCurrentSyncDevice ); | 2956 | (*it).computeCsum( mCurrentSyncDevice ); |
2963 | } | 2957 | } |
2964 | } | 2958 | } |
2965 | } | 2959 | } |
2966 | //AddressBook::Iterator it; | 2960 | //AddressBook::Iterator it; |
2967 | //QStringList vcards; | 2961 | //QStringList vcards; |
2968 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2962 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2969 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2963 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2970 | //} | 2964 | //} |
2971 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2965 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2972 | if ( syncOK ) { | 2966 | if ( syncOK ) { |
2973 | if ( KABPrefs::instance()->mWriteBackFile ) | 2967 | if ( KABPrefs::instance()->mWriteBackFile ) |
2974 | { | 2968 | { |
2975 | if ( external && filename.right(4) != ".xml") | 2969 | if ( external && filename.right(4) != ".xml") |
2976 | abLocal.removeDeletedAddressees(); | 2970 | abLocal.removeDeletedAddressees(); |
2977 | qDebug("Saving remote AB "); | 2971 | qDebug("Saving remote AB "); |
2978 | abLocal.saveAB(); | 2972 | abLocal.saveAB(); |
2979 | if ( external && filename.right(4) == ".xml") { | 2973 | if ( external && filename.right(4) == ".xml") { |
2980 | // afterwrite processing | 2974 | // afterwrite processing |
2981 | AddressBook::Iterator it; | 2975 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
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 | } | 2976 | } |
2998 | } | 2977 | } |
2999 | } | 2978 | } |
3000 | setModified(); | 2979 | setModified(); |
3001 | 2980 | ||
3002 | } | 2981 | } |
3003 | if ( syncOK ) | 2982 | if ( syncOK ) |
3004 | mViewManager->refreshView(); | 2983 | mViewManager->refreshView(); |
3005 | return syncOK; | 2984 | return syncOK; |
3006 | #if 0 | 2985 | #if 0 |
3007 | 2986 | ||
3008 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2987 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
3009 | getEventViewerDialog()->setSyncMode( true ); | 2988 | getEventViewerDialog()->setSyncMode( true ); |
3010 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2989 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
3011 | getEventViewerDialog()->setSyncMode( false ); | 2990 | getEventViewerDialog()->setSyncMode( false ); |
3012 | if ( syncOK ) { | 2991 | if ( syncOK ) { |
3013 | if ( KOPrefs::instance()->mWriteBackFile ) | 2992 | if ( KOPrefs::instance()->mWriteBackFile ) |
3014 | { | 2993 | { |
3015 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2994 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
3016 | storage->save(); | 2995 | storage->save(); |
3017 | } | 2996 | } |
3018 | } | 2997 | } |
3019 | setModified(); | 2998 | setModified(); |
3020 | } | 2999 | } |
3021 | 3000 | ||
3022 | #endif | 3001 | #endif |
3023 | } | 3002 | } |
3024 | 3003 | ||
3025 | void KABCore::confSync() | 3004 | void KABCore::confSync() |
3026 | { | 3005 | { |
3027 | static KSyncPrefsDialog* sp = 0; | 3006 | static KSyncPrefsDialog* sp = 0; |
3028 | if ( ! sp ) { | 3007 | if ( ! sp ) { |
3029 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); | 3008 | sp = new KSyncPrefsDialog( this, "syncprefs", true ); |
3030 | } | 3009 | } |
3031 | sp->usrReadConfig(); | 3010 | sp->usrReadConfig(); |
3032 | #ifndef DESKTOP_VERSION | 3011 | #ifndef DESKTOP_VERSION |
3033 | sp->showMaximized(); | 3012 | sp->showMaximized(); |
3034 | #else | 3013 | #else |
3035 | sp->show(); | 3014 | sp->show(); |
3036 | #endif | 3015 | #endif |
3037 | sp->exec(); | 3016 | sp->exec(); |
3038 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); | 3017 | KABPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames(); |
3039 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); | 3018 | KABPrefs::instance()->mLocalMachineName = sp->getLocalMachineName (); |
3040 | fillSyncMenu(); | 3019 | fillSyncMenu(); |
3041 | } | 3020 | } |
3042 | void KABCore::syncSharp() | 3021 | void KABCore::syncSharp() |
3043 | { | 3022 | { |
3044 | if ( mModified ) | 3023 | if ( mModified ) |
3045 | save(); | 3024 | save(); |
3046 | qDebug("pending syncSharp() "); | 3025 | qDebug("pending syncSharp() "); |
3047 | //mView->syncSharp(); | 3026 | //mView->syncSharp(); |
3048 | setModified(); | 3027 | setModified(); |
3049 | 3028 | ||
3050 | } | 3029 | } |
3051 | void KABCore::syncPhone() | 3030 | void KABCore::syncPhone() |
3052 | { | 3031 | { |
3053 | if ( mModified ) | 3032 | if ( mModified ) |
3054 | save(); | 3033 | save(); |
3055 | qDebug("pending syncPhone(); "); | 3034 | qDebug("pending syncPhone(); "); |
3056 | //mView->syncPhone(); | 3035 | //mView->syncPhone(); |
3057 | setModified(); | 3036 | setModified(); |
3058 | 3037 | ||
3059 | } | 3038 | } |