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

source code of bluez-qt/src/devicesmodel.h