[nautilus/wip/antoniof/gtk4-preparation-drop-libgd: 41/45] canvas-view: Add style class for thumbnails




commit 8a9de63c221a6ca98ca5cc4e5481ebc34850fbc6
Author: António Fernandes <antoniof gnome org>
Date:   Tue Nov 2 21:19:55 2021 +0000

    canvas-view: Add style class for thumbnails
    
    For the sake of visual experimentation, also add this feature to
    canvas view, even though it's going to be removed soon.

 src/nautilus-canvas-container.c      | 11 +++++++----
 src/nautilus-canvas-container.h      |  3 ++-
 src/nautilus-canvas-item.c           | 10 +++++++++-
 src/nautilus-canvas-item.h           |  3 ++-
 src/nautilus-canvas-view-container.c | 12 +++++++++++-
 5 files changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 44b637166..17701b161 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -4788,14 +4788,15 @@ static NautilusIconInfo *
 nautilus_canvas_container_get_icon_images (NautilusCanvasContainer *container,
                                            NautilusCanvasIconData  *data,
                                            int                      size,
-                                           gboolean                 for_drag_accept)
+                                           gboolean                 for_drag_accept,
+                                           gboolean                *is_thumbnail)
 {
     NautilusCanvasContainerClass *klass;
 
     klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
     g_assert (klass->get_icon_images != NULL);
 
-    return klass->get_icon_images (container, data, size, for_drag_accept);
+    return klass->get_icon_images (container, data, size, for_drag_accept, is_thumbnail);
 }
 
 static void
@@ -4897,6 +4898,7 @@ nautilus_canvas_container_update_icon (NautilusCanvasContainer *container,
     guint icon_size;
     guint min_image_size, max_image_size;
     NautilusIconInfo *icon_info;
+    gboolean is_thumbnail;
     GdkPixbuf *pixbuf;
     char *editable_text, *additional_text;
 
@@ -4921,7 +4923,8 @@ nautilus_canvas_container_update_icon (NautilusCanvasContainer *container,
 
     /* Get the icons. */
     icon_info = nautilus_canvas_container_get_icon_images (container, icon->data, icon_size,
-                                                           icon == details->drop_target);
+                                                           icon == details->drop_target,
+                                                           &is_thumbnail);
 
     pixbuf = nautilus_icon_info_get_pixbuf (icon_info);
     g_object_unref (icon_info);
@@ -4938,7 +4941,7 @@ nautilus_canvas_container_update_icon (NautilusCanvasContainer *container,
                          "highlighted_for_drop", icon == details->drop_target,
                          NULL);
 
-    nautilus_canvas_item_set_image (icon->item, pixbuf);
+    nautilus_canvas_item_set_image (icon->item, pixbuf, is_thumbnail);
 
     /* Let the pixbufs go. */
     g_object_unref (pixbuf);
diff --git a/src/nautilus-canvas-container.h b/src/nautilus-canvas-container.h
index 7955cf34d..01df2ad62 100644
--- a/src/nautilus-canvas-container.h
+++ b/src/nautilus-canvas-container.h
@@ -134,7 +134,8 @@ typedef struct {
        NautilusIconInfo *(* get_icon_images)     (NautilusCanvasContainer *container,
                                                     NautilusCanvasIconData *data,
                                                     int canvas_size,
-                                                    gboolean for_drag_accept);
+                                                    gboolean for_drag_accept,
+                                                    gboolean *is_thumbnail);
        void         (* get_icon_text)            (NautilusCanvasContainer *container,
                                                     NautilusCanvasIconData *data,
                                                     char **editable_text,
diff --git a/src/nautilus-canvas-item.c b/src/nautilus-canvas-item.c
index 762c8832a..f51967d23 100644
--- a/src/nautilus-canvas-item.c
+++ b/src/nautilus-canvas-item.c
@@ -116,6 +116,8 @@ struct NautilusCanvasItemDetails
 
     guint is_visible : 1;
 
+    guint is_thumbnail : 1;
+
     /* Cached PangoLayouts. Only used if the icon is visible */
     PangoLayout *editable_text_layout;
     PangoLayout *additional_text_layout;
@@ -472,7 +474,8 @@ get_scaled_icon_size (NautilusCanvasItem *item,
 
 void
 nautilus_canvas_item_set_image (NautilusCanvasItem *item,
-                                GdkPixbuf          *image)
+                                GdkPixbuf          *image,
+                                gboolean            is_thumbnail)
 {
     NautilusCanvasItemDetails *details;
 
@@ -488,6 +491,7 @@ nautilus_canvas_item_set_image (NautilusCanvasItem *item,
     if (image != NULL)
     {
         g_object_ref (image);
+        details->is_thumbnail = is_thumbnail;
     }
     if (details->pixbuf != NULL)
     {
@@ -1358,6 +1362,10 @@ nautilus_canvas_item_draw (EelCanvasItem  *item,
     context = gtk_widget_get_style_context (GTK_WIDGET (container));
     gtk_style_context_save (context);
     gtk_style_context_add_class (context, "nautilus-canvas-item");
+    if (details->is_thumbnail)
+    {
+        gtk_style_context_add_class (context, "thumbnail");
+    }
 
     icon_rect = canvas_item->details->icon_rect;
     temp_surface = map_surface (canvas_item);
diff --git a/src/nautilus-canvas-item.h b/src/nautilus-canvas-item.h
index 436fb6b46..92b59c4eb 100644
--- a/src/nautilus-canvas-item.h
+++ b/src/nautilus-canvas-item.h
@@ -64,7 +64,8 @@ GType       nautilus_canvas_item_get_type                 (void);
 
 /* attributes */
 void        nautilus_canvas_item_set_image                (NautilusCanvasItem       *item,
-                                                          GdkPixbuf                *image);
+                                                          GdkPixbuf                *image,
+                                                          gboolean                  is_thumbnail);
 cairo_surface_t* nautilus_canvas_item_get_drag_surface    (NautilusCanvasItem       *item);
 void        nautilus_canvas_item_set_emblems              (NautilusCanvasItem       *item,
                                                           GList                    *emblem_pixbufs);
diff --git a/src/nautilus-canvas-view-container.c b/src/nautilus-canvas-view-container.c
index a8b1f8ad6..23564aaa2 100644
--- a/src/nautilus-canvas-view-container.c
+++ b/src/nautilus-canvas-view-container.c
@@ -53,7 +53,8 @@ static NautilusIconInfo *
 nautilus_canvas_view_container_get_icon_images (NautilusCanvasContainer *container,
                                                 NautilusCanvasIconData  *data,
                                                 int                      size,
-                                                gboolean                 for_drag_accept)
+                                                gboolean                 for_drag_accept,
+                                                gboolean                *is_thumbnail)
 {
     NautilusCanvasView *canvas_view;
     NautilusFile *file;
@@ -78,6 +79,15 @@ nautilus_canvas_view_container_get_icon_images (NautilusCanvasContainer *contain
     scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas_view));
     icon_info = nautilus_file_get_icon (file, size, scale, flags);
 
+    if (is_thumbnail != NULL)
+    {
+        g_autofree gchar *thumbnail_path = NULL;
+
+        thumbnail_path = nautilus_file_get_thumbnail_path (file);
+        *is_thumbnail = (thumbnail_path != NULL &&
+                         nautilus_file_should_show_thumbnail (file));
+    }
+
     return icon_info;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]