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:
Jonathan White 2018-02-17 22:16:45 -05:00 committed by Janek Bevendorff
parent 397d804cdd
commit cd3e1fc27e
6 changed files with 51 additions and 24 deletions

View File

@ -776,21 +776,18 @@ void DatabaseWidget::switchToView(bool accepted)
m_newGroup->setParent(m_newParent);
m_groupView->setCurrentGroup(m_newGroup);
m_groupView->expandGroup(m_newParent);
}
else {
} else {
delete m_newGroup;
}
m_newGroup = nullptr;
m_newParent = nullptr;
}
else if (m_newEntry) {
} else if (m_newEntry) {
if (accepted) {
m_newEntry->setGroup(m_newParent);
m_entryView->setFocus();
m_entryView->setCurrentEntry(m_newEntry);
}
else {
} else {
delete m_newEntry;
}
@ -798,6 +795,10 @@ void DatabaseWidget::switchToView(bool accepted)
m_newParent = nullptr;
}
if (accepted) {
showMessage(tr("Entry updated successfully."), MessageWidget::Positive, false, 2000);
}
setCurrentWidget(m_mainWidget);
}

View File

@ -119,7 +119,8 @@ bool EditWidget::readOnly() const
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()

View File

@ -151,6 +151,11 @@ void PasswordGeneratorWidget::setStandaloneMode(bool standalone)
}
}
QString PasswordGeneratorWidget::getGeneratedPassword()
{
return m_ui->editNewPassword->text();
}
void PasswordGeneratorWidget::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape && m_standalone == true) {

View File

@ -49,16 +49,18 @@ public:
void saveSettings();
void reset();
void setStandaloneMode(bool standalone);
public Q_SLOTS:
QString getGeneratedPassword();
public slots:
void regeneratePassword();
void applyPassword();
void copyPassword();
signals:
void appliedPassword(const QString& password);
void dialogTerminated();
private slots:
void applyPassword();
void copyPassword();
void updateButtonsEnabled(const QString& password);
void updatePasswordStrength(const QString& password);
void togglePasswordShown(bool hidden);

View File

@ -98,7 +98,7 @@ EditEntryWidget::EditEntryWidget(QWidget* parent)
connect(this, SIGNAL(accepted()), SLOT(acceptEntry()));
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(messageEditEntryDismiss()), SLOT(hideMessage()));
@ -128,7 +128,7 @@ void EditEntryWidget::setupMain()
QAction *action = new QAction(this);
action->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(action, SIGNAL(triggered()), this, SLOT(saveEntry()));
connect(action, SIGNAL(triggered()), this, SLOT(commitEntry()));
this->addAction(action);
m_mainUi->passwordGenerator->hide();
@ -683,20 +683,39 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
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) {
clear();
hideMessage();
emit editFinished(false);
return;
return true;
}
if (!passwordsEqual()) {
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()) {
QString key = m_attributesModel->keyByIndex(m_advancedUi->attributesView->currentIndex());
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(),
@ -734,19 +753,18 @@ void EditEntryWidget::saveEntry()
updateSSHAgent();
}
#endif
showMessage(tr("Entry updated successfully."), MessageWidget::Positive);
return true;
}
void EditEntryWidget::acceptEntry()
{
// Check if passwords are mismatched first to prevent saving
if (!passwordsEqual()) {
showMessage(tr("Different passwords supplied."), MessageWidget::Error);
return;
if (commitEntry()) {
clear();
hideMessage();
emit editFinished(true);
}
saveEntry();
clear();
emit editFinished(true);
}
void EditEntryWidget::updateEntryData(Entry* entry) const

View File

@ -74,7 +74,7 @@ signals:
private slots:
void acceptEntry();
void saveEntry();
bool commitEntry();
void cancel();
void togglePasswordGeneratorButton(bool checked);
void setGeneratedPassword(const QString& password);