icontheme: Add error argument to _load_texture
authorTimm Bäder <mail@baedert.org>
Thu, 29 Aug 2019 15:07:45 +0000 (17:07 +0200)
committerTimm Bäder <mail@baedert.org>
Mon, 9 Sep 2019 15:36:26 +0000 (17:36 +0200)
Loading an icon might fail.

demos/gtk-demo/clipboard.c
gtk/gtkcssimageicontheme.c
gtk/gtkiconhelper.c
gtk/gtkicontheme.c
gtk/gtkicontheme.h
gtk/gtkmountoperation.c
gtk/gtkwindow.c
tests/testdnd2.c
tests/testimage.c

index 36569d8d07f7ec36f9de45b3852f25a1f5178181..9d6b281d7c9d29e7d63ede885c31f9cfbba0051e 100644 (file)
@@ -110,7 +110,7 @@ get_image_paintable (GtkImage *image)
       icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
       if (icon_info == NULL)
         return NULL;
-      return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
+      return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info, NULL));
     default:
       g_warning ("Image storage type %d not handled",
                  gtk_image_get_storage_type (image));
index 582dbfec30b075be02daad8d0333bbe179956906..093b9e901209aa1fe6feb5803cff09afc6d99f9a 100644 (file)
@@ -79,7 +79,7 @@ gtk_css_image_icon_theme_snapshot (GtkCssImage *image,
       g_assert (icon_info != NULL);
 
       symbolic = gtk_icon_info_is_symbolic (icon_info);
-      texture = gtk_icon_info_load_texture (icon_info);
+      texture = gtk_icon_info_load_texture (icon_info, NULL);
 
       g_clear_object (&icon_theme->cached_texture);
 
index 5e96bb8e64a29d3ee072e692ba817e2ec1f88b8f..e6976b3a29316992e99428077a7f35c46f7755e0 100644 (file)
@@ -122,7 +122,7 @@ ensure_paintable_for_gicon (GtkIconHelper    *self,
                                        flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK);
 
   *symbolic = gtk_icon_info_is_symbolic (info);
-  paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (info));
+  paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (info, NULL));
   g_object_unref (info);
 
   if (paintable && scale != 1)
index 8389e4acce829adccba7915dc110eefd9e55a266..48e39683435f1559e40931f1ac00d6d13209e7d0 100644 (file)
@@ -49,6 +49,7 @@
 #include "gtkstylecontextprivate.h"
 #include "gtkprivate.h"
 #include "gdkpixbufutilsprivate.h"
+#include "gdk/gdktextureprivate.h"
 
 /* this is in case round() is not provided by the compiler, 
  * such as in the case of C89 compilers, like MSVC
@@ -3813,24 +3814,52 @@ gtk_icon_info_load_icon (GtkIconInfo *icon_info,
 /**
  * gtk_icon_info_load_texture:
  * @icon_info: a #GtkIconInfo
+ * @error: (nullable): location to store error information on failure,
+ *   or %NULL.
  *
  * Returns a texture object that can be used to render the icon
  * with GSK.
  *
- * Returns: (transfer full): the icon texture; this may be a newly
+ * Returns: (transfer full) (nullable): the icon texture; this may be a newly
  *     created texture or a new reference to an exiting texture. Use
  *     g_object_unref() to release your reference.
+ *     In case of failure, %NULL is returned and @error is set
  */
 GdkTexture *
