From bfd84c3437e555960b5d57dc66ff1d6a7a46762e Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 3 Mar 2016 17:17:31 +0100 Subject: [PATCH] PathChooser: Remove duplicate code Change-Id: Idfbe8e8f89dfe739b10c560a90f56fc519f6b474 Reviewed-by: Tim Jenssen --- src/libs/utils/pathchooser.cpp | 57 +++++++--------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index f591f605389..9246366b68e 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -542,6 +542,11 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); return false; } + if (!fi.isFile()) { + if (errorMessage) + *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(expandedPath)); + return false; + } break; case PathChooser::SaveFile: if (!fi.absoluteDir().exists()) { @@ -549,6 +554,11 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The directory \"%1\" does not exist.").arg(QDir::toNativeSeparators(fi.absolutePath())); return false; } + if (fi.exists() && fi.isDir()) { + if (errorMessage) + *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath())); + return false; + } break; case PathChooser::ExistingCommand: if (!fi.exists()) { @@ -556,9 +566,9 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const *errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); return false; } - if (!fi.isExecutable()) { + if (!fi.isFile() || !fi.isExecutable()) { if (errorMessage) - *errorMessage = tr("Cannot execute \"%1\".").arg(QDir::toNativeSeparators(expandedPath)); + *errorMessage = tr("The path %1 is not an executable file.").arg(QDir::toNativeSeparators(expandedPath)); return false; } break; @@ -581,49 +591,6 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const ; } - // Check expected kind - switch (d->m_acceptingKind) { - case PathChooser::ExistingDirectory: - if (!fi.isDir()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not a directory.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - break; - - case PathChooser::File: - if (!fi.isFile()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - break; - - case PathChooser::SaveFile: - if (fi.exists() && fi.isDir()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath())); - return false; - } - break; - - case PathChooser::ExistingCommand: - if (!fi.isFile() || !fi.isExecutable()) { - if (errorMessage) - *errorMessage = tr("The path %1 is not an executable file.").arg(QDir::toNativeSeparators(expandedPath)); - return false; - } - - case PathChooser::Command: - break; - - case PathChooser::Any: - break; - - default: - ; - } - if (errorMessage) *errorMessage = tr("Full path: %1").arg(QDir::toNativeSeparators(expandedPath)); return true;