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