| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# address.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <kapplication.h>
    00022 #include <kdebug.h>
    00023 #include <klocale.h>
    00024
    00025 #include "address.h"
    00026
    00027 using namespace KABC;
    00028
    00029 Address::Address() :
    00030   mEmpty( true ), mType( 0 )
    00031 {
    00032   mId = KApplication::randomString( 10 );
    00033 }
    00034
    00035 Address::Address( int type ) :
    00036   mEmpty( true ), mType( type )
    00037 {
    00038   mId = KApplication::randomString( 10 );
    00039 }
    00040
    00041 bool Address::operator==( const Address &a ) const
    00042 {
    00043   if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
    00044   if ( mExtended != a.mExtended ) return false;
    00045   if ( mStreet != a.mStreet ) return false;
    00046   if ( mLocality != a.mLocality ) return false;
    00047   if ( mRegion != a.mRegion ) return false;
    00048   if ( mPostalCode != a.mPostalCode ) return false;
    00049   if ( mCountry != a.mCountry ) return false;
    00050   if ( mLabel != a.mLabel ) return false;
    00051
    00052   return true;
    00053 }
    00054
    00055 bool Address::operator!=( const Address &a ) const
    00056 {
    00057   return !( a == *this );
    00058 }
    00059
    00060 bool Address::isEmpty() const
    00061 {
    00062   if ( mPostOfficeBox.isEmpty() &&
    00063        mExtended.isEmpty() &&
    00064        mStreet.isEmpty() &&
    00065        mLocality.isEmpty() &&
    00066        mRegion.isEmpty() &&
    00067        mPostalCode.isEmpty() &&
    00068        mCountry.isEmpty() &&
    00069        mLabel.isEmpty() ) {
    00070     return true;
    00071   }
    00072   return false;
    00073 }
    00074
    00075 void Address::clear()
    00076 {
    00077   *this = Address();
    00078 }
    00079
    00080 void Address::setId( const QString &id )
    00081 {
    00082   mEmpty = false;
    00083
    00084   mId = id;
    00085 }
    00086
    00087 QString Address::id() const
    00088 {
    00089   return mId;
    00090 }
    00091
    00092 void Address::setType( int type )
    00093 {
    00094   mEmpty = false;
    00095
    00096   mType = type;
    00097 }
    00098
    00099 int Address::type() const
    00100 {
    00101   return mType;
    00102 }
    00103
    00104 QString Address::typeLabel() const
    00105 {
    00106   QString label;
    00107   bool first = true;
    00108
    00109   TypeList list = typeList();
    00110
    00111   TypeList::Iterator it;
    00112   for ( it = list.begin(); it != list.end(); ++it ) {
    00113     if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
    00114       label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
    00115       if ( first )
    00116         first = false;
    00117     }
    00118   }
    00119
    00120   return label;
    00121 }
    00122
    00123 void Address::setPostOfficeBox( const QString &s )
    00124 {
    00125   mEmpty = false;
    00126
    00127   mPostOfficeBox = s;
    00128 }
    00129
    00130 QString Address::postOfficeBox() const
    00131 {
    00132   return mPostOfficeBox;
    00133 }
    00134
    00135 QString Address::postOfficeBoxLabel()
    00136 {
    00137   return i18n("Post Office Box");
    00138 }
    00139
    00140
    00141 void Address::setExtended( const QString &s )
    00142 {
    00143   mEmpty = false;
    00144
    00145   mExtended = s;
    00146 }
    00147
    00148 QString Address::extended() const
    00149 {
    00150   return mExtended;
    00151 }
    00152
    00153 QString Address::extendedLabel()
    00154 {
    00155   return i18n("Extended Address Information");
    00156 }
    00157
    00158
    00159 void Address::setStreet( const QString &s )
    00160 {
    00161   mEmpty = false;
    00162
    00163   mStreet = s;
    00164 }
    00165
    00166 QString Address::street() const
    00167 {
    00168   return mStreet;
    00169 }
    00170
    00171 QString Address::streetLabel()
    00172 {
    00173   return i18n("Street");
    00174 }
    00175
    00176
    00177 void Address::setLocality( const QString &s )
    00178 {
    00179   mEmpty = false;
    00180
    00181   mLocality = s;
    00182 }
    00183
    00184 QString Address::locality() const
    00185 {
    00186   return mLocality;
    00187 }
    00188
    00189 QString Address::localityLabel()
    00190 {
    00191   return i18n("Locality");
    00192 }
    00193
    00194
    00195 void Address::setRegion( const QString &s )
    00196 {
    00197   mEmpty = false;
    00198
    00199   mRegion = s;
    00200 }
    00201
    00202 QString Address::region() const
    00203 {
    00204   return mRegion;
    00205 }
    00206
    00207 QString Address::regionLabel()
    00208 {
    00209   return i18n("Region");
    00210 }
    00211
    00212
    00213 void Address::setPostalCode( const QString &s )
    00214 {
    00215   mEmpty = false;
    00216
    00217   mPostalCode = s;
    00218 }
    00219
    00220 QString Address::postalCode() const
    00221 {
    00222   return mPostalCode;
    00223 }
    00224
    00225 QString Address::postalCodeLabel()
    00226 {
    00227   return i18n("Postal Code");
    00228 }
    00229
    00230
    00231 void Address::setCountry( const QString &s )
    00232 {
    00233   mEmpty = false;
    00234
    00235   mCountry = s;
    00236 }
    00237
    00238 QString Address::country() const
    00239 {
    00240   return mCountry;
    00241 }
    00242
    00243 QString Address::countryLabel()
    00244 {
    00245   return i18n("Country");
    00246 }
    00247
    00248
    00249 void Address::setLabel( const QString &s )
    00250 {
    00251   mEmpty = false;
    00252
    00253   mLabel = s;
    00254 }
    00255
    00256 QString Address::label() const
    00257 {
    00258   return mLabel;
    00259 }
    00260
    00261 QString Address::labelLabel()
    00262 {
    00263   return i18n("Delivery Label");
    00264 }
    00265
    00266 Address::TypeList Address::typeList()
    00267 {
    00268   TypeList list;
    00269
    00270   list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
    00271
    00272   return list;
    00273 }
    00274
    00275 QString Address::typeLabel( int type )
    00276 {
    00277   switch ( type ) {
    00278     case Dom:
    00279       return i18n("Domestic");
    00280       break;
    00281     case Intl:
    00282       return i18n("International");
    00283       break;
    00284     case Postal:
    00285       return i18n("Postal");
    00286       break;
    00287     case Parcel:
    00288       return i18n("Parcel");
    00289       break;
    00290     case Home:
    00291       return i18n("Home Address", "Home");
    00292       break;
    00293     case Work:
    00294       return i18n("Work Address", "Work");
    00295       break;
    00296     case Pref:
    00297       return i18n("Preferred Address");
    00298       break;
    00299     default:
    00300       return i18n("Other");
    00301       break;
    00302   }
    00303 }
    00304
    00305 void Address::dump() const
    00306 {
    00307   kdDebug(5700) << "  Address {" << endl;
    00308   kdDebug(5700) << "    Id: " << id() << endl;
    00309   kdDebug(5700) << "    Extended: " << extended() << endl;
    00310   kdDebug(5700) << "    Street: " << street() << endl;
    00311   kdDebug(5700) << "    Postal Code: " << postalCode() << endl;
    00312   kdDebug(5700) << "    Locality: " << locality() << endl;
    00313   kdDebug(5700) << "  }" << endl;
    00314 }
    00315
    00316 QDataStream &KABC::operator<<( QDataStream &s, const Address &addr )
    00317 {
    00318     return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
    00319             addr.mExtended << addr.mStreet << addr.mLocality <<
    00320             addr.mRegion << addr.mPostalCode << addr.mCountry <<
    00321             addr.mLabel;
    00322 }
    00323
    00324 QDataStream &KABC::operator>>( QDataStream &s, Address &addr )
    00325 {
    00326     s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
    00327             addr.mStreet >> addr.mLocality >> addr.mRegion >>
    00328             addr.mPostalCode >> addr.mCountry >> addr.mLabel;
    00329
    00330     addr.mEmpty = false;
    00331
    00332     return s;
    00333 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:15 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001