Krita Source Code Documentation
Loading...
Searching...
No Matches
KoResourcePaths Class Reference

#include <KoResourcePaths.h>

+ Inheritance diagram for KoResourcePaths:

Public Types

enum  SearchOption { NoSearchOptions = 0 , Recursive = 1 , IgnoreExecBit = 4 }
 

Public Member Functions

QStringList aliases (const QString &type)
 
 KoResourcePaths ()
 
QStandardPaths::StandardLocation mapTypeToQStandardPaths (const QString &type)
 
virtual ~KoResourcePaths ()
 

Static Public Member Functions

static void addAssetDir (const QString &type, const QString &dir, bool priority=true)
 
static void addAssetType (const QString &type, const char *basetype, const QString &relativeName, bool priority=true)
 
static QStringList assetDirs (const QString &type)
 
static QStringList findAllAssets (const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)
 
static QString findAsset (const QString &type, const QString &fileName)
 
static QStringList findDirs (const QString &type)
 
static void getAllUserResourceFoldersLocationsForWindowsStore (QString &standardLocation, QString &privateLocation)
 getAllAppDataLocationsForWindowsStore Use this to get both private and general appdata folders which also considers user's choice of custom resource folder Used in GeneralTab in kis_dlg_preferences, and KisViewManager::openResourceDirectory().
 
static QString getAppDataLocation ()
 
static QString getApplicationRoot ()
 
static QString locate (const QString &type, const QString &filename)
 
static QString locateLocal (const QString &type, const QString &filename, bool createDir=false)
 
static QString saveLocation (const QString &type, const QString &suffix=QString(), bool create=true)
 

Public Attributes

QMap< QString, QStringListabsolutes
 
QMutex absolutesMutex
 
QMap< QString, QStringListrelatives
 
QMutex relativesMutex
 

Static Public Attributes

static QString s_overrideAppDataLocation
 getAppDataLocation Use this instead of QStandardPaths::AppDataLocation! The user can configure the location where resources and other user writable items are stored now.
 

Private Member Functions

void addResourceDirInternal (const QString &type, const QString &absdir, bool priority)
 
void addResourceTypeInternal (const QString &type, const QString &basetype, const QString &relativeName, bool priority)
 
QStringList findAllResourcesInternal (const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions) const
 
QStringList findDirsInternal (const QString &type)
 
QStringList findExtraResourceDirs () const
 
QString findResourceInternal (const QString &type, const QString &fileName)
 
QString locateInternal (const QString &type, const QString &filename)
 
QString locateLocalInternal (const QString &type, const QString &filename, bool createDir=false)
 
QStringList resourceDirsInternal (const QString &type)
 
QString saveLocationInternal (const QString &type, const QString &suffix=QString(), bool create=true)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

QScopedPointer< Privated
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

The usual place to look for assets is Qt's AppDataLocation. This corresponds to XDG_DATA_DIRS on Linux. To ensure your installation and path are configured correctly, ensure your files are located in the directories contained in this variable:

QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);

This can be overridden in Krita's configuration.

Unfortunately, we are mixing up two things in the appdatalocation:

  • resources: brushes, presets and so on
  • assets: color themes, icc profiles and other weird stuff

There are many debug lines that can be uncommented for more specific installation checks. In the future these should be converted to qloggingcategory to enable convenient enable/disable functionality.

Note: DO NOT USE THIS CLASS WHEN LOCATING RESOURCES LIKE BRUSHES OR GRADIENTS. Use KisResourceLocator instead.

Definition at line 156 of file KoResourcePaths.cpp.

Member Enumeration Documentation

◆ SearchOption

Enumerator
NoSearchOptions 
Recursive 
IgnoreExecBit 

Definition at line 45 of file KoResourcePaths.h.

Constructor & Destructor Documentation

◆ KoResourcePaths()

KoResourcePaths::KoResourcePaths ( )

Definition at line 205 of file KoResourcePaths.cpp.

206 : d(new Private)
207{
208}
QScopedPointer< Private > d

◆ ~KoResourcePaths()

KoResourcePaths::~KoResourcePaths ( )
virtual

Definition at line 210 of file KoResourcePaths.cpp.

