Skip to content

Commit

Permalink
Merge pull request #2355 from div72/update_ui_interface
Browse files Browse the repository at this point in the history
refactor: port upstream ui_interface changes
  • Loading branch information
jamescowens authored Oct 10, 2021
2 parents 8d9571d + 557829d commit aec0a58
Show file tree
Hide file tree
Showing 38 changed files with 335 additions and 245 deletions.
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ GRIDCOIN_CORE_H = \
threadsafety.h \
tinyformat.h \
txdb.h \
ui_interface.h \
node/ui_interface.h \
uint256.h \
util/check.h \
util/reverse_iterator.h \
Expand Down Expand Up @@ -247,6 +247,7 @@ GRIDCOIN_CORE_CPP = addrdb.cpp \
netbase.cpp \
net.cpp \
node/blockstorage.cpp \
node/ui_interface.cpp \
noui.cpp \
pbkdf2.cpp \
policy/policy.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/alert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "net.h"
#include "streams.h"
#include "sync.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "uint256.h"

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "netbase.h"
#include "net.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"

BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time)
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "txdb.h"
#include "main.h"
#include "node/blockstorage.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"
#include "validation.h"

Expand Down
4 changes: 2 additions & 2 deletions src/gridcoin/gridcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "gridcoin/beacon.h"
#include "init.h"
#include "scheduler.h"
#include "ui_interface.h"
#include "node/ui_interface.h"

using namespace GRC;

Expand Down Expand Up @@ -48,7 +48,7 @@ void ShowChainCorruptedMessage()
"Your wallet will re-download the blockchain. Your balance may "
"appear incorrect until the synchronization finishes.\n" ),
"Gridcoin",
CClientUIInterface::OK | CClientUIInterface::MODAL);
CClientUIInterface::BTN_OK | CClientUIInterface::MODAL);
}

//!
Expand Down
3 changes: 2 additions & 1 deletion src/gridcoin/researcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "gridcoin/support/xml.h"
#include "gridcoin/tally.h"
#include "span.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"

#include <boost/algorithm/string/case_conv.hpp>
Expand All @@ -25,6 +25,7 @@
#include <optional>
#include <openssl/md5.h>
#include <set>
#include <univalue.h>

using namespace GRC;

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// file COPYING or https://opensource.org/licenses/mit-license.php.

#include "main.h"
#include "ui_interface.h"
#include "node/ui_interface.h"

#include "gridcoin/appcache.h"
#include "gridcoin/beacon.h"
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/staking/status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "gridcoin/staking/kernel.h"
#include "gridcoin/staking/status.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"
#include "wallet/wallet.h"

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/upgrade.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>

#include "gridcoin/scraper/http.h"
#include "ui_interface.h"
#include "node/ui_interface.h"

namespace GRC {

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/voting/builders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "gridcoin/voting/payloads.h"
#include "gridcoin/voting/registry.h"
#include "node/blockstorage.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "wallet/wallet.h"
#include <util/string.h>

Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/voting/poll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "gridcoin/support/xml.h"
#include "gridcoin/voting/poll.h"
#include "span.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"

#include <boost/algorithm/string/join.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "gridcoin/support/block_finder.h"
#include "node/blockstorage.h"
#include "txdb.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "validation.h"

using namespace GRC;
Expand Down
2 changes: 1 addition & 1 deletion src/gridcoinresearchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "init.h"
#include "rpc/server.h"
#include "rpc/client.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "gridcoin/upgrade.h"

#include <boost/thread.hpp>
Expand Down
20 changes: 3 additions & 17 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "banman.h"
#include "rpc/server.h"
#include "init.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "scheduler.h"
#include "gridcoin/gridcoin.h"
#include "miner.h"
Expand All @@ -36,7 +36,6 @@ extern void ThreadAppInit2(void* parg);

using namespace std;
CWallet* pwalletMain;
CClientUIInterface uiInterface;
extern bool fQtActive;
extern bool bGridcoinCoreInitComplete;
extern bool fConfChange;
Expand Down Expand Up @@ -188,18 +187,6 @@ static void registerSignalHandler(int signal, void(*handler)(int))
}
#endif

