[Qt] Prevent balloon-spam after rescan

This commit is contained in:
Cozz Lovan 2014-07-13 10:19:56 +02:00
parent e8d4cb8071
commit acd432b5b3
3 changed files with 16 additions and 3 deletions

View File

@ -35,6 +35,8 @@ WalletModel::WalletModel(CWallet *wallet, OptionsModel *optionsModel, QObject *p
cachedEncryptionStatus(Unencrypted), cachedEncryptionStatus(Unencrypted),
cachedNumBlocks(0) cachedNumBlocks(0)
{ {
fProcessingQueuedTransactions = false;
addressTableModel = new AddressTableModel(wallet, this); addressTableModel = new AddressTableModel(wallet, this);
transactionTableModel = new TransactionTableModel(wallet, this); transactionTableModel = new TransactionTableModel(wallet, this);
recentRequestsTableModel = new RecentRequestsTableModel(wallet, this); recentRequestsTableModel = new RecentRequestsTableModel(wallet, this);
@ -492,8 +494,15 @@ static void ShowProgress(WalletModel *walletmodel, const std::string &title, int
if (nProgress == 100) if (nProgress == 100)
{ {
fQueueNotifications = false; fQueueNotifications = false;
BOOST_FOREACH(const PAIRTYPE(uint256, ChangeType)& notification, vQueueNotifications) if (vQueueNotifications.size() > 10) // prevent balloon spam, show maximum 10 balloons
NotifyTransactionChanged(walletmodel, NULL, notification.first, notification.second); QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, true));
for (unsigned int i = 0; i < vQueueNotifications.size(); ++i)
{
if (vQueueNotifications.size() - i <= 10)
QMetaObject::invokeMethod(walletmodel, "setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(bool, false));
NotifyTransactionChanged(walletmodel, NULL, vQueueNotifications[i].first, vQueueNotifications[i].second);
}
std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
} }
} }

View File

@ -133,6 +133,7 @@ public:
qint64 getWatchImmatureBalance() const; qint64 getWatchImmatureBalance() const;
int getNumTransactions() const; int getNumTransactions() const;
EncryptionStatus getEncryptionStatus() const; EncryptionStatus getEncryptionStatus() const;
bool processingQueuedTransactions() { return fProcessingQueuedTransactions; }
// Check address for validity // Check address for validity
bool validateAddress(const QString &address); bool validateAddress(const QString &address);
@ -196,6 +197,7 @@ public:
private: private:
CWallet *wallet; CWallet *wallet;
bool fProcessingQueuedTransactions;
// Wallet has an options model for wallet-specific options // Wallet has an options model for wallet-specific options
// (transaction fee, for example) // (transaction fee, for example)
@ -256,6 +258,8 @@ public slots:
void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status); void updateAddressBook(const QString &address, const QString &label, bool isMine, const QString &purpose, int status);
/* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */ /* Current, immature or unconfirmed balance might have changed - emit 'balanceChanged' if so */
void pollBalanceChanged(); void pollBalanceChanged();
/* Needed to update fProcessingQueuedTransactions through a QueuedConnection */
void setProcessingQueuedTransactions(bool value) { fProcessingQueuedTransactions = value; }
}; };
#endif // WALLETMODEL_H #endif // WALLETMODEL_H

View File

@ -137,7 +137,7 @@ void WalletView::setWalletModel(WalletModel *walletModel)
void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/) void WalletView::processNewTransaction(const QModelIndex& parent, int start, int /*end*/)
{ {
// Prevent balloon-spam when initial block download is in progress // Prevent balloon-spam when initial block download is in progress
if (!walletModel || !clientModel || clientModel->inInitialBlockDownload()) if (!walletModel || walletModel->processingQueuedTransactions() || !clientModel || clientModel->inInitialBlockDownload())
return; return;
TransactionTableModel *ttm = walletModel->getTransactionTableModel(); TransactionTableModel *ttm = walletModel->getTransactionTableModel();