Bitcoin Core  27.99.0
P2P Digital Currency
interface_ui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022 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/string.h>
8 #include <util/translation.h>
9 
10 #include <boost/signals2/optional_last_value.hpp>
11 #include <boost/signals2/signal.hpp>
12 
14 
15 struct UISignals {
16  boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value<bool>> ThreadSafeMessageBox;
17  boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value<bool>> ThreadSafeQuestion;
18  boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
19  boost::signals2::signal<CClientUIInterface::InitWalletSig> InitWallet;
20  boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
21  boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
22  boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
23  boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
24  boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
25  boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
26  boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
27 };
29 
30 #define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
31  boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
32  { \
33  return g_ui_signals.signal_name.connect(fn); \
34  }
35 
37 ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
40 ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
41 ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged);
42 ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
44 ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
46 ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
47 
48 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);}
49 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);}
50 void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
51 void CClientUIInterface::InitWallet() { return g_ui_signals.InitWallet(); }
52 void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
53 void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
54 void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
55 void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
56 void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
57 void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
58 void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
59 
60 bool InitError(const bilingual_str& str)
61 {
62  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
63  return false;
64 }
65 
66 bool InitError(const bilingual_str& str, const std::vector<std::string>& details)
67 {
68  // For now just flatten the list of error details into a string to pass to
69  // the base InitError overload. In the future, if more init code provides
70  // error details, the details could be passed separately from the main
71  // message for rich display in the GUI. But currently the only init
72  // functions which provide error details are ones that run during early init
73  // before the GUI uiInterface is registered, so there's no point passing
74  // main messages and details separately to uiInterface yet.
75  return InitError(details.empty() ? str : strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)));
76 }
77 
78 void InitWarning(const bilingual_str& str)
79 {
80  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
81 }
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:141
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)
std::string MakeUnorderedList(const std::vector< std::string > &items)
Create an unordered multi-line list of items.
Definition: string.h:90
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
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1162
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:48
static bool NotifyHeaderTip(ChainstateManager &chainman) LOCKS_EXCLUDED(cs_main)
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:80