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