Commit 9557449a authored by Volker Krause's avatar Volker Krause
Browse files

Use GrantleeTheme::GenericFormatter

Summary:
This enables the use of i18n commands in addressbook printing templates,
and thus eventually allows the removal of the property hacks in here for
this.

Reviewers: dvratil

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D20989
parent 69c11af3
cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.11.44")
set(PIM_VERSION "5.11.45")
project(kdepim-apps-lib VERSION ${PIM_VERSION})
set(KF5_MIN_VERSION "5.57.0")
......@@ -30,7 +30,7 @@ set(KDEPIM_APPS_LIB_VERSION ${PIM_VERSION})
set(QT_REQUIRED_VERSION "5.10.0")
set(AKONADI_VERSION "5.11.40")
set(GRANTLEETHEME_LIB_VERSION "5.11.40")
set(GRANTLEETHEME_LIB_VERSION "5.11.41")
set(KCONTACTS_LIB_VERSION "5.11.43")
set(AKONADICONTACT_LIB_VERSION "5.11.40")
set(LIBKLEO_LIB_VERSION "5.11.40")
......
......@@ -20,11 +20,11 @@ target_include_directories(KF5KaddressbookGrantlee PUBLIC "$<BUILD_INTERFACE:${G
target_link_libraries(KF5KaddressbookGrantlee
PUBLIC
Grantlee5::Templates
KF5::GrantleeTheme
PRIVATE
Grantlee5::Templates
KF5::ConfigWidgets
KF5::Service
KF5::GrantleeTheme
KF5::AkonadiCore
KF5::ContactEditor
KF5::Contacts
......@@ -32,7 +32,6 @@ PRIVATE
KF5::IconThemes
KF5::Libkleo
KF5::I18n
KF5::PimCommon
)
set_target_properties(KF5KaddressbookGrantlee PROPERTIES
......
......@@ -160,3 +160,5 @@ QVariantList ContactGrantleeWrapper::imAddresses() const
return imAddrs;
}
#include "moc_contactgrantleewrapper.cpp"
ecm_add_test(grantleeprinttest.cpp
NAME_PREFIX "kaddressbookgrantlee-printing-"
LINK_LIBRARIES KF5::KaddressbookGrantlee Qt5::Test KF5::Contacts KF5::PimCommon
LINK_LIBRARIES KF5::KaddressbookGrantlee Qt5::Test KF5::Contacts
)
......@@ -30,62 +30,45 @@ GrantleePrintTest::~GrantleePrintTest()
{
}
void GrantleePrintTest::shouldHaveDefaultValue()
{
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
QVERIFY(grantleePrint);
grantleePrint->deleteLater();
grantleePrint = nullptr;
}
void GrantleePrintTest::shouldReturnEmptyStringWhenNotContentAndNoContacts()
{
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
KAddressBookGrantlee::GrantleePrint grantleePrint;
KContacts::Addressee::List lst;
QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
grantleePrint->deleteLater();
grantleePrint = nullptr;
QVERIFY(grantleePrint.contactsToHtml(lst).isEmpty());
}
void GrantleePrintTest::shouldReturnEmptyStringWhenAddContentWithoutContacts()
{
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
grantleePrint->setContent(QStringLiteral("foo"));
KAddressBookGrantlee::GrantleePrint grantleePrint;
grantleePrint.setTemplateContent(QStringLiteral("foo"));
KContacts::Addressee::List lst;
QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
grantleePrint->deleteLater();
grantleePrint = nullptr;
QVERIFY(grantleePrint.contactsToHtml(lst).isEmpty());
}
void GrantleePrintTest::shouldReturnStringWhenAddContentAndContacts()
{
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
grantleePrint->setContent(QStringLiteral("foo"));
KAddressBookGrantlee::GrantleePrint grantleePrint;
grantleePrint.setTemplateContent(QStringLiteral("foo"));
KContacts::Addressee::List lst;
KContacts::Addressee address;
address.setName(QStringLiteral("foo1"));
address.insertEmail(QStringLiteral("foo@kde.org"), true);
lst << address;
QCOMPARE(grantleePrint->contactsToHtml(lst), QStringLiteral("foo"));
grantleePrint->deleteLater();
grantleePrint = nullptr;
QCOMPARE(grantleePrint.contactsToHtml(lst), QStringLiteral("foo"));
}
void GrantleePrintTest::shouldReturnEmails()
{
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
KAddressBookGrantlee::GrantleePrint grantleePrint;
KContacts::Addressee::List lst;
KContacts::Addressee address;
address.setName(QStringLiteral("foo1"));
address.insertEmail(QStringLiteral("foo@kde.org"), true);
lst << address;
grantleePrint->setContent(QStringLiteral("{% if contacts %}{% for contact in contacts %}{% if contact.name %}{{ contact.name }}{% endif %}{% endfor %}{% endif %}"));
grantleePrint.setTemplateContent(QStringLiteral("{% if contacts %}{% for contact in contacts %}{% if contact.name %}{{ contact.name }}{% endif %}{% endfor %}{% endif %}"));
QCOMPARE(grantleePrint->contactsToHtml(lst), QStringLiteral("foo1"));
grantleePrint->deleteLater();
grantleePrint = nullptr;
QCOMPARE(grantleePrint.contactsToHtml(lst), QStringLiteral("foo1"));
}
void GrantleePrintTest::shouldDisplayContactInfo_data()
......@@ -116,7 +99,7 @@ void GrantleePrintTest::shouldDisplayContactInfo()
QFETCH(QString, variable);
QFETCH(QString, result);
KAddressBookGrantlee::GrantleePrint *grantleePrint = new KAddressBookGrantlee::GrantleePrint;
KAddressBookGrantlee::GrantleePrint grantleePrint;
KContacts::Addressee::List lst;
KContacts::Addressee address;
address.setGivenName(QStringLiteral("foo-givenname"));
......@@ -141,11 +124,9 @@ void GrantleePrintTest::shouldDisplayContactInfo()
address.insertCustom(QStringLiteral("KADDRESSBOOK"), QStringLiteral("X-SpousesName"), QStringLiteral("foo-spousesname"));
lst << address;
grantleePrint->setContent(QStringLiteral("{% if contacts %}{% for contact in contacts %}{% if contact.%1 %}{{ contact.%1 }}{% endif %}{% endfor %}{% endif %}").arg(variable));
grantleePrint.setTemplateContent(QStringLiteral("{% if contacts %}{% for contact in contacts %}{% if contact.%1 %}{{ contact.%1 }}{% endif %}{% endfor %}{% endif %}").arg(variable));
QCOMPARE(grantleePrint->contactsToHtml(lst), result);
grantleePrint->deleteLater();
grantleePrint = nullptr;
QCOMPARE(grantleePrint.contactsToHtml(lst), result);
}
QTEST_MAIN(GrantleePrintTest)
......@@ -29,7 +29,6 @@ public:
explicit GrantleePrintTest(QObject *parent = nullptr);
~GrantleePrintTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldReturnEmptyStringWhenNotContentAndNoContacts();
void shouldReturnEmptyStringWhenAddContentWithoutContacts();
void shouldReturnStringWhenAddContentAndContacts();
......
......@@ -27,6 +27,7 @@
#include <grantlee/templateloader.h>
#include <QMetaProperty>
#include <QVariant>
// Grantlee has no Q_GADGET support yet
#define GRANTLEE_MAKE_GADGET(Class) \
......@@ -53,21 +54,18 @@ GRANTLEE_END_LOOKUP
using namespace KAddressBookGrantlee;
GrantleePrint::GrantleePrint(QObject *parent)
: PimCommon::GenericGrantleeFormatter(parent)
GrantleePrint::GrantleePrint()
{
init();
}
GrantleePrint::GrantleePrint(const QString &themePath, QObject *parent)
: PimCommon::GenericGrantleeFormatter(QStringLiteral("theme.html"), themePath, parent)
GrantleePrint::GrantleePrint(const QString &themePath)
: GrantleeTheme::GenericFormatter(QStringLiteral("theme.html"), themePath)
{
init();
}
GrantleePrint::~GrantleePrint()
{
}
GrantleePrint::~GrantleePrint() = default;
void GrantleePrint::init()
{
......
......@@ -21,17 +21,16 @@
#define GRANTLEEPRINT_H
#include "kaddressbook_grantlee_export.h"
#include <PimCommon/GenericGrantleeFormatter>
#include <QObject>
#include <GrantleeTheme/GenericFormatter>
#include <KContacts/Addressee>
namespace KAddressBookGrantlee {
class KADDRESSBOOK_GRANTLEE_EXPORT GrantleePrint : public PimCommon::GenericGrantleeFormatter
class KADDRESSBOOK_GRANTLEE_EXPORT GrantleePrint : public GrantleeTheme::GenericFormatter
{
Q_OBJECT
public:
explicit GrantleePrint(QObject *parent = nullptr);
explicit GrantleePrint(const QString &themePath, QObject *parent = nullptr);
GrantleePrint();
explicit GrantleePrint(const QString &themePath);
~GrantleePrint();
Q_REQUIRED_RESULT QString contactsToHtml(const KContacts::Addressee::List &contacts);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment