/home/zip/work/bitcoin/src/noui.cpp
Line | Count | Source |
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 <node/interface_ui.h> |
10 | | #include <util/log.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 | | bool noui_ThreadSafeMessageBox(const bilingual_str& message, unsigned int style) |
21 | 0 | { |
22 | 0 | bool fSecure = style & CClientUIInterface::SECURE; |
23 | 0 | style &= ~CClientUIInterface::SECURE; |
24 | |
|
25 | 0 | std::string strCaption; |
26 | 0 | switch (style) { |
27 | 0 | case CClientUIInterface::MSG_ERROR: |
28 | 0 | strCaption = "Error: "; |
29 | 0 | if (!fSecure) LogError("%s\n", message.original);Line | Count | Source | 127 | 0 | #define LogError(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Error, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
30 | 0 | break; |
31 | 0 | case CClientUIInterface::MSG_WARNING: |
32 | 0 | strCaption = "Warning: "; |
33 | 0 | if (!fSecure) LogWarning("%s\n", message.original);Line | Count | Source | 126 | 0 | #define LogWarning(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Warning, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
34 | 0 | break; |
35 | 0 | case CClientUIInterface::MSG_INFORMATION: |
36 | 0 | strCaption = "Information: "; |
37 | 0 | if (!fSecure) LogInfo("%s\n", message.original);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
38 | 0 | break; |
39 | 0 | default: |
40 | 0 | if (!fSecure) LogInfo("%s%s\n", strCaption, message.original);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
41 | 0 | } |
42 | | |
43 | 0 | tfm::format(std::cerr, "%s%s\n", strCaption, message.original); |
44 | 0 | return false; |
45 | 0 | } |
46 | | |
47 | | bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style) |
48 | 0 | { |
49 | 0 | return noui_ThreadSafeMessageBox(Untranslated(message), style); |
50 | 0 | } |
51 | | |
52 | | void noui_InitMessage(const std::string& message) |
53 | 0 | { |
54 | 0 | LogInfo("init message: %s", message);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
55 | 0 | } |
56 | | |
57 | | void noui_connect() |
58 | 0 | { |
59 | 0 | noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); |
60 | 0 | noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); |
61 | 0 | noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage); |
62 | 0 | } |
63 | | |
64 | | bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, unsigned int style) |
65 | 0 | { |
66 | 0 | LogInfo("%s", message.original);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
67 | 0 | return false; |
68 | 0 | } |
69 | | |
70 | | bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, unsigned int style) |
71 | 0 | { |
72 | 0 | LogInfo("%s", message);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
73 | 0 | return false; |
74 | 0 | } |
75 | | |
76 | | void noui_InitMessageRedirect(const std::string& message) |
77 | 0 | { |
78 | 0 | LogInfo("init message: %s", message);Line | Count | Source | 125 | 0 | #define LogInfo(...) detail_LogWithSrcLoc(BCLog::LogFlags::ALL, util::log::Level::Info, __VA_ARGS__) Line | Count | Source | 119 | 0 | #define detail_LogWithSrcLoc(category, level, ...) util::log::LogPrintFormatInternal(SourceLocation{__func__}, category, level, __VA_ARGS__) |
|
|
79 | 0 | } |
80 | | |
81 | | void noui_test_redirect() |
82 | 0 | { |
83 | 0 | noui_ThreadSafeMessageBoxConn.disconnect(); |
84 | 0 | noui_ThreadSafeQuestionConn.disconnect(); |
85 | 0 | noui_InitMessageConn.disconnect(); |
86 | 0 | noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect); |
87 | 0 | noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect); |
88 | 0 | noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect); |
89 | 0 | } |
90 | | |
91 | | void noui_reconnect() |
92 | 0 | { |
93 | 0 | noui_ThreadSafeMessageBoxConn.disconnect(); |
94 | 0 | noui_ThreadSafeQuestionConn.disconnect(); |
95 | 0 | noui_InitMessageConn.disconnect(); |
96 | 0 | noui_connect(); |
97 | 0 | } |