7#include "grantleetheme.h"
8#include "grantleetheme_debug.h"
9#include "grantleetheme_p.h"
10#include "grantleethemeengine.h"
11#include "qtresourcetemplateloader.h"
12#include <config-grantleetheme.h>
15#include <KConfigGroup>
16#include <KLocalizedString>
19#include <QSharedPointer>
21using namespace GrantleeTheme;
26ThemePrivate::ThemePrivate()
31ThemePrivate::ThemePrivate(
const ThemePrivate &other) =
default;
33ThemePrivate::~ThemePrivate() =
default;
35void ThemePrivate::setupEngine()
40void ThemePrivate::setupLoader()
45 for (
const QString &absolutePath : std::as_const(absolutePaths)) {
48 templatePaths <<
dir.absolutePath();
51 loader->setTemplateDirs(templatePaths);
52 loader->setTheme(dirName);
55 ThemePrivate::setupEngine();
57 sEngine->addTemplateLoader(loader);
64 sLocalizer->setApplicationDomain(applicationDomain);
66 ctx.setLocalizer(sLocalizer);
72 "<b>%1:</b> {{ templateName }}<br>\n"
73 "<b>%2:</b> {{ errorMessage }}")
74 .arg(
i18n(
"Template"),
i18n(
"Error message")),
75 QStringLiteral(
"TemplateError"));
78 ctx.
insert(QStringLiteral(
"error"), reason);
79 ctx.
insert(QStringLiteral(
"templateName"), origTemplateName);
81 ctx.
insert(QStringLiteral(
"errorMessage"), errorString);
95 KConfigGroup group(&config, QStringLiteral(
"Desktop Entry"));
96 if (group.isValid()) {
98 d->absolutePaths.
append(themePath);
99 d->name = group.readEntry(
"Name",
QString());
100 d->description = group.readEntry(
"Description",
QString());
101 d->themeFileName = group.readEntry(
"FileName",
QString());
102 d->displayExtraVariables = group.readEntry(
"DisplayExtraVariables",
QStringList());
106Theme::Theme(
const Theme &other)
110Theme::~Theme() =
default;
112bool Theme::operator==(
const Theme &other)
const
114 return isValid() && other.isValid() && d->absolutePaths == other.d->absolutePaths;
119 if (
this != &other) {
126bool Theme::isValid()
const
128 return !d->themeFileName.isEmpty() && !d->name.isEmpty();
131QString Theme::description()
const
133 return d->description;
136QString Theme::themeFilename()
const
138 return d->themeFileName;
148 return d->displayExtraVariables;
156QString Theme::absolutePath()
const
158 if (!d->absolutePaths.isEmpty()) {
159 return d->absolutePaths.at(0);
169QString Theme::authorEmail()
const
174void Theme::addThemePath(
const QString &path)
176 d->absolutePaths.append(path);
186 if (!d->loader->canLoadTemplate(templateName)) {
187 qCWarning(GRANTLEETHEME_LOG) <<
"Cannot load template" << templateName
188 <<
", please check your installation. Tried in these dirs:" << d->loader->templateDirs();
192 if (!tpl || tpl->
error()) {
193 return d->errorTemplate(
i18n(
"Template parsing error"), templateName, tpl);
198 return d->errorTemplate(
i18n(
"Template rendering error"), templateName, tpl);
204void Theme::addPluginPath(
const QString &path)
206 if (!ThemePrivate::sEngine) {
207 ThemePrivate::setupEngine();
210 QStringList paths = ThemePrivate::sEngine->pluginPaths();
213 ThemePrivate::sEngine->setPluginPaths(paths);
The GrantleeKi18nLocalizer class.
void insert(const QString &name, const QVariant &variant)
QString errorString() const
QString render(Context *c) const
QString i18n(const char *text, const TYPE &arg...)
KIOCORE_EXPORT QString dir(const QString &fileClass)
void prepend(parameter_type value)
QSharedPointer< T > create(Args &&... args)
QString & append(QChar ch)
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const