Warning, /plasma/plasma-nm/kcm/qml/main.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2016 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 import QtQuick 2.1
0008 import QtQuick.Dialogs 1.1
0009 import QtQuick.Controls 2.5 as QQC2
0010 import org.kde.plasma.networkmanagement 0.2 as PlasmaNM
0011 import org.kde.kirigami 2.15 as Kirigami
0012 
0013 Item {
0014     id: root
0015 
0016     focus: true
0017 
0018     signal selectedConnectionChanged(string connection)
0019     signal requestCreateConnection(int type, string vpnType, string specificType, bool shared)
0020     signal requestExportConnection(string connection)
0021     signal requestToChangeConnection(string name, string path)
0022 
0023     Kirigami.Theme.colorSet: Kirigami.Theme.Window
0024 
0025     Connections {
0026         target: PlasmaNM.Configuration
0027         function onManageVirtualConnectionsChanged() {
0028             editorProxyModel.invalidate()
0029         }
0030     }
0031 
0032     Rectangle {
0033         id: background
0034         anchors.fill: parent
0035         focus: true
0036         color: Kirigami.Theme.backgroundColor
0037     }
0038 
0039     PlasmaNM.Handler {
0040         id: handler
0041     }
0042 
0043     PlasmaNM.KcmIdentityModel {
0044         id: connectionModel
0045     }
0046 
0047     PlasmaNM.EditorProxyModel {
0048         id: editorProxyModel
0049 
0050         sourceModel: connectionModel
0051     }
0052 
0053     Kirigami.SearchField {
0054         id: searchField
0055 
0056         anchors {
0057             left: parent.left
0058             right: parent.right
0059             top: parent.top
0060         }
0061 
0062         onTextChanged: {
0063             editorProxyModel.setFilterFixedString(text)
0064         }
0065     }
0066 
0067     QQC2.ScrollView {
0068         id: scrollView
0069 
0070         Component.onCompleted: scrollView.background.visible = true // show frame
0071 
0072         anchors {
0073             bottom: rightButtonRow.top
0074             bottomMargin: Kirigami.Units.smallSpacing
0075             left: parent.left
0076             right: parent.right
0077             top: searchField.bottom
0078         }
0079 
0080         ListView {
0081             id: connectionView
0082 
0083             property bool currentConnectionExportable: false
0084             property string currentConnectionName
0085             property string currentConnectionPath
0086 
0087             clip: true
0088             focus: true
0089             activeFocusOnTab: true
0090             model: editorProxyModel
0091             currentIndex: -1
0092             boundsBehavior: Flickable.StopAtBounds
0093             section.property: "KcmConnectionType"
0094             section.delegate: Kirigami.ListSectionHeader { text: section }
0095             delegate: ConnectionItem {
0096                 onAboutToChangeConnection: {
0097                     // Shouldn't be problem to set this in advance
0098                     connectionView.currentConnectionExportable = exportable
0099                     if (connectionModified) {
0100                         requestToChangeConnection(name, path)
0101                     } else {
0102                         connectionView.currentConnectionName = name
0103                         connectionView.currentConnectionPath = path
0104                     }
0105                 }
0106 
0107                 onAboutToExportConnection: {
0108                     requestExportConnection(path)
0109                 }
0110 
0111                 onAboutToRemoveConnection: {
0112                     deleteConfirmationDialog.connectionName = name
0113                     deleteConfirmationDialog.connectionPath = path
0114                     deleteConfirmationDialog.open()
0115                 }
0116             }
0117 
0118             onCurrentConnectionPathChanged: {
0119                 root.selectedConnectionChanged(currentConnectionPath)
0120             }
0121         }
0122     }
0123 
0124     Row {
0125         id: rightButtonRow
0126 
0127         anchors {
0128             bottom: parent.bottom
0129             right: parent.right
0130             margins: Kirigami.Units.smallSpacing
0131         }
0132         spacing: Kirigami.Units.smallSpacing
0133 
0134         QQC2.ToolButton {
0135             id: addConnectionButton
0136 
0137             icon.name: "list-add"
0138 
0139             QQC2.ToolTip.text: i18n("Add new connection")
0140             QQC2.ToolTip.visible: hovered
0141 
0142             onClicked: {
0143                 addNewConnectionDialog.open()
0144             }
0145         }
0146 
0147         QQC2.ToolButton {
0148             id: removeConnectionButton
0149 
0150             enabled: connectionView.currentConnectionPath && connectionView.currentConnectionPath.length
0151             icon.name: "list-remove"
0152 
0153             QQC2.ToolTip.text: i18n("Remove selected connection")
0154             QQC2.ToolTip.visible: hovered
0155 
0156             onClicked: {
0157                 deleteConfirmationDialog.connectionName = connectionView.currentConnectionName
0158                 deleteConfirmationDialog.connectionPath = connectionView.currentConnectionPath
0159                 deleteConfirmationDialog.open()
0160             }
0161         }
0162 
0163         QQC2.ToolButton {
0164             id: exportConnectionButton
0165 
0166             enabled: connectionView.currentConnectionExportable
0167             icon.name: "document-export"
0168 
0169             QQC2.ToolTip.text: i18n("Export selected connection")
0170             QQC2.ToolTip.visible: hovered
0171 
0172             onClicked: {
0173                 root.requestExportConnection(connectionView.currentConnectionPath)
0174             }
0175         }
0176     }
0177 
0178     Row {
0179         id: leftButtonRow
0180 
0181         anchors {
0182             bottom: parent.bottom
0183             left: parent.left
0184             margins: Kirigami.Units.smallSpacing
0185         }
0186         spacing: Kirigami.Units.smallSpacing
0187 
0188         QQC2.ToolButton {
0189             id: configureButton
0190 
0191             icon.name: "configure"
0192 
0193             QQC2.ToolTip.text: i18n("Configuration")
0194             QQC2.ToolTip.visible: hovered
0195 
0196             onClicked: {
0197                 configurationDialog.open()
0198             }
0199         }
0200     }
0201 
0202     MessageDialog {
0203         id: deleteConfirmationDialog
0204 
0205         property string connectionName
0206         property string connectionPath
0207 
0208         /* Like QString::toHtmlEscaped */
0209         function toHtmlEscaped(s) {
0210             return s.replace(/[&<>]/g, function (tag) {
0211                 return {
0212                     '&': '&amp;',
0213                     '<': '&lt;',
0214                     '>': '&gt;'
0215                 }[tag] || tag
0216             });
0217         }
0218 
0219         icon: StandardIcon.Question
0220         standardButtons: StandardButton.Ok | StandardButton.Cancel
0221         title: i18nc("@title:window", "Remove Connection")
0222         text: i18n("Do you want to remove the connection '%1'?", toHtmlEscaped(connectionName))
0223 
0224         onAccepted: {
0225             if (connectionPath == connectionView.currentConnectionPath) {
0226                 // Deselect now non-existing connection
0227                 deselectConnections()
0228             }
0229             handler.removeConnection(connectionPath)
0230         }
0231     }
0232 
0233     AddConnectionDialog {
0234         id: addNewConnectionDialog
0235 
0236         onRequestCreateConnection: {
0237             root.requestCreateConnection(type, vpnType, specificType, shared)
0238         }
0239     }
0240 
0241     ConfigurationDialog {
0242         id: configurationDialog
0243     }
0244 
0245     function deselectConnections() {
0246         connectionView.currentConnectionPath = ""
0247     }
0248 
0249     function selectConnection(connectionName, connectionPath) {
0250         connectionView.currentConnectionName = connectionName
0251         connectionView.currentConnectionPath = connectionPath
0252     }
0253 }