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