-rw-r--r-- | kabc/addressbook.cpp | 19 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 16 |
4 files changed, 26 insertions, 13 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 9b196b5..5774c36 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -861,32 +861,39 @@ void AddressBook::removeSyncAddressees( bool removeDeleted ) Iterator it2 ; QDateTime dt ( QDate( 2004,1,1) ); while ( it != end() ) { (*it).setRevision( dt ); if (( *it).IDStr() != "changed" ) { // "changed" is used for tagging changed addressees when syncing with KDE or OL (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr(""); } if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { it2 = it; //qDebug("removing %s ",(*it).uid().latin1() ); ++it; removeAddressee( it2 ); } else { //qDebug("skipping %s ",(*it).uid().latin1() ); + if ( removeDeleted ) { + // we have no postprocessing in the resource, we have to do it here + // we have to compute csum for all, because it could be the first sync + (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); + + + } ++it; } } deleteRemovedAddressees(); } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); d->mAddressees.remove( it.d->mIt ); } AddressBook::Iterator AddressBook::find( const Addressee &a ) { Iterator it; for ( it = begin(); it != end(); ++it ) { @@ -904,47 +911,51 @@ Addressee AddressBook::findByUid( const QString &uid ) if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) { //qDebug("AddressBook::preExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setID( csd, (*it).externalUID() ); (*it).computeCsum( csd ); } mergeAB( aBook ,csd, isSubset ); } -void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) +void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) { //qDebug("AddressBook::postExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { - // qDebug("check uid %s ", (*it).uid().latin1() ); + //qDebug("check uid %s ", (*it).uid().latin1() ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { Addressee ad = aBook->findByUid( ( (*it).uid() )); if ( ad.isEmpty() ) { qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); } else { + (*it).setIDStr(":"); (*it).computeCsum( csd ); - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) - ad.setID( csd, (*it).externalUID() ); + if ( setID ) { + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) + ad.setID( csd, (*it).externalUID() ); + } else + ad.setID( csd, "_" ); ad.setCsum( csd, (*it).getCsum( csd ) ); aBook->insertAddressee( ad ); } } } } bool AddressBook::containsExternalUid( const QString& uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).externalUID( ) ) return true; } return false; } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f124dc9..75f8b51 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -294,33 +294,33 @@ 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 removeSyncAddressees( bool removeDeleted = false ); void mergeAB( AddressBook *aBook, const QString& profile, bool isSubset ); Addressee findByExternUid( const QString& uid , const QString& profile ); bool containsExternalUid( const QString& uid ); void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); - void postExternSync( AddressBook* aBook, const QString& csd ); + void postExternSync( AddressBook* aBook, const QString& csd , bool setID ); 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 * ); /** Emitted, when the address book has been unlocked. */ void addressBookUnlocked( AddressBook * ); diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index a660a9d..d5a110a 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -253,33 +253,33 @@ void Addressee::computeCsum(const QString &dev) t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->custom; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { t = (*addressIter).asList(); t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); } uint cs = getCsum4List(l); - // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); + //qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); setCsum( dev, QString::number (cs )); } void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) { detach(); if ( mData->name.isEmpty() ) mData->name = ad.mData->name; if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; if ( !mData->birthday.isValid() ) diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index ea87929..b0cb986 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2500,38 +2500,38 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo QString mCurrentSyncName = syncManager->getCurrentSyncName(); QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); //QPtrList<Addressee> el = local->rawAddressees(); Addressee addresseeR; QString uid; int take; Addressee addresseeL; Addressee addresseeRSync; Addressee addresseeLSync; // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); bool fullDateRange = false; local->resetTempSyncStat(); mLastAddressbookSync = QDateTime::currentDateTime(); if ( syncManager->syncWithDesktop() ) { - remote->removeSyncInfo( QString());//remove all info + // remote->removeSyncInfo( QString());//remove all info if ( KSyncManager::mRequestedSyncEvent.isValid() ) { mLastAddressbookSync = KSyncManager::mRequestedSyncEvent; qDebug("using extern time for calendar sync: %s ", mLastAddressbookSync.toString().latin1() ); } else { - qDebug("ERROR: KSyncManager::mRequestedSyncEvent has invalid datatime "); + qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime "); } } QDateTime modifiedCalendar = mLastAddressbookSync; addresseeLSync = getLastSyncAddressee(); qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); if ( !addresseeR.isEmpty() ) { addresseeRSync = addresseeR; remote->removeAddressee(addresseeR ); } else { if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { addresseeRSync = addresseeLSync ; } else { qDebug("FULLDATE 1"); fullDateRange = true; @@ -2607,33 +2607,34 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); inL.setID( mCurrentSyncDevice, inR.getID(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 ) { inR.setOriginalExternalUID( OidS ); inR.setExternalUID( idS ); if ( syncManager->syncWithDesktop() ) - inR.setIDStr( "changed" ); + inR.setIDStr("changed" ); + //inR.insertCustom( "KADDRESSBOOK", "X-KDESYNC","changed" ); } else { inR.setIDStr( idS ); } inR.setResource( 0 ); remote->insertAddressee( inR , false); ++changedRemote; } else { // take == 2 take remote if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { if ( inR.revision().date().year() < 2004 ) inR.setRevision( modifiedCalendar ); } idS = inL.IDStr(); local->removeAddressee( inL ); inL = inR; inL.setIDStr( idS ); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { @@ -2799,73 +2800,74 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); if ( ! abLocal.saveAB()) qDebug("Error writing back AB to file "); - if ( isXML ) { + if ( external ) { // afterwrite processing - abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ,isXML); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } void KABCore::removeSyncInfo( QString syncProfile) { qDebug("AB:removeSyncInfo for profile %s ", syncProfile.latin1()); mAddressBook->removeSyncInfo( syncProfile ); + setModified(); } //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { if ( resource == "phone" ) return syncPhone(); disableBR( true ); QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, false ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( false ); abLocal.saveAB(); - abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); disableBR( false ); return syncOK; } void KABCore::message( QString m ) { topLevelWidget()->setCaption( m ); mMessageTimer->start( 15000, true ); } bool KABCore::syncPhone() @@ -2878,33 +2880,33 @@ bool KABCore::syncPhone() } AddressBook abLocal( fileName,"syncContact"); bool syncOK = false; { abLocal.importFromFile( fileName ); qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preparePhoneSync( mCurrentSyncDevice, true ); abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.removeSyncAddressees( true ); abLocal.saveABphone( fileName ); abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); - abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); + abLocal.postExternSync( mAddressBook,mCurrentSyncDevice, true ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } void KABCore::getFile( bool success ) { if ( ! success ) { message( i18n("Error receiving file. Nothing changed!") ); return; } int count = mAddressBook->importFromFile( sentSyncFile() , false, true ); if ( count ) |