Commit df0b5c86 authored by Laurent Montel's avatar Laurent Montel 😁

Port to PimCommon::GenericGrantleeFormatter

parent b39f0f0e
......@@ -25,7 +25,7 @@ set(QT_REQUIRED_VERSION "5.4.0")
set(KMIME_LIB_VERSION "4.87.0")
set(KPIMTEXTEDIT_LIB_VERSION "5.1.42")
set(KCONTACTS_LIB_VERSION "4.92.0")
set(PIMCOMMON_LIB_VERSION "5.1.42")
set(PIMCOMMON_LIB_VERSION "5.1.51")
set(LIBKLEO_LIB_VERSION "5.1.42")
set(GRANTLEETHEME_LIB_VERSION "5.1.42")
......
......@@ -48,6 +48,7 @@ PRIVATE
KF5::IconThemes
KF5::Libkleo
KF5::I18n
KF5::PimCommon
)
set_target_properties(KF5KaddressbookGrantlee PROPERTIES
......
ecm_add_test(grantleeprinttest.cpp
NAME_PREFIX "kaddressbookgrantlee-printing-"
LINK_LIBRARIES KF5::KaddressbookGrantlee Qt5::Test KF5::Contacts
LINK_LIBRARIES KF5::KaddressbookGrantlee Qt5::Test KF5::Contacts KF5::PimCommon
)
......@@ -18,6 +18,7 @@
#include "grantleeprint.h"
#include "contactgrantleeprintobject.h"
#include "formatter/grantleecontactutils.h"
#include <grantlee/context.h>
......@@ -27,56 +28,23 @@
using namespace KAddressBookGrantlee;
GrantleePrint::GrantleePrint(QObject *parent)
: QObject(parent)
: PimCommon::GenericGrantleeFormatter(parent)
{
mEngine = new Grantlee::Engine;
}
GrantleePrint::GrantleePrint(const QString &themePath, QObject *parent)
: QObject(parent)
: PimCommon::GenericGrantleeFormatter(QStringLiteral("theme.html"), themePath, parent)
{
mEngine = new Grantlee::Engine;
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
changeGrantleePath(themePath);
}
GrantleePrint::~GrantleePrint()
{
delete mEngine;
}
void GrantleePrint::refreshTemplate()
{
mSelfcontainedTemplate = mEngine->loadByName(QStringLiteral("theme.html"));
if (mSelfcontainedTemplate->error()) {
mErrorMessage += mSelfcontainedTemplate->errorString() + QLatin1String("<br>");
}
}
void GrantleePrint::changeGrantleePath(const QString &path)
{
if (!mTemplateLoader) {
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
}
mTemplateLoader->setTemplateDirs(QStringList() << path);
mEngine->addTemplateLoader(mTemplateLoader);
refreshTemplate();
}
void GrantleePrint::setContent(const QString &content)
{
mSelfcontainedTemplate = mEngine->newTemplate(content, QStringLiteral("content"));
if (mSelfcontainedTemplate->error()) {
mErrorMessage = mSelfcontainedTemplate->errorString() + QLatin1String("<br>");
}
}
QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts)
{
if (!mErrorMessage.isEmpty()) {
return mErrorMessage;
if (!errorMessage().isEmpty()) {
return errorMessage();
}
if (contacts.isEmpty()) {
......@@ -115,10 +83,9 @@ QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts
grantleeContactUtil.insertVariableToQVariantHash(contactI18n, QStringLiteral("titlei18n"));
grantleeContactUtil.insertVariableToQVariantHash(contactI18n, QStringLiteral("nextcontacti18n"));
mapping.insert(QStringLiteral("contacti18n"), contactI18n);
mapping.insert(QStringLiteral("contacts"), contactsList);
Grantlee::Context context(mapping);
context.insert(QStringLiteral("contacts"), contactsList);
const QString content = mSelfcontainedTemplate->render(&context);
const QString content = render(mapping);
qDeleteAll(lst);
return content;
}
......
......@@ -19,8 +19,8 @@
#define GRANTLEEPRINT_H
#include "kaddressbook_grantlee_export.h"
#include <PimCommon/GenericGrantleeFormatter>
#include <QObject>
#include <grantlee/templateloader.h>
#include <KContacts/Addressee>
namespace Grantlee
......@@ -30,7 +30,7 @@ class Engine;
namespace KAddressBookGrantlee
{
class KADDRESSBOOK_GRANTLEE_EXPORT GrantleePrint : public QObject
class KADDRESSBOOK_GRANTLEE_EXPORT GrantleePrint : public PimCommon::GenericGrantleeFormatter
{
Q_OBJECT
public:
......@@ -39,16 +39,6 @@ public:
~GrantleePrint();
QString contactsToHtml(const KContacts::Addressee::List &contacts);
void setContent(const QString &content);
void changeGrantleePath(const QString &path);
void refreshTemplate();
private:
QString mErrorMessage;
Grantlee::Engine *mEngine;
QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
Grantlee::Template mSelfcontainedTemplate;
};
}
#endif // GRANTLEEPRINT_H
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