WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties | List of all members
Zbl::ZFile Class Reference

A javascript wrapper for QFile. More...

#include <ZFile.h>

Inheritance diagram for Zbl::ZFile:
Inheritance graph
[legend]
Collaboration diagram for Zbl::ZFile:
Collaboration graph
[legend]

Public Types

enum  Permission {
  ReadOwner = QFileDevice::ReadOwner, WriteOwner = QFileDevice::WriteOwner, ExeOwner = QFileDevice::ExeOwner, ReadUser = QFileDevice::ReadUser,
  WriteUser = QFileDevice::WriteUser, ExeUser = QFileDevice::ExeUser, ReadGroup = QFileDevice::ReadGroup, WriteGroup = QFileDevice::WriteGroup,
  ExeGroup = QFileDevice::ExeGroup, ReadOther = QFileDevice::ReadOther, WriteOther = QFileDevice::WriteOther, ExeOther = QFileDevice::ExeOther
}
 

Public Slots

void getQDevice (QIODevice **device)
 

Signals

void tagsChanged ()
 

Public Member Functions

 ZFile (QObject *parent=0)
 
virtual ~ZFile ()
 
QString getFileName () const
 
void setFileName (const QString &fileName)
 
QObject * getJsDevice ()
 
QVariant getTags ()
 
Q_INVOKABLE void release ()
 Releases references from this object to wrapped Qt C++ objects. More...
 
Q_INVOKABLE void close ()
 Closes the device and sets its OpenMode to NotOpen. The error string is also reset. More...
 
Q_INVOKABLE bool open (int openMode)
 Opens the device and sets its open mode to openMode. Returns true if successful; otherwise returns false. More...
 
Q_INVOKABLE bool copy (const QString &newName)
 Copies this file to newName. More...
 
Q_INVOKABLE bool rename (const QString &newName)
 Renames this file to newName. More...
 
Q_INVOKABLE bool remove ()
 Removes the file. Returns true if successful; otherwise returns false. More...
 
Q_INVOKABLE bool exists ()
 Determine if the file currently exists. Returns true if file exists; otherwise returns false. More...
 
Q_INVOKABLE bool exists (const QString &fileName)
 Determine if the specified file currently exists. More...
 
Q_INVOKABLE QString getAbsoluteFilePath (const QString &filePath)
 Returns the absolute file path for the given file path. More...
 
Q_INVOKABLE QString getCanonicalFilePath (const QString &filePath)
 Returns the canonical file path for the given file path. More...
 
Q_INVOKABLE QObject * zReadData (int maxSize)
 Reads up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray. More...
 
Q_INVOKABLE QObject * zReadDataLine (int maxSize)
 Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray. More...
 
Q_INVOKABLE QObject * zReadDataAll ()
 Reads up to the end of data into a ZByteArray. More...
 
Q_INVOKABLE QList< int > jReadData (int maxSize)
 Reads up to maxSize bytes or up to end of data, whichever comes first, into a Javascript array. More...
 
Q_INVOKABLE QList< int > jReadDataLine (int maxSize)
 Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first, into a Javascript array. More...
 
Q_INVOKABLE QList< int > jReadDataAll ()
 Reads up to the end of data into a Javascript array. More...
 
Q_INVOKABLE bool zWriteData (const ZByteArray &data)
 Write the contents of a ZByteArray to the device. More...
 
Q_INVOKABLE bool jWriteData (const QList< int > data)
 Write the contents of a Javascript array of numbers to the device as bytes. More...
 
Q_INVOKABLE QObject * zTextStream ()
 Returns a Zbl::ZTextStream object that can be used to stream text to or from the device. More...
 
Q_INVOKABLE QObject * zDataStream ()
 Returns a Zbl::ZDataStream object that can be used to stream binary data to or from the device. More...
 

Static Public Member Functions

static void registerType ()
 Registers ZFile as a QML type. More...
 

Protected Member Functions

