From: Matthias Clasen Date: Fri, 18 Oct 2019 12:22:11 +0000 (-0500) Subject: icon theme: Start to untangle GtkIconInfo X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~696^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dd69bcabf778c082ab47bff208a3f81301d89bed;p=gtk4.git 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. --- 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