+ if ( response == GTK_RESPONSE_ACCEPT )
+ {
+ gint file_type = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+ gchar *filename = gtk_file_chooser_get_filename (chooser);
+ struct string_map options;
+
+ g_return_if_fail (filename);
+
+ if (file_type == FT_AUTO)
+ {
+ /* If the "Infer file type from extension" option was chosen,
+ search for the respective type in the list.
+ (It's a O(n) search, but fortunately n is small). */
+ gint i;
+ for (i = 1 ; i < N_EXTENSIONS ; ++i)
+ {
+ if ( g_str_has_suffix (filename, ft[i].ext))
+ {
+ file_type = i;
+ break;
+ }
+ }
+ }
+ else if (! g_str_has_suffix (filename, ft[file_type].ext))
+ {
+ /* If an explicit document format was chosen, and if the chosen
+ filename does not already have that particular "extension",
+ then append it.
+ */
+
+ gchar *of = filename;
+ filename = g_strconcat (filename, ft[file_type].ext, NULL);
+ g_free (of);
+ }
+
+ string_map_init (&options);
+ string_map_insert (&options, "output-file", filename);
+
+ switch (file_type)
+ {
+ case FT_PDF:
+ export_output (window, &options, "pdf");
+ break;
+ case FT_HTML:
+ export_output (window, &options, "html");
+ break;
+ case FT_ODT:
+ export_output (window, &options, "odt");
+ break;
+ case FT_PS:
+ export_output (window, &options, "ps");
+ break;
+ case FT_CSV:
+ export_output (window, &options, "csv");
+ break;
+
+ case FT_TXT:
+ string_map_insert (&options, "box", "unicode");
+ /* Fall through */
+
+ case FT_ASCII:
+ string_map_insert (&options, "headers", "false");
+ string_map_insert (&options, "paginate", "false");
+ string_map_insert (&options, "squeeze", "true");
+ string_map_insert (&options, "emphasis", "none");
+ string_map_insert (&options, "charts", "none");
+ string_map_insert (&options, "top-margin", "0");
+ string_map_insert (&options, "bottom-margin", "0");
+ export_output (window, &options, "txt");
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ string_map_destroy (&options);
+
+ free (filename);
+ }