[gtk/wip/matthiasc/icon-theme: 5/12] icon theme: Start to untangle GtkIconInfo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/icon-theme: 5/12] icon theme: Start to untangle GtkIconInfo
- Date: Fri, 18 Oct 2019 13:59:22 +0000 (UTC)
commit dd69bcabf778c082ab47bff208a3f81301d89bed
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Oct 18 07:22:11 2019 -0500
icon theme: Start to untangle GtkIconInfo
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 | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index fa25c55f49..7598f24d9f 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]