author | zautrix <zautrix> | 2005-08-22 15:42:41 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-08-22 15:42:41 (UTC) |
commit | 1d82d044bbdedd407f6d08305522187ffd256552 (patch) (side-by-side diff) | |
tree | 08f5651d72548b643ed012e5f6ad938b36d1ae3f /kabc | |
parent | f516a558e6d18982a54152b28ca3da78fe76e3fc (diff) | |
download | kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.zip kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.gz kdepimpi-1d82d044bbdedd407f6d08305522187ffd256552.tar.bz2 |
kapi search fix
-rw-r--r-- | kabc/address.cpp | 27 | ||||
-rw-r--r-- | kabc/address.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 25 | ||||
-rw-r--r-- | kabc/addressee.h | 4 |
4 files changed, 58 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp index 5ffe511..6151f9e 100644 --- a/kabc/address.cpp +++ b/kabc/address.cpp @@ -1,295 +1,322 @@ /* 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$ */ //US added kglobal.h #include <kglobal.h> #include <kapplication.h> #include <kdebug.h> #include <klocale.h> #include <ksimpleconfig.h> #include <kstandarddirs.h> #include <qfile.h> #include "address.h" using namespace KABC; QMap<QString, QString> Address::mISOMap; Address::Address() : mEmpty( true ), mType( 0 ) { mId = KApplication::randomString( 10 ); } Address::Address( int type ) : mEmpty( true ), mType( type ) { mId = KApplication::randomString( 10 ); } bool Address::operator==( const Address &a ) const { if ( mPostOfficeBox != a.mPostOfficeBox ) return false; if ( mExtended != a.mExtended ) return false; if ( mStreet != a.mStreet ) return false; if ( mLocality != a.mLocality ) return false; if ( mRegion != a.mRegion ) return false; if ( mPostalCode != a.mPostalCode ) return false; if ( mCountry != a.mCountry ) return false; if ( mLabel != a.mLabel ) return false; return true; } bool Address::operator!=( const Address &a ) const { return !( a == *this ); } bool Address::isEmpty() const { if ( mPostOfficeBox.isEmpty() && mExtended.isEmpty() && mStreet.isEmpty() && mLocality.isEmpty() && mRegion.isEmpty() && mPostalCode.isEmpty() && mCountry.isEmpty() && mLabel.isEmpty() ) { return true; } return false; } QStringList Address::asList() { QStringList result; if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); if ( ! mExtended.isEmpty())result.append(mExtended); if ( ! mStreet.isEmpty())result.append(mStreet); if ( ! mLocality.isEmpty() )result.append(mLocality); if ( ! mRegion.isEmpty())result.append(mRegion); if ( ! mPostalCode.isEmpty())result.append(mPostalCode); if ( ! mCountry.isEmpty())result.append(mCountry); if ( ! mLabel.isEmpty() )result.append(mLabel); return result; } + +bool Address::matchAddress( QRegExp* re ) const +{ + +#if QT_VERSION >= 0x030000 + if (re->search( mPostOfficeBox ) == 0) return true; + if (re->search( mExtended ) == 0) return true; + if (re->search( mStreet ) == 0) return true; + if (re->search( mLocality ) == 0) return true; + if (re->search( mRegion ) == 0) return true; + if (re->search( mPostalCode ) == 0) return true; + if (re->search( mCountry ) == 0) return true; + if (re->search( mLabel ) == 0) return true; +#else + if (re->match( mPostOfficeBox ) == 0) return true; + if (re->match( mExtended ) == 0) return true; + if (re->match( mStreet ) == 0) return true; + if (re->match( mLocality ) == 0) return true; + if (re->match( mRegion ) == 0) return true; + if (re->match( mPostalCode ) == 0) return true; + if (re->match( mCountry ) == 0) return true; + if (re->match( mLabel ) == 0) return true; +#endif + + return false; +} + void Address::clear() { *this = Address(); } void Address::setId( const QString &id ) { mEmpty = false; mId = id; } QString Address::id() const { return mId; } void Address::setType( int type ) { mEmpty = false; mType = type; } int Address::type() const { return mType; } QString Address::typeLabel() const { QString label; bool first = true; TypeList list = typeList(); TypeList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); if ( first ) first = false; } } return label; } void Address::setPostOfficeBox( const QString &s ) { mEmpty = false; mPostOfficeBox = s; } QString Address::postOfficeBox() const { return mPostOfficeBox; } QString Address::postOfficeBoxLabel() { return i18n("Post Office Box"); } void Address::setExtended( const QString &s ) { mEmpty = false; mExtended = s; } QString Address::extended() const { return mExtended; } QString Address::extendedLabel() { return i18n("Extended Address Information"); } void Address::setStreet( const QString &s ) { mEmpty = false; mStreet = s; } QString Address::street() const { return mStreet; } QString Address::streetLabel() { return i18n("Street"); } void Address::setLocality( const QString &s ) { mEmpty = false; mLocality = s; } QString Address::locality() const { return mLocality; } QString Address::localityLabel() { return i18n("Locality"); } void Address::setRegion( const QString &s ) { mEmpty = false; mRegion = s; } QString Address::region() const { return mRegion; } QString Address::regionLabel() { return i18n("Region"); } void Address::setPostalCode( const QString &s ) { mEmpty = false; mPostalCode = s; } QString Address::postalCode() const { return mPostalCode; } QString Address::postalCodeLabel() { return i18n("Postal Code"); } void Address::setCountry( const QString &s ) { mEmpty = false; mCountry = s; } QString Address::country() const { return mCountry; } QString Address::countryLabel() { return i18n("Country"); } void Address::setLabel( const QString &s ) { mEmpty = false; mLabel = s; } QString Address::label() const { return mLabel; } QString Address::labelLabel() { return i18n("Delivery Label"); } Address::TypeList Address::typeList() diff --git a/kabc/address.h b/kabc/address.h index 37dd851..38ad20b 100644 --- a/kabc/address.h +++ b/kabc/address.h @@ -1,289 +1,291 @@ /* 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$ */ #ifndef KABC_ADDRESS_H #define KABC_ADDRESS_H #include <qmap.h> #include <qstring.h> +#include <qregexp.h> #include <qstringlist.h> #include <qvaluelist.h> // template tags for address formatting localization #define KABC_FMTTAG_realname QString("%n") #define KABC_FMTTAG_REALNAME QString("%N") #define KABC_FMTTAG_company QString("%cm") #define KABC_FMTTAG_COMPANY QString("%CM") #define KABC_FMTTAG_pobox QString("%p") #define KABC_FMTTAG_street QString("%s") #define KABC_FMTTAG_STREET QString("%S") #define KABC_FMTTAG_zipcode QString("%z") #define KABC_FMTTAG_location QString("%l") #define KABC_FMTTAG_LOCATION QString("%L") #define KABC_FMTTAG_region QString("%r") #define KABC_FMTTAG_REGION QString("%R") #define KABC_FMTTAG_newline QString("\\n") #define KABC_FMTTAG_condcomma QString("%,") #define KABC_FMTTAG_condwhite QString("%w") #define KABC_FMTTAG_purgeempty QString("%0") namespace KABC { /** @short Postal address information. This class represents information about a postal address. */ class Address { friend QDataStream &operator<<( QDataStream &, const Address & ); friend QDataStream &operator>>( QDataStream &, Address & ); public: /** List of addresses. */ typedef QValueList<Address> List; typedef QValueList<int> TypeList; /** Address types: @li @p Dom - domestic @li @p Intl - international @li @p Postal - postal @li @p Parcel - parcel @li @p Home - home address @li @p Work - address at work @li @p Pref - preferred address */ enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, Pref = 64 }; /** Constructor that creates an empty Address, which is initialized with a unique id (see @ref id()). */ Address(); /** This is like @ref Address() just above, with the difference that you can specify the type. */ Address( int ); + bool matchAddress( QRegExp* searchExp ) const; bool operator==( const Address & ) const; bool operator!=( const Address & ) const; /** Returns true, if the address is empty. */ bool isEmpty() const; /** Clears all entries of the address. */ void clear(); QStringList asList(); /** Sets the unique id. */ void setId( const QString & ); /* Returns the unique id. */ QString id() const; /** Sets the type of address. See enum for definiton of types. @param type type, can be a bitwise or of multiple types. */ void setType( int type ); /** Returns the type of address. Can be a bitwise or of multiple types. */ int type() const; /** Returns a translated string of all types the address has. */ QString typeLabel() const; /** Sets the post office box. */ void setPostOfficeBox( const QString & ); /** Returns the post office box. */ QString postOfficeBox() const; /** Returns the translated label for post office box field. */ static QString postOfficeBoxLabel(); /** Sets the extended address information. */ void setExtended( const QString & ); /** Returns the extended address information. */ QString extended() const; /** Returns the translated label for extended field. */ static QString extendedLabel(); /** Sets the street (including number). */ void setStreet( const QString & ); /** Returns the street. */ QString street() const; /** Returns the translated label for street field. */ static QString streetLabel(); /** Sets the locality, e.g. city. */ void setLocality( const QString & ); /** Returns the locality. */ QString locality() const; /** Returns the translated label for locality field. */ static QString localityLabel(); /** Sets the region, e.g. state. */ void setRegion( const QString & ); /** Returns the region. */ QString region() const; /** Returns the translated label for region field. */ static QString regionLabel(); /** Sets the postal code. */ void setPostalCode( const QString & ); /** Returns the postal code. */ QString postalCode() const; /** Returns the translated label for postal code field. */ static QString postalCodeLabel(); /** Sets the country. */ void setCountry( const QString & ); /** Returns the country. */ QString country() const; /** Returns the translated label for country field. */ static QString countryLabel(); /** Sets the delivery label. This is the literal text to be used as label. */ void setLabel( const QString & ); /** Returns the delivery label. */ QString label() const; /** Returns the translated label for delivery label field. */ static QString labelLabel(); /** Returns the list of available types. */ static TypeList typeList(); /** Returns the translated label for a special type. */ static QString typeLabel( int type ); /** Used for debug output. */ void dump() const; /** Returns this address formatted according to the country-specific address formatting rules. The formatting rules applied depend on either the addresses {@link #country country} field, or (if the latter is empty) on the system country setting. If companyName is provided, an available business address format will be preferred. @param realName the formatted name of the contact @param orgaName the name of the organization or company @return the formatted address (containing newline characters) */ QString formattedAddress( const QString &realName=QString::null , const QString &orgaName=QString::null ) const; /** diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 155ce24..7e1e414 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -117,385 +117,410 @@ Addressee &Addressee::operator=( const Addressee &a ) return (*this); } Addressee Addressee::copy() { Addressee a; *(a.mData) = *mData; return a; } void Addressee::detach() { if ( mData.count() == 1 ) return; *this = copy(); } bool Addressee::operator==( const Addressee &a ) const { if ( uid() != a.uid() ) return false; if ( mData->name != a.mData->name ) return false; if ( mData->formattedName != a.mData->formattedName ) return false; if ( mData->familyName != a.mData->familyName ) return false; if ( mData->givenName != a.mData->givenName ) return false; if ( mData->additionalName != a.mData->additionalName ) return false; if ( mData->prefix != a.mData->prefix ) return false; if ( mData->suffix != a.mData->suffix ) return false; if ( mData->nickName != a.mData->nickName ) return false; if ( mData->birthday != a.mData->birthday ) return false; if ( mData->mailer != a.mData->mailer ) return false; if ( mData->timeZone != a.mData->timeZone ) return false; if ( mData->geo != a.mData->geo ) return false; if ( mData->title != a.mData->title ) return false; if ( mData->role != a.mData->role ) return false; if ( mData->organization != a.mData->organization ) return false; if ( mData->note != a.mData->note ) return false; if ( mData->productId != a.mData->productId ) return false; //if ( mData->revision != a.mData->revision ) return false; if ( mData->sortString != a.mData->sortString ) return false; if ( mData->secrecy != a.mData->secrecy ) return false; if ( mData->logo != a.mData->logo ) return false; if ( mData->photo != a.mData->photo ) return false; if ( mData->sound != a.mData->sound ) return false; if ( mData->agent != a.mData->agent ) return false; if ( ( mData->url.isValid() || a.mData->url.isValid() ) && ( mData->url != a.mData->url ) ) return false; if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; if ( mData->addresses != a.mData->addresses ) return false; if ( mData->keys != a.mData->keys ) return false; if ( mData->emails != a.mData->emails ) return false; if ( mData->categories != a.mData->categories ) return false; if ( mData->custom != a.mData->custom ) return false; return true; } bool Addressee::operator!=( const Addressee &a ) const { return !( a == *this ); } bool Addressee::isEmpty() const { return mData->empty; } 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->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"); } #if 0 if ( !mData->sound.undefined() ) { if ( !mData->sound.isIntern() ) l.append( mData->sound.url() ); else l.append( QString(mData->sound.data().with()* mData->sound.data().height())); } else { l.append( "nosound"); } #endif //if ( !mData->agent.isEmpty() ) l.append( ); if ( mData->url.isValid() ) if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); KABC::PhoneNumber::List phoneNumbers; KABC::PhoneNumber::List::Iterator phoneIter; QStringList t; for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); t.sort(); uint iii; for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->emails; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->categories; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->custom; t.sort(); for ( iii = 0; iii < t.count(); ++iii) if ( t[iii].left( 25 ) != "KADDRESSBOOK-X-ExternalID" ) { int find = t[iii].find (':')+1; //qDebug("lennnn %d %d ", find, t[iii].length()); if ( find < t[iii].length()) l.append( t[iii] ); } KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { t = (*addressIter).asList(); t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); } uint cs = getCsum4List(l); #if 0 for ( iii = 0; iii < l.count(); ++iii) qDebug("%d***%s***",iii,l[iii].latin1()); 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::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; QStringList tAD; uint iii; // ********** phone numbers if ( isSubSet ) { PhoneNumber::List phoneAD = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItAD; for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { bool found = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( ( *phoneItAD ).contains( (*it) ) ) { found = true; (*it).setType( ( *phoneItAD ).type() ); (*it).setNumber( ( *phoneItAD ).number() ); break; } } // if ( isSubSet && ! found ) if ( ! found ) // LR try this one... mData->phoneNumbers.append( *phoneItAD ); } } else { PhoneNumber::List phoneAD = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItAD; for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { bool found = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { if ( ( *phoneItAD ).contains( (*it) ) ) { found = true; (*it).setType( ( *phoneItAD ).type() ); (*it).setNumber( ( *phoneItAD ).number() ); break; } } if ( ! found ) { // append numbers which do not have work or home type if ( ! ( ( *phoneItAD ).type() & (PhoneNumber::Work | PhoneNumber::Home) ) ) mData->phoneNumbers.append( *phoneItAD ); } } } if ( isSubSet ) { // ************* emails; t = mData->emails; tAD = ad.mData->emails; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->emails.append( tAD[iii] ); } // ************* categories; if ( isSubSet ) { t = mData->categories; tAD = ad.mData->categories; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->categories.append( tAD[iii] ); } QStringList::ConstIterator it; for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { QString qualifiedName = (*it).left( (*it).find( ":" )); bool found = false; QStringList::ConstIterator itL; for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { if ( (*itL).startsWith( qualifiedName ) ) { found = true; break; } } if ( ! found ) { mData->custom.append( *it ); } } 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 ); } } } if ( isSubSet ) { KABC::Address::List::Iterator addressIterA; for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { bool found = false; KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { if ( (*addressIter) == (*addressIterA)) { found = true; (*addressIter).setType( (*addressIterA).type() ); break; } } if ( isSubSet && ! found ) { mData->addresses.append( *addressIterA ); } } } //qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } bool Addressee::removeVoice() { PhoneNumber::List phoneN = phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found if ((*phoneIt).type() - PhoneNumber::Voice ) { (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); insertPhoneNumber( (*phoneIt) ); found = true; } } } return found; } bool Addressee::containsAdr(const Addressee& ad ) { if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; // compare phone numbers PhoneNumber::List phoneN = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { diff --git a/kabc/addressee.h b/kabc/addressee.h index a2fbcf5..d1c07cb 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -1,225 +1,226 @@ /*** Warning! This file has been generated by the script makeaddressee ***/ /* 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$ */ #ifndef KABC_ADDRESSEE_H #define KABC_ADDRESSEE_H #include <qdatetime.h> #include <qstring.h> +#include <qregexp.h> #include <qstringlist.h> #include <qvaluelist.h> #include <ksharedptr.h> #include <kurl.h> #include "address.h" #include "agent.h" #include "geo.h" #include "key.h" #include "phonenumber.h" #include "picture.h" #include "secrecy.h" #include "sound.h" #include "timezone.h" namespace KABC { class Resource; /** @short address book entry This class represents an entry in the address book. The data of this class is implicitly shared. You can pass this class by value. If you need the name of a field for presenting it to the user you should use the functions ending in Label(). They return a translated string which can be used as label for the corresponding field. About the name fields: givenName() is the first name and familyName() the last name. In some countries the family name comes first, that's the reason for the naming. formattedName() is the full name with the correct formatting. It is used as an override, when the correct formatting can't be generated from the other name fields automatically. realName() returns a fully formatted name(). It uses formattedName, if set, otherwise it constucts the name from the name fields. As fallback, if nothing else is set it uses name(). name() is the NAME type of RFC2426. It can be used as internal name for the data enty, but shouldn't be used for displaying the data to the user. */ class Addressee { friend QDataStream &operator<<( QDataStream &, const Addressee & ); friend QDataStream &operator>>( QDataStream &, Addressee & ); public: typedef QValueList<Addressee> List; /** Construct an empty address book entry. */ Addressee(); ~Addressee(); Addressee( const Addressee & ); Addressee &operator=( const Addressee & ); bool operator==( const Addressee & ) const; bool operator!=( const Addressee & ) const; // sync stuff void setTempSyncStat(int id); int tempSyncStat() const; void setIDStr( const QString & ); const QString IDStr() const; void setID( const QString &, const QString & ); const QString getID( const QString & ) const; void setCsum( const QString &, const QString & ); const QString getCsum( const QString & ) const ; void removeID(const QString &); void computeCsum(const QString &dev); ulong getCsum4List( const QStringList & attList); /** Return, if the address book entry is empty. */ bool isEmpty() const; void setExternalUID( const QString &id ); const QString externalUID() const; void setOriginalExternalUID( const QString &id ); QString originalExternalUID() const; void mergeContact( const Addressee& ad, bool isSubSet ); void simplifyEmails(); void simplifyAddresses(); void simplifyPhoneNumbers(); void simplifyPhoneNumberTypes(); bool removeVoice(); bool containsAdr(const Addressee& addr ); /** Set unique identifier. */ void setUid( const QString &uid ); /** Return unique identifier. */ const QString uid() const; /** Return translated label for uid field. */ static QString uidLabel(); /** Set name. */ void setName( const QString &name ); /** Return name. */ QString name() const; /** Return translated label for name field. */ static QString nameLabel(); /** Set formatted name. */ void setFormattedName( const QString &formattedName ); /** Return formatted name. */ QString formattedName() const; /** Return translated label for formattedName field. */ static QString formattedNameLabel(); /** Set family name. */ void setFamilyName( const QString &familyName ); /** Return family name. */ QString familyName() const; /** Return translated label for familyName field. */ static QString familyNameLabel(); /** Set given name. */ void setGivenName( const QString &givenName ); /** Return given name. */ QString givenName() const; /** Return translated label for givenName field. */ static QString givenNameLabel(); /** Set additional names. */ void setAdditionalName( const QString &additionalName ); /** Return additional names. */ QString additionalName() const; /** Return translated label for additionalName field. */ static QString additionalNameLabel(); /** Set honorific prefixes. */ void setPrefix( const QString &prefix ); /** Return honorific prefixes. */ QString prefix() const; /** Return translated label for prefix field. */ static QString prefixLabel(); /** Set honorific suffixes. */ void setSuffix( const QString &suffix ); /** Return honorific suffixes. */ QString suffix() const; @@ -461,384 +462,387 @@ class Addressee Set product identifier. */ void setProductId( const QString &productId ); /** Return product identifier. */ QString productId() const; /** Return translated label for productId field. */ static QString productIdLabel(); /** Set revision date. */ void setRevision( const QDateTime &revision ); /** Return revision date. */ QDateTime revision() const; /** Return translated label for revision field. */ static QString revisionLabel(); /** Set sort string. */ void setSortString( const QString &sortString ); /** Return sort string. */ QString sortString() const; /** Return translated label for sortString field. */ static QString sortStringLabel(); /** Set URL. */ void setUrl( const KURL &url ); /** Return URL. */ KURL url() const; /** Return translated label for url field. */ static QString urlLabel(); /** Set security class. */ void setSecrecy( const Secrecy &secrecy ); /** Return security class. */ Secrecy secrecy() const; /** Return translated label for secrecy field. */ static QString secrecyLabel(); /** Set logo. */ void setLogo( const Picture &logo ); /** Return logo. */ Picture logo() const; /** Return translated label for logo field. */ static QString logoLabel(); /** Set photo. */ void setPhoto( const Picture &photo ); /** Return photo. */ Picture photo() const; /** Return translated label for photo field. */ static QString photoLabel(); /** Set sound. */ void setSound( const Sound &sound ); /** Return sound. */ Sound sound() const; /** Return translated label for sound field. */ static QString soundLabel(); /** Set agent. */ void setAgent( const Agent &agent ); /** Return agent. */ Agent agent() const; /** Return translated label for agent field. */ static QString agentLabel(); /** Set name fields by parsing the given string and trying to associate the parts of the string with according fields. This function should probably be a bit more clever. */ void setNameFromString( const QString & ); /** Return the name of the addressee. This is calculated from all the name fields. */ QString realName() const; /** Return the name that consists of all name parts. */ QString assembledName() const; /** Return email address including real name. @param email Email address to be used to construct the full email string. If this is QString::null the preferred email address is used. */ QString fullEmail( const QString &email=QString::null ) const; /** Insert an email address. If the email address already exists in this addressee it is not duplicated. @param email Email address @param preferred Set to true, if this is the preferred email address of the addressee. */ void insertEmail( const QString &email, bool preferred=false ); /** Remove email address. If the email address doesn't exist, nothing happens. */ void removeEmail( const QString &email ); /** Return preferred email address. This is the first email address or the last one added with @ref insertEmail() with a set preferred parameter. */ QString preferredEmail() const; /** Return list of all email addresses. */ QStringList emails() const; /** Set the emails to @param. The first email address gets the preferred one! @param list The list of email addresses. */ void setEmails( const QStringList& list); /** Insert a phone number. If a phone number with the same id already exists in this addressee it is not duplicated. */ void insertPhoneNumber( const PhoneNumber &phoneNumber ); /** Remove phone number. If no phone number with the given id exists for this addresse nothing happens. */ void removePhoneNumber( const PhoneNumber &phoneNumber ); /** Return phone number, which matches the given type. */ PhoneNumber phoneNumber( int type ) const; + bool matchPhoneNumber( QRegExp* searchExp ) const; + bool matchAddress( QRegExp* searchExp ) const; + /** Return list of all phone numbers. */ PhoneNumber::List phoneNumbers() const; /** Return list of phone numbers with a special type. */ PhoneNumber::List phoneNumbers( int type ) const; /** Return phone number with the given id. */ PhoneNumber findPhoneNumber( const QString &id ) const; /** Insert a key. If a key with the same id already exists in this addressee it is not duplicated. */ void insertKey( const Key &key ); /** Remove a key. If no key with the given id exists for this addresse nothing happens. */ void removeKey( const Key &key ); /** Return key, which matches the given type. If @p type == Key::Custom you can specify a string that should match. If you leave the string empty, the first key with a custom value is returned. */ Key key( int type, QString customTypeString = QString::null ) const; /** Return list of all keys. */ Key::List keys() const; /** Set the list of keys @param keys The keys to be set. */ void setKeys( const Key::List& keys); /** Return list of keys with a special type. If @p type == Key::Custom you can specify a string that should match. If you leave the string empty, all custom keys will be returned. */ Key::List keys( int type, QString customTypeString = QString::null ) const; /** Return key with the given id. */ Key findKey( const QString &id ) const; /** Insert an address. If an address with the same id already exists in this addressee it is not duplicated. */ void insertAddress( const Address &address ); /** Remove address. If no address with the given id exists for this addresse nothing happens. */ void removeAddress( const Address &address ); /** Return address, which matches the given type. */ Address address( int type ) const; /** Return list of all addresses. */ Address::List addresses() const; /** Return list of addresses with a special type. */ Address::List addresses( int type ) const; /** Return address with the given id. */ Address findAddress( const QString &id ) const; /** Insert category. If the category already exists it is not duplicated. */ void insertCategory( const QString & ); /** Remove category. */ void removeCategory( const QString & ); /** Return, if addressee has the given category. */ bool hasCategory( const QString & ) const; /** Set categories to given value. */ void setCategories( const QStringList & ); /** Return list of all set categories. */ QStringList categories() const; /** Insert custom entry. The entry is identified by the name of the inserting application and a unique name. If an entry with the given app and name already exists its value is replaced with the new given value. */ void insertCustom( const QString &app, const QString &name, const QString &value ); /** Remove custom entry. */ void removeCustom( const QString &app, const QString &name ); /** Return value of custom entry, identified by app and entry name. */ QString custom( const QString &app, const QString &name ) const; /** Set all custom entries. */ void setCustoms( const QStringList & ); /** Return list of all custom entries. */ QStringList customs() const; /** Parse full email address. The result is given back in fullName and email. */ static void parseEmailAddress( const QString &rawEmail, QString &fullName, QString &email ); /** Debug output. */ void dump() const; /** Returns string representation of the addressee. */ QString asString() const; /** Set resource where the addressee is from. */ void setResource( Resource *resource ); /** Return pointer to resource. */ Resource *resource() const; /** Return resourcelabel. */ //US static QString resourceLabel(); static QString categoryLabel(); /** Mark addressee as changed. */ void setChanged( bool value ); /** Return whether the addressee is changed. */ bool changed() const; void setTagged( bool value ); bool tagged() const; private: Addressee copy(); void detach(); |