From ca8fcf3fd4dc068747d8f31e2189145b22853d55 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sat, 18 Sep 2004 14:22:10 +0000 Subject: more AB sync --- (limited to 'kaddressbook/kabcore.cpp') diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 53c63ff..f497541 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -33,12 +33,14 @@ $Id$ #include #include #include +#include #ifndef KAB_EMBEDDED #include #include #include #include +#include #include #include #include @@ -2597,12 +2599,11 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo } #endif - #if 0 //qDebug("*************************** "); qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); - QPtrList 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!") ); @@ -2616,182 +2617,159 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo 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 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; -- cgit v0.9.0.2