-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 @@ -28,22 +28,24 @@ Copyright (c) 2004 Ulf Schenk $Id$ */ #include "kabcore.h" #include <stdaddressbook.h> #include <klocale.h> #include <kfiledialog.h> +#include <qprogressbar.h> #ifndef KAB_EMBEDDED #include <qclipboard.h> #include <qdir.h> #include <qfile.h> #include <qapplicaton.h> +#include <qprogressbar.h> #include <qlayout.h> #include <qregexp.h> #include <qvbox.h> #include <kabc/addresseelist.h> #include <kabc/errorhandler.h> #include <kabc/resource.h> #include <kabc/vcardconverter.h> #include <kapplication.h> @@ -2592,211 +2594,187 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo // PENDING fixme later when implemented #if 0 if ( mCurrentSyncDevice == "deleteaftersync" ) { mLastAddressbookSync = loadedFileVersion; qDebug("setting mLastAddressbookSync "); } #endif - #if 0 //qDebug("*************************** "); qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); - QPtrList<Incidence> er = remote->rawIncidences(); - Incidence* inR = er.first(); - Incidence* inL; + QStringList er = remote->uidList(); + Addressee inR ;//= er.first(); + Addressee inL; QProgressBar bar( er.count(),0 ); bar.setCaption (i18n("Syncing - close to abort!") ); int w = 300; if ( QApplication::desktop()->width() < 320 ) w = 220; int h = bar.sizeHint().height() ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); bar.show(); int modulo = (er.count()/10)+1; int incCounter = 0; - while ( inR ) { + while ( incCounter < er.count()) { if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); - ++incCounter; - uid = inR->uid(); + uid = er[ incCounter ]; bool skipIncidence = false; - if ( uid.left(15) == QString("last-syncAddressee-") ) + if ( uid.left(20) == QString("last-syncAddressee-") ) skipIncidence = true; QString idS; - qApp->processAddressees(); + qApp->processEvents(); if ( !skipIncidence ) { - inL = local->incidence( uid ); - if ( inL ) { // maybe conflict - same uid in both calendars - int maxrev = inL->revision(); - if ( maxrev < inR->revision() ) - maxrev = inR->revision(); - if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { - //qDebug("take %d %s ", take, inL->summary().latin1()); + inL = local->findByUid( uid ); + inR = remote->findByUid( uid ); + //inL.setResource( 0 ); + //inR.setResource( 0 ); + if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars + // pending if ( (take = takeAddressee( inL, inR, mode, fullDateRange )) > 0 ) { + if ( true ) { + //qDebug("take %d %s ", take, inL.summary().latin1()); if ( take == 3 ) return false; if ( take == 1 ) {// take local - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) - inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) ); + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); + local->insertAddressee( inL ); + } else - idS = inR->IDStr(); - remote->deleteIncidence( inR ); - if ( inL->revision() < maxrev ) - inL->setRevision( maxrev ); - inR = inL->clone(); - inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + idS = inR.IDStr(); + remote->removeAddressee( inR ); + inR = inL; + inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) - inR->setIDStr( idS ); - remote->addIncidence( inR ); + inR.setIDStr( idS ); + inR.setResource( 0 ); + remote->insertAddressee( inR ); ++changedRemote; } else { - if ( inR->revision() < maxrev ) - inR->setRevision( maxrev ); - idS = inL->IDStr(); - local->deleteIncidence( inL ); - inL = inR->clone(); - inL->setIDStr( idS ); - local->addIncidence( inL ); + idS = inL.IDStr(); + local->removeAddressee( inL ); + inL = inR; + inL.setIDStr( idS ); + inL.setResource( 0 ); + local->insertAddressee( inL ); ++changedLocal; } } } else { // no conflict if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - QString des = addresseeLSync->description(); - QString pref = "e"; - if ( inR->type() == "Todo" ) - pref = "t"; - if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it - inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE ); - //remote->deleteIncidence( inR ); + QString des = addresseeLSync.note(); + QString pref = "a"; + if ( des.find(pref+ inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it + inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); ++deletedAddresseeR; } else { - inR->setLastModified( modifiedCalendar ); - inL = inR->clone(); - local->addIncidence( inL ); + inR.setRevision( modifiedCalendar ); + remote->insertAddressee( inR ); + inL = inR; + inL.setResource( 0 ); + local->insertAddressee( inL ); ++addedAddressee; } } else { - if ( inR->lastModified() > mLastAddressbookSync || mode == 5 ) { - inR->setLastModified( modifiedCalendar ); - local->addIncidence( inR->clone() ); + if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { + inR.setRevision( modifiedCalendar ); + remote->insertAddressee( inR ); + inR.setResource( 0 ); + local->insertAddressee( inR ); ++addedAddressee; } else { - checkExternSyncAddressee(addresseeRSyncSharp, inR); - remote->deleteIncidence( inR ); + // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); + remote->removeAddressee( inR ); ++deletedAddresseeR; } } } } - inR = er.next(); + ++incCounter; } - QPtrList<Incidence> el = local->rawIncidences(); - inL = el.first(); + er.clear(); + QStringList el = remote->uidList(); modulo = (el.count()/10)+1; bar.setCaption (i18n("Add / remove addressees") ); bar.setTotalSteps ( el.count() ) ; bar.show(); incCounter = 0; - - while ( inL ) { + while ( incCounter < el.count()) { - qApp->processAddressees(); + qApp->processEvents(); if ( ! bar.isVisible() ) return false; if ( incCounter % modulo == 0 ) bar.setProgress( incCounter ); - ++incCounter; - uid = inL->uid(); + uid = el[ incCounter ]; bool skipIncidence = false; - if ( uid.left(15) == QString("last-syncAddressee-") ) + if ( uid.left(20) == QString("last-syncAddressee-") ) skipIncidence = true; - if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" ) + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) skipIncidence = true; if ( !skipIncidence ) { - inR = remote->incidence( uid ); - if ( ! inR ) { + inL = local->findByUid( uid ); + inR = remote->findByUid( uid ); + if ( inR.isEmpty() ) { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { - if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { - checkExternSyncAddressee(addresseeLSyncSharp, inL); - local->deleteIncidence( inL ); + if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { + // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->removeAddressee( inL ); ++deletedAddresseeL; } else { - if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { - inL->removeID(mCurrentSyncDevice ); + if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { + inL.removeID(mCurrentSyncDevice ); ++addedAddresseeR; - //qDebug("remote added Incidence %s ", inL->summary().latin1()); - inL->setLastModified( modifiedCalendar ); - inR = inL->clone(); - inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); - remote->addIncidence( inR ); + //qDebug("remote added Incidence %s ", inL.summary().latin1()); + inL.setRevision( modifiedCalendar ); + local->insertAddressee( inL ); + inR = inL; + inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + inR.setResource( 0 ); + remote->insertAddressee( inR ); } } } else { - if ( inL->lastModified() < mLastAddressbookSync && mode != 4 ) { - checkExternSyncAddressee(addresseeLSyncSharp, inL); - local->deleteIncidence( inL ); + if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { + // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); + local->removeAddressee( inL ); ++deletedAddresseeL; } else { - if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { + if ( ! KABPrefs::instance()->mWriteBackExistingOnly ) { ++addedAddresseeR; - inL->setLastModified( modifiedCalendar ); - remote->addIncidence( inL->clone() ); + inL.setRevision( modifiedCalendar ); + local->insertAddressee( inL ); + inR = inL; + inR.setResource( 0 ); + remote->insertAddressee( inR ); } } } } } - inL = el.next(); + ++incCounter; } + el.clear(); int delFut = 0; - if ( KOPrefs::instance()->mWriteBackInFuture ) { - er = remote->rawIncidences(); - inR = er.first(); - QDateTime dt; - QDateTime cur = QDateTime::currentDateTime(); - QDateTime end = cur.addSecs( KOPrefs::instance()->mWriteBackInFuture * 3600 *24 *7 ); - while ( inR ) { - if ( inR->type() == "Todo" ) { - Todo * t = (Todo*)inR; - if ( t->hasDueDate() ) - dt = t->dtDue(); - else - dt = cur.addSecs( 62 ); - } - else if (inR->type() == "Addressee" ) { - bool ok; - dt = inR->getNextOccurence( cur, &ok ); - if ( !ok ) - dt = cur.addSecs( -62 ); - } - else - dt = inR->dtStart(); - if ( dt < cur || dt > end ) { - remote->deleteIncidence( inR ); - ++delFut; - } - inR = er.next(); - } - } + + #if 0 + bar.hide(); mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); - addresseeLSync->setReadOnly( false ); - addresseeLSync->setDtStart( mLastAddressbookSync ); - addresseeRSync->setDtStart( mLastAddressbookSync ); - addresseeLSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); - addresseeRSync->setDtEnd( mLastAddressbookSync.addSecs( 3600 ) ); - addresseeRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; - addresseeLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); - addresseeLSync->setReadOnly( true ); + addresseeLSync.setRevision( mLastAddressbookSync ); + addresseeRSync.setRevision( mLastAddressbookSync ); + addresseeRSync.setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; + addresseeLSync.setLocation(i18n("Local from: ") + mCurrentSyncName ); + addresseeLSync.setReadOnly( true ); if ( mGlobalSyncMode == SYNC_MODE_NORMAL) remote->addAddressee( addresseeRSync ); QString mes; 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 ); QString delmess; if ( delFut ) { 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 ); mes += delmess; |