| 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 |
#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(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 |
|
| 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::rssi() 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(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(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(m_mediaPlayer); |
| 246 |
} |
| 247 |
|
| 248 |
#include "moc_declarativedevice.cpp" |