File indexing completed on 2024-05-05 03:52:28

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