mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-21 22:12:05 +08:00
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>
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user