diff --git a/kaddressbookgrantlee/src/CMakeLists.txt b/kaddressbookgrantlee/src/CMakeLists.txt --- a/kaddressbookgrantlee/src/CMakeLists.txt +++ b/kaddressbookgrantlee/src/CMakeLists.txt @@ -11,7 +11,6 @@ contactobject/contactgrantleeaddressobject.cpp contactobject/contactgrantleecryptoobject.cpp contactobject/contactgrantleeimobject.cpp - contactobject/contactgrantleephoneobject.cpp contactobject/contactgrantleewebsite.cpp ) diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.h b/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.h deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2013-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_CONTACTGRANTLEEPHONEOBJECT_H -#define PRINT_CONTACTGRANTLEEPHONEOBJECT_H -#include -#include -namespace KAddressBookGrantlee { -class ContactGrantleePhoneObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString type READ type) - Q_PROPERTY(QString number READ number) - Q_PROPERTY(bool preferred READ preferred) - -public: - explicit ContactGrantleePhoneObject(const KContacts::PhoneNumber &phone, QObject *parent = nullptr); - ~ContactGrantleePhoneObject(); - - Q_REQUIRED_RESULT QString type() const; - Q_REQUIRED_RESULT QString number() const; - Q_REQUIRED_RESULT bool preferred() const; -private: - KContacts::PhoneNumber mPhoneNumber; -}; -} - -#endif // PRINT_CONTACTGRANTLEEPHONEOBJECT_H diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.cpp b/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.cpp deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleephoneobject.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (C) 2013-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 "contactgrantleephoneobject.h" - -using namespace KAddressBookGrantlee; -ContactGrantleePhoneObject::ContactGrantleePhoneObject(const KContacts::PhoneNumber &phone, QObject *parent) - : QObject(parent) - , mPhoneNumber(phone) -{ -} - -ContactGrantleePhoneObject::~ContactGrantleePhoneObject() -{ -} - -QString ContactGrantleePhoneObject::type() const -{ - return mPhoneNumber.typeLabel(); -} - -QString ContactGrantleePhoneObject::number() const -{ - return mPhoneNumber.number(); -} - -bool ContactGrantleePhoneObject::preferred() const -{ - return mPhoneNumber.type() & KContacts::PhoneNumber::Pref; -} 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 @@ -23,7 +23,6 @@ #include "grantleetheme/grantleetheme.h" #include "grantleecontactutils.h" #include "../contactobject/contactgrantleeaddressobject.h" -#include "../contactobject/contactgrantleephoneobject.h" #include "../contactobject/contactgrantleeimobject.h" #include "../contactobject/contactgrantleecryptoobject.h" #include "../contactobject/contactgrantleewebsite.h" @@ -63,6 +62,7 @@ GRANTLEE_END_LOOKUP GRANTLEE_MAKE_GADGET(KContacts::Email) +GRANTLEE_MAKE_GADGET(KContacts::PhoneNumber) class Q_DECL_HIDDEN GrantleeContactFormatter::Private { @@ -116,6 +116,7 @@ : d(new Private) { Grantlee::registerMetaType(); + Grantlee::registerMetaType(); } GrantleeContactFormatter::~GrantleeContactFormatter() @@ -157,30 +158,6 @@ } } -static QVariantHash phoneNumberHash(const KContacts::PhoneNumber &phoneNumber, int counter) -{ - QVariantHash numberObject; - - setHashField(numberObject, QStringLiteral("type"), phoneNumber.typeLabel()); - setHashField(numberObject, QStringLiteral("number"), phoneNumber.number()); - - if (!phoneNumber.isEmpty()) { - const QString url - = QStringLiteral("%2"). - arg(counter). - arg(phoneNumber.number()); - numberObject.insert(QStringLiteral("numberLink"), url); - - if (phoneNumber.type() & KContacts::PhoneNumber::Cell) { - const QString url - = QStringLiteral("").arg(counter); - numberObject.insert(QStringLiteral("smsLink"), url); - } - } - - return numberObject; -} - static QVariantHash imAddressHash(const QString &typeKey, const QString &imAddress) { QVariantHash addressObject; @@ -315,16 +292,7 @@ contactObject.insert(QStringLiteral("emails"), QVariant::fromValue(rawContact.emailList())); // Phone numbers - QVariantList phoneNumbers; - int counter = 0; - const KContacts::PhoneNumber::List lstPhone = rawContact.phoneNumbers(); - phoneNumbers.reserve(lstPhone.count()); - for (const KContacts::PhoneNumber &phoneNumber : lstPhone) { - phoneNumbers.append(phoneNumberHash(phoneNumber, counter)); - counter++; - } - - contactObject.insert(QStringLiteral("phoneNumbers"), phoneNumbers); + contactObject.insert(QStringLiteral("phoneNumbers"), QVariant::fromValue(rawContact.phoneNumbers())); // IM QVariantList imAddresses; @@ -376,7 +344,7 @@ // Addresses QVariantList addresses; - counter = 0; + int counter = 0; const KContacts::Address::List lstAddresses = rawContact.addresses(); addresses.reserve(lstAddresses.count()); for (const KContacts::Address &address : lstAddresses) { 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 @@ -46,7 +46,7 @@ Q_PROPERTY(QString birthday READ birthday) Q_PROPERTY(QString department READ department) Q_PROPERTY(QVariant addresses READ addresses) - Q_PROPERTY(QVariant phones READ phones) + Q_PROPERTY(QVector phones READ phones) Q_PROPERTY(QVariant instantManging READ instantManging) Q_PROPERTY(QString addressBookName READ addressBookName) Q_PROPERTY(QString photo READ photo) @@ -88,7 +88,7 @@ Q_REQUIRED_RESULT QString birthday() const; Q_REQUIRED_RESULT QString department() const; Q_REQUIRED_RESULT QVariant addresses() const; - Q_REQUIRED_RESULT QVariant phones() const; + Q_REQUIRED_RESULT QVector phones() const; Q_REQUIRED_RESULT QString addressBookName() const; Q_REQUIRED_RESULT QVariant instantManging() const; Q_REQUIRED_RESULT QVariant geo() const; @@ -106,7 +106,6 @@ private: QString imgToDataUrl(const QImage &image) const; QList mListAddress; - QList mListPhones; QList mListIm; QList mListWebSite; ContactGrantleeCryptoObject *mCryptoObject = nullptr; 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 @@ -19,7 +19,6 @@ #include "contactgrantleeprintobject.h" #include "../contactobject/contactgrantleeaddressobject.h" -#include "../contactobject/contactgrantleephoneobject.h" #include "../contactobject/contactgrantleeimobject.h" #include "../contactobject/contactgrantleecryptoobject.h" #include "../contactobject/contactgrantleewebsite.h" @@ -51,12 +50,6 @@ mListWebSite << new ContactGrantleeWebSite(webSite); } - const auto phoneNumbers = address.phoneNumbers(); - mListPhones.reserve(phoneNumbers.size()); - for (const KContacts::PhoneNumber &phone : phoneNumbers) { - mListPhones << new ContactGrantleePhoneObject(phone); - } - const QStringList customs = mAddress.customs(); for (const QString &custom : customs) { if (custom.startsWith(QLatin1String("messaging/"))) { @@ -73,7 +66,6 @@ ContactGrantleePrintObject::~ContactGrantleePrintObject() { qDeleteAll(mListAddress); - qDeleteAll(mListPhones); qDeleteAll(mListIm); qDeleteAll(mListWebSite); delete mCryptoObject; @@ -203,9 +195,9 @@ return QVariant::fromValue(mListWebSite); } -QVariant ContactGrantleePrintObject::phones() const +QVector ContactGrantleePrintObject::phones() const { - return QVariant::fromValue(mListPhones); + return mAddress.phoneNumbers(); } QVariant ContactGrantleePrintObject::instantManging() const 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 @@ -41,6 +41,7 @@ GRANTLEE_MAKE_GADGET(KContacts::Email) GRANTLEE_MAKE_GADGET(KContacts::Geo) +GRANTLEE_MAKE_GADGET(KContacts::PhoneNumber) using namespace KAddressBookGrantlee; @@ -64,6 +65,7 @@ { Grantlee::registerMetaType(); Grantlee::registerMetaType(); + Grantlee::registerMetaType(); } QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts)