Loading and saving of settings is starting to work

main
Aaron Rainbolt 1 year ago
parent e9e20b8f8a
commit 832b4d5cf6

1
.gitignore vendored

@ -0,0 +1 @@
CMakeLists.txt.user

@ -87,7 +87,7 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
connSettings->setPermissions(QHash<QString, QString>()); connSettings->setPermissions(QHash<QString, QString>());
} else { } else {
if (connSettings->permissions().isEmpty()) { if (connSettings->permissions().isEmpty()) {
; // TODO: Add current user to permissiosn list connSettings->addToPermissions(ConnectionSettingsEngine::userName(), QString());
} // Otherwise we just leave the permissions as-is } // Otherwise we just leave the permissions as-is
} }
} }
@ -107,3 +107,12 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
} // if it's "Automatic" we just leave it be } // if it's "Automatic" we just leave it be
} }
} }
QString ConnectionSettingsEngine::userName()
{
QProcess userNameGetter;
userNameGetter.setProgram("whoami");
userNameGetter.start();
userNameGetter.waitForFinished();
return QString(userNameGetter.readAllStandardOutput());
}

@ -4,6 +4,7 @@
#include <QString> #include <QString>
#include <QVariant> #include <QVariant>
#include <QHash> #include <QHash>
#include <QProcess>
#include <NetworkManagerQt/Connection> #include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings> #include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/Settings> #include <NetworkManagerQt/Settings>
@ -15,6 +16,9 @@ public:
static QVariantMap readConnectionSettings(QString connUuidStr); static QVariantMap readConnectionSettings(QString connUuidStr);
static void modifyConnectionSettings(QString connUuidStr, QVariantMap settings); static void modifyConnectionSettings(QString connUuidStr, QVariantMap settings);
private:
static QString userName();
}; };
#endif // CONNECTIONSETTINGSENGINE_H #endif // CONNECTIONSETTINGSENGINE_H

@ -1,10 +1,11 @@
#include "ethernetsettings.h" #include "ethernetsettings.h"
#include "ui_genericsettings.h" #include "ui_genericsettings.h"
EthernetSettings::EthernetSettings(QString title, QWidget *parent) : EthernetSettings::EthernetSettings(QString title, QString connUuidStr, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::GenericSettings) ui(new Ui::GenericSettings)
{ {
targetConnUuidStr = connUuidStr;
ui->setupUi(this); ui->setupUi(this);
this->setWindowTitle(title); this->setWindowTitle(title);
ui->connectionNameLineEdit->setText(title); ui->connectionNameLineEdit->setText(title);
@ -12,6 +13,10 @@ EthernetSettings::EthernetSettings(QString title, QWidget *parent) :
ethernetSettingsTab = new EthernetSettingsTab(); ethernetSettingsTab = new EthernetSettingsTab();
ui->tabWidget->addTab(generalSettingsTab, "General"); ui->tabWidget->addTab(generalSettingsTab, "General");
ui->tabWidget->addTab(ethernetSettingsTab, "Ethernet"); ui->tabWidget->addTab(ethernetSettingsTab, "Ethernet");
QVariantMap connSettings = ConnectionSettingsEngine::readConnectionSettings(connUuidStr);
generalSettingsTab->loadSettings(connSettings);
connect(ui->cancelButton, &QPushButton::clicked, this, &EthernetSettings::onCancelButtonClicked);
connect(ui->saveButton, &QPushButton::clicked, this, &EthernetSettings::onSaveButtonClicked);
} }
EthernetSettings::~EthernetSettings() EthernetSettings::~EthernetSettings()
@ -20,3 +25,15 @@ EthernetSettings::~EthernetSettings()
delete generalSettingsTab; delete generalSettingsTab;
delete ethernetSettingsTab; delete ethernetSettingsTab;
} }
void EthernetSettings::onCancelButtonClicked()
{
this->done(0);
}
void EthernetSettings::onSaveButtonClicked()
{
QVariantMap settings = generalSettingsTab->readSettings();
ConnectionSettingsEngine::modifyConnectionSettings(targetConnUuidStr, settings);
this->done(0);
}

