From f6ceffb0d9c0a4b1cb6ecafa73a48898d131ec00 Mon Sep 17 00:00:00 2001
From: Tobias Hunger <tobias.hunger@nokia.com>
Date: Fri, 1 Apr 2011 11:46:10 +0200
Subject: [PATCH] PathChooser: Make error messages more informative

---
 src/libs/utils/pathchooser.cpp | 43 ++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp
index 9b28e2c36a0..b537af7d4ab 100644
--- a/src/libs/utils/pathchooser.cpp
+++ b/src/libs/utils/pathchooser.cpp
@@ -406,28 +406,67 @@ bool PathChooser::validatePath(const QString &path, QString *errorMessage)
 {
     QString expandedPath = m_d->expandedPath(path);
 
-    if (expandedPath.isEmpty()) {
+    if (path.isEmpty()) {
         if (errorMessage)
             *errorMessage = tr("The path must not be empty.");
         return false;
     }
 
+    if (expandedPath.isEmpty()) {
+        if (errorMessage)
+            *errorMessage = tr("The path '%1' expanded to an empty string.").arg(QDir::toNativeSeparators(path));
+        return false;
+    }
     const QFileInfo fi(expandedPath);
 
     // Check if existing
     switch (m_d->m_acceptingKind) {
     case PathChooser::ExistingDirectory: // fall through
+        if (!fi.exists()) {
+            if (errorMessage)
+                *errorMessage = tr("The path '%1' does not exist.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
+        if (!fi.isDir()) {
+            if (errorMessage)
+                *errorMessage = tr("The path '%1' is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
+        break;
     case PathChooser::File: // fall through
+        if (!fi.exists()) {
+            if (errorMessage)
+                *errorMessage = tr("The path '%1' does not exist.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
+        break;
     case PathChooser::ExistingCommand:
         if (!fi.exists()) {
             if (errorMessage)
                 *errorMessage = tr("The path '%1' does not exist.").arg(QDir::toNativeSeparators(expandedPath));
             return false;
         }
+        if (!fi.isExecutable()) {
+            if (errorMessage)
+                *errorMessage = tr("Can not execute '%1'.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
         break;
-
     case PathChooser::Directory:
+        if (fi.exists() && !fi.isDir()) {
+            if (errorMessage)
+                *errorMessage = tr("The path '%1' is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
+        break;
     case PathChooser::Command: // fall through
+        if (fi.exists() && !fi.isExecutable()) {
+            if (errorMessage)
+                *errorMessage = tr("Can not execute '%1'.").arg(QDir::toNativeSeparators(expandedPath));
+            return false;
+        }
+        break;
+
     default:
         ;
     }
-- 
GitLab