mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge pull request #4546 from PastaPastaPasta/backport-oct-25
Backport 15462, 15957, 16118, 16231, 16106
This commit is contained in:
commit
876badbf2e
@ -428,8 +428,9 @@ void BitcoinGUI::createActions()
|
||||
openAction->setStatusTip(tr("Open a dash: URI or payment request"));
|
||||
|
||||
m_open_wallet_action = new QAction(tr("Open Wallet"), this);
|
||||
m_open_wallet_action->setMenu(new QMenu(this));
|
||||
m_open_wallet_action->setEnabled(false);
|
||||
m_open_wallet_action->setStatusTip(tr("Open a wallet"));
|
||||
m_open_wallet_menu = new QMenu(this);
|
||||
|
||||
m_close_wallet_action = new QAction(tr("Close Wallet..."), this);
|
||||
m_close_wallet_action->setStatusTip(tr("Close wallet"));
|
||||
@ -482,11 +483,19 @@ void BitcoinGUI::createActions()
|
||||
connect(usedSendingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedSendingAddresses);
|
||||
connect(usedReceivingAddressesAction, &QAction::triggered, walletFrame, &WalletFrame::usedReceivingAddresses);
|
||||
connect(openAction, &QAction::triggered, this, &BitcoinGUI::openClicked);
|
||||
connect(m_open_wallet_action->menu(), &QMenu::aboutToShow, [this] {
|
||||
m_open_wallet_action->menu()->clear();
|
||||
for (std::string path : m_wallet_controller->getWalletsAvailableToOpen()) {
|
||||
connect(m_open_wallet_menu, &QMenu::aboutToShow, [this] {
|
||||
m_open_wallet_menu->clear();
|
||||
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_action->menu()->addAction(name);
|
||||
QAction* action = m_open_wallet_menu->addAction(name);
|
||||
|
||||
if (i.second) {
|
||||
// This wallet is already loaded
|
||||
action->setEnabled(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
connect(action, &QAction::triggered, [this, name, path] {
|
||||
OpenWalletActivity* activity = m_wallet_controller->openWallet(path);
|
||||
|
||||
@ -510,8 +519,14 @@ void BitcoinGUI::createActions()
|
||||
connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet);
|
||||
connect(activity, &OpenWalletActivity::finished, activity, &QObject::deleteLater);
|
||||
connect(activity, &OpenWalletActivity::finished, dialog, &QObject::deleteLater);
|
||||
bool invoked = QMetaObject::invokeMethod(activity, "open");
|
||||
assert(invoked);
|
||||
});
|
||||
}
|
||||
if (m_open_wallet_menu->isEmpty()) {
|
||||
QAction* action = m_open_wallet_menu->addAction(tr("No wallets available"));
|
||||
action->setEnabled(false);
|
||||
}
|
||||
});
|
||||
connect(m_close_wallet_action, &QAction::triggered, [this] {
|
||||
m_wallet_controller->closeWallet(walletFrame->currentWalletModel(), this);
|
||||
@ -841,10 +856,13 @@ void BitcoinGUI::setWalletController(WalletController* wallet_controller)
|
||||
|
||||
m_wallet_controller = wallet_controller;
|
||||
|
||||
m_open_wallet_action->setEnabled(true);
|
||||
m_open_wallet_action->setMenu(m_open_wallet_menu);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ private:
|
||||
QAction* openAction = nullptr;
|
||||
QAction* showHelpMessageAction = nullptr;
|
||||
QAction* m_open_wallet_action{nullptr};
|
||||
QMenu* m_open_wallet_menu{nullptr};
|
||||
QAction* m_close_wallet_action{nullptr};
|
||||
QAction* showCoinJoinHelpAction = nullptr;
|
||||
QAction* m_wallet_selector_action = nullptr;
|
||||
|
@ -39,19 +39,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;
|
||||
}
|
||||
@ -60,7 +63,6 @@ OpenWalletActivity* WalletController::openWallet(const std::string& name, QWidge
|
||||
{
|
||||
OpenWalletActivity* activity = new OpenWalletActivity(this, name);
|
||||
activity->moveToThread(&m_activity_thread);
|
||||
QMetaObject::invokeMethod(activity, "open", Qt::QueuedConnection);
|
||||
return activity;
|
||||
}
|
||||
|
||||
|
@ -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, 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);
|
||||
|
Loading…
Reference in New Issue
Block a user