icon theme: Start to untangle GtkIconInfo
authorMatthias Clasen <mclasen@redhat.com>
Fri, 18 Oct 2019 12:22:11 +0000 (07:22 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 18 Oct 2019 13:53:23 +0000 (08:53 -0500)
GtkIconInfo contains too much redundant data,
and it is hard to know which fields are to be
used when.

This commit starts to move towards dropping the
icon_file field - we prefer to work with the
filename directly, since it lets us avoid mime
sniffing and strdups.

gtk/gtkicontheme.c

index fa25c55f49e5919851ab697d444f323ca10622f8..7598f24d9f5f367dfa0055feb7ca1e983c113f84 100644 (file)
@@ -3201,6 +3201,31 @@ icon_info_get_pixbuf_ready (GtkIconInfo *icon_info)
   return FALSE;
 }
 
+static GLoadableIcon *
+icon_info_get_loadable (GtkIconInfo *icon_info)
+{
+  GFile *file;
+  GLoadableIcon *loadable;
+
+  if (icon_info->loadable)
+    return g_object_ref (icon_info->loadable);
+
+  if (icon_info->is_resource)
+    {
+      char *uri = g_strconcat ("resource://", icon_info->filename, NULL);
+      file = g_file_new_for_uri (uri);
+      g_free (uri);
+    }
+  else
+    file = g_file_new_for_path (icon_info->filename);
+
+  loadable = G_LOADABLE_ICON (g_file_icon_new (file));
+
+  g_object_unref (file);
+
+  return loadable;
+}
+
 /* This function contains the complicated logic for deciding
  * on the size at which to load the icon and loading it at
  * that size.
@@ -3219,9 +3244,6 @@ icon_info_ensure_scale_and_texture (GtkIconInfo *icon_info)
   if (icon_info->load_error)
     return FALSE;
 
-  if (icon_info->icon_file && !icon_info->loadable)
-    icon_info->loadable = G_LOADABLE_ICON (g_file_icon_new (icon_info->icon_file));
-
   scaled_desired_size = icon_info->desired_size * icon_info->desired_scale;
 
   dir_scale = icon_info->dir_scale;
@@ -3295,13 +3317,16 @@ icon_info_ensure_scale_and_texture (GtkIconInfo *icon_info)
     }
   else
     {
+      GLoadableIcon *loadable;
       GInputStream *stream;
 
-      /* TODO: We should have a load_at_scale */
-      stream = g_loadable_icon_load (icon_info->loadable,
+      loadable = icon_info_get_loadable (icon_info);
+      stream = g_loadable_icon_load (loadable,
                                      scaled_desired_size,
                                      NULL, NULL,
                                      &icon_info->load_error);
+      g_object_unref (loadable);
+
       if (stream)
         {
           /* SVG icons are a special case - we just immediately scale them