Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/FileDialog.cpp')
-rw-r--r--src/gui/FileDialog.cpp61
1 files changed, 25 insertions, 36 deletions
diff --git a/src/gui/FileDialog.cpp b/src/gui/FileDialog.cpp
index 12f582775..df713c44b 100644
--- a/src/gui/FileDialog.cpp
+++ b/src/gui/FileDialog.cpp
@@ -21,6 +21,20 @@
#include <QDir>
+namespace
+{
+ QString modFilter(const QString& filter)
+ {
+#ifdef Q_OS_MACOS
+ // Fix macOS bug that causes the file dialog to freeze when a dot is included in the filters
+ // See https://github.com/keepassxreboot/keepassxc/issues/3895#issuecomment-586724167
+ auto mod = filter;
+ return mod.replace("*.", "*");
+#endif
+ return filter;
+ }
+} // namespace
+
FileDialog* FileDialog::m_instance(nullptr);
QString FileDialog::getOpenFileName(QWidget* parent,
@@ -35,9 +49,9 @@ QString FileDialog::getOpenFileName(QWidget* parent,
m_nextFileName.clear();
return result;
} else {
- const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
+ const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
const auto result = QDir::toNativeSeparators(
- QFileDialog::getOpenFileName(parent, caption, workingDir, filter, selectedFilter, options));
+ QFileDialog::getOpenFileName(parent, caption, workingDir, modFilter(filter), selectedFilter, options));
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog
@@ -62,11 +76,13 @@ QStringList FileDialog::getOpenFileNames(QWidget* parent,
m_nextFileNames.clear();
return results;
} else {
- const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
- auto results = QFileDialog::getOpenFileNames(parent, caption, workingDir, filter, selectedFilter, options);
+ const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
+ auto results =
+ QFileDialog::getOpenFileNames(parent, caption, workingDir, modFilter(filter), selectedFilter, options);
- for (auto& path : results)
+ for (auto& path : results) {
path = QDir::toNativeSeparators(path);
+ }
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog
@@ -81,33 +97,6 @@ QStringList FileDialog::getOpenFileNames(QWidget* parent,
}
}
-QString FileDialog::getFileName(QWidget* parent,
- const QString& caption,
- const QString& dir,
- const QString& filter,
- QString* selectedFilter,
- const QFileDialog::Options options)
-{
- if (!m_nextFileName.isEmpty()) {
- const QString result = m_nextFileName;
- m_nextFileName.clear();
- return result;
- } else {
- const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
- const auto result = QDir::toNativeSeparators(
- QFileDialog::getSaveFileName(parent, caption, workingDir, filter, selectedFilter, options));
-
-#ifdef Q_OS_MACOS
- // on Mac OS X the focus is lost after closing the native dialog
- if (parent) {
- parent->activateWindow();
- }
-#endif
- saveLastDir(result);
- return result;
- }
-}
-
QString FileDialog::getSaveFileName(QWidget* parent,
const QString& caption,
const QString& dir,
@@ -120,9 +109,9 @@ QString FileDialog::getSaveFileName(QWidget* parent,
m_nextFileName.clear();
return result;
} else {
- const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
+ const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
const auto result = QDir::toNativeSeparators(
- QFileDialog::getSaveFileName(parent, caption, workingDir, filter, selectedFilter, options));
+ QFileDialog::getSaveFileName(parent, caption, workingDir, modFilter(filter), selectedFilter, options));
#ifdef Q_OS_MACOS
// on Mac OS X the focus is lost after closing the native dialog
@@ -145,7 +134,7 @@ QString FileDialog::getExistingDirectory(QWidget* parent,
m_nextDirName.clear();
return result;
} else {
- const auto& workingDir = dir.isEmpty() ? config()->get("LastDir").toString() : dir;
+ const auto& workingDir = dir.isEmpty() ? config()->get(Config::LastDir).toString() : dir;
const auto result =
QDir::toNativeSeparators(QFileDialog::getExistingDirectory(parent, caption, workingDir, options));
@@ -187,7 +176,7 @@ FileDialog::FileDialog()
void FileDialog::saveLastDir(const QString& dir)
{
if (!dir.isEmpty() && !m_forgetLastDir) {
- config()->set("LastDir", QFileInfo(dir).absolutePath());
+ config()->set(Config::LastDir, QFileInfo(dir).absolutePath());
}
m_forgetLastDir = false;