211{
212}

Member Function Documentation

◆ addAssetDir()

void KoResourcePaths::addAssetDir ( const QString & type,
const QString & dir,
bool priority = true )
static

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. Nonexistent directories may be saved but pruned.
priorityif true, the directory is added before any other, otherwise after

Definition at line 304 of file KoResourcePaths.cpp.

305{
306 s_instance->addResourceDirInternal(type, dir, priority);
307}

◆ addAssetType()

void KoResourcePaths::addAssetType ( const QString & type,
const char * basetype,
const QString & relativeName,
bool priority = true )
static

Adds suffixes for asset types.

You may add as many as you need, but it is advised that there is exactly one to make writing definite.

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 KoStandardPaths::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

Definition at line 298 of file KoResourcePaths.cpp.

300{
301 s_instance->addResourceTypeInternal(type, QString::fromLatin1(basetype), relativeName, priority);
302}

◆ addResourceDirInternal()

void KoResourcePaths::addResourceDirInternal ( const QString & type,
const QString & absdir,
bool priority )
private

Definition at line 376 of file KoResourcePaths.cpp.

377{
378 if (absdir.isEmpty() || type.isEmpty()) return;
379
380 // find or insert entry in the map
381 QString copy = absdir;
382 if (copy.at(copy.length() - 1) != QLatin1Char('/')) {
383 copy += QLatin1Char('/');
384 }
385
386 d->absolutesMutex.lock();
387 QStringList &paths = d->absolutes[type];
388 if (!paths.contains(copy, cs)) {
389 if (priority) {
390 paths.prepend(copy);
391 } else {
392 paths.append(copy);
393 }
394 }
395 d->absolutesMutex.unlock();
396
397 dbgResources << "addResourceDir: type" << type << "absdir" << absdir << "priority" << priority << d->absolutes[type];
398}
#define dbgResources
Definition kis_debug.h:43

References d, and dbgResources.

◆ addResourceTypeInternal()

void KoResourcePaths::addResourceTypeInternal ( const QString & type,
const QString & basetype,
const QString & relativeName,
bool priority )
private

Definition at line 346 of file KoResourcePaths.cpp.

349{
350 Q_UNUSED(basetype);
351 if (relativename.isEmpty()) return;
352
353 QString copy = relativename;
354
355 Q_ASSERT(basetype == "data");
356
357 if (!copy.endsWith(QLatin1Char('/'))) {
358 copy += QLatin1Char('/');
359 }
360
361 d->relativesMutex.lock();
362 QStringList &rels = d->relatives[type]; // find or insert
363
364 if (!rels.contains(copy, cs)) {
365 if (priority) {
366 rels.prepend(copy);
367 } else {
368 rels.append(copy);
369 }
370 }
371 d->relativesMutex.unlock();
372
373 dbgResources << "addResourceType: type" << type << "basetype" << basetype << "relativename" << relativename << "priority" << priority << d->relatives[type];
374}

References d, and dbgResources.

◆ aliases()

QStringList KoResourcePaths::aliases ( const QString & type)
inline

Definition at line 164 of file KoResourcePaths.cpp.

165 {
167 QStringList a;
168 relativesMutex.lock();
169 if (relatives.contains(type)) {
170 r += relatives[type];
171 }
172 relativesMutex.unlock();
173 absolutesMutex.lock();
174 if (absolutes.contains(type)) {
175 a += absolutes[type];
176 }
177 absolutesMutex.unlock();
178
179 return r + a;
180 }
QMap< QString, QStringList > absolutes
QMap< QString, QStringList > relatives

◆ assetDirs()

QStringList KoResourcePaths::assetDirs ( const QString & type)
static
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 326 of file KoResourcePaths.cpp.

327{
328 return cleanupDirs(s_instance->resourceDirsInternal(type));
329}

◆ findAllAssets()

QStringList KoResourcePaths::findAllAssets ( const QString & type,
const QString & filter = QString(),
SearchOptions options = NoSearchOptions )
static

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.
Returns
List of all the files whose filename matches the specified filter.

Definition at line 319 of file KoResourcePaths.cpp.

