summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qfileinfo.cpp23
-rw-r--r--src/corelib/io/qfileinfo.h1
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp23
3 files changed, 36 insertions, 11 deletions
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
@@ -918,6 +918,29 @@ bool QFileInfo::isHidden() const
}
/*!
+ \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
object points to something which isn't a file, such as a directory.
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(); }
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index a3d80cb66f..797d5ff5e3 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -159,8 +159,8 @@ private slots:
void isBundle_data();
void isBundle();
- void isLocalFs_data();
- void isLocalFs();
+ void isNativePath_data();
+ void isNativePath();
void refresh();
@@ -1222,10 +1222,13 @@ void tst_QFileInfo::isBundle()
QCOMPARE(fi.isBundle(), isBundle);
}
-void tst_QFileInfo::isLocalFs_data()
+void tst_QFileInfo::isNativePath_data()
{
QTest::addColumn<QString>("path");
- QTest::addColumn<bool>("isLocalFs");
+ QTest::addColumn<bool>("isNativePath");
+
+ QTest::newRow("default-constructed") << QString() << false;
+ QTest::newRow("empty") << QString("") << true;
QTest::newRow("local root") << QString::fromLatin1("/") << true;
QTest::newRow("local non-existent file") << QString::fromLatin1("/abrakadabra.boo") << true;
@@ -1233,17 +1236,15 @@ void tst_QFileInfo::isLocalFs_data()
QTest::newRow("qresource root") << QString::fromLatin1(":/") << false;
}
-void tst_QFileInfo::isLocalFs()
+void tst_QFileInfo::isNativePath()
{
QFETCH(QString, path);
- QFETCH(bool, isLocalFs);
+ QFETCH(bool, isNativePath);
QFileInfo info(path);
- QFileInfoPrivate *privateInfo = getPrivate(info);
- QCOMPARE((privateInfo->fileEngine == 0), isLocalFs);
- if (privateInfo->fileEngine)
- QCOMPARE(bool(privateInfo->fileEngine->fileFlags(QAbstractFileEngine::LocalDiskFlag)
- & QAbstractFileEngine::LocalDiskFlag), isLocalFs);
+ if (path.isNull())
+ info = QFileInfo();
+ QCOMPARE(info.isNativePath(), isNativePath);
}
void tst_QFileInfo::refresh()