diff --git a/core/backends/bluetooth/bluetoothlinkprovider.cpp b/core/backends/bluetooth/bluetoothlinkprovider.cpp index c5206c0a8..1415c191d 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.cpp +++ b/core/backends/bluetooth/bluetoothlinkprovider.cpp @@ -13,11 +13,12 @@ #include -BluetoothLinkProvider::BluetoothLinkProvider() +BluetoothLinkProvider::BluetoothLinkProvider(bool isDisabled) : mServiceUuid(QBluetoothUuid(QStringLiteral("185f3df4-3268-4e3f-9fca-d4d5059915bd"))) , mServiceDiscoveryAgent(new QBluetoothServiceDiscoveryAgent(this)) , connectTimer(new QTimer(this)) { + this->disabled = isDisabled; connectTimer->setInterval(30000); connectTimer->setSingleShot(false); @@ -32,7 +33,7 @@ BluetoothLinkProvider::BluetoothLinkProvider() void BluetoothLinkProvider::onStart() { qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed"; - if (enabled) { + if (!disabled) { tryToInitialise(); } } @@ -59,7 +60,7 @@ void BluetoothLinkProvider::tryToInitialise() void BluetoothLinkProvider::onStop() { - if (enabled) { + if (!disabled) { qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStop executed"; if (!mBluetoothServer) { return; @@ -75,16 +76,16 @@ void BluetoothLinkProvider::onStop() void BluetoothLinkProvider::enable() { - if (enabled == false) { - enabled = true; + if (disabled) { + disabled = false; tryToInitialise(); } } void BluetoothLinkProvider::disable() { - if (enabled == true) { - enabled = false; + if (!disabled) { + disabled = true; this->onStop(); mBluetoothServer = nullptr; @@ -95,7 +96,7 @@ void BluetoothLinkProvider::disable() void BluetoothLinkProvider::onNetworkChange() { qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed"; - if (enabled) { + if (!disabled) { tryToInitialise(); } } diff --git a/core/backends/bluetooth/bluetoothlinkprovider.h b/core/backends/bluetooth/bluetoothlinkprovider.h index 7245e4f66..1d31a614e 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.h +++ b/core/backends/bluetooth/bluetoothlinkprovider.h @@ -29,7 +29,8 @@ class KDECONNECTCORE_EXPORT BluetoothLinkProvider : public LinkProvider Q_OBJECT public: - BluetoothLinkProvider(); + BluetoothLinkProvider(bool disabled = false); + virtual ~BluetoothLinkProvider(); QString name() override @@ -73,7 +74,7 @@ private: QBluetoothServiceInfo mKdeconnectService; QBluetoothServiceDiscoveryAgent *mServiceDiscoveryAgent; QTimer *connectTimer; - bool enabled; + bool disabled; QMap mLinks; diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index 019f8477f..cb44691b6 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -42,7 +42,7 @@ static const int MAX_REMEMBERED_IDENTITY_PACKETS = 42; static const long MILLIS_DELAY_BETWEEN_CONNECTIONS_TO_SAME_DEVICE = 500; -LanLinkProvider::LanLinkProvider(bool testMode) +LanLinkProvider::LanLinkProvider(bool testMode, bool isDisabled) : m_server(new Server(this)) , m_udpSocket(this) , m_tcpPort(0) @@ -52,6 +52,8 @@ LanLinkProvider::LanLinkProvider(bool testMode) , m_mdnsDiscovery(this) #endif { + this->disabled = isDisabled; + m_combineNetworkChangeTimer.setInterval(0); // increase this if waiting a single event-loop iteration is not enough m_combineNetworkChangeTimer.setSingleShot(true); connect(&m_combineNetworkChangeTimer, &QTimer::timeout, this, &LanLinkProvider::combinedOnNetworkChange); diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 4184d6569..4eb2847f9 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -30,7 +30,7 @@ public: /** * @param testMode Some special overrides needed while testing */ - LanLinkProvider(bool testMode = false); + LanLinkProvider(bool testMode = false, bool disabled = false); ~LanLinkProvider() override; QString name() override diff --git a/core/daemon.cpp b/core/daemon.cpp index d1ff01b4b..df344a3cb 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -72,13 +72,16 @@ void Daemon::init() qCDebug(KDECONNECT_CORE) << "DBus registration complete"; + auto configInstance = KdeConnectConfig::instance(); + auto status = configInstance.getLinkProviderStatus(); + // Load backends - if (d->m_testMode) + if (d->m_testMode) { d->m_linkProviders.insert(new LoopbackLinkProvider()); - else { - d->m_linkProviders.insert(new LanLinkProvider()); + } else { + d->m_linkProviders.insert(new LanLinkProvider(false, status[QStringLiteral("disabled")].contains(QStringLiteral("LanLinkProvider")))); #ifdef KDECONNECT_BLUETOOTH - d->m_linkProviders.insert(new BluetoothLinkProvider()); + d->m_linkProviders.insert(new BluetoothLinkProvider(status[QStringLiteral("disabled")].contains(QStringLiteral("BluetoothLinkProvider")))); #endif #ifdef KDECONNECT_LOOPBACK d->m_linkProviders.insert(new LoopbackLinkProvider());