1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QABSTRACTFILEENGINE_P_H
5#define QABSTRACTFILEENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include "QtCore/qfile.h"
20#include "QtCore/qdir.h"
21
22#include <optional>
23
24#ifdef open
25#error qabstractfileengine_p.h must be included before any header file that defines open
26#endif
27
28QT_BEGIN_NAMESPACE
29
30class QVariant;
31class QAbstractFileEngineIterator;
32class QAbstractFileEnginePrivate;
33
34class Q_CORE_EXPORT QAbstractFileEngine
35{
36public:
37 enum FileFlag {
38 //perms (overlaps the QFile::Permission)
39 ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000,
40 ReadUserPerm = 0x0400, WriteUserPerm = 0x0200, ExeUserPerm = 0x0100,
41 ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010,
42 ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001,
43
44 //types
45 LinkType = 0x10000,
46 FileType = 0x20000,
47 DirectoryType = 0x40000,
48 BundleType = 0x80000,
49
50 //flags
51 HiddenFlag = 0x0100000,
52 LocalDiskFlag = 0x0200000,
53 ExistsFlag = 0x0400000,
54 RootFlag = 0x0800000,
55 Refresh = 0x1000000,
56
57 //masks
58 PermsMask = 0x0000FFFF,
59 TypesMask = 0x000F0000,
60 FlagsMask = 0x0FF00000,
61 FileInfoAll = FlagsMask | PermsMask | TypesMask
62 };
63 Q_DECLARE_FLAGS(FileFlags, FileFlag)
64
65 enum FileName {
66 DefaultName,
67 BaseName,
68 PathName,
69 AbsoluteName,
70 AbsolutePathName,
71 AbsoluteLinkTarget,
72 CanonicalName,
73 CanonicalPathName,
74 BundleName,
75 JunctionName,
76 RawLinkPath,
77 NFileNames // Must be last.
78 };
79 enum FileOwner {
80 OwnerUser,
81 OwnerGroup
82 };
83 enum FileTime {
84 AccessTime,
85 BirthTime,
86 MetadataChangeTime,
87 ModificationTime
88 };
89
90 virtual ~QAbstractFileEngine();
91
92 virtual bool open(QIODevice::OpenMode openMode,
93 std::optional<QFile::Permissions> permissions = std::nullopt);
94 virtual bool close();
95 virtual bool flush();
96 virtual bool syncToDisk();
97 virtual qint64 size() const;
98 virtual qint64 pos() const;
99 virtual bool seek(qint64 pos);
100 virtual bool isSequential() const;
101 virtual bool remove();
102 virtual bool copy(const QString &newName);
103 virtual bool rename(const QString &newName);
104 virtual bool renameOverwrite(const QString &newName);
105 virtual bool link(const QString &newName);
106 virtual bool mkdir(const QString &dirName, bool createParentDirectories,
107 std::optional<QFile::Permissions> permissions = std::nullopt) const;
108 virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const;
109 virtual bool setSize(qint64 size);
110 virtual bool caseSensitive() const;
111 virtual bool isRelativePath() const;
112 virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const;
113 virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const;
114 virtual bool setPermissions(uint perms);
115 virtual QByteArray id() const;
116 virtual QString fileName(FileName file=DefaultName) const;
117 virtual uint ownerId(FileOwner) const;
118 virtual QString owner(FileOwner) const;
119 virtual bool setFileTime(const QDateTime &newDate, FileTime time);
120 virtual QDateTime fileTime(FileTime time) const;
121 virtual void setFileName(const QString &file);
122 virtual int handle() const;
123 virtual bool cloneTo(QAbstractFileEngine *target);
124 bool atEnd() const;
125 uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
126 bool unmap(uchar *ptr);
127
128 typedef QAbstractFileEngineIterator Iterator;
129 virtual Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames);
130 virtual Iterator *endEntryList();
131
132 virtual qint64 read(char *data, qint64 maxlen);
133 virtual qint64 readLine(char *data, qint64 maxlen);
134 virtual qint64 write(const char *data, qint64 len);
135
136 QFile::FileError error() const;
137 QString errorString() const;
138
139 enum Extension {
140 AtEndExtension,
141 FastReadLineExtension,
142 MapExtension,
143 UnMapExtension
144 };
145 class ExtensionOption
146 {};
147 class ExtensionReturn
148 {};
149
150 class MapExtensionOption : public ExtensionOption {
151 public:
152 qint64 offset;
153 qint64 size;
154 QFile::MemoryMapFlags flags;
155 };
156 class MapExtensionReturn : public ExtensionReturn {
157 public:
158 uchar *address;
159 };
160
161 class UnMapExtensionOption : public ExtensionOption {
162 public:
163 uchar *address;
164 };
165
166 virtual bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr);
167 virtual bool supportsExtension(Extension extension) const;
168
169 // Factory
170 static QAbstractFileEngine *create(const QString &fileName);
171
172protected:
173 void setError(QFile::FileError error, const QString &str);
174
175 QAbstractFileEngine();
176 QAbstractFileEngine(QAbstractFileEnginePrivate &);
177
178 QScopedPointer<QAbstractFileEnginePrivate> d_ptr;
179private:
180 Q_DECLARE_PRIVATE(QAbstractFileEngine)
181 Q_DISABLE_COPY_MOVE(QAbstractFileEngine)
182};
183
184Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags)
185
186class Q_CORE_EXPORT QAbstractFileEngineHandler
187{
188public:
189 QAbstractFileEngineHandler();
190 virtual ~QAbstractFileEngineHandler();
191 virtual QAbstractFileEngine *create(const QString &fileName) const = 0;
192};
193
194class QAbstractFileEngineIteratorPrivate;
195class Q_CORE_EXPORT QAbstractFileEngineIterator
196{
197public:
198 QAbstractFileEngineIterator(QDir::Filters filters, const QStringList &nameFilters);
199 virtual ~QAbstractFileEngineIterator();
200
201 virtual QString next() = 0;
202 virtual bool hasNext() const = 0;
203
204 QString path() const;
205 QStringList nameFilters() const;
206 QDir::Filters filters() const;
207
208 virtual QString currentFileName() const = 0;
209 virtual QFileInfo currentFileInfo() const;
210 virtual QString currentFilePath() const;
211
212protected:
213 enum EntryInfoType {
214 };
215 virtual QVariant entryInfo(EntryInfoType type) const;
216
217private:
218 Q_DISABLE_COPY_MOVE(QAbstractFileEngineIterator)
219 friend class QDirIterator;
220 friend class QDirIteratorPrivate;
221 void setPath(const QString &path);
222 QScopedPointer<QAbstractFileEngineIteratorPrivate> d;
223};
224
225class QAbstractFileEnginePrivate
226{
227public:
228 inline QAbstractFileEnginePrivate()
229 : fileError(QFile::UnspecifiedError)
230 {
231 }
232 inline virtual ~QAbstractFileEnginePrivate() { }
233
234 QFile::FileError fileError;
235 QString errorString;
236
237 QAbstractFileEngine *q_ptr;
238 Q_DECLARE_PUBLIC(QAbstractFileEngine)
239};
240
241QAbstractFileEngine *qt_custom_file_engine_handler_create(const QString &path);
242
243QT_END_NAMESPACE
244
245#endif // QABSTRACTFILEENGINE_P_H
246

source code of qtbase/src/corelib/io/qabstractfileengine_p.h