You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.4 KiB
110 lines
4.4 KiB
1 year ago
|
#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());
|
||
|
}
|
||
|
}
|