author | zautrix <zautrix> | 2004-09-19 20:27:44 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-19 20:27:44 (UTC) |
commit | 3da2cfeab2edbe64a17251662e56668fe143f7a3 (patch) (side-by-side diff) | |
tree | 37e8d4445fca84bd4e93af38c96c5c489f9cbca8 | |
parent | afa28a62314117555d6b32291188eedd1a576284 (diff) | |
download | kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.zip kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.tar.gz kdepimpi-3da2cfeab2edbe64a17251662e56668fe143f7a3.tar.bz2 |
more AB sync
-rw-r--r-- | kabc/addressbook.cpp | 32 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 25 |
3 files changed, 37 insertions, 23 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 64832f1..86dc7c2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -593,24 +593,56 @@ AddressBook::Iterator AddressBook::find( const Addressee &a ) } Addressee AddressBook::findByUid( const QString &uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } +void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) +{ + qDebug("AddressBook::preExternSync "); + AddressBook::Iterator it; + for ( it = begin(); it != end(); ++it ) { + (*it).setID( csd, (*it).externalUID() ); + (*it).computeCsum( csd ); + } + mergeAB( aBook ,csd ); +} +void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) +{ + qDebug("AddressBook::postExternSync "); + AddressBook::Iterator it; + for ( it = begin(); it != end(); ++it ) { + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || + (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { + Addressee ad = aBook->findByUid( ( (*it).uid() )); + if ( ad.isEmpty() ) { + qDebug("ERROR ad empty "); + } else { + (*it).computeCsum( csd ); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) + ad.setID( csd, (*it).externalUID() ); + ad.setCsum( csd, (*it).getCsum( csd ) ); + aBook->insertAddressee( ad ); + } + } + } +} + + Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).getID( profile ) ) return (*it); } return Addressee(); } void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) { Iterator it; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f40e015..157dc56 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -286,24 +286,27 @@ class AddressBook : public QObject /** Query all resources to clean up their lock files */ void cleanUp(); // sync stuff //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); void removeDeletedAddressees(); void mergeAB( AddressBook *aBook, const QString& profile ); Addressee findByExternUid( const QString& uid , const QString& profile ); + + void preExternSync( AddressBook* aBook, const QString& csd ); + void postExternSync( AddressBook* aBook, const QString& csd ); signals: /** Emitted, when the address book has changed on disk. */ void addressBookChanged( AddressBook * ); /** Emitted, when the address book has been locked for writing. */ void addressBookLocked( AddressBook * ); /** diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index b3d88de..8f3ca9b 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2919,31 +2919,25 @@ bool KABCore::syncAB(QString filename, int mode) //pending prepare addresseeview for output //pending detect, if remote file has REV field. if not switch to external sync mGlobalSyncMode = SYNC_MODE_NORMAL; AddressBook abLocal(filename,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; - AddressBook::Iterator it; - for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - (*it).setID( mCurrentSyncDevice, (*it).externalUID() ); - (*it).computeCsum( mCurrentSyncDevice ); - } - abLocal.mergeAB( mAddressBook ,mCurrentSyncDevice ); - + abLocal.preExternSync( 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; @@ -2969,40 +2963,25 @@ bool KABCore::syncAB(QString filename, int mode) // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( KABPrefs::instance()->mWriteBackFile ) { 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 ); - } - } - } + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; #if 0 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |