Skip to content

Commit

Permalink
Have Qt poll for shutdown requested, the QT way.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinandresen committed Apr 3, 2013
1 parent 7861f02 commit d8b0498
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ enum BindFlags {
// immediately and the parent exits from main().
//
// Shutdown for Qt is very similar, only it uses a QTimer to detect
// fRequestShutdown getting set (either by RPC stop or SIGTERM)
// and then does the normal Qt shutdown thing.
// fRequestShutdown getting set, and then does the normal Qt
// shutdown thing.
//

volatile bool fRequestShutdown = false;
Expand All @@ -71,6 +71,10 @@ void StartShutdown()
{
fRequestShutdown = true;
}
bool ShutdownRequested()
{
return fRequestShutdown;
}

static CCoinsViewDB *pcoinsdbview;

Expand Down
1 change: 1 addition & 0 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
extern CWallet* pwalletMain;

void StartShutdown();
bool ShutdownRequested();
void Shutdown();
bool AppInit2(boost::thread_group& threadGroup);
std::string HelpMessage();
Expand Down
12 changes: 6 additions & 6 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ static void InitMessage(const std::string &message)
printf("init message: %s\n", message.c_str());
}

static void QueueShutdown()
{
QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection);
}

/*
Translate string to current locale using Qt.
*/
Expand Down Expand Up @@ -186,7 +181,6 @@ int main(int argc, char *argv[])
uiInterface.ThreadSafeMessageBox.connect(ThreadSafeMessageBox);
uiInterface.ThreadSafeAskFee.connect(ThreadSafeAskFee);
uiInterface.InitMessage.connect(InitMessage);
uiInterface.QueueShutdown.connect(QueueShutdown);
uiInterface.Translate.connect(Translate);

// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
Expand Down Expand Up @@ -217,8 +211,14 @@ int main(int argc, char *argv[])
GUIUtil::SetStartOnSystemStartup(true);

boost::thread_group threadGroup;

BitcoinGUI window;
guiref = &window;

QTimer* pollShutdownTimer = new QTimer(guiref);
QObject::connect(pollShutdownTimer, SIGNAL(timeout()), guiref, SLOT(detectShutdown()));
pollShutdownTimer->start(200);

if(AppInit2(threadGroup))
{
{
Expand Down
7 changes: 7 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "rpcconsole.h"
#include "ui_interface.h"
#include "wallet.h"
#include "init.h"

#ifdef Q_OS_MAC
#include "macdockiconhandler.h"
Expand Down Expand Up @@ -839,3 +840,9 @@ void BitcoinGUI::toggleHidden()
{
showNormalIfMinimized(true);
}

void BitcoinGUI::detectShutdown()
{
if (ShutdownRequested())
QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
}
3 changes: 3 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ private slots:
void showNormalIfMinimized(bool fToggleHidden = false);
/** Simply calls showNormalIfMinimized(true) for use in SLOT() macro */
void toggleHidden();

/** called by a timer to check if fRequestShutdown has been set **/
void detectShutdown();
};

#endif // BITCOINGUI_H
3 changes: 0 additions & 3 deletions src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ class CClientUIInterface
/** Progress message during initialization. */
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. */
boost::signals2::signal<std::string (const char* psz)> Translate;

Expand Down

0 comments on commit d8b0498

Please sign in to comment.