X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/75a790673a6a8b178084c0e2ac03ff848cef6c3f..362e1fbeb47a7161109dbe8a1b96db240fcad702:/src/datasource_osm_my_traces.c diff --git a/src/datasource_osm_my_traces.c b/src/datasource_osm_my_traces.c index 5db7a591..cccc318e 100644 --- a/src/datasource_osm_my_traces.c +++ b/src/datasource_osm_my_traces.c @@ -2,7 +2,7 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * Copyright (C) 2012, Rob Norris + * Copyright (C) 2012-2015, Rob Norris * * 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 @@ -51,8 +51,8 @@ typedef struct { static gpointer datasource_osm_my_traces_init ( acq_vik_t *avt ); static void datasource_osm_my_traces_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_osm_my_traces_get_cmd_string ( gpointer user_data, gchar **args, gchar **extra, DownloadMapOptions *options ); -static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused ); +static void datasource_osm_my_traces_get_process_options ( gpointer user_data, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2 ); +static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, ProcessOptions *process_options, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadFileOptions *options_unused ); static void datasource_osm_my_traces_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_osm_my_traces_interface = { @@ -66,8 +66,8 @@ VikDataSourceInterface vik_datasource_osm_my_traces_interface = { (VikDataSourceInitFunc) datasource_osm_my_traces_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc)datasource_osm_my_traces_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_osm_my_traces_get_cmd_string, - (VikDataSourceProcessFunc) datasource_osm_my_traces_process, + (VikDataSourceGetProcessOptionsFunc) datasource_osm_my_traces_get_process_options, + (VikDataSourceProcessFunc) datasource_osm_my_traces_process, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_osm_my_traces_cleanup, @@ -125,7 +125,7 @@ static void datasource_osm_my_traces_add_setup_widgets ( GtkWidget *dialog, VikV data->vvp = vvp; } -static void datasource_osm_my_traces_get_cmd_string ( gpointer user_data, gchar **args, gchar **extra, DownloadMapOptions *options ) +static void datasource_osm_my_traces_get_process_options ( gpointer user_data, ProcessOptions *po, DownloadFileOptions *options, const gchar *notused1, const gchar *notused2 ) { datasource_osm_my_traces_t *data = (datasource_osm_my_traces_t*) user_data; @@ -133,10 +133,8 @@ static void datasource_osm_my_traces_get_cmd_string ( gpointer user_data, gchar osm_set_login ( gtk_entry_get_text ( GTK_ENTRY(data->user_entry) ), gtk_entry_get_text ( GTK_ENTRY(data->password_entry) ) ); - // If going to use the values passed back into the process function parameters then these need to be set. + // If going to use the values passed back into the process function parameters then they need to be set. // But ATM we aren't - *args = NULL; - *extra = NULL; options = NULL; } @@ -560,7 +558,7 @@ static void set_in_current_view_property ( VikTrwLayer *vtl, datasource_osm_my_t } } -static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused ) +static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, ProcessOptions *process_options, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadFileOptions *options_unused ) { //datasource_osm_my_traces_t *data = (datasource_osm_my_traces_t *)adw->user_data; @@ -569,7 +567,11 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar gchar *user_pass = osm_get_login(); // Support .zip + bzip2 files directly - DownloadMapOptions options = { FALSE, FALSE, NULL, 2, NULL, user_pass, a_try_decompress_file }; // Allow a couple of redirects + DownloadFileOptions options = { FALSE, FALSE, NULL, 2, NULL, user_pass, a_try_decompress_file }; // Allow a couple of redirects + + gchar *tmpname = a_download_uri_to_tmp_file ( DS_OSM_TRACES_GPX_FILES, &options ); + if ( !tmpname ) + return FALSE; xml_data *xd = g_malloc ( sizeof (xml_data) ); //xd->xpath = g_string_new ( "" ); @@ -578,22 +580,24 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar xd->current_gpx_meta_data = new_gpx_meta_data_t(); xd->list_of_gpx_meta_data = NULL; - gchar *tmpname = a_download_uri_to_tmp_file ( DS_OSM_TRACES_GPX_FILES, &options ); result = read_gpx_files_metadata_xml ( tmpname, xd ); // Test already downloaded metadata file: eg: //result = read_gpx_files_metadata_xml ( "/tmp/viking-download.GI47PW", xd ); if ( tmpname ) { - g_remove ( tmpname ); + (void)util_remove ( tmpname ); g_free ( tmpname ); } - if ( ! result ) + if ( ! result ) { + g_free ( xd ); return FALSE; + } if ( g_list_length ( xd->list_of_gpx_meta_data ) == 0 ) { if (!vik_datasource_osm_my_traces_interface.is_thread) none_found ( GTK_WINDOW(adw->vw) ); + g_free ( xd ); return FALSE; } @@ -627,7 +631,7 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar if ( create_new_layer ) { // Have data but no layer - so create one - vtlX = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, vik_window_viewport(adw->vw), NULL, FALSE ) ); + vtlX = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, adw->vvp, FALSE ) ); if ( ((gpx_meta_data_t*)selected_iterator->data)->name ) vik_layer_rename ( VIK_LAYER ( vtlX ), ((gpx_meta_data_t*)selected_iterator->data)->name ); else @@ -639,14 +643,20 @@ static gboolean datasource_osm_my_traces_process ( VikTrwLayer *vtl, const gchar if ( gpx_id ) { gchar *url = g_strdup_printf ( DS_OSM_TRACES_GPX_URL_FMT, gpx_id ); - result = a_babel_convert_from_url ( vtlX, url, "gpx", status_cb, adw, &options ); + // NB download type is GPX (or a compressed version) + ProcessOptions my_po = *process_options; + my_po.url = url; + result = a_babel_convert_from ( vtlX, &my_po, status_cb, adw, &options ); // TODO investigate using a progress bar: // http://developer.gnome.org/gtk/2.24/GtkProgressBar.html got_something = got_something || result; - // TODO feedback to UI to inform which traces failed - if ( !result ) - g_warning ( _("Unable to get trace: %s"), url ); + if ( !result ) { + // Report errors to the status bar + gchar* msg = g_strdup_printf ( _("Unable to get trace: %s"), url ); + vik_window_statusbar_update ( adw->vw, msg, VIK_STATUSBAR_INFO ); + g_free (msg); + } g_free ( url ); }