1/****************************************************************************
2**
3** Copyright (C) 2016 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
48QT_BEGIN_NAMESPACE
49
50
51class QDir;
52class QDirIteratorPrivate;
53class QDateTime;
54class QFileInfoPrivate;
55
56class Q_CORE_EXPORT QFileInfo
57{
58 friend class QDirIteratorPrivate;
59public:
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(d_ptr, 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 isRoot() const;
115 bool isBundle() const;
116
117#if QT_DEPRECATED_SINCE(5, 13)
118 QT_DEPRECATED_X("Use QFileInfo::symLinkTarget() instead")
119 QString readLink() const;
120#endif
121 QString symLinkTarget() const;
122
123 QString owner() const;
124 uint ownerId() const;
125 QString group() const;
126 uint groupId() const;
127
128 bool permission(QFile::Permissions permissions) const;
129 QFile::Permissions permissions() const;
130
131 qint64 size() const;
132
133 // ### Qt6: inline these functions
134#if QT_DEPRECATED_SINCE(5, 10)
135 QT_DEPRECATED_X("Use either birthTime() or metadataChangeTime()")
136 QDateTime created() const;
137#endif
138 QDateTime birthTime() const;
139 QDateTime metadataChangeTime() const;
140 QDateTime lastModified() const;
141 QDateTime lastRead() const;
142 QDateTime fileTime(QFile::FileTime time) const;
143
144 bool caching() const;
145 void setCaching(bool on);
146
147protected:
148 QSharedDataPointer<QFileInfoPrivate> d_ptr;
149
150private:
151 QFileInfoPrivate* d_func();
152 inline const QFileInfoPrivate* d_func() const
153 {
154 return d_ptr.constData();
155 }
156};
157
158Q_DECLARE_SHARED(QFileInfo)
159
160typedef QList<QFileInfo> QFileInfoList;
161
162#ifndef QT_NO_DEBUG_STREAM
163Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &);
164#endif
165
166QT_END_NAMESPACE
167
168Q_DECLARE_METATYPE(QFileInfo)
169
170#endif // QFILEINFO_H
171