aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorCozz Lovan <cozzlovan@yahoo.com>2014-03-19 00:26:14 +0100
committerCozz Lovan <cozzlovan@yahoo.com>2014-04-02 03:48:07 +0200
commit392783697c21a0c4cf3db6b0946d3d44d7fed537 (patch)
tree9f0808ba972d629af5cae087b57c398bbd015b95 /src/qt
parent397521d632b4a49e61c8ea2246135f9cc00e57c4 (diff)
[Qt] rescan progress
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/splashscreen.cpp23
-rw-r--r--src/qt/walletmodel.cpp30
-rw-r--r--src/qt/walletmodel.h3
-rw-r--r--src/qt/walletview.cpp27
-rw-r--r--src/qt/walletview.h6
5 files changed, 89 insertions, 0 deletions
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index cacf5dc49b..7c79b0efd0 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -5,8 +5,12 @@
#include "splashscreen.h"
#include "clientversion.h"
+#include "init.h"
#include "ui_interface.h"
#include "util.h"
+#ifdef ENABLE_WALLET
+#include "wallet.h"
+#endif
#include <QApplication>
#include <QPainter>
@@ -109,14 +113,33 @@ static void InitMessage(SplashScreen *splash, const std::string &message)
Q_ARG(QColor, QColor(55,55,55)));
}
+static void ShowProgress(SplashScreen *splash, const std::string &title, int nProgress)
+{
+ InitMessage(splash, title + strprintf("%d", nProgress) + "%");
+}
+
+#ifdef ENABLE_WALLET
+static void ConnectWallet(SplashScreen *splash, CWallet* wallet)
+{
+ wallet->ShowProgress.connect(boost::bind(ShowProgress, splash, _1, _2));
+}
+#endif
+
void SplashScreen::subscribeToCoreSignals()
{
// Connect signals to client
uiInterface.InitMessage.connect(boost::bind(InitMessage, this, _1));
+#ifdef ENABLE_WALLET
+ uiInterface.LoadWallet.connect(boost::bind(ConnectWallet, this, _1));
+#endif
}
void SplashScreen::unsubscribeFromCoreSignals()
{
// Disconnect signals from client
uiInterface.InitMessage.disconnect(boost::bind(InitMessage, this, _1));
+#ifdef ENABLE_WALLET
+ if(pwalletMain)
+ pwalletMain->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
+#endif
}
diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp
index eae448fee4..424c9ee279 100644
--- a/src/qt/walletmodel.cpp
+++ b/src/qt/walletmodel.cpp
@@ -419,8 +419,17 @@ static void NotifyAddressBookChanged(WalletModel *walletmodel, CWallet *wallet,
Q_ARG(int, status));
}
+// queue notifications to show a non freezing progress dialog e.g. for rescan
+static bool fQueueNotifications = false;
+static std::vector<std::pair<uint256, ChangeType> > vQueueNotifications;
static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet, const uint256 &hash, ChangeType status)
{
+ if (fQueueNotifications)
+ {
+ vQueueNotifications.push_back(make_pair(hash, status));
+ return;
+ }
+
QString strHash = QString::fromStdString(hash.GetHex());
qDebug() << "NotifyTransactionChanged : " + strHash + " status= " + QString::number(status);
@@ -429,12 +438,32 @@ static void NotifyTransactionChanged(WalletModel *walletmodel, CWallet *wallet,
Q_ARG(int, status));
}
+static void ShowProgress(WalletModel *walletmodel, const std::string &title, int nProgress)
+{
+ // emits signal "showProgress"
+ QMetaObject::invokeMethod(walletmodel, "showProgress", Qt::QueuedConnection,
+ Q_ARG(QString, QString::fromStdString(title)),
+ Q_ARG(int, nProgress));
+
+ if (nProgress == 0)
+ fQueueNotifications = true;
+
+ if (nProgress == 100)
+ {
+ fQueueNotifications = false;
+ BOOST_FOREACH(const PAIRTYPE(uint256, ChangeType)& notification, vQueueNotifications)
+ NotifyTransactionChanged(walletmodel, NULL, notification.first, notification.second);
+ std::vector<std::pair<uint256, ChangeType> >().swap(vQueueNotifications); // clear
+ }
+}
+
void WalletModel::subscribeToCoreSignals()
{
// Connect signals to wallet
wallet->NotifyStatusChanged.connect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
wallet->NotifyAddressBookChanged.connect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
wallet->NotifyTransactionChanged.connect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
+ wallet->ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2));
}
void WalletModel::unsubscribeFromCoreSignals()
@@ -443,6 +472,7 @@ void WalletModel::unsubscribeFromCoreSignals()
wallet->NotifyStatusChanged.disconnect(boost::bind(&NotifyKeyStoreStatusChanged, this, _1));
wallet->NotifyAddressBookChanged.disconnect(boost::bind(NotifyAddressBookChanged, this, _1, _2, _3, _4, _5, _6));
wallet->NotifyTransactionChanged.disconnect(boost::bind(NotifyTransactionChanged, this, _1, _2, _3));
+ wallet->ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2));
}
// WalletModel::UnlockContext implementation
diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h
index 28a9169e27..ccf590aaed 100644
--- a/src/qt/walletmodel.h
+++ b/src/qt/walletmodel.h
@@ -237,6 +237,9 @@ signals:
// Coins sent: from wallet, to recipient, in (serialized) transaction:
void coinsSent(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
+ // Show progress dialog e.g. for rescan
+ void showProgress(const QString &title, int nProgress);
+
public slots:
/* Wallet status might have changed */
void updateStatus();
diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp
index 1a9c7866db..1cef48344f 100644
--- a/src/qt/walletview.cpp
+++ b/src/qt/walletview.cpp
@@ -24,6 +24,7 @@
#include <QActionGroup>
#include <QFileDialog>
#include <QHBoxLayout>
+#include <QProgressDialog>
#include <QPushButton>
#include <QVBoxLayout>
@@ -127,6 +128,9 @@ void WalletView::setWalletModel(WalletModel *walletModel)
// Ask for passphrase if needed
connect(walletModel, SIGNAL(requireUnlock()), this, SLOT(unlockWallet()));
+
+ // Show progress dialog
+ connect(walletModel, SIGNAL(showProgress(QString,int)), this, SLOT(showProgress(QString,int)));
}
}
@@ -277,3 +281,26 @@ void WalletView::usedReceivingAddresses()
dlg->setModel(walletModel->getAddressTableModel());
dlg->show();
}
+
+void WalletView::showProgress(const QString &title, int nProgress)
+{
+ if (nProgress == 0)
+ {
+ progressDialog = new QProgressDialog(title, "", 0, 100);
+ progressDialog->setWindowModality(Qt::ApplicationModal);
+ progressDialog->setMinimumDuration(0);
+ progressDialog->setCancelButton(0);
+ progressDialog->setAutoClose(false);
+ progressDialog->setValue(0);
+ }
+ else if (nProgress == 100)
+ {
+ if (progressDialog)
+ {
+ progressDialog->close();
+ progressDialog->deleteLater();
+ }
+ }
+ else if (progressDialog)
+ progressDialog->setValue(nProgress);
+}
diff --git a/src/qt/walletview.h b/src/qt/walletview.h
index ecfa06ac5a..9cfa8d6760 100644
--- a/src/qt/walletview.h
+++ b/src/qt/walletview.h
@@ -18,6 +18,7 @@ class WalletModel;
QT_BEGIN_NAMESPACE
class QModelIndex;
+class QProgressDialog;
QT_END_NAMESPACE
/*
@@ -60,6 +61,8 @@ private:
TransactionView *transactionView;
+ QProgressDialog *progressDialog;
+
public slots:
/** Switch to overview (home) page */
void gotoOverviewPage();
@@ -97,6 +100,9 @@ public slots:
/** Re-emit encryption status signal */
void updateEncryptionStatus();
+ /** Show progress dialog e.g. for rescan */
+ void showProgress(const QString &title, int nProgress);
+
signals:
/** Signal that we want to show the main window */
void showNormalIfMinimized();