Skip to content

Commit 7f9800c

Browse files
committed
Merge #15202: gui: Add Close All Wallets action
c4b5748 gui: Add Close All Wallets action (João Barbosa) f30960a gui: Add closeAllWallets to WalletController (João Barbosa) Pull request description: This PR adds the action to close all wallets. <img width="405" alt="Screenshot 2020-06-01 at 01 06 12" src="https://user-images.githubusercontent.com/3534524/83365986-25a8b980-a3a4-11ea-9613-24dcd8eaa55c.png"> ACKs for top commit: jonasschnelli: Tested ACK c4b5748 Tree-SHA512: 049ad77ac79949fb55f6bde47b583fbf946f4bfaf3d56d768e85f813d814cff0fe326b700f7b5e383cda4af7b5666e13043a6aaeee3798a69fc94385d88ce809
2 parents 4ede05d + c4b5748 commit 7f9800c

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/qt/bitcoingui.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ void BitcoinGUI::createActions()
350350
m_create_wallet_action->setEnabled(false);
351351
m_create_wallet_action->setStatusTip(tr("Create a new wallet"));
352352

353+
m_close_all_wallets_action = new QAction(tr("Close All Wallets..."), this);
354+
m_close_all_wallets_action->setStatusTip(tr("Close all wallets"));
355+
353356
showHelpMessageAction = new QAction(tr("&Command-line options"), this);
354357
showHelpMessageAction->setMenuRole(QAction::NoRole);
355358
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(PACKAGE_NAME));
@@ -421,7 +424,9 @@ void BitcoinGUI::createActions()
421424
connect(activity, &CreateWalletActivity::finished, activity, &QObject::deleteLater);
422425
activity->create();
423426
});
424-
427+
connect(m_close_all_wallets_action, &QAction::triggered, [this] {
428+
m_wallet_controller->closeAllWallets(this);
429+
});
425430
connect(m_mask_values_action, &QAction::toggled, this, &BitcoinGUI::setPrivacy);
426431
}
427432
#endif // ENABLE_WALLET
@@ -447,6 +452,7 @@ void BitcoinGUI::createMenuBar()
447452
file->addAction(m_create_wallet_action);
448453
file->addAction(m_open_wallet_action);
449454
file->addAction(m_close_wallet_action);
455+
file->addAction(m_close_all_wallets_action);
450456
file->addSeparator();
451457
file->addAction(openAction);
452458
file->addAction(backupWalletAction);
@@ -727,6 +733,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
727733
usedReceivingAddressesAction->setEnabled(enabled);
728734
openAction->setEnabled(enabled);
729735
m_close_wallet_action->setEnabled(enabled);
736+
m_close_all_wallets_action->setEnabled(enabled);
730737
}
731738

732739
void BitcoinGUI::createTrayIcon()

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class BitcoinGUI : public QMainWindow
155155
QAction* m_open_wallet_action{nullptr};
156156
QMenu* m_open_wallet_menu{nullptr};
157157
QAction* m_close_wallet_action{nullptr};
158+
QAction* m_close_all_wallets_action{nullptr};
158159
QAction* m_wallet_selector_label_action = nullptr;
159160
QAction* m_wallet_selector_action = nullptr;
160161
QAction* m_mask_values_action{nullptr};

src/qt/walletcontroller.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
9292
removeAndDeleteWallet(wallet_model);
9393
}
9494

95+
void WalletController::closeAllWallets(QWidget* parent)
96+
{
97+
QMessageBox::StandardButton button = QMessageBox::question(parent, tr("Close all wallets"),
98+
tr("Are you sure you wish to close all wallets?"),
99+
QMessageBox::Yes|QMessageBox::Cancel,
100+
QMessageBox::Yes);
101+
if (button != QMessageBox::Yes) return;
102+
103+
QMutexLocker locker(&m_mutex);
104+
for (WalletModel* wallet_model : m_wallets) {
105+
wallet_model->wallet().remove();
106+
Q_EMIT walletRemoved(wallet_model);
107+
delete wallet_model;
108+
}
109+
m_wallets.clear();
110+
}
111+
95112
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)
96113
{
97114
QMutexLocker locker(&m_mutex);

src/qt/walletcontroller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class WalletController : public QObject
6262
std::map<std::string, bool> listWalletDir() const;
6363

6464
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
65+
void closeAllWallets(QWidget* parent = nullptr);
6566

6667
Q_SIGNALS:
6768
void walletAdded(WalletModel* wallet_model);

0 commit comments

Comments
 (0)