Changeset View
Changeset View
Standalone View
Standalone View
src/qt/splashscreen.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#if defined(HAVE_CONFIG_H) | #if defined(HAVE_CONFIG_H) | ||||
#include "config/bitcoin-config.h" | #include "config/bitcoin-config.h" | ||||
#endif | #endif | ||||
#include "splashscreen.h" | #include "splashscreen.h" | ||||
#include "networkstyle.h" | #include "networkstyle.h" | ||||
#include "clientversion.h" | #include "clientversion.h" | ||||
#include "init.h" | #include "init.h" | ||||
#include "interfaces/handler.h" | |||||
#include "interfaces/node.h" | |||||
#include "interfaces/wallet.h" | |||||
#include "ui_interface.h" | #include "ui_interface.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "version.h" | #include "version.h" | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
#endif | #endif | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QCloseEvent> | #include <QCloseEvent> | ||||
#include <QDesktopWidget> | #include <QDesktopWidget> | ||||
#include <QPainter> | #include <QPainter> | ||||
#include <QRadialGradient> | #include <QRadialGradient> | ||||
SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle) | SplashScreen::SplashScreen(interfaces::Node &node, Qt::WindowFlags f, | ||||
: QWidget(0, f), curAlignment(0) { | const NetworkStyle *networkStyle) | ||||
: QWidget(0, f), curAlignment(0), m_node(node) { | |||||
// set reference point, paddings | // set reference point, paddings | ||||
int paddingRight = 50; | int paddingRight = 50; | ||||
int paddingTop = 50; | int paddingTop = 50; | ||||
int titleVersionVSpace = 17; | int titleVersionVSpace = 17; | ||||
int titleCopyrightVSpace = 40; | int titleCopyrightVSpace = 40; | ||||
float fontFactor = 1.0; | float fontFactor = 1.0; | ||||
float devicePixelRatio = 1.0; | float devicePixelRatio = 1.0; | ||||
▲ Show 20 Lines • Show All 114 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') { | if (keyEvent->text()[0] == 'q') { | ||||
StartShutdown(); | m_node.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); | ||||
Show All 14 Lines | |||||
static void ShowProgress(SplashScreen *splash, const std::string &title, | static void ShowProgress(SplashScreen *splash, const std::string &title, | ||||
int nProgress, bool resume_possible) { | int nProgress, bool resume_possible) { | ||||
InitMessage(splash, title + std::string("\n") + | InitMessage(splash, title + std::string("\n") + | ||||
(resume_possible | (resume_possible | ||||
? _("(press q to shutdown and continue later)") | ? _("(press q to shutdown and continue later)") | ||||
: _("press q to shutdown")) + | : _("press q to shutdown")) + | ||||
strprintf("\n%d", nProgress) + "%"); | strprintf("\n%d", nProgress) + "%"); | ||||
} | } | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
void SplashScreen::ConnectWallet(CWallet *wallet) { | void SplashScreen::ConnectWallet(std::unique_ptr<interfaces::Wallet> wallet) { | ||||
wallet->ShowProgress.connect( | m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress( | ||||
boost::bind(ShowProgress, this, _1, _2, false)); | boost::bind(ShowProgress, this, _1, _2, false))); | ||||
connectedWallets.push_back(wallet); | m_connected_wallets.emplace_back(std::move(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)); | m_handler_init_message = | ||||
uiInterface.ShowProgress.connect( | m_node.handleInitMessage(boost::bind(InitMessage, this, _1)); | ||||
boost::bind(ShowProgress, this, _1, _2, _3)); | m_handler_show_progress = | ||||
m_node.handleShowProgress(boost::bind(ShowProgress, this, _1, _2, _3)); | |||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
uiInterface.LoadWallet.connect( | m_handler_load_wallet = m_node.handleLoadWallet( | ||||
boost::bind(&SplashScreen::ConnectWallet, this, _1)); | [this](std::unique_ptr<interfaces::Wallet> wallet) { | ||||
ConnectWallet(std::move(wallet)); | |||||
}); | |||||
#endif | #endif | ||||
} | } | ||||
void SplashScreen::unsubscribeFromCoreSignals() { | void SplashScreen::unsubscribeFromCoreSignals() { | ||||
// Disconnect signals from client | // Disconnect signals from client | ||||
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1)); | m_handler_init_message->disconnect(); | ||||
uiInterface.ShowProgress.disconnect( | m_handler_show_progress->disconnect(); | ||||
boost::bind(ShowProgress, this, _1, _2, _3)); | for (auto &handler : m_connected_wallet_handlers) { | ||||
#ifdef ENABLE_WALLET | handler->disconnect(); | ||||
for (CWallet *const &pwallet : connectedWallets) { | |||||
pwallet->ShowProgress.disconnect( | |||||
boost::bind(ShowProgress, this, _1, _2, false)); | |||||
} | } | ||||
#endif | m_connected_wallet_handlers.clear(); | ||||
m_connected_wallets.clear(); | |||||
} | } | ||||
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; | ||||
curColor = color; | curColor = color; | ||||
update(); | update(); | ||||
} | } | ||||
void SplashScreen::paintEvent(QPaintEvent *event) { | void SplashScreen::paintEvent(QPaintEvent *event) { | ||||
QPainter painter(this); | QPainter painter(this); | ||||
painter.drawPixmap(0, 0, pixmap); | painter.drawPixmap(0, 0, pixmap); | ||||
QRect r = rect().adjusted(5, 5, -5, -5); | QRect r = rect().adjusted(5, 5, -5, -5); | ||||
painter.setPen(curColor); | painter.setPen(curColor); | ||||
painter.drawText(r, curAlignment, curMessage); | painter.drawText(r, curAlignment, curMessage); | ||||
} | } | ||||
void SplashScreen::closeEvent(QCloseEvent *event) { | void SplashScreen::closeEvent(QCloseEvent *event) { | ||||
// allows an "emergency" shutdown during startup | // allows an "emergency" shutdown during startup | ||||
StartShutdown(); | m_node.startShutdown(); | ||||
event->ignore(); | event->ignore(); | ||||
} | } |