diff --git a/applet/contents/ui/PopupDialog.qml b/applet/contents/ui/PopupDialog.qml --- a/applet/contents/ui/PopupDialog.qml +++ b/applet/contents/ui/PopupDialog.qml @@ -88,6 +88,7 @@ notificationInhibitorLock = job.result; } }); + handler.requestScan() } else { notificationInhibitorLock = undefined; toolbar.closeSearch() diff --git a/applet/contents/ui/main.qml b/applet/contents/ui/main.qml --- a/applet/contents/ui/main.qml +++ b/applet/contents/ui/main.qml @@ -65,18 +65,22 @@ PlasmaNM.Handler { id: handler + onWirelessScanTimerEnabled: { + if (enabled) { + scanTimer.restart() + } else { + scanTimer.stop() + } + } } Timer { id: scanTimer interval: 15000 repeat: true running: plasmoid.expanded - triggeredOnStart: true - onTriggered: { - handler.requestScan() - } + onTriggered: handler.requestScan() } PlasmaNM.Configuration { diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -185,7 +185,6 @@ m_timer->setInterval(15000); connect(m_timer, &QTimer::timeout, [this] () { m_handler->requestScan(); - m_timer->start(); }); m_timer->start(); } diff --git a/libs/handler.h b/libs/handler.h --- a/libs/handler.h +++ b/libs/handler.h @@ -100,15 +100,17 @@ * @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(); void replyFinished(QDBusPendingCallWatcher *watcher); #if WITH_MODEMMANAGER_SUPPORT void unlockRequiredChanged(MMModemLock modemLock); #endif +Q_SIGNALS: + void wirelessScanTimerEnabled(bool enable); private: bool m_tmpWirelessEnabled; bool m_tmpWwanEnabled; @@ -119,8 +121,10 @@ QString m_tmpDevicePath; QString m_tmpSpecificPath; QMap m_bluetoothAdapters; + QTimer m_wirelessScanRetryTimer; void enableBluetooth(bool enable); + void scanRequestFailed(const QString &interface); }; diff --git a/libs/handler.cpp b/libs/handler.cpp --- a/libs/handler.cpp +++ b/libs/handler.cpp @@ -73,6 +73,10 @@ 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 @@ 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(); 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 @@ 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 @@ 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; } diff --git a/mobile/wifi/package/contents/ui/main.qml b/mobile/wifi/package/contents/ui/main.qml --- a/mobile/wifi/package/contents/ui/main.qml +++ b/mobile/wifi/package/contents/ui/main.qml @@ -35,6 +35,13 @@ PlasmaNM.Handler { id: handler + onWirelessScanTimerEnabled: { + if (enabled) { + scanTimer.restart() + } else { + scanTimer.stop() + } + } } PlasmaNM.EnabledConnections { @@ -59,16 +66,15 @@ 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 {