summaryrefslogtreecommitdiffabout
path: root/kabc/address.cpp
Unidiff
Diffstat (limited to 'kabc/address.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index c820a6c..5ffe511 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -1,346 +1,359 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28//US added kglobal.h 28//US added kglobal.h
29#include <kglobal.h> 29#include <kglobal.h>
30 30
31#include <kapplication.h> 31#include <kapplication.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34#include <ksimpleconfig.h> 34#include <ksimpleconfig.h>
35#include <kstandarddirs.h> 35#include <kstandarddirs.h>
36 36
37#include <qfile.h> 37#include <qfile.h>
38 38
39#include "address.h" 39#include "address.h"
40 40
41using namespace KABC; 41using namespace KABC;
42 42
43QMap<QString, QString> Address::mISOMap; 43QMap<QString, QString> Address::mISOMap;
44 44
45Address::Address() : 45Address::Address() :
46 mEmpty( true ), mType( 0 ) 46 mEmpty( true ), mType( 0 )
47{ 47{
48 mId = KApplication::randomString( 10 ); 48 mId = KApplication::randomString( 10 );
49} 49}
50 50
51Address::Address( int type ) : 51Address::Address( int type ) :
52 mEmpty( true ), mType( type ) 52 mEmpty( true ), mType( type )
53{ 53{
54 mId = KApplication::randomString( 10 ); 54 mId = KApplication::randomString( 10 );
55} 55}
56 56
57bool Address::operator==( const Address &a ) const 57bool Address::operator==( const Address &a ) const
58{ 58{
59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false; 59 if ( mPostOfficeBox != a.mPostOfficeBox ) return false;
60 if ( mExtended != a.mExtended ) return false; 60 if ( mExtended != a.mExtended ) return false;
61 if ( mStreet != a.mStreet ) return false; 61 if ( mStreet != a.mStreet ) return false;
62 if ( mLocality != a.mLocality ) return false; 62 if ( mLocality != a.mLocality ) return false;
63 if ( mRegion != a.mRegion ) return false; 63 if ( mRegion != a.mRegion ) return false;
64 if ( mPostalCode != a.mPostalCode ) return false; 64 if ( mPostalCode != a.mPostalCode ) return false;
65 if ( mCountry != a.mCountry ) return false; 65 if ( mCountry != a.mCountry ) return false;
66 if ( mLabel != a.mLabel ) return false; 66 if ( mLabel != a.mLabel ) return false;
67 67
68 return true; 68 return true;
69} 69}
70 70
71bool Address::operator!=( const Address &a ) const 71bool Address::operator!=( const Address &a ) const
72{ 72{
73 return !( a == *this ); 73 return !( a == *this );
74} 74}
75 75
76bool Address::isEmpty() const 76bool Address::isEmpty() const
77{ 77{
78 if ( mPostOfficeBox.isEmpty() && 78 if ( mPostOfficeBox.isEmpty() &&
79 mExtended.isEmpty() && 79 mExtended.isEmpty() &&
80 mStreet.isEmpty() && 80 mStreet.isEmpty() &&
81 mLocality.isEmpty() && 81 mLocality.isEmpty() &&
82 mRegion.isEmpty() && 82 mRegion.isEmpty() &&
83 mPostalCode.isEmpty() && 83 mPostalCode.isEmpty() &&
84 mCountry.isEmpty() && 84 mCountry.isEmpty() &&
85 mLabel.isEmpty() ) { 85 mLabel.isEmpty() ) {
86 return true; 86 return true;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91QStringList Address::asList()
92{
93 QStringList result;
94 if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox);
95 if ( ! mExtended.isEmpty())result.append(mExtended);
96 if ( ! mStreet.isEmpty())result.append(mStreet);
97 if ( ! mLocality.isEmpty() )result.append(mLocality);
98 if ( ! mRegion.isEmpty())result.append(mRegion);
99 if ( ! mPostalCode.isEmpty())result.append(mPostalCode);
100 if ( ! mCountry.isEmpty())result.append(mCountry);
101 if ( ! mLabel.isEmpty() )result.append(mLabel);
102 return result;
103}
91void Address::clear() 104void Address::clear()
92{ 105{
93 *this = Address(); 106 *this = Address();
94} 107}
95 108
96void Address::setId( const QString &id ) 109void Address::setId( const QString &id )
97{ 110{
98 mEmpty = false; 111 mEmpty = false;
99 112
100 mId = id; 113 mId = id;
101} 114}
102 115
103QString Address::id() const 116QString Address::id() const
104{ 117{
105 return mId; 118 return mId;
106} 119}
107 120
108void Address::setType( int type ) 121void Address::setType( int type )
109{ 122{
110 mEmpty = false; 123 mEmpty = false;
111 124
112 mType = type; 125 mType = type;
113} 126}
114 127
115int Address::type() const 128int Address::type() const
116{ 129{
117 return mType; 130 return mType;
118} 131}
119 132
120QString Address::typeLabel() const 133QString Address::typeLabel() const
121{ 134{
122 QString label; 135 QString label;
123 bool first = true; 136 bool first = true;
124 137
125 TypeList list = typeList(); 138 TypeList list = typeList();
126 139
127 TypeList::Iterator it; 140 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 141 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 142 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 143 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 144 if ( first )
132 first = false; 145 first = false;
133 } 146 }
134 } 147 }
135 148
136 return label; 149 return label;
137} 150}
138 151
139void Address::setPostOfficeBox( const QString &s ) 152void Address::setPostOfficeBox( const QString &s )
140{ 153{
141 mEmpty = false; 154 mEmpty = false;
142 155
143 mPostOfficeBox = s; 156 mPostOfficeBox = s;
144} 157}
145 158
146QString Address::postOfficeBox() const 159QString Address::postOfficeBox() const
147{ 160{
148 return mPostOfficeBox; 161 return mPostOfficeBox;
149} 162}
150 163
151QString Address::postOfficeBoxLabel() 164QString Address::postOfficeBoxLabel()
152{ 165{
153 return i18n("Post Office Box"); 166 return i18n("Post Office Box");
154} 167}
155 168
156 169
157void Address::setExtended( const QString &s ) 170void Address::setExtended( const QString &s )
158{ 171{
159 mEmpty = false; 172 mEmpty = false;
160 173
161 mExtended = s; 174 mExtended = s;
162} 175}
163 176
164QString Address::extended() const 177QString Address::extended() const
165{ 178{
166 return mExtended; 179 return mExtended;
167} 180}
168 181
169QString Address::extendedLabel() 182QString Address::extendedLabel()
170{ 183{
171 return i18n("Extended Address Information"); 184 return i18n("Extended Address Information");
172} 185}
173 186
174 187
175void Address::setStreet( const QString &s ) 188void Address::setStreet( const QString &s )
176{ 189{
177 mEmpty = false; 190 mEmpty = false;
178 191
179 mStreet = s; 192 mStreet = s;
180} 193}
181 194
182QString Address::street() const 195QString Address::street() const
183{ 196{
184 return mStreet; 197 return mStreet;
185} 198}
186 199
187QString Address::streetLabel() 200QString Address::streetLabel()
188{ 201{
189 return i18n("Street"); 202 return i18n("Street");
190} 203}
191 204
192 205
193void Address::setLocality( const QString &s ) 206void Address::setLocality( const QString &s )
194{ 207{
195 mEmpty = false; 208 mEmpty = false;
196 209
197 mLocality = s; 210 mLocality = s;
198} 211}
199 212
200QString Address::locality() const 213QString Address::locality() const
201{ 214{
202 return mLocality; 215 return mLocality;
203} 216}
204 217
205QString Address::localityLabel() 218QString Address::localityLabel()
206{ 219{
207 return i18n("Locality"); 220 return i18n("Locality");
208} 221}
209 222
210 223
211void Address::setRegion( const QString &s ) 224void Address::setRegion( const QString &s )
212{ 225{
213 mEmpty = false; 226 mEmpty = false;
214 227
215 mRegion = s; 228 mRegion = s;
216} 229}
217 230
218QString Address::region() const 231QString Address::region() const
219{ 232{
220 return mRegion; 233 return mRegion;
221} 234}
222 235
223QString Address::regionLabel() 236QString Address::regionLabel()
224{ 237{
225 return i18n("Region"); 238 return i18n("Region");
226} 239}
227 240
228 241
229void Address::setPostalCode( const QString &s ) 242void Address::setPostalCode( const QString &s )
230{ 243{
231 mEmpty = false; 244 mEmpty = false;
232 245
233 mPostalCode = s; 246 mPostalCode = s;
234} 247}
235 248
236QString Address::postalCode() const 249QString Address::postalCode() const
237{ 250{
238 return mPostalCode; 251 return mPostalCode;
239} 252}
240 253
241QString Address::postalCodeLabel() 254QString Address::postalCodeLabel()
242{ 255{
243 return i18n("Postal Code"); 256 return i18n("Postal Code");
244} 257}
245 258
246 259
247void Address::setCountry( const QString &s ) 260void Address::setCountry( const QString &s )
248{ 261{
249 mEmpty = false; 262 mEmpty = false;
250 263
251 mCountry = s; 264 mCountry = s;
252} 265}
253 266
254QString Address::country() const 267QString Address::country() const
255{ 268{
256 return mCountry; 269 return mCountry;
257} 270}
258 271
259QString Address::countryLabel() 272QString Address::countryLabel()
260{ 273{
261 return i18n("Country"); 274 return i18n("Country");
262} 275}
263 276
264 277
265void Address::setLabel( const QString &s ) 278void Address::setLabel( const QString &s )
266{ 279{
267 mEmpty = false; 280 mEmpty = false;
268 281
269 mLabel = s; 282 mLabel = s;
270} 283}
271 284
272QString Address::label() const 285QString Address::label() const
273{ 286{
274 return mLabel; 287 return mLabel;
275} 288}
276 289
277QString Address::labelLabel() 290QString Address::labelLabel()
278{ 291{
279 return i18n("Delivery Label"); 292 return i18n("Delivery Label");
280} 293}
281 294
282Address::TypeList Address::typeList() 295Address::TypeList Address::typeList()
283{ 296{
284 TypeList list; 297 TypeList list;
285 298
286 list << Dom << Intl << Postal << Parcel << Home << Work << Pref; 299 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
287 300
288 return list; 301 return list;
289} 302}
290 303
291QString Address::typeLabel( int type ) 304QString Address::typeLabel( int type )
292{ 305{
293 QString label; 306 QString label;
294 if ( type & Dom ) 307 if ( type & Dom )
295 label += i18n("Domestic")+" "; 308 label += i18n("Domestic")+" ";
296 if ( type & Intl ) 309 if ( type & Intl )
297 label += i18n("International")+" "; 310 label += i18n("International")+" ";
298 if ( type & Postal ) 311 if ( type & Postal )
299 label += i18n("Postal")+" "; 312 label += i18n("Postal")+" ";
300 if ( type & Parcel ) 313 if ( type & Parcel )
301 label += i18n("Parcel")+" "; 314 label += i18n("Parcel")+" ";
302 if ( type & Work ) 315 if ( type & Work )
303 label += i18n("Work Address", "Work")+" "; 316 label += i18n("Work Address", "Work")+" ";
304 if ( type & Home ) 317 if ( type & Home )
305 label += i18n("Home Address", "Home") +" "; 318 label += i18n("Home Address", "Home") +" ";
306 if ( type & Pref ) 319 if ( type & Pref )
307 label += i18n("Preferred Address", "(p)"); 320 label += i18n("Preferred Address", "(p)");
308 if ( label.isEmpty() ) 321 if ( label.isEmpty() )
309 label = i18n("Other"); 322 label = i18n("Other");
310 return label; 323 return label;
311 324
312#if 0 325#if 0
313 switch ( type ) { 326 switch ( type ) {
314 case Dom: 327 case Dom:
315 return i18n("Domestic"); 328 return i18n("Domestic");
316 break; 329 break;
317 case Intl: 330 case Intl:
318 return i18n("International"); 331 return i18n("International");
319 break; 332 break;
320 case Postal: 333 case Postal:
321 return i18n("Postal"); 334 return i18n("Postal");
322 break; 335 break;
323 case Parcel: 336 case Parcel:
324 return i18n("Parcel"); 337 return i18n("Parcel");
325 break; 338 break;
326 case Home: 339 case Home:
327 return i18n("Home Address", "Home"); 340 return i18n("Home Address", "Home");
328 break; 341 break;
329 case Work: 342 case Work:
330 return i18n("Work Address", "Work"); 343 return i18n("Work Address", "Work");
331 break; 344 break;
332 case Pref: 345 case Pref:
333 return i18n("Preferred Address"); 346 return i18n("Preferred Address");
334 break; 347 break;
335 default: 348 default:
336 return i18n("Other"); 349 return i18n("Other");
337 break; 350 break;
338 } 351 }
339#endif 352#endif
340} 353}
341 354
342void Address::dump() const 355void Address::dump() const
343{ 356{
344 qDebug("Address::dump() +++++++++++++++++ "); 357 qDebug("Address::dump() +++++++++++++++++ ");
345#if 0 358#if 0
346 kdDebug(5700) << " Address {" << endl; 359 kdDebug(5700) << " Address {" << endl;