|
2 | 2 | #include "valenzbridge_p.h" |
3 | 3 | #include "mauikit_system_control.h" |
4 | 4 |
|
5 | | -#include <QDBusConnection> |
6 | | -#include <QDBusInterface> |
7 | | -#include <QDBusObjectPath> |
8 | | -#include <QDBusReply> |
9 | | -#include <QDBusVariant> |
10 | | -#include <QDBusMetaType> |
11 | | -#include <QMap> |
12 | | -#include <QVariant> |
13 | | - |
14 | | -namespace |
15 | | -{ |
16 | | -using BluezPropertyMap = QMap<QString, QVariant>; |
17 | | -using BluezInterfaceMap = QMap<QString, BluezPropertyMap>; |
18 | | -using BluezManagedObjects = QMap<QDBusObjectPath, BluezInterfaceMap>; |
19 | | -} |
20 | | - |
21 | | -Q_DECLARE_METATYPE(BluezPropertyMap) |
22 | | -Q_DECLARE_METATYPE(BluezInterfaceMap) |
23 | | -Q_DECLARE_METATYPE(BluezManagedObjects) |
24 | | - |
25 | 5 | namespace |
26 | 6 | { |
27 | 7 |
|
28 | 8 | bool setBluezAdapterPowered(bool enabled) |
29 | 9 | { |
30 | | - qDBusRegisterMetaType<BluezPropertyMap>(); |
31 | | - qDBusRegisterMetaType<BluezInterfaceMap>(); |
32 | | - qDBusRegisterMetaType<BluezManagedObjects>(); |
33 | | - |
34 | | - QDBusInterface objectsIface(QStringLiteral("org.bluez"), |
35 | | - QStringLiteral("/"), |
36 | | - QStringLiteral("org.freedesktop.DBus.ObjectManager"), |
37 | | - QDBusConnection::systemBus()); |
38 | | - if (!objectsIface.isValid()) |
39 | | - return false; |
40 | | - |
41 | | - const QDBusReply<BluezManagedObjects> reply = objectsIface.call(QStringLiteral("GetManagedObjects")); |
42 | | - if (!reply.isValid()) |
43 | | - return false; |
44 | | - |
45 | | - const BluezManagedObjects objects = reply.value(); |
46 | | - bool anyAdapter = false; |
47 | | - bool allSucceeded = true; |
48 | | - |
49 | | - for (const QDBusObjectPath &path : objects.keys()) |
50 | | - { |
51 | | - const BluezInterfaceMap interfaces = objects.value(path); |
52 | | - if (!interfaces.contains(QStringLiteral("org.bluez.Adapter1"))) |
53 | | - continue; |
54 | | - |
55 | | - anyAdapter = true; |
56 | | - |
57 | | - QDBusInterface propertiesIface(QStringLiteral("org.bluez"), |
58 | | - path.path(), |
59 | | - QStringLiteral("org.freedesktop.DBus.Properties"), |
60 | | - QDBusConnection::systemBus()); |
61 | | - if (!propertiesIface.isValid()) |
62 | | - { |
63 | | - allSucceeded = false; |
64 | | - continue; |
65 | | - } |
66 | | - |
67 | | - QDBusMessage setCall = QDBusMessage::createMethodCall(QStringLiteral("org.bluez"), |
68 | | - path.path(), |
69 | | - QStringLiteral("org.freedesktop.DBus.Properties"), |
70 | | - QStringLiteral("Set")); |
71 | | - setCall.setArguments({QStringLiteral("org.bluez.Adapter1"), |
72 | | - QStringLiteral("Powered"), |
73 | | - QVariant::fromValue(QDBusVariant(QVariant(enabled)))}); |
74 | | - |
75 | | - const QDBusMessage result = QDBusConnection::systemBus().call(setCall); |
76 | | - if (result.type() == QDBusMessage::ErrorMessage) |
77 | | - allSucceeded = false; |
78 | | - } |
79 | | - |
80 | | - return anyAdapter && allSucceeded; |
| 10 | + return MauiKitSystem::setControlCenterBluetoothEnabled(enabled); |
81 | 11 | } |
82 | 12 |
|
83 | 13 | } |
|
0 commit comments