|
| 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 | + |
| 9 | +import "../controls" |
| 10 | + |
| 11 | +ColumnLayout { |
| 12 | + signal snapshotImportCompleted() |
| 13 | + property int snapshotVerificationCycles: 0 |
| 14 | + property real snapshotVerificationProgress: 0 |
| 15 | + property bool snapshotVerified: false |
| 16 | + |
| 17 | + id: columnLayout |
| 18 | + width: Math.min(parent.width, 450) |
| 19 | + anchors.horizontalCenter: parent.horizontalCenter |
| 20 | + |
| 21 | + |
| 22 | + Timer { |
| 23 | + id: snapshotSimulationTimer |
| 24 | + interval: 50 // Update every 50ms |
| 25 | + running: false |
| 26 | + repeat: true |
| 27 | + onTriggered: { |
| 28 | + if (snapshotVerificationProgress < 1) { |
| 29 | + snapshotVerificationProgress += 0.01 |
| 30 | + } else { |
| 31 | + snapshotVerificationCycles++ |
| 32 | + if (snapshotVerificationCycles < 1) { |
| 33 | + snapshotVerificationProgress = 0 |
| 34 | + } else { |
| 35 | + running = false |
| 36 | + snapshotVerified = true |
| 37 | + settingsStack.currentIndex = 2 |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + StackLayout { |
| 44 | + id: settingsStack |
| 45 | + currentIndex: 0 |
| 46 | + |
| 47 | + ColumnLayout { |
| 48 | + Layout.alignment: Qt.AlignHCenter |
| 49 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 50 | + |
| 51 | + Image { |
| 52 | + Layout.alignment: Qt.AlignCenter |
| 53 | + source: "image://images/circle-file" |
| 54 | + |
| 55 | + sourceSize.width: 200 |
| 56 | + sourceSize.height: 200 |
| 57 | + } |
| 58 | + |
| 59 | + Header { |
| 60 | + Layout.fillWidth: true |
| 61 | + Layout.topMargin: 20 |
| 62 | + headerBold: true |
| 63 | + header: qsTr("Load snapshot") |
| 64 | + descriptionBold: false |
| 65 | + descriptionColor: Theme.color.neutral6 |
| 66 | + descriptionSize: 17 |
| 67 | + descriptionLineHeight: 1.1 |
| 68 | + description: qsTr("You can start using the application more quickly by loading a recent transaction snapshot." + |
| 69 | + " It will be automatically verified in the background.") |
| 70 | + } |
| 71 | + |
| 72 | + ContinueButton { |
| 73 | + Layout.preferredWidth: Math.min(300, columnLayout.width - 2 * Layout.leftMargin) |
| 74 | + Layout.topMargin: 40 |
| 75 | + Layout.leftMargin: 20 |
| 76 | + Layout.rightMargin: Layout.leftMargin |
| 77 | + Layout.bottomMargin: 20 |
| 78 | + Layout.alignment: Qt.AlignCenter |
| 79 | + text: qsTr("Choose snapshot file") |
| 80 | + onClicked: { |
| 81 | + settingsStack.currentIndex = 1 |
| 82 | + snapshotSimulationTimer.start() |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + ColumnLayout { |
| 88 | + Layout.alignment: Qt.AlignHCenter |
| 89 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 90 | + |
| 91 | + Image { |
| 92 | + Layout.alignment: Qt.AlignCenter |
| 93 | + source: "image://images/circle-file" |
| 94 | + |
| 95 | + sourceSize.width: 200 |
| 96 | + sourceSize.height: 200 |
| 97 | + } |
| 98 | + |
| 99 | + Header { |
| 100 | + Layout.fillWidth: true |
| 101 | + Layout.topMargin: 20 |
| 102 | + Layout.leftMargin: 20 |
| 103 | + Layout.rightMargin: 20 |
| 104 | + header: qsTr("Loading Snapshot") |
| 105 | + } |
| 106 | + |
| 107 | + ProgressIndicator { |
| 108 | + id: progressIndicator |
| 109 | + Layout.topMargin: 20 |
| 110 | + width: 200 |
| 111 | + height: 20 |
| 112 | + progress: snapshotVerificationProgress |
| 113 | + Layout.alignment: Qt.AlignCenter |
| 114 | + progressColor: Theme.color.blue |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + ColumnLayout { |
| 119 | + id: loadedSnapshotColumn |
| 120 | + Layout.alignment: Qt.AlignHCenter |
| 121 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 122 | + |
| 123 | + Image { |
| 124 | + Layout.alignment: Qt.AlignCenter |
| 125 | + source: "image://images/circle-green-check" |
| 126 | + |
| 127 | + sourceSize.width: 60 |
| 128 | + sourceSize.height: 60 |
| 129 | + } |
| 130 | + |
| 131 | + Header { |
| 132 | + Layout.fillWidth: true |
| 133 | + Layout.topMargin: 20 |
| 134 | + headerBold: true |
| 135 | + header: qsTr("Snapshot Loaded") |
| 136 | + descriptionBold: false |
| 137 | + descriptionColor: Theme.color.neutral6 |
| 138 | + descriptionSize: 17 |
| 139 | + 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.") |
| 142 | + } |
| 143 | + |
| 144 | + ContinueButton { |
| 145 | + Layout.preferredWidth: Math.min(300, columnLayout.width - 2 * Layout.leftMargin) |
| 146 | + Layout.topMargin: 40 |
| 147 | + Layout.alignment: Qt.AlignCenter |
| 148 | + text: qsTr("Done") |
| 149 | + onClicked: { |
| 150 | + snapshotImportCompleted() |
| 151 | + connectionSwipe.decrementCurrentIndex() |
| 152 | + connectionSwipe.decrementCurrentIndex() |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + Setting { |
| 157 | + id: viewDetails |
| 158 | + Layout.alignment: Qt.AlignCenter |
| 159 | + header: qsTr("View details") |
| 160 | + actionItem: CaretRightIcon { |
| 161 | + id: caretIcon |
| 162 | + color: viewDetails.stateColor |
| 163 | + rotation: viewDetails.expanded ? 90 : 0 |
| 164 | + Behavior on rotation { NumberAnimation { duration: 200 } } |
| 165 | + } |
| 166 | + |
| 167 | + property bool expanded: false |
| 168 | + |
| 169 | + onClicked: { |
| 170 | + expanded = !expanded |
| 171 | + } |
| 172 | + } |
| 173 | + |
| 174 | + ColumnLayout { |
| 175 | + id: detailsContent |
| 176 | + visible: viewDetails.expanded |
| 177 | + Layout.preferredWidth: Math.min(300, parent.width - 2 * Layout.leftMargin) |
| 178 | + Layout.alignment: Qt.AlignCenter |
| 179 | + Layout.leftMargin: 80 |
| 180 | + Layout.rightMargin: 80 |
| 181 | + Layout.topMargin: 10 |
| 182 | + spacing: 10 |
| 183 | + // TODO: make sure the block height number aligns right |
| 184 | + RowLayout { |
| 185 | + CoreText { |
| 186 | + text: qsTr("Block Height:") |
| 187 | + Layout.alignment: Qt.AlignLeft |
| 188 | + font.pixelSize: 14 |
| 189 | + } |
| 190 | + CoreText { |
| 191 | + text: qsTr("200,000") |
| 192 | + Layout.alignment: Qt.AlignRight |
| 193 | + font.pixelSize: 14 |
| 194 | + } |
| 195 | + } |
| 196 | + Separator { Layout.fillWidth: true } |
| 197 | + CoreText { |
| 198 | + text: qsTr("Hash: 0x1234567890abcdef...") |
| 199 | + font.pixelSize: 14 |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | +} |
0 commit comments