From 71c63c47b51047533f5d9533f27be4375778b21d Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 8 Oct 2026 21:20:02 +0200 Subject: [PATCH] Reduce redundant dbus signals if the pair state didn't change (cherry picked from commit 1cf29f98647bc2ba1a3ab26b4cc887dc5a94aa04) (conflict resolved w/ commit d4766a6fbe34b08ec5678f3bbbc6b422aa67eb6a) --- core/device.cpp | 24 ++++++++++++++++++------ core/device.h | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index d0af856e0..e502be9ae 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -32,6 +32,7 @@ DevicePrivate(const DeviceInfo &deviceInfo, PairingHandler *pairingHandler) : m_deviceInfo(deviceInfo) , m_pairingHandler(pairingHandler) + , m_lastNotifiedPairState(pairingHandler->pairState()) , m_supportedPlugins(PluginLoader::instance()->pluginsForCapabilities(deviceInfo.incomingCapabilities, deviceInfo.outgoingCapabilities)) { } @@ -43,13 +44,14 @@ } DeviceInfo m_deviceInfo; + PairingHandler *m_pairingHandler; + PairState m_lastNotifiedPairState; QVector m_deviceLinks; QHash m_plugins; QMultiMap m_pluginsByIncomingCapability; QSet m_supportedPlugins; - PairingHandler *m_pairingHandler; }; Device::Device(QObject *parent, const QString &id) @@ -219,7 +221,7 @@ { qCDebug(KDECONNECT_CORE) << "Request pairing"; d->m_pairingHandler->requestPairing(); - Q_EMIT pairStateChanged(pairStateAsInt()); + notifyPairStateChanged(); } void Device::unpair() @@ -240,10 +242,20 @@ d->m_pairingHandler->cancelPairing(); } +void Device::notifyPairStateChanged() +{ + const PairState state = pairState(); + if (state == d->m_lastNotifiedPairState) { + return; + } + d->m_lastNotifiedPairState = state; + Q_EMIT pairStateChanged((int)state); +} + void Device::pairingHandler_incomingPairRequest() { Q_ASSERT(d->m_pairingHandler->pairState() == PairState::RequestedByPeer); - Q_EMIT pairStateChanged(pairStateAsInt()); + notifyPairStateChanged(); } void Device::pairingHandler_pairingSuccessful() @@ -251,7 +263,7 @@ Q_ASSERT(d->m_pairingHandler->pairState() == PairState::Paired); KdeConnectConfig::instance().addTrustedDevice(d->m_deviceInfo); reloadPlugins(); // Will load/unload plugins - Q_EMIT pairStateChanged(pairStateAsInt()); + notifyPairStateChanged(); } void Device::pairingHandler_pairingFailed(const QString &errorMessage) @@ -259,7 +271,7 @@ Q_ASSERT(d->m_pairingHandler->pairState() == PairState::NotPaired); qCWarning(KDECONNECT_CORE) << "Device pairing error" << errorMessage; Q_EMIT pairingFailed(errorMessage); - Q_EMIT pairStateChanged(pairStateAsInt()); + notifyPairStateChanged(); } void Device::pairingHandler_unpaired() @@ -268,7 +280,7 @@ qCDebug(KDECONNECT_CORE) << "Unpaired"; KdeConnectConfig::instance().removeTrustedDevice(id()); reloadPlugins(); // Will load/unload plugins - Q_EMIT pairStateChanged(pairStateAsInt()); + notifyPairStateChanged(); } void Device::addLink(DeviceLink *link) diff --git a/core/device.h b/core/device.h index 688d72b2f..ea293cebc 100644 --- a/core/device.h +++ b/core/device.h @@ -139,6 +139,7 @@ Q_SIGNALS: private: void init(); + void notifyPairStateChanged(); class DevicePrivate; DevicePrivate *d; }; -- GitLab