BluezQt

device.cpp
1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2014 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 "device.h"
10#include "device_p.h"
11#include "pendingcall.h"
12#include "utils.h"
13
14namespace BluezQt
15{
16Device::Device(const QString &path, const QVariantMap &properties, AdapterPtr adapter)
17 : QObject()
18 , d(new DevicePrivate(path, properties, adapter))
19{
20}
21
22Device::~Device() = default;
23
24DevicePtr Device::toSharedPtr() const
25{
26 return d->q.toStrongRef();
27}
28
29QString Device::ubi() const
30{
31 return d->m_bluezDevice->path();
32}
33
34QString Device::address() const
35{
36 return d->m_address;
37}
38
39QString Device::name() const
40{
41 return d->m_alias;
42}
43
45{
46 return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this);
47}
48
49QString Device::friendlyName() const
50{
51 if (name().isEmpty() || name() == remoteName()) {
52 return name();
53 }
54 if (remoteName().isEmpty()) {
55 return name();
56 }
57 return QStringLiteral("%1 (%2)").arg(name(), remoteName());
58}
59
60QString Device::remoteName() const
61{
62 return d->m_name;
63}
64
65quint32 Device::deviceClass() const
66{
67 return d->m_deviceClass;
68}
69
70Device::Type Device::type() const
71{
72 if (deviceClass() == 0) {
73 return appearanceToType(appearance());
74 }
75
76 return classToType(d->m_deviceClass);
77}
78
79quint16 Device::appearance() const
80{
81 return d->m_appearance;
82}
83
84QString Device::icon() const
85{
86 switch (type()) {
87 case Headset:
88 return QStringLiteral("audio-headset");
89 case Headphones:
90 return QStringLiteral("audio-headphones");
91 default:
92 return d->m_icon.isEmpty() ? QStringLiteral("preferences-system-bluetooth") : d->m_icon;
93 }
94}
95
96bool Device::isPaired() const
97{
98 return d->m_paired;
99}
100
102{
103 return d->m_trusted;
104}
105
107{
108 return new PendingCall(d->setDBusProperty(QStringLiteral("Trusted"), trusted), PendingCall::ReturnVoid, this);
109}
110
112{
113 return d->m_blocked;
114}
115
117{
118 return new PendingCall(d->setDBusProperty(QStringLiteral("Blocked"), blocked), PendingCall::ReturnVoid, this);
119}
120
122{
123 return d->m_legacyPairing;
124}
125
126qint16 Device::rssi() const
127{
128 return d->m_rssi;
129}
130
131ManData Device::manufacturerData() const
132{
133 return d->m_manufacturerData;
134}
135
137{
138 return d->m_servicesResolved;
139}
140
142{
143 return d->m_connected;
144}
145
146QStringList Device::uuids() const
147{
148 return d->m_uuids;
149}
150
151QString Device::modalias() const
152{
153 return d->m_modalias;
154}
155
157{
158 return d->m_serviceData;
159}
160
161BatteryPtr Device::battery() const
162{
163 return d->m_battery;
164}
165
166InputPtr Device::input() const
167{
168 return d->m_input;
169}
170
171MediaPlayerPtr Device::mediaPlayer() const
172{
173 return d->m_mediaPlayer;
174}
175
176MediaTransportPtr Device::mediaTransport() const
177{
178 return d->m_mediaTransport;
179}
180
181AdapterPtr Device::adapter() const
182{
183 return d->m_adapter;
184}
185
186QList<GattServiceRemotePtr> Device::gattServices() const
187{
188 return d->m_services;
189}
190
192{
193 switch (type) {
194 case Device::Phone:
195 return QStringLiteral("phone");
196 case Device::Modem:
197 return QStringLiteral("modem");
198 case Device::Computer:
199 return QStringLiteral("computer");
200 case Device::Network:
201 return QStringLiteral("network");
202 case Device::Headset:
203 return QStringLiteral("headset");
205 return QStringLiteral("headphones");
207 return QStringLiteral("audiovideo");
208 case Device::Keyboard:
209 return QStringLiteral("keyboard");
210 case Device::Mouse:
211 return QStringLiteral("mouse");
212 case Device::Joypad:
213 return QStringLiteral("joypad");
214 case Device::Tablet:
215 return QStringLiteral("tablet");
217 return QStringLiteral("peripheral");
218 case Device::Camera:
219 return QStringLiteral("camera");
220 case Device::Printer:
221 return QStringLiteral("printer");
222 case Device::Imaging:
223 return QStringLiteral("imaging");
224 case Device::Wearable:
225 return QStringLiteral("wearable");
226 case Device::Toy:
227 return QStringLiteral("toy");
228 case Device::Health:
229 return QStringLiteral("health");
230 default:
231 return QStringLiteral("uncategorized");
232 }
233}
234
236{
237 if (typeString == QLatin1String("phone")) {
238 return Device::Phone;
239 } else if (typeString == QLatin1String("modem")) {
240 return Device::Modem;
241 } else if (typeString == QLatin1String("computer")) {
242 return Device::Computer;
243 } else if (typeString == QLatin1String("network")) {
244 return Device::Network;
245 } else if (typeString == QLatin1String("headset")) {
246 return Device::Headset;
247 } else if (typeString == QLatin1String("headphones")) {
248 return Device::Headphones;
249 } else if (typeString == QLatin1String("audio")) {
250 return Device::AudioVideo;
251 } else if (typeString == QLatin1String("keyboard")) {
252 return Device::Keyboard;
253 } else if (typeString == QLatin1String("mouse")) {
254 return Device::Mouse;
255 } else if (typeString == QLatin1String("joypad")) {
256 return Device::Joypad;
257 } else if (typeString == QLatin1String("tablet")) {
258 return Device::Tablet;
259 } else if (typeString == QLatin1String("peripheral")) {
260 return Device::Peripheral;
261 } else if (typeString == QLatin1String("camera")) {
262 return Device::Camera;
263 } else if (typeString == QLatin1String("printer")) {
264 return Device::Printer;
265 } else if (typeString == QLatin1String("imaging")) {
266 return Device::Imaging;
267 } else if (typeString == QLatin1String("wearable")) {
268 return Device::Wearable;
269 } else if (typeString == QLatin1String("toy")) {
270 return Device::Toy;
271 } else if (typeString == QLatin1String("health")) {
272 return Device::Health;
273 }
275}
276
278{
279 return new PendingCall(d->m_bluezDevice->Connect(), PendingCall::ReturnVoid, this);
280}
281
283{
284 return new PendingCall(d->m_bluezDevice->Disconnect(), PendingCall::ReturnVoid, this);
285}
286
288{
289 return new PendingCall(d->m_bluezDevice->ConnectProfile(uuid), PendingCall::ReturnVoid, this);
290}
291
293{
294 return new PendingCall(d->m_bluezDevice->DisconnectProfile(uuid), PendingCall::ReturnVoid, this);
295}
296
298{
299 return new PendingCall(d->m_bluezDevice->Pair(), PendingCall::ReturnVoid, this);
300}
301
303{
304 return new PendingCall(d->m_bluezDevice->CancelPairing(), PendingCall::ReturnVoid, this);
305}
306
307} // namespace BluezQt
308
309#include "moc_device.cpp"
PendingCall * connectProfile(const QString &uuid)
Connects a specific profile of the device.
Definition device.cpp:287
bool isTrusted() const
Returns whether the device is trusted.
Definition device.cpp:101
bool isConnected() const
Returns whether the device is connected.
Definition device.cpp:141
bool hasLegacyPairing() const
Returns whether the device has legacy pairing.
Definition device.cpp:121
PendingCall * pair()
Initiates a pairing with the device.
Definition device.cpp:297
PendingCall * setTrusted(bool trusted)
Sets the trusted state of the device.
Definition device.cpp:106
QHash< QString, QByteArray > serviceData() const
Returns the service advertisement data.
Definition device.cpp:156
Type
Device types.
Definition device.h:65
@ Modem
The device is a modem.
Definition device.h:69
@ Wearable
The device is a wearable device.
Definition device.h:97
@ Uncategorized
The device is not of any of the known types.
Definition device.h:103
@ Headset
The device is a headset.
Definition device.h:75
@ Imaging
The device is an uncategorized imaging device.
Definition device.h:95
@ Tablet
The device is a graphics tablet (input device).
Definition device.h:87
@ Camera
The device is a camera.
Definition device.h:91
@ Peripheral
The device is an uncategorized peripheral device.
Definition device.h:89
@ AudioVideo
The device is an uncategorized audio video device.
Definition device.h:79
@ Toy
The device is a toy.
Definition device.h:99
@ Network
The device is a network.
Definition device.h:73
@ Mouse
The device is a mouse.
Definition device.h:83
@ Phone
The device is a phone.
Definition device.h:67
@ Headphones
The device is a headphones.
Definition device.h:77
@ Computer
The device is a computer.
Definition device.h:71
@ Joypad
The device is a joypad.
Definition device.h:85
@ Printer
The device is a printer.
Definition device.h:93
@ Keyboard
The device is a keyboard.
Definition device.h:81
@ Health
The device is a health device.
Definition device.h:101
PendingCall * connectToDevice()
Connects all auto-connectable profiles of the device.
Definition device.cpp:277
PendingCall * cancelPairing()
Cancels a pairing with the device.
Definition device.cpp:302
PendingCall * setBlocked(bool blocked)
Sets the blocked state of the device.
Definition device.cpp:116
bool isPaired() const
Returns whether the device is paired.
Definition device.cpp:96
bool isBlocked() const
Returns whether the device is blocked.
Definition device.cpp:111
PendingCall * disconnectProfile(const QString &uuid)
Disconnects a specific profile of the device.
Definition device.cpp:292
static Device::Type stringToType(const QString &typeString)
Returns a device type for string.
Definition device.cpp:235
PendingCall * setName(const QString &name)
Sets the name of the device.
Definition device.cpp:44
DevicePtr toSharedPtr() const
Returns a shared pointer from this.
Definition device.cpp:24
static QString typeToString(Device::Type type)
Returns a string for device type.
Definition device.cpp:191
PendingCall * disconnectFromDevice()
Disconnects all connected profiles of the device.
Definition device.cpp:282
bool isServicesResolved() const
Returns whether or not service discovery has been resolved.
Definition device.cpp:136
Pending method call.
Definition pendingcall.h:35
QString path(const QString &relativePath)
KGuiItem properties()
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:56:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.