Mostly implement IPv4 settings

main
Aaron Rainbolt 1 year ago
parent dfdd2737ff
commit 549119459a

@ -45,6 +45,10 @@ set(PROJECT_SOURCES
security802_1xtab.h
security802_1xtab.cpp
security802_1xtab.ui
ipv4settingstab.h
ipv4settingstab.cpp
ipv4settingstab.ui
qvarianthelper.h
${TS_FILES}
)

@ -18,6 +18,15 @@ QString ConnectionSettingsEngine::targetConnUuidStr = QString();
* clonedMacAddress: QString
* mtu: int
*
* All things IPv4:
*
* !ipv4Method: ConnectionSettingsEngine::Ipv4Method
* !ipv4DnsServers: QString
* !ipv4SearchDomains: QString
* !ipv4DhcpClientId: QString
* !ipv4AddressList: QList<NetworkManager::IpAddress>
* !ipv4Required: bool
*
* All things 802.1x:
*
* 802.1xEnabled: bool
@ -77,6 +86,7 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
NetworkManager::Security8021xSetting::Ptr connSecurity802_1xSetting = connSettings->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
NetworkManager::WirelessSetting::Ptr connWirelessSetting = connSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
NetworkManager::Ipv4Setting::Ptr connIpv4Setting = connSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
QVariantMap result;
result.insert("connName", connSettings->id());
result.insert("autoconnectEnabled", connSettings->autoconnect());
@ -125,6 +135,39 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
result.insert("device", connSettings->interfaceName());
if (!connIpv4Setting.isNull()) {
switch (connIpv4Setting->method()) {
case NetworkManager::Ipv4Setting::Automatic:
if (connIpv4Setting->ignoreAutoDns()) {
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4AutomaticAddressOnly);
} else {
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Automatic);
}
break;
case NetworkManager::Ipv4Setting::LinkLocal:
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4LinkLocal);
break;
case NetworkManager::Ipv4Setting::Manual:
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Manual);
break;
case NetworkManager::Ipv4Setting::Shared:
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Shared);
break;
case NetworkManager::Ipv4Setting::Disabled:
result.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Disabled);
break;
}
QStringList dnsStringList;
for (const QHostAddress &addr : connIpv4Setting->dns()) {
dnsStringList.append(addr.toString());
}
result.insert("ipv4DnsServers", dnsStringList.join(","));
result.insert("ipv4SearchDomains", connIpv4Setting->dnsSearch().join(","));
result.insert("ipv4DhcpClientId", connIpv4Setting->dhcpClientId());
result.insert("ipv4AddressList", QVariant::fromValue(connIpv4Setting->addresses()));
result.insert("ipv4Required", !connIpv4Setting->mayFail());
}
if (!connSecurity802_1xSetting.isNull()) {
QList<NetworkManager::Security8021xSetting::EapMethod> eapMethods = connSecurity802_1xSetting->eapMethods();
if (eapMethods.length() != 0) {
@ -331,7 +374,7 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
NetworkManager::WirelessSetting::Ptr connWirelessSetting = connSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
NetworkManager::Security8021xSetting secSetting;
NetworkManager::Ipv4Setting::Ptr connIpv4Setting = connSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
if (settings["connName"].isValid()) {
connSettings->setId(settings["connName"].toString());
}
@ -375,6 +418,59 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
connSettings->setInterfaceName(settings["device"].toString());
}
if (settings["ipv4Method"].isValid()) {
switch (settings["ipv4Method"].toInt()) {
case ConnectionSettingsEngine::Ipv4Automatic:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic);
connIpv4Setting->setIgnoreAutoDns(false);
break;
case ConnectionSettingsEngine::Ipv4AutomaticAddressOnly:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::Automatic);
connIpv4Setting->setIgnoreAutoDns(true);
break;
case ConnectionSettingsEngine::Ipv4LinkLocal:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::LinkLocal);
break;
case ConnectionSettingsEngine::Ipv4Manual:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::Manual);
break;
case ConnectionSettingsEngine::Ipv4Shared:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared);
break;
case ConnectionSettingsEngine::Ipv4Disabled:
connIpv4Setting->setMethod(NetworkManager::Ipv4Setting::Disabled);
break;
}
}
if (settings["ipv4DnsServers"].isValid()) {
QStringList dnsStringList = settings["ipv4DnsServers"].toString().split(',');
QList<QHostAddress> dnsAddrList;
for (const QString &dnsStr : dnsStringList) {
QHostAddress dnsAddr(dnsStr);
if (!dnsAddr.isNull()) {
dnsAddrList.append(dnsAddr);
}
}
connIpv4Setting->setDns(dnsAddrList);
}
if (settings["ipv4SearchDomains"].isValid()) {
connIpv4Setting->setDnsSearch(settings["ipv4SearchDomains"].toString().split(','));
}
if (settings["ipv4DhcpClientId"].isValid()) {
connIpv4Setting->setDhcpClientId(settings["ipv4DhcpClientId"].toString());
}
if (settings["ipv4AddressList"].isValid()) {
connIpv4Setting->setAddresses(settings["ipv4AddressList"].value<QList<NetworkManager::IpAddress>>());
}
if (settings["ipv4Required"].isValid()) {
connIpv4Setting->setMayFail(!settings["ipv4Required"].toBool());
}
if (settings["802.1xEnabled"].isValid() && settings["802.1xEnabled"].toBool()) {
QList<NetworkManager::Security8021xSetting::EapMethod> eapMethodsList;
switch (settings["802.1xAuthMode"].toInt()) {

@ -1,6 +1,7 @@
#ifndef CONNECTIONSETTINGSENGINE_H
#define CONNECTIONSETTINGSENGINE_H
#include "qvarianthelper.h"
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/Settings>
@ -10,6 +11,8 @@
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessSetting>
#include <NetworkManagerQt/Utils>
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
#include <QString>
#include <QVariant>
#include <QHash>
@ -27,6 +30,15 @@ public:
MeteredNo
};
enum Ipv4Method {
Ipv4Automatic,
Ipv4AutomaticAddressOnly,
Ipv4LinkLocal,
Ipv4Manual,
Ipv4Shared,
Ipv4Disabled
};
enum LinkSpeed {
SpeedUnknown,
Speed10Mbps,

@ -13,12 +13,15 @@ EthernetSettings::EthernetSettings(QString connUuidStr, QWidget *parent) :
generalSettingsTab = new GeneralSettingsTab();
ethernetSettingsTab = new EthernetSettingsTab();
security802_1xSettingsTab = new Security802_1xTab();
ui->tabWidget->addTab(generalSettingsTab, "General");
ui->tabWidget->addTab(ethernetSettingsTab, "Ethernet");
ui->tabWidget->addTab(security802_1xSettingsTab, "802.1x Security");
ipv4SettingsTab = new Ipv4SettingsTab();
ui->tabWidget->addTab(generalSettingsTab, tr("General"));
ui->tabWidget->addTab(ethernetSettingsTab, tr("Ethernet"));
ui->tabWidget->addTab(security802_1xSettingsTab, tr("802.1x Security"));
ui->tabWidget->addTab(ipv4SettingsTab, tr("IPv4"));
generalSettingsTab->loadSettings(connSettings);
ethernetSettingsTab->loadSettings(connSettings);
security802_1xSettingsTab->loadSettings(connSettings);
ipv4SettingsTab->loadSettings(connSettings);
connect(ui->cancelButton, &QPushButton::clicked, this, &EthernetSettings::onCancelButtonClicked);
connect(ui->saveButton, &QPushButton::clicked, this, &EthernetSettings::onSaveButtonClicked);
}
@ -29,6 +32,7 @@ EthernetSettings::~EthernetSettings()
delete generalSettingsTab;
delete ethernetSettingsTab;
delete security802_1xSettingsTab;
delete ipv4SettingsTab;
}
void EthernetSettings::onCancelButtonClicked()
@ -41,6 +45,7 @@ void EthernetSettings::onSaveButtonClicked()
QVariantMap settings = generalSettingsTab->readSettings();
settings.insert(ethernetSettingsTab->readSettings());
settings.insert(security802_1xSettingsTab->readSettings());
settings.insert(ipv4SettingsTab->readSettings());
settings.insert("connName", ui->connectionNameLineEdit->text());
ConnectionSettingsEngine::modifyConnectionSettings(targetConnUuidStr, settings);
this->done(0);

