-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 @@ -14,64 +14,66 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kconfig.h> #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; QString title; QString role; QString organization; QString note; QString productId; QDateTime revision; QString sortString; QString externalUID; QString originalExternalUID; KURL url; Secrecy secrecy; Picture logo; Picture photo; Sound sound; Agent agent; QString mExternalId; @@ -352,78 +354,78 @@ QString Addressee::getCsum( const QString & prof) { return KIdManager::getCsum ( mData->mExternalId, prof ); } void Addressee::setIDStr( const QString & s ) { detach(); mData->mExternalId = s; } QString Addressee::IDStr() const { return mData->mExternalId; } 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"); } void Addressee::setName( const QString &name ) { if ( name == mData->name ) return; detach(); mData->empty = false; mData->name = name; } QString Addressee::name() const { return mData->name; } QString Addressee::nameLabel() { @@ -1261,65 +1263,65 @@ void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber ) { detach(); mData->empty = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == phoneNumber.id() ) { *it = phoneNumber; return; } } mData->phoneNumbers.append( phoneNumber ); } 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 { PhoneNumber::List list; PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } PhoneNumber Addressee::findPhoneNumber( const QString &id ) const { PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { @@ -1498,65 +1500,65 @@ void Addressee::insertAddress( const Address &address ) { detach(); mData->empty = false; Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( (*it).id() == address.id() ) { *it = address; return; } } mData->addresses.append( address ); } 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 { Address::List list; Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } Address Addressee::findAddress( const QString &id ) const { Address::List::ConstIterator it; @@ -1806,46 +1808,62 @@ QDataStream &KABC::operator>>( QDataStream &s, Addressee &a ) s >> a.mData->additionalName; s >> a.mData->prefix; s >> a.mData->suffix; s >> a.mData->nickName; s >> a.mData->birthday; s >> a.mData->mailer; s >> a.mData->timeZone; s >> a.mData->geo; s >> a.mData->title; s >> a.mData->role; s >> a.mData->organization; s >> a.mData->note; s >> a.mData->productId; s >> a.mData->revision; s >> a.mData->sortString; s >> a.mData->url; 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 ) ); +} |