diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1843cfff4710d1545524a4ba13ee205bca38f113..3ff568cd4d549af2a5ec93c9f6f43331d525f89c 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 ecb4fd505f2ada26755e3f80453883a41ed64815..b86fc3af76905dd107f798d8c7e980b464f0be1d 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 @@ -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 0000000000000000000000000000000000000000..714426fc2b3ae0c74b903db61ad323fff4e71a2d --- /dev/null +++ b/src/grantleethemeengine.cpp @@ -0,0 +1,64 @@ +/* + Copyright (c) 2016 Daniel Vrátil + + 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 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 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 0000000000000000000000000000000000000000..ae129f56a1701759f6b522eedbfdc6e12d841729 --- /dev/null +++ b/src/grantleethemeengine.h @@ -0,0 +1,47 @@ +/* + Copyright (c) 2016 Daniel Vrátil + + 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 +#include + +#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 localizer() const; + +private: + class Private; + Private *const d; +}; + +} + +#endif