Beispiel #1
0
/**
 * 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)
 *
 * 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, ProcessOptions *process_options, BabelStatusFunc cb, gpointer user_data, DownloadFileOptions *download_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->input_file_type, cb, user_data, download_options );
  return FALSE;
}
Beispiel #2
0
/**
 * 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.
 *
 * Returns: %TRUE on successful invocation of GPSBabel or read of the GPX
 *
 */
gboolean a_babel_convert_from_url_or_shell ( VikTrwLayer *vt, const char *input, const char *input_type, BabelStatusFunc cb, gpointer user_data, DownloadMapOptions *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);
}
Beispiel #3
0
/* 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;
    VikTrwLayer *vtl = NULL;

    gboolean creating_new_layer = TRUE;

    acq_dialog_widgets_t *w = wi->w;
    VikDataSourceInterface *source_interface = wi->w->source_interface;
    g_free ( wi );
    wi = NULL;

    gdk_threads_enter();
    if (source_interface->mode == VIK_DATASOURCE_ADDTOLAYER) {
        VikLayer *current_selected = vik_layers_panel_get_selected ( w->vlp );
        if ( IS_VIK_TRW_LAYER(current_selected) ) {
            vtl = VIK_TRW_LAYER(current_selected);
            creating_new_layer = FALSE;
        }
    }
    if ( creating_new_layer ) {
        vtl = VIK_TRW_LAYER ( vik_layer_create ( VIK_LAYER_TRW, w->vvp, NULL, FALSE ) );
        vik_layer_rename ( VIK_LAYER ( vtl ), _(source_interface->layer_title) );
        gtk_label_set_text ( GTK_LABEL(w->status), _("Working...") );
    }
    gdk_threads_leave();

    switch ( source_interface->type ) {
    case VIK_DATASOURCE_GPSBABEL_DIRECT:
        result = a_babel_convert_from (vtl, cmd, (BabelStatusFunc) progress_func, extra, w);
        break;
    case VIK_DATASOURCE_URL:
        result = a_babel_convert_from_url (vtl, cmd, extra, (BabelStatusFunc) progress_func, w);
        break;
    case VIK_DATASOURCE_SHELL_CMD:
        result = a_babel_convert_from_shellcommand ( vtl, cmd, extra, (BabelStatusFunc) progress_func, w);
        break;
    default:
        g_critical("Houston, we've had a problem.");
    }

    g_free ( cmd );
    g_free ( extra );

    if (!result) {
        gdk_threads_enter();
        gtk_label_set_text ( GTK_LABEL(w->status), _("Error: acquisition failed.") );
        if ( creating_new_layer )
            g_object_unref ( G_OBJECT ( vtl ) );
        gdk_threads_leave();
    }
    else {
        gdk_threads_enter();
        if (w->ok) {
            gtk_label_set_text ( GTK_LABEL(w->status), _("Done.") );
            if ( creating_new_layer ) {
                /* Only create the layer if it actually contains anything useful */
                if ( g_hash_table_size (vik_trw_layer_get_tracks(vtl)) ||
                        g_hash_table_size (vik_trw_layer_get_waypoints(vtl)) )
                    vik_aggregate_layer_add_layer( vik_layers_panel_get_top_layer(w->vlp), VIK_LAYER(vtl));
                else
                    gtk_label_set_text ( GTK_LABEL(w->status), _("No data.") );
            }
            /* View this data if available and is desired */
            if ( vtl && source_interface->autoview ) {
                vik_trw_layer_auto_set_view ( vtl, vik_layers_panel_get_viewport(w->vlp) );
                vik_layers_panel_emit_update (w->vlp);
            }
            if ( source_interface->keep_dialog_open ) {
                gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_ACCEPT, TRUE );
                gtk_dialog_set_response_sensitive ( GTK_DIALOG(w->dialog), GTK_RESPONSE_REJECT, FALSE );
            } else {
                gtk_dialog_response ( GTK_DIALOG(w->dialog), GTK_RESPONSE_ACCEPT );
            }
        } else {
            /* canceled */
            if ( creating_new_layer )
                g_object_unref(vtl);
        }
    }
    if ( source_interface->cleanup_func )
        source_interface->cleanup_func ( w->user_data );

    if ( w->ok ) {
        w->ok = FALSE;
    } else {
        g_free ( w );
    }

    gdk_threads_leave();
    g_thread_exit ( NULL );
}