QtlMovie 1.12 (A specialized FFmpeg front-end)
QtlFile Class Reference

Base class of a file description. More...

Inheritance diagram for QtlFile:
QtlMovieExecFile QtlMovieInputFile QtlMovieOutputFile

Signals

void fileNameChanged (const QString &fileName)
 Emitted when the file name has changed. More...
 

Public Member Functions

 QtlFile (const QString &fileName, QObject *parent=0)
 Constructor. More...
 
 QtlFile (const QtlFile &other, QObject *parent=0)
 Copy constructor. More...
 
QString directoryName () const
 Get the directory name of the file. More...
 
QString fileName () const
 Get the file name. More...
 
bool isSet () const
 Check if the file name is set. More...
 
QtlByteBlock readBinary (int maxSize=-1) const
 Read the binary content of the file. More...
 
QString readText () const
 Read the text content of the file. More...
 
QStringList readTextLines (int maxSize=-1) const
 Read the text content of the file. More...
 
virtual bool setFileName (const QString &fileName)
 Set the file name. More...
 
QString shortPath (bool keepOnError) const
 Get the "short path name" of the file. More...
 
bool writeBinary (const QtlByteBlock &content)
 Write the binary content of the file. More...
 
bool writeText (const QString &text)
 Write the text content of the file. More...
 
bool writeTextLines (const QStringList &lines)
 Write the text content of the file. More...
 

Static Public Member Functions

static QString absoluteNativeFilePath (const QString &path, bool removeSymLinks=false)
 Build an absolute file path with native directory separators. More...
 
static QStringList commandSearchPath ()
 Return the list of directories in the system search path. More...
 
static bool createDirectory (const QString &path, bool createOnly=false)
 Create a directory and all parent directories if necessary. More...
 
static QString enforceSuffix (const QString &path, const QString &suffix, Qt::CaseSensitivity cs=Qt::CaseInsensitive)
 Enforce a suffix in a file name. More...
 
static QStringList expandFilePath (const QString &path, QtlFilePathFilterInterface *filter=0)
 Expand a file path containing wildcards to all existing files matching the specification. More...
 
static QString parentPath (const QString &path, int upLevels=1)
 Get the absolute file path of the parent directory of a file. More...
 
template<typename T >
static bool readBigEndianAt (QIODevice &device, qint64 position, T &data)
 Read a big endian integer in a binary file at a given position. More...
 
static bool readBinary (QIODevice &device, QtlByteBlock &data, int maxSize=-1)
 Read a portion of a binary file at the current position. More...
 
static bool readBinaryAt (QIODevice &device, qint64 position, QtlByteBlock &data, int maxSize=-1)
 Read a portion of a binary file at a given position. More...
 
static QtlByteBlock readBinaryFile (const QString &fileName, int maxSize=-1)
 Read the content of a binary file. More...
 
static QString readTextFile (const QString &fileName)
 Read the content of a text file. More...
 
static QStringList readTextLinesFile (const QString &fileName, int maxSize=-1)
 Read the content of a text file. More...
 
static QString search (const QString &baseName, const QStringList &searchPath, const QString &extension=QString(), QFile::Permissions permissions=QFile::Permissions())
 Search a file in a list of directories. More...
 
static QString searchExecutable (const QString &baseName, const QStringList &searchPath)
 Search an executable file in a list of directories. More...
 
static QString searchParentSubdirectory (const QString &dir, const QString &subdir, int maxLevels=128)
 Search a subdirectory in the parent path. More...
 
static QString shortPath (const QString &path, bool keepOnError)
 Get the "short path name" of a file path. More...
 
static QString toFileName (const QUrl &url)
 Format the content of an URL into a file path if the URL scheme is file: More...
 
static bool writeBinary (QIODevice &file, const QtlByteBlock &data)
 Write binary data into an open file. More...
 
static bool writeBinary (QIODevice &file, const void *data, int size, bool processEvents=false)
 Write binary data into an open file. More...
 
static bool writeBinaryFile (const QString &fileName, const QtlByteBlock &content)
 Write the content of a binary file. More...
 
static bool writeTextFile (const QString &fileName, const QString &text)
 Write the content of a text file. More...
 
