Utils: Allow remote paths in PathChooser

At least for the red marking of valid/invalid.

Change-Id: I91f856f93ba74f6b62a540322c2445691afbf170
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
hjk
2021-07-14 07:22:08 +02:00
parent 22121885fe
commit b84c8cf892

View File

@@ -529,69 +529,69 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const
*errorMessage = tr("The path \"%1\" expanded to an empty string.").arg(QDir::toNativeSeparators(path)); *errorMessage = tr("The path \"%1\" expanded to an empty string.").arg(QDir::toNativeSeparators(path));
return false; return false;
} }
const QFileInfo fi(expandedPath); const FilePath filePath = FilePath::fromString(expandedPath);
// Check if existing // Check if existing
switch (d->m_acceptingKind) { switch (d->m_acceptingKind) {
case PathChooser::ExistingDirectory: case PathChooser::ExistingDirectory:
if (!fi.exists()) { if (!filePath.exists()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput());
return false; return false;
} }
if (!fi.isDir()) { if (!filePath.isDir()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" is not a directory.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" is not a directory.").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
case PathChooser::File: case PathChooser::File:
if (!fi.exists()) { if (!filePath.exists()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput());
return false; return false;
} }
if (!fi.isFile()) { if (!filePath.isFile()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" is not a file.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" is not a file.").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
case PathChooser::SaveFile: case PathChooser::SaveFile:
if (!fi.absoluteDir().exists()) { if (!filePath.parentDir().exists()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The directory \"%1\" does not exist.").arg(QDir::toNativeSeparators(fi.absolutePath())); *errorMessage = tr("The directory \"%1\" does not exist.").arg(filePath.toUserOutput());
return false; return false;
} }
if (fi.exists() && fi.isDir()) { if (filePath.exists() && filePath.isDir()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath())); *errorMessage = tr("The path \"%1\" is not a file.").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
case PathChooser::ExistingCommand: case PathChooser::ExistingCommand:
if (!fi.exists()) { if (!filePath.exists()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput());
return false; return false;
} }
if (!fi.isFile() || !fi.isExecutable()) { if (!filePath.isExecutableFile()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" is not an executable file.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" is not an executable file.").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
case PathChooser::Directory: case PathChooser::Directory:
if (fi.exists() && !fi.isDir()) { if (filePath.isDir()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The path \"%1\" is not a directory.").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("The path \"%1\" is not a directory.").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
case PathChooser::Command: case PathChooser::Command:
if (fi.exists() && !fi.isExecutable()) { if (filePath.exists() && !filePath.isExecutableFile()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("Cannot execute \"%1\".").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("Cannot execute \"%1\".").arg(filePath.toUserOutput());
return false; return false;
} }
break; break;
@@ -601,7 +601,7 @@ bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const
} }
if (errorMessage) if (errorMessage)
*errorMessage = tr("Full path: \"%1\"").arg(QDir::toNativeSeparators(expandedPath)); *errorMessage = tr("Full path: \"%1\"").arg(filePath.toUserOutput());
return true; return true;
} }