From 17acdaec83bb90c38159fabe03286a238da51dc3 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Tue, 28 Apr 2015 22:18:11 +0100 Subject: [PATCH] Rework Acquire framework process function options for maintainability and understanding. Instead of overloaded parameters, use a structure with fields for the specific processing types and gpsbabel options. Thus rename functions and parameter variables, update the usage thereof and simplify code as applicable. --- src/acquire.c | 74 ++++++++++---------- src/acquire.h | 29 ++++---- src/babel.c | 124 ++++++++++----------------------- src/babel.h | 27 +++++-- src/datasource_bfilter.c | 119 +++++++++++-------------------- src/datasource_file.c | 17 ++--- src/datasource_gc.c | 12 ++-- src/datasource_geojson.c | 14 ++-- src/datasource_geotag.c | 16 ++--- src/datasource_gps.c | 24 +++---- src/datasource_osm.c | 15 ++-- src/datasource_osm_my_traces.c | 23 +++--- src/datasource_routing.c | 17 +++-- src/datasource_url.c | 16 ++--- src/datasource_wikipedia.c | 8 +-- src/file.c | 3 +- src/vikgpslayer.c | 18 ++--- src/vikroutingwebengine.c | 6 +- src/vikwebtool_datasource.c | 25 +++---- 19 files changed, 258 insertions(+), 329 deletions(-) diff --git a/src/acquire.c b/src/acquire.c index 249bcfda..4be3243b 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 @@ -64,8 +64,7 @@ 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; @@ -135,20 +134,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) { @@ -195,10 +204,8 @@ 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; @@ -268,13 +275,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 ); @@ -283,8 +290,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 ); @@ -294,16 +300,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 */ @@ -318,8 +323,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 @@ -369,7 +373,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 @@ -381,13 +385,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 ); @@ -403,12 +408,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 ); diff --git a/src/acquire.h b/src/acquire.h index fb22918f..16ed7ded 100644 --- a/src/acquire.h +++ b/src/acquire.h @@ -2,6 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2003-2005, Evan Battaglia + * Copyright (C) 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 @@ -93,33 +94,30 @@ typedef gchar *(*VikDataSourceCheckExistenceFunc) (); typedef void (*VikDataSourceAddSetupWidgetsFunc) ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); /** - * VikDataSourceGetCmdStringFunc: + * VikDataSourceGetProcessOptionsFunc: * @user_data: provided by #VikDataSourceInterface.init_func or dialog with params - * @args: the arguments computed for #VikDataSourceInterface.process_func - * @extra: extra arguments for #VikDataSourceInterface.process_func - * @options: even more options for #VikDataSourceInterface.process_func + * @process_options: main options controlling the behaviour of #VikDataSourceInterface.process_func + * @download_options: optional options for downloads from URLs for #VikDataSourceInterface.process_func + * @input_file_name: + * @input_track_file_name: * * set both to %NULL to signal refusal (ie already downloading). */ -typedef void (*VikDataSourceGetCmdStringFunc) ( gpointer user_data, gchar **args, gchar **extra, gpointer options ); - -typedef void (*VikDataSourceGetCmdStringFuncWithInput) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, const gchar *input_file_name ); -typedef void (*VikDataSourceGetCmdStringFuncWithInputInput) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, const gchar *input_file_name, const gchar *input_track_file_name ); +typedef void (*VikDataSourceGetProcessOptionsFunc) ( gpointer user_data, ProcessOptions *process_options, gpointer download_options, const gchar *input_file_name, const gchar *input_track_file_name ); /** * VikDataSourceProcessFunc: * @vtl: - * @cmd: the arguments computed by #VikDataSourceInterface.get_cmd_string_func - * @extra: the extra arguments computed by #VikDataSourceInterface.get_cmd_string_func + * @process_options: options to control the behaviour of this function (see #ProcessOptions) * @status_cb: the #VikDataSourceInterface.progress_func * @adw: the widgets and data used by #VikDataSourceInterface.progress_func - * @options: more options returned by #VikDataSourceInterface.get_cmd_string_func + * @download_options: Optional options used if downloads from URLs is used. * * The actual function to do stuff - must report success/failure. */ -typedef gboolean (*VikDataSourceProcessFunc) ( gpointer vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer options ); +typedef gboolean (*VikDataSourceProcessFunc) ( gpointer vtl, ProcessOptions *process_options, BabelStatusFunc, acq_dialog_widgets_t *adw, gpointer download_options ); -/* */ +/* NB Same as BabelStatusFunc */ typedef void (*VikDataSourceProgressFunc) ( BabelProgressCode c, gpointer data, acq_dialog_widgets_t *w ); /** @@ -136,7 +134,7 @@ typedef void (*VikDataSourceAddProgressWidgetsFunc) ( GtkWidget *dialog, gpoint */ typedef void (*VikDataSourceCleanupFunc) ( gpointer user_data ); -typedef void (*VikDataSourceOffFunc) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype );; +typedef void (*VikDataSourceOffFunc) ( gpointer user_data, gchar **babelargs, gchar **file_descriptor ); /** * VikDataSourceInterface: @@ -159,8 +157,7 @@ struct _VikDataSourceInterface { VikDataSourceAddSetupWidgetsFunc add_setup_widgets_func; /*** ***/ - /* or VikDataSourceGetCmdStringFuncWithInput, if inputtype is not NONE */ - VikDataSourceGetCmdStringFunc get_cmd_string_func; + VikDataSourceGetProcessOptionsFunc get_process_options_func; VikDataSourceProcessFunc process_func; diff --git a/src/babel.c b/src/babel.c index 343fd528..3f13ab37 100644 --- a/src/babel.c +++ b/src/babel.c @@ -4,6 +4,7 @@ * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2006, Quy Tonthat * Copyright (C) 2013, Guilhem Bonnefille + * Copyright (C) 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 @@ -25,9 +26,8 @@ * SECTION:babel * @short_description: running external programs and redirecting to TRWLayers. * - * GPSBabel may not be necessary for everything -- for instance, - * use a_babel_convert_from_shellcommand() with input_file_type == %NULL - * for an external program that outputs GPX. + * GPSBabel may not be necessary for everything, + * one can use shell_command option but this will be OS platform specific */ #ifdef HAVE_CONFIG_H @@ -50,11 +50,6 @@ /* TODO in the future we could have support for other shells (change command strings), or not use a shell at all */ #define BASH_LOCATION "/bin/bash" -/** - * List of supported protocols. - */ -const gchar *PROTOS[] = { "http://", "https://", "ftp://", NULL }; - /** * Path to gpsbabel */ @@ -146,7 +141,8 @@ gboolean a_babel_convert( VikTrwLayer *vt, const char *babelargs, BabelStatusFun gchar *name_src = a_gpx_write_tmp_file ( vt, NULL ); if ( name_src ) { - ret = a_babel_convert_from ( vt, bargs, name_src, cb, user_data, not_used ); + ProcessOptions po = { bargs, name_src, NULL, NULL, NULL }; + ret = a_babel_convert_from ( vt, &po, cb, user_data, not_used ); g_remove(name_src); g_free(name_src); } @@ -183,6 +179,11 @@ static gboolean babel_general_convert( BabelStatusFunc cb, gchar **args, gpointe GError *error = NULL; gint babel_stdout; + if ( vik_debug ) { + for ( guint i=0; args[i]; i++ ) + g_debug ("%s: %s", __FUNCTION__, args[i] ); + } + if (!g_spawn_async_with_pipes (NULL, args, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, NULL, &babel_stdout, NULL, &error)) { g_warning ("Async command failed: %s", error->message); g_error_free(error); @@ -323,30 +324,11 @@ gboolean a_babel_convert_from_filter( VikTrwLayer *vt, const char *babelargs, co return ret; } -/** - * a_babel_convert_from: - * @vt: The TRW layer to place data into. Duplicate items will be overwritten. - * @babelargs: A string containing gpsbabel command line options. This string - * must include the input file type (-i) option. - * @from: The file name to convert from - * @cb: Optional callback function. Same usage as in a_babel_convert(). - * @user_data: passed along to cb - * @not_used: Must use NULL - * - * Loads data into a trw layer from a file, using gpsbabel. This routine is synchronous; - * that is, it will block the calling program until the conversion is done. To avoid blocking, call - * this routine from a worker thread. - * - * Returns: %TRUE on success - */ -gboolean a_babel_convert_from( VikTrwLayer *vt, const char *babelargs, const char *from, BabelStatusFunc cb, gpointer user_data, gpointer not_used ) -{ - return a_babel_convert_from_filter ( vt, babelargs, from, NULL, cb, user_data, not_used ); -} /** * a_babel_convert_from_shellcommand: * @vt: The #VikTrwLayer where to insert the collected data * @input_cmd: the command to run + * @input_file_type: * @cb: Optional callback function. Same usage as in a_babel_convert(). * @user_data: passed along to cb * @not_used: Must use NULL @@ -393,17 +375,17 @@ gboolean a_babel_convert_from_shellcommand ( VikTrwLayer *vt, const char *input_ } /** - * a_babel_convert_from_url: + * a_babel_convert_from_url_filter: * @vt: The #VikTrwLayer where to insert the collected data * @url: the URL to fetch - * @babelfilters: the filter arguments to pass to gpsbabel - * @cb: Optional callback function. Same usage as in a_babel_convert(). - * @user_data: passed along to cb - * @options: download options. Maybe NULL. + * @input_type: If input_type is %NULL, input must be GPX. + * @babelfilters: The filter arguments to pass to gpsbabel + * @cb: Optional callback function. Same usage as in a_babel_convert(). + * @user_data: Passed along to cb + * @options: Download options. If %NULL then default download options will be used. * - * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_file_type. - * If input_file_type is %NULL, input must be GPX. - * If input_file_type and babelfilters are %NULL, gpsbabel is not used. + * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_type. + * If input_type and babelfilters are %NULL, gpsbabel is not used. * * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX * @@ -452,59 +434,29 @@ gboolean a_babel_convert_from_url_filter ( VikTrwLayer *vt, const char *url, con } /** - * a_babel_convert_from_url: - * @vt: The #VikTrwLayer where to insert the collected data - * @url: the URL to fetch - * @cb: Optional callback function. Same usage as in a_babel_convert(). - * @user_data: passed along to cb - * @options: download options. Maybe NULL. - * - * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_file_type. - * If input_file_type is %NULL, doesn't use GPSBabel. Input must be GPX. - * - * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX - * - */ -gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ) -{ - return a_babel_convert_from_url_filter ( vt, url, input_type, NULL, cb, user_data, options ); -} - -/** - * a_babel_convert_from_url_or_shell: - * @vt: The #VikTrwLayer where to insert the collected data - * @url: the URL to fetch - * @cb: Optional callback function. Same usage as in a_babel_convert(). - * @user_data: passed along to cb - * @options: download options. Maybe NULL. - * - * Download the file pointed by the URL and optionally uses GPSBabel to convert from input_file_type. - * If input_file_type is %NULL, doesn't use GPSBabel. Input must be GPX. + * a_babel_convert_from: + * @vt: The TRW layer to place data into. Duplicate items will be overwritten. + * @process_options: The options to control the appropriate processing function. See #ProcessOptions for more detail + * @cb: Optional callback function. Same usage as in a_babel_convert(). + * @user_data: passed along to cb + * @download_options: If downloading from a URL use these options (may be NULL) * - * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX + * Loads data into a trw layer from a file, using gpsbabel. This routine is synchronous; + * that is, it will block the calling program until the conversion is done. To avoid blocking, call + * this routine from a worker thread. * + * Returns: %TRUE on success */ -gboolean a_babel_convert_from_url_or_shell ( VikTrwLayer *vt, const char *input, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ) +gboolean a_babel_convert_from ( VikTrwLayer *vt, ProcessOptions *process_options, BabelStatusFunc cb, gpointer user_data, gpointer download_options ) { - - /* Check nature of input */ - gboolean isUrl = FALSE; - int i = 0; - for (i = 0 ; PROTOS[i] != NULL ; i++) - { - const gchar *proto = PROTOS[i]; - if (strncmp (input, proto, strlen(proto)) == 0) - { - /* Procotol matches: save result */ - isUrl = TRUE; - } - } - - /* Do the job */ - if (isUrl) - return a_babel_convert_from_url (vt, input, input_type, cb, user_data, options); - else - return a_babel_convert_from_shellcommand (vt, input, input_type, cb, user_data, options); + if ( !process_options ) return FALSE; + if ( process_options->url ) + return a_babel_convert_from_url_filter ( vt, process_options->url, process_options->input_file_type, process_options->babel_filters, cb, user_data, download_options ); + if ( process_options->babelargs ) + return a_babel_convert_from_filter ( vt, process_options->babelargs, process_options->filename, process_options->babel_filters, cb, user_data, download_options ); + if ( process_options->shell_command ) + return a_babel_convert_from_shellcommand ( vt, process_options->shell_command, process_options->filename, cb, user_data, download_options ); + return FALSE; } static gboolean babel_general_convert_to( VikTrwLayer *vt, VikTrack *trk, BabelStatusFunc cb, gchar **args, const gchar *name_src, gpointer user_data ) diff --git a/src/babel.h b/src/babel.h index baf2cd44..d32f453d 100644 --- a/src/babel.h +++ b/src/babel.h @@ -3,6 +3,7 @@ * * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2005, Alex Foobarian + * Copyright (C) 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 @@ -50,6 +51,22 @@ typedef enum { */ typedef void (*BabelStatusFunc)(BabelProgressCode, gpointer, gpointer); +/** + * ProcessOptions: + * + * All values are defaulted to NULL + * + * Need to specify at least one of babelargs, URL or shell_command + */ +typedef struct { + gchar* babelargs; // The standard initial arguments to gpsbabel (if gpsbabel is to be used) - normally should include the input file type (-i) option. + gchar* filename; // Input filename (or device port e.g. /dev/ttyS0) + gchar* input_file_type; // If NULL then uses internal file format handler (GPX only ATM), otherwise specify gpsbabel input type like "kml","tcx", etc... + gchar* url; // URL input rather than a filename + gchar* babel_filters; // Optional filter arguments to gpsbabel + gchar* shell_command; // Optional shell command to run instead of gpsbabel - but will be (Unix) platform specific +} ProcessOptions; + /** * BabelMode: * @@ -98,13 +115,9 @@ GList *a_babel_device_list; void a_babel_foreach_file_with_mode (BabelMode mode, GFunc func, gpointer user_data); void a_babel_foreach_file_read_any (GFunc func, gpointer user_data); -gboolean a_babel_convert( VikTrwLayer *vt, const char *babelargs, BabelStatusFunc cb, gpointer user_data, gpointer options ); -gboolean a_babel_convert_from_filter( VikTrwLayer *vt, const char *babelargs, const char *file, const char *babelfilters, BabelStatusFunc cb, gpointer user_data, gpointer options ); -gboolean a_babel_convert_from( VikTrwLayer *vt, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data, gpointer options ); -gboolean a_babel_convert_from_shellcommand ( VikTrwLayer *vt, const char *input_cmd, const char *input_file_type, BabelStatusFunc cb, gpointer user_data, gpointer options ); -gboolean a_babel_convert_from_url_filter ( VikTrwLayer *vt, const char *url, const char *input_type, const char *filter, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ); -gboolean a_babel_convert_from_url ( VikTrwLayer *vt, const char *url, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ); -gboolean a_babel_convert_from_url_or_shell ( VikTrwLayer *vt, const char *input, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *options ); +// NB needs to match typedef VikDataSourceProcessFunc in acquire.h +gboolean a_babel_convert_from ( VikTrwLayer *vt, ProcessOptions *process_options, BabelStatusFunc cb, gpointer user_data, gpointer download_options ); + gboolean a_babel_convert_to( VikTrwLayer *vt, VikTrack *track, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data ); void a_babel_init (); diff --git a/src/datasource_bfilter.c b/src/datasource_bfilter.c index 9b61cc7b..658d6069 100644 --- a/src/datasource_bfilter.c +++ b/src/datasource_bfilter.c @@ -2,7 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2003-2007, Evan Battaglia - * Copyright (C) 2014, Rob Norris + * Copyright (C) 2014-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 @@ -33,11 +33,6 @@ /************************************ Simplify (Count) *****************************/ -static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); - -/* TODO: shell_escape stuff */ -/* TODO: name is useless for filters */ - /* spin button scales */ VikLayerParamScale simplify_params_scales[] = { {1, 10000, 10, 0}, @@ -57,6 +52,11 @@ VikLayerParamData bfilter_simplify_params_defaults[] = { #endif }; +static void datasource_bfilter_simplify_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) +{ + po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,count=%d -o gpx -F -", input_filename, paramdatas[0].u ); +} + VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { N_("Simplify All Tracks..."), N_("Simplified Tracks"), @@ -66,8 +66,8 @@ VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { FALSE, /* keep dialog open after success */ TRUE, NULL, NULL, NULL, - (VikDataSourceGetCmdStringFunc) datasource_bfilter_simplify_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_simplify_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -78,19 +78,8 @@ VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { 0 }; - -static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) -{ - *input_file_type = NULL; - *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,count=%d -o gpx -F -", input_filename, paramdatas[0].u ); -} - /**************************** Compress (Simplify by Error Factor Method) *****************************/ -static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); - -/* TODO: shell_escape stuff */ - static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} }; VikLayerParam bfilter_compress_params[] = { @@ -109,6 +98,21 @@ VikLayerParamData bfilter_compress_params_defaults[] = { #endif }; +/** + * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html + */ +static void datasource_bfilter_compress_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) +{ + gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' '; + // I toyed with making the length,crosstrack or relative methods selectable + // However several things: + // - mainly that typical values to use for the error relate to method being used - so hard to explain and then give a default sensible value in the UI + // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM + // - options make this more complicated to use - is even that useful to be allowed to change the error value? + // NB units not applicable if relative method used - defaults to Miles when not specified + po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,crosstrack,error=%-.5f%c -o gpx -F -", input_filename, paramdatas[0].d, units ); +} + /** * Allow 'compressing' tracks/routes using the Simplify by Error Factor method */ @@ -121,8 +125,8 @@ VikDataSourceInterface vik_datasource_bfilter_compress_interface = { FALSE, // Close the dialog after successful operation TRUE, NULL, NULL, NULL, - (VikDataSourceGetCmdStringFunc) datasource_bfilter_compress_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_compress_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -133,29 +137,12 @@ VikDataSourceInterface vik_datasource_bfilter_compress_interface = { 0 }; -/** - * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html - */ -static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) -{ - *input_file_type = NULL; - gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' '; - // I toyed with making the length,crosstrack or relative methods selectable - // However several things: - // - mainly that typical values to use for the error relate to method being used - so hard to explain and then give a default sensible value in the UI - // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM - // - options make this more complicated to use - is even that useful to be allowed to change the error value? - // NB units not applicable if relative method used - defaults to Miles when not specified - *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,crosstrack,error=%-.5f%c -o gpx -F -", input_filename, paramdatas[0].d, units ); -} - /************************************ Duplicate Location ***********************************/ -static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); - -/* TODO: shell_escape stuff */ -/* TODO: name is useless for filters */ - +static void datasource_bfilter_dup_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) +{ + po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename ); +} VikDataSourceInterface vik_datasource_bfilter_dup_interface = { N_("Remove Duplicate Waypoints"), @@ -166,8 +153,8 @@ VikDataSourceInterface vik_datasource_bfilter_dup_interface = { FALSE, /* keep dialog open after success */ TRUE, NULL, NULL, NULL, - (VikDataSourceGetCmdStringFunc) datasource_bfilter_dup_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_dup_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -175,20 +162,13 @@ VikDataSourceInterface vik_datasource_bfilter_dup_interface = { }; -static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) -{ - *input_file_type = NULL; - *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename ); -} - - /************************************ Polygon ***********************************/ -static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ); - +static void datasource_bfilter_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename ) +{ + po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,file=- -o gpx -F -", input_track_filename, input_filename ); +} /* TODO: shell_escape stuff */ -/* TODO: name is useless for filters */ - VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { N_("Waypoints Inside This"), @@ -199,8 +179,8 @@ VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { FALSE, /* keep dialog open after success */ TRUE, NULL, NULL, NULL, - (VikDataSourceGetCmdStringFunc) datasource_bfilter_polygon_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_polygon_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -211,20 +191,13 @@ VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { 0 }; +/************************************ Exclude Polygon ***********************************/ -static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ) +static void datasource_bfilter_exclude_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename ) { - *input_file_type = NULL; - *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,file=- -o gpx -F -", input_track_filename, input_filename ); + po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,exclude,file=- -o gpx -F -", input_track_filename, input_filename ); } - -/************************************ Exclude Polygon ***********************************/ - -static void datasource_bfilter_exclude_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ); - /* TODO: shell_escape stuff */ -/* TODO: name is useless for filters */ - VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { N_("Waypoints Outside This"), @@ -235,8 +208,8 @@ VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { FALSE, /* keep dialog open after success */ TRUE, NULL, NULL, NULL, - (VikDataSourceGetCmdStringFunc) datasource_bfilter_exclude_polygon_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_exclude_polygon_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -246,11 +219,3 @@ VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { NULL, 0 }; - - -static void datasource_bfilter_exclude_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ) -{ - *input_file_type = NULL; - *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,exclude,file=- -o gpx -F -", input_track_filename, input_filename ); -} - diff --git a/src/datasource_file.c b/src/datasource_file.c index e55891d3..ec0fc3a8 100644 --- a/src/datasource_file.c +++ b/src/datasource_file.c @@ -2,6 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2011, Guilhem Bonnefille + * Copyright (C) 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 @@ -53,7 +54,7 @@ static int last_type = 0; static gpointer datasource_file_init ( acq_vik_t *avt ); static void datasource_file_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_file_get_cmd_string ( datasource_file_widgets_t *widgets, gchar **cmd, gchar **input_file_type, gpointer not_used ); +static void datasource_file_get_process_options ( datasource_file_widgets_t *widgets, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ); static void datasource_file_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_file_interface = { @@ -67,8 +68,8 @@ VikDataSourceInterface vik_datasource_file_interface = { (VikDataSourceInitFunc) datasource_file_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_file_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_file_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from, + (VikDataSourceGetProcessOptionsFunc) datasource_file_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_file_cleanup, @@ -160,7 +161,7 @@ static void datasource_file_add_setup_widgets ( GtkWidget *dialog, VikViewport * } /* See VikDataSourceInterface */ -static void datasource_file_get_cmd_string ( datasource_file_widgets_t *widgets, gchar **cmd, gchar **input_file, gpointer not_used ) +static void datasource_file_get_process_options ( datasource_file_widgets_t *widgets, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ) { /* Retrieve the file selected */ gchar *filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(widgets->file) ); @@ -179,14 +180,14 @@ static void datasource_file_get_cmd_string ( datasource_file_widgets_t *widgets, last_type = gtk_combo_box_get_active ( GTK_COMBO_BOX (widgets->type) ); type = (a_babel_ui_file_type_selector_get ( widgets->type ))->name; - /* Build the string */ - *cmd = g_strdup_printf( "-i %s", type); - *input_file = g_strdup(filename); + /* Generate the process options */ + po->babelargs = g_strdup_printf( "-i %s", type); + po->filename = g_strdup(filename); /* Free memory */ g_free (filename); - g_debug(_("using babel args '%s' and file '%s'"), *cmd, *input_file); + g_debug(_("using babel args '%s' and file '%s'"), po->babelargs, po->filename); } /* See VikDataSourceInterface */ diff --git a/src/datasource_gc.c b/src/datasource_gc.c index d8e20937..b3d7234f 100644 --- a/src/datasource_gc.c +++ b/src/datasource_gc.c @@ -2,6 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2003-2007, Evan Battaglia + * Copyright (C) 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 @@ -56,7 +57,7 @@ typedef struct { static gpointer datasource_gc_init ( acq_vik_t *avt ); static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_file_type, gpointer not_used ); +static void datasource_gc_get_process_options ( datasource_gc_widgets_t *widgets, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ); static void datasource_gc_cleanup ( datasource_gc_widgets_t *widgets ); static gchar *datasource_gc_check_existence (); @@ -73,8 +74,8 @@ VikDataSourceInterface vik_datasource_gc_interface = { (VikDataSourceInitFunc) datasource_gc_init, (VikDataSourceCheckExistenceFunc) datasource_gc_check_existence, (VikDataSourceAddSetupWidgetsFunc) datasource_gc_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_gc_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + (VikDataSourceGetProcessOptionsFunc) datasource_gc_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_gc_cleanup, @@ -219,7 +220,7 @@ static void datasource_gc_add_setup_widgets ( GtkWidget *dialog, VikViewport *vv gtk_widget_show_all(dialog); } -static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_file_type, gpointer not_used ) +static void datasource_gc_get_process_options ( datasource_gc_widgets_t *widgets, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ) { //gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); gchar *safe_user = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "username")->s ); @@ -241,7 +242,7 @@ static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gch // 3. Converts webpages into a single waypoint file, ignoring zero location waypoints '-z' // Probably as they are premium member only geocaches and user is only a basic member // Final output is piped into GPSbabel - hence removal of *html is done at beginning of the command sequence - *cmd = g_strdup_printf( "rm -f ~/.geo/caches/*html ; %s -P -n%d -r%.1fM -u %s -p %s %s %s ; %s -z ~/.geo/caches/*html ", + po->shell_command = g_strdup_printf( "rm -f ~/.geo/caches/*html ; %s -P -n%d -r%.1fM -u %s -p %s %s %s ; %s -z ~/.geo/caches/*html ", GC_PROGRAM1, gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ), gtk_spin_button_get_value_as_float ( GTK_SPIN_BUTTON(widgets->miles_radius_spin) ), @@ -249,7 +250,6 @@ static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gch safe_pass, slat, slon, GC_PROGRAM2 ); - *input_file_type = NULL; //g_free ( safe_string ); g_free ( safe_user ); g_free ( safe_pass ); diff --git a/src/datasource_geojson.c b/src/datasource_geojson.c index ec9fd78a..23d49749 100644 --- a/src/datasource_geojson.c +++ b/src/datasource_geojson.c @@ -2,7 +2,7 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * Copyright (C) 2014, Rob Norris + * Copyright (C) 2014-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 @@ -38,8 +38,8 @@ static gchar *last_folder_uri = NULL; static gpointer datasource_geojson_init ( acq_vik_t *avt ); static void datasource_geojson_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_geojson_get_cmd_string ( datasource_geojson_user_data_t *ud, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ); -static gboolean datasource_geojson_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ); +static void datasource_geojson_get_process_options ( datasource_geojson_user_data_t *user_data, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ); +static gboolean datasource_geojson_process ( VikTrwLayer *vtl, ProcessOptions *process_options, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused ); static void datasource_geojson_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_geojson_interface = { @@ -53,7 +53,7 @@ VikDataSourceInterface vik_datasource_geojson_interface = { (VikDataSourceInitFunc) datasource_geojson_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_geojson_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_geojson_get_cmd_string, + (VikDataSourceGetProcessOptionsFunc) datasource_geojson_get_process_options, (VikDataSourceProcessFunc) datasource_geojson_process, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, @@ -112,7 +112,7 @@ static void datasource_geojson_add_setup_widgets ( GtkWidget *dialog, VikViewpor gtk_widget_show_all ( dialog ); } -static void datasource_geojson_get_cmd_string ( datasource_geojson_user_data_t *userdata, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ) +static void datasource_geojson_get_process_options ( datasource_geojson_user_data_t *userdata, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ) { // Retrieve the files selected userdata->filelist = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER(userdata->files) ); // Not reusable !! @@ -126,13 +126,13 @@ static void datasource_geojson_get_cmd_string ( datasource_geojson_user_data_t * //GtkFileFilter *filter = gtk_file_chooser_get_filter ( GTK_FILE_CHOOSER(userdata->files) ); // return some value so *thread* processing will continue - *cmd = g_strdup ("fake command"); // Not really used, thus no translations + po->babelargs = g_strdup ("fake command"); // Not really used, thus no translations } /** * Process selected files and try to generate waypoints storing them in the given vtl */ -static gboolean datasource_geojson_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ) +static gboolean datasource_geojson_process ( VikTrwLayer *vtl, ProcessOptions *process_options, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options_unused ) { datasource_geojson_user_data_t *user_data = (datasource_geojson_user_data_t *)adw->user_data; diff --git a/src/datasource_geotag.c b/src/datasource_geotag.c index 7deee1a3..a3a4ed41 100644 --- a/src/datasource_geotag.c +++ b/src/datasource_geotag.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 @@ -43,8 +43,8 @@ static gchar *last_folder_uri = NULL; static gpointer datasource_geotag_init ( acq_vik_t *avt ); static void datasource_geotag_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_geotag_get_cmd_string ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, gpointer not_used ); -static gboolean datasource_geotag_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ); +static void datasource_geotag_get_process_options ( gpointer user_data, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ); +static gboolean datasource_geotag_process ( VikTrwLayer *vtl, ProcessOptions *po, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ); static void datasource_geotag_cleanup ( gpointer user_data ); VikDataSourceInterface vik_datasource_geotag_interface = { @@ -58,8 +58,8 @@ VikDataSourceInterface vik_datasource_geotag_interface = { (VikDataSourceInitFunc) datasource_geotag_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_geotag_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_geotag_get_cmd_string, - (VikDataSourceProcessFunc) datasource_geotag_process, + (VikDataSourceGetProcessOptionsFunc) datasource_geotag_get_process_options, + (VikDataSourceProcessFunc) datasource_geotag_process, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_geotag_cleanup, @@ -125,7 +125,7 @@ static void datasource_geotag_add_setup_widgets ( GtkWidget *dialog, VikViewport gtk_widget_show_all ( dialog ); } -static void datasource_geotag_get_cmd_string ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, gpointer not_used ) +static void datasource_geotag_get_process_options ( gpointer user_data, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ) { datasource_geotag_user_data_t *userdata = (datasource_geotag_user_data_t *)user_data; /* Retrieve the files selected */ @@ -140,13 +140,13 @@ static void datasource_geotag_get_cmd_string ( gpointer user_data, gchar **babel //GtkFileFilter *filter = gtk_file_chooser_get_filter ( GTK_FILE_CHOOSER(userdata->files) ); // return some value so *thread* processing will continue - *babelargs_or_shellcmd = g_strdup ("fake command"); // Not really used, thus no translations + po->babelargs = g_strdup ("fake command"); // Not really used, thus no translations } /** * Process selected files and try to generate waypoints storing them in the given vtl */ -static gboolean datasource_geotag_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ) +static gboolean datasource_geotag_process ( VikTrwLayer *vtl, ProcessOptions *po, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, gpointer not_used ) { datasource_geotag_user_data_t *user_data = (datasource_geotag_user_data_t *)adw->user_data; diff --git a/src/datasource_gps.c b/src/datasource_gps.c index 1fd2dd3c..8e545d82 100644 --- a/src/datasource_gps.c +++ b/src/datasource_gps.c @@ -3,7 +3,7 @@ * * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2006, Alex Foobarian - * 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 @@ -43,7 +43,7 @@ static gboolean gps_acquire_in_progress = FALSE; static gint last_active = -1; static gpointer datasource_gps_init_func ( acq_vik_t *avt ); -static void datasource_gps_get_cmd_string ( gpointer add_widgets_data_not_used, gchar **babelargs, gchar **input_file, gpointer not_used ); +static void datasource_gps_get_process_options ( gpointer user_data, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ); static void datasource_gps_cleanup ( gpointer user_data ); static void datasource_gps_progress ( BabelProgressCode c, gpointer data, acq_dialog_widgets_t *w ); static void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); @@ -61,8 +61,8 @@ VikDataSourceInterface vik_datasource_gps_interface = { (VikDataSourceInitFunc) datasource_gps_init_func, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_gps_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_gps_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from, + (VikDataSourceGetProcessOptionsFunc) datasource_gps_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, (VikDataSourceProgressFunc) datasource_gps_progress, (VikDataSourceAddProgressWidgetsFunc) datasource_gps_add_progress_widgets, (VikDataSourceCleanupFunc) datasource_gps_cleanup, @@ -209,7 +209,7 @@ gboolean datasource_gps_get_do_waypoints ( gpointer user_data ) return get_waypoints; } -static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelargs, gchar **input_file, gpointer not_used ) +static void datasource_gps_get_process_options ( gpointer user_data, ProcessOptions *po, gpointer not_used, const gchar *not_used2, const gchar *not_used3 ) { char *device = NULL; char *tracks = NULL; @@ -217,7 +217,7 @@ static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelarg char *waypoints = NULL; if (gps_acquire_in_progress) { - *babelargs = *input_file = NULL; + po->babelargs = po->filename = NULL; } gps_acquire_in_progress = TRUE; @@ -239,16 +239,16 @@ static void datasource_gps_get_cmd_string ( gpointer user_data, gchar **babelarg else waypoints = ""; - *babelargs = g_strdup_printf("-D 9 %s %s %s -i %s", tracks, routes, waypoints, device); + po->babelargs = g_strdup_printf("-D 9 %s %s %s -i %s", tracks, routes, waypoints, device); /* device points to static content => no free */ device = NULL; tracks = NULL; routes = NULL; waypoints = NULL; - *input_file = g_strdup(datasource_gps_get_descriptor(user_data)); + po->filename = g_strdup(datasource_gps_get_descriptor(user_data)); - g_debug(_("using cmdline '%s' and file '%s'\n"), *babelargs, *input_file); + g_debug(_("using cmd '%s' and file '%s'\n"), po->babelargs, po->filename); } /** @@ -264,14 +264,14 @@ gboolean datasource_gps_get_off ( gpointer user_data ) return power_off; } -static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar **input_file ) +static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar **file_descriptor ) { char *ser = NULL; char *device = NULL; gps_user_data_t *w = (gps_user_data_t *)user_data; if (gps_acquire_in_progress) { - *babelargs = *input_file = NULL; + *babelargs = *file_descriptor = NULL; } /* See if we should turn off the device */ @@ -302,7 +302,7 @@ static void datasource_gps_off ( gpointer user_data, gchar **babelargs, gchar ** #else ser = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w->ser_b)); #endif - *input_file = g_strdup(ser); + *file_descriptor = g_strdup(ser); } diff --git a/src/datasource_osm.c b/src/datasource_osm.c index 105c7859..5ae90054 100644 --- a/src/datasource_osm.c +++ b/src/datasource_osm.c @@ -2,6 +2,7 @@ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * * Copyright (C) 2011, Guilhem Bonnefille + * Copyright (C) 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 @@ -45,7 +46,7 @@ static gdouble last_page_number = 0; static gpointer datasource_osm_init ( acq_vik_t *avt ); static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ); -static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ); +static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadMapOptions *options, const gchar *notused1, const gchar *notused2); static void datasource_osm_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_osm_interface = { @@ -59,8 +60,8 @@ VikDataSourceInterface vik_datasource_osm_interface = { (VikDataSourceInitFunc) datasource_osm_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_osm_add_setup_widgets, - (VikDataSourceGetCmdStringFunc) datasource_osm_get_cmd_string, - (VikDataSourceProcessFunc) a_babel_convert_from_url, + (VikDataSourceGetProcessOptionsFunc) datasource_osm_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_osm_cleanup, @@ -96,7 +97,7 @@ static void datasource_osm_add_setup_widgets ( GtkWidget *dialog, VikViewport *v gtk_widget_show_all(dialog); } -static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, gchar **cmd, gchar **input_file_type, DownloadMapOptions *options ) +static void datasource_osm_get_process_options ( datasource_osm_widgets_t *widgets, ProcessOptions *po, DownloadMapOptions *options, const gchar *notused1, const gchar *notused2) { int page = 0; gdouble min_lat, max_lat, min_lon, max_lon; @@ -118,9 +119,9 @@ static void datasource_osm_get_cmd_string ( datasource_osm_widgets_t *widgets, g last_page_number = gtk_spin_button_get_value(GTK_SPIN_BUTTON(widgets->page_number)); page = last_page_number; - *cmd = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page ); - *input_file_type = NULL; - options = NULL; + // NB Download is of GPX type + po->url = g_strdup_printf( DOWNLOAD_URL_FMT, sminlon, sminlat, smaxlon, smaxlat, page ); + options = NULL; // i.e. use the default download settings } static void datasource_osm_cleanup ( gpointer data ) diff --git a/src/datasource_osm_my_traces.c b/src/datasource_osm_my_traces.c index 1c82a185..f6b850af 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, DownloadMapOptions *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, DownloadMapOptions *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, DownloadMapOptions *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, DownloadMapOptions *options_unused ) { //datasource_osm_my_traces_t *data = (datasource_osm_my_traces_t *)adw->user_data; @@ -639,7 +637,10 @@ 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 diff --git a/src/datasource_routing.c b/src/datasource_routing.c index e55205e4..05191c4a 100644 --- a/src/datasource_routing.c +++ b/src/datasource_routing.c @@ -3,6 +3,7 @@ * * Copyright (C) 2003-2005, Evan Battaglia * Copyright (C) 2013, Guilhem Bonnefille + * Copyright (C) 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 @@ -46,7 +47,7 @@ static gchar *last_to_str = NULL; static gpointer datasource_routing_init ( acq_vik_t *avt ); 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, DownloadMapOptions *options, const gchar *not_used2, const gchar *not_used3 ); static void datasource_routing_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_routing_interface = { @@ -60,8 +61,8 @@ VikDataSourceInterface vik_datasource_routing_interface = { (VikDataSourceInitFunc) datasource_routing_init, (VikDataSourceCheckExistenceFunc) NULL, (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, @@ -111,7 +112,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, DownloadMapOptions *options, const gchar *not_used2, const gchar *not_used3 ) { const gchar *from, *to; @@ -122,13 +123,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 ); - - // Give up if no engine available if ( !engine ) return; - *cmd = vik_routing_engine_get_url_from_directions ( engine, from, to ); - *input_file_type = g_strdup ( vik_routing_engine_get_format (engine) ); - options = NULL; + 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 ); diff --git a/src/datasource_url.c b/src/datasource_url.c index bf82fc89..4d667733 100644 --- a/src/datasource_url.c +++ b/src/datasource_url.c @@ -40,7 +40,7 @@ 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, DownloadMapOptions *download_options, const gchar *not_used2, const gchar *not_used3 ); static void datasource_url_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_url_interface = { @@ -54,8 +54,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, @@ -139,7 +139,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, DownloadMapOptions *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 +147,12 @@ 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 ); + download_options = NULL; } static void datasource_url_cleanup ( gpointer data ) diff --git a/src/datasource_wikipedia.c b/src/datasource_wikipedia.c index f6d86346..5caf5f26 100644 --- a/src/datasource_wikipedia.c +++ b/src/datasource_wikipedia.c @@ -2,7 +2,7 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * 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 @@ -26,7 +26,7 @@ #include "acquire.h" #include "geonamessearch.h" -static gboolean datasource_wikipedia_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw ); +static gboolean datasource_wikipedia_process ( VikTrwLayer *vtl, ProcessOptions *po, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw ); VikDataSourceInterface vik_datasource_wikipedia_interface = { N_("Create Waypoints from Wikipedia Articles"), @@ -39,7 +39,7 @@ VikDataSourceInterface vik_datasource_wikipedia_interface = { (VikDataSourceInitFunc) NULL, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) NULL, - (VikDataSourceGetCmdStringFunc) NULL, + (VikDataSourceGetProcessOptionsFunc) NULL, (VikDataSourceProcessFunc) datasource_wikipedia_process, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, @@ -56,7 +56,7 @@ VikDataSourceInterface vik_datasource_wikipedia_interface = { /** * Process selected files and try to generate waypoints storing them in the given vtl */ -static gboolean datasource_wikipedia_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw ) +static gboolean datasource_wikipedia_process ( VikTrwLayer *vtl, ProcessOptions *po, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw ) { struct LatLon maxmin[2] = { {0.0,0.0}, {0.0,0.0} }; diff --git a/src/file.c b/src/file.c index d2692a35..65fd481f 100644 --- a/src/file.c +++ b/src/file.c @@ -692,7 +692,8 @@ VikLoadType_t a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar // In fact both kml & gpx files start the same as they are in xml if ( a_file_check_ext ( filename, ".kml" ) && check_magic ( f, GPX_MAGIC ) ) { // Implicit Conversion - if ( ! ( success = a_babel_convert_from ( VIK_TRW_LAYER(vtl), "-i kml", filename, NULL, NULL, NULL ) ) ) { + ProcessOptions po = { "-i kml", filename, NULL, NULL, NULL, NULL }; + if ( ! ( success = a_babel_convert_from ( VIK_TRW_LAYER(vtl), &po, NULL, NULL, NULL ) ) ) { load_answer = LOAD_TYPE_GPSBABEL_FAILURE; } } diff --git a/src/vikgpslayer.c b/src/vikgpslayer.c index e7cb345f..9cb2f296 100644 --- a/src/vikgpslayer.c +++ b/src/vikgpslayer.c @@ -103,7 +103,7 @@ typedef struct { gint count; VikTrwLayer *vtl; VikTrack *track; - gchar *cmd_args; + gchar *babelargs; gchar *window_title; GtkWidget *dialog; GtkWidget *status_label; @@ -878,7 +878,7 @@ gboolean vik_gps_layer_is_empty ( VikGpsLayer *vgl ) static void gps_session_delete(GpsSession *sess) { vik_mutex_free(sess->mutex); - g_free(sess->cmd_args); + g_free(sess->babelargs); g_free(sess); } @@ -1179,11 +1179,12 @@ static void gps_comm_thread(GpsSession *sess) { gboolean result; - if (sess->direction == GPS_DOWN) - result = a_babel_convert_from (sess->vtl, sess->cmd_args, sess->port, - (BabelStatusFunc) gps_download_progress_func, sess, NULL); + if (sess->direction == GPS_DOWN) { + ProcessOptions po = { sess->babelargs, sess->port, NULL, NULL, NULL, NULL }; + result = a_babel_convert_from (sess->vtl, &po, (BabelStatusFunc) gps_download_progress_func, sess, NULL); + } else { - result = a_babel_convert_to (sess->vtl, sess->track, sess->cmd_args, sess->port, + result = a_babel_convert_to (sess->vtl, sess->track, sess->babelargs, sess->port, (BabelStatusFunc) gps_upload_progress_func, sess); } @@ -1298,7 +1299,7 @@ gint vik_gps_comm ( VikTrwLayer *vtl, else waypoints = ""; - sess->cmd_args = g_strdup_printf("-D 9 %s %s %s -%c %s", + sess->babelargs = g_strdup_printf("-D 9 %s %s %s -%c %s", tracks, routes, waypoints, (dir == GPS_DOWN) ? 'i' : 'o', protocol); tracks = NULL; waypoints = NULL; @@ -1358,7 +1359,8 @@ gint vik_gps_comm ( VikTrwLayer *vtl, if ( turn_off ) { // No need for thread for powering off device (should be quick operation...) - so use babel command directly: gchar *device_off = g_strdup_printf("-i %s,%s", protocol, "power_off"); - gboolean result = a_babel_convert_from (NULL, (const char*)device_off, (const char*)port, NULL, NULL, NULL); + ProcessOptions po = { device_off, port, NULL, NULL, NULL, NULL }; + gboolean result = a_babel_convert_from (NULL, &po, NULL, NULL, NULL); if ( !result ) a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vtl), _("Could not turn off device.") ); g_free ( device_off ); diff --git a/src/vikroutingwebengine.c b/src/vikroutingwebengine.c index 91f7b986..f6ceb8c7 100644 --- a/src/vikroutingwebengine.c +++ b/src/vikroutingwebengine.c @@ -425,7 +425,8 @@ vik_routing_web_engine_find ( VikRoutingEngine *self, VikTrwLayer *vtl, struct L DownloadMapOptions *options = vik_routing_web_engine_get_download_options(self); gchar *format = vik_routing_engine_get_format ( self ); - gboolean ret = a_babel_convert_from_url ( vtl, uri, format, NULL, NULL, options ); + ProcessOptions po = { NULL, NULL, format, uri, NULL, NULL }; + gboolean ret = a_babel_convert_from ( vtl, &po, NULL, NULL, options ); g_free(uri); @@ -559,7 +560,8 @@ vik_routing_web_engine_refine ( VikRoutingEngine *self, VikTrwLayer *vtl, VikTra /* Convert and insert data in model */ gchar *format = vik_routing_engine_get_format ( self ); - gboolean ret = a_babel_convert_from_url ( vtl, uri, format, NULL, NULL, options ); + ProcessOptions po = { NULL, NULL, format, uri, NULL, NULL }; + gboolean ret = a_babel_convert_from ( vtl, &po, NULL, NULL, options ); g_free(uri); diff --git a/src/vikwebtool_datasource.c b/src/vikwebtool_datasource.c index 9512031b..45a0a510 100644 --- a/src/vikwebtool_datasource.c +++ b/src/vikwebtool_datasource.c @@ -2,7 +2,7 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * 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 @@ -217,7 +217,7 @@ static void datasource_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, -static void datasource_get_cmd_string ( gpointer user_data, gchar **cmd, gchar **extra, DownloadMapOptions *options ) +static void datasource_get_process_options ( gpointer user_data, ProcessOptions *po, DownloadMapOptions *options, const gchar *notused1, const gchar *notused2 ) { datasource_t *data = (datasource_t*) user_data; @@ -235,7 +235,7 @@ static void datasource_get_cmd_string ( gpointer user_data, gchar **cmd, gchar * gchar *url = vik_webtool_get_url ( vwd, data->vw ); g_debug ("%s: %s", __FUNCTION__, url ); - *cmd = g_strdup ( url ); + po->url = g_strdup ( url ); // Only use first section of the file_type string // One can't use values like 'kml -x transform,rte=wpt' in order to do fancy things @@ -245,22 +245,13 @@ static void datasource_get_cmd_string ( gpointer user_data, gchar **cmd, gchar * if ( priv->file_type ) parts = g_strsplit ( priv->file_type, " ", 0); if ( parts ) - *extra = g_strdup ( parts[0] ); + po->input_file_type = g_strdup ( parts[0] ); else - *extra = NULL; + po->input_file_type = NULL; g_strfreev ( parts ); options = NULL; -} - -static gboolean datasource_process ( VikTrwLayer *vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw, DownloadMapOptions *options ) -{ - datasource_t *data = (datasource_t *)adw->user_data; - VikWebtoolDatasourcePrivate *priv = WEBTOOL_DATASOURCE_GET_PRIVATE ( data->self ); - // Dependent on the ExtTool / what extra has been set to... - // When extra is NULL - then it interprets results as a GPX - gboolean result = a_babel_convert_from_url_filter ( vtl, cmd, extra, priv->babel_filter_args, status_cb, adw, options); - return result; + po->babel_filters = priv->babel_filter_args; } static void cleanup ( gpointer data ) @@ -289,8 +280,8 @@ static void webtool_datasource_open ( VikExtTool *self, VikWindow *vw ) (VikDataSourceInitFunc) datasource_init, (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) (search ? datasource_add_setup_widgets : NULL), - (VikDataSourceGetCmdStringFunc) datasource_get_cmd_string, - (VikDataSourceProcessFunc) datasource_process, + (VikDataSourceGetProcessOptionsFunc) datasource_get_process_options, + (VikDataSourceProcessFunc) a_babel_convert_from, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) cleanup, -- 2.39.5