Line data Source code
1 : // Copyright (c) 2011-2020 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_BITCOIN_H 6 : #define BITCOIN_QT_BITCOIN_H 7 : 8 : #if defined(HAVE_CONFIG_H) 9 : #include <config/bitcoin-config.h> 10 : #endif 11 : 12 : #include <QApplication> 13 : #include <assert.h> 14 : #include <memory> 15 : 16 : #include <interfaces/node.h> 17 : 18 : class BitcoinGUI; 19 : class ClientModel; 20 : class NetworkStyle; 21 : class OptionsModel; 22 : class PaymentServer; 23 : class PlatformStyle; 24 : class SplashScreen; 25 : class WalletController; 26 : class WalletModel; 27 : 28 : 29 : /** Class encapsulating Bitcoin Core startup and shutdown. 30 : * Allows running startup and shutdown in a different thread from the UI thread. 31 : */ 32 0 : class BitcoinCore: public QObject 33 : { 34 : Q_OBJECT 35 : public: 36 : explicit BitcoinCore(interfaces::Node& node); 37 : 38 : public Q_SLOTS: 39 : void initialize(); 40 : void shutdown(); 41 : 42 : Q_SIGNALS: 43 : void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info); 44 : void shutdownResult(); 45 : void runawayException(const QString &message); 46 : 47 : private: 48 : /// Pass fatal exception message to UI thread 49 : void handleRunawayException(const std::exception *e); 50 : 51 : interfaces::Node& m_node; 52 : }; 53 : 54 : /** Main Bitcoin application object */ 55 : class BitcoinApplication: public QApplication 56 : { 57 : Q_OBJECT 58 : public: 59 : explicit BitcoinApplication(); 60 : ~BitcoinApplication(); 61 : 62 : #ifdef ENABLE_WALLET 63 : /// Create payment server 64 : void createPaymentServer(); 65 : #endif 66 : /// parameter interaction/setup based on rules 67 : void parameterSetup(); 68 : /// Create options model 69 : void createOptionsModel(bool resetSettings); 70 : /// Initialize prune setting 71 : void InitializePruneSetting(bool prune); 72 : /// Create main window 73 : void createWindow(const NetworkStyle *networkStyle); 74 : /// Create splash screen 75 : void createSplashScreen(const NetworkStyle *networkStyle); 76 : /// Basic initialization, before starting initialization/shutdown thread. Return true on success. 77 : bool baseInitialize(); 78 : 79 : /// Request core initialization 80 : void requestInitialize(); 81 : /// Request core shutdown 82 : void requestShutdown(); 83 : 84 : /// Get process return value 85 0 : int getReturnValue() const { return returnValue; } 86 : 87 : /// Get window identifier of QMainWindow (BitcoinGUI) 88 : WId getMainWinId() const; 89 : 90 : /// Setup platform style 91 : void setupPlatformStyle(); 92 : 93 4 : interfaces::Node& node() const { assert(m_node); return *m_node; } 94 : void setNode(interfaces::Node& node); 95 : 96 : public Q_SLOTS: 97 : void initializeResult(bool success, interfaces::BlockAndHeaderTipInfo tip_info); 98 : void shutdownResult(); 99 : /// Handle runaway exceptions. Shows a message box with the problem and quits the program. 100 : void handleRunawayException(const QString &message); 101 : 102 : Q_SIGNALS: 103 : void requestedInitialize(); 104 : void requestedShutdown(); 105 : void splashFinished(); 106 : void windowShown(BitcoinGUI* window); 107 : 108 : private: 109 : QThread *coreThread; 110 : OptionsModel *optionsModel; 111 : ClientModel *clientModel; 112 : BitcoinGUI *window; 113 : QTimer *pollShutdownTimer; 114 : #ifdef ENABLE_WALLET 115 : PaymentServer* paymentServer{nullptr}; 116 : WalletController* m_wallet_controller{nullptr}; 117 : #endif 118 : int returnValue; 119 : const PlatformStyle *platformStyle; 120 : std::unique_ptr<QWidget> shutdownWindow; 121 : SplashScreen* m_splash = nullptr; 122 : interfaces::Node* m_node = nullptr; 123 : 124 : void startThread(); 125 : }; 126 : 127 : int GuiMain(int argc, char* argv[]); 128 : 129 : #endif // BITCOIN_QT_BITCOIN_H