From a34a919a2a8b86b11f934b9f8c3cdd740933036f Mon Sep 17 00:00:00 2001 From: ShaneSmiskol Date: Tue, 27 Jul 2021 16:43:34 -0700 Subject: [PATCH] move to advanced settings --- selfdrive/ui/qt/offroad/networking.cc | 15 ++++++++------- selfdrive/ui/qt/offroad/settings.cc | 6 ------ selfdrive/ui/qt/offroad/wifiManager.cc | 17 ++++++++++++++--- selfdrive/ui/qt/offroad/wifiManager.h | 3 ++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index bb44e0573f..0509173c9a 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -67,13 +67,6 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QFrame(parent) { } )"); main_layout->setCurrentWidget(wifiScreen); - - // roaming timer - QTimer* timer = new QTimer(this); - QObject::connect(timer, &QTimer::timeout, this, [=]() { - wifi->setRoaming(params.getBool("GsmRoaming")); - }); - timer->start(10000); } void Networking::refresh() { @@ -158,6 +151,14 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid main_layout->addWidget(new SshToggle()); main_layout->addWidget(horizontal_line(), 0); main_layout->addWidget(new SshControl()); + main_layout->addWidget(horizontal_line(), 0); + + // Roaming toggle + ToggleControl *roamingToggle = new ToggleControl("Enable Roaming", "", "", wifi->isRoamingEnabled()); + QObject::connect(roamingToggle, &SshToggle::toggleFlipped, [=](bool state) { + wifi->setRoamingEnabled(state); + }); + main_layout->addWidget(roamingToggle); main_layout->addStretch(1); } diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 8e056bdc00..142b2aa836 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -81,12 +81,6 @@ TogglesPanel::TogglesPanel(QWidget *parent) : QWidget(parent) { this)); #endif - toggles.append(new ParamControl("GsmRoaming", - "Enable Roaming", - "Allows mobile network roaming", - "../assets/offroad/icon_map.png", - this)); - bool record_lock = Params().getBool("RecordFrontLock"); record_toggle->setEnabled(!record_lock); diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index 39a20f5152..b5e2f03449 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -422,21 +422,32 @@ NetworkType WifiManager::currentNetworkType() { return NetworkType::NONE; } -void WifiManager::setRoaming(bool roaming) { +void WifiManager::setRoamingEnabled(bool roaming) { const QDBusObjectPath &path = getConnectionPath("lte"); if (!path.path().isEmpty()) { QDBusInterface nm(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); nm.setTimeout(DBUS_TIMEOUT); Connection settings = QDBusReply(nm.call("GetSettings")).value(); - bool prevRoaming = !settings.value("gsm").value("home-only").toBool(); - if (!settings.value("gsm").contains("home-only") || prevRoaming != roaming) { // set if unset or param is changed + if (settings.value("gsm").value("home-only").toBool() == roaming) { settings["gsm"]["home-only"] = !roaming; nm.call("Update", QVariant::fromValue(settings)); } } } +bool WifiManager::isRoamingEnabled() { + const QDBusObjectPath &path = getConnectionPath("lte"); + if (!path.path().isEmpty()) { + QDBusInterface nm(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus); + nm.setTimeout(DBUS_TIMEOUT); + + const Connection &settings = QDBusReply(nm.call("GetSettings")).value(); + return !settings.value("gsm").value("home-only").toBool(); + } + return false; +} + // Functions for tethering void WifiManager::addTetheringConnection() { Connection connection; diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 71c36036f7..0b5526967f 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -49,7 +49,8 @@ public: bool isKnownConnection(const QString &ssid); void activateWifiConnection(const QString &ssid); NetworkType currentNetworkType(); - void setRoaming(bool roaming); + void setRoamingEnabled(bool roaming); + bool isRoamingEnabled(); void connect(const Network &ssid); void connect(const Network &ssid, const QString &password);