322{
323 return cleanup(s_instance->findAllResourcesInternal(type, filter, options));
324}

◆ findAllResourcesInternal()

QStringList KoResourcePaths::findAllResourcesInternal ( const QString & type,
const QString & filter = QString(),
SearchOptions options = NoSearchOptions ) const
private

Definition at line 532 of file KoResourcePaths.cpp.

535{
536 dbgResources << "=====================================================";
537 dbgResources << type << _filter << QStandardPaths::standardLocations(d->mapTypeToQStandardPaths(type));
538
539 bool recursive = options & KoResourcePaths::Recursive;
540
541 dbgResources << "findAllResources: type" << type << "filter" << _filter << "recursive" << recursive;
542
543 QStringList aliases = d->aliases(type);
544 QString filter = _filter;
545
546 // In cases where the filter is like "color-schemes/*.colors" instead of "*.kpp", used with unregistered resource types
547 if (filter.indexOf('*') > 0) {
548 aliases << filter.split('*').first();
549 filter = '*' + filter.split('*')[1];
550 dbgResources << "Split up alias" << aliases << "filter" << filter;
551 }
552
553 QStringList resources;
554 if (aliases.isEmpty()) {
555 QStringList standardResources =
556 QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type),
557 filter, QStandardPaths::LocateFile);
558 dbgResources << "standardResources" << standardResources;
559 appendResources(&resources, standardResources, true);
560 dbgResources << "1" << resources;
561 }
562
563 QStringList extraResourceDirs = findExtraResourceDirs();
564
565 if (!extraResourceDirs.isEmpty()) {
566 Q_FOREACH(const QString &extraResourceDir, extraResourceDirs) {
567 if (aliases.isEmpty()) {
568 appendResources(&resources, filesInDir(extraResourceDir + '/' + type, filter, recursive), true);
569 }
570 else {
571 Q_FOREACH (const QString &alias, aliases) {
572 appendResources(&resources, filesInDir(extraResourceDir + '/' + alias + '/', filter, recursive), true);
573 }
574 }
575 }
576
577 }
578
579 dbgResources << "\tresources from qstandardpaths:" << resources.size();
580
581 Q_FOREACH (const QString &alias, aliases) {
582 dbgResources << "\t\talias:" << alias;
583 QStringList dirs;
584
585 QFileInfo dirInfo(alias);
586 if (dirInfo.exists() && dirInfo.isDir() && dirInfo.isAbsolute()) {
587 dirs << alias;
588 } else {
589 dirs << QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), alias, QStandardPaths::LocateDirectory)
590 << getInstallationPrefix() + "share/" + alias + "/"
591 << getInstallationPrefix() + "share/krita/" + alias + "/";
592 }
593
594 Q_FOREACH (const QString &dir, dirs) {
595 appendResources(&resources,
596 filesInDir(dir, filter, recursive),
597 true);
598 }
599 }
600
601 dbgResources << "\tresources also from aliases:" << resources.size();
602
603 // if the original filter is "input/*", we only want share/input/* and share/krita/input/* here, but not
604 // share/*. therefore, use _filter here instead of filter which was split into alias and "*".
605 QFileInfo fi(_filter);
606
607 QStringList prefixResources;
608 prefixResources << filesInDir(getInstallationPrefix() + "share/" + fi.path(), fi.fileName(), false);
609 prefixResources << filesInDir(getInstallationPrefix() + "share/krita/" + fi.path(), fi.fileName(), false);
610 appendResources(&resources, prefixResources, true);
611
612 dbgResources << "\tresources from installation:" << resources.size();
613 dbgResources << "=====================================================";
614
615 return resources;
616}
QStringList filesInDir(const QString &startdir, const QString &filter, bool recursive)
QStringList aliases(const QString &type)
QStringList findExtraResourceDirs() const

References aliases(), d, dbgResources, filesInDir(), findExtraResourceDirs(), and Recursive.

◆ findAsset()

QString KoResourcePaths::findAsset ( const QString & type,
const QString & fileName )
static

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 it's 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).

Example:

QString iconfilename = KStandardPaths::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 309 of file KoResourcePaths.cpp.

310{
311 return cleanup(s_instance->findResourceInternal(type, fileName));
312}

