1+ // Copyright (c) 2023-present The Bitcoin Core developers
2+ // Distributed under the MIT software license, see the accompanying
3+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+ import QtQuick 2.15
6+ import QtQuick.Controls 2.15
7+ import QtQuick.Layouts 1.15
8+ import QtQuick.Dialogs 1.3
9+
10+ import "../controls"
11+ import "../controls/utils.js" as Utils
12+
13+
14+ ColumnLayout {
15+ id: columnLayout
16+ signal back
17+ property bool onboarding: false
18+ property bool generateSnapshot: false
19+ property string selectedFile: " "
20+ property bool snapshotGenerating: nodeModel .snapshotGenerating
21+ property bool isPruned: optionsModel .prune
22+ property bool isIBDCompleted: nodeModel .isIBDCompleted
23+ property bool isSnapshotGenerated: nodeModel .isSnapshotGenerated
24+ property var snapshotInfo: ( isSnapshotGenerated || isIBDCompleted ) ? chainModel .getSnapshotInfo () : ({})
25+ property bool isRewinding: nodeModel .isRewinding
26+
27+
28+ width: Math .min (parent .width , 450 )
29+ anchors .horizontalCenter : parent .horizontalCenter
30+
31+ StackLayout {
32+ id: genSettingsStack
33+ currentIndex: snapshotGenerating ? 1 : isSnapshotGenerated ? 2 : generateSnapshot ? 0 : onboarding ? 0 : 0
34+
35+ ColumnLayout {
36+ // index: 0
37+ Layout .alignment : Qt .AlignHCenter
38+ Layout .preferredWidth : Math .min (parent .width , 450 )
39+
40+ Image {
41+ Layout .alignment : Qt .AlignCenter
42+ source: " image://images/circle-file"
43+ sourceSize .width : 200
44+ sourceSize .height : 200
45+ }
46+
47+ Header {
48+ Layout .fillWidth : true
49+ Layout .topMargin : 20
50+ headerBold: true
51+ header: qsTr (" Generate snapshot" )
52+ descriptionBold: false
53+ descriptionColor: Theme .color .neutral6
54+ descriptionSize: 17
55+ descriptionLineHeight: 1.1
56+ description: isPruned
57+ ? qsTr (" A snapshot captures the state of the bitcoin network up to a certain date in the recent past. " +
58+ " It can be imported into other bitcoin nodes to speed up the initial setup.\n\n " )
59+ : isIBDCompleted
60+ ? qsTr (" A snapshot captures the state of the bitcoin network up to a certain date in the recent past. " +
61+ " It can be imported into other bitcoin nodes to speed up the initial setup.\n\n " +
62+ " You can generate a snapshot at block height %1 and date %2." ).arg (snapshotInfo[" height" ]).arg (snapshotInfo[" date" ])
63+ : qsTr (" A snapshot captures the state of the bitcoin network up to a certain date in the recent past. " +
64+ " It can be imported into other bitcoin nodes to speed up the initial setup.\n\n " +
65+ " Snapshot generation is available once the initial block download is complete." )
66+ }
67+
68+ CoreText {
69+ Layout .fillWidth : true
70+ // Layout.topMargin: 20
71+ color: Theme .color .red
72+ font .pixelSize : 17
73+ visible: isPruned
74+ text: isPruned
75+ ? qsTr (" Cannot generate snapshot when pruning is enabled" )
76+ : qsTr (" " )
77+ }
78+
79+ ContinueButton {
80+ Layout .preferredWidth : Math .min (300 , columnLayout .width - 2 * Layout .leftMargin )
81+ Layout .topMargin : 40
82+ Layout .alignment : Qt .AlignCenter
83+ text: qsTr (" Generate" )
84+ enabled: ! isPruned && isIBDCompleted
85+ onClicked: {
86+ nodeModel .generateSnapshotThread ()
87+ }
88+ }
89+ }
90+
91+ ColumnLayout {
92+ // index: 1
93+ Layout .alignment : Qt .AlignHCenter
94+ Layout .preferredWidth : Math .min (parent .width , 450 )
95+
96+ Image {
97+ Layout .alignment : Qt .AlignCenter
98+ source: " image://images/circle-file"
99+ sourceSize .width : 200
100+ sourceSize .height : 200
101+ }
102+
103+ Header {
104+ Layout .fillWidth : true
105+ Layout .topMargin : 20
106+ headerBold: true
107+ header: qsTr (" Generating Snapshot" )
108+ description: isRewinding ? qsTr (" Rewinding...\n This might take a while..." ) : qsTr (" Restoring...\n This might take a while..." )
109+ }
110+
111+ ProgressIndicator {
112+ id: generatingProgressIndicator
113+ Layout .topMargin : 20
114+ width: 200
115+ height: 20
116+ progress: nodeModel .snapshotGenerating ? nodeModel .rewindProgress : 0
117+ Layout .alignment : Qt .AlignCenter
118+ progressColor: Theme .color .blue
119+ }
120+ }
121+
122+ ColumnLayout {
123+ // index: 2
124+ id: snapshotGeneratedColumn
125+ Layout .alignment : Qt .AlignHCenter
126+ Layout .preferredWidth : Math .min (parent .width , 450 )
127+
128+ Image {
129+ Layout .alignment : Qt .AlignCenter
130+ source: " image://images/circle-green-check"
131+ sourceSize .width : 60
132+ sourceSize .height : 60
133+ }
134+
135+ Header {
136+ Layout .fillWidth : true
137+ Layout .topMargin : 20
138+ headerBold: true
139+ header: qsTr (" Snapshot Generated" )
140+ descriptionBold: false
141+ descriptionColor: Theme .color .neutral6
142+ descriptionSize: 17
143+ descriptionLineHeight: 1.1
144+ description: snapshotInfo && snapshotInfo[" date" ] ?
145+ qsTr (" It contains transactions up to %1." +
146+ " You can use this snapshot to quickstart other nodes." ).arg (snapshotInfo[" date" ])
147+ : qsTr (" It contains transactions up to DEBUG. You can use this snapshot to quickstart other nodes." )
148+ }
149+
150+ TextButton {
151+ Layout .alignment : Qt .AlignCenter
152+ text: qsTr (" Generate new snapshot" )
153+ onClicked: {
154+ nodeModel .generateSnapshotThread ()
155+ }
156+ }
157+
158+ ContinueButton {
159+ Layout .preferredWidth : Math .min (300 , columnLayout .width - 2 * Layout .leftMargin )
160+ Layout .topMargin : 20
161+ Layout .alignment : Qt .AlignCenter
162+ text: qsTr (" View file" )
163+ borderColor: Theme .color .neutral6
164+ backgroundColor: " transparent"
165+ onClicked: viewSnapshotFileDialog .open ()
166+ }
167+
168+ FileDialog {
169+ id: viewSnapshotFileDialog
170+ folder: nodeModel .getSnapshotDirectory ()
171+ selectMultiple: false
172+ selectExisting: true
173+ nameFilters: [" Snapshot files (*.dat)" , " All files (*)" ]
174+ }
175+
176+ Setting {
177+ id: snapshotGeneratedViewDetails
178+ Layout .alignment : Qt .AlignCenter
179+ header: qsTr (" View details" )
180+ actionItem: CaretRightIcon {
181+ id: snapshotGeneratedCaretIcon
182+ color: snapshotGeneratedViewDetails .stateColor
183+ rotation: snapshotGeneratedViewDetails .expanded ? 90 : 0
184+ Behavior on rotation { NumberAnimation { duration: 200 } }
185+ }
186+
187+ property bool expanded: false
188+
189+ onClicked: {
190+ expanded = ! expanded
191+ }
192+ }
193+
194+ ColumnLayout {
195+ id: snapshotGeneratedDetailsContent
196+ visible: snapshotGeneratedViewDetails .expanded
197+ Layout .preferredWidth : Math .min (300 , parent .width - 2 * Layout .leftMargin )
198+ Layout .alignment : Qt .AlignCenter
199+ Layout .leftMargin : 80
200+ Layout .rightMargin : 80
201+ Layout .topMargin : 10
202+ spacing: 10
203+ // TODO: make sure the block height number aligns right
204+ RowLayout {
205+ CoreText {
206+ text: qsTr (" Block Height:" )
207+ Layout .alignment : Qt .AlignLeft
208+ font .pixelSize : 14
209+ }
210+ CoreText {
211+ text: snapshotInfo && snapshotInfo[" height" ] ?
212+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
213+ Layout .alignment : Qt .AlignRight
214+ font .pixelSize : 14
215+ }
216+ }
217+ Separator { Layout .fillWidth : true }
218+ CoreText {
219+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
220+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
221+ qsTr (" Hash: DEBUG" )
222+ font .pixelSize : 14
223+ }
224+ }
225+ }
226+ }
227+ }
0 commit comments