Skip to content

Commit

Permalink
refactor: Remove SplashScreen::setNode method
Browse files Browse the repository at this point in the history
Make m_node a reference instead of pointer, now that it can no longer be null,
as suggested
bitcoin/bitcoin#15936 (comment)
  • Loading branch information
vasild committed May 19, 2022
1 parent aa2817b commit 945e467
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ void BitcoinApplication::createWindow(const NetworkStyle *networkStyle)
void BitcoinApplication::createSplashScreen(const NetworkStyle *networkStyle)
{
assert(!m_splash);
m_splash = new SplashScreen(networkStyle);
m_splash->setNode(node());
m_splash = new SplashScreen(node(), networkStyle);
// We don't hold a direct pointer to the splash screen after creation, but the splash
// screen will take care of deleting itself when finish() happens.
m_splash->show();
Expand Down
26 changes: 10 additions & 16 deletions src/qt/splashscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <QScreen>


SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
: QWidget(), curAlignment(0)
SplashScreen::SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle)
: QWidget(), curAlignment(0), m_node{node}
{
// set reference point, paddings
int paddingRight = 50;
Expand Down Expand Up @@ -130,25 +130,19 @@ SplashScreen::SplashScreen(const NetworkStyle* networkStyle)
installEventFilter(this);

GUIUtil::handleCloseWindowShortcut(this);
}

SplashScreen::~SplashScreen()
{
if (m_node) unsubscribeFromCoreSignals();
subscribeToCoreSignals();
}

void SplashScreen::setNode(interfaces::Node& node)
SplashScreen::~SplashScreen()
{
assert(!m_node);
m_node = &node;
subscribeToCoreSignals();
if (m_shutdown) m_node->startShutdown();
unsubscribeFromCoreSignals();
}

void SplashScreen::shutdown()
{
m_shutdown = true;
if (m_node) m_node->startShutdown();
m_node.startShutdown();
}

bool SplashScreen::eventFilter(QObject * obj, QEvent * ev) {
Expand Down Expand Up @@ -192,16 +186,16 @@ static void ShowProgress(SplashScreen *splash, const std::string &title, int nPr
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
m_handler_init_message = m_node->handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
m_handler_show_progress = m_node->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_handler_init_wallet = m_node->handleInitWallet([this]() { handleLoadWallet(); });
m_handler_init_message = m_node.handleInitMessage(std::bind(InitMessage, this, std::placeholders::_1));
m_handler_show_progress = m_node.handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_handler_init_wallet = m_node.handleInitWallet([this]() { handleLoadWallet(); });
}

void SplashScreen::handleLoadWallet()
{
#ifdef ENABLE_WALLET
if (!WalletModel::isWalletEnabled()) return;
m_handler_load_wallet = m_node->walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
m_handler_load_wallet = m_node.walletLoader().handleLoadWallet([this](std::unique_ptr<interfaces::Wallet> wallet) {
m_connected_wallet_handlers.emplace_back(wallet->handleShowProgress(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2, false)));
m_connected_wallets.emplace_back(std::move(wallet));
});
Expand Down
5 changes: 2 additions & 3 deletions src/qt/splashscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class SplashScreen : public QWidget
Q_OBJECT

public:
explicit SplashScreen(const NetworkStyle *networkStyle);
explicit SplashScreen(interfaces::Node& node, const NetworkStyle* networkStyle);
~SplashScreen();
void setNode(interfaces::Node& node);

protected:
void paintEvent(QPaintEvent *event) override;
Expand Down Expand Up @@ -62,7 +61,7 @@ public Q_SLOTS:
QColor curColor;
int curAlignment;

interfaces::Node* m_node = nullptr;
interfaces::Node& m_node;
bool m_shutdown = false;
std::unique_ptr<interfaces::Handler> m_handler_init_message;
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
Expand Down

0 comments on commit 945e467

Please sign in to comment.