From bc48c5e9f8bad2fa86ae1d5031bbb071ebc3783c Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 6 Oct 2024 15:32:21 +0100 Subject: [PATCH] Hacking in a very rough enable/disable (untested) implementation --- .../bluetooth/bluetoothlinkprovider.cpp | 28 +++++++++++-------- .../bluetooth/bluetoothlinkprovider.h | 8 ++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/core/backends/bluetooth/bluetoothlinkprovider.cpp b/core/backends/bluetooth/bluetoothlinkprovider.cpp index c021ae2c5..3248e1c68 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.cpp +++ b/core/backends/bluetooth/bluetoothlinkprovider.cpp @@ -32,7 +32,9 @@ BluetoothLinkProvider::BluetoothLinkProvider() void BluetoothLinkProvider::onStart() { qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed"; - tryToInitialise(); + if (enabled) { + tryToInitialise(); + } } void BluetoothLinkProvider::tryToInitialise() @@ -57,22 +59,26 @@ void BluetoothLinkProvider::tryToInitialise() void BluetoothLinkProvider::onStop() { - qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed"; - if (!mBluetoothServer) { - return; + if (enabled) { + qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed"; + if (!mBluetoothServer) { + return; + } + + connectTimer->stop(); + + mKdeconnectService.unregisterService(); + mBluetoothServer->close(); + mBluetoothServer->deleteLater(); } - - connectTimer->stop(); - - mKdeconnectService.unregisterService(); - mBluetoothServer->close(); - mBluetoothServer->deleteLater(); } void BluetoothLinkProvider::onNetworkChange() { qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed"; - tryToInitialise(); + if (enabled) { + tryToInitialise(); + } } void BluetoothLinkProvider::connectError() diff --git a/core/backends/bluetooth/bluetoothlinkprovider.h b/core/backends/bluetooth/bluetoothlinkprovider.h index c5b5719c9..419dcdb55 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.h +++ b/core/backends/bluetooth/bluetoothlinkprovider.h @@ -44,10 +44,17 @@ public: void enable() override { + enabled = true; + tryToInitialise(); } void disable() override { + enabled = false; + this->onStop(); + + mBluetoothServer = nullptr; + mServiceDiscoveryAgent = nullptr; } public Q_SLOTS: @@ -77,6 +84,7 @@ private: QBluetoothServiceInfo mKdeconnectService; QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent; QTimer *connectTimer; + bool enabled; QMap mLinks;