[Xfce4-commits] <xfce4-panel:devel> Put some xfconf code in a macro to make things easier.

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


Updating branch refs/heads/devel
         to 39cd63f0ae2a0a23b7ff9e7155e15429f35ac173 (commit)
       from 7a8c404c28862f7d0cc5c61fa3d0861ef65683cc (commit)

commit 39cd63f0ae2a0a23b7ff9e7155e15429f35ac173
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Jun 7 22:03:01 2009 +0200

    Put some xfconf code in a macro to make things easier.

 common/panel-xfconf.c           |   10 ++++++++++
 common/panel-xfconf.h           |   20 ++++++++++++++++++++
 plugins/actions/actions.c       |   18 +++---------------
 plugins/clock/Makefile.am       |    4 +++-
 plugins/clock/clock.c           |    8 +++-----
 plugins/launcher/launcher.c     |    7 ++-----
 plugins/pager/pager.c           |   10 +++-------
 plugins/separator/separator.c   |   18 +++---------------
 plugins/systray/systray.c       |    8 ++------
 plugins/tasklist/tasklist.c     |   16 ++--------------
 plugins/windowmenu/windowmenu.c |    5 ++---
 11 files changed, 53 insertions(+), 71 deletions(-)

diff --git a/common/panel-xfconf.c b/common/panel-xfconf.c
index cf3855e..1929eb6 100644
--- a/common/panel-xfconf.c
+++ b/common/panel-xfconf.c
@@ -302,3 +302,13 @@ panel_properties_shared_hash_table (GHashTable *hash_table)
   else
     shared_hash_table = NULL;
 }
+
+
+
+void
+panel_properties_shutdown (gpointer  user_data,
+                           GObject  *where_the_object_was)
+{
+  /* delay this a bit to avoid warnings */
+  g_idle_add ((GSourceFunc) xfconf_shutdown, NULL);
+}
diff --git a/common/panel-xfconf.h b/common/panel-xfconf.h
index 6d75660..083450a 100644
--- a/common/panel-xfconf.h
+++ b/common/panel-xfconf.h
@@ -22,6 +22,21 @@
 
 #include <xfconf/xfconf.h>
 
+#define PANEL_PROPERTIES_INIT(panel_plugin) do { \
+  GError *__err = NULL; \
+  if (G_LIKELY (xfconf_init (&__err))) \
+    { \
+      g_object_weak_ref (G_OBJECT (panel_plugin), \
+          panel_properties_shutdown, NULL); \
+    } \
+  else \
+    { \
+      g_critical ("Failed to initialize Xfconf: %s", __err->message); \
+      g_error_free (__err); \
+    } } while (0)
+
+
+
 typedef struct _PanelProperty PanelProperty;
 struct _PanelProperty
 {
@@ -29,6 +44,8 @@ struct _PanelProperty
   GType        type;
 };
 
+
+
 XfconfChannel *panel_properties_get_channel       (void);
 
 void           panel_properties_bind              (XfconfChannel       *channel,
@@ -41,4 +58,7 @@ void           panel_properties_unbind            (GObject             *object);
 
 void           panel_properties_shared_hash_table (GHashTable          *hash_table);
 
+void           panel_properties_shutdown          (gpointer             user_data,
+                                                   GObject             *where_the_object_was);
+
 #endif /* !__PANEL_XFCONF_H__ */
diff --git a/plugins/actions/actions.c b/plugins/actions/actions.c
index c9e387c..9690dc9 100644
--- a/plugins/actions/actions.c
+++ b/plugins/actions/actions.c
@@ -26,7 +26,6 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <common/panel-xfconf.h>
-#include <xfconf/xfconf.h>
 #include <exo/exo.h>
 
 #include "actions.h"
@@ -43,7 +42,6 @@ static void     actions_plugin_set_property        (GObject               *objec
                                                     const GValue          *value,
                                                     GParamSpec            *pspec);
 static void     actions_plugin_construct           (XfcePanelPlugin       *panel_plugin);
-static void     actions_plugin_free_data           (XfcePanelPlugin       *panel_plugin);
 static gboolean actions_plugin_size_changed        (XfcePanelPlugin       *panel_plugin,
                                                     gint                   size);
 static void     actions_plugin_configure_plugin    (XfcePanelPlugin       *panel_plugin);
@@ -146,7 +144,6 @@ actions_plugin_class_init (ActionsPluginClass *klass)
 
   plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
   plugin_class->construct = actions_plugin_construct;
-  plugin_class->free_data = actions_plugin_free_data;
   plugin_class->size_changed = actions_plugin_size_changed;
   plugin_class->configure_plugin = actions_plugin_configure_plugin;
   plugin_class->orientation_changed = actions_plugin_orientation_changed;
@@ -182,12 +179,12 @@ actions_plugin_init (ActionsPlugin *plugin)
   plugin->first_action = ACTION_LOG_OUT_DIALOG;
   plugin->second_action = ACTION_DISABLED;
 
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
+
   /* show the properties dialog */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
-
   plugin->box = xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, TRUE, 0);
   gtk_container_add (GTK_CONTAINER (plugin), plugin->box);
 
