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