5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
12#include <qt/forms/ui_intro.h>
52 void reply(
int status,
const QString &message, quint64 available);
58#include <qt/intro.moc>
67 uint64_t freeBytesAvailable = 0;
68 int replyStatus =
ST_OK;
69 QString replyMessage = tr(
"A new data directory will be created.");
74 while (parentDir.has_parent_path() && !
fs::exists(parentDir)) {
75 parentDir = parentDir.parent_path();
79 if (parentDirOld == parentDir) {
83 parentDirOld = parentDir;
87 freeBytesAvailable = fs::space(parentDir).available;
89 if (fs::is_directory(dataDir)) {
90 QString separator =
"<code>" + QDir::toNativeSeparators(
"/") +
91 tr(
"name") +
"</code>";
93 replyMessage = tr(
"Directory already exists. Add %1 if you "
94 "intend to create a new directory here.")
99 tr(
"Path already exists, and is not a directory.");
102 }
catch (
const fs::filesystem_error &) {
105 replyMessage = tr(
"Cannot create data directory here.");
107 Q_EMIT
reply(replyStatus, replyMessage, freeBytesAvailable);
112int GetPruneTargetGB() {
116 return prune_target_mib > 1 ?
PruneMiBtoGB(prune_target_mib)
122 int64_t chain_state_size_gb)
123 : QDialog(parent), ui(new
Ui::
Intro), thread(nullptr), signalled(false),
124 m_blockchain_size_gb(blockchain_size_gb),
125 m_chain_state_size_gb(chain_state_size_gb),
126 m_prune_target_gb(GetPruneTargetGB()) {
128 ui->welcomeLabel->setText(
ui->welcomeLabel->text().arg(PACKAGE_NAME));
129 ui->storageLabel->setText(
ui->storageLabel->text().arg(PACKAGE_NAME));
131 ui->lblExplanation1->setText(
ui->lblExplanation1->text()
135 .arg(tr(
"Bitcoin")));
136 ui->lblExplanation2->setText(
ui->lblExplanation2->text().arg(PACKAGE_NAME));
140 ui->prune->setChecked(
true);
141 ui->prune->setEnabled(
false);
143 ui->prune->setText(tr(
"Discard blocks after verification, except most "
144 "recent %1 GB (prune)")
148 connect(
ui->prune, &QCheckBox::toggled, [
this](
bool prune_checked) {
149 UpdatePruneLabels(prune_checked);
150 UpdateFreeSpaceLabel();
164 return ui->dataDirectory->text();
168 ui->dataDirectory->setText(dataDir);
170 ui->dataDirDefault->setChecked(
true);
171 ui->dataDirectory->setEnabled(
false);
172 ui->ellipsisButton->setEnabled(
false);
174 ui->dataDirCustom->setChecked(
true);
175 ui->dataDirectory->setEnabled(
true);
176 ui->ellipsisButton->setEnabled(
true);
181 did_show_intro =
false;
192 dataDir = settings.value(
"strDataDir", dataDir).toString();
196 settings.value(
"fReset",
false).toBool() ||
204 }
catch (
const std::exception &) {
216 intro.setWindowIcon(QIcon(
":icons/bitcoin"));
217 did_show_intro =
true;
234 }
catch (
const fs::filesystem_error &) {
235 QMessageBox::critical(
nullptr, PACKAGE_NAME,
236 tr(
"Error: Specified data directory "
237 "\"%1\" cannot be created.")
244 prune = intro.
ui->prune->isChecked();
246 settings.setValue(
"strDataDir", dataDir);
247 settings.setValue(
"fReset",
false);
263 quint64 bytesAvailable) {
266 ui->errorMessage->setText(message);
267 ui->errorMessage->setStyleSheet(
"");
270 ui->errorMessage->setText(tr(
"Error") +
": " + message);
271 ui->errorMessage->setStyleSheet(
"QLabel { color: #800000 }");
276 ui->freeSpace->setText(
"");
279 if (
ui->prune->isEnabled()) {
280 ui->prune->setChecked(
287 ui->buttonBox->button(QDialogButtonBox::Ok)
296 ui->freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
300 ui->freeSpace->setStyleSheet(
"QLabel { color: #999900 }");
302 ui->freeSpace->setStyleSheet(
"");
304 ui->freeSpace->setText(freeString +
".");
309 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
314 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(
315 nullptr,
"Choose data directory",
ui->dataDirectory->text()));
316 if (!dir.isEmpty()) {
317 ui->dataDirectory->setText(dir);
326 ui->dataDirectory->setEnabled(
true);
327 ui->ellipsisButton->setEnabled(
true);
331 thread =
new QThread(
this);
333 executor->moveToThread(
thread);
338 connect(
thread, &QThread::finished, executor, &QObject::deleteLater);
364 QString storageRequiresMsg =
365 tr(
"At least %1 GB of data will be stored in this directory, and it "
366 "will grow over time.");
370 tr(
"Approximately %1 GB of data will be stored in this directory.");
372 ui->lblExplanation3->setVisible(prune_checked);
373 ui->sizeWarningLabel->setText(
374 tr(
"%1 will download and store a copy of the Bitcoin block chain.")
377 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 BIP70 chain name.
ChainType GetChainType() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
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.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
uint64_t AssumedBlockchainSize() const
Minimum free space (in GB) needed for data directory.
uint64_t AssumedChainStateSize() const
Minimum free space (in GB) needed for data directory when pruned; Does not include prune target.
virtual const CChainParams & GetChainParams() const =0
FreespaceChecker(Intro *intro)
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)
static bool showIfNeeded(bool &did_show_intro, bool &prune)
Determine data directory.
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()
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)
void on_dataDirDefault_clicked()
const int64_t m_prune_target_gb
void on_dataDirCustom_clicked()
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
const Config & GetConfig()
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
fs::path qstringToBoostPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
QString getDefaultDataDirectory()
Determine default data directory for operating system.
static bool exists(const path &p)
static std::string PathToString(const path &path)
Convert path object to byte string.
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.