@@ -322,15 +319,6 @@ actions_plugin_construct (XfcePanelPlugin *panel_plugin)
 
 
 
-static void
-actions_plugin_free_data (XfcePanelPlugin *panel_plugin)
-{
-  /* shutdown xfconf */
-  xfconf_shutdown ();
-}
-
-
-
 static gboolean
 actions_plugin_size_changed (XfcePanelPlugin *panel_plugin,
                              gint             size)
diff --git a/plugins/clock/Makefile.am b/plugins/clock/Makefile.am
index 2287640..b288fd3 100644
--- a/plugins/clock/Makefile.am
+++ b/plugins/clock/Makefile.am
@@ -45,6 +45,7 @@ libclock_la_LDFLAGS =	 \
 
 libclock_la_LIBADD = \
 	$(top_builddir)/libxfce4panel/libxfce4panel.la \
+	$(top_builddir)/common/libpanel-xfconf.la \
 	$(GTK_LIBS) \
 	$(CAIRO_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
@@ -52,7 +53,8 @@ libclock_la_LIBADD = \
 	$(XFCONF_LIBS)
 
 libclock_la_DEPENDENCIES = \
-	$(top_builddir)/libxfce4panel/libxfce4panel.la
+	$(top_builddir)/libxfce4panel/libxfce4panel.la \
+	$(top_builddir)/common/libpanel-xfconf.la
 
 #
 # .desktop file
diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index 5df468c..af7f432 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -30,6 +30,7 @@
 #include <libxfce4panel/libxfce4panel.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <xfconf/xfconf.h>
+#include <common/panel-xfconf.h>
 
 #include "clock.h"
 #include "clock-analog.h"
@@ -161,8 +162,8 @@ clock_plugin_init (ClockPlugin *plugin)
   plugin->tooltip_interval = 0;
   plugin->clock_timeout_id = 0;
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
 
   /* show configure */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
@@ -260,9 +261,6 @@ clock_plugin_free_data (XfcePanelPlugin *panel_plugin)
 
   /* free the tooltip string */
   g_free (plugin->tooltip_format);
-
-  /* shutdown xfconf */
-  xfconf_shutdown ();
 }
 
 
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 842adf8..bb74ff9 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -246,8 +246,8 @@ launcher_plugin_init (LauncherPlugin *plugin)
   plugin->menu_timeout_id = 0;
   plugin->menu_icon_size = DEFAULT_MENU_ICON_SIZE;
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
 
   /* show the configure menu item */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
@@ -599,9 +599,6 @@ launcher_plugin_free_data (XfcePanelPlugin *panel_plugin)
   /* destroy the menu and timeout */
   launcher_plugin_menu_destroy (plugin);
 
-  /* shutdown xfconf */
-  xfconf_shutdown ();
-
   /* free items */
   g_slist_foreach (plugin->items, (GFunc) g_object_unref, NULL);
   g_slist_free (plugin->items);
diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
index 78f80df..74a7d24 100644
--- a/plugins/pager/pager.c
+++ b/plugins/pager/pager.c
@@ -27,7 +27,6 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <common/panel-xfconf.h>
-#include <xfconf/xfconf.h>
 #include <libwnck/libwnck.h>
 #include <exo/exo.h>
 
@@ -150,11 +149,11 @@ pager_plugin_init (PagerPlugin *plugin)
   plugin->rows = 1;
   plugin->wnck_pager = NULL;
 
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
+
   /* show the properties dialog */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
-
-  /* initialize xfconf */
-  xfconf_init (NULL);
 }
 
 
@@ -335,9 +334,6 @@ pager_plugin_free_data (XfcePanelPlugin *panel_plugin)
   /* disconnect screen changed signal */
   g_signal_handlers_disconnect_by_func (G_OBJECT (plugin),
       pager_plugin_screen_changed, NULL);
-
-  /* shutdown xfconf */
-  xfconf_shutdown ();
 }
 
 
diff --git a/plugins/separator/separator.c b/plugins/separator/separator.c
index 9c73680..c943e5a 100644
--- a/plugins/separator/separator.c
+++ b/plugins/separator/separator.c
@@ -26,7 +26,6 @@
 #include <libxfce4panel/libxfce4panel.h>
 #include <libxfce4util/libxfce4util.h>
 #include <common/panel-xfconf.h>
-#include <xfconf/xfconf.h>
 #include <exo/exo.h>
 
 #include "separator.h"
