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 "connectionsettingsengine.h"
#include <QDebug> #include <QDebug>
bool ConnectionSettingsEngine::wipeClonedMacAddress = false;
QString ConnectionSettingsEngine::targetConnUuidStr = QString();
/* /*
* The configuration map: * The configuration map:
* *
@ -80,8 +83,10 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
if (!connWiredSetting.isNull()) { if (!connWiredSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWiredSetting->clonedMacAddress())); result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWiredSetting->clonedMacAddress()));
result.insert("mtu", connWiredSetting->mtu());
} else if (!connWirelessSetting.isNull()) { } else if (!connWirelessSetting.isNull()) {
result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWirelessSetting->clonedMacAddress())); result.insert("clonedMacAddress", NetworkManager::macAddressAsString(connWirelessSetting->clonedMacAddress()));
result.insert("mtu", connWirelessSetting->mtu());
} }
// TODO: pick up here // TODO: pick up here
@ -91,8 +96,7 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings) void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVariantMap settings)
{ {
// Contains adapted code from plasma-nm // Contains adapted code from plasma-nm
bool wipeClonedMacAddress = false; wipeClonedMacAddress = false;
NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr); NetworkManager::Connection::Ptr conn = NetworkManager::findConnectionByUuid(connUuidStr);
NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings(); NetworkManager::ConnectionSettings::Ptr connSettings = conn->settings();
NetworkManager::WiredSetting::Ptr connWiredSetting = connSettings->setting(NetworkManager::Setting::Wired).dynamicCast<NetworkManager::WiredSetting>(); 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()); connSettings->setInterfaceName(settings["device"].toString());
} }
if (settings["clonedMacAddress"].isValid()) { QByteArray macBin = NetworkManager::macAddressFromString(settings["clonedMacAddress"].toString());
QByteArray macBin = NetworkManager::macAddressFromString(settings["clonedMacAddress"].toString()); if (settings["clonedMacAddress"].toString().length() != 17) {
if (settings["clonedMacAddress"].toString().length() != 17) { wipeClonedMacAddress = true;
wipeClonedMacAddress = true; }
} else {
if (!connWiredSetting.isNull()) { if (!connWiredSetting.isNull()) {
connWiredSetting->setClonedMacAddress(macBin); if (!wipeClonedMacAddress) {
} else if (!connWirelessSetting.isNull()) { connWiredSetting->setClonedMacAddress(macBin);
connWirelessSetting->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 // 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) { if (wipeClonedMacAddress) {
// Wiping a MAC address with NetworkManagerQt is surprisingly difficult, so we do it with nmcli instead. // Wiping a MAC address with NetworkManagerQt is surprisingly difficult, so we do it with nmcli instead.
QProcess clonedMacWiper; QProcess clonedMacWiper;

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

Loading…
Cancel
Save