service/tray: log icon render failures due to IconThemePath

This commit is contained in:
outfoxxed 2024-04-29 18:16:04 -07:00
parent 1f49c55711
commit c71fdd62d0
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 33 additions and 7 deletions

View file

@ -10,7 +10,19 @@
QPixmap
IconImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
auto icon = QIcon::fromTheme(id);
QString iconName;
QString path;
auto splitIdx = id.indexOf("?path=");
if (splitIdx != -1) {
iconName = id.sliced(0, splitIdx);
path = id.sliced(splitIdx + 6);
qWarning() << "Searching custom icon paths is not yet supported. Icon path will be ignored for"
<< id;
} else {
iconName = id;
}
auto icon = QIcon::fromTheme(iconName);
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
@ -42,3 +54,13 @@ QPixmap IconImageProvider::missingPixmap(const QSize& size) {
painter.fillRect(0, halfHeight, halfWidth, halfHeight, purple);
return pixmap;
}
QString IconImageProvider::requestString(const QString& icon, const QString& path) {
auto req = "image://icon/" + icon;
if (!path.isEmpty()) {
req += "?path=" + path;
}
return req;
}

View file

@ -10,4 +10,5 @@ public:
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
static QPixmap missingPixmap(const QSize& size);
static QString requestString(const QString& icon, const QString& path);
};

View file

@ -15,6 +15,7 @@
#include <qstring.h>
#include <qtmetamacros.h>
#include "../../core/iconimageprovider.hpp"
#include "../../dbus/dbusutil.hpp"
#include "dbus_item.h"
#include "dbus_item_types.hpp"
@ -49,15 +50,16 @@ StatusNotifierItem::StatusNotifierItem(const QString& address, QObject* parent)
QObject::connect(this->item, &DBusStatusNotifierItem::NewTitle, &this->title, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconName, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconPixmaps, &AbstractDBusProperty::update);
//QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconName, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->overlayIconPixmaps, &AbstractDBusProperty::update);
//QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewOverlayIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconName, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->attentionIconPixmaps, &AbstractDBusProperty::update);
//QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewAttentionIcon, &this->iconThemePath, &AbstractDBusProperty::update);
QObject::connect(this->item, &DBusStatusNotifierItem::NewToolTip, &this->tooltip, &AbstractDBusProperty::update);
QObject::connect(&this->iconThemePath, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
QObject::connect(&this->iconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
QObject::connect(&this->attentionIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
QObject::connect(&this->overlayIconName, &AbstractDBusProperty::changed, this, &StatusNotifierItem::updateIcon);
@ -83,11 +85,12 @@ bool StatusNotifierItem::isReady() const { return this->mReady; }
QString StatusNotifierItem::iconId() const {
if (this->status.get() == "NeedsAttention") {
auto name = this->attentionIconName.get();
if (!name.isEmpty()) return QString("image://icon/") + name;
if (!name.isEmpty()) return IconImageProvider::requestString(name, this->iconThemePath.get());
} else {
auto name = this->iconName.get();
auto overlayName = this->overlayIconName.get();
if (!name.isEmpty() && overlayName.isEmpty()) return QString("image://icon/") + name;
if (!name.isEmpty() && overlayName.isEmpty())
return IconImageProvider::requestString(name, this->iconThemePath.get());
}
return QString("image://service.sni/") + this->watcherId + "/" + QString::number(this->iconIndex);

View file

@ -39,7 +39,7 @@ public:
dbus::DBusProperty<QString> status {this->properties, "Status"};
dbus::DBusProperty<QString> category {this->properties, "Category"};
dbus::DBusProperty<quint32> windowId {this->properties, "WindowId"};
//dbus::DBusProperty<QString> iconThemePath {this->properties, "IconThemePath"};
dbus::DBusProperty<QString> iconThemePath {this->properties, "IconThemePath"};
dbus::DBusProperty<QString> iconName {this->properties, "IconName"};
dbus::DBusProperty<DBusSniIconPixmapList> iconPixmaps {this->properties, "IconPixmap"};
dbus::DBusProperty<QString> overlayIconName {this->properties, "OverlayIconName"};