summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-07-07 06:29:27 (UTC)
committer zautrix <zautrix>2004-07-07 06:29:27 (UTC)
commitf2bf08414f8006f0ddedc293804566b3b154428c (patch) (unidiff)
treea611e80fb264c5f2c8551982b1bc6a6da6d8e6d6
parentc9c0fefaead651c073318e8242d86675519dbcf6 (diff)
downloadkdepimpi-f2bf08414f8006f0ddedc293804566b3b154428c.zip
kdepimpi-f2bf08414f8006f0ddedc293804566b3b154428c.tar.gz
kdepimpi-f2bf08414f8006f0ddedc293804566b3b154428c.tar.bz2
Fix of the address type == other problem
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/address.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp
index 26e0b6a..c820a6c 100644
--- a/kabc/address.cpp
+++ b/kabc/address.cpp
@@ -1,630 +1,651 @@
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
91void Address::clear() 91void Address::clear()
92{ 92{
93 *this = Address(); 93 *this = Address();
94} 94}
95 95
96void Address::setId( const QString &id ) 96void Address::setId( const QString &id )
97{ 97{
98 mEmpty = false; 98 mEmpty = false;
99 99
100 mId = id; 100 mId = id;
101} 101}
102 102
103QString Address::id() const 103QString Address::id() const
104{ 104{
105 return mId; 105 return mId;
106} 106}
107 107
108void Address::setType( int type ) 108void Address::setType( int type )
109{ 109{
110 mEmpty = false; 110 mEmpty = false;
111 111
112 mType = type; 112 mType = type;
113} 113}
114 114
115int Address::type() const 115int Address::type() const
116{ 116{
117 return mType; 117 return mType;
118} 118}
119 119
120QString Address::typeLabel() const 120QString Address::typeLabel() const
121{ 121{
122 QString label; 122 QString label;
123 bool first = true; 123 bool first = true;
124 124
125 TypeList list = typeList(); 125 TypeList list = typeList();
126 126
127 TypeList::Iterator it; 127 TypeList::Iterator it;
128 for ( it = list.begin(); it != list.end(); ++it ) { 128 for ( it = list.begin(); it != list.end(); ++it ) {
129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { 129 if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); 130 label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
131 if ( first ) 131 if ( first )
132 first = false; 132 first = false;
133 } 133 }
134 } 134 }
135 135
136 return label; 136 return label;
137} 137}
138 138
139void Address::setPostOfficeBox( const QString &s ) 139void Address::setPostOfficeBox( const QString &s )
140{ 140{
141 mEmpty = false; 141 mEmpty = false;
142 142
143 mPostOfficeBox = s; 143 mPostOfficeBox = s;
144} 144}
145 145
146QString Address::postOfficeBox() const 146QString Address::postOfficeBox() const
147{ 147{
148 return mPostOfficeBox; 148 return mPostOfficeBox;
149} 149}
150 150
151QString Address::postOfficeBoxLabel() 151QString Address::postOfficeBoxLabel()
152{ 152{
153 return i18n("Post Office Box"); 153 return i18n("Post Office Box");
154} 154}
155 155
156 156
157void Address::setExtended( const QString &s ) 157void Address::setExtended( const QString &s )
158{ 158{
159 mEmpty = false; 159 mEmpty = false;
160 160
161 mExtended = s; 161 mExtended = s;
162} 162}
163 163
164QString Address::extended() const 164QString Address::extended() const
165{ 165{
166 return mExtended; 166 return mExtended;
167} 167}
168 168
169QString Address::extendedLabel() 169QString Address::extendedLabel()
170{ 170{
171 return i18n("Extended Address Information"); 171 return i18n("Extended Address Information");
172} 172}
173 173
174 174
175void Address::setStreet( const QString &s ) 175void Address::setStreet( const QString &s )
176{ 176{
177 mEmpty = false; 177 mEmpty = false;
178 178
179 mStreet = s; 179 mStreet = s;
180} 180}
181 181
182QString Address::street() const 182QString Address::street() const
183{ 183{
184 return mStreet; 184 return mStreet;
185} 185}
186 186
187QString Address::streetLabel() 187QString Address::streetLabel()
188{ 188{
189 return i18n("Street"); 189 return i18n("Street");
190} 190}
191 191
192 192
193void Address::setLocality( const QString &s ) 193void Address::setLocality( const QString &s )
194{ 194{
195 mEmpty = false; 195 mEmpty = false;
196 196
197 mLocality = s; 197 mLocality = s;
198} 198}
199 199
200QString Address::locality() const 200QString Address::locality() const
201{ 201{
202 return mLocality; 202 return mLocality;
203} 203}
204 204
205QString Address::localityLabel() 205QString Address::localityLabel()
206{ 206{
207 return i18n("Locality"); 207 return i18n("Locality");
208} 208}
209 209
210 210
211void Address::setRegion( const QString &s ) 211void Address::setRegion( const QString &s )
212{ 212{
213 mEmpty = false; 213 mEmpty = false;
214 214
215 mRegion = s; 215 mRegion = s;
216} 216}
217 217
218QString Address::region() const 218QString Address::region() const
219{ 219{
220 return mRegion; 220 return mRegion;
221} 221}
222 222
223QString Address::regionLabel() 223QString Address::regionLabel()
224{ 224{
225 return i18n("Region"); 225 return i18n("Region");
226} 226}
227 227
228 228
229void Address::setPostalCode( const QString &s ) 229void Address::setPostalCode( const QString &s )
230{ 230{
231 mEmpty = false; 231 mEmpty = false;
232 232
233 mPostalCode = s; 233 mPostalCode = s;
234} 234}
235 235
236QString Address::postalCode() const 236QString Address::postalCode() const
237{ 237{
238 return mPostalCode; 238 return mPostalCode;
239} 239}
240 240
241QString Address::postalCodeLabel() 241QString Address::postalCodeLabel()
242{ 242{
243 return i18n("Postal Code"); 243 return i18n("Postal Code");
244} 244}
245 245
246 246
247void Address::setCountry( const QString &s ) 247void Address::setCountry( const QString &s )
248{ 248{
249 mEmpty = false; 249 mEmpty = false;
250 250
251 mCountry = s; 251 mCountry = s;
252} 252}
253 253
254QString Address::country() const 254QString Address::country() const
255{ 255{
256 return mCountry; 256 return mCountry;
257} 257}
258 258
259QString Address::countryLabel() 259QString Address::countryLabel()
260{ 260{
261 return i18n("Country"); 261 return i18n("Country");
262} 262}
263 263
264 264
265void Address::setLabel( const QString &s ) 265void Address::setLabel( const QString &s )
266{ 266{
267 mEmpty = false; 267 mEmpty = false;
268 268
269 mLabel = s; 269 mLabel = s;
270} 270}
271 271
272QString Address::label() const 272QString Address::label() const
273{ 273{
274 return mLabel; 274 return mLabel;
275} 275}
276 276
277QString Address::labelLabel() 277QString Address::labelLabel()
278{ 278{
279 return i18n("Delivery Label"); 279 return i18n("Delivery Label");
280} 280}
281 281
282Address::TypeList Address::typeList() 282Address::TypeList Address::typeList()
283{ 283{
284 TypeList list; 284 TypeList list;
285 285
286 list << Dom << Intl << Postal << Parcel << Home << Work << Pref; 286 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
287 287
288 return list; 288 return list;
289} 289}
290 290
291QString Address::typeLabel( int type ) 291QString Address::typeLabel( int type )
292{ 292{
293 QString label;
294 if ( type & Dom )
295 label += i18n("Domestic")+" ";
296 if ( type & Intl )
297 label += i18n("International")+" ";
298 if ( type & Postal )
299 label += i18n("Postal")+" ";
300 if ( type & Parcel )
301 label += i18n("Parcel")+" ";
302 if ( type & Work )
303 label += i18n("Work Address", "Work")+" ";
304 if ( type & Home )
305 label += i18n("Home Address", "Home") +" ";
306 if ( type & Pref )
307 label += i18n("Preferred Address", "(p)");
308 if ( label.isEmpty() )
309 label = i18n("Other");
310 return label;
311
312#if 0
293 switch ( type ) { 313 switch ( type ) {
294 case Dom: 314 case Dom:
295 return i18n("Domestic"); 315 return i18n("Domestic");
296 break; 316 break;
297 case Intl: 317 case Intl:
298 return i18n("International"); 318 return i18n("International");
299 break; 319 break;
300 case Postal: 320 case Postal:
301 return i18n("Postal"); 321 return i18n("Postal");
302 break; 322 break;
303 case Parcel: 323 case Parcel:
304 return i18n("Parcel"); 324 return i18n("Parcel");
305 break; 325 break;
306 case Home: 326 case Home:
307 return i18n("Home Address", "Home"); 327 return i18n("Home Address", "Home");
308 break; 328 break;
309 case Work: 329 case Work:
310 return i18n("Work Address", "Work"); 330 return i18n("Work Address", "Work");
311 break; 331 break;
312 case Pref: 332 case Pref:
313 return i18n("Preferred Address"); 333 return i18n("Preferred Address");
314 break; 334 break;
315 default: 335 default:
316 return i18n("Other"); 336 return i18n("Other");
317 break; 337 break;
318 } 338 }
339#endif
319} 340}
320 341
321void Address::dump() const 342void Address::dump() const
322{ 343{
323 qDebug("Address::dump() +++++++++++++++++ "); 344 qDebug("Address::dump() +++++++++++++++++ ");
324#if 0 345#if 0
325 kdDebug(5700) << " Address {" << endl; 346 kdDebug(5700) << " Address {" << endl;
326 kdDebug(5700) << " Id: " << id() << endl; 347 kdDebug(5700) << " Id: " << id() << endl;
327 kdDebug(5700) << " Extended: " << extended() << endl; 348 kdDebug(5700) << " Extended: " << extended() << endl;
328 kdDebug(5700) << " Street: " << street() << endl; 349 kdDebug(5700) << " Street: " << street() << endl;
329 kdDebug(5700) << " Postal Code: " << postalCode() << endl; 350 kdDebug(5700) << " Postal Code: " << postalCode() << endl;
330 kdDebug(5700) << " Locality: " << locality() << endl; 351 kdDebug(5700) << " Locality: " << locality() << endl;
331 kdDebug(5700) << " }" << endl; 352 kdDebug(5700) << " }" << endl;
332#endif 353#endif
333} 354}
334 355
335 356
336QString Address::formattedAddress( const QString &realName 357QString Address::formattedAddress( const QString &realName
337 , const QString &orgaName ) const 358 , const QString &orgaName ) const
338{ 359{
339 QString ciso; 360 QString ciso;
340 QString addrTemplate; 361 QString addrTemplate;
341 QString ret; 362 QString ret;
342 363
343 // ************************************************************** 364 // **************************************************************
344 // LR: currently we have no iso handling - we will format the address manually here 365 // LR: currently we have no iso handling - we will format the address manually here
345 366
346 QString text; 367 QString text;
347 if ( !street().isEmpty() ) 368 if ( !street().isEmpty() )
348 text += street() + "\n"; 369 text += street() + "\n";
349 370
350 if ( !postOfficeBox().isEmpty() ) 371 if ( !postOfficeBox().isEmpty() )
351 text += postOfficeBox() + "\n"; 372 text += postOfficeBox() + "\n";
352 373
353 text += locality() + QString(" ") + region(); 374 text += locality() + QString(" ") + region();
354 375
355 if ( !postalCode().isEmpty() ) 376 if ( !postalCode().isEmpty() )
356 text += QString(", ") + postalCode(); 377 text += QString(", ") + postalCode();
357 378
358 text += "\n"; 379 text += "\n";
359 380
360 if ( !country().isEmpty() ) 381 if ( !country().isEmpty() )
361 text += country() + "\n"; 382 text += country() + "\n";
362 383
363 text += extended(); 384 text += extended();
364 385
365 386
366 return text; 387 return text;
367 // ************************************************************** 388 // **************************************************************
368 389
369 // FIXME: first check for iso-country-field and prefer that one 390 // FIXME: first check for iso-country-field and prefer that one
370 if ( !country().isEmpty() ) { 391 if ( !country().isEmpty() ) {
371 ciso = countryToISO( country() ); 392 ciso = countryToISO( country() );
372 } else { 393 } else {
373 // fall back to our own country 394 // fall back to our own country
374 ciso = KGlobal::locale()->country(); 395 ciso = KGlobal::locale()->country();
375 } 396 }
376 //qDebug("ciso %s ",ciso.latin1() ); 397 //qDebug("ciso %s ",ciso.latin1() );
377 KSimpleConfig entry( locate( "locale", 398 KSimpleConfig entry( locate( "locale",
378 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) ); 399 QString( "l10n/" ) + ciso + QString( "/entry.desktop" ) ) );
379 entry.setGroup( "KCM Locale" ); 400 entry.setGroup( "KCM Locale" );
380 401
381 // decide whether this needs special business address formatting 402 // decide whether this needs special business address formatting
382 if ( orgaName.isNull() ) { 403 if ( orgaName.isNull() ) {
383 addrTemplate = entry.readEntry( "AddressFormat" ); 404 addrTemplate = entry.readEntry( "AddressFormat" );
384 } else { 405 } else {
385 addrTemplate = entry.readEntry( "BusinessAddressFormat" ); 406 addrTemplate = entry.readEntry( "BusinessAddressFormat" );
386 if ( addrTemplate.isEmpty() ) 407 if ( addrTemplate.isEmpty() )
387 addrTemplate = entry.readEntry( "AddressFormat" ); 408 addrTemplate = entry.readEntry( "AddressFormat" );
388 } 409 }
389 410
390 // in the case there's no format found at all, default to what we've always 411 // in the case there's no format found at all, default to what we've always
391 // used: 412 // used:
392 if ( addrTemplate.isEmpty() ) { 413 if ( addrTemplate.isEmpty() ) {
393 qDebug("address format database incomplete****************** "); 414 qDebug("address format database incomplete****************** ");
394 kdWarning(5700) << "address format database incomplete " 415 kdWarning(5700) << "address format database incomplete "
395 << "(no format for locale " << ciso 416 << "(no format for locale " << ciso
396 << " found). Using default address formatting." << endl; 417 << " found). Using default address formatting." << endl;
397 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z"; 418 addrTemplate = "%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z";
398 } 419 }
399 420
400 // scan 421 // scan
401 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName ); 422 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName );
402 423
403 // now add the country line if needed (formatting this time according to 424 // now add the country line if needed (formatting this time according to
404 // the rules of our own system country ) 425 // the rules of our own system country )
405 if ( !country().isEmpty() ) { 426 if ( !country().isEmpty() ) {
406 KSimpleConfig entry( locate( "locale", QString( "l10n/" ) 427 KSimpleConfig entry( locate( "locale", QString( "l10n/" )
407 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) ); 428 + KGlobal::locale()->country() + QString( "/entry.desktop" ) ) );
408 entry.setGroup( "KCM Locale" ); 429 entry.setGroup( "KCM Locale" );
409 QString cpos = entry.readEntry( "AddressCountryPosition" ); 430 QString cpos = entry.readEntry( "AddressCountryPosition" );
410 if ( "BELOW" == cpos || cpos.isEmpty() ) { 431 if ( "BELOW" == cpos || cpos.isEmpty() ) {
411 ret = ret + "\n\n" + country().upper(); 432 ret = ret + "\n\n" + country().upper();
412 } else if ( "below" == cpos ) { 433 } else if ( "below" == cpos ) {
413 ret = ret + "\n\n" + country(); 434 ret = ret + "\n\n" + country();
414 } else if ( "ABOVE" == cpos ) { 435 } else if ( "ABOVE" == cpos ) {
415 ret = country().upper() + "\n\n" + ret; 436 ret = country().upper() + "\n\n" + ret;
416 } else if ( "above" == cpos ) { 437 } else if ( "above" == cpos ) {
417 ret = country() + "\n\n" + ret; 438 ret = country() + "\n\n" + ret;
418 } 439 }
419 } 440 }
420 441
421 return ret; 442 return ret;
422} 443}
423 444
424bool Address::parseAddressTemplateSection( const QString &tsection, 445bool Address::parseAddressTemplateSection( const QString &tsection,
425 QString &result, const QString &realName, const QString &orgaName ) const 446 QString &result, const QString &realName, const QString &orgaName ) const
426{ 447{
427 // This method first parses and substitutes any bracketed sections and 448 // This method first parses and substitutes any bracketed sections and
428 // after that replaces any tags with their values. If a bracketed section 449 // after that replaces any tags with their values. If a bracketed section
429 // or a tag evaluate to zero, they are not just removed but replaced 450 // or a tag evaluate to zero, they are not just removed but replaced
430 // with a placeholder. This is because in the last step conditionals are 451 // with a placeholder. This is because in the last step conditionals are
431 // resolved which depend on information about zero-evaluations. 452 // resolved which depend on information about zero-evaluations.
432 result = tsection; 453 result = tsection;
433 int stpos = 0; 454 int stpos = 0;
434 bool ret = false; 455 bool ret = false;
435 456
436 // first check for brackets that have to be evaluated first 457 // first check for brackets that have to be evaluated first
437 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 458 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
438 while ( -1 != fpos ) { 459 while ( -1 != fpos ) {
439 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length(); 460 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
440 int bpos2; 461 int bpos2;
441 // expect opening bracket and find next balanced closing bracket. If 462 // expect opening bracket and find next balanced closing bracket. If
442 // next char is no opening bracket, continue parsing (no valid tag) 463 // next char is no opening bracket, continue parsing (no valid tag)
443 if ( '(' == result[bpos1] ) { 464 if ( '(' == result[bpos1] ) {
444 bpos2 = findBalancedBracket( result, bpos1 ); 465 bpos2 = findBalancedBracket( result, bpos1 );
445 if ( -1 != bpos2 ) { 466 if ( -1 != bpos2 ) {
446 // we have balanced brackets, recursively parse: 467 // we have balanced brackets, recursively parse:
447 QString rplstr; 468 QString rplstr;
448 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1, 469 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
449 bpos2-bpos1-1 ), rplstr, 470 bpos2-bpos1-1 ), rplstr,
450 realName, orgaName ); 471 realName, orgaName );
451 if ( purge ) { 472 if ( purge ) {
452 // purge -> remove all 473 // purge -> remove all
453 // replace with !_P_!, so conditional tags work later 474 // replace with !_P_!, so conditional tags work later
454 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" ); 475 result.replace( fpos, bpos2 - fpos + 1, "!_P_!" );
455 // leave stpos as it is 476 // leave stpos as it is
456 } else { 477 } else {
457 // no purge -> replace with recursively parsed string 478 // no purge -> replace with recursively parsed string
458 result.replace( fpos, bpos2 - fpos + 1, rplstr ); 479 result.replace( fpos, bpos2 - fpos + 1, rplstr );
459 ret = true; 480 ret = true;
460 stpos = fpos + rplstr.length(); 481 stpos = fpos + rplstr.length();
461 } 482 }
462 } else { 483 } else {
463 // unbalanced brackets: keep on parsing (should not happen 484 // unbalanced brackets: keep on parsing (should not happen
464 // and will result in bad formatting) 485 // and will result in bad formatting)
465 stpos = bpos1; 486 stpos = bpos1;
466 } 487 }
467 } 488 }
468 fpos = result.find( KABC_FMTTAG_purgeempty, stpos ); 489 fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
469 } 490 }
470 491
471 // after sorting out all purge tags, we just search'n'replace the rest, 492 // after sorting out all purge tags, we just search'n'replace the rest,
472 // keeping track of whether at least one tag evaluates to something. 493 // keeping track of whether at least one tag evaluates to something.
473 // The following macro needs QString for R_FIELD 494 // The following macro needs QString for R_FIELD
474 // It substitutes !_P_! for empty fields so conditional tags work later 495 // It substitutes !_P_! for empty fields so conditional tags work later
475#define REPLTAG(R_TAG,R_FIELD) \ 496#define REPLTAG(R_TAG,R_FIELD) \
476 if ( result.contains(R_TAG, false) ) { \ 497 if ( result.contains(R_TAG, false) ) { \
477 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \ 498 QString rpl = R_FIELD.isEmpty() ? QString("!_P_!") : R_FIELD; \
478 result.replace( R_TAG, rpl ); \ 499 result.replace( R_TAG, rpl ); \
479 if ( !R_FIELD.isEmpty() ) { \ 500 if ( !R_FIELD.isEmpty() ) { \
480 ret = true; \ 501 ret = true; \
481 } \ 502 } \
482 } 503 }
483 REPLTAG( KABC_FMTTAG_realname, realName ); 504 REPLTAG( KABC_FMTTAG_realname, realName );
484 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() ); 505 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() );
485 REPLTAG( KABC_FMTTAG_company, orgaName ); 506 REPLTAG( KABC_FMTTAG_company, orgaName );
486 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() ); 507 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() );
487 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() ); 508 REPLTAG( KABC_FMTTAG_pobox, postOfficeBox() );
488 REPLTAG( KABC_FMTTAG_street, street() ); 509 REPLTAG( KABC_FMTTAG_street, street() );
489 REPLTAG( KABC_FMTTAG_STREET, street().upper() ); 510 REPLTAG( KABC_FMTTAG_STREET, street().upper() );
490 REPLTAG( KABC_FMTTAG_zipcode, postalCode() ); 511 REPLTAG( KABC_FMTTAG_zipcode, postalCode() );
491 REPLTAG( KABC_FMTTAG_location, locality() ); 512 REPLTAG( KABC_FMTTAG_location, locality() );
492 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() ); 513 REPLTAG( KABC_FMTTAG_LOCATION, locality().upper() );
493 REPLTAG( KABC_FMTTAG_region, region() ); 514 REPLTAG( KABC_FMTTAG_region, region() );
494 REPLTAG( KABC_FMTTAG_REGION, region().upper() ); 515 REPLTAG( KABC_FMTTAG_REGION, region().upper() );
495 result.replace( KABC_FMTTAG_newline, "\n" ); 516 result.replace( KABC_FMTTAG_newline, "\n" );
496#undef REPLTAG 517#undef REPLTAG
497 518
498 // conditional comma 519 // conditional comma
499 fpos = result.find( KABC_FMTTAG_condcomma, 0 ); 520 fpos = result.find( KABC_FMTTAG_condcomma, 0 );
500 while ( -1 != fpos ) { 521 while ( -1 != fpos ) {
501 QString str1 = result.mid( fpos - 5, 5 ); 522 QString str1 = result.mid( fpos - 5, 5 );
502 QString str2 = result.mid( fpos + 2, 5 ); 523 QString str2 = result.mid( fpos + 2, 5 );
503 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 524 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
504 result.replace( fpos, 2, ", " ); 525 result.replace( fpos, 2, ", " );
505 } else { 526 } else {
506 result.remove( fpos, 2 ); 527 result.remove( fpos, 2 );
507 } 528 }
508 fpos = result.find( KABC_FMTTAG_condcomma, fpos ); 529 fpos = result.find( KABC_FMTTAG_condcomma, fpos );
509 } 530 }
510 // conditional whitespace 531 // conditional whitespace
511 fpos = result.find( KABC_FMTTAG_condwhite, 0 ); 532 fpos = result.find( KABC_FMTTAG_condwhite, 0 );
512 while ( -1 != fpos ) { 533 while ( -1 != fpos ) {
513 QString str1 = result.mid( fpos - 5, 5 ); 534 QString str1 = result.mid( fpos - 5, 5 );
514 QString str2 = result.mid( fpos + 2, 5 ); 535 QString str2 = result.mid( fpos + 2, 5 );
515 if ( str1 != "!_P_!" && str2 != "!_P_!" ) { 536 if ( str1 != "!_P_!" && str2 != "!_P_!" ) {
516 result.replace( fpos, 2, " " ); 537 result.replace( fpos, 2, " " );
517 } else { 538 } else {
518 result.remove( fpos, 2 ); 539 result.remove( fpos, 2 );
519 } 540 }
520 fpos = result.find( KABC_FMTTAG_condwhite, fpos ); 541 fpos = result.find( KABC_FMTTAG_condwhite, fpos );
521 } 542 }
522 543
523 // remove purged: 544 // remove purged:
524//US my QT version does not support remove. So lets do it the old fashioned way. 545//US my QT version does not support remove. So lets do it the old fashioned way.
525//US result.remove( "!_P_!" ); 546//US result.remove( "!_P_!" );
526 int n = result.find("!_P_!"); 547 int n = result.find("!_P_!");
527 if (n >= 0) 548 if (n >= 0)
528 result.remove( n, 5 ); 549 result.remove( n, 5 );
529 550
530 return ret; 551 return ret;
531} 552}
532 553
533int Address::findBalancedBracket( const QString &tsection, int pos ) const 554int Address::findBalancedBracket( const QString &tsection, int pos ) const
534{ 555{
535 int balancecounter = 0; 556 int balancecounter = 0;
536 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) { 557 for( unsigned int i = pos + 1; i < tsection.length(); i++ ) {
537 if ( ')' == tsection.at(i) && 0 == balancecounter ) { 558 if ( ')' == tsection.at(i) && 0 == balancecounter ) {
538 // found end of brackets 559 // found end of brackets
539 return i; 560 return i;
540 } else 561 } else
541 if ( '(' == tsection.at(i) ) { 562 if ( '(' == tsection.at(i) ) {
542 // nested brackets 563 // nested brackets
543 balancecounter++; 564 balancecounter++;
544 } 565 }
545 } 566 }
546 return -1; 567 return -1;
547} 568}
548 569
549QString Address::countryToISO( const QString &cname ) 570QString Address::countryToISO( const QString &cname )
550{ 571{
551 // we search a map file for translations from country names to 572 // we search a map file for translations from country names to
552 // iso codes, storing caching things in a QMap for faster future 573 // iso codes, storing caching things in a QMap for faster future
553 // access. 574 // access.
554/*US 575/*US
555 576
556 QString isoCode = mISOMap[ cname ]; 577 QString isoCode = mISOMap[ cname ];
557 if ( !isoCode.isEmpty() ) 578 if ( !isoCode.isEmpty() )
558 return isoCode; 579 return isoCode;
559 580
560 QString mapfile = KGlobal::dirs()->findResource( "data", 581 QString mapfile = KGlobal::dirs()->findResource( "data",
561 QString::fromLatin1( "kabc/countrytransl.map" ) ); 582 QString::fromLatin1( "kabc/countrytransl.map" ) );
562 583
563 QFile file( mapfile ); 584 QFile file( mapfile );
564 if ( file.open( IO_ReadOnly ) ) { 585 if ( file.open( IO_ReadOnly ) ) {
565 QTextStream s( &file ); 586 QTextStream s( &file );
566 QString strbuf = s.readLine(); 587 QString strbuf = s.readLine();
567 while( !strbuf.isNull() ) { 588 while( !strbuf.isNull() ) {
568 if ( strbuf.startsWith( cname ) ) { 589 if ( strbuf.startsWith( cname ) ) {
569 int index = strbuf.findRev('\t'); 590 int index = strbuf.findRev('\t');
570 strbuf = strbuf.mid(index+1, 2); 591 strbuf = strbuf.mid(index+1, 2);
571 file.close(); 592 file.close();
572 mISOMap[ cname ] = strbuf; 593 mISOMap[ cname ] = strbuf;
573 return strbuf; 594 return strbuf;
574 } 595 }
575 strbuf = s.readLine(); 596 strbuf = s.readLine();
576 } 597 }
577 file.close(); 598 file.close();
578 } 599 }
579*/ 600*/
580 // fall back to system country 601 // fall back to system country
581 mISOMap[ cname ] = KGlobal::locale()->country(); 602 mISOMap[ cname ] = KGlobal::locale()->country();
582 return KGlobal::locale()->country(); 603 return KGlobal::locale()->country();
583} 604}
584 605
585QString Address::ISOtoCountry( const QString &ISOname ) 606QString Address::ISOtoCountry( const QString &ISOname )
586{ 607{
587/*US 608/*US
588 // get country name from ISO country code (e.g. "no" -> i18n("Norway")) 609 // get country name from ISO country code (e.g. "no" -> i18n("Norway"))
589 QString mapfile = KGlobal::dirs()->findResource( "data", 610 QString mapfile = KGlobal::dirs()->findResource( "data",
590 QString::fromLatin1( "kabc/countrytransl.map" ) ); 611 QString::fromLatin1( "kabc/countrytransl.map" ) );
591 612
592kdWarning() << "MAPFILE : " << mapfile << endl; 613kdWarning() << "MAPFILE : " << mapfile << endl;
593 QFile file( mapfile ); 614 QFile file( mapfile );
594 if ( file.open( IO_ReadOnly ) ) { 615 if ( file.open( IO_ReadOnly ) ) {
595 QTextStream s( &file ); 616 QTextStream s( &file );
596 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower(); 617 QString searchStr = "\t" + ISOname.simplifyWhiteSpace().lower();
597kdWarning() << "Suche : " << searchStr << endl; 618kdWarning() << "Suche : " << searchStr << endl;
598 QString strbuf = s.readLine(); 619 QString strbuf = s.readLine();
599 int pos; 620 int pos;
600 while( !strbuf.isNull() ) { 621 while( !strbuf.isNull() ) {
601 if ( (pos=strbuf.find( searchStr )) != -1 ) { 622 if ( (pos=strbuf.find( searchStr )) != -1 ) {
602 file.close(); 623 file.close();
603 return i18n(strbuf.left(pos).utf8()); 624 return i18n(strbuf.left(pos).utf8());
604 } 625 }
605 strbuf = s.readLine(); 626 strbuf = s.readLine();
606 } 627 }
607 file.close(); 628 file.close();
608 } 629 }
609*/ 630*/
610 return ISOname; 631 return ISOname;
611} 632}
612 633
613QDataStream &KABC::operator<<( QDataStream &s, const Address &addr ) 634QDataStream &KABC::operator<<( QDataStream &s, const Address &addr )
614{ 635{
615 return s << addr.mId << addr.mType << addr.mPostOfficeBox << 636 return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
616 addr.mExtended << addr.mStreet << addr.mLocality << 637 addr.mExtended << addr.mStreet << addr.mLocality <<
617 addr.mRegion << addr.mPostalCode << addr.mCountry << 638 addr.mRegion << addr.mPostalCode << addr.mCountry <<
618 addr.mLabel; 639 addr.mLabel;
619} 640}
620 641
621QDataStream &KABC::operator>>( QDataStream &s, Address &addr ) 642QDataStream &KABC::operator>>( QDataStream &s, Address &addr )
622{ 643{
623 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >> 644 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
624 addr.mStreet >> addr.mLocality >> addr.mRegion >> 645 addr.mStreet >> addr.mLocality >> addr.mRegion >>
625 addr.mPostalCode >> addr.mCountry >> addr.mLabel; 646 addr.mPostalCode >> addr.mCountry >> addr.mLabel;
626 647
627 addr.mEmpty = false; 648 addr.mEmpty = false;
628 649
629 return s; 650 return s;
630} 651}