2012-05-19 09:35:26 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2019-12-30 10:39:22 +01:00
|
|
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2012-11-05 08:04:21 +01:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <noui.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2020-04-11 17:47:17 +02:00
|
|
|
#include <logging.h>
|
2020-06-20 00:14:17 +02:00
|
|
|
#include <node/ui_interface.h>
|
2020-04-11 17:47:17 +02:00
|
|
|
#include <util/translation.h>
|
2012-05-19 09:35:26 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-08-13 22:13:29 +02: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 22:13:29 +02:00
|
|
|
|
2020-04-11 17:47:17 +02: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-17 01:16:29 +02:00
|
|
|
bool fSecure = style & CClientUIInterface::SECURE;
|
|
|
|
style &= ~CClientUIInterface::SECURE;
|
|
|
|
|
2012-11-05 08:04:21 +01:00
|
|
|
std::string strCaption;
|
2020-05-10 11:43:30 +02: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 19:55:12 +02:00
|
|
|
if (!fSecure) {
|
2020-04-11 17:47:17 +02:00
|
|
|
LogPrintf("%s%s\n", strCaption, message.original);
|
2019-04-30 19:55:12 +02:00
|
|
|
}
|
2020-04-11 17:47:17 +02: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 17:47:17 +02: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 17:47:17 +02:00
|
|
|
return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
|
2016-06-24 16:35:21 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 20:49:40 +02: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 17:47:17 +02: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 17:47:17 +02:00
|
|
|
LogPrintf("%s: %s\n", caption, message.original);
|
2019-06-24 17:14:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-11 17:47:17 +02: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 23:06:37 +02: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 23:06:37 +02:00
|
|
|
void noui_InitMessageRedirect(const std::string& message)
|
2019-06-24 17:14:43 +02:00
|
|
|
{
|
2019-08-02 23:06:37 +02:00
|
|
|
LogPrintf("init message: %s\n", message);
|
2019-06-24 17:14:43 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 23:06:37 +02: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 23:06:37 +02: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
|
|
|
}
|