[nautilus/gtk4-preparation-trunk: 80/84] icon-info: Stop using gtk_icon_theme_choose_icon_for_scale()
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk4-preparation-trunk: 80/84] icon-info: Stop using gtk_icon_theme_choose_icon_for_scale()
- Date: Thu, 23 Dec 2021 23:08:39 +0000 (UTC)
commit 400757af10f523f872b27eea1b8d3a4e0234511d
Author: António Fernandes <antoniof gnome org>
Date: Wed Dec 22 21:09:07 2021 +0000
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.
src/nautilus-icon-info.c | 70 ++++++++++++++----------------------------------
1 file changed, 20 insertions(+), 50 deletions(-)
---
diff --git a/src/nautilus-icon-info.c b/src/nautilus-icon-info.c
index c4586da3d..48b18fd0e 100644
--- a/src/nautilus-icon-info.c
+++ b/src/nautilus-icon-info.c
@@ -336,6 +336,8 @@ nautilus_icon_info_lookup (GIcon *icon,
int scale)
{
NautilusIconInfo *icon_info;
+ g_autoptr (GtkIconInfo) gtkicon_info = NULL;
+ GtkIconTheme *icon_theme;
if (G_IS_LOADABLE_ICON (icon))
{
@@ -384,13 +386,19 @@ nautilus_icon_info_lookup (GIcon *icon,
return g_object_ref (icon_info);
}
- else if (G_IS_THEMED_ICON (icon))
+
+ icon_theme = gtk_icon_theme_get_default ();
+ gtkicon_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, 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 +410,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 +422,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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]