aboutsummaryrefslogtreecommitdiff
path: root/src/qt/splashscreen.cpp
diff options
context:
space:
mode:
authorJonas Schnelli <dev@jonasschnelli.ch>2017-06-23 09:32:38 +0200
committerJonas Schnelli <dev@jonasschnelli.ch>2017-06-29 17:48:08 +0200
commit00cb69bc8655b1c17064a7e42453fd049e555076 (patch)
treee6b4f5be586f06f073c5a35e30f18e4e845f066d /src/qt/splashscreen.cpp
parent90a002ea647dcea57a2ed4294eab77897168ba1d (diff)
[Qt] allow to execute a callback during splashscreen progress
Diffstat (limited to 'src/qt/splashscreen.cpp')
-rw-r--r--src/qt/splashscreen.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index 10966e42eb..1b7cc69231 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -131,6 +131,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
move(QApplication::desktop()->screenGeometry().center() - r.center());
subscribeToCoreSignals();
+ installEventFilter(this);
}
SplashScreen::~SplashScreen()
@@ -138,6 +139,16 @@ SplashScreen::~SplashScreen()
unsubscribeFromCoreSignals();
}
+bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
+ if (ev->type() == QEvent::KeyPress) {
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
+ if(keyEvent->text()[0] == 'q' && breakAction != nullptr) {
+ breakAction();
+ }
+ }
+ return QObject::eventFilter(obj, ev);
+}
+
void SplashScreen::slotFinish(QWidget *mainWin)
{
Q_UNUSED(mainWin);
@@ -164,6 +175,18 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
InitMessage(splash, title + strprintf("%d", nProgress) + "%");
}
+void SplashScreen::setBreakAction(const std::function<void(void)> &action)
+{
+ breakAction = action;
+}
+
+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
void SplashScreen::ConnectWallet(CWallet* wallet)
{
@@ -177,6 +200,7 @@ 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));
#ifdef ENABLE_WALLET
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
#endif