File indexing completed on 2024-04-28 15:17:51

0001 /*
0002  * BluezQt - Asynchronous BlueZ wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #ifndef BLUEZQT_DEVICESMODEL_H
0010 #define BLUEZQT_DEVICESMODEL_H
0011 
0012 #include <QAbstractListModel>
0013 
0014 #include "bluezqt_export.h"
0015 #include "types.h"
0016 
0017 namespace BluezQt
0018 {
0019 class Manager;
0020 class Device;
0021 
0022 /**
0023  * @class BluezQt::DevicesModel devicesmodel.h <BluezQt/DevicesModel>
0024  *
0025  * Model of all devices.
0026  *
0027  * This class represents a model of all devices.
0028  *
0029  * Example use in QML code:
0030  * @code
0031  * import org.kde.bluezqt 1.0 as BluezQt
0032  *
0033  * ListView {
0034  *     model: BluezQt.DevicesModel { }
0035  *     delegate: Text {
0036  *         text: "%1 (%2)".arg(Name).arg(Address)
0037  *     }
0038  * }
0039  * @endcode
0040  */
0041 class BLUEZQT_EXPORT DevicesModel : public QAbstractListModel
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /**
0047      * Device data roles.
0048      */
0049     enum DeviceRoles {
0050         /** UBI of the device (QString) */
0051         UbiRole = Qt::UserRole + 100,
0052         /** Address of the device (QString) */
0053         AddressRole = Qt::UserRole + 101,
0054         /** Name of the device (QString) */
0055         NameRole = Qt::UserRole + 102,
0056         /** Friendly name of the device (QString) */
0057         FriendlyNameRole = Qt::UserRole + 103,
0058         /** Remote name of the device (QString) */
0059         RemoteNameRole = Qt::UserRole + 104,
0060         /** Class of the device (quint32) */
0061         ClassRole = Qt::UserRole + 105,
0062         /** Type of the device (Device::Type) */
0063         TypeRole = Qt::UserRole + 106,
0064         /** Appearance of the device (quint16) */
0065         AppearanceRole = Qt::UserRole + 107,
0066         /** Icon name of the device (QString) */
0067         IconRole = Qt::UserRole + 108,
0068         /** Indicates whether the device is paired (bool) */
0069         PairedRole = Qt::UserRole + 109,
0070         /** Indicates whether the device is trusted (bool) */
0071         TrustedRole = Qt::UserRole + 110,
0072         /** Indicates whether the device is blocked (bool) */
0073         BlockedRole = Qt::UserRole + 111,
0074         /** Indicates whether the device has legacy pairing (bool) */
0075         LegacyPairingRole = Qt::UserRole + 112,
0076         /** Received Signal Strength Indicator of the device (qint16) */
0077         RssiRole = Qt::UserRole + 113,
0078         /** Indicates whether the device is connected (bool) */
0079         ConnectedRole = Qt::UserRole + 114,
0080         /** UUIDs of supported services by the device (QStringList) */
0081         UuidsRole = Qt::UserRole + 115,
0082         /** Modalias of the device (QString) */
0083         ModaliasRole = Qt::UserRole + 116,
0084         /** Name of the associated adapter (QString) */
0085         AdapterNameRole = Qt::UserRole + 117,
0086         /** Address of the associated adapter (QString) */
0087         AdapterAddressRole = Qt::UserRole + 118,
0088         /** Indicates whether the associated adapter is powered (bool) */
0089         AdapterPoweredRole = Qt::UserRole + 119,
0090         /** Indicates whether the associated adapter is discoverable (bool) */
0091         AdapterDiscoverableRole = Qt::UserRole + 120,
0092         /** Indicates whether the associated adapter is pairable (bool) */
0093         AdapterPairableRole = Qt::UserRole + 121,
0094         /** Indicates whether the associated adapter is discovering (bool) */
0095         AdapterDiscoveringRole = Qt::UserRole + 122,
0096         /** UUIDs of supported services by the associated adapter (QStringList) */
0097         AdapterUuidsRole = Qt::UserRole + 123,
0098         /** Last role used by DevicesModel */
0099         LastRole = Qt::UserRole + 124,
0100     };
0101 
0102     /**
0103      * Creates a new DevicesModel object.
0104      *
0105      * @param manager manager to be used
0106      * @param parent
0107      */
0108     explicit DevicesModel(Manager *manager, QObject *parent = nullptr);
0109 
0110     /**
0111      * Destroys a DevicesModel object.
0112      */
0113     ~DevicesModel() override;
0114 
0115     /**
0116      * Reimplemented from QAbstractListModel::roleNames()
0117      */
0118     QHash<int, QByteArray> roleNames() const override;
0119 
0120     /**
0121      * Reimplemented from QAbstractListModel::rowCount()
0122      */
0123     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0124 
0125     /**
0126      * Reimplemented from QAbstractListModel::data()
0127      */
0128     QVariant data(const QModelIndex &index, int role) const override;
0129 
0130     /**
0131      * Reimplemented from QAbstractListModel::index()
0132      */
0133     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0134 
0135     /**
0136      * Returns a device for specified index.
0137      *
0138      * @param index index in model
0139      * @return device object
0140      */
0141     DevicePtr device(const QModelIndex &index) const;
0142 
0143 private:
0144     class DevicesModelPrivate *const d;
0145 
0146     friend class DevicesModelPrivate;
0147 };
0148 
0149 } // namespace BluezQt
0150 
0151 #endif // BLUEZQT_DEVICESMODEL_H