Warning, /plasma/plasma-firewall/kcm/ui/AdvancedRuleEdit.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Lucas Biaggi <lbjanuario@gmail.com>
0003 
0004 import QtQuick 2.12
0005 import QtQuick.Controls 2.0
0006 import QtQuick.Layouts 1.1
0007 
0008 import QtQuick.Controls 2.12 as QQC2
0009 import org.kde.kirigami 2.4 as Kirigami
0010 
0011 import org.kcm.firewall 1.0 as Firewall
0012 
0013 Kirigami.FormLayout {
0014     id: root
0015     property var rule: null
0016     property alias sourceAddress: sourceAddress
0017     property alias destinationAddress: destinationAddress
0018     property alias destinationPort: destinationPort
0019     property alias sourcePort: sourcePort
0020     property alias policy: policy
0021     property alias incoming: incoming
0022 
0023     readonly property int maxComboboxWidth: Math.max(
0024                                                 policy.implicitWidth,
0025                                                 protocolCb.implicitWidth,
0026                                                 interfaceCb.implicitWidth,
0027                                                 loggingCb.implicitWidth)
0028 
0029     QQC2.ComboBox {
0030         id: policy
0031         Kirigami.FormData.label: i18n("Policy:")
0032         Layout.preferredWidth: root.maxComboboxWidth
0033         model: policyChoices
0034         textRole: "text"
0035         currentIndex: rule == null ? 0 : rule.policy == "" ? 0 : policyChoices.findIndex((policy) => policy.data == rule.policy)
0036         onActivated: index => {
0037             rule.policy = policyChoices[index].data;
0038         }
0039     }
0040 
0041     RowLayout {
0042         Kirigami.FormData.label: i18n("Direction:")
0043         QQC2.RadioButton {
0044             id: incoming
0045             text: i18n("Incoming")
0046             icon.name: "arrow-down"
0047             checked: rule.incoming
0048             onClicked: rule.incoming = true
0049         }
0050         QQC2.RadioButton {
0051             text: i18n("Outgoing")
0052             icon.name: "arrow-up"
0053             checked: !rule.incoming
0054             onClicked: rule.incoming = false
0055         }
0056     }
0057 
0058     RowLayout {
0059         Kirigami.FormData.label: i18n("IP Version:")
0060 
0061         QQC2.RadioButton {
0062             text: i18n("IPv4")
0063             checked: !rule.ipv6
0064             onClicked: rule.ipv6 = false;
0065         }
0066         QQC2.RadioButton {
0067             text: i18n("IPv6")
0068             checked: rule.ipv6
0069             onClicked: rule.ipv6 = true
0070         }
0071     }
0072 
0073     RowLayout {
0074         Kirigami.FormData.label: i18n("Source:")
0075 
0076         IpTextField {
0077             id: sourceAddress
0078             ipv6: rule.ipv6
0079             focus: true // default focus object
0080             text: rule.sourceAddress
0081             Layout.preferredWidth: root.maxComboboxWidth
0082             // NOTE onEditingFinished doesn't fire with non-acceptable / empty input
0083             onTextChanged: rule.sourceAddress = text
0084         }
0085         PortTextField{
0086             id: sourcePort
0087             Layout.preferredWidth: Math.round(root.maxComboboxWidth * 0.75)
0088             text: rule.sourcePort
0089             onTextChanged: rule.sourcePort = text
0090         }
0091     }
0092 
0093     RowLayout {
0094         Kirigami.FormData.label: i18n("Destination:")
0095 
0096         IpTextField {
0097             id: destinationAddress
0098             ipv6: rule.ipv6
0099             text: rule.destinationAddress
0100             Layout.preferredWidth: root.maxComboboxWidth
0101             onTextChanged: rule.destinationAddress = text
0102         }
0103         PortTextField {
0104             id: destinationPort
0105             Layout.preferredWidth: Math.round(root.maxComboboxWidth * 0.75)
0106             text: rule.destinationPort
0107             onTextChanged: rule.destinationPort = text
0108         }
0109     }
0110 
0111     QQC2.ComboBox {
0112         id: protocolCb
0113 
0114         Kirigami.FormData.label: i18n("Protocol:")
0115         Layout.preferredWidth: root.maxComboboxWidth
0116         model: ruleEdit.client.knownProtocols()
0117         currentIndex: rule.protocol
0118         onActivated: index => {
0119             rule.protocol = index;
0120         }
0121     }
0122     QQC2.ComboBox {
0123         id: interfaceCb
0124 
0125         Kirigami.FormData.label: i18n("Interface:")
0126         Layout.preferredWidth: root.maxComboboxWidth
0127         model: ruleEdit.client.knownInterfaces()
0128         currentIndex: rule.interface
0129         onActivated: index => {
0130             rule.interface = index;
0131         }
0132     }
0133 
0134     QQC2.ComboBox {
0135         id: loggingCb
0136 
0137         Kirigami.FormData.label: i18n("Logging:")
0138         Layout.preferredWidth: root.maxComboboxWidth
0139         model: ruleChoices
0140         textRole: "text"
0141         currentIndex: rule.logging == "" ? 0 : ruleChoices.findIndex((rules) => rules.data == rule.logging)
0142         onActivated: index => {
0143             rule.logging = ruleChoices[index].data;
0144         }
0145     }
0146 }