KStandardDirs

Search for usage in LXR

#include <kstandarddirs.h>

Public Types

enum  SearchOption { NoSearchOptions = 0, Recursive = 1, NoDuplicates = 2, IgnoreExecBit = 4 }
 
typedef QFlags< SearchOption > SearchOptions
 

Public Member Functions

 KStandardDirs ()
 
virtual ~KStandardDirs ()
 
bool addCustomized (KConfig *config)
 
void addPrefix (const QString &dir)
 
bool addResourceDir (const char *type, const QString &absdir, bool priority=true)
 
bool addResourceType (const char *type, const char *basetype, const char *relativename, bool priority=true)
 
bool addResourceType (const char *type, const char *basetype, const QString &relativename, bool priority=true)
 
bool addResourceType (const char *type, const QString &relativename, bool priority=true)
 
void addXdgConfigPrefix (const QString &dir)
 
void addXdgDataPrefix (const QString &dir)
 
QStringList allTypes () const
 
quint32 calcResourceHash (const char *type, const QString &filename, SearchOptions options=NoSearchOptions) const
 
QStringList findAllResources (const char *type, const QString &filter, SearchOptions options, QStringList &relPaths) const
 
QStringList findAllResources (const char *type, const QString &filter=QString(), SearchOptions options=NoSearchOptions) const
 
QStringList findDirs (const char *type, const QString &reldir) const
 
QString findResource (const char *type, const QString &filename) const
 
QString findResourceDir (const char *type, const QString &filename) const
 
bool isRestrictedResource (const char *type, const QString &relPath=QString()) const
 
QString kfsstnd_prefixes ()
 
QString localkdedir () const
 
QString localxdgconfdir () const
 
QString localxdgdatadir () const
 
QString relativeLocation (const char *type, const QString &absPath) const
 
QStringList resourceDirs (const char *type) const
 
QString saveLocation (const char *type, const QString &suffix=QString(), bool create=true) const
 

Static Public Member Functions

static bool checkAccess (const QString &pathname, int mode)
 
static bool exists (const QString &fullPath)
 
