diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h --- a/src/qt/walletcontroller.h +++ b/src/qt/walletcontroller.h @@ -38,6 +38,10 @@ ~WalletController(); std::vector getWallets() const; + std::vector getWalletsAvailableToOpen() const; + + WalletModel *openWallet(const CChainParams ¶ms, const std::string &name, + QWidget *parent = nullptr); private Q_SLOTS: void addWallet(WalletModel *wallet_model); diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -38,6 +39,35 @@ return m_wallets; } +std::vector WalletController::getWalletsAvailableToOpen() const { + QMutexLocker locker(&m_mutex); + std::vector 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 CChainParams ¶ms, + const std::string &name, + QWidget *parent) { + std::string error, warning; + WalletModel *wallet_model = + getOrCreateWallet(m_node.loadWallet(params, name, error, warning)); + if (wallet_model == nullptr) { + 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 wallet) { QMutexLocker locker(&m_mutex);