1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 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 | |
37 | #include "qgeofiletilecachenokia.h" |
38 | #include <QtLocation/private/qgeotilespec_p.h> |
39 | #include <QDir> |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | QGeoFileTileCacheNokia::QGeoFileTileCacheNokia(int ppi, const QString &directory, QObject *parent) |
44 | :QGeoFileTileCache(directory, parent) |
45 | { |
46 | m_ppi = QString::number(ppi) + QLatin1String("p" ); |
47 | } |
48 | |
49 | QGeoFileTileCacheNokia::~QGeoFileTileCacheNokia() |
50 | { |
51 | |
52 | } |
53 | |
54 | QString QGeoFileTileCacheNokia::tileSpecToFilename(const QGeoTileSpec &spec, const QString &format, const QString &directory) const |
55 | { |
56 | QString filename = spec.plugin(); |
57 | filename += QLatin1String("-" ); |
58 | filename += QString::number(spec.mapId()); |
59 | filename += QLatin1String("-" ); |
60 | filename += QString::number(spec.zoom()); |
61 | filename += QLatin1String("-" ); |
62 | filename += QString::number(spec.x()); |
63 | filename += QLatin1String("-" ); |
64 | filename += QString::number(spec.y()); |
65 | |
66 | //Append version if real version number to ensure backwards compatibility and eviction of old tiles |
67 | if (spec.version() != -1) { |
68 | filename += QLatin1String("-" ); |
69 | filename += QString::number(spec.version()); |
70 | } |
71 | |
72 | filename += QLatin1String("-" ); |
73 | filename += m_ppi; |
74 | |
75 | filename += QLatin1String("." ); |
76 | filename += format; |
77 | |
78 | QDir dir = QDir(directory); |
79 | |
80 | return dir.filePath(fileName: filename); |
81 | } |
82 | |
83 | QGeoTileSpec QGeoFileTileCacheNokia::filenameToTileSpec(const QString &filename) const |
84 | { |
85 | QGeoTileSpec emptySpec; |
86 | |
87 | QStringList parts = filename.split(sep: '.'); |
88 | |
89 | if (parts.length() != 2) |
90 | return emptySpec; |
91 | |
92 | QString name = parts.at(i: 0); |
93 | QStringList fields = name.split(sep: '-'); |
94 | |
95 | int length = fields.length(); |
96 | if (length != 6 && length != 7) |
97 | return emptySpec; |
98 | else if (fields.last() != m_ppi) |
99 | return QGeoTileSpec(); |
100 | |
101 | QList<int> numbers; |
102 | |
103 | bool ok = false; |
104 | for (int i = 1; i < length-1; ++i) { // skipping -<ppi> |
105 | ok = false; |
106 | int value = fields.at(i).toInt(ok: &ok); |
107 | if (!ok) |
108 | return emptySpec; |
109 | numbers.append(t: value); |
110 | } |
111 | |
112 | //File name without version, append default |
113 | if (numbers.length() < 5) |
114 | numbers.append(t: -1); |
115 | |
116 | return QGeoTileSpec(fields.at(i: 0), |
117 | numbers.at(i: 0), |
118 | numbers.at(i: 1), |
119 | numbers.at(i: 2), |
120 | numbers.at(i: 3), |
121 | numbers.at(i: 4)); |
122 | } |
123 | |
124 | QT_END_NAMESPACE |
125 | |