Update network proxy page with the improved version from Tokodon

This functions the same, but looks a bit nicer.
This commit is contained in:
Joshua Goins
2024-11-09 11:21:14 -05:00
parent f31c644b13
commit c2380fb8df

View File

@@ -1,56 +1,66 @@
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com> // SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later OR LicenseRef-KDE-Accepted-LGPL // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick import QtQuick
import QtQuick.Controls as QQC2 import QtQuick.Controls as QQC2
import QtQuick.Layouts import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.neochat import org.kde.neochat
FormCard.FormCardPage { FormCard.FormCardPage {
id: root
title: i18nc("@title:window", "Proxy") title: i18nc("@title:window", "Proxy")
property int currentType property int currentType
property bool proxyConfigChanged: false property bool proxyConfigChanged: false
FormCard.FormHeader {
title: i18n("Network Proxy")
}
FormCard.FormCard { FormCard.FormCard {
Layout.topMargin: Kirigami.Units.largeSpacing
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
id: systemDefault
text: i18n("System Default") text: i18n("System Default")
checked: currentType === 0 checked: currentType === 0
enabled: !NeoChatConfig.isProxyTypeImmutable enabled: !NeoChatConfig.isProxyTypeImmutable
onToggled: { onToggled: {
currentType = 0; currentType = 0
} }
} }
FormCard.FormDelegateSeparator { below: systemDefault; above: noProxy }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
id:noProxy
text: i18n("No Proxy") text: i18n("No Proxy")
checked: currentType === 3 checked: currentType === 3
enabled: !NeoChatConfig.isProxyTypeImmutable enabled: !Config.isProxyTypeImmutable
onToggled: { onToggled: {
currentType = 3; currentType = 3;
} }
} }
FormCard.FormDelegateSeparator { below: noProxy; above: http }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
id: http
text: i18n("HTTP") text: i18n("HTTP")
checked: currentType === 1 checked: currentType === 1
enabled: !NeoChatConfig.isProxyTypeImmutable enabled: !NeoChatConfig.isProxyTypeImmutable
onToggled: { onToggled: {
currentType = 1; currentType = 1
} }
} }
FormCard.FormDelegateSeparator { below: http; above: socks5 }
FormCard.FormRadioDelegate { FormCard.FormRadioDelegate {
id: socks5
text: i18n("Socks5") text: i18n("Socks5")
checked: currentType === 2 checked: currentType === 2
enabled: !NeoChatConfig.isProxyTypeImmutable enabled: !NeoChatConfig.isProxyTypeImmutable
onToggled: { onToggled: {
currentType = 2; currentType = 2
} }
} }
} }
@@ -58,47 +68,55 @@ FormCard.FormCardPage {
FormCard.FormHeader { FormCard.FormHeader {
title: i18n("Proxy Settings") title: i18n("Proxy Settings")
} }
FormCard.FormCard { FormCard.FormCard {
// It makes no sense to configure proxy settings for "System Default" and "No Proxy"
enabled: currentType !== 0 && currentType !== 3
FormCard.FormTextFieldDelegate { FormCard.FormTextFieldDelegate {
id: hostField id: hostField
label: i18n("Host") label: i18n("Host")
text: NeoChatConfig.proxyHost text: NeoChatConfig.proxyHost
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
onEditingFinished: { onEditingFinished: {
proxyConfigChanged = true; proxyConfigChanged = true
} }
} }
FormCard.FormDelegateSeparator { below: hostField; above: portField }
FormCard.FormDelegateSeparator {} // we probably still need a FormSpinBoxDelegate
FormCard.AbstractFormDelegate {
FormCard.FormSpinBoxDelegate { Layout.fillWidth: true
id: portField contentItem: RowLayout {
label: i18n("Port") QQC2.Label {
value: NeoChatConfig.proxyPort text: i18n("Port")
from: 0 Layout.fillWidth: true
to: 65536 }
textFromValue: function (value, locale) { QQC2.SpinBox {
return value; // it will add a thousands separator if we don't do this, not sure why id: portField
} value: NeoChatConfig.proxyPort
onValueChanged: { from: 0
proxyConfigChanged = true; to: 65536
validator: IntValidator {bottom: portField.from; top: portField.to}
textFromValue: function(value, locale) {
return value // it will add a thousands separator if we don't do this, not sure why
}
onValueChanged: {
proxyConfigChanged = true
}
}
} }
} }
FormCard.FormDelegateSeparator { below: portField; above: userField }
FormCard.FormDelegateSeparator {}
FormCard.FormTextFieldDelegate { FormCard.FormTextFieldDelegate {
id: userField id: userField
label: i18n("User") label: i18n("User")
text: NeoChatConfig.proxyUser text: NeoChatConfig.proxyUser
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
onEditingFinished: { onEditingFinished: {
proxyConfigChanged = true; proxyConfigChanged = true
} }
} }
FormCard.FormDelegateSeparator { below: userField; above: passwordField }
FormCard.FormDelegateSeparator {}
FormCard.FormTextFieldDelegate { FormCard.FormTextFieldDelegate {
id: passwordField id: passwordField
label: i18n("Password") label: i18n("Password")
@@ -106,7 +124,7 @@ FormCard.FormCardPage {
echoMode: TextInput.Password echoMode: TextInput.Password
inputMethodHints: Qt.ImhUrlCharactersOnly inputMethodHints: Qt.ImhUrlCharactersOnly
onEditingFinished: { onEditingFinished: {
proxyConfigChanged = true; proxyConfigChanged = true
} }
} }
} }
@@ -118,8 +136,9 @@ FormCard.FormCardPage {
Layout.fillWidth: true Layout.fillWidth: true
} }
QQC2.Button { QQC2.Button {
text: i18n("Apply") text: i18n("Apply")
icon.name: "dialog-ok-apply-symbolic"
enabled: currentType !== NeoChatConfig.proxyType || proxyConfigChanged enabled: currentType !== NeoChatConfig.proxyType || proxyConfigChanged
onClicked: { onClicked: {
NeoChatConfig.proxyType = currentType; NeoChatConfig.proxyType = currentType;
@@ -136,6 +155,7 @@ FormCard.FormCardPage {
} }
Component.onCompleted: { Component.onCompleted: {
proxyConfigChanged = false; // Make doubly sure that stupid bindings haven't turned this on
currentType = NeoChatConfig.proxyType; currentType = NeoChatConfig.proxyType;
} }
} }