◆ findDirs()

QStringList KoResourcePaths::findDirs ( const QString & type)
static

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 314 of file KoResourcePaths.cpp.

315{
316 return cleanupDirs(s_instance->findDirsInternal(type));
317}

◆ findDirsInternal()

QStringList KoResourcePaths::findDirsInternal ( const QString & type)
private

Definition at line 490 of file KoResourcePaths.cpp.

491{
492 QStringList aliases = d->aliases(type);
493 dbgResources << type << aliases << d->mapTypeToQStandardPaths(type);
494
495 QStringList dirs;
496 QStringList standardDirs =
497 QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), "", QStandardPaths::LocateDirectory);
498
499 appendResources(&dirs, standardDirs, true);
500
501 Q_FOREACH (const QString &alias, aliases) {
502 QStringList aliasDirs =
503 QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), alias + '/', QStandardPaths::LocateDirectory);
504 appendResources(&dirs, aliasDirs, true);
505
506#ifdef Q_OS_MACOS
507 dbgResources << "MAC:" << getApplicationRoot();
508 QStringList bundlePaths;
509 bundlePaths << getApplicationRoot() + "/share/krita/" + alias;
510 bundlePaths << getApplicationRoot() + "/../share/krita/" + alias;
511 dbgResources << "bundlePaths" << bundlePaths;
512 appendResources(&dirs, bundlePaths, true);
513 Q_ASSERT(!dirs.isEmpty());
514#endif
515
516 QStringList fallbackPaths;
517 fallbackPaths << getApplicationRoot() + "/share/" + alias;
518 fallbackPaths << getApplicationRoot() + "/share/krita/" + alias;
519 appendResources(&dirs, fallbackPaths, true);
520
521 }
522
523 QStringList saveLocationList;
524 saveLocationList << saveLocation(type, QString(), true);
525 appendResources(&dirs, saveLocationList, true);
526
527 dbgResources << "findDirs: type" << type << "resource" << dirs;
528 return dirs;
529}
static QString getApplicationRoot()
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)

References aliases(), d, dbgResources, getApplicationRoot(), and saveLocation().

◆ findExtraResourceDirs()

QStringList KoResourcePaths::findExtraResourceDirs ( ) const
private

Definition at line 714 of file KoResourcePaths.cpp.

715{
716 QStringList extraResourceDirs =
717 QString::fromUtf8(qgetenv("EXTRA_RESOURCE_DIRS"))
718 .split(';', Qt::SkipEmptyParts);
719
720 const KConfigGroup cfg(KSharedConfig::openConfig(), "");
721 const QString customPath =
723 if (!customPath.isEmpty()) {
724 extraResourceDirs << customPath;
725 }
726
727 if (getAppDataLocation() != QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)) {
728 extraResourceDirs << getAppDataLocation();
729 }
730
731 return extraResourceDirs;
732}
static const QString resourceLocationKey
static QString getAppDataLocation()

References getAppDataLocation(), and KisResourceLocator::resourceLocationKey.

◆ findResourceInternal()

QString KoResourcePaths::findResourceInternal ( const QString & type,
const QString & fileName )
private

Definition at line 400 of file KoResourcePaths.cpp.

