From 1dcda49f5ca719dfea822a34ac7925246875240f Mon Sep 17 00:00:00 2001 From: Victor Kareh Date: Thu, 24 Jul 2025 09:23:56 -0400 Subject: EomUtil: Add helper to get content type from GFileInfos This prefers the real content type, but automatically falls back to the fast content type the other one isn't set in the GFileInfo. Backported from https://gitlab.gnome.org/GNOME/eog/-/commit/4f80d090fd8f27c8d430dfe5931ea53446643ec7 --- src/eom-util.c | 18 ++++++++++++++++++ src/eom-util.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/src/eom-util.c b/src/eom-util.c index e914223..a839f6f 100644 --- a/src/eom-util.c +++ b/src/eom-util.c @@ -482,3 +482,21 @@ eom_notebook_scroll_event_cb (GtkWidget *widget, return TRUE; } + +const char* +eom_util_get_content_type_with_fallback (GFileInfo *file_info) +{ + g_return_val_if_fail (file_info != NULL, NULL); + + if (g_file_info_has_attribute (file_info, + G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) + return g_file_info_get_content_type (file_info); + else if (g_file_info_has_attribute (file_info, + G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)) + return g_file_info_get_attribute_string (file_info, + G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); + else + g_warn_if_reached (); + + return NULL; +} diff --git a/src/eom-util.h b/src/eom-util.h index d08b88a..9f2c370 100644 --- a/src/eom-util.h +++ b/src/eom-util.h @@ -68,6 +68,9 @@ void eom_util_show_file_in_filemanager (GFile *file, gboolean eom_notebook_scroll_event_cb (GtkWidget *notebook, GdkEventScroll *event); +G_GNUC_INTERNAL +const char *eom_util_get_content_type_with_fallback (GFileInfo *file_info); + G_END_DECLS #endif /* __EOM_UTIL_H__ */ -- cgit v1.2.1