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.
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user