mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2025-11-06 19:14:57 +11:00
service/tray: account for more edge cases and add placeholder img
This commit is contained in:
parent
54bf485101
commit
61812343f5
7 changed files with 117 additions and 35 deletions
|
|
@ -6,26 +6,37 @@
|
|||
#include <qsize.h>
|
||||
#include <qstring.h>
|
||||
|
||||
#include "../../core/iconimageprovider.hpp"
|
||||
#include "host.hpp"
|
||||
|
||||
namespace qs::service::sni {
|
||||
|
||||
QPixmap
|
||||
TrayImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
|
||||
auto split = id.split('/');
|
||||
if (split.size() != 2) {
|
||||
QPixmap pixmap;
|
||||
|
||||
auto targetSize = requestedSize.isValid() ? requestedSize : QSize(100, 100);
|
||||
if (targetSize.width() == 0 || targetSize.height() == 0) targetSize = QSize(2, 2);
|
||||
|
||||
auto lastSplit = id.lastIndexOf('/');
|
||||
if (lastSplit == -1) {
|
||||
qCWarning(logStatusNotifierHost) << "Invalid image request:" << id;
|
||||
return QPixmap();
|
||||
} else {
|
||||
auto path = id.sliced(0, lastSplit);
|
||||
|
||||
auto* item = StatusNotifierHost::instance()->itemByService(path);
|
||||
|
||||
if (item == nullptr) {
|
||||
qCWarning(logStatusNotifierHost) << "Image requested for nonexistant service" << path;
|
||||
} else {
|
||||
pixmap = item->createPixmap(targetSize);
|
||||
}
|
||||
}
|
||||
|
||||
auto* item = StatusNotifierHost::instance()->itemByService(split[0]);
|
||||
|
||||
if (item == nullptr) {
|
||||
qCWarning(logStatusNotifierHost) << "Image requested for nonexistant service" << split[0];
|
||||
return QPixmap();
|
||||
if (pixmap.isNull()) {
|
||||
pixmap = IconImageProvider::missingPixmap(targetSize);
|
||||
}
|
||||
|
||||
auto pixmap = item->createPixmap(requestedSize);
|
||||
if (size != nullptr) *size = pixmap.size();
|
||||
return pixmap;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue