-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 @@ -3,64 +3,65 @@ This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 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 <kmessagebox.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; @@ -182,65 +183,65 @@ ulong Addressee::getCsum4List( const QStringList & attList) { int max = attList.count(); ulong cSum = 0; int j,k,i; int add; for ( i = 0; i < max ; ++i ) { QString s = attList[i]; if ( ! s.isEmpty() ){ j = s.length(); for ( k = 0; k < j; ++k ) { int mul = k +1; add = s[k].unicode (); if ( k < 16 ) mul = mul * mul; int ii = i+1; add = add * mul *ii*ii*ii; cSum += add; //qDebug("csum: %d %d %d", i,k,cSum); } } } //QString dump = attList.join(","); //qDebug("csum: %d %s", cSum,dump.latin1()); 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 ); if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); if ( !mData->title .isEmpty() ) l.append( mData->title ); if ( !mData->role.isEmpty() ) l.append( mData->role ); if ( !mData->organization.isEmpty() ) l.append( mData->organization ); if ( !mData->note.isEmpty() ) l.append( mData->note ); if ( !mData->productId.isEmpty() ) l.append(mData->productId ); if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); if ( !mData->logo.undefined() ) { if ( !mData->logo.isIntern() ) l.append( mData->logo.url() ); else l.append( QString::number(mData->logo.data().width()* mData->logo.data().height())); } else { l.append( "nologo"); } if ( !mData->photo.undefined() ) { if ( !mData->photo.isIntern() ) l.append( mData->photo.url() ); else l.append( QString::number(mData->photo.data().width()* mData->photo.data().height())); } else { l.append( "nophoto"); @@ -303,64 +304,111 @@ void Addressee::computeCsum(const QString &dev) qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); #endif setCsum( dev, QString::number (cs )); } bool Addressee::matchAddress( QRegExp* re ) const { KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { if ( (*addressIter).matchAddress( re ) ) return true; } return false; } bool Addressee::matchPhoneNumber( QRegExp* re ) const { KABC::PhoneNumber::List::Iterator phoneIter; for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) { #if QT_VERSION >= 0x030000 if (re->search( (*phoneIter).number() ) == 0) #else 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; 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->title .isEmpty() ) mData->title = ad.mData->title ; if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; 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->productId.isEmpty() ) mData->productId = ad.mData->productId; if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; QStringList t; @@ -1624,65 +1672,64 @@ void Addressee::insertEmail( const QString &email, bool preferred ) } } } void Addressee::removeEmail( const QString &email ) { detach(); QStringList::Iterator it = mData->emails.find( email ); if ( it == mData->emails.end() ) return; mData->emails.remove( it ); } QString Addressee::preferredEmail() const { if ( mData->emails.count() == 0 ) return QString::null; else return mData->emails.first(); } QStringList Addressee::emails() const { return mData->emails; } 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 ); } 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 ( matchBinaryPatternP( (*it).type(), type ) ) { if ( (*it).type() & PhoneNumber::Pref ) return (*it); else if ( phoneNumber.number().isEmpty() ) @@ -1691,64 +1738,75 @@ PhoneNumber Addressee::phoneNumber( int type ) const } return phoneNumber; } PhoneNumber::List Addressee::phoneNumbers() const { return mData->phoneNumbers; } int Addressee::hasPhoneNumberType( int type ) { int retval = 0; PhoneNumber::List::ConstIterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( (*it).type() == type ) ++retval; } return retval; } 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; } +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; } } return PhoneNumber(); } void Addressee::insertKey( const Key &key ) { detach(); mData->empty = false; Key::List::Iterator it; for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { if ( (*it).id() == key.id() ) { *it = key; return; } } mData->keys.append( key ); } void Addressee::removeKey( const Key &key ) { detach(); Key::List::Iterator it; @@ -1896,65 +1954,76 @@ void Addressee::dump() const kdDebug(5700) << "}" << endl; #endif } 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::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); 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 ); } } |