From 2f5f0fb814b2a5ac47275826f491f38c6bda7b42 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sun, 1 Jun 2014 17:42:37 +0100 Subject: [PATCH] Allow import of file format with *any* readable components as supported by GPSBabel. --- src/babel.c | 24 ++++++++++++++++++++++++ src/babel.h | 1 + src/babel_ui.c | 6 +++++- src/datasource_file.c | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/babel.c b/src/babel.c index 988fadff..4b6ede92 100644 --- a/src/babel.c +++ b/src/babel.c @@ -98,6 +98,30 @@ void a_babel_foreach_file_with_mode (BabelMode mode, GFunc func, gpointer user_d } } +/** + * a_babel_foreach_file_read_any: + * @func: The function to be called on any file format with a read method + * @user_data: Data passed into the function + * + * Run a function on all file formats with any kind of read method + * (which is almost all but not quite - e.g. with GPSBabel v1.4.4 - PalmDoc is write only waypoints) + */ +void a_babel_foreach_file_read_any (GFunc func, gpointer user_data) +{ + GList *current; + for ( current = g_list_first (a_babel_file_list) ; + current != NULL ; + current = g_list_next (current) ) + { + BabelFile *currentFile = current->data; + // Call function when any read mode found + if ( currentFile->mode.waypointsRead || + currentFile->mode.tracksRead || + currentFile->mode.routesRead) + func (currentFile, user_data); + } +} + /** * a_babel_convert: * @vt: The TRW layer to modify. All data will be deleted, and replaced by what gpsbabel outputs. diff --git a/src/babel.h b/src/babel.h index 47652d01..72bfb9d5 100644 --- a/src/babel.h +++ b/src/babel.h @@ -96,6 +96,7 @@ GList *a_babel_file_list; 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( VikTrwLayer *vt, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data, gpointer options ); diff --git a/src/babel_ui.c b/src/babel_ui.c index 14482193..9b785c66 100644 --- a/src/babel_ui.c +++ b/src/babel_ui.c @@ -82,7 +82,11 @@ GtkWidget *a_babel_ui_file_type_selector_new ( BabelMode mode ) g_object_set_data ( G_OBJECT(combo), "formats", formats ); /* Add all known and compatible file formats */ - a_babel_foreach_file_with_mode ( mode, babel_ui_selector_add_entry_cb, combo ); + if ( mode.tracksRead && mode.routesRead && mode.waypointsRead && + !mode.tracksWrite && !mode.routesWrite && !mode.waypointsWrite ) + a_babel_foreach_file_read_any ( babel_ui_selector_add_entry_cb, combo ); + else + a_babel_foreach_file_with_mode ( mode, babel_ui_selector_add_entry_cb, combo ); /* Initialize the selection with the really first entry */ gtk_combo_box_set_active ( GTK_COMBO_BOX(combo), 0 ); diff --git a/src/datasource_file.c b/src/datasource_file.c index 57e6bd08..e55891d3 100644 --- a/src/datasource_file.c +++ b/src/datasource_file.c @@ -141,7 +141,7 @@ static void datasource_file_add_setup_widgets ( GtkWidget *dialog, VikViewport * /* The file format selector */ type_label = gtk_label_new (_("File type:")); - /* Propose all readable file */ + /* Propose any readable file */ BabelMode mode = { 1, 0, 1, 0, 1, 0 }; widgets->type = a_babel_ui_file_type_selector_new ( mode ); g_signal_connect ( G_OBJECT(widgets->type), "changed", -- 2.39.5