2 #include <QDirIterator>
7 #include <QJsonDocument>
39 {
VFS::ERROR( QString(
"VFS_QRC nodes require a QT valid resource path. Invalid path: '%1'").arg(
_path) );
82 QFileInfoList list = dir.entryInfoList( QDir::AllEntries | QDir::Readable | QDir::NoDotAndDotDot );
87 for (
int i=0;i<list.length();i++)
90 o[info.fileName()] = info.isDir();
93 r->
_data = QJsonDocument(o);
100 if(file.open(QFile::ReadOnly))
103 QByteArray f = file.readAll();
108 d = QJsonDocument::fromJson(f,&e);
109 if (e.error != QJsonParseError::NoError)
117 o[
"data"] = QString(f);
132 r->
_reason =
"Unknown QRC error.";
147 VFS::ERROR(QString(
"VFS_QRC nodes are read-only. '%1' is unwritable.").arg(r->
_path));
182 VFS::ERROR(QString(
"VFS_QRC nodes are read-only. '%1' is unwritable.").arg(r->
_path));
196 VFS::ERROR(QString(
"VFS_QRC nodes are read-only. '%1' is not deletable.").arg(r->
_path));
215 r->
_reason = QString(
"Can't subscribe to non-existent resource: '%1'").arg(p);
248 QDirIterator::IteratorFlags f = QDirIterator::FollowSymlinks;
251 QDirIterator it(p,f);
257 if (m!=
"." && m!=
"..")
264 if (r->
_metadata.value(
"sequence").toBool(
false))
268 r->
_data.setObject(a);
virtual void submit(VFS_request *r)
Attempt to submit.
bool _raw
Whether to fetch data in JSON mode or RAW mode.
virtual void subscribe(VFS_request *r)
Subscribe to a path.
virtual void ls(VFS_request *r)
List the contents of a path in this resource.
virtual VFS_node * find(VFS_request *r)
virtual void write(VFS_request *r)
Attempt to write.
QString _path
The Qt resource path prefix. Must start with ":/".
virtual void metadata(VFS_request *r)
Retrieve the metadata for a path.
Q_INVOKABLE VFS_QRC(QString path, bool raw=false)
virtual void rm(VFS_request *r)
Attempt to rm.
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
virtual bool isContainer()
The VFS_QRC class is a read-only container.
static QString getType(QString _path, QString _default="unknownType")
Fetch the type of a file, based on path/filename.ext.
VFS_node is the base class from which all other VFS_node classes derive.
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
virtual void subscribe(VFS_request *r)
Add an entry to this node's _subscription list.
The base class for all requests between nodes.
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
QJsonObject _metadata
the request payload
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
getter path
a getter DOCME
QJsonObject sequenceListing(QJsonObject l, QStringList types=sequenceTypes)
Given a list of filenames and a regex list, collapse the listing to sequences when possible.