Purpose

devicesmodel.h
1/*
2 SPDX-FileCopyrightText: 2024 Nicolas Fella <nicolas.fella@gmx.de>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#ifndef DEVICESMODEL_H
8#define DEVICESMODEL_H
9
10#include <QAbstractListModel>
11
12#include <QQmlEngine>
13
14#include <memory>
15#include <vector>
16
18class OrgKdeKdeconnectDaemonInterface;
19class OrgKdeKdeconnectDeviceInterface;
20
21class DevicesModel : public QAbstractListModel
22{
24 QML_ELEMENT
25
26public:
27 enum Roles {
28 NameModelRole = Qt::DisplayRole,
29 IconNameRole = Qt::DecorationRole,
30 IdRole = Qt::UserRole + 1,
31 };
32
33 explicit DevicesModel(QObject *parent = nullptr);
34 ~DevicesModel() override;
35
36 QVariant data(const QModelIndex &index, int role) const override;
37 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
38
39 QHash<int, QByteArray> roleNames() const override;
40 int rowForDevice(const QString &id) const;
41
42private Q_SLOTS:
43 void loadDeviceList();
44 void gotDeviceList(QDBusPendingCallWatcher *watcher);
45
46 void deviceAdded(const QString &id);
47 void deviceRemoved(const QString &id);
48 void deviceUpdated(const QString &id);
49
50private:
51 struct DeviceInterface {
52 QString id;
53 std::unique_ptr<OrgKdeKdeconnectDeviceInterface> interface;
54 };
55
56 void clearDevices();
57 void addDevice(DeviceInterface &&dev);
58
59 OrgKdeKdeconnectDaemonInterface *m_daemonInterface;
60 std::vector<DeviceInterface> m_devices;
61};
62
63#endif
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:49:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.