Debian Codegraph @

src/device.cpp

raw
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
22 Device::~Device() = default;
23
24 DevicePtr Device::toSharedPtr() const
25 {
26 return d->q.toStrongRef();
27 }
28
29 QString Device::ubi() const
30 {
31 return d->m_bluezDevice->path();
32 }
33
34 QString Device::address() const
35 {
36 return d->m_address;
37 }
38
39 QString Device::name() const
40 {
41 return d->m_alias;
42 }
43
44 PendingCall *Device::setName(const QString &name)
45 {
46 return new PendingCall(d->setDBusProperty(QStringLiteral("Alias"), name), PendingCall::ReturnVoid, this);
47 }
48
49 QString 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
60 QString Device::remoteName() const
61 {
62 return d->m_name;
63 }
64
65 quint32 Device::deviceClass() const
66 {
67 return d->m_deviceClass;
68 }
69
70 Device::Type Device::type() const
71 {
72 if (deviceClass() == 0) {
73 return appearanceToType(appearance());
74 }
75
76 return classToType(d->m_deviceClass);
77 }
78
79 quint16 Device::appearance() const
80 {
81 return d->m_appearance;
82 }
83
84 QString 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
96 bool Device::isPaired() const
97 {
98 return d->m_paired;
99 }
100
101 bool Device::isTrusted() const
102 {
103 return d->m_trusted;
104 }
105
106 PendingCall *Device::setTrusted(bool trusted)
107 {
108 return new PendingCall(d->setDBusProperty(QStringLiteral("Trusted"), trusted), PendingCall::ReturnVoid, this);
109 }
110
111 bool Device::isBlocked() const
112 {
113 return d->m_blocked;
114 }
115
116 PendingCall *Device::setBlocked(bool blocked)
117 {
118 return new PendingCall(d->setDBusProperty(QStringLiteral("Blocked"), blocked), PendingCall::ReturnVoid, this);
119 }
120
121 bool Device::hasLegacyPairing() const
122 {
123 return d->m_legacyPairing;
124 }
125
126 qint16 Device::rssi() const
127 {
128 return d->m_rssi;
129 }
130
131 ManData Device::manufacturerData() const
132 {
133 return d->m_manufacturerData;
134 }
135
136 bool Device::isServicesResolved() const
137 {
138 return d->m_servicesResolved;
139 }
140
141 bool Device::isConnected() const
142 {
143 return d->m_connected;
144 }
145
146 QStringList Device::uuids() const
147 {
148 return d->m_uuids;
149 }
150
151 QString Device::modalias() const
152 {
153 return d->m_modalias;
154 }
155
156 QHash<QString, QByteArray> Device::serviceData() const
157 {
158 return d->m_serviceData;
159 }
160
161 BatteryPtr Device::battery() const
162 {
163 return d->m_battery;
164 }
165
166 InputPtr Device::input() const
167 {
168 return d->m_input;
169 }
170
171 MediaPlayerPtr Device::mediaPlayer() const
172 {
173 return d->m_mediaPlayer;
174 }
175
176 MediaTransportPtr Device::mediaTransport() const
177 {
178 return d->m_mediaTransport;
179 }
180
181 AdapterPtr Device::adapter() const
182 {
183 return d->m_adapter;
184 }
185
186 QList<GattServiceRemotePtr> Device::gattServices() const
187 {
188 return d->m_services;
189 }
190
191 QString Device::typeToString(Device::Type type)
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");
204 case Device::Headphones:
205 return QStringLiteral("headphones");
206 case Device::AudioVideo:
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");
216 case Device::Peripheral:
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
235 Device::Type Device::stringToType(const QString &typeString)
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 }
274 return Device::Uncategorized;
275 }
276
277 PendingCall *Device::connectToDevice()
278 {
279 return new PendingCall(d->m_bluezDevice->Connect(), PendingCall::ReturnVoid, this);
280 }
281
282 PendingCall *Device::disconnectFromDevice()
283 {
284 return new PendingCall(d->m_bluezDevice->Disconnect(), PendingCall::ReturnVoid, this);
285 }
286
287 PendingCall *Device::connectProfile(const QString &uuid)
288 {
289 return new PendingCall(d->m_bluezDevice->ConnectProfile(uuid), PendingCall::ReturnVoid, this);
290 }
291
292 PendingCall *Device::disconnectProfile(const QString &uuid)
293 {
294 return new PendingCall(d->m_bluezDevice->DisconnectProfile(uuid), PendingCall::ReturnVoid, this);
295 }
296
297 PendingCall *Device::pair()
298 {
299 return new PendingCall(d->m_bluezDevice->Pair(), PendingCall::ReturnVoid, this);
300 }
301
302 PendingCall *Device::cancelPairing()
303 {
304 return new PendingCall(d->m_bluezDevice->CancelPairing(), PendingCall::ReturnVoid, this);
305 }
306
307 } // namespace BluezQt
308
309 #include "moc_device.cpp"