-rw-r--r-- | kabc/addressee.cpp | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 6cfac80..e8e440c 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -27,16 +27,17 @@ $Id$ */ #include <kconfig.h> #include <ksharedptr.h> #include <kdebug.h> #include <kapplication.h> #include <klocale.h> +#include <kmessagebox.h> #include <kidmanager.h> //US #include <kstandarddirs.h> #include <libkcal/syncdefines.h> //US #include "resource.h" #include "addressee.h" @@ -206,17 +207,17 @@ ulong Addressee::getCsum4List( const QStringList & attList) return cSum; } void Addressee::computeCsum(const QString &dev) { QStringList l; //if ( !mData->name.isEmpty() ) l.append(mData->name); - //if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); + if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); if ( !mData->additionalName.isEmpty() ) l.append( mData->additionalName ); if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); @@ -327,16 +328,63 @@ bool Addressee::matchPhoneNumber( QRegExp* re ) const if (re->match( (*phoneIter).number() ) == 0) #endif return true; } return false; } +void Addressee::mergeOLContact( const Addressee& ad ) +{ + if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; + 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->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() ) { + mData->agent = ad.mData->agent; + } + } + { + Key::List::Iterator itA; + for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { + bool found = false; + Key::List::Iterator it; + for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { + if ( (*it) == (*itA)) { + found = true; + break; + + } + } + if ( ! found ) { + mData->keys.append( *itA ); + } + } + } + + KABC::Address addthis = otherAddress(); + KABC::Address addother = ad.otherAddress(); + if ( !addthis.isEmpty() && !addother.isEmpty() ) + addthis.setType( addother.type() ); + //qDebug("merge contact %s ", ad.uid().latin1()); + setUid( ad.uid() ); + setRevision( ad.revision() ); + + +} + void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) { // merge all standard non-outlook fields. //if isSubSet (e.g. mobile phone sync) merge all fields detach(); if ( isSubSet ) { if ( mData->name.isEmpty() ) mData->name = ad.mData->name; @@ -1648,17 +1696,16 @@ QStringList Addressee::emails() const void Addressee::setEmails( const QStringList& emails ) { detach(); mData->emails = emails; } 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 ); @@ -1715,16 +1762,27 @@ PhoneNumber::List Addressee::phoneNumbers( int type ) const PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( matchBinaryPattern( (*it).type(), type ) ) { list.append( *it ); } } return list; } +QString Addressee::phoneNumberString( int type ) const +{ + + PhoneNumber::List::ConstIterator it; + for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { + if ((*it).type() == type ) { + return ( *it ).number(); + } + } + return ""; +} PhoneNumber Addressee::findPhoneNumber( const QString &id ) const { PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).id() == id ) { return *it; } @@ -1920,17 +1978,28 @@ void Addressee::removeAddress( const Address &address ) 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::otherAddress() const +{ + Address::List::ConstIterator it; + for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { + if ( matchBinaryPatternA( (*it).type(), KABC::Address::Work ) ) + continue; + if ( matchBinaryPatternA( (*it).type(), KABC::Address::Home ) ) + continue; + return (*it); + } + return Address(); +} Address Addressee::address( int type ) const { Address address( type ); Address::List::ConstIterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( matchBinaryPatternA( (*it).type(), type ) ) { if ( (*it).type() & Address::Pref ) return (*it); |