diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ find_package(KF5ItemViews ${KF5_DEP_VERSION} CONFIG REQUIRED) find_package(KF5Service ${KF5_DEP_VERSION} CONFIG REQUIRED) +find_package(KF5Contacts REQUIRED) + include(ECMSetupVersion) include(ECMGenerateHeaders) include(ECMSetupVersion) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,7 @@ target_link_libraries (KF5People PUBLIC Qt5::Gui + KF5::Contacts PRIVATE Qt5::Sql Qt5::DBus diff --git a/src/backends/CMakeLists.txt b/src/backends/CMakeLists.txt --- a/src/backends/CMakeLists.txt +++ b/src/backends/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries (KF5PeopleBackend PUBLIC Qt5::Widgets #needed for QAction, otherwise QtGui + KF5::Contacts ) target_include_directories (KF5PeopleBackend PUBLIC "$" diff --git a/src/backends/abstractcontact.h b/src/backends/abstractcontact.h --- a/src/backends/abstractcontact.h +++ b/src/backends/abstractcontact.h @@ -74,6 +74,15 @@ /** QVariantList property that lists the emails the contact has */ static const QString AllEmailsProperty; + /** KContact::PhoneNumber property representing the phone number and releated information of a contact */ + static const QString KContactPhoneNumberProperty; + + /** + * KContact::PhoneNumber::List (aka. QVector) property that accesses all phone + * numbers of the contact as KContact::PhoneNumber + */ + static const QString KContactAllPhoneNumbersProperty; + /** * Generic method to access a random contact property * diff --git a/src/backends/abstractcontact.cpp b/src/backends/abstractcontact.cpp --- a/src/backends/abstractcontact.cpp +++ b/src/backends/abstractcontact.cpp @@ -28,6 +28,8 @@ const QString AbstractContact::AllEmailsProperty = QStringLiteral("all-email"); const QString AbstractContact::PictureProperty = QStringLiteral("picture"); const QString AbstractContact::GroupsProperty = QStringLiteral("all-groups"); +const QString AbstractContact::KContactPhoneNumberProperty = QStringLiteral("kcontact-phoneNumber"); +const QString AbstractContact::KContactAllPhoneNumbersProperty = QStringLiteral("kcontact-all-phoneNumber"); AbstractContact::AbstractContact() { diff --git a/src/persondata.h b/src/persondata.h --- a/src/persondata.h +++ b/src/persondata.h @@ -22,9 +22,12 @@ #include +#include #include #include +#include + #include "global.h" namespace KPeople @@ -114,11 +117,11 @@ /** Returns all e-mail addresses from the person. */ QStringList allEmails() const; - // struct PhoneNumber { - // QString name; - // QString number; - // }; - // QVector phoneNumbers() const { createPhoneNumbers(customProperty("phoneNumbers")); }; + /** Returns an arbritrary phone number of the contact */ + KContacts::PhoneNumber phoneNumber() const; + + /** Returns an arbritrary phone number of the contact */ + KContacts::PhoneNumber::List allPhoneNumbers() const; Q_SIGNALS: /** @@ -136,4 +139,8 @@ }; } +// This probably will not be needed in the future since it should already be handled +// by newer (> 19.04) versions of KContacts +Q_DECLARE_METATYPE(KContacts::PhoneNumber) + #endif // PERSONDATA_H diff --git a/src/persondata.cpp b/src/persondata.cpp --- a/src/persondata.cpp +++ b/src/persondata.cpp @@ -207,3 +207,20 @@ return ret; } +KContacts::PhoneNumber PersonData::phoneNumber() const +{ + const QVariant phoneNumber = contactCustomProperty(AbstractContact::KContactPhoneNumberProperty); + return phoneNumber.value(); +} + +KContacts::PhoneNumber::List PersonData::allPhoneNumbers () const +{ + const QVariantList phoneNumberList = contactCustomProperty(AbstractContact::KContactAllPhoneNumbersProperty).toList(); + KContacts::PhoneNumber::List ret; + + for (const QVariant& phoneNumber : phoneNumberList) { + ret += phoneNumber.value(); + } + + return ret; +}