author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 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 "qdir.h" |
|
44 |
#include "qabstractfileengine.h" |
|
45 |
#ifndef QT_NO_DEBUG_STREAM |
|
46 |
#include "qdebug.h" |
|
47 |
#endif |
|
48 |
#include "qdiriterator.h" |
|
49 |
#include "qfsfileengine.h" |
|
50 |
#include "qdatetime.h" |
|
51 |
#include "qstring.h" |
|
52 |
#include "qregexp.h" |
|
53 |
#include "qvector.h" |
|
54 |
#include "qalgorithms.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
55 |
#include "qvarlengtharray.h" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
56 |
|
0 | 57 |
#ifdef QT_BUILD_CORE_LIB |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
58 |
# include "qresource.h" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
59 |
# include "private/qcoreglobaldata_p.h" |
0 | 60 |
#endif |
61 |
||
62 |
#include <stdlib.h> |
|
63 |
||
64 |
QT_BEGIN_NAMESPACE |
|
65 |
||
66 |
static QString driveSpec(const QString &path) |
|
67 |
{ |
|
68 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
69 |
if (path.size() < 2) |
|
70 |
return QString(); |
|
71 |
char c = path.at(0).toAscii(); |
|
72 |
if (c < 'a' && c > 'z' && c < 'A' && c > 'Z') |
|
73 |
return QString(); |
|
74 |
if (path.at(1).toAscii() != ':') |
|
75 |
return QString(); |
|
76 |
return path.mid(0, 2); |
|
77 |
#else |
|
78 |
Q_UNUSED(path); |
|
79 |
return QString(); |
|
80 |
#endif |
|
81 |
} |
|
82 |
||
83 |
//************* QDirPrivate |
|
84 |
class QDirPrivate |
|
85 |
{ |
|
86 |
friend struct QScopedPointerDeleter<QDirPrivate>; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
87 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
88 |
public: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
89 |
QDirPrivate(const QDir *copy = 0); |
0 | 90 |
~QDirPrivate(); |
91 |
||
92 |
void updateFileLists() const; |
|
93 |
void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *) const; |
|
94 |
||
95 |
#ifdef QT3_SUPPORT |
|
96 |
QChar filterSepChar; |
|
97 |
bool matchAllDirs; |
|
98 |
#endif |
|
99 |
static inline QChar getFilterSepChar(const QString &nameFilter) |
|
100 |
{ |
|
101 |
QChar sep(QLatin1Char(';')); |
|
102 |
int i = nameFilter.indexOf(sep, 0); |
|
103 |
if (i == -1 && nameFilter.indexOf(QLatin1Char(' '), 0) != -1) |
|
104 |
sep = QChar(QLatin1Char(' ')); |
|
105 |
return sep; |
|
106 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
107 |
static inline QStringList splitFilters(const QString &nameFilter, QChar sep = 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
108 |
if (sep == 0) |
0 | 109 |
sep = getFilterSepChar(nameFilter); |
110 |
QStringList ret = nameFilter.split(sep); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
111 |
for (int i = 0; i < ret.count(); ++i) |
0 | 112 |
ret[i] = ret[i].trimmed(); |
113 |
return ret; |
|
114 |
} |
|
115 |
||
116 |
struct Data { |
|
117 |
inline Data() |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
118 |
: ref(1), fileEngine(0), listsDirty(1) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
119 |
{} |
0 | 120 |
inline Data(const Data ©) |
121 |
: ref(1), path(copy.path), nameFilters(copy.nameFilters), sort(copy.sort), |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
122 |
filters(copy.filters), fileEngine(0), listsDirty(1) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
123 |
{} |
0 | 124 |
inline ~Data() |
125 |
{ delete fileEngine; } |
|
126 |
||
127 |
inline void clear() { |
|
128 |
listsDirty = 1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
129 |
files.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
130 |
fileInfos.clear(); |
0 | 131 |
} |
132 |
mutable QAtomicInt ref; |
|
133 |
||
134 |
QString path; |
|
135 |
QStringList nameFilters; |
|
136 |
QDir::SortFlags sort; |
|
137 |
QDir::Filters filters; |
|
138 |
||
139 |
mutable QAbstractFileEngine *fileEngine; |
|
140 |
||
141 |
mutable uint listsDirty : 1; |
|
142 |
mutable QStringList files; |
|
143 |
mutable QFileInfoList fileInfos; |
|
144 |
} *data; |
|
145 |
inline void setPath(const QString &p) |
|
146 |
{ |
|
147 |
detach(false); |
|
148 |
QString path = p; |
|
149 |
if ((path.endsWith(QLatin1Char('/')) || path.endsWith(QLatin1Char('\\'))) |
|
150 |
&& path.length() > 1) { |
|
151 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
152 |
if (!(path.length() == 3 && path.at(1) == QLatin1Char(':'))) |
|
153 |
#endif |
|
154 |
path.truncate(path.length() - 1); |
|
155 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
156 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
157 |
delete data->fileEngine; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
158 |
data->fileEngine = QAbstractFileEngine::create(path); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
159 |
|
0 | 160 |
// set the path to be the qt friendly version so then we can operate on it using just / |
161 |
data->path = data->fileEngine->fileName(QAbstractFileEngine::DefaultName); |
|
162 |
data->clear(); |
|
163 |
} |
|
164 |
inline void reset() { |
|
165 |
detach(); |
|
166 |
data->clear(); |
|
167 |
} |
|
168 |
void detach(bool createFileEngine = true); |
|
169 |
}; |
|
170 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
171 |
QDirPrivate::QDirPrivate(const QDir *copy) |
0 | 172 |
#ifdef QT3_SUPPORT |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
173 |
: filterSepChar(0), matchAllDirs(false) |
0 | 174 |
#endif |
175 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
176 |
if (copy) { |
0 | 177 |
copy->d_func()->data->ref.ref(); |
178 |
data = copy->d_func()->data; |
|
179 |
} else { |
|
180 |
data = new QDirPrivate::Data; |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
QDirPrivate::~QDirPrivate() |
|
185 |
{ |
|
186 |
if (!data->ref.deref()) |
|
187 |
delete data; |
|
188 |
data = 0; |
|
189 |
} |
|
190 |
||
191 |
/* For sorting */ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
192 |
struct QDirSortItem |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
193 |
{ |
0 | 194 |
mutable QString filename_cache; |
195 |
mutable QString suffix_cache; |
|
196 |
QFileInfo item; |
|
197 |
}; |
|
198 |
||
199 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
200 |
class QDirSortItemComparator |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
201 |
{ |
0 | 202 |
int qt_cmp_si_sort_flags; |
203 |
public: |
|
204 |
QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {} |
|
205 |
bool operator()(const QDirSortItem &, const QDirSortItem &); |
|
206 |
}; |
|
207 |
||
208 |
bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortItem &n2) |
|
209 |
{ |
|
210 |
const QDirSortItem* f1 = &n1; |
|
211 |
const QDirSortItem* f2 = &n2; |
|
212 |
||
213 |
if ((qt_cmp_si_sort_flags & QDir::DirsFirst) && (f1->item.isDir() != f2->item.isDir())) |
|
214 |
return f1->item.isDir(); |
|
215 |
if ((qt_cmp_si_sort_flags & QDir::DirsLast) && (f1->item.isDir() != f2->item.isDir())) |
|
216 |
return !f1->item.isDir(); |
|
217 |
||
218 |
int r = 0; |
|
219 |
int sortBy = (qt_cmp_si_sort_flags & QDir::SortByMask) |
|
220 |
| (qt_cmp_si_sort_flags & QDir::Type); |
|
221 |
||
222 |
switch (sortBy) { |
|
223 |
case QDir::Time: |
|
224 |
r = f1->item.lastModified().secsTo(f2->item.lastModified()); |
|
225 |
break; |
|
226 |
case QDir::Size: |
|
227 |
r = int(qBound<qint64>(-1, f2->item.size() - f1->item.size(), 1)); |
|
228 |
break; |
|
229 |
case QDir::Type: |
|
230 |
{ |
|
231 |
bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase; |
|
232 |
||
233 |
if (f1->suffix_cache.isNull()) |
|
234 |
f1->suffix_cache = ic ? f1->item.suffix().toLower() |
|
235 |
: f1->item.suffix(); |
|
236 |
if (f2->suffix_cache.isNull()) |
|
237 |
f2->suffix_cache = ic ? f2->item.suffix().toLower() |
|
238 |
: f2->item.suffix(); |
|
239 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
240 |
r = qt_cmp_si_sort_flags & QDir::LocaleAware |
0 | 241 |
? f1->suffix_cache.localeAwareCompare(f2->suffix_cache) |
242 |
: f1->suffix_cache.compare(f2->suffix_cache); |
|
243 |
} |
|
244 |
break; |
|
245 |
default: |
|
246 |
; |
|
247 |
} |
|
248 |
||
249 |
if (r == 0 && sortBy != QDir::Unsorted) { |
|
250 |
// Still not sorted - sort by name |
|
251 |
bool ic = qt_cmp_si_sort_flags & QDir::IgnoreCase; |
|
252 |
||
253 |
if (f1->filename_cache.isNull()) |
|
254 |
f1->filename_cache = ic ? f1->item.fileName().toLower() |
|
255 |
: f1->item.fileName(); |
|
256 |
if (f2->filename_cache.isNull()) |
|
257 |
f2->filename_cache = ic ? f2->item.fileName().toLower() |
|
258 |
: f2->item.fileName(); |
|
259 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
260 |
r = qt_cmp_si_sort_flags & QDir::LocaleAware |
0 | 261 |
? f1->filename_cache.localeAwareCompare(f2->filename_cache) |
262 |
: f1->filename_cache.compare(f2->filename_cache); |
|
263 |
} |
|
264 |
if (r == 0) // Enforce an order - the order the items appear in the array |
|
265 |
r = (&n1) - (&n2); |
|
266 |
if (qt_cmp_si_sort_flags & QDir::Reversed) |
|
267 |
return r > 0; |
|
268 |
return r < 0; |
|
269 |
} |
|
270 |
||
271 |
inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, |
|
272 |
QStringList *names, QFileInfoList *infos) const |
|
273 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
274 |
// names and infos are always empty lists or 0 here |
0 | 275 |
int n = l.size(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
276 |
if (n > 0) { |
0 | 277 |
if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) { |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
278 |
if (infos) |
0 | 279 |
*infos = l; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
280 |
if (names) { |
0 | 281 |
for (int i = 0; i < n; ++i) |
282 |
names->append(l.at(i).fileName()); |
|
283 |
} |
|
284 |
} else { |
|
285 |
QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]); |
|
286 |
for (int i = 0; i < n; ++i) |
|
287 |
si[i].item = l.at(i); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
288 |
qSort(si.data(), si.data() + n, QDirSortItemComparator(sort)); |
0 | 289 |
// put them back in the list(s) |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
290 |
if (infos) { |
0 | 291 |
for (int i = 0; i < n; ++i) |
292 |
infos->append(si[i].item); |
|
293 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
294 |
if (names) { |
0 | 295 |
for (int i = 0; i < n; ++i) |
296 |
names->append(si[i].item.fileName()); |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
||
302 |
inline void QDirPrivate::updateFileLists() const |
|
303 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
304 |
if (data->listsDirty) { |
0 | 305 |
QFileInfoList l; |
306 |
QDirIterator it(data->path, data->nameFilters, data->filters); |
|
307 |
while (it.hasNext()) { |
|
308 |
it.next(); |
|
309 |
l.append(it.fileInfo()); |
|
310 |
} |
|
311 |
sortFileList(data->sort, l, &data->files, &data->fileInfos); |
|
312 |
data->listsDirty = 0; |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
void QDirPrivate::detach(bool createFileEngine) |
|
317 |
{ |
|
318 |
qAtomicDetach(data); |
|
319 |
if (createFileEngine) { |
|
320 |
QAbstractFileEngine *newFileEngine = QAbstractFileEngine::create(data->path); |
|
321 |
delete data->fileEngine; |
|
322 |
data->fileEngine = newFileEngine; |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
/*! |
|
327 |
\class QDir |
|
328 |
\brief The QDir class provides access to directory structures and their contents. |
|
329 |
||
330 |
\ingroup io |
|
331 |
\ingroup shared |
|
332 |
\reentrant |
|
333 |
||
334 |
||
335 |
A QDir is used to manipulate path names, access information |
|
336 |
regarding paths and files, and manipulate the underlying file |
|
337 |
system. It can also be used to access Qt's \l{resource system}. |
|
338 |
||
339 |
Qt uses "/" as a universal directory separator in the same way |
|
340 |
that "/" is used as a path separator in URLs. If you always use |
|
341 |
"/" as a directory separator, Qt will translate your paths to |
|
342 |
conform to the underlying operating system. |
|
343 |
||
344 |
A QDir can point to a file using either a relative or an absolute |
|
345 |
path. Absolute paths begin with the directory separator |
|
346 |
(optionally preceded by a drive specification under Windows). |
|
347 |
Relative file names begin with a directory name or a file name and |
|
348 |
specify a path relative to the current directory. |
|
349 |
||
350 |
Examples of absolute paths: |
|
351 |
||
352 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 0 |
|
353 |
||
354 |
On Windows, the second example above will be translated to |
|
355 |
\c{C:\Documents and Settings} when used to access files. |
|
356 |
||
357 |
Examples of relative paths: |
|
358 |
||
359 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 1 |
|
360 |
||
361 |
You can use the isRelative() or isAbsolute() functions to check if |
|
362 |
a QDir is using a relative or an absolute file path. Call |
|
363 |
makeAbsolute() to convert a relative QDir to an absolute one. |
|
364 |
||
365 |
\section1 Navigation and Directory Operations |
|
366 |
||
367 |
A directory's path can be obtained with the path() function, and |
|
368 |
a new path set with the setPath() function. The absolute path to |
|
369 |
a directory is found by calling absolutePath(). |
|
370 |
||
371 |
The name of a directory is found using the dirName() function. This |
|
372 |
typically returns the last element in the absolute path that specifies |
|
373 |
the location of the directory. However, it can also return "." if |
|
374 |
the QDir represents the current directory. |
|
375 |
||
376 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 2 |
|
377 |
||
378 |
The path for a directory can also be changed with the cd() and cdUp() |
|
379 |
functions, both of which operate like familiar shell commands. |
|
380 |
When cd() is called with the name of an existing directory, the QDir |
|
381 |
object changes directory so that it represents that directory instead. |
|
382 |
The cdUp() function changes the directory of the QDir object so that |
|
383 |
it refers to its parent directory; i.e. cd("..") is equivalent to |
|
384 |
cdUp(). |
|
385 |
||
386 |
Directories can be created with mkdir(), renamed with rename(), and |
|
387 |
removed with rmdir(). |
|
388 |
||
389 |
You can test for the presence of a directory with a given name by |
|
390 |
using exists(), and the properties of a directory can be tested with |
|
391 |
isReadable(), isAbsolute(), isRelative(), and isRoot(). |
|
392 |
||
393 |
The refresh() function re-reads the directory's data from disk. |
|
394 |
||
395 |
\section1 Files and Directory Contents |
|
396 |
||
397 |
Directories contain a number of entries, representing files, |
|
398 |
directories, and symbolic links. The number of entries in a |
|
399 |
directory is returned by count(). |
|
400 |
A string list of the names of all the entries in a directory can be |
|
401 |
obtained with entryList(). If you need information about each |
|
402 |
entry, use entryInfoList() to obtain a list of QFileInfo objects. |
|
403 |
||
404 |
Paths to files and directories within a directory can be |
|
405 |
constructed using filePath() and absoluteFilePath(). |
|
406 |
The filePath() function returns a path to the specified file |
|
407 |
or directory relative to the path of the QDir object; |
|
408 |
absoluteFilePath() returns an absolute path to the specified |
|
409 |
file or directory. Neither of these functions checks for the |
|
410 |
existence of files or directory; they only construct paths. |
|
411 |
||
412 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 3 |
|
413 |
||
414 |
Files can be removed by using the remove() function. Directories |
|
415 |
cannot be removed in the same way as files; use rmdir() to remove |
|
416 |
them instead. |
|
417 |
||
418 |
It is possible to reduce the number of entries returned by |
|
419 |
entryList() and entryInfoList() by applying filters to a QDir object. |
|
420 |
You can apply a name filter to specify a pattern with wildcards that |
|
421 |
file names need to match, an attribute filter that selects properties |
|
422 |
of entries and can distinguish between files and directories, and a |
|
423 |
sort order. |
|
424 |
||
425 |
Name filters are lists of strings that are passed to setNameFilters(). |
|
426 |
Attribute filters consist of a bitwise OR combination of Filters, and |
|
427 |
these are specified when calling setFilter(). |
|
428 |
The sort order is specified using setSorting() with a bitwise OR |
|
429 |
combination of SortFlags. |
|
430 |
||
431 |
You can test to see if a filename matches a filter using the match() |
|
432 |
function. |
|
433 |
||
434 |
Filter and sort order flags may also be specified when calling |
|
435 |
entryList() and entryInfoList() in order to override previously defined |
|
436 |
behavior. |
|
437 |
||
438 |
\section1 The Current Directory and Other Special Paths |
|
439 |
||
440 |
Access to some common directories is provided with a number of static |
|
441 |
functions that return QDir objects. There are also corresponding functions |
|
442 |
for these that return strings: |
|
443 |
||
444 |
\table |
|
445 |
\header \o QDir \o QString \o Return Value |
|
446 |
\row \o current() \o currentPath() \o The application's working directory |
|
447 |
\row \o home() \o homePath() \o The user's home directory |
|
448 |
\row \o root() \o rootPath() \o The root directory |
|
449 |
\row \o temp() \o tempPath() \o The system's temporary directory |
|
450 |
\endtable |
|
451 |
||
452 |
The setCurrent() static function can also be used to set the application's |
|
453 |
working directory. |
|
454 |
||
455 |
If you want to find the directory containing the application's executable, |
|
456 |
see \l{QCoreApplication::applicationDirPath()}. |
|
457 |
||
458 |
The drives() static function provides a list of root directories for each |
|
459 |
device that contains a filing system. On Unix systems this returns a list |
|
460 |
containing a single root directory "/"; on Windows the list will usually |
|
461 |
contain \c{C:/}, and possibly other drive letters such as \c{D:/}, depending |
|
462 |
on the configuration of the user's system. |
|
463 |
||
464 |
\section1 Path Manipulation and Strings |
|
465 |
||
466 |
Paths containing "." elements that reference the current directory at that |
|
467 |
point in the path, ".." elements that reference the parent directory, and |
|
468 |
symbolic links can be reduced to a canonical form using the canonicalPath() |
|
469 |
function. |
|
470 |
||
471 |
Paths can also be simplified by using cleanPath() to remove redundant "/" |
|
472 |
and ".." elements. |
|
473 |
||
474 |
It is sometimes necessary to be able to show a path in the native |
|
475 |
representation for the user's platform. The static toNativeSeparators() |
|
476 |
function returns a copy of the specified path in which each directory |
|
477 |
separator is replaced by the appropriate separator for the underlying |
|
478 |
operating system. |
|
479 |
||
480 |
\section1 Examples |
|
481 |
||
482 |
Check if a directory exists: |
|
483 |
||
484 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 4 |
|
485 |
||
486 |
(We could also use the static convenience function |
|
487 |
QFile::exists().) |
|
488 |
||
489 |
Traversing directories and reading a file: |
|
490 |
||
491 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 5 |
|
492 |
||
493 |
A program that lists all the files in the current directory |
|
494 |
(excluding symbolic links), sorted by size, smallest first: |
|
495 |
||
496 |
\snippet doc/src/snippets/qdir-listfiles/main.cpp 0 |
|
497 |
||
498 |
\sa QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), {Find Files Example} |
|
499 |
*/ |
|
500 |
||
501 |
/*! |
|
502 |
Constructs a QDir pointing to the given directory \a path. If path |
|
503 |
is empty the program's working directory, ("."), is used. |
|
504 |
||
505 |
\sa currentPath() |
|
506 |
*/ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
507 |
QDir::QDir(const QString &path) : d_ptr(new QDirPrivate) |
0 | 508 |
{ |
509 |
Q_D(QDir); |
|
510 |
d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path); |
|
511 |
d->data->nameFilters = QStringList(QString::fromLatin1("*")); |
|
512 |
d->data->filters = AllEntries; |
|
513 |
d->data->sort = SortFlags(Name | IgnoreCase); |
|
514 |
} |
|
515 |
||
516 |
/*! |
|
517 |
Constructs a QDir with path \a path, that filters its entries by |
|
518 |
name using \a nameFilter and by attributes using \a filters. It |
|
519 |
also sorts the names using \a sort. |
|
520 |
||
521 |
The default \a nameFilter is an empty string, which excludes |
|
522 |
nothing; the default \a filters is \l AllEntries, which also means |
|
523 |
exclude nothing. The default \a sort is \l Name | \l IgnoreCase, |
|
524 |
i.e. sort by name case-insensitively. |
|
525 |
||
526 |
If \a path is an empty string, QDir uses "." (the current |
|
527 |
directory). If \a nameFilter is an empty string, QDir uses the |
|
528 |
name filter "*" (all files). |
|
529 |
||
530 |
Note that \a path need not exist. |
|
531 |
||
532 |
\sa exists(), setPath(), setNameFilter(), setFilter(), setSorting() |
|
533 |
*/ |
|
534 |
QDir::QDir(const QString &path, const QString &nameFilter, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
535 |
SortFlags sort, Filters filters) : d_ptr(new QDirPrivate) |
0 | 536 |
{ |
537 |
Q_D(QDir); |
|
538 |
d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path); |
|
539 |
d->data->nameFilters = QDir::nameFiltersFromString(nameFilter); |
|
540 |
bool empty = d->data->nameFilters.isEmpty(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
541 |
if (!empty) { |
0 | 542 |
empty = true; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
543 |
for (int i = 0; i < d->data->nameFilters.size(); ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
544 |
if (!d->data->nameFilters.at(i).isEmpty()) { |
0 | 545 |
empty = false; |
546 |
break; |
|
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
if (empty) |
|
551 |
d->data->nameFilters = QStringList(QString::fromLatin1("*")); |
|
552 |
d->data->sort = sort; |
|
553 |
d->data->filters = filters; |
|
554 |
} |
|
555 |
||
556 |
/*! |
|
557 |
Constructs a QDir object that is a copy of the QDir object for |
|
558 |
directory \a dir. |
|
559 |
||
560 |
\sa operator=() |
|
561 |
*/ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
562 |
QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(&dir)) |
0 | 563 |
{ |
564 |
} |
|
565 |
||
566 |
/*! |
|
567 |
Destroys the QDir object frees up its resources. This has no |
|
568 |
effect on the underlying directory in the file system. |
|
569 |
*/ |
|
570 |
QDir::~QDir() |
|
571 |
{ |
|
572 |
} |
|
573 |
||
574 |
/*! |
|
575 |
Sets the path of the directory to \a path. The path is cleaned of |
|
576 |
redundant ".", ".." and of multiple separators. No check is made |
|
577 |
to see whether a directory with this path actually exists; but you |
|
578 |
can check for yourself using exists(). |
|
579 |
||
580 |
The path can be either absolute or relative. Absolute paths begin |
|
581 |
with the directory separator "/" (optionally preceded by a drive |
|
582 |
specification under Windows). Relative file names begin with a |
|
583 |
directory name or a file name and specify a path relative to the |
|
584 |
current directory. An example of an absolute path is the string |
|
585 |
"/tmp/quartz", a relative path might look like "src/fatlib". |
|
586 |
||
587 |
\sa path(), absolutePath(), exists(), cleanPath(), dirName(), |
|
588 |
absoluteFilePath(), isRelative(), makeAbsolute() |
|
589 |
*/ |
|
590 |
void QDir::setPath(const QString &path) |
|
591 |
{ |
|
592 |
Q_D(QDir); |
|
593 |
d->setPath(path); |
|
594 |
} |
|
595 |
||
596 |
/*! |
|
597 |
Returns the path. This may contain symbolic links, but never |
|
598 |
contains redundant ".", ".." or multiple separators. |
|
599 |
||
600 |
The returned path can be either absolute or relative (see |
|
601 |
setPath()). |
|
602 |
||
603 |
\sa setPath(), absolutePath(), exists(), cleanPath(), dirName(), |
|
604 |
absoluteFilePath(), toNativeSeparators(), makeAbsolute() |
|
605 |
*/ |
|
606 |
QString QDir::path() const |
|
607 |
{ |
|
608 |
Q_D(const QDir); |
|
609 |
return d->data->path; |
|
610 |
} |
|
611 |
||
612 |
/*! |
|
613 |
Returns the absolute path (a path that starts with "/" or with a |
|
614 |
drive specification), which may contain symbolic links, but never |
|
615 |
contains redundant ".", ".." or multiple separators. |
|
616 |
||
617 |
\sa setPath(), canonicalPath(), exists(), cleanPath(), |
|
618 |
dirName(), absoluteFilePath() |
|
619 |
*/ |
|
620 |
QString QDir::absolutePath() const |
|
621 |
{ |
|
622 |
Q_D(const QDir); |
|
623 |
QString ret = d->data->path; |
|
624 |
if (QDir::isRelativePath(ret)) |
|
625 |
ret = absoluteFilePath(QString::fromLatin1("")); |
|
626 |
return cleanPath(ret); |
|
627 |
} |
|
628 |
||
629 |
/*! |
|
630 |
Returns the canonical path, i.e. a path without symbolic links or |
|
631 |
redundant "." or ".." elements. |
|
632 |
||
633 |
On systems that do not have symbolic links this function will |
|
634 |
always return the same string that absolutePath() returns. If the |
|
635 |
canonical path does not exist (normally due to dangling symbolic |
|
636 |
links) canonicalPath() returns an empty string. |
|
637 |
||
638 |
Example: |
|
639 |
||
640 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 6 |
|
641 |
||
642 |
\sa path(), absolutePath(), exists(), cleanPath(), dirName(), |
|
643 |
absoluteFilePath() |
|
644 |
*/ |
|
645 |
QString QDir::canonicalPath() const |
|
646 |
{ |
|
647 |
Q_D(const QDir); |
|
648 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
649 |
if (!d->data->fileEngine) |
0 | 650 |
return QLatin1String(""); |
651 |
return cleanPath(d->data->fileEngine->fileName(QAbstractFileEngine::CanonicalName)); |
|
652 |
} |
|
653 |
||
654 |
/*! |
|
655 |
Returns the name of the directory; this is \e not the same as the |
|
656 |
path, e.g. a directory with the name "mail", might have the path |
|
657 |
"/var/spool/mail". If the directory has no name (e.g. it is the |
|
658 |
root directory) an empty string is returned. |
|
659 |
||
660 |
No check is made to ensure that a directory with this name |
|
661 |
actually exists; but see exists(). |
|
662 |
||
663 |
\sa path(), filePath(), absolutePath(), absoluteFilePath() |
|
664 |
*/ |
|
665 |
QString QDir::dirName() const |
|
666 |
{ |
|
667 |
Q_D(const QDir); |
|
668 |
int pos = d->data->path.lastIndexOf(QLatin1Char('/')); |
|
669 |
if (pos == -1) |
|
670 |
return d->data->path; |
|
671 |
return d->data->path.mid(pos + 1); |
|
672 |
} |
|
673 |
||
674 |
/*! |
|
675 |
Returns the path name of a file in the directory. Does \e not |
|
676 |
check if the file actually exists in the directory; but see |
|
677 |
exists(). If the QDir is relative the returned path name will also |
|
678 |
be relative. Redundant multiple separators or "." and ".." |
|
679 |
directories in \a fileName are not removed (see cleanPath()). |
|
680 |
||
681 |
\sa dirName() absoluteFilePath(), isRelative(), canonicalPath() |
|
682 |
*/ |
|
683 |
QString QDir::filePath(const QString &fileName) const |
|
684 |
{ |
|
685 |
Q_D(const QDir); |
|
686 |
if (isAbsolutePath(fileName)) |
|
687 |
return QString(fileName); |
|
688 |
||
689 |
QString ret = d->data->path; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
690 |
if (!fileName.isEmpty()) { |
0 | 691 |
if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/')) |
692 |
ret += QLatin1Char('/'); |
|
693 |
ret += fileName; |
|
694 |
} |
|
695 |
return ret; |
|
696 |
} |
|
697 |
||
698 |
/*! |
|
699 |
Returns the absolute path name of a file in the directory. Does \e |
|
700 |
not check if the file actually exists in the directory; but see |
|
701 |
exists(). Redundant multiple separators or "." and ".." |
|
702 |
directories in \a fileName are not removed (see cleanPath()). |
|
703 |
||
704 |
\sa relativeFilePath() filePath() canonicalPath() |
|
705 |
*/ |
|
706 |
QString QDir::absoluteFilePath(const QString &fileName) const |
|
707 |
{ |
|
708 |
Q_D(const QDir); |
|
709 |
if (isAbsolutePath(fileName)) |
|
710 |
return fileName; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
711 |
if (!d->data->fileEngine) |
0 | 712 |
return fileName; |
713 |
||
714 |
QString ret; |
|
715 |
#ifndef QT_NO_FSFILEENGINE |
|
716 |
if (isRelativePath(d->data->path)) //get pwd |
|
717 |
ret = QFSFileEngine::currentPath(fileName); |
|
718 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
719 |
if (!d->data->path.isEmpty() && d->data->path != QLatin1String(".")) { |
0 | 720 |
if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) |
721 |
ret += QLatin1Char('/'); |
|
722 |
ret += d->data->path; |
|
723 |
} |
|
724 |
if (!fileName.isEmpty()) { |
|
725 |
if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) |
|
726 |
ret += QLatin1Char('/'); |
|
727 |
ret += fileName; |
|
728 |
} |
|
729 |
return ret; |
|
730 |
} |
|
731 |
||
732 |
/*! |
|
733 |
Returns the path to \a fileName relative to the directory. |
|
734 |
||
735 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 7 |
|
736 |
||
737 |
\sa absoluteFilePath() filePath() canonicalPath() |
|
738 |
*/ |
|
739 |
QString QDir::relativeFilePath(const QString &fileName) const |
|
740 |
{ |
|
741 |
QString dir = absolutePath(); |
|
742 |
QString file = cleanPath(fileName); |
|
743 |
||
744 |
if (isRelativePath(file) || isRelativePath(dir)) |
|
745 |
return file; |
|
746 |
||
747 |
QString dirDrive = driveSpec(dir); |
|
748 |
QString fileDrive = driveSpec(file); |
|
749 |
||
750 |
bool fileDriveMissing = false; |
|
751 |
if (fileDrive.isEmpty()) { |
|
752 |
fileDrive = dirDrive; |
|
753 |
fileDriveMissing = true; |
|
754 |
} |
|
755 |
||
756 |
#ifdef Q_OS_WIN |
|
757 |
if (fileDrive.toLower() != dirDrive.toLower() |
|
758 |
|| (file.startsWith(QLatin1String("//")) |
|
759 |
&& !dir.startsWith(QLatin1String("//")))) |
|
760 |
#elif defined(Q_OS_SYMBIAN) |
|
761 |
if (fileDrive.toLower() != dirDrive.toLower()) |
|
762 |
#else |
|
763 |
if (fileDrive != dirDrive) |
|
764 |
#endif |
|
765 |
return file; |
|
766 |
||
767 |
dir.remove(0, dirDrive.size()); |
|
768 |
if (!fileDriveMissing) |
|
769 |
file.remove(0, fileDrive.size()); |
|
770 |
||
771 |
QString result; |
|
772 |
QStringList dirElts = dir.split(QLatin1Char('/'), QString::SkipEmptyParts); |
|
773 |
QStringList fileElts = file.split(QLatin1Char('/'), QString::SkipEmptyParts); |
|
774 |
||
775 |
int i = 0; |
|
776 |
while (i < dirElts.size() && i < fileElts.size() && |
|
777 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
|
778 |
dirElts.at(i).toLower() == fileElts.at(i).toLower()) |
|
779 |
#else |
|
780 |
dirElts.at(i) == fileElts.at(i)) |
|
781 |
#endif |
|
782 |
++i; |
|
783 |
||
784 |
for (int j = 0; j < dirElts.size() - i; ++j) |
|
785 |
result += QLatin1String("../"); |
|
786 |
||
787 |
for (int j = i; j < fileElts.size(); ++j) { |
|
788 |
result += fileElts.at(j); |
|
789 |
if (j < fileElts.size() - 1) |
|
790 |
result += QLatin1Char('/'); |
|
791 |
} |
|
792 |
||
793 |
return result; |
|
794 |
} |
|
795 |
||
796 |
/*! |
|
797 |
\obsolete |
|
798 |
||
799 |
Use QDir::toNativeSeparators() instead. |
|
800 |
*/ |
|
801 |
QString QDir::convertSeparators(const QString &pathName) |
|
802 |
{ |
|
803 |
return toNativeSeparators(pathName); |
|
804 |
} |
|
805 |
||
806 |
/*! |
|
807 |
\since 4.2 |
|
808 |
||
809 |
Returns \a pathName with the '/' separators converted to |
|
810 |
separators that are appropriate for the underlying operating |
|
811 |
system. |
|
812 |
||
813 |
On Windows, toNativeSeparators("c:/winnt/system32") returns |
|
814 |
"c:\\winnt\\system32". |
|
815 |
||
816 |
The returned string may be the same as the argument on some |
|
817 |
operating systems, for example on Unix. |
|
818 |
||
819 |
\sa fromNativeSeparators(), separator() |
|
820 |
*/ |
|
821 |
QString QDir::toNativeSeparators(const QString &pathName) |
|
822 |
{ |
|
823 |
QString n(pathName); |
|
824 |
#if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
825 |
for (int i = 0; i < (int)n.length(); ++i) { |
0 | 826 |
if (n[i] == QLatin1Char('/')) |
827 |
n[i] = QLatin1Char('\\'); |
|
828 |
} |
|
829 |
#endif |
|
830 |
return n; |
|
831 |
} |
|
832 |
||
833 |
/*! |
|
834 |
\since 4.2 |
|
835 |
||
836 |
Returns \a pathName using '/' as file separator. On Windows, |
|
837 |
for instance, fromNativeSeparators("\c{c:\\winnt\\system32}") returns |
|
838 |
"c:/winnt/system32". |
|
839 |
||
840 |
The returned string may be the same as the argument on some |
|
841 |
operating systems, for example on Unix. |
|
842 |
||
843 |
\sa toNativeSeparators(), separator() |
|
844 |
*/ |
|
845 |
QString QDir::fromNativeSeparators(const QString &pathName) |
|
846 |
{ |
|
847 |
QString n(pathName); |
|
848 |
#if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
849 |
for (int i = 0; i < (int)n.length(); ++i) { |
0 | 850 |
if (n[i] == QLatin1Char('\\')) |
851 |
n[i] = QLatin1Char('/'); |
|
852 |
} |
|
853 |
#endif |
|
854 |
return n; |
|
855 |
} |
|
856 |
||
857 |
/*! |
|
858 |
Changes the QDir's directory to \a dirName. |
|
859 |
||
860 |
Returns true if the new directory exists and is readable; |
|
861 |
otherwise returns false. Note that the logical cd() operation is |
|
862 |
not performed if the new directory does not exist. |
|
863 |
||
864 |
Calling cd("..") is equivalent to calling cdUp(). |
|
865 |
||
866 |
\sa cdUp(), isReadable(), exists(), path() |
|
867 |
*/ |
|
868 |
bool QDir::cd(const QString &dirName) |
|
869 |
{ |
|
870 |
Q_D(QDir); |
|
871 |
||
872 |
if (dirName.isEmpty() || dirName == QLatin1String(".")) |
|
873 |
return true; |
|
874 |
QString newPath = d->data->path; |
|
875 |
if (isAbsolutePath(dirName)) { |
|
876 |
newPath = cleanPath(dirName); |
|
877 |
} else { |
|
878 |
if (isRoot()) { |
|
879 |
if (dirName == QLatin1String("..")) |
|
880 |
return false; |
|
881 |
} else { |
|
882 |
newPath += QLatin1Char('/'); |
|
883 |
} |
|
884 |
||
885 |
newPath += dirName; |
|
886 |
if (dirName.indexOf(QLatin1Char('/')) >= 0 |
|
887 |
|| d->data->path == QLatin1String(".") |
|
888 |
|| dirName == QLatin1String("..")) { |
|
889 |
newPath = cleanPath(newPath); |
|
890 |
/* |
|
891 |
If newPath starts with .., we convert it to absolute to |
|
892 |
avoid infinite looping on |
|
893 |
||
894 |
QDir dir("."); |
|
895 |
while (dir.cdUp()) |
|
896 |
; |
|
897 |
*/ |
|
898 |
if (newPath.startsWith(QLatin1String(".."))) { |
|
899 |
newPath = QFileInfo(newPath).absoluteFilePath(); |
|
900 |
} |
|
901 |
} |
|
902 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
903 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
904 |
QDir dir(*this); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
905 |
dir.setPath(newPath); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
906 |
if (!dir.exists()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
907 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
908 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
909 |
*this = dir; |
0 | 910 |
return true; |
911 |
} |
|
912 |
||
913 |
/*! |
|
914 |
Changes directory by moving one directory up from the QDir's |
|
915 |
current directory. |
|
916 |
||
917 |
Returns true if the new directory exists and is readable; |
|
918 |
otherwise returns false. Note that the logical cdUp() operation is |
|
919 |
not performed if the new directory does not exist. |
|
920 |
||
921 |
\sa cd(), isReadable(), exists(), path() |
|
922 |
*/ |
|
923 |
bool QDir::cdUp() |
|
924 |
{ |
|
925 |
return cd(QString::fromLatin1("..")); |
|
926 |
} |
|
927 |
||
928 |
/*! |
|
929 |
Returns the string list set by setNameFilters() |
|
930 |
*/ |
|
931 |
QStringList QDir::nameFilters() const |
|
932 |
{ |
|
933 |
Q_D(const QDir); |
|
934 |
||
935 |
return d->data->nameFilters; |
|
936 |
} |
|
937 |
||
938 |
/*! |
|
939 |
Sets the name filters used by entryList() and entryInfoList() to the |
|
940 |
list of filters specified by \a nameFilters. |
|
941 |
||
942 |
Each name filter is a wildcard (globbing) filter that understands |
|
943 |
\c{*} and \c{?} wildcards. (See \l{QRegExp wildcard matching}.) |
|
944 |
||
945 |
For example, the following code sets three name filters on a QDir |
|
946 |
to ensure that only files with extensions typically used for C++ |
|
947 |
source files are listed: |
|
948 |
||
949 |
\snippet doc/src/snippets/qdir-namefilters/main.cpp 0 |
|
950 |
||
951 |
\sa nameFilters(), setFilter() |
|
952 |
*/ |
|
953 |
void QDir::setNameFilters(const QStringList &nameFilters) |
|
954 |
{ |
|
955 |
Q_D(QDir); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
956 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
957 |
d->reset(); |
0 | 958 |
d->data->nameFilters = nameFilters; |
959 |
} |
|
960 |
||
961 |
/*! |
|
962 |
\obsolete |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
963 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
964 |
Use QDir::addSearchPath() with a prefix instead. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
965 |
|
0 | 966 |
Adds \a path to the search paths searched in to find resources |
967 |
that are not specified with an absolute path. The default search |
|
968 |
path is to search only in the root (\c{:/}). |
|
969 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
970 |
\sa {The Qt Resource System} |
0 | 971 |
*/ |
972 |
void QDir::addResourceSearchPath(const QString &path) |
|
973 |
{ |
|
974 |
#ifdef QT_BUILD_CORE_LIB |
|
975 |
QResource::addSearchPath(path); |
|
976 |
#else |
|
977 |
Q_UNUSED(path) |
|
978 |
#endif |
|
979 |
} |
|
980 |
||
981 |
#ifdef QT_BUILD_CORE_LIB |
|
982 |
/*! |
|
983 |
\since 4.3 |
|
984 |
||
985 |
Sets or replaces Qt's search paths for file names with the prefix \a prefix |
|
986 |
to \a searchPaths. |
|
987 |
||
988 |
To specify a prefix for a file name, prepend the prefix followed by a single |
|
989 |
colon (e.g., "images:undo.png", "xmldocs:books.xml"). \a prefix can only |
|
990 |
contain letters or numbers (e.g., it cannot contain a colon, nor a slash). |
|
991 |
||
992 |
Qt uses this search path to locate files with a known prefix. The search |
|
993 |
path entries are tested in order, starting with the first entry. |
|
994 |
||
995 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 8 |
|
996 |
||
997 |
File name prefix must be at least 2 characters long to avoid conflicts with |
|
998 |
Windows drive letters. |
|
999 |
||
1000 |
Search paths may contain paths to \l{The Qt Resource System}. |
|
1001 |
*/ |
|
1002 |
void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths) |
|
1003 |
{ |
|
1004 |
if (prefix.length() < 2) { |
|
1005 |
qWarning("QDir::setSearchPaths: Prefix must be longer than 1 character"); |
|
1006 |
return; |
|
1007 |
} |
|
1008 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1009 |
for (int i = 0; i < prefix.count(); ++i) { |
0 | 1010 |
if (!prefix.at(i).isLetterOrNumber()) { |
1011 |
qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers"); |
|
1012 |
return; |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); |
|
1017 |
QMap<QString, QStringList> &paths = QCoreGlobalData::instance()->dirSearchPaths; |
|
1018 |
if (searchPaths.isEmpty()) { |
|
1019 |
paths.remove(prefix); |
|
1020 |
} else { |
|
1021 |
paths.insert(prefix, searchPaths); |
|
1022 |
} |
|
1023 |
} |
|
1024 |
||
1025 |
/*! |
|
1026 |
\since 4.3 |
|
1027 |
||
1028 |
Adds \a path to the search path for \a prefix. |
|
1029 |
||
1030 |
\sa setSearchPaths() |
|
1031 |
*/ |
|
1032 |
void QDir::addSearchPath(const QString &prefix, const QString &path) |
|
1033 |
{ |
|
1034 |
if (path.isEmpty()) |
|
1035 |
return; |
|
1036 |
||
1037 |
QWriteLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); |
|
1038 |
QCoreGlobalData::instance()->dirSearchPaths[prefix] += path; |
|
1039 |
} |
|
1040 |
||
1041 |
/*! |
|
1042 |
\since 4.3 |
|
1043 |
||
1044 |
Returns the search paths for \a prefix. |
|
1045 |
||
1046 |
\sa setSearchPaths(), addSearchPath() |
|
1047 |
*/ |
|
1048 |
QStringList QDir::searchPaths(const QString &prefix) |
|
1049 |
{ |
|
1050 |
QReadLocker lock(&QCoreGlobalData::instance()->dirSearchPathsLock); |
|
1051 |
return QCoreGlobalData::instance()->dirSearchPaths.value(prefix); |
|
1052 |
} |
|
1053 |
||
1054 |
#endif // QT_BUILD_CORE_LIB |
|
1055 |
||
1056 |
/*! |
|
1057 |
Returns the value set by setFilter() |
|
1058 |
*/ |
|
1059 |
QDir::Filters QDir::filter() const |
|
1060 |
{ |
|
1061 |
Q_D(const QDir); |
|
1062 |
||
1063 |
return d->data->filters; |
|
1064 |
} |
|
1065 |
||
1066 |
/*! |
|
1067 |
\enum QDir::Filter |
|
1068 |
||
1069 |
This enum describes the filtering options available to QDir; e.g. |
|
1070 |
for entryList() and entryInfoList(). The filter value is specified |
|
1071 |
by combining values from the following list using the bitwise OR |
|
1072 |
operator: |
|
1073 |
||
1074 |
\value Dirs List directories that match the filters. |
|
1075 |
\value AllDirs List all directories; i.e. don't apply the filters |
|
1076 |
to directory names. |
|
1077 |
\value Files List files. |
|
1078 |
\value Drives List disk drives (ignored under Unix). |
|
1079 |
\value NoSymLinks Do not list symbolic links (ignored by operating |
|
1080 |
systems that don't support symbolic links). |
|
1081 |
\value NoDotAndDotDot Do not list the special entries "." and "..". |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1082 |
\value NoDot Do not list the special entry ".". |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1083 |
\value NoDotDot Do not list the special entry "..". |
0 | 1084 |
\value AllEntries List directories, files, drives and symlinks (this does not list |
1085 |
broken symlinks unless you specify System). |
|
1086 |
\value Readable List files for which the application has read |
|
1087 |
access. The Readable value needs to be combined |
|
1088 |
with Dirs or Files. |
|
1089 |
\value Writable List files for which the application has write |
|
1090 |
access. The Writable value needs to be combined |
|
1091 |
with Dirs or Files. |
|
1092 |
\value Executable List files for which the application has |
|
1093 |
execute access. The Executable value needs to be |
|
1094 |
combined with Dirs or Files. |
|
1095 |
\value Modified Only list files that have been modified (ignored |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
on Unix). |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1097 |
\value Hidden List hidden files (on Unix, files starting with a "."). |
0 | 1098 |
\value System List system files (on Unix, FIFOs, sockets and |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1099 |
device files are included; on Windows, \c {.lnk} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1100 |
files are included) |
0 | 1101 |
\value CaseSensitive The filter should be case sensitive. |
1102 |
||
1103 |
\omitvalue DefaultFilter |
|
1104 |
\omitvalue TypeMask |
|
1105 |
\omitvalue All |
|
1106 |
\omitvalue RWEMask |
|
1107 |
\omitvalue AccessMask |
|
1108 |
\omitvalue PermissionMask |
|
1109 |
\omitvalue NoFilter |
|
1110 |
||
1111 |
Functions that use Filter enum values to filter lists of files |
|
1112 |
and directories will include symbolic links to files and directories |
|
1113 |
unless you set the NoSymLinks value. |
|
1114 |
||
1115 |
A default constructed QDir will not filter out files based on |
|
1116 |
their permissions, so entryList() and entryInfoList() will return |
|
1117 |
all files that are readable, writable, executable, or any |
|
1118 |
combination of the three. This makes the default easy to write, |
|
1119 |
and at the same time useful. |
|
1120 |
||
1121 |
For example, setting the \c Readable, \c Writable, and \c Files |
|
1122 |
flags allows all files to be listed for which the application has read |
|
1123 |
access, write access or both. If the \c Dirs and \c Drives flags are |
|
1124 |
also included in this combination then all drives, directories, all |
|
1125 |
files that the application can read, write, or execute, and symlinks |
|
1126 |
to such files/directories can be listed. |
|
1127 |
||
1128 |
To retrieve the permissons for a directory, use the |
|
1129 |
entryInfoList() function to get the associated QFileInfo objects |
|
1130 |
and then use the QFileInfo::permissons() to obtain the permissions |
|
1131 |
and ownership for each file. |
|
1132 |
*/ |
|
1133 |
||
1134 |
/*! |
|
1135 |
Sets the filter used by entryList() and entryInfoList() to \a |
|
1136 |
filters. The filter is used to specify the kind of files that |
|
1137 |
should be returned by entryList() and entryInfoList(). See |
|
1138 |
\l{QDir::Filter}. |
|
1139 |
||
1140 |
\sa filter(), setNameFilters() |
|
1141 |
*/ |
|
1142 |
void QDir::setFilter(Filters filters) |
|
1143 |
{ |
|
1144 |
Q_D(QDir); |
|
1145 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1146 |
d->reset(); |
0 | 1147 |
d->data->filters = filters; |
1148 |
} |
|
1149 |
||
1150 |
/*! |
|
1151 |
Returns the value set by setSorting() |
|
1152 |
||
1153 |
\sa setSorting() SortFlag |
|
1154 |
*/ |
|
1155 |
QDir::SortFlags QDir::sorting() const |
|
1156 |
{ |
|
1157 |
Q_D(const QDir); |
|
1158 |
||
1159 |
return d->data->sort; |
|
1160 |
} |
|
1161 |
||
1162 |
/*! |
|
1163 |
\enum QDir::SortFlag |
|
1164 |
||
1165 |
This enum describes the sort options available to QDir, e.g. for |
|
1166 |
entryList() and entryInfoList(). The sort value is specified by |
|
1167 |
OR-ing together values from the following list: |
|
1168 |
||
1169 |
\value Name Sort by name. |
|
1170 |
\value Time Sort by time (modification time). |
|
1171 |
\value Size Sort by file size. |
|
1172 |
\value Type Sort by file type (extension). |
|
1173 |
\value Unsorted Do not sort. |
|
1174 |
\value NoSort Not sorted by default. |
|
1175 |
||
1176 |
\value DirsFirst Put the directories first, then the files. |
|
1177 |
\value DirsLast Put the files first, then the directories. |
|
1178 |
\value Reversed Reverse the sort order. |
|
1179 |
\value IgnoreCase Sort case-insensitively. |
|
1180 |
\value LocaleAware Sort items appropriately using the current locale settings. |
|
1181 |
||
1182 |
\omitvalue SortByMask |
|
1183 |
\omitvalue DefaultSort |
|
1184 |
||
1185 |
You can only specify one of the first four. |
|
1186 |
||
1187 |
If you specify both DirsFirst and Reversed, directories are |
|
1188 |
still put first, but in reverse order; the files will be listed |
|
1189 |
after the directories, again in reverse order. |
|
1190 |
*/ |
|
1191 |
||
1192 |
/*! |
|
1193 |
Sets the sort order used by entryList() and entryInfoList(). |
|
1194 |
||
1195 |
The \a sort is specified by OR-ing values from the enum |
|
1196 |
\l{QDir::SortFlag}. |
|
1197 |
||
1198 |
\sa sorting() SortFlag |
|
1199 |
*/ |
|
1200 |
void QDir::setSorting(SortFlags sort) |
|
1201 |
{ |
|
1202 |
Q_D(QDir); |
|
1203 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1204 |
d->reset(); |
0 | 1205 |
d->data->sort = sort; |
1206 |
} |
|
1207 |
||
1208 |
/*! |
|
1209 |
Returns the total number of directories and files in the directory. |
|
1210 |
||
1211 |
Equivalent to entryList().count(). |
|
1212 |
||
1213 |
\sa operator[](), entryList() |
|
1214 |
*/ |
|
1215 |
uint QDir::count() const |
|
1216 |
{ |
|
1217 |
Q_D(const QDir); |
|
1218 |
||
1219 |
d->updateFileLists(); |
|
1220 |
return d->data->files.count(); |
|
1221 |
} |
|
1222 |
||
1223 |
/*! |
|
1224 |
Returns the file name at position \a pos in the list of file |
|
1225 |
names. Equivalent to entryList().at(index). |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1226 |
\a pos must be a valid index position in the list (i.e., 0 <= pos < count()). |
0 | 1227 |
|
1228 |
\sa count(), entryList() |
|
1229 |
*/ |
|
1230 |
QString QDir::operator[](int pos) const |
|
1231 |
{ |
|
1232 |
Q_D(const QDir); |
|
1233 |
||
1234 |
d->updateFileLists(); |
|
1235 |
return d->data->files[pos]; |
|
1236 |
} |
|
1237 |
||
1238 |
/*! |
|
1239 |
\overload |
|
1240 |
||
1241 |
Returns a list of the names of all the files and directories in |
|
1242 |
the directory, ordered according to the name and attribute filters |
|
1243 |
previously set with setNameFilters() and setFilter(), and sorted according |
|
1244 |
to the flags set with setSorting(). |
|
1245 |
||
1246 |
The attribute filter and sorting specifications can be overridden using the |
|
1247 |
\a filters and \a sort arguments. |
|
1248 |
||
1249 |
Returns an empty list if the directory is unreadable, does not |
|
1250 |
exist, or if nothing matches the specification. |
|
1251 |
||
1252 |
\note To list symlinks that point to non existing files, \l System must be |
|
1253 |
passed to the filter. |
|
1254 |
||
1255 |
\sa entryInfoList(), setNameFilters(), setSorting(), setFilter() |
|
1256 |
*/ |
|
1257 |
QStringList QDir::entryList(Filters filters, SortFlags sort) const |
|
1258 |
{ |
|
1259 |
Q_D(const QDir); |
|
1260 |
||
1261 |
return entryList(d->data->nameFilters, filters, sort); |
|
1262 |
} |
|
1263 |
||
1264 |
||
1265 |
/*! |
|
1266 |
\overload |
|
1267 |
||
1268 |
Returns a list of QFileInfo objects for all the files and directories in |
|
1269 |
the directory, ordered according to the name and attribute filters |
|
1270 |
previously set with setNameFilters() and setFilter(), and sorted according |
|
1271 |
to the flags set with setSorting(). |
|
1272 |
||
1273 |
The attribute filter and sorting specifications can be overridden using the |
|
1274 |
\a filters and \a sort arguments. |
|
1275 |
||
1276 |
Returns an empty list if the directory is unreadable, does not |
|
1277 |
exist, or if nothing matches the specification. |
|
1278 |
||
1279 |
\sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() |
|
1280 |
*/ |
|
1281 |
QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const |
|
1282 |
{ |
|
1283 |
Q_D(const QDir); |
|
1284 |
||
1285 |
return entryInfoList(d->data->nameFilters, filters, sort); |
|
1286 |
} |
|
1287 |
||
1288 |
/*! |
|
1289 |
Returns a list of the names of all the files and |
|
1290 |
directories in the directory, ordered according to the name |
|
1291 |
and attribute filters previously set with setNameFilters() |
|
1292 |
and setFilter(), and sorted according to the flags set with |
|
1293 |
setSorting(). |
|
1294 |
||
1295 |
The name filter, file attribute filter, and sorting specification |
|
1296 |
can be overridden using the \a nameFilters, \a filters, and \a sort |
|
1297 |
arguments. |
|
1298 |
||
1299 |
Returns an empty list if the directory is unreadable, does not |
|
1300 |
exist, or if nothing matches the specification. |
|
1301 |
||
1302 |
\sa entryInfoList(), setNameFilters(), setSorting(), setFilter() |
|
1303 |
*/ |
|
1304 |
QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, |
|
1305 |
SortFlags sort) const |
|
1306 |
{ |
|
1307 |
Q_D(const QDir); |
|
1308 |
||
1309 |
if (filters == NoFilter) |
|
1310 |
filters = d->data->filters; |
|
1311 |
#ifdef QT3_SUPPORT |
|
1312 |
if (d->matchAllDirs) |
|
1313 |
filters |= AllDirs; |
|
1314 |
#endif |
|
1315 |
if (sort == NoSort) |
|
1316 |
sort = d->data->sort; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1317 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1318 |
if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) { |
0 | 1319 |
d->updateFileLists(); |
1320 |
return d->data->files; |
|
1321 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1322 |
|
0 | 1323 |
QFileInfoList l; |
1324 |
QDirIterator it(d->data->path, nameFilters, filters); |
|
1325 |
while (it.hasNext()) { |
|
1326 |
it.next(); |
|
1327 |
l.append(it.fileInfo()); |
|
1328 |
} |
|
1329 |
QStringList ret; |
|
1330 |
d->sortFileList(sort, l, &ret, 0); |
|
1331 |
return ret; |
|
1332 |
} |
|
1333 |
||
1334 |
/*! |
|
1335 |
Returns a list of QFileInfo objects for all the files and |
|
1336 |
directories in the directory, ordered according to the name |
|
1337 |
and attribute filters previously set with setNameFilters() |
|
1338 |
and setFilter(), and sorted according to the flags set with |
|
1339 |
setSorting(). |
|
1340 |
||
1341 |
The name filter, file attribute filter, and sorting specification |
|
1342 |
can be overridden using the \a nameFilters, \a filters, and \a sort |
|
1343 |
arguments. |
|
1344 |
||
1345 |
Returns an empty list if the directory is unreadable, does not |
|
1346 |
exist, or if nothing matches the specification. |
|
1347 |
||
1348 |
\sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() |
|
1349 |
*/ |
|
1350 |
QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters, |
|
1351 |
SortFlags sort) const |
|
1352 |
{ |
|
1353 |
Q_D(const QDir); |
|
1354 |
||
1355 |
if (filters == NoFilter) |
|
1356 |
filters = d->data->filters; |
|
1357 |
#ifdef QT3_SUPPORT |
|
1358 |
if (d->matchAllDirs) |
|
1359 |
filters |= AllDirs; |
|
1360 |
#endif |
|
1361 |
if (sort == NoSort) |
|
1362 |
sort = d->data->sort; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1363 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1364 |
if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) { |
0 | 1365 |
d->updateFileLists(); |
1366 |
return d->data->fileInfos; |
|
1367 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1368 |
|
0 | 1369 |
QFileInfoList l; |
1370 |
QDirIterator it(d->data->path, nameFilters, filters); |
|
1371 |
while (it.hasNext()) { |
|
1372 |
it.next(); |
|
1373 |
l.append(it.fileInfo()); |
|
1374 |
} |
|
1375 |
QFileInfoList ret; |
|
1376 |
d->sortFileList(sort, l, 0, &ret); |
|
1377 |
return ret; |
|
1378 |
} |
|
1379 |
||
1380 |
/*! |
|
1381 |
Creates a sub-directory called \a dirName. |
|
1382 |
||
1383 |
Returns true on success; otherwise returns false. |
|
1384 |
||
1385 |
\sa rmdir() |
|
1386 |
*/ |
|
1387 |
bool QDir::mkdir(const QString &dirName) const |
|
1388 |
{ |
|
1389 |
Q_D(const QDir); |
|
1390 |
||
1391 |
if (dirName.isEmpty()) { |
|
1392 |
qWarning("QDir::mkdir: Empty or null file name(s)"); |
|
1393 |
return false; |
|
1394 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1395 |
if (!d->data->fileEngine) |
0 | 1396 |
return false; |
1397 |
||
1398 |
QString fn = filePath(dirName); |
|
1399 |
return d->data->fileEngine->mkdir(fn, false); |
|
1400 |
} |
|
1401 |
||
1402 |
/*! |
|
1403 |
Removes the directory specified by \a dirName. |
|
1404 |
||
1405 |
The directory must be empty for rmdir() to succeed. |
|
1406 |
||
1407 |
Returns true if successful; otherwise returns false. |
|
1408 |
||
1409 |
\sa mkdir() |
|
1410 |
*/ |
|
1411 |
bool QDir::rmdir(const QString &dirName) const |
|
1412 |
{ |
|
1413 |
Q_D(const QDir); |
|
1414 |
||
1415 |
if (dirName.isEmpty()) { |
|
1416 |
qWarning("QDir::rmdir: Empty or null file name(s)"); |
|
1417 |
return false; |
|
1418 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1419 |
if (!d->data->fileEngine) |
0 | 1420 |
return false; |
1421 |
||
1422 |
QString fn = filePath(dirName); |
|
1423 |
return d->data->fileEngine->rmdir(fn, false); |
|
1424 |
} |
|
1425 |
||
1426 |
/*! |
|
1427 |
Creates the directory path \a dirPath. |
|
1428 |
||
1429 |
The function will create all parent directories necessary to |
|
1430 |
create the directory. |
|
1431 |
||
1432 |
Returns true if successful; otherwise returns false. |
|
1433 |
||
1434 |
\sa rmpath() |
|
1435 |
*/ |
|
1436 |
bool QDir::mkpath(const QString &dirPath) const |
|
1437 |
{ |
|
1438 |
Q_D(const QDir); |
|
1439 |
||
1440 |
if (dirPath.isEmpty()) { |
|
1441 |
qWarning("QDir::mkpath: Empty or null file name(s)"); |
|
1442 |
return false; |
|
1443 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1444 |
if (!d->data->fileEngine) |
0 | 1445 |
return false; |
1446 |
||
1447 |
QString fn = filePath(dirPath); |
|
1448 |
return d->data->fileEngine->mkdir(fn, true); |
|
1449 |
} |
|
1450 |
||
1451 |
/*! |
|
1452 |
Removes the directory path \a dirPath. |
|
1453 |
||
1454 |
The function will remove all parent directories in \a dirPath, |
|
1455 |
provided that they are empty. This is the opposite of |
|
1456 |
mkpath(dirPath). |
|
1457 |
||
1458 |
Returns true if successful; otherwise returns false. |
|
1459 |
||
1460 |
\sa mkpath() |
|
1461 |
*/ |
|
1462 |
bool QDir::rmpath(const QString &dirPath) const |
|
1463 |
{ |
|
1464 |
Q_D(const QDir); |
|
1465 |
||
1466 |
if (dirPath.isEmpty()) { |
|
1467 |
qWarning("QDir::rmpath: Empty or null file name(s)"); |
|
1468 |
return false; |
|
1469 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1470 |
if (!d->data->fileEngine) |
0 | 1471 |
return false; |
1472 |
||
1473 |
QString fn = filePath(dirPath); |
|
1474 |
return d->data->fileEngine->rmdir(fn, true); |
|
1475 |
} |
|
1476 |
||
1477 |
/*! |
|
1478 |
Returns true if the directory is readable \e and we can open files |
|
1479 |
by name; otherwise returns false. |
|
1480 |
||
1481 |
\warning A false value from this function is not a guarantee that |
|
1482 |
files in the directory are not accessible. |
|
1483 |
||
1484 |
\sa QFileInfo::isReadable() |
|
1485 |
*/ |
|
1486 |
bool QDir::isReadable() const |
|
1487 |
{ |
|
1488 |
Q_D(const QDir); |
|
1489 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1490 |
if (!d->data->fileEngine) |
0 | 1491 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1492 |
const QAbstractFileEngine::FileFlags info = |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1493 |
d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1494 |
| QAbstractFileEngine::PermsMask); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1495 |
if (!(info & QAbstractFileEngine::DirectoryType)) |
0 | 1496 |
return false; |
1497 |
return info & QAbstractFileEngine::ReadUserPerm; |
|
1498 |
} |
|
1499 |
||
1500 |
/*! |
|
1501 |
\overload |
|
1502 |
||
1503 |
Returns true if the directory exists; otherwise returns false. |
|
1504 |
(If a file with the same name is found this function will return false). |
|
1505 |
||
1506 |
The overload of this function that accepts an argument is used to test |
|
1507 |
for the presence of files and directories within a directory. |
|
1508 |
||
1509 |
\sa QFileInfo::exists(), QFile::exists() |
|
1510 |
*/ |
|
1511 |
bool QDir::exists() const |
|
1512 |
{ |
|
1513 |
Q_D(const QDir); |
|
1514 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1515 |
if (!d->data->fileEngine) |
0 | 1516 |
return false; |
1517 |
const QAbstractFileEngine::FileFlags info = |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1518 |
d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1519 |
| QAbstractFileEngine::ExistsFlag |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1520 |
| QAbstractFileEngine::Refresh); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1521 |
if (!(info & QAbstractFileEngine::DirectoryType)) |
0 | 1522 |
return false; |
1523 |
return info & QAbstractFileEngine::ExistsFlag; |
|
1524 |
} |
|
1525 |
||
1526 |
/*! |
|
1527 |
Returns true if the directory is the root directory; otherwise |
|
1528 |
returns false. |
|
1529 |
||
1530 |
Note: If the directory is a symbolic link to the root directory |
|
1531 |
this function returns false. If you want to test for this use |
|
1532 |
canonicalPath(), e.g. |
|
1533 |
||
1534 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 9 |
|
1535 |
||
1536 |
\sa root(), rootPath() |
|
1537 |
*/ |
|
1538 |
bool QDir::isRoot() const |
|
1539 |
{ |
|
1540 |
Q_D(const QDir); |
|
1541 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1542 |
if (!d->data->fileEngine) |
0 | 1543 |
return true; |
1544 |
return d->data->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag; |
|
1545 |
} |
|
1546 |
||
1547 |
/*! |
|
1548 |
\fn bool QDir::isAbsolute() const |
|
1549 |
||
1550 |
Returns true if the directory's path is absolute; otherwise |
|
1551 |
returns false. See isAbsolutePath(). |
|
1552 |
||
1553 |
\sa isRelative() makeAbsolute() cleanPath() |
|
1554 |
*/ |
|
1555 |
||
1556 |
/*! |
|
1557 |
\fn bool QDir::isAbsolutePath(const QString &) |
|
1558 |
||
1559 |
Returns true if \a path is absolute; returns false if it is |
|
1560 |
relative. |
|
1561 |
||
1562 |
\sa isAbsolute() isRelativePath() makeAbsolute() cleanPath() |
|
1563 |
*/ |
|
1564 |
||
1565 |
/*! |
|
1566 |
Returns true if the directory path is relative; otherwise returns |
|
1567 |
false. (Under Unix a path is relative if it does not start with a |
|
1568 |
"/"). |
|
1569 |
||
1570 |
\sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath() |
|
1571 |
*/ |
|
1572 |
bool QDir::isRelative() const |
|
1573 |
{ |
|
1574 |
Q_D(const QDir); |
|
1575 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1576 |
if (!d->data->fileEngine) |
0 | 1577 |
return false; |
1578 |
return d->data->fileEngine->isRelativePath(); |
|
1579 |
} |
|
1580 |
||
1581 |
||
1582 |
/*! |
|
1583 |
Converts the directory path to an absolute path. If it is already |
|
1584 |
absolute nothing happens. Returns true if the conversion |
|
1585 |
succeeded; otherwise returns false. |
|
1586 |
||
1587 |
\sa isAbsolute() isAbsolutePath() isRelative() cleanPath() |
|
1588 |
*/ |
|
1589 |
bool QDir::makeAbsolute() // ### What do the return values signify? |
|
1590 |
{ |
|
1591 |
Q_D(QDir); |
|
1592 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1593 |
if (!d->data->fileEngine) |
0 | 1594 |
return false; |
1595 |
QString absolutePath = d->data->fileEngine->fileName(QAbstractFileEngine::AbsoluteName); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1596 |
if (QDir::isRelativePath(absolutePath)) |
0 | 1597 |
return false; |
1598 |
d->detach(); |
|
1599 |
d->data->path = absolutePath; |
|
1600 |
d->data->fileEngine->setFileName(absolutePath); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1601 |
if (!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType)) |
0 | 1602 |
return false; |
1603 |
return true; |
|
1604 |
} |
|
1605 |
||
1606 |
/*! |
|
1607 |
Returns true if directory \a dir and this directory have the same |
|
1608 |
path and their sort and filter settings are the same; otherwise |
|
1609 |
returns false. |
|
1610 |
||
1611 |
Example: |
|
1612 |
||
1613 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 10 |
|
1614 |
*/ |
|
1615 |
bool QDir::operator==(const QDir &dir) const |
|
1616 |
{ |
|
1617 |
const QDirPrivate *d = d_func(); |
|
1618 |
const QDirPrivate *other = dir.d_func(); |
|
1619 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1620 |
if (d->data == other->data) |
0 | 1621 |
return true; |
1622 |
Q_ASSERT(d->data->fileEngine && other->data->fileEngine); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1623 |
if (d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive()) |
0 | 1624 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1625 |
if (d->data->filters == other->data->filters |
0 | 1626 |
&& d->data->sort == other->data->sort |
1627 |
&& d->data->nameFilters == other->data->nameFilters) { |
|
1628 |
QString dir1 = absolutePath(), dir2 = dir.absolutePath(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1629 |
if (!other->data->fileEngine->caseSensitive()) |
0 | 1630 |
return (dir1.toLower() == dir2.toLower()); |
1631 |
||
1632 |
return (dir1 == dir2); |
|
1633 |
||
1634 |
} |
|
1635 |
return false; |
|
1636 |
} |
|
1637 |
||
1638 |
/*! |
|
1639 |
Makes a copy of the \a dir object and assigns it to this QDir |
|
1640 |
object. |
|
1641 |
*/ |
|
1642 |
QDir &QDir::operator=(const QDir &dir) |
|
1643 |
{ |
|
1644 |
if (this == &dir) |
|
1645 |
return *this; |
|
1646 |
||
1647 |
Q_D(QDir); |
|
1648 |
qAtomicAssign(d->data, dir.d_func()->data); |
|
1649 |
return *this; |
|
1650 |
} |
|
1651 |
||
1652 |
/*! |
|
1653 |
\overload |
|
1654 |
\obsolete |
|
1655 |
||
1656 |
Sets the directory path to the given \a path. |
|
1657 |
||
1658 |
Use setPath() instead. |
|
1659 |
*/ |
|
1660 |
QDir &QDir::operator=(const QString &path) |
|
1661 |
{ |
|
1662 |
Q_D(QDir); |
|
1663 |
||
1664 |
d->setPath(path); |
|
1665 |
return *this; |
|
1666 |
} |
|
1667 |
||
1668 |
/*! |
|
1669 |
\fn bool QDir::operator!=(const QDir &dir) const |
|
1670 |
||
1671 |
Returns true if directory \a dir and this directory have different |
|
1672 |
paths or different sort or filter settings; otherwise returns |
|
1673 |
false. |
|
1674 |
||
1675 |
Example: |
|
1676 |
||
1677 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 11 |
|
1678 |
*/ |
|
1679 |
||
1680 |
/*! |
|
1681 |
Removes the file, \a fileName. |
|
1682 |
||
1683 |
Returns true if the file is removed successfully; otherwise |
|
1684 |
returns false. |
|
1685 |
*/ |
|
1686 |
bool QDir::remove(const QString &fileName) |
|
1687 |
{ |
|
1688 |
if (fileName.isEmpty()) { |
|
1689 |
qWarning("QDir::remove: Empty or null file name"); |
|
1690 |
return false; |
|
1691 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1692 |
return QFile::remove(filePath(fileName)); |
0 | 1693 |
} |
1694 |
||
1695 |
/*! |
|
1696 |
Renames a file or directory from \a oldName to \a newName, and returns |
|
1697 |
true if successful; otherwise returns false. |
|
1698 |
||
1699 |
On most file systems, rename() fails only if \a oldName does not |
|
1700 |
exist, if \a newName and \a oldName are not on the same |
|
1701 |
partition or if a file with the new name already exists. |
|
1702 |
However, there are also other reasons why rename() can |
|
1703 |
fail. For example, on at least one file system rename() fails if |
|
1704 |
\a newName points to an open file. |
|
1705 |
*/ |
|
1706 |
bool QDir::rename(const QString &oldName, const QString &newName) |
|
1707 |
{ |
|
1708 |
Q_D(QDir); |
|
1709 |
||
1710 |
if (oldName.isEmpty() || newName.isEmpty()) { |
|
1711 |
qWarning("QDir::rename: Empty or null file name(s)"); |
|
1712 |
return false; |
|
1713 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1714 |
if (!d->data->fileEngine) |
0 | 1715 |
return false; |
1716 |
||
1717 |
QFile file(filePath(oldName)); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1718 |
if (!file.exists()) |
0 | 1719 |
return false; |
1720 |
return file.rename(filePath(newName)); |
|
1721 |
} |
|
1722 |
||
1723 |
/*! |
|
1724 |
Returns true if the file called \a name exists; otherwise returns |
|
1725 |
false. |
|
1726 |
||
1727 |
Unless \a name contains an absolute file path, the file name is assumed |
|
1728 |
to be relative to the directory itself, so this function is typically used |
|
1729 |
to check for the presence of files within a directory. |
|
1730 |
||
1731 |
\sa QFileInfo::exists(), QFile::exists() |
|
1732 |
*/ |
|
1733 |
bool QDir::exists(const QString &name) const |
|
1734 |
{ |
|
1735 |
if (name.isEmpty()) { |
|
1736 |
qWarning("QDir::exists: Empty or null file name"); |
|
1737 |
return false; |
|
1738 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1739 |
return QFile::exists(filePath(name)); |
0 | 1740 |
} |
1741 |
||
1742 |
/*! |
|
1743 |
Returns a list of the root directories on this system. |
|
1744 |
||
1745 |
On Windows this returns a list of QFileInfo objects containing "C:/", |
|
1746 |
"D:/", etc. On other operating systems, it returns a list containing |
|
1747 |
just one root directory (i.e. "/"). |
|
1748 |
||
1749 |
\sa root(), rootPath() |
|
1750 |
*/ |
|
1751 |
QFileInfoList QDir::drives() |
|
1752 |
{ |
|
1753 |
#ifdef QT_NO_FSFILEENGINE |
|
1754 |
return QFileInfoList(); |
|
1755 |
#else |
|
1756 |
return QFSFileEngine::drives(); |
|
1757 |
#endif |
|
1758 |
} |
|
1759 |
||
1760 |
/*! |
|
1761 |
Returns the native directory separator: "/" under Unix (including |
|
1762 |
Mac OS X) and "\\" under Windows. |
|
1763 |
||
1764 |
You do not need to use this function to build file paths. If you |
|
1765 |
always use "/", Qt will translate your paths to conform to the |
|
1766 |
underlying operating system. If you want to display paths to the |
|
1767 |
user using their operating system's separator use |
|
1768 |
toNativeSeparators(). |
|
1769 |
*/ |
|
1770 |
QChar QDir::separator() |
|
1771 |
{ |
|
1772 |
#if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) |
|
1773 |
return QLatin1Char('\\'); |
|
1774 |
#elif defined(Q_OS_UNIX) |
|
1775 |
return QLatin1Char('/'); |
|
1776 |
#elif defined (Q_OS_MAC) |
|
1777 |
return QLatin1Char(':'); |
|
1778 |
#else |
|
1779 |
return QLatin1Char('/'); |
|
1780 |
#endif |
|
1781 |
} |
|
1782 |
||
1783 |
/*! |
|
1784 |
Sets the application's current working directory to \a path. |
|
1785 |
Returns true if the directory was successfully changed; otherwise |
|
1786 |
returns false. |
|
1787 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1788 |
\sa current(), currentPath(), home(), root(), temp() |
0 | 1789 |
*/ |
1790 |
bool QDir::setCurrent(const QString &path) |
|
1791 |
{ |
|
1792 |
#ifdef QT_NO_FSFILEENGINE |
|
1793 |
Q_UNUSED(path); |
|
1794 |
return false; |
|
1795 |
#else |
|
1796 |
return QFSFileEngine::setCurrentPath(path); |
|
1797 |
#endif |
|
1798 |
} |
|
1799 |
||
1800 |
/*! |
|
1801 |
\fn QDir QDir::current() |
|
1802 |
||
1803 |
Returns the application's current directory. |
|
1804 |
||
1805 |
The directory is constructed using the absolute path of the current directory, |
|
1806 |
ensuring that its path() will be the same as its absolutePath(). |
|
1807 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1808 |
\sa currentPath(), setCurrent(), home(), root(), temp() |
0 | 1809 |
*/ |
1810 |
||
1811 |
/*! |
|
1812 |
Returns the absolute path of the application's current directory. |
|
1813 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1814 |
\sa current(), setCurrent(), homePath(), rootPath(), tempPath() |
0 | 1815 |
*/ |
1816 |
QString QDir::currentPath() |
|
1817 |
{ |
|
1818 |
#ifdef QT_NO_FSFILEENGINE |
|
1819 |
return QString(); |
|
1820 |
#else |
|
1821 |
return QFSFileEngine::currentPath(); |
|
1822 |
#endif |
|
1823 |
} |
|
1824 |
||
1825 |
/*! |
|
1826 |
\fn QString QDir::currentDirPath() |
|
1827 |
Returns the absolute path of the application's current directory. |
|
1828 |
||
1829 |
Use currentPath() instead. |
|
1830 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1831 |
\sa currentPath(), setCurrent() |
0 | 1832 |
*/ |
1833 |
||
1834 |
/*! |
|
1835 |
\fn QDir QDir::home() |
|
1836 |
||
1837 |
Returns the user's home directory. |
|
1838 |
||
1839 |
The directory is constructed using the absolute path of the home directory, |
|
1840 |
ensuring that its path() will be the same as its absolutePath(). |
|
1841 |
||
1842 |
See homePath() for details. |
|
1843 |
||
1844 |
\sa drives(), current(), root(), temp() |
|
1845 |
*/ |
|
1846 |
||
1847 |
/*! |
|
1848 |
Returns the absolute path of the user's home directory. |
|
1849 |
||
1850 |
Under Windows this function will return the directory of the |
|
1851 |
current user's profile. Typically, this is: |
|
1852 |
||
1853 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 12 |
|
1854 |
||
1855 |
Use the toNativeSeparators() function to convert the separators to |
|
1856 |
the ones that are appropriate for the underlying operating system. |
|
1857 |
||
1858 |
If the directory of the current user's profile does not exist or |
|
1859 |
cannot be retrieved, the following alternatives will be checked (in |
|
1860 |
the given order) until an existing and available path is found: |
|
1861 |
||
1862 |
\list 1 |
|
1863 |
\o The path specified by the \c USERPROFILE environment variable. |
|
1864 |
\o The path formed by concatenating the \c HOMEDRIVE and \c HOMEPATH |
|
1865 |
environment variables. |
|
1866 |
\o The path specified by the \c HOME environment variable. |
|
1867 |
\o The path returned by the rootPath() function (which uses the \c SystemDrive |
|
1868 |
environment variable) |
|
1869 |
\o The \c{C:/} directory. |
|
1870 |
\endlist |
|
1871 |
||
1872 |
Under non-Windows operating systems the \c HOME environment |
|
1873 |
variable is used if it exists, otherwise the path returned by the |
|
1874 |
rootPath(). On Symbian always the same as the path returned by the rootPath(). |
|
1875 |
||
1876 |
\sa home(), currentPath(), rootPath(), tempPath() |
|
1877 |
*/ |
|
1878 |
QString QDir::homePath() |
|
1879 |
{ |
|
1880 |
#ifdef QT_NO_FSFILEENGINE |
|
1881 |
return QString(); |
|
1882 |
#else |
|
1883 |
return cleanPath(QFSFileEngine::homePath()); |
|
1884 |
#endif |
|
1885 |
} |
|
1886 |
||
1887 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1888 |
\fn QString QDir::homeDirPath() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1889 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1890 |
Returns the absolute path of the user's home directory. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1891 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1892 |
Use homePath() instead. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1893 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1894 |
\sa homePath() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1895 |
*/ |
0 | 1896 |
|
1897 |
/*! |
|
1898 |
\fn QDir QDir::temp() |
|
1899 |
||
1900 |
Returns the system's temporary directory. |
|
1901 |
||
1902 |
The directory is constructed using the absolute path of the temporary directory, |
|
1903 |
ensuring that its path() will be the same as its absolutePath(). |
|
1904 |
||
1905 |
See tempPath() for details. |
|
1906 |
||
1907 |
\sa drives(), current(), home(), root() |
|
1908 |
*/ |
|
1909 |
||
1910 |
/*! |
|
1911 |
Returns the absolute path of the system's temporary directory. |
|
1912 |
||
1913 |
On Unix/Linux systems this is usually \c{/tmp}; on Windows this is |
|
1914 |
usually the path in the \c TEMP or \c TMP environment |
|
1915 |
variable. Whether a directory separator is added to the end or |
|
1916 |
not, depends on the operating system. |
|
1917 |
||
1918 |
\sa temp(), currentPath(), homePath(), rootPath() |
|
1919 |
*/ |
|
1920 |
QString QDir::tempPath() |
|
1921 |
{ |
|
1922 |
#ifdef QT_NO_FSFILEENGINE |
|
1923 |
return QString(); |
|
1924 |
#else |
|
1925 |
return cleanPath(QFSFileEngine::tempPath()); |
|
1926 |
#endif |
|
1927 |
} |
|
1928 |
||
1929 |
/*! |
|
1930 |
\fn QDir QDir::root() |
|
1931 |
||
1932 |
Returns the root directory. |
|
1933 |
||
1934 |
The directory is constructed using the absolute path of the root directory, |
|
1935 |
ensuring that its path() will be the same as its absolutePath(). |
|
1936 |
||
1937 |
See rootPath() for details. |
|
1938 |
||
1939 |
\sa drives(), current(), home(), temp() |
|
1940 |
*/ |
|
1941 |
||
1942 |
/*! |
|
1943 |
Returns the absolute path of the root directory. |
|
1944 |
||
1945 |
For Unix operating systems this returns "/". For Windows file |
|
1946 |
systems this normally returns "c:/". On Symbian this typically returns |
|
1947 |
"c:/data", i.e. the same as native PathInfo::PhoneMemoryRootPath(). |
|
1948 |
||
1949 |
\sa root(), drives(), currentPath(), homePath(), tempPath() |
|
1950 |
*/ |
|
1951 |
QString QDir::rootPath() |
|
1952 |
{ |
|
1953 |
#ifdef QT_NO_FSFILEENGINE |
|
1954 |
return QString(); |
|
1955 |
#else |
|
1956 |
return QFSFileEngine::rootPath(); |
|
1957 |
#endif |
|
1958 |
} |
|
1959 |
||
1960 |
/*! |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1961 |
\fn QString QDir::rootDirPath() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1962 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1963 |
Returns the absolute path of the root directory. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1964 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1965 |
Use rootPath() instead. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1966 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1967 |
\sa rootPath() |
0 | 1968 |
*/ |
1969 |
||
1970 |
#ifndef QT_NO_REGEXP |
|
1971 |
/*! |
|
1972 |
\overload |
|
1973 |
||
1974 |
Returns true if the \a fileName matches any of the wildcard (glob) |
|
1975 |
patterns in the list of \a filters; otherwise returns false. The |
|
1976 |
matching is case insensitive. |
|
1977 |
||
1978 |
\sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() |
|
1979 |
*/ |
|
1980 |
bool QDir::match(const QStringList &filters, const QString &fileName) |
|
1981 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1982 |
for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) { |
0 | 1983 |
QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard); |
1984 |
if (rx.exactMatch(fileName)) |
|
1985 |
return true; |
|
1986 |
} |
|
1987 |
return false; |
|
1988 |
} |
|
1989 |
||
1990 |
/*! |
|
1991 |
Returns true if the \a fileName matches the wildcard (glob) |
|
1992 |
pattern \a filter; otherwise returns false. The \a filter may |
|
1993 |
contain multiple patterns separated by spaces or semicolons. |
|
1994 |
The matching is case insensitive. |
|
1995 |
||
1996 |
\sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() |
|
1997 |
*/ |
|
1998 |
bool QDir::match(const QString &filter, const QString &fileName) |
|
1999 |
{ |
|
2000 |
return match(nameFiltersFromString(filter), fileName); |
|
2001 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2002 |
#endif // QT_NO_REGEXP |
0 | 2003 |
|
2004 |
/*! |
|
2005 |
Removes all multiple directory separators "/" and resolves any |
|
2006 |
"."s or ".."s found in the path, \a path. |
|
2007 |
||
2008 |
Symbolic links are kept. This function does not return the |
|
2009 |
canonical path, but rather the simplest version of the input. |
|
2010 |
For example, "./local" becomes "local", "local/../bin" becomes |
|
2011 |
"bin" and "/local/usr/../bin" becomes "/local/bin". |
|
2012 |
||
2013 |
\sa absolutePath() canonicalPath() |
|
2014 |
*/ |
|
2015 |
QString QDir::cleanPath(const QString &path) |
|
2016 |
{ |
|
2017 |
if (path.isEmpty()) |
|
2018 |
return path; |
|
2019 |
QString name = path; |
|
2020 |
QChar dir_separator = separator(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2021 |
if (dir_separator != QLatin1Char('/')) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2022 |
name.replace(dir_separator, QLatin1Char('/')); |
0 | 2023 |
|
2024 |
int used = 0, levels = 0; |
|
2025 |
const int len = name.length(); |
|
2026 |
QVarLengthArray<QChar> outVector(len); |
|
2027 |
QChar *out = outVector.data(); |
|
2028 |
||
2029 |
const QChar *p = name.unicode(); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2030 |
for (int i = 0, last = -1, iwrite = 0; i < len; ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2031 |
if (p[i] == QLatin1Char('/')) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2032 |
while (i < len-1 && p[i+1] == QLatin1Char('/')) { |
0 | 2033 |
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2034 |
if (!i) |
0 | 2035 |
break; |
2036 |
#endif |
|
2037 |
i++; |
|
2038 |
} |
|
2039 |
bool eaten = false; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2040 |
if (i < len - 1 && p[i+1] == QLatin1Char('.')) { |
0 | 2041 |
int dotcount = 1; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2042 |
if (i < len - 2 && p[i+2] == QLatin1Char('.')) |
0 | 2043 |
dotcount++; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2044 |
if (i == len - dotcount - 1) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2045 |
if (dotcount == 1) { |
0 | 2046 |
break; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2047 |
} else if (levels) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2048 |
if (last == -1) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2049 |
for (int i2 = iwrite-1; i2 >= 0; i2--) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2050 |
if (out[i2] == QLatin1Char('/')) { |
0 | 2051 |
last = i2; |
2052 |
break; |
|
2053 |
} |
|
2054 |
} |
|
2055 |
} |
|
2056 |
used -= iwrite - last - 1; |
|
2057 |
break; |
|
2058 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2059 |
} else if (p[i+dotcount+1] == QLatin1Char('/')) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2060 |
if (dotcount == 2 && levels) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2061 |
if (last == -1 || iwrite - last == 1) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2062 |
for (int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2063 |
if (out[i2] == QLatin1Char('/')) { |
0 | 2064 |
eaten = true; |
2065 |
last = i2; |
|
2066 |
break; |
|
2067 |
} |
|
2068 |
} |
|
2069 |
} else { |
|
2070 |
eaten = true; |
|
2071 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2072 |
if (eaten) { |
0 | 2073 |
levels--; |
2074 |
used -= iwrite - last; |
|
2075 |
iwrite = last; |
|
2076 |
last = -1; |
|
2077 |
} |
|
2078 |
} else if (dotcount == 2 && i > 0 && p[i - 1] != QLatin1Char('.')) { |
|
2079 |
eaten = true; |
|
2080 |
used -= iwrite - qMax(0, last); |
|
2081 |
iwrite = qMax(0, last); |
|
2082 |
last = -1; |
|
2083 |
++i; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2084 |
} else if (dotcount == 1) { |
0 | 2085 |
eaten = true; |
2086 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2087 |
if (eaten) |
0 | 2088 |
i += dotcount; |
2089 |
} else { |
|
2090 |
levels++; |
|
2091 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2092 |
} else if (last != -1 && iwrite - last == 1) { |
0 | 2093 |
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) |
2094 |
eaten = (iwrite > 2); |
|
2095 |
#else |
|
2096 |
eaten = true; |
|
2097 |
#endif |
|
2098 |
last = -1; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2099 |
} else if (last != -1 && i == len-1) { |
0 | 2100 |
eaten = true; |
2101 |
} else { |
|
2102 |
levels++; |
|
2103 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2104 |
if (!eaten) |
0 | 2105 |
last = i - (i - iwrite); |
2106 |
else |
|
2107 |
continue; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2108 |
} else if (!i && p[i] == QLatin1Char('.')) { |
0 | 2109 |
int dotcount = 1; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2110 |
if (len >= 1 && p[1] == QLatin1Char('.')) |
0 | 2111 |
dotcount++; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2112 |
if (len >= dotcount && p[dotcount] == QLatin1Char('/')) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2113 |
if (dotcount == 1) { |
0 | 2114 |
i++; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2115 |
while (i+1 < len-1 && p[i+1] == QLatin1Char('/')) |
0 | 2116 |
i++; |
2117 |
continue; |
|
2118 |
} |
|
2119 |
} |
|
2120 |
} |
|
2121 |
out[iwrite++] = p[i]; |
|
2122 |
used++; |
|
2123 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2124 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2125 |
QString ret = (used == len ? name : QString(out, used)); |
0 | 2126 |
// Strip away last slash except for root directories |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2127 |
if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2128 |
#if defined (Q_OS_WIN) || defined (Q_OS_SYMBIAN) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2129 |
if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':'))) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2130 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2131 |
ret.chop(1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2132 |
} |
0 | 2133 |
|
2134 |
return ret; |
|
2135 |
} |
|
2136 |
||
2137 |
/*! |
|
2138 |
Returns true if \a path is relative; returns false if it is |
|
2139 |
absolute. |
|
2140 |
||
2141 |
\sa isRelative() isAbsolutePath() makeAbsolute() |
|
2142 |
*/ |
|
2143 |
bool QDir::isRelativePath(const QString &path) |
|
2144 |
{ |
|
2145 |
return QFileInfo(path).isRelative(); |
|
2146 |
} |
|
2147 |
||
2148 |
/*! |
|
2149 |
Refreshes the directory information. |
|
2150 |
*/ |
|
2151 |
void QDir::refresh() const |
|
2152 |
{ |
|
2153 |
Q_D(const QDir); |
|
2154 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2155 |
const_cast<QDirPrivate *>(d)->reset(); |
0 | 2156 |
} |
2157 |
||
2158 |
/*! |
|
2159 |
\internal |
|
2160 |
||
2161 |
Returns a list of name filters from the given \a nameFilter. (If |
|
2162 |
there is more than one filter, each pair of filters is separated |
|
2163 |
by a space or by a semicolon.) |
|
2164 |
*/ |
|
2165 |
QStringList QDir::nameFiltersFromString(const QString &nameFilter) |
|
2166 |
{ |
|
2167 |
return QDirPrivate::splitFilters(nameFilter); |
|
2168 |
} |
|
2169 |
||
2170 |
/*! |
|
2171 |
\macro void Q_INIT_RESOURCE(name) |
|
2172 |
\relates QDir |
|
2173 |
||
2174 |
Initializes the resources specified by the \c .qrc file with the |
|
2175 |
specified base \a name. Normally, Qt resources are loaded |
|
2176 |
automatically at startup. The Q_INIT_RESOURCE() macro is |
|
2177 |
necessary on some platforms for resources stored in a static |
|
2178 |
library. |
|
2179 |
||
2180 |
For example, if your application's resources are listed in a file |
|
2181 |
called \c myapp.qrc, you can ensure that the resources are |
|
2182 |
initialized at startup by adding this line to your \c main() |
|
2183 |
function: |
|
2184 |
||
2185 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 13 |
|
2186 |
||
2187 |
If the file name contains characters that cannot be part of a valid C++ function name |
|
2188 |
(such as '-'), they have to be replaced by the underscore character ('_'). |
|
2189 |
||
2190 |
Note: This macro cannot be used in a namespace. It should be called from |
|
2191 |
main(). If that is not possible, the following workaround can be used |
|
2192 |
to init the resource \c myapp from the function \c{MyNamespace::myFunction}: |
|
2193 |
||
2194 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 14 |
|
2195 |
||
2196 |
\sa Q_CLEANUP_RESOURCE(), {The Qt Resource System} |
|
2197 |
*/ |
|
2198 |
||
2199 |
/*! |
|
2200 |
\since 4.1 |
|
2201 |
\macro void Q_CLEANUP_RESOURCE(name) |
|
2202 |
\relates QDir |
|
2203 |
||
2204 |
Unloads the resources specified by the \c .qrc file with the base |
|
2205 |
name \a name. |
|
2206 |
||
2207 |
Normally, Qt resources are unloaded automatically when the |
|
2208 |
application terminates, but if the resources are located in a |
|
2209 |
plugin that is being unloaded, call Q_CLEANUP_RESOURCE() to force |
|
2210 |
removal of your resources. |
|
2211 |
||
2212 |
Note: This macro cannot be used in a namespace. Please see the |
|
2213 |
Q_INIT_RESOURCE documentation for a workaround. |
|
2214 |
||
2215 |
Example: |
|
2216 |
||
2217 |
\snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 15 |
|
2218 |
||
2219 |
\sa Q_INIT_RESOURCE(), {The Qt Resource System} |
|
2220 |
*/ |
|
2221 |
||
2222 |
#ifdef QT3_SUPPORT |
|
2223 |
||
2224 |
/*! |
|
2225 |
\fn bool QDir::matchAllDirs() const |
|
2226 |
||
2227 |
Use filter() & AllDirs instead. |
|
2228 |
*/ |
|
2229 |
bool QDir::matchAllDirs() const |
|
2230 |
{ |
|
2231 |
Q_D(const QDir); |
|
2232 |
return d->matchAllDirs; |
|
2233 |
} |
|
2234 |
||
2235 |
||
2236 |
/*! |
|
2237 |
\fn void QDir::setMatchAllDirs(bool on) |
|
2238 |
||
2239 |
Use setFilter() instead. |
|
2240 |
*/ |
|
2241 |
void QDir::setMatchAllDirs(bool on) |
|
2242 |
{ |
|
2243 |
Q_D(QDir); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2244 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2245 |
d->reset(); |
0 | 2246 |
d->matchAllDirs = on; |
2247 |
} |
|
2248 |
||
2249 |
/*! |
|
2250 |
Use nameFilters() instead. |
|
2251 |
*/ |
|
2252 |
QString QDir::nameFilter() const |
|
2253 |
{ |
|
2254 |
Q_D(const QDir); |
|
2255 |
||
2256 |
return nameFilters().join(QString(d->filterSepChar)); |
|
2257 |
} |
|
2258 |
||
2259 |
/*! |
|
2260 |
Use setNameFilters() instead. |
|
2261 |
||
2262 |
The \a nameFilter is a wildcard (globbing) filter that understands |
|
2263 |
"*" and "?" wildcards. (See \l{QRegExp wildcard matching}.) You may |
|
2264 |
specify several filter entries, each separated by spaces or by |
|
2265 |
semicolons. |
|
2266 |
||
2267 |
For example, if you want entryList() and entryInfoList() to list |
|
2268 |
all files ending with either ".cpp" or ".h", you would use either |
|
2269 |
dir.setNameFilters("*.cpp *.h") or dir.setNameFilters("*.cpp;*.h"). |
|
2270 |
||
2271 |
\oldcode |
|
2272 |
QString filter = "*.cpp *.cxx *.cc"; |
|
2273 |
dir.setNameFilter(filter); |
|
2274 |
\newcode |
|
2275 |
QString filter = "*.cpp *.cxx *.cc"; |
|
2276 |
dir.setNameFilters(filter.split(' ')); |
|
2277 |
\endcode |
|
2278 |
*/ |
|
2279 |
void QDir::setNameFilter(const QString &nameFilter) |
|
2280 |
{ |
|
2281 |
Q_D(QDir); |
|
2282 |
||
2283 |
d->filterSepChar = QDirPrivate::getFilterSepChar(nameFilter); |
|
2284 |
setNameFilters(QDirPrivate::splitFilters(nameFilter, d->filterSepChar)); |
|
2285 |
} |
|
2286 |
||
2287 |
/*! |
|
2288 |
\fn QString QDir::absPath() const |
|
2289 |
||
2290 |
Use absolutePath() instead. |
|
2291 |
*/ |
|
2292 |
||
2293 |
/*! |
|
2294 |
\fn QString QDir::absFilePath(const QString &fileName, bool acceptAbsPath) const |
|
2295 |
||
2296 |
Use absoluteFilePath(\a fileName) instead. |
|
2297 |
||
2298 |
The \a acceptAbsPath parameter is ignored. |
|
2299 |
*/ |
|
2300 |
||
2301 |
/*! |
|
2302 |
\fn bool QDir::mkdir(const QString &dirName, bool acceptAbsPath) const |
|
2303 |
||
2304 |
Use mkdir(\a dirName) instead. |
|
2305 |
||
2306 |
The \a acceptAbsPath parameter is ignored. |
|
2307 |
*/ |
|
2308 |
||
2309 |
/*! |
|
2310 |
\fn bool QDir::rmdir(const QString &dirName, bool acceptAbsPath) const |
|
2311 |
||
2312 |
Use rmdir(\a dirName) instead. |
|
2313 |
||
2314 |
The \a acceptAbsPath parameter is ignored. |
|
2315 |
*/ |
|
2316 |
||
2317 |
/*! |
|
2318 |
\fn QStringList QDir::entryList(const QString &nameFilter, Filters filters, |
|
2319 |
SortFlags sort) const |
|
2320 |
\overload |
|
2321 |
||
2322 |
Use the overload that takes a name filter string list as first |
|
2323 |
argument instead of a combination of attribute filter flags. |
|
2324 |
*/ |
|
2325 |
||
2326 |
/*! |
|
2327 |
\fn QFileInfoList QDir::entryInfoList(const QString &nameFilter, Filters filters, |
|
2328 |
SortFlags sort) const |
|
2329 |
\overload |
|
2330 |
||
2331 |
Use the overload that takes a name filter string list as first |
|
2332 |
argument instead of a combination of attribute filter flags. |
|
2333 |
*/ |
|
2334 |
||
2335 |
/*! |
|
2336 |
\fn void QDir::convertToAbs() |
|
2337 |
||
2338 |
Use makeAbsolute() instead. |
|
2339 |
*/ |
|
2340 |
||
2341 |
/*! |
|
2342 |
\fn QString QDir::cleanDirPath(const QString &name) |
|
2343 |
||
2344 |
Use cleanPath() instead. |
|
2345 |
*/ |
|
2346 |
||
2347 |
/*! |
|
2348 |
\typedef QDir::FilterSpec |
|
2349 |
||
2350 |
Use QDir::Filters instead. |
|
2351 |
*/ |
|
2352 |
||
2353 |
/*! |
|
2354 |
\typedef QDir::SortSpec |
|
2355 |
||
2356 |
Use QDir::SortFlags instead. |
|
2357 |
*/ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2358 |
#endif // QT3_SUPPORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2359 |
|
0 | 2360 |
#ifndef QT_NO_DEBUG_STREAM |
2361 |
QDebug operator<<(QDebug debug, QDir::Filters filters) |
|
2362 |
{ |
|
2363 |
QStringList flags; |
|
2364 |
if (filters == QDir::NoFilter) { |
|
2365 |
flags << QLatin1String("NoFilter"); |
|
2366 |
} else { |
|
2367 |
if (filters & QDir::Dirs) flags << QLatin1String("Dirs"); |
|
2368 |
if (filters & QDir::AllDirs) flags << QLatin1String("AllDirs"); |
|
2369 |
if (filters & QDir::Files) flags << QLatin1String("Files"); |
|
2370 |
if (filters & QDir::Drives) flags << QLatin1String("Drives"); |
|
2371 |
if (filters & QDir::NoSymLinks) flags << QLatin1String("NoSymLinks"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2372 |
if (filters & QDir::NoDotAndDotDot) flags << QLatin1String("NoDotAndDotDot"); // ### Qt5: remove (because NoDotAndDotDot=NoDot|NoDotDot) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2373 |
if (filters & QDir::NoDot) flags << QLatin1String("NoDot"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2374 |
if (filters & QDir::NoDotDot) flags << QLatin1String("NoDotDot"); |
0 | 2375 |
if ((filters & QDir::AllEntries) == QDir::AllEntries) flags << QLatin1String("AllEntries"); |
2376 |
if (filters & QDir::Readable) flags << QLatin1String("Readable"); |
|
2377 |
if (filters & QDir::Writable) flags << QLatin1String("Writable"); |
|
2378 |
if (filters & QDir::Executable) flags << QLatin1String("Executable"); |
|
2379 |
if (filters & QDir::Modified) flags << QLatin1String("Modified"); |
|
2380 |
if (filters & QDir::Hidden) flags << QLatin1String("Hidden"); |
|
2381 |
if (filters & QDir::System) flags << QLatin1String("System"); |
|
2382 |
if (filters & QDir::CaseSensitive) flags << QLatin1String("CaseSensitive"); |
|
2383 |
} |
|
2384 |
debug << "QDir::Filters(" << qPrintable(flags.join(QLatin1String("|"))) << ')'; |
|
2385 |
return debug; |
|
2386 |
} |
|
2387 |
||
2388 |
static QDebug operator<<(QDebug debug, QDir::SortFlags sorting) |
|
2389 |
{ |
|
2390 |
if (sorting == QDir::NoSort) { |
|
2391 |
debug << "QDir::SortFlags(NoSort)"; |
|
2392 |
} else { |
|
2393 |
QString type; |
|
2394 |
if ((sorting & 3) == QDir::Name) type = QLatin1String("Name"); |
|
2395 |
if ((sorting & 3) == QDir::Time) type = QLatin1String("Time"); |
|
2396 |
if ((sorting & 3) == QDir::Size) type = QLatin1String("Size"); |
|
2397 |
if ((sorting & 3) == QDir::Unsorted) type = QLatin1String("Unsorted"); |
|
2398 |
||
2399 |
QStringList flags; |
|
2400 |
if (sorting & QDir::DirsFirst) flags << QLatin1String("DirsFirst"); |
|
2401 |
if (sorting & QDir::DirsLast) flags << QLatin1String("DirsLast"); |
|
2402 |
if (sorting & QDir::IgnoreCase) flags << QLatin1String("IgnoreCase"); |
|
2403 |
if (sorting & QDir::LocaleAware) flags << QLatin1String("LocaleAware"); |
|
2404 |
if (sorting & QDir::Type) flags << QLatin1String("Type"); |
|
2405 |
debug << "QDir::SortFlags(" << qPrintable(type) |
|
2406 |
<< '|' |
|
2407 |
<< qPrintable(flags.join(QLatin1String("|"))) << ')'; |
|
2408 |
} |
|
2409 |
return debug; |
|
2410 |
} |
|
2411 |
||
2412 |
QDebug operator<<(QDebug debug, const QDir &dir) |
|
2413 |
{ |
|
2414 |
debug.maybeSpace() << "QDir(" << dir.path() |
|
2415 |
<< ", nameFilters = {" |
|
2416 |
<< qPrintable(dir.nameFilters().join(QLatin1String(","))) |
|
2417 |
<< "}, " |
|
2418 |
<< dir.sorting() |
|
2419 |
<< ',' |
|
2420 |
<< dir.filter() |
|
2421 |
<< ')'; |
|
2422 |
return debug.space(); |
|
2423 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
2424 |
#endif // QT_NO_DEBUG_STREAM |
0 | 2425 |
|
2426 |
QT_END_NAMESPACE |