[gtk+] gtkimage: Add GtkImage::resource property



commit 86f024ba0dda1c18ef45af923e5b742b193b4da1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jan 24 17:09:51 2013 -0500

    gtkimage: Add GtkImage::resource property
    
    This is designed for GtkBuilder scenarios:
    
        <object class="GtkImage" id="blah">
            <property name="resource">/org/myapp/blah.png</property>
        </object>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692481

 gtk/gtkimage.c |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 5e6458c..5b0ae66 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -139,6 +139,7 @@ struct _GtkImagePrivate
   GdkPixbufAnimationIter *animation_iter;
 
   gchar                *filename;       /* Only used with GTK_IMAGE_ANIMATION, GTK_IMAGE_PIXBUF */
+  gchar                *resource_path;  /* Only used with GTK_IMAGE_PIXBUF */
 };
 
 
@@ -184,6 +185,7 @@ enum
   PROP_ICON_NAME,
   PROP_STORAGE_TYPE,
   PROP_GICON,
+  PROP_RESOURCE,
   PROP_USE_FALLBACK
 };
 
@@ -309,7 +311,22 @@ gtk_image_class_init (GtkImageClass *class)
                                                         P_("The GIcon being displayed"),
                                                         G_TYPE_ICON,
                                                         GTK_PARAM_READWRITE));
-  
+
+  /**
+   * GtkImage:resource:
+   *
+   * A path to a resource file to display.
+   *
+   * Since: 3.8
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_RESOURCE,
+                                   g_param_spec_string ("resource",
+                                                        P_("Resource"),
+                                                        P_("The resource path being displayed"),
+                                                        NULL,
+                                                        GTK_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
                                    PROP_STORAGE_TYPE,
                                    g_param_spec_enum ("storage-type",
@@ -418,6 +435,9 @@ gtk_image_set_property (GObject      *object,
       gtk_image_set_from_gicon (image, g_value_get_object (value),
 				icon_size);
       break;
+    case PROP_RESOURCE:
+      gtk_image_set_from_resource (image, g_value_get_string (value));
+      break;
 
     case PROP_USE_FALLBACK:
       _gtk_icon_helper_set_use_fallback (priv->icon_helper, g_value_get_boolean (value));
@@ -467,6 +487,9 @@ gtk_image_get_property (GObject     *object,
     case PROP_GICON:
       g_value_set_object (value, _gtk_icon_helper_peek_gicon (priv->icon_helper));
       break;
+    case PROP_RESOURCE:
+      g_value_set_string (value, priv->resource_path);
+      break;
     case PROP_USE_FALLBACK:
       g_value_set_boolean (value, _gtk_icon_helper_get_use_fallback (priv->icon_helper));
       break;
@@ -791,11 +814,14 @@ void
 gtk_image_set_from_resource (GtkImage    *image,
 			     const gchar *resource_path)
 {
+  GtkImagePrivate *priv;
   GdkPixbuf *pixbuf = NULL;
   GInputStream *stream;
 
   g_return_if_fail (GTK_IS_IMAGE (image));
 
+  priv = image->priv;
+
   g_object_freeze_notify (G_OBJECT (image));
 
   gtk_image_clear (image);
@@ -822,8 +848,12 @@ gtk_image_set_from_resource (GtkImage    *image,
       return;
     }
 
+  priv->resource_path = g_strdup (resource_path);
+
   gtk_image_set_from_pixbuf (image, pixbuf);
 
+  g_object_notify (G_OBJECT (image), "resource");
+
   g_object_unref (pixbuf);
 
   g_object_thaw_notify (G_OBJECT (image));
@@ -1468,6 +1498,13 @@ gtk_image_reset (GtkImage *image)
       g_object_notify (G_OBJECT (image), "file");
     }
 
+  if (priv->resource_path)
+    {
+      g_free (priv->resource_path);
+      priv->resource_path = NULL;
+      g_object_notify (G_OBJECT (image), "resource");
+    }
+
   _gtk_icon_helper_clear (priv->icon_helper);
 
   g_object_thaw_notify (G_OBJECT (image));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]