401{
402 QStringList aliases = d->aliases(type);
403 dbgResources<< "aliases" << aliases << getApplicationRoot();
404 QString resource = QStandardPaths::locate(QStandardPaths::AppDataLocation, fileName, QStandardPaths::LocateFile);
405
406 if (resource.isEmpty()) {
407 Q_FOREACH (const QString &alias, aliases) {
408 resource = QStandardPaths::locate(d->mapTypeToQStandardPaths(type), alias + '/' + fileName, QStandardPaths::LocateFile);
409 if (QFile::exists(resource)) {
410 break;
411 }
412 }
413 }
414 if (resource.isEmpty() || !QFile::exists(resource)) {
415 QString approot = getApplicationRoot();
416 Q_FOREACH (const QString &alias, aliases) {
417 resource = approot + "/share/" + alias + '/' + fileName;
418 if (QFile::exists(resource)) {
419 break;
420 }
421 }
422 }
423 if (resource.isEmpty() || !QFile::exists(resource)) {
424 QString approot = getApplicationRoot();
425 Q_FOREACH (const QString &alias, aliases) {
426 resource = approot + "/share/krita/" + alias + '/' + fileName;
427 if (QFile::exists(resource)) {
428 break;
429 }
430 }
431 }
432
433 if (resource.isEmpty() || !QFile::exists(resource)) {
434 QStringList extraResourceDirs = findExtraResourceDirs();
435
436 if (!extraResourceDirs.isEmpty()) {
437 Q_FOREACH(const QString &extraResourceDir, extraResourceDirs) {
438 if (aliases.isEmpty()) {
439 resource = extraResourceDir + '/' + fileName;
440 dbgResources<< "\t4" << resource;
441 if (QFile::exists(resource)) {
442 break;
443 }
444 }
445 else {
446 Q_FOREACH (const QString &alias, aliases) {
447 resource = extraResourceDir + '/' + alias + '/' + fileName;
448 dbgResources<< "\t4" << resource;
449 if (QFile::exists(resource)) {
450 break;
451 }
452 }
453 }
454 }
455 }
456 }
457
458 dbgResources<< "findResource: type" << type << "filename" << fileName << "resource" << resource;
459 Q_ASSERT(!resource.isEmpty());
460 return resource;
461}

References aliases(), d, dbgResources, findExtraResourceDirs(), and getApplicationRoot().

◆ getAllUserResourceFoldersLocationsForWindowsStore()

void KoResourcePaths::getAllUserResourceFoldersLocationsForWindowsStore ( QString & standardLocation,
QString & privateLocation )
static

getAllAppDataLocationsForWindowsStore Use this to get both private and general appdata folders which also considers user's choice of custom resource folder Used in GeneralTab in kis_dlg_preferences, and KisViewManager::openResourceDirectory().

Parameters
standardLocation- location in standard AppData%
privateLocation- location in private app AppData% location, only relevant for Windows Store
Returns
either both appdata locations, or just the custom resource folder

Definition at line 248 of file KoResourcePaths.cpp.

249{
250 standardLocation = "";
251 privateLocation = "";
252 QString resourcePath = QDir(KisResourceLocator::instance()->resourceLocationBase()).absolutePath();
253#ifndef Q_OS_WIN
254 // not Windows, no problem
255 standardLocation = resourcePath;
256 return;
257#else
259 standardLocation = resourcePath; // Windows, but not Windows Store, so no problem
260 return;
261 }
262
263 // running inside Windows Store
264 const QDir resourceDir(resourcePath);
265 QDir appDataGeneralDir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
266 appDataGeneralDir.cdUp();
267 const QString appDataGeneralDirPath = appDataGeneralDir.path();
268 if (resourceDir.absolutePath().contains(appDataGeneralDirPath, Qt::CaseInsensitive)) {
269 // resource folder location is inside appdata, so it can cause issues
270 // from inside of Krita, we can't determine whether it uses genuine %AppData% or the private Windows Store one
271 // so, half of the time, a custom folder inside %AppData% wouldn't work
272 // we can't fix that, we can only inform users about it or prevent them from choosing such folder
273 // in any case, here we need to return both folders: inside normal appdata and the private one
274 // (note that this case also handles the default resource folder called "krita" inside the appdata)
275
276
277 const QString folderName = QFileInfo(resourcePath).fileName();
278
279 const QString privateAppData = KisWindowsPackageUtils::getPackageRoamingAppDataLocation();
280 const QDir privateResourceDir(QDir::fromNativeSeparators(privateAppData) + '/' + folderName);
281
282 standardLocation = resourcePath;
283
284 if (privateResourceDir.exists()) {
285 privateLocation = privateResourceDir.absolutePath();
286 }
287
288 return;
289
290 } else {
291 standardLocation = resourcePath; // custom folder not inside AppData, so no problem (hopefully)
292 return;
293 }
294
295#endif
296}
static KisResourceLocator * instance()

References KisWindowsPackageUtils::getPackageRoamingAppDataLocation(), KisResourceLocator::instance(), and KisWindowsPackageUtils::isRunningInPackage().

