Merge pull request #1188 from keepassxreboot/feature/forget-last-path

Forget keyfile path by honoring settings
This commit is contained in:
TheZ3ro 2017-11-23 23:35:23 +01:00 committed by GitHub
commit bff80dfc70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 14 deletions

View File

@ -277,6 +277,9 @@ void DatabaseOpenWidget::activateChallengeResponse()
void DatabaseOpenWidget::browseKeyFile() void DatabaseOpenWidget::browseKeyFile()
{ {
QString filters = QString("%1 (*);;%2 (*.key)").arg(tr("All files"), tr("Key files")); 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); QString filename = fileDialog()->getOpenFileName(this, tr("Select key file"), QString(), filters);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {

View File

@ -43,10 +43,7 @@ QString FileDialog::getOpenFileName(QWidget* parent, const QString& caption, QSt
parent->activateWindow(); parent->activateWindow();
} }
if (!result.isEmpty()) { saveLastDir(result);
config()->set("LastDir", QFileInfo(result).absolutePath());
}
return result; return result;
} }
} }
@ -74,9 +71,8 @@ QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption
} }
if (!results.isEmpty()) { if (!results.isEmpty()) {
config()->set("LastDir", QFileInfo(results[0]).absolutePath()); saveLastDir(results[0]);
} }
return results; return results;
} }
} }
@ -125,10 +121,7 @@ QString FileDialog::getSaveFileName(QWidget* parent, const QString& caption, QSt
parent->activateWindow(); parent->activateWindow();
} }
if (!result.isEmpty()) { saveLastDir(result);
config()->set("LastDir", QFileInfo(result).absolutePath());
}
return result; return result;
} }
} }
@ -153,10 +146,7 @@ QString FileDialog::getExistingDirectory(QWidget *parent, const QString &caption
parent->activateWindow(); parent->activateWindow();
} }
if (!dir.isEmpty()) { saveLastDir(dir);
config()->set("LastDir", QFileInfo(dir).absolutePath());
}
return dir; return dir;
} }
} }
@ -176,10 +166,23 @@ void FileDialog::setNextDirName(const QString &dirName)
m_nextDirName = dirName; m_nextDirName = dirName;
} }
void FileDialog::setNextForgetDialog()
{
m_forgetLastDir = true;
}
FileDialog::FileDialog() FileDialog::FileDialog()
{ {
} }
void FileDialog::saveLastDir(QString dir) {
if (!dir.isEmpty() && !m_forgetLastDir) {
config()->set("LastDir", QFileInfo(dir).absolutePath());
}
m_forgetLastDir = false;
}
FileDialog* FileDialog::instance() FileDialog* FileDialog::instance()
{ {
if (!m_instance) { if (!m_instance) {

View File

@ -36,6 +36,7 @@ public:
QString getExistingDirectory(QWidget* parent = nullptr, const QString& caption = QString(), QString getExistingDirectory(QWidget* parent = nullptr, const QString& caption = QString(),
QString dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly); QString dir = QString(), QFileDialog::Options options = QFileDialog::ShowDirsOnly);
void setNextForgetDialog();
/** /**
* Sets the result of the next get* method call. * Sets the result of the next get* method call.
* Use only for testing. * Use only for testing.
@ -51,6 +52,9 @@ private:
QString m_nextFileName; QString m_nextFileName;
QStringList m_nextFileNames; QStringList m_nextFileNames;
QString m_nextDirName; QString m_nextDirName;
bool m_forgetLastDir = false;
void saveLastDir(QString);
static FileDialog* m_instance; static FileDialog* m_instance;

View File

@ -241,6 +241,7 @@ void SettingsWidget::saveSettings()
if (!config()->get("RememberLastKeyFiles").toBool()) { if (!config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastKeyFiles", QVariant()); config()->set("LastKeyFiles", QVariant());
config()->set("LastDir", "");
} }
for (const ExtraPage& page: asConst(m_extraPages)) { for (const ExtraPage& page: asConst(m_extraPages)) {