23 #include <tdeapplication.h>
26 #include <ksimpleconfig.h>
27 #include <kstandarddirs.h>
28 #include <kstaticdeleter.h>
32 using namespace TDEABC;
34 TQMap<TQString, TQString> *Address::mISOMap = 0;
38 mEmpty( true ), mType( 0 )
44 mEmpty( true ), mType( type )
49 bool Address::operator==(
const Address &a )
const
51 if ( mPostOfficeBox != a.mPostOfficeBox )
return false;
52 if ( mExtended != a.mExtended )
return false;
53 if ( mStreet != a.mStreet )
return false;
54 if ( mLocality != a.mLocality )
return false;
55 if ( mRegion != a.mRegion )
return false;
56 if ( mPostalCode != a.mPostalCode )
return false;
57 if ( mCountry != a.mCountry )
return false;
58 if ( mLabel != a.mLabel )
return false;
63 bool Address::operator!=(
const Address &a )
const
65 return !( a == *this );
70 if ( mPostOfficeBox.isEmpty() &&
71 mExtended.isEmpty() &&
73 mLocality.isEmpty() &&
75 mPostalCode.isEmpty() &&
95 TQString Address::id()
const
119 TypeList::ConstIterator it;
120 for ( it = list.begin(); it != list.end(); ++it ) {
121 if ( (
type() & (*it) ) && ( (*it) != Pref ) ) {
122 label.append( ( first ?
"" :
"/" ) +
typeLabel( *it ) );
140 return mPostOfficeBox;
145 return i18n(
"Post Office Box");
163 return i18n(
"Extended Address Information");
181 return i18n(
"Street");
199 return i18n(
"Locality");
217 return i18n(
"Region");
235 return i18n(
"Postal Code");
253 return i18n(
"Country");
271 return i18n(
"Delivery Label");
276 static TypeList list;
278 if ( list.isEmpty() )
279 list << Dom << Intl << Postal << Parcel << Home << Work << Pref;
287 return i18n(
"Preferred address",
"Preferred" );
291 return i18n(
"Domestic");
294 return i18n(
"International");
297 return i18n(
"Postal");
300 return i18n(
"Parcel");
303 return i18n(
"Home Address",
"Home");
306 return i18n(
"Work Address",
"Work");
309 return i18n(
"Preferred Address");
312 return i18n(
"Other");
330 const TQString &orgaName )
const
333 TQString addrTemplate;
344 TQString(
"l10n/" ) + ciso + TQString(
"/entry.desktop" ) ) );
348 if ( orgaName.isEmpty() ) {
349 addrTemplate = entry.
readEntry(
"AddressFormat" );
351 addrTemplate = entry.
readEntry(
"BusinessAddressFormat" );
352 if ( addrTemplate.isEmpty() )
353 addrTemplate = entry.
readEntry(
"AddressFormat" );
358 if ( addrTemplate.isEmpty() ) {
359 kdWarning(5700) <<
"address format database incomplete "
360 <<
"(no format for locale " << ciso
361 <<
" found). Using default address formatting." <<
endl;
362 addrTemplate =
"%0(%n\\n)%0(%cm\\n)%0(%s\\n)%0(PO BOX %p\\n)%0(%l%w%r)%,%z";
366 parseAddressTemplateSection( addrTemplate, ret, realName, orgaName );
374 TQString cpos = entry.
readEntry(
"AddressCountryPosition" );
375 if (
"BELOW" == cpos || cpos.isEmpty() ) {
376 ret = ret +
"\n\n" +
country().upper();
377 }
else if (
"below" == cpos ) {
378 ret = ret +
"\n\n" +
country();
379 }
else if (
"ABOVE" == cpos ) {
380 ret =
country().upper() +
"\n\n" + ret;
381 }
else if (
"above" == cpos ) {
382 ret =
country() +
"\n\n" + ret;
389 bool Address::parseAddressTemplateSection(
const TQString &tsection,
390 TQString &result,
const TQString &realName,
const TQString &orgaName )
const
402 int fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
403 while ( -1 != fpos ) {
404 int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
408 if (
'(' == result[bpos1] ) {
409 bpos2 = findBalancedBracket( result, bpos1 );
413 bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
414 bpos2-bpos1-1 ), rplstr,
415 realName, orgaName );
419 result.replace( fpos, bpos2 - fpos + 1,
"!_P_!" );
423 result.replace( fpos, bpos2 - fpos + 1, rplstr );
425 stpos = fpos + rplstr.length();
433 fpos = result.find( KABC_FMTTAG_purgeempty, stpos );
440 #define REPLTAG(R_TAG,R_FIELD) \
441 if ( result.find(R_TAG, false) != -1 ) { \
442 TQString rpl = R_FIELD.isEmpty() ? TQString("!_P_!") : R_FIELD; \
443 result.replace( R_TAG, rpl ); \
444 if ( !R_FIELD.isEmpty() ) { \
448 REPLTAG( KABC_FMTTAG_realname, realName );
449 REPLTAG( KABC_FMTTAG_REALNAME, realName.upper() );
450 REPLTAG( KABC_FMTTAG_company, orgaName );
451 REPLTAG( KABC_FMTTAG_COMPANY, orgaName.upper() );
453 REPLTAG( KABC_FMTTAG_street,
street() );
454 REPLTAG( KABC_FMTTAG_STREET,
street().upper() );
456 REPLTAG( KABC_FMTTAG_location,
locality() );
457 REPLTAG( KABC_FMTTAG_LOCATION,
locality().upper() );
458 REPLTAG( KABC_FMTTAG_region,
region() );
459 REPLTAG( KABC_FMTTAG_REGION,
region().upper() );
460 result.replace( KABC_FMTTAG_newline,
"\n" );
464 fpos = result.find( KABC_FMTTAG_condcomma, 0 );
465 while ( -1 != fpos ) {
466 TQString str1 = result.mid( fpos - 5, 5 );
467 TQString str2 = result.mid( fpos + 2, 5 );
468 if ( str1 !=
"!_P_!" && str2 !=
"!_P_!" ) {
469 result.replace( fpos, 2,
", " );
471 result.remove( fpos, 2 );
473 fpos = result.find( KABC_FMTTAG_condcomma, fpos );
476 fpos = result.find( KABC_FMTTAG_condwhite, 0 );
477 while ( -1 != fpos ) {
478 TQString str1 = result.mid( fpos - 5, 5 );
479 TQString str2 = result.mid( fpos + 2, 5 );
480 if ( str1 !=
"!_P_!" && str2 !=
"!_P_!" ) {
481 result.replace( fpos, 2,
" " );
483 result.remove( fpos, 2 );
485 fpos = result.find( KABC_FMTTAG_condwhite, fpos );
489 result.remove(
"!_P_!" );
494 int Address::findBalancedBracket(
const TQString &tsection,
int pos )
const
496 int balancecounter = 0;
497 for(
unsigned int i = pos + 1; i < tsection.length(); i++ ) {
498 if (
')' == tsection[i] && 0 == balancecounter ) {
502 if (
'(' == tsection[i] ) {
516 isoMapDeleter.setObject( mISOMap,
new TQMap<TQString, TQString>() );
518 TQMap<TQString, TQString>::ConstIterator it;
519 it = mISOMap->find( cname );
520 if ( it != mISOMap->end() )
524 TQString::fromLatin1(
"tdeabc/countrytransl.map" ) );
526 TQFile file( mapfile );
527 if ( file.open( IO_ReadOnly ) ) {
528 TQTextStream s( &file );
529 TQString strbuf = s.readLine();
530 while( !strbuf.isEmpty() ) {
531 TQStringList countryInfo = TQStringList::split(
'\t', strbuf,
true );
532 if ( countryInfo[ 0 ] == cname ) {
534 mISOMap->insert( cname, countryInfo[ 1 ] );
535 return countryInfo[ 1 ];
537 strbuf = s.readLine();
550 if ( ISOname.simplifyWhiteSpace().isEmpty() )
551 return TQString::null;
554 TQString::fromLatin1(
"tdeabc/countrytransl.map" ) );
556 TQFile file( mapfile );
557 if ( file.open( IO_ReadOnly ) ) {
558 TQTextStream s( &file );
559 TQString searchStr =
"\t" + ISOname.simplifyWhiteSpace().lower();
560 TQString strbuf = s.readLine();
562 while ( !strbuf.isEmpty() ) {
563 if ( (pos = strbuf.find( searchStr )) != -1 ) {
565 return i18n( strbuf.left( pos ).utf8() );
567 strbuf = s.readLine();
575 TQDataStream &TDEABC::operator<<( TQDataStream &s,
const Address &addr )
577 return s << addr.mId << addr.mType << addr.mPostOfficeBox <<
578 addr.mExtended << addr.mStreet << addr.mLocality <<
579 addr.mRegion << addr.mPostalCode << addr.mCountry <<
583 TQDataStream &TDEABC::operator>>( TQDataStream &s,
Address &addr )
585 s >> addr.mId >> addr.mType >> addr.mPostOfficeBox >> addr.mExtended >>
586 addr.mStreet >> addr.mLocality >> addr.mRegion >>
587 addr.mPostalCode >> addr.mCountry >> addr.mLabel;