summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (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
@@ -101,410 +101,431 @@ void Address::setId( const QString &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