From 0d7f357294c89fd71d7404350c736f008bb36b8d Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 17 Aug 2021 14:09:59 +0200 Subject: [PATCH] Utils: Use more FilePath in PathChooser Change-Id: I0a59cb7b8c613a5533e02ad29088f58de02ff578 Reviewed-by: Artem Sokolovskii Reviewed-by: Christian Stenger --- src/libs/utils/pathchooser.cpp | 48 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 8ff224cf9ff..f62b7049c5b 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -70,14 +70,13 @@ namespace Utils { -static QString appBundleExpandedPath(const QString &path) +static FilePath appBundleExpandedPath(const FilePath &path) { - if (HostOsInfo::hostOs() == OsTypeMac && path.endsWith(".app")) { + if (path.osType() == OsTypeMac && path.endsWith(".app")) { // possibly expand to Foo.app/Contents/MacOS/Foo - QFileInfo info(path); - if (info.isDir()) { - QString exePath = path + "/Contents/MacOS/" + info.completeBaseName(); - if (QFileInfo::exists(exePath)) + if (path.isDir()) { + const FilePath exePath = path / "Contents/MacOS" / path.completeBaseName(); + if (exePath.exists()) return exePath; } } @@ -168,8 +167,7 @@ public: BinaryVersionToolTipEventFilter(pe->lineEdit()), m_pathChooser(pe) {} private: - QString defaultToolTip() const override - { return m_pathChooser->errorMessage(); } + QString defaultToolTip() const override { return m_pathChooser->errorMessage(); } const PathChooser *m_pathChooser = nullptr; }; @@ -415,30 +413,27 @@ void PathChooser::slotBrowse() } // Prompt for a file/dir - QString newPath; + FilePath newPath; switch (d->m_acceptingKind) { case PathChooser::Directory: case PathChooser::ExistingDirectory: - newPath = QFileDialog::getExistingDirectory(this, - makeDialogTitle(tr("Choose Directory")), predefined.toUserOutput()); + newPath = FileUtils::getExistingDirectory(this, + makeDialogTitle(tr("Choose Directory")), predefined); break; case PathChooser::ExistingCommand: case PathChooser::Command: - newPath = QFileDialog::getOpenFileName(this, - makeDialogTitle(tr("Choose Executable")), predefined.toUserOutput(), - d->m_dialogFilter); + newPath = FileUtils::getOpenFilePath(this, + makeDialogTitle(tr("Choose Executable")), predefined, d->m_dialogFilter); newPath = appBundleExpandedPath(newPath); break; case PathChooser::File: // fall through - newPath = QFileDialog::getOpenFileName(this, - makeDialogTitle(tr("Choose File")), predefined.toUserOutput(), - d->m_dialogFilter); + newPath = FileUtils::getOpenFilePath(this, + makeDialogTitle(tr("Choose File")), predefined, d->m_dialogFilter); newPath = appBundleExpandedPath(newPath); break; case PathChooser::SaveFile: - newPath = QFileDialog::getSaveFileName(this, - makeDialogTitle(tr("Choose File")), predefined.toUserOutput(), - d->m_dialogFilter); + newPath = FileUtils::getSaveFilePath(this, + makeDialogTitle(tr("Choose File")), predefined, d->m_dialogFilter); break; case PathChooser::Any: { QFileDialog dialog(this); @@ -452,7 +447,7 @@ void PathChooser::slotBrowse() // probably loop here until the *.framework dir match QStringList paths = dialog.selectedFiles(); if (!paths.isEmpty()) - newPath = paths.at(0); + newPath = FilePath::fromString(paths.at(0)); } break; } @@ -465,13 +460,12 @@ void PathChooser::slotBrowse() window()->raise(); window()->activateWindow(); - // Delete trailing slashes unless it is "/"|"\\", only - if (!newPath.isEmpty()) { - newPath = QDir::toNativeSeparators(newPath); - if (newPath.size() > 1 && newPath.endsWith(QDir::separator())) - newPath.truncate(newPath.size() - 1); - setPath(newPath); + // Delete trailing slashes unless it is "/" only. + if (newPath.endsWith("/") && newPath.path().size() > 1) { + newPath = newPath.withNewPath(newPath.path().chopped(1)); + setFilePath(newPath); } + emit browsingFinished(); triggerChanged(); }