Skip to content

Commit 5e0f7b4

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.
1 parent 4e43df9 commit 5e0f7b4

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ColumnLayout {
5959
Layout.topMargin: 20
6060
color: Theme.color.neutral6
6161
font.pixelSize: 17
62-
visible: !headersSynced
62+
visible: !headersSynced && !onboarding
6363
text: !headersSynced
6464
? qsTr("Please wait for headers to sync before loading a snapshot.")
6565
: qsTr("")
@@ -75,7 +75,7 @@ ColumnLayout {
7575
Layout.bottomMargin: 20
7676
Layout.alignment: Qt.AlignCenter
7777
text: qsTr("Choose snapshot file")
78-
enabled: headersSynced
78+
enabled: headersSynced || onboarding
7979
onClicked: fileDialog.open()
8080
}
8181

@@ -88,7 +88,12 @@ ColumnLayout {
8888
onAccepted: {
8989
selectedFile = fileUrl.toString()
9090
snapshotFileName = selectedFile
91-
nodeModel.snapshotLoadThread(snapshotFileName)
91+
if (!onboarding) {
92+
nodeModel.snapshotLoadThread(snapshotFileName)
93+
} else {
94+
nodeModel.setSnapshotFilePath(snapshotFileName)
95+
back()
96+
}
9297
}
9398
}
9499
// TODO: Handle file error signal

src/qml/models/nodemodel.cpp

Lines changed: 16 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

@@ -236,6 +236,7 @@ void NodeModel::setHeadersSynced(bool new_synced) {
236236
if (new_synced != m_headers_synced) {
237237
m_headers_synced = new_synced;
238238
Q_EMIT headersSyncedChanged();
239+
checkAndLoadSnapshot();
239240
}
240241
}
241242

@@ -245,3 +246,17 @@ void NodeModel::setIsIBDCompleted(bool new_completed) {
245246
Q_EMIT isIBDCompletedChanged();
246247
}
247248
}
249+
250+
void NodeModel::setSnapshotFilePath(const QString& new_path) {
251+
if (new_path != m_snapshot_file_path) {
252+
m_snapshot_file_path = new_path;
253+
Q_EMIT snapshotFilePathChanged();
254+
}
255+
}
256+
257+
void NodeModel::checkAndLoadSnapshot()
258+
{
259+
if (m_headers_synced && !m_snapshot_file_path.isEmpty()) {
260+
snapshotLoadThread(m_snapshot_file_path);
261+
}
262+
}

src/qml/models/nodemodel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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)
4243

4344
public:
4445
explicit NodeModel(interfaces::Node& node);
@@ -65,6 +66,8 @@ class NodeModel : public QObject
6566
void setHeadersSynced(bool new_synced);
6667
bool isIBDCompleted() const { return m_is_ibd_completed; }
6768
void setIsIBDCompleted(bool new_completed);
69+
QString snapshotFilePath() const { return m_snapshot_file_path; }
70+
Q_INVOKABLE void setSnapshotFilePath(const QString& new_path);
6871

6972
Q_INVOKABLE float getTotalBytesReceived() const { return (float)m_node.getTotalBytesRecv(); }
7073
Q_INVOKABLE float getTotalBytesSent() const { return (float)m_node.getTotalBytesSent(); }
@@ -73,6 +76,7 @@ class NodeModel : public QObject
7376
Q_INVOKABLE void requestShutdown();
7477

7578
Q_INVOKABLE void snapshotLoadThread(QString path_file);
79+
Q_INVOKABLE void checkAndLoadSnapshot();
7680

7781
void startShutdownPolling();
7882
void stopShutdownPolling();
@@ -102,6 +106,7 @@ public Q_SLOTS:
102106
void showProgress(const QString& title, int progress);
103107
void headersSyncedChanged();
104108
void isIBDCompletedChanged();
109+
void snapshotFilePathChanged();
105110
protected:
106111
void timerEvent(QTimerEvent* event) override;
107112

@@ -121,7 +126,7 @@ public Q_SLOTS:
121126
bool m_snapshot_loaded{false};
122127
bool m_headers_synced{false};
123128
bool m_is_ibd_completed{false};
124-
129+
QString m_snapshot_file_path;
125130
QVector<QPair<int, double>> m_block_process_time;
126131

127132
interfaces::Node& m_node;

0 commit comments

Comments
 (0)