Skip to content

Commit

Permalink
gui: Add openWallet and getWalletsAvailableToOpen to WalletController
Browse files Browse the repository at this point in the history
  • Loading branch information
promag committed Feb 4, 2019
1 parent ab288b4 commit 32a8c6a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/qt/walletcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <algorithm>

#include <QMessageBox>
#include <QMutexLocker>
#include <QThread>

Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/qt/walletcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class WalletController : public QObject
~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);
Expand Down

0 comments on commit 32a8c6a

Please sign in to comment.