diff --git a/src/interface/node.h b/src/interface/node.h --- a/src/interface/node.h +++ b/src/interface/node.h @@ -64,6 +64,9 @@ //! Start shutdown. virtual void startShutdown() = 0; + //! Return whether shutdown was requested. + virtual bool shutdownRequested() = 0; + //! Map port. virtual void mapPort(bool use_upnp) = 0; @@ -73,6 +76,18 @@ //! 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/interface/node.cpp b/src/interface/node.cpp --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -60,6 +60,7 @@ Shutdown(); } void startShutdown() override { StartShutdown(); } + bool shutdownRequested() override { return ShutdownRequested(); } void mapPort(bool use_upnp) override { if (use_upnp) { StartMapPort(); @@ -74,6 +75,12 @@ std::unique_ptr handleInitMessage(InitMessageFn fn) override { 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/qt/bitcoin.cpp b/src/qt/bitcoin.cpp --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -350,7 +350,7 @@ void BitcoinApplication::createWindow(const Config *config, const NetworkStyle *networkStyle) { - window = new BitcoinGUI(config, platformStyle, networkStyle, 0); + window = new BitcoinGUI(m_node, config, platformStyle, networkStyle, 0); pollShutdownTimer = new QTimer(window); connect(pollShutdownTimer, SIGNAL(timeout()), window, diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -18,6 +18,8 @@ #include #include +#include + class ClientModel; class NetworkStyle; class Notificator; @@ -34,6 +36,11 @@ class Config; class CWallet; +namespace interface { +class Handler; +class Node; +} + QT_BEGIN_NAMESPACE class QAction; class QComboBox; @@ -52,7 +59,8 @@ public: static const std::string DEFAULT_UIPLATFORM; - explicit BitcoinGUI(const Config *, const PlatformStyle *platformStyle, + explicit BitcoinGUI(interface::Node &node, const Config *, + const PlatformStyle *platformStyle, const NetworkStyle *networkStyle, QWidget *parent = 0); ~BitcoinGUI(); @@ -83,6 +91,9 @@ bool eventFilter(QObject *object, QEvent *event) override; private: + interface::Node &m_node; + std::unique_ptr m_handler_message_box; + std::unique_ptr m_handler_question; ClientModel *clientModel = nullptr; WalletFrame *walletFrame = nullptr; diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -34,6 +34,8 @@ #include "chainparams.h" #include "init.h" +#include "interface/handler.h" +#include "interface/node.h" #include "ui_interface.h" #include "util.h" @@ -70,11 +72,11 @@ #endif ; -BitcoinGUI::BitcoinGUI(const Config *configIn, +BitcoinGUI::BitcoinGUI(interface::Node &node, const Config *configIn, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) - : QMainWindow(parent), enableWallet(false), platformStyle(_platformStyle), - config(configIn) { + : QMainWindow(parent), enableWallet(false), m_node(node), + platformStyle(_platformStyle), config(configIn) { QSettings settings; if (!restoreGeometry(settings.value("MainWindowGeometry").toByteArray())) { // Restore failed (perhaps missing setting), center the window @@ -1184,7 +1186,7 @@ } void BitcoinGUI::detectShutdown() { - if (ShutdownRequested()) { + if (m_node.shutdownRequested()) { if (rpcConsole) { rpcConsole->hide(); } @@ -1244,18 +1246,16 @@ void BitcoinGUI::subscribeToCoreSignals() { // Connect signals to client - uiInterface.ThreadSafeMessageBox.connect( + m_handler_message_box = m_node.handleMessageBox( boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); - uiInterface.ThreadSafeQuestion.connect( + 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() {