|
33 | 33 | #include <QMessageBox>
|
34 | 34 | #include <QSystemTrayIcon>
|
35 | 35 | #include <QTimer>
|
| 36 | +#include <QProgressDialog> |
| 37 | + |
| 38 | +#include <interfaces/handler.h> |
36 | 39 |
|
37 | 40 | int setFontChoice(QComboBox* cb, const OptionsModel::FontChoice& fc)
|
38 | 41 | {
|
@@ -408,29 +411,46 @@ void OptionsDialog::on_showTrayIcon_stateChanged(int state)
|
408 | 411 |
|
409 | 412 | void OptionsDialog::on_loadSnapshotButton_clicked()
|
410 | 413 | {
|
411 |
| - QString snapshotFile = QFileDialog::getOpenFileName(this, |
412 |
| - tr("Select Snapshot File"), "", |
413 |
| - tr("Bitcoin Snapshot Files (*.dat);;All Files (*)")); |
| 414 | + QString filename = QFileDialog::getOpenFileName(this, |
| 415 | + tr("Load Snapshot"), |
| 416 | + tr("Bitcoin Snapshot Files (*.dat);;")); |
414 | 417 |
|
415 |
| - if (snapshotFile.isEmpty()) |
416 |
| - return; |
| 418 | + if (filename.isEmpty()) return; |
417 | 419 |
|
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 |
| - } |
| 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")); |
434 | 454 | }
|
435 | 455 | }
|
436 | 456 |
|
|
0 commit comments