static int findAllExe (QStringList &list, const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
 
static QString findExe (const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)
 
static QString installPath (const char *type)
 
static QString kde_default (const char *type)
 
static QString locate (const char *type, const QString &filename)
 
static QString locateLocal (const char *type, const QString &filename)
 
static QString locateLocal (const char *type, const QString &filename, bool createDir)
 
static bool makeDir (const QString &dir, int mode=0755)
 
static QString realFilePath (const QString &filename)
 
static QString realPath (const QString &dirname)
 
static QStringList systemPaths (const QString &pstr=QString())
 

Detailed Description

Site-independent access to standard KDE directories.

Author
Stephan Kulow coolo[email protected]@kde[email protected].org and Sirtaj Singh Kang [email protected][email protected]de.o[email protected]rg

This is one of the most central classes in kdelibs: It knows where KDE-related files reside on the user's hard disk. It's meant to be the only one that knows – so applications and the end user don't have to.

Applications should always refer to a file with a resource type. The application should leave it up to e.g. KStandardDirs::findResource("xdgdata-apps", "Home.desktop") to return the desired path /opt/kde/share/applications/Home.desktop or ::locate("data", "kgame/background.jpg") to return /opt/kde/share/kgame/background.jpg

There are several toplevel prefixes under which files can be located. One of them is the kdelibs install location, one is the application install location, and one used to be $KDEHOME, no longer applicable in KDE Frameworks 5 (splitted into XDG_CONFIG_HOME and XDG_DATA_HOME, mostly).

Under these toplevel prefixes there are several well-defined suffixes where specific resource types can be found. For example, for the resource type "html" the suffixes could be share/doc/HTML and share/doc/kde/HTML. The search algorithm tries to locate the file under each prefix-suffix combination.

It is also possible to register absolute paths that KStandardDirs looks up after not finding anything in the former steps. They can be useful if the user wants to provide specific directories that aren't in his $KDEHOME directory, for example for icons.

Standard resources that kdelibs allocates are:

  • autostart - Autostart directories (both XDG and kde-specific) (deprecated since 5.0, use xdgconf-autostart)
  • cache - Cached information (e.g. favicons, web-pages)
  • config - Configuration files.
  • data - Where applications store data.
  • emoticons - Emoticons themes
  • exe - Executables in $prefix/bin. findExe() for a function that takes $PATH into account.
  • html - HTML documentation.
  • icon - Icons, see KIconLoader.
  • kcfg - KConfigXT config files.
  • lib - Libraries.
  • locale - Translation files for KLocale.
  • module - Module (dynamically loaded library).
  • qtplugins - Qt plugins (dynamically loaded objects for Qt)
  • services - Services.
  • servicetypes - Service types.
  • sound - Application sounds.
  • templates - Templates for the "Create new file" functionality.
  • wallpaper - Wallpapers.
  • tmp - Temporary files (specific for both current host and current user)
  • socket - UNIX Sockets (specific for both current host and current user)
  • xdgconf-menu - Freedesktop.org standard location for menu layout (.menu) files.
  • xdgdata-apps - Freedesktop.org standard location for application desktop files.
  • xdgdata-dirs - Freedesktop.org standard location for menu descriptions (.directory files).
  • xdgdata-mime - Freedesktop.org standard location for MIME type definitions.
  • xdgdata-icon - Freedesktop.org standard location for icons.
  • xdgdata-pixmap - Gnome-compatibility location for pixmaps.

A type that is added by the class KApplication if you use it, is appdata. This one makes the use of the type data a bit easier as it appends the name of the application. So while you had to ::locate("data", "appname/filename") so you can also write ::locate("appdata", "filename") if your KApplication instance is called "appname" (as set via KApplication's constructor or KAboutData, if you use the global KStandardDirs object KGlobal::dirs()). Please note though that you cannot use the "appdata" type if you intend to use it in an applet for Kicker because 'appname' would be "Kicker" instead of the applet's name. Therefore, for applets, you've got to work around this by using ::locate("data", "appletname/filename").

KStandardDirs supports the following environment variables:

  • KDEDIRS - This may set an additional number of directory prefixes to search for resources. The directories should be separated by ':'. The directories are searched in the order they are specified.
  • KDEHOME - The directory where changes are saved to. This directory is used to search for resources first. If KDEHOME is not specified it defaults to "$HOME/.kde"
  • KDEROOTHOME - Like KDEHOME, but used for the root user. If KDEROOTHOME is not set it defaults to the .kde directory in the home directory of root, usually "/root/.kde". Note that the setting of $HOME is ignored in this case.
See also
KGlobalSettings

On The Usage Of 'locate' and 'locateLocal'

Typical KDE applications use resource files in one out of three ways:

1) A resource file is read but is never written. A system default is supplied but the user can override this default in his local .kde directory:

// Code example
myFile = KStandardDirs::locate("appdata", "groups.lst");
myData = myReadGroups(myFile); // myFile may be null

2) A resource file is read and written. If the user has no local version of the file the system default is used. The resource file is always written to the users local .kde directory.

// Code example
myFile = KStandardDirs::locate("appdata", "groups.lst")
myData = myReadGroups(myFile);
...
doSomething(myData);
...
myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);

3) A resource file is read and written. No system default is used if the user has no local version of the file. The resource file is always written to the users local .kde directory.

// Code example
myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
myData = myReadGroups(myFile);
...
doSomething(myData);
...
myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
myWriteGroups(myFile, myData);
Deprecated:
since 5.0, use QStandardPaths, see KDE5PORTING.html for details

Definition at line 177 of file kstandarddirs.h.

Constructor & Destructor Documentation

◆ KStandardDirs()

KStandardDirs::KStandardDirs ( )

KStandardDirs' constructor.

It just initializes the caches. Note that you should normally not call this, but use KGlobal::dirs() instead, in order to reuse the same KStandardDirs object as much as possible.

Creating other KStandardDirs instances can be useful in other threads.

Thread safety note: using a shared KStandardDirs instance (such as KGlobal::dirs()) in multiple threads is thread-safe if you only call the readonly "lookup" methods (findExe, resourceDirs, findDirs, findResourceDir, findAllResources, saveLocation, relativeLocation). The methods that modify the object (all those starting with "add", basically all non-const methods) are obviously not thread-safe; set things up before creating threads.

Definition at line 375 of file kstandarddirs.cpp.

◆ ~KStandardDirs()

KStandardDirs::~KStandardDirs ( )
virtual

KStandardDirs' destructor.

Definition at line 381 of file kstandarddirs.cpp.

