icons: Convert use of load() to download_texture()
authorAlexander Larsson <alexl@redhat.com>
Tue, 28 Jan 2020 09:30:01 +0000 (10:30 +0100)
committerAlexander Larsson <alexl@redhat.com>
Wed, 29 Jan 2020 18:06:16 +0000 (19:06 +0100)
demos/gtk-demo/textview.c
gtk/gtkbuilder.c
gtk/gtkmountoperation.c
gtk/gtkwindow.c
tests/testclipboard2.c
tests/testdnd2.c
testsuite/gtk/icontheme.c

index c28312a517c2a08e4a339eb48221fa4b45c08141..f55fa510e0547c41cdcd6193db111a394fad7609 100644 (file)
@@ -130,13 +130,15 @@ insert_text (GtkTextBuffer *buffer)
   GtkTextIter start, end;
   GdkTexture *texture;
   GtkIconTheme *icon_theme;
+  GtkIconInfo *icon;
 
   icon_theme = gtk_icon_theme_get_default ();
-  texture = GDK_TEXTURE (gtk_icon_theme_load_icon (icon_theme,
-                                                   "gtk3-demo",
-                                                   32,
-                                                   GTK_ICON_LOOKUP_GENERIC_FALLBACK,
-                                                   NULL));
+  icon = gtk_icon_theme_lookup_icon (icon_theme,
+                                     "gtk3-demo",
+                                     32,
+                                     GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+  texture = gtk_icon_info_download_texture (icon, NULL);
+  g_object_unref (icon);
   g_assert (texture);
 
   /* get start of buffer; each insertion will revalidate the
index b98ab3566cd332179000f4c51a72bafd031c31ec..7e962e0b31f67ddb1144b5a088fa745b2d7be3ca 100644 (file)
@@ -2157,7 +2157,8 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
           if (pixbuf == NULL)
             {
               GtkIconTheme *theme;
-              GdkPaintable *texture;
+              GtkIconInfo *icon;
+              GdkTexture *texture;
 
               g_warning ("Could not load image '%s': %s",
                          string, tmp_error->message);
@@ -2165,12 +2166,12 @@ gtk_builder_value_from_string_type (GtkBuilder   *builder,
 
               /* fall back to a missing image */
               theme = gtk_icon_theme_get_default ();
-              texture = gtk_icon_theme_load_icon (theme,
-                                                 "image-missing",
-                                                 16,
-                                                 GTK_ICON_LOOKUP_USE_BUILTIN,
-                                                 NULL);
-              pixbuf = gdk_pixbuf_get_from_texture (GDK_TEXTURE (texture));
+
+              icon = gtk_icon_theme_lookup_icon (theme, "image-missing", 16,
+                                                 GTK_ICON_LOOKUP_USE_BUILTIN);
+              texture = gtk_icon_info_download_texture (icon, NULL);
+              pixbuf = gdk_pixbuf_get_from_texture (texture);
+              g_object_unref (icon);
               g_object_unref (texture);
             }
 
index ebcdba0f2b4d4cb530d35d149a115ffcba015f22..e9981387c5da91b287f74d8a3bd42842d3b68893 100644 (file)
@@ -1175,7 +1175,7 @@ add_pid_to_process_list_store (GtkMountOperation              *mount_operation,
         (_gtk_style_context_peek_property (gtk_widget_get_style_context (GTK_WIDGET (mount_operation->priv->dialog)),
                                            GTK_CSS_PROPERTY_ICON_THEME));
       info = gtk_icon_theme_lookup_icon (theme, "application-x-executable", 24, 0);
-      texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, NULL));
+      texture = gtk_icon_info_download_texture (info, NULL);
       g_object_unref (info);
     }
 
index 8846f57820cf74cf8119b594cd80a419844300ae..6cf0598c154ab46d54055aba2aca4d002ba67935 100644 (file)
@@ -4036,9 +4036,9 @@ icon_list_from_theme (GtkWindow   *window,
                                                     0);
       if (info)
         {
-          GdkPaintable *paintable = gtk_icon_info_load_icon (info, NULL);
-          if (paintable && GDK_IS_TEXTURE (paintable))
-            list = g_list_insert_sorted (list, GDK_TEXTURE (paintable), (GCompareFunc) icon_size_compare);
+          GdkTexture *texture = gtk_icon_info_download_texture (info, NULL);
+          if (texture)
+            list = g_list_insert_sorted (list, texture, (GCompareFunc) icon_size_compare);
 
           g_object_unref (info);
         }
index 432cbfc4bf1085aceead4c1e5f324c8d9e5ed686..c7073bd5ea9c1d0e691cc5c418e951b42751bb1c 100644 (file)
@@ -272,6 +272,8 @@ get_button_list (GdkClipboard *clipboard,
                                          0xc9, 'g', 'a', 'l', 'i', 't', 0xe9, ',', ' ',
                                           'F', 'r', 'a', 't', 'e', 'r', 'n', 'i', 't', 0xe9, 0 };
   GtkWidget *box;
+  GtkIconInfo *icon;
+  GdkTexture *texture;
   GValue value = G_VALUE_INIT;
 
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -284,9 +286,13 @@ get_button_list (GdkClipboard *clipboard,
                        "Empty");
 
   g_value_init (&value, GDK_TYPE_PIXBUF);
