author | zautrix <zautrix> | 2004-10-13 13:18:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-13 13:18:51 (UTC) |
commit | d41893fb0a49fbb080326a4c1fd98e1a032a182a (patch) (side-by-side diff) | |
tree | 9b95603ff93801accaa94de4b73d88ea9c5c9386 | |
parent | efdd0735bda81dcd82dfb6d6dc0d0c143f249336 (diff) | |
download | kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.zip kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.gz kdepimpi-d41893fb0a49fbb080326a4c1fd98e1a032a182a.tar.bz2 |
merge contact fixes
-rw-r--r-- | kabc/addressbook.cpp | 8 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 48 | ||||
-rw-r--r-- | kabc/addressee.h | 2 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 6 |
5 files changed, 51 insertions, 17 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 19c26eb..8882259 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -858,25 +858,25 @@ 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 ) +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 ); + mergeAB( aBook ,csd, isSubset ); } void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) { //qDebug("AddressBook::postExternSync "); AddressBook::Iterator it; for ( it = begin(); it != end(); ++it ) { // qDebug("check uid %s ", (*it).uid().latin1() ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || @@ -908,24 +908,24 @@ Addressee AddressBook::findByExternUid( const QString& uid , const QString& pr { 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 ) +void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) { Iterator it; Addressee ad; for ( it = begin(); it != end(); ++it ) { ad = aBook->findByExternUid( (*it).externalUID(), profile ); if ( !ad.isEmpty() ) { - (*it).mergeContact( ad ); + (*it).mergeContact( ad ,isSubset); } } #if 0 // test only for ( it = begin(); it != end(); ++it ) { qDebug("uid %s ", (*it).uid().latin1()); } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index df9048b..a6bf451 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -296,21 +296,21 @@ class AddressBook : public QObject */ void cleanUp(); // sync stuff //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); void removeSyncAddressees( bool removeDeleted = false ); - void mergeAB( AddressBook *aBook, const QString& profile ); + 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 ); + void preExternSync( AddressBook* aBook, const QString& csd, bool isSubset ); void postExternSync( AddressBook* aBook, const QString& csd ); signals: /** Emitted, when the address book has changed on disk. */ void addressBookChanged( AddressBook * ); /** diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 2aca559..295ee4f 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -294,49 +294,48 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; QStringList t; QStringList tAD; uint iii; - if ( isSubSet ) { + // ********** phone numbers PhoneNumber::List phoneAD = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItAD; for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { bool found = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( ( *phoneItAD ).contains( (*it) ) ) { found = true; (*it).setType( ( *phoneItAD ).type() ); break; } } - if ( ! found ) + if ( isSubSet && ! found ) mData->phoneNumbers.append( *phoneItAD ); } + if ( isSubSet ) { // ************* emails; t = mData->emails; tAD = ad.mData->emails; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->emails.append( tAD[iii] ); + } + // ************* categories; t = mData->categories; tAD = ad.mData->categories; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->categories.append( tAD[iii] ); - - - } - QStringList::ConstIterator it; for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { QString qualifiedName = (*it).left( (*it).find( ":" )); bool found = false; QStringList::ConstIterator itL; for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { if ( (*itL).startsWith( qualifiedName ) ) { found = true; @@ -384,17 +383,17 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) ++addressIter ) { if ( (*addressIter) == (*addressIterA)) { found = true; (*addressIter).setType( (*addressIterA).type() ); break; } } - if ( ! found ) { + if ( isSubSet && ! found ) { mData->addresses.append( *addressIterA ); } } //qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } @@ -473,18 +472,53 @@ void Addressee::simplifyEmails() QString email = mData->emails.first(); detach(); mData->emails.clear(); mData->emails.append( email ); } void Addressee::simplifyPhoneNumbers() { + int max = 4; + int inList = mData->phoneNumbers.count(); KABC::PhoneNumber::List removeNumbers; KABC::PhoneNumber::List::Iterator phoneIter; + if ( inList > max ) { + // delete non-preferred numbers + for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); + ++phoneIter ) { + if ( inList > max ) { + if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { + removeNumbers.append( ( *phoneIter ) ); + --inList; + } + } else + break; + } + for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); + ++phoneIter ) { + removePhoneNumber(( *phoneIter )); + } + // delete preferred numbers + if ( inList > max ) { + for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); + ++phoneIter ) { + if ( inList > max ) { + removeNumbers.append( ( *phoneIter ) ); + --inList; + } else + break; + } + for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); + ++phoneIter ) { + removePhoneNumber(( *phoneIter )); + } + } + } + // remove non-numeric characters for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { if ( ! ( *phoneIter ).simplifyNumber() ) removeNumbers.append( ( *phoneIter ) ); } for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); ++phoneIter ) { removePhoneNumber(( *phoneIter )); diff --git a/kabc/addressee.h b/kabc/addressee.h index e7900c6..2c81c1a 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -111,17 +111,17 @@ class Addressee /** Return, if the address book entry is empty. */ bool isEmpty() const; void setExternalUID( const QString &id ); QString externalUID() const; void setOriginalExternalUID( const QString &id ); QString originalExternalUID() const; - void mergeContact( const Addressee& ad, bool isSubSet = false ); + void mergeContact( const Addressee& ad, bool isSubSet ); void simplifyEmails(); void simplifyAddresses(); void simplifyPhoneNumbers(); void simplifyPhoneNumberTypes(); bool removeVoice(); bool containsAdr(const Addressee& addr ); /** diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 205dbc8..ea34be2 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2727,17 +2727,17 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) bool syncOK = false; if ( abLocal.load() ) { qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); bool external = false; bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; isXML = true; - abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice, true ); } else { external = !manager->mIsKapiFile; 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() ); @@ -2782,17 +2782,17 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) return syncPhone(); 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 ); + 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 ); } } @@ -2824,17 +2824,17 @@ 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 ); + 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 ); |