File 0001-Revert-Systray-Move-all-icon-resolution-to-dataengin.patch of Package plasma5-workspace
From 2044b8fa49dc054032c5061fa130152ad1b5c050 Mon Sep 17 00:00:00 2001
From: Fabian Vogt <fabian@ritter-vogt.de>
Date: Tue, 21 Feb 2017 19:02:11 +0100
Subject: [PATCH] Revert "Systray: Move all icon resolution to dataengine"
We used a different approach in 42.2 and it behaves slightly different.
So for now let's be compatible here.
---
.../package/contents/ui/ConfigEntries.qml | 2 +-
.../contents/ui/items/StatusNotifierItem.qml | 4 +-
applets/systemtray/systemtray.cpp | 52 ++++++++++++++++++++++
applets/systemtray/systemtray.h | 6 +++
.../statusnotifieritemsource.cpp | 9 +---
5 files changed, 63 insertions(+), 10 deletions(-)
diff --git a/applets/systemtray/package/contents/ui/ConfigEntries.qml b/applets/systemtray/package/contents/ui/ConfigEntries.qml
index aefac233..ca8b058e 100644
--- a/applets/systemtray/package/contents/ui/ConfigEntries.qml
+++ b/applets/systemtray/package/contents/ui/ConfigEntries.qml
@@ -75,7 +75,7 @@ QtLayouts.GridLayout {
"index": i,
"taskId": item.Id,
"name": item.Title,
- "iconName": item.IconName,
+ "iconName": plasmoid.nativeInterface.resolveIcon(item.IconName, item.IconThemePath),
"icon": item.Icon
});
}
diff --git a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml
index 889b8b53..115e1fbe 100644
--- a/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml
+++ b/applets/systemtray/package/contents/ui/items/StatusNotifierItem.qml
@@ -28,7 +28,7 @@ AbstractItem {
text: Title
mainText: ToolTipTitle != "" ? ToolTipTitle : Title
subText: ToolTipSubTitle
- icon: ToolTipIcon != "" ? ToolTipIcon : Icon ? Icon : IconName
+ icon: ToolTipIcon != "" ? ToolTipIcon : plasmoid.nativeInterface.resolveIcon(IconName != "" ? IconName : Icon, IconThemePath)
textFormat: Text.AutoText
category: Category
@@ -48,7 +48,7 @@ AbstractItem {
PlasmaCore.IconItem {
id: iconItem
- source: Icon ? Icon : IconName
+ source: plasmoid.nativeInterface.resolveIcon(IconName != "" ? IconName : Icon, IconThemePath)
width: Math.min(parent.width, parent.height)
height: width
active: taskIcon.containsMouse
diff --git a/applets/systemtray/systemtray.cpp b/applets/systemtray/systemtray.cpp
index 7de13004..59c7aaf2 100644
--- a/applets/systemtray/systemtray.cpp
+++ b/applets/systemtray/systemtray.cpp
@@ -37,11 +37,37 @@
#include <Plasma/PluginLoader>
#include <Plasma/ServiceJob>
+#include <KIconLoader>
+#include <KIconEngine>
#include <KActionCollection>
#include <KLocalizedString>
#include <plasma_version.h>
+/*
+ * An app may also load icons from their own directories, so we need a new iconloader that takes this into account
+ * This is wrapped into a subclass of iconengine so the iconloader lifespan matches the icon object
+ */
+class AppIconEngine : public KIconEngine
+{
+public:
+ AppIconEngine(const QString &variant, const QString &path, const QString &appName);
+ ~AppIconEngine();
+private:
+ KIconLoader* m_loader;
+};
+
+AppIconEngine::AppIconEngine(const QString &variant, const QString &path, const QString &appName) :
+ KIconEngine(variant, m_loader = new KIconLoader(appName, QStringList()))
+{
+ m_loader->addAppDir(appName, path);
+}
+
+AppIconEngine::~AppIconEngine()
+{
+ delete m_loader;
+}
+
class PlasmoidModel: public QStandardItemModel
{
public:
@@ -143,6 +169,32 @@ void SystemTray::cleanupTask(const QString &task)
}
}
+QVariant SystemTray::resolveIcon(const QVariant &variant, const QString &iconThemePath)
+{
+ if (variant.canConvert<QString>()) {
+ if (!iconThemePath.isEmpty()) {
+ const QString path = iconThemePath;
+ if (!path.isEmpty()) {
+ // FIXME: If last part of path is not "icons", this won't work!
+ auto tokens = path.splitRef('/', QString::SkipEmptyParts);
+ if (tokens.length() >= 3 && tokens.takeLast() == QLatin1String("icons")) {
+ const QString appName = tokens.takeLast().toString();
+
+ return QVariant(QIcon(new AppIconEngine(variant.toString(), path, appName)));
+ } else {
+ qCWarning(SYSTEM_TRAY) << "Wrong IconThemePath" << path << ": too short or does not end with 'icons'";
+ }
+ }
+
+ //return just the string hoping that IconItem will know how to interpret it anyways as either a normal icon or a SVG from the theme
+ return variant;
+ }
+ }
+
+ // Most importantly QIcons. Nothing to do for those.
+ return variant;
+}
+
void SystemTray::showPlasmoidMenu(QQuickItem *appletInterface, int x, int y)
{
if (!appletInterface) {
diff --git a/applets/systemtray/systemtray.h b/applets/systemtray/systemtray.h
index 0a93fe2b..953d81b4 100644
--- a/applets/systemtray/systemtray.h
+++ b/applets/systemtray/systemtray.h
@@ -60,6 +60,12 @@ public:
//Invokable utilities
/**
+ * returns either a simple icon name or a custom path if the app is
+ * using a custom theme
+ */
+ Q_INVOKABLE QVariant resolveIcon(const QVariant &variant, const QString &iconThemePath);
+
+ /**
* Given an AppletInterface pointer, shows a proper context menu for it
*/
Q_INVOKABLE void showPlasmoidMenu(QQuickItem *appletInterface, int x, int y);
diff --git a/dataengines/statusnotifieritem/statusnotifieritemsource.cpp b/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
index d835d50c..2df5e795 100644
--- a/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
+++ b/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
@@ -240,19 +240,14 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
if (!m_customIconLoader) {
m_customIconLoader = new KIconLoader(QString(), QStringList(), this);
}
- // FIXME: If last part of path is not "icons", this won't work!
- QString appName;
- auto tokens = path.splitRef('/', QString::SkipEmptyParts);
- if (tokens.length() >= 3 && tokens.takeLast() == QLatin1String("icons"))
- appName = tokens.takeLast().toString();
//icons may be either in the root directory of the passed path or in a appdir format
//i.e hicolor/32x32/iconname.png
- m_customIconLoader->reconfigure(appName, QStringList(path));
+ m_customIconLoader->reconfigure(QString(), QStringList(path));
//add app dir requires an app name, though this is completely unused in this context
- m_customIconLoader->addAppDir(appName.size() ? appName : QStringLiteral("unused"), path);
+ m_customIconLoader->addAppDir(QStringLiteral("unused"), path);
}
setData(QStringLiteral("IconThemePath"), path);
--
2.11.0