1 | // Copyright (C) 2020 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 QFILEINFO_H |
5 | #define QFILEINFO_H |
6 | |
7 | #include <QtCore/qfile.h> |
8 | #include <QtCore/qlist.h> |
9 | #include <QtCore/qshareddata.h> |
10 | #include <QtCore/qmetatype.h> |
11 | #include <QtCore/qdatetime.h> |
12 | #include <QtCore/qtimezone.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | |
17 | class QDir; |
18 | class QDirIteratorPrivate; |
19 | class QFileInfoPrivate; |
20 | |
21 | class Q_CORE_EXPORT QFileInfo |
22 | { |
23 | friend class QDirIteratorPrivate; |
24 | public: |
25 | explicit QFileInfo(QFileInfoPrivate *d); |
26 | |
27 | #ifdef QT_IMPLICIT_QFILEINFO_CONSTRUCTION |
28 | #define QFILEINFO_MAYBE_EXPLICIT Q_IMPLICIT |
29 | #else |
30 | #define QFILEINFO_MAYBE_EXPLICIT explicit |
31 | #endif |
32 | |
33 | QFileInfo(); |
34 | QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QString &file); |
35 | QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QFileDevice &file); |
36 | QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const QString &file); |
37 | QFileInfo(const QFileInfo &fileinfo); |
38 | #ifdef Q_QDOC |
39 | QFileInfo(const std::filesystem::path &file); |
40 | QFileInfo(const QDir &dir, const std::filesystem::path &file); |
41 | #elif QT_CONFIG(cxx17_filesystem) |
42 | template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> |
43 | QFILEINFO_MAYBE_EXPLICIT QFileInfo(const T &file) : QFileInfo(QtPrivate::fromFilesystemPath(path: file)) { } |
44 | |
45 | template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> |
46 | QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const T &file) : QFileInfo(dir, QtPrivate::fromFilesystemPath(path: file)) |
47 | { |
48 | } |
49 | #endif // QT_CONFIG(cxx17_filesystem) |
50 | |
51 | #undef QFILEINFO_MAYBE_EXPLICIT |
52 | |
53 | ~QFileInfo(); |
54 | |
55 | QFileInfo &operator=(const QFileInfo &fileinfo); |
56 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo) |
57 | |
58 | void swap(QFileInfo &other) noexcept |
59 | { d_ptr.swap(other&: other.d_ptr); } |
60 | |
61 | bool operator==(const QFileInfo &fileinfo) const; |
62 | inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); } |
63 | |
64 | void setFile(const QString &file); |
65 | void setFile(const QFileDevice &file); |
66 | void setFile(const QDir &dir, const QString &file); |
67 | #ifdef Q_QDOC |
68 | void setFile(const std::filesystem::path &file); |
69 | #elif QT_CONFIG(cxx17_filesystem) |
70 | template<typename T, QtPrivate::ForceFilesystemPath<T> = 0> |
71 | void setFile(const T &file) { setFile(QtPrivate::fromFilesystemPath(path: file)); } |
72 | #endif // QT_CONFIG(cxx17_filesystem) |
73 | |
74 | bool exists() const; |
75 | static bool exists(const QString &file); |
76 | void refresh(); |
77 | |
78 | QString filePath() const; |
79 | QString absoluteFilePath() const; |
80 | QString canonicalFilePath() const; |
81 | #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC) |
82 | std::filesystem::path filesystemFilePath() const |
83 | { return QtPrivate::toFilesystemPath(path: filePath()); } |
84 | std::filesystem::path filesystemAbsoluteFilePath() const |
85 | { return QtPrivate::toFilesystemPath(path: absoluteFilePath()); } |
86 | std::filesystem::path filesystemCanonicalFilePath() const |
87 | { return QtPrivate::toFilesystemPath(path: canonicalFilePath()); } |
88 | #endif // QT_CONFIG(cxx17_filesystem) |
89 | QString fileName() const; |
90 | QString baseName() const; |
91 | QString completeBaseName() const; |
92 | QString suffix() const; |
93 | QString bundleName() const; |
94 | QString completeSuffix() const; |
95 | |
96 | QString path() const; |
97 | QString absolutePath() const; |
98 | QString canonicalPath() const; |
99 | #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC) |
100 | std::filesystem::path filesystemPath() const { return QtPrivate::toFilesystemPath(path: path()); } |
101 | std::filesystem::path filesystemAbsolutePath() const |
102 | { return QtPrivate::toFilesystemPath(path: absolutePath()); } |
103 | std::filesystem::path filesystemCanonicalPath() const |
104 | { return QtPrivate::toFilesystemPath(path: canonicalPath()); } |
105 | #endif // QT_CONFIG(cxx17_filesystem) |
106 | QDir dir() const; |
107 | QDir absoluteDir() const; |
108 | |
109 | bool isReadable() const; |
110 | bool isWritable() const; |
111 | bool isExecutable() const; |
112 | bool isHidden() const; |
113 | bool isNativePath() const; |
114 | |
115 | bool isRelative() const; |
116 | inline bool isAbsolute() const { return !isRelative(); } |
117 | bool makeAbsolute(); |
118 | |
119 | bool isFile() const; |
120 | bool isDir() const; |
121 | bool isSymLink() const; |
122 | bool isSymbolicLink() const; |
123 | bool isShortcut() const; |
124 | bool isAlias() const; |
125 | bool isJunction() const; |
126 | bool isRoot() const; |
127 | bool isBundle() const; |
128 | |
129 | QString symLinkTarget() const; |
130 | QString readSymLink() const; |
131 | QString junctionTarget() const; |
132 | |
133 | #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC) |
134 | std::filesystem::path filesystemSymLinkTarget() const |
135 | { return QtPrivate::toFilesystemPath(path: symLinkTarget()); } |
136 | |
137 | std::filesystem::path filesystemReadSymLink() const |
138 | { return QtPrivate::toFilesystemPath(path: readSymLink()); } |
139 | |
140 | std::filesystem::path filesystemJunctionTarget() const |
141 | { return QtPrivate::toFilesystemPath(path: junctionTarget()); } |
142 | #endif // QT_CONFIG(cxx17_filesystem) |
143 | |
144 | QString owner() const; |
145 | uint ownerId() const; |
146 | QString group() const; |
147 | uint groupId() const; |
148 | |
149 | bool permission(QFile::Permissions permissions) const; |
150 | QFile::Permissions permissions() const; |
151 | |
152 | qint64 size() const; |
153 | |
154 | QDateTime birthTime() const { return fileTime(time: QFile::FileBirthTime); } |
155 | QDateTime metadataChangeTime() const { return fileTime(time: QFile::FileMetadataChangeTime); } |
156 | QDateTime lastModified() const { return fileTime(time: QFile::FileModificationTime); } |
157 | QDateTime lastRead() const { return fileTime(time: QFile::FileAccessTime); } |
158 | QDateTime fileTime(QFile::FileTime time) const; |
159 | |
160 | QDateTime birthTime(const QTimeZone &tz) const { return fileTime(time: QFile::FileBirthTime, tz); } |
161 | QDateTime metadataChangeTime(const QTimeZone &tz) const { return fileTime(time: QFile::FileMetadataChangeTime, tz); } |
162 | QDateTime lastModified(const QTimeZone &tz) const { return fileTime(time: QFile::FileModificationTime, tz); } |
163 | QDateTime lastRead(const QTimeZone &tz) const { return fileTime(time: QFile::FileAccessTime, tz); } |
164 | QDateTime fileTime(QFile::FileTime time, const QTimeZone &tz) const; |
165 | |
166 | bool caching() const; |
167 | void setCaching(bool on); |
168 | void stat(); |
169 | |
170 | protected: |
171 | QSharedDataPointer<QFileInfoPrivate> d_ptr; |
172 | |
173 | private: |
174 | QFileInfoPrivate* d_func(); |
175 | inline const QFileInfoPrivate* d_func() const |
176 | { |
177 | return d_ptr.constData(); |
178 | } |
179 | }; |
180 | |
181 | Q_DECLARE_SHARED(QFileInfo) |
182 | |
183 | typedef QList<QFileInfo> QFileInfoList; |
184 | |
185 | #ifndef QT_NO_DEBUG_STREAM |
186 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &); |
187 | #endif |
188 | |
189 | QT_END_NAMESPACE |
190 | |
191 | QT_DECL_METATYPE_EXTERN(QFileInfo, Q_CORE_EXPORT) |
192 | |
193 | #endif // QFILEINFO_H |
194 | |