7 #include <chainparams.h> 20 #include <validation.h> 22 #include <QFileDialog> 24 #include <QMessageBox> 54 void reply(
int status,
const QString &message, quint64 available);
60 #include <qt/intro.moc> 71 uint64_t freeBytesAvailable = 0;
72 int replyStatus =
ST_OK;
73 QString replyMessage = tr(
"A new data directory will be created.");
78 while(parentDir.has_parent_path() && !
fs::exists(parentDir))
80 parentDir = parentDir.parent_path();
83 if (parentDirOld == parentDir)
86 parentDirOld = parentDir;
90 freeBytesAvailable = fs::space(parentDir).available;
93 if(fs::is_directory(dataDir))
95 QString separator =
"<code>" + QDir::toNativeSeparators(
"/") + tr(
"name") +
"</code>";
97 replyMessage = tr(
"Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);
100 replyMessage = tr(
"Path already exists, and is not a directory.");
103 }
catch (
const fs::filesystem_error&)
107 replyMessage = tr(
"Cannot create data directory here.");
109 Q_EMIT
reply(replyStatus, replyMessage, freeBytesAvailable);
114 int GetPruneTargetGB()
122 Intro::Intro(QWidget *parent, int64_t blockchain_size_gb, int64_t chain_state_size_gb) :
125 m_blockchain_size_gb(blockchain_size_gb),
126 m_chain_state_size_gb(chain_state_size_gb),
127 m_prune_target_gb{GetPruneTargetGB()}
130 ui->welcomeLabel->setText(ui->welcomeLabel->text().arg(
PACKAGE_NAME));
131 ui->storageLabel->setText(ui->storageLabel->text().arg(
PACKAGE_NAME));
133 ui->lblExplanation1->setText(ui->lblExplanation1->text()
135 .arg(m_blockchain_size_gb)
139 ui->lblExplanation2->setText(ui->lblExplanation2->text().arg(
PACKAGE_NAME));
142 ui->pruneGB->setRange(min_prune_target_GB, std::numeric_limits<int>::max());
144 m_prune_checkbox_is_default =
false;
146 ui->prune->setEnabled(
false);
148 ui->pruneGB->setValue(m_prune_target_gb);
149 ui->pruneGB->setToolTip(ui->prune->toolTip());
150 ui->lblPruneSuffix->setToolTip(ui->prune->toolTip());
151 UpdatePruneLabels(ui->prune->isChecked());
153 connect(ui->prune, &QCheckBox::toggled, [
this](
bool prune_checked) {
154 m_prune_checkbox_is_default = false;
155 UpdatePruneLabels(prune_checked);
156 UpdateFreeSpaceLabel();
158 connect(ui->pruneGB, qOverload<int>(&QSpinBox::valueChanged), [
this](
int prune_GB) {
159 m_prune_target_gb = prune_GB;
160 UpdatePruneLabels(ui->prune->isChecked());
161 UpdateFreeSpaceLabel();
197 switch (
ui->
prune->checkState()) {
200 case Qt::Unchecked:
default:
207 did_show_intro =
false;
217 dataDir = settings.value(
"strDataDir", dataDir).toString();
224 }
catch (
const std::exception&) {
229 Intro intro(
nullptr,
Params().AssumedBlockchainSize(),
Params().AssumedChainStateSize());
231 intro.setWindowIcon(QIcon(
":icons/bitcoin"));
232 did_show_intro =
true;
248 }
catch (
const fs::filesystem_error&) {
250 tr(
"Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
258 settings.setValue(
"strDataDir", dataDir);
259 settings.setValue(
"fReset",
false);
304 ui->
freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
307 ui->
freeSpace->setStyleSheet(
"QLabel { color: #999900 }");
317 ui->
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
323 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(
nullptr, tr(
"Choose data directory"),
ui->
dataDirectory->text()));
341 thread =
new QThread(
this);
343 executor->moveToThread(
thread);
348 connect(
thread, &QThread::finished, executor, &QObject::deleteLater);
378 QString storageRequiresMsg = tr(
"At least %1 GB of data will be stored in this directory, and it will grow over time.");
381 storageRequiresMsg = tr(
"Approximately %1 GB of data will be stored in this directory.");
385 static constexpr uint64_t nPowTargetSpacing = 10 * 60;
386 static constexpr uint32_t expected_block_data_size = 2250000;
387 const uint64_t expected_backup_days =
m_prune_target_gb * 1e9 / (uint64_t(expected_block_data_size) * 86400 / nPowTargetSpacing);
390 tr(
"(sufficient to restore backups %n day(s) old)",
"", expected_backup_days));
392 tr(
"%1 will download and store a copy of the Bitcoin block chain.").arg(
PACKAGE_NAME) +
" " +
394 tr(
"The wallet will also be stored in this directory.")
static const bool DEFAULT_CHOOSE_DATADIR
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by create_directories if the requested directory exists.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
static constexpr int DEFAULT_PRUNE_TARGET_GB
Utility functions used by the Bitcoin Qt UI.
void reply(int status, const QString &message, quint64 available)
QRadioButton * dataDirDefault
void on_dataDirCustom_clicked()
int64_t m_required_space_gb
Total required space (in GB) depending on user choice (prune or not prune).
FreespaceChecker(Intro *intro)
void UpdatePruneLabels(bool prune_checked)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
QString getDataDirectory()
static constexpr uint64_t GB_BYTES
ChainType GetChainType() const
Returns the appropriate chain type from the program arguments.
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
constexpr auto dialog_flags
QRadioButton * dataDirCustom
static bool showIfNeeded(bool &did_show_intro, int64_t &prune_MiB)
Determine data directory.
void on_dataDirectory_textChanged(const QString &arg1)
void setStatus(int status, const QString &message, quint64 bytesAvailable)
static std::string PathToString(const path &path)
Convert path object to a byte string.
void checkPath(const QString &dataDir)
void on_ellipsisButton_clicked()
QDialogButtonBox * buttonBox
fs::path QStringToPath(const QString &path)
Convert QString to OS specific boost path through UTF-8.
void on_dataDirDefault_clicked()
int64_t getPruneMiB() const
int64_t m_prune_target_gb
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
QLineEdit * dataDirectory
void UpdateFreeSpaceLabel()
const int64_t m_blockchain_size_gb
friend class FreespaceChecker
void setDataDirectory(const QString &dataDir)
const CChainParams & Params()
Return the currently selected parameters.
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.
QLabel * sizeWarningLabel
const int64_t m_chain_state_size_gb
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
static bool exists(const path &p)
QString getDefaultDataDirectory()
Determine default data directory for operating system.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool m_prune_checkbox_is_default
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
Introduction screen (pre-GUI startup).
QPushButton * ellipsisButton
uint64_t m_bytes_available
Intro(QWidget *parent=nullptr, int64_t blockchain_size_gb=0, int64_t chain_state_size_gb=0)