1 // Copyright (c) 2011-2018 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 static const bool DEFAULT_CHOOSE_DATADIR = false;
13 
14 class FreespaceChecker;
15 
16 namespace interfaces {
17     class Node;
18 }
19 
20 namespace Ui {
21     class Intro;
22 }
23 
24 /** Introduction screen (pre-GUI startup).
25   Allows the user to choose a data directory,
26   in which the wallet and block chain will be stored.
27  */
28 class Intro : public QDialog
29 {
30     Q_OBJECT
31 
32 public:
33     explicit Intro(QWidget *parent = nullptr,
34                    uint64_t blockchain_size = 0, uint64_t chain_state_size = 0);
35     ~Intro();
36 
37     QString getDataDirectory();
38     void setDataDirectory(const QString &dataDir);
39 
40     /**
41      * Determine data directory. Let the user choose if the current one doesn't exist.
42      *
43      * @returns true if a data directory was selected, false if the user cancelled the selection
44      * dialog.
45      *
46      * @note do NOT call global GetDataDir() before calling this function, this
47      * will cause the wrong path to be cached.
48      */
49     static bool pickDataDirectory(interfaces::Node& node);
50 
51     /**
52      * Determine default data directory for operating system.
53      */
54     static QString getDefaultDataDirectory();
55 
56 Q_SIGNALS:
57     void requestCheck();
58 
59 public Q_SLOTS:
60     void setStatus(int status, const QString &message, quint64 bytesAvailable);
61 
62 private Q_SLOTS:
63     void on_dataDirectory_textChanged(const QString &arg1);
64     void on_ellipsisButton_clicked();
65     void on_dataDirDefault_clicked();
66     void on_dataDirCustom_clicked();
67 
68 private:
69     Ui::Intro *ui;
70     QThread *thread;
71     QMutex mutex;
72     bool signalled;
73     QString pathToCheck;
74     uint64_t m_blockchain_size;
75     uint64_t m_chain_state_size;
76 
77     void startThread();
78     void checkPath(const QString &dataDir);
79     QString getPathToCheck();
80 
81     friend class FreespaceChecker;
82 };
83 
84 #endif // BITCOIN_QT_INTRO_H
85