From 8847cdaaaeb45c1ddee89f43ac4b8fafb20e5c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Barbosa?= Date: Mon, 21 Jan 2019 16:58:20 +0000 Subject: gui: Add OpenWalletActivity --- src/qt/walletcontroller.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/qt/walletcontroller.cpp') diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp index a103f4c89..3483c7597 100644 --- a/src/qt/walletcontroller.cpp +++ b/src/qt/walletcontroller.cpp @@ -55,17 +55,12 @@ std::vector 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 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 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(); +} -- cgit v1.2.3