-rw-r--r-- | kabc/addressee.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 295ee4f..2564894 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -386,135 +386,153 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) (*addressIter).setType( (*addressIterA).type() ); break; } } if ( isSubSet && ! found ) { mData->addresses.append( *addressIterA ); } } //qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } bool Addressee::removeVoice() { PhoneNumber::List phoneN = phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found if ((*phoneIt).type() - PhoneNumber::Voice ) { (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); insertPhoneNumber( (*phoneIt) ); found = true; } } } return found; } bool Addressee::containsAdr(const Addressee& ad ) { if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; // compare phone numbers PhoneNumber::List phoneN = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { bool found = false; PhoneNumber::List phoneL = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItL; for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { found = true; break; } } if ( ! found ) return false; } return true; } void Addressee::simplifyAddresses() { + + + Address::List list; + Address::List::Iterator it; + Address::List::Iterator it2; + for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { + it2 = it; + ++it2; + for( ; it2 != mData->addresses.end(); ++it2 ) { + if ( (*it) == (*it2) ) { + list.append( *it ); + break; + } + } + } + for( it = list.begin(); it != list.end(); ++it ) { + removeAddress( (*it) ); + } + + list.clear(); int max = 2; if ( mData->url.isValid() ) max = 1; if ( mData->addresses.count() <= max ) return ; int count = 0; - Address::List list; - Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( count >= max ) list.append( *it ); ++count; } for( it = list.begin(); it != list.end(); ++it ) { removeAddress( (*it) ); } } // removes all emails but the first // needed by phone sync void Addressee::simplifyEmails() { if ( mData->emails.count() == 0 ) return ; 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 ) ); |