mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Ask to apply generated password when commiting an entry edit
* Rename saveEntry to commitEntry to accurately capture its purpose * Add message to user when commit is successful * Made all inline messages in edit entry view 2 sec visibility
This commit is contained in:
parent
397d804cdd
commit
cd3e1fc27e
@ -776,21 +776,18 @@ void DatabaseWidget::switchToView(bool accepted)
|
|||||||
m_newGroup->setParent(m_newParent);
|
m_newGroup->setParent(m_newParent);
|
||||||
m_groupView->setCurrentGroup(m_newGroup);
|
m_groupView->setCurrentGroup(m_newGroup);
|
||||||
m_groupView->expandGroup(m_newParent);
|
m_groupView->expandGroup(m_newParent);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
delete m_newGroup;
|
delete m_newGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_newGroup = nullptr;
|
m_newGroup = nullptr;
|
||||||
m_newParent = nullptr;
|
m_newParent = nullptr;
|
||||||
}
|
} else if (m_newEntry) {
|
||||||
else if (m_newEntry) {
|
|
||||||
if (accepted) {
|
if (accepted) {
|
||||||
m_newEntry->setGroup(m_newParent);
|
m_newEntry->setGroup(m_newParent);
|
||||||
m_entryView->setFocus();
|
m_entryView->setFocus();
|
||||||
m_entryView->setCurrentEntry(m_newEntry);
|
m_entryView->setCurrentEntry(m_newEntry);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
delete m_newEntry;
|
delete m_newEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,6 +795,10 @@ void DatabaseWidget::switchToView(bool accepted)
|
|||||||
m_newParent = nullptr;
|
m_newParent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (accepted) {
|
||||||
|
showMessage(tr("Entry updated successfully."), MessageWidget::Positive, false, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
setCurrentWidget(m_mainWidget);
|
setCurrentWidget(m_mainWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,8 @@ bool EditWidget::readOnly() const
|
|||||||
|
|
||||||
void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
|
void EditWidget::showMessage(const QString& text, MessageWidget::MessageType type)
|
||||||
{
|
{
|
||||||
m_ui->messageWidget->showMessage(text, type);
|
m_ui->messageWidget->setCloseButtonVisible(false);
|
||||||
|
m_ui->messageWidget->showMessage(text, type, 2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditWidget::hideMessage()
|
void EditWidget::hideMessage()
|
||||||
|
@ -151,6 +151,11 @@ void PasswordGeneratorWidget::setStandaloneMode(bool standalone)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString PasswordGeneratorWidget::getGeneratedPassword()
|
||||||
|
{
|
||||||
|
return m_ui->editNewPassword->text();
|
||||||
|
}
|
||||||
|
|
||||||
void PasswordGeneratorWidget::keyPressEvent(QKeyEvent* e)
|
void PasswordGeneratorWidget::keyPressEvent(QKeyEvent* e)
|
||||||
{
|
{
|
||||||
if (e->key() == Qt::Key_Escape && m_standalone == true) {
|
if (e->key() == Qt::Key_Escape && m_standalone == true) {
|
||||||
|
@ -49,16 +49,18 @@ public:
|
|||||||
void saveSettings();
|
void saveSettings();
|
||||||
void reset();
|
void reset();
|
||||||
void setStandaloneMode(bool standalone);
|
void setStandaloneMode(bool standalone);
|
||||||
public Q_SLOTS:
|
QString getGeneratedPassword();
|
||||||
|
|
||||||
|
public slots:
|
||||||
void regeneratePassword();
|
void regeneratePassword();
|
||||||
|
void applyPassword();
|
||||||
|
void copyPassword();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void appliedPassword(const QString& password);
|
void appliedPassword(const QString& password);
|
||||||
void dialogTerminated();
|
void dialogTerminated();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void applyPassword();
|
|
||||||
void copyPassword();
|
|
||||||
void updateButtonsEnabled(const QString& password);
|
void updateButtonsEnabled(const QString& password);
|
||||||
void updatePasswordStrength(const QString& password);
|
void updatePasswordStrength(const QString& password);
|
||||||
void togglePasswordShown(bool hidden);
|
void togglePasswordShown(bool hidden);
|
||||||
|
@ -98,7 +98,7 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
|
|||||||
|
|
||||||
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
|
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
|
||||||
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
||||||
connect(this, SIGNAL(apply()), SLOT(saveEntry()));
|
connect(this, SIGNAL(apply()), SLOT(commitEntry()));
|
||||||
connect(m_iconsWidget, SIGNAL(messageEditEntry(QString, MessageWidget::MessageType)), SLOT(showMessage(QString, MessageWidget::MessageType)));
|
connect(m_iconsWidget, SIGNAL(messageEditEntry(QString, MessageWidget::MessageType)), SLOT(showMessage(QString, MessageWidget::MessageType)));
|
||||||
connect(m_iconsWidget, SIGNAL(messageEditEntryDismiss()), SLOT(hideMessage()));
|
connect(m_iconsWidget, SIGNAL(messageEditEntryDismiss()), SLOT(hideMessage()));
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ void EditEntryWidget::setupMain()
|
|||||||
|
|
||||||
QAction *action = new QAction(this);
|
QAction *action = new QAction(this);
|
||||||
action->setShortcut(Qt::CTRL | Qt::Key_Return);
|
action->setShortcut(Qt::CTRL | Qt::Key_Return);
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(saveEntry()));
|
connect(action, SIGNAL(triggered()), this, SLOT(commitEntry()));
|
||||||
this->addAction(action);
|
this->addAction(action);
|
||||||
|
|
||||||
m_mainUi->passwordGenerator->hide();
|
m_mainUi->passwordGenerator->hide();
|
||||||
@ -683,20 +683,39 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
|
|||||||
m_mainUi->titleEdit->setFocus();
|
m_mainUi->titleEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditEntryWidget::saveEntry()
|
/**
|
||||||
|
* Commit the form values to in-memory database representation
|
||||||
|
*
|
||||||
|
* @return true is commit successful, otherwise false
|
||||||
|
*/
|
||||||
|
bool EditEntryWidget::commitEntry()
|
||||||
{
|
{
|
||||||
if (m_history) {
|
if (m_history) {
|
||||||
clear();
|
clear();
|
||||||
hideMessage();
|
hideMessage();
|
||||||
emit editFinished(false);
|
emit editFinished(false);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!passwordsEqual()) {
|
if (!passwordsEqual()) {
|
||||||
showMessage(tr("Different passwords supplied."), MessageWidget::Error);
|
showMessage(tr("Different passwords supplied."), MessageWidget::Error);
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ask the user to apply the generator password, if open
|
||||||
|
if (m_mainUi->togglePasswordGeneratorButton->isChecked() &&
|
||||||
|
m_mainUi->passwordGenerator->getGeneratedPassword() != m_mainUi->passwordEdit->text()) {
|
||||||
|
auto answer = MessageBox::question(this, tr("Apply generated password?"),
|
||||||
|
tr("Do you want to apply the generated password to this entry?"),
|
||||||
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||||
|
if (answer == QMessageBox::Yes) {
|
||||||
|
m_mainUi->passwordGenerator->applyPassword();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide the password generator
|
||||||
|
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
|
||||||
|
|
||||||
if (m_advancedUi->attributesView->currentIndex().isValid() && m_advancedUi->attributesEdit->isEnabled()) {
|
if (m_advancedUi->attributesView->currentIndex().isValid() && m_advancedUi->attributesEdit->isEnabled()) {
|
||||||
QString key = m_attributesModel->keyByIndex(m_advancedUi->attributesView->currentIndex());
|
QString key = m_attributesModel->keyByIndex(m_advancedUi->attributesView->currentIndex());
|
||||||
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(),
|
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(),
|
||||||
@ -734,20 +753,19 @@ void EditEntryWidget::saveEntry()
|
|||||||
updateSSHAgent();
|
updateSSHAgent();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
showMessage(tr("Entry updated successfully."), MessageWidget::Positive);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditEntryWidget::acceptEntry()
|
void EditEntryWidget::acceptEntry()
|
||||||
{
|
{
|
||||||
// Check if passwords are mismatched first to prevent saving
|
if (commitEntry()) {
|
||||||
if (!passwordsEqual()) {
|
|
||||||
showMessage(tr("Different passwords supplied."), MessageWidget::Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
saveEntry();
|
|
||||||
clear();
|
clear();
|
||||||
|
hideMessage();
|
||||||
emit editFinished(true);
|
emit editFinished(true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EditEntryWidget::updateEntryData(Entry* entry) const
|
void EditEntryWidget::updateEntryData(Entry* entry) const
|
||||||
{
|
{
|
||||||
|
@ -74,7 +74,7 @@ signals:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void acceptEntry();
|
void acceptEntry();
|
||||||
void saveEntry();
|
bool commitEntry();
|
||||||
void cancel();
|
void cancel();
|
||||||
void togglePasswordGeneratorButton(bool checked);
|
void togglePasswordGeneratorButton(bool checked);
|
||||||
void setGeneratedPassword(const QString& password);
|
void setGeneratedPassword(const QString& password);
|
||||||
|
Loading…
Reference in New Issue
Block a user