File indexing completed on 2025-01-19 06:44:34
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014 David Rosca <nowrep@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "device.h" 0010 #include "device_p.h" 0011 #include "pendingcall.h" 0012 #include "utils.h" 0013 0014 namespace BluezQt 0015 { 0016 Device::Device(const QString &path, const QVariantMap &properties, AdapterPtr adapter) 0017 : QObject() 0018 , d(new DevicePrivate(path, properties, adapter)) 0019 { 0020 } 0021 0022 Device::~Device() = default; 0023 0024 DevicePtr Device::toSharedPtr() const 0025 { 0026 return d->q.toStrongRef(); 0027 } 0028 0029 QString Device::ubi() const 0030 { 0031 return d->m_bluezDevice->path(); 0032 } 0033 0034 QString Device::address() const 0035 { 0036 return d->m_address; 0037 } 0038 0039 QString Device::name() const 0040 { 0041 return d->m_alias; 0042 } 0043 0044 PendingCall *Device::setName(const QString &name) 0045 { 0046 return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this); 0047 } 0048 0049 QString Device::friendlyName() const 0050 { 0051 if (name().isEmpty() || name() == remoteName()) { 0052 return name(); 0053 } 0054 if (remoteName().isEmpty()) { 0055 return name(); 0056 } 0057 return QStringLiteral("%1 (%2)").arg(name(), remoteName()); 0058 } 0059 0060 QString Device::remoteName() const 0061 { 0062 return d->m_name; 0063 } 0064 0065 quint32 Device::deviceClass() const 0066 { 0067 return d->m_deviceClass; 0068 } 0069 0070 Device::Type Device::type() const 0071 { 0072 if (deviceClass() == 0) { 0073 return appearanceToType(appearance()); 0074 } 0075 0076 return classToType(d->m_deviceClass); 0077 } 0078 0079 quint16 Device::appearance() const 0080 { 0081 return d->m_appearance; 0082 } 0083 0084 QString Device::icon() const 0085 { 0086 switch (type()) { 0087 case Headset: 0088 return QStringLiteral("audio-headset"); 0089 case Headphones: 0090 return QStringLiteral("audio-headphones"); 0091 default: 0092 return d->m_icon.isEmpty() ? QStringLiteral("preferences-system-bluetooth") : d->m_icon; 0093 } 0094 } 0095 0096 bool Device::isPaired() const 0097 { 0098 return d->m_paired; 0099 } 0100 0101 bool Device::isTrusted() const 0102 { 0103 return d->m_trusted; 0104 } 0105 0106 PendingCall *Device::setTrusted(bool trusted) 0107 { 0108 return new PendingCall(d->setDBusProperty(QStringLiteral("Trusted"), trusted), PendingCall::ReturnVoid, this); 0109 } 0110 0111 bool Device::isBlocked() const 0112 { 0113 return d->m_blocked; 0114 } 0115 0116 PendingCall *Device::setBlocked(bool blocked) 0117 { 0118 return new PendingCall(d->setDBusProperty(QStringLiteral("Blocked"), blocked), PendingCall::ReturnVoid, this); 0119 } 0120 0121 bool Device::hasLegacyPairing() const 0122 { 0123 return d->m_legacyPairing; 0124 } 0125 0126 qint16 Device::rssi() const 0127 { 0128 return d->m_rssi; 0129 } 0130 0131 ManData Device::manufacturerData() const 0132 { 0133 return d->m_manufacturerData; 0134 } 0135 0136 bool Device::isServicesResolved() const 0137 { 0138 return d->m_servicesResolved; 0139 } 0140 0141 bool Device::isConnected() const 0142 { 0143 return d->m_connected; 0144 } 0145 0146 QStringList Device::uuids() const 0147 { 0148 return d->m_uuids; 0149 } 0150 0151 QString Device::modalias() const 0152 { 0153 return d->m_modalias; 0154 } 0155 0156 QHash<QString, QByteArray> Device::serviceData() const 0157 { 0158 return d->m_serviceData; 0159 } 0160 0161 BatteryPtr Device::battery() const 0162 { 0163 return d->m_battery; 0164 } 0165 0166 InputPtr Device::input() const 0167 { 0168 return d->m_input; 0169 } 0170 0171 MediaPlayerPtr Device::mediaPlayer() const 0172 { 0173 return d->m_mediaPlayer; 0174 } 0175 0176 MediaTransportPtr Device::mediaTransport() const 0177 { 0178 return d->m_mediaTransport; 0179 } 0180 0181 AdapterPtr Device::adapter() const 0182 { 0183 return d->m_adapter; 0184 } 0185 0186 QList<GattServiceRemotePtr> Device::gattServices() const 0187 { 0188 return d->m_services; 0189 } 0190 0191 QString Device::typeToString(Device::Type type) 0192 { 0193 switch (type) { 0194 case Device::Phone: 0195 return QStringLiteral("phone"); 0196 case Device::Modem: 0197 return QStringLiteral("modem"); 0198 case Device::Computer: 0199 return QStringLiteral("computer"); 0200 case Device::Network: 0201 return QStringLiteral("network"); 0202 case Device::Headset: 0203 return QStringLiteral("headset"); 0204 case Device::Headphones: 0205 return QStringLiteral("headphones"); 0206 case Device::AudioVideo: 0207 return QStringLiteral("audiovideo"); 0208 case Device::Keyboard: 0209 return QStringLiteral("keyboard"); 0210 case Device::Mouse: 0211 return QStringLiteral("mouse"); 0212 case Device::Joypad: 0213 return QStringLiteral("joypad"); 0214 case Device::Tablet: 0215 return QStringLiteral("tablet"); 0216 case Device::Peripheral: 0217 return QStringLiteral("peripheral"); 0218 case Device::Camera: 0219 return QStringLiteral("camera"); 0220 case Device::Printer: 0221 return QStringLiteral("printer"); 0222 case Device::Imaging: 0223 return QStringLiteral("imaging"); 0224 case Device::Wearable: 0225 return QStringLiteral("wearable"); 0226 case Device::Toy: 0227 return QStringLiteral("toy"); 0228 case Device::Health: 0229 return QStringLiteral("health"); 0230 default: 0231 return QStringLiteral("uncategorized"); 0232 } 0233 } 0234 0235 Device::Type Device::stringToType(const QString &typeString) 0236 { 0237 if (typeString == QLatin1String("phone")) { 0238 return Device::Phone; 0239 } else if (typeString == QLatin1String("modem")) { 0240 return Device::Modem; 0241 } else if (typeString == QLatin1String("computer")) { 0242 return Device::Computer; 0243 } else if (typeString == QLatin1String("network")) { 0244 return Device::Network; 0245 } else if (typeString == QLatin1String("headset")) { 0246 return Device::Headset; 0247 } else if (typeString == QLatin1String("headphones")) { 0248 return Device::Headphones; 0249 } else if (typeString == QLatin1String("audio")) { 0250 return Device::AudioVideo; 0251 } else if (typeString == QLatin1String("keyboard")) { 0252 return Device::Keyboard; 0253 } else if (typeString == QLatin1String("mouse")) { 0254 return Device::Mouse; 0255 } else if (typeString == QLatin1String("joypad")) { 0256 return Device::Joypad; 0257 } else if (typeString == QLatin1String("tablet")) { 0258 return Device::Tablet; 0259 } else if (typeString == QLatin1String("peripheral")) { 0260 return Device::Peripheral; 0261 } else if (typeString == QLatin1String("camera")) { 0262 return Device::Camera; 0263 } else if (typeString == QLatin1String("printer")) { 0264 return Device::Printer; 0265 } else if (typeString == QLatin1String("imaging")) { 0266 return Device::Imaging; 0267 } else if (typeString == QLatin1String("wearable")) { 0268 return Device::Wearable; 0269 } else if (typeString == QLatin1String("toy")) { 0270 return Device::Toy; 0271 } else if (typeString == QLatin1String("health")) { 0272 return Device::Health; 0273 } 0274 return Device::Uncategorized; 0275 } 0276 0277 PendingCall *Device::connectToDevice() 0278 { 0279 return new PendingCall(d->m_bluezDevice->Connect(), PendingCall::ReturnVoid, this); 0280 } 0281 0282 PendingCall *Device::disconnectFromDevice() 0283 { 0284 return new PendingCall(d->m_bluezDevice->Disconnect(), PendingCall::ReturnVoid, this); 0285 } 0286 0287 PendingCall *Device::connectProfile(const QString &uuid) 0288 { 0289 return new PendingCall(d->m_bluezDevice->ConnectProfile(uuid), PendingCall::ReturnVoid, this); 0290 } 0291 0292 PendingCall *Device::disconnectProfile(const QString &uuid) 0293 { 0294 return new PendingCall(d->m_bluezDevice->DisconnectProfile(uuid), PendingCall::ReturnVoid, this); 0295 } 0296 0297 PendingCall *Device::pair() 0298 { 0299 return new PendingCall(d->m_bluezDevice->Pair(), PendingCall::ReturnVoid, this); 0300 } 0301 0302 PendingCall *Device::cancelPairing() 0303 { 0304 return new PendingCall(d->m_bluezDevice->CancelPairing(), PendingCall::ReturnVoid, this); 0305 } 0306 0307 } // namespace BluezQt 0308 0309 #include "moc_device.cpp"