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 <adeebshihadeh@gmail.com>
pull/69/head
sshane 4 years ago committed by GitHub
parent 45d57d0611
commit cdc386d5bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      selfdrive/ui/qt/offroad/networking.cc
  2. 3
      selfdrive/ui/qt/offroad/networking.h
  3. 12
      selfdrive/ui/qt/offroad/wifiManager.cc
  4. 2
      selfdrive/ui/qt/offroad/wifiManager.h

@ -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) {

@ -69,6 +69,9 @@ private:
WifiUI* wifiWidget;
WifiManager* wifi = nullptr;
protected:
void showEvent(QShowEvent* event) override;
public slots:
void refresh();

@ -69,11 +69,15 @@ void WifiManager::setup() {
QDBusMessage response = device_props.call("Get", NM_DBUS_INTERFACE_DEVICE, "State");
raw_adapter_state = get_response<uint>(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<QDBusObjectPath>(response);
return r.path();
const QDBusMessage &response = device_props.call("Get", NM_DBUS_INTERFACE_DEVICE_WIRELESS, "ActiveAccessPoint");
activeAp = get_response<QDBusObjectPath>(response).path();
}

@ -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<QDBusObjectPath> get_active_connections();
uint get_wifi_device_state();

Loading…
Cancel
Save