33#include < qcontainerfwd.h>
44#include < qhash.h>
55#include < qobject.h>
6+ #include < qproperty.h>
67#include < qqmlintegration.h>
78#include < qtmetamacros.h>
89
@@ -22,18 +23,21 @@ class Bluez: public QObject {
2223public:
2324 [[nodiscard]] ObjectModel<BluetoothAdapter>* adapters () { return &this ->mAdapters ; }
2425 [[nodiscard]] ObjectModel<BluetoothDevice>* devices () { return &this ->mDevices ; }
25- [[nodiscard]] BluetoothAdapter* defaultAdapter () const ;
2626
2727 [[nodiscard]] BluetoothAdapter* adapter (const QString& path) {
2828 return this ->mAdapterMap .value (path);
2929 }
3030
3131 static Bluez* instance ();
3232
33+ signals:
34+ void defaultAdapterChanged ();
35+
3336private slots:
3437 void
3538 onInterfacesAdded (const QDBusObjectPath& path, const DBusObjectManagerInterfaces& interfaces);
3639 void onInterfacesRemoved (const QDBusObjectPath& path, const QStringList& interfaces);
40+ void updateDefaultAdapter ();
3741
3842private:
3943 explicit Bluez ();
@@ -44,14 +48,17 @@ private slots:
4448 QHash<QString, BluetoothDevice*> mDeviceMap ;
4549 ObjectModel<BluetoothAdapter> mAdapters {this };
4650 ObjectModel<BluetoothDevice> mDevices {this };
51+
52+ public:
53+ Q_OBJECT_BINDABLE_PROPERTY (Bluez, BluetoothAdapter*, bDefaultAdapter, &Bluez::defaultAdapterChanged);
4754};
4855
4956// /! Bluetooth manager
5057// / Provides access to bluetooth devices and adapters.
5158class BluezQml : public QObject {
5259 Q_OBJECT;
5360 // / The default bluetooth adapter. Usually there is only one.
54- Q_PROPERTY (BluetoothAdapter* defaultAdapter READ defaultAdapter CONSTANT );
61+ Q_PROPERTY (BluetoothAdapter* defaultAdapter READ default NOTIFY defaultAdapterChanged BINDABLE bindableDefaultAdapter );
5562 QSDOC_TYPE_OVERRIDE (ObjectModel<qs::bluetooth::BluetoothAdapter>*);
5663 // / A list of all bluetooth adapters. See @@defaultAdapter for the default.
5764 Q_PROPERTY (UntypedObjectModel* adapters READ adapters CONSTANT);
@@ -62,8 +69,11 @@ class BluezQml: public QObject {
6269 QML_NAMED_ELEMENT (Bluetooth);
6370 QML_SINGLETON;
6471
72+ signals:
73+ void defaultAdapterChanged ();
74+
6575public:
66- explicit BluezQml (QObject* parent = nullptr ): QObject(parent) {}
76+ explicit BluezQml ();
6777
6878 [[nodiscard]] static ObjectModel<BluetoothAdapter>* adapters () {
6979 return Bluez::instance ()->adapters ();
@@ -73,8 +83,8 @@ class BluezQml: public QObject {
7383 return Bluez::instance ()->devices ();
7484 }
7585
76- [[nodiscard]] static BluetoothAdapter* defaultAdapter () {
77- return Bluez::instance ()->defaultAdapter () ;
86+ [[nodiscard]] static QBindable< BluetoothAdapter*> bindableDefaultAdapter () {
87+ return & Bluez::instance ()->bDefaultAdapter ;
7888 }
7989};
8090
0 commit comments