Bitcoin Core  24.99.0
P2P Digital Currency
interface_ui.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/interface_ui.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);
39 ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
40 ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged);
41 ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
43 ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
45 ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
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); }
53 void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
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); }
56 void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
57 void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
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 }
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const bilingual_str &message, const std::string &caption, unsigned int style)
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:152
Signals for UI communication.
Definition: interface_ui.h:25
static UISignals g_ui_signals
CClientUIInterface uiInterface
void InitWarning(const bilingual_str &str)
Show warning message.
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name)
bool InitError(const bilingual_str &str)
Show error message.
static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress, bool resume_possible)
static void InitMessage(SplashScreen *splash, const std::string &message)
boost::signals2::signal< CClientUIInterface::BannedListChangedSig > BannedListChanged
boost::signals2::signal< CClientUIInterface::NotifyAlertChangedSig > NotifyAlertChanged
boost::signals2::signal< CClientUIInterface::NotifyHeaderTipSig > NotifyHeaderTip
boost::signals2::signal< CClientUIInterface::NotifyBlockTipSig > NotifyBlockTip
boost::signals2::signal< CClientUIInterface::InitWalletSig > InitWallet
boost::signals2::signal< CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value< bool > > ThreadSafeQuestion
boost::signals2::signal< CClientUIInterface::InitMessageSig > InitMessage
boost::signals2::signal< CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value< bool > > ThreadSafeMessageBox
boost::signals2::signal< CClientUIInterface::NotifyNumConnectionsChangedSig > NotifyNumConnectionsChanged
boost::signals2::signal< CClientUIInterface::NotifyNetworkActiveChangedSig > NotifyNetworkActiveChanged
boost::signals2::signal< CClientUIInterface::ShowProgressSig > ShowProgress
Bilingual messages:
Definition: translation.h:18
static bool NotifyHeaderTip(Chainstate &chainstate) LOCKS_EXCLUDED(cs_main)
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:85