[Xfce4-commits] <xfce4-panel:devel> * Add construct function call in the class for object orientent plugin (try 2). * Don't run FREE_DATA in dispose twice. * Add macro to regiter an object orientent plugin.

Nick Schermer nick at xfce.org
Tue Aug 11 20:24:20 CEST 2009


Updating branch refs/heads/devel
         to 2f6a975ffe9f9244b18d2b1aa4011c5eebacdc0f (commit)
       from c7e062e292f8fb80246c82dee89c6213881d6464 (commit)

commit 2f6a975ffe9f9244b18d2b1aa4011c5eebacdc0f
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Oct 5 22:06:37 2008 +0200

    * Add construct function call in the class for object orientent plugin (try 2).
    * Don't run FREE_DATA in dispose twice.
    * Add macro to regiter an object orientent plugin.

 libxfce4panel/libxfce4panel.h     |   35 +++++++++++++++++++++++++++--------
 libxfce4panel/xfce-panel-plugin.c |   34 ++++++++++++++++++++++++++++++++--
 libxfce4panel/xfce-panel-plugin.h |    3 +++
 3 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/libxfce4panel/libxfce4panel.h b/libxfce4panel/libxfce4panel.h
index 0a01b70..53efc92 100644
--- a/libxfce4panel/libxfce4panel.h
+++ b/libxfce4panel/libxfce4panel.h
@@ -34,6 +34,25 @@ G_BEGIN_DECLS
 
 #undef LIBXFCE4PANEL_INSIDE_LIBXFCE4PANEL_H
 
+#define XFCE_PANEL_PLUGIN_REGISTER_OBJECT(TYPE) \
+  PANEL_SYMBOL_EXPORT G_MODULE_EXPORT XfcePanelPlugin * \
+  __xpp_construct_obj (const gchar  *name, \
+                       const gchar  *id, \
+                       const gchar  *display_name, \
+                       gchar       **arguments, \
+                       GdkScreen    *screen) \
+  { \
+    panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); \
+    panel_return_val_if_fail (name != NULL && id != NULL, NULL); \
+    panel_return_val_if_fail (g_type_is_a (TYPE, XFCE_TYPE_PANEL_PLUGIN), NULL); \
+    \
+    return g_object_new (TYPE, \
+                         "name", name, \
+                         "id", id, \
+                         "display-name", display_name, \
+                         "arguments", arguments, NULL); \
+  }
+
 #define XFCE_PANEL_PLUGIN_REGISTER(init_func) \
   XFCE_PANEL_PLUGIN_REGISTER_EXTENDED (init_func, {})
 
@@ -42,21 +61,21 @@ G_BEGIN_DECLS
 
 #define XFCE_PANEL_PLUGIN_REGISTER_EXTENDED(construct_func, CODE) \
   static void \
-  xfce_panel_plugin_realize (XfcePanelPlugin *plugin) \
+  __xpp_realize (XfcePanelPlugin *plugin) \
   { \
     panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin)); \
     \
-    g_signal_handlers_disconnect_by_func (G_OBJECT (plugin), G_CALLBACK (xfce_panel_plugin_realize), NULL); \
+    g_signal_handlers_disconnect_by_func (G_OBJECT (plugin), G_CALLBACK (__xpp_realize), NULL); \
     \
     (*construct_func) (plugin); \
   } \
   \
   PANEL_SYMBOL_EXPORT G_MODULE_EXPORT XfcePanelPlugin * \
-  xfce_panel_plugin_construct (const gchar  *name, \
-                               const gchar  *id, \
-                               const gchar  *display_name, \
-                               gchar       **arguments, \
-                               GdkScreen    *screen) \
+  __xpp_construct (const gchar  *name, \
+                   const gchar  *id, \
+                   const gchar  *display_name, \
+                   gchar       **arguments, \
+                   GdkScreen    *screen) \
   { \
     XfcePanelPlugin *plugin = NULL; \
     \
@@ -71,7 +90,7 @@ G_BEGIN_DECLS
                                "display-name", display_name, \
                                "arguments", arguments, NULL); \
         \
