From e9e20b8f8aebeb7c9bca42d29eb0fb01300e6123 Mon Sep 17 00:00:00 2001 From: Aaron Rainbolt Date: Tue, 24 Oct 2023 17:46:36 -0500 Subject: [PATCH] Update README, do a bunch of work on the connection settings engine --- README.md | 6 +++ connectionsettingsengine.cpp | 93 ++++++++++++++++++++++++++++++++++++ connectionsettingsengine.h | 4 ++ 3 files changed, 103 insertions(+) diff --git a/README.md b/README.md index 7f919e4..234df87 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This is a straightforward-as-possible Qt reimplmentation of the nm-connection-ed THIS PROJECT IS IN EARLY ALPHA. It may crash or eat your computer, so treat it with caution. +Some code has been copied and adapted from the plasma-nm project. + ## Build instructions sudo apt build-dep lubuntu-connection-editor @@ -13,3 +15,7 @@ THIS PROJECT IS IN EARLY ALPHA. It may crash or eat your computer, so treat it w 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). + +## License and Copyright + +Copyright (c) 2023 Lubuntu Contributors. Licensed under the GNU General Public License version 3 or any later version (GPL-3.0-or-later). This notice applies to all files in this repository. diff --git a/connectionsettingsengine.cpp b/connectionsettingsengine.cpp index 0b7a710..b50995e 100644 --- a/connectionsettingsengine.cpp +++ b/connectionsettingsengine.cpp @@ -14,3 +14,96 @@ ConnectionSettingsEngine::ConnectionSettingsEngine() { } + +QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr) +{ + // Contains adapted code from plasma-nm + NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr); + NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings(); + QVariantMap result; + result.insert("autoconnectEnabled", connSettings->autoconnect()); + result.insert("autoconnectPriority", connSettings->autoconnectPriority()); + result.insert("allUsersMayConnect", connSettings->permissions().isEmpty() ? true : false); + + QStringList secondaryConns = connSettings->secondaries(); + + NetworkManager::Connection::List list = NetworkManager::listConnections(); + QStringList vpnList; + + for (const NetworkManager::Connection::Ptr &conn : list) { + NetworkManager::ConnectionSettings::Ptr conSet = conn->settings(); + if (conSet->connectionType() == NetworkManager::ConnectionSettings::Vpn + || conSet->connectionType() == NetworkManager::ConnectionSettings::WireGuard) { + vpnList.append(conSet->uuid()); + } + } + + if (secondaryConns.isEmpty() || vpnList.isEmpty()) { + result.insert("vpnAutoconnectEnabled", false); + result.insert("autoconnectVpn", ""); + } else { + for (const QString &vpnKey : vpnList) { + if (secondaryConns.contains(vpnKey)) { + result.insert("vpnAutoconnectEnabled", true); + result.insert("autoconnectVpn", vpnKey); + break; + } + } + } + + switch (connSettings->metered()) { + case NetworkManager::ConnectionSettings::MeteredUnknown: + case NetworkManager::ConnectionSettings::MeteredGuessYes: + case NetworkManager::ConnectionSettings::MeteredGuessNo: + result.insert("meteredConnection", "Automatic"); + break; + case NetworkManager::ConnectionSettings::MeteredYes: + result.insert("meteredConnection", "Yes"); + break; + case NetworkManager::ConnectionSettings::MeteredNo: + result.insert("meteredConnection", "No"); + break; + } + + // TODO: pick up here + + return result; +} + +void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings) +{ + // Contains adapted code from plasma-nm + NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr); + NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings(); + + if (settings["autoconnectEnabled"].isValid()) { + connSettings->setAutoconnect(settings["autoconnectEnabled"].toBool()); + } + if (settings["autoconnectPriority"].isValid()) { + connSettings->setAutoconnectPriority(settings["autoconnectPriority"].toInt()); + } + if (settings["allUsersMayConnect"].isValid()) { + if (settings["allUsersMayConnect"].toBool()) { + connSettings->setPermissions(QHash()); + } else { + if (connSettings->permissions().isEmpty()) { + ; // TODO: Add current user to permissiosn list + } // Otherwise we just leave the permissions as-is + } + } + + if (settings["vpnAutoconnectEnabled"].isValid()) { + if (settings["vpnAutoconnectEnabled"].toBool()) { + connSettings->setSecondaries(QStringList() << settings["autoconnectVpn"].toString()); + } + } + + if (settings["meteredConnection"].isValid()) { + QString meteredConnectionStr = settings["meteredConnection"].toString(); + if (meteredConnectionStr == "Yes") { + connSettings->setMetered(NetworkManager::ConnectionSettings::MeteredYes); + } else if (meteredConnectionStr == "No") { + connSettings->setMetered(NetworkManager::ConnectionSettings::MeteredNo); + } // if it's "Automatic" we just leave it be + } +} diff --git a/connectionsettingsengine.h b/connectionsettingsengine.h index 9ce8fcb..7d8fe86 100644 --- a/connectionsettingsengine.h +++ b/connectionsettingsengine.h @@ -3,6 +3,10 @@ #include #include +#include +#include +#include +#include class ConnectionSettingsEngine {