Member Function Documentation

◆ addCustomized()

bool KStandardDirs::addCustomized ( KConfig config)

Reads customized entries out of the given config object and add them via addResourceDirs().

Parameters
configThe object the entries are read from. This should contain global config files
Returns
true if new config paths have been added from config.

Definition at line 2004 of file kstandarddirs.cpp.

◆ addPrefix()

void KStandardDirs::addPrefix ( const QString dir)

Adds another search dir to front of the fsstnd list.

Since 5.0, this prefix is only used for "lib" and "exe" resources, and the compat "config" resource. Use addXdgDataPrefix for most others.

  • When compiling kdelibs, the prefix is added to this.
  • KDEDIRS is taken into account
  • Additional dirs may be loaded from kdeglobals.
Parameters
dirThe directory to append relative paths to.

Definition at line 450 of file kstandarddirs.cpp.

◆ addResourceDir()

bool KStandardDirs::addResourceDir ( const char *  type,
const QString absdir,
bool  priority = true 
)

Adds absolute path at the beginning of the search path for particular types (for example in case of icons where the user specifies extra paths).

You shouldn't need this function in 99% of all cases besides adding user-given paths.

Parameters
typeSpecifies a short descriptive string to access files of this type.
absdirPoints to directory where to look for this specific type. Non-existent directories may be saved but pruned.
priorityif true, the directory is added before any other, otherwise after
Returns
true if successful, false otherwise.

Definition at line 568 of file kstandarddirs.cpp.

◆ addResourceType() [1/3]

bool KStandardDirs::addResourceType ( const char *  type,
const char *  basetype,
const char *  relativename,
bool  priority = true 
)
inline

- just to avoid unwanted overload

Definition at line 291 of file kstandarddirs.h.

◆ addResourceType() [2/3]

bool KStandardDirs::addResourceType ( const char *  type,
const char *  basetype,
const QString relativename,
bool  priority = true 
)

Adds suffixes for types.

You may add as many as you need, but it is advised that there is exactly one to make writing definite. All basic types are added by addKDEDefaults(), but for those you can add more relative paths as well.

The later a suffix is added, the higher its priority. Note, that the suffix should end with / but doesn't have to start with one (as prefixes should end with one). So adding a suffix for app_pics would look like KGlobal::dirs()->addResourceType("app_pics", "data", "app/pics");

Parameters
typeSpecifies a short descriptive string to access files of this type.
basetypeSpecifies an already known type, or 0 if none
relativenameSpecifies a directory relative to the basetype
priorityif true, the directory is added before any other, otherwise after
Returns
true if successful, false otherwise.

Definition at line 530 of file kstandarddirs.cpp.

◆ addResourceType() [3/3]

bool KStandardDirs::addResourceType ( const char *  type,
const QString relativename,
bool  priority = true 
)

Adds suffixes for types.

You may add as many as you need, but it is advised that there is exactly one to make writing definite. All basic types are added by addKDEDefaults(), but for those you can add more relative paths as well.

The later a suffix is added, the higher its priority. Note, that the suffix should end with / but doesn't have to start with one (as prefixes should end with one). So adding a suffix for app_pics would look like KGlobal::dirs()->addResourceType("app_pics", "data" ,"app/pics");

Parameters
typeSpecifies a short descriptive string to access files of this type.
relativenameSpecifies a directory relative to the root of the KFSSTND.
priorityif true, the directory is added before any other, otherwise after
Returns
true if successful, false otherwise.
Deprecated:
, use addResourceType(type, 0, relativename, priority)

Definition at line 522 of file kstandarddirs.cpp.

◆ addXdgConfigPrefix()

void KStandardDirs::addXdgConfigPrefix ( const QString dir)

Adds another search dir to front of the XDG_CONFIG_XXX list of prefixes.

This prefix is only used for resources that start with "xdgconf-"

Parameters
dirThe directory to append relative paths to.

Definition at line 472 of file kstandarddirs.cpp.

◆ addXdgDataPrefix()

void KStandardDirs::addXdgDataPrefix ( const QString dir)

Adds another search dir to front of the XDG_DATA_XXX list of prefixes.

Parameters
dirThe directory to append relative paths to.

Definition at line 494 of file kstandarddirs.cpp.

◆ allTypes()

QStringList KStandardDirs::allTypes ( ) const

