X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/44871dd11ce2566d2ffd45c447219bac1c7f7aff..a502a3b8217f98360424f681ed3bb912127a446f:/src/acquire.c?ds=sidebyside diff --git a/src/acquire.c b/src/acquire.c index c2629da1..0e10c1ab 100644 --- a/src/acquire.c +++ b/src/acquire.c @@ -2,7 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2003-2005, Evan Battaglia - * Copyright (C) 2013, Rob Norris + * Copyright (C) 2013-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 @@ -32,14 +32,15 @@ #include "babel.h" #include "gpx.h" #include "acquire.h" -#include "util.h" /************************ FILTER LIST *******************/ // extern VikDataSourceInterface vik_datasource_gps_interface; /*** Input is TRWLayer ***/ extern VikDataSourceInterface vik_datasource_bfilter_simplify_interface; +extern VikDataSourceInterface vik_datasource_bfilter_compress_interface; extern VikDataSourceInterface vik_datasource_bfilter_dup_interface; +extern VikDataSourceInterface vik_datasource_bfilter_manual_interface; /*** Input is a track and a TRWLayer ***/ extern VikDataSourceInterface vik_datasource_bfilter_polygon_interface; @@ -49,7 +50,9 @@ extern VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface; const VikDataSourceInterface *filters[] = { &vik_datasource_bfilter_simplify_interface, + &vik_datasource_bfilter_compress_interface, &vik_datasource_bfilter_dup_interface, + &vik_datasource_bfilter_manual_interface, &vik_datasource_bfilter_polygon_interface, &vik_datasource_bfilter_exclude_polygon_interface, }; @@ -63,11 +66,10 @@ VikTrack *filter_track = NULL; /* passed along to worker thread */ typedef struct { acq_dialog_widgets_t *w; - gchar *cmd; - gchar *extra; + ProcessOptions *po; gboolean creating_new_layer; VikTrwLayer *vtl; - gpointer options; + DownloadFileOptions *options; } w_and_interface_t; @@ -134,20 +136,30 @@ static void on_complete_process (w_and_interface_t *wi) } } +static void free_process_options ( ProcessOptions *po ) +{ + if ( po ) { + g_free ( po->babelargs ); + g_free ( po->filename ); + g_free ( po->input_file_type ); + g_free ( po->babel_filters ); + g_free ( po->url ); + g_free ( po->shell_command ); + g_free ( po ); + } +} + /* this routine is the worker thread. there is only one simultaneous download allowed */ static void get_from_anything ( w_and_interface_t *wi ) { - gchar *cmd = wi->cmd; - gchar *extra = wi->extra; gboolean result = TRUE; VikDataSourceInterface *source_interface = wi->w->source_interface; - if ( source_interface->process_func ) - result = source_interface->process_func ( wi->vtl, cmd, extra, (BabelStatusFunc) progress_func, wi->w, wi->options ); - - g_free ( cmd ); - g_free ( extra ); + if ( source_interface->process_func ) { + result = source_interface->process_func ( wi->vtl, wi->po, (BabelStatusFunc)progress_func, wi->w, wi->options ); + } + free_process_options ( wi->po ); g_free ( wi->options ); if (wi->w->running && !result) { @@ -194,13 +206,11 @@ static void acquire ( VikWindow *vw, /* for manual dialogs */ GtkWidget *dialog = NULL; GtkWidget *status; - gchar *cmd = NULL; - gchar *extra = NULL; - gchar *cmd_off = NULL; - gchar *extra_off = NULL; + gchar *args_off = NULL; + gchar *fd_off = NULL; acq_dialog_widgets_t *w; gpointer user_data; - gpointer options = NULL; + DownloadFileOptions *options = g_malloc0 ( sizeof(DownloadFileOptions) ); acq_vik_t avt; avt.vlp = vlp; @@ -267,13 +277,13 @@ static void acquire ( VikWindow *vw, return; /* TODO: do we have to free anything here? */ } - /* CREATE INPUT DATA & GET COMMAND STRING */ + /* CREATE INPUT DATA & GET OPTIONS */ + ProcessOptions *po = g_malloc0 ( sizeof(ProcessOptions) ); if ( source_interface->inputtype == VIK_DATASOURCE_INPUTTYPE_TRWLAYER ) { gchar *name_src = a_gpx_write_tmp_file ( vtl, NULL ); - ((VikDataSourceGetCmdStringFuncWithInput) source_interface->get_cmd_string_func) - ( pass_along_data, &cmd, &extra, name_src ); + source_interface->get_process_options_func ( pass_along_data, po, NULL, name_src, NULL ); util_add_to_deletion_list ( name_src ); @@ -282,8 +292,7 @@ static void acquire ( VikWindow *vw, gchar *name_src = a_gpx_write_tmp_file ( vtl, NULL ); gchar *name_src_track = a_gpx_write_track_tmp_file ( track, NULL ); - ((VikDataSourceGetCmdStringFuncWithInputInput) source_interface->get_cmd_string_func) - ( pass_along_data, &cmd, &extra, name_src, name_src_track ); + source_interface->get_process_options_func ( pass_along_data, po, NULL, name_src, name_src_track ); util_add_to_deletion_list ( name_src ); util_add_to_deletion_list ( name_src_track ); @@ -293,16 +302,15 @@ static void acquire ( VikWindow *vw, } else if ( source_interface->inputtype == VIK_DATASOURCE_INPUTTYPE_TRACK ) { gchar *name_src_track = a_gpx_write_track_tmp_file ( track, NULL ); - ((VikDataSourceGetCmdStringFuncWithInput) source_interface->get_cmd_string_func) - ( pass_along_data, &cmd, &extra, name_src_track ); + source_interface->get_process_options_func ( pass_along_data, po, NULL, NULL, name_src_track ); g_free ( name_src_track ); - } else if ( source_interface->get_cmd_string_func ) - source_interface->get_cmd_string_func ( pass_along_data, &cmd, &extra, &options ); + } else if ( source_interface->get_process_options_func ) + source_interface->get_process_options_func ( pass_along_data, po, options, NULL, NULL ); /* Get data for Off command */ if ( source_interface->off_func ) { - source_interface->off_func ( pass_along_data, &cmd_off, &extra_off ); + source_interface->off_func ( pass_along_data, &args_off, &fd_off ); } /* cleanup for option dialogs */ @@ -317,8 +325,7 @@ static void acquire ( VikWindow *vw, wi = g_malloc(sizeof(*wi)); wi->w = w; wi->w->source_interface = source_interface; - wi->cmd = cmd; - wi->extra = extra; /* usually input data type (?) */ + wi->po = po; wi->options = options; wi->vtl = vtl; wi->creating_new_layer = (!vtl); // Default if Auto Layer Management is passed in @@ -368,7 +375,7 @@ static void acquire ( VikWindow *vw, } if ( source_interface->is_thread ) { - if ( cmd ) { + if ( po->babelargs || po->url || po->shell_command ) { #if GLIB_CHECK_VERSION (2, 32, 0) g_thread_try_new ( "get_from_anything", (GThreadFunc)get_from_anything, wi, NULL ); #else @@ -380,13 +387,14 @@ static void acquire ( VikWindow *vw, w->running = FALSE; // NB Thread will free memory } else { - if ( cmd_off ) { + if ( args_off ) { /* Turn off */ - a_babel_convert_from (NULL, cmd_off, extra_off, NULL, NULL, NULL); - g_free ( cmd_off ); + ProcessOptions off_po = { args_off, fd_off, NULL, NULL, NULL }; + a_babel_convert_from (NULL, &off_po, NULL, NULL, NULL); + g_free ( args_off ); } - if ( extra_off ) - g_free ( extra_off ); + if ( fd_off ) + g_free ( fd_off ); // Thread finished by normal completion - free memory g_free ( w ); @@ -402,12 +410,11 @@ static void acquire ( VikWindow *vw, else { // bypass thread method malarkly - you'll just have to wait... if ( source_interface->process_func ) { - gboolean result = source_interface->process_func ( wi->vtl, cmd, extra, (BabelStatusFunc) progress_func, w, options ); + gboolean result = source_interface->process_func ( wi->vtl, po, (BabelStatusFunc) progress_func, w, options ); if ( !result ) a_dialog_msg ( GTK_WINDOW(vw), GTK_MESSAGE_ERROR, _("Error: acquisition failed."), NULL ); } - g_free ( cmd ); - g_free ( extra ); + free_process_options ( po ); g_free ( options ); on_complete_process ( wi );