diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -73,8 +73,8 @@ void parameterSetup(); /// Create options model void createOptionsModel(bool resetSettings); - /// Update prune value - void SetPrune(bool prune, bool force = false); + /// Initialize prune setting + void InitializePruneSetting(bool prune); /// Create main window void createWindow(const Config *, const NetworkStyle *networkStyle); /// Create splash screen diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -320,8 +320,10 @@ InitParameterInteraction(gArgs); } -void BitcoinApplication::SetPrune(bool prune, bool force) { - optionsModel->SetPrune(prune, force); +void BitcoinApplication::InitializePruneSetting(bool prune) { + // If prune is set, intentionally override existing prune size with + // the default size since this is called when choosing a new datadir. + optionsModel->SetPruneTargetGB(prune ? DEFAULT_PRUNE_TARGET_GB : 0, true); } void BitcoinApplication::requestInitialize( @@ -748,7 +750,7 @@ if (did_show_intro) { // Store intro dialog settings other than datadir (network specific) - app.SetPrune(prune, true); + app.InitializePruneSetting(prune); } // Get global config diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -51,4 +51,7 @@ /* One gigabyte (GB) in bytes */ static constexpr uint64_t GB_BYTES{1'000'000'000}; +// Default prune target displayed in GUI. +static constexpr int DEFAULT_PRUNE_TARGET_GB{2}; + #endif // BITCOIN_QT_GUICONSTANTS_H diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -130,9 +130,10 @@ ui->prune->setChecked(true); ui->prune->setEnabled(false); } - ui->prune->setText(tr("Discard blocks after verification, except most " - "recent %1 GB (prune)") - .arg(pruneTarget ? pruneTarget / 1000 : 2)); + ui->prune->setText( + tr("Discard blocks after verification, except most " + "recent %1 GB (prune)") + .arg(pruneTarget ? pruneTarget / 1000 : DEFAULT_PRUNE_TARGET_GB)); requiredSpace = m_blockchain_size; QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it " diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -85,7 +85,8 @@ } /* Explicit setters */ - void SetPrune(bool prune, bool force = false); + void SetPruneEnabled(bool prune, bool force = false); + void SetPruneTargetGB(int prune_target_gb, bool force = false); /* Restart flag helper */ void setRestartRequired(bool fRequired); diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -102,9 +102,9 @@ settings.setValue("bPrune", false); } if (!settings.contains("nPruneSize")) { - settings.setValue("nPruneSize", 2); + settings.setValue("nPruneSize", DEFAULT_PRUNE_TARGET_GB); } - SetPrune(settings.value("bPrune").toBool()); + SetPruneEnabled(settings.value("bPrune").toBool()); if (!settings.contains("nDatabaseCache")) { settings.setValue("nDatabaseCache", (qint64)DEFAULT_DB_CACHE_MB); @@ -283,7 +283,7 @@ .arg(DEFAULT_GUI_PROXY_PORT); } -void OptionsModel::SetPrune(bool prune, bool force) { +void OptionsModel::SetPruneEnabled(bool prune, bool force) { QSettings settings; settings.setValue("bPrune", prune); // Convert prune size from GB to MiB: @@ -299,6 +299,15 @@ } } +void OptionsModel::SetPruneTargetGB(int prune_target_gb, bool force) { + const bool prune = prune_target_gb > 0; + if (prune) { + QSettings settings; + settings.setValue("nPruneSize", prune_target_gb); + } + SetPruneEnabled(prune, force); +} + // read QSettings values and return them QVariant OptionsModel::data(const QModelIndex &index, int role) const { if (role == Qt::EditRole) {