From b712968386e235e55f81aa7fb1aa737c16b48f86 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Mon, 7 Oct 2013 14:16:59 +0000 Subject: [PATCH] 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 --- src/gnome-utils/gnc-plugin.c | 29 ++---------- src/gnome-utils/gnc-plugin.h | 31 ++----------- src/gnome/gnc-plugin-register.c | 76 ++++++++++++++++++++++++++------ src/gnome/gnc-plugin-register2.c | 73 +++++++++++++++++++++++++----- 4 files changed, 131 insertions(+), 78 deletions(-) diff --git a/src/gnome-utils/gnc-plugin.c b/src/gnome-utils/gnc-plugin.c index 113231da6e..33512956a4 100644 --- a/src/gnome-utils/gnc-plugin.c +++ b/src/gnome-utils/gnc-plugin.c @@ -40,7 +40,6 @@ #include "gnc-plugin.h" #include "gnc-engine.h" #include "gnc-filepath-utils.h" -#include "gnc-gconf-utils.h" #include "gnc-gnome-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 - * will add the page's user interface from the window, set up gconf - * notifications if the page uses gconf, and call the plugin to - * perform any plugin specific actions. + * will add the page's user interface from the window and call the + * plugin to perform any plugin specific actions. * * See gnc-plugin.h for documentation on the function arguments. */ 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. */ @@ -214,8 +202,7 @@ gnc_plugin_add_to_window (GncPlugin *plugin, /* Remove the specified plugin from the specified window. This * function will call the plugin to perform any plugin specific - * actions, remove any gconf notifications that were set up for the - * page, and remove the page's user interface from the window. + * actions and remove the page's user interface from the window. * * See gnc-plugin.h for documentation on the function arguments. */ void @@ -240,16 +227,6 @@ gnc_plugin_remove_from_window (GncPlugin *plugin, 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 */ diff --git a/src/gnome-utils/gnc-plugin.h b/src/gnome-utils/gnc-plugin.h index c9a1f56135..a51bd4a590 100644 --- a/src/gnome-utils/gnc-plugin.h +++ b/src/gnome-utils/gnc-plugin.h @@ -81,7 +81,6 @@ #include "gnc-main-window.h" #include "gnc-plugin-page.h" -#include G_BEGIN_DECLS @@ -137,28 +136,6 @@ typedef struct * menu/toolbar action items. */ 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 */ /** 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 - * will add the page's user interface from the window, set up gconf - * notifications if the page uses gconf, and call the plugin to - * perform any plugin specific actions. + * will add the page's user interface from the window and call the + * plugin to perform any plugin specific actions. * * @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 * function will call the plugin to perform any plugin specific - * actions, remove any gconf notifications that were set up for the - * page, and remove the page's user interface from the window. + * actions and remove the page's user interface from the window. * * @param plugin The plugin to be removed. * diff --git a/src/gnome/gnc-plugin-register.c b/src/gnome/gnc-plugin-register.c index f2f45d0159..8828760608 100644 --- a/src/gnome/gnc-plugin-register.c +++ b/src/gnome/gnc-plugin-register.c @@ -31,18 +31,21 @@ #include "gnc-component-manager.h" #include "gnc-plugin-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_init (GncPluginRegister *plugin); 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 */ static void gnc_plugin_register_cmd_general_ledger (GtkAction *action, GncMainWindowActionData *data); #define PLUGIN_ACTIONS_NAME "gnc-plugin-register-actions" #define PLUGIN_UI_FILENAME "gnc-plugin-register-ui.xml" -#define GCONF_REGISTER_SECTION "general/register" 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 - * 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. - * The register pages will then reread their settings from gconf and + * The register pages will then reread their preferences and * update the screen. * - * @client Unused. + * @prefs Unused. * - * @cnxn_id Unused. - * - * @entry Unused. + * @pref Unused. * * @user_data Unused. */ static void -gnc_plugin_register_gconf_changed (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, +gnc_plugin_register_pref_changed (gpointer prefs, gchar *pref, gpointer user_data) { ENTER(""); @@ -154,15 +153,17 @@ gnc_plugin_register_class_init (GncPluginRegisterClass *klass) /* plugin info */ 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 */ plugin_class->actions_name = PLUGIN_ACTIONS_NAME; plugin_class->actions = gnc_plugin_actions; plugin_class->n_actions = gnc_plugin_n_actions; 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)); } @@ -179,6 +180,55 @@ gnc_plugin_register_finalize (GObject *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 * ************************************************************/ diff --git a/src/gnome/gnc-plugin-register2.c b/src/gnome/gnc-plugin-register2.c index aaa5399e3c..12a8ff47a7 100644 --- a/src/gnome/gnc-plugin-register2.c +++ b/src/gnome/gnc-plugin-register2.c @@ -31,11 +31,15 @@ #include "gnc-component-manager.h" #include "gnc-plugin-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_init (GncPluginRegister2 *plugin); 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 */ 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 - * 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. - * The register pages will then reread their settings from gconf and + * The register pages will then reread their preferences and * update the screen. * - * @client Unused. + * @prefs Unused. * - * @cnxn_id Unused. - * - * @entry Unused. + * @pref Unused. * * @user_data Unused. */ static void -gnc_plugin_register2_gconf_changed (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, +gnc_plugin_register2_pref_changed (gpointer prefs, gchar *pref, gpointer user_data) { ENTER(""); @@ -153,13 +153,16 @@ gnc_plugin_register2_class_init (GncPluginRegister2Class *klass) /* plugin info */ 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 */ plugin_class->actions_name = PLUGIN_ACTIONS_NAME; plugin_class->actions = gnc_plugin_actions; plugin_class->n_actions = gnc_plugin_n_actions; 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)); } @@ -183,6 +186,54 @@ gnc_plugin_register2_finalize (GObject *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 * ************************************************************/