Warning, /plasma/plasma-nm/kcm/qml/ConnectionItem.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.Controls 2.15 as QQC2
0009 import org.kde.kirigami 2.5 as Kirigami
0010 import org.kde.plasma.components 3.0 as PlasmaComponents3
0011 import org.kde.plasma.networkmanagement as PlasmaNM
0012 
0013 ListItem {
0014     id: connectionItem
0015 
0016     height: connectionItemBase.height
0017     acceptedButtons: Qt.AllButtons
0018     checked: ConnectionPath === connectionView.currentConnectionPath
0019 
0020     signal aboutToChangeConnection(bool exportable, string name, string path)
0021     signal aboutToRemoveConnection(string name, string path)
0022 
0023     onClicked: mouse => {
0024         if (mouse.button === Qt.LeftButton) {
0025             aboutToChangeConnection(KcmVpnConnectionExportable, Name, ConnectionPath)
0026         } else if (mouse.button === Qt.RightButton) {
0027             connectionItemMenu.popup()
0028         }
0029     }
0030 
0031     Item {
0032         id: connectionItemBase
0033 
0034         anchors {
0035             left: parent.left
0036             right: parent.right
0037             top: parent.top
0038             topMargin: -Math.round(Kirigami.Units.gridUnit / 3)
0039         }
0040         height: Math.max(Kirigami.Units.iconSizes.medium, connectionNameLabel.height + connectionStatusLabel.height) + Math.round(Kirigami.Units.gridUnit / 2)
0041 
0042         Kirigami.Icon {
0043             id: connectionIcon
0044 
0045             anchors {
0046                 left: parent.left
0047                 verticalCenter: parent.verticalCenter
0048             }
0049             color: (connectionItem.checked || connectionItem.pressed) ? Kirigami.Theme.highlightedTextColor : textColor
0050             height: Kirigami.Units.iconSizes.medium; width: height
0051             source: KcmConnectionIcon
0052         }
0053 
0054         Text {
0055             id: connectionNameLabel
0056 
0057             anchors {
0058                 bottom: connectionIcon.verticalCenter
0059                 left: connectionIcon.right
0060                 leftMargin: Math.round(Kirigami.Units.gridUnit / 2)
0061                 right: connectingIndicator.visible ? connectingIndicator.left : parent.right
0062             }
0063             color: (connectionItem.checked || connectionItem.pressed) ? Kirigami.Theme.highlightedTextColor : textColor
0064             height: paintedHeight
0065             elide: Text.ElideRight
0066             font.weight: ConnectionState === PlasmaNM.Enums.Activated ? Font.DemiBold : Font.Normal
0067             font.italic: ConnectionState === PlasmaNM.Enums.Activating ? true : false
0068             text: Name
0069             textFormat: Text.PlainText
0070         }
0071 
0072         Text {
0073             id: connectionStatusLabel
0074 
0075             anchors {
0076                 left: connectionIcon.right
0077                 leftMargin: Math.round(Kirigami.Units.gridUnit / 2)
0078                 right: connectingIndicator.visible ? connectingIndicator.left : parent.right
0079                 top: connectionNameLabel.bottom
0080             }
0081             color: (connectionItem.checked || connectionItem.pressed) ? Kirigami.Theme.highlightedTextColor : textColor
0082             height: paintedHeight
0083             elide: Text.ElideRight
0084             font.pointSize: Kirigami.Theme.smallFont.pointSize
0085             opacity: 0.6
0086             text: itemText()
0087         }
0088 
0089         PlasmaComponents3.BusyIndicator {
0090             id: connectingIndicator
0091 
0092             anchors {
0093                 right: parent.right
0094                 rightMargin: Math.round(Kirigami.Units.gridUnit / 2)
0095                 verticalCenter: connectionIcon.verticalCenter
0096             }
0097             height: Kirigami.Units.iconSizes.medium
0098             width: Kirigami.Units.iconSizes.medium
0099             running: ConnectionState === PlasmaNM.Enums.Activating
0100             visible: running
0101         }
0102     }
0103 
0104     QQC2.Menu {
0105         id: connectionItemMenu
0106 
0107         QQC2.MenuItem {
0108             text: ConnectionState === PlasmaNM.Enums.Deactivated ? i18n("Connect") : i18n("Disconnect")
0109             visible: ItemType === 1
0110             onTriggered: {
0111                 if (ConnectionState === PlasmaNM.Enums.Deactivated) {
0112                     handler.activateConnection(ConnectionPath, DevicePath, SpecificPath);
0113                 } else {
0114                     handler.deactivateConnection(ConnectionPath, DevicePath);
0115                 }
0116             }
0117         }
0118 
0119         QQC2.MenuItem {
0120             icon.name: "list-remove"
0121             text: i18n("Delete");
0122 
0123             onTriggered: {
0124                 aboutToRemoveConnection(Name, ConnectionPath)
0125             }
0126         }
0127 
0128         QQC2.MenuItem {
0129             icon.name: "document-export"
0130             visible: KcmVpnConnectionExportable
0131             text: i18n("Export");
0132 
0133             onTriggered: kcm.onRequestExportConnection(ConnectionPath)
0134         }
0135     }
0136 
0137     /* This generates the status description under each connection
0138        in the list at the left side of the applet. */
0139     function itemText() {
0140         if (ConnectionState === PlasmaNM.Enums.Activated) {
0141             return i18n("Connected")
0142         } else if (ConnectionState === PlasmaNM.Enums.Activating) {
0143             return i18n("Connecting")
0144         } else {
0145             return LastUsed
0146         }
0147     }
0148 }