Gnc-Prefs: migrate gnc-plugin gconf machinery

Instead of storing a gconf callback function that will
eventually by attached to the preference when the
plugin is added to a window, simply do this for each
plugin internally in its own add_to_window override
function.
This had already been done in earlier commits for most
plugins. This commit cleans it up for the remaining
plugins and the base plugin code.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23248 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Geert Janssens 2013-10-07 14:16:59 +00:00
parent b453bf3838
commit b712968386
4 changed files with 131 additions and 78 deletions

View File

@ -40,7 +40,6 @@
#include "gnc-plugin.h" #include "gnc-plugin.h"
#include "gnc-engine.h" #include "gnc-engine.h"
#include "gnc-filepath-utils.h" #include "gnc-filepath-utils.h"
#include "gnc-gconf-utils.h"
#include "gnc-gnome-utils.h" #include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h" #include "gnc-gobject-utils.h"
@ -150,9 +149,8 @@ gnc_plugin_finalize (GObject *object)
/** Add the specified plugin from the specified window. This function /** Add the specified plugin from the specified window. This function
* will add the page's user interface from the window, set up gconf * will add the page's user interface from the window and call the
* notifications if the page uses gconf, and call the plugin to * plugin to perform any plugin specific actions.
* perform any plugin specific actions.
* *
* See gnc-plugin.h for documentation on the function arguments. */ * See gnc-plugin.h for documentation on the function arguments. */
void void
@ -190,16 +188,6 @@ gnc_plugin_add_to_window (GncPlugin *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, GNC_PLUGIN_NAME);
}
/* /*
* Do plugin specific actions. * Do plugin specific actions.
*/ */
@ -214,8 +202,7 @@ gnc_plugin_add_to_window (GncPlugin *plugin,
/* Remove the specified plugin from the specified window. This /* Remove the specified plugin from the specified window. This
* function will call the plugin to perform any plugin specific * function will call the plugin to perform any plugin specific
* actions, remove any gconf notifications that were set up for the * actions and remove the page's user interface from the window.
* page, and remove the page's user interface from the window.
* *
* See gnc-plugin.h for documentation on the function arguments. */ * See gnc-plugin.h for documentation on the function arguments. */
void void
@ -240,16 +227,6 @@ gnc_plugin_remove_from_window (GncPlugin *plugin,
GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window (plugin, window, type); 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,
GNC_PLUGIN_NAME);
}
/* /*
* Update window to remove UI items * Update window to remove UI items
*/ */

View File

