ResourceFinder Class Reference

#include <ResourceFinder.h>

Public Member Functions

 ResourceFinder ()
 
virtual ~ResourceFinder ()
 
QString getResourcePath (QString resourceCat, QString fileName)
 Return the location (as a true file path, or a Qt4 ":"-prefixed resource path) of the file best matching the given resource filename in the given resource category. More...
 
QStringList getResourceFiles (QString resourceCat, QString fileExt)
 Return a list of full file paths for files with the given file extension, found in the given resource category. More...
 
QString getResourceDir (QString resourceCat)
 Return the true file path for installed resource files in the given resource category. More...
 
QString getResourceSavePath (QString resourceCat, QString fileName)
 Return the true file path for the location in which the named resource file in the given resource category should be saved. More...
 
QString getResourceSaveDir (QString resourceCat)
 Return the true file path for the location in which resource files in the given resource category should be saved. More...
 
bool unbundleResource (QString resourceCat, QString fileName)
 If the named resource file in the given resource category is available only as a bundled resource, copy it out into the user location returned by getResourceSavePath so that it can be read by non-Qt code. More...
 
QString getUserResourcePrefix ()
 Return the root path for user-specific resource installation for this application (i.e. More...
 
QStringList getSystemResourcePrefixList ()
 Return the root paths for systemwide resource installations for this application. More...
 
QStringList getResourcePrefixList ()
 Return all root paths for resource installations for this application, in the order in which they will be searched. More...
 

Detailed Description

Definition at line 29 of file ResourceFinder.h.

Constructor & Destructor Documentation

ResourceFinder::ResourceFinder ( )
inline

Definition at line 32 of file ResourceFinder.h.

Member Function Documentation

QString ResourceFinder::getResourcePath ( QString  resourceCat,
QString  fileName 
)

Return the location (as a true file path, or a Qt4 ":"-prefixed resource path) of the file best matching the given resource filename in the given resource category.

Category should be a relative directory path without leading or trailing slashes, for example "chords". The fileName is the remainder of the file name without any path content, for example "user_chords.xml".

Returns an empty string if no matching resource is found.

Use this when you know that a particular resource is required and just need to locate it.

Definition at line 238 of file ResourceFinder.cpp.

References getResourcePrefixList().

Referenced by unbundleResource(), and ~ResourceFinder().

QStringList ResourceFinder::getResourceFiles ( QString  resourceCat,
QString  fileExt 
)

Return a list of full file paths for files with the given file extension, found in the given resource category.

Category should be a relative directory path without leading or trailing slashes, for example "chords". File extension should be the extension without the dot, for example "xml". Returned list may mix true file paths in both installed and user locations with Qt4 ":"-prefixed resource paths.

Use this when you need to enumerate the options available for use directly in the program (rather than e.g. offering the user a file-open dialog).

Definition at line 333 of file ResourceFinder.cpp.

References getResourcePrefixList().

Referenced by ~ResourceFinder().

QString ResourceFinder::getResourceDir ( QString  resourceCat)

Return the true file path for installed resource files in the given resource category.

Category should be a relative directory path without leading or trailing slashes, for example "chords". Note that resources may also exist in the Qt4 resource bundle; this method only returns the external (installed) resource location. Use getResourceFiles instead to return an authoritative list of available resources of a given type.

Use this when you need a file path, e.g. for use in a file finder dialog.

Definition at line 267 of file ResourceFinder.cpp.

References getSystemResourcePrefixList().

Referenced by ~ResourceFinder().

QString ResourceFinder::getResourceSavePath ( QString  resourceCat,
QString  fileName 
)

Return the true file path for the location in which the named resource file in the given resource category should be saved.

ResourceFinder will make a best effort to ensure this directory actually exists, before returning.

Definition at line 291 of file ResourceFinder.cpp.

References getResourceSaveDir().

Referenced by unbundleResource(), and ~ResourceFinder().

QString ResourceFinder::getResourceSaveDir ( QString  resourceCat)

Return the true file path for the location in which resource files in the given resource category should be saved.

Definition at line 300 of file ResourceFinder.cpp.

References getUserResourcePrefix().

Referenced by getResourceSavePath(), and ~ResourceFinder().

bool ResourceFinder::unbundleResource ( QString  resourceCat,
QString  fileName 
)

If the named resource file in the given resource category is available only as a bundled resource, copy it out into the user location returned by getResourceSavePath so that it can be read by non-Qt code.

Any subsequent call to getResourcePath for this resource should return a true file path (if the resource exists) in either user or system location, or an empty string (if the resource does not exist), but never a ":"-prefixed resource path. This function does not overwrite any existing unbundled copy of the resource.

Return false if a system error occurs during unbundling (e.g. disk full).

Definition at line 370 of file ResourceFinder.cpp.

References getResourcePath(), getResourceSavePath(), and SVDEBUG.

Referenced by ~ResourceFinder().

QString ResourceFinder::getUserResourcePrefix ( )

Return the root path for user-specific resource installation for this application (i.e.

resources beneath the user's home directory).

Definition at line 214 of file ResourceFinder.cpp.

References getNewStyleUserResourcePrefix(), and migrateOldStyleResources().

Referenced by TempDirectory::getContainingPath(), getResourcePrefixList(), getResourceSaveDir(), SVDebug::SVDebug(), and ~ResourceFinder().

QStringList ResourceFinder::getSystemResourcePrefixList ( )

Return the root paths for systemwide resource installations for this application.

Resource files may be found in three places:

Bundled into the application as Qt4 resources. These may be opened using Qt classes such as QFile, with "fake" file paths starting with a colon. For example ":icons/fileopen.png".

Installed with the package, or in the user's equivalent home directory location. For example,

  • on Linux, in /usr/share/<appname> or /usr/local/share/<appname>
  • on Linux, in $HOME/.local/share/<appname>
  • on OS/X, in /Library/Application Support/<appname>
  • on OS/X, in $HOME/Library/Application Support/<appname>
  • on Windows, in ProgramFiles%/<company>/<appname>
  • on Windows, in (where?) something from http://msdn.microsoft.com/en-us/library/dd378457%28v=vs.85%29.aspx ?

These locations are searched in reverse order (user-installed copies take priority over system-installed copies take priority over bundled copies). Also, /usr/local takes priority over /usr.

Definition at line 65 of file ResourceFinder.cpp.

References getEnvUtf8().

Referenced by getResourceDir(), getResourcePrefixList(), and ~ResourceFinder().

QStringList ResourceFinder::getResourcePrefixList ( )

Return all root paths for resource installations for this application, in the order in which they will be searched.

This list consists of the user-specific path (getUserResourcePrefix()) followed by the systemwide paths (getSystemResourcePrefixList()).

Definition at line 221 of file ResourceFinder.cpp.

References getSystemResourcePrefixList(), and getUserResourcePrefix().

Referenced by getResourceFiles(), getResourcePath(), and ~ResourceFinder().


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