qt: Fix random segfault when closing "Choose data directory" dialog
[novacoin.git] / src / qt / intro.h
1 // Copyright (c) 2011-2013 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef BITCOIN_QT_INTRO_H
6 #define BITCOIN_QT_INTRO_H
7
8 #include <QDialog>
9 #include <QMutex>
10 #include <QThread>
11
12 class FreespaceChecker;
13
14 namespace Ui {
15     class Intro;
16 }
17
18 /** Introduction screen (pre-GUI startup).
19   Allows the user to choose a data directory,
20   in which the wallet and block chain will be stored.
21  */
22 class Intro : public QDialog
23 {
24     Q_OBJECT
25
26 public:
27     explicit Intro(QWidget *parent = 0);
28     ~Intro();
29
30     QString getDataDirectory();
31     void setDataDirectory(const QString &dataDir);
32
33     /**
34      * Determine data directory. Let the user choose if the current one doesn't exist.
35      *
36      * @returns true if a data directory was selected, false if the user cancelled the selection
37      * dialog.
38      *
39      * @note do NOT call global GetDataDir() before calling this function, this
40      * will cause the wrong path to be cached.
41      */
42     static bool pickDataDirectory();
43
44     /**
45      * Determine default data directory for operating system.
46      */
47     static QString getDefaultDataDirectory();
48
49 signals:
50     void requestCheck();
51     void stopThread();
52
53 public slots:
54     void setStatus(int status, const QString &message, quint64 bytesAvailable);
55
56 private slots:
57     void on_dataDirectory_textChanged(const QString &arg1);
58     void on_ellipsisButton_clicked();
59     void on_dataDirDefault_clicked();
60     void on_dataDirCustom_clicked();
61
62 private:
63     Ui::Intro *ui;
64     QThread *thread;
65     QMutex mutex;
66     bool signalled;
67     QString pathToCheck;
68
69     void startThread();
70     void checkPath(const QString &dataDir);
71     QString getPathToCheck();
72
73     friend class FreespaceChecker;
74 };
75
76 #endif // BITCOIN_QT_INTRO_H