62 zDebug() <<
"ZFile::ZFile";
80 qmlRegisterType<ZFile>(
"org.zuble.qml", 1, 0,
"ZFile");
87 connect(
m_zd, SIGNAL(getCurrentDevice(QIODevice**)),
88 SLOT(
getQDevice(QIODevice**)), Qt::DirectConnection);
98 map.insert(
"permissionReadOwner",
ReadOwner);
99 map.insert(
"permissionWriteOwner",
WriteOwner);
100 map.insert(
"permissionExeOwner",
ExeOwner);
101 map.insert(
"permissionReadUser",
ReadUser);
102 map.insert(
"permissionWriteUser",
WriteUser);
103 map.insert(
"permissionExeUser",
ExeUser);
104 map.insert(
"permissionReadGroup",
ReadGroup);
105 map.insert(
"permissionWriteGroup",
WriteGroup);
106 map.insert(
"permissionExeGroup",
ExeGroup);
107 map.insert(
"permissionReadOther",
ReadOther);
108 map.insert(
"permissionWriteOther",
WriteOther);
109 map.insert(
"permissionExeOther",
ExeOther);
111 m_tags = QVariant::fromValue(map);
124 Z_FAC_JS, ZFile::getStatus, getStatus failed)
129 *device = qobject_cast<QIODevice*>(
m_f.data());
157 fileName =
m_f->fileName();
178 retValue =
m_f->open(QFile::OpenMode(openMode));
188 retValue =
m_f->copy(newName);
198 retValue =
m_f->rename(newName);
208 retValue =
m_f->remove();
218 retValue =
m_f->exists();
227 retValue = QFile::exists(fileName);
236 QFileInfo fi(QDir::cleanPath(filePath));
237 retValue = fi.absoluteFilePath();
246 QFileInfo fi(QDir::cleanPath(filePath));
247 retValue = fi.canonicalFilePath();
254 zDebug() <<
"::zReadDataLine";
257 QByteArray ba =
m_f->readLine(maxSize);
265 zDebug() <<
"::zReadData";
268 QByteArray ba =
m_f->read(maxSize);
276 zDebug() <<
"::zReadDataAll";
279 QByteArray ba =
m_f->readAll();
287 zDebug() <<
"::jReadDataLine";
295 zDebug() <<
"::jReadData";
304 zDebug() <<
"::jReadDataAll";
311 const int maxSize = 1024 * 16;
315 int previousSize = array.size();
316 array.append(
jGetData(maxSize,
false));
317 if((array.size() - previousSize < maxSize))
319 if(
m_f->error() != QFileDevice::NoError)
321 if(
m_f->error() != QFileDevice::NoError)
323 QString msg(
"File error attempting to read data: %1");
338 qint64 sizeReturned = 0;
340 char* data =
new char[maxSize];
347 sizeReturned =
m_f->readLine(data, maxSize);
349 sizeReturned =
m_f->read(data, maxSize);
351 if(sizeReturned == -1 )
353 QString msg(
"File error attempting to read data: %1");
356 else if(sizeReturned < maxSize)
358 if(
m_f->error() != QFileDevice::NoError)
360 QString msg(
"File error attempting to read data: %1");
364 for(
int i = 0; i < sizeReturned; i++)
365 array.append(static_cast<int>(data[i]));
380 zDebug() <<
"::zWriteData";
383 qint64 sizeWritten =
m_f->write(*data.
m_ba);
385 if((sizeWritten == -1)
386 || ((sizeWritten < data.m_ba->size())
387 && (
m_f->error() != QFileDevice::NoError)))
389 QString msg(
"File error attempting to write data: %1");
398 zDebug() <<
"::jWriteData";
401 const int size = data.size();
402 for(
int i = 0; i < size; i++)
404 if(!
m_f->putChar(static_cast<char>(data.at(i))))
406 QString msg(
"File error attempting to write data: %1");
416 zDebug() <<
"::zTextStream";
424 zDebug() <<
"::zDataStream";
This class supports streaming of text and binary data.
void getQDevice(QIODevice **device)
Q_INVOKABLE bool zWriteData(const ZByteArray &data)
Write the contents of a ZByteArray to the device.
void validateReadable() const
Ensures the embedded QFile object is readable by throwing an exception if not.
Q_INVOKABLE QObject * zTextStream()
Returns a Zbl::ZTextStream object that can be used to stream text to or from the device.
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...
Q_INVOKABLE bool open(int openMode)
Opens the device and sets its open mode to openMode. Returns true if successful; otherwise returns fa...
Q_INVOKABLE bool jWriteData(const QList< int > data)
Write the contents of a Javascript array of numbers to the device as bytes.
Q_INVOKABLE QObject * zReadDataAll()
Reads up to the end of data into a ZByteArray.
Q_INVOKABLE QString getCanonicalFilePath(const QString &filePath)
Returns the canonical file path for the given file path.
Q_INVOKABLE void close()
Closes the device and sets its OpenMode to NotOpen. The error string is also reset.
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...
QString fileName
The name of the file.
#define ZBL_REGISTER_LOGGED_OBJECT
static void registerType()
Registers ZFile as a QML type.
Q_INVOKABLE bool remove()
Removes the file. Returns true if successful; otherwise returns false.
QString getFileName() const
static QVariant m_tags
A QVariantMap used to pass QFile enumeration values to Javascript programs.
Q_INVOKABLE bool exists()
Determine if the file currently exists. Returns true if file exists; otherwise returns false...
QObject device
A ZioDevice object that represents the File's QioDevice interface.
Q_INVOKABLE void release()
Releases references from this object to wrapped Qt C++ objects.
A javascript wrapper for QFile.
Q_INVOKABLE bool copy(const QString &newName)
Copies this file to newName.
A javascript wrapper for QIODevice.
void setFileName(const QString &fileName)
void initFile(const QString &fileName)
Closes the current file if opened, then creates a new embedded QFile object with the specified file n...
void validateWritable() const
Ensures the embedded QFile object is writable by throwing an exception if not.
Q_INVOKABLE QObject * zReadData(int maxSize)
Reads up to maxSize bytes or up to end of data, whichever comes first, into a ZByteArray.
#define ZBL_SLOT_BEGIN_TRY
#define ZBL_DEFINE_LOGGED_OBJECT(class_name)
void createTags()
Create the m_tag object that presents a Javascript interface to QFile enumeration values...
#define ZBL_SLOT_END_VOID(facility, code, error_message)
static QString resolvePath(const QString &path, bool includeUrlScheme=true)
Converts relative file paths into canonical file paths. Paths prefixed with prefix are mapped relativ...
Q_INVOKABLE QString getAbsoluteFilePath(const QString &filePath)
Returns the absolute file path for the given file path.
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...
ZBL_DECLARE_LOGGED_OBJECT void initZioDevice()
Construct and connect a ZioDevice object that presents a Javascript interface to this file's QIODevic...
Zuble's Qt Exception Object.
ZqFilePtr m_f
Smart pointer to the embedded QFile object.
ZioDevice * m_zd
Pointer to QioDevice interface object.
Q_INVOKABLE QList< int > jReadDataAll()
Reads up to the end of data into a Javascript array.
void validateReadDataSuccess(const QByteArray &ba) const
Throws an exception if both the supplied QByteArray object is empty and an error condition exists on ...
void validateFile() const
Ensures the embedded QFile object has been initialized by throwing an exception if not...
Q_INVOKABLE bool rename(const QString &newName)
Renames this file to newName.
QList< int > jGetData(int maxSize, bool lineModeOn=false)
A common method for line and no-line mode data fetch operations into a Javascript array...
Q_INVOKABLE QObject * zDataStream()
Returns a Zbl::ZDataStream object that can be used to stream binary data to or from the device...
#define ZBL_SLOT_END_RETURN(return_success, return_failed, facility, code, error_message)