Bitcoin ABC  0.24.7
P2P Digital Currency
noui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <noui.h>
7 
8 #include <logging.h>
9 #include <node/ui_interface.h>
10 #include <util/translation.h>
11 
12 #include <boost/signals2/connection.hpp>
13 #include <boost/signals2/signal.hpp>
14 
16 boost::signals2::connection noui_ThreadSafeMessageBoxConn;
17 boost::signals2::connection noui_ThreadSafeQuestionConn;
18 boost::signals2::connection noui_InitMessageConn;
19 
21  const std::string &caption, unsigned int style) {
22  bool fSecure = style & CClientUIInterface::SECURE;
23  style &= ~CClientUIInterface::SECURE;
24 
25  std::string strCaption;
26  switch (style) {
28  strCaption = "Error: ";
29  break;
31  strCaption = "Warning: ";
32  break;
34  strCaption = "Information: ";
35  break;
36  default:
37  // Use supplied caption (can be empty)
38  strCaption = caption + ": ";
39  }
40 
41  if (!fSecure) {
42  LogPrintf("%s%s\n", strCaption, message.original);
43  }
44  tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
45  return false;
46 }
47 
49  const bilingual_str & /* ignored interactive message */,
50  const std::string &message, const std::string &caption,
51  unsigned int style) {
52  return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
53 }
54 
55 void noui_InitMessage(const std::string &message) {
56  LogPrintf("init message: %s\n", message);
57 }
58 
59 void noui_connect() {
61  uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
63  uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
64  noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
65 }
66 
68  const std::string &caption,
69  unsigned int style) {
70  LogPrintf("%s: %s\n", caption, message.original);
71  return false;
72 }
73 
75  const bilingual_str & /* ignored interactive message */,
76  const std::string &message, const std::string &caption,
77  unsigned int style) {
78  LogPrintf("%s: %s\n", caption, message);
79  return false;
80 }
81 
82 void noui_InitMessageRedirect(const std::string &message) {
83  LogPrintf("init message: %s\n", message);
84 }
85 
87  noui_ThreadSafeMessageBoxConn.disconnect();
88  noui_ThreadSafeQuestionConn.disconnect();
89  noui_InitMessageConn.disconnect();
90  noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(
93  uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
95  uiInterface.InitMessage_connect(noui_InitMessageRedirect);
96 }
97 
99  noui_ThreadSafeMessageBoxConn.disconnect();
100  noui_ThreadSafeQuestionConn.disconnect();
101  noui_InitMessageConn.disconnect();
102  noui_connect();
103 }
CClientUIInterface::MSG_INFORMATION
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:71
noui_ThreadSafeQuestionConn
boost::signals2::connection noui_ThreadSafeQuestionConn
Definition: noui.cpp:17
tinyformat::format
void format(std::ostream &out, const char *fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1111
CClientUIInterface
Signals for UI communication.
Definition: ui_interface.h:24
uiInterface
CClientUIInterface uiInterface
Definition: ui_interface.cpp:12
bilingual_str
Bilingual messages:
Definition: translation.h:17
noui_connect
void noui_connect()
Connect all bitcoind signal handlers.
Definition: noui.cpp:59
noui_ThreadSafeMessageBoxRedirect
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:67
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
CClientUIInterface::SECURE
@ SECURE
Do not print contents of message to debug log.
Definition: ui_interface.h:68
noui_InitMessageConn
boost::signals2::connection noui_InitMessageConn
Definition: noui.cpp:18
noui_InitMessage
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:55
CClientUIInterface::MSG_WARNING
@ MSG_WARNING
Definition: ui_interface.h:72
bilingual_str::original
std::string original
Definition: translation.h:18
ui_interface.h
CClientUIInterface::MSG_ERROR
@ MSG_ERROR
Definition: ui_interface.h:73
translation.h
noui_InitMessageRedirect
void noui_InitMessageRedirect(const std::string &message)
Definition: noui.cpp:82
logging.h
noui.h
noui_ThreadSafeQuestionRedirect
bool noui_ThreadSafeQuestionRedirect(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:74
noui_test_redirect
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogPrintf.
Definition: noui.cpp:86
noui_reconnect
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition: noui.cpp:98
LogPrintf
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:175
noui_ThreadSafeMessageBoxConn
boost::signals2::connection noui_ThreadSafeMessageBoxConn
Store connections so we can disconnect them when suppressing output.
Definition: noui.cpp:16
noui_ThreadSafeQuestion
bool noui_ThreadSafeQuestion(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints questions.
Definition: noui.cpp:48
noui_ThreadSafeMessageBox
bool noui_ThreadSafeMessageBox(const bilingual_str &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
Definition: noui.cpp:20