From 70e7f1aa6d1c742e132373f38a18e0f70c1a89df Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 2 Jan 2023 10:30:56 -0700 Subject: [PATCH] Make geocache a real class. (#968) --- CMakeLists.txt | 2 + defs.h | 102 ++-------------------------- duplicate.cc | 15 +++-- duplicate.h | 3 +- garmin.cc | 76 ++++++++++++--------- geo.cc | 37 +++++----- geocache.cc | 153 +++++++++++++++++++++++++++++++++++++++++ geocache.h | 146 +++++++++++++++++++++++++++++++++++++++ gpx.cc | 180 ++++++++++++------------------------------------- gpx.h | 27 ++++---- html.cc | 13 ++-- kml.cc | 112 +++++++++++++++--------------- lowranceusr.cc | 63 ++++++++--------- mkshort.cc | 1 + osm.cc | 3 +- sort.cc | 5 +- sort.h | 3 +- text.cc | 13 ++-- unicsv.cc | 44 ++++++------ unicsv.h | 3 +- util.cc | 60 ++--------------- vcf.cc | 19 +++--- waypt.cc | 11 +-- xcsv.cc | 103 ++++++++++++++-------------- 24 files changed, 644 insertions(+), 550 deletions(-) create mode 100644 geocache.cc create mode 100644 geocache.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 00536ca5e..0c4448d50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ set(ALL_FMTS ${MINIMAL_FMTS} garmin_txt.cc garmin_xt.cc gdb.cc + geocache.cc geojson.cc globalsat_sport.cc gpssim.cc @@ -221,6 +222,7 @@ set(HEADERS gbser.h gbser_private.h gdb.h + geocache.h geojson.h globalsat_sport.h gpx.h diff --git a/defs.h b/defs.h index 030880260..fe74f4f74 100644 --- a/defs.h +++ b/defs.h @@ -39,6 +39,7 @@ #include // for CaseInsensitive #include // for QForeachContainer, qMakeForeachContainer, foreach, qint64 +#include "geocache.h" // for Geocache #include "formspec.h" // for FormatSpecificData #include "inifile.h" // for inifile_t #include "session.h" // for session_t @@ -198,93 +199,6 @@ enum fix_type { fix_pps }; -enum status_type { - status_unknown=0, - status_true, - status_false -}; - -/* - * Extended data if waypoint happens to represent a geocache. This is - * totally voluntary data... - */ - -enum geocache_type { - gt_unknown = 0, - gt_traditional, - gt_multi, - gt_virtual, - gt_letterbox, - gt_event, - gt_surprise, - gt_webcam, - gt_earth, - gt_locationless, - gt_benchmark, /* Extension to Groundspeak for GSAK */ - gt_cito, - gt_ape, - gt_mega, - gt_wherigo -}; - -enum geocache_container { - gc_unknown = 0, - gc_micro, - gc_other, - gc_regular, - gc_large, - gc_virtual, - gc_small -}; - -class utf_string -{ -public: - utf_string() = default; - utf_string(bool html, QString str) : - is_html{html}, - utfstring{std::move(str)} - {} - bool is_html{false}; - QString utfstring; -}; - -class geocache_data -{ -public: - geocache_data() : - id(0), - type(gt_unknown), - container(gc_unknown), - diff(0), - terr(0), - is_archived(status_unknown), - is_available(status_unknown), - is_memberonly(status_unknown), - has_customcoords(status_unknown), - placer_id(0), - favorite_points(0) - {} - long long id; /* The decimal cache number */ - geocache_type type:5; - geocache_container container:4; - unsigned int diff:6; /* (multiplied by ten internally) */ - unsigned int terr:6; /* (likewise) */ - status_type is_archived:2; - status_type is_available:2; - status_type is_memberonly:2; - status_type has_customcoords:2; - gpsbabel::DateTime exported; - gpsbabel::DateTime last_found; - QString placer; /* Placer name */ - int placer_id; /* Placer id */ - QString hint; /* all these UTF8, XML entities removed, May be not HTML. */ - utf_string desc_short; - utf_string desc_long; - int favorite_points; - QString personal_note; -}; - class gb_color { public: @@ -422,7 +336,7 @@ struct bounds { class Waypoint { private: - static geocache_data empty_gc_data; + static Geocache empty_gc_data; public: @@ -501,7 +415,7 @@ class Waypoint float power; /* watts, as measured by cyclists */ float temperature; /* Degrees celsius */ float odometer_distance; /* Meters */ - geocache_data* gc_data; + Geocache* gc_data; FormatSpecificDataList fs; const session_t* session; /* pointer to a session struct */ void* extra_data; /* Extra data added by, say, a filter. */ @@ -519,7 +433,7 @@ class Waypoint gpsbabel::DateTime GetCreationTime() const; void SetCreationTime(const gpsbabel::DateTime& t); void SetCreationTime(qint64 t, qint64 ms = 0); - geocache_data* AllocGCData(); + Geocache* AllocGCData(); int EmptyGCData() const; }; @@ -893,9 +807,6 @@ using ff_exit = void (*)(); using ff_writeposn = void (*)(Waypoint*); using ff_readposn = Waypoint* (*)(posn_status*); -geocache_type gs_mktype(const QString& t); -geocache_container gs_mkcont(const QString& t); - /* * All shortname functions take a shortname handle as the first arg. * This is an opaque pointer. Callers must not fondle the contents of it. @@ -1072,10 +983,7 @@ time_t mkgmtime(struct tm* t); bool gpsbabel_testmode(); gpsbabel::DateTime current_time(); QDateTime dotnet_time_to_qdatetime(long long dotnet); -QString get_cache_icon(const Waypoint* waypointp); -QString gs_get_cachetype(geocache_type t); -QString gs_get_container(geocache_container t); -QString strip_html(const utf_string*); +QString strip_html(const QString& utfstring); QString strip_nastyhtml(const QString& in); QString convert_human_date_format(const char* human_datef); /* "MM,YYYY,DD" -> "%m,%Y,%d" */ QString convert_human_time_format(const char* human_timef); /* "HH+mm+ss" -> "%H+%M+%S" */ diff --git a/duplicate.cc b/duplicate.cc index 98f5d92d2..82f1eb929 100644 --- a/duplicate.cc +++ b/duplicate.cc @@ -19,16 +19,17 @@ */ -#include // for stable_sort -#include // for snprintf -#include // for memset, strncpy +#include "duplicate.h" + +#include // for stable_sort +#include // for snprintf +#include // for memset, strncpy -#include // for QDateTime -#include // for foreach +#include // for QDateTime #include "defs.h" -#include "duplicate.h" -#include "src/core/datetime.h" // for DateTime +#include "geocache.h" // for Geocache +#include "src/core/datetime.h" // for DateTime #if FILTERS_ENABLED diff --git a/duplicate.h b/duplicate.h index f9ba5b441..0fd5f85ca 100644 --- a/duplicate.h +++ b/duplicate.h @@ -22,7 +22,8 @@ #ifndef DUPLICATE_H_INCLUDED_ #define DUPLICATE_H_INCLUDED_ -#include // for QVector +#include // for QString +#include // for QVector #include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, Waypoint (ptr only) #include "filter.h" // for Filter diff --git a/garmin.cc b/garmin.cc index a7c0c43a2..14166c3eb 100644 --- a/garmin.cc +++ b/garmin.cc @@ -19,32 +19,42 @@ */ -#include // for isalpha, toupper -#include // for INT_MAX -#include // for atan2, floor, sqrt -#include // for setjmp -#include // for fprintf, fflush, snprintf, snprintf -#include // for strtol -#include // for memcpy, strlen, strncpy, strchr -#include // for time_t - -#include // for QByteArray -#include // for QChar -#include // for QString -#include // for CaseInsensitive -#include // for qPrintable, foreach +#include // for isalpha, toupper +#include // for INT_MAX +#include // for atan2, floor, sqrt +#include // for setjmp +#include // for fprintf, fflush, snprintf, snprintf +#include // for strtol +#include // for memcpy, strlen, strncpy, strchr +#include // for time_t + +#include // for QByteArray +#include // for QChar +#include // for QString +#include // for QVector +#include // for CaseInsensitive +#include // for qPrintable, foreach #include "defs.h" -#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8 -#include "format.h" // for Format -#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf -#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write -#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number -#include "grtcirc.h" // for DEG -#include "jeeps/gps.h" -#include "jeeps/gpsserial.h" -#include "src/core/datetime.h" // for DateTime -#include "vecs.h" // for Vecs +#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8 +#include "format.h" // for Format +#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf +#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write +#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number +#include "geocache.h" // for Geocache, Geocache::type_t, Geocache... +#include "grtcirc.h" // for DEG +#include "jeeps/gpsapp.h" // for GPS_Set_Baud_Rate, GPS_Init, GPS_Pre... +#include "jeeps/gpscom.h" // for GPS_Command_Get_Lap, GPS_Command_Get... +#include "jeeps/gpsdevice.h" // for gpsdevh +#include "jeeps/gpsmem.h" // for GPS_Track_Del, GPS_Way_Del, GPS_Pvt_Del +#include "jeeps/gpsport.h" // for int32 +#include "jeeps/gpsprot.h" // for gps_waypt_type, gps_category_type +#include "jeeps/gpssend.h" // for GPS_SWay, GPS_PWay, GPS_STrack, GPS_... +#include "jeeps/gpsserial.h" // for DEFAULT_BAUD +#include "jeeps/gpsutil.h" // for GPS_User, GPS_Enable_Diagnose, GPS_E... +#include "src/core/datetime.h" // for DateTime +#include "vecs.h" // for Vecs + #define MYNAME "GARMIN" static const char* portname; @@ -798,25 +808,25 @@ static const char* get_gc_info(const Waypoint* wpt) { if (global_opts.smart_names) { - if (wpt->gc_data->type == gt_virtual) { + if (wpt->gc_data->type == Geocache::type_t::gt_virtual) { return "V "; } - if (wpt->gc_data->type == gt_unknown) { + if (wpt->gc_data->type == Geocache::type_t::gt_unknown) { return "? "; } - if (wpt->gc_data->type == gt_multi) { + if (wpt->gc_data->type == Geocache::type_t::gt_multi) { return "Mlt "; } - if (wpt->gc_data->type == gt_earth) { + if (wpt->gc_data->type == Geocache::type_t::gt_earth) { return "EC "; } - if (wpt->gc_data->type == gt_event) { + if (wpt->gc_data->type == Geocache::type_t::gt_event) { return "Ev "; } - if (wpt->gc_data->container == gc_micro) { + if (wpt->gc_data->container == Geocache::container_t::gc_micro) { return "M "; } - if (wpt->gc_data->container == gc_small) { + if (wpt->gc_data->container == Geocache::container_t::gc_small) { return "S "; } } @@ -895,8 +905,8 @@ waypoint_prepare() if (deficon) { icon = gt_find_icon_number_from_desc(deficon, PCX); } else { - if (!get_cache_icon(wpt).isEmpty()) { - icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), PCX); + if (!wpt->gc_data->get_icon().isEmpty()) { + icon = gt_find_icon_number_from_desc(wpt->gc_data->get_icon(), PCX); } else { icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX); } diff --git a/geo.cc b/geo.cc index f9999afe1..cc435e3cb 100644 --- a/geo.cc +++ b/geo.cc @@ -29,6 +29,7 @@ #include "defs.h" #include "gbfile.h" // for gbfclose, gbfopen, gbfputs, gbfile +#include "geocache.h" // for Geocache, Geocache::container_t, Geo... #include "src/core/file.h" // for File @@ -50,7 +51,7 @@ QVector geo_args = { static QXmlStreamReader reader; static QString geo_read_fname; -static geocache_container wpt_container(const QString&); +static Geocache::container_t wpt_container(const QString&); static void GeoReadLoc() { @@ -126,34 +127,34 @@ geo_read() } } -geocache_container wpt_container(const QString& args) +Geocache::container_t wpt_container(const QString& args) { - geocache_container v; + Geocache::container_t v; switch (args.toInt()) { case 1: - v = gc_unknown; + v = Geocache::container_t::gc_unknown; break; case 2: - v = gc_micro; + v = Geocache::container_t::gc_micro; break; case 3: - v = gc_regular; + v = Geocache::container_t::gc_regular; break; case 4: - v = gc_large; + v = Geocache::container_t::gc_large; break; case 5: - v = gc_virtual; + v = Geocache::container_t::gc_virtual; break; case 6: - v = gc_other; + v = Geocache::container_t::gc_other; break; case 8: - v = gc_small; + v = Geocache::container_t::gc_small; break; default: - v = gc_unknown; + v = Geocache::container_t::gc_unknown; break; } return v; @@ -219,25 +220,25 @@ geo_waypt_pr(const Waypoint* waypointp) int v = 1; switch (waypointp->gc_data->container) { - case gc_unknown: + case Geocache::container_t::gc_unknown: v = 1; break; - case gc_micro: + case Geocache::container_t::gc_micro: v = 2; break; - case gc_regular: + case Geocache::container_t::gc_regular: v = 3; break; - case gc_large: + case Geocache::container_t::gc_large: v = 4; break; - case gc_virtual: + case Geocache::container_t::gc_virtual: v = 5; break; - case gc_other: + case Geocache::container_t::gc_other: v = 6; break; - case gc_small: + case Geocache::container_t::gc_small: v = 8; break; default: diff --git a/geocache.cc b/geocache.cc new file mode 100644 index 000000000..c20728325 --- /dev/null +++ b/geocache.cc @@ -0,0 +1,153 @@ +/* + Copyright (C) 2002-2023 Robert Lipe, robertlipe+source@gpsbabel.org + + 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 // for QString +#include // for QVector +#include // for CaseInsensitive + +#include "defs.h" // for strip_html, global_options, global_opts + + +const QVector 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_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; +} diff --git a/geocache.h b/geocache.h new file mode 100644 index 000000000..25c491319 --- /dev/null +++ b/geocache.h @@ -0,0 +1,146 @@ +/* + Copyright (C) 2002-2023 Robert Lipe, robertlipe+source@gpsbabel.org + + 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. + + */ +#ifndef GEOCACHE_H_INCLUDED_ +#define GEOCACHE_H_INCLUDED_ + +#include // for QString +#include // for QVector + +#include "src/core/datetime.h" // for DateTime + + +/* + * Extended data if waypoint happens to represent a geocache. This is + * totally voluntary data... + */ +class Geocache +{ +public: + + /* Types */ + + enum class type_t { + gt_unknown = 0, + gt_traditional, + gt_multi, + gt_virtual, + gt_letterbox, + gt_event, + gt_surprise, + gt_webcam, + gt_earth, + gt_locationless, + gt_benchmark, /* Extension to Groundspeak for GSAK */ + gt_cito, + gt_ape, + gt_mega, + gt_wherigo + }; + + enum class container_t { + gc_unknown = 0, + gc_micro, + gc_other, + gc_regular, + gc_large, + gc_virtual, + gc_small + }; + + enum class status_t { + gs_unknown = 0, + gs_true, + gs_false + }; + + class UtfString + { + public: + + QString strip_html() const; + + bool is_html{false}; + QString utf_string; + }; + + /* Special Member Functions */ + + Geocache() : + id(0), + type(type_t::gt_unknown), + container(container_t::gc_unknown), + diff(0), + terr(0), + is_archived(status_t::gs_unknown), + is_available(status_t::gs_unknown), + is_memberonly(status_t::gs_unknown), + has_customcoords(status_t::gs_unknown), + placer_id(0), + favorite_points(0) + {} + + /* Member Functions */ + + void set_type(const QString& type_name); + QString get_type() const; + void set_container(const QString& container_name); + QString get_container() const; + QString get_icon() const; + + /* Data Members */ + + long long id; /* The decimal cache number */ + type_t type:5; + container_t container:4; + unsigned int diff:6; /* (multiplied by ten internally) */ + unsigned int terr:6; /* (likewise) */ + status_t is_archived:2; + status_t is_available:2; + status_t is_memberonly:2; + status_t has_customcoords:2; + gpsbabel::DateTime exported; + gpsbabel::DateTime last_found; + QString placer; /* Placer name */ + int placer_id; /* Placer id */ + QString hint; /* all these UTF8, XML entities removed, May be not HTML. */ + UtfString desc_short; + UtfString desc_long; + int favorite_points; + QString personal_note; + +private: + + /* Types */ + + struct type_mapping { + type_t type; + QString name; + }; + + struct container_mapping { + container_t container; + QString name; + }; + + /* Constants */ + + static const QVector type_map; + static const QVector container_map; +}; +#endif // GEOCACHE_H_INCLUDED_ diff --git a/gpx.cc b/gpx.cc index e034de254..9bd27a10c 100644 --- a/gpx.cc +++ b/gpx.cc @@ -19,39 +19,41 @@ */ -#include // for lround -#include // for sscanf -#include // for strtod -#include // for strchr, strncpy - -#include // for QDate -#include // for QDateTime -#include // for QHash -#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly -#include // for QLatin1Char -#include // for QLatin1String -#include // for QString, QStringLiteral, operator+, operator== -#include // for QStringList -#include // for QStringView -#include // for QTime -#include // for QVersionNumber -#include // for QXmlStreamAttribute -#include // for QXmlStreamAttributes -#include // for QXmlStreamNamespaceDeclaration -#include // for QXmlStreamNamespaceDeclarations -#include // for QXmlStreamReader, QXmlStreamReader::Characters, QXmlStreamReader::EndDocument, QXmlStreamReader::EndElement, QXmlStreamReader::Invalid, QXmlStreamReader::StartElement -#include // for CaseInsensitive, UTC -#include // for qAsConst, QAddConst<>::Type +#include "gpx.h" + +#include // for lround +#include // for sscanf +#include // for strchr, strncpy + +#include // for QByteArray +#include // for QDate +#include // for QDateTime +#include // for QHash +#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly +#include // for QLatin1Char +#include // for QLatin1String +#include // for QString, QStringLiteral, operator+, operator== +#include // for QStringList +#include // for QStringView +#include // for QTime +#include // for QVersionNumber +#include // for QXmlStreamAttribute +#include // for QXmlStreamAttributes +#include // for QXmlStreamNamespaceDeclaration +#include // for QXmlStreamNamespaceDeclarations +#include // for QXmlStreamReader, QXmlStreamReader::Characters, QXmlStreamReader::EndDocument, QXmlStreamReader::EndElement, QXmlStreamReader::Invalid, QXmlStreamReader::StartElement +#include // for CaseInsensitive, UTC +#include // for qAsConst, QAddConst<>::Type #include "defs.h" -#include "gpx.h" -#include "garmin_fs.h" // for garmin_fs_xml_convert, garmin_fs_xml_fprint, GMSD_FIND -#include "garmin_tables.h" // for gt_color_index_by_rgb, gt_color_name, gt_color_value_by_name -#include "src/core/datetime.h" // for DateTime -#include "src/core/file.h" // for File -#include "src/core/logging.h" // for Warning, Fatal -#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter -#include "src/core/xmltag.h" // for xml_tag, fs_xml, fs_xml_alloc, free_gpx_extras +#include "garmin_fs.h" // for garmin_fs_xml_convert, garmin_fs_xml_fprint, GMSD_FIND +#include "garmin_tables.h" // for gt_color_index_by_rgb, gt_color_name, gt_color_value_by_name +#include "geocache.h" // for Geocache, Geocache::UtfSt... +#include "src/core/datetime.h" // for DateTime +#include "src/core/file.h" // for File +#include "src/core/logging.h" // for Warning, Fatal +#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter +#include "src/core/xmltag.h" // for xml_tag, fs_xml, fs_xml_alloc, free_gpx_extras #define MYNAME "GPX" @@ -190,23 +192,23 @@ GpxFormat::tag_cache_desc(const QXmlStreamAttributes& attr) void GpxFormat::tag_gs_cache(const QXmlStreamAttributes& attr) const { - geocache_data* gc_data = wpt_tmp->AllocGCData(); + Geocache* gc_data = wpt_tmp->AllocGCData(); if (attr.hasAttribute(QLatin1String("id"))) { gc_data->id = attr.value(QLatin1String(QLatin1String("id"))).toLongLong(); } if (attr.hasAttribute(QLatin1String("available"))) { if (attr.value(QLatin1String("available")).compare(QLatin1String("True"), Qt::CaseInsensitive) == 0) { - gc_data->is_available = status_true; + gc_data->is_available = Geocache::status_t::gs_true; } else if (attr.value(QLatin1String("available")).compare(QLatin1String("False"), Qt::CaseInsensitive) == 0) { - gc_data->is_available = status_false; + gc_data->is_available = Geocache::status_t::gs_false; } } if (attr.hasAttribute(QLatin1String("archived"))) { if (attr.value(QLatin1String("archived")).compare(QLatin1String("True"), Qt::CaseInsensitive) == 0) { - gc_data->is_archived = status_true; + gc_data->is_archived = Geocache::status_t::gs_true; } else if (attr.value(QLatin1String("archived")).compare(QLatin1String("False"), Qt::CaseInsensitive) == 0) { - gc_data->is_archived = status_false; + gc_data->is_archived = Geocache::status_t::gs_false; } } } @@ -387,100 +389,6 @@ GpxFormat::gpx_start(QStringView el, const QXmlStreamAttributes& attr) } } -struct - gs_type_mapping { - geocache_type type; - const char* name; -} gs_type_map[] = { - { gt_traditional, "Traditional Cache" }, - { gt_traditional, "Traditional" }, /* opencaching.de */ - { gt_multi, "Multi-cache" }, - { gt_multi, "Multi" }, /* opencaching.de */ - { gt_virtual, "Virtual Cache" }, - { gt_virtual, "Virtual" }, /* opencaching.de */ - { gt_event, "Event Cache" }, - { gt_event, "Event" }, /* opencaching.de */ - { gt_webcam, "Webcam Cache" }, - { gt_webcam, "Webcam" }, /* opencaching.de */ - { gt_surprise, "Unknown Cache" }, - { gt_earth, "Earthcache" }, - { gt_earth, "Earth" }, /* opencaching.de */ - { gt_cito, "Cache In Trash Out Event" }, - { gt_letterbox, "Letterbox Hybrid" }, - { gt_locationless, "Locationless (Reverse) Cache" }, - { gt_ape, "Project APE Cache" }, - { gt_mega, "Mega-Event Cache" }, - { gt_wherigo, "Wherigo Cache" }, - - { gt_benchmark, "Benchmark" }, /* Not Groundspeak; for GSAK */ -}; - -struct - gs_container_mapping { - geocache_container type; - const char* name; -} gs_container_map[] = { - { gc_other, "Unknown" }, - { gc_other, "Other" }, /* Synonym on read. */ - { gc_micro, "Micro" }, - { gc_regular, "Regular" }, - { gc_large, "Large" }, - { gc_small, "Small" }, - { gc_virtual, "Virtual" } -}; - -geocache_type -gs_mktype(const QString& t) -{ - int sz = sizeof(gs_type_map) / sizeof(gs_type_map[0]); - - for (int i = 0; i < sz; i++) { - if (!t.compare(gs_type_map[i].name,Qt::CaseInsensitive)) { - return gs_type_map[i].type; - } - } - return gt_unknown; -} - -QString -gs_get_cachetype(geocache_type t) -{ - int sz = sizeof(gs_type_map) / sizeof(gs_type_map[0]); - - for (int i = 0; i < sz; i++) { - if (t == gs_type_map[i].type) { - return gs_type_map[i].name; - } - } - return "Unknown"; -} - -geocache_container -gs_mkcont(const QString& t) -{ - int sz = sizeof(gs_container_map) / sizeof(gs_container_map[0]); - - for (int i = 0; i < sz; i++) { - if (!t.compare(gs_container_map[i].name,Qt::CaseInsensitive)) { - return gs_container_map[i].type; - } - } - return gc_unknown; -} - -QString -gs_get_container(geocache_container t) -{ - int sz = sizeof(gs_container_map) / sizeof(gs_container_map[0]); - - for (int i = 0; i < sz; i++) { - if (t == gs_container_map[i].type) { - return gs_container_map[i].name; - } - } - return "Unknown"; -} - gpsbabel::DateTime xml_parse_time(const QString& dateTimeString) { @@ -618,10 +526,10 @@ GpxFormat::gpx_end(QStringView /*unused*/) wpt_tmp->notes = cdatastr; break; case tt_cache_container: - wpt_tmp->AllocGCData()->container = gs_mkcont(cdatastr); + wpt_tmp->AllocGCData()->set_container(cdatastr); break; case tt_cache_type: - wpt_tmp->AllocGCData()->type = gs_mktype(cdatastr); + wpt_tmp->AllocGCData()->set_type(cdatastr); break; case tt_cache_difficulty: wpt_tmp->AllocGCData()->diff = cdatastr.toFloat() * 10; @@ -630,15 +538,15 @@ GpxFormat::gpx_end(QStringView /*unused*/) wpt_tmp->AllocGCData()->hint = cdatastr; break; case tt_cache_desc_long: { - geocache_data* gc_data = wpt_tmp->AllocGCData(); + Geocache* gc_data = wpt_tmp->AllocGCData(); gc_data->desc_long.is_html = cache_descr_is_html; - gc_data->desc_long.utfstring = cdatastr; + gc_data->desc_long.utf_string = cdatastr; } break; case tt_cache_desc_short: { - geocache_data* gc_data = wpt_tmp->AllocGCData(); + Geocache* gc_data = wpt_tmp->AllocGCData(); gc_data->desc_short.is_html = cache_descr_is_html; - gc_data->desc_short.utfstring = cdatastr; + gc_data->desc_short.utf_string = cdatastr; } break; case tt_cache_terrain: diff --git a/gpx.h b/gpx.h index 98f68b0e7..98bcf8729 100644 --- a/gpx.h +++ b/gpx.h @@ -21,21 +21,22 @@ #ifndef GPX_H_INCLUDED_ #define GPX_H_INCLUDED_ -#include // for QHash -#include // for QString -#include // for QStringList -#include // for QStringView -#include // for QVector -#include // for QVersionNumber -#include // for QXmlStreamAttributes -#include // for QXmlStreamReader +#include // for QHash +#include // for QList +#include // for QString +#include // for QStringList +#include // for QStringView +#include // for QVector +#include // for QVersionNumber +#include // for QXmlStreamAttributes +#include // for QXmlStreamReader #include "defs.h" -#include "format.h" // for Format -#include "formspec.h" // for FormatSpecificData -#include "src/core/file.h" // for File -#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter -#include "src/core/xmltag.h" // for xml_tag +#include "format.h" // for Format +#include "formspec.h" // for FormatSpecificData +#include "src/core/file.h" // for File +#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter +#include "src/core/xmltag.h" // for xml_tag class GpxFormat : public Format diff --git a/html.cc b/html.cc index 17ea64553..5ffe15b36 100644 --- a/html.cc +++ b/html.cc @@ -32,6 +32,7 @@ #include "defs.h" #include "formspec.h" // for FormatSpecificDataList, kFsGpx +#include "geocache.h" // for Geocache, Geocache::UtfString #include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN #include "src/core/datetime.h" // for DateTime #include "src/core/textstream.h" // for TextStream @@ -114,8 +115,8 @@ HtmlFormat::html_disp(const Waypoint* wpt) const .arg((wpt->gc_data->diff%10) ? "½" : "") .arg((int)(wpt->gc_data->terr / 10)) .arg((wpt->gc_data->terr%10) ? "½" : ""); - *file_out << gs_get_cachetype(wpt->gc_data->type) << " / " - << gs_get_container(wpt->gc_data->container) << "

\n"; + *file_out << wpt->gc_data->get_type() << " / " + << wpt->gc_data->get_container() << "

\n"; } *file_out << " \n"; *file_out << " \n"; @@ -123,13 +124,13 @@ HtmlFormat::html_disp(const Waypoint* wpt) const *file_out << " \n"; *file_out << " \n"; - if (!wpt->gc_data->desc_short.utfstring.isEmpty()) { + if (!wpt->gc_data->desc_short.utf_string.isEmpty()) { *file_out << "

" - << strip_nastyhtml(wpt->gc_data->desc_short.utfstring) << "

\n"; + << strip_nastyhtml(wpt->gc_data->desc_short.utf_string) << "\n"; } - if (!wpt->gc_data->desc_long.utfstring.isEmpty()) { + if (!wpt->gc_data->desc_long.utf_string.isEmpty()) { *file_out << "

" - << strip_nastyhtml(wpt->gc_data->desc_long.utfstring) << "

\n"; + << strip_nastyhtml(wpt->gc_data->desc_long.utf_string) << "\n"; } if (!wpt->gc_data->hint.isEmpty()) { QString hint; diff --git a/kml.cc b/kml.cc index 2e9263200..0b8536038 100644 --- a/kml.cc +++ b/kml.cc @@ -20,39 +20,41 @@ */ -#include // for tolower, toupper -#include // for fabs -#include // for sscanf, printf -#include // for strtod -#include // for strcmp -#include // for optional -#include // for tuple, make_tuple - -#include // for QByteArray -#include // for QChar -#include // for QDate -#include // for QDateTime -#include // for QFile -#include // for operator|, QIODevice, QIODevice::Text, QIODevice::WriteOnly -#include // for QList -#include // for QString, QStringLiteral, operator+, operator!= -#include // for QStringList -#include // for QVector -#include // for QXmlStreamAttributes -#include // for ISODate -#include // for foreach, qint64, qRound, qPrintable +#include "kml.h" + +#include // for tolower, toupper +#include // for fabs +#include // for sscanf, printf +#include // for strtod +#include // for strcmp +#include // for optional +#include // for tuple, make_tuple + +#include // for QByteArray +#include // for QChar +#include // for QDate +#include // for QDateTime +#include // for QFile +#include // for operator|, QIODevice, QIODevice::Text, QIODevice::WriteOnly +#include // for QList +#include // for QString, QStringLiteral, operator+, operator!= +#include // for QStringList +#include // for QVector +#include // for QXmlStreamAttributes +#include // for ISODate +#include // for foreach, qint64, qRound, qPrintable #include "defs.h" -#include "kml.h" -#include "formspec.h" // for FsChainFind, kFsGpx -#include "grtcirc.h" // for RAD, gcdist, radtometers -#include "src/core/datetime.h" // for DateTime -#include "src/core/file.h" // for File -#include "src/core/logging.h" // for Warning, Fatal -#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter -#include "src/core/xmltag.h" // for xml_findfirst, xml_tag, fs_xml, xml_attribute, xml_findnext -#include "units.h" // for fmt_setunits, fmt_speed, fmt_altitude, fmt_distance, units_aviation, units_metric, units_nautical, units_statute -#include "xmlgeneric.h" // for cb_cdata, cb_end, cb_start, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_ignore_tags, xml_init, xml_read, xg_tag_mapping +#include "formspec.h" // for FsChainFind, kFsGpx +#include "geocache.h" // for Geocache, Geocache::type_t +#include "grtcirc.h" // for RAD, gcdist, radtometers +#include "src/core/datetime.h" // for DateTime +#include "src/core/file.h" // for File +#include "src/core/logging.h" // for Warning, Fatal +#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter +#include "src/core/xmltag.h" // for xml_findfirst, xml_tag, fs_xml, xml_attribute, xml_findnext +#include "units.h" // for fmt_setunits, fmt_speed, fmt_altitude, fmt_distance, units_aviation, units_metric, units_nautical, units_statute +#include "xmlgeneric.h" // for cb_cdata, cb_end, cb_start, xg_callback, xg_string, xg_cb_type, xml_deinit, xml_ignore_tags, xml_init, xml_read, xg_tag_mapping // Icons provided and hosted by Google. Used with permission. @@ -1107,43 +1109,43 @@ QString KmlFormat::kml_lookup_gc_icon(const Waypoint* waypointp) * initializers... */ switch (waypointp->gc_data->type) { - case gt_traditional: + case Geocache::type_t::gt_traditional: icon = "2.png"; break; - case gt_multi: + case Geocache::type_t::gt_multi: icon = "3.png"; break; - case gt_virtual: + case Geocache::type_t::gt_virtual: icon = "4.png"; break; - case gt_letterbox: + case Geocache::type_t::gt_letterbox: icon = "5.png"; break; - case gt_event: + case Geocache::type_t::gt_event: icon = "6.png"; break; - case gt_ape: + case Geocache::type_t::gt_ape: icon = "7.png"; break; - case gt_locationless: + case Geocache::type_t::gt_locationless: icon = "8.png"; break; // No unique icon. - case gt_surprise: + case Geocache::type_t::gt_surprise: icon = "8.png"; break; - case gt_webcam: + case Geocache::type_t::gt_webcam: icon = "11.png"; break; - case gt_cito: + case Geocache::type_t::gt_cito: icon = "13.png"; break; - case gt_earth: + case Geocache::type_t::gt_earth: icon = "earthcache.png"; break; - case gt_mega: + case Geocache::type_t::gt_mega: icon = "453.png"; break; - case gt_wherigo: + case Geocache::type_t::gt_wherigo: icon = "1858.png"; break; default: @@ -1159,22 +1161,22 @@ const char* KmlFormat::kml_lookup_gc_container(const Waypoint* waypointp) const char* cont; switch (waypointp->gc_data->container) { - case gc_micro: + case Geocache::container_t::gc_micro: cont="micro"; break; - case gc_regular: + case Geocache::container_t::gc_regular: cont="regular"; break; - case gc_large: + case Geocache::container_t::gc_large: cont="large"; break; - case gc_small: + case Geocache::container_t::gc_small: cont="small"; break; - case gc_virtual: + case Geocache::container_t::gc_virtual: cont="virtual"; break; - case gc_other: + case Geocache::container_t::gc_other: cont="other"; break; default: @@ -1336,9 +1338,9 @@ void KmlFormat::kml_geocache_pr(const Waypoint* waypointp) const // Highlight any issues with the cache, such as temp unavail // or archived. - if (waypointp->gc_data->is_archived == status_true) { + if (waypointp->gc_data->is_archived == Geocache::status_t::gs_true) { issues = "<font color=\"red\">This cache has been archived.</font><br/>\n"; - } else if (waypointp->gc_data->is_available == status_false) { + } else if (waypointp->gc_data->is_available == Geocache::status_t::gs_false) { issues = "<font color=\"red\">This cache is temporarily unavailable.</font><br/>\n"; } kml_write_data_element("gc_issues", issues); @@ -1346,10 +1348,10 @@ void KmlFormat::kml_geocache_pr(const Waypoint* waypointp) const kml_write_data_element("gc_lat", waypointp->latitude); kml_write_data_element("gc_lon", waypointp->longitude); - kml_write_data_element("gc_type", gs_get_cachetype(waypointp->gc_data->type)); + kml_write_data_element("gc_type", waypointp->gc_data->get_type()); kml_write_data_element("gc_icon", is); - kml_write_cdata_element("gc_short_desc", waypointp->gc_data->desc_short.utfstring); - kml_write_cdata_element("gc_long_desc", waypointp->gc_data->desc_long.utfstring); + kml_write_cdata_element("gc_short_desc", waypointp->gc_data->desc_short.utf_string); + kml_write_cdata_element("gc_long_desc", waypointp->gc_data->desc_long.utf_string); QString logs = kml_geocache_get_logs(waypointp); kml_write_cdata_element("gc_logs", logs); diff --git a/lowranceusr.cc b/lowranceusr.cc index e7bb1d39b..ece237a69 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -85,32 +85,33 @@ */ -#include // for PRId64 -#include // for M_PI, round, atan, exp, log, tan -#include // for printf, sprintf, SEEK_CUR -#include // for int64_t -#include // for abs -#include // for strcmp, strlen - -#include // for QByteArray -#include // for QDate -#include // for QDateTime -#include // for QLatin1String -#include // for QList -#include // for QScopedPointer -#include // for QString, operator+, operator==, operator!= -#include // for QTextCodec, QTextCodec::IgnoreHeader -#include // for QTextEncoder -#include // for QTime -#include // for CaseInsensitive, UTC -#include // for qPrintable, uint, qAsConst, QAddConst<>::Type +#include "lowranceusr.h" + +#include // for PRId64 +#include // for M_PI, round, atan, exp, log, tan +#include // for printf, sprintf, SEEK_CUR +#include // for int64_t +#include // for abs +#include // for strcmp, strlen + +#include // for QByteArray +#include // for QDate +#include // for QDateTime +#include // for QList +#include // for QScopedPointer +#include // for QString, operator+, operator==, operator!= +#include // for QTextCodec, QTextCodec::IgnoreHeader +#include // for QTextEncoder +#include // for QTime +#include // for CaseInsensitive, UTC +#include // for qPrintable, uint, qAsConst, QAddConst<>::Type #include "defs.h" -#include "lowranceusr.h" -#include "formspec.h" // for FsChainFind, FsChainAdd, kFsLowranceusr4, FormatSpecificData -#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfwrite, gbfputc, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfopen_le, gbfputdbl, gbfputs, gbfile, gbfputflt, gbfread, gbfseek -#include "src/core/datetime.h" // for DateTime -#include "src/core/logging.h" // for Warning +#include "formspec.h" // for FsChainFind, FsChainAdd, kFsLowranceusr4, FormatSpecificData +#include "gbfile.h" // for gbfgetint32, gbfputint32, gbfputint16, gbfgetc, gbfgetint16, gbfwrite, gbfputc, gbfeof, gbfgetflt, gbfclose, gbfgetdbl, gbfopen_le, gbfputdbl, gbfputs, gbfile, gbfputflt, gbfread, gbfseek +#include "geocache.h" // for Geocache, Geocache::status_t, Geocach... +#include "src/core/datetime.h" // for DateTime +#include "src/core/logging.h" // for Warning /* from waypt.c, we need to iterate over waypoints when extracting routes */ @@ -1346,13 +1347,14 @@ LowranceusrFormat::lowranceusr_waypt_disp(const Waypoint* wpt) const gbfputint32(waypt_time, file_out); - if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { - SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt)); + if (!wpt->gc_data->get_icon().isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { + SymbolId = lowranceusr_find_icon_number_from_desc(wpt->gc_data->get_icon()); } else { SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr); } /* If the waypoint is archived or disabled, use a "disabled" icon instead. */ - if ((wpt->gc_data->is_archived==status_true) || (wpt->gc_data->is_available==status_false)) { + if ((wpt->gc_data->is_archived == Geocache::status_t::gs_true) || + (wpt->gc_data->is_available == Geocache::status_t::gs_false)) { SymbolId = lowranceusr_find_icon_number_from_desc(DISABLED_CACHE_TXT); } @@ -1407,11 +1409,11 @@ LowranceusrFormat::lowranceusr4_waypt_disp(const Waypoint* wpt) gbfputint32(2, file_out); int SymbolId, ColorId; - if (!get_cache_icon(wpt).isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { + if (!wpt->gc_data->get_icon().isEmpty() && wpt->icon_descr.compare(u"Geocache Found") == 0) { if (writing_version == 4) { SymbolId = lowranceusr4_find_icon_number_from_desc(wpt->icon_descr); } else { - SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt)); + SymbolId = lowranceusr_find_icon_number_from_desc(wpt->gc_data->get_icon()); } ColorId = 0; // default } else { @@ -1423,7 +1425,8 @@ LowranceusrFormat::lowranceusr4_waypt_disp(const Waypoint* wpt) } } /* If the waypoint is archived or disabled, use a "disabled" icon instead. */ - if ((wpt->gc_data->is_archived==status_true) || (wpt->gc_data->is_available==status_false)) { + if ((wpt->gc_data->is_archived == Geocache::status_t::gs_true) || + (wpt->gc_data->is_available == Geocache::status_t::gs_false)) { SymbolId = lowranceusr_find_icon_number_from_desc(DISABLED_CACHE_TXT); ColorId = 0; // default } diff --git a/mkshort.cc b/mkshort.cc index 34499a1d5..1d50860d8 100644 --- a/mkshort.cc +++ b/mkshort.cc @@ -30,6 +30,7 @@ #include // for foreach #include "defs.h" +#include "geocache.h" // for Geocache #define MYNAME "mkshort" diff --git a/osm.cc b/osm.cc index 070b69f6f..dbd44cd46 100644 --- a/osm.cc +++ b/osm.cc @@ -409,8 +409,7 @@ OsmFormat::osm_feature_symbol(const int ikey, const char* value) const QString OsmFormat::osm_strip_html(const QString& str) { - utf_string utf(true, str); - return strip_html(&utf); // util.cc + return strip_html(str); // util.cc } void diff --git a/sort.cc b/sort.cc index f3f182e89..6c4afecd9 100644 --- a/sort.cc +++ b/sort.cc @@ -19,12 +19,15 @@ */ +#include "sort.h" + #include // for QDateTime #include // for operator<, QString #include "defs.h" +#include "geocache.h" // for Geocache #include "src/core/datetime.h" // for DateTime -#include "sort.h" + #if FILTERS_ENABLED #define MYNAME "sort" diff --git a/sort.h b/sort.h index 2c4ddf01a..07de160c7 100644 --- a/sort.h +++ b/sort.h @@ -22,7 +22,8 @@ #ifndef SORT_H_INCLUDED_ #define SORT_H_INCLUDED_ -#include // for QVector +#include // for QString +#include // for QVector #include "defs.h" // for ARGTYPE_BOOL, ARG_NOMINMAX, arglist_t, ARG_TERMI... #include "filter.h" // for Filter diff --git a/text.cc b/text.cc index 2dd985160..a0daa10ef 100644 --- a/text.cc +++ b/text.cc @@ -32,6 +32,7 @@ #include "defs.h" #include "formspec.h" // for FormatSpecificDataList, kFsGpx +#include "geocache.h" // for Geocache, Geocache::UtfString #include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN #include "src/core/datetime.h" // for DateTime #include "src/core/textstream.h" // for TextStream @@ -102,17 +103,17 @@ TextFormat::text_disp(const Waypoint* wpt) } if (wpt->gc_data->terr) { *file_out << QStringLiteral(" - %1 / %2 - (%3%4 / %5%6)\n") - .arg(gs_get_cachetype(wpt->gc_data->type), - gs_get_container(wpt->gc_data->container)) + .arg(wpt->gc_data->get_type(), + wpt->gc_data->get_container()) .arg((int)(wpt->gc_data->diff / 10)) .arg((wpt->gc_data->diff%10) ? ".5" : "") .arg((int)(wpt->gc_data->terr / 10)) .arg((wpt->gc_data->terr%10) ? ".5" : ""); - if (!wpt->gc_data->desc_short.utfstring.isEmpty()) { - *file_out << "\n" << strip_html(&wpt->gc_data->desc_short) << "\n"; + if (!wpt->gc_data->desc_short.utf_string.isEmpty()) { + *file_out << "\n" << wpt->gc_data->desc_short.strip_html() << "\n"; } - if (!wpt->gc_data->desc_long.utfstring.isEmpty()) { - *file_out << "\n" << strip_html(&wpt->gc_data->desc_long) << "\n"; + if (!wpt->gc_data->desc_long.utf_string.isEmpty()) { + *file_out << "\n" << wpt->gc_data->desc_long.strip_html() << "\n"; } if (!wpt->gc_data->hint.isEmpty()) { QString hint; diff --git a/unicsv.cc b/unicsv.cc index ad6590c1f..104406ef0 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -19,9 +19,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "unicsv.h" + #include // for fabs, lround #include // for NULL, sscanf -#include #include // for memset, strchr, strncpy #include // for gmtime @@ -30,7 +31,6 @@ #include // for QDateTime #include // for QIODevice, QIODevice::ReadOnly, QIODevice::WriteOnly #include // for QLatin1Char -#include // for QLatin1String #include // for QString, operator!=, operator== #include // for QStringList #include // for QTextStream, operator<<, qSetRealNumberPrecision, qSetFieldWidth, QTextStream::FixedNotation @@ -40,11 +40,11 @@ #include // for qPrintable #include "defs.h" -#include "unicsv.h" #include "csv_util.h" // for csv_linesplit, human_to_dec #include "formspec.h" // for FormatSpecificDataList #include "garmin_fs.h" // for garmin_fs_flags_t, garmin_fs_t, GMSD_GET, GMSD_HAS, GMSD_SETQSTR, GMSD_FIND, garmin_fs_alloc #include "garmin_tables.h" // for gt_lookup_datum_index, gt_get_mps_grid_longname, gt_lookup_grid_type +#include "geocache.h" // for Geocache, Geocache::status_t, Geoc... #include "jeeps/gpsmath.h" // for GPS_Math_UKOSMap_To_WGS84_M, GPS_Math_EN_To_UKOSNG_Map, GPS_Math_Known_Datum_To_UTM_EN, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_Swiss_EN_To_WGS84, GPS_Math_UTM_EN_To_Known_Datum, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_WGS84_To_Swiss_EN, GPS_Math_WGS... #include "session.h" // for session_t #include "src/core/datetime.h" // for DateTime @@ -321,20 +321,20 @@ UnicsvFormat::unicsv_parse_time(const QString& str, int* msec, time_t* date) return unicsv_parse_time(CSTR(str), msec, date); } -status_type +Geocache::status_t UnicsvFormat::unicsv_parse_status(const QString& str) { if (str.compare(u"true", Qt::CaseInsensitive) == 0 || str.compare(u"yes", Qt::CaseInsensitive) == 0 || str == '1') { - return status_true; + return Geocache::status_t::gs_true; } if (str.compare(u"false", Qt::CaseInsensitive) == 0 || str.compare(u"no", Qt::CaseInsensitive) == 0 || str == '0') { - return status_false; + return Geocache::status_t::gs_false; } - return status_unknown; + return Geocache::status_t::gs_unknown; } QDateTime @@ -505,7 +505,7 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) int src_datum = unicsv_datum_idx; int ns = 1; int ew = 1; - geocache_data* gc_data = nullptr; + Geocache* gc_data = nullptr; auto* wpt = new Waypoint; wpt->latitude = kUnicsvUnknown; wpt->longitude = kUnicsvUnknown; @@ -902,10 +902,10 @@ UnicsvFormat::unicsv_parse_one_line(const QString& ibuf) } break; case fld_gc_type: - gc_data->type = gs_mktype(value); + gc_data->set_type(value); break; case fld_gc_container: - gc_data->container = gs_mkcont(value); + gc_data->set_container(value); break; case fld_gc_terr: gc_data->terr = value.toDouble() * 10; @@ -1260,15 +1260,15 @@ UnicsvFormat::unicsv_waypt_enum_cb(const Waypoint* wpt) } if (! wpt->EmptyGCData()) { - const geocache_data* gc_data = wpt->gc_data; + const Geocache* gc_data = wpt->gc_data; if (gc_data->id) { gb_setbit(&unicsv_outp_flags, fld_gc_id); } - if (gc_data->type) { + if (gc_data->type != Geocache::type_t::gt_unknown) { gb_setbit(&unicsv_outp_flags, fld_gc_type); } - if (gc_data->container) { + if (gc_data->container != Geocache::container_t::gc_unknown) { gb_setbit(&unicsv_outp_flags, fld_gc_container); } if (gc_data->terr) { @@ -1277,10 +1277,10 @@ UnicsvFormat::unicsv_waypt_enum_cb(const Waypoint* wpt) if (gc_data->diff) { gb_setbit(&unicsv_outp_flags, fld_gc_diff); } - if (gc_data->is_archived) { + if (gc_data->is_archived != Geocache::status_t::gs_unknown) { gb_setbit(&unicsv_outp_flags, fld_gc_is_archived); } - if (gc_data->is_available) { + if (gc_data->is_available != Geocache::status_t::gs_unknown) { gb_setbit(&unicsv_outp_flags, fld_gc_is_available); } if (gc_data->exported.isValid()) { @@ -1305,7 +1305,7 @@ void UnicsvFormat::unicsv_waypt_disp_cb(const Waypoint* wpt) { double lat, lon, alt; - const geocache_data* gc_data = nullptr; + const Geocache* gc_data = nullptr; unicsv_waypt_ct++; QString shortname = wpt->shortname; @@ -1618,14 +1618,14 @@ UnicsvFormat::unicsv_waypt_disp_cb(const Waypoint* wpt) } if FIELD_USED(fld_gc_type) { if (gc_data) { - unicsv_print_str(gs_get_cachetype(gc_data->type)); + unicsv_print_str(gc_data->get_type()); } else { *fout << unicsv_fieldsep; } } if FIELD_USED(fld_gc_container) { if (gc_data) { - unicsv_print_str(gs_get_container(gc_data->container)); + unicsv_print_str(gc_data->get_container()); } else { *fout << unicsv_fieldsep; } @@ -1643,15 +1643,15 @@ UnicsvFormat::unicsv_waypt_disp_cb(const Waypoint* wpt) } } if FIELD_USED(fld_gc_is_archived) { - if (gc_data && gc_data->is_archived) { - unicsv_print_str((gc_data->is_archived == status_true) ? "True" : "False"); + if (gc_data && (gc_data->is_archived != Geocache::status_t::gs_unknown)) { + unicsv_print_str((gc_data->is_archived == Geocache::status_t::gs_true) ? "True" : "False"); } else { *fout << unicsv_fieldsep; } } if FIELD_USED(fld_gc_is_available) { - if (gc_data && gc_data->is_available) { - unicsv_print_str((gc_data->is_available == status_true) ? "True" : "False"); + if (gc_data && (gc_data->is_available != Geocache::status_t::gs_unknown)) { + unicsv_print_str((gc_data->is_available == Geocache::status_t::gs_true) ? "True" : "False"); } else { *fout << unicsv_fieldsep; } diff --git a/unicsv.h b/unicsv.h index 1a0e249d8..08dfa4466 100644 --- a/unicsv.h +++ b/unicsv.h @@ -30,6 +30,7 @@ #include "defs.h" #include "format.h" // for Format +#include "geocache.h" // for Geocache, Geocache::status_t #include "src/core/textstream.h" // for TextStream @@ -176,7 +177,7 @@ class UnicsvFormat : public Format static time_t unicsv_parse_date(const char* str, int* consumed); static time_t unicsv_parse_time(const char* str, int* usec, time_t* date); static time_t unicsv_parse_time(const QString& str, int* msec, time_t* date); - static status_type unicsv_parse_status(const QString& str); + static Geocache::status_t unicsv_parse_status(const QString& str); QDateTime unicsv_adjust_time(time_t time, const time_t* date) const; static bool unicsv_compare_fields(const QString& s, const field_t* f); void unicsv_fondle_header(QString header); diff --git a/util.cc b/util.cc index a5887ab81..643c86244 100644 --- a/util.cc +++ b/util.cc @@ -709,53 +709,6 @@ QDateTime dotnet_time_to_qdatetime(long long dotnet) return epoch.addMSecs(millisecs); } -/* - * Return a pointer to a constant string 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 -get_cache_icon(const Waypoint* waypointp) -{ - if (!global_opts.smart_icons) { - return nullptr; - } - - /* - * For icons, type overwrites container. So a multi-micro will - * get the icons for "multi". - */ - switch (waypointp->gc_data->type) { - case gt_virtual: - return "Virtual cache"; - case gt_multi: - return "Multi-Cache"; - case gt_event: - return "Event Cache"; - case gt_surprise: - return "Unknown Cache"; - case gt_webcam: - return "Webcam Cache"; - default: - break; - } - - switch (waypointp->gc_data->container) { - case gc_micro: - return "Micro-Cache"; - break; - default: - break; - } - - if (waypointp->gc_data->diff > 1) { - return "Geocache"; - } - - return nullptr; -} - double endian_read_double(const void* ptr, int read_le) { @@ -1251,31 +1204,26 @@ strip_nastyhtml(const QString& in) * pleasant for a human reader. Yes, this falls down in all kinds of * ways such as spaces within the tags, etc. */ -QString -strip_html(const utf_string* in) +QString strip_html(const QString& utfstring) { #if 0 // If we were willing to link core against QtGui (not out of the question) // we could just do...and either decide whether to add handling for [IMG] // or just say we don't do that any more. QTextDocument doc; - doc.setHtml(in->utfstring); + doc.setHtml(utfstring); return doc.toPlainText().simplified(); #else - if (!in->is_html) { - return in->utfstring; - } - char* out; char* instr; char tag[8]; unsigned short int taglen = 0; - char* incopy = instr = xstrdup(in->utfstring); + char* incopy = instr = xstrdup(utfstring); /* * We only shorten, so just dupe the input buf for space. */ - char* outstring = out = xstrdup(in->utfstring); + char* outstring = out = xstrdup(utfstring); tag[0] = 0; while (*instr) { diff --git a/vcf.cc b/vcf.cc index 209b46713..fcc616eb0 100644 --- a/vcf.cc +++ b/vcf.cc @@ -18,15 +18,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include // for fabs -#include // for abs +#include // for fabs +#include // for abs -#include // for QString -#include // for QVector -#include // for CaseInsensitive +#include // for QString +#include // for QVector +#include // for CaseInsensitive #include "defs.h" -#include "gbfile.h" // for gbfprintf, gbfputs, gbfclose, gbfopen, gbfile +#include "gbfile.h" // for gbfprintf, gbfputs, gbfclose, gbfopen, gbfile +#include "geocache.h" // for Geocache, Geocache::UtfString static gbfile* file_out; @@ -63,13 +64,13 @@ wr_deinit() * newlines as we go. */ static void -vcf_print_utf(const utf_string* s) +vcf_print_utf(const Geocache::UtfString* s) { - if (!s) { + if (nullptr == s) { return; } - QString stripped_html = strip_html(s); + QString stripped_html = s->strip_html(); stripped_html.replace("\n", "\\n", Qt::CaseInsensitive); stripped_html.replace("

