Branch data Line data Source code
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 <btcsignals.h>
9 : : #include <logging.h>
10 : : #include <node/interface_ui.h>
11 : : #include <util/translation.h>
12 : :
13 : : #include <string>
14 : :
15 : : /** Store connections so we can disconnect them when suppressing output */
16 : : btcsignals::connection noui_ThreadSafeMessageBoxConn;
17 : : btcsignals::connection noui_ThreadSafeQuestionConn;
18 : : btcsignals::connection noui_InitMessageConn;
19 : :
20 : 186 : bool noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style)
21 : : {
22 : 186 : bool fSecure = style & CClientUIInterface::SECURE;
23 : 186 : style &= ~CClientUIInterface::SECURE;
24 : :
25 [ + + - + ]: 186 : std::string strCaption;
26 [ + + - + ]: 186 : switch (style) {
27 : 168 : case CClientUIInterface::MSG_ERROR:
28 [ + - ]: 168 : strCaption = "Error: ";
29 [ + - + - ]: 168 : if (!fSecure) LogError("%s\n", message.original);
30 : : break;
31 : 7 : case CClientUIInterface::MSG_WARNING:
32 [ + - ]: 7 : strCaption = "Warning: ";
33 [ + - + - ]: 7 : if (!fSecure) LogWarning("%s\n", message.original);
34 : : break;
35 : 0 : case CClientUIInterface::MSG_INFORMATION:
36 [ # # ]: 0 : strCaption = "Information: ";
37 [ # # # # ]: 0 : if (!fSecure) LogInfo("%s\n", message.original);
38 : : break;
39 : 11 : default:
40 [ + - + - ]: 11 : if (!fSecure) LogInfo("%s%s\n", strCaption, message.original);
41 : : }
42 : :
43 [ + - ]: 186 : tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
44 : 186 : return false;
45 : 186 : }
46 : :
47 : 11 : bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
48 : : {
49 [ - + + - : 33 : return noui_ThreadSafeMessageBox(Untranslated(message), style);
+ - ]
50 : : }
51 : :
52 : 7786 : void noui_InitMessage(const std::string& message)
53 : : {
54 : 7786 : LogInfo("init message: %s", message);
55 : 7786 : }
56 : :
57 : 1400 : void noui_connect()
58 : : {
59 [ + - - + ]: 2800 : noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
60 [ + - - + ]: 2800 : noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
61 [ + - - + ]: 2800 : noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
62 : 1400 : }
63 : :
64 : 4 : bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, unsigned int style)
65 : : {
66 : 4 : LogInfo("%s", message.original);
67 : 4 : return false;
68 : : }
69 : :
70 : 0 : bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style)
71 : : {
72 : 0 : LogInfo("%s", message);
73 : 0 : return false;
74 : : }
75 : :
76 : 1 : void noui_InitMessageRedirect(const std::string& message)
77 : : {
78 : 1 : LogInfo("init message: %s", message);
79 : 1 : }
80 : :
81 : 62 : void noui_test_redirect()
82 : : {
83 : 62 : noui_ThreadSafeMessageBoxConn.disconnect();
84 : 62 : noui_ThreadSafeQuestionConn.disconnect();
85 : 62 : noui_InitMessageConn.disconnect();
86 [ + - - + ]: 124 : noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
87 [ + - - + ]: 124 : noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
88 [ + - - + ]: 124 : noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
89 : 62 : }
90 : :
91 : 62 : void noui_reconnect()
92 : : {
93 : 62 : noui_ThreadSafeMessageBoxConn.disconnect();
94 : 62 : noui_ThreadSafeQuestionConn.disconnect();
95 : 62 : noui_InitMessageConn.disconnect();
96 : 62 : noui_connect();
97 : 62 : }
|