diff --git a/CMakeLists.txt b/CMakeLists.txt index e9fe4f2..abb160f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ if(DEBUG) set(CMAKE_VERBOSE_MAKEFILE ON) endif() -set(MONERO_HEAD "d029a63fb75c581fa060447b41d385c595144774") +set(MONERO_HEAD "2390030d10b69c357165f82aaf417391a9e11019") set(BUILD_GUI_DEPS ON) set(ARCH "x86-64") set(BUILD_64 ON) diff --git a/monero b/monero index d029a63..2390030 160000 --- a/monero +++ b/monero @@ -1 +1 @@ -Subproject commit d029a63fb75c581fa060447b41d385c595144774 +Subproject commit 2390030d10b69c357165f82aaf417391a9e11019 diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 8622d7a..aac53df 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -610,7 +610,7 @@ void AppContext::onSetRestoreHeight(unsigned int height){ } this->currentWallet->setWalletCreationHeight(height); - this->currentWallet->setPassword(this->walletPassword); // trigger .keys write + this->currentWallet->setPassword(this->currentWallet->getPassword()); // trigger .keys write // nuke wallet cache const auto fn = this->currentWallet->path(); diff --git a/src/dialog/passwordchangedialog.cpp b/src/dialog/passwordchangedialog.cpp index 175d86e..1f199c1 100644 --- a/src/dialog/passwordchangedialog.cpp +++ b/src/dialog/passwordchangedialog.cpp @@ -5,17 +5,39 @@ #include "ui_passwordchangedialog.h" #include +#include -PasswordChangeDialog::PasswordChangeDialog(QWidget *parent) +PasswordChangeDialog::PasswordChangeDialog(QWidget *parent, Wallet *wallet) : QDialog(parent) , ui(new Ui::PasswordChangeDialog) + , m_wallet(wallet) { ui->setupUi(this); - ui->icon->setPixmap(QPixmap(":/assets/images/lock.png").scaledToWidth(32, Qt::SmoothTransformation)); + + bool noPassword = wallet->getPassword().isEmpty(); + + QString warning_str = noPassword ? "Your wallet is not password protected. Use this dialog to add a password to your wallet." : + "Your wallet is password protected and encrypted. Use this dialog to change your password."; + ui->label_warning->setText(warning_str); + + QPixmap pixmap = noPassword ? QPixmap(":/assets/images/unlock.png") : QPixmap(":/assets/images/lock.png"); + ui->icon->setPixmap(pixmap.scaledToWidth(32, Qt::SmoothTransformation)); + + if (noPassword) { + ui->label_currentPassword->hide(); + ui->lineEdit_currentPassword->hide(); + } connect(ui->lineEdit_newPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch); connect(ui->lineEdit_confirmPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch); + connect(ui->btn_Cancel, &QPushButton::clicked, [this]{ + this->reject(); + }); + connect(ui->btn_OK, &QPushButton::clicked, this, &PasswordChangeDialog::setPassword); + + ui->label_match->setVisible(false); + this->adjustSize(); } @@ -24,15 +46,28 @@ PasswordChangeDialog::~PasswordChangeDialog() delete ui; } -QString PasswordChangeDialog::getCurrentPassword() { - return ui->lineEdit_currentPassword->text(); +void PasswordChangeDialog::passwordsMatch() { + bool match = ui->lineEdit_newPassword->text() == ui->lineEdit_confirmPassword->text(); + ui->btn_OK->setEnabled(match); + ui->label_match->setHidden(match); } -QString PasswordChangeDialog::getNewPassword() { - return ui->lineEdit_newPassword->text(); -} +void PasswordChangeDialog::setPassword() { + QString currentPassword = ui->lineEdit_currentPassword->text(); + QString newPassword = ui->lineEdit_newPassword->text(); -void PasswordChangeDialog::passwordsMatch() { - bool match = ui->lineEdit_newPassword->text() == ui->lineEdit_confirmPassword->text(); - ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(match); + if (currentPassword != m_wallet->getPassword()) { + QMessageBox::warning(this, "Error", "Incorrect password"); + ui->lineEdit_currentPassword->setText(""); + ui->lineEdit_currentPassword->setFocus(); + return; + } + + if (m_wallet->setPassword(newPassword)) { + QMessageBox::information(this, "Information", "Password changed successfully"); + this->accept(); + } + else { + QMessageBox::warning(this, "Error", QString("Error: %1").arg(m_wallet->errorString())); + } } \ No newline at end of file diff --git a/src/dialog/passwordchangedialog.h b/src/dialog/passwordchangedialog.h index 64cc7ce..3a3cb1e 100644 --- a/src/dialog/passwordchangedialog.h +++ b/src/dialog/passwordchangedialog.h @@ -5,6 +5,7 @@ #define FEATHER_PASSWORDCHANGEDIALOG_H #include +#include "libwalletqt/Wallet.h" namespace Ui { class PasswordChangeDialog; @@ -15,16 +16,15 @@ class PasswordChangeDialog : public QDialog Q_OBJECT public: - explicit PasswordChangeDialog(QWidget *parent = nullptr); + explicit PasswordChangeDialog(QWidget *parent, Wallet *wallet); ~PasswordChangeDialog() override; - QString getCurrentPassword(); - QString getNewPassword(); - private: Ui::PasswordChangeDialog *ui; + Wallet *m_wallet; void passwordsMatch(); + void setPassword(); }; #endif //FEATHER_PASSWORDCHANGEDIALOG_H diff --git a/src/dialog/passwordchangedialog.ui b/src/dialog/passwordchangedialog.ui index 88db6af..730bd55 100644 --- a/src/dialog/passwordchangedialog.ui +++ b/src/dialog/passwordchangedialog.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 237 + 556 + 309 @@ -30,7 +30,7 @@ - + Your wallet is password protected and encrypted. Use this dialog to change your password. @@ -41,6 +41,22 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 10 + + + + @@ -65,7 +81,7 @@ - + Current Password: @@ -88,14 +104,45 @@ - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + false + + + Passwords do not match + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + OK + + + + @@ -105,38 +152,5 @@ lineEdit_confirmPassword - - - buttonBox - accepted() - PasswordChangeDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - PasswordChangeDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index 3d46aad..77fea34 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -179,6 +179,11 @@ bool Wallet::setPassword(const QString &password) return m_walletImpl->setPassword(password.toStdString()); } +QString Wallet::getPassword() +{ + return QString::fromStdString(m_walletImpl->getPassword()); +} + QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const { return QString::fromStdString(m_walletImpl->address(accountIndex, addressIndex)); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 52f5039..a9c88ad 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -134,6 +134,9 @@ public: //! changes the password using existing parameters (path, seed, seed lang) Q_INVOKABLE bool setPassword(const QString &password); + //! get current wallet password + Q_INVOKABLE QString getPassword(); + //! returns wallet's public address Q_INVOKABLE QString address(quint32 accountIndex, quint32 addressIndex) const; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3dc52b4..fcc6041 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -670,6 +670,7 @@ void MainWindow::onWalletOpened() { }); this->touchbarShowWallet(); + this->updatePasswordIcon(); } void MainWindow::onBalanceUpdated(double balance, double unlocked, const QString &balance_str, const QString &unlocked_str) { @@ -896,28 +897,15 @@ void MainWindow::showConnectionStatusDialog() { } void MainWindow::showPasswordDialog() { - auto *pdialog = new PasswordChangeDialog(this); - int ret = pdialog->exec(); - if (!ret) return; - - QApplication::setActiveWindow(this); - - QString currentPassword = pdialog->getCurrentPassword(); - QString newPassword = pdialog->getNewPassword(); - - if (currentPassword != m_ctx->walletPassword) { - QMessageBox::warning(this, "Error", "Incorrect password"); - return; - } - - if (m_ctx->currentWallet->setPassword(newPassword)) { - QMessageBox::information(this, "Information", "Password changed successfully"); - } - else { - QMessageBox::warning(this, "Error", QString("Error: %1").arg(m_ctx->currentWallet->errorString())); - } - + auto *pdialog = new PasswordChangeDialog(this, m_ctx->currentWallet); + pdialog->exec(); pdialog->deleteLater(); + this->updatePasswordIcon(); +} + +void MainWindow::updatePasswordIcon() { + QIcon icon = m_ctx->currentWallet->getPassword().isEmpty() ? QIcon(":/assets/images/unlock.svg") : QIcon(":/assets/images/lock.svg"); + m_statusBtnPassword->setIcon(icon); } void MainWindow::showRestoreHeightDialog() { diff --git a/src/mainwindow.h b/src/mainwindow.h index 774d588..7a2ae36 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -162,6 +162,7 @@ private: void createUnsignedTxDialog(UnsignedTransaction *tx); void touchbarShowWizard(); void touchbarShowWallet(); + void updatePasswordIcon(); WalletWizard *createWizard(WalletWizard::Page startPage);