22 #include <tdeconfig.h>
23 #include <tdeglobal.h>
30 class Field::FieldImpl
33 FieldImpl(
int fieldId,
int category = 0,
34 const TQString &label = TQString::null,
35 const TQString &key = TQString::null,
36 const TQString &app = TQString::null )
37 : mFieldId( fieldId ), mCategory( category ), mLabel(
label ),
38 mKey(
key ), mApp( app ) {}
46 int fieldId() {
return mFieldId; }
47 int category() {
return mCategory; }
49 TQString
label() {
return mLabel; }
50 TQString
key() {
return mKey; }
51 TQString app() {
return mApp; }
63 Field::List Field::mAllFields;
64 Field::List Field::mDefaultFields;
65 Field::List Field::mCustomFields;
68 Field::Field( FieldImpl *impl )
78 TQString Field::label()
80 switch ( mImpl->fieldId() ) {
82 case FieldImpl::CustomField:
83 return mImpl->label();
85 return i18n(
"Unknown Field");
91 return mImpl->category();
94 TQString Field::categoryLabel(
int category )
100 return i18n(
"Frequent");
102 return i18n(
"street/postal",
"Address");
104 return i18n(
"Email");
106 return i18n(
"Personal");
108 return i18n(
"Organization");
110 return i18n(
"Custom");
112 return i18n(
"Undefined");
118 switch ( mImpl->fieldId() ) {
120 case FieldImpl::Email:
122 case FieldImpl::Birthday:
123 if ( a.birthday().isValid() )
124 return a.birthday().date().toString( Qt::ISODate );
126 return TQString::null;
128 return a.url().prettyURL();
129 case FieldImpl::HomePhone:
131 PhoneNumber::List::ConstIterator it;
135 const PhoneNumber::List list = a.
phoneNumbers( PhoneNumber::Home | PhoneNumber::Pref );
136 for ( it = list.begin(); it != list.end(); ++it )
137 if ( ((*it).type() & ~(PhoneNumber::Pref)) == PhoneNumber::Home )
138 return (*it).number();
143 const PhoneNumber::List list = a.
phoneNumbers( PhoneNumber::Home );
144 for ( it = list.begin(); it != list.end(); ++it )
145 if ( ((*it).type() & ~(PhoneNumber::Pref)) == PhoneNumber::Home )
146 return (*it).number();
149 return TQString::null;
151 case FieldImpl::BusinessPhone:
153 PhoneNumber::List::ConstIterator it;
157 const PhoneNumber::List list = a.
phoneNumbers( PhoneNumber::Work | PhoneNumber::Pref );
158 for ( it = list.begin(); it != list.end(); ++it )
159 if ( ((*it).type() & ~(PhoneNumber::Pref)) == PhoneNumber::Work )
160 return (*it).number();
165 const PhoneNumber::List list = a.
phoneNumbers( PhoneNumber::Work );
166 for ( it = list.begin(); it != list.end(); ++it )
167 if ( ((*it).type() & ~(PhoneNumber::Pref)) == PhoneNumber::Work )
168 return (*it).number();
171 return TQString::null;
173 case FieldImpl::MobilePhone:
175 case FieldImpl::HomeFax:
177 case FieldImpl::BusinessFax:
179 case FieldImpl::CarPhone:
181 case FieldImpl::Isdn:
183 case FieldImpl::Pager:
185 case FieldImpl::HomeAddressStreet:
187 case FieldImpl::HomeAddressPostOfficeBox:
189 case FieldImpl::HomeAddressLocality:
191 case FieldImpl::HomeAddressRegion:
193 case FieldImpl::HomeAddressPostalCode:
195 case FieldImpl::HomeAddressCountry:
197 case FieldImpl::HomeAddressLabel:
199 case FieldImpl::BusinessAddressStreet:
201 case FieldImpl::BusinessAddressPostOfficeBox:
203 case FieldImpl::BusinessAddressLocality:
205 case FieldImpl::BusinessAddressRegion:
207 case FieldImpl::BusinessAddressPostalCode:
209 case FieldImpl::BusinessAddressCountry:
211 case FieldImpl::BusinessAddressLabel:
213 case FieldImpl::CustomField:
214 return a.
custom( mImpl->app(), mImpl->key() );
216 return TQString::null;
222 switch ( mImpl->fieldId() ) {
224 case FieldImpl::MobilePhone:
231 case FieldImpl::HomeFax:
238 case FieldImpl::BusinessFax:
245 case FieldImpl::CarPhone:
252 case FieldImpl::Isdn:
259 case FieldImpl::Pager:
266 case FieldImpl::HomeAddressStreet:
273 case FieldImpl::HomeAddressPostOfficeBox:
280 case FieldImpl::HomeAddressLocality:
287 case FieldImpl::HomeAddressRegion:
294 case FieldImpl::HomeAddressPostalCode:
301 case FieldImpl::HomeAddressCountry:
308 case FieldImpl::HomeAddressLabel:
315 case FieldImpl::BusinessAddressStreet:
322 case FieldImpl::BusinessAddressPostOfficeBox:
329 case FieldImpl::BusinessAddressLocality:
336 case FieldImpl::BusinessAddressRegion:
343 case FieldImpl::BusinessAddressPostalCode:
350 case FieldImpl::BusinessAddressCountry:
357 case FieldImpl::BusinessAddressLabel:
364 case FieldImpl::Birthday:
365 a.setBirthday( TQT_TQDATE_OBJECT(TQDate::fromString( value, Qt::ISODate )) );
367 case FieldImpl::CustomField:
377 switch ( mImpl->fieldId() ) {
379 case FieldImpl::Birthday:
380 if ( a.birthday().isValid() ) {
381 TQDate date = TQT_TQDATE_OBJECT(a.birthday().date());
383 key.sprintf(
"%02d-%02d", date.month(), date.day() );
386 return TQString(
"00-00" );
388 return value( a ).lower();
392 bool Field::isCustom()
394 return mImpl->fieldId() == FieldImpl::CustomField;
397 Field::List Field::allFields()
399 if ( mAllFields.isEmpty() ) {
406 Field::List Field::defaultFields()
408 if ( mDefaultFields.isEmpty() ) {
409 createDefaultField( FieldImpl::FormattedName );
410 createDefaultField( FieldImpl::Email );
413 return mDefaultFields;
416 void Field::createField(
int id,
int category )
418 mAllFields.append(
new Field(
new FieldImpl(
id, category ) ) );
421 void Field::createDefaultField(
int id,
int category )
423 mDefaultFields.append(
new Field(
new FieldImpl(
id, category ) ) );
426 void Field::deleteFields()
428 Field::List::ConstIterator it;
430 for ( it = mAllFields.constBegin(); it != mAllFields.constEnd(); ++it ) {
435 for ( it = mDefaultFields.constBegin(); it != mDefaultFields.constEnd(); ++it ) {
438 mDefaultFields.clear();
440 for ( it = mCustomFields.constBegin(); it != mCustomFields.constEnd(); ++it ) {
443 mCustomFields.clear();
446 void Field::saveFields(
const TQString &identifier,
447 const Field::List &fields )
452 saveFields( cfg, identifier, fields );
455 void Field::saveFields(
TDEConfig *cfg,
const TQString &identifier,
456 const Field::List &fields )
458 TQValueList<int> fieldIds;
461 Field::List::ConstIterator it;
462 for( it = fields.begin(); it != fields.end(); ++it ) {
463 fieldIds.append( (*it)->mImpl->fieldId() );
464 if( (*it)->isCustom() ) {
465 TQStringList customEntry;
466 customEntry << (*it)->mImpl->label();
467 customEntry << (*it)->mImpl->key();
468 customEntry << (*it)->mImpl->app();
469 cfg->writeEntry(
"KABC_CustomEntry_" + identifier +
"_" +
470 TQString::number( custom++ ), customEntry );
474 cfg->writeEntry( identifier, fieldIds );
477 Field::List Field::restoreFields(
const TQString &identifier )
482 return restoreFields( cfg, identifier );
485 Field::List Field::restoreFields(
TDEConfig *cfg,
const TQString &identifier )
487 const TQValueList<int> fieldIds = cfg->readIntListEntry( identifier );
492 TQValueList<int>::ConstIterator it;
493 for( it = fieldIds.begin(); it != fieldIds.end(); ++it ) {
495 if ( (*it) == FieldImpl::CustomField ) {
496 TQStringList customEntry = cfg->readListEntry(
"KABC_CustomEntry_" +
498 TQString::number( custom++ ) );
499 f =
new FieldImpl( *it, CustomCategory, customEntry[ 0 ],
500 customEntry[ 1 ], customEntry[ 2 ] );
502 f =
new FieldImpl( *it );
504 fields.append(
new Field( f ) );
510 bool Field::equals( Field *field )
512 bool sameId = ( mImpl->fieldId() == field->mImpl->fieldId() );
514 if ( !sameId )
return false;
516 if ( mImpl->fieldId() != FieldImpl::CustomField )
return true;
518 return mImpl->key() == field->mImpl->key();
521 Field *Field::createCustomField(
const TQString &label,
int category,
522 const TQString &key,
const TQString &app )
524 Field *field =
new Field(
new FieldImpl( FieldImpl::CustomField,
525 category | CustomCategory,
527 mCustomFields.append( field );
TQString street() const
Returns the street.
void setCountry(const TQString &)
Sets the country.
void setRegion(const TQString &)
Sets the region, e.g.
void setPostOfficeBox(const TQString &)
Sets the post office box.
void setStreet(const TQString &)
Sets the street (including number).
TQString custom(const TQString &app, const TQString &name) const
Return value of custom entry, identified by app and entry name.
int key(StdAccel) KDE_DEPRECATED
void insertAddress(const Address &address)
Insert an address.
TQString postOfficeBox() const
Returns the post office box.
TQString number() const
Returns the number.
static data, shared by ALL addressee objects
void setNumber(const TQString &)
Sets the number.
PhoneNumber::List phoneNumbers() const
Return list of all phone numbers.
PhoneNumber phoneNumber(int type) const
Return phone number, which matches the given type.
Postal address information.
TQString locality() const
Returns the locality.
TQString label() const
Returns the delivery label.
TQString postalCode() const
Returns the postal code.
TQString region() const
Returns the region.
void setPostalCode(const TQString &)
Sets the postal code.
Address address(int type) const
Return address, which matches the given type.
TQString preferredEmail() const
Return preferred email address.
static TDEConfig * config()
void insertCustom(const TQString &app, const TQString &name, const TQString &value)
Insert custom entry.
TQString country() const
Returns the country.
TQString label(StdAccel id)
void insertPhoneNumber(const PhoneNumber &phoneNumber)
Insert a phone number.
void setLocality(const TQString &)
Sets the locality, e.g.
void setLabel(const TQString &)
Sets the delivery label.