static bool writeTextLinesFile (const QString &fileName, const QStringList &lines)
 Write the content of a text file. More...
 

Private Member Functions

 QtlFile () Q_DECL_EQ_DELETE
 

Private Attributes

QString _fileName
 File name. More...
 

Detailed Description

Base class of a file description.

Constructor & Destructor Documentation

◆ QtlFile() [1/3]

QtlFile::QtlFile ( const QString &  fileName,
QObject *  parent = 0 
)
explicit

Constructor.

Parameters
[in]fileNameFile name.
[in]parentOptional parent widget.

◆ QtlFile() [2/3]

QtlFile::QtlFile ( const QtlFile other,
QObject *  parent = 0 
)
explicit

Copy constructor.

Parameters
[in]otherOther instance to copy (except parent).
[in]parentOptional parent widget.

◆ QtlFile() [3/3]

QtlFile::QtlFile ( )
private

Member Function Documentation

◆ fileName()

QString QtlFile::fileName ( ) const
inline

Get the file name.

Returns
Absolute file path.

◆ directoryName()

QString QtlFile::directoryName ( ) const

Get the directory name of the file.

Returns
The directory name of the file.

◆ isSet()

bool QtlFile::isSet ( ) const
inline

Check if the file name is set.

Returns
True if the file is set, false otherwise.

◆ setFileName()

bool QtlFile::setFileName ( const QString &  fileName)
virtual

Set the file name.

Parameters
[in]fileNameFile path.
Returns
True if the file name was modified, false if it was the same file name.

Reimplemented in QtlMovieExecFile.

◆ absoluteNativeFilePath()

QString QtlFile::absoluteNativeFilePath ( const QString &  path,
bool  removeSymLinks = false 
)
static

Build an absolute file path with native directory separators.

Parameters
[in]pathThe file path to transform.
[in]removeSymLinksIf true, remove symbolic links.
Returns
Resulting absolute path.

◆ commandSearchPath()

QStringList QtlFile::commandSearchPath ( )
static

Return the list of directories in the system search path.

Returns
Directories in the system search path.

◆ search()

QString QtlFile::search ( const QString &  baseName,
const QStringList &  searchPath,
const QString &  extension = QString(),
QFile::Permissions  permissions = QFile::Permissions() 
)
static

Search a file in a list of directories.

Parameters
[in]baseNameBase file name. If baseName contains a directory specification, it is not searched into the list of directories.
[in]searchPathList of directories to search.
[in]extensionIf baseName does not end with extension, the file is searched with this extension.
[in]permissionsKeep only files having these permissions.
Returns
File path of first file in the search list. Empty if not found.

◆ searchExecutable()

static QString QtlFile::searchExecutable ( const QString &  baseName,
const QStringList &  searchPath 
)
inlinestatic

Search an executable file in a list of directories.

Parameters
[in]baseNameBase file name. If baseName contains a directory specification, it is not searched into the list of directories. Do not add platform-specific extension such as ".exe".
[in]searchPathList of directories to search.
Returns
File path of first file in the search list. Empty if not found.

◆ expandFilePath()

QStringList QtlFile::expandFilePath ( const QString &  path,
QtlFilePathFilterInterface filter = 0 
)
static

Expand a file path containing wildcards to all existing files matching the specification.

The standard Unix wildcards '*' and '?' are recognized. Additionally, the non-standard wildcard "**", when used as a directory component, means all subdirectories.

Parameters
[in]pathThe path containing wildcards.
[in]filterOptional filter. If null, all files are matched.
Returns
An list of all existing files matching path.

◆ parentPath()

QString QtlFile::parentPath ( const QString &  path,
int  upLevels = 1 
)
static

Get the absolute file path of the parent directory of a file.

Parameters
[in]pathThe path of the file.
[in]upLevelsThe number of parent levels to climb. Default to 1.
Returns
The parent path.

◆ createDirectory()

bool QtlFile::createDirectory ( const QString &  path,
bool  createOnly = false 
)
static

Create a directory and all parent directories if necessary.

Parameters
[in]pathDirectory path to create.
[in]createOnlyIf true, the directory must be created, meaning that the operation fails if the directory already exists.
Returns
True on success, false on error.

◆ searchParentSubdirectory()

