Skip to content

Commit 69b01e6

Browse files
committed
Add cancel button to rescan progress dialog
Adds a cancel button to the rescan progress dialog. When it is clicked, AbortRescan is called to abort a rescan
1 parent 27278df commit 69b01e6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/interfaces/wallet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class WalletImpl : public Wallet
132132
{
133133
return m_wallet.ChangeWalletPassphrase(old_wallet_passphrase, new_wallet_passphrase);
134134
}
135+
void abortRescan() override { m_wallet.AbortRescan(); }
135136
bool backupWallet(const std::string& filename) override { return m_wallet.BackupWallet(filename); }
136137
std::string getWalletName() override { return m_wallet.GetName(); }
137138
bool getKeyFromPool(bool internal, CPubKey& pub_key) override

src/interfaces/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class Wallet
6565
virtual bool changeWalletPassphrase(const SecureString& old_wallet_passphrase,
6666
const SecureString& new_wallet_passphrase) = 0;
6767

68+
//! Abort a rescan.
69+
virtual void abortRescan() = 0;
70+
6871
//! Back up wallet.
6972
virtual bool backupWallet(const std::string& filename) = 0;
7073

src/qt/walletview.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ void WalletView::showProgress(const QString &title, int nProgress)
315315
progressDialog = new QProgressDialog(title, "", 0, 100);
316316
progressDialog->setWindowModality(Qt::ApplicationModal);
317317
progressDialog->setMinimumDuration(0);
318-
progressDialog->setCancelButton(0);
319318
progressDialog->setAutoClose(false);
320319
progressDialog->setValue(0);
320+
progressDialog->setCancelButtonText(tr("Cancel"));
321321
}
322322
else if (nProgress == 100)
323323
{
@@ -327,8 +327,13 @@ void WalletView::showProgress(const QString &title, int nProgress)
327327
progressDialog->deleteLater();
328328
}
329329
}
330-
else if (progressDialog)
331-
progressDialog->setValue(nProgress);
330+
else if (progressDialog) {
331+
if (progressDialog->wasCanceled()) {
332+
getWalletModel()->wallet().abortRescan();
333+
} else {
334+
progressDialog->setValue(nProgress);
335+
}
336+
}
332337
}
333338

334339
void WalletView::requestedSyncWarningInfo()

src/wallet/rpcdump.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,11 @@ UniValue importwallet(const JSONRPCRequest& request)
534534
int64_t nFilesize = std::max((int64_t)1, (int64_t)file.tellg());
535535
file.seekg(0, file.beg);
536536

537-
pwallet->ShowProgress(_("Importing..."), 0); // show progress dialog in GUI
537+
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because pwallet.ShowProgress has a cancel button tied to AbortRescan which
538+
// we don't want for this progress bar shoing the import progress. uiInterface.ShowProgress does not have a cancel button.
539+
uiInterface.ShowProgress(_("Importing..."), 0, false); // show progress dialog in GUI
538540
while (file.good()) {
539-
pwallet->ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))));
541+
uiInterface.ShowProgress("", std::max(1, std::min(99, (int)(((double)file.tellg() / (double)nFilesize) * 100))), false);
540542
std::string line;
541543
std::getline(file, line);
542544
if (line.empty() || line[0] == '#')
@@ -599,7 +601,7 @@ UniValue importwallet(const JSONRPCRequest& request)
599601
}
600602
}
601603
file.close();
602-
pwallet->ShowProgress("", 100); // hide progress dialog in GUI
604+
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
603605
pwallet->UpdateTimeFirstKey(nTimeBegin);
604606
}
605607
pwallet->RescanFromTime(nTimeBegin, reserver, false /* update */);

0 commit comments

Comments
 (0)