|
12 | 12 | #include <qt/guiconstants.h>
|
13 | 13 | #include <qt/guiutil.h>
|
14 | 14 | #include <qt/optionsmodel.h>
|
| 15 | +#include <qt/snapshotmodel.h> |
15 | 16 |
|
16 | 17 | #include <common/system.h>
|
17 | 18 | #include <interfaces/node.h>
|
|
25 | 26 | #include <QApplication>
|
26 | 27 | #include <QDataWidgetMapper>
|
27 | 28 | #include <QDir>
|
| 29 | +#include <QFileDialog> |
28 | 30 | #include <QFontDialog>
|
29 | 31 | #include <QIntValidator>
|
30 | 32 | #include <QLocale>
|
@@ -121,6 +123,10 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)
|
121 | 123 | connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyPortTor, &QWidget::setEnabled);
|
122 | 124 | connect(ui->connectSocksTor, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState);
|
123 | 125 |
|
| 126 | + QPushButton* loadSnapshotButton = new QPushButton(tr("Load Snapshot..."), this); |
| 127 | + ui->verticalLayout_Main->insertWidget(ui->verticalLayout_Main->indexOf(ui->enableServer) + 1, loadSnapshotButton); |
| 128 | + connect(loadSnapshotButton, &QPushButton::clicked, this, &OptionsDialog::on_loadSnapshotButton_clicked); |
| 129 | + |
124 | 130 | /* Window elements init */
|
125 | 131 | #ifdef Q_OS_MACOS
|
126 | 132 | /* remove Window tab on Mac */
|
@@ -400,6 +406,34 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state)
|
400 | 406 | }
|
401 | 407 | }
|
402 | 408 |
|
| 409 | +void OptionsDialog::on_loadSnapshotButton_clicked() |
| 410 | +{ |
| 411 | + QString snapshotFile = QFileDialog::getOpenFileName(this, |
| 412 | + tr("Select Snapshot File"), "", |
| 413 | + tr("Bitcoin Snapshot Files (*.dat);;All Files (*)")); |
| 414 | + |
| 415 | + if (snapshotFile.isEmpty()) |
| 416 | + return; |
| 417 | + |
| 418 | + QMessageBox::StandardButton reply = QMessageBox::question(this, |
| 419 | + tr("Load Snapshot"), |
| 420 | + tr("Loading a snapshot will require restarting Bitcoin. The current blockchain data will be replaced with the snapshot data. Are you sure you want to proceed?"), |
| 421 | + QMessageBox::Yes|QMessageBox::No); |
| 422 | + |
| 423 | + if (reply == QMessageBox::Yes) { |
| 424 | + SnapshotModel snapshotModel(model->node(), snapshotFile); |
| 425 | + if (snapshotModel.processPath()) { |
| 426 | + QMessageBox::information(this, |
| 427 | + tr("Snapshot loaded successfully"), |
| 428 | + tr("The snapshot has been loaded successfully. You can now start the client with the new snapshot.")); |
| 429 | + } else { |
| 430 | + QMessageBox::critical(this, |
| 431 | + tr("Error"), |
| 432 | + tr("Failed to load the snapshot. Please ensure the file is a valid snapshot and try again.")); |
| 433 | + } |
| 434 | + } |
| 435 | +} |
| 436 | + |
403 | 437 | void OptionsDialog::togglePruneWarning(bool enabled)
|
404 | 438 | {
|
405 | 439 | ui->pruneWarning->setVisible(!ui->pruneWarning->isVisible());
|
|
0 commit comments