[gnome-flashback] desktop: add get_icon vfunction



commit 4209ed8572ddf67e35863e872cc40345b6c93635
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Nov 18 02:47:13 2019 +0200

    desktop: add get_icon vfunction

 gnome-flashback/libdesktop/gf-home-icon.c  | 11 ++++++++
 gnome-flashback/libdesktop/gf-icon.c       | 42 +++++++++++++++++++++++++-----
 gnome-flashback/libdesktop/gf-icon.h       |  6 ++++-
 gnome-flashback/libdesktop/gf-trash-icon.c | 11 ++++++++
 4 files changed, 63 insertions(+), 7 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-home-icon.c b/gnome-flashback/libdesktop/gf-home-icon.c
index 7e11bdb..8fb1adc 100644
--- a/gnome-flashback/libdesktop/gf-home-icon.c
+++ b/gnome-flashback/libdesktop/gf-home-icon.c
@@ -25,6 +25,16 @@ struct _GfHomeIcon
 
 G_DEFINE_TYPE (GfHomeIcon, gf_home_icon, GF_TYPE_ICON)
 
+static GIcon *
+gf_home_icon_get_icon (GfIcon *icon)
+{
+  GFileInfo *info;
+
+  info = gf_icon_get_file_info (icon);
+
+  return g_file_info_get_icon (info);
+}
+
 static gboolean
 gf_home_icon_can_rename (GfIcon *icon)
 {
@@ -38,6 +48,7 @@ gf_home_icon_class_init (GfHomeIconClass *self_class)
 
   icon_class = GF_ICON_CLASS (self_class);
 
+  icon_class->get_icon = gf_home_icon_get_icon;
   icon_class->can_rename = gf_home_icon_can_rename;
 }
 
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index d29d10f..5b6fd33 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -427,17 +427,18 @@ update_icon (GfIcon *self)
 {
   GfIconPrivate *priv;
   GIcon *icon;
+  GtkIconSize size;
 
   priv = gf_icon_get_instance_private (self);
 
-  icon = NULL;
-  if (priv->app_info != NULL)
-    icon = g_app_info_get_icon (G_APP_INFO (priv->app_info));
+  icon = GF_ICON_GET_CLASS (self)->get_icon (self);
+  size = GTK_ICON_SIZE_DIALOG;
 
-  if (icon == NULL)
-    icon = g_file_info_get_icon (priv->info);
+  if (icon != NULL)
+    gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, size);
+  else
+    gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), "image-missing", size);
 
-  gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon, GTK_ICON_SIZE_DIALOG);
   gtk_image_set_pixel_size (GTK_IMAGE (priv->image), priv->icon_size);
 }
 
@@ -658,6 +659,24 @@ gf_icon_get_preferred_width (GtkWidget *widget,
   *natural_width += priv->extra_text_width;
 }
 
+static GIcon *
+gf_icon_get_icon (GfIcon *self)
+{
+  GfIconPrivate *priv;
+  GIcon *icon;
+
+  priv = gf_icon_get_instance_private (self);
+  icon = NULL;
+
+  if (priv->app_info != NULL)
+    icon = g_app_info_get_icon (G_APP_INFO (priv->app_info));
+
+  if (icon == NULL)
+    icon = g_file_info_get_icon (priv->info);
+
+  return icon;
+}
+
 static gboolean
 gf_icon_can_rename (GfIcon *self)
 {
@@ -744,6 +763,7 @@ gf_icon_class_init (GfIconClass *self_class)
 
   widget_class->get_preferred_width = gf_icon_get_preferred_width;
 
+  self_class->get_icon = gf_icon_get_icon;
   self_class->can_rename = gf_icon_can_rename;
 
   install_properties (object_class);
@@ -844,6 +864,16 @@ gf_icon_get_file (GfIcon *self)
   return priv->file;
 }
 
+GFileInfo *
+gf_icon_get_file_info (GfIcon *self)
+{
+  GfIconPrivate *priv;
+
+  priv = gf_icon_get_instance_private (self);
+
+  return priv->info;
+}
+
 const char *
 gf_icon_get_name (GfIcon *self)
 {
diff --git a/gnome-flashback/libdesktop/gf-icon.h b/gnome-flashback/libdesktop/gf-icon.h
index fe6d6cf..4b5f743 100644
--- a/gnome-flashback/libdesktop/gf-icon.h
+++ b/gnome-flashback/libdesktop/gf-icon.h
@@ -29,7 +29,9 @@ struct _GfIconClass
 {
   GtkButtonClass parent_class;
 
-  gboolean (* can_rename) (GfIcon *self);
+  GIcon    * (* get_icon)   (GfIcon *self);
+
+  gboolean   (* can_rename) (GfIcon *self);
 };
 
 GtkWidget  *gf_icon_new               (GfIconView *icon_view,
@@ -41,6 +43,8 @@ void        gf_icon_set_file          (GfIcon     *self,
 
 GFile      *gf_icon_get_file          (GfIcon     *self);
 
+GFileInfo  *gf_icon_get_file_info     (GfIcon     *self);
+
 const char *gf_icon_get_name          (GfIcon     *self);
 
 const char *gf_icon_get_name_collated (GfIcon     *self);
diff --git a/gnome-flashback/libdesktop/gf-trash-icon.c b/gnome-flashback/libdesktop/gf-trash-icon.c
index 93a725c..9712c15 100644
--- a/gnome-flashback/libdesktop/gf-trash-icon.c
+++ b/gnome-flashback/libdesktop/gf-trash-icon.c
@@ -186,6 +186,16 @@ gf_trash_icon_dispose (GObject *object)
   G_OBJECT_CLASS (gf_trash_icon_parent_class)->dispose (object);
 }
 
+static GIcon *
+gf_trash_icon_get_icon (GfIcon *icon)
+{
+  GFileInfo *info;
+
+  info = gf_icon_get_file_info (icon);
+
+  return g_file_info_get_icon (info);
+}
+
 static gboolean
 gf_trash_icon_can_rename (GfIcon *icon)
 {
@@ -204,6 +214,7 @@ gf_trash_icon_class_init (GfTrashIconClass *self_class)
   object_class->constructed = gf_trash_icon_constructed;
   object_class->dispose = gf_trash_icon_dispose;
 
+  icon_class->get_icon = gf_trash_icon_get_icon;
   icon_class->can_rename = gf_trash_icon_can_rename;
 }
 


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