diff options
Diffstat (limited to 'src/location/maps/qgeotilecache.cpp')
-rw-r--r-- | src/location/maps/qgeotilecache.cpp | 30 |
1 files changed, 22 insertions, 8 deletions
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 |