-rw-r--r-- | kabc/addressee.cpp | 32 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 23 | ||||
-rw-r--r-- | kabc/phonenumber.h | 2 |
4 files changed, 61 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 25c77f6..e571980 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -315,6 +315,38 @@ void Addressee::mergeContact( const Addressee& ad ) setRevision( ad.revision() ); } +// 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() +{ + KABC::PhoneNumber::List removeNumbers; + KABC::PhoneNumber::List::Iterator phoneIter; + 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(); diff --git a/kabc/addressee.h b/kabc/addressee.h index 8baa888..4cafa86 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -117,6 +117,10 @@ class Addressee void setOriginalExternalUID( const QString &id ); QString originalExternalUID() const; void mergeContact( const Addressee& ad ); + void simplifyEmails(); + void simplifyPhoneNumbers(); + void simplifyPhoneNumberTypes(); + /** Set unique identifier. */ diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 7aeb2ee..e5abc0e 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -66,6 +66,29 @@ bool PhoneNumber::operator!=( const PhoneNumber &p ) const return !( p == *this ); } +bool PhoneNumber::simplifyNumber() +{ + QString Number; + int i; + Number = mNumber.stripWhiteSpace (); + mNumber = ""; + if ( Number.at(0) == '+' ) + mNumber += "+"; + for ( i = 0; i < Number.length(); ++i) { + if ( Number.at(i).isDigit() ) + mNumber += Number.at(i); + } + return ( mNumber.length() > 0 ); +} +// make cellphone compatible +void PhoneNumber::simplifyType() +{ + if ( mType & Fax ) mType = Fax; + else if ( mType & Cell ) mType = Cell; + else if ( mType & Work ) mType = Work ; + else if ( mType & Home ) mType = Home; + else mType = Pref; +} void PhoneNumber::setId( const QString &id ) { mId = id; diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h index 1df344f..410a52f 100644 --- a/kabc/phonenumber.h +++ b/kabc/phonenumber.h @@ -148,6 +148,8 @@ class PhoneNumber @obsolete */ static QString label( int type ); + bool simplifyNumber(); + void simplifyType(); private: void init(); |