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 QDIR_P_H |
5 | #define QDIR_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 "qfilesystementry_p.h" |
19 | #include "qfilesystemmetadata_p.h" |
20 | |
21 | #include <QtCore/qmutex.h> |
22 | |
23 | #include <memory> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | class QDirPrivate : public QSharedData |
28 | { |
29 | public: |
30 | enum PathNormalization { |
31 | DefaultNormalization = 0x00, |
32 | AllowUncPaths = 0x01, |
33 | RemotePath = 0x02, |
34 | KeepLocalTrailingSlash = 0x04, |
35 | }; |
36 | Q_DECLARE_FLAGS(PathNormalizations, PathNormalization) |
37 | Q_FLAGS(PathNormalizations) |
38 | |
39 | explicit QDirPrivate(const QString &path, const QStringList &nameFilters_ = QStringList(), |
40 | QDir::SortFlags sort_ = QDir::SortFlags(QDir::Name | QDir::IgnoreCase), |
41 | QDir::Filters filters_ = QDir::AllEntries); |
42 | |
43 | explicit QDirPrivate(const QDirPrivate ©); // Copies everything except mutex and fileEngine |
44 | |
45 | bool exists() const; |
46 | |
47 | void initFileLists(const QDir &dir) const; |
48 | |
49 | static void sortFileList(QDir::SortFlags, const QFileInfoList &, QStringList *, QFileInfoList *); |
50 | |
51 | static inline QChar getFilterSepChar(const QString &nameFilter); |
52 | |
53 | static inline QStringList splitFilters(const QString &nameFilter, QChar sep = {}); |
54 | |
55 | void setPath(const QString &path); |
56 | |
57 | enum MetaDataClearing { KeepMetaData, IncludingMetaData }; |
58 | void clearCache(MetaDataClearing mode); |
59 | |
60 | QString resolveAbsoluteEntry() const; |
61 | |
62 | QStringList nameFilters; |
63 | QDir::SortFlags sort; |
64 | QDir::Filters filters; |
65 | |
66 | std::unique_ptr<QAbstractFileEngine> fileEngine; |
67 | |
68 | QFileSystemEntry dirEntry; |
69 | |
70 | struct FileCache |
71 | { |
72 | QMutex mutex; |
73 | QStringList files; |
74 | QFileInfoList fileInfos; |
75 | std::atomic<bool> fileListsInitialized = false; |
76 | QFileSystemEntry absoluteDirEntry; |
77 | QFileSystemMetaData metaData; |
78 | }; |
79 | mutable FileCache fileCache; |
80 | }; |
81 | |
82 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDirPrivate::PathNormalizations) |
83 | |
84 | Q_AUTOTEST_EXPORT bool qt_normalizePathSegments(QString *path, QDirPrivate::PathNormalizations flags); |
85 | |
86 | QT_END_NAMESPACE |
87 | |
88 | #endif |
89 | |