Commit d74bb6df authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Add GrantleeTheme::Engine to avoid code duplication

GrantleeTheme::Engine is a simple subclass of Grantlee::Engine which
sets up the correct plugin path and loads the default KDE plugins.

It also provides easy access to Ki18n localizer.
parent 08b546a6
...@@ -7,6 +7,7 @@ add_subdirectory(plugin) ...@@ -7,6 +7,7 @@ add_subdirectory(plugin)
set(libgrantleetheme_SRCS set(libgrantleetheme_SRCS
grantleetheme.cpp grantleetheme.cpp
grantleethememanager.cpp grantleethememanager.cpp
grantleethemeengine.cpp
grantleeki18nlocalizer.cpp grantleeki18nlocalizer.cpp
qtresourcetemplateloader.cpp qtresourcetemplateloader.cpp
) )
...@@ -46,6 +47,7 @@ ecm_generate_headers(GrantleeTheme_CamelCase_HEADERS ...@@ -46,6 +47,7 @@ ecm_generate_headers(GrantleeTheme_CamelCase_HEADERS
HEADER_NAMES HEADER_NAMES
GrantleeThemeManager GrantleeThemeManager
GrantleeTheme GrantleeTheme
GrantleeThemeEngine
QtResourceTemplateLoader QtResourceTemplateLoader
GrantleeKi18nLocalizer GrantleeKi18nLocalizer
REQUIRED_HEADERS GrantleeTheme_HEADERS REQUIRED_HEADERS GrantleeTheme_HEADERS
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "grantleetheme.h" #include "grantleetheme.h"
#include "grantleetheme_p.h" #include "grantleetheme_p.h"
#include "grantleetheme_debug.h" #include "grantleetheme_debug.h"
#include "grantleethemeengine.h"
#include "config-grantleetheme.h" #include "config-grantleetheme.h"
#include <KConfig> #include <KConfig>
...@@ -57,11 +58,7 @@ ThemePrivate::~ThemePrivate() ...@@ -57,11 +58,7 @@ ThemePrivate::~ThemePrivate()
void ThemePrivate::setupEngine() void ThemePrivate::setupEngine()
{ {
sEngine = new Grantlee::Engine; sEngine = new GrantleeTheme::Engine();
sEngine->addPluginPath(QStringLiteral(GRANTLEE_PLUGIN_INSTALL_DIR));
sEngine->addDefaultLibrary(QStringLiteral("grantlee_i18ntags"));
sEngine->addDefaultLibrary(QStringLiteral("kde_grantlee_plugin"));
sEngine->setSmartTrimEnabled(true);
} }
void ThemePrivate::setupLoader() void ThemePrivate::setupLoader()
......
/*
Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grantleethemeengine.h"
#include "grantleeki18nlocalizer.h"
#include "config-grantleetheme.h"
using namespace GrantleeTheme;
class GrantleeTheme::Engine::Private
{
public:
Private()
{
}
~Private()
{
}
QWeakPointer<GrantleeKi18nLocalizer> localizer;
};
Engine::Engine(QObject *parent)
: Grantlee::Engine(parent)
, d(new Private)
{
addPluginPath(QStringLiteral(GRANTLEE_PLUGIN_INSTALL_DIR));
addDefaultLibrary(QStringLiteral("grantlee_i18ntags"));
addDefaultLibrary(QStringLiteral("kde_grantlee_plugin"));
addDefaultLibrary(QStringLiteral("grantlee_scriptabletags"));
setSmartTrimEnabled(true);
}
Engine::~Engine()
{
delete d;
}
QSharedPointer<GrantleeKi18nLocalizer> Engine::localizer() const
{
auto loc = d->localizer.toStrongRef();
if (!loc) {
loc.reset(new GrantleeKi18nLocalizer());
d->localizer = loc.toWeakRef();
}
return loc;
}
/*
Copyright (c) 2016 Daniel Vrátil <dvratil@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRANTLEETHEMEENGINE_H
#define GRANTLEETHEMEENGINE_H
#include <grantlee/engine.h>
#include <QSharedPointer>
#include "grantleetheme_export.h"
namespace GrantleeTheme {
class GrantleeKi18nLocalizer;
class GRANTLEETHEME_EXPORT Engine : public Grantlee::Engine
{
Q_OBJECT
public:
Engine(QObject *parent = Q_NULLPTR);
~Engine() Q_DECL_OVERRIDE;
QSharedPointer<GrantleeKi18nLocalizer> localizer() const;
private:
class Private;
Private *const d;
};
}
#endif
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