Commit 32d76665 authored by Valerio Pilo's avatar Valerio Pilo

[plasma-nm/applet] Add right-click context menu to directly customize a connection

Summary: {F6566071}

Reviewers: #vdg, jgrulich

Reviewed By: jgrulich

Subscribers: broulik, jgrulich, ngraham, abetts, GB_2, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D18504
parent 5e48bff2
......@@ -20,7 +20,9 @@
import QtQuick 2.2
import QtQuick.Layouts 1.2
import QtQuick.Controls 2.4 as Controls
import org.kde.kcoreaddons 1.0 as KCoreAddons
import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
......@@ -137,6 +139,33 @@ PlasmaComponents.ListItem {
}
}
MouseArea {
acceptedButtons: Qt.RightButton
anchors.fill: parent
onPressed: {
contextMenu.visualParent = parent
contextMenu.open()
}
}
PlasmaComponents.Menu {
id: contextMenu
PlasmaComponents.MenuItem {
text: ItemUniqueName
enabled: false
}
PlasmaComponents.MenuItem {
text: stateChangeButton.text
icon: (ConnectionState == PlasmaNM.Enums.Deactivated) ? "network-connect" : "network-disconnect"
onClicked: changeState()
}
PlasmaComponents.MenuItem {
text: i18n("Configure")
icon: "settings-configure"
onClicked: KCMShell.open([mainWindow.kcm, "--args", "Uuid=" + Uuid])
}
}
Component {
id: detailsComponent
......
......@@ -100,17 +100,33 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
setButtons(Button::Apply);
// Pre-select currently active primary connection and if there is none then just select
// the very first connection
NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection();
if (activeConnection && activeConnection->isValid()) {
// Also check if the connection type is supported by KCM
const NetworkManager::ConnectionSettings::ConnectionType type = activeConnection->type();
if (UiUtils::isConnectionTypeSupported(type)) {
QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, activeConnection->id()), Q_ARG(QVariant, activeConnection->connection()->path()));
NetworkManager::Connection::Ptr selectedConnection;
// Look in the arguments for a connection ID to preselect
static const QLatin1Literal uuidArgumentMarker { "Uuid=" };
for (QVariant arg : args) {
if (arg.canConvert(QMetaType::QString)) {
QString uuid = arg.toString();
if (uuid.startsWith(uuidArgumentMarker)) {
uuid = uuid.replace(uuidArgumentMarker, QString());
selectedConnection = NetworkManager::findConnectionByUuid(uuid);
qDebug() << "Selecting user connection:" << uuid;
break;
}
}
} else {
// Select first connection
}
// Pre-select the currently active primary connection
if (!selectedConnection || !selectedConnection->isValid()) {
NetworkManager::ActiveConnection::Ptr activeConnection = NetworkManager::primaryConnection();
if (activeConnection && activeConnection->isValid()) {
selectedConnection = activeConnection->connection();
qDebug() << "Selecting active connection:" << selectedConnection->uuid();
}
}
// Select the very first connection as a fallback
if (!selectedConnection || !selectedConnection->isValid()) {
NetworkManager::Connection::List connectionList = NetworkManager::listConnections();
std::sort(connectionList.begin(), connectionList.end(), [] (const NetworkManager::Connection::Ptr &left, const NetworkManager::Connection::Ptr &right)
{
......@@ -144,12 +160,22 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
Q_FOREACH (const NetworkManager::Connection::Ptr &connection, connectionList) {
const NetworkManager::ConnectionSettings::ConnectionType type = connection->settings()->connectionType();
if (UiUtils::isConnectionTypeSupported(type)) {
QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, connection->settings()->id()), Q_ARG(QVariant, connection->path()));
selectedConnection = connection;
qDebug() << "Selecting first connection:" << connection->uuid();
break;
}
}
}
if (selectedConnection && selectedConnection->isValid()) {
const NetworkManager::ConnectionSettings::Ptr settings = selectedConnection->settings();
if (UiUtils::isConnectionTypeSupported(settings->connectionType())) {
QMetaObject::invokeMethod(rootItem, "selectConnection", Q_ARG(QVariant, settings->id()), Q_ARG(QVariant, selectedConnection->path()));
}
} else {
qDebug() << "Cannot preselect a connection";
}
connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KCMNetworkmanagement::onConnectionAdded, Qt::UniqueConnection);
// Initialize first scan and then scan every 15 seconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment