Warning, /network/tokodon/src/content/ui/Settings/NetworkProxyPage.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls 2 as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami 2 as Kirigami
0009 import org.kde.kirigamiaddons.formcard 1 as FormCard
0010 
0011 import org.kde.tokodon
0012 import org.kde.tokodon.private
0013 
0014 FormCard.FormCardPage {
0015     title: i18nc("@title:window", "Network Proxy")
0016     property int currentType
0017     property bool proxyConfigChanged: false
0018 
0019     FormCard.FormCard {
0020         Layout.topMargin: Kirigami.Units.largeSpacing
0021 
0022         FormCard.FormRadioDelegate {
0023             id: systemDefault
0024             text: i18n("System Default")
0025             checked: currentType === 0
0026             enabled: !Config.isProxyTypeImmutable
0027             onToggled: {
0028                 currentType = 0
0029             }
0030         }
0031 
0032         FormCard.FormDelegateSeparator { below: systemDefault; above: http }
0033 
0034         FormCard.FormRadioDelegate {
0035             id: http
0036             text: i18n("HTTP")
0037             checked: currentType === 1
0038             enabled: !Config.isProxyTypeImmutable
0039             onToggled: {
0040                 currentType = 1
0041             }
0042         }
0043 
0044         FormCard.FormDelegateSeparator { below: http; above: socks5 }
0045 
0046         FormCard.FormRadioDelegate {
0047             id: socks5
0048             text: i18n("Socks5")
0049             checked: currentType === 2
0050             enabled: !Config.isProxyTypeImmutable
0051             onToggled: {
0052                 currentType = 2
0053             }
0054         }
0055     }
0056 
0057     FormCard.FormHeader {
0058         title: i18n("Proxy Settings")
0059     }
0060 
0061     FormCard.FormCard {
0062         FormCard.FormTextFieldDelegate {
0063             id: hostField
0064             label: i18n("Host")
0065             text: Config.proxyHost
0066             inputMethodHints: Qt.ImhUrlCharactersOnly
0067             onEditingFinished: {
0068                 proxyConfigChanged = true
0069             }
0070         }
0071         FormCard.FormDelegateSeparator { below: hostField; above: portField }
0072         // we probably still need a FormSpinBoxDelegate
0073         FormCard.AbstractFormDelegate {
0074             Layout.fillWidth: true
0075             contentItem: RowLayout {
0076                 QQC2.Label {
0077                     text: i18n("Port")
0078                     Layout.fillWidth: true
0079                 }
0080                 QQC2.SpinBox {
0081                     id: portField
0082                     value: Config.proxyPort
0083                     from: 0
0084                     to: 65536
0085                     validator: IntValidator {bottom: portField.from; top: portField.to}
0086                     textFromValue: function(value, locale) {
0087                         return value // it will add a thousands separator if we don't do this, not sure why
0088                     }
0089                     onValueChanged: {
0090                         proxyConfigChanged = true
0091                     }
0092                 }
0093             }
0094         }
0095         FormCard.FormDelegateSeparator { below: portField; above: userField }
0096         FormCard.FormTextFieldDelegate {
0097             id: userField
0098             label: i18n("User")
0099             text: Config.proxyUser
0100             inputMethodHints: Qt.ImhUrlCharactersOnly
0101             onEditingFinished: {
0102                 proxyConfigChanged = true
0103             }
0104         }
0105         FormCard.FormDelegateSeparator { below: userField; above: passwordField }
0106         FormCard.FormTextFieldDelegate {
0107             id: passwordField
0108             label: i18n("Password")
0109             text: Config.proxyPassword
0110             echoMode: TextInput.Password
0111             inputMethodHints: Qt.ImhUrlCharactersOnly
0112             onEditingFinished: {
0113                 proxyConfigChanged = true
0114             }
0115         }
0116     }
0117 
0118     footer: QQC2.ToolBar {
0119         height: visible ? implicitHeight : 0
0120         contentItem: RowLayout {
0121             Item {
0122                 Layout.fillWidth: true
0123             }
0124 
0125             QQC2.Button  {
0126                 text: i18n("Apply")
0127                 enabled: currentType !== Config.proxyType || proxyConfigChanged
0128                 onClicked: {
0129                     Config.proxyType = currentType
0130                     Config.proxyHost = hostField.text
0131                     Config.proxyPort = portField.value
0132                     Config.proxyUser = userField.text
0133                     Config.proxyPassword = passwordField.text
0134                     Config.save()
0135                     proxyConfigChanged = false
0136                     Controller.setApplicationProxy()
0137                 }
0138             }
0139         }
0140     }
0141 
0142     Component.onCompleted: {
0143         currentType = Config.proxyType
0144     }
0145 }