Remoto - VFS: rutils Namespace Reference
Remoto - VFS
rutils Namespace Reference

Utility functions for VFS operations. More...

Functions

QString cleanPath (QString path)
 Clean and normalize a VFS path. More...
 
QJsonObject decodeBase64Path (QByteArray p, bool *ok)
 Decode a base64 string as a JSON object. More...
 
QByteArray encodeBase64Path (QJsonObject p)
 Encode a JSON object as a base64 string. More...
 
QStringList exec (QString command, bool *ok=nullptr)
 execute a command in a shell, and return the resulting output as a QStringList More...
 
QStringList expandSequence (QString sequence)
 Expand a sequence-notated list into a list of numbers. More...
 
QStringList expandSequenceListing (QString sequence)
 Expand a sequence-notated string into a list of names. More...
 
QJsonObject jsonResource (QString resource, bool *ok=nullptr)
 Fetch the contents of a Qt resource as a QJsonObject. More...
 
QJsonValue parseSequenceSyntax (QString path)
 Check if a path or string matches our syntax for file sequences. More...
 
QByteArray resourceContents (QString resource, bool *ok=nullptr, bool squashHash=false)
 Fetch the contents of a Qt resource file. More...
 
QJsonObject sequenceListing (QJsonObject l, QStringList types=sequenceTypes)
 Given a list of filenames and a regex list, collapse the listing to sequences when possible. More...
 
QString unescapeXMLAttribute (QString attribute)
 Un-escape an XML attribute. More...
 

Variables

QStringList sequenceTypes = QStringList() << "jpe?g" << "tif?f" << "exr" << "png" << "dpx"
 A list of regular expressions which can represent image or file sequences. More...
 

Detailed Description

Utility functions for VFS operations.

Function Documentation

◆ cleanPath()

QString rutils::cleanPath ( QString  path)

Clean and normalize a VFS path.

Parameters
pathA VFS path to be cleaned and normalized
Returns
The cleaned path

Ostensibly, this removes leading and duplicate slashes from a path. When doing path manipulation, many times one is adding path parts together, and it can be unclear if one path part starts or ends with a slash, resulting in an unclean result.

Note that all paths are effectively resource IDs, which often must exactly match their use in other contexts.

It is recommended to use rutils::cleanPath() on all assembled paths, especially those being sent or received from a remote client.

Definition at line 32 of file rutils.cpp.

◆ decodeBase64Path()

QJsonObject rutils::decodeBase64Path ( QByteArray  p,
bool *  ok 
)

Decode a base64 string as a JSON object.

Parameters
pThe base 64 string to decode
okWhether or not decode was possible
Returns
The decoded JSON object.

Because Qt uses RFC 2045, we replace the '/' character with an '_', because we want to use the base64 encoded string as a path fragment.

Definition at line 613 of file rutils.cpp.

◆ encodeBase64Path()

QByteArray rutils::encodeBase64Path ( QJsonObject  p)

Encode a JSON object as a base64 string.

Parameters
pThe JSON object to encode
Returns
The base64-encoded string.

Because Qt uses RFC 2045, we replace the '/' character with an '_', because we want to use the base64 encoded string as a path fragment.

Definition at line 592 of file rutils.cpp.

◆ exec()

QStringList rutils::exec ( QString  command,
bool *  ok = nullptr 
)

execute a command in a shell, and return the resulting output as a QStringList

Parameters
commandThe command to execute
okA pointer to return execution status
Returns
The stdout of the executed command as a string list
Note
This has not been tested on Windows.

Definition at line 658 of file rutils.cpp.

◆ expandSequence()

QStringList rutils::expandSequence ( QString  sequence)

Expand a sequence-notated list into a list of numbers.

Parameters
sequenceThe sequence
Returns
The expanded list

Definition at line 407 of file rutils.cpp.

◆ expandSequenceListing()

QStringList rutils::expandSequenceListing ( QString  sequence)

Expand a sequence-notated string into a list of names.

Parameters
sequenceThe list of names
Returns
The expanded list

Definition at line 499 of file rutils.cpp.

◆ jsonResource()

QJsonObject rutils::jsonResource ( QString  resource,
bool *  ok = nullptr 
)

Fetch the contents of a Qt resource as a QJsonObject.

Parameters
resourceThe resource path, which must start with ':'
okThe status of the request and parse
Returns
The contents of the resource, or an empty QJsonObject if unsuccessful

Often, JSON files are stored in a resource file. This function will return parsed JSON data as a convenience for future manipulation or templatizing.

Definition at line 90 of file rutils.cpp.

◆ parseSequenceSyntax()

QJsonValue rutils::parseSequenceSyntax ( QString  p)

Check if a path or string matches our syntax for file sequences.

Parameters
pThe path or string to check
Returns
boolean match

Definition at line 132 of file rutils.cpp.

◆ resourceContents()

QByteArray rutils::resourceContents ( QString  resource,
bool *  ok = nullptr,
bool  squashHash = false 
)

Fetch the contents of a Qt resource file.

Parameters
resourceThe resource path, which must start with ':'
okThe status of the request
squashHashBoolean for replacing '#' with "%23"
Returns
The contents of the resource, or an empty string if unsuccessful

This is useful in plugins, for instance, where resources are stored in the plugin binary and a single line of code saves lots of time and error-checking.

If squashHash=true, '#' will be replaced with "%23". This provides inline data URIs that contain HTML colors (like SVG files) to be compatible with Firefox and other browsers that may interpret the hash as a fragment separator.

Definition at line 53 of file rutils.cpp.

◆ sequenceListing()

QJsonObject rutils::sequenceListing ( QJsonObject  l,
QStringList  types = sequenceTypes 
)

Given a list of filenames and a regex list, collapse the listing to sequences when possible.

Parameters
lThe name list
typesThe regex list
Returns
The collapsed list, as a QVariant, which will autmatically provide sorted keys.

Given a list of filenames:

file.0001.jpg
file.0002.jpg
file.0003.jpg
otherfile.ext
file3.00004.png
file3.00006.png
file3.00007.png
file3.00008.png
file3.00100.png

This function will collapse them into sequence notation:

file.[1-3#4].jpg
file3.[4,6-8,100#5].png
otherfile.ext

Definition at line 183 of file rutils.cpp.

◆ unescapeXMLAttribute()

QString rutils::unescapeXMLAttribute ( QString  attribute)

Un-escape an XML attribute.

Parameters
attributeThe attribute value to un-escape
Returns
The un-escaped attribute value

This is used when, for instance, when inline SVG is used as an attribute value in a config file.

Currently this will replace "&lt;" with "<" and "&gt;" with ">".

Definition at line 640 of file rutils.cpp.

Variable Documentation

◆ sequenceTypes

QStringList rutils::sequenceTypes = QStringList() << "jpe?g" << "tif?f" << "exr" << "png" << "dpx"
extern

A list of regular expressions which can represent image or file sequences.

When performing a rutils::sequenceListing(), these regex types can be used to identify images.

By default: jpg, jpeg, tif, tiff, exr, png, and dpx are recognized.

Definition at line 124 of file rutils.cpp.