ZBL_DECLARE_LOGGED_OBJECT void initZioDevice ()
 Construct and connect a ZioDevice object that presents a Javascript interface to this file's QIODevice object. More...
 
void createTags ()
 Create the m_tag object that presents a Javascript interface to QFile enumeration values. More...
 
QList< int > jGetData (int maxSize, bool lineModeOn=false)
 A common method for line and no-line mode data fetch operations into a Javascript array. More...
 
void initFile (const QString &fileName)
 Closes the current file if opened, then creates a new embedded QFile object with the specified file name. More...
 
void validateFile () const
 Ensures the embedded QFile object has been initialized by throwing an exception if not. More...
 
void validateReadable () const
 Ensures the embedded QFile object is readable by throwing an exception if not. More...
 
void validateWritable () const
 Ensures the embedded QFile object is writable by throwing an exception if not. More...
 
void validateReadDataSuccess (const QByteArray &ba) const
 Throws an exception if both the supplied QByteArray object is empty and an error condition exists on the embedded QFile object, or if the embedded QFile object is not initialized. More...
 

Protected Attributes

ZqFilePtr m_f
 Smart pointer to the embedded QFile object. More...
 
ZioDevicem_zd
 Pointer to QioDevice interface object. More...
 

Static Protected Attributes

static QVariant m_tags
 A QVariantMap used to pass QFile enumeration values to Javascript programs. More...
 

Properties

QString fileName
 The name of the file. More...
 
QObject device
 A ZioDevice object that represents the File's QioDevice interface. More...
 
QVariant tags
 A Javascript object containing QFile enumeration values. More...
 

Detailed Description

A javascript wrapper for QFile.

You must set the fileName property before using this object unless otherwise noted in the method or property description.

Definition at line 53 of file ZFile.h.

Member Enumeration Documentation

◆ Permission

Enumerator
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 

Definition at line 64 of file ZFile.h.

Constructor & Destructor Documentation

◆ ZFile()

Zbl::ZFile::ZFile ( QObject *  parent = 0)
explicit

Definition at line 59 of file ZFile.cpp.

◆ ~ZFile()

Zbl::ZFile::~ZFile ( )
virtual

Definition at line 69 of file ZFile.cpp.

Member Function Documentation

◆ close()

void Zbl::ZFile::close ( )

Closes the device and sets its OpenMode to NotOpen. The error string is also reset.

Definition at line 139 of file ZFile.cpp.

Referenced by initFile(), setFileName(), and ~ZFile().

◆ copy()

bool Zbl::ZFile::copy ( const QString &  newName)

Copies this file to newName.

Returns
true if successful, false if failed

Definition at line 183 of file ZFile.cpp.

◆ createTags()

void Zbl::ZFile::createTags ( )
protected

Create the m_tag object that presents a Javascript interface to QFile enumeration values.

Definition at line 91 of file ZFile.cpp.

◆ exists() [1/2]

bool Zbl::ZFile::exists ( )

Determine if the file currently exists. Returns true if file exists; otherwise returns false.

Definition at line 213 of file ZFile.cpp.

Referenced by exists().

◆ exists() [2/2]

bool Zbl::ZFile::exists ( const QString &  fileName)

Determine if the specified file currently exists.

You are not required to set the fileName property before using this method.

Returns
true if file exists; otherwise returns false.

Definition at line 223 of file ZFile.cpp.

◆ getAbsoluteFilePath()

QString Zbl::ZFile::getAbsoluteFilePath ( const QString &  filePath)

Returns the absolute file path for the given file path.

You are not required to set the fileName property before using this method.

Definition at line 232 of file ZFile.cpp.

◆ getCanonicalFilePath()

QString Zbl::ZFile::getCanonicalFilePath ( const QString &  filePath)

Returns the canonical file path for the given file path.

You are not required to set the fileName property before using this method.

Definition at line 242 of file ZFile.cpp.

◆ getFileName()

QString Zbl::ZFile::getFileName ( ) const

Definition at line 151 of file ZFile.cpp.

◆ getJsDevice()

