qml: generalize Wizard
This commit is contained in:
@@ -2,66 +2,31 @@ import QtQuick 2.6
|
|||||||
import QtQuick.Layouts 1.0
|
import QtQuick.Layouts 1.0
|
||||||
import QtQuick.Controls 2.1
|
import QtQuick.Controls 2.1
|
||||||
|
|
||||||
Dialog {
|
Wizard {
|
||||||
id: walletwizard
|
id: walletwizard
|
||||||
|
|
||||||
title: qsTr('New Wallet')
|
title: qsTr('New Wallet')
|
||||||
modal: true
|
|
||||||
|
|
||||||
enter: null // disable transition
|
enter: null // disable transition
|
||||||
|
|
||||||
property var wizard_data
|
|
||||||
|
|
||||||
function _setWizardData(wdata) {
|
|
||||||
wizard_data = {}
|
|
||||||
Object.assign(wizard_data, wdata) // deep copy
|
|
||||||
console.log('wizard data is now :' + JSON.stringify(wizard_data))
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper function to dynamically load wizard page components
|
|
||||||
// and add them to the SwipeView
|
|
||||||
// Here we do some manual binding of page.valid -> pages.pagevalid
|
|
||||||
// to propagate the state without the binding going stale
|
|
||||||
function _loadNextComponent(comp, wdata={}) {
|
|
||||||
var page = comp.createObject(pages, {
|
|
||||||
'visible': Qt.binding(function() {
|
|
||||||
return pages.currentItem === this
|
|
||||||
})
|
|
||||||
})
|
|
||||||
page.validChanged.connect(function() {
|
|
||||||
pages.pagevalid = page.valid
|
|
||||||
} )
|
|
||||||
page.lastChanged.connect(function() {
|
|
||||||
pages.lastpage = page.last
|
|
||||||
} )
|
|
||||||
Object.assign(page.wizard_data, wdata) // deep copy
|
|
||||||
pages.pagevalid = page.valid
|
|
||||||
|
|
||||||
return page
|
|
||||||
}
|
|
||||||
|
|
||||||
// State transition functions. These functions are called when the 'Next'
|
// State transition functions. These functions are called when the 'Next'
|
||||||
// button is pressed. They take data from the component, add it to the
|
// button is pressed. Depending on the data create the next page
|
||||||
// wizard_data object, and depending on the data create the next page
|
|
||||||
// in the conversation.
|
// in the conversation.
|
||||||
|
|
||||||
function walletnameDone(d) {
|
function walletnameDone(d) {
|
||||||
console.log('wallet name done')
|
console.log('wallet name done')
|
||||||
wizard_data['wallet_name'] = pages.currentItem.wallet_name
|
|
||||||
var page = _loadNextComponent(components.wallettype, wizard_data)
|
var page = _loadNextComponent(components.wallettype, wizard_data)
|
||||||
page.next.connect(function() {wallettypeDone()})
|
page.next.connect(function() {wallettypeDone()})
|
||||||
}
|
}
|
||||||
|
|
||||||
function wallettypeDone(d) {
|
function wallettypeDone(d) {
|
||||||
console.log('wallet type done')
|
console.log('wallet type done')
|
||||||
wizard_data['wallet_type'] = pages.currentItem.wallet_type
|
|
||||||
var page = _loadNextComponent(components.keystore, wizard_data)
|
var page = _loadNextComponent(components.keystore, wizard_data)
|
||||||
page.next.connect(function() {keystoretypeDone()})
|
page.next.connect(function() {keystoretypeDone()})
|
||||||
}
|
}
|
||||||
|
|
||||||
function keystoretypeDone(d) {
|
function keystoretypeDone(d) {
|
||||||
console.log('keystore type done')
|
console.log('keystore type done')
|
||||||
wizard_data['keystore_type'] = pages.currentItem.keystore_type
|
|
||||||
var page
|
var page
|
||||||
switch(wizard_data['keystore_type']) {
|
switch(wizard_data['keystore_type']) {
|
||||||
case 'createseed':
|
case 'createseed':
|
||||||
@@ -79,7 +44,6 @@ Dialog {
|
|||||||
|
|
||||||
function createseedDone(d) {
|
function createseedDone(d) {
|
||||||
console.log('create seed done')
|
console.log('create seed done')
|
||||||
wizard_data['seed'] = pages.currentItem.seed
|
|
||||||
var page = _loadNextComponent(components.confirmseed, wizard_data)
|
var page = _loadNextComponent(components.confirmseed, wizard_data)
|
||||||
page.next.connect(function() {confirmseedDone()})
|
page.next.connect(function() {confirmseedDone()})
|
||||||
}
|
}
|
||||||
@@ -93,7 +57,6 @@ Dialog {
|
|||||||
|
|
||||||
function haveseedDone(d) {
|
function haveseedDone(d) {
|
||||||
console.log('have seed done')
|
console.log('have seed done')
|
||||||
wizard_data['seed'] = pages.currentItem.seed
|
|
||||||
var page = _loadNextComponent(components.walletpassword, wizard_data)
|
var page = _loadNextComponent(components.walletpassword, wizard_data)
|
||||||
page.next.connect(function() {walletpasswordDone()})
|
page.next.connect(function() {walletpasswordDone()})
|
||||||
page.last = true
|
page.last = true
|
||||||
@@ -101,90 +64,18 @@ Dialog {
|
|||||||
|
|
||||||
function walletpasswordDone(d) {
|
function walletpasswordDone(d) {
|
||||||
console.log('walletpassword done')
|
console.log('walletpassword done')
|
||||||
wizard_data['password'] = pages.currentItem.password
|
|
||||||
wizard_data['encrypt'] = pages.currentItem.encrypt
|
|
||||||
var page = _loadNextComponent(components.walletpassword, wizard_data)
|
var page = _loadNextComponent(components.walletpassword, wizard_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ColumnLayout {
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
SwipeView {
|
|
||||||
id: pages
|
|
||||||
Layout.fillHeight: true
|
|
||||||
interactive: false
|
|
||||||
|
|
||||||
function prev() {
|
|
||||||
currentIndex = currentIndex - 1
|
|
||||||
_setWizardData(pages.contentChildren[currentIndex].wizard_data)
|
|
||||||
pages.pagevalid = pages.contentChildren[currentIndex].valid
|
|
||||||
pages.contentChildren[currentIndex+1].destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
function next() {
|
|
||||||
currentItem.next()
|
|
||||||
currentIndex = currentIndex + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function finalize() {
|
|
||||||
walletwizard.accept()
|
|
||||||
}
|
|
||||||
|
|
||||||
property bool pagevalid: false
|
|
||||||
property bool lastpage: false
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
_setWizardData({})
|
|
||||||
var start = _loadNextComponent(components.walletname)
|
|
||||||
start.next.connect(function() {walletnameDone()})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
PageIndicator {
|
|
||||||
id: indicator
|
|
||||||
|
|
||||||
Layout.alignment: Qt.AlignHCenter
|
|
||||||
|
|
||||||
count: pages.count
|
|
||||||
currentIndex: pages.currentIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
Layout.alignment: Qt.AlignHCenter
|
|
||||||
Button {
|
|
||||||
visible: pages.currentIndex == 0
|
|
||||||
text: qsTr("Cancel")
|
|
||||||
onClicked: walletwizard.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
visible: pages.currentIndex > 0
|
|
||||||
text: qsTr('Back')
|
|
||||||
onClicked: pages.prev()
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
text: "Next"
|
|
||||||
visible: !pages.lastpage
|
|
||||||
enabled: pages.pagevalid
|
|
||||||
onClicked: pages.next()
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
text: "Create"
|
|
||||||
visible: pages.lastpage
|
|
||||||
enabled: pages.pagevalid
|
|
||||||
onClicked: pages.finalize()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
WizardComponents {
|
WizardComponents {
|
||||||
id: components
|
id: components
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
_setWizardData({})
|
||||||
|
var start = _loadNextComponent(components.walletname)
|
||||||
|
start.next.connect(function() {walletnameDone()})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
127
electrum/gui/qml/components/Wizard.qml
Normal file
127
electrum/gui/qml/components/Wizard.qml
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
import QtQuick 2.6
|
||||||
|
import QtQuick.Layouts 1.0
|
||||||
|
import QtQuick.Controls 2.1
|
||||||
|
|
||||||
|
Dialog {
|
||||||
|
id: wizard
|
||||||
|
modal: true
|
||||||
|
|
||||||
|
width: parent.width
|
||||||
|
height: parent.height
|
||||||
|
|
||||||
|
property var wizard_data
|
||||||
|
property alias pages : pages
|
||||||
|
|
||||||
|
function _setWizardData(wdata) {
|
||||||
|
wizard_data = {}
|
||||||
|
Object.assign(wizard_data, wdata) // deep copy
|
||||||
|
console.log('wizard data is now :' + JSON.stringify(wizard_data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// helper function to dynamically load wizard page components
|
||||||
|
// and add them to the SwipeView
|
||||||
|
// Here we do some manual binding of page.valid -> pages.pagevalid and
|
||||||
|
// page.last -> pages.lastpage to propagate the state without the binding
|
||||||
|
// going stale.
|
||||||
|
function _loadNextComponent(comp, wdata={}) {
|
||||||
|
var page = comp.createObject(pages, {
|
||||||
|
'visible': Qt.binding(function() {
|
||||||
|
return pages.currentItem === this
|
||||||
|
})
|
||||||
|
})
|
||||||
|
page.validChanged.connect(function() {
|
||||||
|
pages.pagevalid = page.valid
|
||||||
|
} )
|
||||||
|
page.lastChanged.connect(function() {
|
||||||
|
pages.lastpage = page.last
|
||||||
|
} )
|
||||||
|
Object.assign(page.wizard_data, wdata) // deep copy
|
||||||
|
pages.pagevalid = page.valid
|
||||||
|
pages.lastpage = page.last
|
||||||
|
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
SwipeView {
|
||||||
|
id: pages
|
||||||
|
Layout.fillWidth: true
|
||||||
|
interactive: false
|
||||||
|
|
||||||
|
function prev() {
|
||||||
|
currentIndex = currentIndex - 1
|
||||||
|
_setWizardData(pages.contentChildren[currentIndex].wizard_data)
|
||||||
|
pages.pagevalid = pages.contentChildren[currentIndex].valid
|
||||||
|
pages.lastpage = pages.contentChildren[currentIndex].last
|
||||||
|
pages.contentChildren[currentIndex+1].destroy()
|
||||||
|
}
|
||||||
|
|
||||||
|
function next() {
|
||||||
|
currentItem.accept()
|
||||||
|
_setWizardData(pages.contentChildren[currentIndex].wizard_data)
|
||||||
|
currentItem.next()
|
||||||
|
currentIndex = currentIndex + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function finish() {
|
||||||
|
currentItem.accept()
|
||||||
|
_setWizardData(pages.contentChildren[currentIndex].wizard_data)
|
||||||
|
wizard.accept()
|
||||||
|
}
|
||||||
|
|
||||||
|
property bool pagevalid: false
|
||||||
|
property bool lastpage: false
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
_setWizardData({})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ColumnLayout {
|
||||||
|
Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom
|
||||||
|
|
||||||
|
PageIndicator {
|
||||||
|
id: indicator
|
||||||
|
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
|
||||||
|
count: pages.count
|
||||||
|
currentIndex: pages.currentIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
Layout.alignment: Qt.AlignHCenter
|
||||||
|
Button {
|
||||||
|
visible: pages.currentIndex == 0
|
||||||
|
text: qsTr("Cancel")
|
||||||
|
onClicked: wizard.reject()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
visible: pages.currentIndex > 0
|
||||||
|
text: qsTr('Back')
|
||||||
|
onClicked: pages.prev()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("Next")
|
||||||
|
visible: !pages.lastpage
|
||||||
|
enabled: pages.pagevalid
|
||||||
|
onClicked: pages.next()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
text: qsTr("Finish")
|
||||||
|
visible: pages.lastpage
|
||||||
|
enabled: pages.pagevalid
|
||||||
|
onClicked: pages.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import QtQuick 2.0
|
|||||||
|
|
||||||
Item {
|
Item {
|
||||||
signal next
|
signal next
|
||||||
|
signal accept
|
||||||
property var wizard_data : ({})
|
property var wizard_data : ({})
|
||||||
property bool valid
|
property bool valid
|
||||||
property bool last: false
|
property bool last: false
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ Item {
|
|||||||
property Component walletname: Component {
|
property Component walletname: Component {
|
||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: wallet_name.text.length > 0
|
valid: wallet_name.text.length > 0
|
||||||
property alias wallet_name: wallet_name.text
|
//property alias wallet_name: wallet_name.text
|
||||||
|
onAccept: {
|
||||||
|
wizard_data['wallet_name'] = wallet_name.text
|
||||||
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 1
|
columns: 1
|
||||||
Label { text: qsTr('Wallet name') }
|
Label { text: qsTr('Wallet name') }
|
||||||
@@ -20,13 +24,13 @@ Item {
|
|||||||
property Component wallettype: Component {
|
property Component wallettype: Component {
|
||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: wallettypegroup.checkedButton !== null
|
valid: wallettypegroup.checkedButton !== null
|
||||||
property string wallet_type
|
|
||||||
|
onAccept: {
|
||||||
|
wizard_data['wallet_type'] = wallettypegroup.checkedButton.wallettype
|
||||||
|
}
|
||||||
|
|
||||||
ButtonGroup {
|
ButtonGroup {
|
||||||
id: wallettypegroup
|
id: wallettypegroup
|
||||||
onCheckedButtonChanged: {
|
|
||||||
wallet_type = checkedButton.wallettype
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
@@ -63,13 +67,13 @@ Item {
|
|||||||
property Component keystore: Component {
|
property Component keystore: Component {
|
||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: keystoregroup.checkedButton !== null
|
valid: keystoregroup.checkedButton !== null
|
||||||
property string keystore_type
|
|
||||||
|
onAccept: {
|
||||||
|
wizard_data['keystore_type'] = keystoregroup.checkedButton.keystoretype
|
||||||
|
}
|
||||||
|
|
||||||
ButtonGroup {
|
ButtonGroup {
|
||||||
id: keystoregroup
|
id: keystoregroup
|
||||||
onCheckedButtonChanged: {
|
|
||||||
keystore_type = checkedButton.keystoretype
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
@@ -106,8 +110,12 @@ Item {
|
|||||||
property Component createseed: Component {
|
property Component createseed: Component {
|
||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: true
|
valid: true
|
||||||
property alias seed: seedtext.text
|
|
||||||
property alias extend: extendcb.checked
|
onAccept: {
|
||||||
|
wizard_data['seed'] = seedtext.text
|
||||||
|
wizard_data['seed_extend'] = extendcb.checked
|
||||||
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 1
|
columns: 1
|
||||||
Label { text: qsTr('Generating seed') }
|
Label { text: qsTr('Generating seed') }
|
||||||
@@ -129,9 +137,13 @@ Item {
|
|||||||
property Component haveseed: Component {
|
property Component haveseed: Component {
|
||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: true
|
valid: true
|
||||||
property alias seed: seedtext.text
|
|
||||||
property alias extend: extendcb.checked
|
onAccept: {
|
||||||
property alias bip39: bip39cb.checked
|
wizard_data['seed'] = seedtext.text
|
||||||
|
wizard_data['seed_extend'] = extendcb.checked
|
||||||
|
wizard_data['seed_bip39'] = bip39cb.checked
|
||||||
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 1
|
columns: 1
|
||||||
Label { text: qsTr('Enter your seed') }
|
Label { text: qsTr('Enter your seed') }
|
||||||
@@ -179,8 +191,11 @@ Item {
|
|||||||
WizardComponent {
|
WizardComponent {
|
||||||
valid: password1.text === password2.text
|
valid: password1.text === password2.text
|
||||||
|
|
||||||
property alias password: password1.text
|
onAccept: {
|
||||||
property alias encrypt: doencrypt.checked
|
wizard_data['password'] = password1.text
|
||||||
|
wizard_data['encrypt'] = doencrypt.checked
|
||||||
|
}
|
||||||
|
|
||||||
GridLayout {
|
GridLayout {
|
||||||
columns: 1
|
columns: 1
|
||||||
Label { text: qsTr('Password protect wallet?') }
|
Label { text: qsTr('Password protect wallet?') }
|
||||||
|
|||||||
Reference in New Issue
Block a user