More progress on a bunch more components, fully implemented connection deleting

main
Aaron Rainbolt 1 year ago
parent 18f24e03ab
commit 03fab13c88

@ -25,15 +25,23 @@ set(PROJECT_SOURCES
networkselector.cpp
networkselector.h
networkselector.ui
genericsettings.ui
ethernetsettings.h
ethernetsettings.cpp
ethernetsettings.ui
networkcreator.h
networkcreator.cpp
networkcreator.ui
networkdeleter.h
networkdeleter.cpp
networkdeleter.ui
generalsettingstab.h
generalsettingstab.cpp
generalsettingstab.ui
connectionsettingsengine.h
connectionsettingsengine.cpp
ethernetsettingstab.h
ethernetsettingstab.cpp
ethernetsettingstab.ui
${TS_FILES}
)

@ -0,0 +1,15 @@
# lubuntu-connection-editor - A simple application for creating, removing, and modifying NetworkManager connections
This is a straightforward-as-possible Qt reimplmentation of the nm-connection-editor tool from GNOME. It uses NetworkManagerQt (from the KDE project) behind the scenes to do all the heavy lifting.
THIS PROJECT IS IN EARLY ALPHA. It may crash or eat your computer, so treat it with caution.
## Build instructions
sudo apt build-dep lubuntu-connection-editor
mkdir build
cd build
cmake ..
make -j$(nproc)
Do not use `sudo make install` - this will bypass the apt package manager and possibly cause trouble. Instead, package this for your distribution following the guidelines and best practices of that distro. If building for Ubuntu, we recommend using either `debuild` (if working on Ubuntu packages is something you do rarely and you want something that's quick to set up) or `sbuild` (if you need to build packages all the time).

@ -0,0 +1,16 @@
#include "connectionsettingsengine.h"
/*
* The configuration map:
*
* autoconnectEnabled: bool
* autoconnectPriority: int
* allUsersMayConnect: bool
* vpnAutoconnectEnabled: bool
* autoconnectVpn: QString
* meteredConnection: QString
*/
ConnectionSettingsEngine::ConnectionSettingsEngine()
{
}

@ -0,0 +1,16 @@
#ifndef CONNECTIONSETTINGSENGINE_H
#define CONNECTIONSETTINGSENGINE_H
#include <QString>
#include <QVariant>
class ConnectionSettingsEngine
{
public:
ConnectionSettingsEngine();
static QVariantMap readConnectionSettings(QString connUuidStr);
static void modifyConnectionSettings(QString connUuidStr, QVariantMap settings);
};
#endif // CONNECTIONSETTINGSENGINE_H

@ -1,15 +1,22 @@
#include "ethernetsettings.h"
#include "ui_ethernetsettings.h"
#include "ui_genericsettings.h"
EthernetSettings::EthernetSettings(QString title, QWidget *parent) :
QDialog(parent),
ui(new Ui::EthernetSettings)
ui(new Ui::GenericSettings)
{
ui->setupUi(this);
this->setWindowTitle(title);
ui->connectionNameLineEdit->setText(title);
generalSettingsTab = new GeneralSettingsTab();
ethernetSettingsTab = new EthernetSettingsTab();
ui->tabWidget->addTab(generalSettingsTab, "General");
ui->tabWidget->addTab(ethernetSettingsTab, "Ethernet");
}
EthernetSettings::~EthernetSettings()
{
delete ui;
delete generalSettingsTab;
delete ethernetSettingsTab;
}

@ -1,10 +1,13 @@
#ifndef ETHERNETSETTINGS_H
#define ETHERNETSETTINGS_H
#include "generalsettingstab.h"
#include "ethernetsettingstab.h"
#include <QDialog>
namespace Ui {
class EthernetSettings;
class GenericSettings;
}
class EthernetSettings : public QDialog
@ -16,7 +19,10 @@ public:
~EthernetSettings();
private:
Ui::EthernetSettings *ui;
Ui::GenericSettings *ui;
GeneralSettingsTab *generalSettingsTab;
EthernetSettingsTab *ethernetSettingsTab;
};
#endif // ETHERNETSETTINGS_H

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EthernetSettings</class>
<widget class="QDialog" name="EthernetSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,14 @@
#include "ethernetsettingstab.h"
#include "ui_ethernetsettingstab.h"
EthernetSettingsTab::EthernetSettingsTab(QWidget *parent) :
QWidget(parent),
ui(new Ui::EthernetSettingsTab)
{
ui->setupUi(this);
}
EthernetSettingsTab::~EthernetSettingsTab()
{
delete ui;
}

