]> git.street.me.uk Git - andy/viking.git/blobdiff - src/datasource_routing.c
Add option to auto connect to GPSD rather than having to manually control
[andy/viking.git] / src / datasource_routing.c
index db4ce8adc324bd4077b0c352258149cb67537352..030c9e3592a6fa23a6ef5d7f5d8c58127e2e3271 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * Copyright (C) 2013, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ * Copyright (C) 2015, Rob Norris <rw_norris@hotmail.com>
  *
  * 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
@@ -33,6 +34,7 @@
 #include "gpx.h"
 #include "acquire.h"
 #include "vikrouting.h"
+#include "ui_util.h"
 
 typedef struct {
   GtkWidget *engines_combo;
@@ -45,8 +47,9 @@ static gchar *last_from_str = NULL;
 static gchar *last_to_str = NULL;
 
 static gpointer datasource_routing_init ( acq_vik_t *avt );
+static gchar *datasource_routing_check_existence ();
 static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
-static void datasource_routing_get_cmd_string ( datasource_routing_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options );
+static void datasource_routing_get_process_options ( datasource_routing_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *not_used2, const gchar *not_used3 );
 static void datasource_routing_cleanup ( gpointer data );
 
 VikDataSourceInterface vik_datasource_routing_interface = {
@@ -58,10 +61,10 @@ VikDataSourceInterface vik_datasource_routing_interface = {
   TRUE,
   TRUE,
   (VikDataSourceInitFunc)              datasource_routing_init,
-  (VikDataSourceCheckExistenceFunc)    NULL,
+  (VikDataSourceCheckExistenceFunc)    datasource_routing_check_existence,
   (VikDataSourceAddSetupWidgetsFunc)   datasource_routing_add_setup_widgets,
-  (VikDataSourceGetCmdStringFunc)      datasource_routing_get_cmd_string,
-  (VikDataSourceProcessFunc)            a_babel_convert_from_url_or_shell,
+  (VikDataSourceGetProcessOptionsFunc)  datasource_routing_get_process_options,
+  (VikDataSourceProcessFunc)            a_babel_convert_from,
   (VikDataSourceProgressFunc)          NULL,
   (VikDataSourceAddProgressWidgetsFunc)        NULL,
   (VikDataSourceCleanupFunc)           datasource_routing_cleanup,
@@ -80,6 +83,13 @@ static gpointer datasource_routing_init ( acq_vik_t *avt )
   return widgets;
 }
 
+static gchar *datasource_routing_check_existence ()
+{
+  if ( vik_routing_number_of_engines (VIK_ROUTING_METHOD_DIRECTIONS) > 0 )
+    return NULL;
+  return g_strdup ( _("No routing engines with directions available") );
+}
+
 static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data )
 {
   datasource_routing_widgets_t *widgets = (datasource_routing_widgets_t *)user_data;
@@ -92,14 +102,10 @@ static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewpor
   
   /* From and To entries */
   from_label = gtk_label_new (_("From:"));
-  widgets->from_entry = gtk_entry_new();
   to_label = gtk_label_new (_("To:"));
-  widgets->to_entry = gtk_entry_new();
-  if (last_from_str)
-    gtk_entry_set_text(GTK_ENTRY(widgets->from_entry), last_from_str);
-  if (last_to_str)
-    gtk_entry_set_text(GTK_ENTRY(widgets->to_entry), last_to_str);
-  
+  widgets->from_entry = ui_entry_new ( last_from_str, GTK_ENTRY_ICON_SECONDARY );
+  widgets->to_entry = ui_entry_new ( last_from_str, GTK_ENTRY_ICON_SECONDARY );
+
   /* Packing all these widgets */
   GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
   gtk_box_pack_start ( box, engine_label, FALSE, FALSE, 5 );
@@ -111,7 +117,7 @@ static void datasource_routing_add_setup_widgets ( GtkWidget *dialog, VikViewpor
   gtk_widget_show_all(dialog);
 }
 
-static void datasource_routing_get_cmd_string ( datasource_routing_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
+static void datasource_routing_get_process_options ( datasource_routing_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *options, const gchar *not_used2, const gchar *not_used3 )
 {
   const gchar *from, *to;
   
@@ -122,10 +128,11 @@ static void datasource_routing_get_cmd_string ( datasource_routing_widgets_t *wi
   /* Retrieve engine */
   last_engine = gtk_combo_box_get_active ( GTK_COMBO_BOX(widgets->engines_combo) );
   VikRoutingEngine *engine = vik_routing_ui_selector_get_nth ( widgets->engines_combo, last_engine );
-  
-  *cmd = vik_routing_engine_get_url_from_directions ( engine, from, to );
-  *input_file_type = g_strdup ( vik_routing_engine_get_format (engine) );
-  options = NULL;
+  if ( !engine ) return;
+
+  po->url = vik_routing_engine_get_url_from_directions ( engine, from, to );
+  po->input_file_type = g_strdup ( vik_routing_engine_get_format (engine) );
+  options = NULL; // i.e. use the default download settings
 
   /* Save last selection */
   g_free ( last_from_str );