QString QtlFile::searchParentSubdirectory ( const QString &  dir,
const QString &  subdir,
int  maxLevels = 128 
)
static

Search a subdirectory in the parent path.

First the subdirectory subdir is searched in the directory dir. If not found, it is searched in the parent of dir and then in its upper level, etc., until subdir is found or the root directory is reached.

Parameters
[in]dirStart searching at dir.
[in]subdirName of the subdirectory to search.
[in]maxLevelsMaximum number of levels to search.
Returns
Full path of the first subdirectory found or an empty string if none is found.

◆ shortPath() [1/2]

QString QtlFile::shortPath ( const QString &  path,
bool  keepOnError 
)
static

Get the "short path name" of a file path.

On Windows platforms, return the path name in DOS 8.3 convention. On other platforms, return the input path.

Parameters
[in]pathThe path of the file or directory. If the file or directory does not exist, the result is unpredictable.
[in]keepOnErrorIf true and the conversion fails, return the same path.
Returns
The equivalent short path name or the empty string on error and keepOnError is false.

◆ shortPath() [2/2]

QString QtlFile::shortPath ( bool  keepOnError) const
inline

Get the "short path name" of the file.

On Windows platforms, return the path name in DOS 8.3 convention. On other platforms, return the input path.

Parameters
[in]keepOnErrorIf true and the conversion fails, return the same as fileName().
Returns
The equivalent short path name or the empty string on error and keepOnError is false.

◆ enforceSuffix()

QString QtlFile::enforceSuffix ( const QString &  path,
const QString &  suffix,
Qt::CaseSensitivity  cs = Qt::CaseInsensitive 
)
static

Enforce a suffix in a file name.

If path does not end with suffix, it is added.

Parameters
[in]pathA file path.
[in]suffixThe suffix to check or add.
[in]csIndicates if the file names are case sensitive.
Returns
A file path ending with suffix.

◆ toFileName()

QString QtlFile::toFileName ( const QUrl &  url)
static

Format the content of an URL into a file path if the URL scheme is file:

Parameters
[in]urlThe URL.
Returns
A file path if the URL scheme is file:, the URL string otherwise.

◆ writeBinaryFile()

bool QtlFile::writeBinaryFile ( const QString &  fileName,
const QtlByteBlock content 
)
static

Write the content of a binary file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to write.
[in]contentContent of the file to write.
Returns
True on success, false on error.

◆ writeBinary() [1/3]

static bool QtlFile::writeBinary ( QIODevice &  file,
const QtlByteBlock data 
)
inlinestatic

Write binary data into an open file.

Loop on write operations until all data are written or an error occured. Error reporting is minimal.

Parameters
[in]fileAn open file.
[in]dataBinary data to write.
Returns
True on success, false on error.

◆ writeBinary() [2/3]

bool QtlFile::writeBinary ( QIODevice &  file,
const void *  data,
int  size,
bool  processEvents = false 
)
static

Write binary data into an open file.

Loop on write operations until all data are written or an error occured. Error reporting is minimal.

Parameters
[in]fileAn open file.
[in]dataAddress of binary data to write.
[in]sizeSize in bytes of binary data to write.
[in]processEventsIf true, process all pending events before each write operation.
Returns
True on success, false on error.

◆ writeBinary() [3/3]

bool QtlFile::writeBinary ( const QtlByteBlock content)
inline

Write the binary content of the file.

Error reporting is minimal.

Parameters
[in]contentContent of the file to write.
Returns
True on success, false on error.

◆ readBinaryFile()

QtlByteBlock QtlFile::readBinaryFile ( const QString &  fileName,
int  maxSize = -1 
)
static

Read the content of a binary file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to read.
[in]maxSizeMaximum size to read. If the file is larger than maxSize, skip the rest of the file. If negative, read the entire file.
Returns
A byte array containing the file or an empty array on error. It is not possible to differentiate an empty file and an error.

◆ readBinary() [1/2]

QtlByteBlock QtlFile::readBinary ( int  maxSize = -1) const
inline

Read the binary content of the file.

Error reporting is minimal.

