From 806b8b0901790f024b0fb1ca1978bb2adbe05f5c Mon Sep 17 00:00:00 2001 From: SnipFoo <79416808+snipfoo@users.noreply.github.com> Date: Thu, 12 May 2022 12:19:20 +0200 Subject: [PATCH] Add config variable for specifying a default file name for the database --- src/core/Config.cpp | 1 + src/core/Config.h | 1 + src/gui/DatabaseWidget.cpp | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 98bbeeea0..3c20ff80d 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -81,6 +81,7 @@ static const QHash configStrings = { {Config::GlobalAutoTypeRetypeTime,{QS("GlobalAutoTypeRetypeTime"), Roaming, 15}}, {Config::FaviconDownloadTimeout,{QS("FaviconDownloadTimeout"), Roaming, 10}}, {Config::UpdateCheckMessageShown,{QS("UpdateCheckMessageShown"), Roaming, false}}, + {Config::DefaultDatabaseFileName,{QS("DefaultDatabaseFileName"), Roaming, {}}}, {Config::LastDatabases, {QS("LastDatabases"), Local, {}}}, {Config::LastKeyFiles, {QS("LastKeyFiles"), Local, {}}}, diff --git a/src/core/Config.h b/src/core/Config.h index be7a736f8..a48cb4c59 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -63,6 +63,7 @@ public: GlobalAutoTypeRetypeTime, FaviconDownloadTimeout, UpdateCheckMessageShown, + DefaultDatabaseFileName, LastDatabases, LastKeyFiles, diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 52fe1d7dd..481040909 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1980,8 +1980,10 @@ bool DatabaseWidget::saveAs() QString oldFilePath = m_db->filePath(); if (!QFileInfo::exists(oldFilePath)) { + QString defaultFileName = config()->get(Config::DefaultDatabaseFileName).toString(); oldFilePath = - QDir::toNativeSeparators(config()->get(Config::LastDir).toString() + "/" + tr("Passwords").append(".kdbx")); + QDir::toNativeSeparators(config()->get(Config::LastDir).toString() + "/" + + (defaultFileName.isEmpty() ? tr("Passwords").append(".kdbx") : defaultFileName)); } const QString newFilePath = fileDialog()->getSaveFileName( this, tr("Save database as"), oldFilePath, tr("KeePass 2 Database").append(" (*.kdbx)"), nullptr, nullptr); @@ -2068,8 +2070,10 @@ bool DatabaseWidget::saveBackup() while (true) { QString oldFilePath = m_db->filePath(); if (!QFileInfo::exists(oldFilePath)) { - oldFilePath = QDir::toNativeSeparators(config()->get(Config::LastDir).toString() + "/" - + tr("Passwords").append(".kdbx")); + QString defaultFileName = config()->get(Config::DefaultDatabaseFileName).toString(); + oldFilePath = QDir::toNativeSeparators( + config()->get(Config::LastDir).toString() + "/" + + (defaultFileName.isEmpty() ? tr("Passwords").append(".kdbx") : defaultFileName)); } const QString newFilePath = fileDialog()->getSaveFileName(this,