mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-28 21:12:29 +02:00
qt: Refactor ShowProgress to DispatchNotifications
This commit is contained in:
parent
3bccd50ad2
commit
c6cbdf1a90
@ -96,13 +96,14 @@ public:
|
||||
*/
|
||||
QList<TransactionRecord> cachedWallet;
|
||||
|
||||
bool fQueueNotifications = false;
|
||||
/** True when model finishes loading all wallet transactions on start */
|
||||
bool m_loaded = false;
|
||||
/** True when transactions are being notified, for instance when scanning */
|
||||
bool m_loading = false;
|
||||
std::vector< TransactionNotification > vQueueNotifications;
|
||||
|
||||
void NotifyTransactionChanged(const uint256 &hash, ChangeType status);
|
||||
void ShowProgress(const std::string &title, int nProgress);
|
||||
void DispatchNotifications();
|
||||
|
||||
/* Query entire wallet anew from core.
|
||||
*/
|
||||
@ -721,7 +722,7 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
|
||||
|
||||
TransactionNotification notification(hash, status, showTransaction);
|
||||
|
||||
if (fQueueNotifications)
|
||||
if (m_loading)
|
||||
{
|
||||
vQueueNotifications.push_back(notification);
|
||||
return;
|
||||
@ -729,14 +730,11 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT
|
||||
notification.invoke(parent);
|
||||
}
|
||||
|
||||
void TransactionTablePriv::ShowProgress(const std::string &title, int nProgress)
|
||||
void TransactionTablePriv::DispatchNotifications()
|
||||
{
|
||||
if (nProgress == 0)
|
||||
fQueueNotifications = true;
|
||||
if (m_loading) return;
|
||||
|
||||
if (nProgress == 100)
|
||||
{
|
||||
fQueueNotifications = false;
|
||||
if (vQueueNotifications.size() > 10) { // prevent balloon spam, show maximum 10 balloons
|
||||
bool invoked = QMetaObject::invokeMethod(parent, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
|
||||
assert(invoked);
|
||||
@ -758,7 +756,10 @@ void TransactionTableModel::subscribeToCoreSignals()
|
||||
{
|
||||
// Connect signals to wallet
|
||||
m_handler_transaction_changed = walletModel->wallet().handleTransactionChanged(std::bind(&TransactionTablePriv::NotifyTransactionChanged, priv, std::placeholders::_1, std::placeholders::_2));
|
||||
m_handler_show_progress = walletModel->wallet().handleShowProgress(std::bind(&TransactionTablePriv::ShowProgress, priv, std::placeholders::_1, std::placeholders::_2));
|
||||
m_handler_show_progress = walletModel->wallet().handleShowProgress([this](const std::string&, int progress) {
|
||||
priv->m_loading = progress < 100;
|
||||
priv->DispatchNotifications();
|
||||
});
|
||||
}
|
||||
|
||||
void TransactionTableModel::unsubscribeFromCoreSignals()
|
||||
|
Loading…
Reference in New Issue
Block a user