1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtCore module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia 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 | NFileNames = 9
|
---|
105 | };
|
---|
106 | enum FileOwner {
|
---|
107 | OwnerUser,
|
---|
108 | OwnerGroup
|
---|
109 | };
|
---|
110 | enum FileTime {
|
---|
111 | CreationTime,
|
---|
112 | ModificationTime,
|
---|
113 | AccessTime
|
---|
114 | };
|
---|
115 |
|
---|
116 | virtual ~QAbstractFileEngine();
|
---|
117 |
|
---|
118 | virtual bool open(QIODevice::OpenMode openMode);
|
---|
119 | virtual bool close();
|
---|
120 | virtual bool flush();
|
---|
121 | virtual qint64 size() const;
|
---|
122 | virtual qint64 pos() const;
|
---|
123 | virtual bool seek(qint64 pos);
|
---|
124 | virtual bool isSequential() const;
|
---|
125 | virtual bool remove();
|
---|
126 | virtual bool copy(const QString &newName);
|
---|
127 | virtual bool rename(const QString &newName);
|
---|
128 | virtual bool link(const QString &newName);
|
---|
129 | virtual bool mkdir(const QString &dirName, bool createParentDirectories) const;
|
---|
130 | virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
|
---|
131 | virtual bool setSize(qint64 size);
|
---|
132 | virtual bool caseSensitive() const;
|
---|
133 | virtual bool isRelativePath() const;
|
---|
134 | virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
|
---|
135 | virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
|
---|
136 | virtual bool setPermissions(uint perms);
|
---|
137 | virtual QString fileName(FileName file=DefaultName) const;
|
---|
138 | virtual uint ownerId(FileOwner) const;
|
---|
139 | virtual QString owner(FileOwner) const;
|
---|
140 | virtual QDateTime fileTime(FileTime time) const;
|
---|
141 | virtual void setFileName(const QString &file);
|
---|
142 | virtual int handle() const;
|
---|
143 | bool atEnd() const;
|
---|
144 | uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
|
---|
145 | bool unmap(uchar *ptr);
|
---|
146 |
|
---|
147 | typedef QAbstractFileEngineIterator Iterator;
|
---|
148 | virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
|
---|
149 | virtual Iterator *endEntryList();
|
---|
150 |
|
---|
151 | virtual qint64 read(char *data, qint64 maxlen);
|
---|
152 | virtual qint64 readLine(char *data, qint64 maxlen);
|
---|
153 | virtual qint64 write(const char *data, qint64 len);
|
---|
154 |
|
---|
155 | QFile::FileError error() const;
|
---|
156 | QString errorString() const;
|
---|
157 |
|
---|
158 | enum Extension {
|
---|
159 | AtEndExtension,
|
---|
160 | FastReadLineExtension,
|
---|
161 | MapExtension,
|
---|
162 | UnMapExtension
|
---|
163 | };
|
---|
164 | class ExtensionOption
|
---|
165 | {};
|
---|
166 | class ExtensionReturn
|
---|
167 | {};
|
---|
168 |
|
---|
169 | class MapExtensionOption : public ExtensionOption {
|
---|
170 | public:
|
---|
171 | qint64 offset;
|
---|
172 | qint64 size;
|
---|
173 | QFile::MemoryMapFlags flags;
|
---|
174 | };
|
---|
175 | class MapExtensionReturn : public ExtensionReturn {
|
---|
176 | public:
|
---|
177 | uchar *address;
|
---|
178 | };
|
---|
179 |
|
---|
180 | class UnMapExtensionOption : public ExtensionOption {
|
---|
181 | public:
|
---|
182 | uchar *address;
|
---|
183 | };
|
---|
184 |
|
---|
185 | virtual bool extension(Extension extension, const ExtensionOption *option = 0, ExtensionReturn *output = 0);
|
---|
186 | virtual bool supportsExtension(Extension extension) const;
|
---|
187 |
|
---|
188 | // Factory
|
---|
189 | static QAbstractFileEngine *create(const QString &fileName);
|
---|
190 |
|
---|
191 | protected:
|
---|
192 | void setError(QFile::FileError error, const QString &str);
|
---|
193 |
|
---|
194 | QAbstractFileEngine();
|
---|
195 | QAbstractFileEngine(QAbstractFileEnginePrivate &);
|
---|
196 |
|
---|
197 | QScopedPointer<QAbstractFileEnginePrivate> d_ptr;
|
---|
198 | private:
|
---|
199 | Q_DECLARE_PRIVATE(QAbstractFileEngine)
|
---|
200 | Q_DISABLE_COPY(QAbstractFileEngine)
|
---|
201 | };
|
---|
202 |
|
---|
203 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
|
---|
204 |
|
---|
205 | class Q_CORE_EXPORT QAbstractFileEngineHandler
|
---|
206 | {
|
---|
207 | public:
|
---|
208 | QAbstractFileEngineHandler();
|
---|
209 | virtual ~QAbstractFileEngineHandler();
|
---|
210 | virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
|
---|
211 | };
|
---|
212 |
|
---|
213 | class QAbstractFileEngineIteratorPrivate;
|
---|
214 | class Q_CORE_EXPORT QAbstractFileEngineIterator
|
---|
215 | {
|
---|
216 | public:
|
---|
217 | QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
|
---|
218 | virtual ~QAbstractFileEngineIterator();
|
---|
219 |
|
---|
220 | virtual QString next() = 0;
|
---|
221 | virtual bool hasNext() const = 0;
|
---|
222 |
|
---|
223 | QString path() const;
|
---|
224 | QStringList nameFilters() const;
|
---|
225 | QDir::Filters filters() const;
|
---|
226 |
|
---|
227 | virtual QString currentFileName() const = 0;
|
---|
228 | virtual QFileInfo currentFileInfo() const;
|
---|
229 | QString currentFilePath() const;
|
---|
230 |
|
---|
231 | protected:
|
---|
232 | enum EntryInfoType {
|
---|
233 | };
|
---|
234 | virtual QVariant entryInfo(EntryInfoType type) const;
|
---|
235 |
|
---|
236 | private:
|
---|
237 | Q_DISABLE_COPY(QAbstractFileEngineIterator)
|
---|
238 | friend class QDirIterator;
|
---|
239 | friend class QDirIteratorPrivate;
|
---|
240 | void setPath(const QString &path);
|
---|
241 | QScopedPointer<QAbstractFileEngineIteratorPrivate> d;
|
---|
242 | };
|
---|
243 |
|
---|
244 | QT_END_NAMESPACE
|
---|
245 |
|
---|
246 | QT_END_HEADER
|
---|
247 |
|
---|
248 | #endif // QABSTRACTFILEENGINE_H
|
---|