Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
BluetoothAdapterModel.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
10
11#include <QAbstractListModel>
12
14
19class PHOSPHORSERVICEBLUETOOTH_EXPORT BluetoothAdapterModel : public QAbstractListModel
20{
21 Q_OBJECT
22 Q_DISABLE_COPY_MOVE(BluetoothAdapterModel)
24 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
25
26public:
37 Q_ENUM(Roles)
38
39 explicit BluetoothAdapterModel(QObject* parent = nullptr);
41
42 [[nodiscard]] BluetoothHost* host() const;
44
45 [[nodiscard]] int rowCount(const QModelIndex& parent = {}) const override;
46 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
47 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
48
49Q_SIGNALS:
52
53private Q_SLOTS:
54 void onAdapterAdded(PhosphorServiceBluetooth::BluetoothAdapter* adapter);
55 void onAdapterRemoved(PhosphorServiceBluetooth::BluetoothAdapter* adapter);
56 void onAdapterDataChanged(PhosphorServiceBluetooth::BluetoothAdapter* adapter, const QList<int>& roles);
57
58private:
59 void connectAdapter(BluetoothAdapter* adapter);
60
61 BluetoothHost* m_host = nullptr;
62 // Row mirror of host-owned BluetoothAdapter pointers; rowCount/data index
63 // into this list. The model does NOT own these objects and never deletes
64 // them. Safe against dangling because BluetoothHost emits adapterRemoved
65 // before destroying an adapter, and QObject::destroyed fires before the
66 // host's children are deleted (the host-destroyed lambda clears m_rows
67 // while every pointer is still valid).
68 QList<BluetoothAdapter*> m_rows;
69};
70
71} // namespace PhosphorServiceBluetooth
Roles
Definition BluetoothAdapterModel.h:27
@ AddressRole
Definition BluetoothAdapterModel.h:29
@ PoweredRole
Definition BluetoothAdapterModel.h:32
@ DiscoveringRole
Definition BluetoothAdapterModel.h:35
@ AliasRole
Definition BluetoothAdapterModel.h:31
@ PairableRole
Definition BluetoothAdapterModel.h:34
@ NameRole
Definition BluetoothAdapterModel.h:30
@ AdapterRole
Definition BluetoothAdapterModel.h:28
@ DiscoverableRole
Definition BluetoothAdapterModel.h:33
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent={}) const override
QHash< int, QByteArray > roleNames() const override
One BlueZ adapter (org.bluez.Adapter1), e.g.
Definition BluetoothAdapter.h:31
Facade over org.bluez: enumerates adapters and devices.
Definition BluetoothHost.h:36
Definition BluetoothAdapter.h:16