diff --git a/kaddressbookgrantlee/src/CMakeLists.txt b/kaddressbookgrantlee/src/CMakeLists.txt --- a/kaddressbookgrantlee/src/CMakeLists.txt +++ b/kaddressbookgrantlee/src/CMakeLists.txt @@ -13,7 +13,6 @@ contactobject/contactgrantleeimobject.cpp contactobject/contactgrantleephoneobject.cpp contactobject/contactgrantleewebsite.cpp - contactobject/contactgrantleeemail.cpp ) set(kaddressbook_grantlee_printing_LIB_SRCS diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.h b/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.h deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2016-2019 Montel Laurent - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef PRINT_CONTACTGRANTLEEEMAIL_H -#define PRINT_CONTACTGRANTLEEEMAIL_H - -#include - -#include -#include - -namespace KAddressBookGrantlee { -class ContactGrantleeEmail : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString emailFormatted READ emailFormatted) - Q_PROPERTY(QString email READ email) - Q_PROPERTY(bool preferred READ preferred) -public: - explicit ContactGrantleeEmail(const KContacts::Addressee &addressee, const KContacts::Email &email, QObject *parent = nullptr); - ~ContactGrantleeEmail(); - Q_REQUIRED_RESULT QString emailFormatted() const; - - Q_REQUIRED_RESULT QString email() const; - Q_REQUIRED_RESULT bool preferred() const; -private: - KContacts::Email mEmail; - KContacts::Addressee mAddressee; -}; -} -#endif // PRINT_CONTACTGRANTLEEEMAIL_H diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.cpp b/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.cpp deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleeemail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (C) 2016-2019 Montel Laurent - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "contactgrantleeemail.h" -using namespace KAddressBookGrantlee; - -ContactGrantleeEmail::ContactGrantleeEmail(const KContacts::Addressee &addressee, const KContacts::Email &email, QObject *parent) - : QObject(parent) - , mEmail(email) - , mAddressee(addressee) -{ -} - -ContactGrantleeEmail::~ContactGrantleeEmail() -{ -} - -QString ContactGrantleeEmail::email() const -{ - const QString email = mEmail.mail(); - return mAddressee.fullEmail(email); -} - -bool ContactGrantleeEmail::preferred() const -{ - const QStringList value = mEmail.parameters().value(QStringLiteral("type")); - //Validate PREF and pref - return value.contains(QLatin1String("pref"), Qt::CaseInsensitive); -} - -QString ContactGrantleeEmail::emailFormatted() const -{ - const QString email = mEmail.mail(); - const QString fullEmail = QString::fromLatin1(QUrl::toPercentEncoding(mAddressee.fullEmail(email))); - - const QString url = QStringLiteral("%2") - .arg(fullEmail, email); - return url; -} diff --git a/kaddressbookgrantlee/src/formatter/grantleecontactformatter.cpp b/kaddressbookgrantlee/src/formatter/grantleecontactformatter.cpp --- a/kaddressbookgrantlee/src/formatter/grantleecontactformatter.cpp +++ b/kaddressbookgrantlee/src/formatter/grantleecontactformatter.cpp @@ -27,7 +27,6 @@ #include "../contactobject/contactgrantleeimobject.h" #include "../contactobject/contactgrantleecryptoobject.h" #include "../contactobject/contactgrantleewebsite.h" -#include "../contactobject/contactgrantleeemail.h" #include #include diff --git a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h --- a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h +++ b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h @@ -36,7 +36,6 @@ Q_PROPERTY(QString familyName READ familyName) Q_PROPERTY(QString suffix READ suffix) Q_PROPERTY(QString nickName READ nickName) - Q_PROPERTY(QStringList emails READ emails) Q_PROPERTY(QString organization READ organization) Q_PROPERTY(QString note READ note) Q_PROPERTY(QString webPage READ webPage) @@ -61,7 +60,7 @@ Q_PROPERTY(QString spouse READ spouse) Q_PROPERTY(QString languages READ languages) Q_PROPERTY(QVariant webSites READ webSites) - Q_PROPERTY(QVariant emailsList READ emailsList) + Q_PROPERTY(QVariantList emails READ emails) //Add more functions public: @@ -77,7 +76,7 @@ Q_REQUIRED_RESULT QString familyName() const; Q_REQUIRED_RESULT QString suffix() const; Q_REQUIRED_RESULT QString nickName() const; - Q_REQUIRED_RESULT QStringList emails() const; + Q_REQUIRED_RESULT QVariantList emails() const; Q_REQUIRED_RESULT QString organization() const; Q_REQUIRED_RESULT QString note() const; //webPage deprecated. @@ -104,14 +103,12 @@ Q_REQUIRED_RESULT QString spouse() const; Q_REQUIRED_RESULT QString languages() const; Q_REQUIRED_RESULT QVariant webSites() const; - Q_REQUIRED_RESULT QVariant emailsList() const; private: QString imgToDataUrl(const QImage &image) const; QList mListAddress; QList mListPhones; QList mListIm; QList mListWebSite; - QList mListEmails; ContactGrantleeCryptoObject *mCryptoObject = nullptr; KContacts::Addressee mAddress; }; diff --git a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp --- a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp +++ b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp @@ -23,14 +23,14 @@ #include "../contactobject/contactgrantleeimobject.h" #include "../contactobject/contactgrantleecryptoobject.h" #include "../contactobject/contactgrantleewebsite.h" -#include "../contactobject/contactgrantleeemail.h" #include #include #include #include #include +#include #include using namespace KAddressBookGrantlee; @@ -57,12 +57,6 @@ mListPhones << new ContactGrantleePhoneObject(phone); } - const auto emails = address.emailList(); - mListEmails.reserve(emails.size()); - for (const KContacts::Email &email : emails) { - mListEmails << new ContactGrantleeEmail(mAddress, email); - } - const QStringList customs = mAddress.customs(); for (const QString &custom : customs) { if (custom.startsWith(QLatin1String("messaging/"))) { @@ -82,7 +76,6 @@ qDeleteAll(mListPhones); qDeleteAll(mListIm); qDeleteAll(mListWebSite); - qDeleteAll(mListEmails); delete mCryptoObject; } @@ -146,18 +139,13 @@ return result; } -QStringList ContactGrantleePrintObject::emails() const +QVariantList ContactGrantleePrintObject::emails() const { - QStringList emails; - const QStringList lstEmails(mAddress.emails()); - for (const QString &email : lstEmails) { - const QString fullEmail = QString::fromLatin1(QUrl::toPercentEncoding(mAddress.fullEmail(email))); - - const QString url = QStringLiteral("%2") - .arg(fullEmail, email); - emails << url; - } - return emails; + // ### temporary hack until this becomes a KContact::Addressee gadget itself and we can remove this + const auto idx = KContacts::Addressee::staticMetaObject.indexOfProperty("emails"); + Q_ASSERT(idx >= 0); + const auto prop = KContacts::Addressee::staticMetaObject.property(idx); + return prop.readOnGadget(&mAddress).toList(); } QString ContactGrantleePrintObject::organization() const @@ -215,11 +203,6 @@ return QVariant::fromValue(mListWebSite); } -QVariant ContactGrantleePrintObject::emailsList() const -{ - return QVariant::fromValue(mListEmails); -} - QVariant ContactGrantleePrintObject::phones() const { return QVariant::fromValue(mListPhones); diff --git a/kaddressbookgrantlee/src/printing/grantleeprint.cpp b/kaddressbookgrantlee/src/printing/grantleeprint.cpp --- a/kaddressbookgrantlee/src/printing/grantleeprint.cpp +++ b/kaddressbookgrantlee/src/printing/grantleeprint.cpp @@ -39,6 +39,7 @@ return mp.readOnGadget(&object); \ GRANTLEE_END_LOOKUP +GRANTLEE_MAKE_GADGET(KContacts::Email) GRANTLEE_MAKE_GADGET(KContacts::Geo) using namespace KAddressBookGrantlee; @@ -61,6 +62,7 @@ void GrantleePrint::init() { + Grantlee::registerMetaType(); Grantlee::registerMetaType(); }