LCOV - code coverage report
Current view: top level - src - noui.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 49 57 86.0 %
Date: 2026-06-25 07:23:43 Functions: 11 12 91.7 %

          Line data    Source code
       1             : // Copyright (c) 2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2020 The Bitcoin Core developers
       3             : // Copyright (c) 2014-2025 The Dash Core developers
       4             : // Distributed under the MIT software license, see the accompanying
       5             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       6             : 
       7             : #include <noui.h>
       8             : 
       9             : #include <logging.h>
      10             : #include <node/interface_ui.h>
      11             : #include <util/translation.h>
      12             : 
      13             : #include <string>
      14             : 
      15             : #include <boost/signals2/connection.hpp>
      16             : 
      17             : /** Store connections so we can disconnect them when suppressing output */
      18        3308 : boost::signals2::connection noui_ThreadSafeMessageBoxConn;
      19        3308 : boost::signals2::connection noui_ThreadSafeQuestionConn;
      20        3308 : boost::signals2::connection noui_InitMessageConn;
      21             : 
      22         347 : bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style)
      23             : {
      24         347 :     bool fSecure = style & CClientUIInterface::SECURE;
      25         347 :     style &= ~CClientUIInterface::SECURE;
      26             : 
      27         347 :     std::string strCaption;
      28         347 :     switch (style) {
      29             :     case CClientUIInterface::MSG_ERROR:
      30         295 :         strCaption = "Error: ";
      31         295 :         break;
      32             :     case CClientUIInterface::MSG_WARNING:
      33          34 :         strCaption = "Warning: ";
      34          34 :         break;
      35             :     case CClientUIInterface::MSG_INFORMATION:
      36           0 :         strCaption = "Information: ";
      37           0 :         break;
      38             :     default:
      39          18 :         strCaption = caption + ": "; // Use supplied caption (can be empty)
      40          18 :     }
      41             : 
      42         347 :     if (!fSecure) {
      43         347 :         LogPrintf("%s%s\n", strCaption, message.original);
      44         347 :     }
      45         347 :     tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
      46             :     return false;
      47         347 : }
      48             : 
      49          18 : bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      50             : {
      51          18 :     return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
      52           0 : }
      53             : 
      54       21232 : void noui_InitMessage(const std::string& message)
      55             : {
      56       21232 :     LogPrintf("init message: %s\n", message);
      57       21232 : }
      58             : 
      59        3334 : void noui_connect()
      60             : {
      61        3334 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
      62        3334 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
      63        3334 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
      64        3334 : }
      65             : 
      66           4 : bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
      67             : {
      68           4 :     LogPrintf("%s: %s\n", caption, message.original);
      69           4 :     return false;
      70           0 : }
      71             : 
      72           0 : bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      73             : {
      74           0 :     LogPrintf("%s: %s\n", caption, message);
      75           0 :     return false;
      76           0 : }
      77             : 
      78           5 : void noui_InitMessageRedirect(const std::string& message)
      79             : {
      80           5 :     LogPrintf("init message: %s\n", message);
      81           5 : }
      82             : 
      83          56 : void noui_test_redirect()
      84             : {
      85          56 :     noui_ThreadSafeMessageBoxConn.disconnect();
      86          56 :     noui_ThreadSafeQuestionConn.disconnect();
      87          56 :     noui_InitMessageConn.disconnect();
      88          56 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
      89          56 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
      90          56 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
      91          56 : }
      92             : 
      93          56 : void noui_reconnect()
      94             : {
      95          56 :     noui_ThreadSafeMessageBoxConn.disconnect();
      96          56 :     noui_ThreadSafeQuestionConn.disconnect();
      97          56 :     noui_InitMessageConn.disconnect();
      98          56 :     noui_connect();
      99          56 : }

Generated by: LCOV version 1.16