Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletcontroller.cpp
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | void WalletController::removeAndDeleteWallet(WalletModel *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; | ||||
} | } | ||||
WalletControllerActivity::WalletControllerActivity( | WalletControllerActivity::WalletControllerActivity( | ||||
WalletController *wallet_controller, QWidget *parent_widget, | WalletController *wallet_controller, QWidget *parent_widget) | ||||
const CChainParams &chainparams) | |||||
: QObject(wallet_controller), m_wallet_controller(wallet_controller), | : QObject(wallet_controller), m_wallet_controller(wallet_controller), | ||||
m_parent_widget(parent_widget), m_chainparams(chainparams) {} | m_parent_widget(parent_widget) {} | ||||
WalletControllerActivity::~WalletControllerActivity() { | WalletControllerActivity::~WalletControllerActivity() { | ||||
delete m_progress_dialog; | delete m_progress_dialog; | ||||
} | } | ||||
void WalletControllerActivity::showProgressDialog(const QString &label_text) { | void WalletControllerActivity::showProgressDialog(const QString &label_text) { | ||||
assert(!m_progress_dialog); | assert(!m_progress_dialog); | ||||
m_progress_dialog = new QProgressDialog(m_parent_widget); | m_progress_dialog = new QProgressDialog(m_parent_widget); | ||||
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); | ||||
} | } | ||||
void WalletControllerActivity::destroyProgressDialog() { | void WalletControllerActivity::destroyProgressDialog() { | ||||
assert(m_progress_dialog); | assert(m_progress_dialog); | ||||
delete m_progress_dialog; | delete m_progress_dialog; | ||||
m_progress_dialog = nullptr; | m_progress_dialog = nullptr; | ||||
} | } | ||||
CreateWalletActivity::CreateWalletActivity(WalletController *wallet_controller, | CreateWalletActivity::CreateWalletActivity(WalletController *wallet_controller, | ||||
QWidget *parent_widget, | QWidget *parent_widget) | ||||
const CChainParams &chainparams) | : WalletControllerActivity(wallet_controller, parent_widget) { | ||||
: WalletControllerActivity(wallet_controller, parent_widget, chainparams) { | |||||
m_passphrase.reserve(MAX_PASSPHRASE_SIZE); | m_passphrase.reserve(MAX_PASSPHRASE_SIZE); | ||||
} | } | ||||
CreateWalletActivity::~CreateWalletActivity() { | CreateWalletActivity::~CreateWalletActivity() { | ||||
delete m_create_wallet_dialog; | delete m_create_wallet_dialog; | ||||
delete m_passphrase_dialog; | delete m_passphrase_dialog; | ||||
} | } | ||||
Show All 26 Lines | void CreateWalletActivity::createWallet() { | ||||
} | } | ||||
if (m_create_wallet_dialog->isDescriptorWalletChecked()) { | if (m_create_wallet_dialog->isDescriptorWalletChecked()) { | ||||
flags |= WALLET_FLAG_DESCRIPTORS; | flags |= WALLET_FLAG_DESCRIPTORS; | ||||
} | } | ||||
QTimer::singleShot(500, worker(), [this, name, flags] { | QTimer::singleShot(500, worker(), [this, name, flags] { | ||||
WalletCreationStatus status; | WalletCreationStatus status; | ||||
std::unique_ptr<interfaces::Wallet> wallet = | std::unique_ptr<interfaces::Wallet> wallet = | ||||
node().walletClient().createWallet( | node().walletClient().createWallet(name, m_passphrase, flags, | ||||
m_chainparams, name, m_passphrase, flags, status, | status, m_error_message, | ||||
m_error_message, m_warning_message); | m_warning_message); | ||||
if (status == WalletCreationStatus::SUCCESS) { | if (status == WalletCreationStatus::SUCCESS) { | ||||
m_wallet_model = | m_wallet_model = | ||||
m_wallet_controller->getOrCreateWallet(std::move(wallet)); | m_wallet_controller->getOrCreateWallet(std::move(wallet)); | ||||
} | } | ||||
QTimer::singleShot(500, this, &CreateWalletActivity::finish); | QTimer::singleShot(500, this, &CreateWalletActivity::finish); | ||||
}); | }); | ||||
Show All 34 Lines | connect(m_create_wallet_dialog, &QDialog::accepted, [this] { | ||||
askPassphrase(); | askPassphrase(); | ||||
} else { | } else { | ||||
createWallet(); | createWallet(); | ||||
} | } | ||||
}); | }); | ||||
} | } | ||||
OpenWalletActivity::OpenWalletActivity(WalletController *wallet_controller, | OpenWalletActivity::OpenWalletActivity(WalletController *wallet_controller, | ||||
QWidget *parent_widget, | QWidget *parent_widget) | ||||
const CChainParams &chainparams) | : WalletControllerActivity(wallet_controller, parent_widget) {} | ||||
: WalletControllerActivity(wallet_controller, parent_widget, chainparams) {} | |||||
void OpenWalletActivity::finish() { | void OpenWalletActivity::finish() { | ||||
destroyProgressDialog(); | destroyProgressDialog(); | ||||
if (!m_error_message.empty()) { | if (!m_error_message.empty()) { | ||||
QMessageBox::critical( | QMessageBox::critical( | ||||
m_parent_widget, tr("Open wallet failed"), | m_parent_widget, tr("Open wallet failed"), | ||||
QString::fromStdString(m_error_message.translated)); | QString::fromStdString(m_error_message.translated)); | ||||
Show All 15 Lines | void OpenWalletActivity::open(const std::string &path) { | ||||
QString name = path.empty() ? QString("[" + tr("default wallet") + "]") | QString name = path.empty() ? QString("[" + tr("default wallet") + "]") | ||||
: QString::fromStdString(path); | : QString::fromStdString(path); | ||||
showProgressDialog( | showProgressDialog( | ||||
tr("Opening Wallet <b>%1</b>...").arg(name.toHtmlEscaped())); | tr("Opening Wallet <b>%1</b>...").arg(name.toHtmlEscaped())); | ||||
QTimer::singleShot(0, worker(), [this, path] { | QTimer::singleShot(0, worker(), [this, path] { | ||||
std::unique_ptr<interfaces::Wallet> wallet = | std::unique_ptr<interfaces::Wallet> wallet = | ||||
node().walletClient().loadWallet( | node().walletClient().loadWallet(path, m_error_message, | ||||
this->m_chainparams, path, m_error_message, m_warning_message); | m_warning_message); | ||||
if (wallet) { | if (wallet) { | ||||
m_wallet_model = | m_wallet_model = | ||||
m_wallet_controller->getOrCreateWallet(std::move(wallet)); | m_wallet_controller->getOrCreateWallet(std::move(wallet)); | ||||
} | } | ||||
QTimer::singleShot(0, this, &OpenWalletActivity::finish); | QTimer::singleShot(0, this, &OpenWalletActivity::finish); | ||||
}); | }); | ||||
} | } |