summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Grulich <[email protected]>2016-11-23 12:37:16 +0100
committerJan Grulich <[email protected]>2016-11-23 12:37:16 +0100
commit0256ffb29858f9a810d5bb1b312ef3b2c56531d9 (patch)
treed8d719b6abe645ca5b574ec14450a7092eb1a052
parent584e947e39450dad2baca7ded9fd417d02a64a2c (diff)
Add a context menu with options to remove/activate/deactivate connection
+ remove trailing spaces + set minimum size for the kcm
-rwxr-xr-xkcm/kcm.cpp47
-rwxr-xr-xkcm/kcm.h3
-rwxr-xr-xkcm/kcm.ui10
-rw-r--r--kcm/qml/ConnectionItem.qml67
-rw-r--r--kcm/qml/Dialog.qml30
-rwxr-xr-xkcm/qml/main.qml66
6 files changed, 161 insertions, 62 deletions
diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp
index 9507541..dae50ff 100755
--- a/kcm/kcm.cpp
+++ b/kcm/kcm.cpp
@@ -76,7 +76,7 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
QObject *rootItem = m_quickView->rootObject();
connect(rootItem, SIGNAL(selectedConnectionChanged(QString)), this, SLOT(onSelectedConnectionChanged(QString)));
connect(rootItem, SIGNAL(requestCreateConnection(int,QString,QString,bool)), this, SLOT(onRequestCreateConnection(int,QString,QString,bool)));
-
+
QVBoxLayout *l = new QVBoxLayout(this);
l->addWidget(mainWidget);
@@ -85,6 +85,12 @@ KCMNetworkmanagement::KCMNetworkmanagement(QWidget *parent, const QVariantList &
KCMNetworkmanagement::~KCMNetworkmanagement()
{
+ delete m_handler;
+ if (m_tabWidget) {
+ delete m_tabWidget;
+ }
+ delete m_quickView;
+ delete m_ui;
}
void KCMNetworkmanagement::defaults()
@@ -98,7 +104,7 @@ void KCMNetworkmanagement::load()
if (m_currentConnectionPath.isEmpty()) {
return;
}
-
+
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath);
if (connection) {
NetworkManager::ConnectionSettings::Ptr connectionSettings = connection->settings();
@@ -107,18 +113,18 @@ void KCMNetworkmanagement::load()
m_tabWidget->setConnection(connectionSettings);
}
}
-
+
KCModule::load();
}
void KCMNetworkmanagement::save()
{
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath);
-
+
if (connection) {
m_handler->updateConnection(connection, m_tabWidget->setting());
}
-
+
KCModule::save();
}
@@ -219,8 +225,13 @@ void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const Q
void KCMNetworkmanagement::onSelectedConnectionChanged(const QString &connectionPath)
{
+ if (connectionPath.isEmpty()) {
+ resetSelection();
+ return;
+ }
+
m_currentConnectionPath = connectionPath;
-
+
NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(m_currentConnectionPath);
if (connection) {
NetworkManager::ConnectionSettings::Ptr connectionSettings = connection->settings();
@@ -230,16 +241,8 @@ void KCMNetworkmanagement::onSelectedConnectionChanged(const QString &connection
void KCMNetworkmanagement::addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings)
{
- // Reset selected connections
- m_currentConnectionPath.clear();
- QObject *rootItem = m_quickView->rootObject();
- QMetaObject::invokeMethod(rootItem, "deselectConnections");
- if (m_tabWidget) {
- delete m_ui->connectionConfiguration->layout();
- delete m_tabWidget;
- m_tabWidget = nullptr;
- }
-
+ resetSelection();
+
QPointer<ConnectionEditorDialog> editor = new ConnectionEditorDialog(connectionSettings);
connect(editor.data(), &ConnectionEditorDialog::accepted,
[connectionSettings, editor, this] () {
@@ -268,6 +271,18 @@ void KCMNetworkmanagement::loadConnectionSettings(const NetworkManager::Connecti
Q_EMIT changed(true);
}
+void KCMNetworkmanagement::resetSelection()
+{
+ // Reset selected connections
+ m_currentConnectionPath.clear();
+ QObject *rootItem = m_quickView->rootObject();
+ QMetaObject::invokeMethod(rootItem, "deselectConnections");
+ if (m_tabWidget) {
+ delete m_ui->connectionConfiguration->layout();
+ delete m_tabWidget;
+ m_tabWidget = nullptr;
+ }
+}
#include "kcm.moc"
diff --git a/kcm/kcm.h b/kcm/kcm.h
index 54a49d5..d0f2f2d 100755
--- a/kcm/kcm.h
+++ b/kcm/kcm.h
@@ -48,7 +48,8 @@ private Q_SLOTS:
private:
void addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings);
void loadConnectionSettings(const NetworkManager::ConnectionSettings::Ptr &connectionSettings);
-
+ void resetSelection();
+
QString m_currentConnectionPath;
Handler *m_handler;
ConnectionEditorTabWidget *m_tabWidget;
diff --git a/kcm/kcm.ui b/kcm/kcm.ui
index f553936..9861843 100755
--- a/kcm/kcm.ui
+++ b/kcm/kcm.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>606</width>
- <height>456</height>
+ <width>800</width>
+ <height>500</height>
</rect>
</property>
<property name="sizePolicy">
@@ -16,6 +16,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="minimumSize">
+ <size>
+ <width>800</width>
+ <height>500</height>
+ </size>
+ </property>
<property name="windowTitle">
<string>Form</string>
</property>
diff --git a/kcm/qml/ConnectionItem.qml b/kcm/qml/ConnectionItem.qml
index 77686dc..b622b69 100644
--- a/kcm/qml/ConnectionItem.qml
+++ b/kcm/qml/ConnectionItem.qml
@@ -29,10 +29,11 @@ import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
PlasmaComponents.ListItem {
id: connectionItem
- checked: containsMouse || ConnectionPath === connectionView.currentConnection
- enabled: true
+ checked: mouseArea.containsMouse || ConnectionPath === connectionView.currentConnection
height: connectionItemBase.height
+ signal aboutToRemove(string name, string path)
+
Item {
id: connectionItemBase
@@ -63,7 +64,7 @@ PlasmaComponents.ListItem {
bottom: connectionIcon.verticalCenter
left: connectionIcon.right
leftMargin: Math.round(units.gridUnit / 2)
- right: parent.right
+ right: connectingIndicator.visible ? connectingIndicator.left : parent.right
}
height: paintedHeight
elide: Text.ElideRight
@@ -79,7 +80,7 @@ PlasmaComponents.ListItem {
anchors {
left: connectionIcon.right
leftMargin: Math.round(units.gridUnit / 2)
- right: parent.right
+ right: connectingIndicator.visible ? connectingIndicator.left : parent.right
top: connectionNameLabel.bottom
}
height: paintedHeight
@@ -88,6 +89,60 @@ PlasmaComponents.ListItem {
opacity: 0.6
text: itemText()
}
+
+ PlasmaComponents.BusyIndicator {
+ id: connectingIndicator
+
+ anchors {
+ right: parent.right
+ rightMargin: Math.round(units.gridUnit / 2)
+ verticalCenter: connectionIcon.verticalCenter
+ }
+ height: units.iconSizes.medium; width: height
+ running: ConnectionState == PlasmaNM.Enums.Activating
+ visible: running
+ }
+ }
+
+ PlasmaComponents.Menu {
+ id: connectionItemMenu
+ visualParent: mouseArea
+
+ PlasmaComponents.MenuItem {
+ text: ConnectionState == PlasmaNM.Enums.Deactivated ? i18n("Connect") : i18n("Disconnect")
+ visible: ItemType == 1
+ onClicked: {
+ if (ConnectionState == PlasmaNM.Enums.Deactivated) {
+ handler.activateConnection(ConnectionPath, DevicePath, SpecificPath);
+ } else {
+ handler.deactivateConnection(ConnectionPath, DevicePath);
+ }
+ }
+ }
+
+ PlasmaComponents.MenuItem {
+ icon: "list-remove"
+ text: i18n("Delete");
+
+ onClicked: {
+ aboutToRemove(Name, ConnectionPath)
+ }
+ }
+ }
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ acceptedButtons: Qt.AllButtons;
+ hoverEnabled: true
+
+ onClicked: {
+ if (mouse.button === Qt.LeftButton) {
+ connectionView.currentConnection = ConnectionPath
+ } else if (mouse.button == Qt.RightButton) {
+ connectionItemMenu.open(mouse.x, mouse.y)
+ }
+ }
}
function itemText() {
@@ -97,8 +152,4 @@ PlasmaComponents.ListItem {
return LastUsed
}
}
-
- onClicked: {
- connectionView.currentConnection = ConnectionPath
- }
}
diff --git a/kcm/qml/Dialog.qml b/kcm/qml/Dialog.qml
index dbf57f9..2e4a69c 100644
--- a/kcm/qml/Dialog.qml
+++ b/kcm/qml/Dialog.qml
@@ -31,15 +31,15 @@ Dialog {
title: i18n("Choose a connection type")
signal requestCreateConnection(int type, string vpnType, string specificType, bool shared)
-
+
contentItem: Item {
implicitHeight: 600
implicitWidth: 500
-
+
PlasmaNM.CreatableConnectionsModel {
id: connectionModel
}
-
+
SystemPalette {
id: palette
}
@@ -60,16 +60,16 @@ Dialog {
right: parent.right
top: parent.top
}
-
+
ListView {
id: view
-
+
property int currentlySelectedIndex: -1
property bool connectionShared
property string connectionSpecificType
property int connectionType
property string connectionVpnType
-
+
anchors.fill: parent
clip: true
model: connectionModel
@@ -80,7 +80,7 @@ Dialog {
delegate: PlasmaComponents.ListItem {
checked: mouseArea.containsMouse || view.currentlySelectedIndex == index
height: connectionTypeBase.height
-
+
Item {
id: connectionTypeBase
@@ -135,12 +135,12 @@ Dialog {
text: ConnectionDescription
}
}
-
+
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
-
+
onClicked: {
createButton.enabled = true
view.currentlySelectedIndex = index
@@ -149,7 +149,7 @@ Dialog {
view.connectionType = ConnectionType
view.connectionVpnType = ConnectionVpnType
}
-
+
onDoubleClicked: {
dialog.close()
dialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.ConnectionSpecificType, view.connectionShared)
@@ -158,7 +158,7 @@ Dialog {
}
}
}
-
+
Row {
id: buttonRow
anchors {
@@ -167,22 +167,22 @@ Dialog {
margins: Math.round(units.gridUnit / 2)
}
spacing: Math.round(units.gridUnit / 2)
-
+
PlasmaComponents.Button {
id: createButton
enabled: false
text: i18n("Create")
-
+
onClicked: {
dialog.close()
dialog.requestCreateConnection(view.connectionType, view.connectionVpnType, view.connectionSpecificType, view.connectionShared)
}
}
-
+
PlasmaComponents.Button {
id: closeButton
text: i18n("Close")
-
+
onClicked: {
dialog.close()
}
diff --git a/kcm/qml/main.qml b/kcm/qml/main.qml
index 95a270b..3db5637 100755
--- a/kcm/qml/main.qml
+++ b/kcm/qml/main.qml
@@ -21,6 +21,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
+import QtQuick.Dialogs 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
@@ -28,8 +29,9 @@ import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
Item {
id: root
- focus: true
+
anchors.fill: parent
+ focus: true
signal selectedConnectionChanged(string connection)
signal requestCreateConnection(int type, string vpnType, string specificType, bool shared)
@@ -61,21 +63,21 @@ Item {
PlasmaComponents.TextField {
id: searchField
-
+
anchors {
left: parent.left
right: parent.right
top: parent.top
}
-
+
placeholderText: i18n("Type here to search connections...")
-
+
onTextChanged: {
console.error(text)
editorProxyModel.setFilterRegExp(text)
}
}
-
+
PlasmaExtras.ScrollArea {
id: scrollView
@@ -98,59 +100,83 @@ Item {
boundsBehavior: Flickable.StopAtBounds
section.property: "KcmConnectionType"
section.delegate: Header { text: section }
- delegate: ConnectionItem { }
+ delegate: ConnectionItem {
+ onAboutToRemove: {
+ deleteConfirmationDialog.connectionName = name
+ deleteConfirmationDialog.connectionPath = path
+ deleteConfirmationDialog.open()
+ }
+ }
onCurrentConnectionChanged: {
- if (currentConnection) {
- root.selectedConnectionChanged(currentConnection)
- }
+ root.selectedConnectionChanged(currentConnection)
}
}
}
-
+
Column {
id: buttonRow
-
+
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
margins: Math.round(units.gridUnit / 2)
}
-
+
spacing: Math.round(units.gridUnit / 2)
-
+
PlasmaCore.SvgItem {
id: separator
height: lineSvg.elementSize("horizontal-line").height; width: parent.width
elementId: "horizontal-line"
svg: PlasmaCore.Svg { id: lineSvg; imagePath: "widgets/line" }
}
-
+
PlasmaComponents.Button {
id: addConnectionButton
-
+
anchors {
right: parent.right
}
-
+
iconSource: "list-add"
text: i18n("Add new connection")
-
+
onClicked: {
addNewConnectionDialog.open()
}
}
}
-
+
+ MessageDialog {
+ id: deleteConfirmationDialog
+
+ property string connectionName
+ property string connectionPath
+
+ icon: StandardIcon.Question
+ standardButtons: StandardButton.Ok | StandardButton.Close
+ title: i18n("Remove connection")
+ text: i18n("Do you want to remove the connection '%1'", connectionName)
+
+ onAccepted: {
+ if (connectionPath == connectionView.currentConnection) {
+ // Deselect now non-existing connection
+ deselectConnections()
+ }
+ handler.removeConnection(connectionPath)
+ }
+ }
+
Dialog {
id: addNewConnectionDialog
-
+
onRequestCreateConnection: {
root.requestCreateConnection(type, vpnType, specificType, shared)
}
}
-
+
function deselectConnections() {
connectionView.currentConnection = ""
}