Ask before discarding generated password

This commit is contained in:
Jonathan White 2024-09-26 23:35:05 -04:00
parent 7498fe24dc
commit ee9ec0504b
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01
4 changed files with 38 additions and 7 deletions

View File

@ -6979,6 +6979,14 @@ Do you want to overwrite it?</source>
<source>Characters: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Confirm Discard</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you want to discard this password?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Excluded characters: &quot;0&quot;, &quot;1&quot;, &quot;l&quot;, &quot;I&quot;, &quot;O&quot;, &quot;|&quot;, &quot;&quot;, &quot;B&quot;, &quot;8&quot;, &quot;G&quot;, &quot;6&quot;</source>
<translation type="unfinished"></translation>

View File

@ -1973,7 +1973,11 @@ bool DatabaseWidget::lock()
auto parent = modalWidget->parentWidget();
while (parent) {
if (parent == this) {
// Preempt any popup questions
// TODO: Figure out a way to "reject" or "accept" instead of specific buttons
MessageBox::setNextAnswer(MessageBox::Discard);
modalWidget->close();
MessageBox::setNextAnswer(MessageBox::NoButton);
break;
}
parent = parent->parentWidget();

View File

@ -67,7 +67,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
connect(m_ui->buttonGenerate, SIGNAL(clicked()), SLOT(regeneratePassword()));
connect(m_ui->buttonDeleteWordList, SIGNAL(clicked()), SLOT(deleteWordList()));
connect(m_ui->buttonAddWordList, SIGNAL(clicked()), SLOT(addWordList()));
connect(m_ui->buttonClose, SIGNAL(clicked()), SIGNAL(closed()));
connect(m_ui->buttonClose, SIGNAL(clicked()), SLOT(confirmClose()));
connect(m_ui->sliderLength, SIGNAL(valueChanged(int)), SLOT(passwordLengthChanged(int)));
connect(m_ui->spinBoxLength, SIGNAL(valueChanged(int)), SLOT(passwordLengthChanged(int)));
@ -121,9 +121,25 @@ PasswordGeneratorWidget::~PasswordGeneratorWidget() = default;
void PasswordGeneratorWidget::closeEvent(QCloseEvent* event)
{
// Emits closed signal when clicking X from title bar
confirmClose();
event->ignore();
}
void PasswordGeneratorWidget::confirmClose()
{
// Only ask for discard confirmation if in popup mode
if (!m_standalone) {
auto result = MessageBox::question(this,
tr("Confirm Discard"),
tr("Do you want to discard this password?"),
MessageBox::Discard | MessageBox::Cancel,
MessageBox::Cancel);
if (result == MessageBox::Cancel) {
return;
}
}
emit closed();
QWidget::closeEvent(event);
}
PasswordGeneratorWidget* PasswordGeneratorWidget::popupGenerator(QWidget* parent)
@ -325,10 +341,12 @@ void PasswordGeneratorWidget::updatePasswordLengthLabel(const QString& password)
void PasswordGeneratorWidget::applyPassword()
{
saveSettings();
m_passwordGenerated = true;
emit appliedPassword(m_ui->editNewPassword->text());
emit closed();
if (!m_standalone) {
saveSettings();
m_passwordGenerated = true;
emit appliedPassword(m_ui->editNewPassword->text());
emit closed();
}
}
void PasswordGeneratorWidget::copyPassword()

View File

@ -69,6 +69,7 @@ public slots:
void setPasswordVisible(bool visible);
void deleteWordList();
void addWordList();
void confirmClose();
protected:
void closeEvent(QCloseEvent* event) override;