Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
BluetoothDeviceModel.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
11
12#include <QAbstractListModel>
13
15
21class PHOSPHORSERVICEBLUETOOTH_EXPORT BluetoothDeviceModel : public QAbstractListModel
22{
23 Q_OBJECT
24 Q_DISABLE_COPY_MOVE(BluetoothDeviceModel)
27 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
28
29public:
44 Q_ENUM(Roles)
45
46 explicit BluetoothDeviceModel(QObject* parent = nullptr);
48
49 [[nodiscard]] BluetoothHost* host() const;
51
54 [[nodiscard]] BluetoothAdapter* adapter() const;
56
57 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
58 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
59 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
60
61Q_SIGNALS:
65
66private Q_SLOTS:
67 void onDeviceAdded(PhosphorServiceBluetooth::BluetoothDevice* device);
68 void onDeviceRemoved(PhosphorServiceBluetooth::BluetoothDevice* device);
69 void onDeviceDataChanged(PhosphorServiceBluetooth::BluetoothDevice* device, const QList<int>& roles);
70
71private:
72 void rebuild();
73 void connectDevice(BluetoothDevice* device);
74 [[nodiscard]] bool accepts(BluetoothDevice* device) const;
75
76 BluetoothHost* m_host = nullptr;
77 BluetoothAdapter* m_adapterFilter = nullptr;
78 // Row mirror of host-owned BluetoothDevice pointers (post-filter); the
79 // model never owns or deletes these. Dangling-safe for the same reason as
80 // BluetoothAdapterModel: the host removes a device from its list and emits
81 // deviceRemoved before deleteLater, and clears on host destruction.
82 QList<BluetoothDevice*> m_rows;
83};
84
85} // namespace PhosphorServiceBluetooth
One BlueZ adapter (org.bluez.Adapter1), e.g.
Definition BluetoothAdapter.h:31
void setAdapter(BluetoothAdapter *adapter)
Roles
Definition BluetoothDeviceModel.h:30
@ PairedRole
Definition BluetoothDeviceModel.h:36
@ NameRole
Definition BluetoothDeviceModel.h:33
@ AddressRole
Definition BluetoothDeviceModel.h:32
@ ConnectedRole
Definition BluetoothDeviceModel.h:39
@ TrustedRole
Definition BluetoothDeviceModel.h:37
@ UuidsRole
Definition BluetoothDeviceModel.h:42
@ RssiRole
Definition BluetoothDeviceModel.h:40
@ AliasRole
Definition BluetoothDeviceModel.h:34
@ AdapterRole
Definition BluetoothDeviceModel.h:41
@ IconRole
Definition BluetoothDeviceModel.h:35
@ BlockedRole
Definition BluetoothDeviceModel.h:38
@ DeviceRole
Definition BluetoothDeviceModel.h:31
BluetoothAdapter * adapter() const
Adapter filter.
QHash< int, QByteArray > roleNames() const override
int rowCount(const QModelIndex &parent={}) const override
QVariant data(const QModelIndex &index, int role) const override
One BlueZ device (org.bluez.Device1), e.g.
Definition BluetoothDevice.h:35
Facade over org.bluez: enumerates adapters and devices.
Definition BluetoothHost.h:36
Definition BluetoothAdapter.h:16