]> git.street.me.uk Git - andy/viking.git/blobdiff - src/datasource_file.c
Use the last selected date when initializing the date search.
[andy/viking.git] / src / datasource_file.c
index 29fd2f89e4048bb57e2c0dbf98727214a3979245..27da820a4c5413b6658bdce112ef77798b48c18a 100644 (file)
@@ -31,6 +31,7 @@
 #include "viking.h"
 #include "babel.h"
 #include "gpx.h"
+#include "babel_ui.h"
 #include "acquire.h"
 
 typedef struct {
@@ -50,7 +51,7 @@ static BabelFile *last_file_filter = NULL;
 /* The last file format selected */
 static int last_type = 0;
 
-static gpointer datasource_file_init( );
+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_cleanup ( gpointer data );
@@ -75,24 +76,12 @@ VikDataSourceInterface vik_datasource_file_interface = {
 };
 
 /* See VikDataSourceInterface */
-static gpointer datasource_file_init ( )
+static gpointer datasource_file_init ( acq_vik_t *avt )
 {
   datasource_file_widgets_t *widgets = g_malloc(sizeof(*widgets));
   return widgets;
 }
 
-static void fill_combo_box (gpointer data, gpointer user_data)
-{
-  const gchar *label = ((BabelFile*) data)->label;
-#if GTK_CHECK_VERSION (2,24,0)
-  GtkComboBoxText *combo = GTK_COMBO_BOX_TEXT (user_data);
-  gtk_combo_box_text_append_text (combo, label);
-#else
-  GtkComboBox *combo = GTK_COMBO_BOX (user_data);
-  gtk_combo_box_append_text (combo, label);
-#endif
-}
-
 static void add_file_filter (gpointer data, gpointer user_data)
 {
   GtkFileChooser *chooser = GTK_FILE_CHOOSER ( user_data );
@@ -146,19 +135,21 @@ static void datasource_file_add_setup_widgets ( GtkWidget *dialog, VikViewport *
 
   /* The file format selector */
   type_label = gtk_label_new (_("File type:"));
-#if GTK_CHECK_VERSION (2,24,0)
-  widgets->type = gtk_combo_box_text_new ();
-#else
-  widgets->type = gtk_combo_box_new_text ();
-#endif
-  g_list_foreach (a_babel_file_list, fill_combo_box, widgets->type);
-  gtk_combo_box_set_active (GTK_COMBO_BOX (widgets->type), last_type);
+  /* Propose all 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",
+      G_CALLBACK(a_babel_ui_type_selector_dialog_sensitivity_cb), dialog );
+  gtk_combo_box_set_active ( GTK_COMBO_BOX(widgets->type), last_type );
+  /* Manually call the callback to fix the state */
+  a_babel_ui_type_selector_dialog_sensitivity_cb ( GTK_COMBO_BOX(widgets->type), dialog );
 
   /* Packing all these widgets */
-  gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), filename_label, FALSE, FALSE, 5 );
-  gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), widgets->file, FALSE, FALSE, 5 );
-  gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), type_label, FALSE, FALSE, 5 );
-  gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), widgets->type, FALSE, FALSE, 5 );
+  GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog)));
+  gtk_box_pack_start ( box, filename_label, FALSE, FALSE, 5 );
+  gtk_box_pack_start ( box, widgets->file, FALSE, FALSE, 5 );
+  gtk_box_pack_start ( box, type_label, FALSE, FALSE, 5 );
+  gtk_box_pack_start ( box, widgets->type, FALSE, FALSE, 5 );
   gtk_widget_show_all(dialog);
 }
 
@@ -180,8 +171,7 @@ static void datasource_file_get_cmd_string ( datasource_file_widgets_t *widgets,
   /* Retrieve and memorize file format selected */
   gchar *type = NULL;
   last_type = gtk_combo_box_get_active ( GTK_COMBO_BOX (widgets->type) );
-  if ( a_babel_file_list )
-    type = ((BabelFile*)g_list_nth_data (a_babel_file_list, last_type))->name;
+  type = (a_babel_ui_file_type_selector_get ( widgets->type ))->name;
 
   /* Build the string */
   *cmd = g_strdup_printf( "-i %s", type);