@ -0,0 +1,22 @@
#ifndef ETHERNETSETTINGSTAB_H
#define ETHERNETSETTINGSTAB_H
#include <QWidget>
namespace Ui {
class EthernetSettingsTab;
}
class EthernetSettingsTab : public QWidget
{
Q_OBJECT
public:
explicit EthernetSettingsTab(QWidget *parent = nullptr);
~EthernetSettingsTab();
private:
Ui::EthernetSettingsTab *ui;
};
#endif // ETHERNETSETTINGSTAB_H

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EthernetSettingsTab</class>
<widget class="QWidget" name="EthernetSettingsTab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>665</width>
<height>238</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QComboBox" name="deviceComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="linkNegotiationComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<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="5" column="1">
<widget class="QComboBox" name="duplexComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Link negotiation</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="speedComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Device</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Duplex</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="clonedMacAddressComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>MTU</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Speed</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<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_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>bytes</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" 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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,50 @@
#include "generalsettingstab.h"
#include "ui_generalsettingstab.h"
GeneralSettingsTab::GeneralSettingsTab(QWidget *parent) :
QWidget(parent),
ui(new Ui::GeneralSettingsTab)
{
ui->setupUi(this);
}
GeneralSettingsTab::~GeneralSettingsTab()
{
delete ui;
}
// Refer to connectionsettingsengine.cpp for configuration map details
QVariantMap GeneralSettingsTab::readSettings()
{
QVariantMap output;
output.insert("autoconnectEnabled", QVariant(ui->autoconnectCheckBox->isChecked()));
output.insert("autoconnectPriority", QVariant(ui->autoconnectPrioritySpinBox->value()));
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()));
return output;
}
void GeneralSettingsTab::loadSettings(QVariantMap settings)
{
if (settings["autoconnectEnabled"].isValid()) {
ui->autoconnectCheckBox->setChecked(settings["autoconnectEnabled"].toBool());
}
if (settings["autoconnectPriority"].isValid()) {
ui->autoconnectPrioritySpinBox->setValue(settings["autoconnectPriority"].toInt());
}
if (settings["allUsersMayConnect"].isValid()) {
ui->allUsersMayConnectCheckBox->setChecked(settings["allUsersMayConnect"].toBool());
}
if (settings["vpnAutoconnectEnabled"].isValid()) {
ui->vpnAutoconnectCheckBox->setChecked(settings["vpnAutoconnectEnabled"].toBool());
}
if (settings["autoconnectVpn"].isValid()) {
ui->vpnSelectComboBox->setCurrentText(settings["autoconnectVpn"].toString());
}
if (settings["meteredConnection"].isValid()) {
ui->meteredConnectionComboBox->setCurrentText(settings["meteredConnection"].toString());
}
}

