forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geocache.cc
153 lines (132 loc) · 4.33 KB
/
geocache.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright (C) 2002-2023 Robert Lipe, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "geocache.h"
#include <QString> // for QString
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include "defs.h" // for strip_html, global_options, global_opts
const QVector<Geocache::type_mapping> Geocache::type_map = {
{type_t::gt_traditional, "Traditional Cache" },
{type_t::gt_traditional, "Traditional" }, /* opencaching.de */
{type_t::gt_multi, "Multi-cache" },
{type_t::gt_multi, "Multi" }, /* opencaching.de */
{type_t::gt_virtual, "Virtual Cache" },
{type_t::gt_virtual, "Virtual" }, /* opencaching.de */
{type_t::gt_event, "Event Cache" },
{type_t::gt_event, "Event" }, /* opencaching.de */
{type_t::gt_webcam, "Webcam Cache" },
{type_t::gt_webcam, "Webcam" }, /* opencaching.de */
{type_t::gt_surprise, "Unknown Cache" },
{type_t::gt_earth, "Earthcache" },
{type_t::gt_earth, "Earth" }, /* opencaching.de */
{type_t::gt_cito, "Cache In Trash Out Event" },
{type_t::gt_letterbox, "Letterbox Hybrid" },
{type_t::gt_locationless, "Locationless (Reverse) Cache" },
{type_t::gt_ape, "Project APE Cache" },
{type_t::gt_mega, "Mega-Event Cache" },
{type_t::gt_wherigo, "Wherigo Cache" },
{type_t::gt_benchmark, "Benchmark" } /* Not Groundspeak; for GSAK */
};
const QVector<Geocache::container_mapping> Geocache::container_map = {
{container_t::gc_other, "Unknown" },
{container_t::gc_other, "Other" }, /* Synonym on read. */
{container_t::gc_micro, "Micro" },
{container_t::gc_regular, "Regular" },
{container_t::gc_large, "Large" },
{container_t::gc_small, "Small" },
{container_t::gc_virtual, "Virtual" }
};
QString Geocache::UtfString::strip_html() const
{
return is_html? ::strip_html(utf_string) : utf_string;
}
void Geocache::set_type(const QString& type_name)
{
for (const auto& map_entry : type_map) {
if (!type_name.compare(map_entry.name,Qt::CaseInsensitive)) {
type = map_entry.type;
return;
}
}
type = type_t::gt_unknown;
}
QString Geocache::get_type() const
{
for (const auto& map_entry : type_map) {
if (type == map_entry.type) {
return map_entry.name;
}
}
return "Unknown";
}
void Geocache::set_container(const QString& container_name)
{
for (const auto& map_entry : container_map) {
if (!container_name.compare(map_entry.name,Qt::CaseInsensitive)) {
container = map_entry.container;
return;
}
}
container = container_t::gc_unknown;
}
QString Geocache::get_container() const
{
for (const auto& map_entry : container_map) {
if (container == map_entry.container) {
return map_entry.name;
}
}
return "Unknown";
}
/*
* Return a QString that is suitable for icon lookup based on geocache
* attributes. The strings used are those present in a GPX file from
* geocaching.com. Thus we sort of make all the other formats do lookups
* based on these strings.
*/
QString Geocache::get_icon() const
{
if (!global_opts.smart_icons) {
return nullptr;
}
/*
* For icons, type overwrites container. So a multi-micro will
* get the icons for "multi".
*/
switch (type) {
case type_t::gt_virtual:
return "Virtual cache";
case type_t::gt_multi:
return "Multi-Cache";
case type_t::gt_event:
return "Event Cache";
case type_t::gt_surprise:
return "Unknown Cache";
case type_t::gt_webcam:
return "Webcam Cache";
default:
break;
}
switch (container) {
case container_t::gc_micro:
return "Micro-Cache";
default:
break;
}
if (diff > 1) {
return "Geocache";
}
return nullptr;
}