Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.cpp
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <qt/askpassphrasedialog.h> | |||||
#include <qt/createwalletdialog.h> | |||||
#include <qt/guiconstants.h> | |||||
#include <qt/guiutil.h> | #include <qt/guiutil.h> | ||||
#include <qt/walletcontroller.h> | #include <qt/walletcontroller.h> | ||||
#include <wallet/wallet.h> | |||||
#include <interfaces/handler.h> | #include <interfaces/handler.h> | ||||
#include <interfaces/node.h> | #include <interfaces/node.h> | ||||
#include <QApplication> | #include <QApplication> | ||||
#include <QMutexLocker> | #include <QMutexLocker> | ||||
#include <QTimer> | #include <QTimer> | ||||
#include <QWindow> | #include <QWindow> | ||||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | void WalletControllerActivity::showProgressDialog(const QString &label_text) { | ||||
m_progress_dialog->setLabelText(label_text); | m_progress_dialog->setLabelText(label_text); | ||||
m_progress_dialog->setRange(0, 0); | m_progress_dialog->setRange(0, 0); | ||||
m_progress_dialog->setCancelButton(nullptr); | m_progress_dialog->setCancelButton(nullptr); | ||||
m_progress_dialog->setWindowModality(Qt::ApplicationModal); | m_progress_dialog->setWindowModality(Qt::ApplicationModal); | ||||
GUIUtil::PolishProgressDialog(m_progress_dialog); | GUIUtil::PolishProgressDialog(m_progress_dialog); | ||||
} | } | ||||
CreateWalletActivity::CreateWalletActivity(WalletController *wallet_controller, | |||||
QWidget *parent_widget, | |||||
const CChainParams &chainparams) | |||||
: WalletControllerActivity(wallet_controller, parent_widget, chainparams) { | |||||
m_passphrase.reserve(MAX_PASSPHRASE_SIZE); | |||||
} | |||||
CreateWalletActivity::~CreateWalletActivity() { | |||||
delete m_create_wallet_dialog; | |||||
delete m_passphrase_dialog; | |||||
} | |||||
void CreateWalletActivity::askPassphrase() { | |||||
m_passphrase_dialog = new AskPassphraseDialog( | |||||
AskPassphraseDialog::Encrypt, m_parent_widget, &m_passphrase); | |||||
m_passphrase_dialog->show(); | |||||
connect(m_passphrase_dialog, &QObject::destroyed, | |||||
[this] { m_passphrase_dialog = nullptr; }); | |||||
connect(m_passphrase_dialog, &QDialog::accepted, | |||||
[this] { createWallet(); }); | |||||
connect(m_passphrase_dialog, &QDialog::rejected, | |||||
[this] { Q_EMIT finished(); }); | |||||
} | |||||
void CreateWalletActivity::createWallet() { | |||||
showProgressDialog( | |||||
tr("Creating Wallet <b>%1</b>...") | |||||
.arg(m_create_wallet_dialog->walletName().toHtmlEscaped())); | |||||
std::string name = m_create_wallet_dialog->walletName().toStdString(); | |||||
uint64_t flags = 0; | |||||
if (m_create_wallet_dialog->disablePrivateKeys()) { | |||||
flags |= WALLET_FLAG_DISABLE_PRIVATE_KEYS; | |||||
} | |||||
if (m_create_wallet_dialog->blank()) { | |||||
flags |= WALLET_FLAG_BLANK_WALLET; | |||||
} | |||||
QTimer::singleShot(500, worker(), [this, name, flags] { | |||||
std::unique_ptr<interfaces::Wallet> wallet; | |||||
WalletCreationStatus status = | |||||
node().createWallet(this->m_chainparams, m_passphrase, flags, name, | |||||
m_error_message, m_warning_message, wallet); | |||||
if (status == WalletCreationStatus::SUCCESS) { | |||||
m_wallet_model = | |||||
m_wallet_controller->getOrCreateWallet(std::move(wallet)); | |||||
} | |||||
QTimer::singleShot(500, this, &CreateWalletActivity::finish); | |||||
}); | |||||
} | |||||
void CreateWalletActivity::finish() { | |||||
m_progress_dialog->hide(); | |||||
if (!m_error_message.empty()) { | |||||
QMessageBox::critical(m_parent_widget, tr("Create wallet failed"), | |||||
QString::fromStdString(m_error_message)); | |||||
} else if (!m_warning_message.empty()) { | |||||
QMessageBox::warning(m_parent_widget, tr("Create wallet warning"), | |||||
QString::fromStdString(m_warning_message)); | |||||
} | |||||
if (m_wallet_model) { | |||||
Q_EMIT created(m_wallet_model); | |||||
} | |||||
Q_EMIT finished(); | |||||
} | |||||
void CreateWalletActivity::create() { | |||||
m_create_wallet_dialog = new CreateWalletDialog(m_parent_widget); | |||||
m_create_wallet_dialog->setWindowModality(Qt::ApplicationModal); | |||||
m_create_wallet_dialog->show(); | |||||
connect(m_create_wallet_dialog, &QObject::destroyed, | |||||
[this] { m_create_wallet_dialog = nullptr; }); | |||||
connect(m_create_wallet_dialog, &QDialog::rejected, | |||||
[this] { Q_EMIT finished(); }); | |||||
connect(m_create_wallet_dialog, &QDialog::accepted, [this] { | |||||
if (m_create_wallet_dialog->encrypt()) { | |||||
askPassphrase(); | |||||
} else { | |||||
createWallet(); | |||||
} | |||||
}); | |||||
} | |||||
OpenWalletActivity::OpenWalletActivity(WalletController *wallet_controller, | OpenWalletActivity::OpenWalletActivity(WalletController *wallet_controller, | ||||
QWidget *parent_widget, | QWidget *parent_widget, | ||||
const CChainParams &chainparams) | const CChainParams &chainparams) | ||||
: WalletControllerActivity(wallet_controller, parent_widget, chainparams) {} | : WalletControllerActivity(wallet_controller, parent_widget, chainparams) {} | ||||
void OpenWalletActivity::finish() { | void OpenWalletActivity::finish() { | ||||
m_progress_dialog->hide(); | m_progress_dialog->hide(); | ||||
Show All 34 Lines |