", "\\n", Qt::CaseInsensitive); diff --git a/waypt.cc b/waypt.cc index 68e2d6684..62836120b 100644 --- a/waypt.cc +++ b/waypt.cc @@ -37,6 +37,7 @@ #include "defs.h" #include "formspec.h" // for FormatSpecificDataList #include "garmin_fs.h" // for garmin_ilink_t, garmin_fs_t +#include "geocache.h" // for Geocache #include "grtcirc.h" // for RAD, gcdist, heading_true_degrees, radtometers #include "session.h" // for curr_session, session_t #include "src/core/datetime.h" // for DateTime @@ -45,7 +46,7 @@ WaypointList* global_waypoint_list; -geocache_data Waypoint::empty_gc_data; +Geocache Waypoint::empty_gc_data; static global_trait traits; const global_trait* get_traits() @@ -449,7 +450,7 @@ Waypoint::Waypoint(const Waypoint& other) : { // deep copy geocache data unless it is the special static empty_gc_data. if (other.gc_data != &Waypoint::empty_gc_data) { - gc_data = new geocache_data(*other.gc_data); + gc_data = new Geocache(*other.gc_data); } // deep copy fs chain data. @@ -501,7 +502,7 @@ Waypoint& Waypoint::operator=(const Waypoint& rhs) extra_data = rhs.extra_data; // deep copy geocache data unless it is the special static empty_gc_data. if (rhs.gc_data != &Waypoint::empty_gc_data) { - gc_data = new geocache_data(*rhs.gc_data); + gc_data = new Geocache(*rhs.gc_data); } // deep copy fs chain data. @@ -567,11 +568,11 @@ Waypoint::SetCreationTime(qint64 t, qint64 ms) creation_time.setMSecsSinceEpoch((t * 1000) + ms); } -geocache_data* +Geocache* Waypoint::AllocGCData() { if (gc_data == &Waypoint::empty_gc_data) { - gc_data = new geocache_data; + gc_data = new Geocache; } return gc_data; } diff --git a/xcsv.cc b/xcsv.cc index 9425e56d8..a7f2040a8 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -23,42 +23,43 @@ */ -#include // for assert -#include // for isdigit, tolower -#include // for fabs, pow -#include // for snprintf, sscanf -#include // for strtod -#include // for strlen, strncmp, strcmp, memset -#include // for gmtime, localtime, time_t, mktime, strftime -#include // for optional - -#include // for QByteArray -#include // for QChar -#include // for QDate -#include // for QDateTime -#include // for QDebug -#include // for QHash -#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly -#include // for QList -#include // for QRegularExpression -#include // for QString, operator+, operator== -#include // for QStringList -#include // for QTextStream -#include // for qAsConst, qRound, qPrintable +#include "xcsv.h" + +#include // for isdigit, tolower +#include // for fabs, pow +#include // for snprintf, sscanf +#include // for strtod +#include // for strlen, strncmp, strcmp, memset +#include // for gmtime, localtime, time_t, mktime, strftime +#include // for optional + +#include // for QByteArray +#include // for QChar +#include // for QDate +#include // for QDateTime +#include // for QDebug +#include // for QHash +#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly +#include // for QList +#include // for QRegularExpression +#include // for QString, operator+, operator== +#include // for QStringList +#include // for QTextStream +#include // for qAsConst, qRound, qPrintable #include "defs.h" -#include "csv_util.h" // for csv_stringtrim, dec_to_human, csv_stringclean, human_to_dec, ddmmdir_to_degrees, dec_to_intdeg, decdir_to_dec, intdeg_to_dec, csv_linesplit -#include "formspec.h" // for FormatSpecificDataList -#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_alloc -#include "grtcirc.h" // for RAD, gcdist, radtometers -#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN, GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_UTM_EN_To_Known_Datum, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_WGS84_To_UKOSMap_M -#include "jeeps/gpsport.h" // for int32 -#include "session.h" // for session_t -#include "src/core/datetime.h" // for DateTime -#include "src/core/logging.h" // for FatalMsg -#include "src/core/textstream.h" // for TextStream -#include "strptime.h" // for strptime -#include "xcsv.h" +#include "csv_util.h" // for csv_stringtrim, dec_to_human, csv_stringclean, human_to_dec, ddmmdir_to_degrees, dec_to_intdeg, decdir_to_dec, intdeg_to_dec, csv_linesplit +#include "formspec.h" // for FormatSpecificDataList +#include "garmin_fs.h" // for garmin_fs_t, garmin_fs_alloc +#include "geocache.h" // for Geocache, Geocache::status_t, Geoc... +#include "grtcirc.h" // for RAD, gcdist, radtometers +#include "jeeps/gpsmath.h" // for GPS_Math_WGS84_To_UTM_EN, GPS_Lookup_Datum_Index, GPS_Math_Known_Datum_To_WGS84_M, GPS_Math_UTM_EN_To_Known_Datum, GPS_Math_WGS84_To_Known_Datum_M, GPS_Math_WGS84_To_UKOSMap_M +#include "jeeps/gpsport.h" // for int32 +#include "session.h" // for session_t +#include "src/core/datetime.h" // for DateTime +#include "src/core/logging.h" // for FatalMsg +#include "src/core/textstream.h" // for TextStream +#include "strptime.h" // for strptime #if CSVFMTS_ENABLED @@ -388,7 +389,7 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: xcsv_parse_data* parse_data, const int line_no) { QString enclosure = ""; - geocache_data* gc_data = nullptr; + Geocache* gc_data = nullptr; if (fmp.printfc.isNull()) { fatal(MYNAME ": xcsv style '%s' is missing format specifier", fmp.key.constData()); @@ -663,10 +664,10 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: break; case XcsvStyle::XT_GEOCACHE_TYPE: /* Geocache Type */ - wpt->AllocGCData()->type = gs_mktype(value); + wpt->AllocGCData()->set_type(value); break; case XcsvStyle::XT_GEOCACHE_CONTAINER: - wpt->AllocGCData()->container = gs_mkcont(value); + wpt->AllocGCData()->set_container(value); break; case XcsvStyle::XT_GEOCACHE_HINT: wpt->AllocGCData()->hint = value.trimmed(); @@ -677,21 +678,21 @@ XcsvFormat::xcsv_parse_val(const QString& value, Waypoint* wpt, const XcsvStyle: case XcsvStyle::XT_GEOCACHE_ISAVAILABLE: gc_data = wpt->AllocGCData(); if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) { - gc_data->is_available = status_false; + gc_data->is_available = Geocache::status_t::gs_false; } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) { - gc_data->is_available = status_true; + gc_data->is_available = Geocache::status_t::gs_true; } else { - gc_data->is_available = status_unknown; + gc_data->is_available = Geocache::status_t::gs_unknown; } break; case XcsvStyle::XT_GEOCACHE_ISARCHIVED: gc_data = wpt->AllocGCData(); if (value.trimmed().compare(u"False", Qt::CaseInsensitive) == 0) { - gc_data->is_archived = status_false; + gc_data->is_archived = Geocache::status_t::gs_false; } else if (value.trimmed().compare(u"True", Qt::CaseInsensitive) == 0) { - gc_data->is_archived = status_true; + gc_data->is_archived = Geocache::status_t::gs_true; } else { - gc_data->is_archived = status_unknown; + gc_data->is_archived = Geocache::status_t::gs_unknown; } break; @@ -1388,13 +1389,13 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt) break; case XcsvStyle::XT_GEOCACHE_CONTAINER: /* Geocache Container */ - buff = QString::asprintf(fmp.printfc.constData(), CSTR(gs_get_container(wpt->gc_data->container))); - field_is_unknown = wpt->gc_data->container == gc_unknown; + buff = QString::asprintf(fmp.printfc.constData(), CSTR(wpt->gc_data->get_container())); + field_is_unknown = wpt->gc_data->container == Geocache::container_t::gc_unknown; break; case XcsvStyle::XT_GEOCACHE_TYPE: /* Geocache Type */ - buff = QString::asprintf(fmp.printfc.constData(), CSTR(gs_get_cachetype(wpt->gc_data->type))); - field_is_unknown = wpt->gc_data->type == gt_unknown; + buff = QString::asprintf(fmp.printfc.constData(), CSTR(wpt->gc_data->get_type())); + field_is_unknown = wpt->gc_data->type == Geocache::type_t::gt_unknown; break; case XcsvStyle::XT_GEOCACHE_HINT: buff = QString::asprintf(fmp.printfc.constData(), CSTR(wpt->gc_data->hint)); @@ -1405,18 +1406,18 @@ XcsvFormat::xcsv_waypt_pr(const Waypoint* wpt) field_is_unknown = !wpt->gc_data->placer.isEmpty(); break; case XcsvStyle::XT_GEOCACHE_ISAVAILABLE: - if (wpt->gc_data->is_available == status_false) { + if (wpt->gc_data->is_available == Geocache::status_t::gs_false) { buff = QString::asprintf(fmp.printfc.constData(), "False"); - } else if (wpt->gc_data->is_available == status_true) { + } else if (wpt->gc_data->is_available == Geocache::status_t::gs_true) { buff = QString::asprintf(fmp.printfc.constData(), "True"); } else { buff = QString::asprintf(fmp.printfc.constData(), "Unknown"); } break; case XcsvStyle::XT_GEOCACHE_ISARCHIVED: - if (wpt->gc_data->is_archived == status_false) { + if (wpt->gc_data->is_archived == Geocache::status_t::gs_false) { buff = QString::asprintf(fmp.printfc.constData(), "False"); - } else if (wpt->gc_data->is_archived == status_true) { + } else if (wpt->gc_data->is_archived == Geocache::status_t::gs_true) { buff = QString::asprintf(fmp.printfc.constData(), "True"); } else { buff = QString::asprintf(fmp.printfc.constData(), "Unknown");