[Xfce4-commits] <xfce4-panel:devel> Review XfcePanelImage.

Nick Schermer noreply at xfce.org
Sat Jan 23 17:12:02 CET 2010


Updating branch refs/heads/devel
         to 1cbb5eaa1e124d370192ede47744c6f1e359321d (commit)
       from ff44bf446ff3d3a528c4d081879e8f4ac4706784 (commit)

commit 1cbb5eaa1e124d370192ede47744c6f1e359321d
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Jan 23 17:08:59 2010 +0100

    Review XfcePanelImage.

 libxfce4panel/xfce-panel-image.c |   31 ++++++++-----------------------
 1 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/libxfce4panel/xfce-panel-image.c b/libxfce4panel/xfce-panel-image.c
index a929187..a772ddc 100644
--- a/libxfce4panel/xfce-panel-image.c
+++ b/libxfce4panel/xfce-panel-image.c
@@ -54,6 +54,11 @@
 #define XFCE_PANEL_IMAGE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
                                            XFCE_TYPE_PANEL_IMAGE, \
                                            XfcePanelImagePrivate))
+#define xfce_panel_image_unref_null(obj)   G_STMT_START { if ((obj) != NULL) \
+                                             { \
+                                               g_object_unref (G_OBJECT (obj)); \
+                                               (obj) = NULL; \
+                                             } } G_STMT_END
 
 
 
@@ -122,7 +127,6 @@ xfce_panel_image_class_init (XfcePanelImageClass *klass)
   GObjectClass   *gobject_class;
   GtkWidgetClass *gtkwidget_class;
 
-  /* add private data */
   g_type_class_add_private (klass, sizeof (XfcePanelImagePrivate));
 
   gobject_class = G_OBJECT_CLASS (klass);
@@ -179,10 +183,8 @@ xfce_panel_image_init (XfcePanelImage *image)
 {
   GTK_WIDGET_SET_FLAGS (image, GTK_NO_WINDOW);
 
-  /* set private pointer */
   image->priv = XFCE_PANEL_IMAGE_GET_PRIVATE (image);
 
-  /* initialize */
   image->priv->pixbuf = NULL;
   image->priv->cache = NULL;
   image->priv->source = NULL;
@@ -266,7 +268,6 @@ xfce_panel_image_set_property (GObject      *object,
 static void
 xfce_panel_image_finalize (GObject *object)
 {
-  /* cleanup */
   xfce_panel_image_clear (XFCE_PANEL_IMAGE (object));
 
   (*G_OBJECT_CLASS (xfce_panel_image_parent_class)->finalize) (object);
@@ -323,9 +324,7 @@ xfce_panel_image_size_allocate (GtkWidget     *widget,
       priv->height = allocation->height;
 
       /* free cache */
-      if (G_LIKELY (priv->cache != NULL))
-        g_object_unref (G_OBJECT (priv->cache));
-      priv->cache = NULL;
+      xfce_panel_image_unref_null (priv->cache);
 
       if (priv->pixbuf != NULL)
         {
@@ -512,14 +511,12 @@ xfce_panel_image_set_from_pixbuf (XfcePanelImage *image,
   g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
   g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
 
-  /* cleanup */
   xfce_panel_image_clear (image);
 
   /* set the new pixbuf, scale it to the maximum size if needed */
   image->priv->pixbuf = xfce_panel_image_scale_pixbuf (pixbuf,
       MAX_PIXBUF_SIZE, MAX_PIXBUF_SIZE);
 
-  /* queue a resize */
   gtk_widget_queue_resize (GTK_WIDGET (image));
 }
 
@@ -532,13 +529,10 @@ xfce_panel_image_set_from_source (XfcePanelImage *image,
   g_return_if_fail (XFCE_IS_PANEL_IMAGE (image));
   g_return_if_fail (IS_STRING (source));
 
-  /* cleanup */
   xfce_panel_image_clear (image);
 
-  /* set new value */
   image->priv->source = g_strdup (source);
 
-  /* queue a resize */
   gtk_widget_queue_resize (GTK_WIDGET (image));
 }
 
@@ -557,17 +551,8 @@ xfce_panel_image_clear (XfcePanelImage *image)
      priv->source = NULL;
     }
 
-  if (priv->pixbuf != NULL)
-    {
-     g_object_unref (G_OBJECT (priv->pixbuf));
-     priv->pixbuf = NULL;
-    }
-
-  if (priv->cache != NULL)
-    {
-     g_object_unref (G_OBJECT (priv->cache));
-     priv->cache = NULL;
-    }
+  xfce_panel_image_unref_null (priv->pixbuf);
+  xfce_panel_image_unref_null (priv->cache);
 
   /* reset values */
   priv->width = -1;



More information about the Xfce4-commits mailing list