address.h
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., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KABC_ADDRESS_H 00022 #define KABC_ADDRESS_H 00023 00024 #include <tqmap.h> 00025 #include <tqstring.h> 00026 #include <tqvaluelist.h> 00027 00028 #include <kdelibs_export.h> 00029 00030 // template tags for address formatting localization 00031 #define KABC_FMTTAG_realname TQString("%n") 00032 #define KABC_FMTTAG_REALNAME TQString("%N") 00033 #define KABC_FMTTAG_company TQString("%cm") 00034 #define KABC_FMTTAG_COMPANY TQString("%CM") 00035 #define KABC_FMTTAG_pobox TQString("%p") 00036 #define KABC_FMTTAG_street TQString("%s") 00037 #define KABC_FMTTAG_STREET TQString("%S") 00038 #define KABC_FMTTAG_zipcode TQString("%z") 00039 #define KABC_FMTTAG_location TQString("%l") 00040 #define KABC_FMTTAG_LOCATION TQString("%L") 00041 #define KABC_FMTTAG_region TQString("%r") 00042 #define KABC_FMTTAG_REGION TQString("%R") 00043 #define KABC_FMTTAG_newline TQString("\\n") 00044 #define KABC_FMTTAG_condcomma TQString("%,") 00045 #define KABC_FMTTAG_condwhite TQString("%w") 00046 #define KABC_FMTTAG_purgeempty TQString("%0") 00047 00048 namespace KABC { 00049 00055 class KABC_EXPORT Address 00056 { 00057 friend KABC_EXPORT TQDataStream &operator<<( TQDataStream &, const Address & ); 00058 friend KABC_EXPORT TQDataStream &operator>>( TQDataStream &, Address & ); 00059 00060 public: 00064 typedef TQValueList<Address> List; 00065 typedef TQValueList<int> TypeList; 00066 00078 enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, 00079 Pref = 64 }; 00080 00085 Address(); 00086 00091 Address( int ); 00092 00093 bool operator==( const Address & ) const; 00094 bool operator!=( const Address & ) const; 00095 00099 bool isEmpty() const; 00100 00104 void clear(); 00105 00109 void setId( const TQString & ); 00110 00111 /* 00112 Returns the unique id. 00113 */ 00114 TQString id() const; 00115 00121 void setType( int type ); 00122 00126 int type() const; 00127 00131 TQString typeLabel() const; 00132 00136 void setPostOfficeBox( const TQString & ); 00137 00141 TQString postOfficeBox() const; 00142 00146 static TQString postOfficeBoxLabel(); 00147 00151 void setExtended( const TQString & ); 00152 00156 TQString extended() const; 00157 00161 static TQString extendedLabel(); 00162 00166 void setStreet( const TQString & ); 00167 00171 TQString street() const; 00172 00176 static TQString streetLabel(); 00177 00181 void setLocality( const TQString & ); 00182 00186 TQString locality() const; 00187 00191 static TQString localityLabel(); 00192 00196 void setRegion( const TQString & ); 00197 00201 TQString region() const; 00202 00206 static TQString regionLabel(); 00207 00211 void setPostalCode( const TQString & ); 00212 00216 TQString postalCode() const; 00217 00221 static TQString postalCodeLabel(); 00222 00226 void setCountry( const TQString & ); 00227 00231 TQString country() const; 00232 00236 static TQString countryLabel(); 00237 00241 void setLabel( const TQString & ); 00242 00246 TQString label() const; 00247 00251 static TQString labelLabel(); 00252 00256 static TypeList typeList(); 00257 00261 static TQString typeLabel( int type ); 00262 00266 void dump() const; 00267 00279 TQString formattedAddress( const TQString &realName=TQString::null 00280 , const TQString &orgaName=TQString::null ) const; 00281 00289 static TQString countryToISO( const TQString &cname ); 00290 00298 static TQString ISOtoCountry( const TQString &ISOname ); 00299 00300 private: 00307 bool parseAddressTemplateSection( const TQString &tsection 00308 , TQString &result 00309 , const TQString &realName 00310 , const TQString &orgaName ) const; 00311 00317 int findBalancedBracket( const TQString &tsection, int pos ) const; 00318 00319 bool mEmpty; 00320 00321 TQString mId; 00322 int mType; 00323 00324 TQString mPostOfficeBox; 00325 TQString mExtended; 00326 TQString mStreet; 00327 TQString mLocality; 00328 TQString mRegion; 00329 TQString mPostalCode; 00330 TQString mCountry; 00331 TQString mLabel; 00332 00333 static TQMap<TQString, TQString> *mISOMap; 00334 }; 00335 00336 KABC_EXPORT TQDataStream &operator<<( TQDataStream &, const Address & ); 00337 KABC_EXPORT TQDataStream &operator>>( TQDataStream &, Address & ); 00338 00339 } 00340 00341 #endif