From 15e2ed4f5823d80ddd584568e8ebcbb39e6b3abe Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 4 Oct 2022 19:47:29 +0200 Subject: [PATCH] rewrite server connect wizard to new wizard style 'last' property on WizardComponents is now queried from UI, not from the wizard. This allows the content of the WizardComponent itself to be taken into account. --- .../gui/qml/components/NewWalletWizard.qml | 4 +-- .../qml/components/ServerConnectWizard.qml | 28 +++---------------- .../qml/components/wizard/WCAutoConnect.qml | 7 ++--- electrum/gui/qml/components/wizard/Wizard.qml | 5 ++-- .../qml/components/wizard/WizardComponent.qml | 15 ++++++++++ electrum/gui/qml/qeapp.py | 3 +- electrum/gui/qml/qedaemon.py | 11 +++++++- electrum/gui/qml/qewizard.py | 16 ++++++++++- electrum/gui/wizard.py | 24 ++++++++++++++++ 9 files changed, 76 insertions(+), 37 deletions(-) diff --git a/electrum/gui/qml/components/NewWalletWizard.qml b/electrum/gui/qml/components/NewWalletWizard.qml index 1f47eb7af..a391a2525 100644 --- a/electrum/gui/qml/components/NewWalletWizard.qml +++ b/electrum/gui/qml/components/NewWalletWizard.qml @@ -15,9 +15,7 @@ Wizard { property string path - enter: null // disable transition - - property QtObject wiz: Daemon.newWalletWizard + wiz: Daemon.newWalletWizard Component.onCompleted: { var view = wiz.start_wizard() diff --git a/electrum/gui/qml/components/ServerConnectWizard.qml b/electrum/gui/qml/components/ServerConnectWizard.qml index 0f80d47c7..f126a831f 100644 --- a/electrum/gui/qml/components/ServerConnectWizard.qml +++ b/electrum/gui/qml/components/ServerConnectWizard.qml @@ -11,6 +11,8 @@ Wizard { enter: null // disable transition + wiz: Daemon.serverConnectWizard + onAccepted: { var proxy = wizard_data['proxy'] if (proxy && proxy['enabled'] == true) { @@ -25,29 +27,7 @@ Wizard { } Component.onCompleted: { - var start = _loadNextComponent(autoconnect) - start.next.connect(function() {autoconnectDone()}) - } - - function autoconnectDone() { - var page = _loadNextComponent(proxyconfig, wizard_data) - page.next.connect(function() {proxyconfigDone()}) - } - - function proxyconfigDone() { - var page = _loadNextComponent(serverconfig, wizard_data) - } - - property Component autoconnect: Component { - WCAutoConnect {} - } - - property Component proxyconfig: Component { - WCProxyConfig {} + var view = wiz.start_wizard() + _loadNextComponent(view) } - - property Component serverconfig: Component { - WCServerConfig {} - } - } diff --git a/electrum/gui/qml/components/wizard/WCAutoConnect.qml b/electrum/gui/qml/components/wizard/WCAutoConnect.qml index 9b15d533c..51c4625a7 100644 --- a/electrum/gui/qml/components/wizard/WCAutoConnect.qml +++ b/electrum/gui/qml/components/wizard/WCAutoConnect.qml @@ -1,14 +1,12 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls 2.1 -import ".." import "../controls" WizardComponent { valid: true - last: serverconnectgroup.checkedButton.connecttype === 'auto' - onAccept: { + function apply() { wizard_data['autoconnect'] = serverconnectgroup.checkedButton.connecttype === 'auto' } @@ -22,17 +20,18 @@ WizardComponent { ButtonGroup { id: serverconnectgroup + onCheckedButtonChanged: checkIsLast() } RadioButton { ButtonGroup.group: serverconnectgroup property string connecttype: 'auto' text: qsTr('Auto connect') + checked: true } RadioButton { ButtonGroup.group: serverconnectgroup property string connecttype: 'manual' - checked: true text: qsTr('Select servers manually') } diff --git a/electrum/gui/qml/components/wizard/Wizard.qml b/electrum/gui/qml/components/wizard/Wizard.qml index 73874590a..6a80d1fb4 100644 --- a/electrum/gui/qml/components/wizard/Wizard.qml +++ b/electrum/gui/qml/components/wizard/Wizard.qml @@ -11,7 +11,8 @@ Dialog { height: parent.height property var wizard_data - property alias pages : pages + property alias pages: pages + property QtObject wiz function _setWizardData(wdata) { wizard_data = {} @@ -49,7 +50,6 @@ Dialog { if (newview.view) { console.log('next view: ' + newview.view) var newpage = _loadNextComponent(newview.view, newview.wizard_data) - newpage.last = wiz.isLast(newview.wizard_data) } else { console.log('END') } @@ -57,7 +57,6 @@ Dialog { page.prev.connect(function() { var wdata = wiz.prev() console.log('prev view data: ' + JSON.stringify(wdata)) - page.last = wiz.isLast(wdata) }) Object.assign(page.wizard_data, wdata) // deep copy page.ready = true // signal page it can access wizard_data diff --git a/electrum/gui/qml/components/wizard/WizardComponent.qml b/electrum/gui/qml/components/wizard/WizardComponent.qml index 3ee0fbc22..25a9b7072 100644 --- a/electrum/gui/qml/components/wizard/WizardComponent.qml +++ b/electrum/gui/qml/components/wizard/WizardComponent.qml @@ -8,4 +8,19 @@ Item { property bool valid property bool last: false property bool ready: false + + onAccept: { + apply() + } + + function apply() { } + function checkIsLast() { + apply() + last = wizard.wiz.isLast(wizard_data) + } + + Component.onCompleted: { + checkIsLast() + } + } diff --git a/electrum/gui/qml/qeapp.py b/electrum/gui/qml/qeapp.py index 9745bcd7c..c21aefee3 100644 --- a/electrum/gui/qml/qeapp.py +++ b/electrum/gui/qml/qeapp.py @@ -29,7 +29,7 @@ from .qechannelopener import QEChannelOpener from .qelnpaymentdetails import QELnPaymentDetails from .qechanneldetails import QEChannelDetails from .qeswaphelper import QESwapHelper -from .qewizard import QENewWalletWizard +from .qewizard import QENewWalletWizard, QEServerConnectWizard notification = None @@ -219,6 +219,7 @@ class ElectrumQmlApplication(QGuiApplication): qmlRegisterUncreatableType(QEAmount, 'org.electrum', 1, 0, 'Amount', 'Amount can only be used as property') qmlRegisterUncreatableType(QENewWalletWizard, 'org.electrum', 1, 0, 'NewWalletWizard', 'NewWalletWizard can only be used as property') + qmlRegisterUncreatableType(QEServerConnectWizard, 'org.electrum', 1, 0, 'ServerConnectWizard', 'ServerConnectWizard can only be used as property') self.engine = QQmlApplicationEngine(parent=self) diff --git a/electrum/gui/qml/qedaemon.py b/electrum/gui/qml/qedaemon.py index dfd21e32f..5ae0e8232 100644 --- a/electrum/gui/qml/qedaemon.py +++ b/electrum/gui/qml/qedaemon.py @@ -14,7 +14,7 @@ from .auth import AuthMixin, auth_protect from .qefx import QEFX from .qewallet import QEWallet from .qewalletdb import QEWalletDB -from .qewizard import QENewWalletWizard +from .qewizard import QENewWalletWizard, QEServerConnectWizard # wallet list model. supports both wallet basenames (wallet file basenames) # and whole Wallet instances (loaded wallets) @@ -123,6 +123,7 @@ class QEDaemon(AuthMixin, QObject): _available_wallets = None _current_wallet = None _new_wallet_wizard = None + _server_connect_wizard = None _path = None _use_single_password = False _password = None @@ -131,6 +132,7 @@ class QEDaemon(AuthMixin, QObject): availableWalletsChanged = pyqtSignal() fxChanged = pyqtSignal() newWalletWizardChanged = pyqtSignal() + serverConnectWizardChanged = pyqtSignal() walletLoaded = pyqtSignal() walletRequiresPassword = pyqtSignal() @@ -296,3 +298,10 @@ class QEDaemon(AuthMixin, QObject): self._new_wallet_wizard = QENewWalletWizard(self) return self._new_wallet_wizard + + @pyqtProperty(QEServerConnectWizard, notify=serverConnectWizardChanged) + def serverConnectWizard(self): + if not self._server_connect_wizard: + self._server_connect_wizard = QEServerConnectWizard(self) + + return self._server_connect_wizard diff --git a/electrum/gui/qml/qewizard.py b/electrum/gui/qml/qewizard.py index 0cb5b8a43..34cdbf079 100644 --- a/electrum/gui/qml/qewizard.py +++ b/electrum/gui/qml/qewizard.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from PyQt5.QtQml import QQmlApplicationEngine from electrum.logging import get_logger -from electrum.gui.wizard import NewWalletWizard +from electrum.gui.wizard import NewWalletWizard, ServerConnectWizard class QEAbstractWizard(QObject): _logger = get_logger(__name__) @@ -99,3 +99,17 @@ class QENewWalletWizard(NewWalletWizard, QEAbstractWizard): except Exception as e: self._logger.error(repr(e)) self.createError.emit(str(e)) + +class QEServerConnectWizard(ServerConnectWizard, QEAbstractWizard): + + def __init__(self, daemon, parent = None): + ServerConnectWizard.__init__(self, daemon) + QEAbstractWizard.__init__(self, parent) + self._daemon = daemon + + # attach view names + self.navmap_merge({ + 'autoconnect': { 'gui': 'WCAutoConnect' }, + 'proxy_config': { 'gui': 'WCProxyConfig' }, + 'server_config': { 'gui': 'WCServerConfig' }, + }) diff --git a/electrum/gui/wizard.py b/electrum/gui/wizard.py index 869a94ef3..8a128b997 100644 --- a/electrum/gui/wizard.py +++ b/electrum/gui/wizard.py @@ -287,3 +287,27 @@ class NewWalletWizard(AbstractWizard): db.load_plugins() db.write(storage) + +class ServerConnectWizard(AbstractWizard): + + _logger = get_logger(__name__) + + def __init__(self, daemon): + self.navmap = { + 'autoconnect': { + 'next': 'proxy_config', + 'last': lambda v,d: d['autoconnect'] + }, + 'proxy_config': { + 'next': 'server_config' + }, + 'server_config': { + 'last': True + } + } + self._daemon = daemon + + def start(self, initial_data = {}): + self.reset() + self._current = WizardViewState('autoconnect', initial_data, {}) + return self._current