author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qplatformdefs.h" |
|
43 |
#include "qfileinfo.h" |
|
44 |
#include "qglobal.h" |
|
45 |
#include "qdir.h" |
|
46 |
#include "qfileinfo_p.h" |
|
47 |
||
48 |
QT_BEGIN_NAMESPACE |
|
49 |
||
50 |
QFileInfoPrivate::QFileInfoPrivate(const QFileInfo *copy) |
|
51 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
52 |
if (copy) { |
0 | 53 |
copy->d_func()->data->ref.ref(); |
54 |
data = copy->d_func()->data; |
|
55 |
} else { |
|
56 |
data = new QFileInfoPrivate::Data; |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
QFileInfoPrivate::~QFileInfoPrivate() |
|
61 |
{ |
|
62 |
if (!data->ref.deref()) |
|
63 |
delete data; |
|
64 |
data = 0; |
|
65 |
} |
|
66 |
||
67 |
void QFileInfoPrivate::initFileEngine(const QString &file) |
|
68 |
{ |
|
69 |
detach(); |
|
70 |
delete data->fileEngine; |
|
71 |
data->fileEngine = 0; |
|
72 |
data->clear(); |
|
73 |
data->fileEngine = QAbstractFileEngine::create(file); |
|
74 |
data->fileName = file; |
|
75 |
} |
|
76 |
||
77 |
void QFileInfoPrivate::detach() |
|
78 |
{ |
|
79 |
qAtomicDetach(data); |
|
80 |
} |
|
81 |
||
82 |
QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const |
|
83 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
84 |
if (data->cache_enabled && !data->fileNames[(int)name].isNull()) |
0 | 85 |
return data->fileNames[(int)name]; |
86 |
QString ret = data->fileEngine->fileName(name); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
87 |
if (ret.isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
88 |
ret = QLatin1String(""); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
89 |
if (data->cache_enabled) |
0 | 90 |
data->fileNames[(int)name] = ret; |
91 |
return ret; |
|
92 |
} |
|
93 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
94 |
QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
95 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
96 |
if (data->cache_enabled && !data->fileOwners[(int)own].isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
97 |
return data->fileOwners[(int)own]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
98 |
QString ret = data->fileEngine->owner(own); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
99 |
if (ret.isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
100 |
ret = QLatin1String(""); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
101 |
if (data->cache_enabled) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
102 |
data->fileOwners[(int)own] = ret; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
103 |
return ret; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
104 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
105 |
|
0 | 106 |
uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const |
107 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
108 |
// We split the testing into tests for for LinkType, BundleType, PermsMask |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
109 |
// and the rest. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
110 |
// Tests for file permissions on Windows can be slow, expecially on network |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
111 |
// paths and NTFS drives. |
0 | 112 |
// In order to determine if a file is a symlink or not, we have to lstat(). |
113 |
// If we're not interested in that information, we might as well avoid one |
|
114 |
// extra syscall. Bundle detecton on Mac can be slow, expecially on network |
|
115 |
// paths, so we separate out that as well. |
|
116 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
117 |
QAbstractFileEngine::FileFlags req = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
118 |
uint cachedFlags = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
119 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
120 |
if (request & (QAbstractFileEngine::FlagsMask | QAbstractFileEngine::TypesMask)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
121 |
if (!data->getCachedFlag(CachedFileFlags)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
122 |
req |= QAbstractFileEngine::FlagsMask; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
123 |
req |= QAbstractFileEngine::TypesMask; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
124 |
req &= (~QAbstractFileEngine::LinkType); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
125 |
req &= (~QAbstractFileEngine::BundleType); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
126 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
127 |
cachedFlags |= CachedFileFlags; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
128 |
} |
0 | 129 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
130 |
if (request & QAbstractFileEngine::LinkType) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
131 |
if (!data->getCachedFlag(CachedLinkTypeFlag)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
132 |
req |= QAbstractFileEngine::LinkType; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
133 |
cachedFlags |= CachedLinkTypeFlag; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
134 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
135 |
} |
0 | 136 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
137 |
if (request & QAbstractFileEngine::BundleType) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
138 |
if (!data->getCachedFlag(CachedBundleTypeFlag)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
139 |
req |= QAbstractFileEngine::BundleType; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
140 |
cachedFlags |= CachedBundleTypeFlag; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
141 |
} |
0 | 142 |
} |
143 |
} |
|
144 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
145 |
if (request & QAbstractFileEngine::PermsMask) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
146 |
if (!data->getCachedFlag(CachedPerms)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
147 |
req |= QAbstractFileEngine::PermsMask; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
148 |
cachedFlags |= CachedPerms; |
0 | 149 |
} |
150 |
} |
|
151 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
152 |
if (req) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
153 |
if (data->cache_enabled) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
154 |
req &= (~QAbstractFileEngine::Refresh); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
155 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
156 |
req |= QAbstractFileEngine::Refresh; |
0 | 157 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
158 |
QAbstractFileEngine::FileFlags flags = data->fileEngine->fileFlags(req); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
159 |
data->fileFlags |= uint(flags); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
160 |
data->setCachedFlag(cachedFlags); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
161 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
162 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
163 |
return data->fileFlags & request; |
0 | 164 |
} |
165 |
||
166 |
QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const |
|
167 |
{ |
|
168 |
if (!data->cache_enabled) |
|
169 |
data->clearFlags(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
170 |
uint cf; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
171 |
if (request == QAbstractFileEngine::CreationTime) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
172 |
cf = CachedCTime; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
173 |
else if (request == QAbstractFileEngine::ModificationTime) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
174 |
cf = CachedMTime; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
175 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
176 |
cf = CachedATime; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
177 |
if (!data->getCachedFlag(cf)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
178 |
data->fileTimes[request] = data->fileEngine->fileTime(request); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
179 |
data->setCachedFlag(cf); |
0 | 180 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
181 |
return data->fileTimes[request]; |
0 | 182 |
} |
183 |
||
184 |
//************* QFileInfo |
|
185 |
||
186 |
/*! |
|
187 |
\class QFileInfo |
|
188 |
\reentrant |
|
189 |
\brief The QFileInfo class provides system-independent file information. |
|
190 |
||
191 |
\ingroup io |
|
192 |
\ingroup shared |
|
193 |
||
194 |
QFileInfo provides information about a file's name and position |
|
195 |
(path) in the file system, its access rights and whether it is a |
|
196 |
directory or symbolic link, etc. The file's size and last |
|
197 |
modified/read times are also available. QFileInfo can also be |
|
198 |
used to obtain information about a Qt \l{resource |
|
199 |
system}{resource}. |
|
200 |
||
201 |
A QFileInfo can point to a file with either a relative or an |
|
202 |
absolute file path. Absolute file paths begin with the directory |
|
203 |
separator "/" (or with a drive specification on Windows). Relative |
|
204 |
file names begin with a directory name or a file name and specify |
|
205 |
a path relative to the current working directory. An example of an |
|
206 |
absolute path is the string "/tmp/quartz". A relative path might |
|
207 |
look like "src/fatlib". You can use the function isRelative() to |
|
208 |
check whether a QFileInfo is using a relative or an absolute file |
|
209 |
path. You can call the function makeAbsolute() to convert a |
|
210 |
relative QFileInfo's path to an absolute path. |
|
211 |
||
212 |
The file that the QFileInfo works on is set in the constructor or |
|
213 |
later with setFile(). Use exists() to see if the file exists and |
|
214 |
size() to get its size. |
|
215 |
||
216 |
The file's type is obtained with isFile(), isDir() and |
|
217 |
isSymLink(). The symLinkTarget() function provides the name of the file |
|
218 |
the symlink points to. |
|
219 |
||
220 |
On Unix (including Mac OS X), the symlink has the same size() has |
|
221 |
the file it points to, because Unix handles symlinks |
|
222 |
transparently; similarly, opening a symlink using QFile |
|
223 |
effectively opens the link's target. For example: |
|
224 |
||
225 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 0 |
|
226 |
||
227 |
On Windows, symlinks (shortcuts) are \c .lnk files. The reported |
|
228 |
size() is that of the symlink (not the link's target), and |
|
229 |
opening a symlink using QFile opens the \c .lnk file. For |
|
230 |
example: |
|
231 |
||
232 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 1 |
|
233 |
||
234 |
Elements of the file's name can be extracted with path() and |
|
235 |
fileName(). The fileName()'s parts can be extracted with |
|
236 |
baseName(), suffix() or completeSuffix(). QFileInfo objects to |
|
237 |
directories created by Qt classes will not have a trailing file |
|
238 |
separator. If you wish to use trailing separators in your own file |
|
239 |
info objects, just append one to the file name given to the constructors |
|
240 |
or setFile(). |
|
241 |
||
242 |
The file's dates are returned by created(), lastModified() and |
|
243 |
lastRead(). Information about the file's access permissions is |
|
244 |
obtained with isReadable(), isWritable() and isExecutable(). The |
|
245 |
file's ownership is available from owner(), ownerId(), group() and |
|
246 |
groupId(). You can examine a file's permissions and ownership in a |
|
247 |
single statement using the permission() function. |
|
248 |
||
249 |
\section1 Performance Issues |
|
250 |
||
251 |
Some of QFileInfo's functions query the file system, but for |
|
252 |
performance reasons, some functions only operate on the |
|
253 |
file name itself. For example: To return the absolute path of |
|
254 |
a relative file name, absolutePath() has to query the file system. |
|
255 |
The path() function, however, can work on the file name directly, |
|
256 |
and so it is faster. |
|
257 |
||
258 |
\note To speed up performance, QFileInfo caches information about |
|
259 |
the file. |
|
260 |
||
261 |
To speed up performance, QFileInfo caches information about the |
|
262 |
file. Because files can be changed by other users or programs, or |
|
263 |
even by other parts of the same program, there is a function that |
|
264 |
refreshes the file information: refresh(). If you want to switch |
|
265 |
off a QFileInfo's caching and force it to access the file system |
|
266 |
every time you request information from it call setCaching(false). |
|
267 |
||
268 |
\sa QDir, QFile |
|
269 |
*/ |
|
270 |
||
271 |
/*! |
|
272 |
Constructs an empty QFileInfo object. |
|
273 |
||
274 |
Note that an empty QFileInfo object contain no file reference. |
|
275 |
||
276 |
\sa setFile() |
|
277 |
*/ |
|
278 |
QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate()) |
|
279 |
{ |
|
280 |
} |
|
281 |
||
282 |
/*! |
|
283 |
Constructs a new QFileInfo that gives information about the given |
|
284 |
file. The \a file can also include an absolute or relative path. |
|
285 |
||
286 |
\sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() |
|
287 |
*/ |
|
288 |
QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate()) |
|
289 |
{ |
|
290 |
d_ptr->initFileEngine(file); |
|
291 |
} |
|
292 |
||
293 |
/*! |
|
294 |
Constructs a new QFileInfo that gives information about file \a |
|
295 |
file. |
|
296 |
||
297 |
If the \a file has a relative path, the QFileInfo will also have a |
|
298 |
relative path. |
|
299 |
||
300 |
\sa isRelative() |
|
301 |
*/ |
|
302 |
QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate()) |
|
303 |
{ |
|
304 |
d_ptr->initFileEngine(file.fileName()); |
|
305 |
} |
|
306 |
||
307 |
/*! |
|
308 |
Constructs a new QFileInfo that gives information about the given |
|
309 |
\a file in the directory \a dir. |
|
310 |
||
311 |
If \a dir has a relative path, the QFileInfo will also have a |
|
312 |
relative path. |
|
313 |
||
314 |
If \a file is an absolute path, then the directory specified |
|
315 |
by \a dir will be disregarded. |
|
316 |
||
317 |
\sa isRelative() |
|
318 |
*/ |
|
319 |
QFileInfo::QFileInfo(const QDir &dir, const QString &file) : d_ptr(new QFileInfoPrivate()) |
|
320 |
{ |
|
321 |
d_ptr->initFileEngine(dir.filePath(file)); |
|
322 |
} |
|
323 |
||
324 |
/*! |
|
325 |
Constructs a new QFileInfo that is a copy of the given \a fileinfo. |
|
326 |
*/ |
|
327 |
QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fileinfo)) |
|
328 |
{ |
|
329 |
||
330 |
} |
|
331 |
||
332 |
/*! |
|
333 |
Destroys the QFileInfo and frees its resources. |
|
334 |
*/ |
|
335 |
||
336 |
QFileInfo::~QFileInfo() |
|
337 |
{ |
|
338 |
} |
|
339 |
||
340 |
/*! |
|
341 |
\fn bool QFileInfo::operator!=(const QFileInfo &fileinfo) |
|
342 |
||
343 |
Returns true if this QFileInfo object refers to a different file |
|
344 |
than the one specified by \a fileinfo; otherwise returns false. |
|
345 |
||
346 |
\sa operator==() |
|
347 |
*/ |
|
348 |
||
349 |
/*! |
|
350 |
\overload |
|
351 |
\fn bool QFileInfo::operator!=(const QFileInfo &fileinfo) const |
|
352 |
*/ |
|
353 |
||
354 |
/*! |
|
355 |
\overload |
|
356 |
*/ |
|
357 |
bool QFileInfo::operator==(const QFileInfo &fileinfo) const |
|
358 |
{ |
|
359 |
Q_D(const QFileInfo); |
|
360 |
// ### Qt 5: understand long and short file names on Windows |
|
361 |
// ### (GetFullPathName()). |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
362 |
if (fileinfo.d_func()->data == d->data) |
0 | 363 |
return true; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
364 |
if (!d->data->fileEngine || !fileinfo.d_func()->data->fileEngine) |
0 | 365 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
366 |
if (d->data->fileEngine->caseSensitive() != fileinfo.d_func()->data->fileEngine->caseSensitive()) |
0 | 367 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
368 |
if (fileinfo.size() == size()) { //if the size isn't the same... |
0 | 369 |
QString file1 = canonicalFilePath(), |
370 |
file2 = fileinfo.canonicalFilePath(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
371 |
if (file1.length() == file2.length()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
372 |
if (!fileinfo.d_func()->data->fileEngine->caseSensitive()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
373 |
for (int i = 0; i < file1.length(); i++) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
374 |
if (file1.at(i).toLower() != file2.at(i).toLower()) |
0 | 375 |
return false; |
376 |
} |
|
377 |
return true; |
|
378 |
} |
|
379 |
return (file1 == file2); |
|
380 |
} |
|
381 |
} |
|
382 |
return false; |
|
383 |
} |
|
384 |
||
385 |
/*! |
|
386 |
Returns true if this QFileInfo object refers to a file in the same |
|
387 |
location as \a fileinfo; otherwise returns false. |
|
388 |
||
389 |
Note that the result of comparing two empty QFileInfo objects, |
|
390 |
containing no file references, is undefined. |
|
391 |
||
392 |
\warning This will not compare two different symbolic links |
|
393 |
pointing to the same file. |
|
394 |
||
395 |
\warning Long and short file names that refer to the same file on Windows |
|
396 |
are treated as if they referred to different files. |
|
397 |
||
398 |
\sa operator!=() |
|
399 |
*/ |
|
400 |
bool QFileInfo::operator==(const QFileInfo &fileinfo) |
|
401 |
{ |
|
402 |
return const_cast<const QFileInfo *>(this)->operator==(fileinfo); |
|
403 |
} |
|
404 |
||
405 |
/*! |
|
406 |
Makes a copy of the given \a fileinfo and assigns it to this QFileInfo. |
|
407 |
*/ |
|
408 |
QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) |
|
409 |
{ |
|
410 |
Q_D(QFileInfo); |
|
411 |
qAtomicAssign(d->data, fileinfo.d_func()->data); |
|
412 |
return *this; |
|
413 |
} |
|
414 |
||
415 |
/*! |
|
416 |
Sets the file that the QFileInfo provides information about to \a |
|
417 |
file. |
|
418 |
||
419 |
The \a file can also include an absolute or relative file path. |
|
420 |
Absolute paths begin with the directory separator (e.g. "/" under |
|
421 |
Unix) or a drive specification (under Windows). Relative file |
|
422 |
names begin with a directory name or a file name and specify a |
|
423 |
path relative to the current directory. |
|
424 |
||
425 |
Example: |
|
426 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 2 |
|
427 |
||
428 |
\sa isRelative(), QDir::setCurrent(), QDir::isRelativePath() |
|
429 |
*/ |
|
430 |
void QFileInfo::setFile(const QString &file) |
|
431 |
{ |
|
432 |
*this = QFileInfo(file); |
|
433 |
} |
|
434 |
||
435 |
/*! |
|
436 |
\overload |
|
437 |
||
438 |
Sets the file that the QFileInfo provides information about to \a |
|
439 |
file. |
|
440 |
||
441 |
If \a file includes a relative path, the QFileInfo will also have |
|
442 |
a relative path. |
|
443 |
||
444 |
\sa isRelative() |
|
445 |
*/ |
|
446 |
void QFileInfo::setFile(const QFile &file) |
|
447 |
{ |
|
448 |
*this = QFileInfo(file.fileName()); |
|
449 |
} |
|
450 |
||
451 |
/*! |
|
452 |
\overload |
|
453 |
||
454 |
Sets the file that the QFileInfo provides information about to \a |
|
455 |
file in directory \a dir. |
|
456 |
||
457 |
If \a file includes a relative path, the QFileInfo will also |
|
458 |
have a relative path. |
|
459 |
||
460 |
\sa isRelative() |
|
461 |
*/ |
|
462 |
void QFileInfo::setFile(const QDir &dir, const QString &file) |
|
463 |
{ |
|
464 |
*this = QFileInfo(dir.filePath(file)); |
|
465 |
} |
|
466 |
||
467 |
/*! |
|
468 |
Returns an absolute path including the file name. |
|
469 |
||
470 |
The absolute path name consists of the full path and the file |
|
471 |
name. On Unix this will always begin with the root, '/', |
|
472 |
directory. On Windows this will always begin 'D:/' where D is a |
|
473 |
drive letter, except for network shares that are not mapped to a |
|
474 |
drive letter, in which case the path will begin '//sharename/'. |
|
475 |
QFileInfo will uppercase drive letters. Note that QDir does not do |
|
476 |
this. The code snippet below shows this. |
|
477 |
||
478 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp newstuff |
|
479 |
||
480 |
This function returns the same as filePath(), unless isRelative() |
|
481 |
is true. In contrast to canonicalFilePath(), symbolic links or |
|
482 |
redundant "." or ".." elements are not necessarily removed. |
|
483 |
||
484 |
If the QFileInfo is empty it returns QDir::currentPath(). |
|
485 |
||
486 |
\sa filePath(), canonicalFilePath(), isRelative() |
|
487 |
*/ |
|
488 |
QString QFileInfo::absoluteFilePath() const |
|
489 |
{ |
|
490 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
491 |
if (!d->data->fileEngine) |
0 | 492 |
return QLatin1String(""); |
493 |
return d->getFileName(QAbstractFileEngine::AbsoluteName); |
|
494 |
} |
|
495 |
||
496 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
497 |
Returns the canonical path including the file name, i.e. an absolute |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
498 |
path without symbolic links or redundant "." or ".." elements. |
0 | 499 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
500 |
If the file does not exist, canonicalFilePath() returns an empty |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
501 |
string. |
0 | 502 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
503 |
\sa filePath(), absoluteFilePath(), dir() |
0 | 504 |
*/ |
505 |
QString QFileInfo::canonicalFilePath() const |
|
506 |
{ |
|
507 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
508 |
if (!d->data->fileEngine) |
0 | 509 |
return QLatin1String(""); |
510 |
return d->getFileName(QAbstractFileEngine::CanonicalName); |
|
511 |
} |
|
512 |
||
513 |
||
514 |
/*! |
|
515 |
Returns a file's path absolute path. This doesn't include the |
|
516 |
file name. |
|
517 |
||
518 |
On Unix the absolute path will always begin with the root, '/', |
|
519 |
directory. On Windows this will always begin 'D:/' where D is a |
|
520 |
drive letter, except for network shares that are not mapped to a |
|
521 |
drive letter, in which case the path will begin '//sharename/'. |
|
522 |
||
523 |
In contrast to canonicalPath() symbolic links or redundant "." or |
|
524 |
".." elements are not necessarily removed. |
|
525 |
||
526 |
\warning If the QFileInfo object was created with an empty QString, |
|
527 |
the behavior of this function is undefined. |
|
528 |
||
529 |
\sa absoluteFilePath(), path(), canonicalPath(), fileName(), isRelative() |
|
530 |
*/ |
|
531 |
QString QFileInfo::absolutePath() const |
|
532 |
{ |
|
533 |
Q_D(const QFileInfo); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
if (!d->data->fileEngine) { |
0 | 536 |
return QLatin1String(""); |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
} else if (d->data->fileName.isEmpty()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
qWarning("QFileInfo::absolutePath: Constructed with empty filename"); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
return QLatin1String(""); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
} |
0 | 541 |
return d->getFileName(QAbstractFileEngine::AbsolutePathName); |
542 |
} |
|
543 |
||
544 |
/*! |
|
545 |
Returns the file's path canonical path (excluding the file name), |
|
546 |
i.e. an absolute path without symbolic links or redundant "." or ".." elements. |
|
547 |
||
548 |
If the file does not exist, canonicalPath() returns an empty string. |
|
549 |
||
550 |
\sa path(), absolutePath() |
|
551 |
*/ |
|
552 |
QString QFileInfo::canonicalPath() const |
|
553 |
{ |
|
554 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
555 |
if (!d->data->fileEngine) |
0 | 556 |
return QLatin1String(""); |
557 |
return d->getFileName(QAbstractFileEngine::CanonicalPathName); |
|
558 |
} |
|
559 |
||
560 |
/*! |
|
561 |
Returns the file's path. This doesn't include the file name. |
|
562 |
||
563 |
Note that, if this QFileInfo object is given a path ending in a |
|
564 |
slash, the name of the file is considered empty and this function |
|
565 |
will return the entire path. |
|
566 |
||
567 |
\sa filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative() |
|
568 |
*/ |
|
569 |
QString QFileInfo::path() const |
|
570 |
{ |
|
571 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
572 |
if (!d->data->fileEngine) |
0 | 573 |
return QLatin1String(""); |
574 |
return d->getFileName(QAbstractFileEngine::PathName); |
|
575 |
} |
|
576 |
||
577 |
/*! |
|
578 |
\fn bool QFileInfo::isAbsolute() const |
|
579 |
||
580 |
Returns true if the file path name is absolute, otherwise returns |
|
581 |
false if the path is relative. |
|
582 |
||
583 |
\sa isRelative() |
|
584 |
*/ |
|
585 |
||
586 |
/*! |
|
587 |
Returns true if the file path name is relative, otherwise returns |
|
588 |
false if the path is absolute (e.g. under Unix a path is absolute |
|
589 |
if it begins with a "/"). |
|
590 |
||
591 |
\sa isAbsolute() |
|
592 |
*/ |
|
593 |
bool QFileInfo::isRelative() const |
|
594 |
{ |
|
595 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
596 |
if (!d->data->fileEngine) |
0 | 597 |
return true; |
598 |
return d->data->fileEngine->isRelativePath(); |
|
599 |
} |
|
600 |
||
601 |
/*! |
|
602 |
Converts the file's path to an absolute path if it is not already in that form. |
|
603 |
Returns true to indicate that the path was converted; otherwise returns false |
|
604 |
to indicate that the path was already absolute. |
|
605 |
||
606 |
\sa filePath(), isRelative() |
|
607 |
*/ |
|
608 |
bool QFileInfo::makeAbsolute() |
|
609 |
{ |
|
610 |
Q_D(QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
611 |
if (!d->data->fileEngine || !d->data->fileEngine->isRelativePath()) |
0 | 612 |
return false; |
613 |
QString absFileName = d->getFileName(QAbstractFileEngine::AbsoluteName); |
|
614 |
d->initFileEngine(absFileName); |
|
615 |
return true; |
|
616 |
} |
|
617 |
||
618 |
/*! |
|
619 |
Returns true if the file exists; otherwise returns false. |
|
620 |
||
621 |
\note If the file is a symlink that points to a non existing |
|
622 |
file, false is returned. |
|
623 |
*/ |
|
624 |
bool QFileInfo::exists() const |
|
625 |
{ |
|
626 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
627 |
if (!d->data->fileEngine) |
0 | 628 |
return false; |
629 |
return d->getFileFlags(QAbstractFileEngine::ExistsFlag); |
|
630 |
} |
|
631 |
||
632 |
/*! |
|
633 |
Refreshes the information about the file, i.e. reads in information |
|
634 |
from the file system the next time a cached property is fetched. |
|
635 |
||
636 |
\note On Windows CE, there might be a delay for the file system driver |
|
637 |
to detect changes on the file. |
|
638 |
*/ |
|
639 |
void QFileInfo::refresh() |
|
640 |
{ |
|
641 |
Q_D(QFileInfo); |
|
642 |
d->reset(); |
|
643 |
} |
|
644 |
||
645 |
/*! |
|
646 |
Returns the file name, including the path (which may be absolute |
|
647 |
or relative). |
|
648 |
||
649 |
\sa absoluteFilePath(), canonicalFilePath(), isRelative() |
|
650 |
*/ |
|
651 |
QString QFileInfo::filePath() const |
|
652 |
{ |
|
653 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
654 |
if (!d->data->fileEngine) |
0 | 655 |
return QLatin1String(""); |
656 |
return d->getFileName(QAbstractFileEngine::DefaultName); |
|
657 |
} |
|
658 |
||
659 |
/*! |
|
660 |
Returns the name of the file, excluding the path. |
|
661 |
||
662 |
Example: |
|
663 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 3 |
|
664 |
||
665 |
Note that, if this QFileInfo object is given a path ending in a |
|
666 |
slash, the name of the file is considered empty. |
|
667 |
||
668 |
\sa isRelative(), filePath(), baseName(), extension() |
|
669 |
*/ |
|
670 |
QString QFileInfo::fileName() const |
|
671 |
{ |
|
672 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
673 |
if (!d->data->fileEngine) |
0 | 674 |
return QLatin1String(""); |
675 |
return d->getFileName(QAbstractFileEngine::BaseName); |
|
676 |
} |
|
677 |
||
678 |
/*! |
|
679 |
\since 4.3 |
|
680 |
Returns the name of the bundle. |
|
681 |
||
682 |
On Mac OS X this returns the proper localized name for a bundle if the |
|
683 |
path isBundle(). On all other platforms an empty QString is returned. |
|
684 |
||
685 |
Example: |
|
686 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 4 |
|
687 |
||
688 |
\sa isBundle(), filePath(), baseName(), extension() |
|
689 |
*/ |
|
690 |
QString QFileInfo::bundleName() const |
|
691 |
{ |
|
692 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
693 |
if (!d->data->fileEngine) |
0 | 694 |
return QLatin1String(""); |
695 |
return d->getFileName(QAbstractFileEngine::BundleName); |
|
696 |
} |
|
697 |
||
698 |
/*! |
|
699 |
Returns the base name of the file without the path. |
|
700 |
||
701 |
The base name consists of all characters in the file up to (but |
|
702 |
not including) the \e first '.' character. |
|
703 |
||
704 |
Example: |
|
705 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 5 |
|
706 |
||
707 |
||
708 |
The base name of a file is computed equally on all platforms, independent |
|
709 |
of file naming conventions (e.g., ".bashrc" on Unix has an empty base |
|
710 |
name, and the suffix is "bashrc"). |
|
711 |
||
712 |
\sa fileName(), suffix(), completeSuffix(), completeBaseName() |
|
713 |
*/ |
|
714 |
QString QFileInfo::baseName() const |
|
715 |
{ |
|
716 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
717 |
if (!d->data->fileEngine) |
0 | 718 |
return QLatin1String(""); |
719 |
return d->getFileName(QAbstractFileEngine::BaseName).section(QLatin1Char('.'), 0, 0); |
|
720 |
} |
|
721 |
||
722 |
/*! |
|
723 |
Returns the complete base name of the file without the path. |
|
724 |
||
725 |
The complete base name consists of all characters in the file up |
|
726 |
to (but not including) the \e last '.' character. |
|
727 |
||
728 |
Example: |
|
729 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 6 |
|
730 |
||
731 |
\sa fileName(), suffix(), completeSuffix(), baseName() |
|
732 |
*/ |
|
733 |
QString QFileInfo::completeBaseName() const |
|
734 |
{ |
|
735 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
736 |
if (!d->data->fileEngine) |
0 | 737 |
return QLatin1String(""); |
738 |
QString name = d->getFileName(QAbstractFileEngine::BaseName); |
|
739 |
int index = name.lastIndexOf(QLatin1Char('.')); |
|
740 |
return (index == -1) ? name : name.left(index); |
|
741 |
} |
|
742 |
||
743 |
/*! |
|
744 |
Returns the complete suffix of the file. |
|
745 |
||
746 |
The complete suffix consists of all characters in the file after |
|
747 |
(but not including) the first '.'. |
|
748 |
||
749 |
Example: |
|
750 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 7 |
|
751 |
||
752 |
\sa fileName(), suffix(), baseName(), completeBaseName() |
|
753 |
*/ |
|
754 |
QString QFileInfo::completeSuffix() const |
|
755 |
{ |
|
756 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
757 |
if (!d->data->fileEngine) |
0 | 758 |
return QLatin1String(""); |
759 |
QString fileName = d->getFileName(QAbstractFileEngine::BaseName); |
|
760 |
int firstDot = fileName.indexOf(QLatin1Char('.')); |
|
761 |
if (firstDot == -1) |
|
762 |
return QLatin1String(""); |
|
763 |
return fileName.mid(firstDot + 1); |
|
764 |
} |
|
765 |
||
766 |
/*! |
|
767 |
Returns the suffix of the file. |
|
768 |
||
769 |
The suffix consists of all characters in the file after (but not |
|
770 |
including) the last '.'. |
|
771 |
||
772 |
Example: |
|
773 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 8 |
|
774 |
||
775 |
The suffix of a file is computed equally on all platforms, independent of |
|
776 |
file naming conventions (e.g., ".bashrc" on Unix has an empty base name, |
|
777 |
and the suffix is "bashrc"). |
|
778 |
||
779 |
\sa fileName(), completeSuffix(), baseName(), completeBaseName() |
|
780 |
*/ |
|
781 |
QString QFileInfo::suffix() const |
|
782 |
{ |
|
783 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
784 |
if (!d->data->fileEngine) |
0 | 785 |
return QLatin1String(""); |
786 |
QString fileName = d->getFileName(QAbstractFileEngine::BaseName); |
|
787 |
int lastDot = fileName.lastIndexOf(QLatin1Char('.')); |
|
788 |
if (lastDot == -1) |
|
789 |
return QLatin1String(""); |
|
790 |
return fileName.mid(lastDot + 1); |
|
791 |
} |
|
792 |
||
793 |
||
794 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
795 |
Returns the path of the object's parent directory as a QDir object. |
0 | 796 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
797 |
\bold{Note:} The QDir returned always corresponds to the object's |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
798 |
parent directory, even if the QFileInfo represents a directory. |
0 | 799 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
800 |
For each of the follwing, dir() returns a QDir for |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
801 |
\c{"~/examples/191697"}. |
0 | 802 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
803 |
\snippet doc/src/snippets/fileinfo/main.cpp 0 |
0 | 804 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
805 |
For each of the follwing, dir() returns a QDir for |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
806 |
\c{"."}. |
0 | 807 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
808 |
\snippet doc/src/snippets/fileinfo/main.cpp 1 |
0 | 809 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
810 |
\sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir() |
0 | 811 |
*/ |
812 |
QDir QFileInfo::dir() const |
|
813 |
{ |
|
814 |
// ### Qt5: Maybe rename this to parentDirectory(), considering what it actually do? |
|
815 |
return QDir(path()); |
|
816 |
} |
|
817 |
||
818 |
/*! |
|
819 |
Returns the file's absolute path as a QDir object. |
|
820 |
||
821 |
\sa dir(), filePath(), fileName(), isRelative() |
|
822 |
*/ |
|
823 |
QDir QFileInfo::absoluteDir() const |
|
824 |
{ |
|
825 |
return QDir(absolutePath()); |
|
826 |
} |
|
827 |
||
828 |
#ifdef QT3_SUPPORT |
|
829 |
/*! |
|
830 |
Use absoluteDir() or the dir() overload that takes no parameters |
|
831 |
instead. |
|
832 |
*/ |
|
833 |
QDir QFileInfo::dir(bool absPath) const |
|
834 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
835 |
if (absPath) |
0 | 836 |
return absoluteDir(); |
837 |
return dir(); |
|
838 |
} |
|
839 |
#endif //QT3_SUPPORT |
|
840 |
||
841 |
/*! |
|
842 |
Returns true if the user can read the file; otherwise returns false. |
|
843 |
||
844 |
\sa isWritable(), isExecutable(), permission() |
|
845 |
*/ |
|
846 |
bool QFileInfo::isReadable() const |
|
847 |
{ |
|
848 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
849 |
if (!d->data->fileEngine) |
0 | 850 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
851 |
return d->getFileFlags(QAbstractFileEngine::ReadUserPerm); |
0 | 852 |
} |
853 |
||
854 |
/*! |
|
855 |
Returns true if the user can write to the file; otherwise returns false. |
|
856 |
||
857 |
\sa isReadable(), isExecutable(), permission() |
|
858 |
*/ |
|
859 |
bool QFileInfo::isWritable() const |
|
860 |
{ |
|
861 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
862 |
if (!d->data->fileEngine) |
0 | 863 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
864 |
return d->getFileFlags(QAbstractFileEngine::WriteUserPerm); |
0 | 865 |
} |
866 |
||
867 |
/*! |
|
868 |
Returns true if the file is executable; otherwise returns false. |
|
869 |
||
870 |
\sa isReadable(), isWritable(), permission() |
|
871 |
*/ |
|
872 |
bool QFileInfo::isExecutable() const |
|
873 |
{ |
|
874 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
875 |
if (!d->data->fileEngine) |
0 | 876 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
877 |
return d->getFileFlags(QAbstractFileEngine::ExeUserPerm); |
0 | 878 |
} |
879 |
||
880 |
/*! |
|
881 |
Returns true if this is a `hidden' file; otherwise returns false. |
|
882 |
||
883 |
\bold{Note:} This function returns true for the special entries |
|
884 |
"." and ".." on Unix, even though QDir::entryList threats them as shown. |
|
885 |
*/ |
|
886 |
bool QFileInfo::isHidden() const |
|
887 |
{ |
|
888 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
889 |
if (!d->data->fileEngine) |
0 | 890 |
return false; |
891 |
return d->getFileFlags(QAbstractFileEngine::HiddenFlag); |
|
892 |
} |
|
893 |
||
894 |
/*! |
|
895 |
Returns true if this object points to a file or to a symbolic |
|
896 |
link to a file. Returns false if the |
|
897 |
object points to something which isn't a file, such as a directory. |
|
898 |
||
899 |
\sa isDir(), isSymLink(), isBundle() |
|
900 |
*/ |
|
901 |
bool QFileInfo::isFile() const |
|
902 |
{ |
|
903 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
904 |
if (!d->data->fileEngine) |
0 | 905 |
return false; |
906 |
return d->getFileFlags(QAbstractFileEngine::FileType); |
|
907 |
} |
|
908 |
||
909 |
/*! |
|
910 |
Returns true if this object points to a directory or to a symbolic |
|
911 |
link to a directory; otherwise returns false. |
|
912 |
||
913 |
\sa isFile(), isSymLink(), isBundle() |
|
914 |
*/ |
|
915 |
bool QFileInfo::isDir() const |
|
916 |
{ |
|
917 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
918 |
if (!d->data->fileEngine) |
0 | 919 |
return false; |
920 |
return d->getFileFlags(QAbstractFileEngine::DirectoryType); |
|
921 |
} |
|
922 |
||
923 |
||
924 |
/*! |
|
925 |
\since 4.3 |
|
926 |
Returns true if this object points to a bundle or to a symbolic |
|
927 |
link to a bundle on Mac OS X; otherwise returns false. |
|
928 |
||
929 |
\sa isDir(), isSymLink(), isFile() |
|
930 |
*/ |
|
931 |
bool QFileInfo::isBundle() const |
|
932 |
{ |
|
933 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
934 |
if (!d->data->fileEngine) |
0 | 935 |
return false; |
936 |
return d->getFileFlags(QAbstractFileEngine::BundleType); |
|
937 |
} |
|
938 |
||
939 |
/*! |
|
940 |
Returns true if this object points to a symbolic link (or to a |
|
941 |
shortcut on Windows); otherwise returns false. |
|
942 |
||
943 |
On Unix (including Mac OS X), opening a symlink effectively opens |
|
944 |
the \l{symLinkTarget()}{link's target}. On Windows, it opens the \c |
|
945 |
.lnk file itself. |
|
946 |
||
947 |
Example: |
|
948 |
||
949 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 9 |
|
950 |
||
951 |
\note If the symlink points to a non existing file, exists() returns |
|
952 |
false. |
|
953 |
||
954 |
\sa isFile(), isDir(), symLinkTarget() |
|
955 |
*/ |
|
956 |
bool QFileInfo::isSymLink() const |
|
957 |
{ |
|
958 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
959 |
if (!d->data->fileEngine) |
0 | 960 |
return false; |
961 |
return d->getFileFlags(QAbstractFileEngine::LinkType); |
|
962 |
} |
|
963 |
||
964 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
965 |
Returns true if the object points to a directory or to a symbolic |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
966 |
link to a directory, and that directory is the root directory; otherwise |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
967 |
returns false. |
0 | 968 |
*/ |
969 |
bool QFileInfo::isRoot() const |
|
970 |
{ |
|
971 |
Q_D(const QFileInfo); |
|
972 |
if (!d->data->fileEngine) |
|
973 |
return true; |
|
974 |
return d->getFileFlags(QAbstractFileEngine::RootFlag); |
|
975 |
} |
|
976 |
||
977 |
/*! |
|
978 |
\fn QString QFileInfo::symLinkTarget() const |
|
979 |
\since 4.2 |
|
980 |
||
981 |
Returns the absolute path to the file or directory a symlink (or shortcut |
|
982 |
on Windows) points to, or a an empty string if the object isn't a symbolic |
|
983 |
link. |
|
984 |
||
985 |
This name may not represent an existing file; it is only a string. |
|
986 |
QFileInfo::exists() returns true if the symlink points to an |
|
987 |
existing file. |
|
988 |
||
989 |
\sa exists(), isSymLink(), isDir(), isFile() |
|
990 |
*/ |
|
991 |
||
992 |
/*! |
|
993 |
\obsolete |
|
994 |
||
995 |
Use symLinkTarget() instead. |
|
996 |
*/ |
|
997 |
QString QFileInfo::readLink() const |
|
998 |
{ |
|
999 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1000 |
if (!d->data->fileEngine) |
0 | 1001 |
return QLatin1String(""); |
1002 |
return d->getFileName(QAbstractFileEngine::LinkName); |
|
1003 |
} |
|
1004 |
||
1005 |
/*! |
|
1006 |
Returns the owner of the file. On systems where files |
|
1007 |
do not have owners, or if an error occurs, an empty string is |
|
1008 |
returned. |
|
1009 |
||
1010 |
This function can be time consuming under Unix (in the order of |
|
1011 |
milliseconds). |
|
1012 |
||
1013 |
\sa ownerId(), group(), groupId() |
|
1014 |
*/ |
|
1015 |
QString QFileInfo::owner() const |
|
1016 |
{ |
|
1017 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1018 |
if (!d->data->fileEngine) |
0 | 1019 |
return QLatin1String(""); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1020 |
return d->getFileOwner(QAbstractFileEngine::OwnerUser); |
0 | 1021 |
} |
1022 |
||
1023 |
/*! |
|
1024 |
Returns the id of the owner of the file. |
|
1025 |
||
1026 |
On Windows and on systems where files do not have owners this |
|
1027 |
function returns ((uint) -2). |
|
1028 |
||
1029 |
\sa owner(), group(), groupId() |
|
1030 |
*/ |
|
1031 |
uint QFileInfo::ownerId() const |
|
1032 |
{ |
|
1033 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1034 |
if (!d->data->fileEngine) |
0 | 1035 |
return 0; |
1036 |
return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerUser); |
|
1037 |
} |
|
1038 |
||
1039 |
/*! |
|
1040 |
Returns the group of the file. On Windows, on systems where files |
|
1041 |
do not have groups, or if an error occurs, an empty string is |
|
1042 |
returned. |
|
1043 |
||
1044 |
This function can be time consuming under Unix (in the order of |
|
1045 |
milliseconds). |
|
1046 |
||
1047 |
\sa groupId(), owner(), ownerId() |
|
1048 |
*/ |
|
1049 |
QString QFileInfo::group() const |
|
1050 |
{ |
|
1051 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1052 |
if (!d->data->fileEngine) |
0 | 1053 |
return QLatin1String(""); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1054 |
return d->getFileOwner(QAbstractFileEngine::OwnerGroup); |
0 | 1055 |
} |
1056 |
||
1057 |
/*! |
|
1058 |
Returns the id of the group the file belongs to. |
|
1059 |
||
1060 |
On Windows and on systems where files do not have groups this |
|
1061 |
function always returns (uint) -2. |
|
1062 |
||
1063 |
\sa group(), owner(), ownerId() |
|
1064 |
*/ |
|
1065 |
uint QFileInfo::groupId() const |
|
1066 |
{ |
|
1067 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1068 |
if (!d->data->fileEngine) |
0 | 1069 |
return 0; |
1070 |
return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerGroup); |
|
1071 |
} |
|
1072 |
||
1073 |
/*! |
|
1074 |
Tests for file permissions. The \a permissions argument can be |
|
1075 |
several flags of type QFile::Permissions OR-ed together to check |
|
1076 |
for permission combinations. |
|
1077 |
||
1078 |
On systems where files do not have permissions this function |
|
1079 |
always returns true. |
|
1080 |
||
1081 |
Example: |
|
1082 |
\snippet doc/src/snippets/code/src_corelib_io_qfileinfo.cpp 10 |
|
1083 |
||
1084 |
\sa isReadable(), isWritable(), isExecutable() |
|
1085 |
*/ |
|
1086 |
bool QFileInfo::permission(QFile::Permissions permissions) const |
|
1087 |
{ |
|
1088 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1089 |
if (!d->data->fileEngine) |
0 | 1090 |
return false; |
1091 |
return d->getFileFlags(QAbstractFileEngine::FileFlags((int)permissions)) == (uint)permissions; |
|
1092 |
} |
|
1093 |
||
1094 |
/*! |
|
1095 |
Returns the complete OR-ed together combination of |
|
1096 |
QFile::Permissions for the file. |
|
1097 |
*/ |
|
1098 |
QFile::Permissions QFileInfo::permissions() const |
|
1099 |
{ |
|
1100 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1101 |
if (!d->data->fileEngine) |
0 | 1102 |
return 0; |
1103 |
return QFile::Permissions(d->getFileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask); |
|
1104 |
} |
|
1105 |
||
1106 |
||
1107 |
/*! |
|
1108 |
Returns the file size in bytes. If the file does not exist or cannot be |
|
1109 |
fetched, 0 is returned. |
|
1110 |
||
1111 |
\sa exists() |
|
1112 |
*/ |
|
1113 |
qint64 QFileInfo::size() const |
|
1114 |
{ |
|
1115 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1116 |
if (!d->data->fileEngine) |
0 | 1117 |
return 0; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1118 |
if (!d->data->getCachedFlag(QFileInfoPrivate::CachedSize)) { |
0 | 1119 |
d->data->setCachedFlag(QFileInfoPrivate::CachedSize); |
1120 |
d->data->fileSize = d->data->fileEngine->size(); |
|
1121 |
} |
|
1122 |
return d->data->fileSize; |
|
1123 |
} |
|
1124 |
||
1125 |
/*! |
|
1126 |
Returns the date and time when the file was created. |
|
1127 |
||
1128 |
On most Unix systems, this function returns the time of the last |
|
1129 |
status change. A status change occurs when the file is created, |
|
1130 |
but it also occurs whenever the user writes or sets inode |
|
1131 |
information (for example, changing the file permissions). |
|
1132 |
||
1133 |
If neither creation time nor "last status change" time are not |
|
1134 |
available, returns the same as lastModified(). |
|
1135 |
||
1136 |
\sa lastModified() lastRead() |
|
1137 |
*/ |
|
1138 |
QDateTime QFileInfo::created() const |
|
1139 |
{ |
|
1140 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1141 |
if (!d->data->fileEngine) |
0 | 1142 |
return QDateTime(); |
1143 |
return d->getFileTime(QAbstractFileEngine::CreationTime); |
|
1144 |
} |
|
1145 |
||
1146 |
/*! |
|
1147 |
Returns the date and time when the file was last modified. |
|
1148 |
||
1149 |
\sa created() lastRead() |
|
1150 |
*/ |
|
1151 |
QDateTime QFileInfo::lastModified() const |
|
1152 |
{ |
|
1153 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1154 |
if (!d->data->fileEngine) |
0 | 1155 |
return QDateTime(); |
1156 |
return d->getFileTime(QAbstractFileEngine::ModificationTime); |
|
1157 |
} |
|
1158 |
||
1159 |
/*! |
|
1160 |
Returns the date and time when the file was last read (accessed). |
|
1161 |
||
1162 |
On platforms where this information is not available, returns the |
|
1163 |
same as lastModified(). |
|
1164 |
||
1165 |
\sa created() lastModified() |
|
1166 |
*/ |
|
1167 |
QDateTime QFileInfo::lastRead() const |
|
1168 |
{ |
|
1169 |
Q_D(const QFileInfo); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1170 |
if (!d->data->fileEngine) |
0 | 1171 |
return QDateTime(); |
1172 |
return d->getFileTime(QAbstractFileEngine::AccessTime); |
|
1173 |
} |
|
1174 |
||
1175 |
/*! \internal |
|
1176 |
Detaches all internal data. |
|
1177 |
*/ |
|
1178 |
void QFileInfo::detach() |
|
1179 |
{ |
|
1180 |
Q_D(QFileInfo); |
|
1181 |
d->detach(); |
|
1182 |
} |
|
1183 |
||
1184 |
/*! |
|
1185 |
Returns true if caching is enabled; otherwise returns false. |
|
1186 |
||
1187 |
\sa setCaching(), refresh() |
|
1188 |
*/ |
|
1189 |
bool QFileInfo::caching() const |
|
1190 |
{ |
|
1191 |
Q_D(const QFileInfo); |
|
1192 |
return d->data->cache_enabled; |
|
1193 |
} |
|
1194 |
||
1195 |
/*! |
|
1196 |
If \a enable is true, enables caching of file information. If \a |
|
1197 |
enable is false caching is disabled. |
|
1198 |
||
1199 |
When caching is enabled, QFileInfo reads the file information from |
|
1200 |
the file system the first time it's needed, but generally not |
|
1201 |
later. |
|
1202 |
||
1203 |
Caching is enabled by default. |
|
1204 |
||
1205 |
\sa refresh(), caching() |
|
1206 |
*/ |
|
1207 |
void QFileInfo::setCaching(bool enable) |
|
1208 |
{ |
|
1209 |
Q_D(QFileInfo); |
|
1210 |
detach(); |
|
1211 |
d->data->cache_enabled = enable; |
|
1212 |
} |
|
1213 |
||
1214 |
/*! |
|
1215 |
\fn QString QFileInfo::baseName(bool complete) |
|
1216 |
||
1217 |
Use completeBaseName() or the baseName() overload that takes no |
|
1218 |
parameters instead. |
|
1219 |
*/ |
|
1220 |
||
1221 |
/*! |
|
1222 |
\fn QString QFileInfo::extension(bool complete = true) const |
|
1223 |
||
1224 |
Use completeSuffix() or suffix() instead. |
|
1225 |
*/ |
|
1226 |
||
1227 |
/*! |
|
1228 |
\fn QString QFileInfo::absFilePath() const |
|
1229 |
||
1230 |
Use absoluteFilePath() instead. |
|
1231 |
*/ |
|
1232 |
||
1233 |
/*! |
|
1234 |
\fn QString QFileInfo::dirPath(bool absPath) const |
|
1235 |
||
1236 |
Use absolutePath() if the absolute path is wanted (\a absPath |
|
1237 |
is true) or path() if it's not necessary (\a absPath is false). |
|
1238 |
*/ |
|
1239 |
||
1240 |
/*! |
|
1241 |
\fn bool QFileInfo::convertToAbs() |
|
1242 |
||
1243 |
Use makeAbsolute() instead. |
|
1244 |
*/ |
|
1245 |
||
1246 |
/*! |
|
1247 |
\enum QFileInfo::Permission |
|
1248 |
||
1249 |
\compat |
|
1250 |
||
1251 |
\value ReadOwner |
|
1252 |
\value WriteOwner |
|
1253 |
\value ExeOwner |
|
1254 |
\value ReadUser |
|
1255 |
\value WriteUser |
|
1256 |
\value ExeUser |
|
1257 |
\value ReadGroup |
|
1258 |
\value WriteGroup |
|
1259 |
\value ExeGroup |
|
1260 |
\value ReadOther |
|
1261 |
\value WriteOther |
|
1262 |
\value ExeOther |
|
1263 |
*/ |
|
1264 |
||
1265 |
/*! |
|
1266 |
\fn bool QFileInfo::permission(PermissionSpec permissions) const |
|
1267 |
\compat |
|
1268 |
||
1269 |
Use permission() instead. |
|
1270 |
*/ |
|
1271 |
||
1272 |
/*! |
|
1273 |
\typedef QFileInfoList |
|
1274 |
\relates QFileInfo |
|
1275 |
||
1276 |
Synonym for QList<QFileInfo>. |
|
1277 |
*/ |
|
1278 |
||
1279 |
QT_END_NAMESPACE |