Changeset View
Changeset View
Standalone View
Standalone View
src/qt/splashscreen.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | |||||
SplashScreen::~SplashScreen() { | SplashScreen::~SplashScreen() { | ||||
unsubscribeFromCoreSignals(); | unsubscribeFromCoreSignals(); | ||||
} | } | ||||
bool SplashScreen::eventFilter(QObject *obj, QEvent *ev) { | bool SplashScreen::eventFilter(QObject *obj, QEvent *ev) { | ||||
if (ev->type() == QEvent::KeyPress) { | if (ev->type() == QEvent::KeyPress) { | ||||
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); | QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev); | ||||
if (keyEvent->text()[0] == 'q' && breakAction != nullptr) { | if (keyEvent->text()[0] == 'q') { | ||||
breakAction(); | StartShutdown(); | ||||
} | } | ||||
} | } | ||||
return QObject::eventFilter(obj, ev); | return QObject::eventFilter(obj, ev); | ||||
} | } | ||||
void SplashScreen::slotFinish(QWidget *mainWin) { | void SplashScreen::slotFinish(QWidget *mainWin) { | ||||
Q_UNUSED(mainWin); | Q_UNUSED(mainWin); | ||||
/* If the window is minimized, hide() will be ignored. */ | /* If the window is minimized, hide() will be ignored. */ | ||||
/* Make sure we de-minimize the splashscreen window before hiding */ | /* Make sure we de-minimize the splashscreen window before hiding */ | ||||
if (isMinimized()) showNormal(); | if (isMinimized()) showNormal(); | ||||
hide(); | hide(); | ||||
deleteLater(); // No more need for this | deleteLater(); // No more need for this | ||||
} | } | ||||
static void InitMessage(SplashScreen *splash, const std::string &message) { | static void InitMessage(SplashScreen *splash, const std::string &message) { | ||||
QMetaObject::invokeMethod(splash, "showMessage", Qt::QueuedConnection, | QMetaObject::invokeMethod(splash, "showMessage", Qt::QueuedConnection, | ||||
Q_ARG(QString, QString::fromStdString(message)), | Q_ARG(QString, QString::fromStdString(message)), | ||||
Q_ARG(int, Qt::AlignBottom | Qt::AlignHCenter), | Q_ARG(int, Qt::AlignBottom | Qt::AlignHCenter), | ||||
Q_ARG(QColor, QColor(55, 55, 55))); | Q_ARG(QColor, QColor(55, 55, 55))); | ||||
} | } | ||||
static void ShowProgress(SplashScreen *splash, const std::string &title, | static void ShowProgress(SplashScreen *splash, const std::string &title, | ||||
int nProgress) { | int nProgress, bool resume_possible) { | ||||
InitMessage(splash, title + strprintf("%d", nProgress) + "%"); | InitMessage(splash, title + std::string("\n") + | ||||
} | (resume_possible | ||||
? _("(press q to shutdown and continue later)") | |||||
void SplashScreen::setBreakAction(const std::function<void(void)> &action) { | : _("press q to shutdown")) + | ||||
breakAction = action; | strprintf("\n%d", nProgress) + "%"); | ||||
} | |||||
static void SetProgressBreakAction(SplashScreen *splash, | |||||
const std::function<void(void)> &action) { | |||||
QMetaObject::invokeMethod(splash, "setBreakAction", Qt::QueuedConnection, | |||||
Q_ARG(std::function<void(void)>, action)); | |||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
void SplashScreen::ConnectWallet(CWallet *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); | connectedWallets.push_back(wallet); | ||||
} | } | ||||
#endif | #endif | ||||
void SplashScreen::subscribeToCoreSignals() { | void SplashScreen::subscribeToCoreSignals() { | ||||
// Connect signals to client | // Connect signals to client | ||||
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1)); | uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1)); | ||||
uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); | uiInterface.ShowProgress.connect( | ||||
uiInterface.SetProgressBreakAction.connect( | boost::bind(ShowProgress, this, _1, _2, _3)); | ||||
boost::bind(SetProgressBreakAction, this, _1)); | |||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
uiInterface.LoadWallet.connect( | uiInterface.LoadWallet.connect( | ||||
boost::bind(&SplashScreen::ConnectWallet, this, _1)); | boost::bind(&SplashScreen::ConnectWallet, this, _1)); | ||||
#endif | #endif | ||||
} | } | ||||
void SplashScreen::unsubscribeFromCoreSignals() { | void SplashScreen::unsubscribeFromCoreSignals() { | ||||
// Disconnect signals from client | // Disconnect signals from client | ||||
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); | uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); | ||||
uiInterface.ShowProgress.disconnect( | uiInterface.ShowProgress.disconnect( | ||||
boost::bind(ShowProgress, this, _1, _2)); | boost::bind(ShowProgress, this, _1, _2, _3)); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
for (CWallet *const &pwallet : connectedWallets) { | for (CWallet *const &pwallet : connectedWallets) { | ||||
pwallet->ShowProgress.disconnect( | pwallet->ShowProgress.disconnect( | ||||
boost::bind(ShowProgress, this, _1, _2)); | boost::bind(ShowProgress, this, _1, _2, false)); | ||||
} | } | ||||
#endif | #endif | ||||
} | } | ||||
void SplashScreen::showMessage(const QString &message, int alignment, | void SplashScreen::showMessage(const QString &message, int alignment, | ||||
const QColor &color) { | const QColor &color) { | ||||
curMessage = message; | curMessage = message; | ||||
curAlignment = alignment; | curAlignment = alignment; | ||||
Show All 17 Lines |