BluezQt

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

KDE's Doxygen guidelines are available online.