refactor OpenVpnSettings page for correct focus

This commit is contained in:
Cyril Anisimov 2025-06-16 01:10:21 +02:00
parent 09e3f39122
commit 4a8877c2ed

View file

@ -42,15 +42,9 @@ PageType {
enabled: ServersModel.isProcessedServerHasWriteAccess()
model: OpenVpnConfigModel
delegate: ColumnLayout {
header: ColumnLayout {
width: listView.width
property alias vpnAddressSubnetTextField: vpnAddressSubnetTextField
spacing: 0
BaseHeaderType {
Layout.fillWidth: true
Layout.leftMargin: 16
@ -58,6 +52,28 @@ PageType {
headerText: qsTr("OpenVPN settings")
}
}
model: ListModel {
ListElement { type: "subnetHeader" }
ListElement { type: "networkProtocolText" }
ListElement { type: "protoSelector" }
ListElement { type: "portTextField" }
ListElement { type: "encryptionSection" }
ListElement { type: "checkboxSection" }
ListElement { type: "clientCommands" }
ListElement { type: "serverCommands" }
}
delegate: DelegateChooser {
role: "type"
DelegateChoice {
// property alias vpnAddressSubnetTextField: vpnAddressSubnetTextField
roleValue: "subnetHeader"
ColumnLayout {
width: listView.width
TextFieldWithHeaderType {
id: vpnAddressSubnetTextField
@ -68,14 +84,21 @@ PageType {
Layout.rightMargin: 16
headerText: qsTr("VPN address subnet")
textField.text: subnetAddress
textField.text: OpenVpnConfigModel.subnetAddress
textField.onEditingFinished: {
if (textField.text !== subnetAddress) {
subnetAddress = textField.text
if (textField.text !== OpenVpnConfigModel.subnetAddress) {
OpenVpnConfigModel.subnetAddress = textField.text
}
}
}
}
}
DelegateChoice {
roleValue: "networkProtocolText"
ColumnLayout {
width: listView.width
ParagraphTextType {
Layout.fillWidth: true
@ -85,29 +108,44 @@ PageType {
text: qsTr("Network protocol")
}
}
}
DelegateChoice {
roleValue: "protoSelector"
ColumnLayout {
width: listView.width
TransportProtoSelector {
id: transportProtoSelector
Layout.fillWidth: true
Layout.topMargin: 16
Layout.leftMargin: 16
Layout.rightMargin: 16
rootWidth: root.width
enabled: isTransportProtoEditable
enabled: OpenVpnConfigModel.isTransportProtoEditable
currentIndex: {
return transportProto === "tcp" ? 1 : 0
return OpenVpnConfigModel.transportProto === "tcp" ? 1 : 0
}
onCurrentIndexChanged: {
if (transportProto === "tcp" && currentIndex === 0) {
transportProto = "udp"
} else if (transportProto === "udp" && currentIndex === 1) {
transportProto = "tcp"
if (OpenVpnConfigModel.transportProto === "tcp" && currentIndex === 0) {
OpenVpnConfigModel.transportProto = "udp"
} else if (OpenVpnConfigModel.transportProto === "udp" && currentIndex === 1) {
OpenVpnConfigModel.transportProto = "tcp"
}
}
}
}
}
DelegateChoice {
roleValue: "portTextField"
ColumnLayout {
width: listView.width
TextFieldWithHeaderType {
id: portTextField
@ -117,19 +155,26 @@ PageType {
Layout.leftMargin: 16
Layout.rightMargin: 16
enabled: isPortEditable
enabled: OpenVpnConfigModel.isPortEditable
headerText: qsTr("Port")
textField.text: port
textField.text: OpenVpnConfigModel.port
textField.maximumLength: 5
textField.validator: IntValidator { bottom: 1; top: 65535 }
textField.onEditingFinished: {
if (textField.text !== port) {
port = textField.text
if (textField.text !== OpenVpnConfigModel.port) {
OpenVpnConfigModel.port = textField.text
}
}
}
}
}
DelegateChoice {
roleValue: "encryptionSection"
ColumnLayout {
width: listView.width
SwitcherType {
id: autoNegotiateEncryprionSwitcher
@ -140,17 +185,18 @@ PageType {
Layout.rightMargin: 16
text: qsTr("Auto-negotiate encryption")
checked: autoNegotiateEncryprion
checked: OpenVpnConfigModel.autoNegotiateEncryption
onCheckedChanged: {
if (checked !== autoNegotiateEncryprion) {
autoNegotiateEncryprion = checked
if (checked !== OpenVpnConfigModel.autoNegotiateEncryprion) {
OpenVpnConfigModel.autoNegotiateEncryprion = checked
}
}
}
DropDownType {
id: hashDropDown
Layout.fillWidth: true
Layout.topMargin: 20
Layout.leftMargin: 16
@ -183,12 +229,12 @@ PageType {
clickedFunction: function() {
hashDropDown.text = selectedText
hash = hashDropDown.text
OpenVpnConfigModel.hash = hashDropDown.text
hashDropDown.closeTriggered()
}
Component.onCompleted: {
hashDropDown.text = hash
hashDropDown.text = OpenVpnConfigModel.hash
for (var i = 0; i < hashListView.model.count; i++) {
if (hashListView.model.get(i).name === hashDropDown.text) {
@ -201,6 +247,7 @@ PageType {
DropDownType {
id: cipherDropDown
Layout.fillWidth: true
Layout.topMargin: 16
Layout.leftMargin: 16
@ -233,12 +280,12 @@ PageType {
clickedFunction: function() {
cipherDropDown.text = selectedText
cipher = cipherDropDown.text
OpenVpnConfigModel.cipher = cipherDropDown.text
cipherDropDown.closeTriggered()
}
Component.onCompleted: {
cipherDropDown.text = cipher
cipherDropDown.text = OpenVpnConfigModel.cipher
for (var i = 0; i < cipherListView.model.count; i++) {
if (cipherListView.model.get(i).name === cipherDropDown.text) {
@ -248,9 +295,17 @@ PageType {
}
}
}
}
}
DelegateChoice {
roleValue: "checkboxSection"
ColumnLayout {
width: listView.width
Rectangle {
id: contentRect
Layout.fillWidth: true
Layout.topMargin: 32
Layout.leftMargin: 16
@ -263,17 +318,19 @@ PageType {
id: checkboxLayout
anchors.fill: parent
CheckBoxType {
id: tlsAuthCheckBox
Layout.fillWidth: true
text: qsTr("TLS auth")
checked: tlsAuth
checked: OpenVpnConfigModel.tlsAuth
onCheckedChanged: {
if (checked !== tlsAuth) {
if (checked !== OpenVpnConfigModel.tlsAuth) {
console.log("tlsAuth changed to: " + checked)
tlsAuth = checked
OpenVpnConfigModel.tlsAuth = checked
}
}
}
@ -282,40 +339,52 @@ PageType {
CheckBoxType {
id: blockDnsCheckBox
Layout.fillWidth: true
text: qsTr("Block DNS requests outside of VPN")
checked: blockDns
checked: OpenVpnConfigModel.blockDns
onCheckedChanged: {
if (checked !== blockDns) {
blockDns = checked
if (checked !== OpenVpnConfigModel.blockDns) {
OpenVpnConfigModel.blockDns = checked
}
}
}
}
}
}
}
DelegateChoice {
roleValue: "clientCommands"
ColumnLayout {
width: listView.width
SwitcherType {
id: additionalClientCommandsSwitcher
Layout.fillWidth: true
Layout.topMargin: 32
Layout.leftMargin: 16
Layout.rightMargin: 16
checked: additionalClientCommands !== ""
checked: OpenVpnConfigModel.additionalClientCommands !== ""
text: qsTr("Additional client configuration commands")
onCheckedChanged: {
if (!checked) {
additionalClientCommands = ""
OpenVpnConfigModel.additionalClientCommands = ""
}
// listView.positionViewAtIndex(index, ListView.Beginning)
}
}
TextAreaType {
id: additionalClientCommandsTextArea
Layout.fillWidth: true
Layout.topMargin: 16
Layout.leftMargin: 16
@ -323,36 +392,46 @@ PageType {
visible: additionalClientCommandsSwitcher.checked
textAreaText: additionalClientCommands
textAreaText: OpenVpnConfigModel.additionalClientCommands
placeholderText: qsTr("Commands:")
textArea.onEditingFinished: {
if (additionalClientCommands !== textAreaText) {
additionalClientCommands = textAreaText
if (OpenVpnConfigModel.additionalClientCommands !== textAreaText) {
OpenVpnConfigModel.additionalClientCommands = textAreaText
}
}
}
}
}
DelegateChoice {
roleValue: "serverCommands"
ColumnLayout {
width: listView.width
SwitcherType {
id: additionalServerCommandsSwitcher
Layout.fillWidth: true
Layout.topMargin: 16
Layout.leftMargin: 16
Layout.rightMargin: 16
checked: additionalServerCommands !== ""
checked: OpenVpnConfigModel.additionalServerCommands !== ""
text: qsTr("Additional server configuration commands")
onCheckedChanged: {
if (!checked) {
additionalServerCommands = ""
OpenVpnConfigModel.additionalServerCommands = ""
}
// listView.positionViewAtIndex(index, ListView.Beginning)
}
}
TextAreaType {
id: additionalServerCommandsTextArea
Layout.fillWidth: true
Layout.topMargin: 16
Layout.leftMargin: 16
@ -360,15 +439,21 @@ PageType {
visible: additionalServerCommandsSwitcher.checked
textAreaText: additionalServerCommands
textAreaText: OpenVpnConfigModel.additionalServerCommands
placeholderText: qsTr("Commands:")
textArea.onEditingFinished: {
if (additionalServerCommands !== textAreaText) {
additionalServerCommands = textAreaText
if (OpenVpnConfigModel.additionalServerCommands !== textAreaText) {
OpenVpnConfigModel.additionalServerCommands = textAreaText
}
}
}
}
}
}
footer: ColumnLayout {
width: listView.width
BasicButtonType {
id: saveRestartButton