From c6acf18ddc123a52e92f0757310cefc9292b46a7 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Wed, 2 Oct 2013 21:27:44 +0100 Subject: [PATCH] SF Features#116: Add an Acquire From URL option. Add a dialog to download a file from a specific URL directly into Viking, using the datasource methods. By default the downloaded file will be opened as a GPX, but any file type supported by GPSBabel can be specified (as used by the Import from File option). If the URL does not resolve, does not return a file, or the file can not be interpreted, then simply this will give 'Acquisition Error' --- help/C/viking.xml | 16 ++++++++++++++++ src/Makefile.am | 1 + src/babel.h | 2 +- src/datasources.h | 1 + src/menu.xml.h | 1 + src/viktrwlayer.c | 20 ++++++++++++++++++++ src/vikwindow.c | 7 +++++++ 7 files changed, 47 insertions(+), 1 deletion(-) diff --git a/help/C/viking.xml b/help/C/viking.xml index c58e88b1..9328c8c4 100644 --- a/help/C/viking.xml +++ b/help/C/viking.xml @@ -557,6 +557,22 @@ This gets a route from given directions. +
+From URL + +FileAcquireFrom URL + + +This gets a file from the entered URL. +File formats that can be opened are those supported by GPSBabel. + + + +You need to select the type of the file that is going to be returned, since there is no automatic detection of the file kind. + + +
+
Print diff --git a/src/Makefile.am b/src/Makefile.am index 983fe647..1c796776 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -117,6 +117,7 @@ libviking_a_SOURCES = \ datasource_gc.c \ datasource_bfilter.c \ datasource_wikipedia.c \ + datasource_url.c \ datasources.h \ googlesearch.c googlesearch.h \ dem.c dem.h \ diff --git a/src/babel.h b/src/babel.h index 6fe4a079..c037b6e8 100644 --- a/src/babel.h +++ b/src/babel.h @@ -79,7 +79,7 @@ typedef struct { /** * BabelFile: - * @name: gpsbabel's identifier of the device + * @name: gpsbabel's identifier of the format * @ext: file's extension for this format * @label: human readable label * diff --git a/src/datasources.h b/src/datasources.h index 10df1a6f..bae9e3dc 100644 --- a/src/datasources.h +++ b/src/datasources.h @@ -41,6 +41,7 @@ extern VikDataSourceInterface vik_datasource_geotag_interface; #ifdef VIK_CONFIG_GEONAMES extern VikDataSourceInterface vik_datasource_wikipedia_interface; #endif +extern VikDataSourceInterface vik_datasource_url_interface; G_END_DECLS diff --git a/src/menu.xml.h b/src/menu.xml.h index d5f8eaf5..ea048916 100644 --- a/src/menu.xml.h +++ b/src/menu.xml.h @@ -30,6 +30,7 @@ static const char *menu_xml = #ifdef VIK_CONFIG_GEOTAG " " #endif + " " #ifdef VIK_CONFIG_GEONAMES " " #endif diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index bd6cc5dd..74e5564a 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -311,6 +311,7 @@ static void trw_layer_geotagging ( gpointer lav[2] ); #endif static void trw_layer_acquire_gps_cb ( gpointer lav[2] ); static void trw_layer_acquire_routing_cb ( gpointer lav[2] ); +static void trw_layer_acquire_url_cb ( gpointer lav[2] ); #ifdef VIK_CONFIG_OPENSTREETMAP static void trw_layer_acquire_osm_cb ( gpointer lav[2] ); static void trw_layer_acquire_osm_my_traces_cb ( gpointer lav[2] ); @@ -3369,6 +3370,20 @@ static void trw_layer_acquire_routing_cb ( gpointer lav[2] ) a_acquire ( vw, vlp, vvp, &vik_datasource_routing_interface, NULL, NULL ); } +/* + * Acquire into this TRW Layer from an entered URL + */ +static void trw_layer_acquire_url_cb ( gpointer lav[2] ) +{ + VikTrwLayer *vtl = VIK_TRW_LAYER(lav[0]); + VikLayersPanel *vlp = VIK_LAYERS_PANEL(lav[1]); + VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)); + VikViewport *vvp = vik_window_viewport(vw); + + vik_datasource_url_interface.mode = VIK_DATASOURCE_ADDTOLAYER; + a_acquire ( vw, vlp, vvp, &vik_datasource_url_interface, NULL, NULL ); +} + #ifdef VIK_CONFIG_OPENSTREETMAP /* * Acquire into this TRW Layer from OSM @@ -3854,6 +3869,11 @@ static void trw_layer_add_menu_items ( VikTrwLayer *vtl, GtkMenu *menu, gpointer gtk_widget_show ( item ); #endif + item = gtk_menu_item_new_with_mnemonic ( _("From _URL...") ); + g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(trw_layer_acquire_url_cb), pass_along ); + gtk_menu_shell_append (GTK_MENU_SHELL (acquire_submenu), item); + gtk_widget_show ( item ); + #ifdef VIK_CONFIG_GEONAMES GtkWidget *wikipedia_submenu = gtk_menu_new(); item = gtk_image_menu_item_new_with_mnemonic ( _("From _Wikipedia Waypoints") ); diff --git a/src/vikwindow.c b/src/vikwindow.c index 74d38dd6..c1f98f83 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -3007,6 +3007,12 @@ static void acquire_from_wikipedia ( GtkAction *a, VikWindow *vw ) } #endif +static void acquire_from_url ( GtkAction *a, VikWindow *vw ) +{ + vik_datasource_url_interface.mode = VIK_DATASOURCE_CREATENEWLAYER; + a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_url_interface, NULL, NULL ); +} + static void goto_default_location( GtkAction *a, VikWindow *vw) { struct LatLon ll; @@ -3726,6 +3732,7 @@ static GtkActionEntry entries[] = { #ifdef VIK_CONFIG_GEOTAG { "AcquireGeotag", NULL, N_("From Geotagged _Images..."), NULL, N_("Create waypoints from geotagged images"), (GCallback)acquire_from_geotag }, #endif + { "AcquireURL", NULL, N_("From _URL..."), NULL, N_("Get a file from a URL"), (GCallback)acquire_from_url }, #ifdef VIK_CONFIG_GEONAMES { "AcquireWikipedia", NULL, N_("From _Wikipedia Waypoints"), NULL, N_("Create waypoints from Wikipedia items in the current view"), (GCallback)acquire_from_wikipedia }, #endif -- 2.39.5