2 This file is part of KAddressBook.
4 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "contactfields.h"
25 QString
ContactFields::label( Field field
)
28 case Undefined
: return i18nc( "@item Undefined import field type", "Undefined" ); break;
29 case FormattedName
: return KABC::Addressee::formattedNameLabel(); break;
30 case Prefix
: return KABC::Addressee::prefixLabel(); break;
31 case GivenName
: return KABC::Addressee::givenNameLabel(); break;
32 case AdditionalName
: return KABC::Addressee::additionalNameLabel(); break;
33 case FamilyName
: return KABC::Addressee::familyNameLabel(); break;
34 case Suffix
: return KABC::Addressee::suffixLabel(); break;
35 case NickName
: return KABC::Addressee::nickNameLabel(); break;
36 case Birthday
: return KABC::Addressee::birthdayLabel(); break;
37 case Anniversary
: return i18n( "Anniversary" ); break;
38 case HomeAddressStreet
: return KABC::Addressee::homeAddressStreetLabel(); break;
39 case HomeAddressLocality
: return KABC::Addressee::homeAddressLocalityLabel(); break;
40 case HomeAddressRegion
: return KABC::Addressee::homeAddressRegionLabel(); break;
41 case HomeAddressPostalCode
: return KABC::Addressee::homeAddressPostalCodeLabel(); break;
42 case HomeAddressCountry
: return KABC::Addressee::homeAddressCountryLabel(); break;
43 case HomeAddressLabel
: return KABC::Addressee::homeAddressLabelLabel(); break;
44 case BusinessAddressStreet
: return KABC::Addressee::businessAddressStreetLabel(); break;
45 case BusinessAddressLocality
: return KABC::Addressee::businessAddressLocalityLabel(); break;
46 case BusinessAddressRegion
: return KABC::Addressee::businessAddressRegionLabel(); break;
47 case BusinessAddressPostalCode
: return KABC::Addressee::businessAddressPostalCodeLabel(); break;
48 case BusinessAddressCountry
: return KABC::Addressee::businessAddressCountryLabel(); break;
49 case BusinessAddressLabel
: return KABC::Addressee::businessAddressLabelLabel(); break;
50 case HomePhone
: return KABC::Addressee::homePhoneLabel(); break;
51 case BusinessPhone
: return KABC::Addressee::businessPhoneLabel(); break;
52 case MobilePhone
: return KABC::Addressee::mobilePhoneLabel(); break;
53 case HomeFax
: return KABC::Addressee::homeFaxLabel(); break;
54 case BusinessFax
: return KABC::Addressee::businessFaxLabel(); break;
55 case CarPhone
: return KABC::Addressee::carPhoneLabel(); break;
56 case Isdn
: return KABC::Addressee::isdnLabel(); break;
57 case Pager
: return KABC::Addressee::pagerLabel(); break;
58 case PreferredEmail
: return i18nc( "Preferred email address", "EMail (preferred)" ); break;
59 case Email2
: return i18nc( "Second email address", "EMail (2)" ); break;
60 case Email3
: return i18nc( "Third email address", "EMail (3)" ); break;
61 case Email4
: return i18nc( "Fourth email address", "EMail (4)" ); break;
62 case Mailer
: return KABC::Addressee::mailerLabel(); break;
63 case Title
: return KABC::Addressee::titleLabel(); break;
64 case Role
: return KABC::Addressee::roleLabel(); break;
65 case Organization
: return KABC::Addressee::organizationLabel(); break;
66 case Note
: return KABC::Addressee::noteLabel(); break;
67 case Homepage
: return KABC::Addressee::urlLabel(); break;
73 ContactFields::Fields
ContactFields::allFields()
92 << HomeAddressLocality
94 << HomeAddressPostalCode
97 << BusinessAddressStreet
98 << BusinessAddressLocality
99 << BusinessAddressRegion
100 << BusinessAddressPostalCode
101 << BusinessAddressCountry
102 << BusinessAddressLabel
121 void ContactFields::setValue( Field field
, const QString
&value
, KABC::Addressee
&contact
)
124 case ContactFields::Undefined
:
126 case ContactFields::FormattedName
:
127 contact
.setFormattedName( value
);
129 case ContactFields::GivenName
:
130 contact
.setGivenName( value
);
132 case ContactFields::FamilyName
:
133 contact
.setFamilyName( value
);
135 case ContactFields::AdditionalName
:
136 contact
.setAdditionalName( value
);
138 case ContactFields::Prefix
:
139 contact
.setPrefix( value
);
141 case ContactFields::Suffix
:
142 contact
.setSuffix( value
);
144 case ContactFields::NickName
:
145 contact
.setNickName( value
);
147 case ContactFields::Birthday
:
148 contact
.setBirthday( QDateTime::fromString( value
, Qt::ISODate
) );
150 case ContactFields::Anniversary
:
151 contact
.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Anniversary" ), value
);
153 case ContactFields::PreferredEmail
:
154 contact
.insertEmail( value
, true );
156 case ContactFields::Email2
:
157 contact
.insertEmail( value
, false );
159 case ContactFields::Email3
:
160 contact
.insertEmail( value
, false );
162 case ContactFields::Email4
:
163 contact
.insertEmail( value
, false );
165 case ContactFields::Role
:
166 contact
.setRole( value
);
168 case ContactFields::Title
:
169 contact
.setTitle( value
);
171 case ContactFields::Mailer
:
172 contact
.setMailer( value
);
174 case ContactFields::Homepage
:
175 contact
.setUrl( KUrl( value
) );
177 case ContactFields::Organization
:
178 contact
.setOrganization( value
);
180 case ContactFields::Note
:
181 contact
.setNote( value
);
183 case ContactFields::HomePhone
:
185 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Home
);
186 number
.setNumber( value
);
187 contact
.insertPhoneNumber( number
);
190 case ContactFields::BusinessPhone
:
192 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Work
);
193 number
.setNumber( value
);
194 contact
.insertPhoneNumber( number
);
197 case ContactFields::MobilePhone
:
199 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Cell
);
200 number
.setNumber( value
);
201 contact
.insertPhoneNumber( number
);
204 case ContactFields::HomeFax
:
206 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Home
|
207 KABC::PhoneNumber::Fax
);
208 number
.setNumber( value
);
209 contact
.insertPhoneNumber( number
);
212 case ContactFields::BusinessFax
:
214 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Work
|
215 KABC::PhoneNumber::Fax
);
216 number
.setNumber( value
);
217 contact
.insertPhoneNumber( number
);
220 case ContactFields::CarPhone
:
222 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Car
);
223 number
.setNumber( value
);
224 contact
.insertPhoneNumber( number
);
227 case ContactFields::Isdn
:
229 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Isdn
);
230 number
.setNumber( value
);
231 contact
.insertPhoneNumber( number
);
234 case ContactFields::Pager
:
236 KABC::PhoneNumber number
= contact
.phoneNumber( KABC::PhoneNumber::Pager
);
237 number
.setNumber( value
);
238 contact
.insertPhoneNumber( number
);
242 case ContactFields::HomeAddressStreet
:
244 KABC::Address address
= contact
.address( KABC::Address::Home
);
245 address
.setStreet( value
);
246 contact
.insertAddress( address
);
249 case ContactFields::HomeAddressLocality
:
251 KABC::Address address
= contact
.address( KABC::Address::Home
);
252 address
.setLocality( value
);
253 contact
.insertAddress( address
);
256 case ContactFields::HomeAddressRegion
:
258 KABC::Address address
= contact
.address( KABC::Address::Home
);
259 address
.setRegion( value
);
260 contact
.insertAddress( address
);
263 case ContactFields::HomeAddressPostalCode
:
265 KABC::Address address
= contact
.address( KABC::Address::Home
);
266 address
.setPostalCode( value
);
267 contact
.insertAddress( address
);
270 case ContactFields::HomeAddressCountry
:
272 KABC::Address address
= contact
.address( KABC::Address::Home
);
273 address
.setCountry( value
);
274 contact
.insertAddress( address
);
277 case ContactFields::HomeAddressLabel
:
279 KABC::Address address
= contact
.address( KABC::Address::Home
);
280 address
.setLabel( value
);
281 contact
.insertAddress( address
);
284 case ContactFields::BusinessAddressStreet
:
286 KABC::Address address
= contact
.address( KABC::Address::Work
);
287 address
.setStreet( value
);
288 contact
.insertAddress( address
);
291 case ContactFields::BusinessAddressLocality
:
293 KABC::Address address
= contact
.address( KABC::Address::Work
);
294 address
.setLocality( value
);
295 contact
.insertAddress( address
);
298 case ContactFields::BusinessAddressRegion
:
300 KABC::Address address
= contact
.address( KABC::Address::Work
);
301 address
.setRegion( value
);
302 contact
.insertAddress( address
);
305 case ContactFields::BusinessAddressPostalCode
:
307 KABC::Address address
= contact
.address( KABC::Address::Work
);
308 address
.setPostalCode( value
);
309 contact
.insertAddress( address
);
312 case ContactFields::BusinessAddressCountry
:
314 KABC::Address address
= contact
.address( KABC::Address::Work
);
315 address
.setCountry( value
);
316 contact
.insertAddress( address
);
319 case ContactFields::BusinessAddressLabel
:
321 KABC::Address address
= contact
.address( KABC::Address::Work
);
322 address
.setLabel( value
);
323 contact
.insertAddress( address
);
329 QString
ContactFields::value( Field field
, const KABC::Addressee
&contact
)
332 case Undefined
: return QString(); break;
333 case FormattedName
: return contact
.formattedName(); break;
334 case Prefix
: return contact
.prefix(); break;
335 case GivenName
: return contact
.givenName(); break;
336 case AdditionalName
: return contact
.additionalName(); break;
337 case FamilyName
: return contact
.familyName(); break;
338 case Suffix
: return contact
.suffix(); break;
339 case NickName
: return contact
.nickName(); break;
342 const QDateTime birthday
= contact
.birthday();
343 if ( birthday
.isValid() )
344 return birthday
.toString( Qt::ISODate
);
349 case Anniversary
: return contact
.custom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Anniversary" ) ); break;
350 case HomeAddressStreet
:
352 const KABC::Address address
= contact
.address( KABC::Address::Home
);
353 return address
.street();
356 case HomeAddressLocality
:
358 const KABC::Address address
= contact
.address( KABC::Address::Home
);
359 return address
.locality();
362 case HomeAddressRegion
:
364 const KABC::Address address
= contact
.address( KABC::Address::Home
);
365 return address
.region();
368 case HomeAddressPostalCode
:
370 const KABC::Address address
= contact
.address( KABC::Address::Home
);
371 return address
.postalCode();
374 case HomeAddressCountry
:
376 const KABC::Address address
= contact
.address( KABC::Address::Home
);
377 return address
.country();
380 case HomeAddressLabel
:
382 const KABC::Address address
= contact
.address( KABC::Address::Home
);
383 return address
.label();
386 case BusinessAddressStreet
:
388 const KABC::Address address
= contact
.address( KABC::Address::Work
);
389 return address
.street();
392 case BusinessAddressLocality
:
394 const KABC::Address address
= contact
.address( KABC::Address::Work
);
395 return address
.locality();
398 case BusinessAddressRegion
:
400 const KABC::Address address
= contact
.address( KABC::Address::Work
);
401 return address
.region();
404 case BusinessAddressPostalCode
:
406 const KABC::Address address
= contact
.address( KABC::Address::Work
);
407 return address
.postalCode();
410 case BusinessAddressCountry
:
412 const KABC::Address address
= contact
.address( KABC::Address::Work
);
413 return address
.country();
416 case BusinessAddressLabel
:
418 const KABC::Address address
= contact
.address( KABC::Address::Work
);
419 return address
.label();
422 case HomePhone
: return contact
.phoneNumber( KABC::PhoneNumber::Home
).number(); break;
423 case BusinessPhone
: return contact
.phoneNumber( KABC::PhoneNumber::Work
).number(); break;
424 case MobilePhone
: return contact
.phoneNumber( KABC::PhoneNumber::Cell
).number(); break;
425 case HomeFax
: return contact
.phoneNumber( KABC::PhoneNumber::Home
| KABC::PhoneNumber::Fax
).number(); break;
426 case BusinessFax
: return contact
.phoneNumber( KABC::PhoneNumber::Work
| KABC::PhoneNumber::Fax
).number(); break;
427 case CarPhone
: return contact
.phoneNumber( KABC::PhoneNumber::Car
).number(); break;
428 case Isdn
: return contact
.phoneNumber( KABC::PhoneNumber::Isdn
).number(); break;
429 case Pager
: return contact
.phoneNumber( KABC::PhoneNumber::Pager
).number(); break;
432 const QStringList emails
= contact
.emails();
433 if ( emails
.count() > 0 )
434 return emails
.at( 0 );
440 const QStringList emails
= contact
.emails();
441 if ( emails
.count() > 1 )
442 return emails
.at( 1 );
448 const QStringList emails
= contact
.emails();
449 if ( emails
.count() > 2 )
450 return emails
.at( 2 );
456 const QStringList emails
= contact
.emails();
457 if ( emails
.count() > 3 )
458 return emails
.at( 3 );
462 case Mailer
: return contact
.mailer(); break;
463 case Title
: return contact
.title(); break;
464 case Role
: return contact
.role(); break;
465 case Organization
: return contact
.organization(); break;
466 case Note
: return contact
.note(); break;
467 case Homepage
: return contact
.url().url(); break;