summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-09-25 13:14:52 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-02 10:43:48 +0200
commitef3a544436beaecb4d26349ce115be39b680ef6a (patch)
tree540c4d2f4485794165d6d780b04296da8910db14
parentf20266f9f43ab3956de271f696c769db02992e87 (diff)
Rename createLocalFile to createNativeFile & deprecate createLocalFile
As it was confusing to use the term local file when referring to a file that was accessible using native APIs and not just a file that was on a hard disk somewhere already the function name has been changed. By renaming it to createNativeFile we keep it consistant with QFileInfo which has an isNativeFile() function too. Test also added. Task-number: QTBUG-3169 Change-Id: I410e7ed28133d68fd312c6c0faf3f7191460d7ce Reviewed-by: João Abecasis <joao@abecasis.name> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/io/qtemporaryfile.cpp38
-rw-r--r--src/corelib/io/qtemporaryfile.h13
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro1
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc5
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/resources/test.txt1
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp38
6 files changed, 85 insertions, 11 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 6f8f70f8d4..a647d21f40 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -700,6 +700,21 @@ void QTemporaryFile::setFileTemplate(const QString &name)
/*!
\fn QTemporaryFile *QTemporaryFile::createLocalFile(const QString &fileName)
\overload
+ \obsolete
+
+ Use QTemporaryFile::createNativeFile(const QString &fileName) instead.
+*/
+
+/*!
+ \fn QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
+ \obsolete
+
+ Use QTemporaryFile::createNativeFile(QFile &file) instead.
+*/
+
+/*!
+ \fn QTemporaryFile *QTemporaryFile::createNativeFile(const QString &fileName)
+ \overload
Works on the given \a fileName rather than an existing QFile
object.
@@ -707,16 +722,27 @@ void QTemporaryFile::setFileTemplate(const QString &name)
/*!
- If \a file is not on a local disk, a temporary file is created
- on a local disk, \a file is copied into the temporary local file,
- and a pointer to the temporary local file is returned. If \a file
- is already on a local disk, a copy is not created and 0 is returned.
+ If \a file is not already a native file then a QTemporaryFile is created
+ in the tempPath() and \a file is copied into the temporary file, then a
+ pointer to the temporary file is returned. If \a file is already a native
+ file, a QTemporaryFile is not created, no copy is made and 0 is returned.
+
+ For example:
+
+ QFile f(":/resources/file.txt");
+ QTemporaryFile::createNativeFile(f); // Returns a pointer to a temporary file
+
+ QFile f("/users/qt/file.txt");
+ QTemporaryFile::createNativeFile(f); // Returns 0
+
+ \sa QFileInfo::isNativePath()
*/
-QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
+
+QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
{
if (QAbstractFileEngine *engine = file.d_func()->engine()) {
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
- return 0; //local already
+ return 0; //native already
//cache
bool wasOpen = file.isOpen();
qint64 old_off = 0;
diff --git a/src/corelib/io/qtemporaryfile.h b/src/corelib/io/qtemporaryfile.h
index 96e6b1c779..b7c375ea41 100644
--- a/src/corelib/io/qtemporaryfile.h
+++ b/src/corelib/io/qtemporaryfile.h
@@ -83,10 +83,15 @@ public:
QString fileName() const;
QString fileTemplate() const;
void setFileTemplate(const QString &name);
-
- inline static QTemporaryFile *createLocalFile(const QString &fileName)
- { QFile file(fileName); return createLocalFile(file); }
- static QTemporaryFile *createLocalFile(QFile &file);
+#if QT_DEPRECATED_SINCE(5,1)
+ QT_DEPRECATED inline static QTemporaryFile *createLocalFile(const QString &fileName)
+ { return createNativeFile(fileName); }
+ QT_DEPRECATED inline static QTemporaryFile *createLocalFile(QFile &file)
+ { return createNativeFile(file); }
+#endif
+ inline static QTemporaryFile *createNativeFile(const QString &fileName)
+ { QFile file(fileName); return createNativeFile(file); }
+ static QTemporaryFile *createNativeFile(QFile &file);
protected:
bool open(OpenMode flags);
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
index 64331daef9..8a91340e5f 100644
--- a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
@@ -5,3 +5,4 @@ QT = core testlib
SOURCES = tst_qtemporaryfile.cpp
TESTDATA += tst_qtemporaryfile.cpp
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+RESOURCES += qtemporaryfile.qrc \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
new file mode 100644
index 0000000000..efadde8b4d
--- /dev/null
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.qrc
@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file>resources/test.txt</file>
+</qresource>
+</RCC> \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/resources/test.txt b/tests/auto/corelib/io/qtemporaryfile/resources/test.txt
new file mode 100644
index 0000000000..793aa682b0
--- /dev/null
+++ b/tests/auto/corelib/io/qtemporaryfile/resources/test.txt
@@ -0,0 +1 @@
+This is a test \ No newline at end of file
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index e68594ebaf..6d7a6e76ef 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -88,7 +88,8 @@ private slots:
void resetTemplateAfterError();
void setTemplateAfterOpen();
void autoRemoveAfterFailedRename();
-
+ void createNativeFile_data();
+ void createNativeFile();
void QTBUG_4796_data();
void QTBUG_4796();
};
@@ -633,6 +634,41 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename()
cleaner.reset();
}
+void tst_QTemporaryFile::createNativeFile_data()
+{
+ QTest::addColumn<QString>("filePath");
+ QTest::addColumn<qint64>("currentPos");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<QByteArray>("content");
+
+ QTest::newRow("nativeFile") << QFINDTESTDATA("resources/test.txt") << (qint64)-1 << false << QByteArray();
+ QTest::newRow("nativeFileWithPos") << QFINDTESTDATA("resources/test.txt") << (qint64)5 << false << QByteArray();
+ QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test");
+ QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test");
+}
+
+void tst_QTemporaryFile::createNativeFile()
+{
+ QFETCH(QString, filePath);
+ QFETCH(qint64, currentPos);
+ QFETCH(bool, valid);
+ QFETCH(QByteArray, content);
+
+ QFile f(filePath);
+ if (currentPos != -1) {
+ f.open(QIODevice::ReadOnly);
+ f.seek(currentPos);
+ }
+ QTemporaryFile *tempFile = QTemporaryFile::createNativeFile(f);
+ QVERIFY(valid == (bool)tempFile);
+ if (currentPos != -1)
+ QCOMPARE(currentPos, f.pos());
+ if (valid) {
+ QCOMPARE(content, tempFile->readAll());
+ delete tempFile;
+ }
+}
+
void tst_QTemporaryFile::QTBUG_4796_data()
{
QTest::addColumn<QString>("prefix");