@ -1,7 +1,6 @@
# include "connectionsettingsengine.h"
# include <QDebug>
bool ConnectionSettingsEngine : : wipeClonedMacAddress = false ;
QString ConnectionSettingsEngine : : targetConnUuidStr = QString ( ) ;
/*
@ -369,7 +368,8 @@ QVariantMap ConnectionSettingsEngine::readConnectionSettings(QString connUuidStr
void ConnectionSettingsEngine : : modifyConnectionSettings ( QString connUuidStr , QVariantMap settings )
{
// Contains adapted code from plasma-nm
wipeClonedMacAddress = false ;
bool wipeClonedMacAddress = false ;
bool wipeManualIpv4Addresses = false ;
bool ensure802_1xSettings = false ;
NetworkManager : : Connection : : Ptr conn = NetworkManager : : findConnectionByUuid ( connUuidStr ) ;
NetworkManager : : ConnectionSettings : : Ptr connSettings = conn - > settings ( ) ;
@ -466,7 +466,12 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
}
if ( settings [ " ipv4AddressList " ] . isValid ( ) ) {
connIpv4Setting - > setAddresses ( settings [ " ipv4AddressList " ] . value < QList < NetworkManager : : IpAddress > > ( ) ) ;
QList < NetworkManager : : IpAddress > ipv4AddrList = settings [ " ipv4AddressList " ] . value < QList < NetworkManager : : IpAddress > > ( ) ;
if ( ! ipv4AddrList . isEmpty ( ) ) {
connIpv4Setting - > setAddresses ( ipv4AddrList ) ;
} else {
wipeManualIpv4Addresses = true ;
}
}
if ( settings [ " ipv4Required " ] . isValid ( ) ) {
@ -683,6 +688,29 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
if ( ensure802_1xSettings ) {
connSettingsMap . insert ( " 802-1x " , secSetting . toMap ( ) ) ;
}
if ( wipeClonedMacAddress ) {
QVariantMap ethSettingsMap = connSettingsMap . value ( " 802-3-ethernet " ) ;
if ( ! ethSettingsMap . isEmpty ( ) ) {
ethSettingsMap . remove ( " cloned-mac-address " ) ;
ethSettingsMap . remove ( " assigned-mac-address " ) ;
connSettingsMap . remove ( " 802-3-ethernet " ) ;
connSettingsMap . insert ( " 802-3-ethernet " , ethSettingsMap ) ;
}
// TODO: Handle WiFi here
}
if ( wipeManualIpv4Addresses ) {
QVariantMap ipv4SettingsMap = connSettingsMap . value ( " ipv4 " ) ;
if ( ! ipv4SettingsMap . isEmpty ( ) ) {
qWarning ( ) < < " made it " ;
ipv4SettingsMap . remove ( " addresses " ) ;
ipv4SettingsMap . remove ( " address-data " ) ;
ipv4SettingsMap . remove ( " gateway " ) ;
connSettingsMap . remove ( " ipv4 " ) ;
connSettingsMap . insert ( " ipv4 " , ipv4SettingsMap ) ;
}
}
qWarning ( ) < < connSettingsMap ;
// TODO: Do something to surpress app exit here
QDBusPendingReply < > reply = conn - > update ( connSettingsMap ) ;
auto watcher = new QDBusPendingCallWatcher ( reply ) ;
QObject : : connect ( watcher , & QDBusPendingCallWatcher : : finished , saveReplyFinished ) ;
@ -690,24 +718,7 @@ void ConnectionSettingsEngine::modifyConnectionSettings(QString connUuidStr, QVa
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 ;
clonedMacWiper . setProgram ( " bash " ) ;
if ( ! connWiredSetting . isNull ( ) ) {
clonedMacWiper . setArguments ( QStringList ( ) < < QString ( " -c " ) < < QString ( " nmcli connection modify %1 ethernet.cloned-mac-address \" \" " ) . arg ( conn - > uuid ( ) ) ) ;
clonedMacWiper . start ( ) ;
clonedMacWiper . waitForFinished ( ) ;
} else if ( ! connWirelessSetting . isNull ( ) ) {
clonedMacWiper . setArguments ( QStringList ( ) < < QString ( " -c " ) < < QString ( " nmcli connection modify %1 wifi.cloned-mac-address \" \" " ) . arg ( conn - > uuid ( ) ) ) ;
clonedMacWiper . start ( ) ;
clonedMacWiper . waitForFinished ( ) ;
}
}
// TODO: Do something to unsupress app exit here
}
QString ConnectionSettingsEngine : : userName ( )