lbrycrd/src/qt/intro.h
Wladimir J. van der Laan b4a9aa511c qt: Fix random segfault when closing "Choose data directory" dialog
The `pickDataDirectory()` function was calling `exit(0)` to quit
the application when the user closes the dialog without choosing
a data directory.

This is a bad idea because a background thread is created (to
check free space on the drive of the currently selected datadir).
The thread is not stopped and unwound properly, resulting in a potential
race condition somewhere deep in Qt.

So replace the `exit()` by a boolean return value, and let the
stack unwind normally.
2016-08-18 16:58:25 +02:00

78 lines
1.9 KiB
C++

// Copyright (c) 2011-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_INTRO_H
#define BITCOIN_QT_INTRO_H
#include <QDialog>
#include <QMutex>
#include <QThread>
static const bool DEFAULT_CHOOSE_DATADIR = false;
class FreespaceChecker;
namespace Ui {
class Intro;
}
/** Introduction screen (pre-GUI startup).
Allows the user to choose a data directory,
in which the wallet and block chain will be stored.
*/
class Intro : public QDialog
{
Q_OBJECT
public:
explicit Intro(QWidget *parent = 0);
~Intro();
QString getDataDirectory();
void setDataDirectory(const QString &dataDir);
/**
* Determine data directory. Let the user choose if the current one doesn't exist.
*
* @returns true if a data directory was selected, false if the user cancelled the selection
* dialog.
*
* @note do NOT call global GetDataDir() before calling this function, this
* will cause the wrong path to be cached.
*/
static bool pickDataDirectory();
/**
* Determine default data directory for operating system.
*/
static QString getDefaultDataDirectory();
Q_SIGNALS:
void requestCheck();
void stopThread();
public Q_SLOTS:
void setStatus(int status, const QString &message, quint64 bytesAvailable);
private Q_SLOTS:
void on_dataDirectory_textChanged(const QString &arg1);
void on_ellipsisButton_clicked();
void on_dataDirDefault_clicked();
void on_dataDirCustom_clicked();
private:
Ui::Intro *ui;
QThread *thread;
QMutex mutex;
bool signalled;
QString pathToCheck;
void startThread();
void checkPath(const QString &dataDir);
QString getPathToCheck();
friend class FreespaceChecker;
};
#endif // BITCOIN_QT_INTRO_H