indicator: Sort devices in menu
Use `DevicesSortProxyModel` to sort devices before adding them to `menu`.
This commit is contained in:
parent
fef6abe70c
commit
29904c1f8d
1 changed files with 10 additions and 3 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include "deviceindicator.h"
|
#include "deviceindicator.h"
|
||||||
#include "interfaces/dbusinterfaces.h"
|
#include "interfaces/dbusinterfaces.h"
|
||||||
#include "interfaces/devicesmodel.h"
|
#include "interfaces/devicesmodel.h"
|
||||||
|
#include "interfaces/devicessortproxymodel.h"
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
#include <dbushelper.h>
|
#include <dbushelper.h>
|
||||||
|
@ -79,13 +80,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
DevicesModel model;
|
DevicesModel model;
|
||||||
model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired);
|
model.setDisplayFilter(DevicesModel::Reachable | DevicesModel::Paired);
|
||||||
|
DevicesSortProxyModel proxyModel;
|
||||||
|
proxyModel.setSourceModel(&model);
|
||||||
QMenu *menu = new QMenu;
|
QMenu *menu = new QMenu;
|
||||||
|
|
||||||
QPointer<KCMultiDialog> dialog;
|
QPointer<KCMultiDialog> dialog;
|
||||||
|
|
||||||
DaemonDbusInterface iface;
|
DaemonDbusInterface iface;
|
||||||
|
|
||||||
auto refreshMenu = [&iface, &model, &menu, &dialog]() {
|
auto refreshMenu = [&iface, &proxyModel, &menu, &dialog]() {
|
||||||
menu->clear();
|
menu->clear();
|
||||||
auto configure = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure..."));
|
auto configure = menu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure..."));
|
||||||
QObject::connect(configure, &QAction::triggered, configure, [&dialog]() {
|
QObject::connect(configure, &QAction::triggered, configure, [&dialog]() {
|
||||||
|
@ -100,8 +103,12 @@ int main(int argc, char **argv)
|
||||||
dialog->activateWindow();
|
dialog->activateWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (int i = 0, count = model.rowCount(); i < count; ++i) {
|
for (int i = 0, count = proxyModel.rowCount(); i < count; ++i) {
|
||||||
DeviceDbusInterface *device = model.getDevice(i);
|
QObject *deviceObject = proxyModel.data(proxyModel.index(i, 0), DevicesModel::DeviceRole).value<QObject *>();
|
||||||
|
DeviceDbusInterface *device = qobject_cast<DeviceDbusInterface *>(deviceObject);
|
||||||
|
if (device == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
auto indicator = new DeviceIndicator(device);
|
auto indicator = new DeviceIndicator(device);
|
||||||
QObject::connect(device, &DeviceDbusInterface::destroyed, indicator, &QObject::deleteLater);
|
QObject::connect(device, &DeviceDbusInterface::destroyed, indicator, &QObject::deleteLater);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue