File indexing completed on 2024-04-14 14:20:07

0001 /*
0002   This file is part of the KDE libraries
0003   Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org>
0004   Copyright (C) 1999 Stephan Kulow <coolo@kde.org>
0005   Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
0006 
0007   This library is free software; you can redistribute it and/or
0008   modify it under the terms of the GNU Library General Public
0009   License as published by the Free Software Foundation; either
0010   version 2 of the License, or (at your option) any later version.
0011 
0012   This library is distributed in the hope that it will be useful,
0013   but WITHOUT ANY WARRANTY; without even the implied warranty of
0014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015   Library General Public License for more details.
0016 
0017   You should have received a copy of the GNU Library General Public License
0018   along with this library; see the file COPYING.LIB.  If not, write to
0019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020   Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KSTANDARDDIRS_H
0024 #define KSTANDARDDIRS_H
0025 
0026 #include <kdelibs4support_export.h>
0027 
0028 #ifdef KDELIBS4SUPPORT_NO_DEPRECATED_NOISE
0029 #warning "This file is deprecated."
0030 #endif
0031 
0032 #include <QStringList>
0033 #include <QMap>
0034 
0035 class KConfig;
0036 
0037 /**
0038  * @short Site-independent access to standard KDE directories.
0039  * @author Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org>
0040  *
0041  * This is one of the most central classes in kdelibs: It knows where KDE-related files
0042  * reside on the user's hard disk. It's meant to be the only one that knows --
0043  * so applications and the end user don't have to.
0044  *
0045  * Applications should always refer to a file with a resource type.
0046  * The application should leave it up to e.g.
0047  * KStandardDirs::findResource("xdgdata-apps", "Home.desktop")
0048  * to return the desired path <tt>/opt/kde/share/applications/Home.desktop</tt>
0049  * or ::locate("data", "kgame/background.jpg") to return
0050  * <tt>/opt/kde/share/kgame/background.jpg</tt>
0051  *
0052  * There are several toplevel prefixes under which files can be located.
0053  * One of them is the kdelibs install location, one is the application
0054  * install location, and one used to be <tt>$KDEHOME</tt>, no longer applicable
0055  * in KDE Frameworks 5 (splitted into XDG_CONFIG_HOME and XDG_DATA_HOME, mostly).
0056  *
0057  * Under these toplevel prefixes there are several well-defined suffixes
0058  * where specific resource types can be found.
0059  * For example, for the resource type @c "html" the suffixes could be
0060  * @c share/doc/HTML and @c share/doc/kde/HTML.
0061  * The search algorithm tries to locate the file under each prefix-suffix
0062  * combination.
0063  *
0064  * It is also possible to register
0065  * absolute paths that KStandardDirs looks up after not finding anything
0066  * in the former steps. They can be useful if the user wants to provide
0067  * specific directories that aren't in his <tt>$KDEHOME</tt> directory, for
0068  * example for icons.
0069  *
0070  * <b>Standard resources that kdelibs allocates are:</b>
0071  *
0072  * @li @c autostart - Autostart directories (both XDG and kde-specific) (deprecated since 5.0, use xdgconf-autostart)
0073  * @li @c cache - Cached information (e.g. favicons, web-pages)
0074  * @li @c config - Configuration files.
0075  * @li @c data - Where applications store data.
0076  * @li @c emoticons - Emoticons themes
0077  * @li @c exe - Executables in $prefix/bin. findExe() for a function that takes $PATH into account.
0078  * @li @c html - HTML documentation.
0079  * @li @c icon - Icons, see KIconLoader.
0080  * @li @c kcfg - KConfigXT config files.
0081  * @li @c lib - Libraries.
0082  * @li @c locale - Translation files for KLocale.
0083  * @li @c module - Module (dynamically loaded library).
0084  * @li @c qtplugins - Qt plugins (dynamically loaded objects for Qt)
0085  * @li @c services - Services.
0086  * @li @c servicetypes - Service types.
0087  * @li @c sound - Application sounds.
0088  * @li @c templates - Templates for the "Create new file" functionality.
0089  * @li @c wallpaper - Wallpapers.
0090  * @li @c tmp - Temporary files (specific for both current host and current user)
0091  * @li @c socket - UNIX Sockets (specific for both current host and current user)
0092  * @li @c xdgconf-menu - Freedesktop.org standard location for menu layout (.menu) files.
0093  * @li @c xdgdata-apps - Freedesktop.org standard location for application desktop files.
0094  * @li @c xdgdata-dirs - Freedesktop.org standard location for menu descriptions (.directory files).
0095  * @li @c xdgdata-mime - Freedesktop.org standard location for MIME type definitions.
0096  * @li @c xdgdata-icon - Freedesktop.org standard location for icons.
0097  * @li @c xdgdata-pixmap - Gnome-compatibility location for pixmaps.
0098  *
0099  * A type that is added by the class KApplication if you use it, is
0100  * @c appdata. This one makes the use of the type data a bit easier as it
0101  * appends the name of the application.
0102  * So while you had to ::locate("data", "appname/filename") so you can
0103  * also write ::locate("appdata", "filename") if your KApplication instance
0104  * is called @c "appname" (as set via KApplication's constructor or KAboutData, if
0105  * you use the global KStandardDirs object KGlobal::dirs()).
0106  * Please note though that you cannot use the @c "appdata"
0107  * type if you intend to use it in an applet for Kicker because 'appname' would
0108  * be @c "Kicker" instead of the applet's name. Therefore, for applets, you've got
0109  * to work around this by using ::locate("data", "appletname/filename").
0110  *
0111  * <b>KStandardDirs supports the following environment variables:</b>
0112  *
0113  * @li @c KDEDIRS - This may set an additional number of directory prefixes to
0114  *          search for resources. The directories should be separated
0115  *          by <tt>':'</tt>. The directories are searched in the order they are
0116  *          specified.
0117  * @li @c KDEHOME - The directory where changes are saved to. This directory is
0118  *          used to search for resources first. If @c KDEHOME is not
0119  *          specified it defaults to @c "$HOME/.kde"
0120  * @li @c KDEROOTHOME - Like KDEHOME, but used for the root user.
0121  *          If @c KDEROOTHOME is not set it defaults to the <tt>.kde</tt> directory in the
0122  *          home directory of root, usually @c "/root/.kde".
0123  *          Note that the setting of @c $HOME is ignored in this case.
0124  *
0125  * @see KGlobalSettings
0126  *
0127  *
0128  * On The Usage Of 'locate' and 'locateLocal'
0129  *
0130  * Typical KDE applications use resource files in one out of
0131  * three ways:
0132  *
0133  * 1) A resource file is read but is never written. A system
0134  *    default is supplied but the user can override this
0135  *    default in his local .kde directory:
0136  *
0137  *    @code
0138  *    // Code example
0139  *    myFile = KStandardDirs::locate("appdata", "groups.lst");
0140  *    myData =  myReadGroups(myFile); // myFile may be null
0141  *    @endcode
0142  *
0143  * 2) A resource file is read and written. If the user has no
0144  *    local version of the file the system default is used.
0145  *    The resource file is always written to the users local
0146  *    .kde directory.
0147  *
0148  *    @code
0149  *    // Code example
0150  *    myFile = KStandardDirs::locate("appdata", "groups.lst")
0151  *    myData =  myReadGroups(myFile);
0152  *    ...
0153  *    doSomething(myData);
0154  *    ...
0155  *    myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
0156  *    myWriteGroups(myFile, myData);
0157  *    @endcode
0158  *
0159  * 3) A resource file is read and written. No system default
0160  *    is used if the user has no local version of the file.
0161  *    The resource file is always written to the users local
0162  *    .kde directory.
0163  *
0164  *    @code
0165  *    // Code example
0166  *    myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
0167  *    myData =  myReadGroups(myFile);
0168  *    ...
0169  *    doSomething(myData);
0170  *    ...
0171  *    myFile = KStandardDirs::locateLocal("appdata", "groups.lst");
0172  *    myWriteGroups(myFile, myData);
0173  *    @endcode
0174  *
0175  * @deprecated since 5.0, use QStandardPaths, see KDE5PORTING.html for details
0176  **/
0177 class KDELIBS4SUPPORT_DEPRECATED_EXPORT_NOISE KStandardDirs
0178 {
0179 public:
0180     /**
0181      * KStandardDirs' constructor. It just initializes the caches.
0182      * Note that you should normally not call this, but use KGlobal::dirs()
0183      * instead, in order to reuse the same KStandardDirs object as much as possible.
0184      *
0185      * Creating other KStandardDirs instances can be useful in other threads.
0186      *
0187      * Thread safety note: using a shared KStandardDirs instance (such as KGlobal::dirs())
0188      * in multiple threads is thread-safe if you only call the readonly "lookup" methods
0189      * (findExe, resourceDirs, findDirs, findResourceDir, findAllResources, saveLocation,
0190      * relativeLocation). The methods that modify the object (all those starting with "add",
0191      * basically all non-const methods) are obviously not thread-safe; set things up
0192      * before creating threads.
0193      */
0194     KStandardDirs();
0195 
0196     enum SearchOption { NoSearchOptions = 0,
0197                         Recursive = 1,
0198                         NoDuplicates = 2,
0199                         IgnoreExecBit = 4
0200                       };
0201     Q_DECLARE_FLAGS(SearchOptions, SearchOption)
0202 
0203     /**
0204      * KStandardDirs' destructor.
0205      */
0206     virtual ~KStandardDirs();
0207 
0208     /**
0209      * Adds another search dir to front of the @p fsstnd list.
0210      * Since 5.0, this prefix is only used for "lib" and "exe" resources,
0211      * and the compat "config" resource. Use addXdgDataPrefix for most others.
0212      *
0213      * @li When compiling kdelibs, the prefix is added to this.
0214      * @li @c KDEDIRS is taken into account
0215      * @li Additional dirs may be loaded from kdeglobals.
0216      *
0217      * @param dir The directory to append relative paths to.
0218      */
0219     void addPrefix(const QString &dir);
0220 
0221     /**
0222      * Adds another search dir to front of the @c XDG_CONFIG_XXX list
0223      * of prefixes.
0224      * This prefix is only used for resources that start with @c "xdgconf-"
0225      *
0226      * @param dir The directory to append relative paths to.
0227      */
0228     void addXdgConfigPrefix(const QString &dir);
0229 
0230     /**
0231      * Adds another search dir to front of the @c XDG_DATA_XXX list
0232      * of prefixes.
0233      *
0234      * @param dir The directory to append relative paths to.
0235      */
0236     void addXdgDataPrefix(const QString &dir);
0237 
0238     /**
0239      * Adds suffixes for types.
0240      *
0241      * You may add as many as you need, but it is advised that there
0242      * is exactly one to make writing definite.
0243      * All basic types are added by addKDEDefaults(),
0244      * but for those you can add more relative paths as well.
0245      *
0246      * The later a suffix is added, the higher its priority. Note, that the
0247      * suffix should end with / but doesn't have to start with one (as prefixes
0248      * should end with one). So adding a suffix for app_pics would look
0249      * like KGlobal::dirs()->addResourceType("app_pics", "data" ,"app/pics");
0250      *
0251      * @param type Specifies a short descriptive string to access
0252      * files of this type.
0253      * @param relativename Specifies a directory relative to the root
0254      * of the KFSSTND.
0255      * @param priority if true, the directory is added before any other,
0256      * otherwise after
0257      * @return true if successful, false otherwise.
0258      *
0259      * @deprecated, use addResourceType(type, 0, relativename, priority)
0260      */
0261 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0262     KDELIBS4SUPPORT_DEPRECATED bool addResourceType(const char *type,
0263             const QString &relativename, bool priority = true);
0264 #endif
0265 
0266     /**
0267      * Adds suffixes for types.
0268      *
0269      * You may add as many as you need, but it is advised that there
0270      * is exactly one to make writing definite.
0271      * All basic types are added by addKDEDefaults(),
0272      * but for those you can add more relative paths as well.
0273      *
0274      * The later a suffix is added, the higher its priority. Note, that the
0275      * suffix should end with / but doesn't have to start with one (as prefixes
0276      * should end with one). So adding a suffix for app_pics would look
0277      * like KGlobal::dirs()->addResourceType("app_pics", "data", "app/pics");
0278      *
0279      * @param type Specifies a short descriptive string to access
0280      * files of this type.
0281      * @param basetype Specifies an already known type, or 0 if none
0282      * @param relativename Specifies a directory relative to the basetype
0283      * @param priority if true, the directory is added before any other,
0284      * otherwise after
0285      * @return true if successful, false otherwise.
0286      */
0287     bool addResourceType(const char *type, const char *basetype,
0288                          const QString &relativename, bool priority = true);
0289 
0290     /// @internal - just to avoid unwanted overload
0291     bool addResourceType(const char *type, const char *basetype,
0292                          const char *relativename, bool priority = true)
0293     {
0294         return addResourceType(type, basetype, QLatin1String(relativename), priority);
0295     }
0296 
0297     /**
0298      * Adds absolute path at the beginning of the search path for
0299      * particular types (for example in case of icons where
0300      * the user specifies extra paths).
0301      *
0302      * You shouldn't need this
0303      * function in 99% of all cases besides adding user-given
0304      * paths.
0305      *
0306      * @param type Specifies a short descriptive string to access files
0307      * of this type.
0308      * @param absdir Points to directory where to look for this specific
0309      * type. Non-existent directories may be saved but pruned.
0310      * @param priority if true, the directory is added before any other,
0311      * otherwise after
0312      * @return true if successful, false otherwise.
0313      */
0314     bool addResourceDir(const char *type,
0315                         const QString &absdir, bool priority = true);
0316 
0317     /**
0318      * Tries to find a resource in the following order:
0319      * @li All PREFIX/\<relativename> paths (most recent first).
0320      * @li All absolute paths (most recent first).
0321      *
0322      * The filename should be a filename relative to the base dir
0323      * for resources. So is a way to get the path to libkdecore.la
0324      * to findResource("lib", "libkdecore.la"). KStandardDirs will
0325      * then look into the subdir lib of all elements of all prefixes
0326      * ($KDEDIRS) for a file libkdecore.la and return the path to
0327      * the first one it finds (e.g. /opt/kde/lib/libkdecore.la).
0328      * You can use the program kf5-config to list all resource types:
0329      * @code
0330      * $ kf5-config --types
0331      * @endcode
0332      *
0333      * Example:
0334      * @code
0335      * QString iconfilename=KGlobal::dirs()->findResource("icon",QString("oxygen/22x22/apps/ktip.png"));
0336      * @endcode
0337      *
0338      * @param type The type of the wanted resource
0339      * @param filename A relative filename of the resource.
0340      *
0341      * @return A full path to the filename specified in the second
0342      *         argument, or QString() if not found.
0343      */
0344     QString findResource(const char *type,
0345                          const QString &filename) const;
0346 
0347     /**
0348      * Checks whether a resource is restricted as part of the KIOSK
0349      * framework. When a resource is restricted it means that user-
0350      * specific files in the resource are ignored.
0351      *
0352      * E.g. by restricting the @c "wallpaper" resource, only system-wide
0353      * installed wallpapers will be found by this class. Wallpapers
0354      * installed under the @c $KDEHOME directory will be ignored.
0355      *
0356      * @param type The type of the resource to check
0357      * @param relPath A relative path in the resource.
0358      *
0359      * @return True if the resource is restricted.
0360      */
0361     bool isRestrictedResource(const char *type,
0362                               const QString &relPath = QString()) const;
0363 
0364     /**
0365      * Returns a number that identifies this version of the resource.
0366      * When a change is made to the resource this number will change.
0367      *
0368      * @param type The type of the wanted resource
0369      * @param filename A relative filename of the resource.
0370      * @param options If the flags includes Recursive,
0371      *                all resources are taken into account
0372      *                otherwise only the one returned by findResource().
0373      *
0374      * @return A number identifying the current version of the
0375      *          resource.
0376      * @deprecated since 5.0. Only kbuildsycoca needed the multi-dir version of this.
0377      * In other apps, just use QFileInfo(fullPath).lastModified().toTime_t()
0378      */
0379 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0380     KDELIBS4SUPPORT_DEPRECATED quint32 calcResourceHash(const char *type,
0381             const QString &filename,
0382             SearchOptions options = NoSearchOptions) const;
0383 #endif
0384 
0385     /**
0386      * Tries to find all directories whose names consist of the
0387      * specified type and a relative path. So
0388      * findDirs("xdgdata-apps", "Settings") would return
0389      * @li /home/joe/.local/share/applications/Settings/
0390      * @li /usr/share/applications/Settings/
0391      *
0392      * (from the most local to the most global)
0393      *
0394      * Note that it appends @c / to the end of the directories,
0395      * so you can use this right away as directory names.
0396      *
0397      * @param type The type of the base directory.
0398      * @param reldir Relative directory.
0399      *
0400      * @return A list of matching directories, or an empty
0401      *         list if the resource specified is not found.
0402      */
0403     QStringList findDirs(const char *type,
0404                          const QString &reldir) const;
0405 
0406     /**
0407      * Tries to find the directory the file is in.
0408      * It works the same as findResource(), but it doesn't
0409      * return the filename but the name of the directory.
0410      *
0411      * This way the application can access a couple of files
0412      * that have been installed into the same directory without
0413      * having to look for each file.
0414      *
0415      * findResourceDir("lib", "libkdecore.la") would return the
0416      * path of the subdir libkdecore.la is found first in
0417      * (e.g. /opt/kde/lib/)
0418      *
0419      * @param type The type of the wanted resource
0420      * @param filename A relative filename of the resource.
0421      * @return The directory where the file specified in the second
0422      *         argument is located, or QString() if the type
0423      *         of resource specified is unknown or the resource
0424      *         cannot be found.
0425      */
0426     QString findResourceDir(const char *type,
0427                             const QString &filename) const;
0428 
0429     /**
0430      * Tries to find all resources with the specified type.
0431      *
0432      * The function will look into all specified directories
0433      * and return all filenames in these directories.
0434      *
0435      * The "most local" files are returned before the "more global" files.
0436      *
0437      * @param type The type of resource to locate directories for.
0438      * @param filter Only accept filenames that fit to filter. The filter
0439      *        may consist of an optional directory and a QRegExp
0440      *        wildcard expression. E.g. <tt>"images\*.jpg"</tt>.
0441      *        Use QString() if you do not want a filter.
0442      * @param options if the flags passed include Recursive, subdirectories
0443      *        will also be search; if NoDuplicates is passed then only entries with
0444      *        unique filenames will be returned eliminating duplicates.
0445      *
0446      * @return List of all the files whose filename matches the
0447      *         specified filter.
0448      */
0449     QStringList findAllResources(const char *type,
0450                                  const QString &filter = QString(),
0451                                  SearchOptions options = NoSearchOptions) const;
0452 
0453     /**
0454      * Tries to find all resources with the specified type.
0455      *
0456      * The function will look into all specified directories
0457      * and return all filenames (full and relative paths) in
0458      * these directories.
0459      *
0460      * The "most local" files are returned before the "more global" files.
0461      *
0462      * @param type The type of resource to locate directories for. Can be icon,
0463      *        lib, pixmap, .... To get a complete list, call
0464      *        @code
0465      *        kf5-config --types
0466      *        @endcode
0467      * @param filter Only accept filenames that fit to filter. The filter
0468      *        may consist of an optional directory and a QRegExp
0469      *        wildcard expression. E.g. <tt>"images\*.jpg"</tt>.
0470      *        Use QString() if you do not want a filter.
0471      * @param options if the flags passed include Recursive, subdirectories
0472      *        will also be search; if NoDuplicates is passed then only entries with
0473      *        unique filenames will be returned eliminating duplicates.
0474      *
0475      * @param relPaths The list to store the relative paths into
0476      *        These can be used later to ::locate() the file
0477      *
0478      * @return List of all the files whose filename matches the
0479      *         specified filter.
0480      */
0481     QStringList findAllResources(const char *type,
0482                                  const QString &filter,
0483                                  SearchOptions options,
0484                                  QStringList &relPaths) const;
0485 
0486     /**
0487      * Returns a QStringList list of pathnames in the system path.
0488      *
0489      * @param pstr  The path which will be searched. If this is
0490      *      null (default), the @c $PATH environment variable will
0491      *      be searched.
0492      *
0493      * @return a QStringList list of pathnames in the system path.
0494      */
0495     static QStringList systemPaths(const QString &pstr = QString());
0496 
0497     /**
0498      * Finds the executable in the system path.
0499      *
0500      * A valid executable must
0501      * be a file and have its executable bit set.
0502      *
0503      * @param appname The name of the executable file for which to search.
0504      *                if this contains a path separator, it will be resolved
0505      *                according to the current working directory
0506      *                (shell-like behaviour).
0507      * @param pathstr The path which will be searched. If this is
0508      *                null (default), the @c $PATH environment variable will
0509      *                be searched.
0510      * @param options if the flags passed include IgnoreExecBit the path returned
0511      *                may not have the executable bit set.
0512      *
0513      * @return The path of the executable. If it was not found,
0514      *         it will return QString().
0515      * @see findAllExe()
0516      */
0517     static QString findExe(const QString &appname,
0518                            const QString &pathstr = QString(),
0519                            SearchOptions options = NoSearchOptions);
0520 
0521     /**
0522      * Finds all occurrences of an executable in the system path.
0523      *
0524      * @param list will be filled with the pathnames of all the
0525      *             executables found. Will be empty if the executable
0526      *             was not found.
0527      * @param appname the name of the executable for which to
0528      *                search.
0529      * @param pathstr the path list which will be searched. If this
0530      *                is 0 (default), the @c $PATH environment variable will
0531      *                be searched.
0532      * @param options if the flags passed include IgnoreExecBit the path returned
0533      *                may not have the executable bit set.
0534      *
0535      * @return The number of executables found, 0 if none were found.
0536      *
0537      * @see findExe()
0538      */
0539     static int findAllExe(QStringList &list, const QString &appname,
0540                           const QString &pathstr = QString(),
0541                           SearchOptions options = NoSearchOptions);
0542 
0543     /**
0544      * Reads customized entries out of the given config object and add
0545      * them via addResourceDirs().
0546      *
0547      * @param config The object the entries are read from. This should
0548      *        contain global config files
0549      * @return @c true if new config paths have been added
0550      * from @p config.
0551      **/
0552     bool addCustomized(KConfig *config);
0553 
0554     /**
0555      * This function is used internally by almost all other function as
0556      * it serves and fills the directories cache.
0557      *
0558      * @param type The type of resource
0559      * @return The list of possible directories for the specified @p type.
0560      * The function updates the cache if possible.  If the resource
0561      * type specified is unknown, it will return an empty list.
0562      * Note, that the directories are assured to exist beside the save
0563      * location, which may not exist, but is returned anyway.
0564      */
0565     QStringList resourceDirs(const char *type) const;
0566 
0567     /**
0568      * This function will return a list of all the types that KStandardDirs
0569      * supports.
0570      *
0571      * @return All types that KDE supports
0572      */
0573     QStringList allTypes() const;
0574 
0575     /**
0576      * Finds a location to save files into for the given type
0577      * in the user's home directory.
0578      *
0579      * @param type The type of location to return.
0580      * @param suffix A subdirectory name.
0581      *             Makes it easier for you to create subdirectories.
0582      *   You can't pass filenames here, you _have_ to pass
0583      *       directory names only and add possible filename in
0584      *       that directory yourself. A directory name always has a
0585      *       trailing slash ('/').
0586      * @param create If set, saveLocation() will create the directories
0587      *        needed (including those given by @p suffix).
0588      *
0589      * @return A path where resources of the specified type should be
0590      *         saved, or QString() if the resource type is unknown.
0591      */
0592     QString saveLocation(const char *type,
0593                          const QString &suffix = QString(),
0594                          bool create = true) const;
0595 
0596     /**
0597      * Converts an absolute path to a path relative to a certain
0598      * resource.
0599      *
0600      * If "abs = ::locate(resource, rel)"
0601      * then "rel = relativeLocation(resource, abs)" and vice versa.
0602      *
0603      * @param type The type of resource.
0604      *
0605      * @param absPath An absolute path to make relative.
0606      *
0607      * @return A relative path relative to resource @p type that
0608      * will find @p absPath. If no such relative path exists, @p absPath
0609      * will be returned unchanged.
0610      * @deprecated since 5.0, write your own loop, for instance:
0611      * @code
0612      relativeLocation("xdgdata-apps", file) becomes:
0613      static QString relativeToApplications(const QString& file)
0614      {
0615          const QString canonical = QFileInfo(file).canonicalFilePath();
0616          Q_FOREACH(const QString& base, QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) {
0617              if (canonical.startsWith(base))
0618                  return canonical.mid(base.length()+1);
0619          }
0620          return file; // in this example we return an absolute path, you can also choose return QString()
0621      }
0622      * @endcode
0623      * See KDE5PORTING.html for how to port other resources.
0624      */
0625 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0626     KDELIBS4SUPPORT_DEPRECATED QString relativeLocation(const char *type, const QString &absPath) const;
0627 #endif
0628 
0629     /**
0630      * Recursively creates still-missing directories in the given path.
0631      *
0632      * The resulting permissions will depend on the current umask setting.
0633      * <tt>permission = mode & ~umask</tt>.
0634      *
0635      * @param dir Absolute path of the directory to be made.
0636      * @param mode Directory permissions.
0637      * @return true if successful, false otherwise
0638      * @deprecated since 5.0, use QDir().mkpath(dir).
0639      */
0640 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0641     KDELIBS4SUPPORT_DEPRECATED static bool makeDir(const QString &dir, int mode = 0755);
0642 #endif
0643 
0644     /**
0645      * This returns a default relative path for the standard KDE
0646      * resource types. Below is a list of them so you get an idea
0647      * of what this is all about.
0648      *
0649      * @li @c data - @c share
0650      * @li @c html - @c share/doc/HTML
0651      * @li @c icon - @c share/icon
0652      * @li @c config - @c share/config
0653      * @li @c pixmap - @c share/pixmaps
0654      * @li @c sound - @c share/sounds
0655      * @li @c locale - @c share/locale
0656      * @li @c services - @c share/kde5/services
0657      * @li @c servicetypes - @c share/kde5/servicetypes
0658      * @li @c wallpaper - @c share/wallpapers
0659      * @li @c templates - @c share/templates
0660      * @li @c exe - @c bin
0661      * @li @c lib - @c lib[suffix]
0662      * @li @c module - @c lib[suffix]/plugins/kde5
0663      * @li @c qtplugins - @c lib[suffix]/plugins
0664      * @li @c kcfg - @c share/config.kcfg
0665      * @li @c emoticons - @c share/emoticons
0666      * @li @c xdgdata - @c shared files (QStandardPaths::GenericDataLocation)
0667      * @li @c xdgdata-apps - @c applications
0668      * @li @c xdgdata-icon - @c icons
0669      * @li @c xdgdata-pixmap - @c pixmaps
0670      * @li @c xdgdata-dirs - @c desktop-directories
0671      * @li @c xdgdata-mime - @c mime
0672      * @li @c xdgconf-menu - @c menus
0673      * @li @c xdgconf - @c config files
0674      *
0675      * @returns Static default for the specified resource.  You
0676      *          should probably be using locate() or locateLocal()
0677      *          instead.
0678      * @see locate()
0679      * @see locateLocal()
0680      * @deprecated now returns % + type + / ...
0681      */
0682 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0683     static KDELIBS4SUPPORT_DEPRECATED QString kde_default(const char *type);
0684 #endif
0685 
0686     /**
0687      * @internal (for use by sycoca only)
0688      * @deprecated since 5.0, there is no KDEDIRS anymore. If you care for XDG_DATA_DIRS instead, use this:
0689      * QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).join(QString(':'))
0690      */
0691 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0692     KDELIBS4SUPPORT_DEPRECATED QString kfsstnd_prefixes();
0693 #endif
0694 
0695     /**
0696      * Returns the toplevel directory in which KStandardDirs
0697      * will store things. Most likely <tt>$HOME/.kde</tt>.
0698      * Don't use this function if you can use locateLocal()
0699      * @return the toplevel directory
0700      * @deprecated since 5.0, there is no KDEDIRS nor KDEHOME anymore.
0701      * Use QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) or
0702      * QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) instead.
0703      */
0704 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0705     KDELIBS4SUPPORT_DEPRECATED QString localkdedir() const;
0706 #endif
0707 
0708     /**
0709      * @return @c $XDG_DATA_HOME
0710      * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html
0711      * @deprecated since 5.0 use QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + '/'
0712      */
0713 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0714     KDELIBS4SUPPORT_DEPRECATED QString localxdgdatadir() const;
0715 #endif
0716 
0717     /**
0718      * @return @c $XDG_CONFIG_HOME
0719      * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html
0720      * @deprecated since 5.0 use QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + '/'
0721      */
0722 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0723     KDELIBS4SUPPORT_DEPRECATED QString localxdgconfdir() const;
0724 #endif
0725 
0726     /**
0727      * @return the path where type was installed to by kdelibs. This is an absolute path and only
0728      * one out of many search paths
0729      * @deprecated since 5.0, use QStandardPaths::standardLocations(...).last()
0730      */
0731     static QString installPath(const char *type);
0732 
0733     /**
0734      * Checks for existence and accessability of a file or directory.
0735      * Faster than creating a QFileInfo first.
0736      * @param fullPath the path to check. IMPORTANT: must end with a slash if expected to be a directory
0737      *                 (and no slash for a file, obviously).
0738      * @return @c true if the directory exists, @c false otherwise
0739      * @deprecated since 5.0, use QFile::exists or QFileInfo::isFile()/isDir() to be more precise.
0740      */
0741 #ifndef KDELIBS4SUPPORT_NO_DEPRECATED
0742     KDELIBS4SUPPORT_DEPRECATED static bool exists(const QString &fullPath);
0743 #endif
0744 
0745     /**
0746      * Expands all symbolic links and resolves references to
0747      * '/./', '/../' and extra  '/' characters in @p dirname
0748      * and returns the canonicalized absolute pathname.
0749      * The resulting path will have no symbolic link, '/./'
0750      * or '/../' components.
0751      * @deprecated since 5.0, port to QDir::canonicalPath, but note that it returns
0752      * an empty string if filename doesn't exist!
0753      */
0754     static QString realPath(const QString &dirname);
0755 
0756     /**
0757      * Expands all symbolic links and resolves references to
0758      * '/./', '/../' and extra  '/' characters in @p filename
0759      * and returns the canonicalized absolute pathname.
0760      * The resulting path will have no symbolic link, '/./'
0761      * or '/../' components.
0762      * @deprecated since 5.0, port to QFileInfo::canonicalFilePath, but note that it returns
0763      * an empty string if filename doesn't exist!
0764      */
0765     static QString realFilePath(const QString &filename);
0766 
0767     /**
0768      * This function is just for convenience. It simply calls
0769      * instance->dirs()->\link KStandardDirs::findResource() findResource\endlink(type, filename).
0770      *
0771      * @param type   The type of the wanted resource, see KStandardDirs
0772      * @param filename   A relative filename of the resource
0773      *
0774      * @return A full path to the filename specified in the second
0775      *         argument, or QString() if not found
0776      **/
0777     static QString locate(const char *type, const QString &filename);
0778 
0779     /**
0780      * This function is much like locate. However it returns a
0781      * filename suitable for writing to. No check is made if the
0782      * specified @p filename actually exists. Missing directories
0783      * are created. If @p filename is only a directory, without a
0784      * specific file, @p filename must have a trailing slash.
0785      *
0786      * @param type   The type of the wanted resource, see KStandardDirs
0787      * @param filename   A relative filename of the resource
0788      *
0789      * @return A full path to the filename specified in the second
0790      *         argument, or QString() if not found
0791      **/
0792     static QString locateLocal(const char *type, const QString &filename);
0793 
0794     /**
0795      * This function is much like locate. No check is made if the
0796      * specified filename actually exists. Missing directories
0797      * are created if @p createDir is true. If @p filename is only
0798      * a directory, without a specific file, @p filename must have
0799      * a trailing slash.
0800      *
0801      * @param type   The type of the wanted resource, see KStandardDirs
0802      * @param filename   A relative filename of the resource
0803      * @param createDir  If @c true, missing directories are created,
0804      *        if @c false, no directory is created
0805      *
0806      * @return A full path to the filename specified in the second
0807      *         argument, or QString() if not found
0808      **/
0809     static QString locateLocal(const char *type, const QString &filename, bool createDir);
0810 
0811     /**
0812      * Check, if a file may be accessed in a given mode.
0813      * This is a wrapper around the access() system call.
0814      * checkAccess() calls access() with the given parameters.
0815      * If this is OK, checkAccess() returns true. If not, and W_OK
0816      * is part of mode, it is checked if there is write access to
0817      * the directory. If yes, checkAccess() returns true.
0818      * In all other cases checkAccess() returns false.
0819      *
0820      * Other than access() this function EXPLICITLY ignores non-existent
0821      * files if checking for write access.
0822      *
0823      * @param pathname The full path of the file you want to test
0824      * @param mode     The access mode, as in the access() system call.
0825      * @return Whether the access is allowed, true = Access allowed
0826      */
0827     static bool checkAccess(const QString &pathname, int mode);
0828 
0829 private:
0830     // Disallow assignment and copy-construction
0831     KStandardDirs(const KStandardDirs &);
0832     KStandardDirs &operator= (const KStandardDirs &);
0833 
0834     class KStandardDirsPrivate;
0835     KStandardDirsPrivate *const d;
0836 
0837     // Like their public counter parts but with an extra priority argument
0838     // If priority is true, the directory is added directly after
0839     // $KDEHOME/$XDG_DATA_HOME/$XDG_CONFIG_HOME
0840     void addPrefix(const QString &dir, bool priority);
0841     void addXdgConfigPrefix(const QString &dir, bool priority);
0842     void addXdgDataPrefix(const QString &dir, bool priority);
0843     void addKDEDefaults();
0844 
0845     void addResourcesFrom_krcdirs();
0846 };
0847 
0848 Q_DECLARE_OPERATORS_FOR_FLAGS(KStandardDirs::SearchOptions)
0849 
0850 #endif // KSTANDARDDIRS_H