diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-04-29 00:03:52 +0100 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-04-29 00:18:19 +0100 |
commit | c6cbdf1a90a253fef0259b365a782bf88cd437f2 (patch) | |
tree | 02557cc56767ead7d12a6e5949bec97b96323000 | |
parent | 3bccd50ad2f384e6c8c97c7f44bda7ae0d777696 (diff) |
qt: Refactor ShowProgress to DispatchNotifications
-rw-r--r-- | src/qt/transactiontablemodel.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 9e2cccf33c..903a97a59d 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -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() |