-        g_signal_connect_after (G_OBJECT (plugin), "realize", G_CALLBACK (xfce_panel_plugin_realize), NULL); \
+        g_signal_connect_after (G_OBJECT (plugin), "realize", G_CALLBACK (__xpp_realize), NULL); \
       } \
     \
     return plugin; \
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index df6b368..f4f10f8 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -39,6 +39,7 @@ typedef const gchar *(*ProviderToPlugin) (XfcePanelPluginProvider *provider);
 static void         xfce_panel_plugin_class_init             (XfcePanelPluginClass         *klass);
 static void         xfce_panel_plugin_init                   (XfcePanelPlugin              *plugin);
 static void         xfce_panel_plugin_provider_init          (XfcePanelPluginProviderIface *iface);
+static void         xfce_panel_plugin_constructed            (GObject                      *object);
 static void         xfce_panel_plugin_get_property           (GObject                      *object,
                                                               guint                         prop_id,
                                                               GValue                       *value,
@@ -106,6 +107,9 @@ struct _XfcePanelPluginPrivate
   GtkOrientation       orientation;
   XfceScreenPosition   screen_position;
 
+  /* prevent free_data in dispose from running twice */
+  guint                disposed : 1;
+
   /* plugin menu */
   GtkMenu             *menu;
 
@@ -136,7 +140,11 @@ xfce_panel_plugin_class_init (XfcePanelPluginClass *klass)
   /* add private data */
   g_type_class_add_private (klass, sizeof (XfcePanelPluginPrivate));
 
+  /* reset class contruct function */
+  klass->construct = NULL;
+
   gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->constructed = xfce_panel_plugin_constructed;
   gobject_class->get_property = xfce_panel_plugin_get_property;
   gobject_class->set_property = xfce_panel_plugin_set_property;
   gobject_class->dispose = xfce_panel_plugin_dispose;
@@ -373,6 +381,7 @@ xfce_panel_plugin_init (XfcePanelPlugin *plugin)
   plugin->priv->menu = NULL;
   plugin->priv->menu_blocked = 0;
   plugin->priv->registered_menus = 0;
+  plugin->priv->disposed = FALSE;
 
   /* hide the event box window to make the plugin transparent */
   gtk_event_box_set_visible_window (GTK_EVENT_BOX (plugin), FALSE);
@@ -394,6 +403,19 @@ xfce_panel_plugin_provider_init (XfcePanelPluginProviderIface *iface)
 
 
 static void
+xfce_panel_plugin_constructed (GObject *object)
+{
+  XfcePanelPluginClass *klass = XFCE_PANEL_PLUGIN_GET_CLASS (object);
+
+  /* check if there is a construct class attached to this plugin,
+   * if there is, execute it */
+  if (klass->construct != NULL)
+    (*klass->construct) (XFCE_PANEL_PLUGIN (object));
+}
+
+
+
+static void
 xfce_panel_plugin_get_property (GObject    *object,
                                 guint       prop_id,
                                 GValue     *value,
@@ -464,8 +486,16 @@ xfce_panel_plugin_set_property (GObject      *object,
 static void
 xfce_panel_plugin_dispose (GObject *object)
 {
-  /* allow the plugin to cleanup */
-  g_signal_emit (G_OBJECT (object), plugin_signals[FREE_DATA], 0);
+  XfcePanelPlugin *plugin = XFCE_PANEL_PLUGIN (object);
+
+  if (plugin->priv->disposed == FALSE)
+    {
+      /* allow the plugin to cleanup */
+      g_signal_emit (G_OBJECT (object), plugin_signals[FREE_DATA], 0);
+
+      /* plugin disposed, don't try this again */
+      plugin->priv->disposed = TRUE;
+    }
 
   (*G_OBJECT_CLASS (xfce_panel_plugin_parent_class)->dispose) (object);
 }
diff --git a/libxfce4panel/xfce-panel-plugin.h b/libxfce4panel/xfce-panel-plugin.h
index dc6bab8..b686296 100644
--- a/libxfce4panel/xfce-panel-plugin.h
+++ b/libxfce4panel/xfce-panel-plugin.h
@@ -44,6 +44,9 @@ struct _XfcePanelPluginClass
   /*< private >*/
   GtkEventBoxClass __parent__;
 
+  /*< object oriented plugins >*/
+  void     (*construct)               (XfcePanelPlugin *plugin);
+
   /*< signals >*/
   void     (*screen_position_changed) (XfcePanelPlugin *plugin,
                                        gint             position);



More information about the Xfce4-commits mailing list