mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-20 14:05:23 +01:00
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.
This commit is contained in:
parent
295211e668
commit
e35e4b2ba0
2 changed files with 15 additions and 8 deletions
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <qt/guiconstants.h>
|
||||
#include <qt/guiutil.h>
|
||||
#include <qt/optionsmodel.h>
|
||||
|
||||
#include <interfaces/node.h>
|
||||
#include <util/system.h>
|
||||
|
@ -23,7 +24,7 @@
|
|||
#include <cmath>
|
||||
|
||||
/* Total required space (in GB) depending on user choice (prune, not prune) */
|
||||
static uint64_t requiredSpace;
|
||||
static int64_t requiredSpace;
|
||||
|
||||
/* Check free space asynchronously to prevent hanging the UI thread.
|
||||
|
||||
|
@ -130,18 +131,18 @@ Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_siz
|
|||
);
|
||||
ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
|
||||
|
||||
uint64_t pruneTarget = std::max<int64_t>(0, gArgs.GetArg("-prune", 0));
|
||||
if (pruneTarget > 1) { // -prune=1 means enabled, above that it's a size in MB
|
||||
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
|
||||
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 : DEFAULT_PRUNE_TARGET_GB));
|
||||
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));
|
||||
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) {
|
||||
uint64_t prunedGBs = std::ceil(pruneTarget * 1024 * 1024.0 / GB_BYTES);
|
||||
if (prunedGBs <= requiredSpace) {
|
||||
requiredSpace = prunedGBs;
|
||||
if (prune_target_gb) {
|
||||
if (prune_target_gb <= requiredSpace) {
|
||||
requiredSpace = prune_target_gb;
|
||||
storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory.");
|
||||
}
|
||||
ui->lblExplanation3->setVisible(true);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define BITCOIN_QT_OPTIONSMODEL_H
|
||||
|
||||
#include <amount.h>
|
||||
#include <qt/guiconstants.h>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
|
||||
|
@ -16,6 +17,11 @@ class Node;
|
|||
extern const char *DEFAULT_GUI_PROXY_HOST;
|
||||
static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050;
|
||||
|
||||
/**
|
||||
* Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.
|
||||
*/
|
||||
static inline int PruneMiBtoGB(int64_t mib) { return (mib * 1024 * 1024 + GB_BYTES - 1) / GB_BYTES; }
|
||||
|
||||
/** Interface from Qt to configuration data structure for Bitcoin client.
|
||||
To Qt, the options are presented as a list with the different options
|
||||
laid out vertically.
|
||||
|
|
Loading…
Add table
Reference in a new issue