Home · All Namespaces · All Classes · Functions · Coding Style · Plugins · File Structure

StelFileMgr Class Reference

Provides utilities for locating and handling files. More...

#include <StelFileMgr.hpp>

List of all members.

Public Types

enum  Flags {
  RemovableMedia = 0x00000001, Writable = 0x00000002, Directory = 0x00000004, File = 0x00000008,
  New = 0x00000010, Hidden = 0x00000020

Public Member Functions

 StelFileMgr ()
 ~StelFileMgr ()
QString findFile (const QString &path, const Flags &flags=(Flags) 0)
QSet< QString > listContents (const QString &path, const Flags &flags=(Flags) 0, bool recursive=false)
const QStringList & getSearchPaths (void)
void setSearchPaths (const QStringList &paths)
QString dirName (const QString &path)
QString getDesktopDir (void)
QString getUserDir (void)
void setUserDir (const QString &newDir)
QString getScreenshotDir (void)
void setScreenshotDir (const QString &newDir)
QString getLocaleDir (void)

Static Public Member Functions

static bool exists (const QString &path)
static bool isWritable (const QString &path)
static bool isDirectory (const QString &path)
static qint64 size (const QString &path)
static bool mkDir (const QString &path)

Detailed Description

Provides utilities for locating and handling files.

StelFileMgr provides functions for locating files. It maintains a list of directories in which to look for files called the search path. Typcially this includes the Stellarium installation directory, and a per-user settings directory (on platforms which support it). The concept is that the StelFileMgr will be asked for a named path, and it will try to locate that path within each of the search directories.

Lippo Huhtala <lippo.huhtala@meridea.com>

Matthew Gates <matthew@porpoisehead.net>

See also:
File and Directory Structure description.

Member Enumeration Documentation

used as named bitfield flags as specifiers to filter results of StelFileMgr methods.

RemovableMedia  Search on removable media if present (default is not to).
Writable  Only return writable paths.

For directories this means that it is possible to create files within the directory.

Directory  Exclude non-directories.
File  Exclude non-files.
New  Exclude existing paths.
Hidden  Include "hidden" paths (starting with a . on POSIX systems).

Constructor & Destructor Documentation

StelFileMgr::StelFileMgr (  ) 


By default, StelFileMgr will be created with the Stellarium installation directory config_root in the search path. On systems which provide a per-user data/settings directory (which we call the user_settings directory, this is also included in the search path, before the <config_root> directory.

StelFileMgr::~StelFileMgr (  ) 


Member Function Documentation

QString StelFileMgr::findFile ( const QString &  path,
const Flags flags = (Flags) 0 

Search for a path within the search paths, for example "textures/fog.png".

findFile looks through the search paths in order, returning the first instance of the specified path. By specifying a flags parameter it is possible to constrain the results to those matching various criteria. If the path argument is a complete path (is a full path on single root OSes, or unanbigiously identifies one and only one file on multi-root OSes), it will be tested for compliance with other conditions - the regular search path will not be tested. If you wish to search for a non-exiting file which is not in the search path you should explicitly prefix it with "./", or otherwise have a . at the start of the path parameter, e.g. path="./my_config_file_in_the_pwd.ini"

path the name of the file to search for, for example "textures/fog.png".
flags options which constrain the result.
returns a full path of the file if found, else return an empty path.
std::runtime_error what() -> "file not found: [filename]"
std::runtime_error what() -> "file does not match flags: [fullpath]". This exception occurs if a full path is passes at the path argument, but that path does not match the flags specified.

QSet<QString> StelFileMgr::listContents ( const QString &  path,
const Flags flags = (Flags) 0,
bool  recursive = false 

Set a set of all possible files/directories in any Stellarium search directory.

path the path to search inside, e.g. "landscapes"
flags options which constrain the result
recursive if true, all sub-directories are walked recursively
returns a QSet of file and.or directory names, which are available in any of the search paths + path. Returns empty set if none were found or the path is invalid (not a directory / not existing).

const QStringList& StelFileMgr::getSearchPaths ( void   )  [inline]

Get a vector of strings which describes the current search paths.

returns a vector of strings representing the current search paths.

void StelFileMgr::setSearchPaths ( const QStringList &  paths  ) 

Set the search paths.

paths is a vector of strings which will become the new search paths

static bool StelFileMgr::exists ( const QString &  path  )  [static]

Check if a path exists.

Note it might be a file or a directory.

path to check

static bool StelFileMgr::isWritable ( const QString &  path  )  [static]

Check if a path is writable For files, true is returned if the file exists and is writable or if the file doesn't exist, but it's parent directory does, if the file can be created.

In the case of directories, return true if the directory can have files created in it.

path to check

static bool StelFileMgr::isDirectory ( const QString &  path  )  [static]

Check if a path exists and is a directory.

path to check

static qint64 StelFileMgr::size ( const QString &  path  )  [static]

Return the size of the file at the path.

path to file

static bool StelFileMgr::mkDir ( const QString &  path  )  [static]

Make a directory.

path the path of the directory to create.
true if success, else false

QString StelFileMgr::dirName ( const QString &  path  ) 

Convenience function to find the parent directory of a given path May return relative paths if the parameter is a relative path.

path the path whose parent directory is to be returned

QString StelFileMgr::getDesktopDir ( void   ) 

Get the user's Desktop directory This is a portable way to retrieve the directory for the user's desktop.

On Linux and OSX this is $HOME/Desktop. For Windows, the system is queried using SHGetSpecialFolderLocation. If that doesn't work, the USERPROFILE environment variable is checked, and if set, \Desktop is appended, else C:\Windows\Desktop is used.

the path to the user's desktop directory
NOT_FOUND when the directory cannot be determined, or the OS doesn't provide one.

QString StelFileMgr::getUserDir ( void   ) 

Returns the path to the user directory This is the directory where we expect to find the [default] writable configuration file, user versions of scripts, nebulae, stars, skycultures etc.

It will be the first directory in the path which is used when trying to find most data files

the path to the user private data directory
NOT_FOUND if the directory could not be found

void StelFileMgr::setUserDir ( const QString &  newDir  ) 

Sets the user directory.

This updates the search paths (first element)

newDir the new value of the user directory
NOT_VALID if the specified user directory is not usable

QString StelFileMgr::getScreenshotDir ( void   ) 

This is the directory into which screenshots will be saved It is $HOME on Linux, BSD, Solaris etc.

It is the user's Desktop on MacOS X (??? - someone please verify this) It is ??? on Windows

the path to the directory where screenshots are saved
NOT_FOUND if the directory could not be found

void StelFileMgr::setScreenshotDir ( const QString &  newDir  ) 

Sets the screenshot directory.

This is set to platform-specific values in the StelFileMgr constructor, but it is settable using this function to make it possible to implement the command-line option which specifies where screenshots go.

newDir the new value of the screenshot directory

QString StelFileMgr::getLocaleDir ( void   ) 

get the directory for locate files (i18n)

the path to the locale directory or "" if the locale directory could not be found.

Generated on Mon Feb 2 17:23:48 2009 for Stellarium by  doxygen 1.5.5