Skip to content

Commit b7456e6

Browse files
committed
Merge #15195: gui: Add Close Wallet action
94086fb gui: Add close wallet action (João Barbosa) f77ba34 gui: Add closeWallet to WalletController (João Barbosa) f6122ab interfaces: Add remove to Wallet (João Barbosa) Pull request description: This PR adds support to close the current wallet in the GUI. <img width="543" alt="screenshot 2019-01-18 at 00 44 26" src="https://user-images.githubusercontent.com/3534524/51358241-424b9680-1aba-11e9-88f2-b85869507737.png"> <img width="532" alt="screenshot 2019-01-18 at 00 44 38" src="https://user-images.githubusercontent.com/3534524/51358242-424b9680-1aba-11e9-83e2-fa275a9017b3.png"> Tree-SHA512: fd7da4d0f73dc240864cc57a1ff1526daf2376904ce3872e52eeca5d40cc21c6dd29eb2ef25f85ffa63697362c150221a2369d80ad36ae445cc99989d337b688
2 parents 3b33cbc + 94086fb commit b7456e6

File tree

6 files changed

+33
-0
lines changed

6 files changed

+33
-0
lines changed

src/interfaces/wallet.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ class WalletImpl : public Wallet
468468
bool IsWalletFlagSet(uint64_t flag) override { return m_wallet.IsWalletFlagSet(flag); }
469469
OutputType getDefaultAddressType() override { return m_wallet.m_default_address_type; }
470470
OutputType getDefaultChangeType() override { return m_wallet.m_default_change_type; }
471+
void remove() override
472+
{
473+
RemoveWallet(m_shared_wallet);
474+
}
471475
std::unique_ptr<Handler> handleUnload(UnloadFn fn) override
472476
{
473477
return MakeHandler(m_wallet.NotifyUnload.connect(fn));

src/interfaces/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ class Wallet
247247
// Get default change type.
248248
virtual OutputType getDefaultChangeType() = 0;
249249

250+
// Remove wallet.
251+
virtual void remove() = 0;
252+
250253
//! Register handler for unload message.
251254
using UnloadFn = std::function<void()>;
252255
virtual std::unique_ptr<Handler> handleUnload(UnloadFn fn) = 0;

src/qt/bitcoingui.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ void BitcoinGUI::createActions()
338338
m_open_wallet_action->setMenu(new QMenu(this));
339339
m_open_wallet_action->setStatusTip(tr("Open a wallet"));
340340

341+
m_close_wallet_action = new QAction(tr("Close Wallet..."), this);
342+
m_close_wallet_action->setStatusTip(tr("Close wallet"));
343+
341344
showHelpMessageAction = new QAction(platformStyle->TextColorIcon(":/icons/info"), tr("&Command-line options"), this);
342345
showHelpMessageAction->setMenuRole(QAction::NoRole);
343346
showHelpMessageAction->setStatusTip(tr("Show the %1 help message to get a list with possible Bitcoin command-line options").arg(tr(PACKAGE_NAME)));
@@ -396,6 +399,9 @@ void BitcoinGUI::createActions()
396399
});
397400
}
398401
});
402+
connect(m_close_wallet_action, &QAction::triggered, [this] {
403+
m_wallet_controller->closeWallet(walletFrame->currentWalletModel(), this);
404+
});
399405
}
400406
#endif // ENABLE_WALLET
401407

@@ -418,6 +424,7 @@ void BitcoinGUI::createMenuBar()
418424
if(walletFrame)
419425
{
420426
file->addAction(m_open_wallet_action);
427+
file->addAction(m_close_wallet_action);
421428
file->addSeparator();
422429
file->addAction(openAction);
423430
file->addAction(backupWalletAction);
@@ -693,6 +700,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled)
693700
usedSendingAddressesAction->setEnabled(enabled);
694701
usedReceivingAddressesAction->setEnabled(enabled);
695702
openAction->setEnabled(enabled);
703+
m_close_wallet_action->setEnabled(enabled);
696704
}
697705

698706
void BitcoinGUI::createTrayIcon()

src/qt/bitcoingui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class BitcoinGUI : public QMainWindow
148148
QAction* openAction = nullptr;
149149
QAction* showHelpMessageAction = nullptr;
150150
QAction* m_open_wallet_action{nullptr};
151+
QAction* m_close_wallet_action{nullptr};
151152
QAction* m_wallet_selector_label_action = nullptr;
152153
QAction* m_wallet_selector_action = nullptr;
153154

src/qt/walletcontroller.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ OpenWalletActivity* WalletController::openWallet(const std::string& name, QWidge
6363
return activity;
6464
}
6565

66+
void WalletController::closeWallet(WalletModel* wallet_model, QWidget* parent)
67+
{
68+
QMessageBox box(parent);
69+
box.setWindowTitle(tr("Close wallet"));
70+
box.setText(tr("Are you sure you wish to close wallet <i>%1</i>?").arg(wallet_model->getDisplayName()));
71+
box.setInformativeText(tr("Closing the wallet for too long can result in having to resync the entire chain if pruning is enabled."));
72+
box.setStandardButtons(QMessageBox::Yes|QMessageBox::Cancel);
73+
box.setDefaultButton(QMessageBox::Yes);
74+
if (box.exec() != QMessageBox::Yes) return;
75+
76+
// First remove wallet from node.
77+
wallet_model->wallet().remove();
78+
// Now release the model.
79+
removeAndDeleteWallet(wallet_model);
80+
}
81+
6682
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)
6783
{
6884
QMutexLocker locker(&m_mutex);

src/qt/walletcontroller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class WalletController : public QObject
4444
std::vector<std::string> getWalletsAvailableToOpen() const;
4545

4646
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
47+
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
4748

4849
private Q_SLOTS:
4950
void addWallet(WalletModel* wallet_model);

0 commit comments

Comments
 (0)