diff --git a/src/qt/splashscreen.h b/src/qt/splashscreen.h --- a/src/qt/splashscreen.h +++ b/src/qt/splashscreen.h @@ -36,9 +36,6 @@ void showMessage(const QString &message, int alignment, const QColor &color); - /** Sets the break action */ - void setBreakAction(const std::function &action); - protected: bool eventFilter(QObject *obj, QEvent *ev) override; @@ -56,8 +53,6 @@ int curAlignment; QList connectedWallets; - - std::function breakAction; }; #endif // BITCOIN_QT_SPLASHSCREEN_H diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -156,8 +156,8 @@ bool SplashScreen::eventFilter(QObject *obj, QEvent *ev) { if (ev->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(ev); - if (keyEvent->text()[0] == 'q' && breakAction != nullptr) { - breakAction(); + if (keyEvent->text()[0] == 'q') { + StartShutdown(); } } return QObject::eventFilter(obj, ev); @@ -181,23 +181,18 @@ } static void ShowProgress(SplashScreen *splash, const std::string &title, - int nProgress) { - InitMessage(splash, title + strprintf("%d", nProgress) + "%"); -} - -void SplashScreen::setBreakAction(const std::function &action) { - breakAction = action; -} - -static void SetProgressBreakAction(SplashScreen *splash, - const std::function &action) { - QMetaObject::invokeMethod(splash, "setBreakAction", Qt::QueuedConnection, - Q_ARG(std::function, action)); + int nProgress, bool resume_possible) { + InitMessage(splash, title + std::string("\n") + + (resume_possible + ? _("(press q to shutdown and continue later)") + : _("press q to shutdown")) + + strprintf("\n%d", nProgress) + "%"); } #ifdef ENABLE_WALLET void SplashScreen::ConnectWallet(CWallet *wallet) { - wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); + wallet->ShowProgress.connect( + boost::bind(ShowProgress, this, _1, _2, false)); connectedWallets.push_back(wallet); } #endif @@ -205,9 +200,8 @@ void SplashScreen::subscribeToCoreSignals() { // Connect signals to client uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1)); - uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); - uiInterface.SetProgressBreakAction.connect( - boost::bind(SetProgressBreakAction, this, _1)); + uiInterface.ShowProgress.connect( + boost::bind(ShowProgress, this, _1, _2, _3)); #ifdef ENABLE_WALLET uiInterface.LoadWallet.connect( boost::bind(&SplashScreen::ConnectWallet, this, _1)); @@ -218,11 +212,11 @@ // Disconnect signals from client uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); uiInterface.ShowProgress.disconnect( - boost::bind(ShowProgress, this, _1, _2)); + boost::bind(ShowProgress, this, _1, _2, _3)); #ifdef ENABLE_WALLET for (CWallet *const &pwallet : connectedWallets) { pwallet->ShowProgress.disconnect( - boost::bind(ShowProgress, this, _1, _2)); + boost::bind(ShowProgress, this, _1, _2, false)); } #endif } diff --git a/src/txdb.cpp b/src/txdb.cpp --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -391,9 +391,9 @@ int64_t count = 0; LogPrintf("Upgrading utxo-set database...\n"); LogPrintf("[0%%]..."); + uiInterface.ShowProgress(_("Upgrading UTXO database"), 0, true); size_t batch_size = 1 << 24; CDBBatch batch(db); - uiInterface.SetProgressBreakAction(StartShutdown); int reportDone = 0; std::pair key; std::pair prev_key = {DB_COINS, uint256()}; @@ -411,10 +411,8 @@ uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1); int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5); - uiInterface.ShowProgress( - _("Upgrading UTXO database") + "\n" + - _("(press q to shutdown and continue later)") + "\n", - percentageDone); + uiInterface.ShowProgress(_("Upgrading UTXO database"), + percentageDone, true); if (reportDone < percentageDone / 10) { // report max. every 10% step LogPrintf("[%d%%]...", percentageDone); @@ -452,7 +450,7 @@ db.WriteBatch(batch); db.CompactRange({DB_COINS, uint256()}, key); - uiInterface.SetProgressBreakAction(std::function()); + uiInterface.ShowProgress("", 100, false); LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE"); return !ShutdownRequested(); } diff --git a/src/ui_interface.h b/src/ui_interface.h --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -111,15 +111,15 @@ /** A wallet has been loaded. */ boost::signals2::signal LoadWallet; - /** Show progress e.g. for verifychain */ - boost::signals2::signal + /** + * Show progress e.g. for verifychain. + * resume_possible indicates shutting down now will result in the current + * progress action resuming upon restart. + */ + boost::signals2::signal ShowProgress; - /** Set progress break action (possible "cancel button" triggers that - * action) */ - boost::signals2::signal action)> - SetProgressBreakAction; - /** New block has been accepted */ boost::signals2::signal NotifyBlockTip; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4438,11 +4438,11 @@ } CVerifyDB::CVerifyDB() { - uiInterface.ShowProgress(_("Verifying blocks..."), 0); + uiInterface.ShowProgress(_("Verifying blocks..."), 0, false); } CVerifyDB::~CVerifyDB() { - uiInterface.ShowProgress("", 100); + uiInterface.ShowProgress("", 100, false); } bool CVerifyDB::VerifyDB(const Config &config, CCoinsView *coinsview, @@ -4488,7 +4488,8 @@ reportDone = percentageDone / 10; } - uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone); + uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone, + false); if (pindex->nHeight < chainActive.Height() - nCheckDepth) { break; } @@ -4577,7 +4578,8 @@ std::max( 1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / - (double)nCheckDepth * 50)))); + (double)nCheckDepth * 50))), + false); pindex = chainActive.Next(pindex); CBlock block; if (!ReadBlockFromDisk(block, pindex, config)) { @@ -4647,7 +4649,7 @@ return error("ReplayBlocks(): unknown inconsistent state"); } - uiInterface.ShowProgress(_("Replaying blocks..."), 0); + uiInterface.ShowProgress(_("Replaying blocks..."), 0, false); LogPrintf("Replaying blocks\n"); // Old tip during the interrupted flush. @@ -4722,7 +4724,7 @@ cache.SetBestBlock(pindexNew->GetBlockHash()); cache.Flush(); - uiInterface.ShowProgress("", 100); + uiInterface.ShowProgress("", 100, false); return true; }