From 6c77bc5a9f019c4636f0efcb7db55e4bb6df443f Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 25 Jan 2017 01:18:14 +0100 Subject: [PATCH] Debug pairing handlers Make sure we don't emit if it doesn't actually change Make sure if it changed when we react to a pairing Pair-programmed with Albert Vaca --- core/daemon.cpp | 7 +++++-- core/device.cpp | 10 ++++++++-- core/device.h | 4 ++-- interfaces/dbusinterfaces.cpp | 3 ++- interfaces/dbusinterfaces.h | 3 +++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/core/daemon.cpp b/core/daemon.cpp index 5a893996b..a5b767f10 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -247,8 +247,11 @@ void Daemon::addDevice(Device* device) const QString id = device->id(); connect(device, &Device::reachableChanged, this, &Daemon::onDeviceStatusChanged); connect(device, &Device::trustedChanged, this, &Daemon::onDeviceStatusChanged); - connect(device, &Device::pairingRequestsChanged, this, &Daemon::pairingRequestsChanged); - connect(device, &Device::pairingRequestsChanged, this, [this, device]() { askPairingConfirmation(device); } ); + connect(device, &Device::hasPairingRequestsChanged, this, &Daemon::pairingRequestsChanged); + connect(device, &Device::hasPairingRequestsChanged, this, [this, device](bool hasPairingRequests) { + if (hasPairingRequests) + askPairingConfirmation(device); + } ); d->mDevices[id] = device; Q_EMIT deviceAdded(id); diff --git a/core/device.cpp b/core/device.cpp index 255d5670b..e09431be9 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -258,14 +258,20 @@ void Device::addLink(const NetworkPackage& identityPackage, DeviceLink* link) void Device::addPairingRequest(PairingHandler* handler) { + const bool wasEmpty = m_pairRequests.isEmpty(); m_pairRequests.insert(handler); - Q_EMIT pairingRequestsChanged(); + + if (wasEmpty != m_pairRequests.isEmpty()) + Q_EMIT hasPairingRequestsChanged(!m_pairRequests.isEmpty()); } void Device::removePairingRequest(PairingHandler* handler) { + const bool wasEmpty = m_pairRequests.isEmpty(); m_pairRequests.remove(handler); - Q_EMIT pairingRequestsChanged(); + + if (wasEmpty != m_pairRequests.isEmpty()) + Q_EMIT hasPairingRequestsChanged(!m_pairRequests.isEmpty()); } void Device::acceptPairing() diff --git a/core/device.h b/core/device.h index 536ee90d8..f9266b6f9 100644 --- a/core/device.h +++ b/core/device.h @@ -44,7 +44,7 @@ class KDECONNECTCORE_EXPORT Device Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChanged) Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChanged) Q_PROPERTY(QStringList supportedPlugins READ supportedPlugins NOTIFY pluginsChanged) - Q_PROPERTY(bool hasPairingRequests READ hasPairingRequests NOTIFY pairingRequestsChanged) + Q_PROPERTY(bool hasPairingRequests READ hasPairingRequests NOTIFY hasPairingRequestsChanged) public: @@ -133,7 +133,7 @@ Q_SIGNALS: Q_SCRIPTABLE void pairingError(const QString& error); Q_SCRIPTABLE void nameChanged(const QString& name); - void pairingRequestsChanged(); + Q_SCRIPTABLE void hasPairingRequestsChanged(bool hasPairingRequests); private: //Methods static DeviceType str2type(const QString &deviceType); diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index 9e8f72e2b..d288f44d5 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -32,7 +32,7 @@ QString DaemonDbusInterface::activatedService() { DaemonDbusInterface::DaemonDbusInterface(QObject* parent) : OrgKdeKdeconnectDaemonInterface(DaemonDbusInterface::activatedService(), QStringLiteral("/modules/kdeconnect"), QDBusConnection::sessionBus(), parent) { - + connect(this, &OrgKdeKdeconnectDaemonInterface::pairingRequestsChanged, this, &DaemonDbusInterface::pairingRequestsChangedProxy); } DaemonDbusInterface::~DaemonDbusInterface() @@ -47,6 +47,7 @@ DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent) connect(this, &OrgKdeKdeconnectDeviceInterface::trustedChanged, this, &DeviceDbusInterface::trustedChangedProxy); connect(this, &OrgKdeKdeconnectDeviceInterface::reachableChanged, this, &DeviceDbusInterface::reachableChangedProxy); connect(this, &OrgKdeKdeconnectDeviceInterface::nameChanged, this, &DeviceDbusInterface::nameChangedProxy); + connect(this, &OrgKdeKdeconnectDeviceInterface::hasPairingRequestsChanged, this, &DeviceDbusInterface::hasPairingRequestsChangedProxy); } DeviceDbusInterface::~DeviceDbusInterface() diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h index f5eeb13ed..e11f9fa61 100644 --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -52,6 +52,7 @@ public: Q_SIGNALS: void deviceAdded(const QString &id); + void pairingRequestsChangedProxy(); }; class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface @@ -63,6 +64,7 @@ class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableChangedProxy) Q_PROPERTY(bool isTrusted READ isTrusted NOTIFY trustedChangedProxy) Q_PROPERTY(QString name READ name NOTIFY nameChangedProxy) + Q_PROPERTY(bool hasPairingRequests READ hasPairingRequests NOTIFY hasPairingRequestsChangedProxy) public: explicit DeviceDbusInterface(const QString& deviceId, QObject* parent = nullptr); @@ -75,6 +77,7 @@ Q_SIGNALS: void nameChangedProxy(const QString &name); void trustedChangedProxy(bool paired); void reachableChangedProxy(bool reachable); + void hasPairingRequestsChangedProxy(); private: const QString m_id;