Skip to content

Commit fd78f7e

Browse files
committed
qml: Introduce Generate Snapshot page and wiring
This commit adds the Snapshot Gen files to the Connection Settings page. It wires the generate snapshot functionality through the node model and expands the snapshot qml worker class.
1 parent 0ebc18b commit fd78f7e

10 files changed

+770
-7
lines changed

src/Makefile.qt.include

+2
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ QML_RES_QML = \
406406
qml/components/NetworkIndicator.qml \
407407
qml/components/ProxySettings.qml \
408408
qml/components/Separator.qml \
409+
qml/components/SnapshotGenSettings.qml \
409410
qml/components/SnapshotSettings.qml \
410411
qml/components/StorageLocations.qml \
411412
qml/components/StorageOptions.qml \
@@ -465,6 +466,7 @@ QML_RES_QML = \
465466
qml/pages/settings/SettingsDisplay.qml \
466467
qml/pages/settings/SettingsProxy.qml \
467468
qml/pages/settings/SettingsSnapshot.qml \
469+
qml/pages/settings/SettingsSnapshotGen.qml \
468470
qml/pages/settings/SettingsStorage.qml \
469471
qml/pages/settings/SettingsTheme.qml \
470472
qml/pages/wallet/Activity.qml \

src/qml/bitcoin_qml.qrc

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<file>components/ProxySettings.qml</file>
1616
<file>components/StorageLocations.qml</file>
1717
<file>components/Separator.qml</file>
18+
<file>components/SnapshotGenSettings.qml</file>
1819
<file>components/SnapshotSettings.qml</file>
1920
<file>components/StorageOptions.qml</file>
2021
<file>components/StorageSettings.qml</file>
@@ -72,6 +73,7 @@
7273
<file>pages/settings/SettingsDeveloper.qml</file>
7374
<file>pages/settings/SettingsDisplay.qml</file>
7475
<file>pages/settings/SettingsProxy.qml</file>
76+
<file>pages/settings/SettingsSnapshotGen.qml</file>
7577
<file>pages/settings/SettingsSnapshot.qml</file>
7678
<file>pages/settings/SettingsStorage.qml</file>
7779
<file>pages/settings/SettingsTheme.qml</file>

src/qml/components/ConnectionSettings.qml

+30
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,40 @@ ColumnLayout {
1111
id: root
1212
signal next
1313
signal gotoSnapshot
14+
signal gotoGenerateSnapshot
1415
property bool snapshotImportCompleted: chainModel.isSnapshotActive
1516
property bool onboarding: false
17+
property bool generateSnapshot: false
18+
property bool isSnapshotGenerated: nodeModel.isSnapshotGenerated
1619

1720
spacing: 4
21+
Setting {
22+
id: gotoGenerateSnapshot
23+
visible: !root.onboarding
24+
Layout.fillWidth: true
25+
header: qsTr("Generate snapshot")
26+
description: qsTr("Speed up the setup of other nodes")
27+
actionItem: Item {
28+
width: 26
29+
height: 26
30+
CaretRightIcon {
31+
anchors.centerIn: parent
32+
color: gotoGenerateSnapshot.stateColor
33+
}
34+
}
35+
onClicked: {
36+
if (!nodeModel.isSnapshotFileExists()) {
37+
root.generateSnapshot = true
38+
root.gotoGenerateSnapshot()
39+
} else {
40+
root.gotoGenerateSnapshot()
41+
}
42+
}
43+
}
44+
Separator {
45+
visible: !root.onboarding
46+
Layout.fillWidth: true
47+
}
1848
Setting {
1949
id: gotoSnapshot
2050
visible: !root.onboarding
+227
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
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...\nThis might take a while...") : qsTr("Restoring...\nThis 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

Comments
 (0)