QStandardPaths: add GenericCacheLocation.

Much like DataLocation = GenericDataLocation + domain + appname,
this makes CacheLocation = GenericCacheLocation + domain + appname.
This way a framework library can have an application-independent cache
(like ksycoca).

Change-Id: I6a8c47ff85b7d5c68b594cc8b071a752d96b029d
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2012-01-02 23:36:05 +01:00 committed by Qt by Nokia
parent bff6cf7b5b
commit 053676a80e
5 changed files with 17 additions and 6 deletions

View File

@ -83,6 +83,8 @@ QT_BEGIN_NAMESPACE
returned for GenericDataLocation. returned for GenericDataLocation.
\value CacheLocation Returns a directory location where user-specific \value CacheLocation Returns a directory location where user-specific
non-essential (cached) data should be written. non-essential (cached) data should be written.
\value GenericCacheLocation Returns a directory location where user-specific
non-essential (cached) data, shared across applications, should be written.
\value GenericDataLocation Returns a directory location where persistent \value GenericDataLocation Returns a directory location where persistent
data shared across applications can be stored. data shared across applications can be stored.
\value RuntimeLocation Returns a directory location where runtime communication \value RuntimeLocation Returns a directory location where runtime communication

View File

@ -73,7 +73,8 @@ public:
GenericDataLocation, GenericDataLocation,
RuntimeLocation, RuntimeLocation,
ConfigLocation, ConfigLocation,
DownloadLocation DownloadLocation,
GenericCacheLocation
}; };
static QString writableLocation(StandardLocation type); static QString writableLocation(StandardLocation type);

View File

@ -82,6 +82,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type)
case QStandardPaths::RuntimeLocation: case QStandardPaths::RuntimeLocation:
case QStandardPaths::DataLocation: case QStandardPaths::DataLocation:
return kApplicationSupportFolderType; return kApplicationSupportFolderType;
case QStandardPaths::GenericCacheLocation:
case QStandardPaths::CacheLocation: case QStandardPaths::CacheLocation:
return kCachedDataFolderType; return kCachedDataFolderType;
default: default:
@ -128,6 +129,7 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return QDir::tempPath(); return QDir::tempPath();
case GenericDataLocation: case GenericDataLocation:
case DataLocation: case DataLocation:
case GenericCacheLocation:
case CacheLocation: case CacheLocation:
case RuntimeLocation: case RuntimeLocation:
return macLocation(type, kUserDomain); return macLocation(type, kUserDomain);
@ -140,7 +142,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
{ {
QStringList dirs; QStringList dirs;
if (type == GenericDataLocation || type == DataLocation || type == CacheLocation) { if (type == GenericDataLocation || type == DataLocation || type == GenericCacheLocation || type == CacheLocation) {
const QString path = macLocation(type, kOnAppropriateDisk); const QString path = macLocation(type, kOnAppropriateDisk);
if (!path.isEmpty()) if (!path.isEmpty())
dirs.append(path); dirs.append(path);

View File

@ -62,15 +62,18 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case TempLocation: case TempLocation:
return QDir::tempPath(); return QDir::tempPath();
case CacheLocation: case CacheLocation:
case GenericCacheLocation:
{ {
// http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
if (xdgCacheHome.isEmpty()) if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
if (!QCoreApplication::organizationName().isEmpty()) if (type == QStandardPaths::CacheLocation) {
xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName(); if (!QCoreApplication::organizationName().isEmpty())
if (!QCoreApplication::applicationName().isEmpty()) xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName();
xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName(); if (!QCoreApplication::applicationName().isEmpty())
xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName();
}
return xdgCacheHome; return xdgCacheHome;
} }
case DataLocation: case DataLocation:

View File

@ -160,6 +160,9 @@ QString QStandardPaths::writableLocation(StandardLocation type)
// cache directory located in their AppData directory // cache directory located in their AppData directory
return writableLocation(DataLocation) + QLatin1String("\\cache"); return writableLocation(DataLocation) + QLatin1String("\\cache");
case GenericCacheLocation:
return writableLocation(GenericDataLocation) + QLatin1String("\\cache");
case RuntimeLocation: case RuntimeLocation:
case HomeLocation: case HomeLocation:
result = QDir::homePath(); result = QDir::homePath();