Commit 78cfd7a0 authored by Harald Sitter's avatar Harald Sitter
Browse files

KSNI: fix IconThemePath support

IconThemePath is used by a Canonical Patch to enable all Qt apps using
QSystemTrayIcon to transparently provide a SNI with icons exported into
a temporary path. Hence the lack of support breaks icons for all Qt apps
on Ubuntu.

Fix:
- in the dataengine export IconThemePath
- in the systray protocol pick up the value and forward to QML
- in QML set the themePath accordingly on the IconItem
  (requires changes in runtime)

https://bugs.launchpad.net/ubuntu/+source/kde-workspace/+bug/1088772
BUG: 311555
CCMAIL: 1088772@bugs.launchpad.net
REVIEW: 107702
parent 789166af
......@@ -179,11 +179,11 @@ Item {
// Functions =======================================================================================================
function __getDefaultIcon() {
return __icon_name != "" ? __icon_name : __icon
return task.customIcon(__icon_name != "" ? __icon_name : __icon)
}
function __getAttentionIcon() {
return __att_icon_name != "" ? __att_icon_name : __att_icon
return task.customIcon(__att_icon_name != "" ? __att_icon_name : __att_icon)
}
function __processClick(buttons, item) {
......
......@@ -29,7 +29,9 @@
#include <QtGui/QIcon>
#include <KDE/KJob>
#include <KDE/KIcon>
#include <KDE/KIconLoader>
#include <KDE/KStandardDirs>
#include <KDE/Plasma/ServiceJob>
#include <KDE/Plasma/ToolTipManager>
#include <KDE/Plasma/Applet>
......@@ -41,6 +43,7 @@ DBusSystemTrayTask::DBusSystemTrayTask(const QString &serviceName, Plasma::DataE
: Task(parent),
m_serviceName(serviceName),
m_typeId(serviceName),
m_customIconLoader(0),
m_dataEngine(dataEngine),
m_service(dataEngine->serviceForSource(serviceName)),
m_isMenu(false),
......@@ -121,6 +124,51 @@ void DBusSystemTrayTask::activateHorzScroll(int delta) const
_activateScroll(delta, "Horizontal");
}
// Copied from kde-runtime/plasma/declarativeimports/core/iconitem.cpp
bool static hasm_svgIcon(QVariant source)
{
// Set up compat envrionment, afterwards it is 100% copy'n'pastable.
QVariant m_source = source;
Plasma::Svg svgIcon;
Plasma::Svg *m_svgIcon = &svgIcon;
//try as a svg toolbar icon
m_svgIcon->setImagePath("toolbar-icons/" + source.toString().split("-").first());
//try as a svg normal icon (like systray)
if (!m_svgIcon->isValid() || !m_svgIcon->hasElement(m_source.toString())) {
m_svgIcon->setImagePath("icons/" + source.toString().split("-").first());
}
m_svgIcon->setContainsMultipleImages(true);
//success?
if (m_svgIcon->isValid() && m_svgIcon->hasElement(m_source.toString())) {
return true;
}
return false;
}
QVariant DBusSystemTrayTask::customIcon(QVariant variant) const
{
if (variant.canConvert<QString>()) {
// If we have no icon loader there is nothing to be done with strings.
if (!m_customIconLoader)
return variant;
// If an SVG icon can be found (via Plasma theme) the name needs to be
// passed along for IconItem to be able to resolve to the theme name as
// well.
if (hasm_svgIcon(variant))
return variant;
// Otherwise return a QIcon from our custom icon loader.
return QVariant(KIcon(variant.toString(), m_customIconLoader));
} else {
// Most importantly QIcons. Nothing to do for those.
return variant;
}
}
void DBusSystemTrayTask::activateVertScroll(int delta) const
{
_activateScroll(delta, "Vertical");
......@@ -237,6 +285,7 @@ void DBusSystemTrayTask::syncIcons(const Plasma::DataEngine::Data &properties)
QString att_icon_name = properties["AttentionIconName"].toString();
QString movie_path = properties["AttentionMovieName"].toString();
QString overlay_icon_name = properties["OverlayIconName"].value<QString>();
QString icon_theme_path = properties["IconThemePath"].value<QString>();
bool is_icon_name_changed = false;
bool is_att_icon_name_changed = false;
bool is_movie_path_changed = false;
......@@ -266,6 +315,40 @@ void DBusSystemTrayTask::syncIcons(const Plasma::DataEngine::Data &properties)
is_overlay_icon_name_changed = true;
}
if (icon_theme_path != m_iconThemePath) {
m_iconThemePath = icon_theme_path;
if (m_customIconLoader) {
delete m_customIconLoader;
m_customIconLoader = 0;
}
const QString path = m_iconThemePath;
if (!path.isEmpty()) {
// FIXME: If last part of path is not "icons", this won't work!
QStringList tokens = path.split('/', QString::SkipEmptyParts);
if (tokens.length() >= 3 && tokens.takeLast() == QLatin1String("icons")) {
QString appName = tokens.takeLast();
QString prefix = QChar('/') % tokens.join("/");
// FIXME: Fix KIconLoader and KIconTheme so that we can use
// our own instance of KStandardDirs
KGlobal::dirs()->addResourceDir("data", prefix);
// We use a separate instance of KIconLoader to avoid
// adding all application dirs to KIconLoader::global(), to
// avoid potential icon name clashes between application
// icons
m_customIconLoader = new KIconLoader(appName, 0 /* dirs */, this);
} else {
kWarning() << "Wrong IconThemePath" << path << ": too short or does not end with 'icons'";
}
}
// Trigger updates
is_icon_name_changed = true;
is_att_icon_name_changed = true;
is_overlay_icon_name_changed = true;
emit changedIcons();
}
// emit signals
if (is_icon_name_changed) {
emit changedIconName();
......
......@@ -25,6 +25,7 @@
#include <Plasma/DataEngine>
class KIconLoader;
class KJob;
namespace Plasma
......@@ -91,7 +92,8 @@ public:
Q_INVOKABLE void activate1(int x, int y) const;
Q_INVOKABLE void activate2(int x, int y) const;
Q_INVOKABLE void activateVertScroll(int delta) const;
Q_INVOKABLE void activateHorzScroll(int delta) const ;
Q_INVOKABLE void activateHorzScroll(int delta) const;
Q_INVOKABLE QVariant customIcon(QVariant variant) const;
signals:
void changedIcons(); // if icons, icon names, movie path are changed
......@@ -128,9 +130,13 @@ private:
QString m_shortcut;
QString m_moviePath;
QString m_overlayIconName;
QString m_iconThemePath;
QString m_tooltipTitle;
QString m_tooltipText;
QIcon m_tooltipIcon;
KIconLoader *m_customIconLoader;
Plasma::DataEngine *m_dataEngine;
Plasma::Service *m_service;
bool m_isMenu;
......
......@@ -232,6 +232,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
}
}
}
setData("IconThemePath", properties["IconThemePath"]);
setData("Category", properties["Category"]);
setData("Status", properties["Status"]);
......
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