| 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 DECLARATIVEMANAGER_H |
| 10 | #define DECLARATIVEMANAGER_H |
| 11 | |
| 12 | #include <QHash> |
| 13 | #include <QQmlEngine> |
| 14 | #include <QQmlListProperty> |
| 15 | |
| 16 | #include "manager.h" |
| 17 | |
| 18 | class DeclarativeDevice; |
| 19 | class DeclarativeAdapter; |
| 20 | |
| 21 | class DeclarativeManager : public BluezQt::Manager |
| 22 | { |
| 23 | Q_OBJECT |
| 24 | QML_NAMED_ELEMENT(Manager) |
| 25 | QML_SINGLETON |
| 26 | Q_PROPERTY(DeclarativeAdapter *usableAdapter READ usableAdapter NOTIFY usableAdapterChanged) |
| 27 | Q_PROPERTY(QQmlListProperty<DeclarativeAdapter> adapters READ declarativeAdapters NOTIFY adaptersChanged) |
| 28 | Q_PROPERTY(QQmlListProperty<DeclarativeDevice> devices READ declarativeDevices NOTIFY devicesChanged) |
| 29 | Q_PROPERTY(QQmlListProperty<DeclarativeDevice> connectedDevices READ declarativeConnectedDevices NOTIFY connectedDevicesChanged) |
| 30 | |
| 31 | public: |
| 32 | explicit DeclarativeManager(QObject *parent = nullptr); |
| 33 | |
| 34 | DeclarativeAdapter *usableAdapter() const; |
| 35 | QQmlListProperty<DeclarativeAdapter> declarativeAdapters(); |
| 36 | QQmlListProperty<DeclarativeDevice> declarativeDevices(); |
| 37 | QQmlListProperty<DeclarativeDevice> declarativeConnectedDevices(); |
| 38 | |
| 39 | DeclarativeAdapter *declarativeAdapterFromPtr(BluezQt::AdapterPtr ptr) const; |
| 40 | DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const; |
| 41 | |
| 42 | QHash<QString, DeclarativeAdapter *> m_adapters; |
| 43 | QHash<QString, DeclarativeDevice *> m_devices; |
| 44 | |
| 45 | public Q_SLOTS: |
| 46 | DeclarativeAdapter *adapterForAddress(const QString &address) const; |
| 47 | DeclarativeAdapter *adapterForUbi(const QString &ubi) const; |
| 48 | DeclarativeDevice *deviceForAddress(const QString &address) const; |
| 49 | DeclarativeDevice *deviceForUbi(const QString &ubi) const; |
| 50 | |
| 51 | Q_SIGNALS: |
| 52 | void initFinished(); |
| 53 | void initError(const QString &errorText); |
| 54 | void adapterAdded(DeclarativeAdapter *adapter); |
| 55 | void adapterRemoved(DeclarativeAdapter *adapter); |
| 56 | void adapterChanged(DeclarativeAdapter *adapter); |
| 57 | void deviceAdded(DeclarativeDevice *device); |
| 58 | void deviceRemoved(DeclarativeDevice *device); |
| 59 | void deviceChanged(DeclarativeDevice *device); |
| 60 | void usableAdapterChanged(DeclarativeAdapter *adapter); |
| 61 | |
| 62 | void adaptersChanged(QQmlListProperty<DeclarativeAdapter> adapters); |
| 63 | void devicesChanged(QQmlListProperty<DeclarativeDevice> devices); |
| 64 | void connectedDevicesChanged(QQmlListProperty<DeclarativeDevice> devices); |
| 65 | |
| 66 | private Q_SLOTS: |
| 67 | void initJobResult(BluezQt::InitManagerJob *job); |
| 68 | |
| 69 | void slotAdapterAdded(BluezQt::AdapterPtr adapter); |
| 70 | void slotAdapterRemoved(BluezQt::AdapterPtr adapter); |
| 71 | void slotDeviceAdded(BluezQt::DevicePtr device); |
| 72 | void slotDeviceRemoved(BluezQt::DevicePtr device); |
| 73 | void slotUsableAdapterChanged(BluezQt::AdapterPtr adapter); |
| 74 | void slotDeviceConnectedChanged(); |
| 75 | }; |
| 76 | |
| 77 | #endif // DECLARATIVEMANAGER_H |
| 78 | |