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"
23 #include <KLocalizedString>
26 QString
ContactFields::label(Field field
)
30 return i18nc("@item Undefined import field type", "Undefined");
33 return KContacts::Addressee::formattedNameLabel();
35 return KContacts::Addressee::prefixLabel();
37 return KContacts::Addressee::givenNameLabel();
39 return KContacts::Addressee::additionalNameLabel();
41 return KContacts::Addressee::familyNameLabel();
43 return KContacts::Addressee::suffixLabel();
45 return KContacts::Addressee::nickNameLabel();
47 return KContacts::Addressee::birthdayLabel();
49 return i18nc("The wedding anniversary of a contact", "Anniversary");
50 case HomeAddressStreet
:
51 return KContacts::Addressee::homeAddressStreetLabel();
52 case HomeAddressPostOfficeBox
:
53 return KContacts::Addressee::homeAddressPostOfficeBoxLabel();
54 case HomeAddressLocality
:
55 return KContacts::Addressee::homeAddressLocalityLabel();
56 case HomeAddressRegion
:
57 return KContacts::Addressee::homeAddressRegionLabel();
58 case HomeAddressPostalCode
:
59 return KContacts::Addressee::homeAddressPostalCodeLabel();
60 case HomeAddressCountry
:
61 return KContacts::Addressee::homeAddressCountryLabel();
62 case HomeAddressLabel
:
63 return KContacts::Addressee::homeAddressLabelLabel();
64 case BusinessAddressStreet
:
65 return KContacts::Addressee::businessAddressStreetLabel();
66 case BusinessAddressPostOfficeBox
:
67 return KContacts::Addressee::businessAddressPostOfficeBoxLabel();
68 case BusinessAddressLocality
:
69 return KContacts::Addressee::businessAddressLocalityLabel();
70 case BusinessAddressRegion
:
71 return KContacts::Addressee::businessAddressRegionLabel();
72 case BusinessAddressPostalCode
:
73 return KContacts::Addressee::businessAddressPostalCodeLabel();
74 case BusinessAddressCountry
:
75 return KContacts::Addressee::businessAddressCountryLabel();
76 case BusinessAddressLabel
:
77 return KContacts::Addressee::businessAddressLabelLabel();
79 return KContacts::Addressee::homePhoneLabel();
81 return KContacts::Addressee::businessPhoneLabel();
83 return KContacts::Addressee::mobilePhoneLabel();
85 return KContacts::Addressee::homeFaxLabel();
87 return KContacts::Addressee::businessFaxLabel();
89 return KContacts::Addressee::carPhoneLabel();
91 return KContacts::Addressee::isdnLabel();
93 return KContacts::Addressee::pagerLabel();
95 return i18nc("Preferred email address", "EMail (preferred)");
97 return i18nc("Second email address", "EMail (2)");
99 return i18nc("Third email address", "EMail (3)");
101 return i18nc("Fourth email address", "EMail (4)");
103 return KContacts::Addressee::mailerLabel();
105 return KContacts::Addressee::titleLabel();
107 return KContacts::Addressee::roleLabel();
109 return KContacts::Addressee::organizationLabel();
111 return KContacts::Addressee::noteLabel();
113 return KContacts::Addressee::urlLabel();
115 return i18n("Blog Feed");
117 return i18n("Profession");
119 return i18n("Office");
121 return i18n("Manager");
123 return i18n("Assistant");
125 return i18n("Spouse");
131 ContactFields::Fields
ContactFields::allFields()
150 << HomeAddressPostOfficeBox
151 << HomeAddressLocality
153 << HomeAddressPostalCode
154 << HomeAddressCountry
156 << BusinessAddressStreet
157 << BusinessAddressPostOfficeBox
158 << BusinessAddressLocality
159 << BusinessAddressRegion
160 << BusinessAddressPostalCode
161 << BusinessAddressCountry
162 << BusinessAddressLabel
187 void ContactFields::setValue(Field field
, const QString
&value
, KContacts::Addressee
&contact
)
190 case ContactFields::Undefined
:
192 case ContactFields::FormattedName
:
193 contact
.setFormattedName(value
);
195 case ContactFields::GivenName
:
196 contact
.setGivenName(value
);
198 case ContactFields::FamilyName
:
199 contact
.setFamilyName(value
);
201 case ContactFields::AdditionalName
:
202 contact
.setAdditionalName(value
);
204 case ContactFields::Prefix
:
205 contact
.setPrefix(value
);
207 case ContactFields::Suffix
:
208 contact
.setSuffix(value
);
210 case ContactFields::NickName
:
211 contact
.setNickName(value
);
213 case ContactFields::Birthday
:
214 contact
.setBirthday(QDateTime::fromString(value
, Qt::ISODate
));
216 case ContactFields::Anniversary
:
217 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
218 QStringLiteral("X-Anniversary"), value
);
220 case ContactFields::PreferredEmail
:
221 contact
.insertEmail(value
, true);
223 case ContactFields::Email2
:
224 contact
.insertEmail(value
, false);
226 case ContactFields::Email3
:
227 contact
.insertEmail(value
, false);
229 case ContactFields::Email4
:
230 contact
.insertEmail(value
, false);
232 case ContactFields::Role
:
233 contact
.setRole(value
);
235 case ContactFields::Title
:
236 contact
.setTitle(value
);
238 case ContactFields::Mailer
:
239 contact
.setMailer(value
);
241 case ContactFields::Homepage
: {
242 KContacts::ResourceLocatorUrl url
;
243 url
.setUrl(QUrl(value
));
247 case ContactFields::Organization
:
248 contact
.setOrganization(value
);
250 case ContactFields::Note
:
251 contact
.setNote(value
);
253 case ContactFields::HomePhone
: {
254 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Home
);
255 number
.setNumber(value
);
256 contact
.insertPhoneNumber(number
);
259 case ContactFields::BusinessPhone
: {
260 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Work
);
261 number
.setNumber(value
);
262 contact
.insertPhoneNumber(number
);
265 case ContactFields::MobilePhone
: {
266 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Cell
);
267 number
.setNumber(value
);
268 contact
.insertPhoneNumber(number
);
271 case ContactFields::HomeFax
: {
272 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Home
|
273 KContacts::PhoneNumber::Fax
);
274 number
.setNumber(value
);
275 contact
.insertPhoneNumber(number
);
278 case ContactFields::BusinessFax
: {
279 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Work
|
280 KContacts::PhoneNumber::Fax
);
281 number
.setNumber(value
);
282 contact
.insertPhoneNumber(number
);
285 case ContactFields::CarPhone
: {
286 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Car
);
287 number
.setNumber(value
);
288 contact
.insertPhoneNumber(number
);
291 case ContactFields::Isdn
: {
292 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Isdn
);
293 number
.setNumber(value
);
294 contact
.insertPhoneNumber(number
);
297 case ContactFields::Pager
: {
298 KContacts::PhoneNumber number
= contact
.phoneNumber(KContacts::PhoneNumber::Pager
);
299 number
.setNumber(value
);
300 contact
.insertPhoneNumber(number
);
304 case ContactFields::HomeAddressStreet
: {
305 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
306 address
.setStreet(value
);
307 contact
.insertAddress(address
);
310 case ContactFields::HomeAddressPostOfficeBox
: {
311 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
312 address
.setPostOfficeBox(value
);
313 contact
.insertAddress(address
);
316 case ContactFields::HomeAddressLocality
: {
317 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
318 address
.setLocality(value
);
319 contact
.insertAddress(address
);
322 case ContactFields::HomeAddressRegion
: {
323 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
324 address
.setRegion(value
);
325 contact
.insertAddress(address
);
328 case ContactFields::HomeAddressPostalCode
: {
329 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
330 address
.setPostalCode(value
);
331 contact
.insertAddress(address
);
334 case ContactFields::HomeAddressCountry
: {
335 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
336 address
.setCountry(value
);
337 contact
.insertAddress(address
);
340 case ContactFields::HomeAddressLabel
: {
341 KContacts::Address address
= contact
.address(KContacts::Address::Home
);
342 address
.setLabel(value
);
343 contact
.insertAddress(address
);
346 case ContactFields::BusinessAddressStreet
: {
347 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
348 address
.setStreet(value
);
349 contact
.insertAddress(address
);
352 case ContactFields::BusinessAddressPostOfficeBox
: {
353 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
354 address
.setPostOfficeBox(value
);
355 contact
.insertAddress(address
);
358 case ContactFields::BusinessAddressLocality
: {
359 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
360 address
.setLocality(value
);
361 contact
.insertAddress(address
);
364 case ContactFields::BusinessAddressRegion
: {
365 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
366 address
.setRegion(value
);
367 contact
.insertAddress(address
);
370 case ContactFields::BusinessAddressPostalCode
: {
371 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
372 address
.setPostalCode(value
);
373 contact
.insertAddress(address
);
376 case ContactFields::BusinessAddressCountry
: {
377 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
378 address
.setCountry(value
);
379 contact
.insertAddress(address
);
382 case ContactFields::BusinessAddressLabel
: {
383 KContacts::Address address
= contact
.address(KContacts::Address::Work
);
384 address
.setLabel(value
);
385 contact
.insertAddress(address
);
389 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
390 QStringLiteral("BlogFeed"), value
);
393 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
394 QStringLiteral("X-Profession"), value
);
397 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
398 QStringLiteral("X-Office"), value
);
401 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
402 QStringLiteral("X-ManagersName"), value
);
405 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
406 QStringLiteral("X-AssistantsName"), value
);
409 contact
.insertCustom(QStringLiteral("KADDRESSBOOK"),
410 QStringLiteral("X-SpousesName"), value
);
415 QString
ContactFields::value(Field field
, const KContacts::Addressee
&contact
)
422 return contact
.formattedName();
425 return contact
.prefix();
428 return contact
.givenName();
431 return contact
.additionalName();
434 return contact
.familyName();
437 return contact
.suffix();
440 return contact
.nickName();
443 const QDateTime birthday
= contact
.birthday();
444 if (birthday
.date().isValid()) {
445 return birthday
.date().toString(Qt::ISODate
);
452 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"));
454 case HomeAddressStreet
: {
455 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
456 return address
.street();
459 case HomeAddressPostOfficeBox
: {
460 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
461 return address
.postOfficeBox();
464 case HomeAddressLocality
: {
465 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
466 return address
.locality();
469 case HomeAddressRegion
: {
470 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
471 return address
.region();
474 case HomeAddressPostalCode
: {
475 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
476 return address
.postalCode();
479 case HomeAddressCountry
: {
480 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
481 return address
.country();
484 case HomeAddressLabel
: {
485 const KContacts::Address address
= contact
.address(KContacts::Address::Home
);
486 return address
.label();
489 case BusinessAddressStreet
: {
490 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
491 return address
.street();
494 case BusinessAddressPostOfficeBox
: {
495 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
496 return address
.postOfficeBox();
499 case BusinessAddressLocality
: {
500 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
501 return address
.locality();
504 case BusinessAddressRegion
: {
505 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
506 return address
.region();
509 case BusinessAddressPostalCode
: {
510 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
511 return address
.postalCode();
514 case BusinessAddressCountry
: {
515 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
516 return address
.country();
519 case BusinessAddressLabel
: {
520 const KContacts::Address address
= contact
.address(KContacts::Address::Work
);
521 return address
.label();
525 return contact
.phoneNumber(KContacts::PhoneNumber::Home
).number();
528 return contact
.phoneNumber(KContacts::PhoneNumber::Work
).number();
531 return contact
.phoneNumber(KContacts::PhoneNumber::Cell
).number();
534 return contact
.phoneNumber(KContacts::PhoneNumber::Home
| KContacts::PhoneNumber::Fax
).number();
537 return contact
.phoneNumber(KContacts::PhoneNumber::Work
| KContacts::PhoneNumber::Fax
).number();
540 return contact
.phoneNumber(KContacts::PhoneNumber::Car
).number();
543 return contact
.phoneNumber(KContacts::PhoneNumber::Isdn
).number();
546 return contact
.phoneNumber(KContacts::PhoneNumber::Pager
).number();
548 case PreferredEmail
: {
549 const QStringList emails
= contact
.emails();
550 if (emails
.count() > 0) {
558 const QStringList emails
= contact
.emails();
559 if (emails
.count() > 1) {
567 const QStringList emails
= contact
.emails();
568 if (emails
.count() > 2) {
576 const QStringList emails
= contact
.emails();
577 if (emails
.count() > 3) {
585 return contact
.mailer();
588 return contact
.title();
591 return contact
.role();
594 return contact
.organization();
597 return contact
.note();
600 return contact
.url().url().url();
603 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"));
606 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"));
609 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"));
612 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"));
615 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"));
618 return contact
.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"));