Bitcoin Core  0.19.99
P2P Digital Currency
noui.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <ui_interface.h>
9 #include <util/system.h>
10 
11 #include <string>
12 
13 #include <boost/signals2/connection.hpp>
14 #include <boost/signals2/signal.hpp>
15 
17 boost::signals2::connection noui_ThreadSafeMessageBoxConn;
18 boost::signals2::connection noui_ThreadSafeQuestionConn;
19 boost::signals2::connection noui_InitMessageConn;
20 
21 bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style)
22 {
23  bool fSecure = style & CClientUIInterface::SECURE;
24  style &= ~CClientUIInterface::SECURE;
25  bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
26  style &= ~CClientUIInterface::MSG_NOPREFIX;
27 
28  std::string strCaption;
29  if (prefix) {
30  switch (style) {
32  strCaption = "Error: ";
33  break;
35  strCaption = "Warning: ";
36  break;
38  strCaption = "Information: ";
39  break;
40  default:
41  strCaption = caption + ": "; // Use supplied caption (can be empty)
42  }
43  }
44 
45  if (!fSecure) {
46  LogPrintf("%s%s\n", strCaption, message);
47  }
48  tfm::format(std::cerr, "%s%s\n", strCaption, message);
49  return false;
50 }
51 
52 bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
53 {
54  return noui_ThreadSafeMessageBox(message, caption, style);
55 }
56 
57 void noui_InitMessage(const std::string& message)
58 {
59  LogPrintf("init message: %s\n", message);
60 }
61 
63 {
66  noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
67 }
68 
69 bool noui_ThreadSafeMessageBoxRedirect(const std::string& message, const std::string& caption, unsigned int style)
70 {
71  LogPrintf("%s: %s\n", caption, message);
72  return false;
73 }
74 
75 bool noui_ThreadSafeQuestionRedirect(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
76 {
77  LogPrintf("%s: %s\n", caption, message);
78  return false;
79 }
80 
81 void noui_InitMessageRedirect(const std::string& message)
82 {
83  LogPrintf("init message: %s\n", message);
84 }
85 
87 {
88  noui_ThreadSafeMessageBoxConn.disconnect();
89  noui_ThreadSafeQuestionConn.disconnect();
90  noui_InitMessageConn.disconnect();
94 }
95 
97 {
98  noui_ThreadSafeMessageBoxConn.disconnect();
99  noui_ThreadSafeQuestionConn.disconnect();
100  noui_InitMessageConn.disconnect();
101  noui_connect();
102 }
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition: noui.cpp:96
bool noui_ThreadSafeQuestion(const std::string &, const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints questions.
Definition: noui.cpp:52
boost::signals2::connection noui_ThreadSafeQuestionConn
Definition: noui.cpp:18
Do not print contents of message to debug log.
Definition: ui_interface.h:71
const char * prefix
Definition: rest.cpp:650
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:163
bool noui_ThreadSafeQuestionRedirect(const std::string &, const std::string &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:75
void noui_connect()
Connect all bitcoind signal handlers.
Definition: noui.cpp:62
boost::signals2::connection noui_InitMessageConn
Definition: noui.cpp:19
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:57
Signals for UI communication.
Definition: ui_interface.h:29
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:1062
void noui_InitMessageRedirect(const std::string &message)
Definition: noui.cpp:81
bool noui_ThreadSafeMessageBoxRedirect(const std::string &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:69
Do not prepend error/warning prefix.
Definition: ui_interface.h:68
bool noui_ThreadSafeMessageBox(const std::string &message, const std::string &caption, unsigned int style)
Non-GUI handler, which logs and prints messages.
Definition: noui.cpp:21
CClientUIInterface uiInterface
boost::signals2::connection noui_ThreadSafeMessageBoxConn
Store connections so we can disconnect them when suppressing output.
Definition: noui.cpp:17
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogPrintf.
Definition: noui.cpp:86
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:74