5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
12#include <qt/forms/ui_intro.h>
51 void reply(
int status,
const QString &message, quint64 available);
57#include <qt/intro.moc>
66 uint64_t freeBytesAvailable = 0;
67 int replyStatus =
ST_OK;
68 QString replyMessage = tr(
"A new data directory will be created.");
73 while (parentDir.has_parent_path() && !
fs::exists(parentDir)) {
74 parentDir = parentDir.parent_path();
78 if (parentDirOld == parentDir) {
82 parentDirOld = parentDir;
86 freeBytesAvailable = fs::space(parentDir).available;
88 if (fs::is_directory(dataDir)) {
89 QString separator =
"<code>" + QDir::toNativeSeparators(
"/") +
90 tr(
"name") +
"</code>";
92 replyMessage = tr(
"Directory already exists. Add %1 if you "
93 "intend to create a new directory here.")
98 tr(
"Path already exists, and is not a directory.");
101 }
catch (
const fs::filesystem_error &) {
104 replyMessage = tr(
"Cannot create data directory here.");
106 Q_EMIT
reply(replyStatus, replyMessage, freeBytesAvailable);
111int GetPruneTargetGB() {
115 return prune_target_mib > 1 ?
PruneMiBtoGB(prune_target_mib)
121 int64_t chain_state_size_gb)
122 : QDialog(parent), ui(new
Ui::
Intro), thread(nullptr), signalled(false),
123 m_blockchain_size_gb(blockchain_size_gb),
124 m_chain_state_size_gb(chain_state_size_gb),
125 m_prune_target_gb(GetPruneTargetGB()) {
127 ui->welcomeLabel->setText(
ui->welcomeLabel->text().arg(PACKAGE_NAME));
128 ui->storageLabel->setText(
ui->storageLabel->text().arg(PACKAGE_NAME));
130 ui->lblExplanation1->setText(
ui->lblExplanation1->text()
134 .arg(tr(
"Bitcoin")));
135 ui->lblExplanation2->setText(
ui->lblExplanation2->text().arg(PACKAGE_NAME));
139 ui->prune->setChecked(
true);
140 ui->prune->setEnabled(
false);
142 ui->prune->setText(tr(
"Discard blocks after verification, except most "
143 "recent %1 GB (prune)")
147 connect(
ui->prune, &QCheckBox::toggled, [
this](
bool prune_checked) {
148 UpdatePruneLabels(prune_checked);
149 UpdateFreeSpaceLabel();
163 return ui->dataDirectory->text();
167 ui->dataDirectory->setText(dataDir);
169 ui->dataDirDefault->setChecked(
true);
170 ui->dataDirectory->setEnabled(
false);
171 ui->ellipsisButton->setEnabled(
false);
173 ui->dataDirCustom->setChecked(
true);
174 ui->dataDirectory->setEnabled(
true);
175 ui->ellipsisButton->setEnabled(
true);
180 did_show_intro =
false;
191 dataDir = settings.value(
"strDataDir", dataDir).toString();
195 settings.value(
"fReset",
false).toBool() ||
203 }
catch (
const std::exception &) {
215 intro.setWindowIcon(QIcon(
":icons/bitcoin"));
216 did_show_intro =
true;
233 }
catch (
const fs::filesystem_error &) {
234 QMessageBox::critical(
nullptr, PACKAGE_NAME,
235 tr(
"Error: Specified data directory "
236 "\"%1\" cannot be created.")
243 prune = intro.
ui->prune->isChecked();
245 settings.setValue(
"strDataDir", dataDir);
246 settings.setValue(
"fReset",
false);
262 quint64 bytesAvailable) {
265 ui->errorMessage->setText(message);
266 ui->errorMessage->setStyleSheet(
"");
269 ui->errorMessage->setText(tr(
"Error") +
": " + message);
270 ui->errorMessage->setStyleSheet(
"QLabel { color: #800000 }");
275 ui->freeSpace->setText(
"");
278 if (
ui->prune->isEnabled()) {
279 ui->prune->setChecked(
286 ui->buttonBox->button(QDialogButtonBox::Ok)
295 ui->freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
299 ui->freeSpace->setStyleSheet(
"QLabel { color: #999900 }");
301 ui->freeSpace->setStyleSheet(
"");
303 ui->freeSpace->setText(freeString +
".");
308 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
313 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(
314 nullptr,
"Choose data directory",
ui->dataDirectory->text()));
315 if (!dir.isEmpty()) {
316 ui->dataDirectory->setText(dir);
325 ui->dataDirectory->setEnabled(
true);
326 ui->ellipsisButton->setEnabled(
true);
330 thread =
new QThread(
this);
332 executor->moveToThread(
thread);
337 connect(
thread, &QThread::finished, executor, &QObject::deleteLater);
363 QString storageRequiresMsg =
364 tr(
"At least %1 GB of data will be stored in this directory, and it "
365 "will grow over time.");
369 tr(
"Approximately %1 GB of data will be stored in this directory.");
371 ui->lblExplanation3->setVisible(prune_checked);
372 ui->sizeWarningLabel->setText(
373 tr(
"%1 will download and store a copy of the Bitcoin block chain.")
376 tr(
"The wallet will also be stored in this directory."));
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given 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.
std::string GetChainName() const
Looks for -regtest, -testnet and returns the appropriate BIP70 chain name.
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.