diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-01-12 11:34:05 +0000 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2019-02-04 12:20:42 +0000 |
commit | 32a8c6abfe32d5b89bf4505ca8397bdb44867614 (patch) | |
tree | f425a320c391dc8677d540bf590a6073ee09b1e3 /src/qt | |
parent | ab288b4e59c52905343a1de628735b5c871d79a1 (diff) |
gui: Add openWallet and getWalletsAvailableToOpen to WalletController
Diffstat (limited to 'src/qt')
-rw-r--r-- | src/qt/walletcontroller.cpp | 25 | ||||
-rw-r--r-- | src/qt/walletcontroller.h | 3 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index df2b7a3f9b..0730afca98 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -9,6 +9,7 @@ #include <algorithm> +#include <QMessageBox> #include <QMutexLocker> #include <QThread> @@ -37,6 +38,30 @@ std::vector<WalletModel*> WalletController::getWallets() const return m_wallets; } +std::vector<std::string> WalletController::getWalletsAvailableToOpen() const +{ + QMutexLocker locker(&m_mutex); + std::vector<std::string> wallets = m_node.listWalletDir(); + 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); + } + return wallets; +} + +WalletModel* WalletController::openWallet(const std::string& name, QWidget* parent) +{ + std::string error, warning; + WalletModel* wallet_model = getOrCreateWallet(m_node.loadWallet(name, error, warning)); + if (!wallet_model) { + QMessageBox::warning(parent, tr("Open Wallet"), QString::fromStdString(error)); + } + if (!warning.empty()) { + QMessageBox::information(parent, tr("Open Wallet"), QString::fromStdString(warning)); + } + return wallet_model; +} + WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet) { QMutexLocker locker(&m_mutex); diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h index 22b71b07ff..523e47d27a 100644 --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -37,6 +37,9 @@ public: ~WalletController(); std::vector<WalletModel*> getWallets() const; + std::vector<std::string> getWalletsAvailableToOpen() const; + + WalletModel* openWallet(const std::string& name, QWidget* parent = nullptr); private Q_SLOTS: void addWallet(WalletModel* wallet_model); |