BluezQt

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