This function will return a list of all the types that KStandardDirs supports.

Returns
All types that KDE supports

Definition at line 416 of file kstandarddirs.cpp.

◆ calcResourceHash()

quint32 KStandardDirs::calcResourceHash ( const char *  type,
const QString filename,
SearchOptions  options = NoSearchOptions 
) const

Returns a number that identifies this version of the resource.

When a change is made to the resource this number will change.

Parameters
typeThe type of the wanted resource
filenameA relative filename of the resource.
optionsIf the flags includes Recursive, all resources are taken into account otherwise only the one returned by findResource().
Returns
A number identifying the current version of the resource.
Deprecated:
since 5.0. Only kbuildsycoca needed the multi-dir version of this. In other apps, just use QFileInfo(fullPath).lastModified().toTime_t()

Definition at line 640 of file kstandarddirs.cpp.

◆ checkAccess()

bool KStandardDirs::checkAccess ( const QString pathname,
int  mode 
)
static

Check, if a file may be accessed in a given mode.

This is a wrapper around the access() system call. checkAccess() calls access() with the given parameters. If this is OK, checkAccess() returns true. If not, and W_OK is part of mode, it is checked if there is write access to the directory. If yes, checkAccess() returns true. In all other cases checkAccess() returns false.

Other than access() this function EXPLICITLY ignores non-existent files if checking for write access.

Parameters
pathnameThe full path of the file you want to test
modeThe access mode, as in the access() system call.
Returns
Whether the access is allowed, true = Access allowed

Definition at line 2174 of file kstandarddirs.cpp.

◆ exists()

bool KStandardDirs::exists ( const QString fullPath)
static

Checks for existence and accessability of a file or directory.

Faster than creating a QFileInfo first.

Parameters
fullPaththe path to check. IMPORTANT: must end with a slash if expected to be a directory (and no slash for a file, obviously).
Returns
true if the directory exists, false otherwise
Deprecated:
since 5.0, use QFile::exists or QFileInfo::isFile()/isDir() to be more precise.

Definition at line 728 of file kstandarddirs.cpp.

◆ findAllExe()

int KStandardDirs::findAllExe ( QStringList list,
const QString appname,
const QString pathstr = QString(),
SearchOptions  options = NoSearchOptions 
)
static

Finds all occurrences of an executable in the system path.

Parameters
listwill be filled with the pathnames of all the executables found. Will be empty if the executable was not found.
appnamethe name of the executable for which to search.
pathstrthe path list which will be searched. If this is 0 (default), the $PATH environment variable will be searched.
optionsif the flags passed include IgnoreExecBit the path returned may not have the executable bit set.
Returns
The number of executables found, 0 if none were found.
See also
findExe()

Definition at line 1483 of file kstandarddirs.cpp.

◆ findAllResources() [1/2]

QStringList KStandardDirs::findAllResources ( const char *  type,
const QString filter,
SearchOptions  options,
QStringList relPaths 
) const

Tries to find all resources with the specified type.

The function will look into all specified directories and return all filenames (full and relative paths) in these directories.

The "most local" files are returned before the "more global" files.

Parameters
typeThe type of resource to locate directories for. Can be icon, lib, pixmap, .... To get a complete list, call
filterOnly accept filenames that fit to filter. The filter may consist of an optional directory and a QRegExp wildcard expression. E.g. "images\*.jpg". Use QString() if you do not want a filter.
optionsif the flags passed include Recursive, subdirectories will also be search; if NoDuplicates is passed then only entries with unique filenames will be returned eliminating duplicates.
relPathsThe list to store the relative paths into These can be used later to ::locate() the file
Returns
List of all the files whose filename matches the specified filter.

Definition at line 996 of file kstandarddirs.cpp.

◆ findAllResources() [2/2]

QStringList KStandardDirs::findAllResources ( const char *  type,
const QString filter = QString(),
SearchOptions  options = NoSearchOptions 
) const

Tries to find all resources with the specified type.

The function will look into all specified directories and return all filenames in these directories.

The "most local" files are returned before the "more global" files.

Parameters
typeThe type of resource to locate directories for.
filterOnly accept filenames that fit to filter. The filter may consist of an optional directory and a QRegExp wildcard expression. E.g. "images\*.jpg". Use QString() if you do not want a filter.
optionsif the flags passed include Recursive, subdirectories will also be search; if NoDuplicates is passed then only entries with unique filenames will be returned eliminating duplicates.
Returns
List of all the files whose filename matches the specified filter.

