mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-11 12:22:14 +08:00
UI: roaming toggle (#21750)
* roaming toggle * clean up * only tici * fix order * move to wifiManager * should be working * clean up clean up * use map icon * move to advanced settings * clean up * temporarily change home-only * keep setting for now * set both to defaults in case ui doesn't start * knownConnections stores conn names * Revert "knownConnections stores conn names" This reverts commit 4466a029a38f8c89876fad3c221e95e8fc572ded. * save lteConnectionPath instead * use the if statement Co-authored-by: Comma Device <device@comma.ai> old-commit-hash: 6fad0055b464492d6457597116125f50155b74a3
This commit is contained in:
@@ -150,6 +150,7 @@ std::unordered_map<std::string, uint32_t> keys = {
|
||||
{"GitRemote", PERSISTENT},
|
||||
{"GithubSshKeys", PERSISTENT},
|
||||
{"GithubUsername", PERSISTENT},
|
||||
{"GsmRoaming", PERSISTENT},
|
||||
{"HardwareSerial", PERSISTENT},
|
||||
{"HasAcceptedTerms", PERSISTENT},
|
||||
{"IsDriverViewEnabled", CLEAR_ON_MANAGER_START},
|
||||
|
||||
@@ -149,6 +149,17 @@ 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
|
||||
const bool roamingEnabled = params.getBool("GsmRoaming");
|
||||
wifi->setRoamingEnabled(roamingEnabled);
|
||||
ToggleControl *roamingToggle = new ToggleControl("Enable Roaming", "", "", roamingEnabled);
|
||||
QObject::connect(roamingToggle, &SshToggle::toggleFlipped, [=](bool state) {
|
||||
params.putBool("GsmRoaming", state);
|
||||
wifi->setRoamingEnabled(state);
|
||||
});
|
||||
main_layout->addWidget(roamingToggle);
|
||||
|
||||
main_layout->addStretch(1);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ private:
|
||||
LabelControl* ipLabel;
|
||||
ToggleControl* tetheringToggle;
|
||||
WifiManager* wifi = nullptr;
|
||||
Params params;
|
||||
|
||||
signals:
|
||||
void backPress();
|
||||
|
||||
@@ -341,7 +341,7 @@ void WifiManager::connectionRemoved(const QDBusObjectPath &path) {
|
||||
}
|
||||
|
||||
void WifiManager::newConnection(const QDBusObjectPath &path) {
|
||||
knownConnections[path] = getConnectionSsid(path);
|
||||
knownConnections[path] = getConnectionSettings(path).value("802-11-wireless").value("ssid").toString();
|
||||
if (knownConnections[path] != tethering_ssid) {
|
||||
activateWifiConnection(knownConnections[path]);
|
||||
}
|
||||
@@ -362,11 +362,10 @@ QDBusObjectPath WifiManager::getConnectionPath(const QString &ssid) {
|
||||
return QDBusObjectPath();
|
||||
}
|
||||
|
||||
QString WifiManager::getConnectionSsid(const QDBusObjectPath &path) {
|
||||
Connection WifiManager::getConnectionSettings(const QDBusObjectPath &path) {
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, path.path(), NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
const QDBusReply<Connection> result = nm.call("GetSettings");
|
||||
return result.value().value("802-11-wireless").value("ssid").toString();
|
||||
return QDBusReply<Connection>(nm.call("GetSettings")).value();
|
||||
}
|
||||
|
||||
void WifiManager::initConnections() {
|
||||
@@ -375,7 +374,12 @@ void WifiManager::initConnections() {
|
||||
|
||||
const QDBusReply<QList<QDBusObjectPath>> response = nm.call("ListConnections");
|
||||
for (const QDBusObjectPath &path : response.value()) {
|
||||
knownConnections[path] = getConnectionSsid(path);
|
||||
const Connection &settings = getConnectionSettings(path);
|
||||
if (settings.value("connection").value("type") == "802-11-wireless") {
|
||||
knownConnections[path] = settings.value("802-11-wireless").value("ssid").toString();
|
||||
} else if (path.path() != "/") {
|
||||
lteConnectionPath = path.path();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,6 +420,19 @@ NetworkType WifiManager::currentNetworkType() {
|
||||
return NetworkType::NONE;
|
||||
}
|
||||
|
||||
void WifiManager::setRoamingEnabled(bool roaming) {
|
||||
if (!lteConnectionPath.isEmpty()) {
|
||||
QDBusInterface nm(NM_DBUS_SERVICE, lteConnectionPath, NM_DBUS_INTERFACE_SETTINGS_CONNECTION, bus);
|
||||
nm.setTimeout(DBUS_TIMEOUT);
|
||||
|
||||
Connection settings = QDBusReply<Connection>(nm.call("GetSettings")).value();
|
||||
if (settings.value("gsm").value("home-only").toBool() == roaming) {
|
||||
settings["gsm"]["home-only"] = !roaming;
|
||||
nm.call("UpdateUnsaved", QVariant::fromValue(settings)); // update is temporary
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Functions for tethering
|
||||
void WifiManager::addTetheringConnection() {
|
||||
Connection connection;
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
void requestScan();
|
||||
QMap<QString, Network> seenNetworks;
|
||||
QMap<QDBusObjectPath, QString> knownConnections;
|
||||
QString lteConnectionPath;
|
||||
QString ipv4_address;
|
||||
|
||||
void refreshNetworks();
|
||||
@@ -49,6 +50,7 @@ public:
|
||||
bool isKnownConnection(const QString &ssid);
|
||||
void activateWifiConnection(const QString &ssid);
|
||||
NetworkType currentNetworkType();
|
||||
void setRoamingEnabled(bool roaming);
|
||||
|
||||
void connect(const Network &ssid);
|
||||
void connect(const Network &ssid, const QString &password);
|
||||
@@ -84,8 +86,8 @@ private:
|
||||
unsigned int get_ap_strength(const QString &network_path);
|
||||
SecurityType getSecurityType(const QString &path);
|
||||
QDBusObjectPath getConnectionPath(const QString &ssid);
|
||||
Connection getConnectionSettings(const QDBusObjectPath &path);
|
||||
void initConnections();
|
||||
QString getConnectionSsid(const QDBusObjectPath &path);
|
||||
void setup();
|
||||
|
||||
signals:
|
||||
|
||||
Reference in New Issue
Block a user