Warning, file /office/calligra/libs/widgets/KoResourcePaths.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Copyright (c) 2015 Boudewijn Rempt <boud@valdyas.org>
0003  * Copyright (c) 2015 Friedrich W. H. Kossebau <kossebau@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Lesser General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2.1 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Lesser General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Lesser General Public
0016  * License along with this library; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #ifndef KORESOURCEPATHS_H
0021 #define KORESOURCEPATHS_H
0022 
0023 #include <QString>
0024 
0025 #include <kowidgets_export.h>
0026 
0027 class QStringList;
0028 
0029 
0030 namespace KoResourcePaths
0031 {
0032     enum SearchOption { NoSearchOptions = 0,
0033                         Recursive = 1,
0034                         NoDuplicates = 2,
0035                         IgnoreExecBit = 4
0036                       };
0037     Q_DECLARE_FLAGS(SearchOptions, SearchOption)
0038 
0039     /**
0040      * Adds suffixes for types.
0041      *
0042      * You may add as many as you need, but it is advised that there
0043      * is exactly one to make writing definite.
0044      *
0045      * The later a suffix is added, the higher its priority. Note, that the
0046      * suffix should end with / but doesn't have to start with one (as prefixes
0047      * should end with one). So adding a suffix for app_pics would look
0048      * like KoStandardPaths::addResourceType("app_pics", "data", "app/pics");
0049      *
0050      * @param type Specifies a short descriptive string to access
0051      * files of this type.
0052      * @param basetype Specifies an already known type, or 0 if none
0053      * @param relativeName Specifies a directory relative to the basetype
0054      * @param priority if true, the directory is added before any other,
0055      * otherwise after
0056      */
0057     KOWIDGETS_EXPORT void addResourceType(const char *type, const char *basetype,
0058                                           const QString &relativeName, bool priority = true);
0059 
0060 
0061     /**
0062      * Adds absolute path at the beginning of the search path for
0063      * particular types (for example in case of icons where
0064      * the user specifies extra paths).
0065      *
0066      * You shouldn't need this function in 99% of all cases besides
0067      * adding user-given paths.
0068      *
0069      * @param type Specifies a short descriptive string to access files
0070      * of this type.
0071      * @param dir Points to directory where to look for this specific
0072      * type. Non-existent directories may be saved but pruned.
0073      * @param priority if true, the directory is added before any other,
0074      * otherwise after
0075      */
0076     KOWIDGETS_EXPORT void addResourceDir(const char *type, const QString &dir, bool priority = true);
0077 
0078     /**
0079      * Tries to find a resource in the following order:
0080      * @li All PREFIX/\<relativename> paths (most recent first).
0081      * @li All absolute paths (most recent first).
0082      *
0083      * The filename should be a filename relative to the base dir
0084      * for resources. So is a way to get the path to libkdecore.la
0085      * to findResource("lib", "libkdecore.la"). KStandardDirs will
0086      * then look into the subdir lib of all elements of all prefixes
0087      * ($KDEDIRS) for a file libkdecore.la and return the path to
0088      * the first one it finds (e.g. /opt/kde/lib/libkdecore.la).
0089      *
0090      * Example:
0091      * @code
0092      * QString iconfilename = KStandardPaths::findResource("icon",QString("oxygen/22x22/apps/ktip.png"));
0093      * @endcode
0094      *
0095      * @param type The type of the wanted resource
0096      * @param fileName A relative filename of the resource.
0097      *
0098      * @return A full path to the filename specified in the second
0099      *         argument, or QString() if not found.
0100      */
0101 
0102     KOWIDGETS_EXPORT QString findResource(const char *type, const QString &fileName);
0103 
0104     /**
0105      * Tries to find all directories whose names consist of the
0106      * specified type and a relative path. So
0107      * findDirs("xdgdata-apps", "Settings") would return
0108      * @li /home/joe/.local/share/applications/Settings/
0109      * @li /usr/share/applications/Settings/
0110      *
0111      * (from the most local to the most global)
0112      *
0113      * Note that it appends @c / to the end of the directories,
0114      * so you can use this right away as directory names.
0115      *
0116      * @param type The type of the base directory.
0117      * @param reldir Relative directory.
0118      *
0119      * @return A list of matching directories, or an empty
0120      *         list if the resource specified is not found.
0121      */
0122     KOWIDGETS_EXPORT QStringList findDirs(const char *type, const QString &reldir);
0123 
0124     /**
0125      * Tries to find all resources with the specified type.
0126      *
0127      * The function will look into all specified directories
0128      * and return all filenames in these directories.
0129      *
0130      * The "most local" files are returned before the "more global" files.
0131      *
0132      * @param type The type of resource to locate directories for.
0133      * @param filter Only accept filenames that fit to filter. The filter
0134      *        may consist of an optional directory and a QRegExp
0135      *        wildcard expression. E.g. <tt>"images\*.jpg"</tt>.
0136      *        Use QString() if you do not want a filter.
0137      * @param options if the flags passed include Recursive, subdirectories
0138      *        will also be search; if NoDuplicates is passed then only entries with
0139      *        unique filenames will be returned eliminating duplicates.
0140      *
0141      * @return List of all the files whose filename matches the
0142      *         specified filter.
0143      */
0144     KOWIDGETS_EXPORT QStringList findAllResources(const char *type,
0145                                  const QString &filter = QString(),
0146                                  SearchOptions options = NoSearchOptions);
0147 
0148     /**
0149      * @param type The type of resource
0150      * @return The list of possible directories for the specified @p type.
0151      * The function updates the cache if possible.  If the resource
0152      * type specified is unknown, it will return an empty list.
0153      * Note, that the directories are assured to exist beside the save
0154      * location, which may not exist, but is returned anyway.
0155      */
0156     KOWIDGETS_EXPORT QStringList resourceDirs(const char *type);
0157 
0158     /**
0159      * Finds a location to save files into for the given type
0160      * in the user's home directory.
0161      *
0162      * @param type The type of location to return.
0163      * @param suffix A subdirectory name.
0164      *             Makes it easier for you to create subdirectories.
0165      *   You can't pass filenames here, you _have_ to pass
0166      *       directory names only and add possible filename in
0167      *       that directory yourself. A directory name always has a
0168      *       trailing slash ('/').
0169      * @param create If set, saveLocation() will create the directories
0170      *        needed (including those given by @p suffix).
0171      *
0172      * @return A path where resources of the specified type should be
0173      *         saved, or QString() if the resource type is unknown.
0174      */
0175     KOWIDGETS_EXPORT QString saveLocation(const char *type, const QString &suffix = QString(), bool create = true);
0176 
0177     /**
0178      * This function is just for convenience. It simply calls
0179      * KoResourcePaths::findResource((type, filename).
0180      *
0181      * @param type   The type of the wanted resource, see KStandardDirs
0182      * @param filename   A relative filename of the resource
0183      *
0184      * @return A full path to the filename specified in the second
0185      *         argument, or QString() if not found
0186      **/
0187     KOWIDGETS_EXPORT QString locate(const char *type, const QString &filename);
0188 
0189     /**
0190      * This function is much like locate. However it returns a
0191      * filename suitable for writing to. No check is made if the
0192      * specified @p filename actually exists. Missing directories
0193      * are created. If @p filename is only a directory, without a
0194      * specific file, @p filename must have a trailing slash.
0195      *
0196      * @param type   The type of the wanted resource, see KStandardDirs
0197      * @param filename   A relative filename of the resource
0198      * @param createDir Defines whether to create directory should it does not exist
0199      *
0200      * @return A full path to the filename specified in the second
0201      *         argument, or QString() if not found
0202      **/
0203     KOWIDGETS_EXPORT QString locateLocal(const char *type, const QString &filename, bool createDir = false);
0204 }
0205 
0206 Q_DECLARE_OPERATORS_FOR_FLAGS(KoResourcePaths::SearchOptions)
0207 
0208 #endif // KORESOURCEPATHS_H