gnome-panel r11129 - in trunk/gnome-panel: . libpanel-util
- From: vuntz svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-panel r11129 - in trunk/gnome-panel: . libpanel-util
- Date: Thu, 5 Jun 2008 21:23:30 +0000 (UTC)
Author: vuntz
Date: Thu Jun 5 21:23:30 2008
New Revision: 11129
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=11129&view=rev
Log:
2008-06-05 Vincent Untz <vuntz gnome org>
* libpanel-util/Makefile.am: add new file
* libpanel-util/panel-cleanup.[ch]: small utility API to ease cleanup
when the panel exits
* main.c: (main): use new API
* panel-gconf.c: (panel_gconf_get_client): ditto
Added:
trunk/gnome-panel/libpanel-util/panel-cleanup.c
trunk/gnome-panel/libpanel-util/panel-cleanup.h
Modified:
trunk/gnome-panel/ChangeLog
trunk/gnome-panel/libpanel-util/Makefile.am
trunk/gnome-panel/main.c
trunk/gnome-panel/panel-gconf.c
Modified: trunk/gnome-panel/libpanel-util/Makefile.am
==============================================================================
--- trunk/gnome-panel/libpanel-util/Makefile.am (original)
+++ trunk/gnome-panel/libpanel-util/Makefile.am Thu Jun 5 21:23:30 2008
@@ -20,6 +20,8 @@
noinst_LTLIBRARIES=libpanel-util.la
libpanel_util_la_SOURCES= \
+ panel-cleanup.c \
+ panel-cleanup.h \
panel-keyfile.c \
panel-keyfile.h \
$(NULL)
Added: trunk/gnome-panel/libpanel-util/panel-cleanup.c
==============================================================================
--- (empty file)
+++ trunk/gnome-panel/libpanel-util/panel-cleanup.c Thu Jun 5 21:23:30 2008
@@ -0,0 +1,112 @@
+/*
+ * panel-cleanup.c:
+ *
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ * Vincent Untz <vuntz gnome org>
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "panel-cleanup.h"
+
+typedef struct {
+ PanelCleanFunc func;
+ gpointer data;
+} PanelClean;
+
+static GSList *cleaner;
+
+void
+panel_cleanup_do (void)
+{
+ GSList *l;
+
+ if (!cleaner)
+ return;
+
+ for (l = cleaner; l; l = l->next) {
+ PanelClean *clean;
+
+ clean = l->data;
+ clean->func (clean->data);
+ g_slice_free (PanelClean, clean);
+ }
+
+ g_slist_free (cleaner);
+ cleaner = NULL;
+}
+
+void
+panel_cleanup_register (PanelCleanFunc func,
+ gpointer data)
+{
+ PanelClean *clean;
+
+ g_return_if_fail (func != NULL);
+ g_return_if_fail (data != NULL);
+
+ clean = g_slice_new (PanelClean);
+ clean->func = func;
+ clean->data = data;
+
+ cleaner = g_slist_prepend (cleaner, clean);
+}
+
+void
+panel_cleanup_unregister (PanelCleanFunc func,
+ gpointer data)
+{
+ GSList *l, *next;
+ PanelClean *clean;
+
+ g_return_if_fail (func != NULL);
+ g_return_if_fail (data != NULL);
+
+ if (!cleaner)
+ return;
+
+ l = cleaner;
+
+ do {
+ next = l->next;
+
+ clean = l->data;
+ if (clean->func == func && clean->data == data) {
+ g_slice_free (PanelClean, clean);
+ cleaner = g_slist_delete_link (cleaner, l);
+ }
+
+ l = next;
+ } while (l);
+}
+
+void
+panel_cleanup_unref_and_nullify (gpointer data)
+{
+ GObject **obj;
+
+ g_return_if_fail (data != NULL);
+
+ obj = data;
+
+ g_object_unref (*obj);
+ *obj = NULL;
+}
Added: trunk/gnome-panel/libpanel-util/panel-cleanup.h
==============================================================================
--- (empty file)
+++ trunk/gnome-panel/libpanel-util/panel-cleanup.h Thu Jun 5 21:23:30 2008
@@ -0,0 +1,47 @@
+/*
+ * panel-cleanup.h:
+ *
+ * Copyright (C) 2008 Novell, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ * Vincent Untz <vuntz gnome org>
+ */
+
+#ifndef PANEL_CLEANUP_H
+#define PANEL_CLEANUP_H
+
+#include "glib.h"
+
+G_BEGIN_DECLS
+
+#define PANEL_CLEAN_FUNC(f) ((PanelCleanFunc) (f))
+
+typedef void (*PanelCleanFunc) (gpointer data);
+
+void panel_cleanup_unref_and_nullify (gpointer data);
+
+void panel_cleanup_do (void);
+
+void panel_cleanup_register (PanelCleanFunc func,
+ gpointer data);
+void panel_cleanup_unregister (PanelCleanFunc func,
+ gpointer data);
+
+G_END_DECLS
+
+#endif /* PANEL_CLEANUP_H */
Modified: trunk/gnome-panel/main.c
==============================================================================
--- trunk/gnome-panel/main.c (original)
+++ trunk/gnome-panel/main.c Thu Jun 5 21:23:30 2008
@@ -16,6 +16,8 @@
#include <libgnomeui/gnome-authentication-manager.h>
#include <libgnomeui/gnome-ui-init.h>
+#include <libpanel-util/panel-cleanup.h>
+
#include "panel-gconf.h"
#include "panel-profile.h"
#include "panel-config-global.h"
@@ -62,11 +64,14 @@
GNOME_PARAM_GOPTION_CONTEXT, context,
GNOME_PROGRAM_STANDARD_PROPERTIES,
NULL);
+ panel_cleanup_register (PANEL_CLEAN_FUNC (g_object_unref), program);
gtk_window_set_default_icon_name (PANEL_ICON_PANEL);
- if (!panel_shell_register ())
+ if (!panel_shell_register ()) {
+ panel_cleanup_do ();
return -1;
+ }
gnome_authentication_manager_init ();
@@ -100,7 +105,7 @@
"/desktop/gnome/interface",
NULL);
- g_object_unref (program);
+ panel_cleanup_do ();
return 0;
}
Modified: trunk/gnome-panel/panel-gconf.c
==============================================================================
--- trunk/gnome-panel/panel-gconf.c (original)
+++ trunk/gnome-panel/panel-gconf.c Thu Jun 5 21:23:30 2008
@@ -31,6 +31,8 @@
#include <glib.h>
#include <gconf/gconf-client.h>
+#include <libpanel-util/panel-cleanup.h>
+
#undef PANEL_GCONF_DEBUG
GConfClient *
@@ -38,8 +40,11 @@
{
static GConfClient *panel_gconf_client = NULL;
- if (!panel_gconf_client)
+ if (!panel_gconf_client) {
panel_gconf_client = gconf_client_get_default ();
+ panel_cleanup_register (panel_cleanup_unref_and_nullify,
+ &panel_gconf_client);
+ }
return panel_gconf_client;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]