Overhaul combo box internal behavior, make connection saving actually work

main
Aaron Rainbolt 1 year ago
parent 832b4d5cf6
commit 117df45214

@ -8,7 +8,15 @@
* allUsersMayConnect: bool
* vpnAutoconnectEnabled: bool
* autoconnectVpn: QString
* meteredConnection: QString
* meteredConnection: ConnectionSettingsEngine::Metered
* !device: QString
* !clonedMacAddress: QString
* !mtu: int
*
* For Ethernet devices only:
* !linkNegotiation: QString
* !linkSpeed: ConnectionSettingsEngine::LinkSpeed
* !duplexMode: QString
*/
ConnectionSettingsEngine::ConnectionSettingsEngine()
@ -51,17 +59,17 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
}
}
switch (connSettings->metered()) {
switch(connSettings->metered()) {
case NetworkManager::ConnectionSettings::MeteredUnknown:
case NetworkManager::ConnectionSettings::MeteredGuessYes:
case NetworkManager::ConnectionSettings::MeteredGuessNo:
result.insert("meteredConnection", "Automatic");
result.insert("meteredConnection", ConnectionSettingsEngine::MeteredAutomatic);
break;
case NetworkManager::ConnectionSettings::MeteredYes:
result.insert("meteredConnection", "Yes");
result.insert("meteredConnection", ConnectionSettingsEngine::MeteredYes);
break;
case NetworkManager::ConnectionSettings::MeteredNo:
result.insert("meteredConnection", "No");
result.insert("meteredConnection", ConnectionSettingsEngine::MeteredNo);
break;
}
@ -99,13 +107,20 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
}
if (settings["meteredConnection"].isValid()) {
QString meteredConnectionStr = settings["meteredConnection"].toString();
if (meteredConnectionStr == "Yes") {
switch (settings["meteredConnection"].toInt()) {
case ConnectionSettingsEngine::MeteredAutomatic:
connSettings->setMetered(NetworkManager::ConnectionSettings::MeteredUnknown);
break;
case ConnectionSettingsEngine::MeteredYes:
connSettings->setMetered(NetworkManager::ConnectionSettings::MeteredYes);
} else if (meteredConnectionStr == "No") {
break;
case ConnectionSettingsEngine::MeteredNo:
connSettings->setMetered(NetworkManager::ConnectionSettings::MeteredNo);
} // if it's "Automatic" we just leave it be
break;
}
}
conn->update(connSettings->toMap());
}
QString ConnectionSettingsEngine::userName()

@ -8,10 +8,28 @@
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Manager>
class ConnectionSettingsEngine
{
public:
enum MeteredMode {
MeteredAutomatic,
MeteredYes,
MeteredNo
};
enum LinkSpeed {
Speed10Mbps,
Speed100Mbps,
Speed1Gbps,
Speed2_5Gbps,
Speed5Gbps,
Speed10Gbps,
Speed40Gbps,
Speed100Gbps
};
ConnectionSettingsEngine();
static QVariantMap readConnectionSettings(QString connUuidStr);

@ -6,9 +6,98 @@ EthernetSettingsTab::EthernetSettingsTab(QWidget *parent) :
ui(new Ui::EthernetSettingsTab)
{
ui->setupUi(this);
ui->speedComboBox->addItems(QStringList() << tr("10 Mb/s") << tr("100 Mb/s") << tr("1 Gb/s") << tr("2.5 Gb/s") << tr("10 Gb/s") << tr("40 Gb/s") << tr("100 Gb/s"));
ui->linkNegotiationComboBox->addItems(QStringList() << tr("Ignore") << tr("Automatic") << tr("Manual"));
}
EthernetSettingsTab::~EthernetSettingsTab()
{
delete ui;
}
// Refer to connectionsettingsengine.cpp for configuration map details
QVariantMap EthernetSettingsTab::readSettings()
{
QVariantMap output;
output.insert("device", QVariant(ui->deviceComboBox->currentText()));
output.insert("clonedMacAddress", QVariant(ui->clonedMacAddressComboBox->currentText()));
output.insert("mtu", QVariant(ui->mtuSpinBox->value()));
output.insert("linkNegotiation", QVariant(ui->linkNegotiationComboBox->currentText()));
switch(ui->speedComboBox->currentIndex()) {
case 0:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Mbps);
break;
case 1:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed100Mbps);
break;
case 2:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed1Gbps);
break;
case 3:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed2_5Gbps);
break;
case 4:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed5Gbps);
break;
case 5:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed10Gbps);
break;
case 6:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed40Gbps);
break;
case 7:
output.insert("linkSpeed", ConnectionSettingsEngine::Speed100Gbps);
break;
}
output.insert("speedMbps", QVariant(ui->speedComboBox->currentData()));
output.insert("duplexMode", QVariant(ui->duplexComboBox->currentText()));
return output;
}
void EthernetSettingsTab::loadSettings(QVariantMap settings)
{
if (settings["device"].isValid()) {
ui->deviceComboBox->setCurrentText(settings["device"].toString());
}
if (settings["clonedMacAddress"].isValid()) {
ui->clonedMacAddressComboBox->setCurrentText(settings["clonedMacAddress"].toString());
}
if (settings["mtu"].isValid()) {
ui->mtuSpinBox->setValue(settings["mtu"].toInt());
}
if (settings["linkNegotiation"].isValid()) {
ui->linkNegotiationComboBox->setCurrentText(settings["linkNegotiation"].toString());
}
if (settings["linkSpeed"].isValid()) {
switch(settings["linkSpeed"].toInt()) {
case ConnectionSettingsEngine::Speed10Mbps:
ui->speedComboBox->setCurrentIndex(0);
break;
case ConnectionSettingsEngine::Speed100Mbps:
ui->speedComboBox->setCurrentIndex(1);
break;
case ConnectionSettingsEngine::Speed1Gbps:
ui->speedComboBox->setCurrentIndex(2);
break;
case ConnectionSettingsEngine::Speed2_5Gbps:
ui->speedComboBox->setCurrentIndex(3);
break;
case ConnectionSettingsEngine::Speed5Gbps:
ui->speedComboBox->setCurrentIndex(4);
break;
case ConnectionSettingsEngine::Speed10Gbps:
ui->speedComboBox->setCurrentIndex(5);
break;
case ConnectionSettingsEngine::Speed40Gbps:
ui->speedComboBox->setCurrentIndex(6);
break;
case ConnectionSettingsEngine::Speed100Gbps:
ui->speedComboBox->setCurrentIndex(7);
break;
}
}
if (settings["duplexMode"].isValid()) {
ui->duplexComboBox->setCurrentText(settings["duplexMode"].toString());
}
}

