From afa28a62314117555d6b32291188eedd1a576284 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 19 Sep 2004 20:14:28 +0000 Subject: more AB sync --- (limited to 'kaddressbook') diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index d6482fb..b3d88de 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2752,7 +2752,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo bool skipIncidence = false; if ( uid.left(19) == QString("last-syncAddressee-") ) skipIncidence = true; - QString idS; + QString idS,OidS; qApp->processEvents(); if ( !skipIncidence ) { inL = local->findByUid( uid ); @@ -2768,18 +2768,24 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); local->insertAddressee( inL, false ); + idS = inR.externalUID(); + OidS = inR.originalExternalUID(); } else idS = inR.IDStr(); remote->removeAddressee( inR ); inR = inL; inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); - if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL ) + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + inR.setOriginalExternalUID( OidS ); + inR.setExternalUID( idS ); + } else { inR.setIDStr( idS ); + } inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; - } else { + } else { // take == 2 take remote idS = inL.IDStr(); local->removeAddressee( inL ); inL = inR; @@ -2854,7 +2860,7 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo inL.setRevision( modifiedCalendar ); local->insertAddressee( inL, false ); inR = inL; - inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); + inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); inR.setResource( 0 ); remote->insertAddressee( inR, false ); } @@ -2919,47 +2925,76 @@ bool KABCore::syncAB(QString filename, int mode) if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; - Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); - if ( ! lse.isEmpty() ) { - if ( lse.familyName().left(4) == "!E: " ) - external = true; - } else { - bool found = false; - QDateTime dt( QDate( 2004,1,1)); - AddressBook::Iterator it; - for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - if ( (*it).revision() != dt ) { - found = true; - break; - } - } - external = ! found; - } - if ( external ) { - qDebug("Setting vcf mode to external "); + if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - (*it).setID( mCurrentSyncDevice, (*it).uid() ); + (*it).setID( mCurrentSyncDevice, (*it).externalUID() ); (*it).computeCsum( mCurrentSyncDevice ); } + abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); + + } else { + Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); + if ( ! lse.isEmpty() ) { + if ( lse.familyName().left(4) == "!E: " ) + external = true; + } else { + bool found = false; + QDateTime dt( QDate( 2004,1,1)); + AddressBook::Iterator it; + for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { + if ( (*it).revision() != dt ) { + found = true; + break; + } + } + external = ! found; + } + + if ( external ) { + qDebug("Setting vcf mode to external "); + mGlobalSyncMode = SYNC_MODE_EXTERNAL; + AddressBook::Iterator it; + for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { + (*it).setID( mCurrentSyncDevice, (*it).uid() ); + (*it).computeCsum( mCurrentSyncDevice ); + } + } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} - if ( filename.right(4) == ".xml") - abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { - if ( external ) + if ( external && filename.right(4) != ".xml") abLocal.removeDeletedAddressees(); qDebug("Saving remote AB "); abLocal.saveAB(); + if ( external && filename.right(4) == ".xml") { + // afterwrite processing + AddressBook::Iterator it; + for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || + (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { + Addressee ad = mAddressBook->findByUid( ( (*it).uid() )); + if ( ad.isEmpty() ) { + qDebug("ERROR ad empty "); + } else { + (*it).computeCsum( mCurrentSyncDevice ); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) + ad.setID( mCurrentSyncDevice, (*it).externalUID() ); + ad.setCsum( mCurrentSyncDevice, (*it).getCsum( mCurrentSyncDevice ) ); + mAddressBook->insertAddressee( ad ); + } + } + } + } } } setModified(); -- cgit v0.9.0.2