gui: Add Intro::UpdateFreeSpaceLabel()

If a new custom datadir has enough free space, the prune checkbox gets
unchecked, unless -prune=NNN command-line option is provided.
This commit is contained in:
Hennadii Stepanov 2019-12-08 17:18:15 +02:00
parent daa3f3fa90
commit 4824a7d36c
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 21 additions and 12 deletions

View file

@ -251,24 +251,31 @@ void Intro::setStatus(int status, const QString &message, quint64 bytesAvailable
{ {
ui->freeSpace->setText(""); ui->freeSpace->setText("");
} else { } else {
QString freeString = tr("%n GB of free space available", "", bytesAvailable/GB_BYTES); m_bytes_available = bytesAvailable;
if (bytesAvailable < m_required_space_gb * GB_BYTES) { if (ui->prune->isEnabled()) {
freeString += " " + tr("(of %n GB needed)", "", m_required_space_gb); ui->prune->setChecked(m_bytes_available < (m_blockchain_size_gb + m_chain_state_size_gb + 10) * GB_BYTES);
ui->freeSpace->setStyleSheet("QLabel { color: #800000 }");
ui->prune->setChecked(true);
} else if (bytesAvailable / GB_BYTES - m_required_space_gb < 10) {
freeString += " " + tr("(%n GB needed for full chain)", "", m_required_space_gb);
ui->freeSpace->setStyleSheet("QLabel { color: #999900 }");
ui->prune->setChecked(true);
} else {
ui->freeSpace->setStyleSheet("");
} }
ui->freeSpace->setText(freeString + "."); UpdateFreeSpaceLabel();
} }
/* Don't allow confirm in ERROR state */ /* Don't allow confirm in ERROR state */
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status != FreespaceChecker::ST_ERROR); ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(status != FreespaceChecker::ST_ERROR);
} }
void Intro::UpdateFreeSpaceLabel()
{
QString freeString = tr("%n GB of free space available", "", m_bytes_available / GB_BYTES);
if (m_bytes_available < m_required_space_gb * GB_BYTES) {
freeString += " " + tr("(of %n GB needed)", "", m_required_space_gb);
ui->freeSpace->setStyleSheet("QLabel { color: #800000 }");
} else if (m_bytes_available / GB_BYTES - m_required_space_gb < 10) {
freeString += " " + tr("(%n GB needed for full chain)", "", m_required_space_gb);
ui->freeSpace->setStyleSheet("QLabel { color: #999900 }");
} else {
ui->freeSpace->setStyleSheet("");
}
ui->freeSpace->setText(freeString + ".");
}
void Intro::on_dataDirectory_textChanged(const QString &dataDirStr) void Intro::on_dataDirectory_textChanged(const QString &dataDirStr)
{ {
/* Disable OK button until check result comes in */ /* Disable OK button until check result comes in */

View file

@ -71,11 +71,13 @@ private:
const int64_t m_chain_state_size_gb; const int64_t m_chain_state_size_gb;
//! Total required space (in GB) depending on user choice (prune or not prune). //! Total required space (in GB) depending on user choice (prune or not prune).
int64_t m_required_space_gb{0}; int64_t m_required_space_gb{0};
uint64_t m_bytes_available{0};
void startThread(); void startThread();
void checkPath(const QString &dataDir); void checkPath(const QString &dataDir);
QString getPathToCheck(); QString getPathToCheck();
void UpdatePruneLabels(int64_t prune_target_gb); void UpdatePruneLabels(int64_t prune_target_gb);
void UpdateFreeSpaceLabel();
friend class FreespaceChecker; friend class FreespaceChecker;
}; };