qabstractfileengine.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtCore module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QABSTRACTFILEENGINE_H
00043 #define QABSTRACTFILEENGINE_H
00044 
00045 #include <QtCore/qdir.h>
00046 
00047 #ifdef open
00048 #error qabstractfileengine.h must be included before any header file that defines open
00049 #endif
00050 
00051 QT_BEGIN_HEADER
00052 
00053 QT_BEGIN_NAMESPACE
00054 
00055 QT_MODULE(Core)
00056 
00057 class QFileExtension;
00058 class QFileExtensionResult;
00059 class QVariant;
00060 class QAbstractFileEngineIterator;
00061 class QAbstractFileEnginePrivate;
00062 
00063 class Q_CORE_EXPORT QAbstractFileEngine
00064 {
00065 public:
00066     enum FileFlag {
00067         //perms (overlaps the QFile::Permission)
00068         ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
00069         ReadUserPerm  = 0x0400, WriteUserPerm  = 0x0200, ExeUserPerm  = 0x0100,
00070         ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
00071         ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
00072 
00073         //types
00074         LinkType      = 0x10000,
00075         FileType      = 0x20000,
00076         DirectoryType = 0x40000,
00077         BundleType    = 0x80000,
00078 
00079         //flags
00080         HiddenFlag     = 0x0100000,
00081         LocalDiskFlag  = 0x0200000,
00082         ExistsFlag     = 0x0400000,
00083         RootFlag       = 0x0800000,
00084         Refresh        = 0x1000000,
00085 
00086         //masks
00087         PermsMask  = 0x0000FFFF,
00088         TypesMask  = 0x000F0000,
00089         FlagsMask  = 0x0FF00000,
00090         FileInfoAll = FlagsMask | PermsMask | TypesMask
00091     };
00092     Q_DECLARE_FLAGS(FileFlags, FileFlag)
00093 
00094     enum FileName {
00095         DefaultName,
00096         BaseName,
00097         PathName,
00098         AbsoluteName,
00099         AbsolutePathName,
00100         LinkName,
00101         CanonicalName,
00102         CanonicalPathName,
00103         BundleName,
00104         NFileNames = 9
00105     };
00106     enum FileOwner {
00107         OwnerUser,
00108         OwnerGroup
00109     };
00110     enum FileTime {
00111         CreationTime,
00112         ModificationTime,
00113         AccessTime
00114     };
00115 
00116     virtual ~QAbstractFileEngine();
00117 
00118     virtual bool open(QIODevice::OpenMode openMode);
00119     virtual bool close();
00120     virtual bool flush();
00121     virtual qint64 size() const;
00122     virtual qint64 pos() const;
00123     virtual bool seek(qint64 pos);
00124     virtual bool isSequential() const;
00125     virtual bool remove();
00126     virtual bool copy(const QString &newName);
00127     virtual bool rename(const QString &newName);
00128     virtual bool link(const QString &newName);
00129     virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
00130     virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
00131     virtual bool setSize(qint64 size);
00132     virtual bool caseSensitive() const;
00133     virtual bool isRelativePath() const;
00134     virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
00135     virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
00136     virtual bool setPermissions(uint perms);
00137     virtual QString fileName(FileName file=DefaultName) const;
00138     virtual uint ownerId(FileOwner) const;
00139     virtual QString owner(FileOwner) const;
00140     virtual QDateTime fileTime(FileTime time) const;
00141     virtual void setFileName(const QString &file);
00142     virtual int handle() const;
00143     bool atEnd() const;
00144     uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
00145     bool unmap(uchar *ptr);
00146 
00147     typedef QAbstractFileEngineIterator Iterator;
00148     virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
00149     virtual Iterator *endEntryList();
00150 
00151     virtual qint64 read(char *data, qint64 maxlen);
00152     virtual qint64 readLine(char *data, qint64 maxlen);
00153     virtual qint64 write(const char *data, qint64 len);
00154 
00155     QFile::FileError error() const;
00156     QString errorString() const;
00157 
00158     enum Extension {
00159         AtEndExtension,
00160         FastReadLineExtension,
00161         MapExtension,
00162         UnMapExtension
00163     };
00164     class ExtensionOption
00165     {};
00166     class ExtensionReturn
00167     {};
00168 
00169     class MapExtensionOption : public ExtensionOption {
00170     public:
00171         qint64 offset;
00172         qint64 size;
00173         QFile::MemoryMapFlags flags;
00174     };
00175     class MapExtensionReturn : public ExtensionReturn {
00176     public:
00177         uchar *address;
00178     };
00179 
00180     class UnMapExtensionOption : public ExtensionOption {
00181     public:
00182         uchar *address;
00183     };
00184 
00185     virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
00186     virtual bool supportsExtension(Extension extension) const;
00187 
00188     // Factory
00189     static QAbstractFileEngine *create(const QString &fileName);
00190 
00191 protected:
00192     void setError(QFile::FileError error, const QString &str);
00193 
00194     QAbstractFileEngine();
00195     QAbstractFileEngine(QAbstractFileEnginePrivate &);
00196 
00197     QScopedPointer<QAbstractFileEnginePrivate> d_ptr;
00198 private:
00199     Q_DECLARE_PRIVATE(QAbstractFileEngine)
00200     Q_DISABLE_COPY(QAbstractFileEngine)
00201 };
00202 
00203 Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
00204 
00205 class Q_CORE_EXPORT QAbstractFileEngineHandler
00206 {
00207 public:
00208     QAbstractFileEngineHandler();
00209     virtual ~QAbstractFileEngineHandler();
00210     virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
00211 };
00212 
00213 class QAbstractFileEngineIteratorPrivate;
00214 class Q_CORE_EXPORT QAbstractFileEngineIterator
00215 {
00216 public:
00217     QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
00218     virtual ~QAbstractFileEngineIterator();
00219 
00220     virtual QString next() = 0;
00221     virtual bool hasNext() const = 0;
00222 
00223     QString path() const;
00224     QStringList nameFilters() const;
00225     QDir::Filters filters() const;
00226 
00227     virtual QString currentFileName() const = 0;
00228     virtual QFileInfo currentFileInfo() const;
00229     QString currentFilePath() const;
00230 
00231 protected:
00232     enum EntryInfoType {
00233     };
00234     virtual QVariant entryInfo(EntryInfoType type) const;
00235 
00236 private:
00237     Q_DISABLE_COPY(QAbstractFileEngineIterator)
00238     friend class QDirIterator;
00239     friend class QDirIteratorPrivate;
00240     void setPath(const QString &path);
00241     QScopedPointer<QAbstractFileEngineIteratorPrivate> d;
00242 };
00243 
00244 QT_END_NAMESPACE
00245 
00246 QT_END_HEADER
00247 
00248 #endif // QABSTRACTFILEENGINE_H