service/tray: provide default sorting for SystemTray.items

Items are first sorted by category, and then by name.
This commit is contained in:
outfoxxed 2025-03-27 13:51:43 -07:00
parent 392f56c40e
commit 69430e3873
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 30 additions and 2 deletions

View file

@ -17,10 +17,20 @@ SystemTray::SystemTray(QObject* parent): QObject(parent) {
// clang-format on
for (auto* item: host->items()) {
this->mItems.insertObject(item);
this->mItems.insertObjectSorted(item, &SystemTray::compareItems);
}
}
void SystemTray::onItemRegistered(StatusNotifierItem* item) { this->mItems.insertObject(item); }
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(
qs::service::sni::StatusNotifierItem* a,
qs::service::sni::StatusNotifierItem* b
) {
return a->category() > b->category() || a->id().compare(b->id(), Qt::CaseInsensitive) >= 0;
}