Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
Plasma applet for NetworkManager
Commits
d404f0f0
Commit
d404f0f0
authored
Nov 18, 2022
by
Nicolas Fella
Browse files
Reduce nesting by returning early
parent
e4b9209c
Pipeline
#270061
passed with stage
in 1 minute and 58 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
kcm/kcm.cpp
View file @
d404f0f0
...
...
@@ -530,57 +530,59 @@ void KCMNetworkmanagement::importVpn()
const
QString
&
filename
=
QFileDialog
::
getOpenFileName
(
this
,
i18n
(
"Import VPN Connection"
),
QDir
::
homePath
(),
i18n
(
"VPN connections (%1)"
,
extensions
.
join
(
QLatin1Char
(
' '
))));
if
(
!
filename
.
isEmpty
())
{
QFileInfo
fi
(
filename
);
const
QString
ext
=
QStringLiteral
(
"*."
)
%
fi
.
suffix
();
qCDebug
(
PLASMA_NM_KCM_LOG
)
<<
"Importing VPN connection "
<<
filename
<<
"extension:"
<<
ext
;
// Handle WireGuard separately because it is different than all the other VPNs
if
(
WireGuardInterfaceWidget
::
supportedFileExtensions
().
contains
(
ext
))
{
NMVariantMapMap
connection
=
WireGuardInterfaceWidget
::
importConnectionSettings
(
filename
);
NetworkManager
::
ConnectionSettings
connectionSettings
;
connectionSettings
.
fromMap
(
connection
);
connectionSettings
.
setUuid
(
NetworkManager
::
ConnectionSettings
::
createNewUuid
());
if
(
filename
.
isEmpty
())
{
return
;
}
// qCDebug(PLASMA_NM_KCM_LOG) << "Converted connection:" << connectionSettings;
QFileInfo
fi
(
filename
);
const
QString
ext
=
QStringLiteral
(
"*."
)
%
fi
.
suffix
();
qCDebug
(
PLASMA_NM_KCM_LOG
)
<<
"Importing VPN connection "
<<
filename
<<
"extension:"
<<
ext
;
m_handler
->
addConnection
(
connectionSettings
.
toMap
());
// qCDebug(PLASMA_NM_KCM_LOG) << "Adding imported connection under id:" << conId;
// Handle WireGuard separately because it is different than all the other VPNs
if
(
WireGuardInterfaceWidget
::
supportedFileExtensions
().
contains
(
ext
))
{
NMVariantMapMap
connection
=
WireGuardInterfaceWidget
::
importConnectionSettings
(
filename
);
NetworkManager
::
ConnectionSettings
connectionSettings
;
connectionSettings
.
fromMap
(
connection
);
connectionSettings
.
setUuid
(
NetworkManager
::
ConnectionSettings
::
createNewUuid
());
if
(
!
connection
.
isEmpty
())
{
return
;
// get out if the import produced at least some output
}
// qCDebug(PLASMA_NM_KCM_LOG) << "Converted connection:" << connectionSettings;
m_handler
->
addConnection
(
connectionSettings
.
toMap
());
// qCDebug(PLASMA_NM_KCM_LOG) << "Adding imported connection under id:" << conId;
if
(
!
connection
.
isEmpty
())
{
return
;
// get out if the import produced at least some output
}
for
(
const
KPluginMetaData
&
service
:
services
)
{
const
auto
result
=
KPluginFactory
::
instantiatePlugin
<
VpnUiPlugin
>
(
service
);
}
for
(
const
KPluginMetaData
&
service
:
services
)
{
const
auto
result
=
KPluginFactory
::
instantiatePlugin
<
VpnUiPlugin
>
(
service
);
if
(
!
result
)
{
continue
;
}
if
(
!
result
)
{
continue
;
}
std
::
unique_ptr
<
VpnUiPlugin
>
vpnPlugin
(
result
.
plugin
);
std
::
unique_ptr
<
VpnUiPlugin
>
vpnPlugin
(
result
.
plugin
);
if
(
vpnPlugin
->
supportedFileExtensions
().
contains
(
ext
))
{
qCDebug
(
PLASMA_NM_KCM_LOG
)
<<
"Found VPN plugin"
<<
service
.
name
()
<<
", type:"
<<
service
.
value
(
"X-NetworkManager-Services"
);
if
(
vpnPlugin
->
supportedFileExtensions
().
contains
(
ext
))
{
qCDebug
(
PLASMA_NM_KCM_LOG
)
<<
"Found VPN plugin"
<<
service
.
name
()
<<
", type:"
<<
service
.
value
(
"X-NetworkManager-Services"
);
NMVariantMapMap
connection
=
vpnPlugin
->
importConnectionSettings
(
filename
);
NMVariantMapMap
connection
=
vpnPlugin
->
importConnectionSettings
(
filename
);
// qCDebug(PLASMA_NM_KCM_LOG) << "Raw connection:" << connection;
// qCDebug(PLASMA_NM_KCM_LOG) << "Raw connection:" << connection;
NetworkManager
::
ConnectionSettings
connectionSettings
;
connectionSettings
.
fromMap
(
connection
);
connectionSettings
.
setUuid
(
NetworkManager
::
ConnectionSettings
::
createNewUuid
());
NetworkManager
::
ConnectionSettings
connectionSettings
;
connectionSettings
.
fromMap
(
connection
);
connectionSettings
.
setUuid
(
NetworkManager
::
ConnectionSettings
::
createNewUuid
());
// qCDebug(PLASMA_NM_KCM_LOG) << "Converted connection:" << connectionSettings;
// qCDebug(PLASMA_NM_KCM_LOG) << "Converted connection:" << connectionSettings;
m_handler
->
addConnection
(
connectionSettings
.
toMap
());
// qCDebug(PLASMA_NM_KCM_LOG) << "Adding imported connection under id:" << conId;
m_handler
->
addConnection
(
connectionSettings
.
toMap
());
// qCDebug(PLASMA_NM_KCM_LOG) << "Adding imported connection under id:" << conId;
if
(
connection
.
isEmpty
())
{
// the "positive" part will arrive with connectionAdded
// TODO display success
}
else
{
break
;
// stop iterating over the plugins if the import produced at least some output
}
if
(
connection
.
isEmpty
())
{
// the "positive" part will arrive with connectionAdded
// TODO display success
}
else
{
break
;
// stop iterating over the plugins if the import produced at least some output
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment