]> git.street.me.uk Git - andy/viking.git/blobdiff - src/datasource_url.c
Trap some errors reported by gpsbabel
[andy/viking.git] / src / datasource_url.c
index 14886207243634a7d4b924858676ef5644c52ca3..c5c548f5efc822b531cce42435770213f396dfe1 100644 (file)
@@ -25,6 +25,7 @@
 #include "viking.h"
 #include "acquire.h"
 #include "babel.h"
+#include "ui_util.h"
 
 // Initially was just going to be a URL and always in GPX format
 // But might as well specify the file type as per datasource_file.c
@@ -40,13 +41,13 @@ static int last_type = -1;
 
 static gpointer datasource_url_init ( acq_vik_t *avt );
 static void datasource_url_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data );
-static void datasource_url_get_cmd_string ( datasource_url_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options );
+static void datasource_url_get_process_options ( datasource_url_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *download_options, const gchar *not_used2, const gchar *not_used3 );
 static void datasource_url_cleanup ( gpointer data );
 
 VikDataSourceInterface vik_datasource_url_interface = {
        N_("Acquire from URL"),
        N_("URL"),
-       VIK_DATASOURCE_CREATENEWLAYER,
+       VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT,
        VIK_DATASOURCE_INPUTTYPE_NONE,
        TRUE,
        TRUE,
@@ -54,8 +55,8 @@ VikDataSourceInterface vik_datasource_url_interface = {
        (VikDataSourceInitFunc)               datasource_url_init,
        (VikDataSourceCheckExistenceFunc)     NULL,
        (VikDataSourceAddSetupWidgetsFunc)    datasource_url_add_setup_widgets,
-       (VikDataSourceGetCmdStringFunc)       datasource_url_get_cmd_string,
-       (VikDataSourceProcessFunc)            a_babel_convert_from_url,
+       (VikDataSourceGetProcessOptionsFunc)  datasource_url_get_process_options,
+       (VikDataSourceProcessFunc)            a_babel_convert_from,
        (VikDataSourceProgressFunc)           NULL,
        (VikDataSourceAddProgressWidgetsFunc) NULL,
        (VikDataSourceCleanupFunc)            datasource_url_cleanup,
@@ -98,7 +99,9 @@ static void datasource_url_add_setup_widgets ( GtkWidget *dialog, VikViewport *v
 {
        datasource_url_widgets_t *widgets = (datasource_url_widgets_t *)user_data;
        GtkWidget *label = gtk_label_new (_("URL:"));
-       widgets->url = gtk_entry_new ( );
+       widgets->url = ui_entry_new ( NULL, GTK_ENTRY_ICON_SECONDARY );
+       // 'ok' when press return in the entry
+       g_signal_connect_swapped ( widgets->url, "activate", G_CALLBACK(a_dialog_response_accept), dialog );
 
        GtkWidget *type_label = gtk_label_new (_("File type:"));
 
@@ -119,7 +122,7 @@ static void datasource_url_add_setup_widgets ( GtkWidget *dialog, VikViewport *v
                last_type = ( wanted_entry < 0 ) ? 0 : wanted_entry;
        }
 
-       if ( a_babel_file_list ) {
+       if ( a_babel_available() ) {
                widgets->type = vik_combo_box_text_new ();
                g_list_foreach (a_babel_file_list, fill_combo_box, widgets->type);
                gtk_combo_box_set_active (GTK_COMBO_BOX (widgets->type), last_type);
@@ -139,7 +142,7 @@ static void datasource_url_add_setup_widgets ( GtkWidget *dialog, VikViewport *v
        gtk_widget_show_all(dialog);
 }
 
-static void datasource_url_get_cmd_string ( datasource_url_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options )
+static void datasource_url_get_process_options ( datasource_url_widgets_t *widgets, ProcessOptions *po, DownloadFileOptions *download_options, const gchar *not_used2, const gchar *not_used3 )
 {
        // Retrieve the user entered value
        const gchar *value = gtk_entry_get_text ( GTK_ENTRY(widgets->url) );
@@ -147,12 +150,15 @@ static void datasource_url_get_cmd_string ( datasource_url_widgets_t *widgets, g
        if (GTK_IS_COMBO_BOX (widgets->type) )
                last_type = gtk_combo_box_get_active ( GTK_COMBO_BOX (widgets->type) );
 
-       *input_file_type = NULL; // Default to gpx
+       po->input_file_type = NULL; // Default to gpx
        if ( a_babel_file_list )
-               *input_file_type = g_strdup ( ((BabelFile*)g_list_nth_data (a_babel_file_list, last_type))->name );
+               po->input_file_type = g_strdup ( ((BabelFile*)g_list_nth_data (a_babel_file_list, last_type))->name );
 
-       *cmd = g_strdup ( value );
-       options = NULL;
+       po->url = g_strdup ( value );
+
+       // Support .zip + bzip2 files directly
+       download_options->convert_file = a_try_decompress_file;
+       download_options->follow_location = 5;
 }
 
 static void datasource_url_cleanup ( gpointer data )