Kdepim-apps-lib

kaddressbookimportexportcontactfields.cpp
1 /*
2  This file is part of KAddressBook.
3 
4  Copyright (c) 2009 Tobias Koenig <[email protected]>
5 
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.
10 
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.
15 
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.
19 */
20 
21 #include "kaddressbookimportexportcontactfields.h"
22 
23 #include <KLocalizedString>
24 #include <QUrl>
25 using namespace KAddressBookImportExport;
26 
28 {
29  switch (field) {
30  case Undefined:
31  return i18nc("@item Undefined import field type", "Undefined");
32  break;
33  case FormattedName:
35  case Prefix:
37  case GivenName:
39  case AdditionalName:
41  case FamilyName:
43  case Suffix:
45  case NickName:
47  case Birthday:
49  case Anniversary:
50  return i18nc("The wedding anniversary of a contact", "Anniversary");
51  case HomeAddressStreet:
53  case HomeAddressPostOfficeBox:
55  case HomeAddressLocality:
57  case HomeAddressRegion:
59  case HomeAddressPostalCode:
61  case HomeAddressCountry:
63  case HomeAddressLabel:
65  case BusinessAddressStreet:
67  case BusinessAddressPostOfficeBox:
69  case BusinessAddressLocality:
71  case BusinessAddressRegion:
73  case BusinessAddressPostalCode:
75  case BusinessAddressCountry:
77  case BusinessAddressLabel:
79  case HomePhone:
81  case BusinessPhone:
83  case MobilePhone:
85  case HomeFax:
87  case BusinessFax:
89  case CarPhone:
91  case Isdn:
93  case Pager:
95  case PreferredEmail:
96  return i18nc("Preferred email address", "EMail (preferred)");
97  case Email2:
98  return i18nc("Second email address", "EMail (2)");
99  case Email3:
100  return i18nc("Third email address", "EMail (3)");
101  case Email4:
102  return i18nc("Fourth email address", "EMail (4)");
103  case Mailer:
105  case Title:
107  case Role:
109  case Organization:
111  case Note:
113  case Homepage:
115  case BlogFeed:
116  return i18n("Blog Feed");
117  case Profession:
118  return i18n("Profession");
119  case Office:
120  return i18n("Office");
121  case Manager:
122  return i18n("Manager");
123  case Assistant:
124  return i18n("Assistant");
125  case Spouse:
126  return i18n("Spouse");
127  }
128 
129  return QString();
130 }
131 
133 {
134  Fields fields;
135 
136  fields << Undefined
137  << FormattedName
138  << Prefix
139  << GivenName
140  << AdditionalName
141  << FamilyName
142  << Suffix
143  << NickName
144  << Birthday
145  << Anniversary
146  << PreferredEmail
147  << Email2
148  << Email3
149  << Email4
150  << HomeAddressStreet
151  << HomeAddressPostOfficeBox
152  << HomeAddressLocality
153  << HomeAddressRegion
154  << HomeAddressPostalCode
155  << HomeAddressCountry
156  << HomeAddressLabel
157  << BusinessAddressStreet
158  << BusinessAddressPostOfficeBox
159  << BusinessAddressLocality
160  << BusinessAddressRegion
161  << BusinessAddressPostalCode
162  << BusinessAddressCountry
163  << BusinessAddressLabel
164  << HomePhone
165  << BusinessPhone
166  << MobilePhone
167  << HomeFax
168  << BusinessFax
169  << CarPhone
170  << Isdn
171  << Pager
172  << Mailer
173  << Title
174  << Role
175  << Organization
176  << Note
177  << Homepage
178  << BlogFeed
179  << Profession
180  << Office
181  << Manager
182  << Assistant
183  << Spouse;
184 
185  return fields;
186 }
187 
189 {
190  switch (field) {
191  case KAddressBookImportExportContactFields::Undefined:
192  break;
193  case KAddressBookImportExportContactFields::FormattedName:
194  contact.setFormattedName(value);
195  break;
196  case KAddressBookImportExportContactFields::GivenName:
197  contact.setGivenName(value);
198  break;
199  case KAddressBookImportExportContactFields::FamilyName:
200  contact.setFamilyName(value);
201  break;
202  case KAddressBookImportExportContactFields::AdditionalName:
203  contact.setAdditionalName(value);
204  break;
205  case KAddressBookImportExportContactFields::Prefix:
206  contact.setPrefix(value);
207  break;
208  case KAddressBookImportExportContactFields::Suffix:
209  contact.setSuffix(value);
210  break;
211  case KAddressBookImportExportContactFields::NickName:
212  contact.setNickName(value);
213  break;
214  case KAddressBookImportExportContactFields::Birthday:
215  contact.setBirthday(QDate::fromString(value, Qt::ISODate));
216  break;
217  case KAddressBookImportExportContactFields::Anniversary:
218  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
219  QStringLiteral("X-Anniversary"), value);
220  break;
221  case KAddressBookImportExportContactFields::PreferredEmail:
222  contact.insertEmail(value, true);
223  break;
224  case KAddressBookImportExportContactFields::Email2:
225  contact.insertEmail(value, false);
226  break;
227  case KAddressBookImportExportContactFields::Email3:
228  contact.insertEmail(value, false);
229  break;
230  case KAddressBookImportExportContactFields::Email4:
231  contact.insertEmail(value, false);
232  break;
233  case KAddressBookImportExportContactFields::Role:
234  contact.setRole(value);
235  break;
236  case KAddressBookImportExportContactFields::Title:
237  contact.setTitle(value);
238  break;
239  case KAddressBookImportExportContactFields::Mailer:
240  contact.setMailer(value);
241  break;
242  case KAddressBookImportExportContactFields::Homepage:
243  {
245  url.setUrl(QUrl(value));
246  contact.setUrl(url);
247  break;
248  }
249  case KAddressBookImportExportContactFields::Organization:
250  contact.setOrganization(value);
251  break;
252  case KAddressBookImportExportContactFields::Note:
253  contact.setNote(value);
254  break;
255  case KAddressBookImportExportContactFields::HomePhone:
256  {
258  number.setNumber(value);
259  contact.insertPhoneNumber(number);
260  break;
261  }
262  case KAddressBookImportExportContactFields::BusinessPhone:
263  {
265  number.setNumber(value);
266  contact.insertPhoneNumber(number);
267  break;
268  }
269  case KAddressBookImportExportContactFields::MobilePhone:
270  {
272  number.setNumber(value);
273  contact.insertPhoneNumber(number);
274  break;
275  }
276  case KAddressBookImportExportContactFields::HomeFax:
277  {
280  number.setNumber(value);
281  contact.insertPhoneNumber(number);
282  break;
283  }
284  case KAddressBookImportExportContactFields::BusinessFax:
285  {
288  number.setNumber(value);
289  contact.insertPhoneNumber(number);
290  break;
291  }
292  case KAddressBookImportExportContactFields::CarPhone:
293  {
295  number.setNumber(value);
296  contact.insertPhoneNumber(number);
297  break;
298  }
299  case KAddressBookImportExportContactFields::Isdn:
300  {
302  number.setNumber(value);
303  contact.insertPhoneNumber(number);
304  break;
305  }
306  case KAddressBookImportExportContactFields::Pager:
307  {
309  number.setNumber(value);
310  contact.insertPhoneNumber(number);
311  break;
312  }
313 
314  case KAddressBookImportExportContactFields::HomeAddressStreet:
315  {
317  address.setStreet(value);
318  contact.insertAddress(address);
319  break;
320  }
321  case KAddressBookImportExportContactFields::HomeAddressPostOfficeBox:
322  {
324  address.setPostOfficeBox(value);
325  contact.insertAddress(address);
326  break;
327  }
328  case KAddressBookImportExportContactFields::HomeAddressLocality:
329  {
331  address.setLocality(value);
332  contact.insertAddress(address);
333  break;
334  }
335  case KAddressBookImportExportContactFields::HomeAddressRegion:
336  {
338  address.setRegion(value);
339  contact.insertAddress(address);
340  break;
341  }
342  case KAddressBookImportExportContactFields::HomeAddressPostalCode:
343  {
345  address.setPostalCode(value);
346  contact.insertAddress(address);
347  break;
348  }
349  case KAddressBookImportExportContactFields::HomeAddressCountry:
350  {
352  address.setCountry(value);
353  contact.insertAddress(address);
354  break;
355  }
356  case KAddressBookImportExportContactFields::HomeAddressLabel:
357  {
359  address.setLabel(value);
360  contact.insertAddress(address);
361  break;
362  }
363  case KAddressBookImportExportContactFields::BusinessAddressStreet:
364  {
366  address.setStreet(value);
367  contact.insertAddress(address);
368  break;
369  }
370  case KAddressBookImportExportContactFields::BusinessAddressPostOfficeBox:
371  {
373  address.setPostOfficeBox(value);
374  contact.insertAddress(address);
375  break;
376  }
377  case KAddressBookImportExportContactFields::BusinessAddressLocality:
378  {
380  address.setLocality(value);
381  contact.insertAddress(address);
382  break;
383  }
384  case KAddressBookImportExportContactFields::BusinessAddressRegion:
385  {
387  address.setRegion(value);
388  contact.insertAddress(address);
389  break;
390  }
391  case KAddressBookImportExportContactFields::BusinessAddressPostalCode:
392  {
394  address.setPostalCode(value);
395  contact.insertAddress(address);
396  break;
397  }
398  case KAddressBookImportExportContactFields::BusinessAddressCountry:
399  {
401  address.setCountry(value);
402  contact.insertAddress(address);
403  break;
404  }
405  case KAddressBookImportExportContactFields::BusinessAddressLabel:
406  {
408  address.setLabel(value);
409  contact.insertAddress(address);
410  break;
411  }
412  case BlogFeed:
413  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
414  QStringLiteral("BlogFeed"), value);
415  break;
416  case Profession:
417  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
418  QStringLiteral("X-Profession"), value);
419  break;
420  case Office:
421  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
422  QStringLiteral("X-Office"), value);
423  break;
424  case Manager:
425  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
426  QStringLiteral("X-ManagersName"), value);
427  break;
428  case Assistant:
429  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
430  QStringLiteral("X-AssistantsName"), value);
431  break;
432  case Spouse:
433  contact.insertCustom(QStringLiteral("KADDRESSBOOK"),
434  QStringLiteral("X-SpousesName"), value);
435  break;
436  }
437 }
438 
440 {
441  switch (field) {
442  case Undefined:
443  return QString();
444  case FormattedName:
445  return contact.formattedName();
446  case Prefix:
447  return contact.prefix();
448  case GivenName:
449  return contact.givenName();
450  case AdditionalName:
451  return contact.additionalName();
452  case FamilyName:
453  return contact.familyName();
454  case Suffix:
455  return contact.suffix();
456  case NickName:
457  return contact.nickName();
458  case Birthday:
459  {
460  const QDateTime birthday = contact.birthday();
461  if (birthday.date().isValid()) {
462  return birthday.date().toString(Qt::ISODate);
463  } else {
464  return QString();
465  }
466  }
467  case Anniversary:
468  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Anniversary"));
469  case HomeAddressStreet:
470  {
471  const KContacts::Address address = contact.address(KContacts::Address::Home);
472  return address.street();
473  }
474  case HomeAddressPostOfficeBox:
475  {
476  const KContacts::Address address = contact.address(KContacts::Address::Home);
477  return address.postOfficeBox();
478  }
479  case HomeAddressLocality:
480  {
481  const KContacts::Address address = contact.address(KContacts::Address::Home);
482  return address.locality();
483  }
484  case HomeAddressRegion:
485  {
486  const KContacts::Address address = contact.address(KContacts::Address::Home);
487  return address.region();
488  }
489  case HomeAddressPostalCode:
490  {
491  const KContacts::Address address = contact.address(KContacts::Address::Home);
492  return address.postalCode();
493  }
494  case HomeAddressCountry:
495  {
496  const KContacts::Address address = contact.address(KContacts::Address::Home);
497  return address.country();
498  }
499  case HomeAddressLabel:
500  {
501  const KContacts::Address address = contact.address(KContacts::Address::Home);
502  return address.label();
503  }
504  case BusinessAddressStreet:
505  {
506  const KContacts::Address address = contact.address(KContacts::Address::Work);
507  return address.street();
508  }
509  case BusinessAddressPostOfficeBox:
510  {
511  const KContacts::Address address = contact.address(KContacts::Address::Work);
512  return address.postOfficeBox();
513  }
514  case BusinessAddressLocality:
515  {
516  const KContacts::Address address = contact.address(KContacts::Address::Work);
517  return address.locality();
518  }
519  case BusinessAddressRegion:
520  {
521  const KContacts::Address address = contact.address(KContacts::Address::Work);
522  return address.region();
523  }
524  case BusinessAddressPostalCode:
525  {
526  const KContacts::Address address = contact.address(KContacts::Address::Work);
527  return address.postalCode();
528  }
529  case BusinessAddressCountry:
530  {
531  const KContacts::Address address = contact.address(KContacts::Address::Work);
532  return address.country();
533  }
534  case BusinessAddressLabel:
535  {
536  const KContacts::Address address = contact.address(KContacts::Address::Work);
537  return address.label();
538  }
539  case HomePhone:
541  case BusinessPhone:
543  case MobilePhone:
545  case HomeFax:
547  case BusinessFax:
549  case CarPhone:
551  case Isdn:
553  case Pager:
555  case PreferredEmail:
556  {
557  const QStringList emails = contact.emails();
558  if (!emails.isEmpty()) {
559  return emails.at(0);
560  } else {
561  return QString();
562  }
563  }
564  case Email2:
565  {
566  const QStringList emails = contact.emails();
567  if (emails.count() > 1) {
568  return emails.at(1);
569  } else {
570  return QString();
571  }
572  }
573  case Email3:
574  {
575  const QStringList emails = contact.emails();
576  if (emails.count() > 2) {
577  return emails.at(2);
578  } else {
579  return QString();
580  }
581  }
582  case Email4:
583  {
584  const QStringList emails = contact.emails();
585  if (emails.count() > 3) {
586  return emails.at(3);
587  } else {
588  return QString();
589  }
590  }
591  case Mailer:
592  return contact.mailer();
593  case Title:
594  return contact.title();
595  case Role:
596  return contact.role();
597  case Organization:
598  return contact.organization();
599  case Note:
600  return contact.note();
601  case Homepage:
602  return contact.url().url().url();
603  case BlogFeed:
604  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("BlogFeed"));
605  case Profession:
606  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Profession"));
607  case Office:
608  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-Office"));
609  case Manager:
610  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-ManagersName"));
611  case Assistant:
612  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-AssistantsName"));
613  case Spouse:
614  return contact.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"));
615  }
616 
617  return QString();
618 }
QString street() const
QString custom(const QString &app, const QString &name) const
void setFormattedName(const QString &formattedName)
void setMailer(const QString &mailer)
void setNumber(const QString &number)
static QString carPhoneLabel()
QString region() const
static QString businessAddressRegionLabel()
void setLocality(const QString &locality)
QString familyName() const
QString additionalName() const
void insertPhoneNumber(const PhoneNumber &phoneNumber)
static QString givenNameLabel()
QString toString(Qt::DateFormat format) const const
static QString value(Field field, const KContacts::Addressee &contact)
Returns the value for the field of the contact.
QStringList emails() const
static QString mobilePhoneLabel()
QString organization() const
void setSuffix(const QString &suffix)
QString role() const
QString country() const
static QString isdnLabel()
const T & at(int i) const const
static void setValue(Field field, const QString &value, KContacts::Addressee &contact)
Sets the value of the field for the contact.
static QString prefixLabel()
static QString pagerLabel()
void setStreet(const QString &street)
static QString suffixLabel()
static QString nickNameLabel()
QString nickName() const
void setPrefix(const QString &prefix)
static QString homePhoneLabel()
void setLabel(const QString &label)
static QString homeAddressStreetLabel()
void setGivenName(const QString &givenName)
static QString homeAddressLocalityLabel()
void setAdditionalName(const QString &additionalName)
static QString homeFaxLabel()
void insertEmail(const QString &email, bool preferred=false, const QMap< QString, QStringList > &param=QMap< QString, QStringList >())
Address address(Address::Type type) const
QString mailer() const
static QString businessAddressStreetLabel()
void setUrl(const ResourceLocatorUrl &url)
Field
Describes the standard fields that are available for every contact.
ResourceLocatorUrl url() const
QString number() const
QString title() const
void setOrganization(const QString &organization)
QDate fromString(const QString &string, Qt::DateFormat format)
int count(const T &value) const const
void setTitle(const QString &title)
QString postOfficeBox() const
static QString businessAddressCountryLabel()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString label() const
static QString homeAddressLabelLabel()
void setFamilyName(const QString &familyName)
QString suffix() const
bool isEmpty() const const
static QString noteLabel()
static QString businessAddressLabelLabel()
static QString businessAddressPostalCodeLabel()
bool isValid() const const
void setRegion(const QString &region)
QString postalCode() const
QString locality() const
static QString additionalNameLabel()
QDateTime birthday() const
QString formattedName() const
static QString formattedNameLabel()
void setNickName(const QString &nickName)
PhoneNumber phoneNumber(PhoneNumber::Type type) const
static QString mailerLabel()
void setPostalCode(const QString &code)
static QString businessAddressLocalityLabel()
static QString titleLabel()
static QString familyNameLabel()
QString i18n(const char *text, const TYPE &arg...)
void insertCustom(const QString &app, const QString &name, const QString &value)
QDate date() const const
void setNote(const QString &note)
void setPostOfficeBox(const QString &postOfficeBox)
static QString urlLabel()
void setCountry(const QString &country)
static QString businessPhoneLabel()
static QString homeAddressPostalCodeLabel()
static QString homeAddressPostOfficeBoxLabel()
void setBirthday(const QDateTime &birthday, bool withTime=true)
static QString businessAddressPostOfficeBoxLabel()
static QString homeAddressRegionLabel()
static QString roleLabel()
static QString businessFaxLabel()
static QString birthdayLabel()
static QString label(Field field)
Returns the i18n label for the field.
static QString organizationLabel()
QString givenName() const
static QString homeAddressCountryLabel()
QString note() const
void setRole(const QString &role)
QString prefix() const
void insertAddress(const Address &address)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:47:29 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.