From cdc386d5bb2686bd5af98cfca344ab66d930ca6f Mon Sep 17 00:00:00 2001 From: sshane Date: Wed, 14 Jul 2021 13:27:18 -0700 Subject: [PATCH] networking: update on show (#21575) * refresh on show event * setup fix * show scanning message if no networks nearby * setup isn't ready in 1 second, use signal again * clean up * clean up * Update selfdrive/ui/qt/offroad/networking.cc * Update selfdrive/ui/qt/offroad/networking.cc Co-authored-by: Adeeb Shihadeh --- selfdrive/ui/qt/offroad/networking.cc | 16 ++++++++++++++++ selfdrive/ui/qt/offroad/networking.h | 3 +++ selfdrive/ui/qt/offroad/wifiManager.cc | 12 +++++++----- selfdrive/ui/qt/offroad/wifiManager.h | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index 2b0e00dde4..0fe29fd249 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -101,6 +101,16 @@ void Networking::wrongPassword(const QString &ssid) { } } +void Networking::showEvent(QShowEvent* event) { + // Wait to refresh to avoid queuing up too many scans if shown and hidden quickly + QTimer::singleShot(300, this, [=]() { + if (this->isVisible()) { + wifi->refreshNetworks(); + refresh(); + } + }); +} + // AdvancedNetworking functions AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWidget(parent), wifi(wifi) { @@ -169,6 +179,12 @@ WifiUI::WifiUI(QWidget *parent, WifiManager* wifi) : QWidget(parent), wifi(wifi) void WifiUI::refresh() { clearLayout(main_layout); + if (wifi->seen_networks.size() == 0) { + QLabel *scanning = new QLabel("No networks found. Scanning..."); + scanning->setStyleSheet(R"(font-size: 65px;)"); + main_layout->addWidget(scanning, 0, Qt::AlignCenter); + return; + } int i = 0; for (Network &network : wifi->seen_networks) { diff --git a/selfdrive/ui/qt/offroad/networking.h b/selfdrive/ui/qt/offroad/networking.h index 34a7000d38..7c0ad319bf 100644 --- a/selfdrive/ui/qt/offroad/networking.h +++ b/selfdrive/ui/qt/offroad/networking.h @@ -69,6 +69,9 @@ private: WifiUI* wifiWidget; WifiManager* wifi = nullptr; +protected: + void showEvent(QShowEvent* event) override; + public slots: void refresh(); diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index 78c974a9e3..06a51990b2 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -69,11 +69,15 @@ void WifiManager::setup() { QDBusMessage response = device_props.call("Get", NM_DBUS_INTERFACE_DEVICE, "State"); raw_adapter_state = get_response(response); + initActiveAp(); initConnections(); requestScan(); } void WifiManager::refreshNetworks() { + if (adapter.isEmpty()) { + return; + } seen_networks.clear(); seen_ssids.clear(); ipv4_address = get_ipv4_address(); @@ -316,7 +320,6 @@ void WifiManager::stateChange(unsigned int new_state, unsigned int previous_stat void WifiManager::propertyChange(const QString &interface, const QVariantMap &props, const QStringList &invalidated_props) { if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("LastScan")) { if (this->isVisible() || firstScan) { - activeAp = getActiveAp(); refreshNetworks(); emit refreshSignal(); firstScan = false; @@ -431,13 +434,12 @@ void WifiManager::setTetheringEnabled(bool enabled) { } } -QString WifiManager::getActiveAp() { +void WifiManager::initActiveAp() { QDBusInterface device_props(NM_DBUS_SERVICE, adapter, NM_DBUS_INTERFACE_PROPERTIES, bus); device_props.setTimeout(DBUS_TIMEOUT); - QDBusMessage response = device_props.call("Get", NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveAccessPoint"); - QDBusObjectPath r = get_response(response); - return r.path(); + const QDBusMessage &response = device_props.call("Get", NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveAccessPoint"); + activeAp = get_response(response).path(); } diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 4e8a3fd592..e6741ec8ff 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -69,7 +69,7 @@ private: QString get_ipv4_address(); void connect(const QByteArray &ssid, const QString &username, const QString &password, SecurityType security_type); QString activeAp; - QString getActiveAp(); + void initActiveAp(); void deactivateConnection(const QString &ssid); QVector get_active_connections(); uint get_wifi_device_state();