Utils: Make Utils::withTildeHomePath a FilePath member

Gets .osType() right in remote cases.

Change-Id: I6397996062d976d7db690c5729dd4faa1f459563
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2023-01-03 17:04:52 +01:00
parent 55fa109b59
commit ac9023e851
9 changed files with 51 additions and 50 deletions

View File

@@ -1720,6 +1720,28 @@ FilePath FilePath::cleanPath() const
return withNewPath(doCleanPath(path()));
}
/*!
On Linux/Mac replace user's home path with ~ in the \c toString()
result for this path after cleaning.
If path is not sub of home path, or when running on Windows, returns the input
*/
QString FilePath::withTildeHomePath() const
{
if (osType() == OsTypeWindows)
return toString();
if (needsDevice())
return toString();
static const QString homePath = QDir::homePath();
QString outPath = cleanPath().absoluteFilePath().path();
if (outPath.startsWith(homePath))
outPath = '~' + outPath.mid(homePath.size());
return outPath;
}
QTextStream &operator<<(QTextStream &s, const FilePath &fn)
{
return s << fn.toString();