summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-09-14 12:15:17 +0200
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-09-15 14:44:40 +0000
commita99b8ced41b2c634598ce70fe69036a0ed34e9ba (patch)
treeaf55c8822257652f1334fc28403b35c77dcc4d3e
parentd1964046bc55e5b4d99a509c6329f549c47d3f77 (diff)
downloadqtlocation-a99b8ced41b2c634598ce70fe69036a0ed34e9ba.tar.gz
Isolate the default cache directory
Instead of having it in several random places, have a central function that contains all the cache directory selection logic. As per QtCore docs GenericCacheLocation can be empty so introduce a fallback to CacheLocation (the app-specific, non-shared location) in case some future platform does not support the former. Task-number: QTBUG-41187 Change-Id: Icfe5e8926e917483ac11844f625244318ff815c7 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/location/doc/src/plugins/nokia.qdoc4
-rw-r--r--src/location/doc/src/plugins/osm.qdoc8
-rw-r--r--src/location/maps/qgeotilecache.cpp30
-rw-r--r--src/location/maps/qgeotilecache_p.h2
-rw-r--r--src/location/maps/qgeotiledmappingmanagerengine.cpp6
-rw-r--r--src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp3
6 files changed, 38 insertions, 15 deletions
diff --git a/src/location/doc/src/plugins/nokia.qdoc b/src/location/doc/src/plugins/nokia.qdoc
index f1a6828a..1ed5e6e1 100644
--- a/src/location/doc/src/plugins/nokia.qdoc
+++ b/src/location/doc/src/plugins/nokia.qdoc
@@ -92,7 +92,9 @@ a prefix.
\li here.mapping.cache.directory
\li Absolute path to map tile cache directory used as network disk cache.
- Default place for the cache is "QtLocation" directory in \l {QStandardPaths::writableLocation()} {QStandardPaths::writableLocation}(\l{QStandardPaths::GenericCacheLocation}).
+ The default place for the cache is \c{QtLocation/here} directory in \l {QStandardPaths::writableLocation()} {QStandardPaths::writableLocation}(\l{QStandardPaths::GenericCacheLocation}).
+ On systems that have no concept of a shared cache, the application-specific \l{QStandardPaths::CacheLocation} is used instead.
+
\row
\li here.mapping.cache.disk.size
\li Map tile disk cache size in bytes. Default size of the cache is 20MB.
diff --git a/src/location/doc/src/plugins/osm.qdoc b/src/location/doc/src/plugins/osm.qdoc
index f6de9c20..1c924fd3 100644
--- a/src/location/doc/src/plugins/osm.qdoc
+++ b/src/location/doc/src/plugins/osm.qdoc
@@ -106,4 +106,12 @@ Plugin {
PluginParameter { name: "osm.geocoding.host"; value: "http://geocoding.server.address" }
}
\endcode
+
+\section1 Other Plugin-specific Information
+
+\section2 Tile cache
+
+The tiles are cached in a \c{QtLocation/osm} directory in \l {QStandardPaths::writableLocation()}{QStandardPaths::writableLocation}
+(\l{QStandardPaths::GenericCacheLocation}). On systems that have no concept of a shared cache, the application-specific
+\l{QStandardPaths::CacheLocation} is used instead.
*/
diff --git a/src/location/maps/qgeotilecache.cpp b/src/location/maps/qgeotilecache.cpp
index 4e15504d..3da2865b 100644
--- a/src/location/maps/qgeotilecache.cpp
+++ b/src/location/maps/qgeotilecache.cpp
@@ -100,14 +100,10 @@ QGeoTileCache::QGeoTileCache(const QString &directory, QObject *parent)
qRegisterMetaType<QList<QGeoTileSpec> >();
qRegisterMetaType<QSet<QGeoTileSpec> >();
- // We keep default values here so that they are in one place
- // rather than in each individual plugin (the plugins can
- // of course override them)
-
- const QString basePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)
- + QLatin1String("/QtLocation");
+ const QString basePath = baseCacheDirectory();
// delete old tiles from QtLocation 5.4 or prior
+ // Newer version use plugin-specific subdirectories so those are not affected.
// TODO Remove cache cleanup in Qt 6
QDir baseDir(basePath);
if (baseDir.exists()) {
@@ -118,8 +114,7 @@ QGeoTileCache::QGeoTileCache(const QString &directory, QObject *parent)
if (directory_.isEmpty()) {
directory_ = basePath;
- qWarning() << "Plugin uses uninitialized directory for QGeoTileCache"
- " which will was deleted during startup";
+ qWarning() << "Plugin uses uninitialized QGeoTileCache directory which was deleted during startup";
}
QDir::root().mkpath(directory_);
@@ -465,4 +460,23 @@ QGeoTileSpec QGeoTileCache::filenameToTileSpec(const QString &filename)
numbers.at(4));
}
+QString QGeoTileCache::baseCacheDirectory()
+{
+ QString dir;
+
+ // Try the shared cache first and use a specific directory. (e.g. ~/.cache/QtLocation)
+ // If this is not supported by the platform, use the application-specific cache
+ // location. (e.g. ~/.cache/<app_name>/QtLocation)
+ dir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation);
+ if (dir.isEmpty())
+ dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+
+ if (!dir.endsWith(QLatin1Char('/')))
+ dir += QLatin1Char('/');
+
+ dir += QLatin1String("QtLocation/");
+
+ return dir;
+}
+
QT_END_NAMESPACE
diff --git a/src/location/maps/qgeotilecache_p.h b/src/location/maps/qgeotilecache_p.h
index 9cf31db0..d9f7bce9 100644
--- a/src/location/maps/qgeotilecache_p.h
+++ b/src/location/maps/qgeotilecache_p.h
@@ -141,6 +141,8 @@ public:
QGeoTiledMappingManagerEngine::CacheAreas areas = QGeoTiledMappingManagerEngine::AllCaches);
void handleError(const QGeoTileSpec &spec, const QString &errorString);
+ static QString baseCacheDirectory();
+
public Q_SLOTS:
void printStats();
diff --git a/src/location/maps/qgeotiledmappingmanagerengine.cpp b/src/location/maps/qgeotiledmappingmanagerengine.cpp
index b9322c13..43f56872 100644
--- a/src/location/maps/qgeotiledmappingmanagerengine.cpp
+++ b/src/location/maps/qgeotiledmappingmanagerengine.cpp
@@ -288,10 +288,8 @@ QGeoTileCache *QGeoTiledMappingManagerEngine::tileCache()
Q_D(QGeoTiledMappingManagerEngine);
if (!d->tileCache_) {
QString cacheDirectory;
- if (!managerName().isEmpty()) {
- cacheDirectory = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)
- + QLatin1String("/QtLocation/") + managerName();
- }
+ if (!managerName().isEmpty())
+ cacheDirectory = QGeoTileCache::baseCacheDirectory() + managerName();
d->tileCache_ = new QGeoTileCache(cacheDirectory);
}
return d->tileCache_;
diff --git a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
index 54bf29af..1b1163a6 100644
--- a/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
+++ b/src/plugins/geoservices/nokia/qgeotiledmappingmanagerengine_nokia.cpp
@@ -106,8 +106,7 @@ QGeoTiledMappingManagerEngineNokia::QGeoTiledMappingManagerEngineNokia(
cacheDir = parameters.value(QStringLiteral("here.mapping.cache.directory")).toString();
} else {
// managerName() is not yet set, we have to hardcode the plugin name below
- cacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)
- + QLatin1String("/QtLocation/here");
+ cacheDir = QGeoTileCache::baseCacheDirectory() + QLatin1String("here");
}
QGeoTileCache *tileCache = createTileCacheWithDir(cacheDir);