@ -0,0 +1,27 @@
#ifndef GENERALSETTINGSTAB_H
#define GENERALSETTINGSTAB_H
#include <QWidget>
#include <QString>
#include <QVariant>
namespace Ui {
class GeneralSettingsTab;
}
class GeneralSettingsTab : public QWidget
{
Q_OBJECT
public:
explicit GeneralSettingsTab(QWidget *parent = nullptr);
~GeneralSettingsTab();
QVariantMap readSettings();
void loadSettings(QVariantMap settings);
private:
Ui::GeneralSettingsTab *ui;
};
#endif // GENERALSETTINGSTAB_H

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GeneralSettingsTab</class>
<widget class="QWidget" name="GeneralSettingsTab">
<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="1" column="0">
<widget class="QCheckBox" name="allUsersMayConnectCheckBox">
<property name="text">
<string>All users may connect to this network</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="autoconnectCheckBox">
<property name="text">
<string>Connect automatically with priority</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Metered connection:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="meteredConnectionComboBox"/>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="vpnSelectComboBox"/>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="autoconnectPrioritySpinBox"/>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="vpnAutoconnectCheckBox">
<property name="text">
<string>Automatically connect to VPN</string>
</property>
</widget>
</item>
<item row="4" 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>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GenericSettings</class>
<widget class="QDialog" name="GenericSettings">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Connection name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="connectionNameLineEdit"/>
</item>
</layout>
</item>
<item>
<widget class="QTabWidget" name="tabWidget"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -3,6 +3,7 @@
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QDebug>
int main(int argc, char *argv[])
{

@ -5,11 +5,58 @@ NetworkDeleter::NetworkDeleter(QString networkName, QString networkUuidStr, QWid
QDialog(parent),
ui(new Ui::NetworkDeleter)
{
targetNetworkName = networkName;
targetNetworkUuidStr = networkUuidStr;
ui->setupUi(this);
this->setWindowTitle("Delete connection " + networkName + "?");
this->setWindowTitle(tr("Delete connection %1?").arg(networkName));
ui->connectionDeleteWarningLabel->setText(tr("Are you sure you want to delete connection %1?").arg(networkName));
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
connect(ui->cancelButton, &QPushButton::clicked, this, &NetworkDeleter::onCancelClicked);
connect(ui->deleteButton, &QPushButton::clicked, this, &NetworkDeleter::onDeleteClicked);
}
NetworkDeleter::~NetworkDeleter()
{
delete ui;
}
void NetworkDeleter::onCancelClicked()
{
this->done(0);
}
void NetworkDeleter::onDeleteClicked()
{
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(targetNetworkUuidStr);
if (!conn || conn->uuid().isEmpty()) {
QMessageBox errorMsg(QMessageBox::Critical, tr("Connection removal failed"), tr("Could not remove connection %1.").arg(targetNetworkName));
errorMsg.exec();
} else {
// Copied and adapted from plasma-nm
// Remove slave connections
for (const NetworkManager::Connection::Ptr &connection : NetworkManager::listConnections()) {
NetworkManager::ConnectionSettings::Ptr settings = connection->settings();
if (settings->master() == conn->uuid()) {
connection->remove();
}
}
QDBusPendingReply<> reply = conn->remove();
auto watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &NetworkDeleter::deleteReplyFinished);
ui->connectionDeleteWarningLabel->setText(tr("Deleting connection %1...").arg(targetNetworkName));
ui->deleteButton->setEnabled(false);
}
}
void NetworkDeleter::deleteReplyFinished(QDBusPendingCallWatcher *watcher)
{
// Inspired by plasma-nm
QDBusPendingReply<> reply = *watcher;
if (reply.isError() || !reply.isValid()) {
QMessageBox errorMsg(QMessageBox::Critical, tr("Connection removal failed"), tr("Could not remove connection %1.").arg(targetNetworkName));
errorMsg.exec();
}
this->done(0);
}

@ -2,6 +2,14 @@
#define NETWORKDELETER_H
#include <QDialog>
#include <QLayout>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <QMessageBox>
#include <QIcon>
#include <QDBusPendingReply>
#include <QDBusPendingCallWatcher>
namespace Ui {
class NetworkDeleter;
@ -15,8 +23,15 @@ public:
explicit NetworkDeleter(QString networkName, QString networkUuidStr, QWidget *parent = nullptr);
~NetworkDeleter();
private slots:
void onCancelClicked();
void onDeleteClicked();
void deleteReplyFinished(QDBusPendingCallWatcher *watcher);
private:
Ui::NetworkDeleter *ui;
QString targetNetworkName;
QString targetNetworkUuidStr;
};
#endif // NETWORKDELETER_H

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NetworkDeleter</class>
<widget class="QDialog" name="NetworkDeleter">
@ -6,12 +7,48 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>68</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="connectionDeleteWarningLabel">
<property name="text">
<string>connectionDeleteWarningLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>

@ -8,7 +8,6 @@ NetworkSelector::NetworkSelector(QWidget *parent)
{
ui->setupUi(this);
regenConnTree();
ui->modifyConnButton->setEnabled(false);
connect(ui->connTree, &QTreeView::clicked, this, &NetworkSelector::onTreeSingleClicked);
connect(ui->connTree, &QTreeView::doubleClicked, this, &NetworkSelector::onTreeDoubleClicked);
connect(ui->createConnButton, &QPushButton::clicked, this, &NetworkSelector::onCreateClicked);
@ -26,9 +25,11 @@ void NetworkSelector::onTreeSingleClicked(QModelIndex index)
{
QVariant connUuid = index.data(Qt::UserRole+1);
if (!connUuid.isValid()) {
ui->deleteConnButton->setEnabled(false);
ui->modifyConnButton->setEnabled(false);
return;
}
ui->deleteConnButton->setEnabled(true);
ui->modifyConnButton->setEnabled(true);
}
@ -234,6 +235,11 @@ void NetworkSelector::regenConnTree()
connTreeModel->appendRow(currentItemWrap);
}
connTreeModel->sort(0);
ui->modifyConnButton->setEnabled(false);
ui->deleteConnButton->setEnabled(false);
ui->connTree->setModel(connTreeModel);
ui->connTree->setColumnWidth(0, 500);
}

Loading…
Cancel
Save