From 5c637e9171975a86ec1a3982579cd6f371b1d5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Wed, 8 Feb 2012 11:28:30 +0100 Subject: Add QFileInfo::isNativePath This function returns true if the file path can be used directly with native APIs, modulo encoding and path separator conversions. This is important for applications that interface with other libraries or simply need to use native APIs together with Qt. Traditionally, this information was available in QAbstractFileEngine and forced users to explicitly create an engine or use internal API such as QFile::fileEngine to access the underlying engine and this piece of information. Given its usefulness, exposing the information in a more visible place is more appropriate. This reduces the need for people to know or care about implementation details, like file engines... The existing isLocalFs test was updated and repurposed to use the new API, instead of relying on file engines and internal implementation details of QFileInfo. Change-Id: I65f497bb25741f6f7ea4d2c3b3562c8c4aab8bea Reviewed-by: Oswald Buddenhagen Reviewed-by: David Faure Reviewed-by: Lars Knoll --- src/corelib/io/qfileinfo.cpp | 23 +++++++++++++++++++++++ src/corelib/io/qfileinfo.h | 1 + 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 7277a7a0e4..a7fb0fb6c7 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -917,6 +917,29 @@ bool QFileInfo::isHidden() const return d->getFileFlags(QAbstractFileEngine::HiddenFlag); } +/*! + \since 5.0 + Returns true if the file path can be used directly with native APIs. + Returns false if the file is otherwise supported by a virtual file system + inside Qt, such as \l{the Qt Resource System}. + + \bold{Note:} Native paths may still require conversion of path separators + and character encoding, depending on platform and input requirements of the + native API. + + \sa QDir::toNativeSeparators(), QFile::encodeName(), filePath(), + absoluteFilePath(), canonicalFilePath() +*/ +bool QFileInfo::isNativePath() const +{ + Q_D(const QFileInfo); + if (d->isDefaultConstructed) + return false; + if (d->fileEngine == 0) + return true; + return d->getFileFlags(QAbstractFileEngine::LocalDiskFlag); +} + /*! Returns true if this object points to a file or to a symbolic link to a file. Returns false if the diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index bc9b057fb5..0f43ebd439 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -103,6 +103,7 @@ public: bool isWritable() const; bool isExecutable() const; bool isHidden() const; + bool isNativePath() const; bool isRelative() const; inline bool isAbsolute() const { return !isRelative(); } -- cgit v1.2.3