Skip to content

Commit c71fdd6

Browse files
committed
service/tray: log icon render failures due to IconThemePath
1 parent 1f49c55 commit c71fdd6

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

src/core/iconimageprovider.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,19 @@
1010

1111
QPixmap
1212
IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
13-
auto icon = QIcon::fromTheme(id);
13+
QString iconName;
14+
QString path;
15+
auto splitIdx = id.indexOf("?path=");
16+
if (splitIdx != -1) {
17+
iconName = id.sliced(0, splitIdx);
18+
path = id.sliced(splitIdx + 6);
19+
qWarning() << "Searching custom icon paths is not yet supported. Icon path will be ignored for"
20+
<< id;
21+
} else {
22+
iconName = id;
23+
}
24+
25+
auto icon = QIcon::fromTheme(iconName);
1426

1527
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
1628
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
@@ -42,3 +54,13 @@ QPixmap IconImageProvider::missingPixmap(const QSize& size) {
4254
painter.fillRect(0, halfHeight, halfWidth, halfHeight, purple);
4355
return pixmap;
4456
}
57+
58+
QString IconImageProvider::requestString(const QString& icon, const QString& path) {
59+
auto req = "image://icon/" + icon;
60+
61+
if (!path.isEmpty()) {
62+
req += "?path=" + path;
63+
}
64+
65+
return req;
66+
}

src/core/iconimageprovider.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class IconImageProvider: public QQuickImageProvider {
1010
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
1111

1212
static QPixmap missingPixmap(const QSize& size);
13+
static QString requestString(const QString& icon, const QString& path);
1314
};

src/services/status_notifier/item.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <qstring.h>
1616
#include <qtmetamacros.h>
1717

18+
#include "../../core/iconimageprovider.hpp"
1819
#include "../../dbus/dbusutil.hpp"
1920
#include "dbus_item.h"
2021
#include "dbus_item_types.hpp"
@@ -49,15 +50,16 @@ StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent)
4950
QObject::connect(this->item, &DBusStatusNotifierItem::NewTitle, &this->title, &AbstractDBusProperty::update);
5051
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconName, &AbstractDBusProperty::update);
5152
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconPixmaps, &AbstractDBusProperty::update);
52-
//QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update);
53+
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update);
5354
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconName, &AbstractDBusProperty::update);
5455
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconPixmaps, &AbstractDBusProperty::update);
55-
//QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update);
56+
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update);
5657
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconName, &AbstractDBusProperty::update);
5758
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconPixmaps, &AbstractDBusProperty::update);
58-
//QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update);
59+
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update);
5960
QObject::connect(this->item, &DBusStatusNotifierItem::NewToolTip, &this->tooltip, &AbstractDBusProperty::update);
6061

62+
QObject::connect(&this->iconThemePath, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
6163
QObject::connect(&this->iconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
6264
QObject::connect(&this->attentionIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
6365
QObject::connect(&this->overlayIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
@@ -83,11 +85,12 @@ bool StatusNotifierItem::isReady() const { return this->mReady; }
8385
QString StatusNotifierItem::iconId() const {
8486
if (this->status.get() == "NeedsAttention") {
8587
auto name = this->attentionIconName.get();
86-
if (!name.isEmpty()) return QString("image://icon/") + name;
88+
if (!name.isEmpty()) return IconImageProvider::requestString(name, this->iconThemePath.get());
8789
} else {
8890
auto name = this->iconName.get();
8991
auto overlayName = this->overlayIconName.get();
90-
if (!name.isEmpty() && overlayName.isEmpty()) return QString("image://icon/") + name;
92+
if (!name.isEmpty() && overlayName.isEmpty())
93+
return IconImageProvider::requestString(name, this->iconThemePath.get());
9194
}
9295

9396
return QString("image://service.sni/") + this->watcherId + "/" + QString::number(this->iconIndex);

src/services/status_notifier/item.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class StatusNotifierItem: public QObject {
3939
dbus::DBusProperty<QString> status {this->properties, "Status"};
4040
dbus::DBusProperty<QString> category {this->properties, "Category"};
4141
dbus::DBusProperty<quint32> windowId {this->properties, "WindowId"};
42-
//dbus::DBusProperty<QString> iconThemePath {this->properties, "IconThemePath"};
42+
dbus::DBusProperty<QString> iconThemePath {this->properties, "IconThemePath"};
4343
dbus::DBusProperty<QString> iconName {this->properties, "IconName"};
4444
dbus::DBusProperty<DBusSniIconPixmapList> iconPixmaps {this->properties, "IconPixmap"};
4545
dbus::DBusProperty<QString> overlayIconName {this->properties, "OverlayIconName"};

0 commit comments

Comments
 (0)