Merge branch 'wip/fast-content-type' into 'master'

Use "fast" content type as fallback if normal content type is unavailable

Closes #312

See merge request GNOME/eog!161
This commit is contained in:
Felix Riemann 2024-03-28 17:34:16 +00:00
commit f347759df0
11 changed files with 68 additions and 25 deletions

View file

@ -328,7 +328,8 @@ update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
G_FILE_ATTRIBUTE_TIME_MODIFIED ","
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
g_object_unref (file);
@ -347,7 +348,7 @@ update_preview_cb (GtkFileChooser *file_chooser, gpointer data)
/* read files smaller than 100kb directly */
gchar *mime_type = g_content_type_get_mime_type (
g_file_info_get_content_type (file_info));
eog_util_get_content_type_with_fallback (file_info));
if (G_LIKELY (mime_type)) {

View file

@ -613,7 +613,8 @@ eog_image_get_file_info (EogImage *img,
file_info = g_file_query_info (img->priv->file,
G_FILE_ATTRIBUTE_STANDARD_SIZE ","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, error);
if (file_info == NULL) {
@ -626,8 +627,9 @@ eog_image_get_file_info (EogImage *img,
if (bytes)
*bytes = g_file_info_get_size (file_info);
if (mime_type)
*mime_type = g_strdup (g_file_info_get_content_type (file_info));
if (mime_type) {
*mime_type = g_strdup (eog_util_get_content_type_with_fallback (file_info));
}
g_object_unref (file_info);
}
}

View file

@ -26,6 +26,7 @@
#include "eog-jobs.h"
#include "eog-thumbnail.h"
#include "eog-pixbuf-util.h"
#include "eog-util.h"
#include <gio/gio.h>
@ -739,7 +740,9 @@ filter_files (GSList *files, GList **file_list, GList **error_list)
GError *error = NULL;
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE","G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, &error);
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
GMountOperation *operation;
@ -767,7 +770,7 @@ filter_files (GSList *files, GList **file_list, GList **error_list)
if (G_UNLIKELY (type == G_FILE_TYPE_UNKNOWN)) {
const gchar *ctype;
ctype = g_file_info_get_content_type (file_info);
ctype = eog_util_get_content_type_with_fallback (file_info);
/* If the content type is supported
adjust the file_type */

View file

@ -26,6 +26,7 @@
#include "eog-image.h"
#include "eog-job-scheduler.h"
#include "eog-jobs.h"
#include "eog-util.h"
#include <string.h>
@ -464,12 +465,13 @@ file_monitor_changed_cb (GFileMonitor *monitor,
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0, NULL, NULL);
if (file_info == NULL) {
break;
}
mimetype = g_file_info_get_content_type (file_info);
mimetype = eog_util_get_content_type_with_fallback (file_info);
if (is_file_in_list_store_file (store, file, &iter)) {
if (eog_image_is_supported_mime_type (mimetype)) {
@ -517,12 +519,13 @@ file_monitor_changed_cb (GFileMonitor *monitor,
if (!is_file_in_list_store_file (store, file, NULL)) {
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0, NULL, NULL);
if (file_info == NULL) {
break;
}
mimetype = g_file_info_get_content_type (file_info);
mimetype = eog_util_get_content_type_with_fallback (file_info);
if (eog_image_is_supported_mime_type (mimetype)) {
const gchar *caption;
@ -535,12 +538,13 @@ file_monitor_changed_cb (GFileMonitor *monitor,
break;
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
if (file_info == NULL) {
break;
}
mimetype = g_file_info_get_content_type (file_info);
mimetype = eog_util_get_content_type_with_fallback (file_info);
if (is_file_in_list_store_file (store, file, &iter) &&
eog_image_is_supported_mime_type (mimetype)) {
eog_list_store_thumbnail_refresh (store, &iter);
@ -550,12 +554,13 @@ file_monitor_changed_cb (GFileMonitor *monitor,
case G_FILE_MONITOR_EVENT_RENAMED:
file_info = g_file_query_info (other_file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0, NULL, NULL);
if (file_info == NULL) {
break;
}
mimetype = g_file_info_get_content_type (file_info);
mimetype = eog_util_get_content_type_with_fallback (file_info);
if (is_file_in_list_store_file (store, other_file, &iter)) {
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
@ -596,7 +601,7 @@ directory_visit (GFile *directory,
gboolean load_uri = FALSE;
const char *mime_type, *name;
mime_type = g_file_info_get_content_type (children_info);
mime_type = eog_util_get_content_type_with_fallback (children_info);
name = g_file_info_get_name (children_info);
if (!g_str_has_prefix (name, ".")) {
@ -638,6 +643,7 @@ eog_list_store_append_directory (EogListStore *store,
file_enumerator = g_file_enumerate_children (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
G_FILE_ATTRIBUTE_STANDARD_NAME,
0, NULL, NULL);
@ -690,6 +696,7 @@ eog_list_store_add_files (EogListStore *store, GList *file_list)
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE","
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
0, NULL, NULL);
if (file_info == NULL) {
@ -703,7 +710,7 @@ eog_list_store_add_files (EogListStore *store, GList *file_list)
if (G_UNLIKELY (file_type == G_FILE_TYPE_UNKNOWN)) {
const gchar *ctype;
ctype = g_file_info_get_content_type (file_info);
ctype = eog_util_get_content_type_with_fallback (file_info);
/* If the content type is supported adjust file_type */
if (eog_image_is_supported_mime_type (ctype))

View file

@ -152,14 +152,15 @@ eog_metadata_sidebar_update_general_section (EogMetadataSidebar *sidebar)
file = eog_image_get_file (img);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
if (file_info == NULL) {
str = g_strdup (_("Unknown"));
} else {
const gchar *mime_str;
mime_str = g_file_info_get_content_type (file_info);
mime_str = eog_util_get_content_type_with_fallback (file_info);
str = g_content_type_get_description (mime_str);
g_object_unref (file_info);
}

View file

@ -351,12 +351,13 @@ eog_remote_presenter_update (EogRemotePresenter *remote_presenter,
file = eog_image_get_file (image);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
if (file_info == NULL) {
type_str = g_strdup (_("Unknown"));
} else {
mime_str = g_file_info_get_content_type (file_info);
mime_str = eog_util_get_content_type_with_fallback (file_info);
type_str = g_content_type_get_description (mime_str);
g_object_unref (file_info);
}

View file

@ -499,7 +499,8 @@ thumbview_get_tooltip_string (EogImage *image)
file = eog_image_get_file (image);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
g_object_unref (file);
if (file_info == NULL) {
@ -507,7 +508,7 @@ thumbview_get_tooltip_string (EogImage *image)
return NULL;
}
mime_str = g_file_info_get_content_type (file_info);
mime_str = eog_util_get_content_type_with_fallback (file_info);
if (G_UNLIKELY (mime_str == NULL)) {
g_free (bytes);

View file

@ -36,6 +36,7 @@
#include "eog-thumbnail.h"
#include "eog-list-store.h"
#include "eog-debug.h"
#include "eog-util.h"
#define EOG_THUMB_ERROR eog_thumb_error_quark ()
@ -152,6 +153,7 @@ eog_thumb_data_new (GFile *file, GError **error)
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE ","
G_FILE_ATTRIBUTE_TIME_MODIFIED ","
G_FILE_ATTRIBUTE_THUMBNAIL_PATH ","
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","
@ -167,7 +169,7 @@ eog_thumb_data_new (GFile *file, GError **error)
/* if available, copy data */
data->mtime = g_file_info_get_attribute_uint64 (file_info,
G_FILE_ATTRIBUTE_TIME_MODIFIED);
data->mime_type = g_strdup (g_file_info_get_content_type (file_info));
data->mime_type = g_strdup (eog_util_get_content_type_with_fallback (file_info));
data->failed_thumb_exists = g_file_info_get_attribute_boolean (file_info,
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);

View file

@ -475,6 +475,24 @@ eog_util_create_width_height_string (gint width, gint height)
width, height);
}
const char*
eog_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;
}
/* Portal */

View file

@ -68,6 +68,9 @@ void eog_util_show_file_in_filemanager (GFile *file,
G_GNUC_INTERNAL
gchar *eog_util_create_width_height_string (gint width, gint height);
G_GNUC_INTERNAL
const char *eog_util_get_content_type_with_fallback (GFileInfo *file_info);
#ifdef HAVE_LIBPORTAL
G_GNUC_INTERNAL
gboolean eog_util_is_running_inside_flatpak (void);

View file

@ -843,7 +843,8 @@ add_file_to_recent_files (GFile *file)
return FALSE;
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
if (file_info == NULL)
return FALSE;
@ -851,7 +852,7 @@ add_file_to_recent_files (GFile *file)
recent_data = g_slice_new (GtkRecentData);
recent_data->display_name = NULL;
recent_data->description = NULL;
recent_data->mime_type = (gchar *) g_file_info_get_content_type (file_info);
recent_data->mime_type = (gchar *) eog_util_get_content_type_with_fallback (file_info);
recent_data->app_name = EOG_RECENT_FILES_APP_NAME;
recent_data->app_exec = g_strjoin(" ", g_get_prgname (), "%u", NULL);
recent_data->groups = groups;
@ -1088,9 +1089,12 @@ eog_window_open_file_chooser_dialog (EogWindow *window)
const gchar *mime_type = NULL;
file = eog_image_get_file (window->priv->image);
file_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 0, NULL, NULL);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
0, NULL, NULL);
mime_type = g_content_type_get_mime_type (
g_file_info_get_content_type (file_info));
eog_util_get_content_type_with_fallback (file_info));
g_object_unref (file_info);
dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (window),