Warning, /network/neochat/src/qml/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-or-later OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigamiaddons.formcard as FormCard
0009 
0010 import org.kde.neochat
0011 import org.kde.neochat.config
0012 
0013 FormCard.FormCardPage {
0014     id: root
0015 
0016     title: i18nc("@title:window", "General")
0017 
0018     property int currentType
0019     property bool proxyConfigChanged: false
0020 
0021     FormCard.FormHeader {
0022         title: i18n("Network Proxy")
0023     }
0024     FormCard.FormCard {
0025         FormCard.FormRadioDelegate {
0026             text: i18n("System Default")
0027             checked: currentType === 0
0028             enabled: !Config.isProxyTypeImmutable
0029             onToggled: {
0030                 currentType = 0;
0031             }
0032         }
0033         FormCard.FormRadioDelegate {
0034             text: i18n("HTTP")
0035             checked: currentType === 1
0036             enabled: !Config.isProxyTypeImmutable
0037             onToggled: {
0038                 currentType = 1;
0039             }
0040         }
0041         FormCard.FormRadioDelegate {
0042             text: i18n("Socks5")
0043             checked: currentType === 2
0044             enabled: !Config.isProxyTypeImmutable
0045             onToggled: {
0046                 currentType = 2;
0047             }
0048         }
0049     }
0050 
0051     FormCard.FormHeader {
0052         title: i18n("Proxy Settings")
0053     }
0054     FormCard.FormCard {
0055         FormCard.FormTextFieldDelegate {
0056             id: hostField
0057             label: i18n("Host")
0058             text: Config.proxyHost
0059             inputMethodHints: Qt.ImhUrlCharactersOnly
0060             onEditingFinished: {
0061                 proxyConfigChanged = true;
0062             }
0063         }
0064         FormCard.FormSpinBoxDelegate {
0065             id: portField
0066             label: i18n("Port")
0067             value: Config.proxyPort
0068             from: 0
0069             to: 65536
0070             textFromValue: function (value, locale) {
0071                 return value; // it will add a thousands separator if we don't do this, not sure why
0072             }
0073             onValueChanged: {
0074                 proxyConfigChanged = true;
0075             }
0076         }
0077         FormCard.FormTextFieldDelegate {
0078             id: userField
0079             label: i18n("User")
0080             text: Config.proxyUser
0081             inputMethodHints: Qt.ImhUrlCharactersOnly
0082             onEditingFinished: {
0083                 proxyConfigChanged = true;
0084             }
0085         }
0086         FormCard.FormTextFieldDelegate {
0087             id: passwordField
0088             label: i18n("Password")
0089             text: Config.proxyPassword
0090             echoMode: TextInput.Password
0091             inputMethodHints: Qt.ImhUrlCharactersOnly
0092             onEditingFinished: {
0093                 proxyConfigChanged = true;
0094             }
0095         }
0096     }
0097 
0098     footer: QQC2.ToolBar {
0099         height: visible ? implicitHeight : 0
0100         contentItem: RowLayout {
0101             Item {
0102                 Layout.fillWidth: true
0103             }
0104 
0105             QQC2.Button {
0106                 text: i18n("Apply")
0107                 enabled: currentType !== Config.proxyType || proxyConfigChanged
0108                 onClicked: {
0109                     Config.proxyType = currentType;
0110                     Config.proxyHost = hostField.text;
0111                     Config.proxyPort = portField.value;
0112                     Config.proxyUser = userField.text;
0113                     Config.proxyPassword = passwordField.text;
0114                     Config.save();
0115                     proxyConfigChanged = false;
0116                     ProxyController.setApplicationProxy();
0117                 }
0118             }
0119         }
0120     }
0121 
0122     Component.onCompleted: {
0123         currentType = Config.proxyType;
0124     }
0125 }