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 ?  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 ?  qsTr (" A snapshot captures the current state of bitcoin transactions on the network. It can be imported into other bitcoin nodes to speed up the initial setup.\n\n Cannot generate snapshot when pruning is enabled" :  isIBDCompleted ?  qsTr (" A snapshot captures the current state of bitcoin transactions on the network. It can be imported into other bitcoin nodes to speed up the initial setup.\n\n You can generate a snapshot of the current chain state." :  qsTr (" A snapshot captures the current state of bitcoin transactions on the network. It can be imported into other bitcoin nodes to speed up the initial setup.\n\n Snapshot generation is available once the initial block download is complete." 
57+             }
58+ 
59+             ContinueButton {
60+                 Layout .preferredWidth :  Math .min (300 , columnLayout .width  -  2  *  Layout .leftMargin )
61+                 Layout .topMargin :  40 
62+                 Layout .alignment :  Qt .AlignCenter 
63+                 text:  qsTr (" Generate" 
64+                 enabled:  ! isPruned &&  isIBDCompleted
65+                 onClicked:  {
66+                     nodeModel .generateSnapshotThread ()
67+                     console .log (" UI Is Snapshot generated" 
68+                 }
69+             }
70+         }
71+ 
72+         ColumnLayout {
73+             //  index: 1
74+             Layout .alignment :  Qt .AlignHCenter 
75+             Layout .preferredWidth :  Math .min (parent .width , 450 )
76+ 
77+             Image {
78+                 Layout .alignment :  Qt .AlignCenter 
79+                 source:  " image://images/circle-file" 
80+                 sourceSize .width :  200 
81+                 sourceSize .height :  200 
82+             }
83+ 
84+             Header {
85+                 Layout .fillWidth :  true 
86+                 Layout .topMargin :  20 
87+                 headerBold:  true 
88+                 header:  qsTr (" Generating Snapshot" 
89+                 description:  isRewinding ?  qsTr (" Rewinding...\n This might take a while..." :  qsTr (" Restoring...\n This might take a while..." 
90+             }
91+ 
92+             ProgressIndicator {
93+                 id:  generatingProgressIndicator
94+                 Layout .topMargin :  20 
95+                 width:  200 
96+                 height:  20 
97+                 progress:  nodeModel .snapshotGenerating  ?  nodeModel .rewindProgress  :  0 
98+                 Layout .alignment :  Qt .AlignCenter 
99+                 progressColor:  Theme .color .blue 
100+             }
101+         }
102+ 
103+         ColumnLayout {
104+             //  index: 2
105+             id:  snapshotGeneratedColumn
106+             Layout .alignment :  Qt .AlignHCenter 
107+             Layout .preferredWidth :  Math .min (parent .width , 450 )
108+ 
109+             Image {
110+                 Layout .alignment :  Qt .AlignCenter 
111+                 source:  " image://images/circle-green-check" 
112+                 sourceSize .width :  60 
113+                 sourceSize .height :  60 
114+             }
115+ 
116+             Header {
117+                 Layout .fillWidth :  true 
118+                 Layout .topMargin :  20 
119+                 headerBold:  true 
120+                 header:  qsTr (" Snapshot Generated" 
121+                 descriptionBold:  false 
122+                 descriptionColor:  Theme .color .neutral6 
123+                 descriptionSize:  17 
124+                 descriptionLineHeight:  1.1 
125+                 description:  snapshotInfo &&  snapshotInfo[" date" ? 
126+                     qsTr (" It contains transactions up to %1." + 
127+                     "  You can use this snapshot to quickstart other nodes." arg (snapshotInfo[" date" 
128+                     :  qsTr (" It contains transactions up to DEBUG. You can use this snapshot to quickstart other nodes." 
129+             }
130+ 
131+             TextButton {
132+                 Layout .alignment :  Qt .AlignCenter 
133+                 text:  qsTr (" Generate new snapshot" 
134+                 onClicked:  {
135+                     nodeModel .generateSnapshotThread ()
136+                 }
137+             }
138+ 
139+             ContinueButton {
140+                 Layout .preferredWidth :  Math .min (300 , columnLayout .width  -  2  *  Layout .leftMargin )
141+                 Layout .topMargin :  20 
142+                 Layout .alignment :  Qt .AlignCenter 
143+                 text:  qsTr (" View file" 
144+                 borderColor:  Theme .color .neutral6 
145+                 backgroundColor:  " transparent" 
146+                 onClicked:  viewSnapshotFileDialog .open ()
147+             }
148+ 
149+             FileDialog {
150+                 id:  viewSnapshotFileDialog
151+                 folder:  nodeModel .getSnapshotDirectory ()
152+                 selectMultiple:  false 
153+                 selectExisting:  true 
154+                 nameFilters:  [" Snapshot files (*.dat)" " All files (*)" 
155+             }
156+ 
157+             Setting {
158+                 id:  snapshotGeneratedViewDetails
159+                 Layout .alignment :  Qt .AlignCenter 
160+                 header:  qsTr (" View details" 
161+                 actionItem:  CaretRightIcon {
162+                     id:  snapshotGeneratedCaretIcon
163+                     color:  snapshotGeneratedViewDetails .stateColor 
164+                     rotation:  snapshotGeneratedViewDetails .expanded  ?  90  :  0 
165+                     Behavior on rotation { NumberAnimation { duration:  200  } }
166+                 }
167+ 
168+                 property bool expanded:  false 
169+ 
170+                 onClicked:  {
171+                     expanded =  ! expanded
172+                 }
173+             }
174+ 
175+             ColumnLayout {
176+                 id:  snapshotGeneratedDetailsContent
177+                 visible:  snapshotGeneratedViewDetails .expanded 
178+                 Layout .preferredWidth :  Math .min (300 , parent .width  -  2  *  Layout .leftMargin )
179+                 Layout .alignment :  Qt .AlignCenter 
180+                 Layout .leftMargin :  80 
181+                 Layout .rightMargin :  80 
182+                 Layout .topMargin :  10 
183+                 spacing:  10 
184+                 //  TODO: make sure the block height number aligns right
185+                 RowLayout {
186+                     CoreText {
187+                         text:  qsTr (" Block Height:" 
188+                         Layout .alignment :  Qt .AlignLeft 
189+                         font .pixelSize :  14 
190+                     }
191+                     CoreText {
192+                         text:  snapshotInfo &&  snapshotInfo[" height" ? 
193+                             snapshotInfo[" height" :  qsTr (" DEBUG" 
194+                         Layout .alignment :  Qt .AlignRight 
195+                         font .pixelSize :  14 
196+                     }
197+                 }
198+                 Separator { Layout .fillWidth :  true  }
199+                 CoreText {
200+                     text:  snapshotInfo &&  snapshotInfo[" hashSerialized" ? 
201+                         qsTr (" Hash: %1" arg (snapshotInfo[" hashSerialized" substring (0 , 13 ) +  " ..." : 
202+                         qsTr (" Hash: DEBUG" 
203+                     font .pixelSize :  14 
204+                 }
205+             }
206+         }
207+     }
208+ }
0 commit comments