intro.h raw
1 // Copyright (c) 2011-present 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 <qt/freespacechecker.h>
9
10 #include <QDialog>
11 #include <QMutex>
12 #include <QThread>
13
14 static const bool DEFAULT_CHOOSE_DATADIR = false;
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, public FreespaceChecker::PathQuery
29 {
30 Q_OBJECT
31
32 public:
33 explicit Intro(QWidget *parent = nullptr,
34 int64_t blockchain_size_gb = 0, int64_t chain_state_size_gb = 0);
35 ~Intro();
36
37 QString getDataDirectory();
38 void setDataDirectory(const QString &dataDir);
39 int64_t getPruneMiB() const;
40
41 /**
42 * Determine data directory. Let the user choose if the current one doesn't exist.
43 * Let the user configure additional preferences such as pruning.
44 *
45 * @returns true if a data directory was selected, false if the user cancelled the selection
46 * dialog.
47 *
48 * @note do NOT call global gArgs.GetDataDirNet() before calling this function, this
49 * will cause the wrong path to be cached.
50 */
51 static bool showIfNeeded(bool& did_show_intro, int64_t& prune_MiB);
52
53 Q_SIGNALS:
54 void requestCheck();
55
56 public Q_SLOTS:
57 void setStatus(int status, const QString &message, quint64 bytesAvailable);
58
59 private Q_SLOTS:
60 void on_dataDirectory_textChanged(const QString &arg1);
61 void on_ellipsisButton_clicked();
62 void on_dataDirDefault_clicked();
63 void on_dataDirCustom_clicked();
64
65 private:
66 Ui::Intro *ui;
67 bool m_prune_checkbox_is_default{true};
68 QThread* thread{nullptr};
69 QMutex mutex;
70 bool signalled{false};
71 QString pathToCheck;
72 const int64_t m_blockchain_size_gb;
73 const int64_t m_chain_state_size_gb;
74 //! Total required space (in GB) depending on user choice (prune or not prune).
75 int64_t m_required_space_gb{0};
76 uint64_t m_bytes_available{0};
77 int64_t m_prune_target_gb;
78
79 void startThread();
80 void checkPath(const QString &dataDir);
81 QString getPathToCheck() override;
82 void UpdatePruneLabels(bool prune_checked);
83 void UpdateFreeSpaceLabel();
84
85 friend class FreespaceChecker;
86 };
87
88 #endif // BITCOIN_QT_INTRO_H
89