aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2019-07-08 16:27:18 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2019-07-08 16:32:01 +0200
commit2679bb8919b5089f8067ccfd94f766747b8df671 (patch)
tree74b8127eb93fc97e0f9ba790ecad42a206df8df6
parentb5fa2319d86343499ae0c49605d379a20038ca85 (diff)
parentfa90fe6440301edba71a6f0b1ba3ef1c78d5eae4 (diff)
downloadbitcoin-2679bb8919b5089f8067ccfd94f766747b8df671.tar.xz
Merge #16106: gui: Sort wallets in open wallet menu
fa90fe6440301edba71a6f0b1ba3ef1c78d5eae4 refactor: Rename getWallets to getOpenWallets in WalletController (João Barbosa) 224eb9534a8d2b0f140ecb0cc00c61af8ba1da4e gui: Sort wallets in open wallet menu (João Barbosa) Pull request description: Ensure wallets are sorted by name in the open wallet menu. This also improves the change done in #15957, since it avoids a second call to `listWalletDir`. ACKs for top commit: laanwj: code review ACK fa90fe6440301edba71a6f0b1ba3ef1c78d5eae4 Tree-SHA512: 349ea195021e56760dea3551126d1b9dc4821faab44aaf2858229db4fddaf0ce0b5eb0a8fa5025f47c77134b003067a77e8c340f9655a99e1305d430ccecced8
-rw-r--r--src/qt/bitcoingui.cpp11
-rw-r--r--src/qt/walletcontroller.cpp13
-rw-r--r--src/qt/walletcontroller.h10
3 files changed, 20 insertions, 14 deletions
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index babb2ce518..98c291aa63 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -371,13 +371,12 @@ void BitcoinGUI::createActions()
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
m_open_wallet_menu->clear();
- std::vector<std::string> available_wallets = m_wallet_controller->getWalletsAvailableToOpen();
- std::vector<std::string> wallets = m_node.listWalletDir();
- for (const auto& path : wallets) {
+ for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
+ const std::string& path = i.first;
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
QAction* action = m_open_wallet_menu->addAction(name);
- if (std::find(available_wallets.begin(), available_wallets.end(), path) == available_wallets.end()) {
+ if (i.second) {
// This wallet is already loaded
action->setEnabled(false);
continue;
@@ -410,7 +409,7 @@ void BitcoinGUI::createActions()
assert(invoked);
});
}
- if (wallets.empty()) {
+ if (m_open_wallet_menu->isEmpty()) {
QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
action->setEnabled(false);
}
@@ -640,7 +639,7 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
connect(wallet_controller, &WalletController::walletAdded, this, &BitcoinGUI::addWallet);
connect(wallet_controller, &WalletController::walletRemoved, this, &BitcoinGUI::removeWallet);
- for (WalletModel* wallet_model : m_wallet_controller->getWallets()) {
+ for (WalletModel* wallet_model : m_wallet_controller->getOpenWallets()) {
addWallet(wallet_model);
}
}
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp
index 019bd65823..4d489d7f44 100644
--- a/src/qt/walletcontroller.cpp
+++ b/src/qt/walletcontroller.cpp
@@ -40,19 +40,22 @@ WalletController::~WalletController()
m_activity_thread.wait();
}
-std::vector<WalletModel*> WalletController::getWallets() const
+std::vector<WalletModel*> WalletController::getOpenWallets() const
{
QMutexLocker locker(&m_mutex);
return m_wallets;
}
-std::vector<std::string> WalletController::getWalletsAvailableToOpen() const
+std::map<std::string, bool> WalletController::listWalletDir() const
{
QMutexLocker locker(&m_mutex);
- std::vector<std::string> wallets = m_node.listWalletDir();
+ std::map<std::string, bool> wallets;
+ for (const std::string& name : m_node.listWalletDir()) {
+ wallets[name] = false;
+ }
for (WalletModel* wallet_model : m_wallets) {
- auto it = std::remove(wallets.begin(), wallets.end(), wallet_model->wallet().getWalletName());
- if (it != wallets.end()) wallets.erase(it);
+ auto it = wallets.find(wallet_model->wallet().getWalletName());
+ if (it != wallets.end()) it->second = true;
}
return wallets;
}
diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h
index 19b3a82253..03039dd795 100644
--- a/src/qt/walletcontroller.h
+++ b/src/qt/walletcontroller.h
@@ -8,7 +8,7 @@
#include <qt/walletmodel.h>
#include <sync.h>
-#include <list>
+#include <map>
#include <memory>
#include <vector>
@@ -40,8 +40,12 @@ public:
WalletController(interfaces::Node& node, const PlatformStyle* platform_style, OptionsModel* options_model, QObject* parent);
~WalletController();
- std::vector<WalletModel*> getWallets() const;
- std::vector<std::string> getWalletsAvailableToOpen() const;
+ //! Returns wallet models currently open.
+ std::vector<WalletModel*> getOpenWallets() const;
+
+ //! Returns all wallet names in the wallet dir mapped to whether the wallet
+ //! is loaded.
+ std::map<std::string, bool> listWalletDir() const;
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);