QObject * Zbl::ZFile::getJsDevice ( )

Definition at line 120 of file ZFile.cpp.

◆ getQDevice

void Zbl::ZFile::getQDevice ( QIODevice **  device)
slot

Definition at line 127 of file ZFile.cpp.

Referenced by initZioDevice().

◆ getTags()

QVariant Zbl::ZFile::getTags ( )

Definition at line 114 of file ZFile.cpp.

◆ initFile()

void Zbl::ZFile::initFile ( const QString &  fileName)
inlineprotected

Closes the current file if opened, then creates a new embedded QFile object with the specified file name.

Parameters
fileNameThe file name to set for the new embedded QFile object.

Definition at line 364 of file ZFile.h.

Referenced by setFileName().

◆ initZioDevice()

void Zbl::ZFile::initZioDevice ( )
protected

Construct and connect a ZioDevice object that presents a Javascript interface to this file's QIODevice object.

Definition at line 83 of file ZFile.cpp.

◆ jGetData()

QList< int > Zbl::ZFile::jGetData ( int  maxSize,
bool  lineModeOn = false 
)
protected

A common method for line and no-line mode data fetch operations into a Javascript array.

Parameters
maxSizeThe largest number of bytes to read
lineModeOntrue stops reading if a new line is encountered before maxBytes number of bytes have been read. false continues reading until maxBytes number of bytes or the end of data is encountered. Default is false.
Returns
A Javascript array containing the data that was read

Definition at line 334 of file ZFile.cpp.

Referenced by jReadData(), jReadDataAll(), and jReadDataLine().

◆ jReadData()

QList< int > Zbl::ZFile::jReadData ( int  maxSize)

Reads up to maxSize bytes or up to end of data, whichever comes first, into a Javascript array.

Returns
A Javascript array containing the data that was read

Definition at line 293 of file ZFile.cpp.

◆ jReadDataAll()

QList< int > Zbl::ZFile::jReadDataAll ( )

Reads up to the end of data into a Javascript array.

Returns
A Javascript array containing the data that was read

Definition at line 302 of file ZFile.cpp.

◆ jReadDataLine()

QList< int > Zbl::ZFile::jReadDataLine ( int  maxSize)

Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first, into a Javascript array.

Returns
A Javascript array containing the data that was read

Definition at line 285 of file ZFile.cpp.

◆ jWriteData()

bool Zbl::ZFile::jWriteData ( const QList< int >  data)

Write the contents of a Javascript array of numbers to the device as bytes.

Only the low order byte of each number is written out to the device.

Returns
true if successful, false if an error occurs

Definition at line 396 of file ZFile.cpp.

◆ open()

bool Zbl::ZFile::open ( int  openMode)

Opens the device and sets its open mode to openMode. Returns true if successful; otherwise returns false.

Definition at line 173 of file ZFile.cpp.

Referenced by Zbl::ZTableFile::validateWatcher().

◆ registerType()

void Zbl::ZFile::registerType ( )
static

Registers ZFile as a QML type.

Definition at line 76 of file ZFile.cpp.

Referenced by Zbl::Zblcore::registerTypes().

◆ release()

void Zbl::ZFile::release ( )

Releases references from this object to wrapped Qt C++ objects.

The C++ objects may be deleted by this function if no other Javascript objects reference them at the time this method is called.

WARNING: The ZFile object can't be used again once this function is called.

Definition at line 132 of file ZFile.cpp.

◆ remove()

bool Zbl::ZFile::remove ( )

Removes the file. Returns true if successful; otherwise returns false.

Definition at line 203 of file ZFile.cpp.

◆ rename()

bool Zbl::ZFile::rename ( const QString &  newName)

Renames this file to newName.

Returns
true if successful, false if failed

Definition at line 193 of file ZFile.cpp.

◆ setFileName()

void Zbl::ZFile::setFileName ( const QString &  fileName)

Definition at line 164 of file ZFile.cpp.

◆ tagsChanged

void Zbl::ZFile::tagsChanged ( )
signal