@@ -49,7 +48,6 @@ static void     separator_plugin_set_property              (GObject
 static gboolean separator_plugin_expose_event              (GtkWidget             *widget,
                                                             GdkEventExpose        *event);
 static void     separator_plugin_construct                 (XfcePanelPlugin       *panel_plugin);
-static void     separator_plugin_free_data                 (XfcePanelPlugin       *panel_plugin);
 static gboolean separator_plugin_size_changed              (XfcePanelPlugin       *panel_plugin,
                                                             gint                   size);
 static void     separator_plugin_configure_plugin          (XfcePanelPlugin       *panel_plugin);
@@ -111,7 +109,6 @@ separator_plugin_class_init (SeparatorPluginClass *klass)
 
   plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
   plugin_class->construct = separator_plugin_construct;
-  plugin_class->free_data = separator_plugin_free_data;
   plugin_class->size_changed = separator_plugin_size_changed;
   plugin_class->configure_plugin = separator_plugin_configure_plugin;
   plugin_class->orientation_changed = separator_plugin_orientation_changed;
@@ -141,11 +138,11 @@ separator_plugin_init (SeparatorPlugin *plugin)
   /* initialize */
   plugin->style = SEPARATOR_PLUGIN_STYLE_SEPARATOR;
 
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
+
   /* show the properties dialog */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
-
-  /* initialize xfconf */
-  xfconf_init (NULL);
 }
 
 
@@ -291,15 +288,6 @@ separator_plugin_construct (XfcePanelPlugin *panel_plugin)
 
 
 
-static void
-separator_plugin_free_data (XfcePanelPlugin *panel_plugin)
-{
-  /* shutdown xfconf */
-  xfconf_shutdown ();
-}
-
-
-
 static gboolean
 separator_plugin_size_changed (XfcePanelPlugin *panel_plugin,
                                gint             size)
diff --git a/plugins/systray/systray.c b/plugins/systray/systray.c
index 3a22d90..c83ff52 100644
--- a/plugins/systray/systray.c
+++ b/plugins/systray/systray.c
@@ -26,7 +26,6 @@
 #include <libxfce4ui/libxfce4ui.h>
 #include <common/panel-private.h>
 #include <common/panel-xfconf.h>
-#include <xfconf/xfconf.h>
 #include <exo/exo.h>
 
 #include "systray.h"
@@ -156,8 +155,8 @@ systray_plugin_init (SystrayPlugin *plugin)
   plugin->manager = NULL;
   plugin->show_frame = FALSE;
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
 
   /* show configure */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
@@ -329,9 +328,6 @@ systray_plugin_free_data (XfcePanelPlugin *panel_plugin)
   /* release the manager */
   if (G_LIKELY (plugin->manager))
     g_object_unref (G_OBJECT (plugin->manager));
-
-  /* shutdown xfconf */
-  xfconf_shutdown ();
 }
 
 
diff --git a/plugins/tasklist/tasklist.c b/plugins/tasklist/tasklist.c
index 2609dea..7aa99e7 100644
--- a/plugins/tasklist/tasklist.c
+++ b/plugins/tasklist/tasklist.c
@@ -21,7 +21,6 @@
 #include <config.h>
 #endif
 
-#include <xfconf/xfconf.h>
 #include <exo/exo.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <common/panel-xfconf.h>
@@ -60,7 +59,6 @@ struct _TasklistPlugin
 
 
 static void tasklist_plugin_construct (XfcePanelPlugin *panel_plugin);
-static void tasklist_plugin_free_data (XfcePanelPlugin *panel_plugin);
 static void tasklist_plugin_orientation_changed (XfcePanelPlugin *panel_plugin, GtkOrientation orientation);
 static gboolean tasklist_plugin_size_changed (XfcePanelPlugin *panel_plugin, gint size);
 static void tasklist_plugin_configure_plugin (XfcePanelPlugin *panel_plugin);
@@ -80,7 +78,6 @@ tasklist_plugin_class_init (TasklistPluginClass *klass)
 
   plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
   plugin_class->construct = tasklist_plugin_construct;
-  plugin_class->free_data = tasklist_plugin_free_data;
   plugin_class->orientation_changed = tasklist_plugin_orientation_changed;
   plugin_class->size_changed = tasklist_plugin_size_changed;
   plugin_class->configure_plugin = tasklist_plugin_configure_plugin;
@@ -93,8 +90,8 @@ tasklist_plugin_init (TasklistPlugin *plugin)
 {
   GtkWidget *box;
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
 
   /* show configure */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
@@ -153,15 +150,6 @@ tasklist_plugin_construct (XfcePanelPlugin *panel_plugin)
 
 
 static void
-tasklist_plugin_free_data (XfcePanelPlugin *panel_plugin)
-{
-  /* shutdown xfconf */
-  xfconf_shutdown ();
-}
-
-
-
-static void
 tasklist_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
                                      GtkOrientation   orientation)
 {
diff --git a/plugins/windowmenu/windowmenu.c b/plugins/windowmenu/windowmenu.c
index fda591b..4726fd8 100644
--- a/plugins/windowmenu/windowmenu.c
+++ b/plugins/windowmenu/windowmenu.c
@@ -21,7 +21,6 @@
 #include <config.h>
 #endif
 
-#include <xfconf/xfconf.h>
 #include <exo/exo.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4panel/libxfce4panel.h>
@@ -202,8 +201,8 @@ window_menu_plugin_init (WindowMenuPlugin *plugin)
   plugin->all_workspaces = TRUE;
   plugin->urgent_windows = 0;
 
-  /* initialize xfconf */
-  xfconf_init (NULL);
+  /* initialize properties */
+  PANEL_PROPERTIES_INIT (plugin);
 
   /* show configure */
   xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));



More information about the Xfce4-commits mailing list