@ -1,6 +1,7 @@
#ifndef ETHERNETSETTINGS_H #ifndef ETHERNETSETTINGS_H
#define ETHERNETSETTINGS_H #define ETHERNETSETTINGS_H
#include "connectionsettingsengine.h"
#include "generalsettingstab.h" #include "generalsettingstab.h"
#include "ethernetsettingstab.h" #include "ethernetsettingstab.h"
@ -15,12 +16,17 @@ class EthernetSettings : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit EthernetSettings(QString title, QWidget *parent = nullptr); explicit EthernetSettings(QString title, QString connUuidStr, QWidget *parent = nullptr);
~EthernetSettings(); ~EthernetSettings();
private slots:
void onCancelButtonClicked();
void onSaveButtonClicked();
private: private:
Ui::GenericSettings *ui; Ui::GenericSettings *ui;
QString targetConnUuidStr;
GeneralSettingsTab *generalSettingsTab; GeneralSettingsTab *generalSettingsTab;
EthernetSettingsTab *ethernetSettingsTab; EthernetSettingsTab *ethernetSettingsTab;
}; };

@ -6,6 +6,7 @@ GeneralSettingsTab::GeneralSettingsTab(QWidget *parent) :
ui(new Ui::GeneralSettingsTab) ui(new Ui::GeneralSettingsTab)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->meteredConnectionComboBox->addItems(QStringList() << "Automatic" << "Yes" << "No");
} }
GeneralSettingsTab::~GeneralSettingsTab() GeneralSettingsTab::~GeneralSettingsTab()

@ -47,7 +47,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="cancelButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -60,7 +60,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton_2"> <widget class="QPushButton" name="saveButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>

@ -183,8 +183,6 @@ void NetworkSelector::regenConnTree()
break; break;
case NetworkManager::ConnectionSettings::Vpn: case NetworkManager::ConnectionSettings::Vpn:
case NetworkManager::ConnectionSettings::Tun:
case NetworkManager::ConnectionSettings::IpTunnel:
case NetworkManager::ConnectionSettings::WireGuard: case NetworkManager::ConnectionSettings::WireGuard:
targetItem = connGroupItem("VPN"); targetItem = connGroupItem("VPN");
if (targetItem == NULL) { if (targetItem == NULL) {
@ -193,6 +191,22 @@ void NetworkSelector::regenConnTree()
} }
break; break;
case NetworkManager::ConnectionSettings::Tun:
targetItem = connGroupItem("Tun");
if (targetItem == NULL) {
targetItem = new QStandardItem("Tun");
connTreeList.append(targetItem);
}
break;
case NetworkManager::ConnectionSettings::IpTunnel:
targetItem = connGroupItem("IpTunnel");
if (targetItem == NULL) {
targetItem = new QStandardItem("IpTunnel");
connTreeList.append(targetItem);
}
break;
case NetworkManager::ConnectionSettings::Wimax: case NetworkManager::ConnectionSettings::Wimax:
targetItem = connGroupItem("WiMAX"); targetItem = connGroupItem("WiMAX");
if (targetItem == NULL) { if (targetItem == NULL) {
@ -256,7 +270,7 @@ void NetworkSelector::modifyConnection(QModelIndex index)
NetworkManager::ConnectionSettings::ConnectionType connType = connList[i]->settings()->connectionType(); NetworkManager::ConnectionSettings::ConnectionType connType = connList[i]->settings()->connectionType();
switch(connType) { switch(connType) {
case NetworkManager::ConnectionSettings::Wired: case NetworkManager::ConnectionSettings::Wired:
dialogWindow = new EthernetSettings(index.data().toString()); dialogWindow = new EthernetSettings(index.data().toString(), index.data(Qt::UserRole+1).toString());
dialogWindow->exec(); dialogWindow->exec();
delete dialogWindow; delete dialogWindow;
break; break;

Loading…
Cancel
Save