Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | for (WalletModel *wallet_model : m_wallets) { | ||||
wallet_model->wallet().getWalletName()); | wallet_model->wallet().getWalletName()); | ||||
if (it != wallets.end()) { | if (it != wallets.end()) { | ||||
wallets.erase(it); | wallets.erase(it); | ||||
} | } | ||||
} | } | ||||
return wallets; | return wallets; | ||||
} | } | ||||
WalletModel *WalletController::openWallet(const CChainParams ¶ms, | OpenWalletActivity *WalletController::openWallet(const CChainParams ¶ms, | ||||
const std::string &name, | const std::string &name, | ||||
QWidget *parent) { | QWidget *parent) { | ||||
std::string error, warning; | OpenWalletActivity *activity = new OpenWalletActivity(this, name, params); | ||||
WalletModel *wallet_model = | activity->moveToThread(&m_activity_thread); | ||||
getOrCreateWallet(m_node.loadWallet(params, name, error, warning)); | QMetaObject::invokeMethod(activity, "open", Qt::QueuedConnection); | ||||
if (wallet_model == nullptr) { | return activity; | ||||
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( | WalletModel *WalletController::getOrCreateWallet( | ||||
std::unique_ptr<interfaces::Wallet> wallet) { | std::unique_ptr<interfaces::Wallet> wallet) { | ||||
QMutexLocker locker(&m_mutex); | QMutexLocker locker(&m_mutex); | ||||
// Return model instance if exists. | // Return model instance if exists. | ||||
if (!m_wallets.empty()) { | if (!m_wallets.empty()) { | ||||
std::string name = wallet->getWalletName(); | std::string name = wallet->getWalletName(); | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | // Unregister wallet model. | ||||
m_wallets.erase( | m_wallets.erase( | ||||
std::remove(m_wallets.begin(), m_wallets.end(), wallet_model)); | std::remove(m_wallets.begin(), m_wallets.end(), wallet_model)); | ||||
} | } | ||||
Q_EMIT walletRemoved(wallet_model); | Q_EMIT walletRemoved(wallet_model); | ||||
// Currently this can trigger the unload since the model can hold the last | // Currently this can trigger the unload since the model can hold the last | ||||
// CWallet shared pointer. | // CWallet shared pointer. | ||||
delete wallet_model; | delete wallet_model; | ||||
} | } | ||||
OpenWalletActivity::OpenWalletActivity(WalletController *wallet_controller, | |||||
const std::string &name, | |||||
const CChainParams ¶ms) | |||||
: m_wallet_controller(wallet_controller), m_name(name), | |||||
m_chain_params(params) {} | |||||
void OpenWalletActivity::open() { | |||||
std::string error, warning; | |||||
std::unique_ptr<interfaces::Wallet> wallet = | |||||
m_wallet_controller->m_node.loadWallet(m_chain_params, 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(); | |||||
} |