|
|
|
@ -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()) {
|
|
|
|
|
connWiredSetting->setClonedMacAddress(macBin);
|
|
|
|
|
} else if (!connWirelessSetting.isNull()) {
|
|
|
|
|
connWirelessSetting->setClonedMacAddress(macBin);
|
|
|
|
|
}
|
|
|
|
|
QByteArray macBin = NetworkManager::macAddressFromString(settings["clonedMacAddress"].toString());
|
|
|
|
|
if (settings["clonedMacAddress"].toString().length() != 17) {
|
|
|
|
|
wipeClonedMacAddress = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|