Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
BluetoothDevice.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceBluetooth/phosphorservicebluetooth_export.h>
7
8#include <QObject>
9#include <QString>
10#include <QStringList>
11#include <QVariantMap>
12
13#include <memory>
14
15class QDBusConnection;
16
18
34class PHOSPHORSERVICEBLUETOOTH_EXPORT BluetoothDevice : public QObject
35{
36 Q_OBJECT
37 Q_PROPERTY(QString dbusPath READ dbusPath CONSTANT)
38 Q_PROPERTY(QString address READ address NOTIFY addressChanged)
39 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
40 Q_PROPERTY(QString alias READ alias NOTIFY aliasChanged)
41 Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
42 Q_PROPERTY(bool paired READ paired NOTIFY pairedChanged)
43 Q_PROPERTY(bool trusted READ trusted NOTIFY trustedChanged)
44 Q_PROPERTY(bool blocked READ blocked NOTIFY blockedChanged)
45 Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
47 Q_PROPERTY(int rssi READ rssi NOTIFY rssiChanged)
48 Q_PROPERTY(QString adapter READ adapter NOTIFY adapterChanged)
49 Q_PROPERTY(QStringList uuids READ uuids NOTIFY uuidsChanged)
50
51public:
52 BluetoothDevice(QDBusConnection connection, const QString& dbusPath, const QVariantMap& initialProperties,
53 QObject* parent = nullptr);
54 ~BluetoothDevice() override;
55
56 [[nodiscard]] QString dbusPath() const;
57 [[nodiscard]] QString address() const;
58 [[nodiscard]] QString name() const;
59 [[nodiscard]] QString alias() const;
60 [[nodiscard]] QString icon() const;
61 [[nodiscard]] bool paired() const;
62 [[nodiscard]] bool trusted() const;
63 [[nodiscard]] bool blocked() const;
64 [[nodiscard]] bool connected() const;
65 [[nodiscard]] int rssi() const;
67 [[nodiscard]] int batteryPercentage() const;
69 void applyBattery(const QVariantMap& properties);
70 [[nodiscard]] QString adapter() const;
71 [[nodiscard]] QStringList uuids() const;
72
78 Q_INVOKABLE void connectDevice();
79 Q_INVOKABLE void disconnectDevice();
80
84 Q_INVOKABLE void setTrusted(bool trusted);
85 Q_INVOKABLE void setBlocked(bool blocked);
86
91 Q_INVOKABLE void pair();
92 Q_INVOKABLE void cancelPairing();
93
94Q_SIGNALS:
96 void operationFinished(const QString& operation, const QString& errorName);
109
110private Q_SLOTS:
111 void _q_onPropertiesChanged(const QString& interfaceName, const QVariantMap& changed,
112 const QStringList& invalidated);
113
114private:
115 Q_DISABLE_COPY_MOVE(BluetoothDevice)
116 class Private;
117 std::unique_ptr<Private> d;
118};
119
120} // namespace PhosphorServiceBluetooth
void applyBattery(const QVariantMap &properties)
Internal ObjectManager update, including removal (empty map).
void setTrusted(bool trusted)
Mark the device (un)trusted / (un)blocked (org.bluez.Device1 Properties.Set).
void pair()
Begin / abort pairing (org.bluez.Device1.Pair / CancelPairing).
void operationFinished(const QString &operation, const QString &errorName)
Completion of a write request; state follows BlueZ properties.
int batteryPercentage() const
-1 when the device does not report Battery1.Percentage.
void connectDevice()
Establish / tear down a connection to this device (org.bluez.Device1.Connect / Disconnect).
BluetoothDevice(QDBusConnection connection, const QString &dbusPath, const QVariantMap &initialProperties, QObject *parent=nullptr)
Definition BluetoothAdapter.h:16