1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36#include "qabstractgeotilecache_p.h"
37
38#include "qgeotilespec_p.h"
39
40#include "qgeomappingmanager_p.h"
41
42#include <QDir>
43#include <QStandardPaths>
44#include <QMetaType>
45#include <QPixmap>
46#include <QDebug>
47
48Q_DECLARE_METATYPE(QList<QGeoTileSpec>)
49Q_DECLARE_METATYPE(QSet<QGeoTileSpec>)
50
51QT_BEGIN_NAMESPACE
52
53QGeoTileTexture::QGeoTileTexture()
54 : textureBound(false) {}
55
56QGeoTileTexture::~QGeoTileTexture()
57{
58}
59
60QAbstractGeoTileCache::QAbstractGeoTileCache(QObject *parent)
61 : QObject(parent)
62{
63 qRegisterMetaType<QGeoTileSpec>();
64 qRegisterMetaType<QList<QGeoTileSpec> >();
65 qRegisterMetaType<QSet<QGeoTileSpec> >();
66}
67
68QAbstractGeoTileCache::~QAbstractGeoTileCache()
69{
70}
71
72void QAbstractGeoTileCache::printStats()
73{
74}
75
76void QAbstractGeoTileCache::handleError(const QGeoTileSpec &, const QString &error)
77{
78 qWarning() << "tile request error " << error;
79}
80
81void QAbstractGeoTileCache::setMaxDiskUsage(int diskUsage)
82{
83 Q_UNUSED(diskUsage);
84}
85
86int QAbstractGeoTileCache::maxDiskUsage() const
87{
88 return 0;
89}
90
91int QAbstractGeoTileCache::diskUsage() const
92{
93 return 0;
94}
95
96void QAbstractGeoTileCache::setMaxMemoryUsage(int memoryUsage)
97{
98 Q_UNUSED(memoryUsage);
99}
100
101int QAbstractGeoTileCache::maxMemoryUsage() const
102{
103 return 0;
104}
105
106int QAbstractGeoTileCache::memoryUsage() const
107{
108 return 0;
109}
110
111QString QAbstractGeoTileCache::baseCacheDirectory()
112{
113 QString dir;
114
115 // Try the shared cache first and use a specific directory. (e.g. ~/.cache/QtLocation)
116 // If this is not supported by the platform, use the application-specific cache
117 // location. (e.g. ~/.cache/<app_name>/QtLocation)
118 dir = QStandardPaths::writableLocation(type: QStandardPaths::GenericCacheLocation);
119
120 if (!dir.isEmpty()) {
121 // The shared cache may not be writable when application isolation is enforced.
122 static bool writable = false;
123 static bool writableChecked = false;
124 if (!writableChecked) {
125 writableChecked = true;
126 QDir::root().mkpath(dirPath: dir);
127 QFile writeTestFile(QDir(dir).filePath(QStringLiteral("qt_cache_check")));
128 writable = writeTestFile.open(flags: QIODevice::WriteOnly);
129 if (writable)
130 writeTestFile.remove();
131 }
132 if (!writable)
133 dir = QString();
134 }
135
136 if (dir.isEmpty())
137 dir = QStandardPaths::writableLocation(type: QStandardPaths::CacheLocation);
138
139 if (!dir.endsWith(c: QLatin1Char('/')))
140 dir += QLatin1Char('/');
141
142 return dir;
143}
144
145QString QAbstractGeoTileCache::baseLocationCacheDirectory()
146{
147 // This scheme allows to have the "tiles" prefix hardcoded here
148 // NOTE: changing the Qt version here requires changing it also in QGeoFileTileCache::init,
149 // in the code that remove old version tiles !
150 return baseCacheDirectory() + QLatin1String("QtLocation/5.8/tiles/");
151}
152
153QT_END_NAMESPACE
154

source code of qtlocation/src/location/maps/qabstractgeotilecache.cpp