quickshell/src/services/status_notifier/qml.cpp
outfoxxed b67f92bc13
all: use BINDABLE only with trivial setters
Fixes various bugs caused by the QML engine bypassing setters
when BINDABLE is specified (even if the bindable is const).
Also restructures all properties using BINDABLE to have
a default READ and WRITE to ensure this doesn't happen again.
2025-05-29 16:08:39 -07:00

35 lines
1.2 KiB
C++

#include "qml.hpp"
#include <qnamespace.h>
#include <qobject.h>
#include "../../core/model.hpp"
#include "host.hpp"
#include "item.hpp"
using namespace qs::service::sni;
SystemTray::SystemTray(QObject* parent): QObject(parent) {
auto* host = StatusNotifierHost::instance();
// clang-format off
QObject::connect(host, &StatusNotifierHost::itemReady, this, &SystemTray::onItemRegistered);
QObject::connect(host, &StatusNotifierHost::itemUnregistered, this, &SystemTray::onItemUnregistered);
// clang-format on
for (auto* item: host->items()) {
this->mItems.insertObjectSorted(item, &SystemTray::compareItems);
}
}
void SystemTray::onItemRegistered(StatusNotifierItem* item) {
this->mItems.insertObjectSorted(item, &SystemTray::compareItems);
}
void SystemTray::onItemUnregistered(StatusNotifierItem* item) { this->mItems.removeObject(item); }
ObjectModel<StatusNotifierItem>* SystemTray::items() { return &this->mItems; }
bool SystemTray::compareItems(StatusNotifierItem* a, StatusNotifierItem* b) {
return a->bindableCategory().value() < b->bindableCategory().value()
|| a->bindableId().value().compare(b->bindableId().value(), Qt::CaseInsensitive) >= 0;
}