diff --git a/src/gui/DatabaseOpenWidget.cpp b/src/gui/DatabaseOpenWidget.cpp index e487f97ca..451dc597a 100644 --- a/src/gui/DatabaseOpenWidget.cpp +++ b/src/gui/DatabaseOpenWidget.cpp @@ -277,6 +277,9 @@ void DatabaseOpenWidget::activateChallengeResponse() void DatabaseOpenWidget::browseKeyFile() { QString filters = QString("%1 (*);;%2 (*.key)").arg(tr("All files"), tr("Key files")); + if (!config()->get("RememberLastKeyFiles").toBool()) { + fileDialog()->setNextForgetDialog(); + } QString filename = fileDialog()->getOpenFileName(this, tr("Select key file"), QString(), filters); if (!filename.isEmpty()) { diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp index cf792e160..9f3caf6da 100644 --- a/src/gui/FileDialog.cpp +++ b/src/gui/FileDialog.cpp @@ -43,10 +43,7 @@ QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QSt parent->activateWindow(); } - if (!result.isEmpty()) { - config()->set("LastDir", QFileInfo(result).absolutePath()); - } - + saveLastDir(result); return result; } } @@ -74,9 +71,8 @@ QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption } if (!results.isEmpty()) { - config()->set("LastDir", QFileInfo(results[0]).absolutePath()); + saveLastDir(results[0]); } - return results; } } @@ -125,10 +121,7 @@ QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QSt parent->activateWindow(); } - if (!result.isEmpty()) { - config()->set("LastDir", QFileInfo(result).absolutePath()); - } - + saveLastDir(result); return result; } } @@ -153,10 +146,7 @@ QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption parent->activateWindow(); } - if (!dir.isEmpty()) { - config()->set("LastDir", QFileInfo(dir).absolutePath()); - } - + saveLastDir(dir); return dir; } } @@ -176,10 +166,23 @@ void FileDialog::setNextDirName(const QString &dirName) m_nextDirName = dirName; } +void FileDialog::setNextForgetDialog() +{ + m_forgetLastDir = true; +} + FileDialog::FileDialog() { } +void FileDialog::saveLastDir(QString dir) { + if (!dir.isEmpty() && !m_forgetLastDir) { + config()->set("LastDir", QFileInfo(dir).absolutePath()); + } + + m_forgetLastDir = false; +} + FileDialog* FileDialog::instance() { if (!m_instance) { diff --git a/src/gui/FileDialog.h b/src/gui/FileDialog.h index 92b58a584..9a57a9218 100644 --- a/src/gui/FileDialog.h +++ b/src/gui/FileDialog.h @@ -36,6 +36,7 @@ public: QString getExistingDirectory(QWidget* parent = nullptr, const QString& caption = QString(), QString dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly); + void setNextForgetDialog(); /** * Sets the result of the next get* method call. * Use only for testing. @@ -51,6 +52,9 @@ private: QString m_nextFileName; QStringList m_nextFileNames; QString m_nextDirName; + bool m_forgetLastDir = false; + + void saveLastDir(QString); static FileDialog* m_instance; diff --git a/src/gui/SettingsWidget.cpp b/src/gui/SettingsWidget.cpp index a8b0e9424..4ba81c6f7 100644 --- a/src/gui/SettingsWidget.cpp +++ b/src/gui/SettingsWidget.cpp @@ -241,6 +241,7 @@ void SettingsWidget::saveSettings() if (!config()->get("RememberLastKeyFiles").toBool()) { config()->set("LastKeyFiles", QVariant()); + config()->set("LastDir", ""); } for (const ExtraPage& page: asConst(m_extraPages)) {