◆ getAppDataLocation()

QString KoResourcePaths::getAppDataLocation ( )
static

Definition at line 219 of file KoResourcePaths.cpp.

220{
221 if (!s_overrideAppDataLocation.isEmpty()) {
223 }
224
225 QString path;
226
227 KConfigGroup cfg(KSharedConfig::openConfig(), "");
228 path = cfg.readEntry(KisResourceLocator::resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
229
230 QFileInfo fi(path);
231
232 // Check whether an existing location is writable
233 if (fi.exists() && !fi.isWritable()) {
234 path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
235 }
236 else if (!fi.exists()) {
237 // Check whether a non-existing location can be created
238 if (!QDir().mkpath(path)) {
239 path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
240 }
241 QDir().rmpath(path);
242 }
243 return path;
244
245
246}
static QString s_overrideAppDataLocation
getAppDataLocation Use this instead of QStandardPaths::AppDataLocation! The user can configure the lo...

References KisResourceLocator::resourceLocationKey, and s_overrideAppDataLocation.

◆ getApplicationRoot()

QString KoResourcePaths::getApplicationRoot ( )
static

Definition at line 214 of file KoResourcePaths.cpp.

215{
216 return getInstallationPrefix();
217}

◆ locate()

QString KoResourcePaths::locate ( const QString & type,
const QString & filename )
static

This function is just for convenience. It simply calls KoResourcePaths::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 336 of file KoResourcePaths.cpp.

337{
338 return cleanup(s_instance->locateInternal(type, filename));
339}

◆ locateInternal()

QString KoResourcePaths::locateInternal ( const QString & type,
const QString & filename )
private

Definition at line 685 of file KoResourcePaths.cpp.

686{
687 QStringList aliases = d->aliases(type);
688
689 QStringList locations;
690 if (aliases.isEmpty()) {
691 locations << QStandardPaths::locate(d->mapTypeToQStandardPaths(type), filename, QStandardPaths::LocateFile);
692 }
693
694 Q_FOREACH (const QString &alias, aliases) {
695 locations << QStandardPaths::locate(d->mapTypeToQStandardPaths(type),
696 (alias.endsWith('/') ? alias : alias + '/') + filename, QStandardPaths::LocateFile);
697 }
698 dbgResources << "locate: type" << type << "filename" << filename << "locations" << locations;
699 if (locations.size() > 0) {
700 return locations.first();
701 }
702 else {
703 return "";
704 }
705}

References aliases(), d, and dbgResources.

◆ locateLocal()

QString KoResourcePaths::locateLocal ( const QString & type,
const QString & filename,
bool createDir = false )
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 341 of file KoResourcePaths.cpp.

342{
343 return cleanup(s_instance->locateLocalInternal(type, filename, createDir));
344}

◆ locateLocalInternal()

QString KoResourcePaths::locateLocalInternal ( const QString & type,
const QString & filename,
bool createDir = false )
private

Definition at line 707 of file KoResourcePaths.cpp.

708{
709 QString path = saveLocationInternal(type, "", createDir);
710 dbgResources << "locateLocal: type" << type << "filename" << filename << "CreateDir" << createDir << "path" << path;
711 return path + '/' + filename;
712}
QString saveLocationInternal(const QString &type, const QString &suffix=QString(), bool create=true)

References dbgResources, and saveLocationInternal().

◆ mapTypeToQStandardPaths()

QStandardPaths::StandardLocation KoResourcePaths::mapTypeToQStandardPaths ( const QString & type)
inline

Definition at line 182 of file KoResourcePaths.cpp.

183 {
184 if (type == "appdata") {
185 return QStandardPaths::AppDataLocation;
186 }
187 else if (type == "data") {
188 return QStandardPaths::AppDataLocation;
189 }
190 else if (type == "cache") {
191 return QStandardPaths::CacheLocation;
192 }
193 else if (type == "locale") {
194 return QStandardPaths::AppDataLocation;
195 }
196 else if (type == "genericdata") {
197 return QStandardPaths::GenericDataLocation;
198 }
199 else {
200 return QStandardPaths::AppDataLocation;
201 }
202 }

◆ resourceDirsInternal()

QStringList KoResourcePaths::resourceDirsInternal ( const QString & type)
private

Definition at line 618 of file KoResourcePaths.cpp.

619{
620 QStringList resourceDirs;
621 QStringList aliases = d->aliases(type);
622
623 Q_FOREACH (const QString &alias, aliases) {
624 QStringList aliasDirs;
625
626 aliasDirs << QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), alias, QStandardPaths::LocateDirectory);
627
628 aliasDirs << getInstallationPrefix() + "share/" + alias + "/"
629 << QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), alias, QStandardPaths::LocateDirectory);
630 aliasDirs << getInstallationPrefix() + "share/krita/" + alias + "/"
631 << QStandardPaths::locateAll(d->mapTypeToQStandardPaths(type), alias, QStandardPaths::LocateDirectory);
632
633 appendResources(&resourceDirs, aliasDirs, true);
634 }
635
636 dbgResources << "resourceDirs: type" << type << resourceDirs;
637
638 return resourceDirs;
639}

