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