BluezQt

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