diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2010-08-30 10:02:39 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2010-08-30 12:00:21 (GMT) |
commit | 1d52b8a0643dca077de432d841df5f49f472352a (patch) | |
tree | abdab952ae27d3a64873b576b467b1d9c029f49c /src/corelib/io/qfsfileengine.cpp | |
parent | 5dfcf2c6778e6852b3d1a2f9c6cc4c9e7c8a5d3b (diff) | |
download | Qt-1d52b8a0643dca077de432d841df5f49f472352a.zip Qt-1d52b8a0643dca077de432d841df5f49f472352a.tar.gz Qt-1d52b8a0643dca077de432d841df5f49f472352a.tar.bz2 |
Removed native file path handling from QFSFileEngine
Moved it into QFileSystemEntry, instead.
For the time being, QFileSystemEntry may look like an unnecessary extra
layer of indirection. For the time being, this allows us to do some code
cleanup and de-duplication. It is also a stepping stone to becoming
completely independent of the current file engine abstraction.
Changes to QFileSystemEntry:
- native file path on Windows is now a QString, instead of a
QByteArray. Accordingly, constructors taking a QByteArray were
removed for these platforms.
- Encoding/decoding of file names uses QFile::encode/decodeName API,
instead of assuming local 8 bit. On Windows, UTF-16 is used for
native, as was being done in QFSFileEngine.
- new functions isRoot(), isDriveRoot() [Windows/Symbian], and path()
- convenience functions clear() and isEmpty() added to facilitate
porting.
Changes to QFSFileEngine (Windows):
- removed QFSFileEnginePrivate::sizeFdFh(): the function was broken
and never used, so might as well not get compiled in.
- repeated pattern for use of FindFirstFile/FindClose hidden away in a
static inline function.
- repeated and inconsistent conversions from QString to native file
paths reduced through the use of QFileSystemEntry.
Done-with: Prasanth Ullattil
Done-with: Thomas Zander
Diffstat (limited to 'src/corelib/io/qfsfileengine.cpp')
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 511a1a6..75f82a6 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -239,11 +239,11 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path) /*! Constructs a QFSFileEngine for the file name \a file. */ -QFSFileEngine::QFSFileEngine(const QString &file) : QAbstractFileEngine(*new QFSFileEnginePrivate) +QFSFileEngine::QFSFileEngine(const QString &file) + : QAbstractFileEngine(*new QFSFileEnginePrivate) { Q_D(QFSFileEngine); - d->filePath = QDir::fromNativeSeparators(file); - d->nativeInitFileName(); + d->fileEntry = QFileSystemEntry(QDir::fromNativeSeparators(file)); } /*! @@ -292,8 +292,7 @@ void QFSFileEngine::setFileName(const QString &file) { Q_D(QFSFileEngine); d->init(); - d->filePath = QDir::fromNativeSeparators(file); - d->nativeInitFileName(); + d->fileEntry = QFileSystemEntry(QDir::fromNativeSeparators(file)); } /*! @@ -302,7 +301,7 @@ void QFSFileEngine::setFileName(const QString &file) bool QFSFileEngine::open(QIODevice::OpenMode openMode) { Q_D(QFSFileEngine); - if (d->filePath.isEmpty()) { + if (d->fileEntry.isEmpty()) { qWarning("QFSFileEngine::open: No file name specified"); setError(QFile::OpenError, QLatin1String("No file name specified")); return false; @@ -344,8 +343,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, FILE *fh) d->openMode = openMode; d->lastFlushFailed = false; d->closeFileHandle = false; - d->nativeFilePath.clear(); - d->filePath.clear(); + d->fileEntry.clear(); d->tried_stat = 0; d->fd = -1; @@ -401,8 +399,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd) d->openMode = openMode; d->lastFlushFailed = false; d->closeFileHandle = false; - d->nativeFilePath.clear(); - d->filePath.clear(); + d->fileEntry.clear(); d->fh = 0; d->fd = -1; d->tried_stat = 0; @@ -549,6 +546,7 @@ qint64 QFSFileEngine::size() const /*! \internal */ +#ifndef Q_OS_WIN qint64 QFSFileEnginePrivate::sizeFdFh() const { Q_Q(const QFSFileEngine); @@ -556,13 +554,13 @@ qint64 QFSFileEnginePrivate::sizeFdFh() const QT_STATBUF st; int ret = 0; const_cast<QFSFileEngine *>(q)->flush(); - if (fh && nativeFilePath.isEmpty()) { + if (fh && fileEntry.isEmpty()) { // Buffered stdlib mode. // ### This should really be an ftell ret = QT_FSTAT(QT_FILENO(fh), &st); } else if (fd == -1) { // Stateless stat. - ret = QT_STAT(nativeFilePath.constData(), &st); + ret = QT_STAT(fileEntry.nativeFilePath().constData(), &st); } else { // Unbuffered stdio mode. ret = QT_FSTAT(fd, &st); @@ -571,6 +569,7 @@ qint64 QFSFileEnginePrivate::sizeFdFh() const return 0; return st.st_size; } +#endif /*! \reimp |