forked from qt-creator/qt-creator
PathChooser: Remove duplicate code
Change-Id: Idfbe8e8f89dfe739b10c560a90f56fc519f6b474 Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
@@ -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 <b>%1</b> 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 <b>%1</b> 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 <b>%1</b> 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 <b>%1</b> is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case PathChooser::File:
|
||||
if (!fi.isFile()) {
|
||||
if (errorMessage)
|
||||
*errorMessage = tr("The path <b>%1</b> 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 <b>%1</b> 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 <b>%1</b> 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: <b>%1</b>").arg(QDir::toNativeSeparators(expandedPath));
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user