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