Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
noui.cpp
Go to the documentation of this file.
1
// Copyright (c) 2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
18
boost::signals2::connection
noui_ThreadSafeMessageBoxConn
;
19
boost::signals2::connection
noui_ThreadSafeQuestionConn
;
20
boost::signals2::connection
noui_InitMessageConn
;
21
22
bool
noui_ThreadSafeMessageBox
(
const
bilingual_str
& message,
unsigned
int
style)
23
{
24
bool
fSecure = style &
CClientUIInterface::SECURE
;
25
style &=
~CClientUIInterface
::SECURE;
26
27
std::string strCaption;
28
switch
(style) {
29
case
CClientUIInterface::MSG_ERROR
:
30
strCaption =
"Error: "
;
31
if
(!fSecure)
LogError
(
"%s\n"
, message.
original
);
32
break
;
33
case
CClientUIInterface::MSG_WARNING
:
34
strCaption =
"Warning: "
;
35
if
(!fSecure)
LogWarning
(
"%s\n"
, message.
original
);
36
break
;
37
case
CClientUIInterface::MSG_INFORMATION
:
38
strCaption =
"Information: "
;
39
if
(!fSecure)
LogInfo
(
"%s\n"
, message.
original
);
40
break
;
41
default
:
42
if
(!fSecure)
LogInfo
(
"%s%s\n"
, strCaption, message.
original
);
43
}
44
45
tfm::format
(std::cerr,
"%s%s\n"
, strCaption, message.
original
);
46
return
false
;
47
}
48
49
bool
noui_ThreadSafeQuestion
(
const
bilingual_str
&
/* ignored interactive message */
,
const
std::string& message,
unsigned
int
style)
50
{
51
return
noui_ThreadSafeMessageBox
(
Untranslated
(message), style);
52
}
53
54
void
noui_InitMessage
(
const
std::string& message)
55
{
56
LogInfo
(
"init message: %s"
, message);
57
}
58
59
void
noui_connect
()
60
{
61
noui_ThreadSafeMessageBoxConn
=
uiInterface
.ThreadSafeMessageBox_connect(
noui_ThreadSafeMessageBox
);
62
noui_ThreadSafeQuestionConn
=
uiInterface
.ThreadSafeQuestion_connect(
noui_ThreadSafeQuestion
);
63
noui_InitMessageConn
=
uiInterface
.InitMessage_connect(
noui_InitMessage
);
64
}
65
66
bool
noui_ThreadSafeMessageBoxRedirect
(
const
bilingual_str
& message,
unsigned
int
style)
67
{
68
LogInfo
(
"%s"
, message.
original
);
69
return
false
;
70
}
71
72
bool
noui_ThreadSafeQuestionRedirect
(
const
bilingual_str
&
/* ignored interactive message */
,
const
std::string& message,
unsigned
int
style)
73
{
74
LogInfo
(
"%s"
, message);
75
return
false
;
76
}
77
78
void
noui_InitMessageRedirect
(
const
std::string& message)
79
{
80
LogInfo
(
"init message: %s"
, message);
81
}
82
83
void
noui_test_redirect
()
84
{
85
noui_ThreadSafeMessageBoxConn
.disconnect();
86
noui_ThreadSafeQuestionConn
.disconnect();
87
noui_InitMessageConn
.disconnect();
88
noui_ThreadSafeMessageBoxConn
=
uiInterface
.ThreadSafeMessageBox_connect(
noui_ThreadSafeMessageBoxRedirect
);
89
noui_ThreadSafeQuestionConn
=
uiInterface
.ThreadSafeQuestion_connect(
noui_ThreadSafeQuestionRedirect
);
90
noui_InitMessageConn
=
uiInterface
.InitMessage_connect(
noui_InitMessageRedirect
);
91
}
92
93
void
noui_reconnect
()
94
{
95
noui_ThreadSafeMessageBoxConn
.disconnect();
96
noui_ThreadSafeQuestionConn
.disconnect();
97
noui_InitMessageConn
.disconnect();
98
noui_connect
();
99
}
CClientUIInterface
Signals for UI communication.
Definition
interface_ui.h:26
CClientUIInterface::MSG_ERROR
@ MSG_ERROR
Definition
interface_ui.h:68
CClientUIInterface::MSG_WARNING
@ MSG_WARNING
Definition
interface_ui.h:67
CClientUIInterface::MSG_INFORMATION
@ MSG_INFORMATION
Predefined combinations for certain default usage cases.
Definition
interface_ui.h:66
CClientUIInterface::SECURE
@ SECURE
Do not print contents of message to debug log.
Definition
interface_ui.h:63
uiInterface
CClientUIInterface uiInterface
Definition
interface_ui.cpp:15
interface_ui.h
LogWarning
#define LogWarning(...)
Definition
log.h:96
LogInfo
#define LogInfo(...)
Definition
log.h:95
LogError
#define LogError(...)
Definition
log.h:97
logging.h
tinyformat::format
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:1079
noui_ThreadSafeQuestion
bool noui_ThreadSafeQuestion(const bilingual_str &, const std::string &message, unsigned int style)
Non-GUI handler, which logs and prints questions.
Definition
noui.cpp:49
noui_ThreadSafeMessageBoxRedirect
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str &message, unsigned int style)
Definition
noui.cpp:66
noui_InitMessageRedirect
void noui_InitMessageRedirect(const std::string &message)
Definition
noui.cpp:78
noui_ThreadSafeQuestionRedirect
bool noui_ThreadSafeQuestionRedirect(const bilingual_str &, const std::string &message, unsigned int style)
Definition
noui.cpp:72
noui_test_redirect
void noui_test_redirect()
Redirect all bitcoind signal handlers to LogInfo.
Definition
noui.cpp:83
noui_InitMessage
void noui_InitMessage(const std::string &message)
Non-GUI handler, which only logs a message.
Definition
noui.cpp:54
noui_reconnect
void noui_reconnect()
Reconnects the regular Non-GUI handlers after having used noui_test_redirect.
Definition
noui.cpp:93
noui_ThreadSafeMessageBoxConn
boost::signals2::connection noui_ThreadSafeMessageBoxConn
Store connections so we can disconnect them when suppressing output.
Definition
noui.cpp:18
noui_InitMessageConn
boost::signals2::connection noui_InitMessageConn
Definition
noui.cpp:20
noui_ThreadSafeQuestionConn
boost::signals2::connection noui_ThreadSafeQuestionConn
Definition
noui.cpp:19
noui_connect
void noui_connect()
Definition
noui.cpp:59
noui_ThreadSafeMessageBox
bool noui_ThreadSafeMessageBox(const bilingual_str &message, unsigned int style)
Non-GUI handler, which logs and prints messages.
Definition
noui.cpp:22
noui.h
bilingual_str
Bilingual messages:
Definition
translation.h:24
bilingual_str::original
std::string original
Definition
translation.h:25
translation.h
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition
translation.h:82
Generated on
for Bitcoin Core by
1.17.0