aboutsummaryrefslogtreecommitdiff
path: root/src/qt/bitcoingui.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-01-08 08:59:24 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2014-01-11 10:20:28 +0100
commit35ecf854c084c248ad640c6af030a9d1ed726c47 (patch)
tree06dc516ca6c4e60bc841cfe49cfda089ef1fc005 /src/qt/bitcoingui.cpp
parent55fe4de96056cf7b6bdf708a2912927dc9857207 (diff)
qt: Remove global references in bitcoin.cpp
Remove the need for global references `guiref` and `splashref` by making the BitcoinGUI and SplashScreen classes register for the UI interface signals themselves.
Diffstat (limited to 'src/qt/bitcoingui.cpp')
-rw-r--r--src/qt/bitcoingui.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index 6be5a64015..f8daa08c4d 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -170,10 +170,16 @@ BitcoinGUI::BitcoinGUI(bool fIsTestnet, QWidget *parent) :
// Initially wallet actions should be disabled
setWalletActionsEnabled(false);
+
+ // Subscribe to notifications from core
+ subscribeToCoreSignals();
}
BitcoinGUI::~BitcoinGUI()
{
+ // Unsubscribe from notifications from core
+ unsubscribeFromCoreSignals();
+
GUIUtil::saveWindowGeometry("nWindow", this);
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
trayIcon->hide();
@@ -851,3 +857,29 @@ void BitcoinGUI::detectShutdown()
if (ShutdownRequested())
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
}
+
+static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
+{
+ bool modal = (style & CClientUIInterface::MODAL);
+ bool ret = false;
+ // In case of modal message, use blocking connection to wait for user to click a button
+ QMetaObject::invokeMethod(gui, "message",
+ modal ? GUIUtil::blockingGUIThreadConnection() : Qt::QueuedConnection,
+ Q_ARG(QString, QString::fromStdString(caption)),
+ Q_ARG(QString, QString::fromStdString(message)),
+ Q_ARG(unsigned int, style),
+ Q_ARG(bool*, &ret));
+ return ret;
+}
+
+void BitcoinGUI::subscribeToCoreSignals()
+{
+ // Connect signals to client
+ uiInterface.ThreadSafeMessageBox.connect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
+}
+
+void BitcoinGUI::unsubscribeFromCoreSignals()
+{
+ // Disconnect signals from client
+ uiInterface.ThreadSafeMessageBox.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _2, _3));
+}