CopperSpice API  2.0.0
QAbstractFileEngine Class Reference

The QAbstractFileEngine is a base class abstraction for accessing the file system. More...

Inheritance diagram for QAbstractFileEngine:
QFSFileEngine

Classes

class  ExtensionOption
 Provides an extended input argument to QAbstractFileEngine's extension support More...
 
class  ExtensionReturn
 Provides an extended output argument to QAbstractFileEngine's extension support More...
 
class  MapExtensionOption
 Indicates a file engine supports the map() method More...
 
class  MapExtensionReturn
 Indicates a file engine which supports returning an address from the map() method More...
 
class  UnMapExtensionOption
 Indicates a file engine supports the unmap() method More...
 

Public Typedefs

using FileFlags = QFlags< FileFlag >
 

Public Types

enum  Extension
 
enum  FileFlag
 
enum  FileName
 
enum  FileOwner
 

Public Methods

virtual ~QAbstractFileEngine ()
 
bool atEnd () const
 
virtual QAbstractFileEngineIteratorbeginEntryList (QDir::Filters filters, const QStringList &filterNames)
 
virtual bool caseSensitive () const
 
virtual bool close ()
 
virtual bool copy (const QString &newName)
 
virtual QStringList entryList (QDir::Filters filters, const QStringList &filterNames) const
 
QFile::FileError error () const
 
QString errorString () const
 
virtual bool extension (Extension extension, const ExtensionOption *option=nullptr, ExtensionReturn *output=nullptr)
 
virtual FileFlags fileFlags (FileFlags type=FileInfoAll) const
 
virtual QString fileName (FileName file=DefaultName) const
 
virtual QDateTime fileTime (QFileDevice::FileTimeType type) const
 
virtual bool flush ()
 
virtual int handle () const
 
virtual bool isRelativePath () const
 
virtual bool isSequential () const
 
virtual bool link (const QString &newName)
 
