diff options
author | António Fernandes <antoniof@gnome.org> | 2021-12-22 21:09:07 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2021-12-31 11:12:24 +0000 |
commit | d5d9be0c06bb9f0997baee5bb513fa1a7dd4ecd0 (patch) | |
tree | ef99101d5b1b11c58808a9b97dae416029960693 /src | |
parent | 88b3e193476660a8dcbf760acf0cbd86d900fe0a (diff) | |
download | nautilus-d5d9be0c06bb9f0997baee5bb513fa1a7dd4ecd0.tar.gz |
icon-info: Stop using gtk_icon_theme_choose_icon_for_scale()
This non-GIcon API is gone in GTK 4.
The forward-compatible way is to lookup by GIcon. Actually, we already
have a GIcon anyway, and we are going the long way of getting its icon
names to pass to the non-GIcon API.
So, just use gtk_icon_theme_lookup_by_gicon_for_scale(). Also, remove
a lot of now-redundant code. This is going to help switching to GTK 4.
Diffstat (limited to 'src')
-rw-r--r-- | src/nautilus-icon-info.c | 68 |
1 files changed, 18 insertions, 50 deletions
diff --git a/src/nautilus-icon-info.c b/src/nautilus-icon-info.c index c4586da3d..fee560806 100644 --- a/src/nautilus-icon-info.c +++ b/src/nautilus-icon-info.c @@ -336,6 +336,7 @@ nautilus_icon_info_lookup (GIcon *icon, int scale) { NautilusIconInfo *icon_info; + g_autoptr (GtkIconInfo) gtkicon_info = NULL; if (G_IS_LOADABLE_ICON (icon)) { @@ -384,13 +385,18 @@ nautilus_icon_info_lookup (GIcon *icon, return g_object_ref (icon_info); } - else if (G_IS_THEMED_ICON (icon)) + + gtkicon_info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (), + icon, size, scale, 0); + if (gtkicon_info == NULL) + { + return nautilus_icon_info_new_for_pixbuf (NULL, scale); + } + + if (G_IS_THEMED_ICON (icon)) { - const char * const *names; ThemedIconKey lookup_key; ThemedIconKey *key; - GtkIconTheme *icon_theme; - GtkIconInfo *gtkicon_info; const char *filename; if (themed_icon_cache == NULL) @@ -402,17 +408,6 @@ nautilus_icon_info_lookup (GIcon *icon, (GDestroyNotify) g_object_unref); } - names = g_themed_icon_get_names (G_THEMED_ICON (icon)); - - icon_theme = gtk_icon_theme_get_default (); - gtkicon_info = gtk_icon_theme_choose_icon_for_scale (icon_theme, (const char **) names, - size, scale, GTK_ICON_LOOKUP_FORCE_SIZE); - - if (gtkicon_info == NULL) - { - return nautilus_icon_info_new_for_pixbuf (NULL, scale); - } - filename = gtk_icon_info_get_filename (gtkicon_info); if (filename == NULL) { @@ -425,49 +420,22 @@ nautilus_icon_info_lookup (GIcon *icon, lookup_key.size = size; icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key); - if (icon_info) + if (!icon_info) { - g_object_unref (gtkicon_info); - return g_object_ref (icon_info); - } + icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info, scale); - icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info, scale); - - key = themed_icon_key_new (filename, scale, size); - g_hash_table_insert (themed_icon_cache, key, icon_info); - - g_object_unref (gtkicon_info); + key = themed_icon_key_new (filename, scale, size); + g_hash_table_insert (themed_icon_cache, key, icon_info); + } return g_object_ref (icon_info); } else { - GdkPixbuf *pixbuf; - GtkIconInfo *gtk_icon_info; - - gtk_icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (), - icon, - size, - scale, - GTK_ICON_LOOKUP_FORCE_SIZE); - if (gtk_icon_info != NULL) - { - pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL); - g_object_unref (gtk_icon_info); - } - else - { - pixbuf = NULL; - } - - icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale); - - if (pixbuf != NULL) - { - g_object_unref (pixbuf); - } + g_autoptr (GdkPixbuf) pixbuf = NULL; - return icon_info; + pixbuf = gtk_icon_info_load_icon (gtkicon_info, NULL); + return nautilus_icon_info_new_for_pixbuf (pixbuf, scale); } } |