1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 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 DECLARATIVEADAPTER_H
10#define DECLARATIVEADAPTER_H
11
12#include <QQmlListProperty>
13#include <qqmlregistration.h>
14
15#include "adapter.h"
16#include "declarativedevice.h"
17#include "pendingcall.h"
18
19class DeclarativeAdapter : public QObject
20{
21 Q_OBJECT
22 QML_NAMED_ELEMENT(Adapter)
23 QML_UNCREATABLE("Adapter cannot be created")
24
25 Q_PROPERTY(QString ubi READ ubi CONSTANT)
26 Q_PROPERTY(QString address READ address CONSTANT)
27 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
28 Q_PROPERTY(QString systemName READ systemName NOTIFY systemNameChanged)
29 Q_PROPERTY(quint32 adapterClass READ adapterClass NOTIFY adapterClassChanged)
30 Q_PROPERTY(bool powered READ isPowered WRITE setPowered NOTIFY poweredChanged)
31 Q_PROPERTY(bool discoverable READ isDiscoverable WRITE setDiscoverable NOTIFY discoverableChanged)
32 Q_PROPERTY(quint32 discoverableTimeout READ discoverableTimeout WRITE setDiscoverableTimeout NOTIFY discoverableTimeoutChanged)
33 Q_PROPERTY(bool pairable READ isPairable WRITE setPairable NOTIFY pairableChanged)
34 Q_PROPERTY(quint32 pairableTimeout READ pairableTimeout WRITE setPairableTimeout NOTIFY pairableTimeoutChanged)
35 Q_PROPERTY(bool discovering READ isDiscovering NOTIFY discoveringChanged)
36 Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged)
37 Q_PROPERTY(QString modalias READ modalias NOTIFY modaliasChanged)
38 Q_PROPERTY(QQmlListProperty<DeclarativeDevice> devices READ devices NOTIFY devicesChanged)
39
40public:
41 explicit DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent = nullptr);
42
43 QString ubi() const;
44
45 QString address() const;
46
47 QString name() const;
48 void setName(const QString &name);
49
50 QString systemName() const;
51
52 quint32 adapterClass() const;
53
54 bool isPowered() const;
55 void setPowered(bool powered);
56
57 bool isDiscoverable() const;
58 void setDiscoverable(bool discoverable);
59
60 quint32 discoverableTimeout() const;
61 void setDiscoverableTimeout(quint32 timeout);
62
63 bool isPairable() const;
64 void setPairable(bool pairable);
65
66 quint32 pairableTimeout() const;
67 void setPairableTimeout(quint32 timeout);
68
69 bool isDiscovering();
70
71 QStringList uuids() const;
72
73 QString modalias() const;
74
75 QQmlListProperty<DeclarativeDevice> devices();
76
77 BluezQt::AdapterPtr m_adapter;
78 QHash<QString, DeclarativeDevice *> m_devices;
79
80public Q_SLOTS:
81 DeclarativeDevice *deviceForAddress(const QString &address) const;
82 BluezQt::PendingCall *startDiscovery();
83 BluezQt::PendingCall *stopDiscovery();
84 BluezQt::PendingCall *removeDevice(DeclarativeDevice *device);
85
86Q_SIGNALS:
87 void adapterRemoved(DeclarativeAdapter *adapter);
88 void adapterChanged(DeclarativeAdapter *adapter);
89 void nameChanged(const QString &name);
90 void systemNameChanged(const QString &name);
91 void adapterClassChanged(quint32 adapterClass);
92 void poweredChanged(bool powered);
93 void discoverableChanged(bool discoverable);
94 void discoverableTimeoutChanged(quint32 timeout);
95 void pairableChanged(bool pairable);
96 void pairableTimeoutChanged(quint32 timeout);
97 void discoveringChanged(bool discovering);
98 void uuidsChanged(const QStringList &uuids);
99 void modaliasChanged(const QString &modalias);
100 void deviceFound(DeclarativeDevice *device);
101 void deviceRemoved(DeclarativeDevice *device);
102 void deviceChanged(DeclarativeDevice *device);
103
104 void devicesChanged(QQmlListProperty<DeclarativeDevice> devices);
105
106private Q_SLOTS:
107 void slotDeviceAdded(BluezQt::DevicePtr device);
108 void slotDeviceRemoved(BluezQt::DevicePtr device);
109
110private:
111 DeclarativeDevice *declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const;
112};
113
114#endif // DECLARATIVEADAPTER_H
115

source code of bluez-qt/src/imports/declarativeadapter.h