diff --git a/src/utils/file-selection.cpp b/src/utils/file-selection.cpp index 9cacd1b1..9bc39c71 100644 --- a/src/utils/file-selection.cpp +++ b/src/utils/file-selection.cpp @@ -29,17 +29,19 @@ void FileSelection::SetPath(const QString &path) _filePath->setText(path); } +QString FileSelection::ValidPathOrDesktop(const QString &path) +{ + if (std::filesystem::exists( + std::filesystem::path(path.toStdString()))) { + return path; + } + return QStandardPaths::writableLocation( + QStandardPaths::DesktopLocation); +} + void FileSelection::BrowseButtonClicked() { - QString defaultPath; - if (std::filesystem::exists( - std::filesystem::path(_filePath->text().toStdString()))) { - defaultPath = _filePath->text(); - } else { - defaultPath = QStandardPaths::writableLocation( - QStandardPaths::DesktopLocation); - } - + QString defaultPath = ValidPathOrDesktop(_filePath->text()); QString path; if (_type == FileSelection::Type::WRITE) { path = QFileDialog::getSaveFileName(this, "", defaultPath); diff --git a/src/utils/file-selection.hpp b/src/utils/file-selection.hpp index 18255a8e..ba45b95e 100644 --- a/src/utils/file-selection.hpp +++ b/src/utils/file-selection.hpp @@ -17,6 +17,7 @@ public: QWidget *parent = 0); void SetPath(const QString &); QPushButton *Button() { return _browseButton; } + static QString ValidPathOrDesktop(const QString &path); private slots: void BrowseButtonClicked();