qml: refactor proxy options to map, remove explicit TOR option
This commit is contained in:
@@ -58,7 +58,6 @@ ElDialog {
|
|||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
var p = Network.proxy
|
var p = Network.proxy
|
||||||
console.log(JSON.stringify(p))
|
|
||||||
|
|
||||||
if ('mode' in p) {
|
if ('mode' in p) {
|
||||||
proxyconfig.proxy_enabled = true
|
proxyconfig.proxy_enabled = true
|
||||||
@@ -66,10 +65,9 @@ ElDialog {
|
|||||||
proxyconfig.proxy_port = p['port']
|
proxyconfig.proxy_port = p['port']
|
||||||
proxyconfig.username = p['user']
|
proxyconfig.username = p['user']
|
||||||
proxyconfig.password = p['password']
|
proxyconfig.password = p['password']
|
||||||
if (p['mode'] == 'socks5' && p['port'] == 9050)
|
proxyconfig.proxy_type = proxyconfig.proxy_types.map(function(x) {
|
||||||
p['mode'] = 'tor'
|
return x.value
|
||||||
proxyconfig.proxy_type = proxyconfig.proxy_types.indexOf(p['mode'].toUpperCase())
|
}).indexOf(p['mode'])
|
||||||
console.log('proxy type: ' + proxyconfig.proxy_type)
|
|
||||||
} else {
|
} else {
|
||||||
proxyconfig.proxy_enabled = false
|
proxyconfig.proxy_enabled = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import QtQuick.Controls 2.1
|
|||||||
Item {
|
Item {
|
||||||
id: pc
|
id: pc
|
||||||
|
|
||||||
|
implicitHeight: rootLayout.height
|
||||||
|
|
||||||
property alias proxy_enabled: proxy_enabled_cb.checked
|
property alias proxy_enabled: proxy_enabled_cb.checked
|
||||||
property alias proxy_type: proxytype.currentIndex
|
property alias proxy_type: proxytype.currentIndex
|
||||||
property alias proxy_address: address.text
|
property alias proxy_address: address.text
|
||||||
@@ -12,17 +14,16 @@ Item {
|
|||||||
property alias username: username_tf.text
|
property alias username: username_tf.text
|
||||||
property alias password: password_tf.text
|
property alias password: password_tf.text
|
||||||
|
|
||||||
property var proxy_types: ['TOR', 'SOCKS5', 'SOCKS4']
|
property var proxy_type_map: [
|
||||||
|
{ text: qsTr('SOCKS5/TOR'), value: 'socks5' },
|
||||||
height: rootLayout.height
|
{ text: qsTr('SOCKS4'), value: 'socks4' }
|
||||||
|
]
|
||||||
|
|
||||||
function toProxyDict() {
|
function toProxyDict() {
|
||||||
var p = {}
|
var p = {}
|
||||||
p['enabled'] = pc.proxy_enabled
|
p['enabled'] = pc.proxy_enabled
|
||||||
if (pc.proxy_enabled) {
|
if (pc.proxy_enabled) {
|
||||||
var type = pc.proxy_types[pc.proxy_type].toLowerCase()
|
var type = proxy_type_map[pc.proxy_type]['value']
|
||||||
if (type == 'tor')
|
|
||||||
type = 'socks5'
|
|
||||||
p['mode'] = type
|
p['mode'] = type
|
||||||
p['host'] = pc.proxy_address
|
p['host'] = pc.proxy_address
|
||||||
p['port'] = pc.proxy_port
|
p['port'] = pc.proxy_port
|
||||||
@@ -43,14 +44,20 @@ Item {
|
|||||||
text: qsTr('Enable Proxy')
|
text: qsTr('Enable Proxy')
|
||||||
}
|
}
|
||||||
|
|
||||||
ComboBox {
|
ElComboBox {
|
||||||
id: proxytype
|
id: proxytype
|
||||||
enabled: proxy_enabled_cb.checked
|
enabled: proxy_enabled_cb.checked
|
||||||
model: proxy_types
|
|
||||||
|
textRole: 'text'
|
||||||
|
valueRole: 'value'
|
||||||
|
model: proxy_type_map
|
||||||
|
|
||||||
onCurrentIndexChanged: {
|
onCurrentIndexChanged: {
|
||||||
if (currentIndex == 0) {
|
if (currentIndex == 0) {
|
||||||
address.text = "127.0.0.1"
|
if (address.text == '' || port.text == '') {
|
||||||
port.text = "9050"
|
address.text = "127.0.0.1"
|
||||||
|
port.text = "9050"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +73,7 @@ Item {
|
|||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: address
|
id: address
|
||||||
enabled: proxytype.enabled && proxytype.currentIndex > 0
|
enabled: proxy_enabled_cb.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
@@ -76,7 +83,7 @@ Item {
|
|||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: port
|
id: port
|
||||||
enabled: proxytype.enabled && proxytype.currentIndex > 0
|
enabled: proxy_enabled_cb.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
@@ -86,7 +93,7 @@ Item {
|
|||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
id: username_tf
|
id: username_tf
|
||||||
enabled: proxytype.enabled && proxytype.currentIndex > 0
|
enabled: proxy_enabled_cb.checked
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
@@ -96,7 +103,7 @@ Item {
|
|||||||
|
|
||||||
PasswordField {
|
PasswordField {
|
||||||
id: password_tf
|
id: password_tf
|
||||||
enabled: proxytype.enabled && proxytype.currentIndex > 0
|
enabled: proxy_enabled_cb.checked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user