Add a command line option to list supported types
Make it work without a display connection.
This commit is contained in:
parent
47293cfc10
commit
06af1a3cc9
22
fastiv-io.c
22
fastiv-io.c
@ -78,6 +78,28 @@ const char *fastiv_io_supported_media_types[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
char **
|
||||
fastiv_io_all_supported_media_types(void)
|
||||
{
|
||||
GPtrArray *types = g_ptr_array_new();
|
||||
for (const char **p = fastiv_io_supported_media_types; *p; p++)
|
||||
g_ptr_array_add(types, g_strdup(*p));
|
||||
|
||||
#ifdef HAVE_GDKPIXBUF
|
||||
GSList *formats = gdk_pixbuf_get_formats();
|
||||
for (GSList *iter = formats; iter; iter = iter->next) {
|
||||
gchar **subtypes = gdk_pixbuf_format_get_mime_types(iter->data);
|
||||
for (gchar **p = subtypes; *p; p++)
|
||||
g_ptr_array_add(types, *p);
|
||||
g_free(subtypes);
|
||||
}
|
||||
g_slist_free(formats);
|
||||
#endif // HAVE_GDKPIXBUF
|
||||
|
||||
g_ptr_array_add(types, NULL);
|
||||
return (char **) g_ptr_array_free(types, FALSE);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
#define FASTIV_IO_ERROR fastiv_io_error_quark()
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
extern const char *fastiv_io_supported_media_types[];
|
||||
|
||||
char **fastiv_io_all_supported_media_types(void);
|
||||
|
||||
cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
|
||||
cairo_surface_t *fastiv_io_open_from_data(
|
||||
const char *data, size_t len, const gchar *path, GError **error);
|
||||
|
25
fastiv.c
25
fastiv.c
@ -396,24 +396,33 @@ on_button_press_browser(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
gboolean show_version = FALSE;
|
||||
gboolean show_version = FALSE, show_supported_media_types = FALSE;
|
||||
gchar **path_args = NULL;
|
||||
const GOptionEntry options[] = {
|
||||
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &path_args,
|
||||
NULL, "[FILE | DIRECTORY]"},
|
||||
{"list-supported-media-types", 0, G_OPTION_FLAG_IN_MAIN,
|
||||
G_OPTION_ARG_NONE, &show_supported_media_types,
|
||||
"Output supported media types and exit", NULL},
|
||||
{"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
||||
&show_version, "output version information and exit", NULL},
|
||||
&show_version, "Output version information and exit", NULL},
|
||||
{},
|
||||
};
|
||||
|
||||
GError *error = NULL;
|
||||
if (!gtk_init_with_args(
|
||||
&argc, &argv, " - fast image viewer", options, NULL, &error))
|
||||
exit_fatal("%s", error->message);
|
||||
gboolean initialized = gtk_init_with_args(
|
||||
&argc, &argv, " - fast image viewer", options, NULL, &error);
|
||||
if (show_version) {
|
||||
printf(PROJECT_NAME " " PROJECT_VERSION "\n");
|
||||
return 0;
|
||||
}
|
||||
if (show_supported_media_types) {
|
||||
for (char **types = fastiv_io_all_supported_media_types(); *types; )
|
||||
g_print("%s\n", *types++);
|
||||
return 0;
|
||||
}
|
||||
if (!initialized)
|
||||
exit_fatal("%s", error->message);
|
||||
|
||||
// NOTE: Firefox and Eye of GNOME both interpret multiple arguments
|
||||
// in a special way. This is problematic, because one-element lists
|
||||
@ -506,8 +515,10 @@ main(int argc, char *argv[])
|
||||
G_CALLBACK(on_key_press), NULL);
|
||||
gtk_container_add(GTK_CONTAINER(g.window), g.stack);
|
||||
|
||||
// TODO(p): Also milk gdk-pixbuf, if linked in, needs to be done in runtime.
|
||||
g.supported_globs = extract_mime_globs(fastiv_io_supported_media_types);
|
||||
char **types = fastiv_io_all_supported_media_types();
|
||||
g.supported_globs = extract_mime_globs((const char **) types);
|
||||
g_strfreev(types);
|
||||
|
||||
g.files = g_ptr_array_new_full(16, g_free);
|
||||
gchar *cwd = g_get_current_dir();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user