Definition at line 1043 of file kstandarddirs.cpp.

◆ findDirs()

QStringList KStandardDirs::findDirs ( const char *  type,
const QString reldir 
) const

Tries to find all directories whose names consist of the specified type and a relative path.

So findDirs("xdgdata-apps", "Settings") would return

  • /home/joe/.local/share/applications/Settings/
  • /usr/share/applications/Settings/

(from the most local to the most global)

Note that it appends / to the end of the directories, so you can use this right away as directory names.

Parameters
typeThe type of the base directory.
reldirRelative directory.
Returns
A list of matching directories, or an empty list if the resource specified is not found.

Definition at line 662 of file kstandarddirs.cpp.

◆ findExe()

QString KStandardDirs::findExe ( const QString appname,
const QString pathstr = QString(),
SearchOptions  options = NoSearchOptions 
)
static

Finds the executable in the system path.

A valid executable must be a file and have its executable bit set.

Parameters
appnameThe name of the executable file for which to search. if this contains a path separator, it will be resolved according to the current working directory (shell-like behaviour).
pathstrThe path which will be searched. If this is null (default), the $PATH environment variable will be searched.
optionsif the flags passed include IgnoreExecBit the path returned may not have the executable bit set.
Returns
The path of the executable. If it was not found, it will return QString().
See also
findAllExe()

Definition at line 1415 of file kstandarddirs.cpp.

◆ findResource()

QString KStandardDirs::findResource ( const char *  type,
const QString filename 
) const

Tries to find a resource in the following order:

  • All PREFIX/<relativename> paths (most recent first).
  • All absolute paths (most recent first).

The filename should be a filename relative to the base dir for resources. So is a way to get the path to libkdecore.la to findResource("lib", "libkdecore.la"). KStandardDirs will then look into the subdir lib of all elements of all prefixes ($KDEDIRS) for a file libkdecore.la and return the path to the first one it finds (e.g. /opt/kde/lib/libkdecore.la). You can use the program kf5-config to list all resource types:

$ kf5-config --types

Example:

QString iconfilename=KGlobal::dirs()->findResource("icon",QString("oxygen/22x22/apps/ktip.png"));
Parameters
typeThe type of the wanted resource
filenameA relative filename of the resource.
Returns
A full path to the filename specified in the second argument, or QString() if not found.

Definition at line 597 of file kstandarddirs.cpp.

◆ findResourceDir()

QString KStandardDirs::findResourceDir ( const char *  type,
const QString filename 
) const

Tries to find the directory the file is in.

It works the same as findResource(), but it doesn't return the filename but the name of the directory.

This way the application can access a couple of files that have been installed into the same directory without having to look for each file.

findResourceDir("lib", "libkdecore.la") would return the path of the subdir libkdecore.la is found first in (e.g. /opt/kde/lib/)

Parameters
typeThe type of the wanted resource
filenameA relative filename of the resource.
Returns
The directory where the file specified in the second argument is located, or QString() if the type of resource specified is unknown or the resource cannot be found.

Definition at line 692 of file kstandarddirs.cpp.

◆ installPath()

QString KStandardDirs::installPath ( const char *  type)
static
Returns
the path where type was installed to by kdelibs. This is an absolute path and only one out of many search paths
Deprecated:
since 5.0, use QStandardPaths::standardLocations(...).last()

Definition at line 359 of file kstandarddirs.cpp.

◆ isRestrictedResource()

bool KStandardDirs::isRestrictedResource ( const char *  type,
const QString relPath = QString() 
) const

Checks whether a resource is restricted as part of the KIOSK framework.

When a resource is restricted it means that user- specific files in the resource are ignored.

E.g. by restricting the "wallpaper" resource, only system-wide installed wallpapers will be found by this class. Wallpapers installed under the $KDEHOME directory will be ignored.

Parameters
typeThe type of the resource to check
relPathA relative path in the resource.
Returns
True if the resource is restricted.

Definition at line 386 of file kstandarddirs.cpp.

◆ kde_default()

QString KStandardDirs::kde_default ( const char *  type)
static

This returns a default relative path for the standard KDE resource types.

