Skip to content

Commit

Permalink
Gnc-Prefs: migrate gnc-plugin gconf machinery
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gjanssens committed Oct 7, 2013
1 parent b453bf3 commit b712968
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 78 deletions.
29 changes: 3 additions & 26 deletions src/gnome-utils/gnc-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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
Expand All @@ -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
*/
Expand Down
31 changes: 3 additions & 28 deletions src/gnome-utils/gnc-plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@

#include "gnc-main-window.h"
#include "gnc-plugin-page.h"
#include <gconf/gconf-client.h>

G_BEGIN_DECLS

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down
76 changes: 63 additions & 13 deletions src/gnome/gnc-plugin-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 [] =
{
Expand Down Expand Up @@ -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.
*
* @cnxn_id Unused.
* @prefs 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("");
Expand Down Expand Up @@ -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));
}

Expand All @@ -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 *
************************************************************/
Expand Down
73 changes: 62 additions & 11 deletions src/gnome/gnc-plugin-register2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
*
* @cnxn_id Unused.
* @prefs 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("");
Expand Down Expand Up @@ -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));
}
Expand All @@ -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 *
************************************************************/
Expand Down

0 comments on commit b712968

Please sign in to comment.