-rw-r--r-- | kabc/addressee.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index e241281..31ce1d6 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -30,32 +30,34 @@ $Id$ #include <ksharedptr.h> #include <kdebug.h> #include <kapplication.h> #include <klocale.h> #include <kidmanager.h> //US #include <kstandarddirs.h> #include <libkcal/syncdefines.h> //US #include "resource.h" #include "addressee.h" using namespace KABC; static bool matchBinaryPattern( int value, int pattern ); +static bool matchBinaryPatternA( int value, int pattern ); +static bool matchBinaryPatternP( int value, int pattern ); struct Addressee::AddresseeData : public KShared { QString uid; QString name; QString formattedName; QString familyName; QString givenName; QString additionalName; QString prefix; QString suffix; QString nickName; QDateTime birthday; QString mailer; TimeZone timeZone; Geo geo; @@ -368,46 +370,46 @@ void Addressee::setExternalUID( const QString &id ) { if ( id == mData->externalUID ) return; detach(); mData->empty = false; mData->externalUID = id; } QString Addressee::externalUID() const { return mData->externalUID; } void Addressee::setOriginalExternalUID( const QString &id ) { if ( id == mData->originalExternalUID ) return; detach(); mData->empty = false; - qDebug("*******Set orig uid %s ", id.latin1()); + //qDebug("*******Set orig uid %s ", id.latin1()); mData->originalExternalUID = id; } QString Addressee::originalExternalUID() const { return mData->originalExternalUID; } void Addressee::setUid( const QString &id ) { if ( id == mData->uid ) return; detach(); - qDebug("****setuid %s ", id.latin1()); + //qDebug("****setuid %s ", id.latin1()); mData->empty = false; mData->uid = id; } QString Addressee::uid() const { if ( mData->uid.isEmpty() ) mData->uid = KApplication::randomString( 10 ); return mData->uid; } QString Addressee::uidLabel() { return i18n("Unique Identifier"); } @@ -1277,33 +1279,33 @@ void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber ) detach(); PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { mData->phoneNumbers.remove( it ); return; } } } PhoneNumber Addressee::phoneNumber( int type ) const { PhoneNumber phoneNumber( "", type ); PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { - if ( matchBinaryPattern( (*it).type(), type ) ) { + if ( matchBinaryPatternP( (*it).type(), type ) ) { if ( (*it).type() & PhoneNumber::Pref ) return (*it); else if ( phoneNumber.number().isEmpty() ) phoneNumber = (*it); } } return phoneNumber; } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } PhoneNumber::List Addressee::phoneNumbers( int type ) const @@ -1514,33 +1516,33 @@ void Addressee::removeAddress( const Address &address ) detach(); Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == address.id() ) { mData->addresses.remove( it ); return; } } } Address Addressee::address( int type ) const { Address address( type ); Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { - if ( matchBinaryPattern( (*it).type(), type ) ) { + if ( matchBinaryPatternA( (*it).type(), type ) ) { if ( (*it).type() & Address::Pref ) return (*it); else if ( address.isEmpty() ) address = (*it); } } return address; } Address::List Addressee::addresses() const { return mData->addresses; } Address::List Addressee::addresses( int type ) const @@ -1822,30 +1824,46 @@ QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) s >> a.mData->secrecy; s >> a.mData->logo; s >> a.mData->photo; s >> a.mData->sound; s >> a.mData->agent; s >> a.mData->phoneNumbers; s >> a.mData->addresses; s >> a.mData->emails; s >> a.mData->categories; s >> a.mData->custom; s >> a.mData->keys; a.mData->empty = false; return s; } - bool matchBinaryPattern( int value, int pattern ) { /** We want to match all telephonnumbers/addresses which have the bits in the pattern set. More are allowed. if pattern == 0 we have a special handling, then we want only those with exactly no bit set. */ if ( pattern == 0 ) return ( value == 0 ); else return ( pattern == ( pattern & value ) ); } + +bool matchBinaryPatternP( int value, int pattern ) +{ + + if ( pattern == 0 ) + return ( value == 0 ); + else + return ( (pattern |PhoneNumber::Pref ) == ( value |PhoneNumber::Pref ) ); +} +bool matchBinaryPatternA( int value, int pattern ) +{ + + if ( pattern == 0 ) + return ( value == 0 ); + else + return ( (pattern | Address::Pref) == ( value | Address::Pref ) ); +} |