From 385c5b3405f46f292e176174dd00f63b41eb3cf7 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 9 Nov 2024 11:21:14 -0500 Subject: [PATCH] Update network proxy page with the improved version from Tokodon This functions the same, but looks a bit nicer. (cherry picked from commit c2380fb8df664c398951e154a2409c16c81fc693) --- src/settings/NetworkProxyPage.qml | 90 +++++++++++++++++++------------ 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/src/settings/NetworkProxyPage.qml b/src/settings/NetworkProxyPage.qml index 3095d4cae..2b2aced2b 100644 --- a/src/settings/NetworkProxyPage.qml +++ b/src/settings/NetworkProxyPage.qml @@ -1,56 +1,66 @@ // SPDX-FileCopyrightText: 2022 Gary Wang -// 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.Controls as QQC2 import QtQuick.Layouts +import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat FormCard.FormCardPage { - id: root - title: i18nc("@title:window", "Proxy") - property int currentType property bool proxyConfigChanged: false - FormCard.FormHeader { - title: i18n("Network Proxy") - } FormCard.FormCard { + Layout.topMargin: Kirigami.Units.largeSpacing + FormCard.FormRadioDelegate { + id: systemDefault text: i18n("System Default") checked: currentType === 0 enabled: !NeoChatConfig.isProxyTypeImmutable onToggled: { - currentType = 0; + currentType = 0 } } + + FormCard.FormDelegateSeparator { below: systemDefault; above: noProxy } + FormCard.FormRadioDelegate { + id:noProxy text: i18n("No Proxy") checked: currentType === 3 - enabled: !NeoChatConfig.isProxyTypeImmutable + enabled: !Config.isProxyTypeImmutable onToggled: { currentType = 3; } } + + FormCard.FormDelegateSeparator { below: noProxy; above: http } + FormCard.FormRadioDelegate { + id: http text: i18n("HTTP") checked: currentType === 1 enabled: !NeoChatConfig.isProxyTypeImmutable onToggled: { - currentType = 1; + currentType = 1 } } + + FormCard.FormDelegateSeparator { below: http; above: socks5 } + FormCard.FormRadioDelegate { + id: socks5 text: i18n("Socks5") checked: currentType === 2 enabled: !NeoChatConfig.isProxyTypeImmutable onToggled: { - currentType = 2; + currentType = 2 } } } @@ -58,47 +68,55 @@ FormCard.FormCardPage { FormCard.FormHeader { title: i18n("Proxy Settings") } + FormCard.FormCard { + // It makes no sense to configure proxy settings for "System Default" and "No Proxy" + enabled: currentType !== 0 && currentType !== 3 + FormCard.FormTextFieldDelegate { id: hostField label: i18n("Host") text: NeoChatConfig.proxyHost inputMethodHints: Qt.ImhUrlCharactersOnly onEditingFinished: { - proxyConfigChanged = true; + proxyConfigChanged = true } } - - FormCard.FormDelegateSeparator {} - - FormCard.FormSpinBoxDelegate { - id: portField - label: i18n("Port") - value: NeoChatConfig.proxyPort - from: 0 - to: 65536 - 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: hostField; above: portField } + // we probably still need a FormSpinBoxDelegate + FormCard.AbstractFormDelegate { + Layout.fillWidth: true + contentItem: RowLayout { + QQC2.Label { + text: i18n("Port") + Layout.fillWidth: true + } + QQC2.SpinBox { + id: portField + value: NeoChatConfig.proxyPort + from: 0 + 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 {} - + FormCard.FormDelegateSeparator { below: portField; above: userField } FormCard.FormTextFieldDelegate { id: userField label: i18n("User") text: NeoChatConfig.proxyUser inputMethodHints: Qt.ImhUrlCharactersOnly onEditingFinished: { - proxyConfigChanged = true; + proxyConfigChanged = true } } - - FormCard.FormDelegateSeparator {} - + FormCard.FormDelegateSeparator { below: userField; above: passwordField } FormCard.FormTextFieldDelegate { id: passwordField label: i18n("Password") @@ -106,7 +124,7 @@ FormCard.FormCardPage { echoMode: TextInput.Password inputMethodHints: Qt.ImhUrlCharactersOnly onEditingFinished: { - proxyConfigChanged = true; + proxyConfigChanged = true } } } @@ -118,8 +136,9 @@ FormCard.FormCardPage { Layout.fillWidth: true } - QQC2.Button { + QQC2.Button { text: i18n("Apply") + icon.name: "dialog-ok-apply-symbolic" enabled: currentType !== NeoChatConfig.proxyType || proxyConfigChanged onClicked: { NeoChatConfig.proxyType = currentType; @@ -136,6 +155,7 @@ FormCard.FormCardPage { } Component.onCompleted: { + proxyConfigChanged = false; // Make doubly sure that stupid bindings haven't turned this on currentType = NeoChatConfig.proxyType; } }