From ab283d39889e28a6802cbec299db6a6792aebe5a Mon Sep 17 00:00:00 2001
From: Přemysl Eric Janouch
Date: Mon, 1 Nov 2021 04:40:58 +0100
Subject: Split out fastiv-io.h, move media types list
---
fastiv-browser.c | 1 +
fastiv-io.c | 14 ++++++++++++++
fastiv-io.h | 26 ++++++++++++++++++++++++++
fastiv-view.c | 1 +
fastiv-view.h | 4 ----
fastiv.c | 28 +++++++---------------------
6 files changed, 49 insertions(+), 25 deletions(-)
create mode 100644 fastiv-io.h
diff --git a/fastiv-browser.c b/fastiv-browser.c
index 883a8b2..4e810e1 100644
--- a/fastiv-browser.c
+++ b/fastiv-browser.c
@@ -18,6 +18,7 @@
#include
#include "fastiv-browser.h"
+#include "fastiv-io.h"
#include "fastiv-view.h"
typedef struct entry Entry;
diff --git a/fastiv-io.c b/fastiv-io.c
index 9c862e3..db0efb9 100644
--- a/fastiv-io.c
+++ b/fastiv-io.c
@@ -37,6 +37,20 @@
#define WUFFS_CONFIG__MODULE__ZLIB
#include "wuffs-mirror-release-c/release/c/wuffs-v0.3.c"
+// A subset of shared-mime-info that produces an appropriate list of
+// file extensions. Chiefly motivated by the suckiness of RAW images:
+// someone else will maintain the list of file extensions for us.
+const char *fastiv_io_supported_media_types[] = {
+ "image/bmp",
+ "image/gif",
+ "image/png",
+ "image/jpeg",
+#ifdef HAVE_LIBRAW
+ "image/x-dcraw",
+#endif // HAVE_LIBRAW
+ NULL
+};
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#define FASTIV_IO_ERROR fastiv_io_error_quark()
diff --git a/fastiv-io.h b/fastiv-io.h
new file mode 100644
index 0000000..96b4929
--- /dev/null
+++ b/fastiv-io.h
@@ -0,0 +1,26 @@
+//
+// fastiv-io.h: image loaders
+//
+// Copyright (c) 2021, Přemysl Eric Janouch
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+//
+
+#pragma once
+
+#include
+#include
+
+extern const char *fastiv_io_supported_media_types[];
+
+cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
+cairo_surface_t *fastiv_io_lookup_thumbnail(const gchar *target);
diff --git a/fastiv-view.c b/fastiv-view.c
index 01187b8..df534bb 100644
--- a/fastiv-view.c
+++ b/fastiv-view.c
@@ -17,6 +17,7 @@
#include
+#include "fastiv-io.h"
#include "fastiv-view.h"
struct _FastivView {
diff --git a/fastiv-view.h b/fastiv-view.h
index edc99d4..024b3ac 100644
--- a/fastiv-view.h
+++ b/fastiv-view.h
@@ -24,7 +24,3 @@ G_DECLARE_FINAL_TYPE(FastivView, fastiv_view, FASTIV, VIEW, GtkWidget)
/// Try to open the given file, synchronously, to be displayed by the widget.
gboolean fastiv_view_open(FastivView *self, const gchar *path, GError **error);
-
-// Private, fastiv-io.c
-cairo_surface_t *fastiv_io_open(const gchar *path, GError **error);
-cairo_surface_t *fastiv_io_lookup_thumbnail(const gchar *target);
diff --git a/fastiv.c b/fastiv.c
index 3f622c3..ad55884 100644
--- a/fastiv.c
+++ b/fastiv.c
@@ -27,6 +27,7 @@
#include
#include "config.h"
+#include "fastiv-io.h"
#include "fastiv-view.h"
#include "fastiv-browser.h"
@@ -115,21 +116,6 @@ get_xdg_data_dirs(void)
// Derived from shared-mime-info-spec 0.21.
-// TODO(p): Move to fastiv-io.c, expose the prototype in a header file
-// (perhaps finally start a new one for it).
-// A subset of shared-mime-info that produces an appropriate list of
-// file extensions. Chiefly motivated by the suckiness of RAW images:
-// someone else will maintain the list of file extensions for us.
-static const char *supported_media_types[] = {
- "image/bmp",
- "image/gif",
- "image/png",
- "image/jpeg",
-#ifdef HAVE_LIBRAW
- "image/x-dcraw",
-#endif // HAVE_LIBRAW
-};
-
static void
read_mime_subclasses(const gchar *path, GHashTable *subclass_sets)
{
@@ -189,7 +175,7 @@ filter_mime_globs(const gchar *path, guint is_globs2, GHashTable *supported_set,
}
static gchar **
-get_supported_globs (void)
+get_supported_globs(const char **media_types)
{
gchar **data_dirs = get_xdg_data_dirs();
@@ -208,8 +194,8 @@ get_supported_globs (void)
// but not aliases.
GHashTable *supported =
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- for (gsize i = 0; i < G_N_ELEMENTS(supported_media_types); i++) {
- add_applying_transitive_closure(supported_media_types[i],
+ while (*media_types) {
+ add_applying_transitive_closure(*media_types++,
subclass_sets, supported);
}
g_hash_table_destroy(subclass_sets);
@@ -363,8 +349,8 @@ on_open(void)
// NOTE: gdk-pixbuf has gtk_file_filter_add_pixbuf_formats().
GtkFileFilter *filter = gtk_file_filter_new();
- for (gsize i = 0; i < G_N_ELEMENTS(supported_media_types); i++)
- gtk_file_filter_add_mime_type(filter, supported_media_types[i]);
+ for (const char **p = fastiv_io_supported_media_types; *p; p++)
+ gtk_file_filter_add_mime_type(filter, *p);
gtk_file_filter_set_name(filter, "Supported images");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
@@ -496,7 +482,7 @@ main(int argc, char *argv[])
g_cclosure_new(G_CALLBACK(on_next), NULL, NULL));
gtk_window_add_accel_group(GTK_WINDOW(g.window), accel_group);
- g.supported_globs = get_supported_globs();
+ g.supported_globs = get_supported_globs(fastiv_io_supported_media_types);
g.files = g_ptr_array_new_full(16, g_free);
gchar *cwd = g_get_current_dir();
--
cgit v1.2.3-70-g09d2