|
12 | 12 |
|
13 | 13 | #include <qt/guiconstants.h>
|
14 | 14 | #include <qt/guiutil.h>
|
| 15 | +#include <qt/optionsmodel.h> |
15 | 16 |
|
16 | 17 | #include <interfaces/node.h>
|
17 | 18 | #include <util/system.h>
|
|
22 | 23 |
|
23 | 24 | #include <cmath>
|
24 | 25 |
|
25 |
| -/* Total required space (in GB) depending on user choice (prune, not prune) */ |
26 |
| -static uint64_t requiredSpace; |
27 |
| - |
28 | 26 | /* Check free space asynchronously to prevent hanging the UI thread.
|
29 | 27 |
|
30 | 28 | Up to one request to check a path is in flight to this thread; when the check()
|
@@ -109,52 +107,49 @@ void FreespaceChecker::check()
|
109 | 107 | Q_EMIT reply(replyStatus, replyMessage, freeBytesAvailable);
|
110 | 108 | }
|
111 | 109 |
|
| 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 |
112 | 119 |
|
113 |
| -Intro::Intro(QWidget *parent, uint64_t blockchain_size, uint64_t chain_state_size) : |
| 120 | +Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) : |
114 | 121 | QDialog(parent),
|
115 | 122 | ui(new Ui::Intro),
|
116 | 123 | thread(nullptr),
|
117 | 124 | signalled(false),
|
118 |
| - m_blockchain_size(blockchain_size), |
119 |
| - m_chain_state_size(chain_state_size) |
| 125 | + m_blockchain_size_gb(blockchain_size_gb), |
| 126 | + m_chain_state_size_gb(chain_state_size_gb), |
| 127 | + m_prune_target_gb{GetPruneTargetGB()} |
120 | 128 | {
|
121 | 129 | ui->setupUi(this);
|
122 | 130 | ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(PACKAGE_NAME));
|
123 | 131 | ui->storageLabel->setText(ui->storageLabel->text().arg(PACKAGE_NAME));
|
124 | 132 |
|
125 | 133 | ui->lblExplanation1->setText(ui->lblExplanation1->text()
|
126 | 134 | .arg(PACKAGE_NAME)
|
127 |
| - .arg(m_blockchain_size) |
| 135 | + .arg(m_blockchain_size_gb) |
128 | 136 | .arg(2009)
|
129 | 137 | .arg(tr("Bitcoin"))
|
130 | 138 | );
|
131 | 139 | ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(PACKAGE_NAME));
|
132 | 140 |
|
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 |
| 141 | + if (gArgs.GetArg("-prune", 0) > 1) { // -prune=1 means enabled, above that it's a size in MiB |
135 | 142 | ui->prune->setChecked(true);
|
136 | 143 | ui->prune->setEnabled(false);
|
137 | 144 | }
|
138 |
| - ui->prune->setText(tr("Discard blocks after verification, except most recent %1 GB (prune)").arg(pruneTarget ? pruneTarget / 1000 : DEFAULT_PRUNE_TARGET_GB)); |
139 |
| - requiredSpace = m_blockchain_size; |
140 |
| - 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; |
145 |
| - storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory."); |
146 |
| - } |
147 |
| - ui->lblExplanation3->setVisible(true); |
148 |
| - } else { |
149 |
| - ui->lblExplanation3->setVisible(false); |
150 |
| - } |
151 |
| - requiredSpace += m_chain_state_size; |
152 |
| - ui->sizeWarningLabel->setText( |
153 |
| - tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + |
154 |
| - storageRequiresMsg.arg(requiredSpace) + " " + |
155 |
| - tr("The wallet will also be stored in this directory.") |
156 |
| - ); |
157 |
| - this->adjustSize(); |
| 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 | + |
158 | 153 | startThread();
|
159 | 154 | }
|
160 | 155 |
|
@@ -270,25 +265,31 @@ void Intro::setStatus(int status, const QString &message, quint64 bytesAvailable
|
270 | 265 | {
|
271 | 266 | ui->freeSpace->setText("");
|
272 | 267 | } else {
|
273 |
| - QString freeString = tr("%n GB of free space available", "", bytesAvailable/GB_BYTES); |
274 |
| - if(bytesAvailable < requiredSpace * GB_BYTES) |
275 |
| - { |
276 |
| - freeString += " " + tr("(of %n GB needed)", "", requiredSpace); |
277 |
| - ui->freeSpace->setStyleSheet("QLabel { color: #800000 }"); |
278 |
| - ui->prune->setChecked(true); |
279 |
| - } else if (bytesAvailable / GB_BYTES - requiredSpace < 10) { |
280 |
| - freeString += " " + tr("(%n GB needed for full chain)", "", requiredSpace); |
281 |
| - ui->freeSpace->setStyleSheet("QLabel { color: #999900 }"); |
282 |
| - ui->prune->setChecked(true); |
283 |
| - } else { |
284 |
| - ui->freeSpace->setStyleSheet(""); |
| 268 | + m_bytes_available = bytesAvailable; |
| 269 | + if (ui->prune->isEnabled()) { |
| 270 | + ui->prune->setChecked(m_bytes_available < (m_blockchain_size_gb + m_chain_state_size_gb + 10) * GB_BYTES); |
285 | 271 | }
|
286 |
| - ui->freeSpace->setText(freeString + "."); |
| 272 | + UpdateFreeSpaceLabel(); |
287 | 273 | }
|
288 | 274 | /* Don't allow confirm in ERROR state */
|
289 | 275 | ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status != FreespaceChecker::ST_ERROR);
|
290 | 276 | }
|
291 | 277 |
|
| 278 | +void Intro::UpdateFreeSpaceLabel() |
| 279 | +{ |
| 280 | + QString freeString = tr("%n GB of free space available", "", m_bytes_available / GB_BYTES); |
| 281 | + if (m_bytes_available < m_required_space_gb * GB_BYTES) { |
| 282 | + freeString += " " + tr("(of %n GB needed)", "", m_required_space_gb); |
| 283 | + ui->freeSpace->setStyleSheet("QLabel { color: #800000 }"); |
| 284 | + } else if (m_bytes_available / GB_BYTES - m_required_space_gb < 10) { |
| 285 | + freeString += " " + tr("(%n GB needed for full chain)", "", m_required_space_gb); |
| 286 | + ui->freeSpace->setStyleSheet("QLabel { color: #999900 }"); |
| 287 | + } else { |
| 288 | + ui->freeSpace->setStyleSheet(""); |
| 289 | + } |
| 290 | + ui->freeSpace->setText(freeString + "."); |
| 291 | +} |
| 292 | + |
292 | 293 | void Intro::on_dataDirectory_textChanged(const QString &dataDirStr)
|
293 | 294 | {
|
294 | 295 | /* Disable OK button until check result comes in */
|
@@ -349,3 +350,20 @@ QString Intro::getPathToCheck()
|
349 | 350 | mutex.unlock();
|
350 | 351 | return retval;
|
351 | 352 | }
|
| 353 | + |
| 354 | +void Intro::UpdatePruneLabels(bool prune_checked) |
| 355 | +{ |
| 356 | + m_required_space_gb = m_blockchain_size_gb + m_chain_state_size_gb; |
| 357 | + QString storageRequiresMsg = tr("At least %1 GB of data will be stored in this directory, and it will grow over time."); |
| 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; |
| 360 | + storageRequiresMsg = tr("Approximately %1 GB of data will be stored in this directory."); |
| 361 | + } |
| 362 | + ui->lblExplanation3->setVisible(prune_checked); |
| 363 | + ui->sizeWarningLabel->setText( |
| 364 | + tr("%1 will download and store a copy of the Bitcoin block chain.").arg(PACKAGE_NAME) + " " + |
| 365 | + storageRequiresMsg.arg(m_required_space_gb) + " " + |
| 366 | + tr("The wallet will also be stored in this directory.") |
| 367 | + ); |
| 368 | + this->adjustSize(); |
| 369 | +} |
0 commit comments