Skip to content

Commit cac8de9

Browse files
committed
qml: Enable snapshot load path setting during onboarding
- Update visibility conditions in ConnectionSettings and SnapshotSettings to enable loading during onboarding. - Introduce new methods in NodeModel for handling snapshot file paths and loading logic based on header sync status. - Ensure snapshot loading is triggered appropriately when headers are synced and a snapshot file path is set. - Adds error handling on snapshot failure.
1 parent 7904b8c commit cac8de9

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

src/qml/components/ConnectionSettings.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ColumnLayout {
1717
spacing: 4
1818
Setting {
1919
id: gotoSnapshot
20-
visible: !root.onboarding && !snapshotImportCompleted && !root.isIBDCompleted
20+
visible: !snapshotImportCompleted && !root.isIBDCompleted
2121
Layout.fillWidth: true
2222
header: qsTr("Load snapshot")
2323
description: qsTr("Instant use with background sync")
@@ -39,7 +39,7 @@ ColumnLayout {
3939
onClicked: root.gotoSnapshot()
4040
}
4141
Separator {
42-
visible: !root.onboarding && !snapshotImportCompleted && !root.isIBDCompleted
42+
visible: !snapshotImportCompleted && !root.isIBDCompleted
4343
Layout.fillWidth: true
4444
}
4545
Setting {

src/qml/components/SnapshotSettings.qml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ColumnLayout {
2121
property var snapshotInfo: (snapshotVerified || snapshotLoaded) ? chainModel.getSnapshotInfo() : ({})
2222
property string selectedFile: ""
2323
property bool headersSynced: nodeModel.headersSynced
24-
property bool snapshotError: false
24+
property bool snapshotError: nodeModel.snapshotError
2525

2626
width: Math.min(parent.width, 450)
2727
anchors.horizontalCenter: parent.horizontalCenter
@@ -60,7 +60,7 @@ ColumnLayout {
6060
Layout.topMargin: 20
6161
color: Theme.color.neutral6
6262
font.pixelSize: 17
63-
visible: !headersSynced
63+
visible: !headersSynced && !onboarding
6464
text: !headersSynced
6565
? qsTr("Please wait for headers to sync before loading a snapshot.")
6666
: qsTr("")
@@ -76,7 +76,7 @@ ColumnLayout {
7676
Layout.bottomMargin: 20
7777
Layout.alignment: Qt.AlignCenter
7878
text: qsTr("Choose snapshot file")
79-
enabled: headersSynced
79+
enabled: headersSynced || onboarding
8080
onClicked: fileDialog.open()
8181
}
8282

@@ -89,8 +89,11 @@ ColumnLayout {
8989
onAccepted: {
9090
selectedFile = fileUrl.toString()
9191
snapshotFileName = selectedFile
92-
if (!nodeModel.snapshotLoadThread(snapshotFileName)) {
93-
snapshotError = true
92+
if (!onboarding) {
93+
nodeModel.snapshotLoadThread(snapshotFileName)
94+
} else {
95+
nodeModel.setSnapshotFilePath(snapshotFileName)
96+
back()
9497
}
9598
}
9699
}
@@ -259,7 +262,7 @@ ColumnLayout {
259262
Layout.alignment: Qt.AlignCenter
260263
text: qsTr("OK")
261264
onClicked: {
262-
snapshotError = false
265+
nodeModel.setSnapshotError(false)
263266
back()
264267
}
265268
}

src/qml/models/nodemodel.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void NodeModel::setVerificationProgress(double new_progress)
8686
if (new_progress != m_verification_progress) {
8787
setRemainingSyncTime(new_progress);
8888

89-
if (new_progress >= 0.00001) {
89+
if (new_progress >= 0.00014) {
9090
setHeadersSynced(true);
9191
}
9292

@@ -213,6 +213,8 @@ void NodeModel::snapshotLoadThread(QString path_file) {
213213
if (!result) {
214214
m_snapshot_loading = false;
215215
Q_EMIT snapshotLoadingChanged();
216+
m_snapshot_error = true;
217+
Q_EMIT snapshotErrorChanged();
216218
} else {
217219
m_snapshot_loaded = true;
218220
Q_EMIT snapshotLoaded(result);
@@ -236,6 +238,7 @@ void NodeModel::setHeadersSynced(bool new_synced) {
236238
if (new_synced != m_headers_synced) {
237239
m_headers_synced = new_synced;
238240
Q_EMIT headersSyncedChanged();
241+
checkAndLoadSnapshot();
239242
}
240243
}
241244

@@ -245,3 +248,24 @@ void NodeModel::setIsIBDCompleted(bool new_completed) {
245248
Q_EMIT isIBDCompletedChanged();
246249
}
247250
}
251+
252+
void NodeModel::setSnapshotFilePath(const QString& new_path) {
253+
if (new_path != m_snapshot_file_path) {
254+
m_snapshot_file_path = new_path;
255+
Q_EMIT snapshotFilePathChanged();
256+
}
257+
}
258+
259+
void NodeModel::checkAndLoadSnapshot()
260+
{
261+
if (m_headers_synced && !m_snapshot_file_path.isEmpty()) {
262+
snapshotLoadThread(m_snapshot_file_path);
263+
}
264+
}
265+
266+
void NodeModel::setSnapshotError(bool new_error) {
267+
if (new_error != m_snapshot_error) {
268+
m_snapshot_error = new_error;
269+
Q_EMIT snapshotErrorChanged();
270+
}
271+
}

src/qml/models/nodemodel.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class NodeModel : public QObject
3939
Q_PROPERTY(bool isSnapshotLoaded READ isSnapshotLoaded NOTIFY snapshotLoaded)
4040
Q_PROPERTY(bool headersSynced READ headersSynced WRITE setHeadersSynced NOTIFY headersSyncedChanged)
4141
Q_PROPERTY(bool isIBDCompleted READ isIBDCompleted WRITE setIsIBDCompleted NOTIFY isIBDCompletedChanged)
42+
Q_PROPERTY(QString snapshotFilePath READ snapshotFilePath WRITE setSnapshotFilePath NOTIFY snapshotFilePathChanged)
43+
Q_PROPERTY(bool snapshotError READ snapshotError WRITE setSnapshotError NOTIFY snapshotErrorChanged)
4244

4345
public:
4446
explicit NodeModel(interfaces::Node& node);
@@ -65,6 +67,10 @@ class NodeModel : public QObject
6567
void setHeadersSynced(bool new_synced);
6668
bool isIBDCompleted() const { return m_is_ibd_completed; }
6769
void setIsIBDCompleted(bool new_completed);
70+
QString snapshotFilePath() const { return m_snapshot_file_path; }
71+
Q_INVOKABLE void setSnapshotFilePath(const QString& new_path);
72+
bool snapshotError() const { return m_snapshot_error; }
73+
Q_INVOKABLE void setSnapshotError(bool new_error);
6874

6975
Q_INVOKABLE float getTotalBytesReceived() const { return (float)m_node.getTotalBytesRecv(); }
7076
Q_INVOKABLE float getTotalBytesSent() const { return (float)m_node.getTotalBytesSent(); }
@@ -73,6 +79,7 @@ class NodeModel : public QObject
7379
Q_INVOKABLE void requestShutdown();
7480

7581
Q_INVOKABLE void snapshotLoadThread(QString path_file);
82+
Q_INVOKABLE void checkAndLoadSnapshot();
7683

7784
void startShutdownPolling();
7885
void stopShutdownPolling();
@@ -102,6 +109,8 @@ public Q_SLOTS:
102109
void showProgress(const QString& title, int progress);
103110
void headersSyncedChanged();
104111
void isIBDCompletedChanged();
112+
void snapshotFilePathChanged();
113+
void snapshotErrorChanged();
105114
protected:
106115
void timerEvent(QTimerEvent* event) override;
107116

@@ -121,7 +130,8 @@ public Q_SLOTS:
121130
bool m_snapshot_loaded{false};
122131
bool m_headers_synced{false};
123132
bool m_is_ibd_completed{false};
124-
133+
QString m_snapshot_file_path;
134+
bool m_snapshot_error{false};
125135
QVector<QPair<int, double>> m_block_process_time;
126136

127137
interfaces::Node& m_node;

0 commit comments

Comments
 (0)