Implement database closing question on escape

This commit is contained in:
Jonathan White 2025-06-19 17:40:51 -04:00
parent 925af722f8
commit f8b7dc88a9
No known key found for this signature in database
GPG key ID: 440FC65F2E0C6E01
3 changed files with 30 additions and 0 deletions

View file

@ -1746,6 +1746,10 @@ Are you sure you want to continue with this file?.</source>
<source>Hardware keys found, but no slots are configured.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Press ESC again to close this database</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Windows Hello setup was canceled or failed. Quick unlock has not been enabled.</source>
<translation type="unfinished"></translation>

View file

@ -171,6 +171,29 @@ void DatabaseOpenWidget::toggleHardwareKeyComponent(bool state)
m_ui->useHardwareKeyCheckBox->setText(tr("Use hardware key"));
}
}
void DatabaseOpenWidget::closeDatabase()
{
int closeWarningInterval = 3000;
if (!m_triedToQuit && window() == getMainWindow()) {
m_triedToQuit = true;
m_ui->messageWidget->showMessage(
tr("Press ESC again to close this database"), MessageWidget::Warning, closeWarningInterval);
QTimer::singleShot(closeWarningInterval, this, [this]() { m_triedToQuit = false; });
return;
}
reject();
}
void DatabaseOpenWidget::keyPressEvent(QKeyEvent* event)
{
if (event->key() == Qt::Key_Escape) {
closeDatabase();
} else {
DialogyWidget::keyPressEvent(event);
}
}
bool DatabaseOpenWidget::event(QEvent* event)
{

View file

@ -66,6 +66,7 @@ signals:
protected:
bool event(QEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
QSharedPointer<CompositeKey> buildDatabaseKey();
void setUserInteractionLock(bool state);
@ -81,6 +82,7 @@ protected slots:
private slots:
bool browseKeyFile();
void toggleHardwareKeyComponent(bool state);
void closeDatabase();
void pollHardwareKey(bool manualTrigger = false, int delay = 0);
void hardwareKeyResponse(bool found);
@ -92,6 +94,7 @@ private:
bool m_manualHardwareKeyRefresh = false;
bool m_blockQuickUnlock = false;
bool m_unlockingDatabase = false;
bool m_triedToQuit = false;
QTimer m_hideTimer;
QTimer m_hideNoHardwareKeysFoundTimer;