| 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 | #include "QtCore/qdirlisting.h" | 
| 22 |  | 
| 23 | #include <memory> | 
| 24 | #include <optional> | 
| 25 |  | 
| 26 | #ifdef open | 
| 27 | #error qabstractfileengine_p.h must be included before any header file that defines open | 
| 28 | #endif | 
| 29 |  | 
| 30 | QT_BEGIN_NAMESPACE | 
| 31 |  | 
| 32 | class QVariant; | 
| 33 | class QAbstractFileEngineIterator; | 
| 34 | class QAbstractFileEnginePrivate; | 
| 35 |  | 
| 36 | class Q_CORE_EXPORT QAbstractFileEngine | 
| 37 | { | 
| 38 | public: | 
| 39 |     enum FileFlag { | 
| 40 |         //perms (overlaps the QFile::Permission) | 
| 41 |         ReadOwnerPerm = 0x4000, WriteOwnerPerm = 0x2000, ExeOwnerPerm = 0x1000, | 
| 42 |         ReadUserPerm  = 0x0400, WriteUserPerm  = 0x0200, ExeUserPerm  = 0x0100, | 
| 43 |         ReadGroupPerm = 0x0040, WriteGroupPerm = 0x0020, ExeGroupPerm = 0x0010, | 
| 44 |         ReadOtherPerm = 0x0004, WriteOtherPerm = 0x0002, ExeOtherPerm = 0x0001, | 
| 45 |  | 
| 46 |         //types | 
| 47 |         LinkType      = 0x10000, | 
| 48 |         FileType      = 0x20000, | 
| 49 |         DirectoryType = 0x40000, | 
| 50 |         BundleType    = 0x80000, | 
| 51 |  | 
| 52 |         //flags | 
| 53 |         HiddenFlag     = 0x0100000, | 
| 54 |         LocalDiskFlag  = 0x0200000, | 
| 55 |         ExistsFlag     = 0x0400000, | 
| 56 |         RootFlag       = 0x0800000, | 
| 57 |         Refresh        = 0x1000000, | 
| 58 |  | 
| 59 |         //masks | 
| 60 |         PermsMask  = 0x0000FFFF, | 
| 61 |         TypesMask  = 0x000F0000, | 
| 62 |         FlagsMask  = 0x0FF00000, | 
| 63 |         FileInfoAll = FlagsMask | PermsMask | TypesMask | 
| 64 |     }; | 
| 65 |     Q_DECLARE_FLAGS(FileFlags, FileFlag) | 
| 66 |  | 
| 67 |     enum FileName { | 
| 68 |         DefaultName, | 
| 69 |         BaseName, | 
| 70 |         PathName, | 
| 71 |         AbsoluteName, | 
| 72 |         AbsolutePathName, | 
| 73 |         AbsoluteLinkTarget, | 
| 74 |         CanonicalName, | 
| 75 |         CanonicalPathName, | 
| 76 |         BundleName, | 
| 77 |         JunctionName, | 
| 78 |         RawLinkPath, | 
| 79 |         NFileNames  // Must be last. | 
| 80 |     }; | 
| 81 |     enum FileOwner { | 
| 82 |         OwnerUser, | 
| 83 |         OwnerGroup | 
| 84 |     }; | 
| 85 |  | 
| 86 |  | 
| 87 |     virtual ~QAbstractFileEngine(); | 
| 88 |  | 
| 89 |     virtual bool open(QIODevice::OpenMode openMode, | 
| 90 |                       std::optional<QFile::Permissions> permissions = std::nullopt); | 
| 91 |     virtual bool close(); | 
| 92 |     virtual bool flush(); | 
| 93 |     virtual bool syncToDisk(); | 
| 94 |     virtual qint64 size() const; | 
| 95 |     virtual qint64 pos() const; | 
| 96 |     virtual bool seek(qint64 pos); | 
| 97 |     virtual bool isSequential() const; | 
| 98 |     virtual bool remove(); | 
| 99 |     virtual bool copy(const QString &newName); | 
| 100 |     virtual bool rename(const QString &newName); | 
| 101 |     virtual bool renameOverwrite(const QString &newName); | 
| 102 |     virtual bool link(const QString &newName); | 
| 103 |     virtual bool mkdir(const QString &dirName, bool createParentDirectories, | 
| 104 |                        std::optional<QFile::Permissions> permissions = std::nullopt) const; | 
| 105 |     virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const; | 
| 106 |     virtual bool setSize(qint64 size); | 
| 107 |     virtual bool caseSensitive() const; | 
| 108 |     virtual bool isRelativePath() const; | 
| 109 |     virtual QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const; | 
| 110 |     virtual QStringList entryList(QDirListing::IteratorFlags filters, | 
| 111 |                                   const QStringList &filterNames) const; | 
| 112 |     virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const; | 
| 113 |     virtual bool setPermissions(uint perms); | 
| 114 |     virtual QByteArray id() const; | 
| 115 |     virtual QString fileName(FileName file=DefaultName) const; | 
| 116 |     virtual uint ownerId(FileOwner) const; | 
| 117 |     virtual QString owner(FileOwner) const; | 
| 118 |     virtual bool setFileTime(const QDateTime &newDate, QFile::FileTime time); | 
| 119 |     virtual QDateTime fileTime(QFile::FileTime time) const; | 
| 120 |     virtual void setFileName(const QString &file); | 
| 121 |     virtual int handle() const; | 
| 122 |     virtual bool cloneTo(QAbstractFileEngine *target); | 
| 123 |     bool atEnd() const; | 
| 124 |     uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags); | 
| 125 |     bool unmap(uchar *ptr); | 
| 126 |  | 
| 127 |     typedef QAbstractFileEngineIterator Iterator; | 
| 128 |     using IteratorUniquePtr = std::unique_ptr<Iterator>; | 
| 129 |  | 
| 130 |     virtual IteratorUniquePtr endEntryList() { return {}; } | 
| 131 |     virtual IteratorUniquePtr | 
| 132 |     beginEntryList(const QString &path, QDirListing::IteratorFlags filters, | 
| 133 |                    const QStringList &filterNames); | 
| 134 |  | 
| 135 |     virtual qint64 read(char *data, qint64 maxlen); | 
| 136 |     virtual qint64 readLine(char *data, qint64 maxlen); | 
| 137 |     virtual qint64 write(const char *data, qint64 len); | 
| 138 |  | 
| 139 |     QFile::FileError error() const; | 
| 140 |     QString errorString() const; | 
| 141 |  | 
| 142 |     enum Extension { | 
| 143 |         AtEndExtension, | 
| 144 |         FastReadLineExtension, | 
| 145 |         MapExtension, | 
| 146 |         UnMapExtension | 
| 147 |     }; | 
| 148 |     class ExtensionOption | 
| 149 |     {}; | 
| 150 |     class ExtensionReturn | 
| 151 |     {}; | 
| 152 |  | 
| 153 |     class MapExtensionOption : public ExtensionOption { | 
| 154 |         Q_DISABLE_COPY_MOVE(MapExtensionOption) | 
| 155 |     public: | 
| 156 |         qint64 offset; | 
| 157 |         qint64 size; | 
| 158 |         QFile::MemoryMapFlags flags; | 
| 159 |         constexpr MapExtensionOption(qint64 off, qint64 sz, QFile::MemoryMapFlags f) | 
| 160 |             : offset(off), size(sz), flags(f) {} | 
| 161 |     }; | 
| 162 |     class MapExtensionReturn : public ExtensionReturn { | 
| 163 |         Q_DISABLE_COPY_MOVE(MapExtensionReturn) | 
| 164 |     public: | 
| 165 |         MapExtensionReturn() = default; | 
| 166 |         uchar *address = nullptr; | 
| 167 |     }; | 
| 168 |  | 
| 169 |     class UnMapExtensionOption : public ExtensionOption { | 
| 170 |         Q_DISABLE_COPY_MOVE(UnMapExtensionOption) | 
| 171 |     public: | 
| 172 |         uchar *address = nullptr; | 
| 173 |         constexpr UnMapExtensionOption(uchar *p) : address(p) {} | 
| 174 |     }; | 
| 175 |  | 
| 176 |     virtual bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr); | 
| 177 |     virtual bool supportsExtension(Extension extension) const; | 
| 178 |  | 
| 179 |     // Factory | 
| 180 |     static std::unique_ptr<QAbstractFileEngine> create(const QString &fileName); | 
| 181 |  | 
| 182 | protected: | 
| 183 |     void setError(QFile::FileError error, const QString &str); | 
| 184 |  | 
| 185 |     QAbstractFileEngine(); | 
| 186 |     QAbstractFileEngine(QAbstractFileEnginePrivate &); | 
| 187 |  | 
| 188 |     QScopedPointer<QAbstractFileEnginePrivate> d_ptr; | 
| 189 | private: | 
| 190 |     Q_DECLARE_PRIVATE(QAbstractFileEngine) | 
| 191 |     Q_DISABLE_COPY_MOVE(QAbstractFileEngine) | 
| 192 | }; | 
| 193 |  | 
| 194 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractFileEngine::FileFlags) | 
| 195 |  | 
| 196 | class Q_CORE_EXPORT QAbstractFileEngineHandler | 
| 197 | { | 
| 198 |     Q_DISABLE_COPY_MOVE(QAbstractFileEngineHandler) | 
| 199 | public: | 
| 200 |     QAbstractFileEngineHandler(); | 
| 201 |     virtual ~QAbstractFileEngineHandler(); | 
| 202 |     virtual std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const = 0; | 
| 203 | }; | 
| 204 |  | 
| 205 | class Q_CORE_EXPORT QAbstractFileEngineIterator | 
| 206 | { | 
| 207 | public: | 
| 208 |     QAbstractFileEngineIterator(const QString &path, QDir::Filters filters, | 
| 209 |                                 const QStringList &nameFilters); | 
| 210 |     QAbstractFileEngineIterator(const QString &path, QDirListing::IteratorFlags filters, | 
| 211 |                                 const QStringList &nameFilters); | 
| 212 |     virtual ~QAbstractFileEngineIterator(); | 
| 213 |  | 
| 214 |     virtual bool advance() = 0; | 
| 215 |  | 
| 216 |     QString path() const; | 
| 217 |     QStringList nameFilters() const; | 
| 218 |     QDir::Filters filters() const; | 
| 219 |  | 
| 220 |     virtual QString currentFileName() const = 0; | 
| 221 |     virtual QFileInfo currentFileInfo() const; | 
| 222 |     virtual QString currentFilePath() const; | 
| 223 |  | 
| 224 | protected: | 
| 225 |     mutable QFileInfo m_fileInfo; | 
| 226 |  | 
| 227 | private: | 
| 228 |     Q_DISABLE_COPY_MOVE(QAbstractFileEngineIterator) | 
| 229 |     friend class QDirIterator; | 
| 230 |     friend class QDirIteratorPrivate; | 
| 231 |     friend class QDirListingPrivate; | 
| 232 |  | 
| 233 |     QDir::Filters m_filters; | 
| 234 |     QDirListing::IteratorFlags m_listingFilters; | 
| 235 |     QStringList m_nameFilters; | 
| 236 |     QString m_path; | 
| 237 | }; | 
| 238 |  | 
| 239 | class QAbstractFileEnginePrivate | 
| 240 | { | 
| 241 | public: | 
| 242 |     inline QAbstractFileEnginePrivate() | 
| 243 |         : fileError(QFile::UnspecifiedError) | 
| 244 |     { | 
| 245 |     } | 
| 246 |     virtual ~QAbstractFileEnginePrivate(); | 
| 247 |  | 
| 248 |     QFile::FileError fileError; | 
| 249 |     QString errorString; | 
| 250 |  | 
| 251 |     QAbstractFileEngine *q_ptr; | 
| 252 |     Q_DECLARE_PUBLIC(QAbstractFileEngine) | 
| 253 | }; | 
| 254 |  | 
| 255 | std::unique_ptr<QAbstractFileEngine> qt_custom_file_engine_handler_create(const QString &path); | 
| 256 |  | 
| 257 | QT_END_NAMESPACE | 
| 258 |  | 
| 259 | #endif // QABSTRACTFILEENGINE_P_H | 
| 260 |  |