Skip to content

Commit 224eb95

Browse files
committed
gui: Sort wallets in open wallet menu
1 parent b5fa231 commit 224eb95

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/qt/bitcoingui.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,12 @@ void BitcoinGUI::createActions()
371371
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
372372
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
373373
m_open_wallet_menu->clear();
374-
std::vector<std::string> available_wallets = m_wallet_controller->getWalletsAvailableToOpen();
375-
std::vector<std::string> wallets = m_node.listWalletDir();
376-
for (const auto& path : wallets) {
374+
for (const std::pair<const std::string, bool>& i : m_wallet_controller->listWalletDir()) {
375+
const std::string& path = i.first;
377376
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
378377
QAction* action = m_open_wallet_menu->addAction(name);
379378

380-
if (std::find(available_wallets.begin(), available_wallets.end(), path) == available_wallets.end()) {
379+
if (i.second) {
381380
// This wallet is already loaded
382381
action->setEnabled(false);
383382
continue;
@@ -410,7 +409,7 @@ void BitcoinGUI::createActions()
410409
assert(invoked);
411410
});
412411
}
413-
if (wallets.empty()) {
412+
if (m_open_wallet_menu->isEmpty()) {
414413
QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
415414
action->setEnabled(false);
416415
}

src/qt/walletcontroller.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ std::vector<WalletModel*> WalletController::getWallets() const
4646
return m_wallets;
4747
}
4848

49-
std::vector<std::string> WalletController::getWalletsAvailableToOpen() const
49+
std::map<std::string, bool> WalletController::listWalletDir() const
5050
{
5151
QMutexLocker locker(&m_mutex);
52-
std::vector<std::string> wallets = m_node.listWalletDir();
52+
std::map<std::string, bool> wallets;
53+
for (const std::string& name : m_node.listWalletDir()) {
54+
wallets[name] = false;
55+
}
5356
for (WalletModel* wallet_model : m_wallets) {
54-
auto it = std::remove(wallets.begin(), wallets.end(), wallet_model->wallet().getWalletName());
55-
if (it != wallets.end()) wallets.erase(it);
57+
auto it = wallets.find(wallet_model->wallet().getWalletName());
58+
if (it != wallets.end()) it->second = true;
5659
}
5760
return wallets;
5861
}

src/qt/walletcontroller.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <qt/walletmodel.h>
99
#include <sync.h>
1010

11-
#include <list>
11+
#include <map>
1212
#include <memory>
1313
#include <vector>
1414

@@ -41,7 +41,10 @@ class WalletController : public QObject
4141
~WalletController();
4242

4343
std::vector<WalletModel*> getWallets() const;
44-
std::vector<std::string> getWalletsAvailableToOpen() const;
44+
45+
//! Returns all wallet names in the wallet dir mapped to whether the wallet
46+
//! is loaded.
47+
std::map<std::string, bool> listWalletDir() const;
4548

4649
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
4750
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);

0 commit comments

Comments
 (0)