@ -1,6 +1,7 @@
#ifndef ETHERNETSETTINGSTAB_H
#define ETHERNETSETTINGSTAB_H
#include "connectionsettingsengine.h"
#include <QWidget>
namespace Ui {
@ -15,6 +16,9 @@ public:
explicit EthernetSettingsTab(QWidget *parent = nullptr);
~EthernetSettingsTab();
QVariantMap readSettings();
void loadSettings(QVariantMap settings);
private:
Ui::EthernetSettingsTab *ui;
};

@ -6,7 +6,7 @@ GeneralSettingsTab::GeneralSettingsTab(QWidget *parent) :
ui(new Ui::GeneralSettingsTab)
{
ui->setupUi(this);
ui->meteredConnectionComboBox->addItems(QStringList() << "Automatic" << "Yes" << "No");
ui->meteredConnectionComboBox->addItems(QStringList() << tr("Automatic") << tr("Yes") << tr("No"));
}
GeneralSettingsTab::~GeneralSettingsTab()
@ -24,7 +24,17 @@ QVariantMap GeneralSettingsTab::readSettings()
output.insert("allUsersMayConnect", QVariant(ui->allUsersMayConnectCheckBox->isChecked()));
output.insert("vpnAutoconnectEnabled", QVariant(ui->vpnAutoconnectCheckBox->isChecked()));
output.insert("autoconnectVpn", QVariant(ui->vpnSelectComboBox->currentText()));
output.insert("meteredConnection", QVariant(ui->meteredConnectionComboBox->currentText()));
switch (ui->meteredConnectionComboBox->currentIndex()) {
case 0:
output.insert("meteredConnection", ConnectionSettingsEngine::MeteredAutomatic);
break;
case 1:
output.insert("meteredConnection", ConnectionSettingsEngine::MeteredYes);
break;
case 2:
output.insert("meteredConnection", ConnectionSettingsEngine::MeteredNo);
break;
}
return output;
}
@ -46,6 +56,16 @@ void GeneralSettingsTab::loadSettings(QVariantMap settings)
ui->vpnSelectComboBox->setCurrentText(settings["autoconnectVpn"].toString());
}
if (settings["meteredConnection"].isValid()) {
ui->meteredConnectionComboBox->setCurrentText(settings["meteredConnection"].toString());
switch(settings["meteredConnection"].toInt()) {
case ConnectionSettingsEngine::MeteredAutomatic:
ui->meteredConnectionComboBox->setCurrentIndex(0);
break;
case ConnectionSettingsEngine::MeteredYes:
ui->meteredConnectionComboBox->setCurrentIndex(1);
break;
case ConnectionSettingsEngine::MeteredNo:
ui->meteredConnectionComboBox->setCurrentIndex(2);
break;
}
}
}

@ -1,6 +1,9 @@
#ifndef GENERALSETTINGSTAB_H
#define GENERALSETTINGSTAB_H
#include "connectionsettingsengine.h"
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <QWidget>
#include <QString>
#include <QVariant>

Loading…
Cancel
Save