diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts
index 81895f9ea..183837fae 100644
--- a/share/translations/keepassxc_en.ts
+++ b/share/translations/keepassxc_en.ts
@@ -1708,6 +1708,10 @@ Are you sure you want to continue with this file?.
Hardware keys found, but no slots are configured.
+
+ Press ESC again to close this database
+
+
DatabaseSettingWidgetMetaData
diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp
index 1a84a7185..7cf5dcb15 100644
--- a/src/gui/DatabaseOpenWidget.cpp
+++ b/src/gui/DatabaseOpenWidget.cpp
@@ -159,6 +159,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)
{
diff --git a/src/gui/DatabaseOpenWidget.h b/src/gui/DatabaseOpenWidget.h
index 7c52717a0..d730634b3 100644
--- a/src/gui/DatabaseOpenWidget.h
+++ b/src/gui/DatabaseOpenWidget.h
@@ -66,6 +66,7 @@ signals:
protected:
bool event(QEvent* event) override;
+ void keyPressEvent(QKeyEvent* event) override;
QSharedPointer 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;