Commit 8db6402b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add grantlee here

parent 0402c47c
...@@ -36,6 +36,7 @@ find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED) ...@@ -36,6 +36,7 @@ find_package(KF5KIO ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Completion ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED) find_package(KF5Codecs ${KF5_VERSION} CONFIG REQUIRED)
find_package(Phonon4Qt5 CONFIG REQUIRED) find_package(Phonon4Qt5 CONFIG REQUIRED)
find_package(Grantlee5 "5.0" CONFIG REQUIRED)
find_package(KF5Contacts ${KCONTACTS_VERSION} CONFIG REQUIRED) find_package(KF5Contacts ${KCONTACTS_VERSION} CONFIG REQUIRED)
find_package(KF5CalendarCore ${CALENDARCORE_VERSION} CONFIG REQUIRED) find_package(KF5CalendarCore ${CALENDARCORE_VERSION} CONFIG REQUIRED)
......
...@@ -165,6 +165,7 @@ PRIVATE ...@@ -165,6 +165,7 @@ PRIVATE
KF5::WidgetsAddons KF5::WidgetsAddons
KF5::XmlGui KF5::XmlGui
Phonon::phonon4qt5 Phonon::phonon4qt5
Grantlee5::Templates
) )
if(KF5Prison_FOUND) if(KF5Prison_FOUND)
......
...@@ -22,18 +22,21 @@ ...@@ -22,18 +22,21 @@
#include "addresseslocationgrantleeformater.h" #include "addresseslocationgrantleeformater.h"
#include "addressgrantleeobject.h" #include "addressgrantleeobject.h"
#include <grantlee/engine.h>
#include <QVariantList> #include <QVariantList>
AddressesLocationGrantleeFormater::AddressesLocationGrantleeFormater(QObject *parent) AddressesLocationGrantleeFormater::AddressesLocationGrantleeFormater(QObject *parent)
: QObject(parent) : QObject(parent),
mEngine(new Grantlee::Engine)
{ {
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
QString themePath; //TODO
changeGrantleePath(themePath);
} }
AddressesLocationGrantleeFormater::~AddressesLocationGrantleeFormater() AddressesLocationGrantleeFormater::~AddressesLocationGrantleeFormater()
{ {
delete mEngine;
} }
QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Address::List &addresses) QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Address::List &addresses)
...@@ -46,5 +49,22 @@ QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Addr ...@@ -46,5 +49,22 @@ QString AddressesLocationGrantleeFormater::formatAddresses(const KContacts::Addr
addressList << QVariant::fromValue(static_cast<QObject *>(addressObj)); addressList << QVariant::fromValue(static_cast<QObject *>(addressObj));
} }
//TODO //TODO
return QString(); QVariantHash addressHash;
Grantlee::Context context(addressHash);
const QString contentHtml = mSelfcontainedTemplate->render(&context);
return contentHtml;
}
void AddressesLocationGrantleeFormater::changeGrantleePath(const QString &path)
{
if (!mTemplateLoader) {
mTemplateLoader = QSharedPointer<Grantlee::FileSystemTemplateLoader>(new Grantlee::FileSystemTemplateLoader);
}
mTemplateLoader->setTemplateDirs(QStringList() << path);
mEngine->addTemplateLoader(mTemplateLoader);
mSelfcontainedTemplate = mEngine->loadByName(QStringLiteral("sss")); //TODO
if (mSelfcontainedTemplate->error()) {
mErrorMessage += mSelfcontainedTemplate->errorString() + QLatin1String("<br>");
}
} }
...@@ -26,7 +26,12 @@ ...@@ -26,7 +26,12 @@
#include <QObject> #include <QObject>
#include <KContacts/Address> #include <KContacts/Address>
#include <QSharedPointer>
#include <grantlee/templateloader.h>
namespace Grantlee
{
class Engine;
}
class AddressesLocationGrantleeFormater : public QObject class AddressesLocationGrantleeFormater : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -35,7 +40,12 @@ public: ...@@ -35,7 +40,12 @@ public:
~AddressesLocationGrantleeFormater(); ~AddressesLocationGrantleeFormater();
QString formatAddresses(const KContacts::Address::List &addresses); QString formatAddresses(const KContacts::Address::List &addresses);
private:
void changeGrantleePath(const QString &path);
Grantlee::Engine *mEngine;
QString mErrorMessage;
QSharedPointer<Grantlee::FileSystemTemplateLoader> mTemplateLoader;
Grantlee::Template mSelfcontainedTemplate;
}; };
#endif // ADDRESSESLOCATIONGRANTLEEFORMATER_H #endif // ADDRESSESLOCATIONGRANTLEEFORMATER_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