Implement database closing question on escape

This commit is contained in:
Jan Schwietzer 2025-03-29 14:49:07 +01:00 committed by Jonathan White
parent dff5f3bc13
commit af2479da8d
3 changed files with 30 additions and 0 deletions

View file

@ -1708,6 +1708,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>
</context>
<context>
<name>DatabaseSettingWidgetMetaData</name>

View file

@ -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)
{

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;