TemplatedPathResolver Class Reference

Resolver for paths that contain placeholders. More...

#include <templatedpathresolver.h>

Public Member Functions

bool envVarsEnabled () const
 Control the $ env. variable resolution.
 
bool progdirEnabled () const
 Control the $PROGDIR resolution.
 
QString resolve (const QString &templatedPath) const
 Resolve a templated path.
 
QStringList resolve (const QStringList &templatedPaths) const
 Convenience method, calls resolve(QString) for each element.
 
void setEnvVarsEnabled (bool enabled)
 
void setProgdirEnabled (bool enabled)
 
void setUserHomeEnabled (bool enabled)
 
bool userHomeEnabled () const
 Control the resolution of both ~ and ~username.
 

Static Public Attributes

static const QString PROGDIR_TEMPLATE = "$PROGDIR"
 

Detailed Description

Resolver for paths that contain placeholders.

The transformation of each placeholder type can be toggled by appropriate setters.

The allowed placeholders are:

  • $PROGDIR (capitals important) resolves to the directory where the application's executable resides.
  • $ character followed by a letter or underscore followed optionally by a string of letters, digits or underscores is treated as an env. variable and a resolution using such variable is attempted. If there's no matching env. variable, the placeholder resolves to an empty string. Regex: $[a-zA-Z_][a-zA-Z0-9_]*.
  • ~ character at the beginning, followed by a directory delimiter or end of the string is replaced with current user's home directory. The ~someone pattern will resolve to the home directory of "someone" but only on a UNIX system. On MS Windows, the ~ pattern is resolved but ~someone is not.

While Windows platform quotes the env. variables with %, this resolver doesn't follow this pattern and uses the $ prefix universally for all platforms.

Definition at line 73 of file templatedpathresolver.h.

Member Function Documentation

bool TemplatedPathResolver::envVarsEnabled ( ) const

Control the $ env. variable resolution.

Default: false

Definition at line 151 of file templatedpathresolver.cpp.

bool TemplatedPathResolver::progdirEnabled ( ) const

Control the $PROGDIR resolution.

If this is disabled, but the env. variable resolution is enabled, $PROGDIR will be treated like a common env. variable!

Default: false

Definition at line 141 of file templatedpathresolver.cpp.

QString TemplatedPathResolver::resolve ( const QString &  templatedPath) const

Resolve a templated path.

Returns
Path with all placeholders resolved as best as possible. The returned path is not normalized.

Definition at line 61 of file templatedpathresolver.cpp.

QStringList TemplatedPathResolver::resolve ( const QStringList &  templatedPaths) const

Convenience method, calls resolve(QString) for each element.

Returns
List transformed by resolve(QString).

Definition at line 133 of file templatedpathresolver.cpp.

bool TemplatedPathResolver::userHomeEnabled ( ) const

Control the resolution of both ~ and ~username.

Default: true

Definition at line 161 of file templatedpathresolver.cpp.


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