From 053676a80e6fd3d415fd1915968b22bd5fb87704 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 2 Jan 2012 23:36:05 +0100 Subject: [PATCH] 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 Reviewed-by: Thiago Macieira --- src/corelib/io/qstandardpaths.cpp | 2 ++ src/corelib/io/qstandardpaths.h | 3 ++- src/corelib/io/qstandardpaths_mac.cpp | 4 +++- src/corelib/io/qstandardpaths_unix.cpp | 11 +++++++---- src/corelib/io/qstandardpaths_win.cpp | 3 +++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 43ae5c07ab..2f5a01a7b5 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -83,6 +83,8 @@ QT_BEGIN_NAMESPACE returned for GenericDataLocation. \value CacheLocation Returns a directory location where user-specific 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 data shared across applications can be stored. \value RuntimeLocation Returns a directory location where runtime communication diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h index d91da9de2f..af74bfec10 100644 --- a/src/corelib/io/qstandardpaths.h +++ b/src/corelib/io/qstandardpaths.h @@ -73,7 +73,8 @@ public: GenericDataLocation, RuntimeLocation, ConfigLocation, - DownloadLocation + DownloadLocation, + GenericCacheLocation }; static QString writableLocation(StandardLocation type); diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index 84fc81494c..104ba221fa 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -82,6 +82,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type) case QStandardPaths::RuntimeLocation: case QStandardPaths::DataLocation: return kApplicationSupportFolderType; + case QStandardPaths::GenericCacheLocation: case QStandardPaths::CacheLocation: return kCachedDataFolderType; default: @@ -128,6 +129,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) return QDir::tempPath(); case GenericDataLocation: case DataLocation: + case GenericCacheLocation: case CacheLocation: case RuntimeLocation: return macLocation(type, kUserDomain); @@ -140,7 +142,7 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; - if (type == GenericDataLocation || type == DataLocation || type == CacheLocation) { + if (type == GenericDataLocation || type == DataLocation || type == GenericCacheLocation || type == CacheLocation) { const QString path = macLocation(type, kOnAppropriateDisk); if (!path.isEmpty()) dirs.append(path); diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index b1c5869f71..4a4b5049aa 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -62,15 +62,18 @@ QString QStandardPaths::writableLocation(StandardLocation type) case TempLocation: return QDir::tempPath(); case CacheLocation: + case GenericCacheLocation: { // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); if (xdgCacheHome.isEmpty()) xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); - if (!QCoreApplication::organizationName().isEmpty()) - xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName(); - if (!QCoreApplication::applicationName().isEmpty()) - xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName(); + if (type == QStandardPaths::CacheLocation) { + if (!QCoreApplication::organizationName().isEmpty()) + xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName(); + if (!QCoreApplication::applicationName().isEmpty()) + xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName(); + } return xdgCacheHome; } case DataLocation: diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index e9093649f3..7b21363858 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -160,6 +160,9 @@ QString QStandardPaths::writableLocation(StandardLocation type) // cache directory located in their AppData directory return writableLocation(DataLocation) + QLatin1String("\\cache"); + case GenericCacheLocation: + return writableLocation(GenericDataLocation) + QLatin1String("\\cache"); + case RuntimeLocation: case HomeLocation: result = QDir::homePath();