gui: Add OpenWalletActivity

This commit is contained in:
João Barbosa
2019-01-21 16:58:20 +00:00
parent 4c8982a88e
commit 8847cdaaae
4 changed files with 56 additions and 13 deletions

View File

@@ -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();
}