summaryrefslogtreecommitdiffabout
path: root/kaddressbook
Unidiff
Diffstat (limited to 'kaddressbook') (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
@@ -2611,661 +2611,666 @@ void KABCore::requestForDetails(const QString& sourceChannel, const QString& ses
2611 mViewManager->refreshView( "" ); 2611 mViewManager->refreshView( "" );
2612 mViewManager->setSelected( foundUid, true ); 2612 mViewManager->setSelected( foundUid, true );
2613 mViewManager->refreshView( foundUid ); 2613 mViewManager->refreshView( foundUid );
2614 2614
2615 if ( !mMultipleViewsAtOnce ) 2615 if ( !mMultipleViewsAtOnce )
2616 { 2616 {
2617 setDetailsVisible( true ); 2617 setDetailsVisible( true );
2618 mActionDetails->setChecked(true); 2618 mActionDetails->setChecked(true);
2619 } 2619 }
2620 } 2620 }
2621} 2621}
2622 2622
2623void KABCore::whatsnew() 2623void KABCore::whatsnew()
2624{ 2624{
2625 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" ); 2625 KApplication::showFile( "KDE-Pim/Pi Version Info", "kdepim/WhatsNew.txt" );
2626} 2626}
2627void KABCore::synchowto() 2627void KABCore::synchowto()
2628{ 2628{
2629 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" ); 2629 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/SyncHowto.txt" );
2630} 2630}
2631void KABCore::kdesynchowto() 2631void KABCore::kdesynchowto()
2632{ 2632{
2633 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" ); 2633 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/Zaurus-KDE_syncHowTo.txt" );
2634} 2634}
2635void KABCore::multisynchowto() 2635void KABCore::multisynchowto()
2636{ 2636{
2637 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" ); 2637 KApplication::showFile( "KDE-Pim/Pi Synchronization HowTo", "kdepim/MultiSyncHowTo.txt" );
2638} 2638}
2639void KABCore::faq() 2639void KABCore::faq()
2640{ 2640{
2641 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); 2641 KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" );
2642} 2642}
2643 2643
2644#include <libkcal/syncdefines.h> 2644#include <libkcal/syncdefines.h>
2645 2645
2646KABC::Addressee KABCore::getLastSyncAddressee() 2646KABC::Addressee KABCore::getLastSyncAddressee()
2647{ 2647{
2648 Addressee lse; 2648 Addressee lse;
2649 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2649 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2650 2650
2651 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 2651 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2652 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2652 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2653 if (lse.isEmpty()) { 2653 if (lse.isEmpty()) {
2654 qDebug("Creating new last-syncAddressee "); 2654 qDebug("Creating new last-syncAddressee ");
2655 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); 2655 lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice );
2656 QString sum = ""; 2656 QString sum = "";
2657 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) 2657 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
2658 sum = "E: "; 2658 sum = "E: ";
2659 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); 2659 lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event"));
2660 lse.setRevision( mLastAddressbookSync ); 2660 lse.setRevision( mLastAddressbookSync );
2661 lse.setCategories( i18n("SyncEvent") ); 2661 lse.setCategories( i18n("SyncEvent") );
2662 mAddressBook->insertAddressee( lse ); 2662 mAddressBook->insertAddressee( lse );
2663 } 2663 }
2664 return lse; 2664 return lse;
2665} 2665}
2666int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) 2666int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full )
2667{ 2667{
2668 2668
2669 //void setZaurusId(int id); 2669 //void setZaurusId(int id);
2670 // int zaurusId() const; 2670 // int zaurusId() const;
2671 // void setZaurusUid(int id); 2671 // void setZaurusUid(int id);
2672 // int zaurusUid() const; 2672 // int zaurusUid() const;
2673 // void setZaurusStat(int id); 2673 // void setZaurusStat(int id);
2674 // int zaurusStat() const; 2674 // int zaurusStat() const;
2675 // 0 equal 2675 // 0 equal
2676 // 1 take local 2676 // 1 take local
2677 // 2 take remote 2677 // 2 take remote
2678 // 3 cancel 2678 // 3 cancel
2679 QDateTime lastSync = mLastAddressbookSync; 2679 QDateTime lastSync = mLastAddressbookSync;
2680 QDateTime localMod = local->revision(); 2680 QDateTime localMod = local->revision();
2681 QDateTime remoteMod = remote->revision(); 2681 QDateTime remoteMod = remote->revision();
2682 2682
2683 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 2683 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
2684 2684
2685 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2685 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2686 bool remCh, locCh; 2686 bool remCh, locCh;
2687 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); 2687 remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
2688 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); 2688 //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
2689 locCh = ( localMod > mLastAddressbookSync ); 2689 locCh = ( localMod > mLastAddressbookSync );
2690 //qDebug("cahnged rem %d loc %d",remCh, locCh ); 2690 //qDebug("cahnged rem %d loc %d",remCh, locCh );
2691 if ( !remCh && ! locCh ) { 2691 if ( !remCh && ! locCh ) {
2692 //qDebug("both not changed "); 2692 //qDebug("both not changed ");
2693 lastSync = localMod.addDays(1); 2693 lastSync = localMod.addDays(1);
2694 if ( mode <= SYNC_PREF_ASK ) 2694 if ( mode <= SYNC_PREF_ASK )
2695 return 0; 2695 return 0;
2696 } else { 2696 } else {
2697 if ( locCh ) { 2697 if ( locCh ) {
2698 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); 2698 //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1());
2699 lastSync = localMod.addDays( -1 ); 2699 lastSync = localMod.addDays( -1 );
2700 if ( !remCh ) 2700 if ( !remCh )
2701 remoteMod =( lastSync.addDays( -1 ) ); 2701 remoteMod =( lastSync.addDays( -1 ) );
2702 } else { 2702 } else {
2703 //qDebug(" not loc changed "); 2703 //qDebug(" not loc changed ");
2704 lastSync = localMod.addDays( 1 ); 2704 lastSync = localMod.addDays( 1 );
2705 if ( remCh ) { 2705 if ( remCh ) {
2706 //qDebug("rem changed "); 2706 //qDebug("rem changed ");
2707 remoteMod =( lastSync.addDays( 1 ) ); 2707 remoteMod =( lastSync.addDays( 1 ) );
2708 } 2708 }
2709 2709
2710 } 2710 }
2711 } 2711 }
2712 full = true; 2712 full = true;
2713 if ( mode < SYNC_PREF_ASK ) 2713 if ( mode < SYNC_PREF_ASK )
2714 mode = SYNC_PREF_ASK; 2714 mode = SYNC_PREF_ASK;
2715 } else { 2715 } else {
2716 if ( localMod == remoteMod ) 2716 if ( localMod == remoteMod )
2717 return 0; 2717 return 0;
2718 2718
2719 } 2719 }
2720 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec()); 2720 //qDebug("%s %s --- %d %d", localMod.toString().latin1() , remoteMod.toString().latin1(), localMod.time().msec(), remoteMod.time().msec());
2721 //qDebug("lastsync %s ", lastSync.toString().latin1() ); 2721 //qDebug("lastsync %s ", lastSync.toString().latin1() );
2722 //full = true; //debug only 2722 //full = true; //debug only
2723 if ( full ) { 2723 if ( full ) {
2724 bool equ = ( (*local) == (*remote) ); 2724 bool equ = ( (*local) == (*remote) );
2725 if ( equ ) { 2725 if ( equ ) {
2726 //qDebug("equal "); 2726 //qDebug("equal ");
2727 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2727 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2728 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); 2728 local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
2729 } 2729 }
2730 if ( mode < SYNC_PREF_FORCE_LOCAL ) 2730 if ( mode < SYNC_PREF_FORCE_LOCAL )
2731 return 0; 2731 return 0;
2732 2732
2733 }//else //debug only 2733 }//else //debug only
2734 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); 2734 //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
2735 } 2735 }
2736 int result; 2736 int result;
2737 bool localIsNew; 2737 bool localIsNew;
2738 //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() ); 2738 //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() );
2739 2739
2740 if ( full && mode < SYNC_PREF_NEWEST ) 2740 if ( full && mode < SYNC_PREF_NEWEST )
2741 mode = SYNC_PREF_ASK; 2741 mode = SYNC_PREF_ASK;
2742 2742
2743 switch( mode ) { 2743 switch( mode ) {
2744 case SYNC_PREF_LOCAL: 2744 case SYNC_PREF_LOCAL:
2745 if ( lastSync > remoteMod ) 2745 if ( lastSync > remoteMod )
2746 return 1; 2746 return 1;
2747 if ( lastSync > localMod ) 2747 if ( lastSync > localMod )
2748 return 2; 2748 return 2;
2749 return 1; 2749 return 1;
2750 break; 2750 break;
2751 case SYNC_PREF_REMOTE: 2751 case SYNC_PREF_REMOTE:
2752 if ( lastSync > remoteMod ) 2752 if ( lastSync > remoteMod )
2753 return 1; 2753 return 1;
2754 if ( lastSync > localMod ) 2754 if ( lastSync > localMod )
2755 return 2; 2755 return 2;
2756 return 2; 2756 return 2;
2757 break; 2757 break;
2758 case SYNC_PREF_NEWEST: 2758 case SYNC_PREF_NEWEST:
2759 if ( localMod > remoteMod ) 2759 if ( localMod > remoteMod )
2760 return 1; 2760 return 1;
2761 else 2761 else
2762 return 2; 2762 return 2;
2763 break; 2763 break;
2764 case SYNC_PREF_ASK: 2764 case SYNC_PREF_ASK:
2765 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); 2765 //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
2766 if ( lastSync > remoteMod ) 2766 if ( lastSync > remoteMod )
2767 return 1; 2767 return 1;
2768 if ( lastSync > localMod ) { 2768 if ( lastSync > localMod ) {
2769 return 2; 2769 return 2;
2770 } 2770 }
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 );
2835 2837
2836 } else { 2838 } else {
2837 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2839 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2838 addresseeRSync = addresseeLSync ; 2840 addresseeRSync = addresseeLSync ;
2839 } else { 2841 } else {
2840 //qDebug("FULLDATE 1"); 2842 //qDebug("FULLDATE 1");
2841 fullDateRange = true; 2843 fullDateRange = true;
2842 Addressee newAdd; 2844 Addressee newAdd;
2843 addresseeRSync = newAdd; 2845 addresseeRSync = newAdd;
2844 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); 2846 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2845 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); 2847 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2846 addresseeRSync.setRevision( mLastAddressbookSync ); 2848 addresseeRSync.setRevision( mLastAddressbookSync );
2847 addresseeRSync.setCategories( i18n("SyncAddressee") ); 2849 addresseeRSync.setCategories( i18n("SyncAddressee") );
2848 } 2850 }
2849 } 2851 }
2850 if ( addresseeLSync.revision() == mLastAddressbookSync ) { 2852 if ( addresseeLSync.revision() == mLastAddressbookSync ) {
2851 // qDebug("FULLDATE 2"); 2853 // qDebug("FULLDATE 2");
2852 fullDateRange = true; 2854 fullDateRange = true;
2853 } 2855 }
2854 if ( ! fullDateRange ) { 2856 if ( ! fullDateRange ) {
2855 if ( addresseeLSync.revision() != addresseeRSync.revision() ) { 2857 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2856 2858
2857 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2859 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2858 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2860 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2859 fullDateRange = true; 2861 fullDateRange = true;
2860 //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); 2862 //qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() );
2861 } 2863 }
2862 } 2864 }
2863 // fullDateRange = true; // debug only! 2865 // fullDateRange = true; // debug only!
2864 if ( fullDateRange ) 2866 if ( fullDateRange )
2865 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); 2867 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2866 else 2868 else
2867 mLastAddressbookSync = addresseeLSync.revision(); 2869 mLastAddressbookSync = addresseeLSync.revision();
2868 // for resyncing if own file has changed 2870 // for resyncing if own file has changed
2869 // PENDING fixme later when implemented 2871 // PENDING fixme later when implemented
2870#if 0 2872#if 0
2871 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2873 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2872 mLastAddressbookSync = loadedFileVersion; 2874 mLastAddressbookSync = loadedFileVersion;
2873 qDebug("setting mLastAddressbookSync "); 2875 qDebug("setting mLastAddressbookSync ");
2874 } 2876 }
2875#endif 2877#endif
2876 2878
2877 2879
2878 // ********** setting filters **************** 2880 // ********** setting filters ****************
2879 Filter filterIN = mViewManager->getFilterByName( syncManager->mFilterInAB ); 2881 Filter filterIN = mViewManager->getFilterByName( syncManager->mFilterInAB );
2880 Filter filterOUT = mViewManager->getFilterByName( syncManager->mFilterOutAB ); 2882 Filter filterOUT = mViewManager->getFilterByName( syncManager->mFilterOutAB );
2881 2883
2882 //qDebug("*************************** "); 2884 //qDebug("*************************** ");
2883 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); 2885 // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2884 QStringList er = remote->uidList(); 2886 QStringList er = remote->uidList();
2885 Addressee inR ;//= er.first(); 2887 Addressee inR ;//= er.first();
2886 Addressee inL; 2888 Addressee inL;
2887 2889
2888 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); 2890 syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count());
2889 2891
2890 int modulo = (er.count()/10)+1; 2892 int modulo = (er.count()/10)+1;
2891 int incCounter = 0; 2893 int incCounter = 0;
2892 while ( incCounter < er.count()) { 2894 while ( incCounter < er.count()) {
2893 if (syncManager->isProgressBarCanceled()) 2895 if (syncManager->isProgressBarCanceled())
2894 return false; 2896 return false;
2895 if ( incCounter % modulo == 0 ) 2897 if ( incCounter % modulo == 0 )
2896 syncManager->showProgressBar(incCounter); 2898 syncManager->showProgressBar(incCounter);
2897 2899
2898 uid = er[ incCounter ]; 2900 uid = er[ incCounter ];
2899 bool skipIncidence = false; 2901 bool skipIncidence = false;
2900 if ( uid.left(19) == QString("last-syncAddressee-") ) 2902 if ( uid.left(19) == QString("last-syncAddressee-") )
2901 skipIncidence = true; 2903 skipIncidence = true;
2902 QString idS,OidS; 2904 QString idS,OidS;
2903 qApp->processEvents(); 2905 qApp->processEvents();
2904 if ( !skipIncidence ) { 2906 if ( !skipIncidence ) {
2905 inL = local->findByUid( uid ); 2907 inL = local->findByUid( uid );
2906 inR = remote->findByUid( uid ); 2908 inR = remote->findByUid( uid );
2907 //inL.setResource( 0 ); 2909 //inL.setResource( 0 );
2908 //inR.setResource( 0 ); 2910 //inR.setResource( 0 );
2909 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars 2911 if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars
2910 if ( !inL.resource() || inL.resource()->includeInSync() ) { 2912 if ( !inL.resource() || inL.resource()->includeInSync() ) {
2911 if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) { 2913 if ( (take = takeAddressee( &inL, &inR, mode, fullDateRange )) ) {
2912 //qDebug("take %d %s ", take, inL.summary().latin1()); 2914 //qDebug("take %d %s ", take, inL.summary().latin1());
2913 if ( take == 3 ) 2915 if ( take == 3 )
2914 return false; 2916 return false;
2915 if ( take == 1 ) {// take local ********************** 2917 if ( take == 1 ) {// take local **********************
2916 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2918 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2917 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2919 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2918 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2920 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2919 local->insertAddressee( inL, false ); 2921 local->insertAddressee( inL, false );
2920 idS = inR.externalUID(); 2922 idS = inR.externalUID();
2921 OidS = inR.originalExternalUID(); 2923 OidS = inR.originalExternalUID();
2922 } 2924 }
2923 else 2925 else
2924 idS = inR.IDStr(); 2926 idS = inR.IDStr();
2925 remote->removeAddressee( inR ); 2927 remote->removeAddressee( inR );
2926 inR = inL; 2928 inR = inL;
2927 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2929 inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2928 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2930 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2929 inR.setOriginalExternalUID( OidS ); 2931 inR.setOriginalExternalUID( OidS );
2930 inR.setExternalUID( idS ); 2932 inR.setExternalUID( idS );
2931 if ( syncManager->syncWithDesktop() ) { 2933 if ( syncManager->syncWithDesktop() ) {
2932 inR.setIDStr("changed" ); 2934 inR.setIDStr("changed" );
2933 } 2935 }
2934 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); 2936 //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" );
2935 } else { 2937 } else {
2936 inR.setIDStr( idS ); 2938 inR.setIDStr( idS );
2937 } 2939 }
2938 inR.setResource( 0 ); 2940 inR.setResource( 0 );
2939 remote->insertAddressee( inR , false); 2941 remote->insertAddressee( inR , false);
2940 ++changedRemote; 2942 ++changedRemote;
2941 } else { // take == 2 take remote ********************** 2943 } else { // take == 2 take remote **********************
2942 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2944 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2943 if ( inR.revision().date().year() < 2004 ) 2945 if ( inR.revision().date().year() < 2004 )
2944 inR.setRevision( modifiedCalendar ); 2946 inR.setRevision( modifiedCalendar );
2945 } 2947 }
2946 idS = inL.IDStr(); 2948 idS = inL.IDStr();
2947 local->removeAddressee( inL ); 2949 local->removeAddressee( inL );
2948 inL = inR; 2950 inL = inR;
2949 inL.setIDStr( idS ); 2951 inL.setIDStr( idS );
2950 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2952 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2951 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); 2953 inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) );
2952 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); 2954 inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) );
2953 } 2955 }
2954 inL.setResource( 0 ); 2956 inL.setResource( 0 );
2955 local->insertAddressee( inL , false ); 2957 local->insertAddressee( inL , false );
2956 ++changedLocal; 2958 ++changedLocal;
2957 } 2959 }
2958 } 2960 }
2959 } 2961 }
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;
3116 isXML = true; 3121 isXML = true;
3117 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 3122 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
3118 } else { 3123 } else {
3119 external = !manager->mIsKapiFile; 3124 external = !manager->mIsKapiFile;
3120 if ( external ) { 3125 if ( external ) {
3121 qDebug("Setting vcf mode to external "); 3126 qDebug("Setting vcf mode to external ");
3122 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3127 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3123 AddressBook::Iterator it; 3128 AddressBook::Iterator it;
3124 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 3129 for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
3125 (*it).setID( mCurrentSyncDevice, (*it).uid() ); 3130 (*it).setID( mCurrentSyncDevice, (*it).uid() );
3126 (*it).computeCsum( mCurrentSyncDevice ); 3131 (*it).computeCsum( mCurrentSyncDevice );
3127 } 3132 }
3128 } 3133 }
3129 } 3134 }
3130 //AddressBook::Iterator it; 3135 //AddressBook::Iterator it;
3131 //QStringList vcards; 3136 //QStringList vcards;
3132 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { 3137 //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) {
3133 // qDebug("Name %s ", (*it).familyName().latin1()); 3138 // qDebug("Name %s ", (*it).familyName().latin1());
3134 //} 3139 //}
3135 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); 3140 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode );
3136 if ( syncOK ) { 3141 if ( syncOK ) {
3137 if ( syncManager->mWriteBackFile ) 3142 if ( syncManager->mWriteBackFile )
3138 { 3143 {
3139 if ( external ) 3144 if ( external )
3140 abLocal.removeSyncAddressees( !isXML); 3145 abLocal.removeSyncAddressees( !isXML);
3141 qDebug("Saving remote AB "); 3146 qDebug("Saving remote AB ");
3142 if ( ! abLocal.saveAB()) 3147 if ( ! abLocal.saveAB())
3143 qDebug("Error writing back AB to file "); 3148 qDebug("Error writing back AB to file ");
3144 if ( external ) { 3149 if ( external ) {
3145 // afterwrite processing 3150 // afterwrite processing
3146 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); 3151 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML);
3147 } 3152 }
3148 } 3153 }
3149 } 3154 }
3150 setModified(); 3155 setModified();
3151 3156
3152 } 3157 }
3153 abLocal.removeResources(); 3158 abLocal.removeResources();
3154 if ( syncOK ) 3159 if ( syncOK )
3155 mViewManager->refreshView(); 3160 mViewManager->refreshView();
3156 return syncOK; 3161 return syncOK;
3157 3162
3158} 3163}
3159void KABCore::removeSyncInfo( QString syncProfile) 3164void KABCore::removeSyncInfo( QString syncProfile)
3160{ 3165{
3161 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); 3166 qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1());
3162 mAddressBook->removeSyncInfo( syncProfile ); 3167 mAddressBook->removeSyncInfo( syncProfile );
3163 setModified(); 3168 setModified();
3164} 3169}
3165 3170
3166 3171
3167//this is a overwritten callbackmethods from the syncinterface 3172//this is a overwritten callbackmethods from the syncinterface
3168bool KABCore::syncExternal(KSyncManager* manager, QString resource) 3173bool KABCore::syncExternal(KSyncManager* manager, QString resource)
3169{ 3174{
3170 if ( resource == "phone" ) 3175 if ( resource == "phone" )
3171 return syncPhone(); 3176 return syncPhone();
3172 disableBR( true ); 3177 disableBR( true );
3173 if ( manager != syncManager ) 3178 if ( manager != syncManager )
3174 qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager "); 3179 qDebug("KABCore::syncExternal:: ERROR! :: manager != syncManager ");
3175 QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); 3180 QString mCurrentSyncDevice = manager->getCurrentSyncDevice();
3176 3181
3177 AddressBook abLocal( resource,"syncContact"); 3182 AddressBook abLocal( resource,"syncContact");
3178 bool syncOK = false; 3183 bool syncOK = false;
3179 if ( abLocal.load() ) { 3184 if ( abLocal.load() ) {
3180 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); 3185 qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1());
3181 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3186 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3182 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); 3187 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false );
3183 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 3188 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
3184 if ( syncOK ) { 3189 if ( syncOK ) {
3185 if ( syncManager->mWriteBackFile ) { 3190 if ( syncManager->mWriteBackFile ) {
3186 abLocal.removeSyncAddressees( false ); 3191 abLocal.removeSyncAddressees( false );
3187 abLocal.saveAB(); 3192 abLocal.saveAB();
3188 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 3193 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
3189 } 3194 }
3190 } else 3195 } else
3191 message( i18n("Sync cancelled or failed.") ); 3196 message( i18n("Sync cancelled or failed.") );
3192 setModified(); 3197 setModified();
3193 } 3198 }
3194 abLocal.removeResources(); 3199 abLocal.removeResources();
3195 if ( syncOK ) 3200 if ( syncOK )
3196 mViewManager->refreshView(); 3201 mViewManager->refreshView();
3197 disableBR( false ); 3202 disableBR( false );
3198 return syncOK; 3203 return syncOK;
3199 3204
3200} 3205}
3201void KABCore::message( QString m ) 3206void KABCore::message( QString m )
3202{ 3207{
3203 topLevelWidget()->setCaption( m ); 3208 topLevelWidget()->setCaption( m );
3204 mMessageTimer->start( 15000, true ); 3209 mMessageTimer->start( 15000, true );
3205} 3210}
3206bool KABCore::syncPhone() 3211bool KABCore::syncPhone()
3207{ 3212{
3208 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); 3213 QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice();
3209 QString fileName = getPhoneFile(); 3214 QString fileName = getPhoneFile();
3210 if ( !PhoneAccess::readFromPhone( fileName) ) { 3215 if ( !PhoneAccess::readFromPhone( fileName) ) {
3211 message(i18n("Phone access failed!")); 3216 message(i18n("Phone access failed!"));
3212 return false; 3217 return false;
3213 } 3218 }
3214 AddressBook abLocal( fileName,"syncContact"); 3219 AddressBook abLocal( fileName,"syncContact");
3215 bool syncOK = false; 3220 bool syncOK = false;
3216 { 3221 {
3217 abLocal.importFromFile( fileName ); 3222 abLocal.importFromFile( fileName );
3218 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 3223 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
3219 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 3224 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
3220 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 3225 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
3221 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); 3226 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true );
3222 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 3227 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
3223 if ( syncOK ) { 3228 if ( syncOK ) {
3224 if ( syncManager->mWriteBackFile ) { 3229 if ( syncManager->mWriteBackFile ) {
3225 abLocal.removeSyncAddressees( true ); 3230 abLocal.removeSyncAddressees( true );
3226 abLocal.saveABphone( fileName ); 3231 abLocal.saveABphone( fileName );
3227 abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); 3232 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
3228 //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 3233 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
3229 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); 3234 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true );
3230 } 3235 }
3231 } 3236 }
3232 setModified(); 3237 setModified();
3233 } 3238 }
3234 abLocal.removeResources(); 3239 abLocal.removeResources();
3235 if ( syncOK ) 3240 if ( syncOK )
3236 mViewManager->refreshView(); 3241 mViewManager->refreshView();
3237 return syncOK; 3242 return syncOK;
3238} 3243}
3239void KABCore::getFile( bool success ) 3244void KABCore::getFile( bool success )
3240{ 3245{
3241 if ( ! success ) { 3246 if ( ! success ) {
3242 message( i18n("Error receiving file. Nothing changed!") ); 3247 message( i18n("Error receiving file. Nothing changed!") );
3243 return; 3248 return;
3244 } 3249 }
3245 int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); 3250 int count = mAddressBook->importFromFile( sentSyncFile() , false, true );
3246 if ( count ) 3251 if ( count )
3247 setModified( true ); 3252 setModified( true );
3248 message( i18n("Pi-Sync successful!") ); 3253 message( i18n("Pi-Sync successful!") );
3249 mViewManager->refreshView(); 3254 mViewManager->refreshView();
3250} 3255}
3251void KABCore::syncFileRequest() 3256void KABCore::syncFileRequest()
3252{ 3257{
3253 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) { 3258 if ( KABPrefs::instance()->mPassiveSyncWithDesktop ) {
3254 syncManager->slotSyncMenu( 999 ); 3259 syncManager->slotSyncMenu( 999 );
3255 } 3260 }
3256 mAddressBook->export2File( sentSyncFile() ); 3261 mAddressBook->export2File( sentSyncFile() );
3257} 3262}
3258QString KABCore::sentSyncFile() 3263QString KABCore::sentSyncFile()
3259{ 3264{
3260#ifdef DESKTOP_VERSION 3265#ifdef DESKTOP_VERSION
3261 return locateLocal( "tmp", "copysyncab.vcf" ); 3266 return locateLocal( "tmp", "copysyncab.vcf" );
3262#else 3267#else
3263 return QString( "/tmp/copysyncab.vcf" ); 3268 return QString( "/tmp/copysyncab.vcf" );
3264#endif 3269#endif
3265} 3270}
3266 3271
3267void KABCore::setCaptionBack() 3272void KABCore::setCaptionBack()
3268{ 3273{
3269 mMessageTimer->stop(); 3274 mMessageTimer->stop();
3270 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); 3275 topLevelWidget()->setCaption( i18n("KAddressbook/Pi") );
3271} 3276}