From f8998e1624bc80021557a2ce908525e33a89afd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 1 Jul 2022 13:44:41 +0100 Subject: [PATCH 1/4] bookmark: Simplify broken bookmark icon logic There is no need to restore emblem functionlity here, because a warning icon works just fine. Let's cleanup. --- src/nautilus-bookmark.c | 46 +++++++---------------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/src/nautilus-bookmark.c b/src/nautilus-bookmark.c index ba56a97e5b..f016eee37f 100644 --- a/src/nautilus-bookmark.c +++ b/src/nautilus-bookmark.c @@ -168,36 +168,6 @@ bookmark_file_changed_callback (NautilusFile *file, } } -static void -apply_warning_emblem (GIcon **base, - gboolean symbolic) -{ -#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION - GIcon *emblemed_icon; - g_autoptr (GIcon) warning = NULL; - g_autoptr (GEmblem) emblem = NULL; - - if (symbolic) - { - warning = g_themed_icon_new ("dialog-warning-symbolic"); - } - else - { - warning = g_themed_icon_new ("dialog-warning"); - } - - emblem = g_emblem_new (warning); - emblemed_icon = g_emblemed_icon_new (*base, emblem); - - g_object_unref (*base); - - *base = emblemed_icon; -#else - /* GTK 4 doesn't draw emblemed icons. Use the warning icon itself. */ - g_set_object (base, g_themed_icon_new (symbolic ? "dialog-warning-symbolic" : "dialog-warning")); -#endif -} - gboolean nautilus_bookmark_get_is_builtin (NautilusBookmark *bookmark) { @@ -303,7 +273,13 @@ nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark) g_autoptr (GIcon) icon = NULL; g_autoptr (GIcon) symbolic_icon = NULL; - if (g_file_is_native (bookmark->location)) + if (!bookmark->exists) + { + DEBUG ("%s: file does not exist, set warning icon", nautilus_bookmark_get_name (bookmark)); + symbolic_icon = g_themed_icon_new ("dialog-warning-symbolic"); + icon = g_themed_icon_new ("dialog-warning"); + } + else if (g_file_is_native (bookmark->location)) { symbolic_icon = get_native_icon (bookmark, TRUE); icon = get_native_icon (bookmark, FALSE); @@ -314,14 +290,6 @@ nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark) icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_REMOTE); } - if (!bookmark->exists) - { - DEBUG ("%s: file does not exist, add emblem", nautilus_bookmark_get_name (bookmark)); - - apply_warning_emblem (&icon, FALSE); - apply_warning_emblem (&symbolic_icon, TRUE); - } - DEBUG ("%s: setting icon to default", nautilus_bookmark_get_name (bookmark)); g_object_set (bookmark, -- GitLab From 9e08463e798badecf88937ee2c531deff86edf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 1 Jul 2022 14:52:58 +0100 Subject: [PATCH 2/4] file: Remove remaining GEmblemedIcon support Emblemed icons are not implemented in GTK 4 and we don't want to reimplement them here anyway, so let's drop this code. --- src/nautilus-file.c | 62 +--------------------------------------- src/nautilus-file.h | 3 -- src/nautilus-grid-cell.c | 4 +-- src/nautilus-name-cell.c | 4 +-- 4 files changed, 3 insertions(+), 70 deletions(-) diff --git a/src/nautilus-file.c b/src/nautilus-file.c index 5bdc0e125f..35538c96c0 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -5032,53 +5032,6 @@ prepend_icon_name (const char *name, g_themed_icon_prepend_name (icon, name); } -static void -apply_emblems_to_icon (NautilusFile *file, - GIcon **icon, - NautilusFileIconFlags flags) -{ -#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION - GIcon *emblemed_icon = NULL; - - g_autolist (GIcon) emblems = NULL; - - emblems = nautilus_file_get_emblem_icons (file); - - for (GList *l = emblems; l != NULL; l = l->next) - { - g_autoptr (GEmblem) emblem = NULL; - - if (g_icon_equal (l->data, *icon)) - { - continue; - } - - emblem = g_emblem_new (l->data); - - if (emblemed_icon == NULL) - { - emblemed_icon = g_emblemed_icon_new (*icon, emblem); - } - else - { - g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem); - } - - if (emblemed_icon != NULL && - (flags & NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM)) - { - break; - } - } - - if (emblemed_icon != NULL) - { - g_object_unref (*icon); - *icon = emblemed_icon; - } -#endif -} - GIcon * nautilus_file_get_gicon (NautilusFile *file, NautilusFileIconFlags flags) @@ -5117,8 +5070,7 @@ nautilus_file_get_gicon (NautilusFile *file, if (((flags & NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT) || (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER) || - (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON) || - (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS)) && + (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON)) && G_IS_THEMED_ICON (file->details->icon)) { names = g_themed_icon_get_names (G_THEMED_ICON (file->details->icon)); @@ -5179,11 +5131,6 @@ out: icon = g_object_ref (get_default_file_icon ()); } - if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS) - { - apply_emblems_to_icon (file, &icon, flags); - } - return icon; } @@ -5290,8 +5237,6 @@ nautilus_file_get_thumbnail_icon (NautilusFile *file, if (gicon != NULL) { - apply_emblems_to_icon (file, &gicon, flags); - if (g_icon_equal (gicon, G_ICON (pixbuf))) { icon = nautilus_icon_info_new_for_pixbuf (pixbuf, scale); @@ -5342,11 +5287,6 @@ nautilus_file_get_icon (NautilusFile *file, gicon = get_custom_icon (file); if (gicon != NULL) { - if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS) - { - apply_emblems_to_icon (file, &gicon, flags); - } - icon = nautilus_icon_info_lookup (gicon, size, scale); g_object_unref (gicon); diff --git a/src/nautilus-file.h b/src/nautilus-file.h index 713ef7349c..4d8b3aecd3 100644 --- a/src/nautilus-file.h +++ b/src/nautilus-file.h @@ -87,9 +87,6 @@ typedef enum { NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE = (1<<4), /* uses the icon of the mount if present */ NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON = (1<<5), - /* render emblems */ - NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS = (1<<6), - NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM = (1<<7) } NautilusFileIconFlags; #define NAUTILUS_THUMBNAIL_MINIMUM_ICON_SIZE 32 diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c index 28fc43622b..5e36d352d1 100644 --- a/src/nautilus-grid-cell.c +++ b/src/nautilus-grid-cell.c @@ -43,9 +43,7 @@ update_icon (NautilusGridCell *self) file = nautilus_view_item_get_file (item); icon_size = nautilus_view_item_get_icon_size (item); flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS | - NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE | - NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS | - NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM; + NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE; g_object_get (item, "drag-accept", &drag_accept, NULL); if (drag_accept) diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c index 55574cb0a7..397693cdbf 100644 --- a/src/nautilus-name-cell.c +++ b/src/nautilus-name-cell.c @@ -149,9 +149,7 @@ update_icon (NautilusNameCell *self) file = nautilus_view_item_get_file (item); icon_size = nautilus_view_item_get_icon_size (item); flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS | - NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE | - NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS | - NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM; + NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE; g_object_get (item, "drag-accept", &drag_accept, NULL); if (drag_accept) -- GitLab From 8a50974788cc47ba11048679362abc9154a33e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Sat, 2 Jul 2022 13:26:02 +0100 Subject: [PATCH 3/4] grid-cell: Set extra margin in UI, not code We have been setting this margin in code depending on icon size. But we are going to need this margin in all sizes in order to have space for emblems. --- src/nautilus-grid-cell.c | 8 -------- src/resources/ui/nautilus-grid-cell.ui | 2 ++ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c index 5e36d352d1..41fb3d0fc6 100644 --- a/src/nautilus-grid-cell.c +++ b/src/nautilus-grid-cell.c @@ -24,8 +24,6 @@ struct _NautilusGridCell G_DEFINE_TYPE (NautilusGridCell, nautilus_grid_cell, NAUTILUS_TYPE_VIEW_CELL) -#define EXTRA_WIDTH_FOR_TEXT 36 - static void update_icon (NautilusGridCell *self) { @@ -57,12 +55,6 @@ update_icon (NautilusGridCell *self) /* Set the same height and width for all icons regardless of aspect ratio. */ gtk_widget_set_size_request (self->fixed_height_box, icon_size, icon_size); - if (icon_size < NAUTILUS_GRID_ICON_SIZE_EXTRA_LARGE) - { - int extra_margins = 0.5 * EXTRA_WIDTH_FOR_TEXT; - gtk_widget_set_margin_start (self->fixed_height_box, extra_margins); - gtk_widget_set_margin_end (self->fixed_height_box, extra_margins); - } style_context = gtk_widget_get_style_context (self->icon); thumbnail_path = nautilus_file_get_thumbnail_path (file); if (thumbnail_path != NULL && diff --git a/src/resources/ui/nautilus-grid-cell.ui b/src/resources/ui/nautilus-grid-cell.ui index 2a9417aa86..1b98d22014 100644 --- a/src/resources/ui/nautilus-grid-cell.ui +++ b/src/resources/ui/nautilus-grid-cell.ui @@ -13,6 +13,8 @@ vertical center + 18 + 18 0 -- GitLab From 9112f1b45e055ebc2862e4ae9f13bdbad0160a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= Date: Fri, 1 Jul 2022 14:54:00 +0100 Subject: [PATCH 4/4] general: Reimplement emblems as a box of icons We used to display emblems overlaid on icons. This had a few problems: * Emblemed icons were not cached. * If the icon was too small, some emblems could be omitted. * Emblems would partially obstruct the visibility of thumbnails. So, we are reintroducing them as a mere box of icons: * vertically next to the file icon/thumbnail in grid view; * horizontally next to the filename in list view. This avoids all the problems of the old implementation. Closes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2017 --- src/nautilus-file.c | 10 +++----- src/nautilus-file.h | 2 ++ src/nautilus-grid-cell.c | 30 ++++++++++++++++++++++ src/nautilus-name-cell.c | 29 +++++++++++++++++++++ src/resources/ui/nautilus-grid-cell.ui | 12 +++++++-- src/resources/ui/nautilus-name-cell.ui | 35 ++++++++++++++++++-------- 6 files changed, 99 insertions(+), 19 deletions(-) diff --git a/src/nautilus-file.c b/src/nautilus-file.c index 35538c96c0..a173f63d96 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -3390,7 +3390,6 @@ compare_by_directory_name (NautilusFile *file_1, file_2->details->directory_name_collation_key); } -#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION static GList * prepend_automatic_keywords (NautilusFile *file, GList *names) @@ -3428,7 +3427,6 @@ prepend_automatic_keywords (NautilusFile *file, return names; } -#endif static int compare_by_type (NautilusFile *file_1, @@ -4850,7 +4848,6 @@ nautilus_is_video_file (NautilusFile *file) return FALSE; } -#if 0 && EMBLEMS_NEEDS_GTK4_REIMPLEMENTATION static GList * sort_keyword_list_and_remove_duplicates (GList *keywords) { @@ -4958,7 +4955,7 @@ nautilus_file_get_keywords (NautilusFile *file) metadata_strv = nautilus_file_get_metadata_list (file, NAUTILUS_METADATA_KEY_EMBLEMS); /* Convert array to list */ - for (gint i = 0; metadata_strv[i] != NULL; i++) + for (gint i = 0; metadata_strv != NULL && metadata_strv[i] != NULL; i++) { metadata_keywords = g_list_prepend (metadata_keywords, metadata_strv[i]); } @@ -4978,10 +4975,10 @@ nautilus_file_get_keywords (NautilusFile *file) * in canonical order. * @file: NautilusFile representing the file in question. * - * Returns: A list of emblem names. + * Returns: (transfer full) (element-type GIcon): A list of emblem names. * **/ -static GList * +GList * nautilus_file_get_emblem_icons (NautilusFile *file) { GList *keywords, *l; @@ -5023,7 +5020,6 @@ nautilus_file_get_emblem_icons (NautilusFile *file) return icons; } -#endif static void prepend_icon_name (const char *name, diff --git a/src/nautilus-file.h b/src/nautilus-file.h index 4d8b3aecd3..088d57d4be 100644 --- a/src/nautilus-file.h +++ b/src/nautilus-file.h @@ -479,6 +479,8 @@ GdkPaintable * nautilus_file_get_icon_paintable (Nautilu int scale, NautilusFileIconFlags flags); +GList * nautilus_file_get_emblem_icons (NautilusFile *file); + /* Whether the file should open inside a view */ gboolean nautilus_file_opens_in_view (NautilusFile *file); /* Thumbnailing handling */ diff --git a/src/nautilus-grid-cell.c b/src/nautilus-grid-cell.c index 41fb3d0fc6..383d85b036 100644 --- a/src/nautilus-grid-cell.c +++ b/src/nautilus-grid-cell.c @@ -16,6 +16,7 @@ struct _NautilusGridCell GtkWidget *fixed_height_box; GtkWidget *icon; + GtkWidget *emblems_box; GtkWidget *label; GtkWidget *first_caption; GtkWidget *second_caption; @@ -100,6 +101,33 @@ update_captions (NautilusGridCell *self) } } +static void +update_emblems (NautilusGridCell *self) +{ + NautilusViewItem *item; + NautilusFile *file; + GtkWidget *child; + g_autolist (GIcon) emblems = NULL; + + item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self)); + g_return_if_fail (item != NULL); + file = nautilus_view_item_get_file (item); + + /* Remove old emblems. */ + while ((child = gtk_widget_get_first_child (self->emblems_box)) != NULL) + { + gtk_box_remove (GTK_BOX (self->emblems_box), child); + } + + emblems = nautilus_file_get_emblem_icons (file); + for (GList *l = emblems; l != NULL; l = l->next) + { + gtk_box_append (GTK_BOX (self->emblems_box), + gtk_image_new_from_gicon (l->data)); + } +} + + static void on_file_changed (NautilusGridCell *self) { @@ -111,6 +139,7 @@ on_file_changed (NautilusGridCell *self) file = nautilus_view_item_get_file (item); update_icon (self); + update_emblems (self); gtk_label_set_text (GTK_LABEL (self->label), nautilus_file_get_display_name (file)); @@ -169,6 +198,7 @@ nautilus_grid_cell_class_init (NautilusGridCellClass *klass) gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, fixed_height_box); gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, icon); + gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, emblems_box); gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, label); gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, first_caption); gtk_widget_class_bind_template_child (widget_class, NautilusGridCell, second_caption); diff --git a/src/nautilus-name-cell.c b/src/nautilus-name-cell.c index 397693cdbf..1a0720ea62 100644 --- a/src/nautilus-name-cell.c +++ b/src/nautilus-name-cell.c @@ -19,6 +19,7 @@ struct _NautilusNameCell GtkWidget *fixed_height_box; GtkWidget *icon; GtkWidget *label; + GtkWidget *emblems_box; GtkWidget *snippet; GtkWidget *path; @@ -190,11 +191,38 @@ update_icon (NautilusNameCell *self) } } +static void +update_emblems (NautilusNameCell *self) +{ + NautilusViewItem *item; + NautilusFile *file; + GtkWidget *child; + g_autolist (GIcon) emblems = NULL; + + item = nautilus_view_cell_get_item (NAUTILUS_VIEW_CELL (self)); + g_return_if_fail (item != NULL); + file = nautilus_view_item_get_file (item); + + /* Remove old emblems. */ + while ((child = gtk_widget_get_first_child (self->emblems_box)) != NULL) + { + gtk_box_remove (GTK_BOX (self->emblems_box), child); + } + + emblems = nautilus_file_get_emblem_icons (file); + for (GList *l = emblems; l != NULL; l = l->next) + { + gtk_box_append (GTK_BOX (self->emblems_box), + gtk_image_new_from_gicon (l->data)); + } +} + static void on_file_changed (NautilusNameCell *self) { update_icon (self); update_labels (self); + update_emblems (self); } static void @@ -289,6 +317,7 @@ nautilus_name_cell_class_init (NautilusNameCellClass *klass) gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, fixed_height_box); gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, icon); gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, label); + gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, emblems_box); gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, snippet); gtk_widget_class_bind_template_child (widget_class, NautilusNameCell, path); } diff --git a/src/resources/ui/nautilus-grid-cell.ui b/src/resources/ui/nautilus-grid-cell.ui index 1b98d22014..63ec651c2c 100644 --- a/src/resources/ui/nautilus-grid-cell.ui +++ b/src/resources/ui/nautilus-grid-cell.ui @@ -11,10 +11,9 @@ 6 - vertical + horizontal center 18 - 18 0 @@ -29,6 +28,15 @@ + + + vertical + end + 6 + 2 + 16 + + diff --git a/src/resources/ui/nautilus-name-cell.ui b/src/resources/ui/nautilus-name-cell.ui index 366e6e370f..4313b92d67 100644 --- a/src/resources/ui/nautilus-name-cell.ui +++ b/src/resources/ui/nautilus-name-cell.ui @@ -52,16 +52,31 @@ - - middle - 1 - -1 - False - word-char - start - - - + + horizontal + fill + True + 6 + + + middle + 1 + -1 + False + word-char + start + + + + + + + + horizontal + start + 6 + + -- GitLab