Skip to content

Commit

Permalink
qt: Refactor ShowProgress to DispatchNotifications
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Apr 28, 2021
1 parent 3bccd50 commit c6cbdf1
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ class TransactionTablePriv
*/
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.
*/
Expand Down Expand Up @@ -721,22 +722,19 @@ void TransactionTablePriv::NotifyTransactionChanged(const uint256 &hash, ChangeT

TransactionNotification notification(hash, status, showTransaction);

if (fQueueNotifications)
if (m_loading)
{
vQueueNotifications.push_back(notification);
return;
}
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);
Expand All @@ -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()
Expand Down

0 comments on commit c6cbdf1

Please sign in to comment.