]> git.street.me.uk Git - andy/viking.git/commitdiff
SF Features#116: Add an Acquire From URL option.
authorRob Norris <rw_norris@hotmail.com>
Wed, 2 Oct 2013 20:27:44 +0000 (21:27 +0100)
committerRob Norris <rw_norris@hotmail.com>
Wed, 2 Oct 2013 20:30:26 +0000 (21:30 +0100)
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
src/Makefile.am
src/babel.h
src/datasources.h
src/menu.xml.h
src/viktrwlayer.c
src/vikwindow.c

index c58e88b174a74e1a0efa7bd6a1a534b28c4e209c..9328c8c49fde6d523b29bc7ff616313c5288d158 100644 (file)
@@ -557,6 +557,22 @@ This gets a route from given directions.
 </para>
 </section>
 
+<section>
+<title>From URL</title>
+<para>
+<menuchoice><guimenu>File</guimenu><guimenuitem>Acquire</guimenuitem><guimenuitem>From URL</guimenuitem></menuchoice>
+</para>
+<para>
+This gets a file from the entered URL.
+File formats that can be opened are those supported by GPSBabel.
+</para>
+<note>
+<para>
+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.
+</para>
+</note>
+</section>
+
 </section> <!-- End Acquire -->
 
 <section><title>Print</title>
index 983fe6471b8274ad9ec08667a7b905f38338a422..1c796776a5a38cd4d6439780cfc050c5fbe45aa8 100644 (file)
@@ -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 \
index 6fe4a079b51ab199681725acd2fc3d4a30dcdf39..c037b6e8243e95a6258e6d184fd1e0c72113b3a1 100644 (file)
@@ -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
  * 
index 10df1a6fe341d706617deae2ab43b93b3471198b..bae9e3dcc81be5490ce6f1c648aea83ef7279a1d 100644 (file)
@@ -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
 
index d5f8eaf5fcc1835087d653073731fb87ce4ddfe0..ea048916eac3769528267b3b2476c7acb9354a07 100644 (file)
@@ -30,6 +30,7 @@ static const char *menu_xml =
 #ifdef VIK_CONFIG_GEOTAG
        "        <menuitem action='AcquireGeotag'/>"
 #endif
+       "        <menuitem action='AcquireURL'/>"
 #ifdef VIK_CONFIG_GEONAMES
        "        <menuitem action='AcquireWikipedia'/>"
 #endif
index bd6cc5ddbd3e8e8f75028022fc40bc1a8b8dc829..74e5564aaba043b83770176ffd86d3a58fc26a88 100644 (file)
@@ -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") );
index 74d38dd6b584298bf63d81fd918c3774f1c856f2..c1f98f83a4c5b58708ca37aa9e4692ce78175dd2 100644 (file)
@@ -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