Qt 4.8
qfileinfo.h
Go to the documentation of this file.
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 
50 
52 
53 QT_MODULE(Core)
54 
55 class QDir;
57 class QDateTime;
58 class QFileInfoPrivate;
59 
61 {
62  friend class QDirIteratorPrivate;
63 public:
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 
176 protected:
178 private:
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 
192 
193 #ifdef QT3_SUPPORT
194 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileInfo::PermissionSpec)
195 #endif
196 
198 #ifdef QT3_SUPPORT
199 typedef QList<QFileInfo>::Iterator QFileInfoListIterator;
200 #endif
201 
203 
205 
206 #endif // QFILEINFO_H
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
const QFileInfoPrivate * d_func() const
Definition: qfileinfo.h:185
bool operator!=(const QFileInfo &fileinfo)
Returns true if this QFileInfo object refers to a different file than the one specified by fileinfo; ...
Definition: qfileinfo.h:80
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QList< QFileInfo > QFileInfoList
Definition: qfileinfo.h:197
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
bool isAbsolute() const
Returns true if the file path name is absolute, otherwise returns false if the path is relative...
Definition: qfileinfo.h:111
QSharedDataPointer< QFileInfoPrivate > d_ptr
Definition: qfileinfo.h:177
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QWidget * owner
QFileInfoPrivate * d_func()
Definition: qfileinfo.h:179
static QString readLink(const QFileSystemEntry &link)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
Q_DECLARE_TYPEINFO(QFileInfo, Q_MOVABLE_TYPE)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
unsigned int uint
Definition: qglobal.h:996
__int64 qint64
Definition: qglobal.h:942
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
QByteArray suffix
QString symLinkTarget() const
Returns the absolute path to the file or directory a symlink (or shortcut on Windows) points to...
Definition: qfileinfo.h:121
bool operator!=(const QFileInfo &fileinfo) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qfileinfo.h:81
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
#define QT_END_HEADER
Definition: qglobal.h:137
static QString fileName(const QString &fileUrl)
bool operator==(QBool b1, bool b2)
Definition: qglobal.h:2023