bool static InitError(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Gridcoin"), CClientUIInterface::OK | CClientUIInterface::MODAL);
return false;
}

bool static InitWarning(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, _("Gridcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
return true;
}


bool static Bind(const CService &addr, bool fError = true) {
if (IsLimited(addr))
Expand Down Expand Up @@ -1052,8 +1039,7 @@ bool AppInit2(ThreadHandlerPtr threads)
" Original wallet.dat saved as wallet.{timestamp}.bak in %s; if"
" your balance or transactions are incorrect you should"
" restore from a backup."), datadir.string());
uiInterface.ThreadSafeMessageBox(msg, _("Gridcoin"),
CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
InitWarning(msg);
}
if (r == CDBEnv::RECOVER_FAIL)
return InitError(_("wallet.dat corrupt, salvage failed"));
Expand Down Expand Up @@ -1250,7 +1236,7 @@ bool AppInit2(ThreadHandlerPtr threads)
{
string msg(_("Warning: error reading wallet.dat! All keys read correctly, but transaction data"
" or address book entries might be missing or incorrect."));
uiInterface.ThreadSafeMessageBox(msg, _("Gridcoin"), CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
InitWarning(msg);
}
else if (nLoadWalletRet == DB_TOO_NEW)
strErrors << _("Error loading wallet.dat: Wallet requires newer version of Gridcoin") << "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "checkpoints.h"
#include "txdb.h"
#include "init.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "gridcoin/beacon.h"
#include "gridcoin/claim.h"
#include "gridcoin/contract/contract.h"
Expand Down Expand Up @@ -2532,7 +2532,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes)
string strMessage = _("Warning: Disk space is low!");
strMiscWarning = strMessage;
LogPrintf("*** %s", strMessage);
uiInterface.ThreadSafeMessageBox(strMessage, "Gridcoin", CClientUIInterface::OK | CClientUIInterface::ICON_EXCLAMATION | CClientUIInterface::MODAL);
uiInterface.ThreadSafeMessageBox(strMessage, "Gridcoin", CClientUIInterface::MSG_ERROR);
StartShutdown();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "banman.h"
#include "net.h"
#include "init.h"
#include "ui_interface.h"
#include "node/ui_interface.h"
#include "util.h"
#include "util/threadnames.h"

Expand Down
87 changes: 87 additions & 0 deletions src/node/ui_interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2010-2020 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <node/ui_interface.h>

#include <boost/signals2/optional_last_value.hpp>
#include <boost/signals2/signal.hpp>


CClientUIInterface uiInterface;


struct UISignals {
boost::signals2::signal<CClientUIInterface::ThreadSafeMessageBoxSig> ThreadSafeMessageBox;
boost::signals2::signal<CClientUIInterface::ThreadSafeAskQuestionSig> ThreadSafeAskQuestion;
boost::signals2::signal<CClientUIInterface::InitMessageSig> InitMessage;
boost::signals2::signal<CClientUIInterface::NotifyNumConnectionsChangedSig> NotifyNumConnectionsChanged;
boost::signals2::signal<CClientUIInterface::NotifyAlertChangedSig> NotifyAlertChanged;
boost::signals2::signal<CClientUIInterface::BannedListChangedSig> BannedListChanged;
boost::signals2::signal<CClientUIInterface::MinerStatusChangedSig> MinerStatusChanged;
boost::signals2::signal<CClientUIInterface::ResearcherChangedSig> ResearcherChanged;
boost::signals2::signal<CClientUIInterface::BeaconChangedSig> BeaconChanged;
boost::signals2::signal<CClientUIInterface::NewPollReceivedSig> NewPollReceived;
boost::signals2::signal<CClientUIInterface::NotifyScraperEventSig> NotifyScraperEvent;
boost::signals2::signal<CClientUIInterface::ThreadSafeAskFeeSig> ThreadSafeAskFee;
boost::signals2::signal<CClientUIInterface::ThreadSafeHandleURISig> ThreadSafeHandleURI;
boost::signals2::signal<CClientUIInterface::QueueShutdownSig> QueueShutdown;
boost::signals2::signal<CClientUIInterface::TranslateSig> Translate;
boost::signals2::signal<CClientUIInterface::NotifyBlocksChangedSig> NotifyBlocksChanged;
boost::signals2::signal<CClientUIInterface::UpdateMessageBoxSig> UpdateMessageBox;
};
static UISignals g_ui_signals;

