summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index eba74a6..20b107e 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2775,206 +2775,208 @@ KABC::Addressee KABCore::getLastSyncAddressee()
2775 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2775 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2776 sum = "E: "; 2776 sum = "E: ";
2777 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2777 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2778 lse.setRevision( mLastAddressbookSync ); 2778 lse.setRevision( mLastAddressbookSync );
2779 lse.setCategories( i18n("SyncEvent") ); 2779 lse.setCategories( i18n("SyncEvent") );
2780 mAddressBook->insertAddressee( lse ); 2780 mAddressBook->insertAddressee( lse );
2781 } 2781 }
2782 return lse; 2782 return lse;
2783} 2783}
2784int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2784int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2785{ 2785{
2786 2786
2787 //void setZaurusId(int id); 2787 //void setZaurusId(int id);
2788 // int zaurusId() const; 2788 // int zaurusId() const;
2789 // void setZaurusUid(int id); 2789 // void setZaurusUid(int id);
2790 // int zaurusUid() const; 2790 // int zaurusUid() const;
2791 // void setZaurusStat(int id); 2791 // void setZaurusStat(int id);
2792 // int zaurusStat() const; 2792 // int zaurusStat() const;
2793 // 0 equal 2793 // 0 equal
2794 // 1 take local 2794 // 1 take local
2795 // 2 take remote 2795 // 2 take remote
2796 // 3 cancel 2796 // 3 cancel
2797 QDateTime lastSync = mLastAddressbookSync; 2797 QDateTime lastSync = mLastAddressbookSync;
2798 QDateTime localMod = local->revision(); 2798 QDateTime localMod = local->revision();
2799 QDateTime remoteMod = remote->revision(); 2799 QDateTime remoteMod = remote->revision();
2800 2800
2801 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2801 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2802 2802
2803 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2803 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2804 bool remCh, locCh; 2804 bool remCh, locCh;
2805 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2805 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2806 //if ( remCh ) 2806 //if ( remCh )
2807 // qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2807 // qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2808 locCh = ( localMod > mLastAddressbookSync ); 2808 locCh = ( localMod > mLastAddressbookSync );
2809 //qDebug("cahnged rem %d loc %d",remCh, locCh ); 2809 //qDebug("cahnged rem %d loc %d",remCh, locCh );
2810 if ( !remCh && ! locCh ) { 2810 if ( !remCh && ! locCh ) {
2811 //qDebug("both not changed "); 2811 //qDebug("both not changed ");
2812 lastSync = localMod.addDays(1); 2812 lastSync = localMod.addDays(1);
2813 if ( mode <= SYNC_PREF_ASK ) 2813 if ( mode <= SYNC_PREF_ASK )
2814 return 0; 2814 return 0;
2815 } else { 2815 } else {
2816 if ( locCh ) { 2816 if ( locCh ) {
2817 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2817 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2818 lastSync = localMod.addDays( -1 ); 2818 lastSync = localMod.addDays( -1 );
2819 if ( !remCh ) 2819 if ( !remCh )
2820 remoteMod =( lastSync.addDays( -1 ) ); 2820 remoteMod =( lastSync.addDays( -1 ) );
2821 } else { 2821 } else {
2822 //qDebug(" not loc changed "); 2822 //qDebug(" not loc changed ");
2823 lastSync = localMod.addDays( 1 ); 2823 lastSync = localMod.addDays( 1 );
2824 if ( remCh ) { 2824 if ( remCh ) {
2825 //qDebug("rem changed "); 2825 //qDebug("rem changed ");
2826 remoteMod =( lastSync.addDays( 1 ) ); 2826 remoteMod =( lastSync.addDays( 1 ) );
2827 } 2827 }
2828 2828
2829 } 2829 }
2830 } 2830 }
2831 full = true; 2831 full = true;
2832 if ( mode < SYNC_PREF_ASK ) 2832 if ( mode < SYNC_PREF_ASK )
2833 mode = SYNC_PREF_ASK; 2833 mode = SYNC_PREF_ASK;
2834 } else { 2834 } else {
2835 if ( localMod == remoteMod ) 2835 if ( localMod == remoteMod )
2836 return 0; 2836 return 0;
2837 2837
2838 } 2838 }
2839 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); 2839 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
2840 //qDebug("lastsync %s ", lastSync.toString().latin1() ); 2840 //qDebug("lastsync %s ", lastSync.toString().latin1() );
2841 //full = true; //debug only 2841 //full = true; //debug only
2842 if ( full ) { 2842 if ( full ) {
2843 bool equ = ( (*local) == (*remote) ); 2843 bool equ = ( (*local) == (*remote) );
2844 if ( equ ) { 2844 if ( equ ) {
2845 //qDebug("equal "); 2845 //qDebug("equal ");
2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2846 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2847 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2847 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2848 } 2848 }
2849 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2849 if ( mode < SYNC_PREF_FORCE_LOCAL )
2850 return 0; 2850 return 0;
2851 2851
2852 }//else //debug only 2852 }//else //debug only
2853 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2853 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2854 } 2854 }
2855 int result; 2855 int result;
2856 bool localIsNew; 2856 bool localIsNew;
2857 //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() ); 2857 //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() );
2858 2858
2859 if ( full && mode < SYNC_PREF_NEWEST ) 2859 if ( full && mode < SYNC_PREF_NEWEST )
2860 mode = SYNC_PREF_ASK; 2860 mode = SYNC_PREF_ASK;
2861 2861
2862 switch( mode ) { 2862 switch( mode ) {
2863 case SYNC_PREF_LOCAL: 2863 case SYNC_PREF_LOCAL:
2864 if ( lastSync > remoteMod ) 2864 if ( lastSync > remoteMod )
2865 return 1; 2865 return 1;
2866 if ( lastSync > localMod ) 2866 if ( lastSync > localMod )
2867 return 2; 2867 return 2;
2868 return 1; 2868 return 1;
2869 break; 2869 break;
2870 case SYNC_PREF_REMOTE: 2870 case SYNC_PREF_REMOTE:
2871 if ( lastSync > remoteMod )
2872 return 1;
2873 if ( lastSync > localMod ) 2871 if ( lastSync > localMod )
2874 return 2; 2872 return 2;
2873 if ( lastSync > remoteMod )
2874 return 1;
2875 return 2; 2875 return 2;
2876 break; 2876 break;
2877 case SYNC_PREF_NEWEST: 2877 case SYNC_PREF_NEWEST:
2878 if ( localMod > remoteMod ) 2878 if ( localMod > remoteMod )
2879 return 1; 2879 return 1;
2880 else 2880 else
2881 return 2; 2881 return 2;
2882 break; 2882 break;
2883 case SYNC_PREF_ASK: 2883 case SYNC_PREF_ASK:
2884 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2884 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2885 if ( lastSync > remoteMod && lastSync > localMod)
2886 return 0;
2885 if ( lastSync > remoteMod ) 2887 if ( lastSync > remoteMod )
2886 return 1; 2888 return 1;
2887 if ( lastSync > localMod ) { 2889 if ( lastSync > localMod ) {
2888 return 2; 2890 return 2;
2889 } 2891 }
2890 localIsNew = localMod >= remoteMod; 2892 localIsNew = localMod >= remoteMod;
2891 //qDebug("conflict! ************************************** "); 2893 //qDebug("conflict! ************************************** ");
2892 { 2894 {
2893 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this ); 2895 KABC::AddresseeChooser acd ( *local,*remote, localIsNew , this );
2894 result = acd.executeD(localIsNew); 2896 result = acd.executeD(localIsNew);
2895 return result; 2897 return result;
2896 } 2898 }
2897 break; 2899 break;
2898 case SYNC_PREF_FORCE_LOCAL: 2900 case SYNC_PREF_FORCE_LOCAL:
2899 return 1; 2901 return 1;
2900 break; 2902 break;
2901 case SYNC_PREF_FORCE_REMOTE: 2903 case SYNC_PREF_FORCE_REMOTE:
2902 return 2; 2904 return 2;
2903 break; 2905 break;
2904 2906
2905 default: 2907 default:
2906 // SYNC_PREF_TAKE_BOTH not implemented 2908 // SYNC_PREF_TAKE_BOTH not implemented
2907 break; 2909 break;
2908 } 2910 }
2909 return 0; 2911 return 0;
2910} 2912}
2911 2913
2912 2914
2913bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2915bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2914{ 2916{
2915 bool syncOK = true; 2917 bool syncOK = true;
2916 int addedAddressee = 0; 2918 int addedAddressee = 0;
2917 int addedAddresseeR = 0; 2919 int addedAddresseeR = 0;
2918 int deletedAddresseeR = 0; 2920 int deletedAddresseeR = 0;
2919 int deletedAddresseeL = 0; 2921 int deletedAddresseeL = 0;
2920 int changedLocal = 0; 2922 int changedLocal = 0;
2921 int changedRemote = 0; 2923 int changedRemote = 0;
2922 int filteredIN = 0; 2924 int filteredIN = 0;
2923 int filteredOUT = 0; 2925 int filteredOUT = 0;
2924 2926
2925 QString mCurrentSyncName = syncManager->getCurrentSyncName(); 2927 QString mCurrentSyncName = syncManager->getCurrentSyncName();
2926 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2928 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2927 2929
2928 //QPtrList<Addressee> el = local->rawAddressees(); 2930 //QPtrList<Addressee> el = local->rawAddressees();
2929 Addressee addresseeR; 2931 Addressee addresseeR;
2930 QString uid; 2932 QString uid;
2931 int take; 2933 int take;
2932 Addressee addresseeL; 2934 Addressee addresseeL;
2933 Addressee addresseeRSync; 2935 Addressee addresseeRSync;
2934 Addressee addresseeLSync; 2936 Addressee addresseeLSync;
2935 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2937 // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2936 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2938 //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2937 bool fullDateRange = false; 2939 bool fullDateRange = false;
2938 local->resetTempSyncStat(); 2940 local->resetTempSyncStat();
2939 mLastAddressbookSync = QDateTime::currentDateTime(); 2941 mLastAddressbookSync = QDateTime::currentDateTime();
2940 if ( syncManager->syncWithDesktop() ) { 2942 if ( syncManager->syncWithDesktop() ) {
2941 // remote->removeSyncInfo( QString());//remove all info 2943 // remote->removeSyncInfo( QString());//remove all info
2942 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 2944 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
2943 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; 2945 mLastAddressbookSync = KSyncManager::mRequestedSyncEvent;
2944 qDebug("KA: using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); 2946 qDebug("KA: using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() );
2945 } else { 2947 } else {
2946 qDebug("KA: KSyncManager::mRequestedSyncEvent has invalid datatime "); 2948 qDebug("KA: KSyncManager::mRequestedSyncEvent has invalid datatime ");
2947 } 2949 }
2948 } 2950 }
2949 QDateTime modifiedCalendar = mLastAddressbookSync; 2951 QDateTime modifiedCalendar = mLastAddressbookSync;
2950 addresseeLSync = getLastSyncAddressee(); 2952 addresseeLSync = getLastSyncAddressee();
2951 qDebug("KA: Last Sync %s ", addresseeLSync.revision().toString().latin1()); 2953 qDebug("KA: Last Sync %s ", addresseeLSync.revision().toString().latin1());
2952 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); 2954 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2953 if ( !addresseeR.isEmpty() ) { 2955 if ( !addresseeR.isEmpty() ) {
2954 addresseeRSync = addresseeR; 2956 addresseeRSync = addresseeR;
2955 remote->removeAddressee(addresseeR ); 2957 remote->removeAddressee(addresseeR );
2956 2958
2957 } else { 2959 } else {
2958 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2960 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2959 addresseeRSync = addresseeLSync ; 2961 addresseeRSync = addresseeLSync ;
2960 } else { 2962 } else {
2961 //qDebug("FULLDATE 1"); 2963 //qDebug("FULLDATE 1");
2962 fullDateRange = true; 2964 fullDateRange = true;
2963 Addressee newAdd; 2965 Addressee newAdd;
2964 addresseeRSync = newAdd; 2966 addresseeRSync = newAdd;
2965 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2967 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2966 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2968 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2967 addresseeRSync.setRevision( mLastAddressbookSync ); 2969 addresseeRSync.setRevision( mLastAddressbookSync );
2968 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2970 addresseeRSync.setCategories( i18n("SyncAddressee") );
2969 } 2971 }
2970 } 2972 }
2971 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2973 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2972 // qDebug("FULLDATE 2"); 2974 // qDebug("FULLDATE 2");
2973 fullDateRange = true; 2975 fullDateRange = true;
2974 } 2976 }
2975 if ( ! fullDateRange ) { 2977 if ( ! fullDateRange ) {
2976 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2978 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2977 2979
2978 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2980 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2979 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2981 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2980 fullDateRange = true; 2982 fullDateRange = true;