Below is a list of them so you get an idea of what this is all about.

  • data - share
  • html - share/doc/HTML
  • icon - share/icon
  • config - share/config
  • pixmap - share/pixmaps
  • sound - share/sounds
  • locale - share/locale
  • services - share/kde5/services
  • servicetypes - share/kde5/servicetypes
  • wallpaper - share/wallpapers
  • templates - share/templates
  • exe - bin
  • lib - lib[suffix]
  • module - lib[suffix]/plugins/kde5
  • qtplugins - lib[suffix]/plugins
  • kcfg - share/config.kcfg
  • emoticons - share/emoticons
  • xdgdata - shared files (QStandardPaths::GenericDataLocation)
  • xdgdata-apps - applications
  • xdgdata-icon - icons
  • xdgdata-pixmap - pixmaps
  • xdgdata-dirs - desktop-directories
  • xdgdata-mime - mime
  • xdgconf-menu - menus
  • xdgconf - config files
Returns
Static default for the specified resource. You should probably be using locate() or locateLocal() instead.
See also
locate()
locateLocal()
Deprecated:
now returns % + type + / ...

Definition at line 1557 of file kstandarddirs.cpp.

◆ kfsstnd_prefixes()

QString KStandardDirs::kfsstnd_prefixes ( )

(for use by sycoca only)

Deprecated:
since 5.0, there is no KDEDIRS anymore. If you care for XDG_DATA_DIRS instead, use this: QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).join(QString(':'))

Definition at line 517 of file kstandarddirs.cpp.

◆ localkdedir()

QString KStandardDirs::localkdedir ( ) const

Returns the toplevel directory in which KStandardDirs will store things.

Most likely $HOME/.kde. Don't use this function if you can use locateLocal()

Returns
the toplevel directory
Deprecated:
since 5.0, there is no KDEDIRS nor KDEHOME anymore. Use QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) or QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) instead.

Definition at line 2126 of file kstandarddirs.cpp.

◆ localxdgconfdir()

QString KStandardDirs::localxdgconfdir ( ) const
Returns
$XDG_CONFIG_HOME See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html
Deprecated:
since 5.0 use QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + '/'

Definition at line 2138 of file kstandarddirs.cpp.

◆ localxdgdatadir()

QString KStandardDirs::localxdgdatadir ( ) const
Returns
$XDG_DATA_HOME See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html
Deprecated:
since 5.0 use QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + '/'

Definition at line 2132 of file kstandarddirs.cpp.

◆ locate()

QString KStandardDirs::locate ( const char *  type,
const QString filename 
)
static

This function is just for convenience.

It simply calls instance->dirs()->findResource(type, filename).

Parameters
typeThe type of the wanted resource, see KStandardDirs
filenameA relative filename of the resource
Returns
A full path to the filename specified in the second argument, or QString() if not found

Definition at line 2146 of file kstandarddirs.cpp.

◆ locateLocal() [1/2]

QString KStandardDirs::locateLocal ( const char *  type,
const QString filename 
)
static

This function is much like locate.

However it returns a filename suitable for writing to. No check is made if the specified filename actually exists. Missing directories are created. If filename is only a directory, without a specific file, filename must have a trailing slash.

Parameters
typeThe type of the wanted resource, see KStandardDirs
filenameA relative filename of the resource
Returns
A full path to the filename specified in the second argument, or QString() if not found

Definition at line 2152 of file kstandarddirs.cpp.

◆ locateLocal() [2/2]

QString KStandardDirs::locateLocal ( const char *  type,
const QString filename,
bool  createDir 
)
static

This function is much like locate.

No check is made if the specified filename actually exists. Missing directories are created if createDir is true. If filename is only a directory, without a specific file, filename must have a trailing slash.

Parameters
typeThe type of the wanted resource, see KStandardDirs
filenameA relative filename of the resource
createDirIf true, missing directories are created, if false, no directory is created
Returns
A full path to the filename specified in the second argument, or QString() if not found

Definition at line 2158 of file kstandarddirs.cpp.

◆ makeDir()

bool KStandardDirs::makeDir ( const QString dir,
int  mode = 0755 
)
static

Recursively creates still-missing directories in the given path.

The resulting permissions will depend on the current umask setting. permission = mode & ~umask.

Parameters
dirAbsolute path of the directory to be made.
modeDirectory permissions.
Returns
true if successful, false otherwise
Deprecated:
since 5.0, use QDir().mkpath(dir).

