[Gnucash-changes] Add infrastructure for plugins to easily request notification of changes

David Hampton hampton at cvs.gnucash.org
Sun Apr 24 18:24:41 EDT 2005


Log Message:
-----------
Add infrastructure for plugins to easily request notification of
changes to gconf for a specific section of gnucash variables.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash/src/gnome:
        gnc-plugin.c
        gnc-plugin.h

Revision Data
-------------
Index: gnc-plugin.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin.h,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -Lsrc/gnome/gnc-plugin.h -Lsrc/gnome/gnc-plugin.h -u -r1.1.2.7 -r1.1.2.8
--- src/gnome/gnc-plugin.h
+++ src/gnome/gnc-plugin.h
@@ -27,6 +27,7 @@
 
 #include "gnc-main-window.h"
 #include "gnc-plugin-page.h"
+#include <gconf/gconf-client.h>
 
 G_BEGIN_DECLS
 
@@ -44,8 +45,6 @@
 typedef struct {
 	GObject parent;
 	GncPluginPrivate *priv;
-
-	GncMainWindow *window;
 } GncPlugin;
 
 typedef struct {
@@ -56,7 +55,10 @@
 	GtkActionEntry *actions;
 	guint n_actions; 
 	const gchar *ui_filename;
- 
+
+	const gchar* gconf_section;
+	void (* gconf_notifications) (GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data);
+
 	/* Virtual Table */
 	void (* add_to_window) (GncPlugin *plugin, GncMainWindow *window, GQuark type);
 	void (* remove_from_window) (GncPlugin *plugin, GncMainWindow *window, GQuark type);
Index: gnc-plugin.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome/Attic/gnc-plugin.c,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -Lsrc/gnome/gnc-plugin.c -Lsrc/gnome/gnc-plugin.c -u -r1.1.2.8 -r1.1.2.9
--- src/gnome/gnc-plugin.c
+++ src/gnome/gnc-plugin.c
@@ -26,6 +26,7 @@
 
 #include "gnc-plugin.h"
 #include "gnc-trace.h"
+#include "gnc-gconf-utils.h"
 
 static gpointer parent_class = NULL;
 static short module = MOD_GUI;
@@ -79,8 +80,6 @@
 	GncPluginPrivate *priv;
 
 	priv = plugin_page->priv = g_new0 (GncPluginPrivate, 1);
-
-	plugin_page->window      = NULL;
 }
 
 static void
@@ -107,19 +106,38 @@
 	GncPluginClass *class;
 
 	g_return_if_fail (GNC_IS_PLUGIN (plugin));
-	ENTER (""); 
 	class = GNC_PLUGIN_GET_CLASS (plugin);
-	plugin->window = window;
+	ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
+	       plugin, window);
+
+	/*
+	 * Update window with additional UI items
+	 */
 	if (class->actions_name) {
+	  DEBUG ("%s: %d actions to merge with gui from %s",
+		 class->actions_name, class->n_actions, class->ui_filename);
 	  gnc_main_window_merge_actions (window, class->actions_name,
 					 class->actions, class->n_actions,
 					 class->ui_filename, plugin);
 	}
 
+	/*
+	 * Setup gconf notifications if requested
+	 */
+	if (class->gconf_section && class->gconf_notifications) {
+	  DEBUG ("Requesting notification for section %s", class->gconf_section);
+	  gnc_gconf_add_notification(G_OBJECT(window), class->gconf_section,
+				     class->gconf_notifications);
+	}
+
+	/*
+	 * Do plugin specific actions.
+	 */
 	if (GNC_PLUGIN_GET_CLASS (plugin)->add_to_window) {
+	  DEBUG ("Calling child class function %p", GNC_PLUGIN_GET_CLASS (plugin)->add_to_window);
 	  GNC_PLUGIN_GET_CLASS (plugin)->add_to_window (plugin, window, type);
 	}
-	LEAVE ("plugin name = %s", gnc_plugin_get_name(plugin));
+	LEAVE ("");
 }
 
 void
@@ -130,16 +148,36 @@
 	GncPluginClass *class;
 
 	g_return_if_fail (GNC_IS_PLUGIN (plugin));
-
 	class = GNC_PLUGIN_GET_CLASS (plugin);
+	ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
+	       plugin, window);
+
+	/*
+	 * Do plugin specific actions.
+	 */
 	if (GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window) {
+	  DEBUG ("Calling child class function %p",
+		 GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window);
 	  GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window (plugin, window, type);
 	}
 
+	/*
+	 * Remove any gconf notifications
+	 */
+	if (class->gconf_section && class->gconf_notifications) {
+	  DEBUG ("Remove notification for section %s", class->gconf_section);
+	  gnc_gconf_remove_notification (G_OBJECT(window), class->gconf_section);
+	}
+
+	/*
+	 * Update window to remove UI items
+	 */
 	if (class->actions_name) {
+	  DEBUG ("%s: %d actions to unmerge",
+		 class->actions_name, class->n_actions);
 	  gnc_main_window_unmerge_actions (window, class->actions_name);
 	}
-	plugin->window = NULL;
+	LEAVE ("");
 }
 
 GncPluginPage *


More information about the gnucash-changes mailing list