Commit 49966b8d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Prepare to port to KTextTemplate

parent 1eaecb2d
Pipeline #131482 passed with stage
in 1 minute and 15 seconds
......@@ -14,10 +14,15 @@
#include <GrantleeTheme/GrantleeKi18nLocalizer>
#include <GrantleeTheme/GrantleeTheme>
#include <GrantleeTheme/GrantleeThemeEngine>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <grantlee/context.h>
#include <grantlee/metatype.h>
#include <grantlee/templateloader.h>
#else
#include <KTextTemplate/context.h>
#include <KTextTemplate/metatype.h>
#include <KTextTemplate/templateloader.h>
#endif
#include <Akonadi/Item>
......@@ -33,13 +38,21 @@
using namespace KAddressBookGrantlee;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
GRANTLEE_BEGIN_LOOKUP(QUrl)
#else
KTEXTTEMPLATE_BEGIN_LOOKUP(QUrl)
#endif
if (property == QLatin1String("scheme")) {
return object.scheme();
} else if (property == QLatin1String("path")) {
return object.path();
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
GRANTLEE_END_LOOKUP
#else
KTEXTTEMPLATE_END_LOOKUP
#endif
class KAddressBookGrantlee::GrantleeContactFormatterPrivate
{
......@@ -49,10 +62,15 @@ public:
KConfig config(QStringLiteral("akonadi_contactrc"));
KConfigGroup group(&config, QStringLiteral("View"));
showQRCode = group.readEntry("QRCodes", true);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
mEngine = std::make_unique<GrantleeTheme::Engine>();
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader());
#else
mEngine = std::make_unique<KTextTemplate::Engine>();
mTemplateLoader = QSharedPointer<KTextTemplate::FileSystemTemplateLoader>(new KTextTemplate::FileSystemTemplateLoader());
#endif
}
~GrantleeContactFormatterPrivate()
......@@ -77,10 +95,17 @@ public:
}
QVector<QObject *> mObjects;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
std::unique_ptr<GrantleeTheme::Engine> mEngine;
QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
Grantlee::Template mSelfcontainedTemplate;
Grantlee::Template mEmbeddableTemplate;
#else
std::unique_ptr<KTextTemplate::Engine> mEngine;
QSharedPointer<KTextTemplate::FileSystemTemplateLoader> mTemplateLoader;
KTextTemplate::Template mSelfcontainedTemplate;
v::Template mEmbeddableTemplate;
#endif
QString mErrorMessage;
bool forceDisableQRCode = false;
bool showQRCode = true;
......@@ -89,7 +114,11 @@ public:
GrantleeContactFormatter::GrantleeContactFormatter()
: d(new GrantleeContactFormatterPrivate)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Grantlee::registerMetaType<QUrl>();
#else
KTextTemplate::registerMetaType<QUrl>();
#endif
}
GrantleeContactFormatter::~GrantleeContactFormatter() = default;
......@@ -228,8 +257,11 @@ QString GrantleeContactFormatter::toHtml(HtmlForm form) const
mapping.insert(QStringLiteral("customFields"), customFields);
mapping.insert(QStringLiteral("customFieldsUrl"), customFieldsUrl);
mapping.insert(QStringLiteral("hasqrcode"), !d->forceDisableQRCode && d->showQRCode);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Grantlee::Context context(mapping);
#else
KTextTemplate::Context context(mapping);
#endif
context.setLocalizer(d->mEngine->localizer());
if (form == SelfcontainedForm) {
......
......@@ -10,9 +10,15 @@
#include <GrantleeTheme/GrantleeTheme>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <grantlee/context.h>
#include <grantlee/engine.h>
#include <grantlee/templateloader.h>
#else
#include <KTextTemplate/context.h>
#include <KTextTemplate/engine.h>
#include <KTextTemplate/templateloader.h>
#endif
#include <Akonadi/Contact/ContactGroupExpandJob>
#include <Akonadi/Item>
......@@ -25,10 +31,17 @@ class KAddressBookGrantlee::GrantleeContactGroupFormatterPrivate
{
public:
GrantleeContactGroupFormatterPrivate()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
: mEngine(new Grantlee::Engine)
#else
: mEngine(new KTextTemplate::Engine)
#endif
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
#else
mTemplateLoader = QSharedPointer<KTextTemplate::FileSystemTemplateLoader>(new KTextTemplate::FileSystemTemplateLoader);
#endif
}
~GrantleeContactGroupFormatterPrivate()
......@@ -54,10 +67,17 @@ public:
}
QVector<QObject *> mObjects;
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Grantlee::Engine *const mEngine;
QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
Grantlee::Template mSelfcontainedTemplate;
Grantlee::Template mEmbeddableTemplate;
#else
KTextTemplate::Engine *const mEngine;
QSharedPointer<KTextTemplate::FileSystemTemplateLoader> mTemplateLoader;
KTextTemplate::Template mSelfcontainedTemplate;
KTextTemplate::Template mEmbeddableTemplate;
#endif
QString mErrorMessage;
};
......@@ -176,8 +196,11 @@ QString GrantleeContactGroupFormatter::toHtml(HtmlForm form) const
QVariantHash mapping;
mapping.insert(QStringLiteral("contactGroup"), contactGroupObject);
mapping.insert(QStringLiteral("colors"), colorsObject);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Grantlee::Context context(mapping);
#else
KTextTemplate::Context context(mapping);
#endif
if (form == SelfcontainedForm) {
return d->mSelfcontainedTemplate->render(&context);
......
......@@ -7,19 +7,34 @@
#include "grantleeprint.h"
#include "contactgrantleewrapper.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <grantlee/context.h>
#include <grantlee/engine.h>
#include <grantlee/metatype.h>
#include <grantlee/templateloader.h>
#else
#include <KTextTemplate/context.h>
#include <KTextTemplate/engine.h>
#include <KTextTemplate/metatype.h>
#include <KTextTemplate/templateloader.h>
#endif
#include <QMetaProperty>
#include <QVariant>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
GRANTLEE_BEGIN_LOOKUP(QUrl)
#else
KTEXTTEMPLATE_BEGIN_LOOKUP(QUrl)
#endif
if (property == QLatin1String("scheme")) {
return object.scheme();
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
GRANTLEE_END_LOOKUP
#else
KTEXTTEMPLATE_END_LOOKUP
#endif
using namespace KAddressBookGrantlee;
......
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