KContacts

addressee.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
4  SPDX-FileCopyrightText: 2003 Carsten Pfeiffer <[email protected]>
5  SPDX-FileCopyrightText: 2005 Ingo Kloecker <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include <QDate>
11 #include <QRegularExpression>
12 #include <QSharedData>
13 #include <QUuid>
14 
15 #include "kcontacts_debug.h"
16 #include <KLocalizedString>
17 
18 #include "addressee.h"
19 #include "addresseehelper.h"
20 #include "field.h"
21 
22 using namespace KContacts;
23 
24 static bool matchBinaryPattern(int value, int pattern);
25 
26 template<class L>
27 static bool listEquals(const QVector<L> &list, const QVector<L> &pattern);
28 static bool listEquals(const QStringList &list, const QStringList &pattern);
29 
30 class Q_DECL_HIDDEN Addressee::Private : public QSharedData
31 {
32 public:
33  Private()
34  : mUid(QUuid::createUuid().toString().mid(1, 36))
35  , mEmpty(true)
36  , mChanged(false)
37  , mBirthdayWithTime(false)
38  {
39  // We avoid the curly braces so the string is RFC4122 compliant and can be used as urn
40  }
41 
42  Private(const Private &other)
43  : QSharedData(other)
44  {
45  mUid = other.mUid;
46  mName = other.mName;
47  mFormattedName = other.mFormattedName;
48  mFamilyName = other.mFamilyName;
49  mGivenName = other.mGivenName;
50  mAdditionalName = other.mAdditionalName;
51  mPrefix = other.mPrefix;
52  mSuffix = other.mSuffix;
53  mBirthday = other.mBirthday;
54  mBirthdayWithTime = other.mBirthdayWithTime;
55  mMailer = other.mMailer;
56  mTimeZone = other.mTimeZone;
57  mGeo = other.mGeo;
58  mDepartment = other.mDepartment;
59  mNote = other.mNote;
60  mProductId = other.mProductId;
61  mRevision = other.mRevision;
62  mSortString = other.mSortString;
63  mSecrecy = other.mSecrecy;
64  mLogo = other.mLogo;
65  mPhoto = other.mPhoto;
66  mSound = other.mSound;
67 
68  mPhoneNumbers = other.mPhoneNumbers;
69  mAddresses = other.mAddresses;
70  mKeys = other.mKeys;
71  mLangs = other.mLangs;
72  mGender = other.mGender;
73  mEmails = other.mEmails;
74  mCategories = other.mCategories;
75  mCustomFields = other.mCustomFields;
76  mCalendarUrl = other.mCalendarUrl;
77  mSoundListExtra = other.mSoundListExtra;
78  mPhotoExtraList = other.mPhotoExtraList;
79  mLogoExtraList = other.mLogoExtraList;
80  mUrlExtraList = other.mUrlExtraList;
81  mMembers = other.mMembers;
82  mRelationships = other.mRelationships;
83  mSources = other.mSources;
84  mEmpty = other.mEmpty;
85  mImpps = other.mImpps;
86  mChanged = other.mChanged;
87  mTitleExtraList = other.mTitleExtraList;
88  mRoleExtraList = other.mRoleExtraList;
89  mOrgExtraList = other.mOrgExtraList;
90  }
91 
92  ~Private()
93  {
94  }
95 
96  QString mUid;
97  QString mName;
98  QString mFormattedName;
99  QString mFamilyName;
100  QString mGivenName;
101  QString mAdditionalName;
102  QString mPrefix;
103  QString mSuffix;
104  QDateTime mBirthday;
105  QString mMailer;
106  TimeZone mTimeZone;
107  Geo mGeo;
108  QString mDepartment;
109  QString mNote;
110  QString mProductId;
111  QDateTime mRevision;
112  QString mSortString;
113  Secrecy mSecrecy;
114  Picture mLogo;
115  Picture mPhoto;
116  Sound mSound;
117 
118  PhoneNumber::List mPhoneNumbers;
119  Address::List mAddresses;
120  Key::List mKeys;
121  Email::List mEmails;
122  Lang::List mLangs;
123  Impp::List mImpps;
124  Gender mGender;
125  QString mKind;
126  QStringList mCategories;
127  QHash<QString, QString> mCustomFields;
128  CalendarUrl::List mCalendarUrl;
129  Sound::List mSoundListExtra;
130  Picture::List mPhotoExtraList;
131  Picture::List mLogoExtraList;
132  ResourceLocatorUrl::List mUrlExtraList;
133  QVector<QUrl> mSources;
134  QStringList mMembers;
135  Related::List mRelationships;
136  FieldGroup::List mFieldGroupList;
137  Title::List mTitleExtraList;
138  Role::List mRoleExtraList;
139  Org::List mOrgExtraList;
140  NickName::List mNickNameExtraList;
141  ClientPidMap::List mClientPidMapList;
142  bool mEmpty : 1;
143  bool mChanged : 1;
144  bool mBirthdayWithTime;
145 };
146 
148  : d(new Private)
149 {
150 }
151 
153 {
154 }
155 
157  : d(other.d)
158 {
159 }
160 
162 {
163  if (this != &other) {
164  d = other.d;
165  }
166 
167  return *this;
168 }
169 
170 bool Addressee::operator==(const Addressee &addressee) const
171 {
172  if (d->mUid != addressee.d->mUid) {
173  qCDebug(KCONTACTS_LOG) << "uid differs";
174  return false;
175  }
176 
177  if (d->mName != addressee.d->mName //
178  && !(d->mName.isEmpty() && addressee.d->mName.isEmpty())) {
179  qCDebug(KCONTACTS_LOG) << "name differs";
180  return false;
181  }
182 
183  if (d->mFormattedName != addressee.d->mFormattedName //
184  && !(d->mFormattedName.isEmpty() && addressee.d->mFormattedName.isEmpty())) {
185  qCDebug(KCONTACTS_LOG) << "formattedName differs";
186  return false;
187  }
188 
189  if (d->mFamilyName != addressee.d->mFamilyName //
190  && !(d->mFamilyName.isEmpty() && addressee.d->mFamilyName.isEmpty())) {
191  qCDebug(KCONTACTS_LOG) << "familyName differs";
192  return false;
193  }
194 
195  if (d->mGivenName != addressee.d->mGivenName //
196  && !(d->mGivenName.isEmpty() && addressee.d->mGivenName.isEmpty())) {
197  qCDebug(KCONTACTS_LOG) << "givenName differs";
198  return false;
199  }
200 
201  if (d->mAdditionalName != addressee.d->mAdditionalName //
202  && !(d->mAdditionalName.isEmpty() && addressee.d->mAdditionalName.isEmpty())) {
203  qCDebug(KCONTACTS_LOG) << "additionalName differs";
204  return false;
205  }
206 
207  if (d->mPrefix != addressee.d->mPrefix //
208  && !(d->mPrefix.isEmpty() && addressee.d->mPrefix.isEmpty())) {
209  qCDebug(KCONTACTS_LOG) << "prefix differs";
210  return false;
211  }
212 
213  if (d->mSuffix != addressee.d->mSuffix //
214  && !(d->mSuffix.isEmpty() && addressee.d->mSuffix.isEmpty())) {
215  qCDebug(KCONTACTS_LOG) << "suffix differs";
216  return false;
217  }
218 
219  if (d->mBirthday != addressee.d->mBirthday //
220  || d->mBirthdayWithTime != addressee.d->mBirthdayWithTime) {
221  qCDebug(KCONTACTS_LOG) << "birthday differs";
222  return false;
223  }
224 
225  if (d->mMailer != addressee.d->mMailer //
226  && !(d->mMailer.isEmpty() && addressee.d->mMailer.isEmpty())) {
227  qCDebug(KCONTACTS_LOG) << "mailer differs";
228  return false;
229  }
230 
231  if (d->mTimeZone != addressee.d->mTimeZone) {
232  qCDebug(KCONTACTS_LOG) << "timeZone differs";
233  return false;
234  }
235 
236  if (d->mGeo != addressee.d->mGeo) {
237  qCDebug(KCONTACTS_LOG) << "geo differs";
238  return false;
239  }
240 
241  if (d->mDepartment != addressee.d->mDepartment //
242  && !(d->mDepartment.isEmpty() && addressee.d->mDepartment.isEmpty())) {
243  qCDebug(KCONTACTS_LOG) << "department differs";
244  return false;
245  }
246 
247  if (d->mNote != addressee.d->mNote //
248  && !(d->mNote.isEmpty() && addressee.d->mNote.isEmpty())) {
249  qCDebug(KCONTACTS_LOG) << "note differs";
250  return false;
251  }
252 
253  if (d->mProductId != addressee.d->mProductId //
254  && !(d->mProductId.isEmpty() && addressee.d->mProductId.isEmpty())) {
255  qCDebug(KCONTACTS_LOG) << "productId differs";
256  return false;
257  }
258 
259  if (d->mSortString != addressee.d->mSortString //
260  && !(d->mSortString.isEmpty() && addressee.d->mSortString.isEmpty())) {
261  qCDebug(KCONTACTS_LOG) << "sortString differs";
262  return false;
263  }
264 
265  if (d->mSecrecy != addressee.d->mSecrecy) {
266  qCDebug(KCONTACTS_LOG) << "secrecy differs";
267  return false;
268  }
269 
270  if (d->mLogo != addressee.d->mLogo) {
271  qCDebug(KCONTACTS_LOG) << "logo differs";
272  return false;
273  }
274 
275  if (d->mPhoto != addressee.d->mPhoto) {
276  qCDebug(KCONTACTS_LOG) << "photo differs";
277  return false;
278  }
279 
280  if (d->mSound != addressee.d->mSound) {
281  qCDebug(KCONTACTS_LOG) << "sound differs";
282  return false;
283  }
284 
285  if (!listEquals(d->mPhoneNumbers, addressee.d->mPhoneNumbers)) {
286  qCDebug(KCONTACTS_LOG) << "phoneNumbers differs";
287  return false;
288  }
289 
290  if (!listEquals(d->mAddresses, addressee.d->mAddresses)) {
291  qCDebug(KCONTACTS_LOG) << "addresses differs";
292  return false;
293  }
294 
295  if (!listEquals(d->mKeys, addressee.d->mKeys)) {
296  qCDebug(KCONTACTS_LOG) << "keys differs";
297  return false;
298  }
299  if (!listEquals(d->mEmails, addressee.d->mEmails)) {
300  qCDebug(KCONTACTS_LOG) << "emails differs";
301  return false;
302  }
303 
304  if (!listEquals(d->mCategories, addressee.d->mCategories)) {
305  qCDebug(KCONTACTS_LOG) << "categories differs";
306  return false;
307  }
308 
309  if (d->mCustomFields != addressee.d->mCustomFields) {
310  qCDebug(KCONTACTS_LOG) << "custom differs";
311  return false;
312  }
313  if (d->mLangs != addressee.d->mLangs) {
314  qCDebug(KCONTACTS_LOG) << "langs differs";
315  return false;
316  }
317  if (d->mImpps != addressee.d->mImpps) {
318  qCDebug(KCONTACTS_LOG) << "impps differs";
319  return false;
320  }
321  if (d->mGender != addressee.d->mGender) {
322  qCDebug(KCONTACTS_LOG) << "gender differs";
323  return false;
324  }
325  if (d->mKind != addressee.d->mKind) {
326  qCDebug(KCONTACTS_LOG) << "kind differs";
327  return false;
328  }
329  if (!listEquals(d->mCalendarUrl, addressee.d->mCalendarUrl)) {
330  qCDebug(KCONTACTS_LOG) << "calendarUrl differs";
331  return false;
332  }
333  if (!listEquals(d->mSoundListExtra, addressee.d->mSoundListExtra)) {
334  qCDebug(KCONTACTS_LOG) << "Extra sound differs";
335  return false;
336  }
337  if (!listEquals(d->mPhotoExtraList, addressee.d->mPhotoExtraList)) {
338  qCDebug(KCONTACTS_LOG) << "Extra photo differs";
339  return false;
340  }
341  if (!listEquals(d->mLogoExtraList, addressee.d->mLogoExtraList)) {
342  qCDebug(KCONTACTS_LOG) << "Extra logo differs";
343  return false;
344  }
345  if (!listEquals(d->mUrlExtraList, addressee.d->mUrlExtraList)) {
346  qCDebug(KCONTACTS_LOG) << "Extra url differs";
347  return false;
348  }
349  if (!listEquals(d->mMembers, addressee.d->mMembers)) {
350  qCDebug(KCONTACTS_LOG) << "Extra url differs";
351  return false;
352  }
353  if (!listEquals(d->mRelationships, addressee.d->mRelationships)) {
354  qCDebug(KCONTACTS_LOG) << "Relationships differs";
355  return false;
356  }
357  if (!listEquals(d->mSources, addressee.d->mSources)) {
358  qCDebug(KCONTACTS_LOG) << "Sources differs";
359  return false;
360  }
361 
362  if (!listEquals(d->mFieldGroupList, addressee.d->mFieldGroupList)) {
363  qCDebug(KCONTACTS_LOG) << "Field Groups differs";
364  return false;
365  }
366 
367  if (!listEquals(d->mTitleExtraList, addressee.d->mTitleExtraList)) {
368  qCDebug(KCONTACTS_LOG) << "Extra TitleList differs";
369  return false;
370  }
371 
372  if (!listEquals(d->mRoleExtraList, addressee.d->mRoleExtraList)) {
373  qCDebug(KCONTACTS_LOG) << "Extra RoleList differs";
374  return false;
375  }
376 
377  if (!listEquals(d->mOrgExtraList, addressee.d->mOrgExtraList)) {
378  qCDebug(KCONTACTS_LOG) << "Extra Organization List differs";
379  return false;
380  }
381 
382  if (!listEquals(d->mNickNameExtraList, addressee.d->mNickNameExtraList)) {
383  qCDebug(KCONTACTS_LOG) << "Extra NickName List differs";
384  return false;
385  }
386 
387  if (!listEquals(d->mClientPidMapList, addressee.d->mClientPidMapList)) {
388  qCDebug(KCONTACTS_LOG) << "ClientPidMap List differs";
389  return false;
390  }
391  return true;
392 }
393 
394 bool Addressee::operator!=(const Addressee &a) const
395 {
396  return !(a == *this);
397 }
398 
399 bool Addressee::isEmpty() const
400 {
401  return d->mEmpty;
402 }
403 
404 void Addressee::setUid(const QString &id)
405 {
406  if (id == d->mUid) {
407  return;
408  }
409 
410  d->mEmpty = false;
411  d->mUid = id;
412 }
413 
414 QString Addressee::uid() const
415 {
416  return d->mUid;
417 }
418 
420 {
421  return i18n("Unique Identifier");
422 }
423 
425 {
426  if (name == d->mName) {
427  return;
428  }
429 
430  d->mEmpty = false;
431  d->mName = name;
432 }
433 
434 QString Addressee::name() const
435 {
436  return d->mName;
437 }
438 
440 {
441  return i18n("Name");
442 }
443 
444 void Addressee::setKind(const QString &kind)
445 {
446  if (kind == d->mKind) {
447  return;
448  }
449 
450  d->mEmpty = false;
451  d->mKind = kind;
452 }
453 
454 QString Addressee::kind() const
455 {
456  return d->mKind;
457 }
458 
459 void Addressee::insertExtraSound(const Sound &sound)
460 {
461  d->mEmpty = false;
462  d->mSoundListExtra.append(sound);
463 }
464 
465 Sound::List Addressee::extraSoundList() const
466 {
467  return d->mSoundListExtra;
468 }
469 
470 void Addressee::insertExtraPhoto(const Picture &picture)
471 {
472  d->mEmpty = false;
473  d->mPhotoExtraList.append(picture);
474 }
475 
476 Picture::List Addressee::extraPhotoList() const
477 {
478  return d->mPhotoExtraList;
479 }
480 
481 void Addressee::insertExtraLogo(const Picture &logo)
482 {
483  d->mEmpty = false;
484  d->mLogoExtraList.append(logo);
485 }
486 
487 Picture::List Addressee::extraLogoList() const
488 {
489  return d->mLogoExtraList;
490 }
491 
492 void Addressee::setExtraSoundList(const Sound::List &soundList)
493 {
494  d->mEmpty = false;
495  d->mSoundListExtra = soundList;
496 }
497 
498 void Addressee::setExtraPhotoList(const Picture::List &pictureList)
499 {
500  d->mEmpty = false;
501  d->mPhotoExtraList = pictureList;
502 }
503 
504 void Addressee::setExtraLogoList(const Picture::List &logoList)
505 {
506  d->mEmpty = false;
507  d->mLogoExtraList = logoList;
508 }
509 
510 void Addressee::insertExtraUrl(const ResourceLocatorUrl &url)
511 {
512  if (url.isValid()) {
513  d->mEmpty = false;
514  d->mUrlExtraList.append(url);
515  }
516 }
517 
518 void Addressee::setExtraUrlList(const ResourceLocatorUrl::List &urlList)
519 {
520  d->mEmpty = false;
521  d->mUrlExtraList = urlList;
522 }
523 
524 ResourceLocatorUrl::List Addressee::extraUrlList() const
525 {
526  return d->mUrlExtraList;
527 }
528 
529 void Addressee::insertSourceUrl(const QUrl &url)
530 {
531  d->mEmpty = false;
532  d->mSources.append(url);
533 }
534 
535 void Addressee::setSourcesUrlList(const QVector<QUrl> &urlList)
536 {
537  d->mEmpty = false;
538  d->mSources = urlList;
539 }
540 
541 QVector<QUrl> Addressee::sourcesUrlList() const
542 {
543  return d->mSources;
544 }
545 
546 FieldGroup::List Addressee::fieldGroupList() const
547 {
548  return d->mFieldGroupList;
549 }
550 
551 void Addressee::setFieldGroupList(const FieldGroup::List &fieldGroupList)
552 {
553  d->mEmpty = false;
554  d->mFieldGroupList = fieldGroupList;
555 }
556 
557 void Addressee::insertFieldGroup(const FieldGroup &fieldGroup)
558 {
559  if (fieldGroup.isValid()) {
560  d->mEmpty = false;
561  // TODO don't duplicate ?
562  d->mFieldGroupList.append(fieldGroup);
563  }
564 }
565 
566 ClientPidMap::List Addressee::clientPidMapList() const
567 {
568  return d->mClientPidMapList;
569 }
570 
571 void Addressee::setClientPidMapList(const ClientPidMap::List &clientpidmaplist)
572 {
573  d->mEmpty = false;
574  d->mClientPidMapList = clientpidmaplist;
575 }
576 
577 void Addressee::insertClientPidMap(const ClientPidMap &clientpidmap)
578 {
579  if (clientpidmap.isValid()) {
580  d->mEmpty = false;
581  // TODO don't duplicate ?
582  d->mClientPidMapList.append(clientpidmap);
583  }
584 }
585 
586 void Addressee::insertImpp(const Impp &impp)
587 {
588  if (impp.isValid()) {
589  d->mEmpty = false;
590  // Don't duplicate ?
591  d->mImpps.append(impp);
592  }
593 }
594 
595 void Addressee::setImppList(const Impp::List &imppList)
596 {
597  d->mEmpty = false;
598  d->mImpps = imppList;
599 }
600 
601 Impp::List Addressee::imppList() const
602 {
603  return d->mImpps;
604 }
605 
606 void Addressee::insertCalendarUrl(const CalendarUrl &calendarUrl)
607 {
608  d->mEmpty = false;
609  // TODO verify that there is not same calendarurl
610  if (calendarUrl.isValid()) {
611  d->mCalendarUrl.append(calendarUrl);
612  }
613 }
614 
615 CalendarUrl::List Addressee::calendarUrlList() const
616 {
617  return d->mCalendarUrl;
618 }
619 
621 {
622  if (formattedName == d->mFormattedName) {
623  return;
624  }
625 
626  d->mEmpty = false;
627  d->mFormattedName = formattedName;
628 }
629 
631 {
632  return d->mFormattedName;
633 }
634 
636 {
637  return i18n("Formatted Name");
638 }
639 
641 {
642  if (familyName == d->mFamilyName) {
643  return;
644  }
645 
646  d->mEmpty = false;
647  d->mFamilyName = familyName;
648 }
649 
651 {
652  return d->mFamilyName;
653 }
654 
656 {
657  return i18n("Family Name");
658 }
659 
661 {
662  if (givenName == d->mGivenName) {
663  return;
664  }
665 
666  d->mEmpty = false;
667  d->mGivenName = givenName;
668 }
669 
671 {
672  return d->mGivenName;
673 }
674 
676 {
677  return i18n("Given Name");
678 }
679 
681 {
682  if (additionalName == d->mAdditionalName) {
683  return;
684  }
685 
686  d->mEmpty = false;
687  d->mAdditionalName = additionalName;
688 }
689 
691 {
692  return d->mAdditionalName;
693 }
694 
696 {
697  return i18n("Additional Names");
698 }
699 
701 {
702  if (prefix == d->mPrefix) {
703  return;
704  }
705 
706  d->mEmpty = false;
707  d->mPrefix = prefix;
708 }
709 
711 {
712  return d->mPrefix;
713 }
714 
716 {
717  return i18n("Honorific Prefixes");
718 }
719 
721 {
722  if (suffix == d->mSuffix) {
723  return;
724  }
725 
726  d->mEmpty = false;
727  d->mSuffix = suffix;
728 }
729 
731 {
732  return d->mSuffix;
733 }
734 
736 {
737  return i18n("Honorific Suffixes");
738 }
739 
741 {
742  NickName t(nickName);
743  if (!d->mNickNameExtraList.isEmpty()) {
744  t = d->mNickNameExtraList.takeFirst();
745  t.setNickName(nickName);
746  d->mNickNameExtraList.prepend(t);
747  d->mEmpty = false;
748  } else {
749  insertExtraNickName(t);
750  }
751 }
752 
754 {
755  insertExtraNickName(nickName);
756 }
757 
758 void Addressee::insertExtraNickName(const NickName &nickName)
759 {
760  if (nickName.isValid()) {
761  d->mEmpty = false;
762  d->mNickNameExtraList.append(nickName);
763  }
764 }
765 
766 void Addressee::setExtraNickNameList(const NickName::List &nickNameList)
767 {
768  d->mEmpty = false;
769  d->mNickNameExtraList = nickNameList;
770 }
771 
772 NickName::List Addressee::extraNickNameList() const
773 {
774  return d->mNickNameExtraList;
775 }
776 
778 {
779  if (d->mNickNameExtraList.isEmpty()) {
780  return {};
781  } else {
782  return d->mNickNameExtraList.at(0).nickname();
783  }
784 }
785 
787 {
788  return i18n("Nick Name");
789 }
790 
791 void Addressee::setBirthday(const QDateTime &birthday, bool withTime)
792 {
793  if (birthday == d->mBirthday && d->mBirthdayWithTime == withTime) {
794  return;
795  }
796 
797  d->mEmpty = false;
798  d->mBirthday = birthday;
799  if (!withTime) {
800  d->mBirthday.setTime(QTime());
801  }
802  d->mBirthdayWithTime = withTime;
803 }
804 
806 {
807  if (birthday == d->mBirthday.date() && !d->mBirthdayWithTime) {
808  return;
809  }
810 
811  d->mEmpty = false;
812  d->mBirthday = QDateTime(birthday, QTime());
813  d->mBirthdayWithTime = false;
814 }
815 
817 {
818  return d->mBirthday;
819 }
820 
821 bool Addressee::birthdayHasTime() const
822 {
823  return d->mBirthdayWithTime;
824 }
825 
827 {
828  return i18n("Birthday");
829 }
830 
832 {
833  return i18n("Home Address Street");
834 }
835 
837 {
838  return i18n("Home Address Post Office Box");
839 }
840 
842 {
843  return i18n("Home Address City");
844 }
845 
847 {
848  return i18n("Home Address State");
849 }
850 
852 {
853  return i18n("Home Address Zip Code");
854 }
855 
857 {
858  return i18n("Home Address Country");
859 }
860 
862 {
863  return i18n("Home Address Label");
864 }
865 
867 {
868  return i18n("Business Address Street");
869 }
870 
872 {
873  return i18n("Business Address Post Office Box");
874 }
875 
877 {
878  return i18n("Business Address City");
879 }
880 
882 {
883  return i18n("Business Address State");
884 }
885 
887 {
888  return i18n("Business Address Zip Code");
889 }
890 
892 {
893  return i18n("Business Address Country");
894 }
895 
897 {
898  return i18n("Business Address Label");
899 }
900 
902 {
903  return i18n("Home Phone");
904 }
905 
907 {
908  return i18n("Business Phone");
909 }
910 
912 {
913  return i18n("Mobile Phone");
914 }
915 
917 {
918  return i18n("Home Fax");
919 }
920 
922 {
923  return i18n("Business Fax");
924 }
925 
927 {
928  return i18n("Car Phone");
929 }
930 
932 {
933  return i18n("ISDN");
934 }
935 
937 {
938  return i18n("Pager");
939 }
940 
942 {
943  return i18n("Email Address");
944 }
945 
947 {
948  if (mailer == d->mMailer) {
949  return;
950  }
951 
952  d->mEmpty = false;
953  d->mMailer = mailer;
954 }
955 
957 {
958  return d->mMailer;
959 }
960 
962 {
963  return i18n("Mail Client");
964 }
965 
967 {
968  if (timeZone == d->mTimeZone) {
969  return;
970  }
971 
972  d->mEmpty = false;
973  d->mTimeZone = timeZone;
974 }
975 
977 {
978  return d->mTimeZone;
979 }
980 
982 {
983  return i18n("Time Zone");
984 }
985 
987 {
988  if (geo == d->mGeo) {
989  return;
990  }
991 
992  d->mEmpty = false;
993  d->mGeo = geo;
994 }
995 
996 Geo Addressee::geo() const
997 {
998  return d->mGeo;
999 }
1000 
1002 {
1003  return i18n("Geographic Position");
1004 }
1005 
1007 {
1008  Title t(title);
1009  if (!d->mTitleExtraList.isEmpty()) {
1010  t = d->mTitleExtraList.takeFirst();
1011  t.setTitle(title);
1012  d->mTitleExtraList.prepend(t);
1013  d->mEmpty = false;
1014  } else {
1015  insertExtraTitle(title);
1016  }
1017 }
1018 
1019 void Addressee::setTitle(const Title &title)
1020 {
1021  insertExtraTitle(title);
1022 }
1023 
1024 void Addressee::insertExtraTitle(const Title &title)
1025 {
1026  if (title.isValid()) {
1027  d->mEmpty = false;
1028  d->mTitleExtraList.append(title);
1029  }
1030 }
1031 
1032 QString Addressee::title() const
1033 {
1034  if (d->mTitleExtraList.isEmpty()) {
1035  return {};
1036  } else {
1037  return d->mTitleExtraList.at(0).title();
1038  }
1039 }
1040 
1041 Title::List Addressee::extraTitleList() const
1042 {
1043  return d->mTitleExtraList;
1044 }
1045 
1046 void Addressee::setExtraTitleList(const Title::List &urltitle)
1047 {
1048  d->mEmpty = false;
1049  d->mTitleExtraList = urltitle;
1050 }
1051 
1053 {
1054  return i18nc("a person's title", "Title");
1055 }
1056 
1058 {
1059  Role t(role);
1060  if (!d->mRoleExtraList.isEmpty()) {
1061  t = d->mRoleExtraList.takeFirst();
1062  t.setRole(role);
1063  d->mRoleExtraList.prepend(t);
1064  d->mEmpty = false;
1065  } else {
1066  insertExtraRole(t);
1067  }
1068 }
1069 
1070 void Addressee::setRole(const Role &role)
1071 {
1072  insertExtraRole(role);
1073 }
1074 
1075 void Addressee::insertExtraRole(const Role &role)
1076 {
1077  if (role.isValid()) {
1078  d->mEmpty = false;
1079  d->mRoleExtraList.append(role);
1080  }
1081 }
1082 
1083 void Addressee::setExtraRoleList(const Role::List &roleList)
1084 {
1085  d->mEmpty = false;
1086  d->mRoleExtraList = roleList;
1087 }
1088 
1089 Role::List Addressee::extraRoleList() const
1090 {
1091  return d->mRoleExtraList;
1092 }
1093 
1094 QString Addressee::role() const
1095 {
1096  if (d->mRoleExtraList.isEmpty()) {
1097  return {};
1098  } else {
1099  return d->mRoleExtraList.at(0).role();
1100  }
1101 }
1102 
1104 {
1105  return i18nc("of a person in an organization", "Role");
1106 }
1107 
1109 {
1110  Org t(organization);
1111  if (!d->mOrgExtraList.isEmpty()) {
1112  t = d->mOrgExtraList.takeFirst();
1113  t.setOrganization(organization);
1114  d->mOrgExtraList.prepend(t);
1115  d->mEmpty = false;
1116  } else {
1117  insertExtraOrganization(t);
1118  }
1119 }
1120 
1122 {
1123  insertExtraOrganization(organization);
1124 }
1125 
1126 void Addressee::insertExtraOrganization(const Org &organization)
1127 {
1128  if (organization.isValid()) {
1129  d->mEmpty = false;
1130  d->mOrgExtraList.append(organization);
1131  }
1132 }
1133 
1134 void Addressee::setExtraOrganizationList(const Org::List &orgList)
1135 {
1136  d->mEmpty = false;
1137  d->mOrgExtraList = orgList;
1138 }
1139 
1140 Org::List Addressee::extraOrganizationList() const
1141 {
1142  return d->mOrgExtraList;
1143 }
1144 
1146 {
1147  if (d->mOrgExtraList.isEmpty()) {
1148  return {};
1149  } else {
1150  return d->mOrgExtraList.at(0).organization();
1151  }
1152 }
1153 
1155 {
1156  return i18n("Organization");
1157 }
1158 
1160 {
1161  if (department == d->mDepartment) {
1162  return;
1163  }
1164 
1165  d->mEmpty = false;
1166  d->mDepartment = department;
1167 }
1168 
1170 {
1171  return d->mDepartment;
1172 }
1173 
1175 {
1176  return i18n("Department");
1177 }
1178 
1180 {
1181  if (note == d->mNote) {
1182  return;
1183  }
1184 
1185  d->mEmpty = false;
1186  d->mNote = note;
1187 }
1188 
1189 QString Addressee::note() const
1190 {
1191  return d->mNote;
1192 }
1193 
1195 {
1196  return i18n("Note");
1197 }
1198 
1200 {
1201  if (productId == d->mProductId) {
1202  return;
1203  }
1204 
1205  d->mEmpty = false;
1206  d->mProductId = productId;
1207 }
1208 
1210 {
1211  return d->mProductId;
1212 }
1213 
1215 {
1216  return i18n("Product Identifier");
1217 }
1218 
1220 {
1221  if (revision == d->mRevision) {
1222  return;
1223  }
1224 
1225  d->mEmpty = false;
1226  d->mRevision = revision;
1227 }
1228 
1230 {
1231  return d->mRevision;
1232 }
1233 
1235 {
1236  return i18n("Revision Date");
1237 }
1238 
1240 {
1241  if (sortString == d->mSortString) {
1242  return;
1243  }
1244 
1245  d->mEmpty = false;
1246  d->mSortString = sortString;
1247 }
1248 
1250 {
1251  return d->mSortString;
1252 }
1253 
1255 {
1256  return i18n("Sort String");
1257 }
1258 
1259 void Addressee::setUrl(const QUrl &url)
1260 {
1261  KContacts::ResourceLocatorUrl resourceLocator;
1262  resourceLocator.setUrl(url);
1263  insertExtraUrl(resourceLocator);
1264 }
1265 
1267 {
1268  insertExtraUrl(url);
1269 }
1270 
1272 {
1273  if (d->mUrlExtraList.isEmpty()) {
1274  return ResourceLocatorUrl();
1275  } else {
1276  return d->mUrlExtraList.at(0);
1277  }
1278 }
1279 
1281 {
1282  return i18n("Homepage");
1283 }
1284 
1286 {
1287  if (secrecy == d->mSecrecy) {
1288  return;
1289  }
1290 
1291  d->mEmpty = false;
1292  d->mSecrecy = secrecy;
1293 }
1294 
1296 {
1297  return d->mSecrecy;
1298 }
1299 
1301 {
1302  return i18n("Security Class");
1303 }
1304 
1305 void Addressee::setLogo(const Picture &logo)
1306 {
1307  if (logo == d->mLogo) {
1308  return;
1309  }
1310 
1311  d->mEmpty = false;
1312  d->mLogo = logo;
1313 }
1314 
1316 {
1317  return d->mLogo;
1318 }
1319 
1321 {
1322  return i18n("Logo");
1323 }
1324 
1326 {
1327  if (photo == d->mPhoto) {
1328  return;
1329  }
1330 
1331  d->mEmpty = false;
1332  d->mPhoto = photo;
1333 }
1334 
1335 Picture Addressee::photo() const
1336 {
1337  return d->mPhoto;
1338 }
1339 
1341 {
1342  return i18n("Photo");
1343 }
1344 
1345 void Addressee::setSound(const Sound &sound)
1346 {
1347  if (sound == d->mSound) {
1348  return;
1349  }
1350 
1351  d->mEmpty = false;
1352  d->mSound = sound;
1353 }
1354 
1356 {
1357  return d->mSound;
1358 }
1359 
1361 {
1362  return i18n("Sound");
1363 }
1364 
1366 {
1367  QString str = s;
1368  // remove enclosing quotes from string
1369  if (str.length() > 1 && s[0] == QLatin1Char('"') && s[s.length() - 1] == QLatin1Char('"')) {
1370  str = s.mid(1, s.length() - 2);
1371  }
1372 
1373  setFormattedName(str);
1374  setName(str);
1375 
1376  // clear all name parts
1377  setPrefix(QString());
1378  setGivenName(QString());
1381  setSuffix(QString());
1382 
1383  if (str.isEmpty()) {
1384  return;
1385  }
1386 
1387  static QString spaceStr = QStringLiteral(" ");
1388  static QString emptyStr = QStringLiteral("");
1390 
1391  int i = str.indexOf(QLatin1Char(','));
1392  if (i < 0) {
1393  QStringList parts = str.split(spaceStr);
1394  int leftOffset = 0;
1395  int rightOffset = parts.count() - 1;
1396 
1397  QString suffix;
1398  while (rightOffset >= 0) {
1399  if (helper->containsSuffix(parts[rightOffset])) {
1400  suffix.prepend(parts[rightOffset] + (suffix.isEmpty() ? emptyStr : spaceStr));
1401  rightOffset--;
1402  } else {
1403  break;
1404  }
1405  }
1406  setSuffix(suffix);
1407 
1408  if (rightOffset < 0) {
1409  return;
1410  }
1411 
1412  if (rightOffset - 1 >= 0 && helper->containsPrefix(parts[rightOffset - 1].toLower())) {
1413  setFamilyName(parts[rightOffset - 1] + spaceStr + parts[rightOffset]);
1414  rightOffset--;
1415  } else {
1416  if (helper->treatAsFamilyName()) {
1417  setFamilyName(parts[rightOffset]);
1418  } else {
1419  setGivenName(parts[rightOffset]);
1420  }
1421  }
1422 
1423  QString prefix;
1424  while (leftOffset < rightOffset) {
1425  if (helper->containsTitle(parts[leftOffset])) {
1426  prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]);
1427  leftOffset++;
1428  } else {
1429  break;
1430  }
1431  }
1432  setPrefix(prefix);
1433 
1434  if (leftOffset < rightOffset) {
1435  setGivenName(parts[leftOffset]);
1436  leftOffset++;
1437  }
1438 
1440  while (leftOffset < rightOffset) {
1441  additionalName.append((additionalName.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]);
1442  leftOffset++;
1443  }
1444  setAdditionalName(additionalName);
1445  } else {
1446  QString part1 = str.left(i);
1447  QString part2 = str.mid(i + 1);
1448 
1449  QStringList parts = part1.split(spaceStr);
1450  int leftOffset = 0;
1451  int rightOffset = parts.count() - 1;
1452 
1453  if (!parts.isEmpty()) {
1454  QString suffix;
1455  while (rightOffset >= 0) {
1456  if (helper->containsSuffix(parts[rightOffset])) {
1457  suffix.prepend(parts[rightOffset] + (suffix.isEmpty() ? emptyStr : spaceStr));
1458  rightOffset--;
1459  } else {
1460  break;
1461  }
1462  }
1463  setSuffix(suffix);
1464 
1465  if (rightOffset - 1 >= 0 && helper->containsPrefix(parts[rightOffset - 1].toLower())) {
1466  setFamilyName(parts[rightOffset - 1] + spaceStr + parts[rightOffset]);
1467  rightOffset--;
1468  } else {
1469  setFamilyName(parts[rightOffset]);
1470  }
1471 
1472  QString prefix;
1473  while (leftOffset < rightOffset) {
1474  if (helper->containsTitle(parts[leftOffset])) {
1475  prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]);
1476  leftOffset++;
1477  } else {
1478  break;
1479  }
1480  }
1481  } else {
1482  setPrefix(QString());
1484  setSuffix(QString());
1485  }
1486 
1487  parts = part2.split(spaceStr);
1488 
1489  leftOffset = 0;
1490  rightOffset = parts.count();
1491 
1492  if (!parts.isEmpty()) {
1493  QString prefix;
1494  while (leftOffset < rightOffset) {
1495  if (helper->containsTitle(parts[leftOffset])) {
1496  prefix.append((prefix.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]);
1497  leftOffset++;
1498  } else {
1499  break;
1500  }
1501  }
1502  setPrefix(prefix);
1503 
1504  if (leftOffset < rightOffset) {
1505  setGivenName(parts[leftOffset]);
1506  leftOffset++;
1507  }
1508 
1510  while (leftOffset < rightOffset) {
1511  additionalName.append((additionalName.isEmpty() ? emptyStr : spaceStr) + parts[leftOffset]);
1512  leftOffset++;
1513  }
1514  setAdditionalName(additionalName);
1515  } else {
1516  setGivenName(QString());
1518  }
1519  }
1520 }
1521 
1523 {
1524  QString n(formattedName());
1525  if (!n.isEmpty()) {
1526  return n;
1527  }
1528 
1529  n = assembledName();
1530  if (!n.isEmpty()) {
1531  return n;
1532  }
1533 
1534  n = name();
1535  if (!n.isEmpty()) {
1536  return n;
1537  }
1538 
1539  return organization();
1540 }
1541 
1543 {
1544  // clang-format off
1545  const QString name = prefix() + QLatin1Char(' ')
1546  + givenName() + QLatin1Char(' ')
1547  + additionalName() + QLatin1Char(' ')
1548  + familyName() + QLatin1Char(' ')
1549  + suffix();
1550  // clang-format on
1551 
1552  return name.simplified();
1553 }
1554 
1556 {
1557  QString e;
1558  if (email.isNull()) {
1559  e = preferredEmail();
1560  } else {
1561  e = email;
1562  }
1563  if (e.isEmpty()) {
1564  return QString();
1565  }
1566 
1567  QString text;
1568  if (realName().isEmpty()) {
1569  text = e;
1570  } else {
1571  QRegularExpression needQuotes(QStringLiteral("[^ 0-9A-Za-z\\x{0080}-\\x{FFFF}]"));
1572  if (realName().indexOf(needQuotes) != -1) {
1573  QString name = realName();
1574  name.replace(QLatin1String("\""), QLatin1String("\\\""));
1575  text = QLatin1String("\"") + name + QLatin1String("\" <") + e + QLatin1Char('>');
1576  } else {
1577  text = realName() + QLatin1String(" <") + e + QLatin1Char('>');
1578  }
1579  }
1580 
1581  return text;
1582 }
1583 
1584 void Addressee::insertEmail(const QString &email, bool preferred, const QMap<QString, QStringList> &param)
1585 {
1586  if (email.simplified().isEmpty()) {
1587  return;
1588  }
1589 
1590  for (int i = 0; i < d->mEmails.size(); ++i) {
1591  if (d->mEmails.at(i).mail() == email) {
1592  if (!preferred || i == 0) {
1593  return;
1594  }
1595  Email tempMail = d->mEmails.takeAt(i);
1596  d->mEmails.prepend(tempMail);
1597  return;
1598  }
1599  }
1600 
1601  Email mail(email);
1602  mail.setParameters(param);
1603  d->mEmpty = false;
1604  if (preferred) {
1605  d->mEmails.prepend(mail);
1606  } else {
1607  d->mEmails.append(mail);
1608  }
1609 }
1610 
1612 {
1613  for (int i = 0; i < d->mEmails.size(); ++i) {
1614  if (d->mEmails.at(i).mail() == email) {
1615  d->mEmails.removeAt(i);
1616  }
1617  }
1618 }
1619 
1621 {
1622  if (d->mEmails.isEmpty()) {
1623  return QString();
1624  } else {
1625  return d->mEmails.first().mail();
1626  }
1627 }
1628 
1630 {
1631  QStringList list;
1632  const int numberOfEmail = d->mEmails.size();
1633  list.reserve(numberOfEmail);
1634  for (int i = 0; i < numberOfEmail; ++i) {
1635  list << d->mEmails.at(i).mail();
1636  }
1637 
1638  return list;
1639 }
1640 
1641 Email::List Addressee::emailList() const
1642 {
1643  return d->mEmails;
1644 }
1645 
1647 {
1648  d->mEmails.clear();
1649  const int numEmails = emails.size();
1650  d->mEmails.reserve(numEmails);
1651  for (int i = 0; i < numEmails; ++i) {
1652  d->mEmails.append(Email(emails.at(i)));
1653  }
1654  d->mEmpty = false;
1655 }
1656 
1657 void Addressee::setEmailList(const Email::List &list)
1658 {
1659  d->mEmails = list;
1660  d->mEmpty = false;
1661 }
1662 
1663 void Addressee::removeLang(const QString &language)
1664 {
1665  for (int i = 0; i < d->mLangs.size(); ++i) {
1666  if (d->mLangs.at(i).language() == language) {
1667  d->mLangs.removeAt(i);
1668  }
1669  }
1670 }
1671 
1672 void Addressee::setLangs(const Lang::List &langs)
1673 {
1674  d->mLangs = langs;
1675  d->mEmpty = false;
1676 }
1677 
1678 void Addressee::insertLang(const Lang &language)
1679 {
1680  const QString languageStr = language.language();
1681  if (languageStr.simplified().isEmpty()) {
1682  return;
1683  }
1684  d->mEmpty = false;
1685 
1687  Lang::List::Iterator end(d->mLangs.end());
1688  for (it = d->mLangs.begin(); it != end; ++it) {
1689  if ((*it).language() == languageStr) {
1690  (*it).setParameters(language.parameters());
1691  return;
1692  }
1693  }
1694  d->mLangs.append(language);
1695 }
1696 
1698 {
1699  return d->mLangs;
1700 }
1701 
1702 void Addressee::setGender(const Gender &gender)
1703 {
1704  if (gender == d->mGender) {
1705  return;
1706  }
1707 
1708  d->mEmpty = false;
1709  d->mGender = gender;
1710 }
1711 
1712 Gender Addressee::gender() const
1713 {
1714  return d->mGender;
1715 }
1716 
1718 {
1719  d->mEmpty = false;
1720 
1722  PhoneNumber::List::Iterator end(d->mPhoneNumbers.end());
1723  for (it = d->mPhoneNumbers.begin(); it != end; ++it) {
1724  if ((*it).id() == phoneNumber.id()) {
1725  *it = phoneNumber;
1726  return;
1727  }
1728  }
1729  if (!phoneNumber.number().simplified().isEmpty()) {
1730  d->mPhoneNumbers.append(phoneNumber);
1731  }
1732 }
1733 
1735 {
1737  for (it = d->mPhoneNumbers.begin(); it != d->mPhoneNumbers.end(); ++it) {
1738  if ((*it).id() == phoneNumber.id()) {
1739  d->mPhoneNumbers.erase(it);
1740  return;
1741  }
1742  }
1743 }
1744 
1746 {
1747  PhoneNumber phoneNumber(QString(), type);
1749  for (it = d->mPhoneNumbers.constBegin(); it != d->mPhoneNumbers.constEnd(); ++it) {
1750  if (matchBinaryPattern((*it).type(), type)) {
1751  if ((*it).type() & PhoneNumber::Pref) {
1752  return *it;
1753  } else if (phoneNumber.number().isEmpty()) {
1754  phoneNumber = (*it);
1755  }
1756  }
1757  }
1758 
1759  return phoneNumber;
1760 }
1761 
1763 {
1764  return d->mPhoneNumbers;
1765 }
1766 
1767 void Addressee::setPhoneNumbers(const PhoneNumber::List &phoneNumbers)
1768 {
1769  d->mEmpty = false;
1770  d->mPhoneNumbers.clear();
1771  d->mPhoneNumbers = phoneNumbers;
1772 }
1773 
1775 {
1776  PhoneNumber::List list;
1777 
1779  const PhoneNumber::List::ConstIterator end(d->mPhoneNumbers.constEnd());
1780  for (it = d->mPhoneNumbers.constBegin(); it != end; ++it) {
1781  if (matchBinaryPattern((*it).type(), type)) {
1782  list.append(*it);
1783  }
1784  }
1785  return list;
1786 }
1787 
1789 {
1791  const PhoneNumber::List::ConstIterator end(d->mPhoneNumbers.constEnd());
1792  for (it = d->mPhoneNumbers.constBegin(); it != end; ++it) {
1793  if ((*it).id() == id) {
1794  return *it;
1795  }
1796  }
1797  return PhoneNumber();
1798 }
1799 
1801 {
1802  d->mEmpty = false;
1803 
1805  Key::List::Iterator end(d->mKeys.end());
1806  for (it = d->mKeys.begin(); it != end; ++it) {
1807  if ((*it).id() == key.id()) {
1808  *it = key;
1809  return;
1810  }
1811  }
1812  d->mKeys.append(key);
1813 }
1814 
1815 void vectorRemoveAll(Key::List &t, const Key &key)
1816 {
1817  t.removeAll(key);
1818 }
1819 
1820 void Addressee::removeKey(const Key &key)
1821 {
1823  for (it = d->mKeys.begin(); it != d->mKeys.end(); ++it) {
1824  if ((*it).id() == key.id()) {
1825  d->mKeys.removeAll(key);
1826  return;
1827  }
1828  }
1829 }
1830 
1831 Key Addressee::key(Key::Type type, const QString &customTypeString) const
1832 {
1834  Key::List::ConstIterator end(d->mKeys.constEnd());
1835  for (it = d->mKeys.constBegin(); it != end; ++it) {
1836  if ((*it).type() == type) {
1837  if (type == Key::Custom) {
1838  if (customTypeString.isEmpty()) {
1839  return *it;
1840  } else {
1841  if ((*it).customTypeString() == customTypeString) {
1842  return *it;
1843  }
1844  }
1845  } else {
1846  return *it;
1847  }
1848  }
1849  }
1850  return Key(QString(), type);
1851 }
1852 
1854 {
1855  d->mKeys = list;
1856  d->mEmpty = false;
1857 }
1858 
1860 {
1861  return d->mKeys;
1862 }
1863 
1864 Key::List Addressee::keys(Key::Type type, const QString &customTypeString) const
1865 {
1866  Key::List list;
1867 
1869  Key::List::ConstIterator end(d->mKeys.constEnd());
1870  for (it = d->mKeys.constBegin(); it != end; ++it) {
1871  if ((*it).type() == type) {
1872  if (type == Key::Custom) {
1873  if (customTypeString.isEmpty()) {
1874  list.append(*it);
1875  } else {
1876  if ((*it).customTypeString() == customTypeString) {
1877  list.append(*it);
1878  }
1879  }
1880  } else {
1881  list.append(*it);
1882  }
1883  }
1884  }
1885  return list;
1886 }
1887 
1889 {
1891  Key::List::ConstIterator end(d->mKeys.constEnd());
1892  for (it = d->mKeys.constBegin(); it != end; ++it) {
1893  if ((*it).id() == id) {
1894  return *it;
1895  }
1896  }
1897  return Key();
1898 }
1899 
1901 {
1902  QString str = QLatin1String("Addressee {\n");
1903  str += QStringLiteral(" Uid: %1\n").arg(uid());
1904 
1905  str += QStringLiteral(" Name: %1\n").arg(name());
1906  str += QStringLiteral(" FormattedName: %1\n").arg(formattedName());
1907  str += QStringLiteral(" FamilyName: %1\n").arg(familyName());
1908  str += QStringLiteral(" GivenName: %1\n").arg(givenName());
1909  str += QStringLiteral(" AdditionalName: %1\n").arg(additionalName());
1910  str += QStringLiteral(" Prefix: %1\n").arg(prefix());
1911  str += QStringLiteral(" Suffix: %1\n").arg(suffix());
1912  str += QStringLiteral(" NickName: %1\n").arg(nickName());
1913  str += QStringLiteral(" Birthday: %1\n").arg(birthday().toString());
1914  str += QStringLiteral(" Mailer: %1\n").arg(mailer());
1915  str += QStringLiteral(" TimeZone: %1\n").arg(timeZone().toString());
1916  str += QStringLiteral(" Geo: %1\n").arg(geo().toString());
1917  str += QStringLiteral(" Title: %1\n").arg(title());
1918  str += QStringLiteral(" Role: %1\n").arg(role());
1919  str += QStringLiteral(" Organization: %1\n").arg(organization());
1920  str += QStringLiteral(" Department: %1\n").arg(department());
1921  str += QStringLiteral(" Note: %1\n").arg(note());
1922  str += QStringLiteral(" ProductId: %1\n").arg(productId());
1923  str += QStringLiteral(" Revision: %1\n").arg(revision().toString());
1924  str += QStringLiteral(" SortString: %1\n").arg(sortString());
1925  str += QStringLiteral(" Url: %1\n").arg(url().url().url());
1926  str += QStringLiteral(" Secrecy: %1\n").arg(secrecy().toString());
1927  str += QStringLiteral(" Logo: %1\n").arg(logo().toString());
1928  str += QStringLiteral(" Photo: %1\n").arg(photo().toString());
1929  str += QStringLiteral(" Sound: %1\n").arg(sound().toString());
1930  str += QStringLiteral(" Gender: %1\n").arg(gender().toString());
1931  str += QStringLiteral(" Kind: %1\n").arg(kind());
1932 
1933  str += QLatin1String(" Emails {\n");
1934  const Email::List listEmail = d->mEmails;
1936  for (it5 = listEmail.begin(); it5 != listEmail.end(); ++it5) {
1937  str += (*it5).toString();
1938  }
1939  str += QLatin1String(" }\n");
1940 
1941  str += QLatin1String(" Langs {\n");
1942  const Lang::List listLang = d->mLangs;
1944  for (it6 = listLang.begin(); it6 != listLang.end(); ++it6) {
1945  str += (*it6).toString();
1946  }
1947  str += QLatin1String(" }\n");
1948 
1949  str += QLatin1String(" PhoneNumbers {\n");
1950  const PhoneNumber::List p = phoneNumbers();
1952  for (it2 = p.begin(); it2 != p.end(); ++it2) {
1953  str += (*it2).toString();
1954  }
1955  str += QLatin1String(" }\n");
1956 
1957  str += QLatin1String(" Addresses {\n");
1958  const Address::List a = addresses();
1960  for (it3 = a.begin(); it3 != a.end(); ++it3) {
1961  str += (*it3).toString();
1962  }
1963  str += QLatin1String(" }\n");
1964 
1965  str += QLatin1String(" Keys {\n");
1966  const Key::List k = keys();
1968  for (it4 = k.begin(); it4 != k.end(); ++it4) {
1969  str += (*it4).toString();
1970  }
1971  str += QLatin1String(" }\n");
1972 
1973  str += QLatin1String("}\n");
1974 
1975  return str;
1976 }
1977 
1979 {
1980  if (address.isEmpty()) {
1981  return;
1982  }
1983 
1984  d->mEmpty = false;
1985 
1987  Address::List::Iterator end(d->mAddresses.end());
1988  for (it = d->mAddresses.begin(); it != end; ++it) {
1989  if ((*it).id() == address.id()) {
1990  *it = address;
1991  return;
1992  }
1993  }
1994 
1995  d->mAddresses.append(address);
1996 }
1997 
1999 {
2001  for (it = d->mAddresses.begin(); it != d->mAddresses.end(); ++it) {
2002  if ((*it).id() == address.id()) {
2003  d->mAddresses.erase(it);
2004  return;
2005  }
2006  }
2007 }
2008 
2010 {
2011  Address address(type);
2013  Address::List::ConstIterator end(d->mAddresses.constEnd());
2014  for (it = d->mAddresses.constBegin(); it != end; ++it) {
2015  if (matchBinaryPattern((*it).type(), type)) {
2016  if ((*it).type() & Address::Pref) {
2017  return *it;
2018  } else if (address.isEmpty()) {
2019  address = (*it);
2020  }
2021  }
2022  }
2023 
2024  return address;
2025 }
2026 
2028 {
2029  return d->mAddresses;
2030 }
2031 
2033 {
2034  Address::List list;
2035 
2037  Address::List::ConstIterator end(d->mAddresses.constEnd());
2038  for (it = d->mAddresses.constBegin(); it != end; ++it) {
2039  if (matchBinaryPattern((*it).type(), type)) {
2040  list.append(*it);
2041  }
2042  }
2043 
2044  return list;
2045 }
2046 
2048 {
2050  Address::List::ConstIterator end(d->mAddresses.constEnd());
2051  for (it = d->mAddresses.constBegin(); it != end; ++it) {
2052  if ((*it).id() == id) {
2053  return *it;
2054  }
2055  }
2056  return Address();
2057 }
2058 
2060 {
2061  d->mEmpty = false;
2062 
2063  if (d->mCategories.contains(c)) {
2064  return;
2065  }
2066 
2067  d->mCategories.append(c);
2068 }
2069 
2070 void Addressee::removeCategory(const QString &category)
2071 {
2072  if (d->mCategories.contains(category)) {
2073  d->mCategories.removeAll(category);
2074  }
2075 }
2076 
2077 bool Addressee::hasCategory(const QString &category) const
2078 {
2079  return d->mCategories.contains(category);
2080 }
2081 
2083 {
2084  d->mEmpty = false;
2085 
2086  d->mCategories = c;
2087 }
2088 
2090 {
2091  return d->mCategories;
2092 }
2093 
2094 void Addressee::insertMember(const QString &member)
2095 {
2096  d->mEmpty = false;
2097 
2098  if (d->mMembers.contains(member)) {
2099  return;
2100  }
2101 
2102  d->mMembers.append(member);
2103 }
2104 
2105 void Addressee::setMembers(const QStringList &m)
2106 {
2107  d->mEmpty = false;
2108  d->mMembers = m;
2109 }
2110 
2111 QStringList Addressee::members() const
2112 {
2113  return d->mMembers;
2114 }
2115 
2116 void Addressee::insertRelationship(const Related &relation)
2117 {
2118  d->mEmpty = false;
2119 
2120  if (d->mRelationships.contains(relation)) {
2121  return;
2122  }
2123 
2124  d->mRelationships.append(relation);
2125 }
2126 
2127 void Addressee::setRelationships(const Related::List &c)
2128 {
2129  d->mEmpty = false;
2130  d->mRelationships = c;
2131 }
2132 
2133 Related::List Addressee::relationships() const
2134 {
2135  return d->mRelationships;
2136 }
2137 
2138 static const auto VENDOR_ID = QStringLiteral("KADDRESSBOOK");
2139 static const auto X_ANNIVERSARY = QStringLiteral("X-Anniversary");
2140 static const auto X_ASSISTANTSNAME = QStringLiteral("X-AssistantsName");
2141 static const auto BLOGFEED = QStringLiteral("BlogFeed");
2142 static const auto X_MANAGERSNAME = QStringLiteral("X-ManagersName");
2143 static const auto X_OFFICE = QStringLiteral("X-Office");
2144 static const auto X_PROFESSION = QStringLiteral("X-Profession");
2145 static const auto X_SPOUSESNAME = QStringLiteral("X-SpousesName");
2146 
2148 {
2149  return QDate::fromString(custom(VENDOR_ID, X_ANNIVERSARY), Qt::ISODate);
2150 }
2151 
2153 {
2154  if (anniversary.isValid()) {
2155  insertCustom(VENDOR_ID, X_ANNIVERSARY, anniversary.toString(Qt::ISODate));
2156  } else {
2157  removeCustom(VENDOR_ID, X_ANNIVERSARY);
2158  }
2159 }
2160 
2162 {
2163  return custom(VENDOR_ID, X_ASSISTANTSNAME);
2164 }
2165 
2167 {
2168  if (!assistantsName.isEmpty()) {
2169  insertCustom(VENDOR_ID, X_ASSISTANTSNAME, assistantsName);
2170  } else {
2171  removeCustom(VENDOR_ID, X_ASSISTANTSNAME);
2172  }
2173 }
2174 
2175 QUrl Addressee::blogFeed() const
2176 {
2177  return QUrl(custom(VENDOR_ID, BLOGFEED));
2178 }
2179 
2181 {
2182  if (!blogFeed.isEmpty()) {
2183  insertCustom(VENDOR_ID, BLOGFEED, blogFeed.url());
2184  } else {
2185  removeCustom(VENDOR_ID, BLOGFEED);
2186  }
2187 }
2188 
2190 {
2191  return custom(VENDOR_ID, X_MANAGERSNAME);
2192 }
2193 
2195 {
2196  if (!managersName.isEmpty()) {
2197  insertCustom(VENDOR_ID, X_MANAGERSNAME, managersName);
2198  } else {
2199  removeCustom(VENDOR_ID, X_MANAGERSNAME);
2200  }
2201 }
2202 
2203 QString Addressee::office() const
2204 {
2205  return custom(VENDOR_ID, X_OFFICE);
2206 }
2207 
2209 {
2210  if (!office.isEmpty()) {
2211  insertCustom(VENDOR_ID, X_OFFICE, office);
2212  } else {
2213  removeCustom(VENDOR_ID, X_OFFICE);
2214  }
2215 }
2216 
2218 {
2219  return custom(VENDOR_ID, X_PROFESSION);
2220 }
2221 
2223 {
2224  if (!profession.isEmpty()) {
2225  insertCustom(VENDOR_ID, X_PROFESSION, profession);
2226  } else {
2227  removeCustom(VENDOR_ID, X_PROFESSION);
2228  }
2229 }
2230 
2232 {
2233  return custom(VENDOR_ID, X_SPOUSESNAME);
2234 }
2235 
2237 {
2238  if (!spousesName.isEmpty()) {
2239  insertCustom(VENDOR_ID, X_SPOUSESNAME, spousesName);
2240  } else {
2241  removeCustom(VENDOR_ID, X_SPOUSESNAME);
2242  }
2243 }
2244 
2245 void Addressee::insertCustom(const QString &app, const QString &name, const QString &value)
2246 {
2247  if (value.isEmpty() || name.isEmpty() || app.isEmpty()) {
2248  return;
2249  }
2250 
2251  d->mEmpty = false;
2252 
2253  const QString qualifiedName = app + QLatin1Char('-') + name;
2254 
2255  d->mCustomFields.insert(qualifiedName, value);
2256 }
2257 
2259 {
2260  const QString qualifiedName = app + QLatin1Char('-') + name;
2261 
2262  d->mCustomFields.remove(qualifiedName);
2263 }
2264 
2265 QString Addressee::custom(const QString &app, const QString &name) const
2266 {
2267  const QString qualifiedName = app + QLatin1Char('-') + name;
2268 
2269  return d->mCustomFields.value(qualifiedName);
2270 }
2271 
2273 {
2274  d->mEmpty = false;
2275 
2276  d->mCustomFields.clear();
2277 
2278  for (const QString &custom : customs) {
2279  const int index = custom.indexOf(QLatin1Char(':'));
2280  if (index == -1) {
2281  continue;
2282  }
2283 
2284  const QString qualifiedName = custom.left(index);
2285  const QString value = custom.mid(index + 1);
2286 
2287  d->mCustomFields.insert(qualifiedName, value);
2288  }
2289 }
2290 
2292 {
2293  QStringList result;
2294 
2295  QHash<QString, QString>::const_iterator it = d->mCustomFields.constBegin();
2296  const QHash<QString, QString>::const_iterator end = d->mCustomFields.constEnd();
2297  result.reserve(d->mCustomFields.count());
2298  while (it != end) {
2299  result << it.key() + QLatin1Char(':') + it.value();
2300  ++it;
2301  }
2302 
2303  return result;
2304 }
2305 
2306 void Addressee::parseEmailAddress(const QString &rawEmail, QString &fullName, QString &email)
2307 {
2308  // This is a simplified version of KPIM::splitAddress().
2309 
2310  fullName.clear();
2311  email.clear();
2312  if (rawEmail.isEmpty()) {
2313  return; // KPIM::AddressEmpty;
2314  }
2315 
2316  // The code works on 8-bit strings, so convert the input to UTF-8.
2317  QByteArray address = rawEmail.toUtf8();
2318 
2319  QByteArray displayName;
2320  QByteArray addrSpec;
2321  QByteArray comment;
2322 
2323  // The following is a primitive parser for a mailbox-list (cf. RFC 2822).
2324  // The purpose is to extract a displayable string from the mailboxes.
2325  // Comments in the addr-spec are not handled. No error checking is done.
2326 
2327  enum sourceLevel {
2328  TopLevel,
2329  InComment,
2330  InAngleAddress,
2331  };
2332  sourceLevel context = TopLevel;
2333  bool inQuotedString = false;
2334  int commentLevel = 0;
2335  bool stop = false;
2336 
2337  for (char *p = address.data(); *p && !stop; ++p) {
2338  switch (context) {
2339  case TopLevel:
2340  switch (*p) {
2341  case '"':
2342  inQuotedString = !inQuotedString;
2343  displayName += *p;
2344  break;
2345  case '(':
2346  if (!inQuotedString) {
2347  context = InComment;
2348  commentLevel = 1;
2349  } else {
2350  displayName += *p;
2351  }
2352  break;
2353  case '<':
2354  if (!inQuotedString) {
2355  context = InAngleAddress;
2356  } else {
2357  displayName += *p;
2358  }
2359  break;
2360  case '\\': // quoted character
2361  displayName += *p;
2362  ++p; // skip the '\'
2363  if (*p) {
2364  displayName += *p;
2365  } else {
2366  // return KPIM::UnexpectedEnd;
2367  goto ABORT_PARSING;
2368  }
2369  break;
2370  case ',':
2371  if (!inQuotedString) {
2372  // if ( allowMultipleAddresses )
2373  // stop = true;
2374  // else
2375  // return KPIM::UnexpectedComma;
2376  goto ABORT_PARSING;
2377  } else {
2378  displayName += *p;
2379  }
2380  break;
2381  default:
2382  displayName += *p;
2383  }
2384  break;
2385  case InComment:
2386  switch (*p) {
2387  case '(':
2388  ++commentLevel;
2389  comment += *p;
2390  break;
2391  case ')':
2392  --commentLevel;
2393  if (commentLevel == 0) {
2394  context = TopLevel;
2395  comment += ' '; // separate the text of several comments
2396  } else {
2397  comment += *p;
2398  }
2399  break;
2400  case '\\': // quoted character
2401  comment += *p;
2402  ++p; // skip the '\'
2403  if (*p) {
2404  comment += *p;
2405  } else {
2406  // return KPIM::UnexpectedEnd;
2407  goto ABORT_PARSING;
2408  }
2409  break;
2410  default:
2411  comment += *p;
2412  }
2413  break;
2414  case InAngleAddress:
2415  switch (*p) {
2416  case '"':
2417  inQuotedString = !inQuotedString;
2418  addrSpec += *p;
2419  break;
2420  case '>':
2421  if (!inQuotedString) {
2422  context = TopLevel;
2423  } else {
2424  addrSpec += *p;
2425  }
2426  break;
2427  case '\\': // quoted character
2428  addrSpec += *p;
2429  ++p; // skip the '\'
2430  if (*p) {
2431  addrSpec += *p;
2432  } else {
2433  // return KPIM::UnexpectedEnd;
2434  goto ABORT_PARSING;
2435  }
2436  break;
2437  default:
2438  addrSpec += *p;
2439  }
2440  break;
2441  } // switch ( context )
2442  }
2443 
2444 ABORT_PARSING:
2445  displayName = displayName.trimmed();
2446  comment = comment.trimmed();
2447  addrSpec = addrSpec.trimmed();
2448  fullName = QString::fromUtf8(displayName);
2449  email = QString::fromUtf8(addrSpec); // check for errors
2450  if (inQuotedString) {
2451  return; // KPIM::UnbalancedQuote;
2452  }
2453  if (context == InComment) {
2454  return; // KPIM::UnbalancedParens;
2455  }
2456  if (context == InAngleAddress) {
2457  return; // KPIM::UnclosedAngleAddr;
2458  }
2459 
2460  if (addrSpec.isEmpty()) {
2461  if (displayName.isEmpty()) {
2462  return; // KPIM::NoAddressSpec;
2463  } else {
2464  // addrSpec = displayName;
2465  // displayName.truncate( 0 );
2466  // Address of the form "[email protected]" or "[email protected] (Name)".
2467  email = fullName;
2468  fullName = QString::fromUtf8(comment);
2469  }
2470  }
2471 
2472  email = email.toLower();
2473 
2474  // Check that the full name is not enclosed in balanced double quotes.
2475  // If it is then remove them.
2476  const unsigned int len = fullName.length();
2477  if (len < 3) { // not long enough to be
2478  return;
2479  }
2480  if (fullName.startsWith(QLatin1Char('"')) && fullName.endsWith(QLatin1Char('"'))) {
2481  fullName = fullName.mid(1, len - 2);
2482  }
2483 }
2484 
2485 void Addressee::setChanged(bool value)
2486 {
2487  d->mChanged = value;
2488 }
2489 
2490 bool Addressee::changed() const
2491 {
2492  return d->mChanged;
2493 }
2494 
2496 {
2497  return QStringLiteral("text/directory");
2498 }
2499 
2500 QDataStream &KContacts::operator<<(QDataStream &s, const Addressee &a)
2501 {
2502  s << a.d->mUid;
2503 
2504  s << a.d->mName;
2505  s << a.d->mFormattedName;
2506  s << a.d->mFamilyName;
2507  s << a.d->mGivenName;
2508  s << a.d->mAdditionalName;
2509  s << a.d->mPrefix;
2510  s << a.d->mSuffix;
2511  s << a.d->mBirthday;
2512  s << a.d->mBirthdayWithTime;
2513  s << a.d->mMailer;
2514  s << a.d->mTimeZone;
2515  s << a.d->mGeo;
2516  s << a.d->mDepartment;
2517  s << a.d->mNote;
2518  s << a.d->mProductId;
2519  s << a.d->mRevision;
2520  s << a.d->mSortString;
2521  s << a.d->mSecrecy;
2522  s << a.d->mLogo;
2523  s << a.d->mPhoto;
2524  s << a.d->mSound;
2525  s << a.d->mPhoneNumbers;
2526  s << a.d->mAddresses;
2527  s << a.d->mEmails;
2528  s << a.d->mCategories;
2529  s << a.customs();
2530  s << a.d->mKeys;
2531  s << a.d->mLangs;
2532  s << a.d->mGender;
2533  s << a.d->mKind;
2534  s << a.d->mCalendarUrl;
2535  s << a.d->mSoundListExtra;
2536  s << a.d->mPhotoExtraList;
2537  s << a.d->mLogoExtraList;
2538  s << a.d->mUrlExtraList;
2539  s << a.d->mMembers;
2540  s << a.d->mRelationships;
2541  s << a.d->mSources;
2542  s << a.d->mImpps;
2543  s << a.d->mFieldGroupList;
2544  s << a.d->mTitleExtraList;
2545  s << a.d->mRoleExtraList;
2546  s << a.d->mOrgExtraList;
2547  s << a.d->mNickNameExtraList;
2548  s << a.d->mClientPidMapList;
2549 
2550  return s;
2551 }
2552 
2553 QDataStream &KContacts::operator>>(QDataStream &s, Addressee &a)
2554 {
2555  s >> a.d->mUid;
2556 
2557  s >> a.d->mName;
2558  s >> a.d->mFormattedName;
2559  s >> a.d->mFamilyName;
2560  s >> a.d->mGivenName;
2561  s >> a.d->mAdditionalName;
2562  s >> a.d->mPrefix;
2563  s >> a.d->mSuffix;
2564  s >> a.d->mBirthday;
2565  s >> a.d->mBirthdayWithTime;
2566  s >> a.d->mMailer;
2567  s >> a.d->mTimeZone;
2568  s >> a.d->mGeo;
2569  s >> a.d->mDepartment;
2570  s >> a.d->mNote;
2571  s >> a.d->mProductId;
2572  s >> a.d->mRevision;
2573  s >> a.d->mSortString;
2574  s >> a.d->mSecrecy;
2575  s >> a.d->mLogo;
2576  s >> a.d->mPhoto;
2577  s >> a.d->mSound;
2578  s >> a.d->mPhoneNumbers;
2579  s >> a.d->mAddresses;
2580  s >> a.d->mEmails;
2581  s >> a.d->mCategories;
2582  QStringList customFields;
2583  s >> customFields;
2584  a.setCustoms(customFields);
2585  s >> a.d->mKeys;
2586  s >> a.d->mLangs;
2587  s >> a.d->mGender;
2588  s >> a.d->mKind;
2589  s >> a.d->mCalendarUrl;
2590  s >> a.d->mSoundListExtra;
2591  s >> a.d->mPhotoExtraList;
2592  s >> a.d->mLogoExtraList;
2593  s >> a.d->mUrlExtraList;
2594  s >> a.d->mMembers;
2595  s >> a.d->mRelationships;
2596  s >> a.d->mSources;
2597  s >> a.d->mImpps;
2598  s >> a.d->mFieldGroupList;
2599  s >> a.d->mTitleExtraList;
2600  s >> a.d->mRoleExtraList;
2601  s >> a.d->mOrgExtraList;
2602  s >> a.d->mNickNameExtraList;
2603  s >> a.d->mClientPidMapList;
2604  a.d->mEmpty = false;
2605 
2606  return s;
2607 }
2608 
2609 bool matchBinaryPattern(int value, int pattern)
2610 {
2611  /**
2612  We want to match all telephonnumbers/addresses which have the bits in the
2613  pattern set. More are allowed.
2614  if pattern == 0 we have a special handling, then we want only those with
2615  exactly no bit set.
2616  */
2617  if (pattern == 0) {
2618  return value == 0;
2619  } else {
2620  return pattern == (pattern & value);
2621  }
2622 }
2623 
2624 template<class L>
2625 bool listEquals(const QVector<L> &list, const QVector<L> &pattern)
2626 {
2627  if (list.count() != pattern.count()) {
2628  return false;
2629  }
2630  const int numberOfElement(list.count());
2631  for (int i = 0; i < numberOfElement; ++i) {
2632  if (!pattern.contains(list[i])) {
2633  return false;
2634  }
2635  }
2636 
2637  return true;
2638 }
2639 
2640 bool listEquals(const QStringList &list, const QStringList &pattern)
2641 {
2642  if (list.count() != pattern.count()) {
2643  return false;
2644  }
2645 
2646  const int numberOfElement(list.count());
2647  for (int i = 0; i < numberOfElement; ++i) {
2648  if (!pattern.contains(list[i])) {
2649  return false;
2650  }
2651  }
2652 
2653  return true;
2654 }
2655 
2656 template<typename T>
2657 static QVariantList toVariantList(const QVector<T> &v)
2658 {
2659  QVariantList l;
2660  l.reserve(v.size());
2661  std::transform(v.begin(), v.end(), std::back_inserter(l), [](const T &elem) {
2662  return QVariant::fromValue(elem);
2663  });
2664  return l;
2665 }
2666 
2667 template<typename T>
2668 static QVector<T> fromVariantList(const QVariantList &v)
2669 {
2670  QVector<T> l;
2671  l.reserve(v.size());
2672  std::transform(v.begin(), v.end(), std::back_inserter(l), [](const QVariant &elem) {
2673  return elem.value<T>();
2674  });
2675  return l;
2676 }
2677 
2678 QVariantList Addressee::emailsVariant() const
2679 {
2680  return toVariantList(d->mEmails);
2681 }
2682 
2683 void Addressee::setEmailsVariant(const QVariantList &emails)
2684 {
2685  setEmailList(fromVariantList<Email>(emails));
2686 }
2687 
2688 void Addressee::setPhoneNumbersVariant(const QVariantList &emails)
2689 {
2690  setPhoneNumbers(fromVariantList<PhoneNumber>(emails));
2691 }
2692 
2693 QVariantList Addressee::phoneNumbersVariant() const
2694 {
2695  return toVariantList(d->mPhoneNumbers);
2696 }
2697 
2698 QVariantList Addressee::addressesVariant() const
2699 {
2700  return toVariantList(d->mAddresses);
2701 }
2702 
2703 QVariantList Addressee::urlsVariant() const
2704 {
2705  return toVariantList(d->mUrlExtraList);
2706 }
2707 
2708 QVariantList Addressee::imppsVariant() const
2709 {
2710  return toVariantList(d->mImpps);
2711 }
2712 
2713 void Addressee::setImppsVariant(const QVariantList &impps)
2714 {
2715  setImppList(fromVariantList<Impp>(impps));
2716 }
2717 
2718 #include "moc_addressee.cpp"
QString url(QUrl::FormattingOptions options) const const
QString custom(const QString &app, const QString &name) const
Return value of custom entry, identified by app and entry name.
Definition: addressee.cpp:2265
void setFormattedName(const QString &formattedName)
Set formatted name.
Definition: addressee.cpp:620
Class that holds a FieldGroup for a contact.
Definition: fieldgroup.h:21
static QString mimeType()
Returns the MIME type used for Addressees.
Definition: addressee.cpp:2495
void setMailer(const QString &mailer)
Set mail client.
Definition: addressee.cpp:946
Key findKey(const QString &id) const
Return key with the given id.
Definition: addressee.cpp:1888
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
Addressee()
Construct an empty address book entry.
Definition: addressee.cpp:147
typedef Iterator
static QString carPhoneLabel()
Return translated label for carPhone field.
Definition: addressee.cpp:926
QString & append(QChar ch)
void insertCategory(const QString &category)
Insert category.
Definition: addressee.cpp:2059
Class that holds a Email for a contact.
Definition: email.h:23
Custom or IANA conform key.
Definition: key.h:38
QString name() const
Return name.
static QString businessAddressRegionLabel()
Return translated label for businessAddressRegion field.
Definition: addressee.cpp:881
void setAnniversary(const QDate &anniversary)
Sets the contact&#39;s anniversary date.
Definition: addressee.cpp:2152
bool containsSuffix(const QString &suffix) const
Queries the list of honoric suffixes.
void insertLang(const Lang &language)
Insert Language.
Definition: addressee.cpp:1678
void setBlogFeed(const QUrl &blogFeed)
Set the contact&#39;s blog feed.
Definition: addressee.cpp:2180
QString familyName() const
Return family name.
void removeEmail(const QString &email)
Remove email address.
Definition: addressee.cpp:1611
QString additionalName() const
Return additional names.
QString assistantsName() const
Returns the contact&#39;s assistant&#39;s name.
const Key key(const T &value) const const
QStringList categories() const
Return list of all set categories.
void removeAddress(const Address &address)
Remove address.
Definition: addressee.cpp:1998
int removeAll(const T &t)
void removeCategory(const QString &category)
Remove category.
Definition: addressee.cpp:2070
void insertPhoneNumber(const PhoneNumber &phoneNumber)
Insert a phone number.
Definition: addressee.cpp:1717
static QString givenNameLabel()
Return translated label for givenName field.
Definition: addressee.cpp:675
QString toString(Qt::DateFormat format) const const
Describes a relationship of an Addressee.
Definition: related.h:19
void append(const T &value)
QByteArray trimmed() const const
QVector::iterator begin()
void setTimeZone(const TimeZone &timeZone)
Set time zone.
Definition: addressee.cpp:966
static QString productIdLabel()
Return translated label for productId field.
Definition: addressee.cpp:1214
QStringList emails() const
Return list of all email addresses.
Class that holds a Role for a contact.
Definition: role.h:21
QString productId() const
Return product identifier.
void setPhoto(const Picture &photo)
Set photo.
Definition: addressee.cpp:1325
static QString mobilePhoneLabel()
Return translated label for mobilePhone field.
Definition: addressee.cpp:911
static void parseEmailAddress(const QString &rawEmail, QString &fullName, QString &email)
Parse full email address.
Definition: addressee.cpp:2306
QString organization() const
Return organization.
void setSuffix(const QString &suffix)
Set honorific suffixes.
Definition: addressee.cpp:720
QString role() const
Return role.
static QString timeZoneLabel()
Return translated label for timeZone field.
Definition: addressee.cpp:981
QString toString() const
Returns string representation of the addressee.
Definition: addressee.cpp:1900
QString sortString() const
Return sort string.
void reserve(int alloc)
Class that holds a Resource Locator.
bool treatAsFamilyName() const
Returns whether or not a single name component should be interpreted as a family name.
void setCustoms(const QStringList &customs)
Set all custom entries.
Definition: addressee.cpp:2272
QString & prepend(QChar ch)
QString uid() const
Return unique identifier.
static AddresseeHelper * self()
Singleton interface to this class.
static QString isdnLabel()
Return translated label for isdn field.
Definition: addressee.cpp:931
void setUid(const QString &uid)
Set unique identifier.
Definition: addressee.cpp:404
static QString geoLabel()
Return translated label for geo field.
Definition: addressee.cpp:1001
const T & at(int i) const const
Geographic position.
Definition: geo.h:24
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition: calendarurl.h:22
bool contains(const QString &str, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QDateTime revision() const
Return revision date.
QString simplified() const const
static QString prefixLabel()
Return translated label for prefix field.
Definition: addressee.cpp:715
static QString pagerLabel()
Return translated label for pager field.
Definition: addressee.cpp:936
static QString suffixLabel()
Return translated label for suffix field.
Definition: addressee.cpp:735
static QString nickNameLabel()
Return translated label for nickName field.
Definition: addressee.cpp:786
QString nickName() const
Return nick name.
void setPrefix(const QString &prefix)
Set honorific prefixes.
Definition: addressee.cpp:700
QString assembledName() const
Return the name that consists of all name parts.
static QString homePhoneLabel()
Return translated label for homePhone field.
Definition: addressee.cpp:901
This singleton class stores static data, which is shared by all Addressee objects.
static QString homeAddressStreetLabel()
Return translated label for homeAddressStreet field.
Definition: addressee.cpp:831
void removeLang(const QString &language)
Remove Language.
Definition: addressee.cpp:1663
void setEmails(const QStringList &list)
Set the emails to list.
Definition: addressee.cpp:1646
void setGivenName(const QString &givenName)
Set given name.
Definition: addressee.cpp:660
typedef ConstIterator
static QString homeAddressLocalityLabel()
Return translated label for homeAddressLocality field.
Definition: addressee.cpp:841
void setDepartment(const QString &department)
Set department.
Definition: addressee.cpp:1159
bool isEmpty() const const
Sound sound() const
Return sound.
Definition: addressee.cpp:1355
static QString sortStringLabel()
Return translated label for sortString field.
Definition: addressee.cpp:1254
void setAdditionalName(const QString &additionalName)
Set additional names.
Definition: addressee.cpp:680
static QString homeFaxLabel()
Return translated label for homeFax field.
Definition: addressee.cpp:916
preferred address
Definition: address.h:72
void insertEmail(const QString &email, bool preferred=false, const QMap< QString, QStringList > &param=QMap< QString, QStringList >())
Insert an email address.
Definition: addressee.cpp:1584
void removeKey(const Key &key)
Remove a key.
Definition: addressee.cpp:1820
Address address(Address::Type type) const
Return address, which matches the given type.
Definition: addressee.cpp:2009
static QString logoLabel()
Return translated label for logo field.
Definition: addressee.cpp:1320
QString managersName() const
Returns the contact&#39;s manager&#39;s name.
int size() const const
bool isNull() const const
QString mailer() const
Return mail client.
void clear()
static QString businessAddressStreetLabel()
Return translated label for businessAddressStreet field.
Definition: addressee.cpp:866
void setUrl(const ResourceLocatorUrl &url)
Set homepage.
Definition: addressee.cpp:1266
void setAssistantsName(const QString &assistantsName)
Set the contact&#39;s assistant&#39;s name.
Definition: addressee.cpp:2166
ResourceLocatorUrl url() const
Return homepage.
QString fullEmail(const QString &email=QString()) const
Return email address including real name.
Definition: addressee.cpp:1555
QString profession() const
Returns the contact&#39;s profession.
void setCategories(const QStringList &category)
Set categories to given value.
Definition: addressee.cpp:2082
QString title() const
Return title.
void setOrganization(const QString &organization)
Set organization.
Definition: addressee.cpp:1108
Preferred number.
Definition: phonenumber.h:52
void removePhoneNumber(const PhoneNumber &phoneNumber)
Remove phone number.
Definition: addressee.cpp:1734
QDate fromString(const QString &string, Qt::DateFormat format)
bool containsPrefix(const QString &prefix) const
Queries the list of inclusions.
int count(const T &value) const const
Class that holds a ClientPidMap for a contact.
Definition: clientpidmap.h:21
bool contains(const T &value) const const
void setTitle(const QString &title)
Set title.
Definition: addressee.cpp:1006
QString fromUtf8(const char *str, int size)
static QString revisionLabel()
Return translated label for revision field.
Definition: addressee.cpp:1234
void setSortString(const QString &sortString)
Set sort string.
Definition: addressee.cpp:1239
void setOffice(const QString &office)
Set the contact&#39;s office.
Definition: addressee.cpp:2208
void setProfession(const QString &profession)
Set the contact&#39;s profession.
Definition: addressee.cpp:2222
static QString soundLabel()
Return translated label for sound field.
Definition: addressee.cpp:1360
static QString businessAddressCountryLabel()
Return translated label for businessAddressCountry field.
Definition: addressee.cpp:891
QString i18nc(const char *context, const char *text, const TYPE &arg...)
TimeZone timeZone() const
Return time zone.
Definition: addressee.cpp:976
static QString homeAddressLabelLabel()
Return translated label for homeAddressLabel field.
Definition: addressee.cpp:861
void setNameFromString(const QString &s)
Set name fields by parsing the given string and trying to associate the parts of the string with acco...
Definition: addressee.cpp:1365
void setFamilyName(const QString &familyName)
Set family name.
Definition: addressee.cpp:640
void setChanged(bool value)
Mark addressee as changed.
Definition: addressee.cpp:2485
QString suffix() const
Return honorific suffixes.
bool isEmpty() const const
bool isEmpty() const const
Key key(Key::Type type, const QString &customTypeString=QString()) const
Return key, which matches the given type.
Definition: addressee.cpp:1831
static QString noteLabel()
Return translated label for note field.
Definition: addressee.cpp:1194
Secrecy secrecy() const
Return security class.
Definition: addressee.cpp:1295
static QString businessAddressLabelLabel()
Return translated label for businessAddressLabel field.
Definition: addressee.cpp:896
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
A class to store an encryption key.
Definition: key.h:21
QStringList split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
static QString businessAddressPostalCodeLabel()
Return translated label for businessAddressPostalCode field.
Definition: addressee.cpp:886
bool isValid() const const
bool isEmpty() const
Return if the address book entry is empty.
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const const
void setSpousesName(const QString &spousesName)
Set the contact&#39;s spouse&#39;s name.
Definition: addressee.cpp:2236
static QString additionalNameLabel()
Return translated label for additionalName field.
Definition: addressee.cpp:695
QUrl blogFeed() const
Returns the contact&#39;s blog feed.
Addressee & operator=(const Addressee &other)
Assignment operator.
Definition: addressee.cpp:161
QDateTime birthday() const
Return birthday.
Class that holds a IMPP for a contact.
Definition: impp.h:27
~Addressee()
Destroys the address book entry.
Definition: addressee.cpp:152
QString realName() const
Return the name of the addressee.
A class to store a picture of an addressee.
Definition: picture.h:26
bool containsTitle(const QString &title) const
Queries the list of honoric prefixes.
bool operator!=(const Addressee &other) const
Not-equal operator.
Definition: addressee.cpp:394
QString preferredEmail() const
Return preferred email address.
QString toLower() const const
QString formattedName() const
Return formatted name.
const T value(const Key &key) const const
void reserve(int size)
Type
Key types.
Definition: key.h:35
static QString formattedNameLabel()
Return translated label for formattedName field.
Definition: addressee.cpp:635
bool birthdayHasTime() const
Returns true if birthday has been set with a time.
Address findAddress(const QString &id) const
Return address with the given id.
Definition: addressee.cpp:2047
void setNickName(const QString &nickName)
Set nick name.
Definition: addressee.cpp:740
PhoneNumber phoneNumber(PhoneNumber::Type type) const
Return phone number, which matches the given type.
Definition: addressee.cpp:1745
static QString mailerLabel()
Return translated label for mailer field.
Definition: addressee.cpp:961
void setProductId(const QString &productId)
Set product identifier.
Definition: addressee.cpp:1199
QVariant fromValue(const T &value)
static QString businessAddressLocalityLabel()
Return translated label for businessAddressLocality field.
Definition: addressee.cpp:876
QString spousesName() const
Returns the contact&#39;s spouse&#39;s name.
static QString titleLabel()
Return translated label for title field.
Definition: addressee.cpp:1052
static QString emailLabel()
Return translated label for email field.
Definition: addressee.cpp:941
static QString familyNameLabel()
Return translated label for familyName field.
Definition: addressee.cpp:655
static QString uidLabel()
Return translated label for uid field.
Definition: addressee.cpp:419
QString i18n(const char *text, const TYPE &arg...)
void insertCustom(const QString &app, const QString &name, const QString &value)
Insert custom entry.
Definition: addressee.cpp:2245
QString & replace(int position, int n, QChar after)
void insertKey(const Key &key)
Insert a key.
Definition: addressee.cpp:1800
PhoneNumber::List phoneNumbers() const
Return list of all phone numbers.
Class that holds a Sound clip for a contact.
Definition: sound.h:45
QString mid(int position, int n) const const
QString department() const
Return department.
void setKeys(const Key::List &keys)
Set the list of keys.
Definition: addressee.cpp:1853
bool operator==(const Addressee &other) const
Equality operator.
Definition: addressee.cpp:170
char * toString(const T &value)
static QString secrecyLabel()
Return translated label for secrecy field.
Definition: addressee.cpp:1300
void setNote(const QString &note)
Set note.
Definition: addressee.cpp:1179
Postal address information.
Definition: address.h:28
Lang::List langs() const
langs
Definition: addressee.cpp:1697
Class that holds a NickName for a contact.
Definition: nickname.h:21
static QString nameLabel()
Return translated label for name field.
Definition: addressee.cpp:439
static QString urlLabel()
Return translated label for url field.
Definition: addressee.cpp:1280
static QString businessPhoneLabel()
Return translated label for businessPhone field.
Definition: addressee.cpp:906
void setGeo(const Geo &geo)
Set geographic position.
Definition: addressee.cpp:986
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QStringList customs() const
Return list of all custom entries.
void setRevision(const QDateTime &revision)
Set revision date.
Definition: addressee.cpp:1219
static QString homeAddressPostalCodeLabel()
Return translated label for homeAddressPostalCode field.
Definition: addressee.cpp:851
Class that holds a Language for a contact.
Definition: lang.h:21
static QString homeAddressPostOfficeBoxLabel()
Return translated label for homeAddressPostOfficeBox field.
Definition: addressee.cpp:836
Describes the confidentiality of an addressee.
Definition: secrecy.h:18
void setLogo(const Picture &logo)
Set logo.
Definition: addressee.cpp:1305
int count(const T &value) const const
Picture photo() const
Return photo.
void setBirthday(const QDateTime &birthday, bool withTime=true)
Set birthday (date and time).
Definition: addressee.cpp:791
Class that holds a Gender for a contact.
Definition: gender.h:19
Class that holds a Title for a contact.
Definition: title.h:21
int length() const const
QString office() const
Returns the contact&#39;s office.
char * data()
static QString businessAddressPostOfficeBoxLabel()
Return translated label for businessAddressPostOfficeBox field.
Definition: addressee.cpp:871
QString left(int n) const const
static QString homeAddressRegionLabel()
Return translated label for homeAddressRegion field.
Definition: addressee.cpp:846
static QString photoLabel()
Return translated label for photo field.
Definition: addressee.cpp:1340
static QString roleLabel()
Return translated label for role field.
Definition: addressee.cpp:1103
static QString businessFaxLabel()
Return translated label for businessFax field.
Definition: addressee.cpp:921
QString id() const
Returns the unique identifier.
Definition: key.cpp:112
static QString birthdayLabel()
Return translated label for birthday field.
Definition: addressee.cpp:826
address book entry
Definition: addressee.h:69
Class that holds a Organization for a contact.
Definition: org.h:21
void removeCustom(const QString &app, const QString &name)
Remove custom entry.
Definition: addressee.cpp:2258
Time zone information.
Definition: timezone.h:22
void setName(const QString &name)
Set name.
Definition: addressee.cpp:424
Address::List addresses() const
Return list of all addresses.
bool hasCategory(const QString &category) const
Return, if addressee has the given category.
Definition: addressee.cpp:2077
bool changed() const
Return whether the addressee is changed.
int size() const const
static QString organizationLabel()
Return translated label for organization field.
Definition: addressee.cpp:1154
QDate anniversary() const
Returns the contact&#39;s anniversary date.
QString givenName() const
Return given name.
QVector::iterator end()
static QString departmentLabel()
Return translated label for department field.
Definition: addressee.cpp:1174
static QString homeAddressCountryLabel()
Return translated label for homeAddressCountry field.
Definition: addressee.cpp:856
void setSecrecy(const Secrecy &secrecy)
Set security class.
Definition: addressee.cpp:1285
QString note() const
Return note.
void setRole(const QString &role)
Set role.
Definition: addressee.cpp:1057
Phonenumber information.
Definition: phonenumber.h:28
Key::List keys() const
Return list of all keys.
Definition: addressee.cpp:1859
QString prefix() const
Return honorific prefixes.
PhoneNumber findPhoneNumber(const QString &id) const
Return phone number with the given id.
Definition: addressee.cpp:1788
void insertAddress(const Address &address)
Insert an address.
Definition: addressee.cpp:1978
Geo geo() const
Return geographic position.
void setManagersName(const QString &managersName)
Set the contact&#39;s manager&#39;s name.
Definition: addressee.cpp:2194
void setSound(const Sound &sound)
Set sound.
Definition: addressee.cpp:1345
QByteArray toUtf8() const const
Picture logo() const
Return logo.
Definition: addressee.cpp:1315
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Sep 20 2021 22:56:06 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.