-  g_value_take_object (&value, gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                                         "utilities-terminal",
-                                                         48, 0, NULL));
+  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+                                     "utilities-terminal",
+                                     48, 0);
+  texture = gtk_icon_info_download_texture (icon, NULL);
+  g_value_take_object (&value, gdk_pixbuf_get_from_texture (texture));
+  g_object_unref (texture);
+  g_object_unref (icon);
   add_provider_button (box,
                        gdk_content_provider_new_for_value (&value),
                        clipboard,
index ecf5a95551ad167d65e8e67e5dcbccef4016cb73..2b4c5fcb96284fad9d6d96bdb7f55b7bd48f901b 100644 (file)
@@ -1,35 +1,40 @@
 #include <unistd.h>
 #include <gtk/gtk.h>
 
-static GdkPaintable *
-get_image_paintable (GtkImage *image,
-                    int      *out_size)
+static GdkTexture *
+get_image_texture (GtkImage *image,
+                   int      *out_size)
 {
   GtkIconTheme *icon_theme;
   const char *icon_name;
   int width = 48;
   GdkPaintable *paintable;
+  GdkTexture *texture = NULL;
   GtkIconInfo *icon_info;
 
   switch (gtk_image_get_storage_type (image))
     {
     case GTK_IMAGE_PAINTABLE:
       paintable = gtk_image_get_paintable (image);
-      *out_size = gdk_paintable_get_intrinsic_width (paintable);
-      return g_object_ref (paintable);
+      if (GDK_IS_TEXTURE (paintable))
+        {
+          *out_size = gdk_paintable_get_intrinsic_width (paintable);
+          texture = g_object_ref (GDK_TEXTURE (paintable));
+        }
     case GTK_IMAGE_ICON_NAME:
       icon_name = gtk_image_get_icon_name (image);
       icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
       *out_size = width;
       icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, width, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
-      paintable = gtk_icon_info_load_icon (icon_info, NULL);
+      if (icon_info)
+        texture = gtk_icon_info_download_texture (icon_info, NULL);
       g_object_unref (icon_info);
-      return paintable;
     default:
       g_warning ("Image storage type %d not handled",
                  gtk_image_get_storage_type (image));
-      return NULL;
     }
+
+  return texture;
 }
 
 enum {
@@ -44,17 +49,18 @@ image_drag_data_get (GtkWidget        *widget,
                      GtkSelectionData *selection_data,
                      gpointer          data)
 {
-  GdkPaintable *paintable;
+  GdkTexture *texture;
   const gchar *name;
   int size;
 
   if (gtk_selection_data_targets_include_image (selection_data, TRUE))
     {
-      paintable = get_image_paintable (GTK_IMAGE (data), &size);
-      if (GDK_IS_TEXTURE (paintable))
-        gtk_selection_data_set_texture (selection_data, GDK_TEXTURE (paintable));
-      if (paintable)
-        g_object_unref (paintable);
+      texture = get_image_texture (GTK_IMAGE (data), &size);
+      if (texture)
+        {
+          gtk_selection_data_set_texture (selection_data, texture);
+          g_object_unref (texture);
+        }
     }
   else if (gtk_selection_data_targets_include_text (selection_data))
     {
@@ -217,12 +223,12 @@ update_source_icon (GtkDragSource *source,
                     const char *icon_name,
                     int hotspot)
 {
-  GdkPaintable *paintable;
+  GtkIconInfo *icon;
   int hot_x, hot_y;
   int size = 48;
 
-  paintable = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
-                                        icon_name, size, 0, NULL);
+  icon = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (),
+                                     icon_name, size, 0);
   switch (hotspot)
     {
     default:
@@ -239,8 +245,8 @@ update_source_icon (GtkDragSource *source,
       hot_y = size;
       break;
     }
-  gtk_drag_source_set_icon (source, paintable, hot_x, hot_y);
-  g_object_unref (paintable);
+  gtk_drag_source_set_icon (source, GDK_PAINTABLE (icon), hot_x, hot_y);
+  g_object_unref (icon);
 }
 
 static GBytes *
@@ -265,8 +271,8 @@ get_data (const char *mimetype,
   else if (strcmp (mimetype, "image/png") == 0)
     {
       int size;
-      GdkPaintable *paintable = get_image_paintable (GTK_IMAGE (image), &size);
-      if (GDK_IS_TEXTURE (paintable))
+      GdkTexture *texture = get_image_texture (GTK_IMAGE (image), &size);
+      if (texture)
         {
           char *name = g_strdup ("drag-data-XXXXXX");
           int fd;
@@ -278,15 +284,14 @@ get_data (const char *mimetype,
           fd = g_mkstemp (name);
           close (fd);
 
-          gdk_texture_save_to_png (GDK_TEXTURE (paintable), name);
+          gdk_texture_save_to_png (texture, name);
+          g_object_unref (texture);
 
           g_file_get_contents (name, &data, &size, NULL);
           g_free (name);
 
           return g_bytes_new_take (data, size);
         }
-      
-      g_clear_object (&paintable);
     }
   return NULL;
 }
index 0260e1625cbaa44f2367ff24e09e9ba340c26f13..927eab9839bdd37811bac901a09671a109e861f8 100644 (file)
@@ -85,7 +85,7 @@ assert_icon_lookup_size (const char         *icon_name,
       GdkTexture *texture;
       GError *error = NULL;
 
-      texture = GDK_TEXTURE (gtk_icon_info_load_icon (info, &error));
+      texture = gtk_icon_info_download_texture (info, &error);
       g_assert_no_error (error);
       g_assert_cmpint (gdk_texture_get_width (texture), ==, pixbuf_size);
       g_object_unref (texture);