Skip to content

Commit 3d619e9

Browse files
ryanofskyjnewbery
authored andcommitted
Remove direct bitcoin calls from qt/bitcoingui.cpp
1 parent c0f2756 commit 3d619e9

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

src/interface/node.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class NodeImpl : public Node
4545
Shutdown();
4646
}
4747
void startShutdown() override { StartShutdown(); }
48+
bool shutdownRequested() override { return ShutdownRequested(); }
4849
void mapPort(bool use_upnp) override
4950
{
5051
if (use_upnp) {
@@ -59,6 +60,14 @@ class NodeImpl : public Node
5960
{
6061
return MakeHandler(::uiInterface.InitMessage.connect(fn));
6162
}
63+
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
64+
{
65+
return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn));
66+
}
67+
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
68+
{
69+
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn));
70+
}
6271
};
6372

6473
} // namespace

src/interface/node.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class Node
5959
//! Start shutdown.
6060
virtual void startShutdown() = 0;
6161

62+
//! Return whether shutdown was requested.
63+
virtual bool shutdownRequested() = 0;
64+
6265
//! Map port.
6366
virtual void mapPort(bool use_upnp) = 0;
6467

@@ -68,6 +71,18 @@ class Node
6871
//! Register handler for init messages.
6972
using InitMessageFn = std::function<void(const std::string& message)>;
7073
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
74+
75+
//! Register handler for message box messages.
76+
using MessageBoxFn =
77+
std::function<bool(const std::string& message, const std::string& caption, unsigned int style)>;
78+
virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
79+
80+
//! Register handler for question messages.
81+
using QuestionFn = std::function<bool(const std::string& message,
82+
const std::string& non_interactive_message,
83+
const std::string& caption,
84+
unsigned int style)>;
85+
virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
7186
};
7287

7388
//! Return implementation of Node interface.

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void BitcoinApplication::createOptionsModel(bool resetSettings)
367367

368368
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
369369
{
370-
window = new BitcoinGUI(platformStyle, networkStyle, 0);
370+
window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0);
371371

372372
pollShutdownTimer = new QTimer(window);
373373
connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));

src/qt/bitcoingui.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
#include <chainparams.h>
3232
#include <init.h>
33+
#include <interface/handler.h>
34+
#include <interface/node.h>
3335
#include <ui_interface.h>
3436
#include <util.h>
3537

@@ -72,9 +74,10 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
7274
#endif
7375
;
7476

75-
BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
77+
BitcoinGUI::BitcoinGUI(interface::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
7678
QMainWindow(parent),
7779
enableWallet(false),
80+
m_node(node),
7881
clientModel(0),
7982
walletFrame(0),
8083
unitDisplayControl(0),
@@ -1149,7 +1152,7 @@ void BitcoinGUI::toggleHidden()
11491152

11501153
void BitcoinGUI::detectShutdown()
11511154
{
1152-
if (ShutdownRequested())
1155+
if (m_node.shutdownRequested())
11531156
{
11541157
if(rpcConsole)
11551158
rpcConsole->hide();
@@ -1214,15 +1217,15 @@ static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, co
12141217
void BitcoinGUI::subscribeToCoreSignals()
12151218
{
12161219
// Connect signals to client
1217-
uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
1218-
uiInterface.ThreadSafeQuestion.connect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
1220+
m_handler_message_box = m_node.handleMessageBox(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
1221+
m_handler_question = m_node.handleQuestion(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
12191222
}
12201223

12211224
void BitcoinGUI::unsubscribeFromCoreSignals()
12221225
{
12231226
// Disconnect signals from client
1224-
uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
1225-
uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
1227+
m_handler_message_box->disconnect();
1228+
m_handler_question->disconnect();
12261229
}
12271230

12281231
void BitcoinGUI::toggleNetworkActive()

src/qt/bitcoingui.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <QPoint>
1919
#include <QSystemTrayIcon>
2020

21+
#include <memory>
22+
2123
class ClientModel;
2224
class NetworkStyle;
2325
class Notificator;
@@ -31,6 +33,11 @@ class WalletModel;
3133
class HelpMessageDialog;
3234
class ModalOverlay;
3335

36+
namespace interface {
37+
class Handler;
38+
class Node;
39+
}
40+
3441
QT_BEGIN_NAMESPACE
3542
class QAction;
3643
class QComboBox;
@@ -49,7 +56,7 @@ class BitcoinGUI : public QMainWindow
4956
public:
5057
static const std::string DEFAULT_UIPLATFORM;
5158

52-
explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);
59+
explicit BitcoinGUI(interface::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0);
5360
~BitcoinGUI();
5461

5562
/** Set the client model.
@@ -76,6 +83,9 @@ class BitcoinGUI : public QMainWindow
7683
bool eventFilter(QObject *object, QEvent *event);
7784

7885
private:
86+
interface::Node& m_node;
87+
std::unique_ptr<interface::Handler> m_handler_message_box;
88+
std::unique_ptr<interface::Handler> m_handler_question;
7989
ClientModel *clientModel;
8090
WalletFrame *walletFrame;
8191

0 commit comments

Comments
 (0)