From a75e0ba0316af08d0f86fdd741dbece005f2f805 Mon Sep 17 00:00:00 2001 From: Holger Kaelberer Date: Tue, 3 Jan 2017 22:13:02 +0100 Subject: [PATCH] Make pairing notifications more persistent Notifications are not persistent, and once gone there is no way to accept the request. Clicking the notification in the notification history does nothing in plasma and gnome. There make them persistent and close them after the pairing timeout, after which they are no longer useful. BUG: https://phabricator.kde.org/T5002 --- core/backends/lan/lanpairinghandler.cpp | 2 +- core/backends/pairinghandler.h | 1 + daemon/kdeconnectd.cpp | 5 ++++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/backends/lan/lanpairinghandler.cpp b/core/backends/lan/lanpairinghandler.cpp index 35c41d00b..226acc47f 100644 --- a/core/backends/lan/lanpairinghandler.cpp +++ b/core/backends/lan/lanpairinghandler.cpp @@ -32,7 +32,7 @@ LanPairingHandler::LanPairingHandler(DeviceLink* deviceLink) , m_status(NotPaired) { m_pairingTimeout.setSingleShot(true); - m_pairingTimeout.setInterval(30 * 1000); //30 seconds of timeout + m_pairingTimeout.setInterval(pairingTimeoutMsec()); connect(&m_pairingTimeout, &QTimer::timeout, this, &LanPairingHandler::pairingTimeout); } diff --git a/core/backends/pairinghandler.h b/core/backends/pairinghandler.h index 0ff161bef..21b0e5801 100644 --- a/core/backends/pairinghandler.h +++ b/core/backends/pairinghandler.h @@ -49,6 +49,7 @@ public: virtual void packageReceived(const NetworkPackage& np) = 0; virtual void unpair() = 0; + virtual int pairingTimeoutMsec() const { return 30 * 1000; } // 30 seconds of timeout (default), subclasses that use different values should override public Q_SLOTS: virtual bool requestPairing() = 0; diff --git a/daemon/kdeconnectd.cpp b/daemon/kdeconnectd.cpp index 0f242c7b8..80fee6d71 100644 --- a/daemon/kdeconnectd.cpp +++ b/daemon/kdeconnectd.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -43,7 +44,8 @@ public: void askPairingConfirmation(PairingHandler* d) override { - KNotification* notification = new KNotification(QStringLiteral("pairingRequest")); + KNotification* notification = new KNotification(QStringLiteral("pairingRequest"), + KNotification::Persistent); notification->setIconName(QStringLiteral("dialog-information")); notification->setComponentName(QStringLiteral("kdeconnect")); notification->setText(i18n("Pairing request from %1", getDevice(d->deviceLink()->deviceId())->name())); @@ -51,6 +53,7 @@ public: connect(notification, &KNotification::ignored, d, &PairingHandler::rejectPairing); connect(notification, &KNotification::action1Activated, d, &PairingHandler::acceptPairing); connect(notification, &KNotification::action2Activated, d, &PairingHandler::rejectPairing); + QTimer::singleShot(d->pairingTimeoutMsec(), notification, &KNotification::close); // close after pairing timeout, assuming that the peer uses the same timeout value notification->sendEvent(); }