@ -5,6 +5,7 @@
#include "generalsettingstab.h"
#include "ethernetsettingstab.h"
#include "security802_1xtab.h"
#include "ipv4settingstab.h"
#include <QDialog>
@ -31,6 +32,7 @@ private:
GeneralSettingsTab *generalSettingsTab;
EthernetSettingsTab *ethernetSettingsTab;
Security802_1xTab *security802_1xSettingsTab;
Ipv4SettingsTab *ipv4SettingsTab;
};
#endif // ETHERNETSETTINGS_H

@ -0,0 +1,109 @@
#include "ipv4settingstab.h"
#include "ui_ipv4settingstab.h"
Ipv4SettingsTab::Ipv4SettingsTab(QWidget *parent) :
QWidget(parent),
ui(new Ui::Ipv4SettingsTab)
{
ui->setupUi(this);
ui->methodComboBox->addItems(QStringList() << tr("Automatic") << tr("Automatic (address-only)") << tr("Link-Local") << tr("Manual") << tr("Shared to other computers") << tr("Disabled"));
}
Ipv4SettingsTab::~Ipv4SettingsTab()
{
delete ui;
}
QVariantMap Ipv4SettingsTab::readSettings()
{
QVariantMap output;
switch (ui->methodComboBox->currentIndex()) {
case 0: // Automatic
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Automatic);
break;
case 1: // Automatic (address-only)
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4AutomaticAddressOnly);
break;
case 2: // Link-local
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4LinkLocal);
break;
case 3: // Manual
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Manual);
break;
case 4: // Shared
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Shared);
break;
case 5: // Disabled
output.insert("ipv4Method", ConnectionSettingsEngine::Ipv4Disabled);
break;
}
output.insert("ipv4DnsServers", ui->dnsServersLineEdit->text());
output.insert("ipv4SearchDomains", ui->searchDomainsLineEdit->text());
output.insert("ipv4DhcpClientId", ui->dhcpClientIdLineEdit->text());
QList<NetworkManager::IpAddress> ipAddrList;
if (ui->methodComboBox->currentIndex() == 3) { // Manual
for (int i = 0, rowCount = ui->manualIpv4ConfigurationTable->rowCount(); i < rowCount; i++) {
NetworkManager::IpAddress ipAddr;
ipAddr.setIp(QHostAddress(ui->manualIpv4ConfigurationTable->item(i, 0)->text()));
ipAddr.setNetmask(QHostAddress(ui->manualIpv4ConfigurationTable->item(i, 1)->text()));
ipAddr.setGateway(QHostAddress(ui->manualIpv4ConfigurationTable->item(i, 2)->text()));
ipAddrList.append(ipAddr);
}
}
output.insert("ipv4AddressList", QVariant::fromValue(ipAddrList));
output.insert("ipv4Required", ui->ipv4RequiredCheckBox->isChecked());
return output;
}
void Ipv4SettingsTab::loadSettings(QVariantMap settings)
{
if (settings["ipv4Method"].isValid()) {
switch (settings["ipv4Method"].toInt()) {
case ConnectionSettingsEngine::Ipv4Automatic:
ui->methodComboBox->setCurrentIndex(0);
break;
case ConnectionSettingsEngine::Ipv4AutomaticAddressOnly:
ui->methodComboBox->setCurrentIndex(1);
break;
case ConnectionSettingsEngine::Ipv4LinkLocal:
ui->methodComboBox->setCurrentIndex(2);
break;
case ConnectionSettingsEngine::Ipv4Manual:
ui->methodComboBox->setCurrentIndex(3);
break;
case ConnectionSettingsEngine::Ipv4Shared:
ui->methodComboBox->setCurrentIndex(4);
break;
case ConnectionSettingsEngine::Ipv4Disabled:
ui->methodComboBox->setCurrentIndex(5);
break;
}
}
if (settings["ipv4DnsServers"].isValid()) {
ui->dnsServersLineEdit->setText(settings["ipv4DnsServers"].toString());
}
if (settings["ipv4SearchDomains"].isValid()) {
ui->searchDomainsLineEdit->setText(settings["ipv4SearchDomains"].toString());
}
if (settings["ipv4DhcpClientId"].isValid()) {
ui->dhcpClientIdLineEdit->setText(settings["ipv4DhcpClientId"].toString());
}
if (settings["ipv4AddressList"].isValid()) {
QList<NetworkManager::IpAddress> ipAddrList = settings["ipv4AddressList"].value<QList<NetworkManager::IpAddress>>();
for (int i = 0; i < ipAddrList.length(); i++) {
int newRow = ui->manualIpv4ConfigurationTable->rowCount();
ui->manualIpv4ConfigurationTable->insertRow(newRow);
ui->manualIpv4ConfigurationTable->setItem(newRow, 0, new QTableWidgetItem(ipAddrList[i].ip().toString()));
ui->manualIpv4ConfigurationTable->setItem(newRow, 1, new QTableWidgetItem(ipAddrList[i].netmask().toString()));
ui->manualIpv4ConfigurationTable->setItem(newRow, 2, new QTableWidgetItem(ipAddrList[i].gateway().toString()));
}
}
if (settings["ipv4Required"].isValid()) {
ui->ipv4RequiredCheckBox->setChecked(settings["ipv4Required"].toBool());
}
}

