2012-05-19 09:35:26 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2018-07-27 00:36:45 +02:00
|
|
|
// Copyright (c) 2009-2018 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
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <ui_interface.h>
|
2018-10-23 00:51:11 +02:00
|
|
|
#include <util/system.h>
|
2012-05-19 09:35:26 +02:00
|
|
|
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 16:11:09 +02:00
|
|
|
#include <cstdio>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <stdint.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
|
|
|
|
2018-09-06 20:49:40 +02:00
|
|
|
bool noui_ThreadSafeMessageBox(const std::string& 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;
|
2019-04-30 19:55:12 +02:00
|
|
|
bool prefix = !(style & CClientUIInterface::MSG_NOPREFIX);
|
|
|
|
style &= ~CClientUIInterface::MSG_NOPREFIX;
|
2014-10-17 01:16:29 +02:00
|
|
|
|
2012-11-05 08:04:21 +01:00
|
|
|
std::string strCaption;
|
2019-04-30 19:55:12 +02:00
|
|
|
if (prefix) {
|
|
|
|
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) {
|
|
|
|
LogPrintf("%s%s\n", strCaption, message);
|
|
|
|
}
|
|
|
|
tfm::format(std::cerr, "%s%s\n", strCaption.c_str(), message.c_str());
|
2013-02-16 17:58:45 +01:00
|
|
|
return false;
|
2012-05-19 09:35:26 +02:00
|
|
|
}
|
|
|
|
|
2018-09-06 20:49:40 +02:00
|
|
|
bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2016-06-24 16:35:21 +02:00
|
|
|
{
|
|
|
|
return noui_ThreadSafeMessageBox(message, caption, style);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool noui_ThreadSafeMessageBoxSuppressed(const std::string& message, const std::string& caption, unsigned int style)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool noui_ThreadSafeQuestionSuppressed(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
|
|
|
{
|
|
|
|
return false;
|
2012-05-19 09:35:26 +02:00
|
|
|
}
|
2019-06-24 17:14:43 +02:00
|
|
|
|
|
|
|
void noui_InitMessageSuppressed(const std::string& message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void noui_suppress()
|
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
|
|
|
noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxSuppressed);
|
|
|
|
noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionSuppressed);
|
|
|
|
noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageSuppressed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void noui_reconnect()
|
|
|
|
{
|
|
|
|
noui_ThreadSafeMessageBoxConn.disconnect();
|
|
|
|
noui_ThreadSafeQuestionConn.disconnect();
|
|
|
|
noui_InitMessageConn.disconnect();
|
|
|
|
noui_connect();
|
|
|
|
}
|