2012-05-19 09:35:26 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
2022-06-08 01:36:46 +02:00
|
|
|
// Copyright (c) 2014-2022 The Dash 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
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <noui.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2020-05-08 18:17:47 +02:00
|
|
|
#include <logging.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <ui_interface.h>
|
2020-05-08 18:17:47 +02:00
|
|
|
#include <util/translation.h>
|
2012-05-19 09:35:26 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2018-08-25 20:20:30 +02:00
|
|
|
#include <boost/signals2/connection.hpp>
|
2021-10-08 14:54:20 +02:00
|
|
|
|
|
|
|
/** 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-25 20:20:30 +02:00
|
|
|
|
2020-05-08 18:17:47 +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 10:42:11 +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-06-25 13:32:24 +02:00
|
|
|
if (!fSecure) {
|
2020-05-08 18:17:47 +02:00
|
|
|
LogPrintf("%s%s\n", strCaption, message.original);
|
2019-06-25 13:32:24 +02:00
|
|
|
}
|
2020-05-08 18:17:47 +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-05-08 18:17:47 +02:00
|
|
|
bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2017-09-09 09:04:02 +02:00
|
|
|
{
|
2020-05-08 18:17:47 +02:00
|
|
|
return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
|
2017-09-09 09:04:02 +02:00
|
|
|
}
|
|
|
|
|
2018-09-11 08:38:43 +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()
|
|
|
|
{
|
2021-10-08 14:54:20 +02:00
|
|
|
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
|
|
|
|
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
|
|
|
|
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:17:47 +02:00
|
|
|
bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
|
2021-10-08 14:54:20 +02:00
|
|
|
{
|
2020-05-08 18:17:47 +02:00
|
|
|
LogPrintf("%s: %s\n", caption, message.original);
|
2021-10-08 14:54:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:17:47 +02:00
|
|
|
bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2021-10-08 14:54:20 +02:00
|
|
|
{
|
2022-02-26 06:07:36 +01:00
|
|
|
LogPrintf("%s: %s\n", caption, message);
|
2021-10-08 14:54:20 +02:00
|
|
|
return false;
|
2012-05-19 09:35:26 +02:00
|
|
|
}
|
2021-10-08 14:54:20 +02:00
|
|
|
|
2022-02-26 06:07:36 +01:00
|
|
|
void noui_InitMessageRedirect(const std::string& message)
|
2021-10-08 14:54:20 +02:00
|
|
|
{
|
2022-02-26 06:07:36 +01:00
|
|
|
LogPrintf("init message: %s\n", message);
|
2021-10-08 14:54:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-26 06:07:36 +01:00
|
|
|
void noui_test_redirect()
|
2021-10-08 14:54:20 +02:00
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
2022-02-26 06:07:36 +01:00
|
|
|
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
|
|
|
|
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
|
|
|
|
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
|
2021-10-08 14:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void noui_reconnect()
|
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
|
|
|
noui_connect();
|
2022-03-21 18:28:10 +01:00
|
|
|
}
|