2012-05-19 09:35:26 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2009-2022 The Bitcoin Core developers
|
2014-12-13 12:09:33 +08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 22:02:28 +08:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2012-11-05 08:04:21 +01:00
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <noui.h>
|
2013-04-13 00:13:08 -05:00
|
|
|
|
2020-04-11 18:47:17 +03:00
|
|
|
#include <logging.h>
|
2022-06-14 10:38:51 +02:00
|
|
|
#include <node/interface_ui.h>
|
2020-04-11 18:47:17 +03:00
|
|
|
#include <util/translation.h>
|
2012-05-19 09:35:26 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-08-13 16:13:29 -04:00
|
|
|
#include <boost/signals2/connection.hpp>
|
2019-06-24 17:14:43 +02:00
|
|
|
#include <boost/signals2/signal.hpp>
|
|
|
|
|
|
|
|
/** Store connections so we can disconnect them when suppressing output */
|
|
|
|
boost::signals2::connection noui_ThreadSafeMessageBoxConn;
|
|
|
|
boost::signals2::connection noui_ThreadSafeQuestionConn;
|
|
|
|
boost::signals2::connection noui_InitMessageConn;
|
2018-08-13 16:13:29 -04:00
|
|
|
|
2020-04-11 18:47:17 +03:00
|
|
|
bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style)
|
2012-05-19 09:35:26 +02:00
|
|
|
{
|
2014-10-16 16:16:29 -07:00
|
|
|
bool fSecure = style & CClientUIInterface::SECURE;
|
|
|
|
style &= ~CClientUIInterface::SECURE;
|
|
|
|
|
2012-11-05 08:04:21 +01:00
|
|
|
std::string strCaption;
|
2020-05-10 12:43:30 +03:00
|
|
|
switch (style) {
|
|
|
|
case CClientUIInterface::MSG_ERROR:
|
|
|
|
strCaption = "Error: ";
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_WARNING:
|
|
|
|
strCaption = "Warning: ";
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_INFORMATION:
|
|
|
|
strCaption = "Information: ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strCaption = caption + ": "; // Use supplied caption (can be empty)
|
2012-11-05 08:04:21 +01:00
|
|
|
}
|
|
|
|
|
2019-04-30 20:55:12 +03:00
|
|
|
if (!fSecure) {
|
2020-04-11 18:47:17 +03:00
|
|
|
LogPrintf("%s%s\n", strCaption, message.original);
|
2019-04-30 20:55:12 +03:00
|
|
|
}
|
2020-04-11 18:47:17 +03:00
|
|
|
tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
|
2013-02-16 17:58:45 +01:00
|
|
|
return false;
|
2012-05-19 09:35:26 +02:00
|
|
|
}
|
|
|
|
|
2020-04-11 18:47:17 +03:00
|
|
|
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2016-06-24 16:35:21 +02:00
|
|
|
{
|
2020-04-11 18:47:17 +03:00
|
|
|
return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
|
2016-06-24 16:35:21 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 14:49:40 -04:00
|
|
|
void noui_InitMessage(const std::string& message)
|
2013-01-11 22:57:22 +01:00
|
|
|
{
|
2014-01-16 16:15:27 +01:00
|
|
|
LogPrintf("init message: %s\n", message);
|
2013-01-11 22:57:22 +01:00
|
|
|
}
|
|
|
|
|
2012-05-19 09:35:26 +02:00
|
|
|
void noui_connect()
|
|
|
|
{
|
2019-06-24 17:14:43 +02:00
|
|
|
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
|
|
|
|
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
|
|
|
|
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
|
|
|
|
}
|
|
|
|
|
2020-04-11 18:47:17 +03:00
|
|
|
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
|
2019-06-24 17:14:43 +02:00
|
|
|
{
|
2020-04-11 18:47:17 +03:00
|
|
|
LogPrintf("%s: %s\n", caption, message.original);
|
2019-06-24 17:14:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-11 18:47:17 +03:00
|
|
|
bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2019-06-24 17:14:43 +02:00
|
|
|
{
|
2019-08-02 17:06:37 -04:00
|
|
|
LogPrintf("%s: %s\n", caption, message);
|
2019-06-24 17:14:43 +02:00
|
|
|
return false;
|
2012-05-19 09:35:26 +02:00
|
|
|
}
|
2019-06-24 17:14:43 +02:00
|
|
|
|
2019-08-02 17:06:37 -04:00
|
|
|
void noui_InitMessageRedirect(const std::string& message)
|
2019-06-24 17:14:43 +02:00
|
|
|
{
|
2019-08-02 17:06:37 -04:00
|
|
|
LogPrintf("init message: %s\n", message);
|
2019-06-24 17:14:43 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 17:06:37 -04:00
|
|
|
void noui_test_redirect()
|
2019-06-24 17:14:43 +02:00
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
2019-08-02 17:06:37 -04:00
|
|
|
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
|
|
|
|
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
|
|
|
|
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
|
2019-06-24 17:14:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void noui_reconnect()
|
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
|
|
|
noui_connect();
|
2019-10-28 13:30:20 +01:00
|
|
|
}
|