/** * gnm_app_create_opener_filter: * @openers: (element-type GOFileOpener): a list of file openers. * * Creates a #GtkFileFilter from the list of file types supported by the * openers in the list. * Returns: (transfer full): the newly allocated #GtkFileFilter. **/ void * gnm_app_create_opener_filter (GList *openers) { /* See below. */ static const char *const bad_suffixes[] = { "txt", "html", "htm", "xml", NULL }; GtkFileFilter *filter = gtk_file_filter_new (); gboolean for_history = (openers == NULL); if (openers == NULL) openers = go_get_file_openers (); for (; openers; openers = openers->next) { GOFileOpener *opener = openers->data; if (opener != NULL) { const GSList *mimes = go_file_opener_get_mimes (opener); const GSList *suffixes = go_file_opener_get_suffixes (opener); if (!for_history) while (mimes) { const char *mime = mimes->data; /* * See 438918. Too many things * like *.xml and *.txt get added * to be useful for the file history */ gtk_file_filter_add_mime_type (filter, mime); if (0) g_print ("%s: Adding mime %s\n", go_file_opener_get_description (opener), mime); mimes = mimes->next; } while (suffixes) { const char *suffix = suffixes->data; GString *pattern; int i; if (for_history) for (i = 0; bad_suffixes[i]; i++) if (strcmp (suffix, bad_suffixes[i]) == 0) goto bad_suffix; /* Create "*.[xX][lL][sS]" */ pattern = g_string_new ("*."); while (*suffix) { gunichar uc = g_utf8_get_char (suffix); suffix = g_utf8_next_char (suffix); if (g_unichar_islower (uc)) { g_string_append_c (pattern, '['); g_string_append_unichar (pattern, uc); uc = g_unichar_toupper (uc); g_string_append_unichar (pattern, uc); g_string_append_c (pattern, ']'); } else g_string_append_unichar (pattern, uc); } gtk_file_filter_add_pattern (filter, pattern->str); if (0) g_print ("%s: Adding %s\n", go_file_opener_get_description (opener), pattern->str); g_string_free (pattern, TRUE); bad_suffix: suffixes = suffixes->next; } } } return filter; }
int main (int argc, char const **argv) { GOErrorInfo *plugin_errs; int res = 0; GOCmdContext *cc; GOptionContext *ocontext; GError *error = NULL; /* No code before here, we need to init threads */ argv = gnm_pre_parse_init (argc, argv); ocontext = g_option_context_new (_("INFILE...")); g_option_context_add_main_entries (ocontext, ssindex_options, GETTEXT_PACKAGE); g_option_context_add_group (ocontext, gnm_get_option_group ()); g_option_context_parse (ocontext, &argc, (gchar ***)&argv, &error); g_option_context_free (ocontext); if (error) { g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (ssindex_show_version) { g_printerr (_("ssindex version '%s'\ndatadir := '%s'\nlibdir := '%s'\n"), GNM_VERSION_FULL, gnm_sys_data_dir (), gnm_sys_lib_dir ()); return 0; } else if (!ssindex_run_indexer && !ssindex_list_mime_types) { g_printerr (_("Usage: %s [OPTION...] %s\n"), g_get_prgname (), _("INFILE...")); return 1; } gnm_init (); cc = gnm_cmd_context_stderr_new (); gnm_plugins_init (GO_CMD_CONTEXT (cc)); go_plugin_db_activate_plugin_list ( go_plugins_get_available_plugins (), &plugin_errs); if (plugin_errs) { /* FIXME: What do we want to do here? */ go_error_info_free (plugin_errs); } go_component_set_default_command_context (cc); if (ssindex_run_indexer) { GOIOContext *ioc = go_io_context_new (cc); int i; go_io_context_set_num_files (ioc, argc - 1); for (i = 1; i < argc; i++) { char const *file = argv[i]; go_io_context_processing_file (ioc, file); res |= ssindex (file, ioc); } g_object_unref (ioc); } else if (ssindex_list_mime_types) { GList *o; for (o = go_get_file_openers (); o != NULL ; o = o->next) { GSList const *mime = go_file_opener_get_mimes (o->data); for (; mime != NULL ; mime = mime->next) g_print ("%s\n", (char const *)mime->data); } } go_component_set_default_command_context (NULL); g_object_unref (cc); gnm_shutdown (); gnm_pre_parse_shutdown (); return res; }