diff options
-rw-r--r-- | src/qt/intro.cpp | 34 | ||||
-rw-r--r-- | src/qt/intro.h | 3 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/qt/intro.cpp b/src/qt/intro.cpp index cb7b13260a..873d9dcd6f 100644 --- a/src/qt/intro.cpp +++ b/src/qt/intro.cpp @@ -107,6 +107,15 @@ void FreespaceChecker::check() Q_EMIT reply(replyStatus, replyMessage, freeBytesAvailable); } +namespace { +//! Return pruning size that will be used if automatic pruning is enabled. +int GetPruneTargetGB() +{ + int64_t prune_target_mib = gArgs.GetArg("-prune", 0); + // >1 means automatic pruning is enabled by config, 1 means manual pruning, 0 means no pruning. + return prune_target_mib > 1 ? PruneMiBtoGB(prune_target_mib) : DEFAULT_PRUNE_TARGET_GB; +} +} // namespace Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) : QDialog(parent), @@ -114,7 +123,8 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si thread(nullptr), signalled(false), m_blockchain_size_gb(blockchain_size_gb), - m_chain_state_size_gb(chain_state_size_gb) + m_chain_state_size_gb(chain_state_size_gb), + m_prune_target_gb{GetPruneTargetGB()} { ui->setupUi(this); ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(PACKAGE_NAME)); @@ -128,14 +138,18 @@ Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_si ); ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME)); - int64_t prune_target_mib = std::max<int64_t>(0, gArgs.GetArg("-prune", 0)); - if (prune_target_mib > 1) { // -prune=1 means enabled, above that it's a size in MiB + if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB ui->prune->setChecked(true); ui->prune->setEnabled(false); } - const int prune_target_gb = PruneMiBtoGB(prune_target_mib); - ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(prune_target_gb ? prune_target_gb : DEFAULT_PRUNE_TARGET_GB)); - UpdatePruneLabels(prune_target_gb); + ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(m_prune_target_gb)); + UpdatePruneLabels(ui->prune->isChecked()); + + connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) { + UpdatePruneLabels(prune_checked); + UpdateFreeSpaceLabel(); + }); + startThread(); } @@ -337,15 +351,15 @@ QString Intro::getPathToCheck() return retval; } -void Intro::UpdatePruneLabels(int64_t prune_target_gb) +void Intro::UpdatePruneLabels(bool prune_checked) { m_required_space_gb = m_blockchain_size_gb + m_chain_state_size_gb; QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time."); - if (0 < prune_target_gb && prune_target_gb <= m_blockchain_size_gb) { - m_required_space_gb = prune_target_gb + m_chain_state_size_gb; + if (prune_checked && m_prune_target_gb <= m_blockchain_size_gb) { + m_required_space_gb = m_prune_target_gb + m_chain_state_size_gb; storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory."); } - ui->lblExplanation3->setVisible(prune_target_gb > 0); + ui->lblExplanation3->setVisible(prune_checked); ui->sizeWarningLabel->setText( tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + storageRequiresMsg.arg(m_required_space_gb) + " " + diff --git a/src/qt/intro.h b/src/qt/intro.h index 8375847cc0..732393246e 100644 --- a/src/qt/intro.h +++ b/src/qt/intro.h @@ -72,11 +72,12 @@ private: //! Total required space (in GB) depending on user choice (prune or not prune). int64_t m_required_space_gb{0}; uint64_t m_bytes_available{0}; + const int64_t m_prune_target_gb; void startThread(); void checkPath(const QString &dataDir); QString getPathToCheck(); - void UpdatePruneLabels(int64_t prune_target_gb); + void UpdatePruneLabels(bool prune_checked); void UpdateFreeSpaceLabel(); friend class FreespaceChecker; |