-rw-r--r-- | kaddressbook/kabcore.cpp | 206 |
1 files changed, 92 insertions, 114 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 53c63ff..f497541 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1,89 +1,91 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "kabcore.h" | 31 | #include "kabcore.h" |
32 | 32 | ||
33 | #include <stdaddressbook.h> | 33 | #include <stdaddressbook.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kfiledialog.h> | 35 | #include <kfiledialog.h> |
36 | #include <qprogressbar.h> | ||
36 | 37 | ||
37 | #ifndef KAB_EMBEDDED | 38 | #ifndef KAB_EMBEDDED |
38 | #include <qclipboard.h> | 39 | #include <qclipboard.h> |
39 | #include <qdir.h> | 40 | #include <qdir.h> |
40 | #include <qfile.h> | 41 | #include <qfile.h> |
41 | #include <qapplicaton.h> | 42 | #include <qapplicaton.h> |
43 | #include <qprogressbar.h> | ||
42 | #include <qlayout.h> | 44 | #include <qlayout.h> |
43 | #include <qregexp.h> | 45 | #include <qregexp.h> |
44 | #include <qvbox.h> | 46 | #include <qvbox.h> |
45 | #include <kabc/addresseelist.h> | 47 | #include <kabc/addresseelist.h> |
46 | #include <kabc/errorhandler.h> | 48 | #include <kabc/errorhandler.h> |
47 | #include <kabc/resource.h> | 49 | #include <kabc/resource.h> |
48 | #include <kabc/vcardconverter.h> | 50 | #include <kabc/vcardconverter.h> |
49 | #include <kapplication.h> | 51 | #include <kapplication.h> |
50 | #include <kactionclasses.h> | 52 | #include <kactionclasses.h> |
51 | #include <kcmultidialog.h> | 53 | #include <kcmultidialog.h> |
52 | #include <kdebug.h> | 54 | #include <kdebug.h> |
53 | #include <kdeversion.h> | 55 | #include <kdeversion.h> |
54 | #include <kkeydialog.h> | 56 | #include <kkeydialog.h> |
55 | #include <kmessagebox.h> | 57 | #include <kmessagebox.h> |
56 | #include <kprinter.h> | 58 | #include <kprinter.h> |
57 | #include <kprotocolinfo.h> | 59 | #include <kprotocolinfo.h> |
58 | #include <kresources/selectdialog.h> | 60 | #include <kresources/selectdialog.h> |
59 | #include <kstandarddirs.h> | 61 | #include <kstandarddirs.h> |
60 | #include <ktempfile.h> | 62 | #include <ktempfile.h> |
61 | #include <kxmlguiclient.h> | 63 | #include <kxmlguiclient.h> |
62 | #include <kaboutdata.h> | 64 | #include <kaboutdata.h> |
63 | #include <libkdepim/categoryselectdialog.h> | 65 | #include <libkdepim/categoryselectdialog.h> |
64 | 66 | ||
65 | #include "addresseeutil.h" | 67 | #include "addresseeutil.h" |
66 | #include "addresseeeditordialog.h" | 68 | #include "addresseeeditordialog.h" |
67 | #include "extensionmanager.h" | 69 | #include "extensionmanager.h" |
68 | #include "kstdaction.h" | 70 | #include "kstdaction.h" |
69 | #include "kaddressbookservice.h" | 71 | #include "kaddressbookservice.h" |
70 | #include "ldapsearchdialog.h" | 72 | #include "ldapsearchdialog.h" |
71 | #include "printing/printingwizard.h" | 73 | #include "printing/printingwizard.h" |
72 | #else // KAB_EMBEDDED | 74 | #else // KAB_EMBEDDED |
73 | 75 | ||
74 | #include <kapplication.h> | 76 | #include <kapplication.h> |
75 | #include "KDGanttMinimizeSplitter.h" | 77 | #include "KDGanttMinimizeSplitter.h" |
76 | #include "kaddressbookmain.h" | 78 | #include "kaddressbookmain.h" |
77 | #include "kactioncollection.h" | 79 | #include "kactioncollection.h" |
78 | #include "addresseedialog.h" | 80 | #include "addresseedialog.h" |
79 | //US | 81 | //US |
80 | #include <addresseeview.h> | 82 | #include <addresseeview.h> |
81 | 83 | ||
82 | #include <qapp.h> | 84 | #include <qapp.h> |
83 | #include <qmenubar.h> | 85 | #include <qmenubar.h> |
84 | //#include <qtoolbar.h> | 86 | //#include <qtoolbar.h> |
85 | #include <qmessagebox.h> | 87 | #include <qmessagebox.h> |
86 | #include <kdebug.h> | 88 | #include <kdebug.h> |
87 | #include <kiconloader.h> // needed for SmallIcon | 89 | #include <kiconloader.h> // needed for SmallIcon |
88 | #include <kresources/kcmkresources.h> | 90 | #include <kresources/kcmkresources.h> |
89 | #include <ktoolbar.h> | 91 | #include <ktoolbar.h> |
@@ -2552,291 +2554,267 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2552 | KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2554 | KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2553 | KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2555 | KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2554 | bool fullDateRange = false; | 2556 | bool fullDateRange = false; |
2555 | local->resetTempSyncStat(); | 2557 | local->resetTempSyncStat(); |
2556 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2558 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2557 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2559 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2558 | addresseeLSync = getLastSyncAddressee(); | 2560 | addresseeLSync = getLastSyncAddressee(); |
2559 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2561 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2560 | if ( !addresseeR.isEmpty() ) { | 2562 | if ( !addresseeR.isEmpty() ) { |
2561 | addresseeRSync = addresseeR; | 2563 | addresseeRSync = addresseeR; |
2562 | remote->removeAddressee(addresseeR ); | 2564 | remote->removeAddressee(addresseeR ); |
2563 | 2565 | ||
2564 | } else { | 2566 | } else { |
2565 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2567 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2566 | addresseeRSync = addresseeLSync ; | 2568 | addresseeRSync = addresseeLSync ; |
2567 | } else { | 2569 | } else { |
2568 | fullDateRange = true; | 2570 | fullDateRange = true; |
2569 | Addressee newAdd; | 2571 | Addressee newAdd; |
2570 | addresseeRSync = newAdd; | 2572 | addresseeRSync = newAdd; |
2571 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2573 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2572 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2574 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2573 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2575 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2574 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2576 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2575 | } | 2577 | } |
2576 | } | 2578 | } |
2577 | if ( addresseeLSync.revision() == mLastAddressbookSync ) | 2579 | if ( addresseeLSync.revision() == mLastAddressbookSync ) |
2578 | fullDateRange = true; | 2580 | fullDateRange = true; |
2579 | if ( ! fullDateRange ) { | 2581 | if ( ! fullDateRange ) { |
2580 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2582 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2581 | 2583 | ||
2582 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2584 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2583 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2585 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2584 | fullDateRange = true; | 2586 | fullDateRange = true; |
2585 | } | 2587 | } |
2586 | } | 2588 | } |
2587 | if ( fullDateRange ) | 2589 | if ( fullDateRange ) |
2588 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2590 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2589 | else | 2591 | else |
2590 | mLastAddressbookSync = addresseeLSync.revision(); | 2592 | mLastAddressbookSync = addresseeLSync.revision(); |
2591 | // for resyncing if own file has changed | 2593 | // for resyncing if own file has changed |
2592 | // PENDING fixme later when implemented | 2594 | // PENDING fixme later when implemented |
2593 | #if 0 | 2595 | #if 0 |
2594 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2596 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2595 | mLastAddressbookSync = loadedFileVersion; | 2597 | mLastAddressbookSync = loadedFileVersion; |
2596 | qDebug("setting mLastAddressbookSync "); | 2598 | qDebug("setting mLastAddressbookSync "); |
2597 | } | 2599 | } |
2598 | #endif | 2600 | #endif |
2599 | 2601 | ||
2600 | #if 0 | ||
2601 | //qDebug("*************************** "); | 2602 | //qDebug("*************************** "); |
2602 | qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2603 | qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2603 | QPtrList<Incidence> er = remote->rawIncidences(); | 2604 | QStringList er = remote->uidList(); |
2604 | Incidence* inR = er.first(); | 2605 | Addressee inR ;//= er.first(); |
2605 | Incidence* inL; | 2606 | Addressee inL; |
2606 | QProgressBar bar( er.count(),0 ); | 2607 | QProgressBar bar( er.count(),0 ); |
2607 | bar.setCaption (i18n("Syncing - close to abort!") ); | 2608 | bar.setCaption (i18n("Syncing - close to abort!") ); |
2608 | 2609 | ||
2609 | int w = 300; | 2610 | int w = 300; |
2610 | if ( QApplication::desktop()->width() < 320 ) | 2611 | if ( QApplication::desktop()->width() < 320 ) |
2611 | w = 220; | 2612 | w = 220; |
2612 | int h = bar.sizeHint().height() ; | 2613 | int h = bar.sizeHint().height() ; |
2613 | int dw = QApplication::desktop()->width(); | 2614 | int dw = QApplication::desktop()->width(); |
2614 | int dh = QApplication::desktop()->height(); | 2615 | int dh = QApplication::desktop()->height(); |
2615 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2616 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2616 | bar.show(); | 2617 | bar.show(); |
2617 | int modulo = (er.count()/10)+1; | 2618 | int modulo = (er.count()/10)+1; |
2618 | int incCounter = 0; | 2619 | int incCounter = 0; |
2619 | while ( inR ) { | 2620 | while ( incCounter < er.count()) { |
2620 | if ( ! bar.isVisible() ) | 2621 | if ( ! bar.isVisible() ) |
2621 | return false; | 2622 | return false; |
2622 | if ( incCounter % modulo == 0 ) | 2623 | if ( incCounter % modulo == 0 ) |
2623 | bar.setProgress( incCounter ); | 2624 | bar.setProgress( incCounter ); |
2624 | ++incCounter; | 2625 | uid = er[ incCounter ]; |
2625 | uid = inR->uid(); | ||
2626 | bool skipIncidence = false; | 2626 | bool skipIncidence = false; |
2627 | if ( uid.left(15) == QString("last-syncAddressee-") ) | 2627 | if ( uid.left(20) == QString("last-syncAddressee-") ) |
2628 | skipIncidence = true; | 2628 | skipIncidence = true; |
2629 | QString idS; | 2629 | QString idS; |
2630 | qApp->processAddressees(); | 2630 | qApp->processEvents(); |
2631 | if ( !skipIncidence ) { | 2631 | if ( !skipIncidence ) { |
2632 | inL = local->incidence( uid ); | 2632 | inL = local->findByUid( uid ); |
2633 | if ( inL ) { // maybe conflict - same uid in both calendars | 2633 | inR = remote->findByUid( uid ); |
2634 | int maxrev = inL->revision(); | 2634 | //inL.setResource( 0 ); |
2635 | if ( maxrev < inR->revision() ) | 2635 | //inR.setResource( 0 ); |
2636 | maxrev = inR->revision(); | 2636 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2637 | if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { | 2637 | // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { |
2638 | //qDebug("take %d %s ", take, inL->summary().latin1()); | 2638 | if ( true ) { |
2639 | //qDebug("take %d %s ", take, inL.summary().latin1()); | ||
2639 | if ( take == 3 ) | 2640 | if ( take == 3 ) |
2640 | return false; | 2641 | return false; |
2641 | if ( take == 1 ) {// take local | 2642 | if ( take == 1 ) {// take local |
2642 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2643 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2643 | inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); | 2644 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2645 | local->insertAddressee( inL ); | ||
2646 | } | ||
2644 | else | 2647 | else |
2645 | idS = inR->IDStr(); | 2648 | idS = inR.IDStr(); |
2646 | remote->deleteIncidence( inR ); | 2649 | remote->removeAddressee( inR ); |
2647 | if ( inL->revision() < maxrev ) | 2650 | inR = inL; |
2648 | inL->setRevision( maxrev ); | 2651 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2649 | inR = inL->clone(); | ||
2650 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | ||
2651 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) | 2652 | if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) |
2652 | inR->setIDStr( idS ); | 2653 | inR.setIDStr( idS ); |
2653 | remote->addIncidence( inR ); | 2654 | inR.setResource( 0 ); |
2655 | remote->insertAddressee( inR ); | ||
2654 | ++changedRemote; | 2656 | ++changedRemote; |
2655 | } else { | 2657 | } else { |
2656 | if ( inR->revision() < maxrev ) | 2658 | idS = inL.IDStr(); |
2657 | inR->setRevision( maxrev ); | 2659 | local->removeAddressee( inL ); |
2658 | idS = inL->IDStr(); | 2660 | inL = inR; |
2659 | local->deleteIncidence( inL ); | 2661 | inL.setIDStr( idS ); |
2660 | inL = inR->clone(); | 2662 | inL.setResource( 0 ); |
2661 | inL->setIDStr( idS ); | 2663 | local->insertAddressee( inL ); |
2662 | local->addIncidence( inL ); | ||
2663 | ++changedLocal; | 2664 | ++changedLocal; |
2664 | } | 2665 | } |
2665 | } | 2666 | } |
2666 | } else { // no conflict | 2667 | } else { // no conflict |
2667 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2668 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2668 | QString des = addresseeLSync->description(); | 2669 | QString des = addresseeLSync.note(); |
2669 | QString pref = "e"; | 2670 | QString pref = "a"; |
2670 | if ( inR->type() == "Todo" ) | 2671 | if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2671 | pref = "t"; | 2672 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2672 | if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | ||
2673 | inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | ||
2674 | //remote->deleteIncidence( inR ); | ||
2675 | ++deletedAddresseeR; | 2673 | ++deletedAddresseeR; |
2676 | } else { | 2674 | } else { |
2677 | inR->setLastModified( modifiedCalendar ); | 2675 | inR.setRevision( modifiedCalendar ); |
2678 | inL = inR->clone(); | 2676 | remote->insertAddressee( inR ); |
2679 | local->addIncidence( inL ); | 2677 | inL = inR; |
2678 | inL.setResource( 0 ); | ||
2679 | local->insertAddressee( inL ); | ||
2680 | ++addedAddressee; | 2680 | ++addedAddressee; |
2681 | } | 2681 | } |
2682 | } else { | 2682 | } else { |
2683 | if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) { | 2683 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2684 | inR->setLastModified( modifiedCalendar ); | 2684 | inR.setRevision( modifiedCalendar ); |
2685 | local->addIncidence( inR->clone() ); | 2685 | remote->insertAddressee( inR ); |
2686 | inR.setResource( 0 ); | ||
2687 | local->insertAddressee( inR ); | ||
2686 | ++addedAddressee; | 2688 | ++addedAddressee; |
2687 | } else { | 2689 | } else { |
2688 | checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2690 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2689 | remote->deleteIncidence( inR ); | 2691 | remote->removeAddressee( inR ); |
2690 | ++deletedAddresseeR; | 2692 | ++deletedAddresseeR; |
2691 | } | 2693 | } |
2692 | } | 2694 | } |
2693 | } | 2695 | } |
2694 | } | 2696 | } |
2695 | inR = er.next(); | 2697 | ++incCounter; |
2696 | } | 2698 | } |
2697 | QPtrList<Incidence> el = local->rawIncidences(); | 2699 | er.clear(); |
2698 | inL = el.first(); | 2700 | QStringList el = remote->uidList(); |
2699 | modulo = (el.count()/10)+1; | 2701 | modulo = (el.count()/10)+1; |
2700 | bar.setCaption (i18n("Add / remove addressees") ); | 2702 | bar.setCaption (i18n("Add / remove addressees") ); |
2701 | bar.setTotalSteps ( el.count() ) ; | 2703 | bar.setTotalSteps ( el.count() ) ; |
2702 | bar.show(); | 2704 | bar.show(); |
2703 | incCounter = 0; | 2705 | incCounter = 0; |
2704 | 2706 | while ( incCounter < el.count()) { | |
2705 | while ( inL ) { | ||
2706 | 2707 | ||
2707 | qApp->processAddressees(); | 2708 | qApp->processEvents(); |
2708 | if ( ! bar.isVisible() ) | 2709 | if ( ! bar.isVisible() ) |
2709 | return false; | 2710 | return false; |
2710 | if ( incCounter % modulo == 0 ) | 2711 | if ( incCounter % modulo == 0 ) |
2711 | bar.setProgress( incCounter ); | 2712 | bar.setProgress( incCounter ); |
2712 | ++incCounter; | 2713 | uid = el[ incCounter ]; |
2713 | uid = inL->uid(); | ||
2714 | bool skipIncidence = false; | 2714 | bool skipIncidence = false; |
2715 | if ( uid.left(15) == QString("last-syncAddressee-") ) | 2715 | if ( uid.left(20) == QString("last-syncAddressee-") ) |
2716 | skipIncidence = true; | 2716 | skipIncidence = true; |
2717 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) | 2717 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2718 | skipIncidence = true; | 2718 | skipIncidence = true; |
2719 | if ( !skipIncidence ) { | 2719 | if ( !skipIncidence ) { |
2720 | inR = remote->incidence( uid ); | 2720 | inL = local->findByUid( uid ); |
2721 | if ( ! inR ) { | 2721 | inR = remote->findByUid( uid ); |
2722 | if ( inR.isEmpty() ) { | ||
2722 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2723 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2723 | if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2724 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2724 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2725 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2725 | local->deleteIncidence( inL ); | 2726 | local->removeAddressee( inL ); |
2726 | ++deletedAddresseeL; | 2727 | ++deletedAddresseeL; |
2727 | } else { | 2728 | } else { |
2728 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 2729 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2729 | inL->removeID(mCurrentSyncDevice ); | 2730 | inL.removeID(mCurrentSyncDevice ); |
2730 | ++addedAddresseeR; | 2731 | ++addedAddresseeR; |
2731 | //qDebug("remote added Incidence %s ", inL->summary().latin1()); | 2732 | //qDebug("remote added Incidence %s ", inL.summary().latin1()); |
2732 | inL->setLastModified( modifiedCalendar ); | 2733 | inL.setRevision( modifiedCalendar ); |
2733 | inR = inL->clone(); | 2734 | local->insertAddressee( inL ); |
2734 | inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2735 | inR = inL; |
2735 | remote->addIncidence( inR ); | 2736 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2737 | inR.setResource( 0 ); | ||
2738 | remote->insertAddressee( inR ); | ||
2736 | } | 2739 | } |
2737 | } | 2740 | } |
2738 | } else { | 2741 | } else { |
2739 | if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) { | 2742 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2740 | checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2743 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2741 | local->deleteIncidence( inL ); | 2744 | local->removeAddressee( inL ); |
2742 | ++deletedAddresseeL; | 2745 | ++deletedAddresseeL; |
2743 | } else { | 2746 | } else { |
2744 | if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { | 2747 | if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { |
2745 | ++addedAddresseeR; | 2748 | ++addedAddresseeR; |
2746 | inL->setLastModified( modifiedCalendar ); | 2749 | inL.setRevision( modifiedCalendar ); |
2747 | remote->addIncidence( inL->clone() ); | 2750 | local->insertAddressee( inL ); |
2751 | inR = inL; | ||
2752 | inR.setResource( 0 ); | ||
2753 | remote->insertAddressee( inR ); | ||
2748 | } | 2754 | } |
2749 | } | 2755 | } |
2750 | } | 2756 | } |
2751 | } | 2757 | } |
2752 | } | 2758 | } |
2753 | inL = el.next(); | 2759 | ++incCounter; |
2754 | } | 2760 | } |
2761 | el.clear(); | ||
2755 | int delFut = 0; | 2762 | int delFut = 0; |
2756 | if ( KOPrefs::instance()->mWriteBackInFuture ) { | 2763 | |
2757 | er = remote->rawIncidences(); | 2764 | #if 0 |
2758 | inR = er.first(); | 2765 | |
2759 | QDateTime dt; | ||
2760 | QDateTime cur = QDateTime::currentDateTime(); | ||
2761 | QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); | ||
2762 | while ( inR ) { | ||
2763 | if ( inR->type() == "Todo" ) { | ||
2764 | Todo * t = (Todo*)inR; | ||
2765 | if ( t->hasDueDate() ) | ||
2766 | dt = t->dtDue(); | ||
2767 | else | ||
2768 | dt = cur.addSecs( 62 ); | ||
2769 | } | ||
2770 | else if (inR->type() == "Addressee" ) { | ||
2771 | bool ok; | ||
2772 | dt = inR->getNextOccurence( cur, &ok ); | ||
2773 | if ( !ok ) | ||
2774 | dt = cur.addSecs( -62 ); | ||
2775 | } | ||
2776 | else | ||
2777 | dt = inR->dtStart(); | ||
2778 | if ( dt < cur || dt > end ) { | ||
2779 | remote->deleteIncidence( inR ); | ||
2780 | ++delFut; | ||
2781 | } | ||
2782 | inR = er.next(); | ||
2783 | } | ||
2784 | } | ||
2785 | bar.hide(); | 2766 | bar.hide(); |
2786 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2767 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2787 | addresseeLSync->setReadOnly( false ); | 2768 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2788 | addresseeLSync->setDtStart( mLastAddressbookSync ); | 2769 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2789 | addresseeRSync->setDtStart( mLastAddressbookSync ); | 2770 | addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; |
2790 | addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); | 2771 | addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName ); |
2791 | addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); | 2772 | addresseeLSync.setReadOnly( true ); |
2792 | addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; | ||
2793 | addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); | ||
2794 | addresseeLSync->setReadOnly( true ); | ||
2795 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2773 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2796 | remote->addAddressee( addresseeRSync ); | 2774 | remote->addAddressee( addresseeRSync ); |
2797 | QString mes; | 2775 | QString mes; |
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 | 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 ); |
2799 | QString delmess; | 2777 | QString delmess; |
2800 | if ( delFut ) { | 2778 | if ( delFut ) { |
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 | 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 ); |
2802 | mes += delmess; | 2780 | mes += delmess; |
2803 | } | 2781 | } |
2804 | if ( KOPrefs::instance()->mShowSyncSummary ) { | 2782 | if ( KOPrefs::instance()->mShowSyncSummary ) { |
2805 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); | 2783 | KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); |
2806 | } | 2784 | } |
2807 | qDebug( mes ); | 2785 | qDebug( mes ); |
2808 | mCalendar->checkAlarmForIncidence( 0, true ); | 2786 | mCalendar->checkAlarmForIncidence( 0, true ); |
2809 | return syncOK; | 2787 | return syncOK; |
2810 | #endif | 2788 | #endif |
2811 | return false; | 2789 | return false; |
2812 | } | 2790 | } |
2813 | bool KABCore::syncAB(QString filename, int mode) | 2791 | bool KABCore::syncAB(QString filename, int mode) |
2814 | { | 2792 | { |
2815 | 2793 | ||
2816 | //pending prepare addresseeview for output | 2794 | //pending prepare addresseeview for output |
2817 | //pending detect, if remote file has REV field. if not switch to external sync | 2795 | //pending detect, if remote file has REV field. if not switch to external sync |
2818 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2796 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2819 | AddressBook abLocal(filename,"syncContact"); | 2797 | AddressBook abLocal(filename,"syncContact"); |
2820 | bool syncOK = false; | 2798 | bool syncOK = false; |
2821 | if ( abLocal.load() ) { | 2799 | if ( abLocal.load() ) { |
2822 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); | 2800 | qDebug("AB loaded %s mode %d",filename.latin1(), mode ); |
2823 | AddressBook::Iterator it; | 2801 | AddressBook::Iterator it; |
2824 | QStringList vcards; | 2802 | QStringList vcards; |
2825 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2803 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2826 | qDebug("Name %s ", (*it).familyName().latin1()); | 2804 | qDebug("Name %s ", (*it).familyName().latin1()); |
2827 | } | 2805 | } |
2828 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2806 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2829 | if ( syncOK ) { | 2807 | if ( syncOK ) { |
2830 | if ( KABPrefs::instance()->mWriteBackFile ) | 2808 | if ( KABPrefs::instance()->mWriteBackFile ) |
2831 | { | 2809 | { |
2832 | qDebug("saving remote AB "); | 2810 | qDebug("saving remote AB "); |
2833 | abLocal.saveAB(); | 2811 | abLocal.saveAB(); |
2834 | } | 2812 | } |
2835 | } | 2813 | } |
2836 | setModified(); | 2814 | setModified(); |
2837 | 2815 | ||
2838 | } | 2816 | } |
2839 | if ( syncOK ) | 2817 | if ( syncOK ) |
2840 | mViewManager->refreshView(); | 2818 | mViewManager->refreshView(); |
2841 | return syncOK; | 2819 | return syncOK; |
2842 | #if 0 | 2820 | #if 0 |