diff --git a/src/appcontext.cpp b/src/appcontext.cpp index f8ce281..6e0c323 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -282,6 +282,10 @@ void AppContext::onOpenWallet(const QString &path, const QString &password){ return; } + if (password.isEmpty()) { + this->walletPassword = ""; + } + config()->set(Config::firstRun, false); this->walletPath = path; @@ -316,7 +320,7 @@ void AppContext::onWalletOpened(Wallet *wallet) { emit walletOpenedError(errMsg); } else { this->walletClose(false); - emit walletOpenPasswordNeeded(this->walletPassword.isEmpty(), wallet->path()); + emit walletOpenPasswordNeeded(!this->walletPassword.isEmpty(), wallet->path()); } return; } diff --git a/src/dialog/passworddialog.cpp b/src/dialog/passworddialog.cpp new file mode 100644 index 0000000..c736708 --- /dev/null +++ b/src/dialog/passworddialog.cpp @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2020, The Monero Project. + +#include "passworddialog.h" +#include "ui_passworddialog.h" + +PasswordDialog::PasswordDialog(QWidget *parent, const QString &walletName, bool incorrectPassword) + : QDialog(parent) + , ui(new Ui::PasswordDialog) +{ + ui->setupUi(this); + + ui->label_wallet->setText(QString("Please enter password for wallet: %1").arg(walletName)); + ui->label_incorrectPassword->setVisible(incorrectPassword); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, [this]{ + password = ui->line_password->text(); + }); + + this->adjustSize(); +} + +PasswordDialog::~PasswordDialog() +{ + delete ui; +} diff --git a/src/dialog/passworddialog.h b/src/dialog/passworddialog.h new file mode 100644 index 0000000..092830c --- /dev/null +++ b/src/dialog/passworddialog.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: BSD-3-Clause +// Copyright (c) 2020, The Monero Project. + +#ifndef FEATHER_PASSWORDDIALOG_H +#define FEATHER_PASSWORDDIALOG_H + +#include + +namespace Ui { + class PasswordDialog; +} + +class PasswordDialog : public QDialog +{ +Q_OBJECT + +public: + explicit PasswordDialog(QWidget *parent, const QString &walletName, bool incorrectPassword); + ~PasswordDialog() override; + + QString password = ""; + +private: + Ui::PasswordDialog *ui; +}; + +#endif //FEATHER_PASSWORDDIALOG_H diff --git a/src/dialog/passworddialog.ui b/src/dialog/passworddialog.ui new file mode 100644 index 0000000..1ef82e5 --- /dev/null +++ b/src/dialog/passworddialog.ui @@ -0,0 +1,85 @@ + + + PasswordDialog + + + + 0 + 0 + 832 + 158 + + + + Password required + + + + + + Please enter password for wallet: + + + + + + + <html><head/><body><p><span style=" font-weight:600; color:#a40000;">Incorrect password, try again.</span></p></body></html> + + + + + + + QLineEdit::Password + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PasswordDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PasswordDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5037b02..49f91cd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -20,6 +20,7 @@ #include "dialog/viewonlydialog.h" #include "dialog/broadcasttxdialog.h" #include "dialog/tximportdialog.h" +#include "dialog/passworddialog.h" #include "utils/utils.h" #include "utils/config.h" #include "utils/daemonrpc.h" @@ -589,18 +590,20 @@ void MainWindow::onWalletCreatedError(const QString &err) { void MainWindow::onWalletOpenPasswordRequired(bool invalidPassword, const QString &path) { QFileInfo fileInfo(path); - QInputDialog passwordDialog(this); - passwordDialog.setInputMode(QInputDialog::TextInput); - passwordDialog.setTextEchoMode(QLineEdit::Password); - passwordDialog.setWindowTitle("Password required"); - passwordDialog.setLabelText(QString("Please enter %1 wallet password.").arg(fileInfo.fileName())); - passwordDialog.resize(300, 100); - if(!(bool)passwordDialog.exec()) - return this->showWizard(WalletWizard::Page_OpenWallet); - - const auto passwd = passwordDialog.textValue(); - m_ctx->walletPassword = passwd; + + auto dialog = new PasswordDialog(this, fileInfo.fileName(), invalidPassword); + switch (dialog->exec()) { + case QDialog::Rejected: + { + this->showWizard(WalletWizard::Page_OpenWallet); + return; + } + } + + m_ctx->walletPassword = dialog->password; m_ctx->onOpenWallet(m_ctx->walletPath, m_ctx->walletPassword); + + dialog->deleteLater(); } void MainWindow::onWalletOpenedError(const QString &err) {