@ -0,0 +1,27 @@
#ifndef IPV4SETTINGSTAB_H
#define IPV4SETTINGSTAB_H
#include "qvarianthelper.h"
#include "connectionsettingsengine.h"
#include <QWidget>
namespace Ui {
class Ipv4SettingsTab;
}
class Ipv4SettingsTab : public QWidget
{
Q_OBJECT
public:
explicit Ipv4SettingsTab(QWidget *parent = nullptr);
~Ipv4SettingsTab();
QVariantMap readSettings();
void loadSettings(QVariantMap settings);
private:
Ui::Ipv4SettingsTab *ui;
};
#endif // IPV4SETTINGSTAB_H

@ -0,0 +1,171 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Ipv4SettingsTab</class>
<widget class="QWidget" name="Ipv4SettingsTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>479</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="dnsServersLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="editDnsServersButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Edit...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Method:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="dnsServersLabel">
<property name="text">
<string>DNS servers:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="methodComboBox"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="dhcpClientIdLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>DHCP client ID:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QTableWidget" name="manualIpv4ConfigurationTable">
<attribute name="horizontalHeaderDefaultSectionSize">
<number>125</number>
</attribute>
<column>
<property name="text">
<string>Address</string>
</property>
</column>
<column>
<property name="text">
<string>Netmask</string>
</property>
</column>
<column>
<property name="text">
<string>Gateway</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="manualIpv4ConfigurationAddButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="manualIpv4ConfigurationRemoveButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<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>
</layout>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="searchDomainsLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="editSearchDomainsButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Edit...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Search domains:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="ipv4RequiredCheckBox">
<property name="text">
<string>IPv4 is required for this connection</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,9 @@
#ifndef QVARIANTHELPER_H
#define QVARIANTHELPER_H
#include <NetworkManagerQt/Ipv4Setting>
#include <QList>
Q_DECLARE_METATYPE(QList<NetworkManager::IpAddress>)
#endif // QVARIANTHELPER_H
Loading…
Cancel
Save