-rw-r--r-- | kabc/addressee.cpp | 82 |
1 files changed, 58 insertions, 24 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 2aca559..295ee4f 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -278,81 +278,80 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) 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() ) if ( ad.mData->birthday.isValid()) mData->birthday = ad.mData->birthday; if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; 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; - } + + // ********** 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 ) - mData->phoneNumbers.append( *phoneItAD ); } + 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] ); - - } + // ************* 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; break; } } if ( ! found ) { mData->custom.append( *it ); } } if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; if ( !mData->sound.isIntern() ) { if ( mData->sound.url().isEmpty() ) { mData->sound = ad.mData->sound; } } if ( !mData->agent.isIntern() ) { if ( mData->agent.url().isEmpty() ) { @@ -368,49 +367,49 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) if ( (*it) == (*itA)) { found = true; break; } } if ( ! found ) { mData->keys.append( *itA ); } } } KABC::Address::List::Iterator addressIterA; for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { bool found = false; KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++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() ); } 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; @@ -457,50 +456,85 @@ void Addressee::simplifyAddresses() 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 ) ); } for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); ++phoneIter ) { removePhoneNumber(( *phoneIter )); } } void Addressee::simplifyPhoneNumberTypes() { KABC::PhoneNumber::List::Iterator phoneIter; for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) ( *phoneIter ).simplifyType(); } void Addressee::removeID(const QString &prof) { detach(); mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); } void Addressee::setID( const QString & prof , const QString & id ) |