2015-04-01 11:56:05 +03:00
// Copyright (c) 2014-2015, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2014-08-19 15:58:02 +03:00
import QtQuick 2.2
2016-06-15 13:25:45 +03:00
import Qt . labs . settings 1.0
2016-10-30 19:07:56 +02:00
import QtQuick . Dialogs 1.2
2017-01-30 11:37:14 +02:00
import QtQuick . Layouts 1.1
2016-06-15 13:25:45 +03:00
2014-08-29 11:44:31 +03:00
import "../components"
2014-08-19 15:58:02 +03:00
2017-01-30 11:37:14 +02:00
ColumnLayout {
2017-01-26 22:54:31 +02:00
anchors.fill: parent
2017-01-30 11:37:14 +02:00
Layout.fillHeight: true
2014-08-19 15:58:02 +03:00
id: wizard
2016-01-25 23:17:55 +02:00
property alias nextButton : nextButton
2016-01-26 09:30:07 +02:00
property var settings : ( { } )
property int currentPage: 0
2017-08-06 18:03:16 +03:00
property int wizardLeftMargin: ( ! isMobile ) ? 150 : 25 * scaleRatio
property int wizardRightMargin: ( ! isMobile ) ? 150 : 25 * scaleRatio
property int wizardBottomMargin: ( isMobile ) ? 150 : 25 * scaleRatio
property int wizardTopMargin: ( isMobile ) ? 15 * scaleRatio : 50
2017-08-06 18:11:12 +03:00
// Storing wallet in Settings object doesn't work in qt 5.8 on android
property var m_wallet ;
2016-02-06 18:19:54 +02:00
property var paths: {
2016-10-29 17:35:16 +03:00
// "create_wallet" : [welcomePage, optionsPage, createWalletPage, passwordPage, donationPage, finishPage ],
// "recovery_wallet" : [welcomePage, optionsPage, recoveryWalletPage, passwordPage, donationPage, finishPage ],
// disable donation page
2017-08-06 18:26:48 +03:00
"create_wallet" : [ welcomePage , optionsPage , createWalletPage , passwordPage , daemonSettingsPage , finishPage ] ,
"recovery_wallet" : [ welcomePage , optionsPage , recoveryWalletPage , passwordPage , daemonSettingsPage , finishPage ] ,
2017-01-04 18:25:22 +02:00
"create_view_only_wallet" : [ createViewOnlyWalletPage , passwordPage ] ,
2016-10-29 17:34:24 +03:00
2016-02-06 18:19:54 +02:00
}
property string currentPath: "create_wallet"
property var pages: paths [ currentPath ]
2016-01-25 23:17:55 +02:00
2016-12-08 16:37:16 +02:00
signal wizardRestarted ( ) ;
2014-08-29 11:44:31 +03:00
signal useMoneroClicked ( )
2016-10-29 17:34:24 +03:00
signal openWalletFromFileClicked ( )
2017-01-26 22:54:31 +02:00
// border.color: "#DBDBDB"
// border.width: 1
// color: "#FFFFFF"
2014-08-19 15:58:02 +03:00
2016-10-29 17:34:24 +03:00
function restart ( ) {
wizard . currentPage = 0 ;
wizard . settings = ( { } )
wizard . currentPath = "create_wallet"
wizard . pages = paths [ currentPath ]
2016-12-08 16:37:16 +02:00
wizardRestarted ( ) ;
2016-10-29 17:34:24 +03:00
//hide all pages except first
for ( var i = 1 ; i < wizard . pages . length ; i ++ ) {
wizard . pages [ i ] . opacity = 0 ;
}
//Show first pages
wizard . pages [ 0 ] . opacity = 1 ;
}
2016-01-25 23:17:55 +02:00
function switchPage ( next ) {
2017-08-06 18:48:50 +03:00
// Android focus workaround
releaseFocus ( ) ;
2016-01-26 09:30:07 +02:00
// save settings for current page;
2016-06-14 16:09:14 +03:00
if ( next && typeof pages [ currentPage ] . onPageClosed !== 'undefined' ) {
if ( pages [ currentPage ] . onPageClosed ( settings ) !== true ) {
print ( "Can't go to the next page" ) ;
return ;
} ;
2016-01-26 09:30:07 +02:00
}
2016-10-29 17:44:13 +03:00
console . log ( "switchpage: currentPage: " , currentPage ) ;
2016-01-26 09:30:07 +02:00
2017-01-30 11:37:14 +02:00
// Update prev/next button positions for mobile/desktop
prevButton . anchors . verticalCenter = ( ! isMobile ) ? wizard.verticalCenter : undefined
prevButton . anchors . bottom = ( isMobile ) ? wizard.bottom : undefined
nextButton . anchors . verticalCenter = ( ! isMobile ) ? wizard.verticalCenter : undefined
nextButton . anchors . bottom = ( isMobile ) ? wizard.bottom : undefined
2016-02-02 23:09:45 +02:00
if ( currentPage > 0 || currentPage < pages . length - 1 ) {
pages [ currentPage ] . opacity = 0
var step_value = next ? 1 : - 1
currentPage += step_value
pages [ currentPage ] . opacity = 1 ;
2016-06-14 16:09:14 +03:00
2017-01-30 11:37:14 +02:00
var nextButtonVisible = currentPage > 1 && currentPage < pages . length - 1
nextButton . visible = nextButtonVisible
2016-07-21 13:56:17 +03:00
2016-12-17 16:38:43 +02:00
if ( typeof pages [ currentPage ] . onPageOpened !== 'undefined' ) {
pages [ currentPage ] . onPageOpened ( settings , next )
2016-06-14 16:09:14 +03:00
}
2016-01-25 23:17:55 +02:00
}
2016-02-02 23:09:45 +02:00
}
2016-01-25 23:17:55 +02:00
2016-06-10 16:41:13 +03:00
2016-02-02 23:09:45 +02:00
function openCreateWalletPage ( ) {
2017-05-04 18:04:12 +03:00
wizardRestarted ( ) ;
2016-02-02 23:09:45 +02:00
print ( "show create wallet page" ) ;
2016-02-06 18:19:54 +02:00
currentPath = "create_wallet"
2017-01-17 23:38:38 +02:00
pages = paths [ currentPath ]
2016-02-23 17:59:26 +02:00
createWalletPage . createWallet ( settings )
2016-07-21 13:56:17 +03:00
wizard . nextButton . visible = true
2017-01-02 19:45:10 +02:00
// goto next page
switchPage ( true ) ;
2016-02-02 23:09:45 +02:00
}
function openRecoveryWalletPage ( ) {
2017-05-04 18:04:12 +03:00
wizardRestarted ( ) ;
2016-02-02 23:09:45 +02:00
print ( "show recovery wallet page" ) ;
2016-02-06 18:19:54 +02:00
currentPath = "recovery_wallet"
2017-01-17 23:38:38 +02:00
pages = paths [ currentPath ]
2017-08-06 18:29:43 +03:00
// Create temporary wallet
createWalletPage . createWallet ( settings )
2016-07-21 13:56:17 +03:00
wizard . nextButton . visible = true
2017-01-02 19:45:10 +02:00
// goto next page
switchPage ( true ) ;
2016-10-29 17:34:24 +03:00
}
2016-07-21 13:56:17 +03:00
2016-10-29 17:34:24 +03:00
function openOpenWalletPage ( ) {
console . log ( "open wallet from file page" ) ;
2017-08-06 18:11:12 +03:00
if ( typeof m_wallet !== 'undefined' && m_wallet != null ) {
walletManager . closeWallet ( )
2016-11-29 18:45:40 +02:00
}
2017-01-02 19:45:10 +02:00
optionsPage . onPageClosed ( settings )
wizard . openWalletFromFileClicked ( ) ;
2016-02-02 23:09:45 +02:00
}
2017-01-04 18:25:22 +02:00
function openCreateViewOnlyWalletPage ( ) {
pages [ currentPage ] . opacity = 0
currentPath = "create_view_only_wallet"
pages = paths [ currentPath ]
currentPage = pages . indexOf ( createViewOnlyWalletPage )
createViewOnlyWalletPage . opacity = 1
nextButton . visible = true
rootItem . state = "wizard" ;
}
2016-10-30 19:07:56 +02:00
function createWalletPath ( folder_path , account_name ) {
// Remove trailing slash - (default on windows and mac)
if ( folder_path . substring ( folder_path . length - 1 ) === "/" ) {
folder_path = folder_path . substring ( 0 , folder_path . length - 1 )
}
2017-04-03 19:51:55 +03:00
// Store releative path on ios.
if ( isIOS )
folder_path = "" ;
2016-10-30 19:07:56 +02:00
return folder_path + "/" + account_name + "/" + account_name
}
2016-11-29 18:14:11 +02:00
function walletPathValid ( path ) {
2017-04-03 19:51:55 +03:00
if ( isIOS )
path = moneroAccountsDir + path ;
2016-11-29 18:14:11 +02:00
if ( walletManager . walletExists ( path ) ) {
walletErrorDialog . text = qsTr ( "A wallet with same name already exists. Please change wallet name" ) + translationManager . emptyString ;
walletErrorDialog . open ( ) ;
return false ;
2016-10-30 19:07:56 +02:00
}
2016-11-29 18:14:11 +02:00
// Don't allow non ascii characters in path on windows platforms until supported by Wallet2
if ( isWindows ) {
if ( ! isAscii ( path ) ) {
walletErrorDialog . text = qsTr ( "Non-ASCII characters are not allowed in wallet path or account name" ) + translationManager . emptyString ;
walletErrorDialog . open ( ) ;
return false ;
}
}
return true ;
}
function isAscii ( str ) {
for ( var i = 0 ; i < str . length ; i ++ ) {
if ( str . charCodeAt ( i ) > 127 )
return false ;
}
return true ;
2016-10-30 19:07:56 +02:00
}
2016-06-14 16:09:14 +03:00
//! actually writes the wallet
function applySettings ( ) {
2017-01-03 22:44:55 +02:00
// Save wallet files in user specified location
2016-10-30 19:07:56 +02:00
var new_wallet_filename = createWalletPath ( settings . wallet_path , settings . account_name )
2017-04-03 19:51:55 +03:00
if ( isIOS ) {
console . log ( "saving in ios: " + moneroAccountsDir + new_wallet_filename )
2017-08-06 18:11:12 +03:00
m_wallet . store ( moneroAccountsDir + new_wallet_filename ) ;
2017-04-03 19:51:55 +03:00
} else {
console . log ( "saving in wizard: " + new_wallet_filename )
2017-08-06 18:11:12 +03:00
m_wallet . store ( new_wallet_filename ) ;
2017-04-03 19:51:55 +03:00
}
2017-01-03 22:44:55 +02:00
// make sure temporary wallet files are deleted
console . log ( "Removing temporary wallet: " + settings . tmp_wallet_filename )
oshelper . removeTemporaryWallet ( settings . tmp_wallet_filename )
2016-06-14 16:09:14 +03:00
2016-08-16 23:21:46 +03:00
// protecting wallet with password
2017-08-06 18:11:12 +03:00
m_wallet . setPassword ( settings . wallet_password ) ;
2016-08-16 23:21:46 +03:00
2016-10-11 02:02:07 +03:00
// Store password in session to be able to use password protected functions (e.g show seed)
appWindow . password = settings . wallet_password
2016-06-14 16:09:14 +03:00
// saving wallet_filename;
settings [ 'wallet_filename' ] = new_wallet_filename ;
2016-06-15 13:25:45 +03:00
// persist settings
2016-06-15 16:34:55 +03:00
appWindow . persistentSettings . language = settings . language
2016-07-19 23:45:12 +03:00
appWindow . persistentSettings . locale = settings . locale
2016-06-15 16:34:55 +03:00
appWindow . persistentSettings . account_name = settings . account_name
2016-10-29 17:34:24 +03:00
appWindow . persistentSettings . wallet_path = new_wallet_filename
2016-10-29 17:35:16 +03:00
appWindow . persistentSettings . allow_background_mining = false //settings.allow_background_mining
appWindow . persistentSettings . auto_donations_enabled = false //settings.auto_donations_enabled
appWindow . persistentSettings . auto_donations_amount = false //settings.auto_donations_amount
2016-10-10 23:50:14 +03:00
appWindow . persistentSettings . restore_height = ( isNaN ( settings . restore_height ) ) ? 0 : settings . restore_height
2016-10-10 22:38:30 +03:00
appWindow . persistentSettings . is_recovering = ( settings . is_recovering === undefined ) ? false : settings . is_recovering
2016-06-14 16:09:14 +03:00
}
2016-06-15 13:25:45 +03:00
// reading settings from persistent storage
Component.onCompleted: {
2016-06-15 16:34:55 +03:00
settings [ 'allow_background_mining' ] = appWindow . persistentSettings . allow_background_mining
settings [ 'auto_donations_enabled' ] = appWindow . persistentSettings . auto_donations_enabled
settings [ 'auto_donations_amount' ] = appWindow . persistentSettings . auto_donations_amount
2016-06-15 13:25:45 +03:00
}
2016-02-02 23:09:45 +02:00
2016-10-30 19:07:56 +02:00
MessageDialog {
2016-11-29 18:14:11 +02:00
id: walletErrorDialog
2016-10-30 19:07:56 +02:00
title: "Error"
onAccepted: {
}
}
2016-02-02 23:09:45 +02:00
2014-08-19 15:58:02 +03:00
WizardWelcome {
id: welcomePage
2017-01-30 11:37:14 +02:00
// Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2014-08-19 15:58:02 +03:00
}
WizardOptions {
id: optionsPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2016-02-02 23:09:45 +02:00
onCreateWalletClicked: wizard . openCreateWalletPage ( )
onRecoveryWalletClicked: wizard . openRecoveryWalletPage ( )
2016-10-29 17:34:24 +03:00
onOpenWalletClicked: wizard . openOpenWalletPage ( ) ;
2014-08-20 22:19:21 +03:00
}
WizardCreateWallet {
id: createWalletPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2014-08-19 15:58:02 +03:00
}
2017-01-04 18:25:22 +02:00
WizardCreateViewOnlyWallet {
id: createViewOnlyWalletPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2017-01-04 18:25:22 +02:00
}
2016-02-02 23:09:45 +02:00
WizardRecoveryWallet {
id: recoveryWalletPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2016-02-02 23:09:45 +02:00
}
2014-08-21 13:09:52 +03:00
WizardPassword {
id: passwordPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2014-08-21 13:09:52 +03:00
}
2017-08-06 18:26:48 +03:00
WizardDaemonSettings {
id: daemonSettingsPage
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
}
2014-08-21 13:09:52 +03:00
WizardDonation {
id: donationPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2014-08-21 13:09:52 +03:00
}
WizardFinish {
id: finishPage
2017-01-30 11:37:14 +02:00
Layout.bottomMargin: wizardBottomMargin
Layout.topMargin: wizardTopMargin
2014-08-21 13:09:52 +03:00
}
2014-08-19 15:58:02 +03:00
Rectangle {
id: prevButton
2017-01-30 11:37:14 +02:00
anchors.verticalCenter: wizard . verticalCenter
2014-08-19 15:58:02 +03:00
anchors.left: parent . left
2017-01-30 11:37:14 +02:00
anchors.leftMargin: isMobile ? 20 : 50
2017-08-06 18:03:16 +03:00
anchors.bottomMargin: isMobile ? 20 * scaleRatio : 50
2014-08-19 15:58:02 +03:00
visible: parent . currentPage > 0
2017-08-06 18:03:16 +03:00
width: 50 * scaleRatio ; height: 50 * scaleRatio
2014-08-19 15:58:02 +03:00
radius: 25
color: prevArea . containsMouse ? "#FF4304" : "#FF6C3C"
Image {
anchors.centerIn: parent
anchors.horizontalCenterOffset: - 3
source: "qrc:///images/prevPage.png"
}
MouseArea {
id: prevArea
anchors.fill: parent
hoverEnabled: true
onClicked: wizard . switchPage ( false )
}
}
2014-08-29 11:44:31 +03:00
2017-01-30 11:37:14 +02:00
Rectangle {
id: nextButton
anchors.verticalCenter: wizard . verticalCenter
anchors.right: parent . right
2017-08-06 18:03:16 +03:00
anchors.rightMargin: isMobile ? 20 * scaleRatio : 50
anchors.bottomMargin: isMobile ? 20 * scaleRatio : 50
2017-01-30 11:37:14 +02:00
visible: currentPage > 1 && currentPage < pages . length - 1
2017-08-06 18:03:16 +03:00
width: 50 * scaleRatio ; height: 50 * scaleRatio
2017-01-30 11:37:14 +02:00
radius: 25
color: enabled ? nextArea . containsMouse ? "#FF4304" : "#FF6C3C" : "#DBDBDB"
Image {
anchors.centerIn: parent
anchors.horizontalCenterOffset: 3
source: "qrc:///images/nextPage.png"
}
MouseArea {
id: nextArea
anchors.fill: parent
hoverEnabled: true
onClicked: wizard . switchPage ( true )
}
}
2014-08-29 11:44:31 +03:00
StandardButton {
id: sendButton
anchors.right: parent . right
anchors.bottom: parent . bottom
2017-08-06 18:03:16 +03:00
anchors.margins: ( isMobile ) ? 20 * scaleRatio : 50 * scaleRatio
2016-07-20 22:28:11 +03:00
text: qsTr ( "USE MONERO" ) + translationManager . emptyString
2014-08-29 11:44:31 +03:00
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
2016-02-06 18:19:54 +02:00
visible: parent . paths [ currentPath ] [ currentPage ] === finishPage
2016-06-14 16:09:14 +03:00
onClicked: {
wizard . applySettings ( ) ;
2016-10-29 17:34:24 +03:00
wizard . useMoneroClicked ( ) ;
2016-06-14 16:09:14 +03:00
}
2014-08-29 11:44:31 +03:00
}
2017-01-04 18:25:22 +02:00
StandardButton {
id: createViewOnlyWalletButton
anchors.right: parent . right
anchors.bottom: parent . bottom
2017-08-06 18:03:16 +03:00
anchors.margins: ( isMobile ) ? 20 * scaleRatio : 50
2017-01-04 18:25:22 +02:00
text: qsTr ( "Create wallet" ) + translationManager . emptyString
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
visible: currentPath === "create_view_only_wallet" && parent . paths [ currentPath ] [ currentPage ] === passwordPage
enabled: passwordPage . passwordsMatch
onClicked: {
if ( currentWallet . createViewOnly ( settings [ 'view_only_wallet_path' ] , passwordPage . password ) ) {
console . log ( "view only wallet created in " , settings [ 'view_only_wallet_path' ] ) ;
informationPopup . title = qsTr ( "Success" ) + translationManager . emptyString ;
informationPopup . text = qsTr ( 'The view only wallet has been created. You can open it by closing this current wallet, clicking the "Open wallet from file" option, and selecting the view wallet in: \n%1' )
. arg ( settings [ 'view_only_wallet_path' ] ) ;
informationPopup . open ( )
informationPopup . onCloseCallback = null
rootItem . state = "normal"
wizard . restart ( ) ;
} else {
informationPopup . title = qsTr ( "Error" ) + translationManager . emptyString ;
informationPopup . text = currentWallet . errorString ;
informationPopup . open ( )
}
}
}
StandardButton {
id: abortViewOnlyButton
anchors.right: createViewOnlyWalletButton . left
anchors.bottom: parent . bottom
2017-08-06 18:03:16 +03:00
anchors.margins: ( isMobile ) ? 20 * scaleRatio : 50
2017-01-04 18:25:22 +02:00
text: qsTr ( "Abort" ) + translationManager . emptyString
shadowReleasedColor: "#FF4304"
shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C"
pressedColor: "#FF4304"
visible: currentPath === "create_view_only_wallet" && parent . paths [ currentPath ] [ currentPage ] === passwordPage
onClicked: {
wizard . restart ( ) ;
rootItem . state = "normal"
}
}
2014-08-19 15:58:02 +03:00
}