◆ validateFile()

void Zbl::ZFile::validateFile ( ) const
inlineprotected

Ensures the embedded QFile object has been initialized by throwing an exception if not.

Definition at line 373 of file ZFile.h.

Referenced by copy(), exists(), open(), remove(), rename(), validateReadable(), validateReadDataSuccess(), and validateWritable().

◆ validateReadable()

void Zbl::ZFile::validateReadable ( ) const
inlineprotected

Ensures the embedded QFile object is readable by throwing an exception if not.

Definition at line 383 of file ZFile.h.

Referenced by jGetData(), jReadDataAll(), zReadData(), zReadDataAll(), and zReadDataLine().

◆ validateReadDataSuccess()

void Zbl::ZFile::validateReadDataSuccess ( const QByteArray &  ba) const
inlineprotected

Throws an exception if both the supplied QByteArray object is empty and an error condition exists on the embedded QFile object, or if the embedded QFile object is not initialized.

Parameters
baThe byte array to check for empty

Definition at line 401 of file ZFile.h.

Referenced by zReadData(), zReadDataAll(), and zReadDataLine().

◆ validateWritable()

void Zbl::ZFile::validateWritable ( ) const
inlineprotected

Ensures the embedded QFile object is writable by throwing an exception if not.

Definition at line 392 of file ZFile.h.

Referenced by jWriteData(), and zWriteData().

◆ zDataStream()

QObject * Zbl::ZFile::zDataStream ( )

Returns a Zbl::ZDataStream object that can be used to stream binary data to or from the device.

Definition at line 422 of file ZFile.cpp.

◆ zReadData()

QObject * Zbl::ZFile::zReadData ( int  maxSize)

Reads up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray.

Returns
ZByteArray containing the data that was read

Definition at line 263 of file ZFile.cpp.

◆ zReadDataAll()

QObject * Zbl::ZFile::zReadDataAll ( )

Reads up to the end of data into a ZByteArray.

Returns
A ZByteArray containing the data that was read

Definition at line 274 of file ZFile.cpp.

◆ zReadDataLine()

QObject * Zbl::ZFile::zReadDataLine ( int  maxSize)

Reads up to the next new line or up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray.

Returns
A ZByteArray containing the data that was read

Definition at line 252 of file ZFile.cpp.

◆ zTextStream()

QObject * Zbl::ZFile::zTextStream ( )

Returns a Zbl::ZTextStream object that can be used to stream text to or from the device.

Definition at line 414 of file ZFile.cpp.

◆ zWriteData()

bool Zbl::ZFile::zWriteData ( const ZByteArray data)

Write the contents of a ZByteArray to the device.

Returns
true if successful, false if an error occurs

Definition at line 378 of file ZFile.cpp.

Member Data Documentation

◆ m_f

ZqFilePtr Zbl::ZFile::m_f
protected

◆ m_tags

QVariant Zbl::ZFile::m_tags
staticprotected

A QVariantMap used to pass QFile enumeration values to Javascript programs.

Definition at line 359 of file ZFile.h.

Referenced by createTags(), and getTags().

◆ m_zd

ZioDevice* Zbl::ZFile::m_zd
protected

Pointer to QioDevice interface object.

Definition at line 352 of file ZFile.h.

Referenced by getJsDevice(), and initZioDevice().

Property Documentation

◆ device

QObject Zbl::ZFile::device
read

A ZioDevice object that represents the File's QioDevice interface.

Definition at line 107 of file ZFile.h.

◆ fileName

QString Zbl::ZFile::fileName
readwrite

The name of the file.

The name can have no path, a relative path, or an absolute path. Do not assign a file name if the file has already been opened.

If the file name has no path or a relative path, the path used will be the application's current directory path at the time of the open() call.

Definition at line 100 of file ZFile.h.

Referenced by getFileName().

◆ tags

QVariant Zbl::ZFile::tags
read

A Javascript object containing QFile enumeration values.

Definition at line 113 of file ZFile.h.


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