5
5
import QtQuick 2.15
6
6
import QtQuick.Controls 2.15
7
7
import QtQuick.Layouts 1.15
8
+ import QtQuick.Dialogs 1.3
8
9
9
10
import "../controls"
10
11
12
+ // This QML component manages the snapshot loading process in the GUI.
13
+ // It provides visual feedback to the user about the snapshot's loading state.
14
+
11
15
ColumnLayout {
16
+ // The snapshotLoading property indicates if the snapshot is currently being loaded.
17
+ // When true, the UI will show a loading indicator.
18
+ property bool snapshotLoading: nodeModel .snapshotLoading
12
19
signal snapshotImportCompleted ()
13
20
property int snapshotVerificationCycles: 0
14
21
property real snapshotVerificationProgress: 0
15
- property bool snapshotVerified: false
22
+ property bool onboarding: false
23
+
24
+ // The snapshotVerified property indicates if the snapshot has been successfully loaded and verified.
25
+ // When true, the UI will transition to the "Snapshot Loaded" page.
26
+ property bool snapshotVerified: onboarding ? false : chainModel .isSnapshotActive
27
+
28
+ // The snapshotFileName property holds the name of the snapshot file being loaded.
29
+ // It is set when a file is selected in the FileDialog.
30
+ property string snapshotFileName: " "
31
+
32
+ // The snapshotInfo property holds information about the loaded snapshot.
33
+ // It is updated when the snapshot is loaded and verified.
34
+ property var snapshotInfo: ({})
16
35
17
36
id: columnLayout
18
37
width: Math .min (parent .width , 450 )
19
38
anchors .horizontalCenter : parent .horizontalCenter
20
39
21
-
40
+ // The Timer component simulates snapshot verification progress for testing purposes.
41
+ // It updates the snapshotVerificationProgress property, which can be used to display a progress bar.
22
42
Timer {
23
43
id: snapshotSimulationTimer
24
44
interval: 50 // Update every 50ms
@@ -29,7 +49,7 @@ ColumnLayout {
29
49
snapshotVerificationProgress += 0.01
30
50
} else {
31
51
snapshotVerificationCycles++
32
- if (snapshotVerificationCycles < 1 ) {
52
+ if (snapshotVerificationCycles < 3 ) {
33
53
snapshotVerificationProgress = 0
34
54
} else {
35
55
running = false
@@ -40,9 +60,11 @@ ColumnLayout {
40
60
}
41
61
}
42
62
63
+ // The StackLayout component manages the different pages of the snapshot settings UI.
64
+ // It determines which page to display based on the snapshotLoading and snapshotVerified properties.
43
65
StackLayout {
44
66
id: settingsStack
45
- currentIndex: 0
67
+ currentIndex: onboarding ? 0 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0
46
68
47
69
ColumnLayout {
48
70
Layout .alignment : Qt .AlignHCenter
@@ -69,6 +91,8 @@ ColumnLayout {
69
91
" It will be automatically verified in the background." )
70
92
}
71
93
94
+ // The ContinueButton component is used to trigger the snapshot file selection process.
95
+ // When clicked, it opens a FileDialog for the user to choose a snapshot file.
72
96
ContinueButton {
73
97
Layout .preferredWidth : Math .min (300 , columnLayout .width - 2 * Layout .leftMargin )
74
98
Layout .topMargin : 40
@@ -78,8 +102,25 @@ ColumnLayout {
78
102
Layout .alignment : Qt .AlignCenter
79
103
text: qsTr (" Choose snapshot file" )
80
104
onClicked: {
81
- settingsStack .currentIndex = 1
82
- snapshotSimulationTimer .start ()
105
+ fileDialog .open ()
106
+ }
107
+ }
108
+
109
+ // The FileDialog component is used to allow the user to select a snapshot file from their system.
110
+ FileDialog {
111
+ id: fileDialog
112
+ folder: shortcuts .home
113
+ selectMultiple: false
114
+ onAccepted: {
115
+ console .log (" File chosen:" , fileDialog .fileUrls )
116
+ snapshotFileName = fileDialog .fileUrl .toString ()
117
+ console .log (" Snapshot file name:" , snapshotFileName)
118
+ if (snapshotFileName .endsWith (" .dat" )) {
119
+ nodeModel .initializeSnapshot (true , snapshotFileName)
120
+ // nodeModel.presyncProgress
121
+ } else {
122
+ console .error (" Snapshot loading failed" )
123
+ }
83
124
}
84
125
}
85
126
}
@@ -102,17 +143,40 @@ ColumnLayout {
102
143
Layout .leftMargin : 20
103
144
Layout .rightMargin : 20
104
145
header: qsTr (" Loading Snapshot" )
146
+ description: qsTr (" This might take a while..." )
105
147
}
106
148
149
+ // The ProgressIndicator component displays the progress of the snapshot verification process.
107
150
ProgressIndicator {
108
151
id: progressIndicator
109
152
Layout .topMargin : 20
110
153
width: 200
111
154
height: 20
112
- progress: snapshotVerificationProgress
155
+ progress: nodeModel . snapshotProgress
113
156
Layout .alignment : Qt .AlignCenter
114
157
progressColor: Theme .color .blue
115
158
}
159
+
160
+ // The Connections component listens for signals from the nodeModel
161
+ // to update the UI based on snapshot loading progress.
162
+ Connections {
163
+ target: nodeModel
164
+ function onSnapshotProgressChanged () {
165
+ progressIndicator .progress = nodeModel .snapshotProgress
166
+ }
167
+
168
+ function onSnapshotLoaded (success ) {
169
+ if (success) {
170
+ chainModel .isSnapshotActiveChanged ()
171
+ snapshotVerified = chainModel .isSnapshotActive
172
+ snapshotInfo = chainModel .getSnapshotInfo ()
173
+ settingsStack .currentIndex = 2 // Move to the "Snapshot Loaded" page
174
+ } else {
175
+ // Handle snapshot loading failure
176
+ console .error (" Snapshot loading failed" )
177
+ }
178
+ }
179
+ }
116
180
}
117
181
118
182
ColumnLayout {
@@ -137,8 +201,11 @@ ColumnLayout {
137
201
descriptionColor: Theme .color .neutral6
138
202
descriptionSize: 17
139
203
descriptionLineHeight: 1.1
140
- description: qsTr (" It contains transactions up to January 12, 2024. Newer transactions still need to be downloaded." +
141
- " The data will be verified in the background." )
204
+ description: snapshotInfo && snapshotInfo[" date" ] ?
205
+ qsTr (" It contains transactions up to %1. Newer transactions still need to be downloaded." +
206
+ " The data will be verified in the background." ).arg (snapshotInfo[" date" ]) :
207
+ qsTr (" It contains transactions up to DEBUG. Newer transactions still need to be downloaded." +
208
+ " The data will be verified in the background." )
142
209
}
143
210
144
211
ContinueButton {
@@ -153,6 +220,7 @@ ColumnLayout {
153
220
}
154
221
}
155
222
223
+ // The Setting component provides a toggleable view for detailed snapshot information.
156
224
Setting {
157
225
id: viewDetails
158
226
Layout .alignment : Qt .AlignCenter
@@ -188,16 +256,26 @@ ColumnLayout {
188
256
font .pixelSize : 14
189
257
}
190
258
CoreText {
191
- text: qsTr (" 200,000" )
259
+ text: snapshotInfo && snapshotInfo[" height" ] ?
260
+ snapshotInfo[" height" ] : qsTr (" DEBUG" )
192
261
Layout .alignment : Qt .AlignRight
193
262
font .pixelSize : 14
194
263
}
195
264
}
196
265
Separator { Layout .fillWidth : true }
197
266
CoreText {
198
- text: qsTr (" Hash: 0x1234567890abcdef..." )
267
+ // The CoreText component displays the hash of the loaded snapshot.
268
+ text: snapshotInfo && snapshotInfo[" hashSerialized" ] ?
269
+ qsTr (" Hash: %1" ).arg (snapshotInfo[" hashSerialized" ].substring (0 , 13 ) + " ..." ) :
270
+ qsTr (" Hash: DEBUG" )
199
271
font .pixelSize : 14
200
272
}
273
+
274
+ Component .onCompleted : {
275
+ if (snapshotVerified) {
276
+ snapshotInfo = chainModel .getSnapshotInfo ()
277
+ }
278
+ }
201
279
}
202
280
}
203
281
}
0 commit comments