aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <[email protected]>2016-06-30 11:41:08 +0200
committerDaniel Vrátil <[email protected]>2016-06-30 11:51:06 +0200
commitd74bb6df2688e670299cb8258d66bd309e43930e (patch)
tree72ae53c354317400b73d850799436ec0bff9810f
parent08b546a67875a6720d54813e7a232042ad0b3b90 (diff)
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.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/grantleetheme.cpp7
-rw-r--r--src/grantleethemeengine.cpp64
-rw-r--r--src/grantleethemeengine.h47
4 files changed, 115 insertions, 5 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1843cff..3ff568c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,6 +7,7 @@ add_subdirectory(plugin)
set(libgrantleetheme_SRCS
grantleetheme.cpp
grantleethememanager.cpp
+ grantleethemeengine.cpp
grantleeki18nlocalizer.cpp
qtresourcetemplateloader.cpp
)
@@ -46,6 +47,7 @@ ecm_generate_headers(GrantleeTheme_CamelCase_HEADERS
HEADER_NAMES
GrantleeThemeManager
GrantleeTheme
+ GrantleeThemeEngine
QtResourceTemplateLoader
GrantleeKi18nLocalizer
REQUIRED_HEADERS GrantleeTheme_HEADERS
diff --git a/src/grantleetheme.cpp b/src/grantleetheme.cpp
index ecb4fd5..b86fc3a 100644
--- a/src/grantleetheme.cpp
+++ b/src/grantleetheme.cpp
@@ -18,6 +18,7 @@
#include "grantleetheme.h"
#include "grantleetheme_p.h"
#include "grantleetheme_debug.h"
+#include "grantleethemeengine.h"
#include "config-grantleetheme.h"
#include <KConfig>
@@ -57,11 +58,7 @@ ThemePrivate::~ThemePrivate()
void ThemePrivate::setupEngine()
{
- sEngine = new Grantlee::Engine;
- sEngine->addPluginPath(QStringLiteral(GRANTLEE_PLUGIN_INSTALL_DIR));
- sEngine->addDefaultLibrary(QStringLiteral("grantlee_i18ntags"));
- sEngine->addDefaultLibrary(QStringLiteral("kde_grantlee_plugin"));
- sEngine->setSmartTrimEnabled(true);
+ sEngine = new GrantleeTheme::Engine();
}
void ThemePrivate::setupLoader()
diff --git a/src/grantleethemeengine.cpp b/src/grantleethemeengine.cpp
new file mode 100644
index 0000000..714426f
--- /dev/null
+++ b/src/grantleethemeengine.cpp
@@ -0,0 +1,64 @@
+/*
+ Copyright (c) 2016 Daniel Vrátil <[email protected]>
+
+ 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;
+}
diff --git a/src/grantleethemeengine.h b/src/grantleethemeengine.h
new file mode 100644
index 0000000..ae129f5
--- /dev/null
+++ b/src/grantleethemeengine.h
@@ -0,0 +1,47 @@
+/*
+ Copyright (c) 2016 Daniel Vrátil <[email protected]>
+
+ 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