BluezQt

declarativedevice.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 "declarativedevice.h"
10#include "declarativeadapter.h"
11#include "declarativebattery.h"
12#include "declarativeinput.h"
13#include "declarativemediaplayer.h"
14
15#include <QStringList>
16
17DeclarativeDevice::DeclarativeDevice(BluezQt::DevicePtr device, DeclarativeAdapter *adapter)
18 : QObject(adapter)
19 , m_device(device)
20 , m_adapter(adapter)
21 , m_battery(nullptr)
22 , m_input(nullptr)
23 , m_mediaPlayer(nullptr)
24{
25 connect(m_device.data(), &BluezQt::Device::nameChanged, this, &DeclarativeDevice::nameChanged);
26 connect(m_device.data(), &BluezQt::Device::friendlyNameChanged, this, &DeclarativeDevice::friendlyNameChanged);
27 connect(m_device.data(), &BluezQt::Device::remoteNameChanged, this, &DeclarativeDevice::remoteNameChanged);
28 connect(m_device.data(), &BluezQt::Device::deviceClassChanged, this, &DeclarativeDevice::deviceClassChanged);
29 connect(m_device.data(), &BluezQt::Device::typeChanged, this, &DeclarativeDevice::typeChanged);
30 connect(m_device.data(), &BluezQt::Device::appearanceChanged, this, &DeclarativeDevice::appearanceChanged);
31 connect(m_device.data(), &BluezQt::Device::iconChanged, this, &DeclarativeDevice::iconChanged);
32 connect(m_device.data(), &BluezQt::Device::pairedChanged, this, &DeclarativeDevice::pairedChanged);
33 connect(m_device.data(), &BluezQt::Device::trustedChanged, this, &DeclarativeDevice::trustedChanged);
34 connect(m_device.data(), &BluezQt::Device::blockedChanged, this, &DeclarativeDevice::blockedChanged);
35 connect(m_device.data(), &BluezQt::Device::legacyPairingChanged, this, &DeclarativeDevice::legacyPairingChanged);
36 connect(m_device.data(), &BluezQt::Device::rssiChanged, this, &DeclarativeDevice::rssiChanged);
37 connect(m_device.data(), &BluezQt::Device::connectedChanged, this, &DeclarativeDevice::connectedChanged);
38 connect(m_device.data(), &BluezQt::Device::uuidsChanged, this, &DeclarativeDevice::uuidsChanged);
39 connect(m_device.data(), &BluezQt::Device::modaliasChanged, this, &DeclarativeDevice::modaliasChanged);
40 connect(m_device.data(), &BluezQt::Device::mediaPlayerChanged, this, &DeclarativeDevice::updateMediaPlayer);
41 connect(m_device.data(), &BluezQt::Device::inputChanged, this, &DeclarativeDevice::updateInput);
42 connect(m_device.data(), &BluezQt::Device::batteryChanged, this, &DeclarativeDevice::updateBattery);
43
44 connect(m_device.data(), &BluezQt::Device::deviceRemoved, this, [this]() {
45 Q_EMIT deviceRemoved(this);
46 });
47
48 connect(m_device.data(), &BluezQt::Device::deviceChanged, this, [this]() {
49 Q_EMIT deviceChanged(this);
50 });
51
52 updateInput();
53 updateMediaPlayer();
54}
55
56QString DeclarativeDevice::ubi() const
57{
58 return m_device->ubi();
59}
60
61QString DeclarativeDevice::address() const
62{
63 return m_device->address();
64}
65
66QString DeclarativeDevice::name() const
67{
68 return m_device->name();
69}
70
71void DeclarativeDevice::setName(const QString &name)
72{
73 m_device->setName(name);
74}
75
76QString DeclarativeDevice::friendlyName() const
77{
78 return m_device->friendlyName();
79}
80
81QString DeclarativeDevice::remoteName() const
82{
83 return m_device->remoteName();
84}
85
86quint32 DeclarativeDevice::deviceClass() const
87{
88 return m_device->deviceClass();
89}
90
91BluezQt::Device::Type DeclarativeDevice::type() const
92{
93 return m_device->type();
94}
95
96quint16 DeclarativeDevice::appearance() const
97{
98 return m_device->appearance();
99}
100
101QString DeclarativeDevice::icon() const
102{
103 return m_device->icon();
104}
105
106bool DeclarativeDevice::isPaired() const
107{
108 return m_device->isPaired();
109}
110
111bool DeclarativeDevice::isTrusted() const
112{
113 return m_device->isTrusted();
114}
115
116void DeclarativeDevice::setTrusted(bool trusted)
117{
118 m_device->setTrusted(trusted);
119}
120
121bool DeclarativeDevice::isBlocked() const
122{
123 return m_device->isBlocked();
124}
125
126void DeclarativeDevice::setBlocked(bool blocked)
127{
128 m_device->setBlocked(blocked);
129}
130
131bool DeclarativeDevice::hasLegacyPairing() const
132{
133 return m_device->hasLegacyPairing();
134}
135
136qint16 DeclarativeDevice::rssi() const
137{
138 return m_device->rssi();
139}
140
141bool DeclarativeDevice::isConnected() const
142{
143 return m_device->isConnected();
144}
145
146QStringList DeclarativeDevice::uuids() const
147{
148 return m_device->uuids();
149}
150
151QString DeclarativeDevice::modalias() const
152{
153 return m_device->modalias();
154}
155
156DeclarativeBattery *DeclarativeDevice::battery() const
157{
158 return m_battery;
159}
160
161DeclarativeInput *DeclarativeDevice::input() const
162{
163 return m_input;
164}
165
166DeclarativeMediaPlayer *DeclarativeDevice::mediaPlayer() const
167{
168 return m_mediaPlayer;
169}
170
171DeclarativeAdapter *DeclarativeDevice::adapter() const
172{
173 return m_adapter;
174}
175
176BluezQt::PendingCall *DeclarativeDevice::connectToDevice()
177{
178 return m_device->connectToDevice();
179}
180
181BluezQt::PendingCall *DeclarativeDevice::disconnectFromDevice()
182{
183 return m_device->disconnectFromDevice();
184}
185
186BluezQt::PendingCall *DeclarativeDevice::connectProfile(const QString &uuid)
187{
188 return m_device->connectProfile(uuid);
189}
190
191BluezQt::PendingCall *DeclarativeDevice::disconnectProfile(const QString &uuid)
192{
193 return m_device->disconnectProfile(uuid);
194}
195
196BluezQt::PendingCall *DeclarativeDevice::pair()
197{
198 return m_device->pair();
199}
200
201BluezQt::PendingCall *DeclarativeDevice::cancelPairing()
202{
203 return m_device->cancelPairing();
204}
205
206void DeclarativeDevice::updateBattery()
207{
208 if (m_battery) {
209 m_battery->deleteLater();
210 m_battery = nullptr;
211 }
212
213 if (m_device->battery()) {
214 m_battery = new DeclarativeBattery(m_device->battery(), this);
215 }
216
217 Q_EMIT batteryChanged(m_battery);
218}
219
220void DeclarativeDevice::updateInput()
221{
222 if (m_input) {
223 m_input->deleteLater();
224 m_input = nullptr;
225 }
226
227 if (m_device->input()) {
228 m_input = new DeclarativeInput(m_device->input(), this);
229 }
230
231 Q_EMIT inputChanged(m_input);
232}
233
234void DeclarativeDevice::updateMediaPlayer()
235{
236 if (m_mediaPlayer) {
237 m_mediaPlayer->deleteLater();
238 m_mediaPlayer = nullptr;
239 }
240
241 if (m_device->mediaPlayer()) {
242 m_mediaPlayer = new DeclarativeMediaPlayer(m_device->mediaPlayer(), this);
243 }
244
245 Q_EMIT mediaPlayerChanged(m_mediaPlayer);
246}
247
248#include "moc_declarativedevice.cpp"
void nameChanged(const QString &name)
Indicates that device's name have changed.
void modaliasChanged(const QString &modalias)
Indicates that device's modalias have changed.
Type
Device types.
Definition device.h:65
void deviceRemoved(DevicePtr device)
Indicates that the device was removed.
void typeChanged(Type type)
Indicates that device's type have changed.
void trustedChanged(bool trusted)
Indicates that device's trusted state have changed.
void inputChanged(InputPtr input)
Indicates that device's input have changed.
void blockedChanged(bool blocked)
Indicates that device's blocked state have changed.
void iconChanged(const QString &icon)
Indicates that device's icon have changed.
void mediaPlayerChanged(MediaPlayerPtr mediaPlayer)
Indicates that device's media player have changed.
void appearanceChanged(quint16 appearance)
Indicates that device's appearance have changed.
void legacyPairingChanged(bool legacyPairing)
Indicates that device's legacy pairing state have changed.
void friendlyNameChanged(const QString &friendlyName)
Indicates that device's friendly name have changed.
void rssiChanged(qint16 rssi)
Indicates that device's RSSI have changed.
void remoteNameChanged(const QString &remoteName)
Indicates that device's remote name have changed.
void connectedChanged(bool connected)
Indicates that device's connected state have changed.
void pairedChanged(bool paired)
Indicates that device's paired state have changed.
void deviceClassChanged(quint32 deviceClass)
Indicates that device's class have changed.
void batteryChanged(BatteryPtr battery)
Indicates that device's battery has changed.
void uuidsChanged(const QStringList &uuids)
Indicates that device's UUIDs have changed.
void deviceChanged(DevicePtr device)
Indicates that at least one of the device's properties have changed.
Pending method call.
Definition pendingcall.h:35
Q_EMITQ_EMIT
void deleteLater()
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 Tue Mar 26 2024 11:13:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.