-gtk_icon_info_load_texture (GtkIconInfo *icon_info)
+gtk_icon_info_load_texture (GtkIconInfo  *icon_info,
+                            GError      **error)
 {
+  g_return_val_if_fail (icon_info != NULL, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
   if (!icon_info->texture)
     {
       GdkPixbuf *pixbuf;
 
       pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
-      icon_info->texture = gdk_texture_new_for_pixbuf (pixbuf);
-      g_object_unref (pixbuf);
+
+      if (!pixbuf)
+        {
+          if (icon_info->load_error)
+            {
+              if (error)
+                *error = g_error_copy (icon_info->load_error);
+            }
+          else
+            {
+              g_set_error_literal (error,
+                                   GTK_ICON_THEME_ERROR,
+                                   GTK_ICON_THEME_NOT_FOUND,
+                                   _("Failed to load icon"));
+            }
+
+          return NULL;
+        }
+      else
+        {
+          icon_info->texture = gdk_texture_new_for_pixbuf (pixbuf);
+          g_object_unref (pixbuf);
+        }
 
       g_object_add_weak_pointer (G_OBJECT (icon_info->texture), (void **)&icon_info->texture);
     }
index de0cd2308de5cb97d70f913022d661d2473160ec..5a98d149a11131aea8e71db5702f3f2a1301c1c2 100644 (file)
@@ -65,7 +65,7 @@ typedef struct _GtkIconTheme        GtkIconTheme;
  *   text direction
  * @GTK_ICON_LOOKUP_DIR_RTL: Try to load a variant of the icon for right-to-left
  *   text direction
- * 
+ *
  * Used to specify options for gtk_icon_theme_lookup_icon()
  */
 typedef enum
@@ -92,7 +92,7 @@ typedef enum
  * GtkIconThemeError:
  * @GTK_ICON_THEME_NOT_FOUND: The icon specified does not exist in the theme
  * @GTK_ICON_THEME_FAILED: An unspecified error occurred.
- * 
+ *
  * Error codes for GtkIconTheme operations.
  **/
 typedef enum {
@@ -225,7 +225,8 @@ GDK_AVAILABLE_IN_ALL
 GdkPixbuf *           gtk_icon_info_load_icon          (GtkIconInfo   *icon_info,
                                                        GError       **error);
 GDK_AVAILABLE_IN_ALL
-GdkTexture *          gtk_icon_info_load_texture       (GtkIconInfo   *icon_info);
+GdkTexture *          gtk_icon_info_load_texture       (GtkIconInfo   *icon_info,
+                                                        GError       **error);
 
 GDK_AVAILABLE_IN_ALL
 void                  gtk_icon_info_load_icon_async   (GtkIconInfo          *icon_info,
index 4ad02628ab4ad4f8131f0e3ffeb35b0cc1cbe12f..f5fab7902907a9c7e7887a33b36cfe32330bd176 100644 (file)
@@ -1171,7 +1171,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 = gtk_icon_info_load_texture (info);
+      texture = gtk_icon_info_load_texture (info, NULL);
       g_object_unref (info);
     }
 
index 5748b278e5ce30578d426ce6c5f90d797e1967b1..513232c3099b05f2e9ece6e5c4746cac7ed05a2a 100644 (file)
@@ -4048,7 +4048,7 @@ icon_list_from_theme (GtkWindow   *window,
                                                     0);
       if (info)
         {
-          list = g_list_insert_sorted (list, gtk_icon_info_load_texture (info), (GCompareFunc) icon_size_compare);
+          list = g_list_insert_sorted (list, gtk_icon_info_load_texture (info, NULL), (GCompareFunc) icon_size_compare);
           g_object_unref (info);
         }
     }
@@ -4126,7 +4126,7 @@ gtk_window_get_icon_for_size (GtkWindow *window,
   if (info == NULL)
     return NULL;
 
-  texture = gtk_icon_info_load_texture (info);
+  texture = gtk_icon_info_load_texture (info, NULL);
   g_object_unref (info);
 
   return texture;
index b94362e57c9704569013c746f477764e8d3f82c0..7df9bb3a903bb100e52d676dbb9e7019a3e9ff00 100644 (file)
@@ -21,7 +21,7 @@ get_image_paintable (GtkImage *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 = GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
+      paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info, NULL));
       g_object_unref (icon_info);
       return paintable;
     default:
index 2e2d5da50b55b2f955758a5b98988b4a1b3e4565..b595cd8f4d477cbc3ee88ceee49b04eeba35a634 100644 (file)
@@ -110,7 +110,7 @@ main (int argc, char **argv)
 
   theme = gtk_icon_theme_get_default ();
   icon_info = gtk_icon_theme_lookup_icon_for_scale (theme, icon_name, 48, gtk_widget_get_scale_factor (window), GTK_ICON_LOOKUP_GENERIC_FALLBACK);
-  texture = gtk_icon_info_load_texture (icon_info);
+  texture = gtk_icon_info_load_texture (icon_info, NULL);
   g_object_unref (icon_info);
   image = gtk_image_new_from_paintable (GDK_PAINTABLE (texture));
   g_object_unref (texture);