From 21b081ad145b1cac8ef7cc31c0e8662a3292a23a Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Sun, 6 Oct 2024 01:06:30 +0100 Subject: [PATCH] Wiring up config and forcing implementation of enable/disable per provider --- .../bluetooth/bluetoothlinkprovider.h | 8 ++++ core/backends/lan/lanlinkprovider.h | 7 ++++ core/backends/linkprovider.h | 3 ++ core/backends/loopback/loopbacklinkprovider.h | 8 ++++ core/daemon.cpp | 37 ++++++++++++++++++- core/kdeconnectconfig.cpp | 17 +++++++++ core/kdeconnectconfig.h | 2 + 7 files changed, 80 insertions(+), 2 deletions(-) diff --git a/core/backends/bluetooth/bluetoothlinkprovider.h b/core/backends/bluetooth/bluetoothlinkprovider.h index cf35d0ae2..c5b5719c9 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.h +++ b/core/backends/bluetooth/bluetoothlinkprovider.h @@ -42,6 +42,14 @@ public: return 10; } + void enable() override + { + } + + void disable() override + { + } + public Q_SLOTS: virtual void onNetworkChange() override; virtual void onStart() override; diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 53522dafa..0ceeed51d 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -43,6 +43,13 @@ public: return 20; } + void enable() override + { + } + void disable() override + { + } + void sendUdpIdentityPacket(const QList &addresses); static void configureSslSocket(QSslSocket *socket, const QString &deviceId, bool isDeviceTrusted); diff --git a/core/backends/linkprovider.h b/core/backends/linkprovider.h index eeddd1d07..7b863ba30 100644 --- a/core/backends/linkprovider.h +++ b/core/backends/linkprovider.h @@ -24,6 +24,9 @@ public: virtual QString name() = 0; virtual int priority() = 0; + virtual void enable() = 0; + virtual void disable() = 0; + public Q_SLOTS: virtual void onStart() = 0; virtual void onStop() = 0; diff --git a/core/backends/loopback/loopbacklinkprovider.h b/core/backends/loopback/loopbacklinkprovider.h index d6e82b888..fc5adda2e 100644 --- a/core/backends/loopback/loopbacklinkprovider.h +++ b/core/backends/loopback/loopbacklinkprovider.h @@ -27,6 +27,14 @@ public: return 0; } + void enable() override + { + } + + void disable() override + { + } + void onStart() override; void onStop() override; void onNetworkChange() override; diff --git a/core/daemon.cpp b/core/daemon.cpp index e91eefa28..d1ff01b4b 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -149,11 +149,19 @@ QSet Daemon::getLinkProviders() const QStringList Daemon::linkProviders() const { + auto configInstance = KdeConnectConfig::instance(); + auto status = configInstance.getLinkProviderStatus(); QStringList returnValue; for (LinkProvider *a : std::as_const(d->m_linkProviders)) { QString line = QString(a->name()); - line += QStringLiteral("|enabled"); + + if (status[QStringLiteral("enabled")].contains(a->name())) { + line += QStringLiteral("|enabled"); + } else { + line += QStringLiteral("|disabled"); + } + returnValue.append(line); } return returnValue; @@ -162,9 +170,34 @@ QStringList Daemon::linkProviders() const void Daemon::setProviderStatus(const QStringList &providerStatus) { qCDebug(KDECONNECT_CORE) << "setProviderStatus called" << providerStatus; + + KdeConnectConfig configInstance = KdeConnectConfig::instance(); + + QStringList enabledProviders; + QStringList disabledProviders; + for (const auto &i : providerStatus) { - qCDebug(KDECONNECT_CORE) << "setProviderstatus with: " << i; + auto components = i.split(QStringLiteral("|")); + QString providerName = components.at(0); + QString providerStatus = components.at(1); + + auto linkProviders = this->getLinkProviders(); + for (LinkProvider *provider : linkProviders) { + if (provider->name() == providerName) { + if (providerStatus == QStringLiteral("enabled")) { + qCDebug(KDECONNECT_CORE) << "enabling " << providerName; + provider->enable(); + enabledProviders.append(providerName); + } else { + qCDebug(KDECONNECT_CORE) << "disabling" << providerName; + provider->disable(); + disabledProviders.append(providerName); + } + break; + } + } } + configInstance.setLinkProviderStatus(enabledProviders, disabledProviders); } QStringList Daemon::devices(bool onlyReachable, bool onlyTrusted) const diff --git a/core/kdeconnectconfig.cpp b/core/kdeconnectconfig.cpp index 8fc419e61..351789a76 100644 --- a/core/kdeconnectconfig.cpp +++ b/core/kdeconnectconfig.cpp @@ -76,6 +76,23 @@ void KdeConnectConfig::setName(const QString &name) d->m_config->sync(); } +void KdeConnectConfig::setLinkProviderStatus(const QStringList enabledProviders, const QStringList disabledProviders) +{ + d->m_config->setValue(QStringLiteral("enabled_providers"), enabledProviders); + d->m_config->setValue(QStringLiteral("disabled_providers"), disabledProviders); + d->m_config->sync(); +} + +QMap KdeConnectConfig::getLinkProviderStatus() +{ + QMap result; + + result[QStringLiteral("enabled")] = d->m_config->value(QStringLiteral("enabled_providers")).toStringList(); + result[QStringLiteral("disabled")] = d->m_config->value(QStringLiteral("disabled_providers")).toStringList(); + + return result; +} + DeviceType KdeConnectConfig::deviceType() { const QByteArrayList platforms = qgetenv("PLASMA_PLATFORM").split(':'); diff --git a/core/kdeconnectconfig.h b/core/kdeconnectconfig.h index 2137e2170..5cc1b256e 100644 --- a/core/kdeconnectconfig.h +++ b/core/kdeconnectconfig.h @@ -35,6 +35,8 @@ public: QString certificatePath(); void setName(const QString &name); + void setLinkProviderStatus(const QStringList enabledProviders, const QStringList disabledProviders); + QMap getLinkProviderStatus(); /* * Trusted devices