diff options
Diffstat (limited to 'src/qt/walletcontroller.cpp')
-rw-r--r-- | src/qt/walletcontroller.cpp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index a103f4c89b..3483c75970 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -55,17 +55,12 @@ std::vector<std::string> WalletController::getWalletsAvailableToOpen() const return wallets; } -WalletModel* WalletController::openWallet(const std::string& name, QWidget* parent) +OpenWalletActivity* 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; + OpenWalletActivity* activity = new OpenWalletActivity(this, name); + activity->moveToThread(&m_activity_thread); + QMetaObject::invokeMethod(activity, "open", Qt::QueuedConnection); + return activity; } WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet) @@ -124,3 +119,24 @@ void WalletController::removeAndDeleteWallet(WalletModel* wallet_model) // CWallet shared pointer. delete wallet_model; } + + +OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, const std::string& name) + : m_wallet_controller(wallet_controller) + , m_name(name) +{} + +void OpenWalletActivity::open() +{ + std::string error, warning; + std::unique_ptr<interfaces::Wallet> wallet = m_wallet_controller->m_node.loadWallet(m_name, error, warning); + if (!warning.empty()) { + Q_EMIT message(QMessageBox::Warning, QString::fromStdString(warning)); + } + if (wallet) { + Q_EMIT opened(m_wallet_controller->getOrCreateWallet(std::move(wallet))); + } else { + Q_EMIT message(QMessageBox::Critical, QString::fromStdString(error)); + } + Q_EMIT finished(); +} |