Bitcoin Core 22.99.0
P2P Digital Currency
noui.cpp
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-2020 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 <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 break;
33 strCaption = "Warning: ";
34 break;
36 strCaption = "Information: ";
37 break;
38 default:
39 strCaption = caption + ": "; // Use supplied caption (can be empty)
40 }
41
42 if (!fSecure) {
43 LogPrintf("%s%s\n", strCaption, message.original);
44 }
45 tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
46 return false;
47}
48
49bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
50{
51 return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
52}
53
54void noui_InitMessage(const std::string& message)
55{
56 LogPrintf("init message: %s\n", message);
57}
58
60{
64}
65
66bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
67{
68 LogPrintf("%s: %s\n", caption, message.original);
69 return false;
70}
71
72bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
73{
74 LogPrintf("%s: %s\n", caption, message);
75 return false;
76}
77
78void noui_InitMessageRedirect(const std::string& message)
79{
80 LogPrintf("init message: %s\n", message);
81}
82
84{
86 noui_ThreadSafeQuestionConn.disconnect();
87 noui_InitMessageConn.disconnect();
91}
92
94{
96 noui_ThreadSafeQuestionConn.disconnect();
97 noui_InitMessageConn.disconnect();
99}
Signals for UI communication.
Definition: ui_interface.h:25
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition: ui_interface.h:66
@ SECURE
Do not print contents of message to debug log.
Definition: ui_interface.h:63
#define LogPrintf(...)
Definition: logging.h:187
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
bool noui_ThreadSafeQuestionRedirect(const bilingual_str &, const std::string &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:72
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:49
void noui_InitMessageRedirect(const std::string &message)
Definition: noui.cpp:78
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str &message, const std::string &caption, unsigned int style)
Definition: noui.cpp:66
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogPrintf.
Definition: noui.cpp:83
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition: noui.cpp:54
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition: noui.cpp:93
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:59
Bilingual messages:
Definition: translation.h:16
std::string original
Definition: translation.h:17
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:46
CClientUIInterface uiInterface