BluezQt

declarativeadapter.cpp
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#include "declarativeadapter.h"
10#include "declarativedevice.h"
11static qsizetype devicesCountDeclarativeAdapterFunction(QQmlListProperty<DeclarativeDevice> *property)
12{
13 Q_ASSERT(qobject_cast<DeclarativeAdapter *>(property->object));
14 DeclarativeAdapter *adapter = static_cast<DeclarativeAdapter *>(property->object);
15
16 return adapter->m_devices.count();
17}
18
19static DeclarativeDevice *devicesAtDeclarativeAdapterFunction(QQmlListProperty<DeclarativeDevice> *property, qsizetype index)
20{
21 Q_ASSERT(qobject_cast<DeclarativeAdapter *>(property->object));
22 DeclarativeAdapter *adapter = static_cast<DeclarativeAdapter *>(property->object);
23
24 return adapter->m_devices.values().at(index);
25}
26
27DeclarativeAdapter::DeclarativeAdapter(BluezQt::AdapterPtr adapter, QObject *parent)
28 : QObject(parent)
29 , m_adapter(adapter)
30{
31 connect(m_adapter.data(), &BluezQt::Adapter::nameChanged, this, &DeclarativeAdapter::nameChanged);
32 connect(m_adapter.data(), &BluezQt::Adapter::systemNameChanged, this, &DeclarativeAdapter::systemNameChanged);
33 connect(m_adapter.data(), &BluezQt::Adapter::adapterClassChanged, this, &DeclarativeAdapter::adapterClassChanged);
34 connect(m_adapter.data(), &BluezQt::Adapter::poweredChanged, this, &DeclarativeAdapter::poweredChanged);
35 connect(m_adapter.data(), &BluezQt::Adapter::discoverableChanged, this, &DeclarativeAdapter::discoverableChanged);
36 connect(m_adapter.data(), &BluezQt::Adapter::discoverableTimeoutChanged, this, &DeclarativeAdapter::discoverableTimeoutChanged);
37 connect(m_adapter.data(), &BluezQt::Adapter::pairableChanged, this, &DeclarativeAdapter::pairableChanged);
38 connect(m_adapter.data(), &BluezQt::Adapter::pairableTimeoutChanged, this, &DeclarativeAdapter::pairableTimeoutChanged);
39 connect(m_adapter.data(), &BluezQt::Adapter::discoveringChanged, this, &DeclarativeAdapter::discoveringChanged);
40 connect(m_adapter.data(), &BluezQt::Adapter::uuidsChanged, this, &DeclarativeAdapter::uuidsChanged);
41 connect(m_adapter.data(), &BluezQt::Adapter::modaliasChanged, this, &DeclarativeAdapter::modaliasChanged);
42
43 connect(m_adapter.data(), &BluezQt::Adapter::deviceAdded, this, &DeclarativeAdapter::slotDeviceAdded);
44 connect(m_adapter.data(), &BluezQt::Adapter::deviceRemoved, this, &DeclarativeAdapter::slotDeviceRemoved);
45
46 connect(m_adapter.data(), &BluezQt::Adapter::adapterRemoved, this, [this]() {
47 Q_EMIT adapterRemoved(this);
48 });
49
50 connect(m_adapter.data(), &BluezQt::Adapter::adapterChanged, this, [this]() {
51 Q_EMIT adapterChanged(this);
52 });
53
54 connect(m_adapter.data(), &BluezQt::Adapter::deviceChanged, this, [this](const BluezQt::DevicePtr &device) {
55 Q_EMIT deviceChanged(declarativeDeviceFromPtr(device));
56 });
57}
58
59QString DeclarativeAdapter::ubi() const
60{
61 return m_adapter->ubi();
62}
63
64QString DeclarativeAdapter::address() const
65{
66 return m_adapter->address();
67}
68
69QString DeclarativeAdapter::name() const
70{
71 return m_adapter->name();
72}
73
74void DeclarativeAdapter::setName(const QString &name)
75{
76 m_adapter->setName(name);
77}
78
79QString DeclarativeAdapter::systemName() const
80{
81 return m_adapter->systemName();
82}
83
84quint32 DeclarativeAdapter::adapterClass() const
85{
86 return m_adapter->adapterClass();
87}
88
89bool DeclarativeAdapter::isPowered() const
90{
91 return m_adapter->isPowered();
92}
93
94void DeclarativeAdapter::setPowered(bool powered)
95{
96 m_adapter->setPowered(powered);
97}
98
99bool DeclarativeAdapter::isDiscoverable() const
100{
101 return m_adapter->isDiscoverable();
102}
103
104void DeclarativeAdapter::setDiscoverable(bool discoverable)
105{
106 m_adapter->setDiscoverable(discoverable);
107}
108
109quint32 DeclarativeAdapter::discoverableTimeout() const
110{
111 return m_adapter->discoverableTimeout();
112}
113
114void DeclarativeAdapter::setDiscoverableTimeout(quint32 timeout)
115{
116 m_adapter->setDiscoverableTimeout(timeout);
117}
118
119bool DeclarativeAdapter::isPairable() const
120{
121 return m_adapter->isPairable();
122}
123
124void DeclarativeAdapter::setPairable(bool pairable)
125{
126 m_adapter->setPairable(pairable);
127}
128
129quint32 DeclarativeAdapter::pairableTimeout() const
130{
131 return m_adapter->pairableTimeout();
132}
133
134void DeclarativeAdapter::setPairableTimeout(quint32 timeout)
135{
136 m_adapter->setPairableTimeout(timeout);
137}
138
139bool DeclarativeAdapter::isDiscovering()
140{
141 return m_adapter->isDiscovering();
142}
143
144QStringList DeclarativeAdapter::uuids() const
145{
146 return m_adapter->uuids();
147}
148
149QString DeclarativeAdapter::modalias() const
150{
151 return m_adapter->modalias();
152}
153
154QQmlListProperty<DeclarativeDevice> DeclarativeAdapter::devices()
155{
156 return QQmlListProperty<DeclarativeDevice>(this, nullptr, devicesCountDeclarativeAdapterFunction, devicesAtDeclarativeAdapterFunction);
157}
158
159DeclarativeDevice *DeclarativeAdapter::deviceForAddress(const QString &address) const
160{
161 return declarativeDeviceFromPtr(m_adapter->deviceForAddress(address));
162}
163
164BluezQt::PendingCall *DeclarativeAdapter::startDiscovery()
165{
166 return m_adapter->startDiscovery();
167}
168
169BluezQt::PendingCall *DeclarativeAdapter::stopDiscovery()
170{
171 return m_adapter->stopDiscovery();
172}
173
174BluezQt::PendingCall *DeclarativeAdapter::removeDevice(DeclarativeDevice *device)
175{
176 return m_adapter->removeDevice(m_adapter->deviceForAddress(device->address()));
177}
178
179void DeclarativeAdapter::slotDeviceAdded(BluezQt::DevicePtr device)
180{
181 Q_EMIT deviceFound(declarativeDeviceFromPtr(device));
182 Q_EMIT devicesChanged(devices());
183}
184
185void DeclarativeAdapter::slotDeviceRemoved(BluezQt::DevicePtr device)
186{
187 Q_EMIT deviceRemoved(declarativeDeviceFromPtr(device));
188 Q_EMIT devicesChanged(devices());
189}
190
191DeclarativeDevice *DeclarativeAdapter::declarativeDeviceFromPtr(BluezQt::DevicePtr ptr) const
192{
193 if (!ptr) {
194 return nullptr;
195 }
196 return m_devices.value(ptr->ubi());
197}
198
199#include "moc_declarativeadapter.cpp"
void deviceChanged(DevicePtr device)
Indicates that at least one of the device's properties have changed.
void adapterChanged(AdapterPtr adapter)
Indicates that at least one of the adapter's properties have changed.
void systemNameChanged(const QString &systemName)
Indicates that adapter's system name have changed.
void nameChanged(const QString &name)
Indicates that adapter's name have changed.
void deviceRemoved(DevicePtr device)
Indicates that a device was removed.
void uuidsChanged(const QStringList &uuids)
Indicates that adapter's UUIDs have changed.
void discoveringChanged(bool discovering)
Indicates that adapter's discovering state have changed.
void adapterClassChanged(quint32 adapterClass)
Indicates that adapter's class have changed.
void pairableTimeoutChanged(quint32 timeout)
Indicates that adapter's pairable timeout have changed.
void poweredChanged(bool powered)
Indicates that adapter's powered state have changed.
void discoverableTimeoutChanged(quint32 timeout)
Indicates that adapter's discoverable timeout have changed.
void pairableChanged(bool pairable)
Indicates that adapter's pairable state have changed.
void deviceAdded(DevicePtr device)
Indicates that a new device was added (eg.
void adapterRemoved(AdapterPtr adapter)
Indicates that the adapter was removed.
void modaliasChanged(const QString &modalias)
Indicates that adapter's modalias have changed.
void discoverableChanged(bool discoverable)
Indicates that adapter's discoverable state have changed.
Pending method call.
qsizetype count() const const
T value(const Key &key) const const
QList< T > values() const const
const_reference at(qsizetype i) const const
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.