summaryrefslogtreecommitdiff
path: root/src/corelib/io
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-02-04 01:10:55 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-16 01:59:56 +0100
commitaf115e5bc02eea489d7c15f62e07bc0d46781c3a (patch)
treeda38840ae0d861fefde51f7b6a3be0c42d9947d4 /src/corelib/io
parent7a5bb18dc68326537ff0dc81932e715f1d129a83 (diff)
downloadqtbase-af115e5bc02eea489d7c15f62e07bc0d46781c3a.tar.gz
Drop QFile::fileEngine
The function was already marked as internal. By moving access to the underlying file engine to private API this supports the effort to completely drop file engines from public API. In the future, the goal is to completely drop the file-engine abstraction as it exists today. Change-Id: I332fa56e70c87e83c1e08bb9f75e04df7c93fec7 Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Anselmo L. S. Melo <anselmo.melo@openbossa.org> Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qfile.cpp51
-rw-r--r--src/corelib/io/qfile.h6
-rw-r--r--src/corelib/io/qfile_p.h5
-rw-r--r--src/corelib/io/qtemporaryfile.cpp35
-rw-r--r--src/corelib/io/qtemporaryfile.h2
5 files changed, 48 insertions, 51 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index d7308c710d..58935fad3b 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -130,6 +130,13 @@ QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handl
#endif
}
+QAbstractFileEngine *QFilePrivate::engine() const
+{
+ if (!fileEngine)
+ fileEngine = QAbstractFileEngine::create(fileName);
+ return fileEngine;
+}
+
inline bool QFilePrivate::ensureFlushed() const
{
// This function ensures that the write buffer has been flushed (const
@@ -424,7 +431,8 @@ QFile::~QFile()
*/
QString QFile::fileName() const
{
- return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+ Q_D(const QFile);
+ return d->engine()->fileName(QAbstractFileEngine::DefaultName);
}
/*!
@@ -569,8 +577,9 @@ QFile::setDecodingFunction(DecoderFn f)
bool
QFile::exists() const
{
+ Q_D(const QFile);
// 0x1000000 = QAbstractFileEngine::Refresh, forcing an update
- return (fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask
+ return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask
| QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
}
@@ -608,7 +617,8 @@ QFile::exists(const QString &fileName)
QString
QFile::readLink() const
{
- return fileEngine()->fileName(QAbstractFileEngine::LinkName);
+ Q_D(const QFile);
+ return d->engine()->fileName(QAbstractFileEngine::LinkName);
}
/*!
@@ -654,7 +664,7 @@ QFile::remove()
unsetError();
close();
if(error() == QFile::NoError) {
- if(fileEngine()->remove()) {
+ if (d->engine()->remove()) {
unsetError();
return true;
}
@@ -709,7 +719,7 @@ QFile::rename(const QString &newName)
unsetError();
close();
if(error() == QFile::NoError) {
- if (fileEngine()->rename(newName)) {
+ if (d->engine()->rename(newName)) {
unsetError();
// engine was able to handle the new name so we just reset it
d->fileEngine->setFileName(newName);
@@ -806,7 +816,7 @@ QFile::link(const QString &linkName)
return false;
}
QFileInfo fi(linkName);
- if(fileEngine()->link(fi.absoluteFilePath())) {
+ if (d->engine()->link(fi.absoluteFilePath())) {
unsetError();
return true;
}
@@ -861,7 +871,7 @@ QFile::copy(const QString &newName)
unsetError();
close();
if(error() == QFile::NoError) {
- if(fileEngine()->copy(newName)) {
+ if (d->engine()->copy(newName)) {
unsetError();
return true;
} else {
@@ -996,7 +1006,7 @@ bool QFile::open(OpenMode mode)
}
// QIODevice provides the buffering, so there's no need to request it from the file engine.
- if (fileEngine()->open(mode | QIODevice::Unbuffered)) {
+ if (d->engine()->open(mode | QIODevice::Unbuffered)) {
QIODevice::open(mode);
if (mode & Append)
seek(size());
@@ -1271,7 +1281,7 @@ QFile::handle() const
uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
{
Q_D(QFile);
- if (fileEngine()
+ if (d->engine()
&& d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
unsetError();
uchar *address = d->fileEngine->map(offset, size, flags);
@@ -1293,7 +1303,7 @@ uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
bool QFile::unmap(uchar *address)
{
Q_D(QFile);
- if (fileEngine()
+ if (d->engine()
&& d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
unsetError();
bool success = d->fileEngine->unmap(address);
@@ -1320,7 +1330,7 @@ QFile::resize(qint64 sz)
Q_D(QFile);
if (!d->ensureFlushed())
return false;
- fileEngine();
+ d->engine();
if (isOpen() && d->fileEngine->pos() > sz)
seek(sz);
if(d->fileEngine->setSize(sz)) {
@@ -1360,7 +1370,8 @@ QFile::resize(const QString &fileName, qint64 sz)
QFile::Permissions
QFile::permissions() const
{
- QAbstractFileEngine::FileFlags perms = fileEngine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
+ Q_D(const QFile);
+ QAbstractFileEngine::FileFlags perms = d->engine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;
return QFile::Permissions((int)perms); //ewww
}
@@ -1389,7 +1400,7 @@ bool
QFile::setPermissions(Permissions permissions)
{
Q_D(QFile);
- if(fileEngine()->setPermissions(permissions)) {
+ if (d->engine()->setPermissions(permissions)) {
unsetError();
return true;
}
@@ -1490,7 +1501,7 @@ qint64 QFile::size() const
Q_D(const QFile);
if (!d->ensureFlushed())
return 0;
- d->cachedSize = fileEngine()->size();
+ d->cachedSize = d->engine()->size();
return d->cachedSize;
}
@@ -1731,18 +1742,6 @@ QFile::writeData(const char *data, qint64 len)
}
/*!
- \internal
- Returns the QIOEngine for this QFile object.
-*/
-QAbstractFileEngine *QFile::fileEngine() const
-{
- Q_D(const QFile);
- if(!d->fileEngine)
- d->fileEngine = QAbstractFileEngine::create(d->fileName);
- return d->fileEngine;
-}
-
-/*!
Returns the file error status.
The I/O device status returns an error code. For example, if open()
diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h
index bc278cf600..bf7290dda2 100644
--- a/src/corelib/io/qfile.h
+++ b/src/corelib/io/qfile.h
@@ -54,8 +54,7 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-
-class QAbstractFileEngine;
+class QTemporaryFile;
class QFilePrivate;
class Q_CORE_EXPORT QFile : public QIODevice
@@ -174,8 +173,6 @@ public:
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
bool unmap(uchar *address);
- virtual QAbstractFileEngine *fileEngine() const;
-
protected:
#ifdef QT_NO_QOBJECT
QFile(QFilePrivate &dd);
@@ -188,6 +185,7 @@ protected:
qint64 readLineData(char *data, qint64 maxlen);
private:
+ friend class QTemporaryFile;
Q_DISABLE_COPY(QFile)
};
diff --git a/src/corelib/io/qfile_p.h b/src/corelib/io/qfile_p.h
index b932627ec0..4a637d44a8 100644
--- a/src/corelib/io/qfile_p.h
+++ b/src/corelib/io/qfile_p.h
@@ -59,9 +59,12 @@
QT_BEGIN_NAMESPACE
+class QTemporaryFile;
+
class QFilePrivate : public QIODevicePrivate
{
Q_DECLARE_PUBLIC(QFile)
+ friend class QTemporaryFile;
protected:
QFilePrivate();
@@ -70,6 +73,8 @@ protected:
bool openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags);
bool openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags);
+ virtual QAbstractFileEngine *engine() const;
+
QString fileName;
mutable QAbstractFileEngine *fileEngine;
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index b80ba6eee1..75681dadff 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -407,6 +407,8 @@ protected:
QTemporaryFilePrivate();
~QTemporaryFilePrivate();
+ QAbstractFileEngine *engine() const;
+
bool autoRemove;
QString templateName;
};
@@ -419,6 +421,17 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
{
}
+QAbstractFileEngine *QTemporaryFilePrivate::engine() const
+{
+ if (!fileEngine) {
+ if (fileName.isEmpty())
+ fileEngine = new QTemporaryFileEngine(templateName);
+ else
+ fileEngine = new QTemporaryFileEngine(fileName, false);
+ }
+ return fileEngine;
+}
+
static QString defaultTemplateName()
{
QString baseName;
@@ -640,7 +653,7 @@ QString QTemporaryFile::fileName() const
Q_D(const QTemporaryFile);
if(d->fileName.isEmpty())
return QString();
- return fileEngine()->fileName(QAbstractFileEngine::DefaultName);
+ return d->engine()->fileName(QAbstractFileEngine::DefaultName);
}
/*!
@@ -692,7 +705,7 @@ void QTemporaryFile::setFileTemplate(const QString &name)
*/
QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
{
- if (QAbstractFileEngine *engine = file.fileEngine()) {
+ if (QAbstractFileEngine *engine = file.d_func()->engine()) {
if(engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::LocalDiskFlag)
return 0; //local already
//cache
@@ -726,22 +739,6 @@ QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file)
}
/*!
- \internal
-*/
-
-QAbstractFileEngine *QTemporaryFile::fileEngine() const
-{
- Q_D(const QTemporaryFile);
- if(!d->fileEngine) {
- if (d->fileName.isEmpty())
- d->fileEngine = new QTemporaryFileEngine(d->templateName);
- else
- d->fileEngine = new QTemporaryFileEngine(d->fileName, false);
- }
- return d->fileEngine;
-}
-
-/*!
\reimp
Creates a unique file name for the temporary file, and opens it. You can
@@ -752,7 +749,7 @@ bool QTemporaryFile::open(OpenMode flags)
{
Q_D(QTemporaryFile);
if (!d->fileName.isEmpty()) {
- if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) {
+ if (static_cast<QTemporaryFileEngine*>(d->engine())->isReallyOpen()) {
setOpenMode(flags);
return true;
}
diff --git a/src/corelib/io/qtemporaryfile.h b/src/corelib/io/qtemporaryfile.h
index 8b14e5a14a..e766569293 100644
--- a/src/corelib/io/qtemporaryfile.h
+++ b/src/corelib/io/qtemporaryfile.h
@@ -88,8 +88,6 @@ public:
{ QFile file(fileName); return createLocalFile(file); }
static QTemporaryFile *createLocalFile(QFile &file);
- virtual QAbstractFileEngine *fileEngine() const;
-
protected:
bool open(OpenMode flags);