2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2010-2022 The Bitcoin Core developers
|
2016-03-21 18:29:17 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2022-06-14 10:38:51 +02:00
|
|
|
#include <node/interface_ui.h>
|
2016-03-21 18:29:17 +01:00
|
|
|
|
2023-02-24 13:44:07 -05:00
|
|
|
#include <util/string.h>
|
2020-04-11 18:47:17 +03:00
|
|
|
#include <util/translation.h>
|
|
|
|
|
2020-05-26 13:43:54 -04:00
|
|
|
#include <boost/signals2/optional_last_value.hpp>
|
2018-07-11 08:00:15 -04:00
|
|
|
#include <boost/signals2/signal.hpp>
|
|
|
|
|
2023-12-06 15:13:39 -05:00
|
|
|
using util::MakeUnorderedList;
|
|
|
|
|
2016-03-21 18:29:17 +01:00
|
|
|
CClientUIInterface uiInterface;
|
|
|
|
|
2018-07-11 08:00:15 -04:00
|
|
|
struct UISignals {
|
2020-05-26 13:43:54 -04:00
|
|
|
boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig, boost::signals2::optional_last_value<bool>> ThreadSafeMessageBox;
|
|
|
|
boost::signals2::signal<CClientUIInterface::ThreadSafeQuestionSig, boost::signals2::optional_last_value<bool>> ThreadSafeQuestion;
|
2018-07-11 08:00:15 -04:00
|
|
|
boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
|
2021-08-30 21:04:06 -04:00
|
|
|
boost::signals2::signal<CClientUIInterface::InitWalletSig> InitWallet;
|
2018-07-11 08:00:15 -04:00
|
|
|
boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
|
|
|
|
boost::signals2::signal<CClientUIInterface::NotifyNetworkActiveChangedSig> NotifyNetworkActiveChanged;
|
|
|
|
boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
|
|
|
|
boost::signals2::signal<CClientUIInterface::ShowProgressSig> ShowProgress;
|
|
|
|
boost::signals2::signal<CClientUIInterface::NotifyBlockTipSig> NotifyBlockTip;
|
|
|
|
boost::signals2::signal<CClientUIInterface::NotifyHeaderTipSig> NotifyHeaderTip;
|
|
|
|
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
|
2019-05-26 11:01:58 +02:00
|
|
|
};
|
|
|
|
static UISignals g_ui_signals;
|
2018-07-11 08:00:15 -04:00
|
|
|
|
|
|
|
#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \
|
|
|
|
boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function<signal_name##Sig> fn) \
|
|
|
|
{ \
|
|
|
|
return g_ui_signals.signal_name.connect(fn); \
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(InitMessage);
|
2021-08-30 21:04:06 -04:00
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(InitWallet);
|
2018-07-11 08:00:15 -04:00
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(ShowProgress);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip);
|
|
|
|
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
|
|
|
|
|
2020-05-26 13:43:54 -04:00
|
|
|
bool CClientUIInterface::ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style).value_or(false);}
|
|
|
|
bool CClientUIInterface::ThreadSafeQuestion(const bilingual_str& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style).value_or(false);}
|
2018-07-11 08:00:15 -04:00
|
|
|
void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); }
|
2021-08-30 21:04:06 -04:00
|
|
|
void CClientUIInterface::InitWallet() { return g_ui_signals.InitWallet(); }
|
2018-07-11 08:00:15 -04:00
|
|
|
void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
|
|
|
|
void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); }
|
|
|
|
void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); }
|
|
|
|
void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); }
|
2020-03-04 20:05:42 +02:00
|
|
|
void CClientUIInterface::NotifyBlockTip(SynchronizationState s, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(s, i); }
|
2022-08-13 14:21:12 -04:00
|
|
|
void CClientUIInterface::NotifyHeaderTip(SynchronizationState s, int64_t height, int64_t timestamp, bool presync) { return g_ui_signals.NotifyHeaderTip(s, height, timestamp, presync); }
|
2018-07-11 08:00:15 -04:00
|
|
|
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
|
|
|
|
|
2020-04-11 18:48:04 +03:00
|
|
|
bool InitError(const bilingual_str& str)
|
2016-03-21 18:29:17 +01:00
|
|
|
{
|
2020-04-11 18:48:04 +03:00
|
|
|
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR);
|
2016-03-21 18:29:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-02-24 13:44:07 -05:00
|
|
|
bool InitError(const bilingual_str& str, const std::vector<std::string>& details)
|
|
|
|
{
|
|
|
|
// For now just flatten the list of error details into a string to pass to
|
|
|
|
// the base InitError overload. In the future, if more init code provides
|
|
|
|
// error details, the details could be passed separately from the main
|
|
|
|
// message for rich display in the GUI. But currently the only init
|
|
|
|
// functions which provide error details are ones that run during early init
|
|
|
|
// before the GUI uiInterface is registered, so there's no point passing
|
|
|
|
// main messages and details separately to uiInterface yet.
|
|
|
|
return InitError(details.empty() ? str : strprintf(Untranslated("%s:\n%s"), str, MakeUnorderedList(details)));
|
|
|
|
}
|
|
|
|
|
2020-05-09 14:46:01 +03:00
|
|
|
void InitWarning(const bilingual_str& str)
|
2016-03-21 18:29:17 +01:00
|
|
|
{
|
2020-05-09 14:46:01 +03:00
|
|
|
uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_WARNING);
|
2016-03-21 18:29:17 +01:00
|
|
|
}
|