6 #if defined(HAVE_CONFIG_H) 18 #include <QFileDialog> 20 #include <QMessageBox> 24 static const uint64_t GB_BYTES = 1000000000LL;
26 static const uint64_t BLOCK_CHAIN_SIZE = 5;
28 static const uint64_t CHAIN_STATE_SIZE = 3;
30 static uint64_t requiredSpace;
58 void reply(
int status,
const QString &message, quint64 available);
75 uint64_t freeBytesAvailable = 0;
76 int replyStatus =
ST_OK;
77 QString replyMessage = tr(
"A new data directory will be created.");
80 fs::path parentDir = dataDir;
81 fs::path parentDirOld = fs::path();
82 while(parentDir.has_parent_path() && !fs::exists(parentDir))
84 parentDir = parentDir.parent_path();
87 if (parentDirOld == parentDir)
90 parentDirOld = parentDir;
94 freeBytesAvailable = fs::space(parentDir).available;
95 if(fs::exists(dataDir))
97 if(fs::is_directory(dataDir))
99 QString separator =
"<code>" + QDir::toNativeSeparators(
"/") + tr(
"name") +
"</code>";
101 replyMessage = tr(
"Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);
104 replyMessage = tr(
"Path already exists, and is not a directory.");
107 }
catch (
const fs::filesystem_error&)
111 replyMessage = tr(
"Cannot create data directory here.");
113 Q_EMIT
reply(replyStatus, replyMessage, freeBytesAvailable);
127 ui->lblExplanation1->setText(
ui->lblExplanation1->text()
129 .arg(BLOCK_CHAIN_SIZE)
133 ui->lblExplanation2->setText(
ui->lblExplanation2->text().arg(tr(
PACKAGE_NAME)));
135 uint64_t pruneTarget = std::max<int64_t>(0,
gArgs.
GetArg(
"-prune", 0));
136 requiredSpace = BLOCK_CHAIN_SIZE;
137 QString storageRequiresMsg = tr(
"At least %1 GB of data will be stored in this directory, and it will grow over time.");
139 uint64_t prunedGBs = std::ceil(pruneTarget * 1024 * 1024.0 / GB_BYTES);
140 if (prunedGBs <= requiredSpace) {
141 requiredSpace = prunedGBs;
142 storageRequiresMsg = tr(
"Approximately %1 GB of data will be stored in this directory.");
144 ui->lblExplanation3->setVisible(
true);
146 ui->lblExplanation3->setVisible(
false);
148 requiredSpace += CHAIN_STATE_SIZE;
149 ui->sizeWarningLabel->setText(
150 tr(
"%1 will download and store a copy of the Raven block chain.").arg(tr(
PACKAGE_NAME)) +
" " +
151 storageRequiresMsg.arg(requiredSpace) +
" " +
152 tr(
"The wallet will also be stored in this directory.")
167 return ui->dataDirectory->text();
172 ui->dataDirectory->setText(dataDir);
175 ui->dataDirDefault->setChecked(
true);
176 ui->dataDirectory->setEnabled(
false);
177 ui->ellipsisButton->setEnabled(
false);
179 ui->dataDirCustom->setChecked(
true);
180 ui->dataDirectory->setEnabled(
true);
181 ui->ellipsisButton->setEnabled(
true);
200 dataDir = settings.value(
"strDataDir", dataDir).toString();
207 intro.setWindowIcon(QIcon(
":icons/raven"));
220 }
catch (
const fs::filesystem_error&) {
222 tr(
"Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
227 settings.setValue(
"strDataDir", dataDir);
228 settings.setValue(
"fReset",
false);
244 ui->errorMessage->setText(message);
245 ui->errorMessage->setStyleSheet(
"");
248 ui->errorMessage->setText(tr(
"Error") +
": " + message);
249 ui->errorMessage->setStyleSheet(
"QLabel { color: #800000 }");
255 ui->freeSpace->setText(
"");
257 QString freeString = tr(
"%n GB of free space available",
"", bytesAvailable/GB_BYTES);
258 if(bytesAvailable < requiredSpace * GB_BYTES)
260 freeString +=
" " + tr(
"(of %n GB needed)",
"", requiredSpace);
261 ui->freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
263 ui->freeSpace->setStyleSheet(
"");
265 ui->freeSpace->setText(freeString +
".");
274 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
280 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(0,
"Choose data directory",
ui->dataDirectory->text()));
282 ui->dataDirectory->setText(dir);
292 ui->dataDirectory->setEnabled(
true);
293 ui->ellipsisButton->setEnabled(
true);
298 thread =
new QThread(
this);
300 executor->moveToThread(
thread);
302 connect(executor, SIGNAL(reply(
int,QString,quint64)),
this, SLOT(
setStatus(
int,QString,quint64)));
303 connect(
this, SIGNAL(
requestCheck()), executor, SLOT(check()));
305 connect(
this, SIGNAL(
stopThread()), executor, SLOT(deleteLater()));
void reply(int status, const QString &message, quint64 available)
void on_dataDirCustom_clicked()
FreespaceChecker(Intro *intro)
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
QString getDataDirectory()
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
static QString getDefaultDataDirectory()
Determine default data directory for operating system.
void on_dataDirectory_textChanged(const QString &arg1)
void setStatus(int status, const QString &message, quint64 bytesAvailable)
void checkPath(const QString &dataDir)
void on_ellipsisButton_clicked()
bool TryCreateDirectories(const fs::path &p)
Ignores exceptions thrown by Boost's create_directories if the requested directory exists...
void on_dataDirDefault_clicked()
fs::path GetDefaultDataDir()
friend class FreespaceChecker
void setDataDirectory(const QString &dataDir)
fs::path qstringToBoostPath(const QString &path)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
QString boostPathToQString(const fs::path &path)
static bool pickDataDirectory()
Determine data directory.
Introduction screen (pre-GUI startup).