mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-18 03:20:24 +01:00
gui: Add OpenWalletActivity
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user