Add a WiFi settings tab to the WiFi settings dialog

main
Aaron Rainbolt 1 year ago
parent b9139483e1
commit 24d16bdf2d

@ -57,6 +57,9 @@ set(PROJECT_SOURCES
ipv6settingstab.ui
wifisettings.h
wifisettings.cpp
wifisettingstab.h
wifisettingstab.cpp
wifisettingstab.ui
${TS_FILES}
)

@ -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:

@ -30,6 +30,12 @@ public:
MeteredNo
};
enum WifiMode {
WifiModeInfrastructure,
WifiModeAdhoc,
WifiModeAccessPoint
};
enum Ipv4Method {
Ipv4Automatic,
Ipv4AutomaticAddressOnly,

@ -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());

@ -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;
};

@ -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());
}
}

@ -0,0 +1,27 @@
#ifndef WIFISETTINGSTAB_H
#define WIFISETTINGSTAB_H
#include "connectionsettingsengine.h"
#include <QWidget>
#include <NetworkManagerQt/Utils>
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

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WifiSettingsTab</class>
<widget class="QWidget" name="WifiSettingsTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="2">
<widget class="QComboBox" name="modeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Cloned MAC address</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>BSSID</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Mode</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Visibility</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="clonedMacAddressLineEdit"/>
</item>
<item row="7" column="2">
<widget class="QCheckBox" name="hiddenNetworkCheckbox">
<property name="text">
<string>Hidden network</string>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>SSID</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="ssidComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>MTU</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QComboBox" name="bssidComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Device</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="mtuSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>bytes</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<widget class="QComboBox" name="deviceComboBox">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading…
Cancel
Save