|
| 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 WalletModel; |
| 23 | + |
| 24 | +namespace interfaces { |
| 25 | +class Handler; |
| 26 | +class Node; |
| 27 | +} // namespace interfaces |
| 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 | +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); |
| 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(interfaces::Node& node, int &argc, char **argv); |
| 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 | + /// Create main window |
| 71 | + void createWindow(const NetworkStyle *networkStyle); |
| 72 | + /// Create splash screen |
| 73 | + void createSplashScreen(const NetworkStyle *networkStyle); |
| 74 | + |
| 75 | + /// Request core initialization |
| 76 | + void requestInitialize(); |
| 77 | + /// Request core shutdown |
| 78 | + void requestShutdown(); |
| 79 | + |
| 80 | + /// Get process return value |
| 81 | + int getReturnValue() const { return returnValue; } |
| 82 | + |
| 83 | + /// Get window identifier of QMainWindow (BitcoinGUI) |
| 84 | + WId getMainWinId() const; |
| 85 | + |
| 86 | + /// Setup platform style |
| 87 | + void setupPlatformStyle(); |
| 88 | + |
| 89 | +public Q_SLOTS: |
| 90 | + void initializeResult(bool success); |
| 91 | + void shutdownResult(); |
| 92 | + /// Handle runaway exceptions. Shows a message box with the problem and quits the program. |
| 93 | + void handleRunawayException(const QString &message); |
| 94 | + void addWallet(WalletModel* walletModel); |
| 95 | + void removeWallet(); |
| 96 | + |
| 97 | +Q_SIGNALS: |
| 98 | + void requestedInitialize(); |
| 99 | + void requestedShutdown(); |
| 100 | + void stopThread(); |
| 101 | + void splashFinished(); |
| 102 | + |
| 103 | +private: |
| 104 | + QThread *coreThread; |
| 105 | + interfaces::Node& m_node; |
| 106 | + OptionsModel *optionsModel; |
| 107 | + ClientModel *clientModel; |
| 108 | + BitcoinGUI *window; |
| 109 | + QTimer *pollShutdownTimer; |
| 110 | +#ifdef ENABLE_WALLET |
| 111 | + PaymentServer* paymentServer; |
| 112 | + std::vector<WalletModel*> m_wallet_models; |
| 113 | + std::unique_ptr<interfaces::Handler> m_handler_load_wallet; |
| 114 | +#endif |
| 115 | + int returnValue; |
| 116 | + const PlatformStyle *platformStyle; |
| 117 | + std::unique_ptr<QWidget> shutdownWindow; |
| 118 | + |
| 119 | + void startThread(); |
| 120 | +}; |
| 121 | + |
| 122 | +#endif // BITCOIN_QT_BITCOIN_H |
0 commit comments