Remove direct bitcoin calls from qt/bitcoingui.cpp

This commit is contained in:
Russell Yanofsky 2017-04-17 14:33:47 -04:00 committed by John Newbery
parent c0f2756be5
commit 3d619e9d36
5 changed files with 45 additions and 8 deletions

View File

@ -45,6 +45,7 @@ class NodeImpl : public Node
Shutdown(); Shutdown();
} }
void startShutdown() override { StartShutdown(); } void startShutdown() override { StartShutdown(); }
bool shutdownRequested() override { return ShutdownRequested(); }
void mapPort(bool use_upnp) override void mapPort(bool use_upnp) override
{ {
if (use_upnp) { if (use_upnp) {
@ -59,6 +60,14 @@ class NodeImpl : public Node
{ {
return MakeHandler(::uiInterface.InitMessage.connect(fn)); return MakeHandler(::uiInterface.InitMessage.connect(fn));
} }
std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn));
}
std::unique_ptr<Handler> handleQuestion(QuestionFn fn) override
{
return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn));
}
}; };
} // namespace } // namespace

View File

@ -59,6 +59,9 @@ public:
//! Start shutdown. //! Start shutdown.
virtual void startShutdown() = 0; virtual void startShutdown() = 0;
//! Return whether shutdown was requested.
virtual bool shutdownRequested() = 0;
//! Map port. //! Map port.
virtual void mapPort(bool use_upnp) = 0; virtual void mapPort(bool use_upnp) = 0;
@ -68,6 +71,18 @@ public:
//! Register handler for init messages. //! Register handler for init messages.
using InitMessageFn = std::function<void(const std::string& message)>; using InitMessageFn = std::function<void(const std::string& message)>;
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0; virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
//! Register handler for message box messages.
using MessageBoxFn =
std::function<bool(const std::string& message, const std::string& caption, unsigned int style)>;
virtual std::unique_ptr<Handler> handleMessageBox(MessageBoxFn fn) = 0;
//! Register handler for question messages.
using QuestionFn = std::function<bool(const std::string& message,
const std::string& non_interactive_message,
const std::string& caption,
unsigned int style)>;
virtual std::unique_ptr<Handler> handleQuestion(QuestionFn fn) = 0;
}; };
//! Return implementation of Node interface. //! Return implementation of Node interface.

View File

@ -367,7 +367,7 @@ void BitcoinApplication::createOptionsModel(bool resetSettings)
void BitcoinApplication::createWindow(const NetworkStyle *networkStyle) void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
{ {
window = new BitcoinGUI(platformStyle, networkStyle, 0); window = new BitcoinGUI(m_node, platformStyle, networkStyle, 0);
pollShutdownTimer = new QTimer(window); pollShutdownTimer = new QTimer(window);
connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown())); connect(pollShutdownTimer, SIGNAL(timeout()), window, SLOT(detectShutdown()));

View File

@ -30,6 +30,8 @@
#include <chainparams.h> #include <chainparams.h>
#include <init.h> #include <init.h>
#include <interface/handler.h>
#include <interface/node.h>
#include <ui_interface.h> #include <ui_interface.h>
#include <util.h> #include <util.h>
@ -72,9 +74,10 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#endif #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), QMainWindow(parent),
enableWallet(false), enableWallet(false),
m_node(node),
clientModel(0), clientModel(0),
walletFrame(0), walletFrame(0),
unitDisplayControl(0), unitDisplayControl(0),
@ -1149,7 +1152,7 @@ void BitcoinGUI::toggleHidden()
void BitcoinGUI::detectShutdown() void BitcoinGUI::detectShutdown()
{ {
if (ShutdownRequested()) if (m_node.shutdownRequested())
{ {
if(rpcConsole) if(rpcConsole)
rpcConsole->hide(); rpcConsole->hide();
@ -1214,15 +1217,15 @@ static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, co
void BitcoinGUI::subscribeToCoreSignals() void BitcoinGUI::subscribeToCoreSignals()
{ {
// Connect signals to client // Connect signals to client
uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); m_handler_message_box = m_node.handleMessageBox(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
uiInterface.ThreadSafeQuestion.connect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); m_handler_question = m_node.handleQuestion(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
} }
void BitcoinGUI::unsubscribeFromCoreSignals() void BitcoinGUI::unsubscribeFromCoreSignals()
{ {
// Disconnect signals from client // Disconnect signals from client
uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3)); m_handler_message_box->disconnect();
uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4)); m_handler_question->disconnect();
} }
void BitcoinGUI::toggleNetworkActive() void BitcoinGUI::toggleNetworkActive()

View File

@ -18,6 +18,8 @@
#include <QPoint> #include <QPoint>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <memory>
class ClientModel; class ClientModel;
class NetworkStyle; class NetworkStyle;
class Notificator; class Notificator;
@ -31,6 +33,11 @@ class WalletModel;
class HelpMessageDialog; class HelpMessageDialog;
class ModalOverlay; class ModalOverlay;
namespace interface {
class Handler;
class Node;
}
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QAction; class QAction;
class QComboBox; class QComboBox;
@ -49,7 +56,7 @@ class BitcoinGUI : public QMainWindow
public: public:
static const std::string DEFAULT_UIPLATFORM; 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(); ~BitcoinGUI();
/** Set the client model. /** Set the client model.
@ -76,6 +83,9 @@ protected:
bool eventFilter(QObject *object, QEvent *event); bool eventFilter(QObject *object, QEvent *event);
private: private:
interface::Node& m_node;
std::unique_ptr<interface::Handler> m_handler_message_box;
std::unique_ptr<interface::Handler> m_handler_question;
ClientModel *clientModel; ClientModel *clientModel;
WalletFrame *walletFrame; WalletFrame *walletFrame;