Bitcoin ABC  0.24.7
P2P Digital Currency
ui_interface.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2016 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,
16  boost::signals2::optional_last_value<bool>>
18  boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig,
19  boost::signals2::optional_last_value<bool>>
21  boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
22  boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig>
24  boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig>
26  boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig>
28  boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
29  boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig>
31  boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig>
33  boost::signals2::signal<CClientUIInterface::BannedListChangedSig>
35 };
37 
38 #define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
39  boost::signals2::connection CClientUIInterface::signal_name##_connect( \
40  std::function<signal_name##Sig> fn) { \
41  return g_ui_signals.signal_name.connect(fn); \
42  }
43 
45 ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
51 ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
54 
56  const std::string &caption,
57  unsigned int style) {
58  return g_ui_signals.ThreadSafeMessageBox(message, caption, style)
59  .value_or(false);
60 }
61 bool CClientUIInterface::ThreadSafeQuestion(
62  const bilingual_str &message, const std::string &non_interactive_message,
63  const std::string &caption, unsigned int style) {
64  return g_ui_signals
65  .ThreadSafeQuestion(message, non_interactive_message, caption, style)
66  .value_or(false);
67 }
68 void CClientUIInterface::InitMessage(const std::string &message) {
69  return g_ui_signals.InitMessage(message);
70 }
71 void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) {
72  return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections);
73 }
74 void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) {
75  return g_ui_signals.NotifyNetworkActiveChanged(networkActive);
76 }
79 }
80 void CClientUIInterface::ShowProgress(const std::string &title, int nProgress,
81  bool resume_possible) {
82  return g_ui_signals.ShowProgress(title, nProgress, resume_possible);
83 }
84 void CClientUIInterface::NotifyBlockTip(SynchronizationState s,
85  const CBlockIndex *i) {
86  return g_ui_signals.NotifyBlockTip(s, i);
87 }
89  const CBlockIndex *i) {
90  return g_ui_signals.NotifyHeaderTip(s, i);
91 }
94 }
95 
96 bool InitError(const bilingual_str &str) {
97  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
98  return false;
99 }
100 
101 void InitWarning(const bilingual_str &str) {
102  uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
103 }
UISignals::NotifyHeaderTip
boost::signals2::signal< CClientUIInterface::NotifyHeaderTipSig > NotifyHeaderTip
Definition: ui_interface.cpp:32
CClientUIInterface
Signals for UI communication.
Definition: ui_interface.h:24
NotifyAlertChanged
static void NotifyAlertChanged(ClientModel *clientmodel)
Definition: clientmodel.cpp:233
InitMessage
static void InitMessage(SplashScreen *splash, const std::string &message)
Definition: splashscreen.cpp:191
uiInterface
CClientUIInterface uiInterface
Definition: ui_interface.cpp:12
ShowProgress
static void ShowProgress(ClientModel *clientmodel, const std::string &title, int nProgress)
Definition: clientmodel.cpp:206
bilingual_str
Bilingual messages:
Definition: translation.h:17
UISignals::BannedListChanged
boost::signals2::signal< CClientUIInterface::BannedListChangedSig > BannedListChanged
Definition: ui_interface.cpp:34
UISignals::ShowProgress
boost::signals2::signal< CClientUIInterface::ShowProgressSig > ShowProgress
Definition: ui_interface.cpp:28
UISignals::ThreadSafeMessageBox
boost::signals2::signal< CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value< bool > > ThreadSafeMessageBox
Definition: ui_interface.cpp:17
UISignals::NotifyNetworkActiveChanged
boost::signals2::signal< CClientUIInterface::NotifyNetworkActiveChangedSig > NotifyNetworkActiveChanged
Definition: ui_interface.cpp:25
InitError
bool InitError(const bilingual_str &str)
Show error message.
Definition: ui_interface.cpp:96
CClientUIInterface::MSG_WARNING
@ MSG_WARNING
Definition: ui_interface.h:72
BannedListChanged
static void BannedListChanged(ClientModel *clientmodel)
Definition: clientmodel.cpp:240
NotifyHeaderTip
static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:2955
UISignals::NotifyNumConnectionsChanged
boost::signals2::signal< CClientUIInterface::NotifyNumConnectionsChangedSig > NotifyNumConnectionsChanged
Definition: ui_interface.cpp:23
UISignals::ThreadSafeQuestion
boost::signals2::signal< CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value< bool > > ThreadSafeQuestion
Definition: ui_interface.cpp:20
ui_interface.h
InitWarning
void InitWarning(const bilingual_str &str)
Show warning message.
Definition: ui_interface.cpp:101
CClientUIInterface::MSG_ERROR
@ MSG_ERROR
Definition: ui_interface.h:73
UISignals::NotifyAlertChanged
boost::signals2::signal< CClientUIInterface::NotifyAlertChangedSig > NotifyAlertChanged
Definition: ui_interface.cpp:27
translation.h
g_ui_signals
static UISignals g_ui_signals
Definition: ui_interface.cpp:36
UISignals::InitMessage
boost::signals2::signal< CClientUIInterface::InitMessageSig > InitMessage
Definition: ui_interface.cpp:21
ThreadSafeMessageBox
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const bilingual_str &message, const std::string &caption, unsigned int style)
Definition: bitcoingui.cpp:1539
NotifyNumConnectionsChanged
static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections)
Definition: clientmodel.cpp:215
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:130
UISignals
Definition: ui_interface.cpp:14
UISignals::NotifyBlockTip
boost::signals2::signal< CClientUIInterface::NotifyBlockTipSig > NotifyBlockTip
Definition: ui_interface.cpp:30
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
NotifyNetworkActiveChanged
static void NotifyNetworkActiveChanged(ClientModel *clientmodel, bool networkActive)
Definition: clientmodel.cpp:225
ADD_SIGNALS_IMPL_WRAPPER
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name)
Definition: ui_interface.cpp:38