Bitcoin Core 28.99.0
P2P Digital Currency
noui.cpp
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-2022 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/interface_ui.h>
10#include <util/translation.h>
11
12#include <string>
13
14#include <boost/signals2/connection.hpp>
15#include <boost/signals2/signal.hpp>
16
18boost::signals2::connection noui_ThreadSafeMessageBoxConn;
19boost::signals2::connection noui_ThreadSafeQuestionConn;
20boost::signals2::connection noui_InitMessageConn;
21
22bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style)
23{
24 bool fSecure = style & CClientUIInterface::SECURE;
25 style &= ~CClientUIInterface::SECURE;
26
27 std::string strCaption;
28 switch (style) {
30 strCaption = "Error: ";
31 if (!fSecure) LogError("%s\n", message.original);
32 break;
34 strCaption = "Warning: ";
35 if (!fSecure) LogWarning("%s\n", message.original);
36 break;
38 strCaption = "Information: ";
39 if (!fSecure) LogInfo("%s\n", message.original);
40 break;
41 default:
42 strCaption = caption + ": "; // Use supplied caption (can be empty)
43 if (!fSecure) LogInfo("%s%s\n", strCaption, message.original);
44 }
45
46 tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
47 return false;
48}
49
50bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
51{
52 return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
53}
54
55void noui_InitMessage(const std::string& message)
56{
57 LogPrintf("init message: %s\n", message);
58}
59
61{
65}
66
67bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
68{
69 LogPrintf("%s: %s\n", caption, message.original);
70 return false;
71}
72
73bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
74{
75 LogPrintf("%s: %s\n", caption, message);
76 return false;
77}
78
79void noui_InitMessageRedirect(const std::string& message)
80{
81 LogPrintf("init message: %s\n", message);
82}
83
85{
87 noui_ThreadSafeQuestionConn.disconnect();
88 noui_InitMessageConn.disconnect();
92}
93
95{
97 noui_ThreadSafeQuestionConn.disconnect();
98 noui_InitMessageConn.disconnect();
100}
Signals for UI communication.
Definition: interface_ui.h:26
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: interface_ui.h:66
@ SECURE
Do not print contents of message to debug log.
Definition: interface_ui.h:63
CClientUIInterface uiInterface
#define LogWarning(...)
Definition: logging.h:262
#define LogInfo(...)
Definition: logging.h:261
#define LogError(...)
Definition: logging.h:263
#define LogPrintf(...)
Definition: logging.h:266
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1072
bool noui_ThreadSafeQuestionRedirect(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:73
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:50
void noui_InitMessageRedirect(const std::string &message)
Definition: noui.cpp:79
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:67
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogPrintf.
Definition: noui.cpp:84
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:55
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition: noui.cpp:94
boost::signals2::connection noui_ThreadSafeMessageBoxConn
Store connections so we can disconnect them when suppressing output.
Definition: noui.cpp:18
boost::signals2::connection noui_InitMessageConn
Definition: noui.cpp:20
boost::signals2::connection noui_ThreadSafeQuestionConn
Definition: noui.cpp:19
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:22
void noui_connect()
Connect all bitcoind signal handlers.
Definition: noui.cpp:60
Bilingual messages:
Definition: translation.h:21
std::string original
Definition: translation.h:22
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:51