Browse Source

Have Qt poll for shutdown requested, the QT way.

0.8
Gavin Andresen 12 years ago
parent
commit
723035bb68
  1. 8
      src/init.cpp
  2. 1
      src/init.h
  3. 12
      src/qt/bitcoin.cpp
  4. 7
      src/qt/bitcoingui.cpp
  5. 3
      src/qt/bitcoingui.h
  6. 3
      src/ui_interface.h

8
src/init.cpp

@ -61,8 +61,8 @@ enum BindFlags {
// immediately and the parent exits from main(). // immediately and the parent exits from main().
// //
// Shutdown for Qt is very similar, only it uses a QTimer to detect // Shutdown for Qt is very similar, only it uses a QTimer to detect
// fRequestShutdown getting set (either by RPC stop or SIGTERM) // fRequestShutdown getting set, and then does the normal Qt
// and then does the normal Qt shutdown thing. // shutdown thing.
// //
volatile bool fRequestShutdown = false; volatile bool fRequestShutdown = false;
@ -71,6 +71,10 @@ void StartShutdown()
{ {
fRequestShutdown = true; fRequestShutdown = true;
} }
bool ShutdownRequested()
{
return fRequestShutdown;
}
static CCoinsViewDB *pcoinsdbview; static CCoinsViewDB *pcoinsdbview;

1
src/init.h

@ -10,6 +10,7 @@
extern CWallet* pwalletMain; extern CWallet* pwalletMain;
void StartShutdown(); void StartShutdown();
bool ShutdownRequested();
void Shutdown(); void Shutdown();
bool AppInit2(boost::thread_group& threadGroup); bool AppInit2(boost::thread_group& threadGroup);
std::string HelpMessage(); std::string HelpMessage();

12
src/qt/bitcoin.cpp

@ -88,11 +88,6 @@ static void InitMessage(const std::string &message)
printf("init message: %s\n", message.c_str()); printf("init message: %s\n", message.c_str());
} }
static void QueueShutdown()
{
QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
}
/* /*
Translate string to current locale using Qt. Translate string to current locale using Qt.
*/ */
@ -186,7 +181,6 @@ int main(int argc, char *argv[])
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox); uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee); uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
uiInterface.InitMessage.connect(InitMessage); uiInterface.InitMessage.connect(InitMessage);
uiInterface.QueueShutdown.connect(QueueShutdown);
uiInterface.Translate.connect(Translate); uiInterface.Translate.connect(Translate);
// Show help message immediately after parsing command-line options (for "-lang") and setting locale, // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
@ -217,8 +211,14 @@ int main(int argc, char *argv[])
GUIUtil::SetStartOnSystemStartup(true); GUIUtil::SetStartOnSystemStartup(true);
boost::thread_group threadGroup; boost::thread_group threadGroup;
BitcoinGUI window; BitcoinGUI window;
guiref = &window; guiref = &window;
QTimer* pollShutdownTimer = new QTimer(guiref);
QObject::connect(pollShutdownTimer, SIGNAL(timeout()), guiref, SLOT(detectShutdown()));
pollShutdownTimer->start(200);
if(AppInit2(threadGroup)) if(AppInit2(threadGroup))
{ {
{ {

7
src/qt/bitcoingui.cpp

@ -24,6 +24,7 @@
#include "rpcconsole.h" #include "rpcconsole.h"
#include "ui_interface.h" #include "ui_interface.h"
#include "wallet.h" #include "wallet.h"
#include "init.h"
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
#include "macdockiconhandler.h" #include "macdockiconhandler.h"
@ -839,3 +840,9 @@ void BitcoinGUI::toggleHidden()
{ {
showNormalIfMinimized(true); showNormalIfMinimized(true);
} }
void BitcoinGUI::detectShutdown()
{
if (ShutdownRequested())
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
}

3
src/qt/bitcoingui.h

@ -199,6 +199,9 @@ private slots:
void showNormalIfMinimized(bool fToggleHidden = false); void showNormalIfMinimized(bool fToggleHidden = false);
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */ /** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
void toggleHidden(); void toggleHidden();
/** called by a timer to check if fRequestShutdown has been set **/
void detectShutdown();
}; };
#endif // BITCOINGUI_H #endif // BITCOINGUI_H

3
src/ui_interface.h

@ -79,9 +79,6 @@ public:
/** Progress message during initialization. */ /** Progress message during initialization. */
boost::signals2::signal<void (const std::string &message)> InitMessage; boost::signals2::signal<void (const std::string &message)> InitMessage;
/** Initiate client shutdown. */
boost::signals2::signal<void ()> QueueShutdown;
/** Translate a message to the native language of the user. */ /** Translate a message to the native language of the user. */
boost::signals2::signal<std::string (const char* psz)> Translate; boost::signals2::signal<std::string (const char* psz)> Translate;

Loading…
Cancel
Save