|
|
@ -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;
|
|
|
|