diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -set(PIM_VERSION "5.11.43") +set(PIM_VERSION "5.11.44") project(kdepim-apps-lib VERSION ${PIM_VERSION}) set(KF5_MIN_VERSION "5.57.0") diff --git a/kaddressbookgrantlee/src/CMakeLists.txt b/kaddressbookgrantlee/src/CMakeLists.txt --- a/kaddressbookgrantlee/src/CMakeLists.txt +++ b/kaddressbookgrantlee/src/CMakeLists.txt @@ -5,21 +5,11 @@ formatter/grantleecontactformatter.cpp formatter/grantleecontactgroupformatter.cpp formatter/grantleecontactutils.cpp + contactobject/contactgrantleewrapper.cpp + printing/grantleeprint.cpp ) -set(kaddressbook_grantlee_object_LIB_SRCS - contactobject/contactgrantleecryptoobject.cpp - contactobject/contactgrantleeimobject.cpp - contactobject/contactgrantleewrapper.cpp -) - -set(kaddressbook_grantlee_printing_LIB_SRCS - printing/contactgrantleeprintobject.cpp - printing/grantleeprint.cpp -) - - -add_library(KF5KaddressbookGrantlee ${kaddressbook_grantlee_LIB_SRCS} ${kaddressbook_grantlee_printing_LIB_SRCS} ${kaddressbook_grantlee_object_LIB_SRCS}) +add_library(KF5KaddressbookGrantlee ${kaddressbook_grantlee_LIB_SRCS}) generate_export_header(KF5KaddressbookGrantlee BASE_NAME kaddressbook_grantlee) add_library(KF5::KaddressbookGrantlee ALIAS KF5KaddressbookGrantlee) diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.h b/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.h deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (C) 2014-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_CONTACTGRANTLEECRYPTOOBJECT_H -#define PRINT_CONTACTGRANTLEECRYPTOOBJECT_H -#include -#include -namespace KAddressBookGrantlee { -class ContactGrantleeCryptoObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString signaturePreference READ signaturePreference) - Q_PROPERTY(QString cryptoPreference READ cryptoPreference) -public: - explicit ContactGrantleeCryptoObject(const KContacts::Addressee &address, QObject *parent = nullptr); - ~ContactGrantleeCryptoObject(); - - Q_REQUIRED_RESULT QString signaturePreference() const; - Q_REQUIRED_RESULT QString cryptoPreference() const; - -private: - KContacts::Addressee mAddress; -}; -} - -#endif // PRINT_CONTACTGRANTLEECRYPTOOBJECT_H diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.cpp b/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.cpp deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleecryptoobject.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (C) 2014-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 "contactgrantleecryptoobject.h" -#include "Libkleo/Enum" - -using namespace KAddressBookGrantlee; -inline QString loadCustom(const KContacts::Addressee &contact, const QString &key) -{ - return contact.custom(QStringLiteral("KADDRESSBOOK"), key); -} - -ContactGrantleeCryptoObject::ContactGrantleeCryptoObject(const KContacts::Addressee &address, QObject *parent) - : QObject(parent) - , mAddress(address) -{ -} - -ContactGrantleeCryptoObject::~ContactGrantleeCryptoObject() -{ -} - -QString ContactGrantleeCryptoObject::signaturePreference() const -{ - return Kleo::signingPreferenceToLabel(Kleo::stringToSigningPreference(loadCustom(mAddress, QStringLiteral("CRYPTOSIGNPREF")))); -} - -QString ContactGrantleeCryptoObject::cryptoPreference() const -{ - return Kleo::encryptionPreferenceToLabel(Kleo::stringToEncryptionPreference(loadCustom(mAddress, QStringLiteral("CRYPTOENCRYPTPREF")))); -} diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.h b/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.h deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.h +++ /dev/null @@ -1,42 +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_CONTACTGRANTLEEIMOBJECT_H -#define PRINT_CONTACTGRANTLEEIMOBJECT_H -#include -namespace KAddressBookGrantlee { -class ContactGrantleeImObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString type READ type) - Q_PROPERTY(QString address READ address) - -public: - explicit ContactGrantleeImObject(const QString &type, const QString &address, QObject *parent = nullptr); - ~ContactGrantleeImObject(); - - Q_REQUIRED_RESULT QString type() const; - Q_REQUIRED_RESULT QString address() const; - -private: - QString mType; - QString mAddress; -}; -} -#endif // PRINT_CONTACTGRANTLEEIMOBJECT_H diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.cpp b/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.cpp deleted file mode 100644 --- a/kaddressbookgrantlee/src/contactobject/contactgrantleeimobject.cpp +++ /dev/null @@ -1,43 +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 "contactgrantleeimobject.h" -#include "contacteditor/improtocols.h" - -using namespace KAddressBookGrantlee; -ContactGrantleeImObject::ContactGrantleeImObject(const QString &type, const QString &address, QObject *parent) - : QObject(parent) - , mType(type) - , mAddress(address) -{ -} - -ContactGrantleeImObject::~ContactGrantleeImObject() -{ -} - -QString ContactGrantleeImObject::type() const -{ - return IMProtocols::self()->name(mType); -} - -QString ContactGrantleeImObject::address() const -{ - return mAddress; -} diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.h b/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.h --- a/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.h +++ b/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.h @@ -44,15 +44,26 @@ Q_PROPERTY(QString addressBookName READ addressBookName) Q_PROPERTY(int age READ age) + Q_PROPERTY(QString cryptoPreference READ cryptoPreference) + Q_PROPERTY(QString signaturePreference READ signaturePreference) + + // ### this shouldn't be returning assembled HTML, that's a job for Grantlee + Q_PROPERTY(QString photo READ photoImgElement) + Q_PROPERTY(QString logo READ logoImgElement) // ### those two would be unneccessary if we had a proper way for formatting dates in Grantlee Q_PROPERTY(QString formattedBirthday READ formattedBirthday) Q_PROPERTY(QString formattedAnniversary READ formattedAnniversary) // ### this is temporary, until KContacts::Impp takes over this part Q_PROPERTY(QVariantList imAddresses READ imAddresses) +public: + ContactGrantleeWrapper(); + ContactGrantleeWrapper(const KContacts::Addressee &addr); + private: + QString addressBookLabel() const; QString anniversaryLabel() const; QString assistantLabel() const; @@ -63,6 +74,11 @@ QString addressBookName() const; int age() const; + QString cryptoPreference() const; + QString signaturePreference() const; + + QString photoImgElement() const; + QString logoImgElement() const; QString formattedBirthday() const; QString formattedAnniversary() const; diff --git a/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.cpp b/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.cpp --- a/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.cpp +++ b/kaddressbookgrantlee/src/contactobject/contactgrantleewrapper.cpp @@ -21,14 +21,25 @@ #include +#include + #include +#include +#include #include using namespace KAddressBookGrantlee; static_assert(sizeof(KContacts::Addressee) == sizeof(KAddressBookGrantlee::ContactGrantleeWrapper), "Grantlee wrapper must not have member variables to prevent sliciing issues"); +ContactGrantleeWrapper::ContactGrantleeWrapper() = default; + +ContactGrantleeWrapper::ContactGrantleeWrapper(const KContacts::Addressee& addr) + : KContacts::Addressee(addr) +{ +} + QString ContactGrantleeWrapper::addressBookLabel() const { return i18n("Address Book"); @@ -79,6 +90,41 @@ return age; } +QString ContactGrantleeWrapper::cryptoPreference() const +{ + return Kleo::encryptionPreferenceToLabel(Kleo::stringToEncryptionPreference(custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("CRYPTOENCRYPTPREF")))); +} + +QString ContactGrantleeWrapper::signaturePreference() const +{ + return Kleo::signingPreferenceToLabel(Kleo::stringToSigningPreference(custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("CRYPTOSIGNPREF")))); +} + +static QString imgToDataUrl(const QImage &image) +{ + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + image.save(&buffer, "PNG"); + return QStringLiteral("data:image/%1;base64,%2").arg(QStringLiteral("PNG"), QString::fromLatin1(ba.toBase64())); +} + +QString ContactGrantleeWrapper::logoImgElement() const +{ + if (logo().isEmpty()) { + return {}; + } + return QStringLiteral("  ").arg(imgToDataUrl(logo().data()), QString::number(60), QString::number(60)); +} + +QString ContactGrantleeWrapper::photoImgElement() const +{ + if (photo().isEmpty()) { + return {}; + } + return QStringLiteral("  ").arg(imgToDataUrl(photo().data()), QString::number(60), QString::number(60)); +} + QString ContactGrantleeWrapper::formattedBirthday() const { return QLocale().toString(birthday().date()); 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 @@ -21,7 +21,6 @@ #include "grantleecontactformatter.h" #include "grantleetheme/grantleetheme.h" -#include "grantleecontactutils.h" #include "../contactobject/contactgrantleewrapper.h" #include @@ -272,7 +271,7 @@ KColorScheme(QPalette::Active, KColorScheme::View).background().color().name()); QVariantHash mapping; - mapping.insert(QStringLiteral("contact"), QVariant::fromValue(*reinterpret_cast(&rawContact))); + mapping.insert(QStringLiteral("contact"), QVariant::fromValue(ContactGrantleeWrapper(rawContact))); mapping.insert(QStringLiteral("colors"), colorsObject); mapping.insert(QStringLiteral("customFields"), customFields); mapping.insert(QStringLiteral("customFieldsUrl"), customFieldsUrl); diff --git a/kaddressbookgrantlee/src/printing/autotests/grantleeprinttest.cpp b/kaddressbookgrantlee/src/printing/autotests/grantleeprinttest.cpp --- a/kaddressbookgrantlee/src/printing/autotests/grantleeprinttest.cpp +++ b/kaddressbookgrantlee/src/printing/autotests/grantleeprinttest.cpp @@ -94,7 +94,6 @@ QTest::addColumn("result"); QTest::newRow("name") << QStringLiteral("name") << QStringLiteral("foo1"); QTest::newRow("organization") << QStringLiteral("organization") << QStringLiteral("kde"); - QTest::newRow("languages") << QStringLiteral("languages") << QStringLiteral("fr"); QTest::newRow("note") << QStringLiteral("note") << QStringLiteral("foo-note"); QTest::newRow("title") << QStringLiteral("title") << QStringLiteral("foo-title"); QTest::newRow("nickName") << QStringLiteral("nickName") << QStringLiteral("foo-nickname"); @@ -105,9 +104,9 @@ QTest::newRow("department") << QStringLiteral("department") << QStringLiteral("foo-department"); QTest::newRow("office") << QStringLiteral("office") << QStringLiteral("foo-office"); QTest::newRow("profesion") << QStringLiteral("profession") << QStringLiteral("foo-profession"); - QTest::newRow("manager") << QStringLiteral("manager") << QStringLiteral("foo-managersname"); - QTest::newRow("assistant") << QStringLiteral("assistant") << QStringLiteral("foo-assistantsname"); - QTest::newRow("spouse") << QStringLiteral("spouse") << QStringLiteral("foo-spousesname"); + QTest::newRow("manager") << QStringLiteral("managersName") << QStringLiteral("foo-managersname"); + QTest::newRow("assistant") << QStringLiteral("assistantsName") << QStringLiteral("foo-assistantsname"); + QTest::newRow("spouse") << QStringLiteral("spousesName") << QStringLiteral("foo-spousesname"); QTest::newRow("givenname") << QStringLiteral("givenName") << QStringLiteral("foo-givenname"); QTest::newRow("additionalname") << QStringLiteral("additionalName") << QStringLiteral("foo-additionalname"); } diff --git a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h deleted file mode 100644 --- a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.h +++ /dev/null @@ -1,111 +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 CONTACTGRANTLEEPRINTOBJECT_H -#define CONTACTGRANTLEEPRINTOBJECT_H -#include -#include -#include -namespace KAddressBookGrantlee { -class ContactGrantleeCryptoObject; -class ContactGrantleePrintObject : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString name READ name) - Q_PROPERTY(QString realName READ realName) - Q_PROPERTY(QString formattedName READ formattedName) - Q_PROPERTY(QString prefix READ prefix) - Q_PROPERTY(QString givenName READ givenName) - Q_PROPERTY(QString additionalName READ additionalName) - Q_PROPERTY(QString familyName READ familyName) - Q_PROPERTY(QString suffix READ suffix) - Q_PROPERTY(QString nickName READ nickName) - Q_PROPERTY(QString organization READ organization) - Q_PROPERTY(QString note READ note) - Q_PROPERTY(KContacts::ResourceLocatorUrl url READ url) - Q_PROPERTY(QString title READ title) - Q_PROPERTY(QString preferredEmail READ preferredEmail) - Q_PROPERTY(QString role READ role) - Q_PROPERTY(QString birthday READ birthday) - Q_PROPERTY(QString department READ department) - Q_PROPERTY(QVector addresses READ addresses) - Q_PROPERTY(QVector phones READ phones) - Q_PROPERTY(QVariant instantManging READ instantManging) - Q_PROPERTY(QString addressBookName READ addressBookName) - Q_PROPERTY(QString photo READ photo) - Q_PROPERTY(QString logo READ logo) - Q_PROPERTY(QVariant crypto READ crypto) - Q_PROPERTY(QString anniversary READ anniversary) - Q_PROPERTY(QString profession READ profession) - Q_PROPERTY(QString office READ office) - Q_PROPERTY(QString manager READ manager) - Q_PROPERTY(QString assistant READ assistant) - Q_PROPERTY(QString spouse READ spouse) - Q_PROPERTY(QString languages READ languages) - Q_PROPERTY(QVector urls READ urls) - Q_PROPERTY(QVariantList emails READ emails) - - //Add more functions -public: - explicit ContactGrantleePrintObject(const KContacts::Addressee &address, QObject *parent = nullptr); - ~ContactGrantleePrintObject(); - - Q_REQUIRED_RESULT QString name() const; - Q_REQUIRED_RESULT QString realName() const; - Q_REQUIRED_RESULT QString formattedName() const; - Q_REQUIRED_RESULT QString prefix() const; - Q_REQUIRED_RESULT QString givenName() const; - Q_REQUIRED_RESULT QString additionalName() const; - Q_REQUIRED_RESULT QString familyName() const; - Q_REQUIRED_RESULT QString suffix() const; - Q_REQUIRED_RESULT QString nickName() const; - Q_REQUIRED_RESULT QVariantList emails() const; - Q_REQUIRED_RESULT QString organization() const; - Q_REQUIRED_RESULT QString note() const; - Q_REQUIRED_RESULT KContacts::ResourceLocatorUrl url() const; - Q_REQUIRED_RESULT QString title() const; - Q_REQUIRED_RESULT QString preferredEmail() const; - Q_REQUIRED_RESULT QString role() const; - Q_REQUIRED_RESULT QString birthday() const; - Q_REQUIRED_RESULT QString department() const; - Q_REQUIRED_RESULT QVector addresses() 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; - Q_REQUIRED_RESULT QString photo() const; - Q_REQUIRED_RESULT QString logo() const; - Q_REQUIRED_RESULT QVariant crypto() const; - Q_REQUIRED_RESULT QString anniversary() const; - Q_REQUIRED_RESULT QString profession() const; - Q_REQUIRED_RESULT QString office() const; - Q_REQUIRED_RESULT QString manager() const; - Q_REQUIRED_RESULT QString assistant() const; - Q_REQUIRED_RESULT QString spouse() const; - Q_REQUIRED_RESULT QString languages() const; - Q_REQUIRED_RESULT QVector urls() const; -private: - QString imgToDataUrl(const QImage &image) const; - QList mListIm; - ContactGrantleeCryptoObject *mCryptoObject = nullptr; - KContacts::Addressee mAddress; -}; -} -Q_DECLARE_METATYPE(QList) -#endif // CONTACTGRANTLEEPRINTOBJECT_H diff --git a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp b/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp deleted file mode 100644 --- a/kaddressbookgrantlee/src/printing/contactgrantleeprintobject.cpp +++ /dev/null @@ -1,272 +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 "contactgrantleeprintobject.h" -#include "../contactobject/contactgrantleeimobject.h" -#include "../contactobject/contactgrantleecryptoobject.h" - -#include - -#include -#include -#include -#include -#include -#include - -using namespace KAddressBookGrantlee; - -ContactGrantleePrintObject::ContactGrantleePrintObject(const KContacts::Addressee &address, QObject *parent) - : QObject(parent) - , mAddress(address) -{ - const QStringList customs = mAddress.customs(); - for (const QString &custom : customs) { - if (custom.startsWith(QLatin1String("messaging/"))) { - const int pos = custom.indexOf(QLatin1Char(':')); - QString key = custom.left(pos); - key.remove(QStringLiteral("-All")); - const QString value = custom.mid(pos + 1); - mListIm << new ContactGrantleeImObject(key, value); - } - } - mCryptoObject = new ContactGrantleeCryptoObject(address); -} - -ContactGrantleePrintObject::~ContactGrantleePrintObject() -{ - qDeleteAll(mListIm); - delete mCryptoObject; -} - -QString ContactGrantleePrintObject::realName() const -{ - return mAddress.realName(); -} - -QString ContactGrantleePrintObject::formattedName() const -{ - return mAddress.formattedName(); -} - -QString ContactGrantleePrintObject::prefix() const -{ - return mAddress.prefix(); -} - -QString ContactGrantleePrintObject::givenName() const -{ - return mAddress.givenName(); -} - -QString ContactGrantleePrintObject::additionalName() const -{ - return mAddress.additionalName(); -} - -QString ContactGrantleePrintObject::familyName() const -{ - return mAddress.familyName(); -} - -QString ContactGrantleePrintObject::suffix() const -{ - return mAddress.suffix(); -} - -QString ContactGrantleePrintObject::nickName() const -{ - return mAddress.nickName(); -} - -QString ContactGrantleePrintObject::name() const -{ - return mAddress.name(); -} - -QString ContactGrantleePrintObject::languages() const -{ - QString result; - QStringList langList; - const KContacts::Lang::List lstLangs = mAddress.langs(); - langList.reserve(lstLangs.count()); - for (const KContacts::Lang &lang : lstLangs) { - langList.append(lang.language()); - } - if (!langList.isEmpty()) { - result = langList.join(QLatin1Char(',')); - } - return result; -} - -QVariantList ContactGrantleePrintObject::emails() const -{ - // ### 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 -{ - return mAddress.organization(); -} - -QString ContactGrantleePrintObject::note() const -{ - return mAddress.note().replace(QLatin1Char('\n'), QStringLiteral("
")); -} - -KContacts::ResourceLocatorUrl ContactGrantleePrintObject::url() const -{ - return mAddress.url(); -} - -QString ContactGrantleePrintObject::title() const -{ - return mAddress.title(); -} - -QString ContactGrantleePrintObject::preferredEmail() const -{ - return mAddress.preferredEmail(); -} - -QString ContactGrantleePrintObject::role() const -{ - return mAddress.role(); -} - -QString ContactGrantleePrintObject::birthday() const -{ - return QLocale().toString(mAddress.birthday().date(), QLocale::LongFormat); -} - -QString ContactGrantleePrintObject::department() const -{ - return mAddress.department(); -} - -QVector ContactGrantleePrintObject::addresses() const -{ - return mAddress.addresses(); -} - -QVector ContactGrantleePrintObject::urls() const -{ - return mAddress.extraUrlList(); -} - -QVector ContactGrantleePrintObject::phones() const -{ - return mAddress.phoneNumbers(); -} - -QVariant ContactGrantleePrintObject::instantManging() const -{ - return QVariant::fromValue(mListIm); -} - -QVariant ContactGrantleePrintObject::geo() const -{ - return QVariant::fromValue(mAddress.geo()); -} - -QVariant ContactGrantleePrintObject::crypto() const -{ - return QVariant::fromValue(mCryptoObject); -} - -QString ContactGrantleePrintObject::addressBookName() const -{ - const QString addressBookName = mAddress.custom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("AddressBook")); - return addressBookName; -} - -QString ContactGrantleePrintObject::photo() const -{ - if (mAddress.photo().isEmpty()) { - return QString(); - } else { - const QString photoStr = QStringLiteral("  ") - .arg(imgToDataUrl(mAddress.photo().data()), QString::number(60), QString::number(60)); - return photoStr; - } -} - -QString ContactGrantleePrintObject::imgToDataUrl(const QImage &image) const -{ - QByteArray ba; - QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - image.save(&buffer, "PNG"); - return QStringLiteral("data:image/%1;base64,%2").arg(QStringLiteral("PNG"), QString::fromLatin1(ba.toBase64())); -} - -QString ContactGrantleePrintObject::logo() const -{ - if (mAddress.logo().isEmpty()) { - return QString(); - } else { - const QString photoStr = QStringLiteral("  ") - .arg(imgToDataUrl(mAddress.logo().data()), QString::number(60), QString::number(60)); - return photoStr; - } -} - -QString ContactGrantleePrintObject::anniversary() const -{ - const QDate anniversary = QDate::fromString(mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-Anniversary")), Qt::ISODate); - if (anniversary.isValid()) { - return QLocale().toString(anniversary); - } - return QString(); -} - -QString ContactGrantleePrintObject::profession() const -{ - return mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-Profession")); -} - -QString ContactGrantleePrintObject::office() const -{ - return mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-Office")); -} - -QString ContactGrantleePrintObject::manager() const -{ - return mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-ManagersName")); -} - -QString ContactGrantleePrintObject::assistant() const -{ - return mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-AssistantsName")); -} - -QString ContactGrantleePrintObject::spouse() const -{ - return mAddress.custom(QStringLiteral("KADDRESSBOOK"), - QStringLiteral("X-SpousesName")); -} 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 @@ -18,8 +18,7 @@ */ #include "grantleeprint.h" -#include "contactgrantleeprintobject.h" - +#include "contactobject/contactgrantleewrapper.h" #include "formatter/grantleecontactutils.h" #include @@ -44,6 +43,7 @@ GRANTLEE_MAKE_GADGET(KContacts::Geo) GRANTLEE_MAKE_GADGET(KContacts::PhoneNumber) GRANTLEE_MAKE_GADGET(KContacts::ResourceLocatorUrl) +GRANTLEE_MAKE_GADGET(KAddressBookGrantlee::ContactGrantleeWrapper) GRANTLEE_BEGIN_LOOKUP(QUrl) if (property == QLatin1String("scheme")) { @@ -77,6 +77,7 @@ Grantlee::registerMetaType(); Grantlee::registerMetaType(); Grantlee::registerMetaType(); + Grantlee::registerMetaType(); } QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts) @@ -89,14 +90,9 @@ return QString(); } QVariantList contactsList; - QList lst; - const int numberContacts(contacts.count()); - lst.reserve(numberContacts); - contactsList.reserve(numberContacts); - for (const KContacts::Addressee &address : contacts) { - ContactGrantleePrintObject *contactPrintObject = new ContactGrantleePrintObject(address); - lst.append(contactPrintObject); - contactsList << QVariant::fromValue(static_cast(contactPrintObject)); + contactsList.reserve(contacts.count()); + for (const KContacts::Addressee &contact : contacts) { + contactsList.push_back(QVariant::fromValue(ContactGrantleeWrapper(contact))); } QVariantHash mapping; QVariantHash contactI18n; @@ -123,7 +119,5 @@ mapping.insert(QStringLiteral("contacti18n"), contactI18n); mapping.insert(QStringLiteral("contacts"), contactsList); - const QString content = render(mapping); - qDeleteAll(lst); - return content; + return render(mapping); }