Skip to content

Commit 4f7127d

Browse files
committed
gui: Make Intro consistent with prune checkbox
When prune checkbox is toggled, the related text labels and the amount of required space shown are updated (previously they were only updated when the data directory was updated).
1 parent 4824a7d commit 4f7127d

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/qt/intro.cpp

+24-10
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,24 @@ void FreespaceChecker::check()
107107
Q_EMIT reply(replyStatus, replyMessage, freeBytesAvailable);
108108
}
109109

110+
namespace {
111+
//! Return pruning size that will be used if automatic pruning is enabled.
112+
int GetPruneTargetGB()
113+
{
114+
int64_t prune_target_mib = gArgs.GetArg("-prune", 0);
115+
// >1 means automatic pruning is enabled by config, 1 means manual pruning, 0 means no pruning.
116+
return prune_target_mib > 1 ? PruneMiBtoGB(prune_target_mib) : DEFAULT_PRUNE_TARGET_GB;
117+
}
118+
} // namespace
110119

111120
Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) :
112121
QDialog(parent),
113122
ui(new Ui::Intro),
114123
thread(nullptr),
115124
signalled(false),
116125
m_blockchain_size_gb(blockchain_size_gb),
117-
m_chain_state_size_gb(chain_state_size_gb)
126+
m_chain_state_size_gb(chain_state_size_gb),
127+
m_prune_target_gb{GetPruneTargetGB()}
118128
{
119129
ui->setupUi(this);
120130
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
128138
);
129139
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
130140

131-
int64_t prune_target_mib = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
132-
if (prune_target_mib > 1) { // -prune=1 means enabled, above that it's a size in MiB
141+
if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB
133142
ui->prune->setChecked(true);
134143
ui->prune->setEnabled(false);
135144
}
136-
const int prune_target_gb = PruneMiBtoGB(prune_target_mib);
137-
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));
138-
UpdatePruneLabels(prune_target_gb);
145+
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(m_prune_target_gb));
146+
UpdatePruneLabels(ui->prune->isChecked());
147+
148+
connect(ui->prune, &QCheckBox::toggled, [this](bool prune_checked) {
149+
UpdatePruneLabels(prune_checked);
150+
UpdateFreeSpaceLabel();
151+
});
152+
139153
startThread();
140154
}
141155

@@ -337,15 +351,15 @@ QString Intro::getPathToCheck()
337351
return retval;
338352
}
339353

340-
void Intro::UpdatePruneLabels(int64_t prune_target_gb)
354+
void Intro::UpdatePruneLabels(bool prune_checked)
341355
{
342356
m_required_space_gb = m_blockchain_size_gb + m_chain_state_size_gb;
343357
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
344-
if (0 < prune_target_gb && prune_target_gb <= m_blockchain_size_gb) {
345-
m_required_space_gb = prune_target_gb + m_chain_state_size_gb;
358+
if (prune_checked && m_prune_target_gb <= m_blockchain_size_gb) {
359+
m_required_space_gb = m_prune_target_gb + m_chain_state_size_gb;
346360
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
347361
}
348-
ui->lblExplanation3->setVisible(prune_target_gb > 0);
362+
ui->lblExplanation3->setVisible(prune_checked);
349363
ui->sizeWarningLabel->setText(
350364
tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " +
351365
storageRequiresMsg.arg(m_required_space_gb) + " " +

src/qt/intro.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ private Q_SLOTS:
7272
//! Total required space (in GB) depending on user choice (prune or not prune).
7373
int64_t m_required_space_gb{0};
7474
uint64_t m_bytes_available{0};
75+
const int64_t m_prune_target_gb;
7576

7677
void startThread();
7778
void checkPath(const QString &dataDir);
7879
QString getPathToCheck();
79-
void UpdatePruneLabels(int64_t prune_target_gb);
80+
void UpdatePruneLabels(bool prune_checked);
8081
void UpdateFreeSpaceLabel();
8182

8283
friend class FreespaceChecker;

0 commit comments

Comments
 (0)