PIVX Core  5.6.99
P2P Digital Currency
splash.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2021 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #if defined(HAVE_CONFIG_H)
6 #include "config/pivx-config.h"
7 #endif
8 
9 #include "splash.h"
10 #include "ui_splash.h"
11 
12 #include "interfaces/handler.h"
13 #include "guiinterface.h"
14 #include "networkstyle.h"
15 #include "shutdown.h"
16 #include "util/system.h"
17 #include "version.h"
18 #include "guiutil.h"
19 
20 #ifdef ENABLE_WALLET
21 #include "wallet/wallet.h"
22 #endif
23 
24 #include <QCloseEvent>
25 #include <QDesktopWidget>
26 #include <QFile>
27 #include <QScreen>
28 
29 #include <iostream>
30 
31 Splash::Splash(const NetworkStyle* networkStyle) :
32  QWidget(nullptr), ui(new Ui::Splash)
33 {
34  ui->setupUi(this);
35  QString titleText = PACKAGE_NAME;
36  QString titleAddText = networkStyle->getTitleAddText();
37  setWindowTitle(titleText + " " + titleAddText);
38 
39  this->setStyleSheet(GUIUtil::loadStyleSheet());
40  this->setAttribute( Qt::WA_TranslucentBackground, true );
41  ui->progressBar->setAttribute( Qt::WA_TranslucentBackground, true );
42 
43  ui->progressBar->setTextVisible(false);
44  ui->progressBar->setMaximum(0);
45  ui->progressBar->setMinimum(0);
46  ui->progressBar->setProperty("cssClass", "progress-splash");
47  ui->frame->setProperty("cssClass", "container-splash");
48  ui->layoutProgress->setProperty("cssClass", "bg-progress");
49  ui->imgLogo->setProperty("cssClass", "img-splash-logo");
50  ui->lblVersion->setText(QString("v") + QString::fromStdString(FormatVersionFriendly()));
51 
52  // Resize window and move to center of desktop, disallow resizing
53  QRect r(QPoint(), size());
54  resize(r.size());
55  setFixedSize(r.size());
56  move(QGuiApplication::primaryScreen()->geometry().center() - r.center());
57 
59 }
60 
63  delete ui;
64 }
65 
66 void Splash::slotFinish(QWidget* mainWin){
67  Q_UNUSED(mainWin);
68  hide();
69 }
70 
71 static void InitMessage(Splash* splash, const std::string& message){
72  QMetaObject::invokeMethod(splash, "showMessage",
73  Qt::QueuedConnection,
74  Q_ARG(QString, QString::fromStdString(message)),
75  Q_ARG(int, Qt::AlignBottom | Qt::AlignHCenter),
76  Q_ARG(QColor, QColor(100, 100, 100)));
77 }
78 
79 static void ShowProgress(Splash* splash, const std::string& title, int nProgress){
80  InitMessage(splash, title + strprintf("%d", nProgress) + "%");
81 }
82 
83 #ifdef ENABLE_WALLET
84 std::unique_ptr<interfaces::Handler> m_handler_show_progress_wallet;
85 static void ConnectWallet(Splash* splash, CWallet* wallet){
86  m_handler_show_progress_wallet = interfaces::MakeHandler(wallet->ShowProgress.connect(std::bind(ShowProgress, splash, std::placeholders::_1, std::placeholders::_2)));
87 }
88 #endif
89 
91  // Connect signals to client
92  m_handler_init_message = interfaces::MakeHandler(uiInterface.InitMessage.connect(std::bind(InitMessage, this, std::placeholders::_1)));
93  m_handler_show_progress = interfaces::MakeHandler(uiInterface.ShowProgress.connect(std::bind(ShowProgress, this, std::placeholders::_1, std::placeholders::_2)));
94 #ifdef ENABLE_WALLET
95  m_handler_load_wallet = interfaces::MakeHandler(uiInterface.LoadWallet.connect(std::bind(ConnectWallet, this, std::placeholders::_1)));
96 #endif
97 }
98 
100  // Disconnect signals from client
101  m_handler_init_message->disconnect();
102  m_handler_show_progress->disconnect();
103 #ifdef ENABLE_WALLET
104  m_handler_load_wallet->disconnect();
105  if (m_handler_show_progress_wallet) m_handler_show_progress_wallet->disconnect();
106 #endif
107 }
108 
109 void Splash::showMessage(const QString& message, int alignment, const QColor& color){
110  ui->lblMessage->setText(message);
111 }
112 
113 void Splash::closeEvent(QCloseEvent* event){
114  StartShutdown(); // allows an "emergency" shutdown during startup
115  event->ignore();
116 }
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: guiinterface.h:102
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
Definition: guiinterface.h:87
boost::signals2::signal< void(CWallet *wallet)> LoadWallet
A wallet has been loaded.
Definition: guiinterface.h:99
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
Definition: wallet.h:577
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: wallet.h:1242
const QString & getTitleAddText() const
Definition: networkstyle.h:21
Definition: splash.h:23
void showMessage(const QString &message, int alignment, const QColor &color)
Show message and progress.
Definition: splash.cpp:109
void slotFinish(QWidget *mainWin)
Slot to call finish() method as it's not defined as slot.
Definition: splash.cpp:66
void closeEvent(QCloseEvent *event)
Definition: splash.cpp:113
std::unique_ptr< interfaces::Handler > m_handler_show_progress
Definition: splash.h:45
void subscribeToCoreSignals()
Connect core signals to splash screen.
Definition: splash.cpp:90
void unsubscribeFromCoreSignals()
Disconnect core signals to splash screen.
Definition: splash.cpp:99
~Splash()
Definition: splash.cpp:61
Ui::Splash * ui
Definition: splash.h:41
std::unique_ptr< interfaces::Handler > m_handler_init_message
Definition: splash.h:44
Splash(const NetworkStyle *networkStyle)
Definition: splash.cpp:31
std::unique_ptr< interfaces::Handler > m_handler_load_wallet
Definition: splash.h:46
std::string FormatVersionFriendly()
CClientUIInterface uiInterface
Definition: init.cpp:109
QString loadStyleSheet()
Load global CSS theme.
Definition: guiutil.cpp:639
std::unique_ptr< Handler > MakeHandler(boost::signals2::connection connection)
Return handler wrapping a boost signal connection.
Definition: handler.cpp:26
const char * titleAddText
#define PACKAGE_NAME
Definition: pivx-config.h:366
void StartShutdown()
Definition: shutdown.cpp:14
#define strprintf
Definition: tinyformat.h:1056