From 415b0e21cfbd2d8a1e22ac02d7e6ccd2f9743f7c Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 27 Jan 2014 20:03:55 +0000 Subject: [PATCH] Add support for reading waypoint specific URL fields in GPX1.0 files. --- src/gpx.c | 17 ++++++++++++++++- src/viktrwlayer.c | 7 +++++-- src/vikwaypoint.c | 16 ++++++++++++++++ src/vikwaypoint.h | 2 ++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/gpx.c b/src/gpx.c index b05a1118..b6985050 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -5,7 +5,7 @@ * Copyright (C) 2007, Quy Tonthat * Copyright (C) 2008, Hein Ragas * Copyright (C) 2009, Tal B - * Copyright (c) 2012, Rob Norris + * Copyright (c) 2012-2014, Rob Norris * * Some of the code adapted from GPSBabel 1.2.7 * http://gpsbabel.sf.net/ @@ -61,6 +61,7 @@ typedef enum { tt_wpt_ele, tt_wpt_sym, tt_wpt_time, + tt_wpt_url, tt_wpt_link, /* New in GPX 1.1 */ tt_trk, @@ -135,6 +136,7 @@ tag_mapping tag_path_map[] = { { tt_wpt_desc, "/gpx/wpt/desc" }, { tt_wpt_sym, "/gpx/wpt/sym" }, { tt_wpt_sym, "/loc/waypoint/type" }, + { tt_wpt_url, "/gpx/wpt/url" }, { tt_wpt_link, "/gpx/wpt/link" }, /* GPX 1.1 */ { tt_trk, "/gpx/trk" }, @@ -286,6 +288,7 @@ static void gpx_start(VikTrwLayer *vtl, const char *el, const char **attr) case tt_wpt_name: case tt_wpt_ele: case tt_wpt_time: + case tt_wpt_url: case tt_wpt_link: case tt_trk_cmt: case tt_trk_desc: @@ -421,6 +424,11 @@ static void gpx_end(VikTrwLayer *vtl, const char *el) g_string_erase ( c_cdata, 0, -1 ); break; + case tt_wpt_url: + vik_waypoint_set_url ( c_wp, c_cdata->str ); + g_string_erase ( c_cdata, 0, -1 ); + break; + case tt_wpt_link: vik_waypoint_set_image ( c_wp, c_cdata->str ); g_string_erase ( c_cdata, 0, -1 ); @@ -524,6 +532,7 @@ static void gpx_cdata(void *dta, const XML_Char *s, int len) case tt_wpt_cmt: case tt_wpt_desc: case tt_wpt_sym: + case tt_wpt_url: case tt_wpt_link: case tt_trk_cmt: case tt_trk_desc: @@ -809,6 +818,12 @@ static void gpx_write_waypoint ( VikWaypoint *wp, GpxWritingContext *context ) fprintf ( f, " %s\n", tmp ); g_free ( tmp ); } + if ( wp->url ) + { + tmp = entitize(wp->url); + fprintf ( f, " %s\n", tmp ); + g_free ( tmp ); + } if ( wp->image ) { tmp = entitize(wp->image); diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index 84d963a1..c2476fa1 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -7388,7 +7388,9 @@ static void trw_layer_waypoint_webpage ( menu_array_sublayer values ) VikWaypoint *wp = g_hash_table_lookup ( vtl->waypoints, values[MA_SUBLAYER_ID] ); if ( !wp ) return; - if ( !strncmp(wp->comment, "http", 4) ) { + if ( wp->url ) { + open_url(VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(vtl)), wp->url); + } else if ( !strncmp(wp->comment, "http", 4) ) { open_url(VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(vtl)), wp->comment); } else if ( !strncmp(wp->description, "http", 4) ) { open_url(VIK_GTK_WINDOW_FROM_LAYER(VIK_LAYER(vtl)), wp->description); @@ -7654,7 +7656,8 @@ static gboolean trw_layer_sublayer_add_menu_items ( VikTrwLayer *l, GtkMenu *men if ( wp ) { - if ( ( wp->comment && !strncmp(wp->comment, "http", 4) ) || + if ( wp->url || + ( wp->comment && !strncmp(wp->comment, "http", 4) ) || ( wp->description && !strncmp(wp->description, "http", 4) )) { item = gtk_image_menu_item_new_with_mnemonic ( _("Visit _Webpage") ); gtk_image_menu_item_set_image ( (GtkImageMenuItem*)item, gtk_image_new_from_stock (GTK_STOCK_NETWORK, GTK_ICON_SIZE_MENU) ); diff --git a/src/vikwaypoint.c b/src/vikwaypoint.c index 8504185c..21d63deb 100644 --- a/src/vikwaypoint.c +++ b/src/vikwaypoint.c @@ -75,6 +75,17 @@ void vik_waypoint_set_description(VikWaypoint *wp, const gchar *description) wp->description = NULL; } +void vik_waypoint_set_url(VikWaypoint *wp, const gchar *url) +{ + if ( wp->url ) + g_free ( wp->url ); + + if ( url && url[0] != '\0' ) + wp->url = g_strdup(url); + else + wp->url = NULL; +} + void vik_waypoint_set_image(VikWaypoint *wp, const gchar *image) { if ( wp->image ) @@ -115,6 +126,8 @@ void vik_waypoint_free(VikWaypoint *wp) g_free ( wp->comment ); if ( wp->description ) g_free ( wp->description ); + if ( wp->url ) + g_free ( wp->url ); if ( wp->image ) g_free ( wp->image ); if ( wp->symbol ) @@ -133,6 +146,7 @@ VikWaypoint *vik_waypoint_copy(const VikWaypoint *wp) vik_waypoint_set_name(new_wp,wp->name); vik_waypoint_set_comment(new_wp,wp->comment); vik_waypoint_set_description(new_wp,wp->description); + vik_waypoint_set_url(new_wp,wp->url); vik_waypoint_set_image(new_wp,wp->image); vik_waypoint_set_symbol(new_wp,wp->symbol); return new_wp; @@ -182,6 +196,7 @@ void vik_waypoint_marshall ( VikWaypoint *wp, guint8 **data, guint *datalen) vwm_append(wp->name); vwm_append(wp->comment); vwm_append(wp->description); + vwm_append(wp->url); vwm_append(wp->image); vwm_append(wp->symbol); @@ -216,6 +231,7 @@ VikWaypoint *vik_waypoint_unmarshall (guint8 *data, guint datalen) vwu_get(new_wp->name); vwu_get(new_wp->comment); vwu_get(new_wp->description); + vwu_get(new_wp->url); vwu_get(new_wp->image); vwu_get(new_wp->symbol); diff --git a/src/vikwaypoint.h b/src/vikwaypoint.h index 15b2df0a..d7cac9f4 100644 --- a/src/vikwaypoint.h +++ b/src/vikwaypoint.h @@ -42,6 +42,7 @@ struct _VikWaypoint { gchar *name; gchar *comment; gchar *description; + gchar *url; gchar *image; /* a rather misleading, ugly hack needed for trwlayer's click image. * these are the height at which the thumbnail is being drawn, not the @@ -57,6 +58,7 @@ VikWaypoint *vik_waypoint_new(); void vik_waypoint_set_name(VikWaypoint *wp, const gchar *name); void vik_waypoint_set_comment(VikWaypoint *wp, const gchar *comment); void vik_waypoint_set_description(VikWaypoint *wp, const gchar *description); +void vik_waypoint_set_url(VikWaypoint *wp, const gchar *url); void vik_waypoint_set_image(VikWaypoint *wp, const gchar *image); void vik_waypoint_set_symbol(VikWaypoint *wp, const gchar *symname); void vik_waypoint_free(VikWaypoint * wp); -- 2.39.5