Skip to content

Commit e35e4b2

Browse files
committed
util: Add PruneMiBtoGB() function
Now the text of prune QCheckBox shows the space in GB instead of thousands MiB, which is consistent with other parts of the GUI.
1 parent 295211e commit e35e4b2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/qt/intro.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <qt/guiconstants.h>
1414
#include <qt/guiutil.h>
15+
#include <qt/optionsmodel.h>
1516

1617
#include <interfaces/node.h>
1718
#include <util/system.h>
@@ -23,7 +24,7 @@
2324
#include <cmath>
2425

2526
/* Total required space (in GB) depending on user choice (prune, not prune) */
26-
static uint64_t requiredSpace;
27+
static int64_t requiredSpace;
2728

2829
/* Check free space asynchronously to prevent hanging the UI thread.
2930
@@ -130,18 +131,18 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
130131
);
131132
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
132133

133-
uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
134-
if (pruneTarget > 1) { // -prune=1 means enabled, above that it's a size in MB
134+
int64_t prune_target_mib = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
135+
if (prune_target_mib > 1) { // -prune=1 means enabled, above that it's a size in MiB
135136
ui->prune->setChecked(true);
136137
ui->prune->setEnabled(false);
137138
}
138-
ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : DEFAULT_PRUNE_TARGET_GB));
139+
const int prune_target_gb = PruneMiBtoGB(prune_target_mib);
140+
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));
139141
requiredSpace = m_blockchain_size;
140142
QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time.");
141-
if (pruneTarget) {
142-
uint64_t prunedGBs = std::ceil(pruneTarget * 1024 * 1024.0 / GB_BYTES);
143-
if (prunedGBs <= requiredSpace) {
144-
requiredSpace = prunedGBs;
143+
if (prune_target_gb) {
144+
if (prune_target_gb <= requiredSpace) {
145+
requiredSpace = prune_target_gb;
145146
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
146147
}
147148
ui->lblExplanation3->setVisible(true);

src/qt/optionsmodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_QT_OPTIONSMODEL_H
77

88
#include <amount.h>
9+
#include <qt/guiconstants.h>
910

1011
#include <QAbstractListModel>
1112

@@ -16,6 +17,11 @@ class Node;
1617
extern const char *DEFAULT_GUI_PROXY_HOST;
1718
static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050;
1819

20+
/**
21+
* Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.
22+
*/
23+
static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
24+
1925
/** Interface from Qt to configuration data structure for Bitcoin client.
2026
To Qt, the options are presented as a list with the different options
2127
laid out vertically.

0 commit comments

Comments
 (0)