From 9a72f98855b2ebf51e0c39f011ad087c5a37915b Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 24 Aug 2022 16:01:50 +0200 Subject: [PATCH] qml: add server and proxy config dialogs --- electrum/gui/qml/components/NetworkStats.qml | 47 ++++++++++++++++++- .../controls/NetworkStatusIndicator.qml | 2 +- .../qml/components/controls/ProxyConfig.qml | 23 +++++++++ .../qml/components/controls/ServerConfig.qml | 6 +++ .../qml/components/wizard/WCProxyConfig.qml | 14 +----- 5 files changed, 77 insertions(+), 15 deletions(-) diff --git a/electrum/gui/qml/components/NetworkStats.qml b/electrum/gui/qml/components/NetworkStats.qml index a486bcaab..d3c7ee669 100644 --- a/electrum/gui/qml/components/NetworkStats.qml +++ b/electrum/gui/qml/components/NetworkStats.qml @@ -1,13 +1,58 @@ import QtQuick 2.6 import QtQuick.Layouts 1.0 -import QtQuick.Controls 2.0 +import QtQuick.Controls 2.3 import QtQuick.Controls.Material 2.0 +import QtQml 2.6 import "controls" Pane { + id: root + property string title: qsTr('Network') + property QtObject menu: Menu { + id: menu + MenuItem { + icon.color: 'transparent' + action: Action { + text: qsTr('Server Settings'); + onTriggered: menu.openPage(sc_comp); + enabled: Daemon.currentWallet + icon.source: '../../icons/network.png' + } + } + MenuItem { + icon.color: 'transparent' + action: Action { + text: qsTr('Proxy Settings'); + onTriggered: menu.openPage(pc_comp); + enabled: Daemon.currentWallet + icon.source: '../../icons/status_connected_proxy.png' + } + } + + function openPage(comp) { + var dialog = comp.createObject(root) + dialog.open() + currentIndex = -1 + } + } + + Component { + id: sc_comp + ServerConfigDialog { + onClosed: destroy() + } + } + + Component { + id: pc_comp + ProxyConfigDialog { + onClosed: destroy() + } + } + GridLayout { columns: 2 diff --git a/electrum/gui/qml/components/controls/NetworkStatusIndicator.qml b/electrum/gui/qml/components/controls/NetworkStatusIndicator.qml index b82ff5672..5e7bbf95a 100644 --- a/electrum/gui/qml/components/controls/NetworkStatusIndicator.qml +++ b/electrum/gui/qml/components/controls/NetworkStatusIndicator.qml @@ -10,7 +10,7 @@ Image { property bool lagging: connected && Network.isLagging property bool fork: connected && Network.chaintips > 1 property bool syncing: connected && Daemon.currentWallet && Daemon.currentWallet.synchronizing - property bool proxy: connected && Network.proxy.mode + property bool proxy: connected && 'mode' in Network.proxy && Network.proxy.mode // ?: in order to keep this a binding.. source: !connected diff --git a/electrum/gui/qml/components/controls/ProxyConfig.qml b/electrum/gui/qml/components/controls/ProxyConfig.qml index b890a9946..4e61c716f 100644 --- a/electrum/gui/qml/components/controls/ProxyConfig.qml +++ b/electrum/gui/qml/components/controls/ProxyConfig.qml @@ -3,6 +3,8 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls 2.1 Item { + id: pc + property alias proxy_enabled: proxy_enabled_cb.checked property alias proxy_type: proxytype.currentIndex property alias proxy_address: address.text @@ -12,8 +14,29 @@ Item { property var proxy_types: ['TOR', 'SOCKS5', 'SOCKS4'] + height: rootLayout.height + + function toProxyDict() { + var p = {} + p['enabled'] = pc.proxy_enabled + if (pc.proxy_enabled) { + var type = pc.proxy_types[pc.proxy_type].toLowerCase() + if (type == 'tor') + type = 'socks5' + p['mode'] = type + p['host'] = pc.proxy_address + p['port'] = pc.proxy_port + p['user'] = pc.username + p['password'] = pc.password + } + return p + } + ColumnLayout { + id: rootLayout + width: parent.width + spacing: constants.paddingLarge Label { text: qsTr('Proxy settings') diff --git a/electrum/gui/qml/components/controls/ServerConfig.qml b/electrum/gui/qml/components/controls/ServerConfig.qml index fde71089d..4c0102d67 100644 --- a/electrum/gui/qml/components/controls/ServerConfig.qml +++ b/electrum/gui/qml/components/controls/ServerConfig.qml @@ -6,8 +6,13 @@ Item { property alias auto_server: auto_server_cb.checked property alias address: address_tf.text + height: rootLayout.height + ColumnLayout { + id: rootLayout + width: parent.width + spacing: constants.paddingLarge Label { text: qsTr('Server settings') @@ -31,6 +36,7 @@ Item { TextField { id: address_tf enabled: !auto_server_cb.checked + Layout.fillWidth: true } } } diff --git a/electrum/gui/qml/components/wizard/WCProxyConfig.qml b/electrum/gui/qml/components/wizard/WCProxyConfig.qml index 0703c6f83..ddc0fc60d 100644 --- a/electrum/gui/qml/components/wizard/WCProxyConfig.qml +++ b/electrum/gui/qml/components/wizard/WCProxyConfig.qml @@ -4,19 +4,7 @@ WizardComponent { valid: true onAccept: { - var p = {} - p['enabled'] = pc.proxy_enabled - if (pc.proxy_enabled) { - var type = pc.proxy_types[pc.proxy_type].toLowerCase() - if (type == 'tor') - type = 'socks5' - p['mode'] = type - p['host'] = pc.proxy_address - p['port'] = pc.proxy_port - p['user'] = pc.username - p['password'] = pc.password - } - wizard_data['proxy'] = p + wizard_data['proxy'] = pc.toProxyDict() } ProxyConfig {