5#include <bitcoin-build-config.h>
7#include <chainparams.h>
9#include <qt/forms/ui_intro.h>
21#include <validation.h>
39Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) :
42 m_blockchain_size_gb(blockchain_size_gb),
43 m_chain_state_size_gb(chain_state_size_gb),
44 m_prune_target_gb{GetPruneTargetGB()}
47 ui->welcomeLabel->setText(
ui->welcomeLabel->text().arg(CLIENT_NAME));
48 ui->storageLabel->setText(
ui->storageLabel->text().arg(CLIENT_NAME));
50 ui->lblExplanation1->setText(
ui->lblExplanation1->text()
56 ui->lblExplanation2->setText(
ui->lblExplanation2->text().arg(CLIENT_NAME));
59 ui->pruneGB->setRange(min_prune_target_GB, std::numeric_limits<int>::max());
62 ui->prune->setChecked(*arg >= 1);
63 ui->prune->setEnabled(
false);
66 ui->pruneGB->setToolTip(
ui->prune->toolTip());
67 ui->lblPruneSuffix->setToolTip(
ui->prune->toolTip());
70 connect(
ui->prune, &QCheckBox::toggled, [
this](
bool prune_checked) {
71 m_prune_checkbox_is_default = false;
72 UpdatePruneLabels(prune_checked);
73 UpdateFreeSpaceLabel();
75 connect(
ui->pruneGB, qOverload<int>(&QSpinBox::valueChanged), [
this](
int prune_GB) {
76 m_prune_target_gb = prune_GB;
77 UpdatePruneLabels(ui->prune->isChecked());
78 UpdateFreeSpaceLabel();
94 return ui->dataDirectory->text();
99 ui->dataDirectory->setText(dataDir);
102 ui->dataDirDefault->setChecked(
true);
103 ui->dataDirectory->setEnabled(
false);
104 ui->ellipsisButton->setEnabled(
false);
106 ui->dataDirCustom->setChecked(
true);
107 ui->dataDirectory->setEnabled(
true);
108 ui->ellipsisButton->setEnabled(
true);
114 switch (
ui->prune->checkState()) {
117 case Qt::Unchecked:
default:
124 did_show_intro =
false;
134 dataDir = settings.value(
"strDataDir", dataDir).toString();
141 }
catch (
const std::exception&) {
146 Intro intro(
nullptr,
Params().AssumedBlockchainSize(),
Params().AssumedChainStateSize());
148 intro.setWindowIcon(QIcon(
":icons/bitcoin"));
149 did_show_intro =
true;
165 }
catch (
const fs::filesystem_error&) {
166 QMessageBox::critical(
nullptr, CLIENT_NAME,
167 tr(
"Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
175 settings.setValue(
"strDataDir", dataDir);
176 settings.setValue(
"fReset",
false);
193 ui->errorMessage->setText(message);
194 ui->errorMessage->setStyleSheet(
"");
197 ui->errorMessage->setText(tr(
"Error") +
": " + message);
198 ui->errorMessage->setStyleSheet(
"QLabel { color: #800000 }");
204 ui->freeSpace->setText(
"");
221 ui->freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
224 ui->freeSpace->setStyleSheet(
"QLabel { color: #999900 }");
226 ui->freeSpace->setStyleSheet(
"");
228 ui->freeSpace->setText(freeString +
".");
234 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
240 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(
nullptr, tr(
"Choose data directory"),
ui->dataDirectory->text()));
242 ui->dataDirectory->setText(dir);
252 ui->dataDirectory->setEnabled(
true);
253 ui->ellipsisButton->setEnabled(
true);
258 thread =
new QThread(
this);
260 executor->moveToThread(
thread);
265 connect(
thread, &QThread::finished, executor, &QObject::deleteLater);
295 QString storageRequiresMsg = tr(
"At least %1 GB of data will be stored in this directory, and it will grow over time.");
298 storageRequiresMsg = tr(
"Approximately %1 GB of data will be stored in this directory.");
300 ui->lblExplanation3->setVisible(prune_checked);
301 ui->pruneGB->setEnabled(prune_checked);
302 static constexpr uint64_t nPowTargetSpacing = 10 * 60;
303 static constexpr uint32_t expected_block_data_size = 2250000;
304 const uint64_t expected_backup_days =
m_prune_target_gb * 1e9 / (uint64_t(expected_block_data_size) * 86400 / nPowTargetSpacing);
305 ui->lblPruneSuffix->setText(
307 tr(
"(sufficient to restore backups %n day(s) old)",
"", expected_backup_days));
308 ui->sizeWarningLabel->setText(
309 tr(
"%1 will download and store a copy of the Bitcoin block chain.").arg(CLIENT_NAME) +
" " +
311 tr(
"The wallet will also be stored in this directory.")
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
const CChainParams & Params()
Return the currently selected parameters.
ChainType GetChainType() const
Returns the appropriate chain type from the program arguments.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void reply(int status, const QString &message, quint64 available)
Introduction screen (pre-GUI startup).
void setStatus(int status, const QString &message, quint64 bytesAvailable)
void on_ellipsisButton_clicked()
void UpdatePruneLabels(bool prune_checked)
const int64_t m_blockchain_size_gb
void setDataDirectory(const QString &dataDir)
int64_t m_prune_target_gb
bool m_prune_checkbox_is_default
uint64_t m_bytes_available
friend class FreespaceChecker
void on_dataDirectory_textChanged(const QString &arg1)
int64_t m_required_space_gb
Total required space (in GB) depending on user choice (prune or not prune).
void UpdateFreeSpaceLabel()
int64_t getPruneMiB() const
static bool showIfNeeded(bool &did_show_intro, int64_t &prune_MiB)
Determine data directory.
Intro(QWidget *parent=nullptr, int64_t blockchain_size_gb=0, int64_t chain_state_size_gb=0)
const int64_t m_chain_state_size_gb
QString getDataDirectory()
void checkPath(const QString &dataDir)
QString getPathToCheck() override
void on_dataDirDefault_clicked()
void on_dataDirCustom_clicked()
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to a byte string.
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
static constexpr int DEFAULT_PRUNE_TARGET_GB
static constexpr uint64_t GB_BYTES
static const bool DEFAULT_CHOOSE_DATADIR
Utility functions used by the Bitcoin Qt UI.
QString getDefaultDataDirectory()
Determine default data directory for operating system.
constexpr auto dialog_flags
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES