From cd1e0571a5f9af260cdf4ab53353116c0ce1b445 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Thu, 16 Nov 2017 16:04:30 +0100 Subject: [PATCH 1/2] forget keyfile path, fix #1151 --- src/gui/DatabaseOpenWidget.cpp | 3 +++ src/gui/FileDialog.cpp | 18 +++++++++++++----- src/gui/FileDialog.h | 2 ++ src/gui/SettingsWidget.cpp | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) 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..ed86bd851 100644 --- a/src/gui/FileDialog.cpp +++ b/src/gui/FileDialog.cpp @@ -42,11 +42,11 @@ QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QSt if (parent) { parent->activateWindow(); } - - if (!result.isEmpty()) { + if (!result.isEmpty() && m_nextSaveLastDir) { config()->set("LastDir", QFileInfo(result).absolutePath()); } + m_nextSaveLastDir = true; return result; } } @@ -73,10 +73,11 @@ QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption parent->activateWindow(); } - if (!results.isEmpty()) { + if (!results.isEmpty() && m_nextSaveLastDir) { config()->set("LastDir", QFileInfo(results[0]).absolutePath()); } + m_nextSaveLastDir = true; return results; } } @@ -125,10 +126,11 @@ QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QSt parent->activateWindow(); } - if (!result.isEmpty()) { + if (!result.isEmpty() && m_nextSaveLastDir) { config()->set("LastDir", QFileInfo(result).absolutePath()); } + m_nextSaveLastDir = true; return result; } } @@ -153,10 +155,11 @@ QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption parent->activateWindow(); } - if (!dir.isEmpty()) { + if (!dir.isEmpty() && m_nextSaveLastDir) { config()->set("LastDir", QFileInfo(dir).absolutePath()); } + m_nextSaveLastDir = true; return dir; } } @@ -176,6 +179,11 @@ void FileDialog::setNextDirName(const QString &dirName) m_nextDirName = dirName; } +void FileDialog::setNextForgetDialog() +{ + m_nextSaveLastDir = false; +} + FileDialog::FileDialog() { } diff --git a/src/gui/FileDialog.h b/src/gui/FileDialog.h index 92b58a584..b4f032eaf 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,7 @@ private: QString m_nextFileName; QStringList m_nextFileNames; QString m_nextDirName; + bool m_nextSaveLastDir = true; 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)) { From 135e8419ae54c9cde3003776e5f7791e151a0bc4 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Wed, 22 Nov 2017 22:12:43 +0100 Subject: [PATCH 2/2] refactor saveLastDir code --- src/gui/FileDialog.cpp | 33 ++++++++++++++------------------- src/gui/FileDialog.h | 4 +++- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp index ed86bd851..9f3caf6da 100644 --- a/src/gui/FileDialog.cpp +++ b/src/gui/FileDialog.cpp @@ -42,11 +42,8 @@ QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QSt if (parent) { parent->activateWindow(); } - if (!result.isEmpty() && m_nextSaveLastDir) { - config()->set("LastDir", QFileInfo(result).absolutePath()); - } - m_nextSaveLastDir = true; + saveLastDir(result); return result; } } @@ -73,11 +70,9 @@ QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption parent->activateWindow(); } - if (!results.isEmpty() && m_nextSaveLastDir) { - config()->set("LastDir", QFileInfo(results[0]).absolutePath()); + if (!results.isEmpty()) { + saveLastDir(results[0]); } - - m_nextSaveLastDir = true; return results; } } @@ -126,11 +121,7 @@ QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QSt parent->activateWindow(); } - if (!result.isEmpty() && m_nextSaveLastDir) { - config()->set("LastDir", QFileInfo(result).absolutePath()); - } - - m_nextSaveLastDir = true; + saveLastDir(result); return result; } } @@ -155,11 +146,7 @@ QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption parent->activateWindow(); } - if (!dir.isEmpty() && m_nextSaveLastDir) { - config()->set("LastDir", QFileInfo(dir).absolutePath()); - } - - m_nextSaveLastDir = true; + saveLastDir(dir); return dir; } } @@ -181,13 +168,21 @@ void FileDialog::setNextDirName(const QString &dirName) void FileDialog::setNextForgetDialog() { - m_nextSaveLastDir = false; + 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 b4f032eaf..9a57a9218 100644 --- a/src/gui/FileDialog.h +++ b/src/gui/FileDialog.h @@ -52,7 +52,9 @@ private: QString m_nextFileName; QStringList m_nextFileNames; QString m_nextDirName; - bool m_nextSaveLastDir = true; + bool m_forgetLastDir = false; + + void saveLastDir(QString); static FileDialog* m_instance;