From a82bd8fa5708c16d1db3edc4e82d70788eb5af19 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 12 Nov 2019 12:03:29 +0200 Subject: [PATCH 1/4] util: Replace magics with DEFAULT_PRUNE_TARGET_GB This commit does not change behavior. --- src/qt/guiconstants.h | 3 +++ src/qt/intro.cpp | 2 +- src/qt/optionsmodel.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index dcdb2479770..3bc242d0dc4 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -51,4 +51,7 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80; /* One gigabyte (GB) in bytes */ static constexpr uint64_t GB_BYTES{1000000000}; +// 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 index 53c80639b99..34b43c26366 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -135,7 +135,7 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz 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 will grow over time."); if (pruneTarget) { diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index d74d0dbfebe..c721c801e1a 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -91,7 +91,7 @@ void OptionsModel::Init(bool resetSettings) if (!settings.contains("bPrune")) settings.setValue("bPrune", false); if (!settings.contains("nPruneSize")) - settings.setValue("nPruneSize", 2); + settings.setValue("nPruneSize", DEFAULT_PRUNE_TARGET_GB); SetPrune(settings.value("bPrune").toBool()); if (!settings.contains("nDatabaseCache")) From 68c9bbe9bc91f882404556998666b1b5acea60e4 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 12 Nov 2019 12:09:10 +0200 Subject: [PATCH 2/4] qt: Force set nPruneSize in QSettings after intro If QSettings is set already, it is required to force set nPruneSize after the intro dialog. --- src/qt/bitcoin.cpp | 7 +++++-- src/qt/optionsmodel.cpp | 14 ++++++++++++-- src/qt/optionsmodel.h | 3 ++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 676c15ea43b..9bee0090174 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -281,8 +281,11 @@ void BitcoinApplication::parameterSetup() m_node.initParameterInteraction(); } -void BitcoinApplication::SetPrune(bool prune, bool force) { - optionsModel->SetPrune(prune, force); +void BitcoinApplication::SetPrune(bool prune, bool force) +{ + // 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, force); } void BitcoinApplication::requestInitialize() diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp index c721c801e1a..1512babbc3a 100644 --- a/src/qt/optionsmodel.cpp +++ b/src/qt/optionsmodel.cpp @@ -92,7 +92,7 @@ void OptionsModel::Init(bool resetSettings) settings.setValue("bPrune", false); if (!settings.contains("nPruneSize")) 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)nDefaultDbCache); @@ -236,7 +236,7 @@ static const QString GetDefaultProxyAddress() return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).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); @@ -252,6 +252,16 @@ void OptionsModel::SetPrune(bool prune, bool force) } } +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 { diff --git a/src/qt/optionsmodel.h b/src/qt/optionsmodel.h index 5791b47f283..5089a405099 100644 --- a/src/qt/optionsmodel.h +++ b/src/qt/optionsmodel.h @@ -73,7 +73,8 @@ public: const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; } /* 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); From b0bfbe50282877a1eee87118902901a280d6656d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 7 Jan 2020 22:00:23 +0200 Subject: [PATCH 3/4] refactor: Drop `bool force' parameter --- src/qt/bitcoin.cpp | 6 +++--- src/qt/bitcoin.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 9bee0090174..e73740651de 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -281,11 +281,11 @@ void BitcoinApplication::parameterSetup() m_node.initParameterInteraction(); } -void BitcoinApplication::SetPrune(bool prune, bool force) +void BitcoinApplication::SetPrune(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, force); + optionsModel->SetPruneTargetGB(prune ? DEFAULT_PRUNE_TARGET_GB : 0, true); } void BitcoinApplication::requestInitialize() @@ -564,7 +564,7 @@ int GuiMain(int argc, char* argv[]) if (did_show_intro) { // Store intro dialog settings other than datadir (network specific) - app.SetPrune(prune, true); + app.SetPrune(prune); } if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index 8c77fd8a7d8..599481fb71b 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -68,7 +68,7 @@ public: /// Create options model void createOptionsModel(bool resetSettings); /// Update prune value - void SetPrune(bool prune, bool force = false); + void SetPrune(bool prune); /// Create main window void createWindow(const NetworkStyle *networkStyle); /// Create splash screen From af112ab62895b145660f4cd7ff842e9cfea2a530 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Tue, 7 Jan 2020 22:08:55 +0200 Subject: [PATCH 4/4] qt: Rename SetPrune() to InitializePruneSetting() This function now resets the prune size and is only called after the intro sequence. --- src/qt/bitcoin.cpp | 4 ++-- src/qt/bitcoin.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index e73740651de..266339f6eb6 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -281,7 +281,7 @@ void BitcoinApplication::parameterSetup() m_node.initParameterInteraction(); } -void BitcoinApplication::SetPrune(bool prune) +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. @@ -564,7 +564,7 @@ int GuiMain(int argc, char* argv[]) if (did_show_intro) { // Store intro dialog settings other than datadir (network specific) - app.SetPrune(prune); + app.InitializePruneSetting(prune); } if (gArgs.GetBoolArg("-splash", DEFAULT_SPLASHSCREEN) && !gArgs.GetBoolArg("-min", false)) diff --git a/src/qt/bitcoin.h b/src/qt/bitcoin.h index 599481fb71b..7c921e50314 100644 --- a/src/qt/bitcoin.h +++ b/src/qt/bitcoin.h @@ -67,8 +67,8 @@ public: void parameterSetup(); /// Create options model void createOptionsModel(bool resetSettings); - /// Update prune value - void SetPrune(bool prune); + /// Initialize prune setting + void InitializePruneSetting(bool prune); /// Create main window void createWindow(const NetworkStyle *networkStyle); /// Create splash screen