⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qabstractfileengine.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtCore module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qabstractfileengine.h"#include "private/qabstractfileengine_p.h"#include "qdatetime.h"#include "qmutex.h"#include "qvariant.h"// built-in handlers#include "qfsfileengine.h"#include "qdiriterator.h"/*!    \class QAbstractFileEngineHandler    \reentrant    \brief The QAbstractFileEngineHandler class provides a way to register    custom file engines with your application.    \ingroup io    \since 4.1    QAbstractFileEngineHandler is a factory for creating QAbstractFileEngine    objects (file engines), which are used internally by QFile, QFileInfo, and    QDir when working with files and directories.    When you open a file, Qt chooses a suitable file engine by passing the    file name from QFile or QDir through an internal list of registered file    engine handlers. The first handler to recognize the file name is used to    create the engine. Qt provides internal file engines for working with    regular files and resources, but you can also register your own    QAbstractFileEngine subclasses.    To install an application-specific file engine, you subclass    QAbstractFileEngineHandler and reimplement create(). When you instantiate    the handler (e.g. by creating an instance on the stack or on the heap), it    will automatically register with Qt. (The latest registered handler takes    precedence over existing handlers.)    For example:    \code        class ZipEngineHandler : public QAbstractFileEngineHandler        {        public:            QAbstractFileEngine *create(const QString &fileName) const;        };        QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const        {            // ZipEngineHandler returns a ZipEngine for all .zip files            return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;        }        int main(int argc, char **argv)        {            QApplication app(argc, argv);            ZipEngineHandler engine;            MainWindow window;            window.show();            return app.exec();        }    \endcode    When the handler is destroyed, it is automatically removed from Qt.    The most common approach to registering a handler is to create an instance    as part of the start-up phase of your application. It is also possible to    limit the scope of the file engine handler to a particular area of    interest (e.g. a special file dialog that needs a custom file engine). By    creating the handler inside a local scope, you can precisely control the    area in which your engine will be applied without disturbing file    operations in other parts of your application.    \sa QAbstractFileEngine, QAbstractFileEngine::create()*//*    All application-wide handlers are stored in this list. The mutex must be    acquired to ensure thread safety. */Q_GLOBAL_STATIC_WITH_ARGS(QMutex, fileEngineHandlerMutex, (QMutex::Recursive))static bool qt_abstractfileenginehandlerlist_shutDown = false;class QAbstractFileEngineHandlerList : public QList<QAbstractFileEngineHandler *>{public:    ~QAbstractFileEngineHandlerList()    {        QMutexLocker locker(fileEngineHandlerMutex());        qt_abstractfileenginehandlerlist_shutDown = true;    }};Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers)/*!    Constructs a file handler and registers it with Qt. Once created this    handler's create() function will be called (along with all the other    handlers) for any paths used. The most recently created handler that    recognizes the given path (i.e. that returns a QAbstractFileEngine) is    used for the new path.    \sa create() */QAbstractFileEngineHandler::QAbstractFileEngineHandler(){    QMutexLocker locker(fileEngineHandlerMutex());    fileEngineHandlers()->prepend(this);}/*!    Destroys the file handler. This will automatically unregister the handler    from Qt. */QAbstractFileEngineHandler::~QAbstractFileEngineHandler(){    QMutexLocker locker(fileEngineHandlerMutex());    // Remove this handler from the handler list only if the list is valid.    if (!qt_abstractfileenginehandlerlist_shutDown)        fileEngineHandlers()->removeAll(this);}/*!    \fn QAbstractFileEngine *QAbstractFileEngineHandler::create(const QString &fileName) const    Creates a file engine for file \a fileName. Returns 0 if this    file handler cannot handle \a fileName.    Example:    \code        QAbstractSocketEngine *ZipEngineHandler::create(const QString &fileName) const        {            // ZipEngineHandler returns a ZipEngine for all .zip files            return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;        }    \endcode    \sa QAbstractFileEngine::create()*//*!    Creates and returns a QAbstractFileEngine suitable for processing \a    fileName.    You should not need to call this function; use QFile, QFileInfo or    QDir directly instead.    If you reimplemnt this function, it should only return file    engines that knows how to handle \a fileName; otherwise, it should    return 0.    \sa QAbstractFileEngineHandler*/QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName){    QMutexLocker locker(fileEngineHandlerMutex());    // check for registered handlers that can load the file    for (int i = 0; i < fileEngineHandlers()->size(); i++) {        if (QAbstractFileEngine *ret = fileEngineHandlers()->at(i)->create(fileName))            return ret;    }#ifdef QT_BUILD_CORE_LIB    if (!fileName.startsWith(QLatin1Char('/'))) {        int prefixSeparator = fileName.indexOf(QLatin1Char(':'));        if (prefixSeparator > 1) {            QString prefix = fileName.left(prefixSeparator);            QString fileNameWithoutPrefix = fileName.mid(prefixSeparator + 1).prepend(QLatin1Char('/'));            const QStringList &paths = QDir::searchPaths(prefix);            for (int i = 0; i < paths.count(); i++) {                QString path = paths.at(i);                path.append(fileNameWithoutPrefix);                QAbstractFileEngine *engine = create(path);                if (engine && (engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::ExistsFlag)) {                    return engine;                }                delete engine;            }        }    }#endif    // fall back to regular file engine    return new QFSFileEngine(fileName);}/*!    \class QAbstractFileEngine    \reentrant    \brief The QAbstractFileEngine class provides an abstraction for accessing    the filesystem.    \ingroup io    \since 4.1    The QDir, QFile, and QFileInfo classes all make use of a    QAbstractFileEngine internally. If you create your own QAbstractFileEngine    subclass (and register it with Qt by creating a QAbstractFileEngineHandler    subclass), your file engine will be used when the path is one that your    file engine handles.    A QAbstractFileEngine refers to one file or one directory. If the referent    is a file, the setFileName(), rename(), and remove() functions are    applicable. If the referent is a directory the mkdir(), rmdir(), and    entryList() functions are applicable. In all cases the caseSensitive(),    isRelativePath(), fileFlags(), ownerId(), owner(), and fileTime()    functions are applicable.    A QAbstractFileEngine subclass can be created to do synchronous network I/O    based file system operations, local file system operations, or to operate    as a resource system to access file based resources.   \sa QAbstractFileEngineHandler*//*!    \enum QAbstractFileEngine::FileName    These values are used to request a file name in a particular    format.    \value DefaultName The same filename that was passed to the    QAbstractFileEngine.    \value BaseName The name of the file excluding the path.    \value PathName The path to the file excluding the base name.    \value AbsoluteName The absolute path to the file (including    the base name).    \value AbsolutePathName The absolute path to the file (excluding    the base name).    \value LinkName The full file name of the file that this file is a    link to. (This will be empty if this file is not a link.)    \value CanonicalName Often very similar to LinkName. Will return the true path to the file.    \value CanonicalPathName Same as CanonicalName, excluding the base name.    \value BundleName Returns the name of the bundle implies BundleType is set.    \sa fileName(), setFileName()*//*!    \enum QAbstractFileEngine::FileFlag    The permissions and types of a file, suitable for OR'ing together.    \value ReadOwnerPerm The owner of the file has permission to read    it.    \value WriteOwnerPerm The owner of the file has permission to    write to it.    \value ExeOwnerPerm The owner of the file has permission to    execute it.    \value ReadUserPerm The current user has permission to read the    file.    \value WriteUserPerm The current user has permission to write to    the file.    \value ExeUserPerm The current user has permission to execute the    file.    \value ReadGroupPerm Members of the current user's group have    permission to read the file.    \value WriteGroupPerm Members of the current user's group have    permission to write to the file.    \value ExeGroupPerm Members of the current user's group have    permission to execute the file.    \value ReadOtherPerm All users have permission to read the file.    \value WriteOtherPerm All users have permission to write to the    file.    \value ExeOtherPerm All users have permission to execute the file.    \value LinkType The file is a link to another file (or link) in    the file system (i.e. not a file or directory).    \value FileType The file is a regular file to the file system    (i.e. not a link or directory)    \value BundleType The file is a Mac OS X bundle implies DirectoryType    \value DirectoryType The file is a directory in the file system    (i.e. not a link or file).    \value HiddenFlag The file is hidden.    \value ExistsFlag The file actually exists in the file system.    \value RootFlag  The file or the file pointed to is the root of the filesystem.    \value LocalDiskFlag The file resides on the local disk and can be passed to standard file functions.    \value Refresh Passing this flag will force the file engine to refresh all flags.    \omitvalue PermsMask    \omitvalue TypesMask    \omitvalue FlagsMask    \omitvalue FileInfoAll    \sa fileFlags(), setFileName()*//*!    \enum QAbstractFileEngine::FileTime    These are used by the fileTime() function.    \value CreationTime When the file was created.    \value ModificationTime When the file was most recently modified.    \value AccessTime When the file was most recently accessed (e.g.    read or written to).    \sa setFileName()*//*!    \enum QAbstractFileEngine::FileOwner    \value OwnerUser The user who owns the file.    \value OwnerGroup The group who owns the file.    \sa owner(), ownerId(), setFileName()*//*!   Constructs a new QAbstractFileEngine that does not refer to any file or directory.   \sa setFileName() */QAbstractFileEngine::QAbstractFileEngine() : d_ptr(new QAbstractFileEnginePrivate){    d_ptr->q_ptr = this;}/*!   \internal   Constructs a QAbstractFileEngine. */QAbstractFileEngine::QAbstractFileEngine(QAbstractFileEnginePrivate &dd) : d_ptr(&dd){    d_ptr->q_ptr = this;}/*!    Destroys the QAbstractFileEngine. */QAbstractFileEngine::~QAbstractFileEngine(){    delete d_ptr;    d_ptr = 0;}/*!    \fn bool QAbstractFileEngine::open(QIODevice::OpenMode mode)    Opens the file in the specified \a mode. Returns true if the file    was successfully opened; otherwise returns false.    The \a mode is an OR combination of QIODevice::OpenMode and    QIODevice::HandlingMode values.*/bool QAbstractFileEngine::open(QIODevice::OpenMode openMode){    Q_UNUSED(openMode);    return false;}/*!    Closes the file, returning true if successful; otherwise returns false.    The default implementation always returns false.*/bool QAbstractFileEngine::close(){    return false;}/*!    Flushes the open file, returning true if successful; otherwise returns    false.    The default implementation always returns false.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -