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
This commit is contained in:
Holger Kaelberer 2017-01-03 22:13:02 +01:00
parent 8bd4a5831c
commit a75e0ba031
3 changed files with 6 additions and 2 deletions

View file

@ -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);
}

View file

@ -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;

View file

@ -20,6 +20,7 @@
#include <QApplication>
#include <QNetworkAccessManager>
#include <QTimer>
#include <KDBusService>
#include <KNotification>
@ -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();
}