From 3d619e9d3658e36cba4a19a5bed33e5538317b27 Mon Sep 17 00:00:00 2001 From: Russell Yanofsky Date: Mon, 17 Apr 2017 14:33:47 -0400 Subject: Remove direct bitcoin calls from qt/bitcoingui.cpp --- src/interface/node.cpp | 9 +++++++++ src/interface/node.h | 15 +++++++++++++++ src/qt/bitcoin.cpp | 2 +- src/qt/bitcoingui.cpp | 15 +++++++++------ src/qt/bitcoingui.h | 12 +++++++++++- 5 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/interface/node.cpp b/src/interface/node.cpp index 877c5f57a8..7bfe79ed50 100644 --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -45,6 +45,7 @@ class NodeImpl : public Node Shutdown(); } void startShutdown() override { StartShutdown(); } + bool shutdownRequested() override { return ShutdownRequested(); } void mapPort(bool use_upnp) override { if (use_upnp) { @@ -59,6 +60,14 @@ class NodeImpl : public Node { return MakeHandler(::uiInterface.InitMessage.connect(fn)); } + std::unique_ptr handleMessageBox(MessageBoxFn fn) override + { + return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); + } + std::unique_ptr handleQuestion(QuestionFn fn) override + { + return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); + } }; } // namespace diff --git a/src/interface/node.h b/src/interface/node.h index 368bade28b..00304cce24 100644 --- a/src/interface/node.h +++ b/src/interface/node.h @@ -59,6 +59,9 @@ public: //! Start shutdown. virtual void startShutdown() = 0; + //! Return whether shutdown was requested. + virtual bool shutdownRequested() = 0; + //! Map port. virtual void mapPort(bool use_upnp) = 0; @@ -68,6 +71,18 @@ public: //! Register handler for init messages. using InitMessageFn = std::function; virtual std::unique_ptr handleInitMessage(InitMessageFn fn) = 0; + + //! Register handler for message box messages. + using MessageBoxFn = + std::function; + virtual std::unique_ptr handleMessageBox(MessageBoxFn fn) = 0; + + //! Register handler for question messages. + using QuestionFn = std::function; + virtual std::unique_ptr handleQuestion(QuestionFn fn) = 0; }; //! Return implementation of Node interface. diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 3cce9d9bf6..aad276fd1d 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -367,7 +367,7 @@ void BitcoinApplication::createOptionsModel(bool resetSettings) void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) { - window = new BitcoinGUI(platformStyle, networkStyle, 0); + window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0); pollShutdownTimer = new QTimer(window); connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown())); diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index e4207fce99..5e590ec7d2 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include @@ -72,9 +74,10 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM = #endif ; -BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) : +BitcoinGUI::BitcoinGUI(interface::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) : QMainWindow(parent), enableWallet(false), + m_node(node), clientModel(0), walletFrame(0), unitDisplayControl(0), @@ -1149,7 +1152,7 @@ void BitcoinGUI::toggleHidden() void BitcoinGUI::detectShutdown() { - if (ShutdownRequested()) + if (m_node.shutdownRequested()) { if(rpcConsole) rpcConsole->hide(); @@ -1214,15 +1217,15 @@ static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, co void BitcoinGUI::subscribeToCoreSignals() { // Connect signals to client - uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); - uiInterface.ThreadSafeQuestion.connect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); + m_handler_message_box = m_node.handleMessageBox(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); + m_handler_question = m_node.handleQuestion(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); } void BitcoinGUI::unsubscribeFromCoreSignals() { // Disconnect signals from client - uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); - uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); + m_handler_message_box->disconnect(); + m_handler_question->disconnect(); } void BitcoinGUI::toggleNetworkActive() diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index b9e92f2d5b..3a4b25d804 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -18,6 +18,8 @@ #include #include +#include + class ClientModel; class NetworkStyle; class Notificator; @@ -31,6 +33,11 @@ class WalletModel; class HelpMessageDialog; class ModalOverlay; +namespace interface { +class Handler; +class Node; +} + QT_BEGIN_NAMESPACE class QAction; class QComboBox; @@ -49,7 +56,7 @@ class BitcoinGUI : public QMainWindow public: static const std::string DEFAULT_UIPLATFORM; - explicit BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0); + explicit BitcoinGUI(interface::Node& node, const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0); ~BitcoinGUI(); /** Set the client model. @@ -76,6 +83,9 @@ protected: bool eventFilter(QObject *object, QEvent *event); private: + interface::Node& m_node; + std::unique_ptr m_handler_message_box; + std::unique_ptr m_handler_question; ClientModel *clientModel; WalletFrame *walletFrame; -- cgit v1.2.3