diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index b9444666b5..15035c1911 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -117,13 +117,13 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid main_layout->addWidget(back, 0, Qt::AlignLeft); // Enable tethering layout - ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->tetheringEnabled()); + ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->isTetheringEnabled()); main_layout->addWidget(tetheringToggle); QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); main_layout->addWidget(horizontal_line(), 0); // Change tethering password - editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); + ButtonControl *editPasswordButton = new ButtonControl("Tethering Password", "EDIT"); connect(editPasswordButton, &ButtonControl::released, [=]() { QString pass = InputDialog::getText("Enter new tethering password", 8, wifi->getTetheringPassword()); if (!pass.isEmpty()) { @@ -151,13 +151,8 @@ void AdvancedNetworking::refresh() { update(); } -void AdvancedNetworking::toggleTethering(bool enable) { - if (enable) { - wifi->enableTethering(); - } else { - wifi->disableTethering(); - } - editPasswordButton->setEnabled(!enable); +void AdvancedNetworking::toggleTethering(bool enabled) { + wifi->setTetheringEnabled(enabled); } // WifiUI functions @@ -183,7 +178,7 @@ void WifiUI::refresh() { ssid_label->setStyleSheet("font-size: 55px;"); hlayout->addWidget(ssid_label, 1, Qt::AlignLeft); - if (wifi->isKnownConnection(network.ssid) && !wifi->tetheringEnabled()) { + if (wifi->isKnownConnection(network.ssid) && !wifi->isTetheringEnabled()) { QPushButton *forgetBtn = new QPushButton(); QPixmap pix("../assets/offroad/icon_close.svg"); diff --git a/selfdrive/ui/qt/offroad/networking.h b/selfdrive/ui/qt/offroad/networking.h index e523965071..34a7000d38 100644 --- a/selfdrive/ui/qt/offroad/networking.h +++ b/selfdrive/ui/qt/offroad/networking.h @@ -30,8 +30,6 @@ private: WifiManager *wifi = nullptr; QVBoxLayout* main_layout; - bool tetheringEnabled; - signals: void connectToNetwork(const Network &n); @@ -46,14 +44,13 @@ public: private: LabelControl* ipLabel; - ButtonControl* editPasswordButton; WifiManager* wifi = nullptr; signals: void backPress(); public slots: - void toggleTethering(bool enable); + void toggleTethering(bool enabled); void refresh(); }; diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index abeedf4491..9a5da5f372 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -438,18 +438,18 @@ void WifiManager::addTetheringConnection() { nm_settings.call("AddConnection", QVariant::fromValue(connection)); } -void WifiManager::enableTethering() { - if (!isKnownConnection(tethering_ssid)) { - addTetheringConnection(); +void WifiManager::setTetheringEnabled(bool enabled) { + if (enabled) { + if (!isKnownConnection(tethering_ssid)) { + addTetheringConnection(); + } + activateWifiConnection(tethering_ssid); + } else { + deactivateConnection(tethering_ssid); } - activateWifiConnection(tethering_ssid.toUtf8()); } -void WifiManager::disableTethering() { - deactivateConnection(tethering_ssid.toUtf8()); -} - -bool WifiManager::tetheringEnabled() { +bool WifiManager::isTetheringEnabled() { if (activeAp != "" && activeAp != "/") { return get_property(activeAp, "Ssid") == tethering_ssid; } @@ -480,5 +480,9 @@ void WifiManager::changeTetheringPassword(const QString &newPassword) { Connection settings = QDBusReply(nm.call("GetSettings")).value(); settings["802-11-wireless-security"]["psk"] = newPassword; nm.call("Update", QVariant::fromValue(settings)); + + if (isTetheringEnabled()) { + activateWifiConnection(tethering_ssid); + } } } diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 6649f93b9c..4e52a726f9 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -40,6 +40,7 @@ public: void refreshNetworks(); void forgetConnection(const QString &ssid); bool isKnownConnection(const QString &ssid); + void activateWifiConnection(const QString &ssid); void connect(const Network &ssid); void connect(const Network &ssid, const QString &password); @@ -47,12 +48,9 @@ public: void disconnect(); // Tethering functions - void enableTethering(); - void disableTethering(); - bool tetheringEnabled(); - + void setTetheringEnabled(bool enabled); + bool isTetheringEnabled(); void addTetheringConnection(); - void activateWifiConnection(const QString &ssid); void changeTetheringPassword(const QString &newPassword); QString getTetheringPassword();