13 #include <boost/filesystem.hpp>
15 #include <QFileDialog>
17 #include <QMessageBox>
20 static const uint64_t GB_BYTES = 1000000000LL;
21 static const uint64_t BLOCK_CHAIN_SIZE = 1LL * GB_BYTES;
49 void reply(
int status,
const QString &message, quint64 available);
64 namespace fs = boost::filesystem;
67 uint64_t freeBytesAvailable = 0;
68 int replyStatus =
ST_OK;
69 QString replyMessage = tr(
"A new data directory will be created.");
72 fs::path parentDir = dataDir;
73 fs::path parentDirOld = fs::path();
74 while(parentDir.has_parent_path() && !fs::exists(parentDir))
76 parentDir = parentDir.parent_path();
79 if (parentDirOld == parentDir)
82 parentDirOld = parentDir;
86 freeBytesAvailable = fs::space(parentDir).available;
87 if(fs::exists(dataDir))
89 if(fs::is_directory(dataDir))
91 QString separator =
"<code>" + QDir::toNativeSeparators(
"/") + tr(
"name") +
"</code>";
93 replyMessage = tr(
"Directory already exists. Add %1 if you intend to create a new directory here.").arg(separator);
96 replyMessage = tr(
"Path already exists, and is not a directory.");
99 }
catch(fs::filesystem_error &e)
103 replyMessage = tr(
"Cannot create data directory here.");
105 emit
reply(replyStatus, replyMessage, freeBytesAvailable);
155 namespace fs = boost::filesystem;
159 if(!
GetArg(
"-datadir",
"").empty())
164 dataDir = settings.value(
"strDataDir", dataDir).toString();
171 intro.setWindowIcon(QIcon(
":icons/anoncoin"));
184 }
catch(fs::filesystem_error &e) {
185 QMessageBox::critical(0, tr(
"Anoncoin"),
186 tr(
"Error: Specified data directory \"%1\" cannot be created.").arg(dataDir));
191 settings.setValue(
"strDataDir", dataDir);
219 QString freeString = QString::number(bytesAvailable/GB_BYTES) + tr(
"GB of free space available");
220 if(bytesAvailable < BLOCK_CHAIN_SIZE)
222 freeString +=
" " + tr(
"(of %1GB needed)").arg(BLOCK_CHAIN_SIZE/GB_BYTES);
223 ui->
freeSpace->setStyleSheet(
"QLabel { color: #800000 }");
236 ui->
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
242 QString dir = QDir::toNativeSeparators(QFileDialog::getExistingDirectory(0,
"Choose data directory",
ui->
dataDirectory->text()));
260 thread =
new QThread(
this);
262 executor->moveToThread(
thread);
264 connect(executor, SIGNAL(reply(
int,QString,quint64)),
this, SLOT(
setStatus(
int,QString,quint64)));
265 connect(
this, SIGNAL(
requestCheck()), executor, SLOT(check()));
267 connect(
this, SIGNAL(
stopThread()), executor, SLOT(deleteLater()));
void reply(int status, const QString &message, quint64 available)
QRadioButton * dataDirDefault
void on_dataDirCustom_clicked()
FreespaceChecker(Intro *intro)
void setupUi(QDialog *Intro)
QString getDataDirectory()
boost::filesystem::path qstringToBoostPath(const QString &path)
QRadioButton * dataDirCustom
static QString getDefaultDataDirectory()
Determine default data directory for operating system.
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
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()
QDialogButtonBox * buttonBox
void on_dataDirDefault_clicked()
bool TryCreateDirectory(const boost::filesystem::path &p)
QLineEdit * dataDirectory
friend class FreespaceChecker
void setDataDirectory(const QString &dataDir)
static void pickDataDirectory()
Determine data directory.
QLabel * sizeWarningLabel
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
QString boostPathToQString(const boost::filesystem::path &path)
Introduction screen (pre-GUI startup).
QPushButton * ellipsisButton
boost::filesystem::path GetDefaultDataDir()