Parameters
[in]maxSizeMaximum size to read. If the file is larger than maxSize, skip the rest of the file. If negative, read the entire file.
Returns
A byte array containing the file or an empty array on error. It is not possible to differentiate an empty file and an error.

◆ readTextLinesFile()

QStringList QtlFile::readTextLinesFile ( const QString &  fileName,
int  maxSize = -1 
)
static

Read the content of a text file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to read.
[in]maxSizeMaximum number of characters to return. If the file is larger than maxSize, skip the rest of the file. If negative, read the entire file.
Returns
A list of strings containing the text lines of the file or an empty list on error. It is not possible to differentiate an empty file and an error.

◆ readTextLines()

QStringList QtlFile::readTextLines ( int  maxSize = -1) const
inline

Read the text content of the file.

Error reporting is minimal.

Parameters
[in]maxSizeMaximum number of characters to return. If the file is larger than maxSize, skip the rest of the file (do not truncate the last line, so the actual number of returned characters may be larger). If negative, read the entire file.
Returns
A list of strings containing the text lines of the file or an empty list on error. It is not possible to differentiate an empty file and an error.

◆ readTextFile()

QString QtlFile::readTextFile ( const QString &  fileName)
static

Read the content of a text file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to read.
Returns
The text content of the file or an empty string on error. It is not possible to differentiate an empty file and an error.

◆ readText()

QString QtlFile::readText ( ) const
inline

Read the text content of the file.

Error reporting is minimal.

Returns
The text content of the file or an empty string on error. It is not possible to differentiate an empty file and an error.

◆ writeTextLinesFile()

bool QtlFile::writeTextLinesFile ( const QString &  fileName,
const QStringList &  lines 
)
static

Write the content of a text file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to write.
[in]linesA list of strings containing the text lines of the file.
Returns
True on success, false on error.

◆ writeTextLines()

bool QtlFile::writeTextLines ( const QStringList &  lines)
inline

Write the text content of the file.

Error reporting is minimal.

Parameters
[in]linesA list of strings containing the text lines of the file.
Returns
True on success, false on error.

◆ writeTextFile()

bool QtlFile::writeTextFile ( const QString &  fileName,
const QString &  text 
)
static

Write the content of a text file.

Error reporting is minimal.

Parameters
[in]fileNameName of file to write.
[in]textThe text content of the file.
Returns
True on success, false on error.

◆ writeText()

bool QtlFile::writeText ( const QString &  text)
inline

Write the text content of the file.

Error reporting is minimal.

Parameters
[in]textThe text content of the file.
Returns
True on success, false on error.

◆ readBinary() [2/2]

bool QtlFile::readBinary ( QIODevice &  device,
QtlByteBlock data,
int  maxSize = -1 
)
static

Read a portion of a binary file at the current position.

Parameters
[in,out]deviceI/O device to read.
[out]dataReturned byte array containing the read data.
[in]maxSizeMaximum size to read. If the file is larger than maxSize, skip the rest of the file. If negative, read the entire file.
Returns
True on success, false on error.

◆ readBinaryAt()

static bool QtlFile::readBinaryAt ( QIODevice &  device,
qint64  position,
QtlByteBlock data,
int  maxSize = -1 
)
inlinestatic

Read a portion of a binary file at a given position.

Parameters
[in,out]deviceI/O device to read.
[in]positionPosition to seek in the device before reading.
[out]dataReturned byte array containing the read data.
[in]maxSizeMaximum size to read. If the file is larger than maxSize, skip the rest of the file. If negative, read the entire file.
Returns
True on success, false on error.

◆ readBigEndianAt()

template<typename T >
static bool QtlFile::readBigEndianAt ( QIODevice &  device,
qint64  position,
T &  data 
)
inlinestatic

Read a big endian integer in a binary file at a given position.

Template Parameters
TInteger type.
Parameters
[in,out]deviceI/O device to read.
[in]positionPosition to seek in the device before reading.
[out]dataRead data.
Returns
True on success, false on error.

◆ fileNameChanged

void QtlFile::fileNameChanged ( const QString &  fileName)
signal

Emitted when the file name has changed.

Parameters
[in]fileNameAbsolute file path.

Member Data Documentation

◆ _fileName

QString QtlFile::_fileName
private

File name.


The documentation for this class was generated from the following files: