Fix Plasma's SNI icons + port away from kdelibs4support

REVIEW: 118592
wilder-5.14
Martin Klapetek 12 years ago
parent 796b34b4c8
commit b0c2fda3ab
  1. 23
      applets/systemtray/plugin/protocols/dbussystemtray/dbussystemtraytask.cpp
  2. 1
      dataengines/statusnotifieritem/CMakeLists.txt
  3. 1
      dataengines/statusnotifieritem/statusnotifieritem_engine.cpp
  4. 46
      dataengines/statusnotifieritem/statusnotifieritemsource.cpp

@ -32,6 +32,7 @@
#include <KJob>
#include <KIconLoader>
#include <KIconEngine>
#include <Plasma/ServiceJob>
#include <Plasma/Applet>
@ -158,11 +159,7 @@ QVariant DBusSystemTrayTask::customIcon(QVariant variant) const
if (hasm_svgIcon(variant))
return variant;
// Otherwise return a QIcon from our custom icon loader.
if (!QIcon::themeSearchPaths().contains(m_iconThemePath)) {
QIcon::setThemeSearchPaths(QStringList(m_iconThemePath) << QIcon::themeSearchPaths());
}
return QVariant(QIcon::fromTheme(variant.toString()));
return QVariant(QIcon(new KIconEngine(variant.toString(), m_customIconLoader)));
} else {
// Most importantly QIcons. Nothing to do for those.
return variant;
@ -328,15 +325,21 @@ void DBusSystemTrayTask::syncIcons(const Plasma::DataEngine::Data &properties)
QStringList tokens = path.split('/', QString::SkipEmptyParts);
if (tokens.length() >= 3 && tokens.takeLast() == QLatin1String("icons")) {
QString appName = tokens.takeLast();
QString prefix = QChar('/') + tokens.join("/");
if (!QIcon::themeSearchPaths().contains(prefix)) {
QIcon::setThemeSearchPaths(QStringList(prefix) << QIcon::themeSearchPaths());
}
// 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, QStringList() /* dirs */, this);
m_customIconLoader = new KIconLoader(appName, QStringList(), this);
m_customIconLoader->addAppDir(appName, path);
m_icon = QIcon(new KIconEngine(icon_name, m_customIconLoader));
// Given we're using custom icon loader to load the icon and IconItem
// would not use this icon loader, we first check if Plasma themed SVG
// exists for this icon and if not, force IconItem to use the QIcon we provide
// instead of trying to lookup the icon by name (and fail)
if (!hasm_svgIcon(icon_name)) {
m_iconName = QString();
}
} else {
qWarning() << "Wrong IconThemePath" << path << ": too short or does not end with 'icons'";
}

@ -31,7 +31,6 @@ target_link_libraries(plasma_engine_statusnotifieritem
KF5::Service
KF5::Plasma
KF5::IconThemes
KF5::KDELibs4Support
dbusmenu-qt5
)

@ -23,7 +23,6 @@
#include "statusnotifieritemsource.h"
#include <QDebug>
#include <KIcon>
#include <iostream>
static const QString s_watcherServiceName("org.kde.StatusNotifierWatcher");

@ -26,10 +26,8 @@
#include <QApplication>
#include <QIcon>
#include <QDebug>
#include <KIcon>
#include <KIconEngine>
#include <KIconLoader>
#include <KStandardDirs>
#include <KGlobal>
#include <QPainter>
#include <QDBusMessage>
#include <QDBusPendingCall>
@ -59,7 +57,7 @@ public:
protected:
virtual QIcon iconForName(const QString &name)
{
return KIcon(name, m_iconLoader);
return QIcon(new KIconEngine(name, m_iconLoader));
}
private:
@ -211,28 +209,20 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
//IconThemePath (handle this one first, because it has an impact on
//others)
QVariantMap properties = reply.argumentAt<0>();
if (!m_customIconLoader) {
QString path = properties["IconThemePath"].toString();
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() == "icons") {
QString appName = tokens.takeLast();
QString prefix = '/' + 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, QStringList() /* dirs */, this);
} else {
qWarning() << "Wrong IconThemePath" << path << ": too short or does not end with 'icons'";
}
QString path = properties["IconThemePath"].toString();
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() == "icons") {
QString appName = tokens.takeLast();
m_customIconLoader = new KIconLoader(appName, QStringList(), this);
m_customIconLoader->addAppDir(appName, path);
} else {
qWarning() << "Wrong IconThemePath" << path << ": too short or does not end with 'icons'";
}
}
setData("IconThemePath", properties["IconThemePath"]);
setData("IconThemePath", path);
setData("Category", properties["Category"]);
setData("Status", properties["Status"]);
@ -259,7 +249,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
setData("OverlayIconName", iconName);
if (!iconName.isEmpty()) {
overlayNames << iconName;
overlay = KIcon(iconName, iconLoader());
overlay = QIcon(new KIconEngine(iconName, iconLoader()));
}
} else {
overlay = imageVectorToPixmap(image);
@ -269,7 +259,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
if (image.isEmpty()) {
iconName = properties["IconName"].toString();
if (!iconName.isEmpty()) {
icon = KIcon(iconName, iconLoader(), overlayNames);
icon = QIcon(new KIconEngine(iconName, iconLoader()));
if (overlayNames.isEmpty() && !overlay.isNull()) {
overlayIcon(&icon, &overlay);
@ -295,7 +285,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
QString iconName = properties["AttentionIconName"].toString();
setData("AttentionIconName", iconName);
if (!iconName.isEmpty()) {
attentionIcon = KIcon(iconName, iconLoader(), overlayNames);
attentionIcon = QIcon(new KIconEngine(iconName, iconLoader()));
if (overlayNames.isEmpty() && !overlay.isNull()) {
overlayIcon(&attentionIcon, &overlay);
@ -321,7 +311,7 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
} else {
QIcon toolTipIcon;
if (toolTip.image.size() == 0) {
toolTipIcon = KIcon(toolTip.icon, iconLoader());
toolTipIcon = QIcon(new KIconEngine(toolTip.icon, iconLoader()));
} else {
toolTipIcon = imageVectorToPixmap(toolTip.image);
}

Loading…
Cancel
Save