References aliases(), d, and dbgResources.

◆ saveLocation()

QString KoResourcePaths::saveLocation ( const QString & type,
const QString & suffix = QString(),
bool create = true )
static

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 331 of file KoResourcePaths.cpp.

332{
333 return QDir::cleanPath(s_instance->saveLocationInternal(type, suffix, create)) + '/';
334}

◆ saveLocationInternal()

QString KoResourcePaths::saveLocationInternal ( const QString & type,
const QString & suffix = QString(),
bool create = true )
private

Definition at line 641 of file KoResourcePaths.cpp.

642{
643 QString path;
644
645 bool useStandardLocation = false;
646 const QStringList aliases = d->aliases(type);
647 const QStandardPaths::StandardLocation location = d->mapTypeToQStandardPaths(type);
648
649 if (location == QStandardPaths::AppDataLocation) {
650 KConfigGroup cfg(KSharedConfig::openConfig(), "");
651 path = cfg.readEntry(KisResourceLocator::resourceLocationKey, "");
652 }
653
654 if (path.isEmpty()) {
655 path = QStandardPaths::writableLocation(location);
656 useStandardLocation = true;
657 }
658
659#ifndef Q_OS_ANDROID
660 // on Android almost all config locations we save to are app specific,
661 // and don't end with "krita".
662 if (!path.endsWith("krita") && useStandardLocation) {
663 path += "/krita";
664 }
665#endif
666
667 if (!aliases.isEmpty()) {
668 path += '/' + aliases.first();
669 } else {
670
671 if (!suffix.isEmpty()) {
672 path += "/" + suffix;
673 }
674 }
675
676 QDir d(path);
677 if (!d.exists() && create) {
678 d.mkpath(path);
679 }
680 dbgResources << "saveLocation: type" << type << "suffix" << suffix << "create" << create << "path" << path;
681
682 return path;
683}
QPainterPath create(const char32_t codepoint, double height)
Creates a tofu missing glyph indicator representing the provided Unicode codepoint.

References aliases(), d, dbgResources, and KisResourceLocator::resourceLocationKey.

Member Data Documentation

◆ absolutes

QMap<QString, QStringList> KoResourcePaths::absolutes

Definition at line 158 of file KoResourcePaths.cpp.

◆ absolutesMutex

QMutex KoResourcePaths::absolutesMutex

Definition at line 162 of file KoResourcePaths.cpp.

◆ d

QScopedPointer<Private> KoResourcePaths::d
private

Definition at line 265 of file KoResourcePaths.h.

◆ relatives

QMap<QString, QStringList> KoResourcePaths::relatives

Definition at line 159 of file KoResourcePaths.cpp.

◆ relativesMutex

QMutex KoResourcePaths::relativesMutex

Definition at line 161 of file KoResourcePaths.cpp.

◆ s_overrideAppDataLocation

QString KoResourcePaths::s_overrideAppDataLocation
static

getAppDataLocation Use this instead of QStandardPaths::AppDataLocation! The user can configure the location where resources and other user writable items are stored now.

Returns
the configured location for the appdata folder

Definition at line 62 of file KoResourcePaths.h.


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