Skip to content

Commit ca20b65

Browse files
committed
Move BitcoinApplication to header so it can be tested
Move-only commit, no code changes
1 parent f7e182a commit ca20b65

File tree

3 files changed

+125
-96
lines changed

3 files changed

+125
-96
lines changed

src/Makefile.qt.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ QT_MOC_CPP = \
120120
qt/moc_bantablemodel.cpp \
121121
qt/moc_bitcoinaddressvalidator.cpp \
122122
qt/moc_bitcoinamountfield.cpp \
123+
qt/moc_bitcoin.cpp \
123124
qt/moc_bitcoingui.cpp \
124125
qt/moc_bitcoinunits.cpp \
125126
qt/moc_clientmodel.cpp \
@@ -166,7 +167,6 @@ BITCOIN_MM = \
166167
qt/macos_appnap.mm
167168

168169
QT_MOC = \
169-
qt/bitcoin.moc \
170170
qt/bitcoinamountfield.moc \
171171
qt/intro.moc \
172172
qt/overviewpage.moc \
@@ -194,6 +194,7 @@ BITCOIN_QT_H = \
194194
qt/bantablemodel.h \
195195
qt/bitcoinaddressvalidator.h \
196196
qt/bitcoinamountfield.h \
197+
qt/bitcoin.h \
197198
qt/bitcoingui.h \
198199
qt/bitcoinunits.h \
199200
qt/clientmodel.h \

src/qt/bitcoin.cpp

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <config/bitcoin-config.h>
77
#endif
88

9+
#include <qt/bitcoin.h>
910
#include <qt/bitcoingui.h>
1011

1112
#include <chainparams.h>
@@ -140,101 +141,6 @@ void DebugMessageHandler(QtMsgType type, const QMessageLogContext& context, cons
140141
}
141142
}
142143

143-
/** Class encapsulating Bitcoin Core startup and shutdown.
144-
* Allows running startup and shutdown in a different thread from the UI thread.
145-
*/
146-
class BitcoinCore: public QObject
147-
{
148-
Q_OBJECT
149-
public:
150-
explicit BitcoinCore(interfaces::Node& node);
151-
152-
public Q_SLOTS:
153-
void initialize();
154-
void shutdown();
155-
156-
Q_SIGNALS:
157-
void initializeResult(bool success);
158-
void shutdownResult();
159-
void runawayException(const QString &message);
160-
161-
private:
162-
/// Pass fatal exception message to UI thread
163-
void handleRunawayException(const std::exception *e);
164-
165-
interfaces::Node& m_node;
166-
};
167-
168-
/** Main Bitcoin application object */
169-
class BitcoinApplication: public QApplication
170-
{
171-
Q_OBJECT
172-
public:
173-
explicit BitcoinApplication(interfaces::Node& node, int &argc, char **argv);
174-
~BitcoinApplication();
175-
176-
#ifdef ENABLE_WALLET
177-
/// Create payment server
178-
void createPaymentServer();
179-
#endif
180-
/// parameter interaction/setup based on rules
181-
void parameterSetup();
182-
/// Create options model
183-
void createOptionsModel(bool resetSettings);
184-
/// Create main window
185-
void createWindow(const NetworkStyle *networkStyle);
186-
/// Create splash screen
187-
void createSplashScreen(const NetworkStyle *networkStyle);
188-
189-
/// Request core initialization
190-
void requestInitialize();
191-
/// Request core shutdown
192-
void requestShutdown();
193-
194-
/// Get process return value
195-
int getReturnValue() const { return returnValue; }
196-
197-
/// Get window identifier of QMainWindow (BitcoinGUI)
198-
WId getMainWinId() const;
199-
200-
/// Setup platform style
201-
void setupPlatformStyle();
202-
203-
public Q_SLOTS:
204-
void initializeResult(bool success);
205-
void shutdownResult();
206-
/// Handle runaway exceptions. Shows a message box with the problem and quits the program.
207-
void handleRunawayException(const QString &message);
208-
void addWallet(WalletModel* walletModel);
209-
void removeWallet();
210-
211-
Q_SIGNALS:
212-
void requestedInitialize();
213-
void requestedShutdown();
214-
void stopThread();
215-
void splashFinished();
216-
217-
private:
218-
QThread *coreThread;
219-
interfaces::Node& m_node;
220-
OptionsModel *optionsModel;
221-
ClientModel *clientModel;
222-
BitcoinGUI *window;
223-
QTimer *pollShutdownTimer;
224-
#ifdef ENABLE_WALLET
225-
PaymentServer* paymentServer;
226-
std::vector<WalletModel*> m_wallet_models;
227-
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
228-
#endif
229-
int returnValue;
230-
const PlatformStyle *platformStyle;
231-
std::unique_ptr<QWidget> shutdownWindow;
232-
233-
void startThread();
234-
};
235-
236-
#include <qt/bitcoin.moc>
237-
238144
BitcoinCore::BitcoinCore(interfaces::Node& node) :
239145
QObject(), m_node(node)
240146
{

src/qt/bitcoin.h

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)