ucharmap (qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
 
virtual bool mkdir (const QString &dirName, bool createParentDirectories) const
 
virtual bool open (QIODevice::OpenMode mode)
 
virtual QString owner (FileOwner owner) const
 
virtual uint ownerId (FileOwner owner) const
 
virtual qint64 pos () const
 
virtual qint64 read (char *data, qint64 maxlen)
 
virtual qint64 readLine (char *data, qint64 maxlen)
 
virtual bool remove ()
 
virtual bool rename (const QString &newName)
 
virtual bool renameOverwrite (const QString &newName)
 
virtual bool rmdir (const QString &dirName, bool recurseParentDirectories) const
 
virtual bool seek (qint64 offset)
 
virtual void setFileName (const QString &file)
 
virtual bool setFileTime (const QDateTime &newTime, QFileDevice::FileTimeType type)
 
virtual bool setPermissions (uint perms)
 
virtual bool setSize (qint64 size)
 
virtual qint64 size () const
 
virtual bool supportsExtension (Extension extension) const
 
virtual bool syncToDisk ()
 
bool unmap (uchar *address)
 
virtual qint64 write (const char *data, qint64 len)
 

Static Public Methods

static QAbstractFileEngine * create (const QString &fileName)
 

Protected Methods

 QAbstractFileEngine ()
 
void setError (QFile::FileError error, const QString &errorString)
 

Detailed Description

This is a base class abstraction for accessing the file system.

The QDir, QFile, and QFileInfo classes will call methods in QAbstractFileEngine. To change the behavior of these classes create a new class which inherits from QAbstractFileEngine. To use your custom file engine, you will need to register your new class with CopperSpice by inheriting from QAbstractFileEngineHandler.

The design of QAbstractFileEngine is to refer to a single file or directory. The main file methods include setFileName(), rename(), and remove(). The methods for a directory are mkdir(), rmdir(), and entryList(). The methods caseSensitive(), isRelativePath(), fileFlags(), ownerId(), owner(), and fileTime() apply to both files and directories.

See also
QAbstractFileEngineHandler

Member Typedef Documentation

Typedef for QFlags<FileFlag> which contains an OR combination of FileFlag values.

Refer to QAbstractFileEngine::FileFlag for the enum documentation.

Member Enumeration Documentation

This enum describes the types of extensions the file engine can support. Before using an extension verify it is supported by calling supportsExtension().

ConstantValueDescription
QAbstractFileEngine::AtEndExtension0 Test if the current file position is at the end of the file.

This extension allows file engines with local buffering to report end-of-file status without checking the file size. It is useful for sequential files where the size of the file can not be used to determine whether or not you have reached the end. Calling extension() with this value returns true if the current position is at the end of the file, otherwise it returns false.

QAbstractFileEngine::FastReadLineExtension1 Test if the file engine provides a fast implementation for readLine().

If readLine() is not implemented in the file engine, QAbstractFileEngine will provide a default implementation based on calling read() repeatedly. If supportsExtension() returns false for this value QIODevice can provide a faster implementation by making use of its internal buffer. For engines which provide a fast readLine() implementation, returning false for this extension can avoid unnecessary double-buffering in QIODevice.

QAbstractFileEngine::MapExtension2 File engine has the ability to map a file into memory.
QAbstractFileEngine::UnMapExtension3 File engine provides the ability to unmap memory which was previously mapped.

The permissions and types of a file which can be ORed together.

ConstantValueDescription
QAbstractFileEngine::ReadOwnerPerm 0x4000 Owner of the file has permission to read
QAbstractFileEngine::WriteOwnerPerm 0x2000 Owner of the file has permission to write
QAbstractFileEngine::ExeOwnerPerm 0x1000 Owner of the file has permission to execute
QAbstractFileEngine::ReadUserPerm 0x0400 Current user has permission to read
QAbstractFileEngine::WriteUserPerm 0x0200 Current user has permission to write
QAbstractFileEngine::ExeUserPerm 0x0100 Current user has permission to execute
QAbstractFileEngine::ReadGroupPerm 0x0040 Members of the current user's group have permission to read
QAbstractFileEngine::WriteGroupPerm 0x0020 Members of the current user's group have permission to write
QAbstractFileEngine::ExeGroupPerm 0x0010 Members of the current user's group have permission to execute
QAbstractFileEngine::ReadOtherPerm 0x0004 All users have permission to read
QAbstractFileEngine::WriteOtherPerm 0x0002 All users have permission to write
QAbstractFileEngine::ExeOtherPerm 0x0001 All users have permission to execute
QAbstractFileEngine::LinkType 0x10000 File is a link to another file or link
QAbstractFileEngine::FileType 0x20000 File is a regular file, not a link or a directory
QAbstractFileEngine::BundleType 0x80000 File is a Mac OS X bundle
QAbstractFileEngine::DirectoryType 0x40000 File is a directory in the file system, not a file or a link
QAbstractFileEngine::HiddenFlag 0x0100000 File is hidden
QAbstractFileEngine::ExistsFlag 0x0400000 File actually exists in the file system
QAbstractFileEngine::RootFlag 0x0800000 File or the file pointed to is the root of the filesystem
QAbstractFileEngine::LocalDiskFlag 0x0200000 File resides on the local disk and can be passed to standard file methods
QAbstractFileEngine::Refresh 0x1000000 Passing this flag will force the file engine to refresh all flags
See also
fileFlags(), setFileName()

These values are used to request a file name in a particular format.

ConstantValueDescription
QAbstractFileEngine::DefaultName 0 Same filename which was passed to the QAbstractFileEngine
QAbstractFileEngine::BaseName 1 Name of the file excluding the path
QAbstractFileEngine::PathName 2 Path to the file excluding the base name
QAbstractFileEngine::AbsoluteName 3 Absolute path to the file (including the base name)
QAbstractFileEngine::AbsolutePathName 4 Absolute path to the file (excluding the base name)
QAbstractFileEngine::LinkName 5 Full file name of the target of this link, empty if this file is not a link
QAbstractFileEngine::CanonicalName 6 Often very similar to LinkName, will return the canonical path to the file
QAbstractFileEngine::CanonicalPathName 7 Same as CanonicalName, excluding the base name
QAbstractFileEngine::BundleName 8 Returns the name of the bundle
See also
fileName(), setFileName()

An enum which indicates information about the owner of a file.

ConstantValueDescription
QAbstractFileEngine::OwnerUser 0 User who owns the file
QAbstractFileEngine::OwnerGroup 1 Group who owns the file
See also
owner(), ownerId()

Constructor & Destructor Documentation

QAbstractFileEngine::~QAbstractFileEngine ( )
virtual

Destroys the current QAbstractFileEngine.

QAbstractFileEngine::QAbstractFileEngine ( )
protected

Constructs a new QAbstractFileEngine which does not refer to any specific file or directory.

See also
setFileName()

Method Documentation

bool QAbstractFileEngine::atEnd ( ) const

Returns true if the current position is at the end of the file, otherwise returns false.

This method calls extension() with the enum AtEndExtension. If the current QAbstractFileEngine does not support this extension, false will be returned.

See also
extension(), supportsExtension(), QFile::atEnd()
QAbstractFileEngineIterator * QAbstractFileEngine::beginEntryList ( QDir::Filters  filters,
const QStringList filterNames 
)
virtual

Returns a pointer to a QAbstractFileEngineIterator. Only files matching filters and filterNames will be part of the list. The caller is the owner of the iterator and is responsible for deleting it.

See also
QDirIterator

Reimplemented in QFSFileEngine::beginEntryList()

bool QAbstractFileEngine::caseSensitive ( ) const
virtual

This method returns true if the underlying file system is case sensitive, otherwise return false.

Reimplemented in QFSFileEngine::caseSensitive()

bool QAbstractFileEngine::close ( )
virtual

Closes the file, returning true if successful, otherwise returns false. The default implementation always returns false.

Reimplemented in QFSFileEngine::close()

bool QAbstractFileEngine::copy ( const QString newName)
virtual

Copies the contents of the current file to a file with the name newName. Returns true on success, otherwise false is returned.

Reimplemented in QFSFileEngine::copy()

QAbstractFileEngine * QAbstractFileEngine::create ( const QString fileName)
static

Creates and returns a QAbstractFileEngine for processing fileName. Normally, this method should not be called. Prefer using methods in QFile, QFileInfo or QDir.

When overriding this method only return a file engine which can handle the given fileName, otherwise it should return a nullptr.

See also
QAbstractFileEngineHandler
QStringList QAbstractFileEngine::entryList ( QDir::Filters  filters,
const QStringList filterNames 
) const
virtual

Returns a list of all files matching filters based on the filterNames in the current QAbstractFileEngine.

This method should return an empty list if the QAbstractFileEngine refers to a file rather than a directory. It should also return an empty list if the directory is unreadable, the directory does not exist, or if there are no filter matches.

See also
setFileName()

Reimplemented in QFSFileEngine::entryList()

QFile::FileError QAbstractFileEngine::error ( ) const

Returns a value from the enum QFile::FileError which resulted from the last failed operation.

See also
errorString(), setError(), QFile::FileError
QString QAbstractFileEngine::errorString ( ) const

Returns the human readable message correspoding to the current error reported by calling error(). If no suitable string is available, an empty string is returned.

See also
error()
bool QAbstractFileEngine::extension ( Extension  extension,
const ExtensionOption option = nullptr,
ExtensionReturn output = nullptr 
)
virtual

This method can be reimplemented in a custom QAbstractFileEngine class to provide support for extensions. The value for option is the input to the extension and this method needs to store the output result in output.

The behavior of this method is determined by extension. You can call supportsExtension() to check if an extension is supported by the current file engine. By default, no extensions are supported and this method returns false.

See also
supportsExtension(), Extension
FileFlags QAbstractFileEngine::fileFlags ( FileFlags  type = FileInfoAll) const
virtual

This method returns the set of flags which are true for the current file, if they match the flags in the given type.

See also
setFileName()

Reimplemented in QFSFileEngine::fileFlags()

QString QAbstractFileEngine::fileName ( FileName  file = DefaultName) const
virtual

Returns the file name for the current QAbstractFileEngine in the format specified by value of the file enum.

See also
setFileName(), FileName

Reimplemented in QFSFileEngine::fileName()

QDateTime QAbstractFileEngine::fileTime ( QFileDevice::FileTimeType  type) const
virtual

If type is CreationTime, returns when the file was created. If type is ModificationTime, returns when the file was most recently modified. If type is AccessTime, returns when the file was most recently accessed.

If the time can not be determined this method returns an invalid QDateTime().

See also
setFileTime(), QDateTime::isValid(), QFileDevice::FileTimeType

Reimplemented in QFSFileEngine::fileTime()

bool QAbstractFileEngine::flush ( )
virtual

Flushes the current open file and returns true if successful, otherwise returns false. The default implementation always returns false.

Reimplemented in QFSFileEngine::flush()

int QAbstractFileEngine::handle ( ) const
virtual

Returns the native file handle for the current QAbstractFileEngine. This handle must be used carefully since the type and value are platform specific. Using this method can lead to non-portable code.

Reimplemented in QFSFileEngine::handle()

bool QAbstractFileEngine::isRelativePath ( ) const
virtual

Return true if the file for the current QAbstractFileEngine has a relative path, otherwise return false.

See also
setFileName()

Reimplemented in QFSFileEngine::isRelativePath()

bool QAbstractFileEngine::isSequential ( ) const
virtual

Returns true if the file is a sequential access device. Returns false if the file is a random access device. Operations involving size() and seek(int) are not valid on sequential devices.

Reimplemented in QFSFileEngine::isSequential()

bool QAbstractFileEngine::link ( const QString newName)
virtual

Creates a link from the file specified by fileName(), to the given newName. Returns true if successful, otherwise returns false.

The definition of a link depends on the underlying file system. On Unix it is a symbolic link. On Windows a link is a shortcut. To create a valid link on Windows the given newName must have a ".lnk" file extension.

Reimplemented in QFSFileEngine::link()

uchar * QAbstractFileEngine::map ( qint64  offset,
qint64  size,
QFile::MemoryMapFlags  flags 
)

Makes an operating system call which mirrors the contents of the current file in memory.

This method maps size bytes of the current file into memory starting at offset. Returns a pointer to the beginning of the mapped memory when successful, otherwise returns a nullptr.

Calls extension() with the enum value MapExtensionOption. If the QAbstractFileEngine does not support this extension a nullptr is returned. The value for flags is not used.

See also
supportsExtension(), unmap()
bool QAbstractFileEngine::mkdir ( const QString dirName,
bool  createParentDirectories 
) const
virtual

Creates a new directory with the specified dirName. If the operation succeeds return true, otherwise return false.

If createParentDirectories is true, then any parent directories in dirName which do not exist are also created. If createParentDirectories is false then any parent directories in dirName must already exist for this method to succeed.

See also
isRelativePath(), rmdir(), setFileName()

Reimplemented in QFSFileEngine::mkdir()

bool QAbstractFileEngine::open ( QIODevice::OpenMode  mode)
virtual

Opens the file in the specified mode. Returns true if the file was successfully opened, otherwise returns false. The mode is an OR combination of QIODevice::OpenMode and QIODevice::HandlingMode values.

Reimplemented in QFSFileEngine::open()

QString QAbstractFileEngine::owner ( FileOwner  owner) const
virtual

If owner is OwnerUser returns the name of the user who owns the file. If owner is OwnerGroup returns the name of the group who owns the file. If the owner can not be determined returns an empty QString().

See also
ownerId(), setFileName(), FileOwner

Reimplemented in QFSFileEngine::owner()

uint QAbstractFileEngine::ownerId ( FileOwner  owner) const
virtual

If owner is OwnerUser returns the ID of the user who owns the file. If owner is OwnerGroup returns the ID of the group which owns the file. If the owner can not be determined -2 is returned.

See also
owner(), setFileName(), FileOwner

Reimplemented in QFSFileEngine::ownerId()

qint64 QAbstractFileEngine::pos ( ) const
virtual

Returns the current file position. This is the position where data will be read/write.

Reimplemented in QFSFileEngine::pos()

qint64 QAbstractFileEngine::read ( char *  data,
qint64  maxlen 
)
virtual

Reads characters from the file into data. At most maxlen characters will be read. Returns -1 if a fatal error occurs or 0 if there are no bytes to read.

Reimplemented in QFSFileEngine::read()

qint64 QAbstractFileEngine::readLine ( char *  data,
qint64  maxlen 
)
virtual

This method reads one line which is terminated by a '\n' character into data. At most maxlen characters will be read. The end of line character is included.

Reimplemented in QFSFileEngine::readLine()

bool QAbstractFileEngine::remove ( )
virtual

Requests the file for the current QAbstractFileEngine should be deleted from the file system. If the operation succeeds return true, otherwise return false.

See also
rmdir(), setFileName()

Reimplemented in QFSFileEngine::remove()

bool QAbstractFileEngine::rename ( const QString newName)
virtual

Requests the file for the current QAbstractFileEngine should be renamed to newName. If the operation succeeds the method returns true, otherwise returns false.

See also
setFileName()

Reimplemented in QFSFileEngine::rename()

bool QAbstractFileEngine::renameOverwrite ( const QString newName)
virtual

Requests the file for the current QAbstractFileEngine should be renamed to newName. If the new name already exists it must be overwritten. If the operation succeeds the method returns true, otherwise returns false.

See also
setFileName()

Reimplemented in QFSFileEngine::renameOverwrite()

bool QAbstractFileEngine::rmdir ( const QString dirName,
bool  recurseParentDirectories 
) const
virtual

Requests the directory dirName is deleted from the file system. When recurseParentDirectories is true, any empty parent directories must also be deleted. If recurseParentDirectories is false, only the dirName directory should be deleted. In most file systems a directory can not be deleted using this method if it is not empty. If the operation succeeds return true, otherwise return false.

See also
isRelativePath(), mkdir(), remove(), setFileName()

Reimplemented in QFSFileEngine::rmdir()

bool QAbstractFileEngine::seek ( qint64  offset)
virtual

Sets the file position to the given offset. Returns true if the position was successfully set, otherwise returns false. The offset is from the beginning of the file unless the file is sequential.

See also
isSequential()

Reimplemented in QFSFileEngine::seek()

void QAbstractFileEngine::setError ( QFile::FileError  error,
const QString errorString 
)
protected

Sets the error type to error and the error string to errorString.

See also
QFile::error(), QIODevice::errorString(), QIODevice::setErrorString()
void QAbstractFileEngine::setFileName ( const QString file)
virtual

Sets the filename for the current QAbstractFileEngine to file.

See also
fileName(), rename()

Reimplemented in QFSFileEngine::setFileName()

bool QAbstractFileEngine::setFileTime ( const QDateTime newTime,
QFileDevice::FileTimeType  type 
)
virtual

Sets the file time to newTime based on the given type. Returns true if successful, otherwise returns false.

The file must be open to use this method.

See also
fileTime(), QFileDevice::FileTimeType

Reimplemented in QFSFileEngine::setFileTime()

bool QAbstractFileEngine::setPermissions ( uint  perms)
virtual

Set the file permission to perms. If the operation succeeds true is returned, otherwise false is returned.

See also
size()

Reimplemented in QFSFileEngine::setPermissions()

bool QAbstractFileEngine::setSize ( qint64  size)
virtual

Set the file to the given size. If size is larger than the current file the appended bytes are filled with zeros. If size is smaller, the file is truncated. If the operations succeeds returns true, otherwise returns false.

See also
size()

Reimplemented in QFSFileEngine::setSize()

qint64 QAbstractFileEngine::size ( ) const
virtual

Returns the size of the file for the current QAbstractFileEngine.

See also
setSize()

Reimplemented in QFSFileEngine::size()

bool QAbstractFileEngine::supportsExtension ( Extension  extension) const
virtual

This method returns true if the file engine supports extension, otherwise false is returned. By default no extensions are supported.

See also
extension()

Reimplemented in QFSFileEngine::supportsExtension()

bool QAbstractFileEngine::syncToDisk ( )
virtual

Flushes the contents of the file for the current QAbstractFileEngine to the file on disk. Returns true if successful, otherwise returns false.

Reimplemented in QFSFileEngine::syncToDisk()

bool QAbstractFileEngine::unmap ( uchar address)

Makes an operating system call which clears a memory mapping. The method map() must have been previously called.

This method undoes the mapping at the given address. Returns true if this succeeds, otherwise returns false.

Calls extension() with UnMapExtensionOption. If the engine does not support this extension false is returned.

See also
map(), supportsExtension()
qint64 QAbstractFileEngine::write ( const char *  data,
qint64  len 
)
virtual

Writes len number of bytes from data to the file for the current QAbstractFileEngine. If the write succeeds, the number of characters written is returned, otherwise returns -1.

Reimplemented in QFSFileEngine::write()