From af43a21864c2c3f2118b07bec01dd1f6f7c313db Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Thu, 17 Dec 2015 06:53:29 -0800 Subject: [PATCH] Propagate pairingError --- core/backends/lan/lanlinkprovider.cpp | 29 +++++++++++++-------------- core/backends/lan/lanlinkprovider.h | 3 ++- core/device.cpp | 9 +++++++++ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index 504dff943..aab269c1a 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -460,28 +460,27 @@ void LanLinkProvider::addLink(const QString& deviceId, QSslSocket* socket, Netwo } +LanPairingHandler* LanLinkProvider::createPairingHandler(DeviceLink* link) +{ + LanPairingHandler* ph = mPairingHandlers.value(link->deviceId()); + if (!ph) { + ph = new LanPairingHandler(link); + qDebug() << "creating pairing handler for" << link->deviceId(); + connect (ph, &LanPairingHandler::pairingError, link, &DeviceLink::pairingError); + mPairingHandlers[link->deviceId()] = ph; + } + return ph; +} + void LanLinkProvider::userRequestsPair(const QString& deviceId) { - LanPairingHandler* ph = mPairingHandlers.value(deviceId); - if (!ph) { - LanDeviceLink* link = mLinks.value(deviceId); - qDebug() << "Creating LanPairingHandler with link " << link; - ph = new LanPairingHandler(link); - mPairingHandlers[deviceId] = ph; - } - + LanPairingHandler* ph = createPairingHandler(mLinks.value(deviceId)); ph->requestPairing(); } void LanLinkProvider::incomingPairPackage(DeviceLink* deviceLink, const NetworkPackage& np) { - const QString deviceId = deviceLink->deviceId(); - LanPairingHandler* ph = mPairingHandlers.value(deviceId); - if (!ph) { - ph = new LanPairingHandler(deviceLink); - mPairingHandlers[deviceId] = ph; - } - + LanPairingHandler* ph = createPairingHandler(deviceLink); ph->packageReceived(np); } diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index db82e6334..42bcb6801 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -64,9 +64,10 @@ private Q_SLOTS: private: static void configureSocket(QSslSocket* socket); + LanPairingHandler* createPairingHandler(DeviceLink* link); + void onNetworkConfigurationChanged(const QNetworkConfiguration &config); void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, DeviceLink::ConnectionStarted connectionOrigin); - void refreshPairingHandler(const QString &deviceId); Server* mServer; QUdpSocket* mUdpServer; diff --git a/core/device.cpp b/core/device.cpp index afeff20f9..1074c031a 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -47,6 +47,11 @@ Q_LOGGING_CATEGORY(KDECONNECT_CORE, "kdeconnect.core") +static void warn(const QString &info) +{ + qWarning() << "Device pairing error" << info; +} + Device::Device(QObject* parent, const QString& id) : QObject(parent) , m_deviceId(id) @@ -59,6 +64,8 @@ Device::Device(QObject* parent, const QString& id) //Register in bus QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); + + connect(this, &Device::pairingError, this, &warn); } Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLink* dl) @@ -72,6 +79,8 @@ Device::Device(QObject* parent, const NetworkPackage& identityPackage, DeviceLin //Register in bus QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents | QDBusConnection::ExportAdaptors); + + connect(this, &Device::pairingError, this, &warn); } Device::~Device()