Commit f070ce97 authored by David Faure's avatar David Faure
Browse files

Support multiple entries in XDG_DATA_DIRS

Summary:
Multiple themes named "Default" were inserted into the QMap,
one for my prefix and then one for /usr/share, which replaced it.
What we want is this to be a single theme with multiple search paths.

Test Plan:
This fixes the "Kontact introduction" in my developer
setup where everything is installed into a custom prefix.
Before this fix, only /usr/share/messageviewer/about was looked at,
and I don't have kontact installed there.

Reviewers: dvratil, mlaurent, vkrause, skelly

Reviewed By: dvratil

Subscribers: kde-pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D29613
parent 71c46fc5
Pipeline #20725 passed with stage
in 3 minutes and 33 seconds
......@@ -47,7 +47,7 @@ ThemePrivate::ThemePrivate(const ThemePrivate &other)
, description(other.description)
, name(other.name)
, dirName(other.dirName)
, absolutePath(other.absolutePath)
, absolutePaths(other.absolutePaths)
, author(other.author)
, email(other.email)
, loader(other.loader)
......@@ -66,11 +66,16 @@ void ThemePrivate::setupEngine()
void ThemePrivate::setupLoader()
{
// Get the parent dir with themes, we set the theme directory separately
QDir dir(absolutePath);
dir.cdUp();
QStringList templatePaths;
for (const QString &absolutePath : qAsConst(absolutePaths)) {
QDir dir(absolutePath);
dir.cdUp();
templatePaths << dir.absolutePath();
}
loader = QSharedPointer<GrantleeTheme::QtResourceTemplateLoader>::create();
loader->setTemplateDirs({ dir.absolutePath() });
loader->setTemplateDirs(templatePaths);
loader->setTheme(dirName);
if (!sEngine) {
......@@ -122,7 +127,7 @@ Theme::Theme(const QString &themePath, const QString &dirName, const QString &de
KConfigGroup group(&config, QStringLiteral("Desktop Entry"));
if (group.isValid()) {
d->dirName = dirName;
d->absolutePath = themePath;
d->absolutePaths.append(themePath);
d->name = group.readEntry("Name", QString());
d->description = group.readEntry("Description", QString());
d->themeFileName = group.readEntry("FileName", QString());
......@@ -141,7 +146,7 @@ Theme::~Theme()
bool Theme::operator==(const Theme &other) const
{
return isValid() && other.isValid() && d->absolutePath == other.absolutePath();
return isValid() && other.isValid() && d->absolutePaths == other.d->absolutePaths;
}
Theme &Theme::operator=(const Theme &other)
......@@ -185,7 +190,7 @@ QString Theme::dirName() const
QString Theme::absolutePath() const
{
return d->absolutePath;
return d->absolutePaths.at(0); // ####
}
QString Theme::author() const
......@@ -198,6 +203,11 @@ QString Theme::authorEmail() const
return d->email;
}
void Theme::addThemePath(const QString &path)
{
d->absolutePaths.append(path);
}
QString Theme::render(const QString &templateName, const QVariantHash &data, const QByteArray &applicationDomain)
{
if (!d->loader) {
......@@ -206,7 +216,7 @@ QString Theme::render(const QString &templateName, const QVariantHash &data, con
Q_ASSERT(d->loader);
if (!d->loader->canLoadTemplate(templateName)) {
qCWarning(GRANTLEETHEME_LOG) << "Cannot load template" << templateName << ", please check your installation";
qCWarning(GRANTLEETHEME_LOG) << "Cannot load template" << templateName << ", please check your installation. Tried in these dirs:" << d->loader->templateDirs();
return QString();
}
......
......@@ -54,6 +54,8 @@ public:
Q_REQUIRED_RESULT QString author() const;
Q_REQUIRED_RESULT QString authorEmail() const;
void addThemePath(const QString &path);
Q_REQUIRED_RESULT QString render(const QString &templateName, const QVariantHash &data, const QByteArray &applicationDomain = QByteArray());
static void addPluginPath(const QString &path);
......
......@@ -44,7 +44,7 @@ public:
QString description;
QString name;
QString dirName;
QString absolutePath;
QStringList absolutePaths;
QString author;
QString email;
......
......@@ -143,8 +143,12 @@ public:
theme.d->name = themeName;
}
alreadyLoadedThemeName << themeName;
themes.insert(dirName, theme);
//qDebug()<<" theme.name()"<<theme.name();
auto it = themes.find(dirName);
if (it != themes.end()) {
(*it).addThemePath(dirIt.filePath());
} else {
themes.insert(dirName, theme);
}
}
}
watch->addDir(directory);
......
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