summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kabcore.cpp
Unidiff
Diffstat (limited to 'kaddressbook/kabcore.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp93
1 files changed, 58 insertions, 35 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 1196360..53c63ff 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2504,88 +2504,111 @@ QString KABCore::getPassword( )
2504 QPushButton pb ( "OK", &dia); 2504 QPushButton pb ( "OK", &dia);
2505 lay.addWidget( &pb ); 2505 lay.addWidget( &pb );
2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 2506 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2507 dia.show(); 2507 dia.show();
2508 int res = dia.exec(); 2508 int res = dia.exec();
2509 if ( res ) 2509 if ( res )
2510 retfile = lab.text(); 2510 retfile = lab.text();
2511 dia.hide(); 2511 dia.hide();
2512 qApp->processEvents(); 2512 qApp->processEvents();
2513 return retfile; 2513 return retfile;
2514 2514
2515} 2515}
2516#include <libkcal/syncdefines.h>
2517
2518KABC::Addressee KABCore::getLastSyncAddressee()
2519{
2520 Addressee lse;
2521 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
2522 lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice );
2523 if (lse.isEmpty()) {
2524 lse.setUid( "last-syncEvent-"+mCurrentSyncDevice );
2525 QString sum = "";
2526 if ( KABPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
2527 sum = "E: ";
2528 lse.setFamilyName(sum+mCurrentSyncDevice + i18n(" - sync event"));
2529 lse.setRevision( mLastAddressbookSync );
2530 lse.setCategories( i18n("SyncEvent") );
2531 mAddressBook->insertAddressee( lse );
2532 }
2533 return lse;
2534}
2535
2516bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) 2536bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode)
2517{ 2537{
2518#if 0
2519 bool syncOK = true; 2538 bool syncOK = true;
2520 int addedAddressee = 0; 2539 int addedAddressee = 0;
2521 int addedAddresseeR = 0; 2540 int addedAddresseeR = 0;
2522 int deletedAddresseeR = 0; 2541 int deletedAddresseeR = 0;
2523 int deletedAddresseeL = 0; 2542 int deletedAddresseeL = 0;
2524 int changedLocal = 0; 2543 int changedLocal = 0;
2525 int changedRemote = 0; 2544 int changedRemote = 0;
2526 //QPtrList<Addressee> el = local->rawAddressees(); 2545 //QPtrList<Addressee> el = local->rawAddressees();
2527 Addressee* addresseeR; 2546 Addressee addresseeR;
2528 QString uid; 2547 QString uid;
2529 int take; 2548 int take;
2530 Addressee* addresseeL; 2549 Addressee addresseeL;
2531 Addressee* addresseeRSync; 2550 Addressee addresseeRSync;
2532 Addressee* addresseeLSync; 2551 Addressee addresseeLSync;
2533 QPtrList<Addressee> addresseeRSyncSharp = remote->getExternLastSyncAddressees(); 2552 KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees();
2534 QPtrList<Addressee> addresseeLSyncSharp = local->getExternLastSyncAddressees(); 2553 KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees();
2535 bool fullDateRange = false; 2554 bool fullDateRange = false;
2536 local->resetTempSyncStat(); 2555 local->resetTempSyncStat();
2537 mLastCalendarSync = QDateTime::currentDateTime(); 2556 mLastAddressbookSync = QDateTime::currentDateTime();
2538 QDateTime modifiedCalendar = mLastCalendarSync;; 2557 QDateTime modifiedCalendar = mLastAddressbookSync;;
2539 addresseeLSync = getLastSyncAddressee(); 2558 addresseeLSync = getLastSyncAddressee();
2540 addresseeR = remote->addressee("last-syncAddressee-"+mCurrentSyncName ); 2559 addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName );
2541 if ( addresseeR ) { 2560 if ( !addresseeR.isEmpty() ) {
2542 addresseeRSync = (Addressee*) addresseeR->clone(); 2561 addresseeRSync = addresseeR;
2543 remote->deleteAddressee(addresseeR ); 2562 remote->removeAddressee(addresseeR );
2544 2563
2545 } else { 2564 } else {
2546 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 2565 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
2547 addresseeRSync = (Addressee*)addresseeLSync->clone(); 2566 addresseeRSync = addresseeLSync ;
2548 } else { 2567 } else {
2549 fullDateRange = true; 2568 fullDateRange = true;
2550 addresseeRSync = new Addressee(); 2569 Addressee newAdd;
2551 addresseeRSync->setSummary(mCurrentSyncName + i18n(" - sync addressee")); 2570 addresseeRSync = newAdd;
2552 addresseeRSync->setUid("last-syncAddressee-"+mCurrentSyncName ); 2571 addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee"));
2553 addresseeRSync->setDtStart( mLastCalendarSync ); 2572 addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName );
2554 addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 2573 addresseeRSync.setRevision( mLastAddressbookSync );
2555 addresseeRSync->setCategories( i18n("SyncAddressee") ); 2574 addresseeRSync.setCategories( i18n("SyncAddressee") );
2556 } 2575 }
2557 } 2576 }
2558 if ( addresseeLSync->dtStart() == mLastCalendarSync ) 2577 if ( addresseeLSync.revision() == mLastAddressbookSync )
2559 fullDateRange = true; 2578 fullDateRange = true;
2560
2561 if ( ! fullDateRange ) { 2579 if ( ! fullDateRange ) {
2562 if ( addresseeLSync->dtStart() != addresseeRSync->dtStart() ) { 2580 if ( addresseeLSync.revision() != addresseeRSync.revision() ) {
2563 2581
2564 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); 2582 // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() );
2565 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); 2583 //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec());
2566 fullDateRange = true; 2584 fullDateRange = true;
2567 } 2585 }
2568 } 2586 }
2569 if ( fullDateRange ) 2587 if ( fullDateRange )
2570 mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365); 2588 mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365);
2571 else 2589 else
2572 mLastCalendarSync = addresseeLSync->dtStart(); 2590 mLastAddressbookSync = addresseeLSync.revision();
2573 // for resyncing if own file has changed 2591 // for resyncing if own file has changed
2592 // PENDING fixme later when implemented
2593#if 0
2574 if ( mCurrentSyncDevice == "deleteaftersync" ) { 2594 if ( mCurrentSyncDevice == "deleteaftersync" ) {
2575 mLastCalendarSync = loadedFileVersion; 2595 mLastAddressbookSync = loadedFileVersion;
2576 qDebug("setting mLastCalendarSync "); 2596 qDebug("setting mLastAddressbookSync ");
2577 } 2597 }
2598#endif
2599
2600 #if 0
2578 //qDebug("*************************** "); 2601 //qDebug("*************************** ");
2579 qDebug("mLastCalendarSync %s ",mLastCalendarSync.toString().latin1() ); 2602 qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() );
2580 QPtrList<Incidence> er = remote->rawIncidences(); 2603 QPtrList<Incidence> er = remote->rawIncidences();
2581 Incidence* inR = er.first(); 2604 Incidence* inR = er.first();
2582 Incidence* inL; 2605 Incidence* inL;
2583 QProgressBar bar( er.count(),0 ); 2606 QProgressBar bar( er.count(),0 );
2584 bar.setCaption (i18n("Syncing - close to abort!") ); 2607 bar.setCaption (i18n("Syncing - close to abort!") );
2585 2608
2586 int w = 300; 2609 int w = 300;
2587 if ( QApplication::desktop()->width() < 320 ) 2610 if ( QApplication::desktop()->width() < 320 )
2588 w = 220; 2611 w = 220;
2589 int h = bar.sizeHint().height() ; 2612 int h = bar.sizeHint().height() ;
2590 int dw = QApplication::desktop()->width(); 2613 int dw = QApplication::desktop()->width();
2591 int dh = QApplication::desktop()->height(); 2614 int dh = QApplication::desktop()->height();
@@ -2648,25 +2671,25 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2648 pref = "t"; 2671 pref = "t";
2649 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it 2672 if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
2650 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); 2673 inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
2651 //remote->deleteIncidence( inR ); 2674 //remote->deleteIncidence( inR );
2652 ++deletedAddresseeR; 2675 ++deletedAddresseeR;
2653 } else { 2676 } else {
2654 inR->setLastModified( modifiedCalendar ); 2677 inR->setLastModified( modifiedCalendar );
2655 inL = inR->clone(); 2678 inL = inR->clone();
2656 local->addIncidence( inL ); 2679 local->addIncidence( inL );
2657 ++addedAddressee; 2680 ++addedAddressee;
2658 } 2681 }
2659 } else { 2682 } else {
2660 if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) { 2683 if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) {
2661 inR->setLastModified( modifiedCalendar ); 2684 inR->setLastModified( modifiedCalendar );
2662 local->addIncidence( inR->clone() ); 2685 local->addIncidence( inR->clone() );
2663 ++addedAddressee; 2686 ++addedAddressee;
2664 } else { 2687 } else {
2665 checkExternSyncAddressee(addresseeRSyncSharp, inR); 2688 checkExternSyncAddressee(addresseeRSyncSharp, inR);
2666 remote->deleteIncidence( inR ); 2689 remote->deleteIncidence( inR );
2667 ++deletedAddresseeR; 2690 ++deletedAddresseeR;
2668 } 2691 }
2669 } 2692 }
2670 } 2693 }
2671 } 2694 }
2672 inR = er.next(); 2695 inR = er.next();
@@ -2704,25 +2727,25 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2704 } else { 2727 } else {
2705 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2728 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
2706 inL->removeID(mCurrentSyncDevice ); 2729 inL->removeID(mCurrentSyncDevice );
2707 ++addedAddresseeR; 2730 ++addedAddresseeR;
2708 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 2731 //qDebug("remote added Incidence %s ", inL->summary().latin1());
2709 inL->setLastModified( modifiedCalendar ); 2732 inL->setLastModified( modifiedCalendar );
2710 inR = inL->clone(); 2733 inR = inL->clone();
2711 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 2734 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
2712 remote->addIncidence( inR ); 2735 remote->addIncidence( inR );
2713 } 2736 }
2714 } 2737 }
2715 } else { 2738 } else {
2716 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 2739 if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) {
2717 checkExternSyncAddressee(addresseeLSyncSharp, inL); 2740 checkExternSyncAddressee(addresseeLSyncSharp, inL);
2718 local->deleteIncidence( inL ); 2741 local->deleteIncidence( inL );
2719 ++deletedAddresseeL; 2742 ++deletedAddresseeL;
2720 } else { 2743 } else {
2721 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 2744 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
2722 ++addedAddresseeR; 2745 ++addedAddresseeR;
2723 inL->setLastModified( modifiedCalendar ); 2746 inL->setLastModified( modifiedCalendar );
2724 remote->addIncidence( inL->clone() ); 2747 remote->addIncidence( inL->clone() );
2725 } 2748 }
2726 } 2749 }
2727 } 2750 }
2728 } 2751 }
@@ -2751,30 +2774,30 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo
2751 dt = cur.addSecs( -62 ); 2774 dt = cur.addSecs( -62 );
2752 } 2775 }
2753 else 2776 else
2754 dt = inR->dtStart(); 2777 dt = inR->dtStart();
2755 if ( dt < cur || dt > end ) { 2778 if ( dt < cur || dt > end ) {
2756 remote->deleteIncidence( inR ); 2779 remote->deleteIncidence( inR );
2757 ++delFut; 2780 ++delFut;
2758 } 2781 }
2759 inR = er.next(); 2782 inR = er.next();
2760 } 2783 }
2761 } 2784 }
2762 bar.hide(); 2785 bar.hide();
2763 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 2786 mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 );
2764 addresseeLSync->setReadOnly( false ); 2787 addresseeLSync->setReadOnly( false );
2765 addresseeLSync->setDtStart( mLastCalendarSync ); 2788 addresseeLSync->setDtStart( mLastAddressbookSync );
2766 addresseeRSync->setDtStart( mLastCalendarSync ); 2789 addresseeRSync->setDtStart( mLastAddressbookSync );
2767 addresseeLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 2790 addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
2768 addresseeRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 2791 addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) );
2769 addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 2792 addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
2770 addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 2793 addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
2771 addresseeLSync->setReadOnly( true ); 2794 addresseeLSync->setReadOnly( true );
2772 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 2795 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
2773 remote->addAddressee( addresseeRSync ); 2796 remote->addAddressee( addresseeRSync );
2774 QString mes; 2797 QString mes;
2775 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 ); 2798 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 );
2776 QString delmess; 2799 QString delmess;
2777 if ( delFut ) { 2800 if ( delFut ) {
2778 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 2801 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture );
2779 mes += delmess; 2802 mes += delmess;
2780 } 2803 }