From 29904c1f8dea8444e9ef8c5b39af69306c23a96a Mon Sep 17 00:00:00 2001 From: Mavroudis Chatzilazaridis Date: Sat, 1 Jun 2024 22:30:02 +0300 Subject: [PATCH] indicator: Sort devices in menu Use `DevicesSortProxyModel` to sort devices before adding them to `menu`. --- indicator/main.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/indicator/main.cpp b/indicator/main.cpp index eec24c837..16c437416 100644 --- a/indicator/main.cpp +++ b/indicator/main.cpp @@ -28,6 +28,7 @@ #include "deviceindicator.h" #include "interfaces/dbusinterfaces.h" #include "interfaces/devicesmodel.h" +#include "interfaces/devicessortproxymodel.h" #include "kdeconnect-version.h" #include @@ -79,13 +80,15 @@ int main(int argc, char **argv) DevicesModel model; model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired); + DevicesSortProxyModel proxyModel; + proxyModel.setSourceModel(&model); QMenu *menu = new QMenu; QPointer dialog; DaemonDbusInterface iface; - auto refreshMenu = [&iface, &model, &menu, &dialog]() { + auto refreshMenu = [&iface, &proxyModel, &menu, &dialog]() { menu->clear(); auto configure = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure...")); QObject::connect(configure, &QAction::triggered, configure, [&dialog]() { @@ -100,8 +103,12 @@ int main(int argc, char **argv) dialog->activateWindow(); } }); - for (int i = 0, count = model.rowCount(); i < count; ++i) { - DeviceDbusInterface *device = model.getDevice(i); + for (int i = 0, count = proxyModel.rowCount(); i < count; ++i) { + QObject *deviceObject = proxyModel.data(proxyModel.index(i, 0), DevicesModel::DeviceRole).value(); + DeviceDbusInterface *device = qobject_cast(deviceObject); + if (device == nullptr) + continue; + auto indicator = new DeviceIndicator(device); QObject::connect(device, &DeviceDbusInterface::destroyed, indicator, &QObject::deleteLater);