| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtCore module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QABSTRACTFILEENGINE_H
|
|---|
| 43 | #define QABSTRACTFILEENGINE_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtCore/qdir.h>
|
|---|
| 46 |
|
|---|
| 47 | #ifdef open
|
|---|
| 48 | #error qabstractfileengine.h must be included before any header file that defines open
|
|---|
| 49 | #endif
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_HEADER
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | QT_MODULE(Core)
|
|---|
| 56 |
|
|---|
| 57 | class QFileExtension;
|
|---|
| 58 | class QFileExtensionResult;
|
|---|
| 59 | class QVariant;
|
|---|
| 60 | class QAbstractFileEngineIterator;
|
|---|
| 61 | class QAbstractFileEnginePrivate;
|
|---|
| 62 |
|
|---|
| 63 | class Q_CORE_EXPORT QAbstractFileEngine
|
|---|
| 64 | {
|
|---|
| 65 | public:
|
|---|
| 66 | enum FileFlag {
|
|---|
| 67 | //perms (overlaps the QFile::Permission)
|
|---|
| 68 | ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
|
|---|
| 69 | ReadUserPerm = 0x0400, WriteUserPerm = 0x0200, ExeUserPerm = 0x0100,
|
|---|
| 70 | ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
|
|---|
| 71 | ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
|
|---|
| 72 |
|
|---|
| 73 | //types
|
|---|
| 74 | LinkType = 0x10000,
|
|---|
| 75 | FileType = 0x20000,
|
|---|
| 76 | DirectoryType = 0x40000,
|
|---|
| 77 | BundleType = 0x80000,
|
|---|
| 78 |
|
|---|
| 79 | //flags
|
|---|
| 80 | HiddenFlag = 0x0100000,
|
|---|
| 81 | LocalDiskFlag = 0x0200000,
|
|---|
| 82 | ExistsFlag = 0x0400000,
|
|---|
| 83 | RootFlag = 0x0800000,
|
|---|
| 84 | Refresh = 0x1000000,
|
|---|
| 85 |
|
|---|
| 86 | //masks
|
|---|
| 87 | PermsMask = 0x0000FFFF,
|
|---|
| 88 | TypesMask = 0x000F0000,
|
|---|
| 89 | FlagsMask = 0x0FF00000,
|
|---|
| 90 | FileInfoAll = FlagsMask | PermsMask | TypesMask
|
|---|
| 91 | };
|
|---|
| 92 | Q_DECLARE_FLAGS(FileFlags, FileFlag)
|
|---|
| 93 |
|
|---|
| 94 | enum FileName {
|
|---|
| 95 | DefaultName,
|
|---|
| 96 | BaseName,
|
|---|
| 97 | PathName,
|
|---|
| 98 | AbsoluteName,
|
|---|
| 99 | AbsolutePathName,
|
|---|
| 100 | LinkName,
|
|---|
| 101 | CanonicalName,
|
|---|
| 102 | CanonicalPathName,
|
|---|
| 103 | BundleName
|
|---|
| 104 | };
|
|---|
| 105 | enum FileOwner {
|
|---|
| 106 | OwnerUser,
|
|---|
| 107 | OwnerGroup
|
|---|
| 108 | };
|
|---|
| 109 | enum FileTime {
|
|---|
| 110 | CreationTime,
|
|---|
| 111 | ModificationTime,
|
|---|
| 112 | AccessTime
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | virtual ~QAbstractFileEngine();
|
|---|
| 116 |
|
|---|
| 117 | virtual bool open(QIODevice::OpenMode openMode);
|
|---|
| 118 | virtual bool close();
|
|---|
| 119 | virtual bool flush();
|
|---|
| 120 | virtual qint64 size() const;
|
|---|
| 121 | virtual qint64 pos() const;
|
|---|
| 122 | virtual bool seek(qint64 pos);
|
|---|
| 123 | virtual bool isSequential() const;
|
|---|
| 124 | virtual bool remove();
|
|---|
| 125 | virtual bool copy(const QString &newName);
|
|---|
| 126 | virtual bool rename(const QString &newName);
|
|---|
| 127 | virtual bool link(const QString &newName);
|
|---|
| 128 | virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
|
|---|
| 129 | virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
|
|---|
| 130 | virtual bool setSize(qint64 size);
|
|---|
| 131 | virtual bool caseSensitive() const;
|
|---|
| 132 | virtual bool isRelativePath() const;
|
|---|
| 133 | virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
|
|---|
| 134 | virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
|
|---|
| 135 | virtual bool setPermissions(uint perms);
|
|---|
| 136 | virtual QString fileName(FileName file=DefaultName) const;
|
|---|
| 137 | virtual uint ownerId(FileOwner) const;
|
|---|
| 138 | virtual QString owner(FileOwner) const;
|
|---|
| 139 | virtual QDateTime fileTime(FileTime time) const;
|
|---|
| 140 | virtual void setFileName(const QString &file);
|
|---|
| 141 | virtual int handle() const;
|
|---|
| 142 | bool atEnd() const;
|
|---|
| 143 | uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
|
|---|
| 144 | bool unmap(uchar *ptr);
|
|---|
| 145 |
|
|---|
| 146 | typedef QAbstractFileEngineIterator Iterator;
|
|---|
| 147 | virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
|
|---|
| 148 | virtual Iterator *endEntryList();
|
|---|
| 149 |
|
|---|
| 150 | virtual qint64 read(char *data, qint64 maxlen);
|
|---|
| 151 | virtual qint64 readLine(char *data, qint64 maxlen);
|
|---|
| 152 | virtual qint64 write(const char *data, qint64 len);
|
|---|
| 153 |
|
|---|
| 154 | QFile::FileError error() const;
|
|---|
| 155 | QString errorString() const;
|
|---|
| 156 |
|
|---|
| 157 | enum Extension {
|
|---|
| 158 | AtEndExtension,
|
|---|
| 159 | FastReadLineExtension,
|
|---|
| 160 | MapExtension,
|
|---|
| 161 | UnMapExtension
|
|---|
| 162 | };
|
|---|
| 163 | class ExtensionOption
|
|---|
| 164 | {};
|
|---|
| 165 | class ExtensionReturn
|
|---|
| 166 | {};
|
|---|
| 167 |
|
|---|
| 168 | class MapExtensionOption : public ExtensionOption {
|
|---|
| 169 | public:
|
|---|
| 170 | qint64 offset;
|
|---|
| 171 | qint64 size;
|
|---|
| 172 | QFile::MemoryMapFlags flags;
|
|---|
| 173 | };
|
|---|
| 174 | class MapExtensionReturn : public ExtensionReturn {
|
|---|
| 175 | public:
|
|---|
| 176 | uchar *address;
|
|---|
| 177 | };
|
|---|
| 178 |
|
|---|
| 179 | class UnMapExtensionOption : public ExtensionOption {
|
|---|
| 180 | public:
|
|---|
| 181 | uchar *address;
|
|---|
| 182 | };
|
|---|
| 183 |
|
|---|
| 184 | virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
|
|---|
| 185 | virtual bool supportsExtension(Extension extension) const;
|
|---|
| 186 |
|
|---|
| 187 | // Factory
|
|---|
| 188 | static QAbstractFileEngine *create(const QString &fileName);
|
|---|
| 189 |
|
|---|
| 190 | protected:
|
|---|
| 191 | void setError(QFile::FileError error, const QString &str);
|
|---|
| 192 |
|
|---|
| 193 | QAbstractFileEngine();
|
|---|
| 194 | QAbstractFileEngine(QAbstractFileEnginePrivate &);
|
|---|
| 195 |
|
|---|
| 196 | QAbstractFileEnginePrivate *d_ptr;
|
|---|
| 197 | private:
|
|---|
| 198 | Q_DECLARE_PRIVATE(QAbstractFileEngine)
|
|---|
| 199 | Q_DISABLE_COPY(QAbstractFileEngine)
|
|---|
| 200 | };
|
|---|
| 201 |
|
|---|
| 202 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
|
|---|
| 203 |
|
|---|
| 204 | class Q_CORE_EXPORT QAbstractFileEngineHandler
|
|---|
| 205 | {
|
|---|
| 206 | public:
|
|---|
| 207 | QAbstractFileEngineHandler();
|
|---|
| 208 | virtual ~QAbstractFileEngineHandler();
|
|---|
| 209 | virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
|
|---|
| 210 | };
|
|---|
| 211 |
|
|---|
| 212 | class QAbstractFileEngineIteratorPrivate;
|
|---|
| 213 | class Q_CORE_EXPORT QAbstractFileEngineIterator
|
|---|
| 214 | {
|
|---|
| 215 | public:
|
|---|
| 216 | QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
|
|---|
| 217 | virtual ~QAbstractFileEngineIterator();
|
|---|
| 218 |
|
|---|
| 219 | virtual QString next() = 0;
|
|---|
| 220 | virtual bool hasNext() const = 0;
|
|---|
| 221 |
|
|---|
| 222 | QString path() const;
|
|---|
| 223 | QStringList nameFilters() const;
|
|---|
| 224 | QDir::Filters filters() const;
|
|---|
| 225 |
|
|---|
| 226 | virtual QString currentFileName() const = 0;
|
|---|
| 227 | virtual QFileInfo currentFileInfo() const;
|
|---|
| 228 | QString currentFilePath() const;
|
|---|
| 229 |
|
|---|
| 230 | protected:
|
|---|
| 231 | enum EntryInfoType {
|
|---|
| 232 | };
|
|---|
| 233 | virtual QVariant entryInfo(EntryInfoType type) const;
|
|---|
| 234 |
|
|---|
| 235 | private:
|
|---|
| 236 | Q_DISABLE_COPY(QAbstractFileEngineIterator)
|
|---|
| 237 | friend class QDirIterator;
|
|---|
| 238 | friend class QDirIteratorPrivate;
|
|---|
| 239 | void setPath(const QString &path);
|
|---|
| 240 | QAbstractFileEngineIteratorPrivate *d;
|
|---|
| 241 | };
|
|---|
| 242 |
|
|---|
| 243 | QT_END_NAMESPACE
|
|---|
| 244 |
|
|---|
| 245 | QT_END_HEADER
|
|---|
| 246 |
|
|---|
| 247 | #endif // QABSTRACTFILEENGINE_H
|
|---|