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
|
2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2020 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-03-19 23:46:56 +01:00
|
|
|
#include <ui_interface.h>
|
2021-06-27 08:33:13 +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-25 20:20:30 +02:00
|
|
|
#include <boost/signals2/connection.hpp>
|
2021-10-08 14:54:20 +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-25 20:20:30 +02:00
|
|
|
|
2018-09-11 08:38:43 +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;
|
|
|
|
|
2012-11-05 08:04:21 +01:00
|
|
|
std::string strCaption;
|
|
|
|
// Check for usage of predefined caption
|
|
|
|
switch (style) {
|
|
|
|
case CClientUIInterface::MSG_ERROR:
|
|
|
|
strCaption += _("Error");
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_WARNING:
|
|
|
|
strCaption += _("Warning");
|
|
|
|
break;
|
|
|
|
case CClientUIInterface::MSG_INFORMATION:
|
|
|
|
strCaption += _("Information");
|
|
|
|
break;
|
|
|
|
default:
|
2013-01-02 15:09:24 +01:00
|
|
|
strCaption += caption; // Use supplied caption (can be empty)
|
2012-11-05 08:04:21 +01:00
|
|
|
}
|
|
|
|
|
2014-10-17 01:16:29 +02:00
|
|
|
if (!fSecure)
|
|
|
|
LogPrintf("%s: %s\n", strCaption, message);
|
2021-10-24 12:51:47 +02:00
|
|
|
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-11 08:38:43 +02:00
|
|
|
bool noui_ThreadSafeQuestion(const std::string& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
|
2017-09-09 09:04:02 +02:00
|
|
|
{
|
|
|
|
return noui_ThreadSafeMessageBox(message, caption, style);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-10-08 14:54:20 +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();
|
|
|
|
}
|