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 | |
48 | QT_BEGIN_NAMESPACE |
49 | |
50 | |
51 | class QDir; |
52 | class QDirIteratorPrivate; |
53 | class QDateTime; |
54 | class QFileInfoPrivate; |
55 | |
56 | class Q_CORE_EXPORT QFileInfo |
57 | { |
58 | friend class QDirIteratorPrivate; |
59 | public: |
60 | explicit QFileInfo(QFileInfoPrivate *d); |
61 | |
62 | QFileInfo(); |
63 | QFileInfo(const QString &file); |
64 | QFileInfo(const QFile &file); |
65 | QFileInfo(const QDir &dir, const QString &file); |
66 | QFileInfo(const QFileInfo &fileinfo); |
67 | ~QFileInfo(); |
68 | |
69 | QFileInfo &operator=(const QFileInfo &fileinfo); |
70 | QFileInfo &operator=(QFileInfo &&other) noexcept { swap(other); return *this; } |
71 | |
72 | void swap(QFileInfo &other) noexcept |
73 | { qSwap(value1&: d_ptr, value2&: other.d_ptr); } |
74 | |
75 | bool operator==(const QFileInfo &fileinfo) const; |
76 | inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); } |
77 | |
78 | void setFile(const QString &file); |
79 | void setFile(const QFile &file); |
80 | void setFile(const QDir &dir, const QString &file); |
81 | bool exists() const; |
82 | static bool exists(const QString &file); |
83 | void refresh(); |
84 | |
85 | QString filePath() const; |
86 | QString absoluteFilePath() const; |
87 | QString canonicalFilePath() const; |
88 | QString fileName() const; |
89 | QString baseName() const; |
90 | QString completeBaseName() const; |
91 | QString suffix() const; |
92 | QString bundleName() const; |
93 | QString completeSuffix() const; |
94 | |
95 | QString path() const; |
96 | QString absolutePath() const; |
97 | QString canonicalPath() const; |
98 | QDir dir() const; |
99 | QDir absoluteDir() const; |
100 | |
101 | bool isReadable() const; |
102 | bool isWritable() const; |
103 | bool isExecutable() const; |
104 | bool isHidden() const; |
105 | bool isNativePath() const; |
106 | |
107 | bool isRelative() const; |
108 | inline bool isAbsolute() const { return !isRelative(); } |
109 | bool makeAbsolute(); |
110 | |
111 | bool isFile() const; |
112 | bool isDir() const; |
113 | bool isSymLink() const; |
114 | bool isSymbolicLink() const; |
115 | bool isShortcut() const; |
116 | bool isJunction() const; |
117 | bool isRoot() const; |
118 | bool isBundle() const; |
119 | |
120 | #if QT_DEPRECATED_SINCE(5, 13) |
121 | QT_DEPRECATED_X("Use QFileInfo::symLinkTarget() instead" ) |
122 | QString readLink() const; |
123 | #endif |
124 | QString symLinkTarget() const; |
125 | |
126 | QString owner() const; |
127 | uint ownerId() const; |
128 | QString group() const; |
129 | uint groupId() const; |
130 | |
131 | bool permission(QFile::Permissions permissions) const; |
132 | QFile::Permissions permissions() const; |
133 | |
134 | qint64 size() const; |
135 | |
136 | // ### Qt6: inline these functions |
137 | #if QT_DEPRECATED_SINCE(5, 10) |
138 | QT_DEPRECATED_X("Use either birthTime() or metadataChangeTime()" ) |
139 | QDateTime created() const; |
140 | #endif |
141 | QDateTime birthTime() const; |
142 | QDateTime metadataChangeTime() const; |
143 | QDateTime lastModified() const; |
144 | QDateTime lastRead() const; |
145 | QDateTime fileTime(QFile::FileTime time) const; |
146 | |
147 | bool caching() const; |
148 | void setCaching(bool on); |
149 | |
150 | protected: |
151 | QSharedDataPointer<QFileInfoPrivate> d_ptr; |
152 | |
153 | private: |
154 | friend class QFileInfoGatherer; |
155 | void stat(); |
156 | QFileInfoPrivate* d_func(); |
157 | inline const QFileInfoPrivate* d_func() const |
158 | { |
159 | return d_ptr.constData(); |
160 | } |
161 | }; |
162 | |
163 | Q_DECLARE_SHARED(QFileInfo) |
164 | |
165 | typedef QList<QFileInfo> QFileInfoList; |
166 | |
167 | #ifndef QT_NO_DEBUG_STREAM |
168 | Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &); |
169 | #endif |
170 | |
171 | QT_END_NAMESPACE |
172 | |
173 | Q_DECLARE_METATYPE(QFileInfo) |
174 | |
175 | #endif // QFILEINFO_H |
176 | |