1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QFILEINFO_H
43#define QFILEINFO_H
44
45#include <QtCore/qfile.h>
46#include <QtCore/qlist.h>
47#include <QtCore/qshareddata.h>
48
49QT_BEGIN_HEADER
50
51QT_BEGIN_NAMESPACE
52
53QT_MODULE(Core)
54
55class QDir;
56class QDirIteratorPrivate;
57class QDateTime;
58class QFileInfoPrivate;
59
60class Q_CORE_EXPORT QFileInfo
61{
62 friend class QDirIteratorPrivate;
63public:
64 explicit QFileInfo(QFileInfoPrivate *d);
65
66 QFileInfo();
67 QFileInfo(const QString &file);
68 QFileInfo(const QFile &file);
69 QFileInfo(const QDir &dir, const QString &file);
70 QFileInfo(const QFileInfo &fileinfo);
71 ~QFileInfo();
72
73 QFileInfo &operator=(const QFileInfo &fileinfo);
74#ifdef Q_COMPILER_RVALUE_REFS
75 inline QFileInfo&operator=(QFileInfo &&other)
76 { qSwap(d_ptr, other.d_ptr); return *this; }
77#endif
78 bool operator==(const QFileInfo &fileinfo); // 5.0 - remove me
79 bool operator==(const QFileInfo &fileinfo) const;
80 inline bool operator!=(const QFileInfo &fileinfo) { return !(operator==(fileinfo)); } // 5.0 - remove me
81 inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }
82
83 void setFile(const QString &file);
84 void setFile(const QFile &file);
85 void setFile(const QDir &dir, const QString &file);
86 bool exists() const;
87 void refresh();
88
89 QString filePath() const;
90 QString absoluteFilePath() const;
91 QString canonicalFilePath() const;
92 QString fileName() const;
93 QString baseName() const;
94 QString completeBaseName() const;
95 QString suffix() const;
96 QString bundleName() const;
97 QString completeSuffix() const;
98
99 QString path() const;
100 QString absolutePath() const;
101 QString canonicalPath() const;
102 QDir dir() const;
103 QDir absoluteDir() const;
104
105 bool isReadable() const;
106 bool isWritable() const;
107 bool isExecutable() const;
108 bool isHidden() const;
109
110 bool isRelative() const;
111 inline bool isAbsolute() const { return !isRelative(); }
112 bool makeAbsolute();
113
114 bool isFile() const;
115 bool isDir() const;
116 bool isSymLink() const;
117 bool isRoot() const;
118 bool isBundle() const;
119
120 QString readLink() const;
121 inline QString symLinkTarget() const { return readLink(); }
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 QDateTime created() const;
134 QDateTime lastModified() const;
135 QDateTime lastRead() const;
136
137 void detach();
138
139 bool caching() const;
140 void setCaching(bool on);
141
142#ifdef QT3_SUPPORT
143 enum Permission {
144 ReadOwner = QFile::ReadOwner, WriteOwner = QFile::WriteOwner, ExeOwner = QFile::ExeOwner,
145 ReadUser = QFile::ReadUser, WriteUser = QFile::WriteUser, ExeUser = QFile::ExeUser,
146 ReadGroup = QFile::ReadGroup, WriteGroup = QFile::WriteGroup, ExeGroup = QFile::ExeGroup,
147 ReadOther = QFile::ReadOther, WriteOther = QFile::WriteOther, ExeOther = QFile::ExeOther
148 };
149 Q_DECLARE_FLAGS(PermissionSpec, Permission)
150
151 inline QT3_SUPPORT QString baseName(bool complete) {
152 if(complete)
153 return completeBaseName();
154 return baseName();
155 }
156 inline QT3_SUPPORT QString extension(bool complete = true) const {
157 if(complete)
158 return completeSuffix();
159 return suffix();
160 }
161 inline QT3_SUPPORT QString absFilePath() const { return absoluteFilePath(); }
162
163 inline QT3_SUPPORT QString dirPath(bool absPath = false) const {
164 if(absPath)
165 return absolutePath();
166 return path();
167 }
168 QT3_SUPPORT QDir dir(bool absPath) const;
169 inline QT3_SUPPORT bool convertToAbs() { return makeAbsolute(); }
170#if !defined(Q_NO_TYPESAFE_FLAGS)
171 inline QT3_SUPPORT bool permission(PermissionSpec permissions) const
172 { return permission(QFile::Permissions(static_cast<int>(permissions))); }
173#endif
174#endif
175
176protected:
177 QSharedDataPointer<QFileInfoPrivate> d_ptr;
178private:
179 inline QFileInfoPrivate* d_func()
180 {
181 detach();
182 return const_cast<QFileInfoPrivate *>(d_ptr.constData());
183 }
184
185 inline const QFileInfoPrivate* d_func() const
186 {
187 return d_ptr.constData();
188 }
189};
190
191Q_DECLARE_TYPEINFO(QFileInfo, Q_MOVABLE_TYPE);
192
193#ifdef QT3_SUPPORT
194Q_DECLARE_OPERATORS_FOR_FLAGS(QFileInfo::PermissionSpec)
195#endif
196
197typedef QList<QFileInfo> QFileInfoList;
198#ifdef QT3_SUPPORT
199typedef QList<QFileInfo>::Iterator QFileInfoListIterator;
200#endif
201
202QT_END_NAMESPACE
203
204QT_END_HEADER
205
206#endif // QFILEINFO_H
207