From 2d90031dabac866b8aec6f82202c5db3ea6ce55f Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 28 Feb 2023 13:50:08 -0300 Subject: [PATCH 1/3] filethumbnail: Cosmetics Remove an empty newline --- gtk/gtkfilethumbnail.c | 1 - 1 file changed, 1 deletion(-) diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c index f48de386a9..3203589027 100644 --- a/gtk/gtkfilethumbnail.c +++ b/gtk/gtkfilethumbnail.c @@ -91,7 +91,6 @@ update_image (GtkFileThumbnail *self) g_object_unref (icon); return TRUE; - } static void From 158165f769c6eaee7209b0bd84d480c000d64e07 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 28 Feb 2023 13:52:12 -0300 Subject: [PATCH 2/3] filethumbnail: Clear image on failure Unset the image if we fail to find the appropriate icon, regardless of the reason of the failure. Prevents the thumbnail to misrepresent the GFileInfo it's supposed to represent. --- gtk/gtkfilethumbnail.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c index 3203589027..3e01484158 100644 --- a/gtk/gtkfilethumbnail.c +++ b/gtk/gtkfilethumbnail.c @@ -78,7 +78,10 @@ update_image (GtkFileThumbnail *self) int scale; if (!g_file_info_has_attribute (self->info, G_FILE_ATTRIBUTE_STANDARD_ICON)) - return FALSE; + { + gtk_image_clear (GTK_IMAGE (self->image)); + return FALSE; + } scale = gtk_widget_get_scale_factor (GTK_WIDGET (self)); icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (self))); @@ -128,7 +131,10 @@ static void get_thumbnail (GtkFileThumbnail *self) { if (!self->info) - return; + { + gtk_image_clear (GTK_IMAGE (self->image)); + return; + } if (!update_image (self)) { From d8b7c909ea1d14afd366dd2edf5b07696b2b91a6 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 28 Feb 2023 13:54:11 -0300 Subject: [PATCH 3/3] filethumbnail: Set filechooser::queried after querying Setting this attribute after querying, but before receiving the results, can lead to inappropriate behaviour. This can be reproduced by dragging the scrollbar very quickly in a large directory; after going up and down a few times, some thumbnails will be wrong. Without this branch, "wrong" means they'll show the completely wrong icon or thumbnail, e.g. a folder icon in a video file. With previous commit, "wrong" means they'll be empty even when there is a thumbnail available. The sequence of events that triggers this is as follows: 1. GtkListItem receives a GFileInfo object and passes it to GtkFileThumbnail via expressions 2. `get_thumbnail()` is called, doesn't find a thumbnail 3. `filechooser::queried` is not set yet, so it is set to TRUE and we call `g_file_query_info_async()` 4. **Before `thumbnail_queried_cb` is called**, a new GFileInfo is set, and we cancel the query initiated in the previous step 5. We now have a GFileInfo with `filechooser::queried` set to TRUE, and no thumbnail! This commit fixes that by only setting the `filechooser::queried` attribute after the icon is queried. We need to set it in two situations: when the query is successful, or when the error is not G_IO_ERROR_CANCELLED. That's because the query was cancelled, we didn't really perform it! --- gtk/gtkfilethumbnail.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c index 3e01484158..84df7dcc07 100644 --- a/gtk/gtkfilethumbnail.c +++ b/gtk/gtkfilethumbnail.c @@ -104,10 +104,19 @@ thumbnail_queried_cb (GObject *object, GtkFileThumbnail *self = user_data; /* might be unreffed if operation was cancelled */ GFile *file = G_FILE (object); GFileInfo *queried; + GError *error = NULL; - queried = g_file_query_info_finish (file, result, NULL); - if (queried == NULL) - return; + queried = g_file_query_info_finish (file, result, &error); + + if (error) + { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_file_info_set_attribute_boolean (self->info, "filechooser::queried", TRUE); + g_clear_error (&error); + return; + } + + g_file_info_set_attribute_boolean (self->info, "filechooser::queried", TRUE); copy_attribute (self->info, queried, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); copy_attribute (self->info, queried, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); @@ -147,7 +156,6 @@ get_thumbnail (GtkFileThumbnail *self) self->cancellable = g_cancellable_new (); file = _gtk_file_info_get_file (self->info); - g_file_info_set_attribute_boolean (self->info, "filechooser::queried", TRUE); g_file_query_info_async (file, G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," G_FILE_ATTRIBUTE_THUMBNAILING_FAILED ","