intro.h raw
1 // Copyright (c) 2011-2021 The Limenka 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 LIMENKA_QT_INTRO_H
6 #define LIMENKA_QT_INTRO_H
7
8 #include <QDialog>
9 #include <QMutex>
10 #include <QThread>
11
12 #include <memory>
13
14 static const bool DEFAULT_CHOOSE_DATADIR = false;
15
16 class FreespaceChecker;
17
18 namespace interfaces {
19 class Node;
20 }
21
22 namespace Ui {
23 class Intro;
24 }
25
26 /** Introduction screen (pre-GUI startup).
27 Allows the user to choose a data directory,
28 in which the wallet and block chain will be stored.
29 */
30 class Intro : public QDialog
31 {
32 Q_OBJECT
33
34 public:
35 explicit Intro(QWidget *parent = nullptr,
36 int64_t blockchain_size_gb = 0, int64_t chain_state_size_gb = 0);
37 ~Intro();
38
39 QString getDataDirectory();
40 void setDataDirectory(const QString &dataDir);
41 int64_t getPruneMiB() const;
42 QString getAssumeValid() const;
43
44 /**
45 * Determine data directory. Let the user choose if the current one doesn't exist.
46 * Let the user configure additional preferences such as pruning.
47 *
48 * @returns true if a data directory was selected, false if the user cancelled the selection
49 * dialog.
50 *
51 * @note do NOT call global gArgs.GetDataDirNet() before calling this function, this
52 * will cause the wrong path to be cached.
53 */
54 static bool showIfNeeded(std::unique_ptr<Intro>& intro);
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 bool m_prune_checkbox_is_default{true};
71 QThread* thread{nullptr};
72 QMutex mutex;
73 bool signalled{false};
74 QString pathToCheck;
75 const int64_t m_blockchain_size_gb;
76 const int64_t m_chain_state_size_gb;
77 //! Total required space (in GB) depending on user choice (prune or not prune).
78 int64_t m_required_space_gb{0};
79 uint64_t m_bytes_available{0};
80 int64_t m_prune_target_mib;
81
82 void startThread();
83 void checkPath(const QString &dataDir);
84 QString getPathToCheck();
85 void UpdatePruneLabels(bool prune_checked);
86 void UpdateFreeSpaceLabel();
87
88 friend class FreespaceChecker;
89 };
90
91 #endif // LIMENKA_QT_INTRO_H
92