Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qabstractfileengine.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
5 | ** | - | ||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
7 | ** | - | ||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
9 | ** Commercial License Usage | - | ||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
16 | ** | - | ||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
25 | ** | - | ||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
29 | ** | - | ||||||
30 | ** $QT_END_LICENSE$ | - | ||||||
31 | ** | - | ||||||
32 | ****************************************************************************/ | - | ||||||
33 | - | |||||||
34 | #include "private/qabstractfileengine_p.h" | - | ||||||
35 | #include "private/qfsfileengine_p.h" | - | ||||||
36 | #ifdef QT_BUILD_CORE_LIB | - | ||||||
37 | #include "private/qresource_p.h" | - | ||||||
38 | #endif | - | ||||||
39 | #include "qdatetime.h" | - | ||||||
40 | #include "qreadwritelock.h" | - | ||||||
41 | #include "qvariant.h" | - | ||||||
42 | // built-in handlers | - | ||||||
43 | #include "qdiriterator.h" | - | ||||||
44 | #include "qstringbuilder.h" | - | ||||||
45 | - | |||||||
46 | #include <QtCore/private/qfilesystementry_p.h> | - | ||||||
47 | #include <QtCore/private/qfilesystemmetadata_p.h> | - | ||||||
48 | #include <QtCore/private/qfilesystemengine_p.h> | - | ||||||
49 | - | |||||||
50 | QT_BEGIN_NAMESPACE | - | ||||||
51 | - | |||||||
52 | /*! | - | ||||||
53 | \class QAbstractFileEngineHandler | - | ||||||
54 | \inmodule QtCore | - | ||||||
55 | \reentrant | - | ||||||
56 | \internal | - | ||||||
57 | - | |||||||
58 | \brief The QAbstractFileEngineHandler class provides a way to register | - | ||||||
59 | custom file engines with your application. | - | ||||||
60 | - | |||||||
61 | \ingroup io | - | ||||||
62 | \since 4.1 | - | ||||||
63 | - | |||||||
64 | QAbstractFileEngineHandler is a factory for creating QAbstractFileEngine | - | ||||||
65 | objects (file engines), which are used internally by QFile, QFileInfo, and | - | ||||||
66 | QDir when working with files and directories. | - | ||||||
67 | - | |||||||
68 | When you open a file, Qt chooses a suitable file engine by passing the | - | ||||||
69 | file name from QFile or QDir through an internal list of registered file | - | ||||||
70 | engine handlers. The first handler to recognize the file name is used to | - | ||||||
71 | create the engine. Qt provides internal file engines for working with | - | ||||||
72 | regular files and resources, but you can also register your own | - | ||||||
73 | QAbstractFileEngine subclasses. | - | ||||||
74 | - | |||||||
75 | To install an application-specific file engine, you subclass | - | ||||||
76 | QAbstractFileEngineHandler and reimplement create(). When you instantiate | - | ||||||
77 | the handler (e.g. by creating an instance on the stack or on the heap), it | - | ||||||
78 | will automatically register with Qt. (The latest registered handler takes | - | ||||||
79 | precedence over existing handlers.) | - | ||||||
80 | - | |||||||
81 | For example: | - | ||||||
82 | - | |||||||
83 | \snippet code/src_corelib_io_qabstractfileengine.cpp 0 | - | ||||||
84 | - | |||||||
85 | When the handler is destroyed, it is automatically removed from Qt. | - | ||||||
86 | - | |||||||
87 | The most common approach to registering a handler is to create an instance | - | ||||||
88 | as part of the start-up phase of your application. It is also possible to | - | ||||||
89 | limit the scope of the file engine handler to a particular area of | - | ||||||
90 | interest (e.g. a special file dialog that needs a custom file engine). By | - | ||||||
91 | creating the handler inside a local scope, you can precisely control the | - | ||||||
92 | area in which your engine will be applied without disturbing file | - | ||||||
93 | operations in other parts of your application. | - | ||||||
94 | - | |||||||
95 | \sa QAbstractFileEngine, QAbstractFileEngine::create() | - | ||||||
96 | */ | - | ||||||
97 | - | |||||||
98 | static bool qt_file_engine_handlers_in_use = false; | - | ||||||
99 | - | |||||||
100 | /* | - | ||||||
101 | All application-wide handlers are stored in this list. The mutex must be | - | ||||||
102 | acquired to ensure thread safety. | - | ||||||
103 | */ | - | ||||||
104 | Q_GLOBAL_STATIC_WITH_ARGS(QReadWriteLock, fileEngineHandlerMutex, (QReadWriteLock::Recursive)) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 120 times by 6 tests: return &holder.value; Executed by:
| 0-120 | ||||||
105 | static bool qt_abstractfileenginehandlerlist_shutDown = false; | - | ||||||
106 | class QAbstractFileEngineHandlerList : public QList<QAbstractFileEngineHandler *> | - | ||||||
107 | { | - | ||||||
108 | public: | - | ||||||
109 | ~QAbstractFileEngineHandlerList() | - | ||||||
110 | { | - | ||||||
111 | QWriteLocker locker(fileEngineHandlerMutex()); | - | ||||||
112 | qt_abstractfileenginehandlerlist_shutDown = true; | - | ||||||
113 | } executed 3 times by 3 tests: end of block Executed by:
| 3 | ||||||
114 | }; | - | ||||||
115 | Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers) executed 3 times by 3 tests: end of block Executed by:
executed 3 times by 3 tests: guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 117 times by 3 tests: return &holder.value; Executed by:
| 0-117 | ||||||
116 | - | |||||||
117 | /*! | - | ||||||
118 | Constructs a file handler and registers it with Qt. Once created this | - | ||||||
119 | handler's create() function will be called (along with all the other | - | ||||||
120 | handlers) for any paths used. The most recently created handler that | - | ||||||
121 | recognizes the given path (i.e. that returns a QAbstractFileEngine) is | - | ||||||
122 | used for the new path. | - | ||||||
123 | - | |||||||
124 | \sa create() | - | ||||||
125 | */ | - | ||||||
126 | QAbstractFileEngineHandler::QAbstractFileEngineHandler() | - | ||||||
127 | { | - | ||||||
128 | QWriteLocker locker(fileEngineHandlerMutex()); | - | ||||||
129 | qt_file_engine_handlers_in_use = true; | - | ||||||
130 | fileEngineHandlers()->prepend(this); | - | ||||||
131 | } executed 15 times by 3 tests: end of block Executed by:
| 15 | ||||||
132 | - | |||||||
133 | /*! | - | ||||||
134 | Destroys the file handler. This will automatically unregister the handler | - | ||||||
135 | from Qt. | - | ||||||
136 | */ | - | ||||||
137 | QAbstractFileEngineHandler::~QAbstractFileEngineHandler() | - | ||||||
138 | { | - | ||||||
139 | QWriteLocker locker(fileEngineHandlerMutex()); | - | ||||||
140 | // Remove this handler from the handler list only if the list is valid. | - | ||||||
141 | if (!qt_abstractfileenginehandlerlist_shutDown) {
| 0-15 | ||||||
142 | QAbstractFileEngineHandlerList *handlers = fileEngineHandlers(); | - | ||||||
143 | handlers->removeOne(this); | - | ||||||
144 | if (handlers->isEmpty())
| 1-14 | ||||||
145 | qt_file_engine_handlers_in_use = false; executed 14 times by 3 tests: qt_file_engine_handlers_in_use = false; Executed by:
| 14 | ||||||
146 | } executed 15 times by 3 tests: end of block Executed by:
| 15 | ||||||
147 | } executed 15 times by 3 tests: end of block Executed by:
| 15 | ||||||
148 | - | |||||||
149 | /* | - | ||||||
150 | \internal | - | ||||||
151 | - | |||||||
152 | Handles calls to custom file engine handlers. | - | ||||||
153 | */ | - | ||||||
154 | QAbstractFileEngine *qt_custom_file_engine_handler_create(const QString &path) | - | ||||||
155 | { | - | ||||||
156 | QAbstractFileEngine *engine = 0; | - | ||||||
157 | - | |||||||
158 | if (qt_file_engine_handlers_in_use) {
| 87-589734 | ||||||
159 | QReadLocker locker(fileEngineHandlerMutex()); | - | ||||||
160 | - | |||||||
161 | // check for registered handlers that can load the file | - | ||||||
162 | QAbstractFileEngineHandlerList *handlers = fileEngineHandlers(); | - | ||||||
163 | for (int i = 0; i < handlers->size(); i++) {
| 34-87 | ||||||
164 | if ((engine = handlers->at(i)->create(path)))
| 34-53 | ||||||
165 | break; executed 53 times by 3 tests: break; Executed by:
| 53 | ||||||
166 | } executed 34 times by 2 tests: end of block Executed by:
| 34 | ||||||
167 | } executed 87 times by 3 tests: end of block Executed by:
| 87 | ||||||
168 | - | |||||||
169 | return engine; executed 589821 times by 302 tests: return engine; Executed by:
| 589821 | ||||||
170 | } | - | ||||||
171 | - | |||||||
172 | /*! | - | ||||||
173 | \fn QAbstractFileEngine *QAbstractFileEngineHandler::create(const QString &fileName) const | - | ||||||
174 | - | |||||||
175 | Creates a file engine for file \a fileName. Returns 0 if this | - | ||||||
176 | file handler cannot handle \a fileName. | - | ||||||
177 | - | |||||||
178 | Example: | - | ||||||
179 | - | |||||||
180 | \snippet code/src_corelib_io_qabstractfileengine.cpp 1 | - | ||||||
181 | - | |||||||
182 | \sa QAbstractFileEngine::create() | - | ||||||
183 | */ | - | ||||||
184 | - | |||||||
185 | /*! | - | ||||||
186 | Creates and returns a QAbstractFileEngine suitable for processing \a | - | ||||||
187 | fileName. | - | ||||||
188 | - | |||||||
189 | You should not need to call this function; use QFile, QFileInfo or | - | ||||||
190 | QDir directly instead. | - | ||||||
191 | - | |||||||
192 | If you reimplemnt this function, it should only return file | - | ||||||
193 | engines that knows how to handle \a fileName; otherwise, it should | - | ||||||
194 | return 0. | - | ||||||
195 | - | |||||||
196 | \sa QAbstractFileEngineHandler | - | ||||||
197 | */ | - | ||||||
198 | QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName) | - | ||||||
199 | { | - | ||||||
200 | QFileSystemEntry entry(fileName); | - | ||||||
201 | QFileSystemMetaData metaData; | - | ||||||
202 | QAbstractFileEngine *engine = QFileSystemEngine::resolveEntryAndCreateLegacyEngine(entry, metaData); | - | ||||||
203 | - | |||||||
204 | #ifndef QT_NO_FSFILEENGINE | - | ||||||
205 | if (!engine)
| 12389-43064 | ||||||
206 | // fall back to regular file engine | - | ||||||
207 | return new QFSFileEngine(entry.filePath()); executed 43064 times by 205 tests: return new QFSFileEngine(entry.filePath()); Executed by:
| 43064 | ||||||
208 | #endif | - | ||||||
209 | - | |||||||
210 | return engine; executed 12389 times by 82 tests: return engine; Executed by:
| 12389 | ||||||
211 | } | - | ||||||
212 | - | |||||||
213 | /*! | - | ||||||
214 | \class QAbstractFileEngine | - | ||||||
215 | \inmodule QtCore | - | ||||||
216 | \reentrant | - | ||||||
217 | \internal | - | ||||||
218 | - | |||||||
219 | \brief The QAbstractFileEngine class provides an abstraction for accessing | - | ||||||
220 | the filesystem. | - | ||||||
221 | - | |||||||
222 | \ingroup io | - | ||||||
223 | \since 4.1 | - | ||||||
224 | - | |||||||
225 | The QDir, QFile, and QFileInfo classes all make use of a | - | ||||||
226 | QAbstractFileEngine internally. If you create your own QAbstractFileEngine | - | ||||||
227 | subclass (and register it with Qt by creating a QAbstractFileEngineHandler | - | ||||||
228 | subclass), your file engine will be used when the path is one that your | - | ||||||
229 | file engine handles. | - | ||||||
230 | - | |||||||
231 | A QAbstractFileEngine refers to one file or one directory. If the referent | - | ||||||
232 | is a file, the setFileName(), rename(), and remove() functions are | - | ||||||
233 | applicable. If the referent is a directory the mkdir(), rmdir(), and | - | ||||||
234 | entryList() functions are applicable. In all cases the caseSensitive(), | - | ||||||
235 | isRelativePath(), fileFlags(), ownerId(), owner(), and fileTime() | - | ||||||
236 | functions are applicable. | - | ||||||
237 | - | |||||||
238 | A QAbstractFileEngine subclass can be created to do synchronous network I/O | - | ||||||
239 | based file system operations, local file system operations, or to operate | - | ||||||
240 | as a resource system to access file based resources. | - | ||||||
241 | - | |||||||
242 | \sa QAbstractFileEngineHandler | - | ||||||
243 | */ | - | ||||||
244 | - | |||||||
245 | /*! | - | ||||||
246 | \enum QAbstractFileEngine::FileName | - | ||||||
247 | - | |||||||
248 | These values are used to request a file name in a particular | - | ||||||
249 | format. | - | ||||||
250 | - | |||||||
251 | \value DefaultName The same filename that was passed to the | - | ||||||
252 | QAbstractFileEngine. | - | ||||||
253 | \value BaseName The name of the file excluding the path. | - | ||||||
254 | \value PathName The path to the file excluding the base name. | - | ||||||
255 | \value AbsoluteName The absolute path to the file (including | - | ||||||
256 | the base name). | - | ||||||
257 | \value AbsolutePathName The absolute path to the file (excluding | - | ||||||
258 | the base name). | - | ||||||
259 | \value LinkName The full file name of the file that this file is a | - | ||||||
260 | link to. (This will be empty if this file is not a link.) | - | ||||||
261 | \value CanonicalName Often very similar to LinkName. Will return the true path to the file. | - | ||||||
262 | \value CanonicalPathName Same as CanonicalName, excluding the base name. | - | ||||||
263 | \value BundleName Returns the name of the bundle implies BundleType is set. | - | ||||||
264 | - | |||||||
265 | \omitvalue NFileNames | - | ||||||
266 | - | |||||||
267 | \sa fileName(), setFileName() | - | ||||||
268 | */ | - | ||||||
269 | - | |||||||
270 | /*! | - | ||||||
271 | \enum QAbstractFileEngine::FileFlag | - | ||||||
272 | - | |||||||
273 | The permissions and types of a file, suitable for OR'ing together. | - | ||||||
274 | - | |||||||
275 | \value ReadOwnerPerm The owner of the file has permission to read | - | ||||||
276 | it. | - | ||||||
277 | \value WriteOwnerPerm The owner of the file has permission to | - | ||||||
278 | write to it. | - | ||||||
279 | \value ExeOwnerPerm The owner of the file has permission to | - | ||||||
280 | execute it. | - | ||||||
281 | \value ReadUserPerm The current user has permission to read the | - | ||||||
282 | file. | - | ||||||
283 | \value WriteUserPerm The current user has permission to write to | - | ||||||
284 | the file. | - | ||||||
285 | \value ExeUserPerm The current user has permission to execute the | - | ||||||
286 | file. | - | ||||||
287 | \value ReadGroupPerm Members of the current user's group have | - | ||||||
288 | permission to read the file. | - | ||||||
289 | \value WriteGroupPerm Members of the current user's group have | - | ||||||
290 | permission to write to the file. | - | ||||||
291 | \value ExeGroupPerm Members of the current user's group have | - | ||||||
292 | permission to execute the file. | - | ||||||
293 | \value ReadOtherPerm All users have permission to read the file. | - | ||||||
294 | \value WriteOtherPerm All users have permission to write to the | - | ||||||
295 | file. | - | ||||||
296 | \value ExeOtherPerm All users have permission to execute the file. | - | ||||||
297 | - | |||||||
298 | \value LinkType The file is a link to another file (or link) in | - | ||||||
299 | the file system (i.e. not a file or directory). | - | ||||||
300 | \value FileType The file is a regular file to the file system | - | ||||||
301 | (i.e. not a link or directory) | - | ||||||
302 | \value BundleType \macos and iOS: the file is a bundle; implies DirectoryType | - | ||||||
303 | \value DirectoryType The file is a directory in the file system | - | ||||||
304 | (i.e. not a link or file). | - | ||||||
305 | - | |||||||
306 | \value HiddenFlag The file is hidden. | - | ||||||
307 | \value ExistsFlag The file actually exists in the file system. | - | ||||||
308 | \value RootFlag The file or the file pointed to is the root of the filesystem. | - | ||||||
309 | \value LocalDiskFlag The file resides on the local disk and can be passed to standard file functions. | - | ||||||
310 | \value Refresh Passing this flag will force the file engine to refresh all flags. | - | ||||||
311 | - | |||||||
312 | \omitvalue PermsMask | - | ||||||
313 | \omitvalue TypesMask | - | ||||||
314 | \omitvalue FlagsMask | - | ||||||
315 | \omitvalue FileInfoAll | - | ||||||
316 | - | |||||||
317 | \sa fileFlags(), setFileName() | - | ||||||
318 | */ | - | ||||||
319 | - | |||||||
320 | /*! | - | ||||||
321 | \enum QAbstractFileEngine::FileTime | - | ||||||
322 | - | |||||||
323 | These are used by the fileTime() function. | - | ||||||
324 | - | |||||||
325 | \value CreationTime When the file was created. | - | ||||||
326 | \value ModificationTime When the file was most recently modified. | - | ||||||
327 | \value AccessTime When the file was most recently accessed (e.g. | - | ||||||
328 | read or written to). | - | ||||||
329 | - | |||||||
330 | \sa setFileName() | - | ||||||
331 | */ | - | ||||||
332 | - | |||||||
333 | /*! | - | ||||||
334 | \enum QAbstractFileEngine::FileOwner | - | ||||||
335 | - | |||||||
336 | \value OwnerUser The user who owns the file. | - | ||||||
337 | \value OwnerGroup The group who owns the file. | - | ||||||
338 | - | |||||||
339 | \sa owner(), ownerId(), setFileName() | - | ||||||
340 | */ | - | ||||||
341 | - | |||||||
342 | /*! | - | ||||||
343 | Constructs a new QAbstractFileEngine that does not refer to any file or directory. | - | ||||||
344 | - | |||||||
345 | \sa setFileName() | - | ||||||
346 | */ | - | ||||||
347 | QAbstractFileEngine::QAbstractFileEngine() : d_ptr(new QAbstractFileEnginePrivate) | - | ||||||
348 | { | - | ||||||
349 | d_ptr->q_ptr = this; | - | ||||||
350 | } executed 18 times by 2 tests: end of block Executed by:
| 18 | ||||||
351 | - | |||||||
352 | /*! | - | ||||||
353 | \internal | - | ||||||
354 | - | |||||||
355 | Constructs a QAbstractFileEngine. | - | ||||||
356 | */ | - | ||||||
357 | QAbstractFileEngine::QAbstractFileEngine(QAbstractFileEnginePrivate &dd) : d_ptr(&dd) | - | ||||||
358 | { | - | ||||||
359 | d_ptr->q_ptr = this; | - | ||||||
360 | } executed 90320 times by 216 tests: end of block Executed by:
| 90320 | ||||||
361 | - | |||||||
362 | /*! | - | ||||||
363 | Destroys the QAbstractFileEngine. | - | ||||||
364 | */ | - | ||||||
365 | QAbstractFileEngine::~QAbstractFileEngine() | - | ||||||
366 | { | - | ||||||
367 | } | - | ||||||
368 | - | |||||||
369 | /*! | - | ||||||
370 | \fn bool QAbstractFileEngine::open(QIODevice::OpenMode mode) | - | ||||||
371 | - | |||||||
372 | Opens the file in the specified \a mode. Returns \c true if the file | - | ||||||
373 | was successfully opened; otherwise returns \c false. | - | ||||||
374 | - | |||||||
375 | The \a mode is an OR combination of QIODevice::OpenMode and | - | ||||||
376 | QIODevice::HandlingMode values. | - | ||||||
377 | */ | - | ||||||
378 | bool QAbstractFileEngine::open(QIODevice::OpenMode openMode) | - | ||||||
379 | { | - | ||||||
380 | Q_UNUSED(openMode); | - | ||||||
381 | return false; never executed: return false; | 0 | ||||||
382 | } | - | ||||||
383 | - | |||||||
384 | /*! | - | ||||||
385 | Closes the file, returning true if successful; otherwise returns \c false. | - | ||||||
386 | - | |||||||
387 | The default implementation always returns \c false. | - | ||||||
388 | */ | - | ||||||
389 | bool QAbstractFileEngine::close() | - | ||||||
390 | { | - | ||||||
391 | return false; never executed: return false; | 0 | ||||||
392 | } | - | ||||||
393 | - | |||||||
394 | /*! | - | ||||||
395 | \since 5.1 | - | ||||||
396 | - | |||||||
397 | Flushes and syncs the file to disk. | - | ||||||
398 | - | |||||||
399 | Returns \c true if successful; otherwise returns \c false. | - | ||||||
400 | The default implementation always returns \c false. | - | ||||||
401 | */ | - | ||||||
402 | bool QAbstractFileEngine::syncToDisk() | - | ||||||
403 | { | - | ||||||
404 | return false; never executed: return false; | 0 | ||||||
405 | } | - | ||||||
406 | - | |||||||
407 | /*! | - | ||||||
408 | Flushes the open file, returning true if successful; otherwise returns | - | ||||||
409 | false. | - | ||||||
410 | - | |||||||
411 | The default implementation always returns \c false. | - | ||||||
412 | */ | - | ||||||
413 | bool QAbstractFileEngine::flush() | - | ||||||
414 | { | - | ||||||
415 | return false; never executed: return false; | 0 | ||||||
416 | } | - | ||||||
417 | - | |||||||
418 | /*! | - | ||||||
419 | Returns the size of the file. | - | ||||||
420 | */ | - | ||||||
421 | qint64 QAbstractFileEngine::size() const | - | ||||||
422 | { | - | ||||||
423 | return 0; never executed: return 0; | 0 | ||||||
424 | } | - | ||||||
425 | - | |||||||
426 | /*! | - | ||||||
427 | Returns the current file position. | - | ||||||
428 | - | |||||||
429 | This is the position of the data read/write head of the file. | - | ||||||
430 | */ | - | ||||||
431 | qint64 QAbstractFileEngine::pos() const | - | ||||||
432 | { | - | ||||||
433 | return 0; never executed: return 0; | 0 | ||||||
434 | } | - | ||||||
435 | - | |||||||
436 | /*! | - | ||||||
437 | \fn bool QAbstractFileEngine::seek(qint64 offset) | - | ||||||
438 | - | |||||||
439 | Sets the file position to the given \a offset. Returns \c true if | - | ||||||
440 | the position was successfully set; otherwise returns \c false. | - | ||||||
441 | - | |||||||
442 | The offset is from the beginning of the file, unless the | - | ||||||
443 | file is sequential. | - | ||||||
444 | - | |||||||
445 | \sa isSequential() | - | ||||||
446 | */ | - | ||||||
447 | bool QAbstractFileEngine::seek(qint64 pos) | - | ||||||
448 | { | - | ||||||
449 | Q_UNUSED(pos); | - | ||||||
450 | return false; never executed: return false; | 0 | ||||||
451 | } | - | ||||||
452 | - | |||||||
453 | /*! | - | ||||||
454 | Returns \c true if the file is a sequential access device; returns | - | ||||||
455 | false if the file is a direct access device. | - | ||||||
456 | - | |||||||
457 | Operations involving size() and seek(int) are not valid on | - | ||||||
458 | sequential devices. | - | ||||||
459 | */ | - | ||||||
460 | bool QAbstractFileEngine::isSequential() const | - | ||||||
461 | { | - | ||||||
462 | return false; executed 13 times by 1 test: return false; Executed by:
| 13 | ||||||
463 | } | - | ||||||
464 | - | |||||||
465 | /*! | - | ||||||
466 | Requests that the file is deleted from the file system. If the | - | ||||||
467 | operation succeeds return true; otherwise return false. | - | ||||||
468 | - | |||||||
469 | This virtual function must be reimplemented by all subclasses. | - | ||||||
470 | - | |||||||
471 | \sa setFileName(), rmdir() | - | ||||||
472 | */ | - | ||||||
473 | bool QAbstractFileEngine::remove() | - | ||||||
474 | { | - | ||||||
475 | return false; never executed: return false; | 0 | ||||||
476 | } | - | ||||||
477 | - | |||||||
478 | /*! | - | ||||||
479 | Copies the contents of this file to a file with the name \a newName. | - | ||||||
480 | Returns \c true on success; otherwise, false is returned. | - | ||||||
481 | */ | - | ||||||
482 | bool QAbstractFileEngine::copy(const QString &newName) | - | ||||||
483 | { | - | ||||||
484 | Q_UNUSED(newName); | - | ||||||
485 | return false; never executed: return false; | 0 | ||||||
486 | } | - | ||||||
487 | - | |||||||
488 | /*! | - | ||||||
489 | Requests that the file be renamed to \a newName in the file | - | ||||||
490 | system. If the operation succeeds return true; otherwise return | - | ||||||
491 | false. | - | ||||||
492 | - | |||||||
493 | This virtual function must be reimplemented by all subclasses. | - | ||||||
494 | - | |||||||
495 | \sa setFileName() | - | ||||||
496 | */ | - | ||||||
497 | bool QAbstractFileEngine::rename(const QString &newName) | - | ||||||
498 | { | - | ||||||
499 | Q_UNUSED(newName); | - | ||||||
500 | return false; never executed: return false; | 0 | ||||||
501 | } | - | ||||||
502 | - | |||||||
503 | /*! | - | ||||||
504 | \since 5.1 | - | ||||||
505 | - | |||||||
506 | Requests that the file be renamed to \a newName in the file | - | ||||||
507 | system. If the new name already exists, it must be overwritten. | - | ||||||
508 | If the operation succeeds, returns \c true; otherwise returns | - | ||||||
509 | false. | - | ||||||
510 | - | |||||||
511 | This virtual function must be reimplemented by all subclasses. | - | ||||||
512 | - | |||||||
513 | \sa setFileName() | - | ||||||
514 | */ | - | ||||||
515 | bool QAbstractFileEngine::renameOverwrite(const QString &newName) | - | ||||||
516 | { | - | ||||||
517 | Q_UNUSED(newName); | - | ||||||
518 | return false; never executed: return false; | 0 | ||||||
519 | } | - | ||||||
520 | - | |||||||
521 | /*! | - | ||||||
522 | Creates a link from the file currently specified by fileName() to | - | ||||||
523 | \a newName. What a link is depends on the underlying filesystem | - | ||||||
524 | (be it a shortcut on Windows or a symbolic link on Unix). Returns | - | ||||||
525 | true if successful; otherwise returns \c false. | - | ||||||
526 | */ | - | ||||||
527 | bool QAbstractFileEngine::link(const QString &newName) | - | ||||||
528 | { | - | ||||||
529 | Q_UNUSED(newName); | - | ||||||
530 | return false; never executed: return false; | 0 | ||||||
531 | } | - | ||||||
532 | - | |||||||
533 | /*! | - | ||||||
534 | Requests that the directory \a dirName be created. If | - | ||||||
535 | \a createParentDirectories is true, then any sub-directories in \a dirName | - | ||||||
536 | that don't exist must be created. If \a createParentDirectories is false then | - | ||||||
537 | any sub-directories in \a dirName must already exist for the function to | - | ||||||
538 | succeed. If the operation succeeds return true; otherwise return | - | ||||||
539 | false. | - | ||||||
540 | - | |||||||
541 | This virtual function must be reimplemented by all subclasses. | - | ||||||
542 | - | |||||||
543 | \sa setFileName(), rmdir(), isRelativePath() | - | ||||||
544 | */ | - | ||||||
545 | bool QAbstractFileEngine::mkdir(const QString &dirName, bool createParentDirectories) const | - | ||||||
546 | { | - | ||||||
547 | Q_UNUSED(dirName); | - | ||||||
548 | Q_UNUSED(createParentDirectories); | - | ||||||
549 | return false; never executed: return false; | 0 | ||||||
550 | } | - | ||||||
551 | - | |||||||
552 | /*! | - | ||||||
553 | Requests that the directory \a dirName is deleted from the file | - | ||||||
554 | system. When \a recurseParentDirectories is true, then any empty | - | ||||||
555 | parent-directories in \a dirName must also be deleted. If | - | ||||||
556 | \a recurseParentDirectories is false, only the \a dirName leaf-node | - | ||||||
557 | should be deleted. In most file systems a directory cannot be deleted | - | ||||||
558 | using this function if it is non-empty. If the operation succeeds | - | ||||||
559 | return true; otherwise return false. | - | ||||||
560 | - | |||||||
561 | This virtual function must be reimplemented by all subclasses. | - | ||||||
562 | - | |||||||
563 | \sa setFileName(), remove(), mkdir(), isRelativePath() | - | ||||||
564 | */ | - | ||||||
565 | bool QAbstractFileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const | - | ||||||
566 | { | - | ||||||
567 | Q_UNUSED(dirName); | - | ||||||
568 | Q_UNUSED(recurseParentDirectories); | - | ||||||
569 | return false; never executed: return false; | 0 | ||||||
570 | } | - | ||||||
571 | - | |||||||
572 | /*! | - | ||||||
573 | Requests that the file be set to size \a size. If \a size is larger | - | ||||||
574 | than the current file then it is filled with 0's, if smaller it is | - | ||||||
575 | simply truncated. If the operations succceeds return true; otherwise | - | ||||||
576 | return false; | - | ||||||
577 | - | |||||||
578 | This virtual function must be reimplemented by all subclasses. | - | ||||||
579 | - | |||||||
580 | \sa size() | - | ||||||
581 | */ | - | ||||||
582 | bool QAbstractFileEngine::setSize(qint64 size) | - | ||||||
583 | { | - | ||||||
584 | Q_UNUSED(size); | - | ||||||
585 | return false; never executed: return false; | 0 | ||||||
586 | } | - | ||||||
587 | - | |||||||
588 | /*! | - | ||||||
589 | Should return true if the underlying file system is case-sensitive; | - | ||||||
590 | otherwise return false. | - | ||||||
591 | - | |||||||
592 | This virtual function must be reimplemented by all subclasses. | - | ||||||
593 | */ | - | ||||||
594 | bool QAbstractFileEngine::caseSensitive() const | - | ||||||
595 | { | - | ||||||
596 | return false; never executed: return false; | 0 | ||||||
597 | } | - | ||||||
598 | - | |||||||
599 | /*! | - | ||||||
600 | Return true if the file referred to by this file engine has a | - | ||||||
601 | relative path; otherwise return false. | - | ||||||
602 | - | |||||||
603 | This virtual function must be reimplemented by all subclasses. | - | ||||||
604 | - | |||||||
605 | \sa setFileName() | - | ||||||
606 | */ | - | ||||||
607 | bool QAbstractFileEngine::isRelativePath() const | - | ||||||
608 | { | - | ||||||
609 | return false; never executed: return false; | 0 | ||||||
610 | } | - | ||||||
611 | - | |||||||
612 | /*! | - | ||||||
613 | Requests that a list of all the files matching the \a filters | - | ||||||
614 | list based on the \a filterNames in the file engine's directory | - | ||||||
615 | are returned. | - | ||||||
616 | - | |||||||
617 | Should return an empty list if the file engine refers to a file | - | ||||||
618 | rather than a directory, or if the directory is unreadable or does | - | ||||||
619 | not exist or if nothing matches the specifications. | - | ||||||
620 | - | |||||||
621 | This virtual function must be reimplemented by all subclasses. | - | ||||||
622 | - | |||||||
623 | \sa setFileName() | - | ||||||
624 | */ | - | ||||||
625 | QStringList QAbstractFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const | - | ||||||
626 | { | - | ||||||
627 | QStringList ret; | - | ||||||
628 | QDirIterator it(fileName(), filterNames, filters); | - | ||||||
629 | while (it.hasNext()) {
| 0 | ||||||
630 | it.next(); | - | ||||||
631 | ret << it.fileName(); | - | ||||||
632 | } never executed: end of block | 0 | ||||||
633 | return ret; never executed: return ret; | 0 | ||||||
634 | } | - | ||||||
635 | - | |||||||
636 | /*! | - | ||||||
637 | This function should return the set of OR'd flags that are true | - | ||||||
638 | for the file engine's file, and that are in the \a type's OR'd | - | ||||||
639 | members. | - | ||||||
640 | - | |||||||
641 | In your reimplementation you can use the \a type argument as an | - | ||||||
642 | optimization hint and only return the OR'd set of members that are | - | ||||||
643 | true and that match those in \a type; in other words you can | - | ||||||
644 | ignore any members not mentioned in \a type, thus avoiding some | - | ||||||
645 | potentially expensive lookups or system calls. | - | ||||||
646 | - | |||||||
647 | This virtual function must be reimplemented by all subclasses. | - | ||||||
648 | - | |||||||
649 | \sa setFileName() | - | ||||||
650 | */ | - | ||||||
651 | QAbstractFileEngine::FileFlags QAbstractFileEngine::fileFlags(FileFlags type) const | - | ||||||
652 | { | - | ||||||
653 | Q_UNUSED(type); | - | ||||||
654 | return 0; never executed: return 0; | 0 | ||||||
655 | } | - | ||||||
656 | - | |||||||
657 | /*! | - | ||||||
658 | Requests that the file's permissions be set to \a perms. The argument | - | ||||||
659 | perms will be set to the OR-ed together combination of | - | ||||||
660 | QAbstractFileEngine::FileInfo, with only the QAbstractFileEngine::PermsMask being | - | ||||||
661 | honored. If the operations succceeds return true; otherwise return | - | ||||||
662 | false; | - | ||||||
663 | - | |||||||
664 | This virtual function must be reimplemented by all subclasses. | - | ||||||
665 | - | |||||||
666 | \sa size() | - | ||||||
667 | */ | - | ||||||
668 | bool QAbstractFileEngine::setPermissions(uint perms) | - | ||||||
669 | { | - | ||||||
670 | Q_UNUSED(perms); | - | ||||||
671 | return false; never executed: return false; | 0 | ||||||
672 | } | - | ||||||
673 | - | |||||||
674 | /*! | - | ||||||
675 | Return the file engine's current file name in the format | - | ||||||
676 | specified by \a file. | - | ||||||
677 | - | |||||||
678 | If you don't handle some \c FileName possibilities, return the | - | ||||||
679 | file name set in setFileName() when an unhandled format is | - | ||||||
680 | requested. | - | ||||||
681 | - | |||||||
682 | This virtual function must be reimplemented by all subclasses. | - | ||||||
683 | - | |||||||
684 | \sa setFileName(), FileName | - | ||||||
685 | */ | - | ||||||
686 | QString QAbstractFileEngine::fileName(FileName file) const | - | ||||||
687 | { | - | ||||||
688 | Q_UNUSED(file); | - | ||||||
689 | return QString(); never executed: return QString(); | 0 | ||||||
690 | } | - | ||||||
691 | - | |||||||
692 | /*! | - | ||||||
693 | If \a owner is \c OwnerUser return the ID of the user who owns | - | ||||||
694 | the file. If \a owner is \c OwnerGroup return the ID of the group | - | ||||||
695 | that own the file. If you can't determine the owner return -2. | - | ||||||
696 | - | |||||||
697 | This virtual function must be reimplemented by all subclasses. | - | ||||||
698 | - | |||||||
699 | \sa owner(), setFileName(), FileOwner | - | ||||||
700 | */ | - | ||||||
701 | uint QAbstractFileEngine::ownerId(FileOwner owner) const | - | ||||||
702 | { | - | ||||||
703 | Q_UNUSED(owner); | - | ||||||
704 | return 0; never executed: return 0; | 0 | ||||||
705 | } | - | ||||||
706 | - | |||||||
707 | /*! | - | ||||||
708 | If \a owner is \c OwnerUser return the name of the user who owns | - | ||||||
709 | the file. If \a owner is \c OwnerGroup return the name of the group | - | ||||||
710 | that own the file. If you can't determine the owner return | - | ||||||
711 | QString(). | - | ||||||
712 | - | |||||||
713 | This virtual function must be reimplemented by all subclasses. | - | ||||||
714 | - | |||||||
715 | \sa ownerId(), setFileName(), FileOwner | - | ||||||
716 | */ | - | ||||||
717 | QString QAbstractFileEngine::owner(FileOwner owner) const | - | ||||||
718 | { | - | ||||||
719 | Q_UNUSED(owner); | - | ||||||
720 | return QString(); never executed: return QString(); | 0 | ||||||
721 | } | - | ||||||
722 | - | |||||||
723 | /*! | - | ||||||
724 | If \a time is \c CreationTime, return when the file was created. | - | ||||||
725 | If \a time is \c ModificationTime, return when the file was most | - | ||||||
726 | recently modified. If \a time is \c AccessTime, return when the | - | ||||||
727 | file was most recently accessed (e.g. read or written). | - | ||||||
728 | If the time cannot be determined return QDateTime() (an invalid | - | ||||||
729 | date time). | - | ||||||
730 | - | |||||||
731 | This virtual function must be reimplemented by all subclasses. | - | ||||||
732 | - | |||||||
733 | \sa setFileName(), QDateTime, QDateTime::isValid(), FileTime | - | ||||||
734 | */ | - | ||||||
735 | QDateTime QAbstractFileEngine::fileTime(FileTime time) const | - | ||||||
736 | { | - | ||||||
737 | Q_UNUSED(time); | - | ||||||
738 | return QDateTime(); never executed: return QDateTime(); | 0 | ||||||
739 | } | - | ||||||
740 | - | |||||||
741 | /*! | - | ||||||
742 | Sets the file engine's file name to \a file. This file name is the | - | ||||||
743 | file that the rest of the virtual functions will operate on. | - | ||||||
744 | - | |||||||
745 | This virtual function must be reimplemented by all subclasses. | - | ||||||
746 | - | |||||||
747 | \sa rename() | - | ||||||
748 | */ | - | ||||||
749 | void QAbstractFileEngine::setFileName(const QString &file) | - | ||||||
750 | { | - | ||||||
751 | Q_UNUSED(file); | - | ||||||
752 | } never executed: end of block | 0 | ||||||
753 | - | |||||||
754 | /*! | - | ||||||
755 | Returns the native file handle for this file engine. This handle must be | - | ||||||
756 | used with care; its value and type are platform specific, and using it | - | ||||||
757 | will most likely lead to non-portable code. | - | ||||||
758 | */ | - | ||||||
759 | int QAbstractFileEngine::handle() const | - | ||||||
760 | { | - | ||||||
761 | return -1; executed 1 time by 1 test: return -1; Executed by:
| 1 | ||||||
762 | } | - | ||||||
763 | - | |||||||
764 | /*! | - | ||||||
765 | \since 4.3 | - | ||||||
766 | - | |||||||
767 | Returns \c true if the current position is at the end of the file; otherwise, | - | ||||||
768 | returns \c false. | - | ||||||
769 | - | |||||||
770 | This function bases its behavior on calling extension() with | - | ||||||
771 | AtEndExtension. If the engine does not support this extension, false is | - | ||||||
772 | returned. | - | ||||||
773 | - | |||||||
774 | \sa extension(), supportsExtension(), QFile::atEnd() | - | ||||||
775 | */ | - | ||||||
776 | bool QAbstractFileEngine::atEnd() const | - | ||||||
777 | { | - | ||||||
778 | return const_cast<QAbstractFileEngine *>(this)->extension(AtEndExtension); never executed: return const_cast<QAbstractFileEngine *>(this)->extension(AtEndExtension); | 0 | ||||||
779 | } | - | ||||||
780 | - | |||||||
781 | /*! | - | ||||||
782 | \since 4.4 | - | ||||||
783 | - | |||||||
784 | Maps \a size bytes of the file into memory starting at \a offset. | - | ||||||
785 | Returns a pointer to the memory if successful; otherwise returns \c false | - | ||||||
786 | if, for example, an error occurs. | - | ||||||
787 | - | |||||||
788 | This function bases its behavior on calling extension() with | - | ||||||
789 | MapExtensionOption. If the engine does not support this extension, 0 is | - | ||||||
790 | returned. | - | ||||||
791 | - | |||||||
792 | \a flags is currently not used, but could be used in the future. | - | ||||||
793 | - | |||||||
794 | \sa unmap(), supportsExtension() | - | ||||||
795 | */ | - | ||||||
796 | - | |||||||
797 | uchar *QAbstractFileEngine::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) | - | ||||||
798 | { | - | ||||||
799 | MapExtensionOption option; | - | ||||||
800 | option.offset = offset; | - | ||||||
801 | option.size = size; | - | ||||||
802 | option.flags = flags; | - | ||||||
803 | MapExtensionReturn r; | - | ||||||
804 | if (!extension(MapExtension, &option, &r))
| 24-34265 | ||||||
805 | return 0; executed 24 times by 1 test: return 0; Executed by:
| 24 | ||||||
806 | return r.address; executed 34265 times by 119 tests: return r.address; Executed by:
| 34265 | ||||||
807 | } | - | ||||||
808 | - | |||||||
809 | /*! | - | ||||||
810 | \since 4.4 | - | ||||||
811 | - | |||||||
812 | Unmaps the memory \a address. Returns \c true if the unmap succeeds; otherwise | - | ||||||
813 | returns \c false. | - | ||||||
814 | - | |||||||
815 | This function bases its behavior on calling extension() with | - | ||||||
816 | UnMapExtensionOption. If the engine does not support this extension, false is | - | ||||||
817 | returned. | - | ||||||
818 | - | |||||||
819 | \sa map(), supportsExtension() | - | ||||||
820 | */ | - | ||||||
821 | bool QAbstractFileEngine::unmap(uchar *address) | - | ||||||
822 | { | - | ||||||
823 | UnMapExtensionOption options; | - | ||||||
824 | options.address = address; | - | ||||||
825 | return extension(UnMapExtension, &options); executed 32814 times by 2 tests: return extension(UnMapExtension, &options); Executed by:
| 32814 | ||||||
826 | } | - | ||||||
827 | - | |||||||
828 | /*! | - | ||||||
829 | \since 4.3 | - | ||||||
830 | \class QAbstractFileEngineIterator | - | ||||||
831 | \inmodule QtCore | - | ||||||
832 | \brief The QAbstractFileEngineIterator class provides an iterator | - | ||||||
833 | interface for custom file engines. | - | ||||||
834 | \internal | - | ||||||
835 | - | |||||||
836 | If all you want is to iterate over entries in a directory, see | - | ||||||
837 | QDirIterator instead. This class is only for custom file engine authors. | - | ||||||
838 | - | |||||||
839 | QAbstractFileEngineIterator is a unidirectional single-use virtual | - | ||||||
840 | iterator that plugs into QDirIterator, providing transparent proxy | - | ||||||
841 | iteration for custom file engines. | - | ||||||
842 | - | |||||||
843 | You can subclass QAbstractFileEngineIterator to provide an iterator when | - | ||||||
844 | writing your own file engine. To plug the iterator into your file system, | - | ||||||
845 | you simply return an instance of this subclass from a reimplementation of | - | ||||||
846 | QAbstractFileEngine::beginEntryList(). | - | ||||||
847 | - | |||||||
848 | Example: | - | ||||||
849 | - | |||||||
850 | \snippet code/src_corelib_io_qabstractfileengine.cpp 2 | - | ||||||
851 | - | |||||||
852 | QAbstractFileEngineIterator is associated with a path, name filters, and | - | ||||||
853 | entry filters. The path is the directory that the iterator lists entries | - | ||||||
854 | in. The name filters and entry filters are provided for file engines that | - | ||||||
855 | can optimize directory listing at the iterator level (e.g., network file | - | ||||||
856 | systems that need to minimize network traffic), but they can also be | - | ||||||
857 | ignored by the iterator subclass; QAbstractFileEngineIterator already | - | ||||||
858 | provides the required filtering logics in the matchesFilters() function. | - | ||||||
859 | You can call dirName() to get the directory name, nameFilters() to get a | - | ||||||
860 | stringlist of name filters, and filters() to get the entry filters. | - | ||||||
861 | - | |||||||
862 | The pure virtual function hasNext() returns \c true if the current directory | - | ||||||
863 | has at least one more entry (i.e., the directory name is valid and | - | ||||||
864 | accessible, and we have not reached the end of the entry list), and false | - | ||||||
865 | otherwise. Reimplement next() to seek to the next entry. | - | ||||||
866 | - | |||||||
867 | The pure virtual function currentFileName() returns the name of the | - | ||||||
868 | current entry without advancing the iterator. The currentFilePath() | - | ||||||
869 | function is provided for convenience; it returns the full path of the | - | ||||||
870 | current entry. | - | ||||||
871 | - | |||||||
872 | Here is an example of how to implement an iterator that returns each of | - | ||||||
873 | three fixed entries in sequence. | - | ||||||
874 | - | |||||||
875 | \snippet code/src_corelib_io_qabstractfileengine.cpp 3 | - | ||||||
876 | - | |||||||
877 | Note: QAbstractFileEngineIterator does not deal with QDir::IteratorFlags; | - | ||||||
878 | it simply returns entries for a single directory. | - | ||||||
879 | - | |||||||
880 | \sa QDirIterator | - | ||||||
881 | */ | - | ||||||
882 | - | |||||||
883 | /*! | - | ||||||
884 | \enum QAbstractFileEngineIterator::EntryInfoType | - | ||||||
885 | \internal | - | ||||||
886 | - | |||||||
887 | This enum describes the different types of information that can be | - | ||||||
888 | requested through the QAbstractFileEngineIterator::entryInfo() function. | - | ||||||
889 | */ | - | ||||||
890 | - | |||||||
891 | /*! | - | ||||||
892 | \typedef QAbstractFileEngine::Iterator | - | ||||||
893 | \since 4.3 | - | ||||||
894 | - | |||||||
895 | Synonym for QAbstractFileEngineIterator. | - | ||||||
896 | */ | - | ||||||
897 | - | |||||||
898 | class QAbstractFileEngineIteratorPrivate | - | ||||||
899 | { | - | ||||||
900 | public: | - | ||||||
901 | QString path; | - | ||||||
902 | QDir::Filters filters; | - | ||||||
903 | QStringList nameFilters; | - | ||||||
904 | QFileInfo fileInfo; | - | ||||||
905 | }; | - | ||||||
906 | - | |||||||
907 | /*! | - | ||||||
908 | Constructs a QAbstractFileEngineIterator, using the entry filters \a | - | ||||||
909 | filters, and wildcard name filters \a nameFilters. | - | ||||||
910 | */ | - | ||||||
911 | QAbstractFileEngineIterator::QAbstractFileEngineIterator(QDir::Filters filters, | - | ||||||
912 | const QStringList &nameFilters) | - | ||||||
913 | : d(new QAbstractFileEngineIteratorPrivate) | - | ||||||
914 | { | - | ||||||
915 | d->nameFilters = nameFilters; | - | ||||||
916 | d->filters = filters; | - | ||||||
917 | } executed 176 times by 7 tests: end of block Executed by:
| 176 | ||||||
918 | - | |||||||
919 | /*! | - | ||||||
920 | Destroys the QAbstractFileEngineIterator. | - | ||||||
921 | - | |||||||
922 | \sa QDirIterator | - | ||||||
923 | */ | - | ||||||
924 | QAbstractFileEngineIterator::~QAbstractFileEngineIterator() | - | ||||||
925 | { | - | ||||||
926 | } | - | ||||||
927 | - | |||||||
928 | /*! | - | ||||||
929 | Returns the path for this iterator. QDirIterator is responsible for | - | ||||||
930 | assigning this path; it cannot change during the iterator's lifetime. | - | ||||||
931 | - | |||||||
932 | \sa nameFilters(), filters() | - | ||||||
933 | */ | - | ||||||
934 | QString QAbstractFileEngineIterator::path() const | - | ||||||
935 | { | - | ||||||
936 | return d->path; executed 1210 times by 7 tests: return d->path; Executed by:
| 1210 | ||||||
937 | } | - | ||||||
938 | - | |||||||
939 | /*! | - | ||||||
940 | \internal | - | ||||||
941 | - | |||||||
942 | Sets the iterator path to \a path. This function is called from within | - | ||||||
943 | QDirIterator. | - | ||||||
944 | */ | - | ||||||
945 | void QAbstractFileEngineIterator::setPath(const QString &path) | - | ||||||
946 | { | - | ||||||
947 | d->path = path; | - | ||||||
948 | } executed 176 times by 7 tests: end of block Executed by:
| 176 | ||||||
949 | - | |||||||
950 | /*! | - | ||||||
951 | Returns the name filters for this iterator. | - | ||||||
952 | - | |||||||
953 | \sa QDir::nameFilters(), filters(), path() | - | ||||||
954 | */ | - | ||||||
955 | QStringList QAbstractFileEngineIterator::nameFilters() const | - | ||||||
956 | { | - | ||||||
957 | return d->nameFilters; never executed: return d->nameFilters; | 0 | ||||||
958 | } | - | ||||||
959 | - | |||||||
960 | /*! | - | ||||||
961 | Returns the entry filters for this iterator. | - | ||||||
962 | - | |||||||
963 | \sa QDir::filter(), nameFilters(), path() | - | ||||||
964 | */ | - | ||||||
965 | QDir::Filters QAbstractFileEngineIterator::filters() const | - | ||||||
966 | { | - | ||||||
967 | return d->filters; never executed: return d->filters; | 0 | ||||||
968 | } | - | ||||||
969 | - | |||||||
970 | /*! | - | ||||||
971 | \fn QString QAbstractFileEngineIterator::currentFileName() const = 0 | - | ||||||
972 | - | |||||||
973 | This pure virtual function returns the name of the current directory | - | ||||||
974 | entry, excluding the path. | - | ||||||
975 | - | |||||||
976 | \sa currentFilePath() | - | ||||||
977 | */ | - | ||||||
978 | - | |||||||
979 | /*! | - | ||||||
980 | Returns the path to the current directory entry. It's the same as | - | ||||||
981 | prepending path() to the return value of currentFileName(). | - | ||||||
982 | - | |||||||
983 | \sa currentFileName() | - | ||||||
984 | */ | - | ||||||
985 | QString QAbstractFileEngineIterator::currentFilePath() const | - | ||||||
986 | { | - | ||||||
987 | QString name = currentFileName(); | - | ||||||
988 | if (!name.isNull()) {
| 0-1036 | ||||||
989 | QString tmp = path(); | - | ||||||
990 | if (!tmp.isEmpty()) {
| 0-1036 | ||||||
991 | if (!tmp.endsWith(QLatin1Char('/')))
| 142-894 | ||||||
992 | tmp.append(QLatin1Char('/')); executed 894 times by 7 tests: tmp.append(QLatin1Char('/')); Executed by:
| 894 | ||||||
993 | name.prepend(tmp); | - | ||||||
994 | } executed 1036 times by 7 tests: end of block Executed by:
| 1036 | ||||||
995 | } executed 1036 times by 7 tests: end of block Executed by:
| 1036 | ||||||
996 | return name; executed 1036 times by 7 tests: return name; Executed by:
| 1036 | ||||||
997 | } | - | ||||||
998 | - | |||||||
999 | /*! | - | ||||||
1000 | The virtual function returns a QFileInfo for the current directory | - | ||||||
1001 | entry. This function is provided for convenience. It can also be slightly | - | ||||||
1002 | faster than creating a QFileInfo object yourself, as the object returned | - | ||||||
1003 | by this function might contain cached information that QFileInfo otherwise | - | ||||||
1004 | would have to access through the file engine. | - | ||||||
1005 | - | |||||||
1006 | \sa currentFileName() | - | ||||||
1007 | */ | - | ||||||
1008 | QFileInfo QAbstractFileEngineIterator::currentFileInfo() const | - | ||||||
1009 | { | - | ||||||
1010 | QString path = currentFilePath(); | - | ||||||
1011 | if (d->fileInfo.filePath() != path)
| 0-518 | ||||||
1012 | d->fileInfo.setFile(path); executed 518 times by 7 tests: d->fileInfo.setFile(path); Executed by:
| 518 | ||||||
1013 | - | |||||||
1014 | // return a shallow copy | - | ||||||
1015 | return d->fileInfo; executed 518 times by 7 tests: return d->fileInfo; Executed by:
| 518 | ||||||
1016 | } | - | ||||||
1017 | - | |||||||
1018 | /*! | - | ||||||
1019 | \internal | - | ||||||
1020 | - | |||||||
1021 | Returns the entry info \a type for this iterator's current directory entry | - | ||||||
1022 | as a QVariant. If \a type is undefined for this entry, a null QVariant is | - | ||||||
1023 | returned. | - | ||||||
1024 | - | |||||||
1025 | \sa QAbstractFileEngine::beginEntryList(), QDir::beginEntryList() | - | ||||||
1026 | */ | - | ||||||
1027 | QVariant QAbstractFileEngineIterator::entryInfo(EntryInfoType type) const | - | ||||||
1028 | { | - | ||||||
1029 | Q_UNUSED(type) | - | ||||||
1030 | return QVariant(); never executed: return QVariant(); | 0 | ||||||
1031 | } | - | ||||||
1032 | - | |||||||
1033 | /*! | - | ||||||
1034 | \fn virtual QString QAbstractFileEngineIterator::next() = 0 | - | ||||||
1035 | - | |||||||
1036 | This pure virtual function advances the iterator to the next directory | - | ||||||
1037 | entry, and returns the file path to the current entry. | - | ||||||
1038 | - | |||||||
1039 | This function can optionally make use of nameFilters() and filters() to | - | ||||||
1040 | optimize its performance. | - | ||||||
1041 | - | |||||||
1042 | Reimplement this function in a subclass to advance the iterator. | - | ||||||
1043 | - | |||||||
1044 | \sa QDirIterator::next() | - | ||||||
1045 | */ | - | ||||||
1046 | - | |||||||
1047 | /*! | - | ||||||
1048 | \fn virtual bool QAbstractFileEngineIterator::hasNext() const = 0 | - | ||||||
1049 | - | |||||||
1050 | This pure virtual function returns \c true if there is at least one more | - | ||||||
1051 | entry in the current directory (i.e., the iterator path is valid and | - | ||||||
1052 | accessible, and the iterator has not reached the end of the entry list). | - | ||||||
1053 | - | |||||||
1054 | \sa QDirIterator::hasNext() | - | ||||||
1055 | */ | - | ||||||
1056 | - | |||||||
1057 | /*! | - | ||||||
1058 | Returns an instance of a QAbstractFileEngineIterator using \a filters for | - | ||||||
1059 | entry filtering and \a filterNames for name filtering. This function is | - | ||||||
1060 | called by QDirIterator to initiate directory iteration. | - | ||||||
1061 | - | |||||||
1062 | QDirIterator takes ownership of the returned instance, and deletes it when | - | ||||||
1063 | it's done. | - | ||||||
1064 | - | |||||||
1065 | \sa QDirIterator | - | ||||||
1066 | */ | - | ||||||
1067 | QAbstractFileEngine::Iterator *QAbstractFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames) | - | ||||||
1068 | { | - | ||||||
1069 | Q_UNUSED(filters); | - | ||||||
1070 | Q_UNUSED(filterNames); | - | ||||||
1071 | return 0; never executed: return 0; | 0 | ||||||
1072 | } | - | ||||||
1073 | - | |||||||
1074 | /*! | - | ||||||
1075 | \internal | - | ||||||
1076 | */ | - | ||||||
1077 | QAbstractFileEngine::Iterator *QAbstractFileEngine::endEntryList() | - | ||||||
1078 | { | - | ||||||
1079 | return 0; never executed: return 0; | 0 | ||||||
1080 | } | - | ||||||
1081 | - | |||||||
1082 | /*! | - | ||||||
1083 | Reads a number of characters from the file into \a data. At most | - | ||||||
1084 | \a maxlen characters will be read. | - | ||||||
1085 | - | |||||||
1086 | Returns -1 if a fatal error occurs, or 0 if there are no bytes to | - | ||||||
1087 | read. | - | ||||||
1088 | */ | - | ||||||
1089 | qint64 QAbstractFileEngine::read(char *data, qint64 maxlen) | - | ||||||
1090 | { | - | ||||||
1091 | Q_UNUSED(data); | - | ||||||
1092 | Q_UNUSED(maxlen); | - | ||||||
1093 | return -1; never executed: return -1; | 0 | ||||||
1094 | } | - | ||||||
1095 | - | |||||||
1096 | /*! | - | ||||||
1097 | Writes \a len bytes from \a data to the file. Returns the number | - | ||||||
1098 | of characters written on success; otherwise returns -1. | - | ||||||
1099 | */ | - | ||||||
1100 | qint64 QAbstractFileEngine::write(const char *data, qint64 len) | - | ||||||
1101 | { | - | ||||||
1102 | Q_UNUSED(data); | - | ||||||
1103 | Q_UNUSED(len); | - | ||||||
1104 | return -1; never executed: return -1; | 0 | ||||||
1105 | } | - | ||||||
1106 | - | |||||||
1107 | /*! | - | ||||||
1108 | This function reads one line, terminated by a '\\n' character, from the | - | ||||||
1109 | file info \a data. At most \a maxlen characters will be read. The | - | ||||||
1110 | end-of-line character is included. | - | ||||||
1111 | */ | - | ||||||
1112 | qint64 QAbstractFileEngine::readLine(char *data, qint64 maxlen) | - | ||||||
1113 | { | - | ||||||
1114 | qint64 readSoFar = 0; | - | ||||||
1115 | while (readSoFar < maxlen) {
| 0-8 | ||||||
1116 | char c; | - | ||||||
1117 | qint64 readResult = read(&c, 1); | - | ||||||
1118 | if (readResult <= 0)
| 0-8 | ||||||
1119 | return (readSoFar > 0) ? readSoFar : -1; executed 8 times by 1 test: return (readSoFar > 0) ? readSoFar : -1; Executed by:
| 0-8 | ||||||
1120 | ++readSoFar; | - | ||||||
1121 | *data++ = c; | - | ||||||
1122 | if (c == '\n')
| 0 | ||||||
1123 | return readSoFar; never executed: return readSoFar; | 0 | ||||||
1124 | } never executed: end of block | 0 | ||||||
1125 | return readSoFar; never executed: return readSoFar; | 0 | ||||||
1126 | } | - | ||||||
1127 | - | |||||||
1128 | /*! | - | ||||||
1129 | \enum QAbstractFileEngine::Extension | - | ||||||
1130 | \since 4.3 | - | ||||||
1131 | - | |||||||
1132 | This enum describes the types of extensions that the file engine can | - | ||||||
1133 | support. Before using these extensions, you must verify that the extension | - | ||||||
1134 | is supported (i.e., call supportsExtension()). | - | ||||||
1135 | - | |||||||
1136 | \value AtEndExtension Whether the current file position is at the end of | - | ||||||
1137 | the file or not. This extension allows file engines that implement local | - | ||||||
1138 | buffering to report end-of-file status without having to check the size of | - | ||||||
1139 | the file. It is also useful for sequential files, where the size of the | - | ||||||
1140 | file cannot be used to determine whether or not you have reached the end. | - | ||||||
1141 | This extension returns \c true if the file is at the end; otherwise it returns | - | ||||||
1142 | false. The input and output arguments to extension() are ignored. | - | ||||||
1143 | - | |||||||
1144 | \value FastReadLineExtension Whether the file engine provides a | - | ||||||
1145 | fast implementation for readLine() or not. If readLine() remains | - | ||||||
1146 | unimplemented in the file engine, QAbstractFileEngine will provide | - | ||||||
1147 | an implementation based on calling read() repeatedly. If | - | ||||||
1148 | supportsExtension() returns \c false for this extension, however, | - | ||||||
1149 | QIODevice can provide a faster implementation by making use of its | - | ||||||
1150 | internal buffer. For engines that already provide a fast readLine() | - | ||||||
1151 | implementation, returning false for this extension can avoid | - | ||||||
1152 | unnnecessary double-buffering in QIODevice. | - | ||||||
1153 | - | |||||||
1154 | \value MapExtension Whether the file engine provides the ability to map | - | ||||||
1155 | a file to memory. | - | ||||||
1156 | - | |||||||
1157 | \value UnMapExtension Whether the file engine provides the ability to | - | ||||||
1158 | unmap memory that was previously mapped. | - | ||||||
1159 | */ | - | ||||||
1160 | - | |||||||
1161 | /*! | - | ||||||
1162 | \class QAbstractFileEngine::ExtensionOption | - | ||||||
1163 | \inmodule QtCore | - | ||||||
1164 | \since 4.3 | - | ||||||
1165 | \brief provides an extended input argument to QAbstractFileEngine's | - | ||||||
1166 | extension support. | - | ||||||
1167 | - | |||||||
1168 | \sa QAbstractFileEngine::extension() | - | ||||||
1169 | */ | - | ||||||
1170 | - | |||||||
1171 | /*! | - | ||||||
1172 | \class QAbstractFileEngine::ExtensionReturn | - | ||||||
1173 | \inmodule QtCore | - | ||||||
1174 | \since 4.3 | - | ||||||
1175 | \brief provides an extended output argument to QAbstractFileEngine's | - | ||||||
1176 | extension support. | - | ||||||
1177 | - | |||||||
1178 | \sa QAbstractFileEngine::extension() | - | ||||||
1179 | */ | - | ||||||
1180 | - | |||||||
1181 | /*! | - | ||||||
1182 | \since 4.3 | - | ||||||
1183 | - | |||||||
1184 | This virtual function can be reimplemented in a QAbstractFileEngine | - | ||||||
1185 | subclass to provide support for extensions. The \a option argument is | - | ||||||
1186 | provided as input to the extension, and this function can store output | - | ||||||
1187 | results in \a output. | - | ||||||
1188 | - | |||||||
1189 | The behavior of this function is determined by \a extension; see the | - | ||||||
1190 | Extension documentation for details. | - | ||||||
1191 | - | |||||||
1192 | You can call supportsExtension() to check if an extension is supported by | - | ||||||
1193 | the file engine. | - | ||||||
1194 | - | |||||||
1195 | By default, no extensions are supported, and this function returns \c false. | - | ||||||
1196 | - | |||||||
1197 | \sa supportsExtension(), Extension | - | ||||||
1198 | */ | - | ||||||
1199 | bool QAbstractFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) | - | ||||||
1200 | { | - | ||||||
1201 | Q_UNUSED(extension); | - | ||||||
1202 | Q_UNUSED(option); | - | ||||||
1203 | Q_UNUSED(output); | - | ||||||
1204 | return false; never executed: return false; | 0 | ||||||
1205 | } | - | ||||||
1206 | - | |||||||
1207 | /*! | - | ||||||
1208 | \since 4.3 | - | ||||||
1209 | - | |||||||
1210 | This virtual function returns \c true if the file engine supports \a | - | ||||||
1211 | extension; otherwise, false is returned. By default, no extensions are | - | ||||||
1212 | supported. | - | ||||||
1213 | - | |||||||
1214 | \sa extension() | - | ||||||
1215 | */ | - | ||||||
1216 | bool QAbstractFileEngine::supportsExtension(Extension extension) const | - | ||||||
1217 | { | - | ||||||
1218 | Q_UNUSED(extension); | - | ||||||
1219 | return false; never executed: return false; | 0 | ||||||
1220 | } | - | ||||||
1221 | - | |||||||
1222 | /*! | - | ||||||
1223 | Returns the QFile::FileError that resulted from the last failed | - | ||||||
1224 | operation. If QFile::UnspecifiedError is returned, QFile will | - | ||||||
1225 | use its own idea of the error status. | - | ||||||
1226 | - | |||||||
1227 | \sa QFile::FileError, errorString() | - | ||||||
1228 | */ | - | ||||||
1229 | QFile::FileError QAbstractFileEngine::error() const | - | ||||||
1230 | { | - | ||||||
1231 | Q_D(const QAbstractFileEngine); | - | ||||||
1232 | return d->fileError; executed 3539 times by 52 tests: return d->fileError; Executed by:
| 3539 | ||||||
1233 | } | - | ||||||
1234 | - | |||||||
1235 | /*! | - | ||||||
1236 | Returns the human-readable message appropriate to the current error | - | ||||||
1237 | reported by error(). If no suitable string is available, an | - | ||||||
1238 | empty string is returned. | - | ||||||
1239 | - | |||||||
1240 | \sa error() | - | ||||||
1241 | */ | - | ||||||
1242 | QString QAbstractFileEngine::errorString() const | - | ||||||
1243 | { | - | ||||||
1244 | Q_D(const QAbstractFileEngine); | - | ||||||
1245 | return d->errorString; executed 4122 times by 62 tests: return d->errorString; Executed by:
| 4122 | ||||||
1246 | } | - | ||||||
1247 | - | |||||||
1248 | /*! | - | ||||||
1249 | Sets the error type to \a error, and the error string to \a errorString. | - | ||||||
1250 | Call this function to set the error values returned by the higher-level | - | ||||||
1251 | classes. | - | ||||||
1252 | - | |||||||
1253 | \sa QFile::error(), QIODevice::errorString(), QIODevice::setErrorString() | - | ||||||
1254 | */ | - | ||||||
1255 | void QAbstractFileEngine::setError(QFile::FileError error, const QString &errorString) | - | ||||||
1256 | { | - | ||||||
1257 | Q_D(QAbstractFileEngine); | - | ||||||
1258 | d->fileError = error; | - | ||||||
1259 | d->errorString = errorString; | - | ||||||
1260 | } executed 6178 times by 70 tests: end of block Executed by:
| 6178 | ||||||
1261 | - | |||||||
1262 | QT_END_NAMESPACE | - | ||||||
Source code | Switch to Preprocessed file |