forked from qt-creator/qt-creator
Utils: add home FilePath convenience function
Change-Id: I5d0d695dc127090be4323fac6ff4ef2b1729cb92 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -291,7 +291,7 @@ bool FilePath::isEmpty() const
|
|||||||
QString FilePath::shortNativePath() const
|
QString FilePath::shortNativePath() const
|
||||||
{
|
{
|
||||||
if (HostOsInfo::isAnyUnixHost()) {
|
if (HostOsInfo::isAnyUnixHost()) {
|
||||||
const FilePath home = FilePath::fromString(QDir::cleanPath(QDir::homePath()));
|
const FilePath home = FileUtils::homePath();
|
||||||
if (isChildOf(home)) {
|
if (isChildOf(home)) {
|
||||||
return QLatin1Char('~') + QDir::separator()
|
return QLatin1Char('~') + QDir::separator()
|
||||||
+ QDir::toNativeSeparators(relativeChildPath(home).toString());
|
+ QDir::toNativeSeparators(relativeChildPath(home).toString());
|
||||||
@@ -468,6 +468,11 @@ QByteArray FileUtils::fileId(const FilePath &fileName)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath FileUtils::homePath()
|
||||||
|
{
|
||||||
|
return FilePath::fromString(QDir::cleanPath(QDir::homePath()));
|
||||||
|
}
|
||||||
|
|
||||||
QByteArray FileReader::fetchQrc(const QString &fileName)
|
QByteArray FileReader::fetchQrc(const QString &fileName)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(fileName.startsWith(':'), return QByteArray());
|
QTC_ASSERT(fileName.startsWith(':'), return QByteArray());
|
||||||
@@ -1048,7 +1053,7 @@ FilePath FilePath::fromUserInput(const QString &filePath)
|
|||||||
{
|
{
|
||||||
QString clean = QDir::fromNativeSeparators(filePath);
|
QString clean = QDir::fromNativeSeparators(filePath);
|
||||||
if (clean.startsWith(QLatin1String("~/")))
|
if (clean.startsWith(QLatin1String("~/")))
|
||||||
clean = QDir::homePath() + clean.mid(1);
|
return FileUtils::homePath().pathAppended(clean.mid(2));
|
||||||
return FilePath::fromString(clean);
|
return FilePath::fromString(clean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -238,6 +238,7 @@ public:
|
|||||||
static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); }
|
static bool isAbsolutePath(const QString &fileName) { return !isRelativePath(fileName); }
|
||||||
static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName);
|
static FilePath commonPath(const FilePath &oldCommonPath, const FilePath &fileName);
|
||||||
static QByteArray fileId(const FilePath &fileName);
|
static QByteArray fileId(const FilePath &fileName);
|
||||||
|
static FilePath homePath();
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
Reference in New Issue
Block a user