From 976c400489e56e4e12bb57ed62342203096b91b7 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sun, 3 Nov 2024 22:24:43 +0100 Subject: [PATCH] Listen to providersChanged in the KCM ui --- kcm/kcm.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index d74c3735c..50a6cff21 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "dbushelpers.h" #include "dbusinterfaces.h" @@ -131,6 +132,31 @@ KdeConnectKcm::KdeConnectKcm(QObject *parent, const KPluginMetaData &md, const Q connect(daemon, &DaemonDbusInterface::announcedNameChanged, kcmUi.rename_edit, &QLineEdit::setText); connect(daemon, &DaemonDbusInterface::announcedNameChanged, kcmUi.rename_label, &QLabel::setText); + connect(daemon, &DaemonDbusInterface::linkProvidersChanged, this, [this](const QStringList &providers) { + if (kcmUi.linkProviders_list->count() == 0) { + return; // not yet setup + } + for (auto i = 0, count = kcmUi.linkProviders_list->count(); i < count; i++) { + const auto item = kcmUi.linkProviders_list->item(i); + const auto id = item->data(Qt::UserRole).toString(); + + bool found = false; + for (const auto &provider : providers) { + if (provider.startsWith(id)) { + const auto status = provider.split(QStringLiteral("|")).at(1); + if (status.compare(QStringLiteral("enabled")) == 0) { + item->setCheckState(Qt::Checked); + } else { + item->setCheckState(Qt::Unchecked); + } + found = true; + break; + } + } + + Q_ASSERT_X(found, Q_FUNC_INFO, "A new backend appeared, this should not happen as the list of backends is static"); + } + }); setRenameMode(false); setButtons(KCModule::Help | KCModule::NoAdditionalButton);