Bitcoin Core  22.99.0
P2P Digital Currency
ui_interface.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021 The Bitcoin 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 #include <node/ui_interface.h>
6 
7 #include <util/translation.h>
8 
9 #include <boost/signals2/optional_last_value.hpp>
10 #include <boost/signals2/signal.hpp>
11 
13 
14 struct UISignals {
15  boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value<bool>> ThreadSafeMessageBox;
16  boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value<bool>> ThreadSafeQuestion;
17  boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
18  boost::signals2::signal<CClientUIInterface::InitWalletSig> InitWallet;
19  boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
20  boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
21  boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
22  boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
23  boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
24  boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
25  boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
26 };
28 
29 #define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
30  boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
31  { \
32  return g_ui_signals.signal_name.connect(fn); \
33  }
34 
36 ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
38 ADD_SIGNALS_IMPL_WRAPPER(InitWallet);
43 ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
46 
47 bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style).value_or(false);}
48 bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style).value_or(false);}
49 void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
50 void CClientUIInterface::InitWallet() { return g_ui_signals.InitWallet(); }
51 void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
52 void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
54 void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
55 void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
58 
59 bool InitError(const bilingual_str& str)
60 {
61  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
62  return false;
63 }
64 
65 void InitWarning(const bilingual_str& str)
66 {
67  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
68 }
UISignals::NotifyHeaderTip
boost::signals2::signal< CClientUIInterface::NotifyHeaderTipSig > NotifyHeaderTip
Definition: ui_interface.cpp:24
CClientUIInterface
Signals for UI communication.
Definition: ui_interface.h:24
NotifyAlertChanged
static void NotifyAlertChanged(ClientModel *clientmodel)
Definition: clientmodel.cpp:263
InitMessage
static void InitMessage(SplashScreen *splash, const std::string &message)
Definition: splashscreen.cpp:174
uiInterface
CClientUIInterface uiInterface
Definition: ui_interface.cpp:12
ShowProgress
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
Definition: clientmodel.cpp:239
bilingual_str
Bilingual messages:
Definition: translation.h:16
UISignals::BannedListChanged
boost::signals2::signal< CClientUIInterface::BannedListChangedSig > BannedListChanged
Definition: ui_interface.cpp:25
UISignals::ShowProgress
boost::signals2::signal< CClientUIInterface::ShowProgressSig > ShowProgress
Definition: ui_interface.cpp:22
UISignals::ThreadSafeMessageBox
boost::signals2::signal< CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value< bool > > ThreadSafeMessageBox
Definition: ui_interface.cpp:15
UISignals::NotifyNetworkActiveChanged
boost::signals2::signal< CClientUIInterface::NotifyNetworkActiveChangedSig > NotifyNetworkActiveChanged
Definition: ui_interface.cpp:20
InitError
bool InitError(const bilingual_str &str)
Show error message.
Definition: ui_interface.cpp:59
CClientUIInterface::MSG_WARNING
@ MSG_WARNING
Definition: ui_interface.h:67
BannedListChanged
static void BannedListChanged(ClientModel *clientmodel)
Definition: clientmodel.cpp:270
NotifyHeaderTip
static bool NotifyHeaderTip(CChainState &chainstate) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:2783
UISignals::NotifyNumConnectionsChanged
boost::signals2::signal< CClientUIInterface::NotifyNumConnectionsChangedSig > NotifyNumConnectionsChanged
Definition: ui_interface.cpp:19
UISignals::ThreadSafeQuestion
boost::signals2::signal< CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value< bool > > ThreadSafeQuestion
Definition: ui_interface.cpp:16
ui_interface.h
InitWarning
void InitWarning(const bilingual_str &str)
Show warning message.
Definition: ui_interface.cpp:65
CClientUIInterface::MSG_ERROR
@ MSG_ERROR
Definition: ui_interface.h:68
UISignals::NotifyAlertChanged
boost::signals2::signal< CClientUIInterface::NotifyAlertChangedSig > NotifyAlertChanged
Definition: ui_interface.cpp:21
translation.h
UISignals::InitWallet
boost::signals2::signal< CClientUIInterface::InitWalletSig > InitWallet
Definition: ui_interface.cpp:18
g_ui_signals
static UISignals g_ui_signals
Definition: ui_interface.cpp:27
UISignals::InitMessage
boost::signals2::signal< CClientUIInterface::InitMessageSig > InitMessage
Definition: ui_interface.cpp:17
ThreadSafeMessageBox
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const bilingual_str &message, const std::string &caption, unsigned int style)
Definition: bitcoingui.cpp:1439
NotifyNumConnectionsChanged
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
Definition: clientmodel.cpp:248
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:105
UISignals
Definition: ui_interface.cpp:14
UISignals::NotifyBlockTip
boost::signals2::signal< CClientUIInterface::NotifyBlockTipSig > NotifyBlockTip
Definition: ui_interface.cpp:23
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:148
NotifyNetworkActiveChanged
static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive)
Definition: clientmodel.cpp:256
ADD_SIGNALS_IMPL_WRAPPER
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name)
Definition: ui_interface.cpp:29