mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-11 23:58:18 +00:00
[Qt] allow to execute a callback during splashscreen progress
This commit is contained in:
parent
90a002ea64
commit
00cb69bc86
@ -578,6 +578,7 @@ int main(int argc, char *argv[])
|
|||||||
// Need to pass name here as CAmount is a typedef (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
|
// Need to pass name here as CAmount is a typedef (see http://qt-project.org/doc/qt-5/qmetatype.html#qRegisterMetaType)
|
||||||
// IMPORTANT if it is no longer a typedef use the normal variant above
|
// IMPORTANT if it is no longer a typedef use the normal variant above
|
||||||
qRegisterMetaType< CAmount >("CAmount");
|
qRegisterMetaType< CAmount >("CAmount");
|
||||||
|
qRegisterMetaType< std::function<void(void)> >("std::function<void(void)>");
|
||||||
|
|
||||||
/// 3. Application identification
|
/// 3. Application identification
|
||||||
// must be set before OptionsModel is initialized or translations are loaded,
|
// must be set before OptionsModel is initialized or translations are loaded,
|
||||||
|
@ -131,6 +131,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
|
|||||||
move(QApplication::desktop()->screenGeometry().center() - r.center());
|
move(QApplication::desktop()->screenGeometry().center() - r.center());
|
||||||
|
|
||||||
subscribeToCoreSignals();
|
subscribeToCoreSignals();
|
||||||
|
installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SplashScreen::~SplashScreen()
|
SplashScreen::~SplashScreen()
|
||||||
@ -138,6 +139,16 @@ SplashScreen::~SplashScreen()
|
|||||||
unsubscribeFromCoreSignals();
|
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)
|
void SplashScreen::slotFinish(QWidget *mainWin)
|
||||||
{
|
{
|
||||||
Q_UNUSED(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) + "%");
|
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
|
#ifdef ENABLE_WALLET
|
||||||
void SplashScreen::ConnectWallet(CWallet* wallet)
|
void SplashScreen::ConnectWallet(CWallet* wallet)
|
||||||
{
|
{
|
||||||
@ -177,6 +200,7 @@ 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(boost::bind(ShowProgress, this, _1, _2));
|
||||||
|
uiInterface.SetProgressBreakAction.connect(boost::bind(SetProgressBreakAction, this, _1));
|
||||||
#ifdef ENABLE_WALLET
|
#ifdef ENABLE_WALLET
|
||||||
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
|
uiInterface.LoadWallet.connect(boost::bind(&SplashScreen::ConnectWallet, this, _1));
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef BITCOIN_QT_SPLASHSCREEN_H
|
#ifndef BITCOIN_QT_SPLASHSCREEN_H
|
||||||
#define BITCOIN_QT_SPLASHSCREEN_H
|
#define BITCOIN_QT_SPLASHSCREEN_H
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <QSplashScreen>
|
#include <QSplashScreen>
|
||||||
|
|
||||||
class CWallet;
|
class CWallet;
|
||||||
@ -35,6 +36,11 @@ public Q_SLOTS:
|
|||||||
/** Show message and progress */
|
/** Show message and progress */
|
||||||
void showMessage(const QString &message, int alignment, const QColor &color);
|
void showMessage(const QString &message, int alignment, const QColor &color);
|
||||||
|
|
||||||
|
/** Sets the break action */
|
||||||
|
void setBreakAction(const std::function<void(void)> &action);
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject * obj, QEvent * ev);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Connect core signals to splash screen */
|
/** Connect core signals to splash screen */
|
||||||
void subscribeToCoreSignals();
|
void subscribeToCoreSignals();
|
||||||
@ -49,6 +55,8 @@ private:
|
|||||||
int curAlignment;
|
int curAlignment;
|
||||||
|
|
||||||
QList<CWallet*> connectedWallets;
|
QList<CWallet*> connectedWallets;
|
||||||
|
|
||||||
|
std::function<void(void)> breakAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_QT_SPLASHSCREEN_H
|
#endif // BITCOIN_QT_SPLASHSCREEN_H
|
||||||
|
@ -97,6 +97,9 @@ public:
|
|||||||
/** Show progress e.g. for verifychain */
|
/** Show progress e.g. for verifychain */
|
||||||
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
boost::signals2::signal<void (const std::string &title, int nProgress)> ShowProgress;
|
||||||
|
|
||||||
|
/** Set progress break action (possible "cancel button" triggers that action) */
|
||||||
|
boost::signals2::signal<void (std::function<void(void)> action)> SetProgressBreakAction;
|
||||||
|
|
||||||
/** New block has been accepted */
|
/** New block has been accepted */
|
||||||
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;
|
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user