-rw-r--r-- | kabc/address.cpp | 27 |
1 files changed, 27 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,359 +1,386 @@ /* 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() { TypeList list; list << Dom << Intl << Postal << Parcel << Home << Work << Pref; return list; } QString Address::typeLabel( int type ) { QString label; if ( type & Dom ) label += i18n("Domestic")+" "; if ( type & Intl ) label += i18n("International")+" "; if ( type & Postal ) label += i18n("Postal")+" "; if ( type & Parcel ) label += i18n("Parcel")+" "; if ( type & Work ) label += i18n("Work Address", "Work")+" "; if ( type & Home ) label += i18n("Home Address", "Home") +" "; if ( type & Pref ) label += i18n("Preferred Address", "(p)"); if ( label.isEmpty() ) label = i18n("Other"); return label; #if 0 switch ( type ) { case Dom: return i18n("Domestic"); break; case Intl: return i18n("International"); break; case Postal: return i18n("Postal"); break; case Parcel: return i18n("Parcel"); break; case Home: return i18n("Home Address", "Home"); break; case Work: return i18n("Work Address", "Work"); break; case Pref: return i18n("Preferred Address"); break; default: return i18n("Other"); break; } #endif } void Address::dump() const { qDebug("Address::dump() +++++++++++++++++ "); #if 0 kdDebug(5700) << " Address {" << endl; |