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