#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(ThreadSafeAskQuestion);
ADD_SIGNALS_IMPL_WRAPPER(InitMessage);
ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged);
ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged);
ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged);
ADD_SIGNALS_IMPL_WRAPPER(MinerStatusChanged);
ADD_SIGNALS_IMPL_WRAPPER(ResearcherChanged);
ADD_SIGNALS_IMPL_WRAPPER(BeaconChanged);
ADD_SIGNALS_IMPL_WRAPPER(NewPollReceived);
ADD_SIGNALS_IMPL_WRAPPER(NotifyScraperEvent);
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeAskFee);
ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeHandleURI);
ADD_SIGNALS_IMPL_WRAPPER(QueueShutdown);
ADD_SIGNALS_IMPL_WRAPPER(Translate);
ADD_SIGNALS_IMPL_WRAPPER(NotifyBlocksChanged);
ADD_SIGNALS_IMPL_WRAPPER(UpdateMessageBox);

void CClientUIInterface::ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style); }
void CClientUIInterface::UpdateMessageBox(const std::string& version, const std::string& message) { return g_ui_signals.UpdateMessageBox(version, message); }
bool CClientUIInterface::ThreadSafeAskFee(int64_t nFeeRequired, const std::string& strCaption) { return g_ui_signals.ThreadSafeAskFee(nFeeRequired, strCaption).value_or(false); }
bool CClientUIInterface::ThreadSafeAskQuestion(std::string caption, std::string body) { return g_ui_signals.ThreadSafeAskQuestion(caption, body).value_or(false); }
void CClientUIInterface::ThreadSafeHandleURI(const std::string& strURI) { return g_ui_signals.ThreadSafeHandleURI(strURI); }
void CClientUIInterface::InitMessage(const std::string &message) { return g_ui_signals.InitMessage(message); }
void CClientUIInterface::QueueShutdown() { return g_ui_signals.QueueShutdown(); }
std::string CClientUIInterface::Translate(const char* psz) { return g_ui_signals.Translate(psz).value_or(std::string(psz)); }
void CClientUIInterface::NotifyBlocksChanged(bool syncing, int height, int64_t best_time, uint32_t target_bits) { return g_ui_signals.NotifyBlocksChanged(syncing, height, best_time, target_bits); }
void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); }
void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); }
void CClientUIInterface::MinerStatusChanged(bool staking, double coin_weight) { return g_ui_signals.MinerStatusChanged(staking, coin_weight); }
void CClientUIInterface::ResearcherChanged() { return g_ui_signals.ResearcherChanged(); }
void CClientUIInterface::BeaconChanged() { return g_ui_signals.BeaconChanged(); }
void CClientUIInterface::NewPollReceived(int64_t poll_time) { return g_ui_signals.NewPollReceived(poll_time); }
void CClientUIInterface::NotifyAlertChanged(const uint256 &hash, ChangeType status) { return g_ui_signals.NotifyAlertChanged(hash, status); }
void CClientUIInterface::NotifyScraperEvent(const scrapereventtypes& ScraperEventtype, ChangeType status, const std::string& message) { return g_ui_signals.NotifyScraperEvent(ScraperEventtype, status, message); }


bool InitError(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, "Gridcoin", CClientUIInterface::MSG_ERROR);
return false;
}

void InitWarning(const std::string &str)
{
uiInterface.ThreadSafeMessageBox(str, "Gridcoin", CClientUIInterface::MSG_WARNING);
}
Loading

0 comments on commit aec0a58

Please sign in to comment.