|
| 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 | + |
| 12 | +ColumnLayout { |
| 13 | + id: columnLayout |
| 14 | + signal back |
| 15 | + property bool snapshotLoading: nodeModel.snapshotLoading |
| 16 | + property bool snapshotLoaded: nodeModel.isSnapshotLoaded |
| 17 | + property bool snapshotImportCompleted: onboarding ? false : chainModel.isSnapshotActive |
| 18 | + property bool onboarding: false |
| 19 | + property bool snapshotVerified: onboarding ? false : chainModel.isSnapshotActive |
| 20 | + property string snapshotFileName: "" |
| 21 | + property var snapshotInfo: (snapshotVerified || snapshotLoaded) ? chainModel.getSnapshotInfo() : ({}) |
| 22 | + property string selectedFile: "" |
| 23 | + property bool headersSynced: nodeModel.headersSynced |
| 24 | + |
| 25 | + width: Math.min(parent.width, 450) |
| 26 | + anchors.horizontalCenter: parent.horizontalCenter |
| 27 | + |
| 28 | + StackLayout { |
| 29 | + id: settingsStack |
| 30 | + currentIndex: onboarding ? 0 : snapshotLoaded ? 2 : snapshotVerified ? 2 : snapshotLoading ? 1 : 0 |
| 31 | + |
| 32 | + ColumnLayout { |
| 33 | + Layout.alignment: Qt.AlignHCenter |
| 34 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 35 | + |
| 36 | + Image { |
| 37 | + Layout.alignment: Qt.AlignCenter |
| 38 | + source: "image://images/circle-file" |
| 39 | + |
| 40 | + sourceSize.width: 200 |
| 41 | + sourceSize.height: 200 |
| 42 | + } |
| 43 | + |
| 44 | + Header { |
| 45 | + Layout.fillWidth: true |
| 46 | + Layout.topMargin: 20 |
| 47 | + headerBold: true |
| 48 | + header: qsTr("Load snapshot") |
| 49 | + descriptionBold: false |
| 50 | + descriptionColor: Theme.color.neutral6 |
| 51 | + descriptionSize: 17 |
| 52 | + descriptionLineHeight: 1.1 |
| 53 | + description: qsTr("You can start using the application more quickly by loading a recent transaction snapshot." + |
| 54 | + " It will be automatically verified in the background.") |
| 55 | + } |
| 56 | + |
| 57 | + CoreText { |
| 58 | + Layout.fillWidth: true |
| 59 | + Layout.topMargin: 20 |
| 60 | + color: Theme.color.neutral6 |
| 61 | + font.pixelSize: 17 |
| 62 | + visible: !headersSynced |
| 63 | + text: !headersSynced |
| 64 | + ? qsTr("Please wait for headers to sync before loading a snapshot.") |
| 65 | + : qsTr("") |
| 66 | + wrap: true |
| 67 | + wrapMode: Text.WordWrap |
| 68 | + } |
| 69 | + |
| 70 | + ContinueButton { |
| 71 | + Layout.preferredWidth: Math.min(300, columnLayout.width - 2 * Layout.leftMargin) |
| 72 | + Layout.topMargin: 40 |
| 73 | + Layout.leftMargin: 20 |
| 74 | + Layout.rightMargin: Layout.leftMargin |
| 75 | + Layout.bottomMargin: 20 |
| 76 | + Layout.alignment: Qt.AlignCenter |
| 77 | + text: qsTr("Choose snapshot file") |
| 78 | + enabled: headersSynced |
| 79 | + onClicked: fileDialog.open() |
| 80 | + } |
| 81 | + |
| 82 | + FileDialog { |
| 83 | + id: fileDialog |
| 84 | + folder: shortcuts.home |
| 85 | + selectMultiple: false |
| 86 | + selectExisting: true |
| 87 | + nameFilters: ["Snapshot files (*.dat)", "All files (*)"] |
| 88 | + onAccepted: { |
| 89 | + selectedFile = fileUrl.toString() |
| 90 | + snapshotFileName = selectedFile |
| 91 | + nodeModel.snapshotLoadThread(snapshotFileName) |
| 92 | + } |
| 93 | + } |
| 94 | + // TODO: Handle file error signal |
| 95 | + } |
| 96 | + |
| 97 | + ColumnLayout { |
| 98 | + Layout.alignment: Qt.AlignHCenter |
| 99 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 100 | + |
| 101 | + Image { |
| 102 | + Layout.alignment: Qt.AlignCenter |
| 103 | + source: "image://images/circle-file" |
| 104 | + |
| 105 | + sourceSize.width: 200 |
| 106 | + sourceSize.height: 200 |
| 107 | + } |
| 108 | + |
| 109 | + Header { |
| 110 | + Layout.fillWidth: true |
| 111 | + Layout.topMargin: 20 |
| 112 | + Layout.leftMargin: 20 |
| 113 | + Layout.rightMargin: 20 |
| 114 | + header: qsTr("Loading Snapshot") |
| 115 | + description: qsTr("This might take a while...") |
| 116 | + } |
| 117 | + |
| 118 | + ProgressIndicator { |
| 119 | + id: progressIndicator |
| 120 | + Layout.topMargin: 20 |
| 121 | + width: 200 |
| 122 | + height: 20 |
| 123 | + progress: nodeModel.snapshotProgress |
| 124 | + Layout.alignment: Qt.AlignCenter |
| 125 | + progressColor: Theme.color.blue |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + ColumnLayout { |
| 130 | + id: loadedSnapshotColumn |
| 131 | + Layout.alignment: Qt.AlignHCenter |
| 132 | + Layout.preferredWidth: Math.min(parent.width, 450) |
| 133 | + |
| 134 | + Image { |
| 135 | + Layout.alignment: Qt.AlignCenter |
| 136 | + source: "image://images/circle-green-check" |
| 137 | + |
| 138 | + sourceSize.width: 60 |
| 139 | + sourceSize.height: 60 |
| 140 | + } |
| 141 | + |
| 142 | + Header { |
| 143 | + Layout.fillWidth: true |
| 144 | + Layout.topMargin: 20 |
| 145 | + headerBold: true |
| 146 | + header: qsTr("Snapshot Loaded") |
| 147 | + descriptionBold: false |
| 148 | + descriptionColor: Theme.color.neutral6 |
| 149 | + descriptionSize: 17 |
| 150 | + descriptionLineHeight: 1.1 |
| 151 | + description: snapshotInfo && snapshotInfo["date"] ? |
| 152 | + qsTr("It contains unspent transactions up to %1. Next, transactions will be verified and newer transactions downloaded.").arg(snapshotInfo["date"]) : |
| 153 | + qsTr("It contains transactions up to DEBUG. Newer transactions still need to be downloaded." + |
| 154 | + " The data will be verified in the background.") |
| 155 | + } |
| 156 | + |
| 157 | + ContinueButton { |
| 158 | + Layout.preferredWidth: Math.min(300, columnLayout.width - 2 * Layout.leftMargin) |
| 159 | + Layout.topMargin: 40 |
| 160 | + Layout.alignment: Qt.AlignCenter |
| 161 | + text: qsTr("Done") |
| 162 | + onClicked: { |
| 163 | + chainModel.isSnapshotActiveChanged() |
| 164 | + back() |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + Setting { |
| 169 | + id: viewDetails |
| 170 | + Layout.alignment: Qt.AlignCenter |
| 171 | + header: qsTr("View details") |
| 172 | + actionItem: CaretRightIcon { |
| 173 | + id: caretIcon |
| 174 | + color: viewDetails.stateColor |
| 175 | + rotation: viewDetails.expanded ? 90 : 0 |
| 176 | + Behavior on rotation { NumberAnimation { duration: 200 } } |
| 177 | + } |
| 178 | + |
| 179 | + property bool expanded: false |
| 180 | + |
| 181 | + onClicked: { |
| 182 | + expanded = !expanded |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + ColumnLayout { |
| 187 | + id: detailsContent |
| 188 | + visible: viewDetails.expanded |
| 189 | + Layout.preferredWidth: Math.min(300, parent.width - 2 * Layout.leftMargin) |
| 190 | + Layout.alignment: Qt.AlignCenter |
| 191 | + Layout.leftMargin: 80 |
| 192 | + Layout.rightMargin: 80 |
| 193 | + Layout.topMargin: 10 |
| 194 | + spacing: 10 |
| 195 | + // TODO: make sure the block height number aligns right |
| 196 | + RowLayout { |
| 197 | + CoreText { |
| 198 | + text: qsTr("Block Height:") |
| 199 | + Layout.alignment: Qt.AlignLeft |
| 200 | + font.pixelSize: 14 |
| 201 | + } |
| 202 | + CoreText { |
| 203 | + text: snapshotInfo && snapshotInfo["height"] ? |
| 204 | + snapshotInfo["height"] : qsTr("DEBUG") |
| 205 | + Layout.alignment: Qt.AlignRight |
| 206 | + font.pixelSize: 14 |
| 207 | + } |
| 208 | + } |
| 209 | + Separator { Layout.fillWidth: true } |
| 210 | + ColumnLayout { |
| 211 | + Layout.fillWidth: true |
| 212 | + spacing: 5 |
| 213 | + CoreText { |
| 214 | + text: qsTr("Hash:") |
| 215 | + font.pixelSize: 14 |
| 216 | + } |
| 217 | + CoreText { |
| 218 | + text: snapshotInfo && snapshotInfo["hashSerializedFirstHalf"] ? |
| 219 | + snapshotInfo["hashSerializedFirstHalf"] + "\n" + snapshotInfo["hashSerializedSecondHalf"] : |
| 220 | + qsTr("DEBUG") |
| 221 | + Layout.fillWidth: true |
| 222 | + font.pixelSize: 14 |
| 223 | + textFormat: Text.PlainText |
| 224 | + } |
| 225 | + } |
| 226 | + } |
| 227 | + } |
| 228 | + } |
| 229 | +} |
0 commit comments