[sushi/wip/cosimoc/no-clutter: 65/67] fallbackRenderer: rework how the file icon is set



commit 7d725d87a014f76bd73e77c5418f7ad3070c4908
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sun Apr 29 16:46:13 2018 -0700

    fallbackRenderer: rework how the file icon is set
    
    Instead of loading a pixbuf through the C library, return directly the
    GIcon from there. That simplifies things, and allows GtkImage to
    automatically do HiDpi handling for us.

 src/js/ui/fallbackRenderer.js    |    6 ++++--
 src/libsushi/sushi-file-loader.c |   36 +++++-------------------------------
 src/libsushi/sushi-file-loader.h |    3 +--
 3 files changed, 10 insertions(+), 35 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index 7e0359e..3e6829d 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -139,8 +139,10 @@ const FallbackRenderer = new Lang.Class({
             this._spinner.hide();
         }
 
-        if (this._fileLoader.icon)
-            this._image.set_from_pixbuf(this._fileLoader.icon);
+        if (this._fileLoader.icon) {
+            this._image.set_from_gicon(this._fileLoader.icon, Gtk.IconSize.DIALOG);
+            this._image.set_pixel_size(256);
+        }
 
         this._applyLabels();
         this._mainWindow.resizeWindow();
diff --git a/src/libsushi/sushi-file-loader.c b/src/libsushi/sushi-file-loader.c
index eddd74c..49f031c 100644
--- a/src/libsushi/sushi-file-loader.c
+++ b/src/libsushi/sushi-file-loader.c
@@ -437,7 +437,7 @@ sushi_file_loader_get_property (GObject *object,
     g_value_take_string (value, sushi_file_loader_get_date_string (self));
     break;
   case PROP_ICON:
-    g_value_take_object (value, sushi_file_loader_get_icon (self));
+    g_value_set_object (value, sushi_file_loader_get_icon (self));
     break;
   case PROP_FILE:
     g_value_set_object (value, self->priv->file);
@@ -523,7 +523,7 @@ sushi_file_loader_class_init (SushiFileLoaderClass *klass)
     g_param_spec_object ("icon",
                          "Icon",
                          "The icon of the file",
-                         GDK_TYPE_PIXBUF,
+                         G_TYPE_ICON,
                          G_PARAM_READABLE);
 
   g_type_class_add_private (klass, sizeof (SushiFileLoaderPrivate));
@@ -569,41 +569,15 @@ sushi_file_loader_get_display_name (SushiFileLoader *self)
  * sushi_file_loader_get_icon:
  * @self:
  *
- * Returns: (transfer full):
+ * Returns: (transfer none):
  */
-GdkPixbuf *
+GIcon *
 sushi_file_loader_get_icon (SushiFileLoader *self)
 {
-  GdkPixbuf *retval;
-  GtkIconInfo *info;
-  GError *error = NULL;
-
   if (self->priv->info == NULL)
     return NULL;
 
-  info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
-                                         g_file_info_get_icon (self->priv->info),
-                                         256, 0);
-
-  if (info == NULL)
-    return NULL;
-
-  retval = gtk_icon_info_load_icon (info, &error);
-  g_object_unref (info);
-
-  if (error != NULL) {
-    gchar *uri;
-
-    uri = g_file_get_uri (self->priv->file);
-    g_warning ("Unable to load icon for %s: %s", uri, error->message);
-
-    g_free (uri);
-    g_error_free (error);
-
-    return NULL;
-  }
-
-  return retval;
+  return g_file_info_get_icon (self->priv->info);
 }
 
 /**
diff --git a/src/libsushi/sushi-file-loader.h b/src/libsushi/sushi-file-loader.h
index 7a724f9..b883a5c 100644
--- a/src/libsushi/sushi-file-loader.h
+++ b/src/libsushi/sushi-file-loader.h
@@ -28,7 +28,6 @@
 
 #include <glib-object.h>
 #include <gio/gio.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
 
 G_BEGIN_DECLS
 
@@ -63,7 +62,7 @@ gchar *sushi_file_loader_get_display_name (SushiFileLoader *self);
 gchar *sushi_file_loader_get_size_string  (SushiFileLoader *self);
 gchar *sushi_file_loader_get_date_string  (SushiFileLoader *self);
 gchar *sushi_file_loader_get_content_type_string (SushiFileLoader *self);
-GdkPixbuf *sushi_file_loader_get_icon     (SushiFileLoader *self);
+GIcon *sushi_file_loader_get_icon     (SushiFileLoader *self);
 GFileType sushi_file_loader_get_file_type (SushiFileLoader *self);
 
 gboolean sushi_file_loader_get_loading (SushiFileLoader *self);


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