1 | /* |
2 | * BluezQt - Asynchronous BlueZ wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #ifndef BLUEZQT_DEVICESMODEL_H |
10 | #define BLUEZQT_DEVICESMODEL_H |
11 | |
12 | #include <QAbstractListModel> |
13 | |
14 | #include "bluezqt_export.h" |
15 | #include "types.h" |
16 | |
17 | #include <memory> |
18 | |
19 | namespace BluezQt |
20 | { |
21 | class Manager; |
22 | class Device; |
23 | |
24 | /*! |
25 | * \inmodule BluezQt |
26 | * \class BluezQt::DevicesModel |
27 | * \inheaderfile BluezQt/DevicesModel |
28 | * |
29 | * \brief Model of all devices. |
30 | * |
31 | * This class represents a model of all devices. |
32 | * |
33 | * Example use in QML code: |
34 | * \code |
35 | * import org.kde.bluezqt 1.0 as BluezQt |
36 | * |
37 | * ListView { |
38 | * model: BluezQt.DevicesModel { } |
39 | * delegate: Text { |
40 | * text: "%1 (%2)".arg(Name).arg(Address) |
41 | * } |
42 | * } |
43 | * \endcode |
44 | */ |
45 | class BLUEZQT_EXPORT DevicesModel : public QAbstractListModel |
46 | { |
47 | Q_OBJECT |
48 | |
49 | public: |
50 | /*! |
51 | * Device data roles. |
52 | * |
53 | * \value UbiRole |
54 | * UBI of the device (QString). |
55 | * \value AddressRole |
56 | * Address of the device (QString). |
57 | * \value NameRole |
58 | * Name of the device (QString). |
59 | * \value FriendlyNameRole |
60 | * Friendly name of the device (QString). |
61 | * \value RemoteNameRole |
62 | * Remote name of the device (QString). |
63 | * \value ClassRole |
64 | * Class of the device (quint32). |
65 | * \value TypeRole |
66 | * Type of the device (Device::Type). |
67 | * \value AppearanceRole |
68 | * Appearance of the device (quint16). |
69 | * \value IconRole |
70 | * Icon name of the device (QString). |
71 | * \value PairedRole |
72 | * Indicates whether the device is paired (bool). |
73 | * \value TrustedRole |
74 | * Indicates whether the device is trusted (bool). |
75 | * \value BlockedRole |
76 | * Indicates whether the device is blocked (bool). |
77 | * \value LegacyPairingRole |
78 | * Indicates whether the device has legacy pairing (bool). |
79 | * \value RssiRole |
80 | * Received Signal Strength Indicator of the device (qint16). |
81 | * \value ConnectedRole |
82 | * Indicates whether the device is connected (bool). |
83 | * \value UuidsRole |
84 | * UUIDs of supported services by the device (QStringList). |
85 | * \value ModaliasRole |
86 | * Modalias of the device (QString). |
87 | * \value AdapterNameRole |
88 | * Name of the associated adapter (QString). |
89 | * \value AdapterAddressRole |
90 | * Address of the associated adapter (QString). |
91 | * \value AdapterPoweredRole |
92 | * Indicates whether the associated adapter is powered (bool). |
93 | * \value AdapterDiscoverableRole |
94 | * Indicates whether the associated adapter is discoverable (bool). |
95 | * \value AdapterPairableRole |
96 | * Indicates whether the associated adapter is pairable (bool). |
97 | * \value AdapterDiscoveringRole |
98 | * Indicates whether the associated adapter is discovering (bool). |
99 | * \value AdapterUuidsRole |
100 | * UUIDs of supported services by the associated adapter (QStringList). |
101 | * \value LastRole |
102 | * Last role used by DevicesModel. |
103 | */ |
104 | enum DeviceRoles { |
105 | UbiRole = Qt::UserRole + 100, |
106 | AddressRole = Qt::UserRole + 101, |
107 | NameRole = Qt::UserRole + 102, |
108 | FriendlyNameRole = Qt::UserRole + 103, |
109 | RemoteNameRole = Qt::UserRole + 104, |
110 | ClassRole = Qt::UserRole + 105, |
111 | TypeRole = Qt::UserRole + 106, |
112 | AppearanceRole = Qt::UserRole + 107, |
113 | IconRole = Qt::UserRole + 108, |
114 | PairedRole = Qt::UserRole + 109, |
115 | TrustedRole = Qt::UserRole + 110, |
116 | BlockedRole = Qt::UserRole + 111, |
117 | LegacyPairingRole = Qt::UserRole + 112, |
118 | = Qt::UserRole + 113, |
119 | ConnectedRole = Qt::UserRole + 114, |
120 | UuidsRole = Qt::UserRole + 115, |
121 | ModaliasRole = Qt::UserRole + 116, |
122 | AdapterNameRole = Qt::UserRole + 117, |
123 | AdapterAddressRole = Qt::UserRole + 118, |
124 | AdapterPoweredRole = Qt::UserRole + 119, |
125 | AdapterDiscoverableRole = Qt::UserRole + 120, |
126 | AdapterPairableRole = Qt::UserRole + 121, |
127 | AdapterDiscoveringRole = Qt::UserRole + 122, |
128 | AdapterUuidsRole = Qt::UserRole + 123, |
129 | LastRole = Qt::UserRole + 124, |
130 | }; |
131 | |
132 | /*! |
133 | * Creates a new DevicesModel object using the given \a manager as a child of \a parent. |
134 | */ |
135 | explicit DevicesModel(Manager *manager, QObject *parent = nullptr); |
136 | |
137 | ~DevicesModel() override; |
138 | |
139 | QHash<int, QByteArray> roleNames() const override; |
140 | |
141 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
142 | |
143 | QVariant data(const QModelIndex &index, int role) const override; |
144 | |
145 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
146 | |
147 | /*! |
148 | * Returns a device object for the specified \a index in the model. |
149 | */ |
150 | DevicePtr device(const QModelIndex &index) const; |
151 | |
152 | private: |
153 | std::unique_ptr<class DevicesModelPrivate> const d; |
154 | |
155 | friend class DevicesModelPrivate; |
156 | }; |
157 | |
158 | } // namespace BluezQt |
159 | |
160 | #endif // BLUEZQT_DEVICESMODEL_H |
161 | |