@ -81,7 +81,6 @@
#include "gnc-main-window.h" #include "gnc-main-window.h"
#include "gnc-plugin-page.h" #include "gnc-plugin-page.h"
#include <gconf/gconf-client.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -137,28 +136,6 @@ typedef struct
* menu/toolbar action items. */ * menu/toolbar action items. */
const gchar *ui_filename; const gchar *ui_filename;
/* GConf section */
/** The partial section name that will be used in GConf for
* any preferences that are automatically stored for this
* page. This will be converted to a full section name by
* prefixing the string "/apps/gnucash/" to whatever is
* here. */
const gchar* gconf_section;
/** A callback that will be invoked when any key in the
* specified GConf section is changed.
*
* @param client A pointer to the gconf client instance.
*
* @param cnxn_id The id number for this callback function.
*
* @param entry A pointer to the changed data.
*
* @param user_data A pointer to the GncWindow where the
* plugin is installed. */
void (* gconf_notifications)
(GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer user_data);
/* Virtual Table */ /* Virtual Table */
/** A callback that will be invoked when this plugin is added /** A callback that will be invoked when this plugin is added
@ -204,9 +181,8 @@ GType gnc_plugin_get_type (void);
/** Add the specified plugin to the specified window. This function /** Add the specified plugin to the specified window. This function
* will add the page's user interface from the window, set up gconf * will add the page's user interface from the window and call the
* notifications if the page uses gconf, and call the plugin to * plugin to perform any plugin specific actions.
* perform any plugin specific actions.
* *
* @param plugin The plugin to be added. * @param plugin The plugin to be added.
* *
@ -221,8 +197,7 @@ void gnc_plugin_add_to_window (GncPlugin *plugin,
/** Remove the specified plugin from the specified window. This /** Remove the specified plugin from the specified window. This
* function will call the plugin to perform any plugin specific * function will call the plugin to perform any plugin specific
* actions, remove any gconf notifications that were set up for the * actions and remove the page's user interface from the window.
* page, and remove the page's user interface from the window.
* *
* @param plugin The plugin to be removed. * @param plugin The plugin to be removed.
* *

View File

@ -31,18 +31,21 @@
#include "gnc-component-manager.h" #include "gnc-component-manager.h"
#include "gnc-plugin-register.h" #include "gnc-plugin-register.h"
#include "gnc-plugin-page-register.h" #include "gnc-plugin-page-register.h"
#include "gnc-prefs.h"
static void gnc_plugin_register_class_init (GncPluginRegisterClass *klass); static void gnc_plugin_register_class_init (GncPluginRegisterClass *klass);
static void gnc_plugin_register_init (GncPluginRegister *plugin); static void gnc_plugin_register_init (GncPluginRegister *plugin);
static void gnc_plugin_register_finalize (GObject *object); static void gnc_plugin_register_finalize (GObject *object);
static void gnc_plugin_register_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
static void gnc_plugin_register_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
/* Command callbacks */ /* Command callbacks */
static void gnc_plugin_register_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data); static void gnc_plugin_register_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data);
#define PLUGIN_ACTIONS_NAME "gnc-plugin-register-actions" #define PLUGIN_ACTIONS_NAME "gnc-plugin-register-actions"
#define PLUGIN_UI_FILENAME "gnc-plugin-register-ui.xml" #define PLUGIN_UI_FILENAME "gnc-plugin-register-ui.xml"
#define GCONF_REGISTER_SECTION "general/register"
static GtkActionEntry gnc_plugin_actions [] = static GtkActionEntry gnc_plugin_actions [] =
{ {
@ -70,23 +73,19 @@ static QofLogModule log_module = GNC_MOD_GUI;
************************************************************/ ************************************************************/
/** This function is called whenever an entry in the general register /** This function is called whenever an entry in the general register
* section of gconf is changed. It does nothing more than kick off a * preferences group is changed. It does nothing more than kick off a
* gui refresh which should be delivered to any open register page. * gui refresh which should be delivered to any open register page.
* The register pages will then reread their settings from gconf and * The register pages will then reread their preferences and
* update the screen. * update the screen.
* *
* @client Unused. * @prefs Unused.
* *
* @cnxn_id Unused. * @pref Unused.
*
* @entry Unused.
* *
* @user_data Unused. * @user_data Unused.
*/ */
static void static void
gnc_plugin_register_gconf_changed (GConfClient *client, gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data) gpointer user_data)
{ {
ENTER(""); ENTER("");
@ -154,15 +153,17 @@ gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
/* plugin info */ /* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME; plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
/* function overrides */
plugin_class->add_to_window = gnc_plugin_register_add_to_window;
plugin_class->remove_from_window =
gnc_plugin_register_remove_from_window;
/* widget addition/removal */ /* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME; plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions; plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions; plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME; plugin_class->ui_filename = PLUGIN_UI_FILENAME;
plugin_class->gconf_section = GCONF_REGISTER_SECTION;
plugin_class->gconf_notifications = gnc_plugin_register_gconf_changed;
g_type_class_add_private(klass, sizeof(GncPluginRegisterPrivate)); g_type_class_add_private(klass, sizeof(GncPluginRegisterPrivate));
} }
@ -179,6 +180,55 @@ gnc_plugin_register_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
/************************************************************
* Plugin Function Implementation *
************************************************************/
/** Initialize the registeru for a window. This function is
* called as part of the initialization of a window, after all the
* plugin menu items have been added to the menu structure. Its job
* is to correctly initialize the register. It does this by
* installing a function that listens for preference changes. Each
* time a preference changes, it kicks off a gui refresh.
*
* @param plugin A pointer to the gnc-plugin object responsible for
* adding/removing the register.
*
* @param window A pointer to the gnc-main-window that is being initialized.
*
* @param type Unused
*/
static void
gnc_plugin_register_add_to_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
{
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
gnc_plugin_register_pref_changed, window);
}
/** Finalize the register for this window. This function is
* called as part of the destruction of a window.
*
* @param plugin A pointer to the gnc-plugin object responsible for
* adding/removing the register. It stops listening for
* changes in the register preferences.
*
* @param window A pointer the gnc-main-window that is being destroyed.
*
* @param type Unused
*/
static void
gnc_plugin_register_remove_from_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
{
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
gnc_plugin_register_pref_changed, window);
}
/************************************************************ /************************************************************
* Command Callbacks * * Command Callbacks *
************************************************************/ ************************************************************/

View File

@ -31,11 +31,15 @@
#include "gnc-component-manager.h" #include "gnc-component-manager.h"
#include "gnc-plugin-register2.h" #include "gnc-plugin-register2.h"
#include "gnc-plugin-page-register2.h" #include "gnc-plugin-page-register2.h"
#include "gnc-prefs.h"
static void gnc_plugin_register2_class_init (GncPluginRegister2Class *klass); static void gnc_plugin_register2_class_init (GncPluginRegister2Class *klass);
static void gnc_plugin_register2_init (GncPluginRegister2 *plugin); static void gnc_plugin_register2_init (GncPluginRegister2 *plugin);
static void gnc_plugin_register2_finalize (GObject *object); static void gnc_plugin_register2_finalize (GObject *object);
static void gnc_plugin_register2_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
static void gnc_plugin_register2_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type);
/* Command callbacks */ /* Command callbacks */
static void gnc_plugin_register2_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data); static void gnc_plugin_register2_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data);
@ -69,23 +73,19 @@ static QofLogModule log_module = GNC_MOD_GUI;
************************************************************/ ************************************************************/
/** This function is called whenever an entry in the general register /** This function is called whenever an entry in the general register
* section of gconf is changed. It does nothing more than kick off a * preferences group is changed. It does nothing more than kick off a
* gui refresh which should be delivered to any open register page. * gui refresh which should be delivered to any open register page.
* The register pages will then reread their settings from gconf and * The register pages will then reread their preferences and
* update the screen. * update the screen.
* *
* @client Unused. * @prefs Unused.
* *
* @cnxn_id Unused. * @pref Unused.
*
* @entry Unused.
* *
* @user_data Unused. * @user_data Unused.
*/ */
static void static void
gnc_plugin_register2_gconf_changed (GConfClient *client, gnc_plugin_register2_pref_changed (gpointer prefs, gchar *pref,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data) gpointer user_data)
{ {
ENTER(""); ENTER("");
@ -153,13 +153,16 @@ gnc_plugin_register2_class_init (GncPluginRegister2Class *klass)
/* plugin info */ /* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_REGISTER2_NAME; plugin_class->plugin_name = GNC_PLUGIN_REGISTER2_NAME;
/* function overrides */
plugin_class->add_to_window = gnc_plugin_register2_add_to_window;
plugin_class->remove_from_window =
gnc_plugin_register2_remove_from_window;
/* widget addition/removal */ /* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME; plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions; plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions; plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME; plugin_class->ui_filename = PLUGIN_UI_FILENAME;
plugin_class->gconf_section = GCONF_REGISTER2_SECTION;
plugin_class->gconf_notifications = gnc_plugin_register2_gconf_changed;
g_type_class_add_private(klass, sizeof(GncPluginRegister2Private)); g_type_class_add_private(klass, sizeof(GncPluginRegister2Private));
} }
@ -183,6 +186,54 @@ gnc_plugin_register2_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object); G_OBJECT_CLASS (parent_class)->finalize (object);
} }
/************************************************************
* Plugin Function Implementation *
************************************************************/
/** Initialize the registeru for a window. This function is
* called as part of the initialization of a window, after all the
* plugin menu items have been added to the menu structure. Its job
* is to correctly initialize the register. It does this by
* installing a function that listens for preference changes. Each
* time a preference changes, it kicks off a gui refresh.
*
* @param plugin A pointer to the gnc-plugin object responsible for
* adding/removing the register.
*
* @param window A pointer to the gnc-main-window that is being initialized.
*
* @param type Unused
*/
static void
gnc_plugin_register2_add_to_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
{
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
gnc_plugin_register2_pref_changed, window);
}
/** Finalize the register for this window. This function is
* called as part of the destruction of a window.
*
* @param plugin A pointer to the gnc-plugin object responsible for
* adding/removing the register. It stops listening for
* changes in the register preferences.
*
* @param window A pointer the gnc-main-window that is being destroyed.
*
* @param type Unused
*/
static void
gnc_plugin_register2_remove_from_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
{
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
gnc_plugin_register2_pref_changed, window);
}
/************************************************************ /************************************************************
* Command Callbacks * * Command Callbacks *
************************************************************/ ************************************************************/