Commit 1b49255d authored by Valerio Pilo's avatar Valerio Pilo

[plasma-nm] Refresh wifi networks as fast as possible

Summary:
Added a retry mechanism when scanning fails, to prevent waiting unnecessarily long for the next scan.

This usually happens when closing and reopening the applet, or when a scan was started by another component before opening the applet.

Test Plan:
* First enable debug logging, there is no UI feedback
* Tested opening/closing the applet every now and then: wifis are scanned as early as NM allows
* Tested switching to the NM KCM, then switching to the applet, then to the KCM again: wifis are always scanned as early as allowed

Reviewers: jgrulich, ngraham, #plasma

Reviewed By: jgrulich

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D18896
parent 29b6d0ee
......@@ -88,6 +88,7 @@ FocusScope {
notificationInhibitorLock = job.result;
}
});
handler.requestScan()
} else {
notificationInhibitorLock = undefined;
toolbar.closeSearch()
......
......@@ -65,6 +65,13 @@ Item {
PlasmaNM.Handler {
id: handler
onWirelessScanTimerEnabled: {
if (enabled) {
scanTimer.restart()
} else {
scanTimer.stop()
}
}
}
Timer {
......@@ -72,11 +79,8 @@ Item {
interval: 15000
repeat: true
running: plasmoid.expanded
triggeredOnStart: true
onTriggered: {
handler.requestScan()
}
onTriggered: handler.requestScan()
}
PlasmaNM.Configuration {
......
......@@ -185,7 +185,6 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
m_timer->setInterval(15000);
connect(m_timer, &QTimer::timeout, [this] () {
m_handler->requestScan();
m_timer->start();
});
m_timer->start();
}
......
......@@ -73,6 +73,10 @@ Handler::Handler(QObject *parent)
QStringLiteral(AGENT_IFACE),
QStringLiteral("registered"),
this, SLOT(initKdedModule()));
// Interval (in ms) between attempts to scan for wifi networks
m_wirelessScanRetryTimer.setInterval(2000);
m_wirelessScanRetryTimer.setSingleShot(true);
}
Handler::~Handler()
......@@ -408,21 +412,43 @@ void Handler::updateConnection(const NetworkManager::Connection::Ptr& connection
connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished);
}
void Handler::requestScan()
void Handler::requestScan(const QString &interface)
{
for (NetworkManager::Device::Ptr device : NetworkManager::networkInterfaces()) {
if (device->type() == NetworkManager::Device::Wifi) {
NetworkManager::WirelessDevice::Ptr wifiDevice = device.objectCast<NetworkManager::WirelessDevice>();
if (wifiDevice) {
if (!interface.isEmpty() && interface != wifiDevice->interfaceName()) {
continue;
}
qCDebug(PLASMA_NM) << "Requesting wifi scan on device" << wifiDevice->interfaceName();
QDBusPendingReply<> reply = wifiDevice->requestScan();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
watcher->setProperty("action", Handler::RequestScan);
watcher->setProperty("interface", wifiDevice->interfaceName());
connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished);
}
}
}
}
void Handler::scanRequestFailed(const QString &interface)
{
if (m_wirelessScanRetryTimer.isActive()) {
return;
}
qCDebug(PLASMA_NM) << "Trying soon a new scan on" << interface;
emit wirelessScanTimerEnabled(false);
auto retryAction = [this,interface]() {
m_wirelessScanRetryTimer.disconnect();
requestScan(interface);
};
connect(&m_wirelessScanRetryTimer, &QTimer::timeout, this, retryAction);
m_wirelessScanRetryTimer.start();
}
void Handler::initKdedModule()
{
QDBusMessage initMsg = QDBusMessage::createMethodCall(QStringLiteral(AGENT_SERVICE),
......@@ -460,16 +486,17 @@ void Handler::replyFinished(QDBusPendingCallWatcher * watcher)
notification = new KNotification("FailedToRemoveConnection", KNotification::CloseOnTimeout, this);
notification->setTitle(i18n("Failed to remove %1", watcher->property("connection").toString()));
break;
case Handler::RequestScan:
/* INFO: Disabled for now as wifi scanning is now automatic
notification = new KNotification("FailedToRequestScan", KNotification::CloseOnTimeout, this);
notification->setTitle(i18n("Failed to request scan"));
*/
break;
case Handler::UpdateConnection:
notification = new KNotification("FailedToUpdateConnection", KNotification::CloseOnTimeout, this);
notification->setTitle(i18n("Failed to update connection %1", watcher->property("connection").toString()));
break;
case Handler::RequestScan:
{
const QString interface = watcher->property("interface").toString();
qCDebug(PLASMA_NM) << "Wireless scan on" << interface << "failed:" << error;
scanRequestFailed(interface);
break;
}
default:
break;
}
......@@ -497,6 +524,10 @@ void Handler::replyFinished(QDBusPendingCallWatcher * watcher)
notification = new KNotification("ConnectionUpdated", KNotification::CloseOnTimeout, this);
notification->setText(i18n("Connection %1 has been updated", watcher->property("connection").toString()));
break;
case Handler::RequestScan:
qCDebug(PLASMA_NM) << "Wireless scan on" << watcher->property("interface").toString() << "succeeded";
emit wirelessScanTimerEnabled(true);
break;
default:
break;
}
......
......@@ -100,7 +100,7 @@ public Q_SLOTS:
* @map - NMVariantMapMap with new connection settings
*/
void updateConnection(const NetworkManager::Connection::Ptr &connection, const NMVariantMapMap &map);
void requestScan();
void requestScan(const QString &interface = QString());
private Q_SLOTS:
void initKdedModule();
......@@ -109,6 +109,8 @@ private Q_SLOTS:
void unlockRequiredChanged(MMModemLock modemLock);
#endif
Q_SIGNALS:
void wirelessScanTimerEnabled(bool enable);
private:
bool m_tmpWirelessEnabled;
bool m_tmpWwanEnabled;
......@@ -119,8 +121,10 @@ private:
QString m_tmpDevicePath;
QString m_tmpSpecificPath;
QMap<QString, bool> m_bluetoothAdapters;
QTimer m_wirelessScanRetryTimer;
void enableBluetooth(bool enable);
void scanRequestFailed(const QString &interface);
};
......
......@@ -35,6 +35,13 @@ Kirigami.ApplicationItem {
PlasmaNM.Handler {
id: handler
onWirelessScanTimerEnabled: {
if (enabled) {
scanTimer.restart()
} else {
scanTimer.stop()
}
}
}
PlasmaNM.EnabledConnections {
......@@ -59,16 +66,15 @@ Kirigami.ApplicationItem {
showSavedMode: false
}
Component.onCompleted: handler.requestScan()
Timer {
id: scanTimer
interval: 15000
repeat: true
running: parent.visible
triggeredOnStart: true
onTriggered: {
handler.requestScan()
}
onTriggered: handler.requestScan()
}
NetworkListView {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment