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