Skip to content

Commit

Permalink
Ask to apply generated password when commiting an entry edit
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
droidmonkey authored and phoerious committed Feb 21, 2018
1 parent 397d804 commit cd3e1fc
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
13 changes: 7 additions & 6 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,28 +776,29 @@ 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;
}

m_newEntry = nullptr;
m_newParent = nullptr;
}

if (accepted) {
showMessage(tr("Entry updated successfully."), MessageWidget::Positive, false, 2000);
}

setCurrentWidget(m_mainWidget);
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/EditWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions src/gui/PasswordGeneratorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ class PasswordGeneratorWidget : public QWidget
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);
Expand Down
44 changes: 31 additions & 13 deletions src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gui/entry/EditEntryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class EditEntryWidget : public EditWidget

private slots:
void acceptEntry();
void saveEntry();
bool commitEntry();
void cancel();
void togglePasswordGeneratorButton(bool checked);
void setGeneratedPassword(const QString& password);
Expand Down

0 comments on commit cd3e1fc

Please sign in to comment.