From 24d16bdf2d7fe16b8549a8aa2ae75bb3f4f07125 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Sat, 2 Dec 2023 20:54:59 -0600 Subject: [PATCH] Add a WiFi settings tab to the WiFi settings dialog --- CMakeLists.txt | 3 + connectionsettingsengine.cpp | 51 +++++++++- connectionsettingsengine.h | 6 ++ wifisettings.cpp | 5 + wifisettings.h | 2 + wifisettingstab.cpp | 80 ++++++++++++++++ wifisettingstab.h | 27 ++++++ wifisettingstab.ui | 178 +++++++++++++++++++++++++++++++++++ 8 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 wifisettingstab.cpp create mode 100644 wifisettingstab.h create mode 100644 wifisettingstab.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index dba0d23..dd051eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,9 @@ set(PROJECT_SOURCES ipv6settingstab.ui wifisettings.h wifisettings.cpp + wifisettingstab.h + wifisettingstab.cpp + wifisettingstab.ui ${TS_FILES} ) diff --git a/connectionsettingsengine.cpp b/connectionsettingsengine.cpp index 7d113fb..f7a39a2 100644 --- a/connectionsettingsengine.cpp +++ b/connectionsettingsengine.cpp @@ -14,7 +14,7 @@ QString ConnectionSettingsEngine::targetConnUuidStr = QString(); * autoconnectVpn: QString * meteredConnection: ConnectionSettingsEngine::Metered * device: QString - * clonedMacAddress: QString + * clonedMacAddress: QString (mac address) * mtu: int * * All things IPv4: @@ -82,6 +82,12 @@ QString ConnectionSettingsEngine::targetConnUuidStr = QString(); * autoLinkNegotiation: ConnectionSettingsEngine::LinkNegotiation * linkSpeed: ConnectionSettingsEngine::LinkSpeed * duplexMode: ConnectionSettingsEngine::DuplexMode + * + * For WiFi devices only: + * ssid: QString + * wifiMode: ConnectionSettingsEngine::WifiMode + * bssid: QString (mac address) + * isWifiHidden: bool */ ConnectionSettingsEngine::ConnectionSettingsEngine() @@ -146,6 +152,23 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr result.insert("device", connSettings->interfaceName()); + if (!connWirelessSetting.isNull()) { + result.insert("ssid", QString(connWirelessSetting->ssid())); + switch (connWirelessSetting->mode()) { + case NetworkManager::WirelessSetting::Infrastructure: + result.insert("wifiMode", ConnectionSettingsEngine::WifiModeInfrastructure); + break; + case NetworkManager::WirelessSetting::Adhoc: + result.insert("wifiMode", ConnectionSettingsEngine::WifiModeAdhoc); + break; + case NetworkManager::WirelessSetting::Ap: + result.insert("wifiMode", ConnectionSettingsEngine::WifiModeAccessPoint); + break; + } + result.insert("bssid", NetworkManager::macAddressAsString(connWirelessSetting->bssid())); + result.insert("isWifiHidden", connWirelessSetting->hidden()); + } + if (!connIpv4Setting.isNull()) { switch (connIpv4Setting->method()) { case NetworkManager::Ipv4Setting::Automatic: @@ -480,6 +503,32 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa connSettings->setInterfaceName(settings["device"].toString()); } + if (settings["ssid"].isValid()) { + connWirelessSetting->setSsid(settings["ssid"].toString().toUtf8()); + } + + if (settings["wifiMode"].isValid()) { + switch (settings["wifiMode"].toInt()) { + case ConnectionSettingsEngine::WifiModeInfrastructure: + connWirelessSetting->setMode(NetworkManager::WirelessSetting::Infrastructure); + break; + case ConnectionSettingsEngine::WifiModeAdhoc: + connWirelessSetting->setMode(NetworkManager::WirelessSetting::Adhoc); + break; + case ConnectionSettingsEngine::WifiModeAccessPoint: + connWirelessSetting->setMode(NetworkManager::WirelessSetting::Ap); + break; + } + } + + if (settings["bssid"].isValid()) { + connWirelessSetting->setBssid(NetworkManager::macAddressFromString(settings["bssid"].toString())); + } + + if (settings["isWifiHidden"].isValid()) { + connWirelessSetting->setHidden(settings["isWifiPublic"].toBool()); + } + if (settings["ipv4Method"].isValid()) { switch (settings["ipv4Method"].toInt()) { case ConnectionSettingsEngine::Ipv4Automatic: diff --git a/connectionsettingsengine.h b/connectionsettingsengine.h index bacffec..b7f7f9f 100644 --- a/connectionsettingsengine.h +++ b/connectionsettingsengine.h @@ -30,6 +30,12 @@ public: MeteredNo }; + enum WifiMode { + WifiModeInfrastructure, + WifiModeAdhoc, + WifiModeAccessPoint + }; + enum Ipv4Method { Ipv4Automatic, Ipv4AutomaticAddressOnly, diff --git a/wifisettings.cpp b/wifisettings.cpp index 2350cab..f7d592e 100644 --- a/wifisettings.cpp +++ b/wifisettings.cpp @@ -11,12 +11,15 @@ WifiSettings::WifiSettings(QString connUuidStr, QWidget *parent) : this->setWindowTitle(connSettings["connName"].toString()); ui->connectionNameLineEdit->setText(connSettings["connName"].toString()); generalSettingsTab = new GeneralSettingsTab(); + wifiSettingsTab = new WifiSettingsTab(); ipv4SettingsTab = new Ipv4SettingsTab(); ipv6SettingsTab = new Ipv6SettingsTab(); ui->tabWidget->addTab(generalSettingsTab, tr("General")); + ui->tabWidget->addTab(wifiSettingsTab, tr("WiFi")); ui->tabWidget->addTab(ipv4SettingsTab, tr("IPv4")); ui->tabWidget->addTab(ipv6SettingsTab, tr("IPv6")); generalSettingsTab->loadSettings(connSettings); + wifiSettingsTab->loadSettings(connSettings); ipv4SettingsTab->loadSettings(connSettings); ipv6SettingsTab->loadSettings(connSettings); connect(ui->cancelButton, &QPushButton::clicked, this, &WifiSettings::onCancelButtonClicked); @@ -27,6 +30,7 @@ WifiSettings::~WifiSettings() { delete ui; delete generalSettingsTab; + delete wifiSettingsTab; delete ipv4SettingsTab; delete ipv6SettingsTab; } @@ -39,6 +43,7 @@ void WifiSettings::onCancelButtonClicked() void WifiSettings::onSaveButtonClicked() { QVariantMap settings = generalSettingsTab->readSettings(); + settings.insert(wifiSettingsTab->readSettings()); settings.insert(ipv4SettingsTab->readSettings()); settings.insert(ipv6SettingsTab->readSettings()); settings.insert("connName", ui->connectionNameLineEdit->text()); diff --git a/wifisettings.h b/wifisettings.h index fd9722a..0cc8606 100644 --- a/wifisettings.h +++ b/wifisettings.h @@ -3,6 +3,7 @@ #include "connectionsettingsengine.h" #include "generalsettingstab.h" +#include "wifisettingstab.h" #include "security802_1xtab.h" #include "ipv4settingstab.h" #include "ipv6settingstab.h" @@ -30,6 +31,7 @@ private: QString targetConnUuidStr; GeneralSettingsTab *generalSettingsTab; + WifiSettingsTab *wifiSettingsTab; Ipv4SettingsTab *ipv4SettingsTab; Ipv6SettingsTab *ipv6SettingsTab; }; diff --git a/wifisettingstab.cpp b/wifisettingstab.cpp new file mode 100644 index 0000000..b21ef66 --- /dev/null +++ b/wifisettingstab.cpp @@ -0,0 +1,80 @@ +#include "wifisettingstab.h" +#include "ui_wifisettingstab.h" + +WifiSettingsTab::WifiSettingsTab(QWidget *parent) : + QWidget(parent), + ui(new Ui::WifiSettingsTab) +{ + ui->setupUi(this); + ui->modeComboBox->addItems(QStringList() << tr("Infrastructure") << tr("Adhoc") << tr("Access Point")); +} + +WifiSettingsTab::~WifiSettingsTab() +{ + delete ui; +} + +QVariantMap WifiSettingsTab::readSettings() +{ + QVariantMap output; + output.insert("device", QVariant(ui->deviceComboBox->currentText())); + output.insert("clonedMacAddress", QVariant(ui->clonedMacAddressLineEdit->text())); + output.insert("ssid", ui->ssidComboBox->currentText()); + switch (ui->modeComboBox->currentIndex()) { + case 0: // Infrastructure + output.insert("wifiMode", ConnectionSettingsEngine::WifiModeInfrastructure); + break; + case 1: // Adhoc + output.insert("wifiMode", ConnectionSettingsEngine::WifiModeAdhoc); + break; + case 2: // Access Point + output.insert("wifiMode", ConnectionSettingsEngine::WifiModeAccessPoint); + break; + } + output.insert("bssid", ui->bssidComboBox->currentText()); + output.insert("clonedMacAddress", QVariant(ui->clonedMacAddressLineEdit->text())); + output.insert("mtu", QVariant(ui->mtuSpinBox->value())); + output.insert("isWifiHidden", ui->hiddenNetworkCheckbox->isChecked()); + return output; +} + +void WifiSettingsTab::loadSettings(QVariantMap settings) +{ + if (settings["device"].isValid()) { + ui->deviceComboBox->setCurrentText(settings["device"].toString()); + } + + if (settings["ssid"].isValid()) { + ui->ssidComboBox->setCurrentText(settings["ssid"].toString()); + } + + if (settings["wifiMode"].isValid()) { + switch (settings["wifiMode"].toInt()) { + case ConnectionSettingsEngine::WifiModeInfrastructure: + ui->modeComboBox->setCurrentIndex(0); + break; + case ConnectionSettingsEngine::WifiModeAdhoc: + ui->modeComboBox->setCurrentIndex(1); + break; + case ConnectionSettingsEngine::WifiModeAccessPoint: + ui->modeComboBox->setCurrentIndex(2); + break; + } + } + + if (settings["bssid"].isValid()) { + ui->bssidComboBox->setCurrentText(settings["bssid"].toString()); + } + + if (settings["clonedMacAddress"].isValid()) { + ui->clonedMacAddressLineEdit->setText(settings["clonedMacAddress"].toString()); + } + + if (settings["mtu"].isValid()) { + ui->mtuSpinBox->setValue(settings["mtu"].toInt()); + } + + if (settings["isWifiHidden"].isValid()) { + ui->hiddenNetworkCheckbox->setChecked(settings["isWifiHidden"].toBool()); + } +} diff --git a/wifisettingstab.h b/wifisettingstab.h new file mode 100644 index 0000000..b059375 --- /dev/null +++ b/wifisettingstab.h @@ -0,0 +1,27 @@ +#ifndef WIFISETTINGSTAB_H +#define WIFISETTINGSTAB_H + +#include "connectionsettingsengine.h" +#include +#include + +namespace Ui { +class WifiSettingsTab; +} + +class WifiSettingsTab : public QWidget +{ + Q_OBJECT + +public: + explicit WifiSettingsTab(QWidget *parent = nullptr); + ~WifiSettingsTab(); + + QVariantMap readSettings(); + void loadSettings(QVariantMap settings); + +private: + Ui::WifiSettingsTab *ui; +}; + +#endif // WIFISETTINGSTAB_H diff --git a/wifisettingstab.ui b/wifisettingstab.ui new file mode 100644 index 0000000..1454569 --- /dev/null +++ b/wifisettingstab.ui @@ -0,0 +1,178 @@ + + + WifiSettingsTab + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + 0 + 0 + + + + + + + + Cloned MAC address + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + BSSID + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Mode + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Visibility + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + Hidden network + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + SSID + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + true + + + + + + + MTU + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + true + + + + + + + Device + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 0 + 0 + + + + + + + + bytes + + + + + + + + + true + + + + + + + +