add MTU load/save for Ethernet, reorganize yet more stuff

main
Aaron Rainbolt 1 year ago
parent 77320c140f
commit 48a0974529

@ -1,6 +1,9 @@
#include "connectionsettingsengine.h"
#include <QDebug>
bool ConnectionSettingsEngine::wipeClonedMacAddress = false;
QString ConnectionSettingsEngine::targetConnUuidStr = QString();
/*
* The configuration map:
*
@ -80,8 +83,10 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
if (!connWiredSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWiredSetting->clonedMacAddress()));
result.insert("mtu", connWiredSetting->mtu());
} else if (!connWirelessSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWirelessSetting->clonedMacAddress()));
result.insert("mtu", connWirelessSetting->mtu());
}
// TODO: pick up here
@ -91,8 +96,7 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings)
{
// Contains adapted code from plasma-nm
bool wipeClonedMacAddress = false;
wipeClonedMacAddress = false;
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr);
NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings();
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
@ -138,23 +142,43 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
connSettings->setInterfaceName(settings["device"].toString());
}
if (settings["clonedMacAddress"].isValid()) {
QByteArray macBin = NetworkManager::macAddressFromString(settings["clonedMacAddress"].toString());
if (settings["clonedMacAddress"].toString().length() != 17) {
wipeClonedMacAddress = true;
} else {
}
if (!connWiredSetting.isNull()) {
if (!wipeClonedMacAddress) {
connWiredSetting->setClonedMacAddress(macBin);
}
if (settings["mtu"].isValid()) {
connWiredSetting->setMtu(settings["mtu"].toUInt());
}
} else if (!connWirelessSetting.isNull()) {
if (!wipeClonedMacAddress) {
connWirelessSetting->setClonedMacAddress(macBin);
}
if (settings["mtu"].isValid()) {
connWirelessSetting->setMtu(settings["mtu"].toUInt());
}
}
// TODO: pick up here
conn->update(connSettings->toMap());
targetConnUuidStr = connUuidStr;
QDBusPendingReply<> reply = conn->update(connSettings->toMap());
auto watcher = new QDBusPendingCallWatcher(reply);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, saveReplyFinished);
}
void ConnectionSettingsEngine::saveReplyFinished()
{
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(targetConnUuidStr);
NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings();
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>();
NetworkManager::WirelessSetting::Ptr connWirelessSetting = connSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
if (wipeClonedMacAddress) {
// Wiping a MAC address with NetworkManagerQt is surprisingly difficult, so we do it with nmcli instead.
QProcess clonedMacWiper;

@ -1,10 +1,6 @@
#ifndef CONNECTIONSETTINGSENGINE_H
#define CONNECTIONSETTINGSENGINE_H
#include <QString>
#include <QVariant>
#include <QHash>
#include <QProcess>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/Settings>
@ -13,6 +9,12 @@
#include <NetworkManagerQt/WiredSetting>
#include <NetworkManagerQt/WirelessSetting>
#include <NetworkManagerQt/Utils>
#include <QString>
#include <QVariant>
#include <QHash>
#include <QProcess>
#include <QDBusPendingReply>
#include <QDBusPendingCallWatcher>
class ConnectionSettingsEngine
{
@ -39,8 +41,13 @@ public:
static QVariantMap readConnectionSettings(QString connUuidStr);
static void modifyConnectionSettings(QString connUuidStr, QVariantMap settings);
private slots:
static void saveReplyFinished();
private:
static QString userName();
static QString targetConnUuidStr;
static bool wipeClonedMacAddress;
};
#endif // CONNECTIONSETTINGSENGINE_H

Loading…
Cancel
Save