Definition at line 1655 of file kstandarddirs.cpp.

◆ realFilePath()

QString KStandardDirs::realFilePath ( const QString filename)
static

Expands all symbolic links and resolves references to '/.

/', '/../' and extra '/' characters in filename and returns the canonicalized absolute pathname. The resulting path will have no symbolic link, '/./' or '/../' components.

Deprecated:
since 5.0, port to QFileInfo::canonicalFilePath, but note that it returns an empty string if filename doesn't exist!

Definition at line 1119 of file kstandarddirs.cpp.

◆ realPath()

QString KStandardDirs::realPath ( const QString dirname)
static

Expands all symbolic links and resolves references to '/.

/', '/../' and extra '/' characters in dirname and returns the canonicalized absolute pathname. The resulting path will have no symbolic link, '/./' or '/../' components.

Deprecated:
since 5.0, port to QDir::canonicalPath, but note that it returns an empty string if filename doesn't exist!

Definition at line 1057 of file kstandarddirs.cpp.

◆ relativeLocation()

QString KStandardDirs::relativeLocation ( const char *  type,
const QString absPath 
) const

Converts an absolute path to a path relative to a certain resource.

If "abs = ::locate(resource, rel)" then "rel = relativeLocation(resource, abs)" and vice versa.

Parameters
typeThe type of resource.
absPathAn absolute path to make relative.
Returns
A relative path relative to resource type that will find absPath. If no such relative path exists, absPath will be returned unchanged.
Deprecated:
since 5.0, write your own loop, for instance:
relativeLocation("xdgdata-apps", file) becomes:
static QString relativeToApplications(const QString& file)
{
const QString canonical = QFileInfo(file).canonicalFilePath();
if (canonical.startsWith(base))
return canonical.mid(base.length()+1);
}
return file; // in this example we return an absolute path, you can also choose return QString()
}

See KDE5PORTING.html for how to port other resources.

Definition at line 1636 of file kstandarddirs.cpp.

◆ resourceDirs()

QStringList KStandardDirs::resourceDirs ( const char *  type) const

This function is used internally by almost all other function as it serves and fills the directories cache.

Parameters
typeThe type of resource
Returns
The list of possible directories for the specified type. The function updates the cache if possible. If the resource type specified is unknown, it will return an empty list. Note, that the directories are assured to exist beside the save location, which may not exist, but is returned anyway.

Definition at line 1147 of file kstandarddirs.cpp.

◆ saveLocation()

QString KStandardDirs::saveLocation ( const char *  type,
const QString suffix = QString(),
bool  create = true 
) const

Finds a location to save files into for the given type in the user's home directory.

Parameters
typeThe type of location to return.
suffixA subdirectory name. Makes it easier for you to create subdirectories. You can't pass filenames here, you have to pass directory names only and add possible filename in that directory yourself. A directory name always has a trailing slash ('/').
createIf set, saveLocation() will create the directories needed (including those given by suffix).
Returns
A path where resources of the specified type should be saved, or QString() if the resource type is unknown.

Definition at line 1563 of file kstandarddirs.cpp.

◆ systemPaths()

QStringList KStandardDirs::systemPaths ( const QString pstr = QString())
static

Returns a QStringList list of pathnames in the system path.

Parameters
pstrThe path which will be searched. If this is null (default), the $PATH environment variable will be searched.
Returns
a QStringList list of pathnames in the system path.

Definition at line 1322 of file kstandarddirs.cpp.


The documentation for this class was generated from the following files:
QString findResource(const char *type, const QString &filename) const
Tries to find a resource in the following order:
QString relativeLocation(const char *type, const QString &absPath) const
Converts an absolute path to a path relative to a certain resource.
QStringList types(Mode mode=Writing)
Returns a list of all KImageIO supported formats.
Definition: kimageio.cpp:88
QStringList standardLocations(QStandardPaths::StandardLocation type)
int length() const const
static QString locateLocal(const char *type, const QString &filename)
This function is much like locate.
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:102
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
KStandardDirs * dirs()
Returns the application standard dirs object.
Definition: kglobal.cpp:89
Site-independent access to standard KDE directories.
static QString locate(const char *type, const QString &filename)
This function is just for convenience.
QString mid(int position, int n) const const
QString canonicalFilePath() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:56:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.