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 | |
17 | DeclarativeDevice::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(sender: m_device.data(), signal: &BluezQt::Device::nameChanged, context: this, slot: &DeclarativeDevice::nameChanged); |
26 | connect(sender: m_device.data(), signal: &BluezQt::Device::friendlyNameChanged, context: this, slot: &DeclarativeDevice::friendlyNameChanged); |
27 | connect(sender: m_device.data(), signal: &BluezQt::Device::remoteNameChanged, context: this, slot: &DeclarativeDevice::remoteNameChanged); |
28 | connect(sender: m_device.data(), signal: &BluezQt::Device::deviceClassChanged, context: this, slot: &DeclarativeDevice::deviceClassChanged); |
29 | connect(sender: m_device.data(), signal: &BluezQt::Device::typeChanged, context: this, slot: &DeclarativeDevice::typeChanged); |
30 | connect(sender: m_device.data(), signal: &BluezQt::Device::appearanceChanged, context: this, slot: &DeclarativeDevice::appearanceChanged); |
31 | connect(sender: m_device.data(), signal: &BluezQt::Device::iconChanged, context: this, slot: &DeclarativeDevice::iconChanged); |
32 | connect(sender: m_device.data(), signal: &BluezQt::Device::pairedChanged, context: this, slot: &DeclarativeDevice::pairedChanged); |
33 | connect(sender: m_device.data(), signal: &BluezQt::Device::trustedChanged, context: this, slot: &DeclarativeDevice::trustedChanged); |
34 | connect(sender: m_device.data(), signal: &BluezQt::Device::blockedChanged, context: this, slot: &DeclarativeDevice::blockedChanged); |
35 | connect(sender: m_device.data(), signal: &BluezQt::Device::legacyPairingChanged, context: this, slot: &DeclarativeDevice::legacyPairingChanged); |
36 | connect(sender: m_device.data(), signal: &BluezQt::Device::rssiChanged, context: this, slot: &DeclarativeDevice::rssiChanged); |
37 | connect(sender: m_device.data(), signal: &BluezQt::Device::connectedChanged, context: this, slot: &DeclarativeDevice::connectedChanged); |
38 | connect(sender: m_device.data(), signal: &BluezQt::Device::uuidsChanged, context: this, slot: &DeclarativeDevice::uuidsChanged); |
39 | connect(sender: m_device.data(), signal: &BluezQt::Device::modaliasChanged, context: this, slot: &DeclarativeDevice::modaliasChanged); |
40 | connect(sender: m_device.data(), signal: &BluezQt::Device::mediaPlayerChanged, context: this, slot: &DeclarativeDevice::updateMediaPlayer); |
41 | connect(sender: m_device.data(), signal: &BluezQt::Device::inputChanged, context: this, slot: &DeclarativeDevice::updateInput); |
42 | connect(sender: m_device.data(), signal: &BluezQt::Device::batteryChanged, context: this, slot: &DeclarativeDevice::updateBattery); |
43 | |
44 | connect(sender: m_device.data(), signal: &BluezQt::Device::deviceRemoved, context: this, slot: [this]() { |
45 | Q_EMIT deviceRemoved(device: this); |
46 | }); |
47 | |
48 | connect(sender: m_device.data(), signal: &BluezQt::Device::deviceChanged, context: this, slot: [this]() { |
49 | Q_EMIT deviceChanged(device: this); |
50 | }); |
51 | |
52 | updateInput(); |
53 | updateMediaPlayer(); |
54 | } |
55 | |
56 | QString DeclarativeDevice::ubi() const |
57 | { |
58 | return m_device->ubi(); |
59 | } |
60 | |
61 | QString DeclarativeDevice::address() const |
62 | { |
63 | return m_device->address(); |
64 | } |
65 | |
66 | QString DeclarativeDevice::name() const |
67 | { |
68 | return m_device->name(); |
69 | } |
70 | |
71 | void DeclarativeDevice::setName(const QString &name) |
72 | { |
73 | m_device->setName(name); |
74 | } |
75 | |
76 | QString DeclarativeDevice::friendlyName() const |
77 | { |
78 | return m_device->friendlyName(); |
79 | } |
80 | |
81 | QString DeclarativeDevice::remoteName() const |
82 | { |
83 | return m_device->remoteName(); |
84 | } |
85 | |
86 | quint32 DeclarativeDevice::deviceClass() const |
87 | { |
88 | return m_device->deviceClass(); |
89 | } |
90 | |
91 | BluezQt::Device::Type DeclarativeDevice::type() const |
92 | { |
93 | return m_device->type(); |
94 | } |
95 | |
96 | quint16 DeclarativeDevice::appearance() const |
97 | { |
98 | return m_device->appearance(); |
99 | } |
100 | |
101 | QString DeclarativeDevice::icon() const |
102 | { |
103 | return m_device->icon(); |
104 | } |
105 | |
106 | bool DeclarativeDevice::isPaired() const |
107 | { |
108 | return m_device->isPaired(); |
109 | } |
110 | |
111 | bool DeclarativeDevice::isTrusted() const |
112 | { |
113 | return m_device->isTrusted(); |
114 | } |
115 | |
116 | void DeclarativeDevice::setTrusted(bool trusted) |
117 | { |
118 | m_device->setTrusted(trusted); |
119 | } |
120 | |
121 | bool DeclarativeDevice::isBlocked() const |
122 | { |
123 | return m_device->isBlocked(); |
124 | } |
125 | |
126 | void DeclarativeDevice::setBlocked(bool blocked) |
127 | { |
128 | m_device->setBlocked(blocked); |
129 | } |
130 | |
131 | bool DeclarativeDevice::hasLegacyPairing() const |
132 | { |
133 | return m_device->hasLegacyPairing(); |
134 | } |
135 | |
136 | qint16 DeclarativeDevice::() const |
137 | { |
138 | return m_device->rssi(); |
139 | } |
140 | |
141 | bool DeclarativeDevice::isConnected() const |
142 | { |
143 | return m_device->isConnected(); |
144 | } |
145 | |
146 | QStringList DeclarativeDevice::uuids() const |
147 | { |
148 | return m_device->uuids(); |
149 | } |
150 | |
151 | QString DeclarativeDevice::modalias() const |
152 | { |
153 | return m_device->modalias(); |
154 | } |
155 | |
156 | DeclarativeBattery *DeclarativeDevice::battery() const |
157 | { |
158 | return m_battery; |
159 | } |
160 | |
161 | DeclarativeInput *DeclarativeDevice::input() const |
162 | { |
163 | return m_input; |
164 | } |
165 | |
166 | DeclarativeMediaPlayer *DeclarativeDevice::mediaPlayer() const |
167 | { |
168 | return m_mediaPlayer; |
169 | } |
170 | |
171 | DeclarativeAdapter *DeclarativeDevice::adapter() const |
172 | { |
173 | return m_adapter; |
174 | } |
175 | |
176 | BluezQt::PendingCall *DeclarativeDevice::connectToDevice() |
177 | { |
178 | return m_device->connectToDevice(); |
179 | } |
180 | |
181 | BluezQt::PendingCall *DeclarativeDevice::disconnectFromDevice() |
182 | { |
183 | return m_device->disconnectFromDevice(); |
184 | } |
185 | |
186 | BluezQt::PendingCall *DeclarativeDevice::connectProfile(const QString &uuid) |
187 | { |
188 | return m_device->connectProfile(uuid); |
189 | } |
190 | |
191 | BluezQt::PendingCall *DeclarativeDevice::disconnectProfile(const QString &uuid) |
192 | { |
193 | return m_device->disconnectProfile(uuid); |
194 | } |
195 | |
196 | BluezQt::PendingCall *DeclarativeDevice::pair() |
197 | { |
198 | return m_device->pair(); |
199 | } |
200 | |
201 | BluezQt::PendingCall *DeclarativeDevice::cancelPairing() |
202 | { |
203 | return m_device->cancelPairing(); |
204 | } |
205 | |
206 | void 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(battery: m_battery); |
218 | } |
219 | |
220 | void 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(input: m_input); |
232 | } |
233 | |
234 | void 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(mediaPlayer: m_mediaPlayer); |
246 | } |
247 | |
248 | #include "moc_declarativedevice.cpp" |
249 | |