|
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> |
31 | 33 | #include <QMessageBox> |
32 | 34 | #include <QSystemTrayIcon> |
33 | 35 | #include <QTimer> |
| 36 | +#include <QProgressDialog> |
| 37 | + |
| 38 | +#include <interfaces/handler.h> |
34 | 39 |
|
35 | 40 | int setFontChoice(QComboBox* cb, const OptionsModel::FontChoice& fc) |
36 | 41 | { |
@@ -121,6 +126,10 @@ OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet) |
121 | 126 | connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyPortTor, &QWidget::setEnabled); |
122 | 127 | connect(ui->connectSocksTor, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState); |
123 | 128 |
|
| 129 | + QPushButton* loadSnapshotButton = new QPushButton(tr("Load Snapshot..."), this); |
| 130 | + ui->verticalLayout_Main->insertWidget(ui->verticalLayout_Main->indexOf(ui->enableServer) + 1, loadSnapshotButton); |
| 131 | + connect(loadSnapshotButton, &QPushButton::clicked, this, &OptionsDialog::on_loadSnapshotButton_clicked); |
| 132 | + |
124 | 133 | /* Window elements init */ |
125 | 134 | #ifdef Q_OS_MACOS |
126 | 135 | /* remove Window tab on Mac */ |
@@ -400,6 +409,51 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state) |
400 | 409 | } |
401 | 410 | } |
402 | 411 |
|
| 412 | +void OptionsDialog::on_loadSnapshotButton_clicked() |
| 413 | +{ |
| 414 | + QString filename = QFileDialog::getOpenFileName(this, |
| 415 | + tr("Load Snapshot"), |
| 416 | + tr("Bitcoin Snapshot Files (*.dat);;")); |
| 417 | + |
| 418 | + if (filename.isEmpty()) return; |
| 419 | + |
| 420 | + QMessageBox::StandardButton retval = QMessageBox::question(this, tr("Confirm snapshot load"), |
| 421 | + tr("Are you sure you want to load this snapshot? This will delete your current blockchain data."), |
| 422 | + QMessageBox::Yes | QMessageBox::Cancel, |
| 423 | + QMessageBox::Cancel); |
| 424 | + |
| 425 | + if (retval != QMessageBox::Yes) return; |
| 426 | + |
| 427 | + QProgressDialog* progress = new QProgressDialog(tr("Loading snapshot..."), tr("Cancel"), 0, 100, this); |
| 428 | + progress->setWindowModality(Qt::WindowModal); |
| 429 | + progress->setMinimumDuration(0); |
| 430 | + progress->setValue(0); |
| 431 | + progress->show(); |
| 432 | + |
| 433 | + // Store the handler in the member variable to keep it alive |
| 434 | + m_snapshot_load_handler = model->node().handleSnapshotLoadProgress( |
| 435 | + [progress](double p) { |
| 436 | + progress->setValue(static_cast<int>(p * 100)); |
| 437 | + QApplication::processEvents(); |
| 438 | + }); |
| 439 | + |
| 440 | + SnapshotModel snapshotModel(model->node(), filename); |
| 441 | + bool success = snapshotModel.processPath(); |
| 442 | + |
| 443 | + // Clean up the progress dialog |
| 444 | + progress->close(); |
| 445 | + progress->deleteLater(); |
| 446 | + |
| 447 | + // Clean up the handler |
| 448 | + m_snapshot_load_handler.reset(); |
| 449 | + |
| 450 | + if (success) { |
| 451 | + QMessageBox::information(this, tr("Success"), tr("Snapshot loaded successfully")); |
| 452 | + } else { |
| 453 | + QMessageBox::critical(this, tr("Error"), tr("Error loading snapshot")); |
| 454 | + } |
| 455 | +} |
| 456 | + |
403 | 457 | void OptionsDialog::togglePruneWarning(bool enabled) |
404 | 458 | { |
405 | 459 | ui->pruneWarning->setVisible(!ui->pruneWarning->isVisible()); |
|
0 commit comments