GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | Functions
Common object and functions

Files

file  gnc-plugin.c
 Functions for adding plugins to a Gnucash window.
 
file  gnc-plugin.h
 Functions for adding plugins to a GnuCash window.
 

Data Structures

struct  GncPluginPrivate
 
struct  GncPlugin
 
struct  GncPluginClass
 
struct  action_toolbar_labels
 

Macros

#define GNC_PLUGIN_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN, GncPluginPrivate))
 
#define GNC_TYPE_PLUGIN   (gnc_plugin_get_type ())
 
#define GNC_PLUGIN(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_PLUGIN, GncPlugin))
 
#define GNC_PLUGIN_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_PLUGIN, GncPluginClass))
 
#define GNC_IS_PLUGIN(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_PLUGIN))
 
#define GNC_IS_PLUGIN_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_PLUGIN))
 
#define GNC_PLUGIN_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_PLUGIN, GncPluginClass))
 
#define GNC_PLUGIN_NAME   "GncPlugin"
 

Typedefs

typedef struct GncPluginPrivate GncPluginPrivate
 

Functions

GType gnc_plugin_get_type (void)
 
void gnc_plugin_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
 
void gnc_plugin_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
 
const gchar * gnc_plugin_get_name (GncPlugin *plugin)
 
void gnc_plugin_init_short_names (GtkActionGroup *action_group, action_toolbar_labels *toolbar_labels)
 
void gnc_plugin_set_important_actions (GtkActionGroup *action_group, const gchar **name)
 
void gnc_plugin_update_actions (GtkActionGroup *action_group, const gchar **action_names, const gchar *property_name, gboolean value)
 
gint gnc_plugin_add_actions (GtkUIManager *ui_merge, GtkActionGroup *action_group, const gchar *filename)
 

Detailed Description

Typedef Documentation

The instance private data for a menu-only plugin. This data structure is unused.

Function Documentation

gint gnc_plugin_add_actions ( GtkUIManager *  ui_merge,
GtkActionGroup *  action_group,
const gchar *  filename 
)

Load a new set of actions into an existing UI.

See gnc-plugin.h for documentation on the function arguments.

Load a new set of actions into an existing UI. The actions from the provided group will be merged into the pre-existing ui, as directed by the specified file.

Parameters
ui_mergeA pointer to the UI manager data structure for a window.
action_groupThe set of actions provided by a given plugin.
filenameThe name of the ui description file. This file name will be searched for in the ui directory.
Returns
The merge_id number for the newly merged UI. If an error occurred, the return value is 0.

Definition at line 346 of file gnc-plugin.c.

349 {
350  GError *error = NULL;
351  gchar *pathname;
352  gint merge_id;
353 
354  g_return_val_if_fail (ui_merge, 0);
355  g_return_val_if_fail (action_group, 0);
356  g_return_val_if_fail (filename, 0);
357 
358  ENTER("ui_merge %p, action_group %p, filename %s",
359  ui_merge, action_group, filename);
360  gtk_ui_manager_insert_action_group (ui_merge, action_group, 0);
361 
362  pathname = gnc_filepath_locate_ui_file (filename);
363  if (pathname == NULL)
364  {
365  LEAVE("fail");
366  return 0;
367  }
368 
369  merge_id = gtk_ui_manager_add_ui_from_file (ui_merge, pathname, &error);
370  DEBUG("merge_id is %d", merge_id);
371 
372  g_assert(merge_id || error);
373  if (merge_id)
374  {
375  gtk_ui_manager_ensure_update (ui_merge);
376  }
377  else
378  {
379  g_critical("Failed to load ui file.\n Filename %s\n Error %s",
380  filename, error->message);
381  g_error_free(error);
382  }
383 
384  g_free(pathname);
385  LEAVE(" ");
386  return merge_id;
387 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
gchar * gnc_filepath_locate_ui_file(const gchar *name)
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_plugin_add_to_window ( GncPlugin plugin,
GncMainWindow window,
GQuark  type 
)

Add the specified plugin from the specified window. This function 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.

Add the specified plugin to the specified window. This function will add the page's user interface from the window and call the plugin to perform any plugin specific actions.

Parameters
pluginThe plugin to be added.
windowAdd the plugin to this window.
typeAn identifier for the type of window specified.

Definition at line 157 of file gnc-plugin.c.

160 {
161  GncPluginClass *klass;
162  GtkActionGroup *action_group;
163 
164  g_return_if_fail (GNC_IS_PLUGIN (plugin));
165  klass = GNC_PLUGIN_GET_CLASS (plugin);
166  ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
167  plugin, window);
168 
169  /*
170  * Update window with additional UI items
171  */
172  if (klass->actions_name)
173  {
174  DEBUG ("%s: %d actions to merge with gui from %s",
175  klass->actions_name, (klass->n_actions + klass->n_toggle_actions), klass->ui_filename);
177  klass->actions, klass->n_actions,
178  klass->toggle_actions, klass->n_toggle_actions,
179  klass->ui_filename, plugin);
180 
181 
182  if (klass->important_actions)
183  {
184  action_group =
187  klass->important_actions);
188  }
189  }
190 
191  /*
192  * Do plugin specific actions.
193  */
194  if (GNC_PLUGIN_GET_CLASS (plugin)->add_to_window)
195  {
196  DEBUG ("Calling child class function %p", GNC_PLUGIN_GET_CLASS (plugin)->add_to_window);
197  GNC_PLUGIN_GET_CLASS (plugin)->add_to_window (plugin, window, type);
198  }
199  LEAVE ("");
200 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
#define ENTER(format, args...)
Definition: qoflog.h:261
guint n_toggle_actions
Definition: gnc-plugin.h:129
void gnc_main_window_merge_actions(GncMainWindow *window, const gchar *group_name, GtkActionEntry *actions, guint n_actions, GtkToggleActionEntry *toggle_actions, guint n_toggle_actions, const gchar *filename, gpointer user_data)
const gchar * ui_filename
Definition: gnc-plugin.h:137
GtkActionEntry * actions
Definition: gnc-plugin.h:122
const gchar ** important_actions
Definition: gnc-plugin.h:134
const gchar * gnc_plugin_get_name(GncPlugin *plugin)
Definition: gnc-plugin.c:246
GtkToggleActionEntry * toggle_actions
Definition: gnc-plugin.h:127
const gchar * actions_name
Definition: gnc-plugin.h:119
GtkActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_plugin_set_important_actions(GtkActionGroup *action_group, const gchar **name)
Definition: gnc-plugin.c:289
const gchar * gnc_plugin_get_name ( GncPlugin plugin)

Retrieve the textual name of a plugin.

Retrieve the textual name of a plugin.

Parameters
pluginThe plugin whose name should be returned.
Returns
A string containing the name of this plugin

Definition at line 246 of file gnc-plugin.c.

247 {
248  g_return_val_if_fail (GNC_IS_PLUGIN (plugin), NULL);
249  return (GNC_PLUGIN_GET_CLASS(plugin)->plugin_name);
250 }
GType gnc_plugin_get_type ( void  )

Get the type of a gnc window plugin.

Get the type of a menu-only plugin.

Returns
A GType.

Definition at line 71 of file gnc-plugin.c.

72 {
73  static GType gnc_plugin_type = 0;
74 
75  if (gnc_plugin_type == 0)
76  {
77  static const GTypeInfo our_info =
78  {
79  sizeof (GncPluginClass),
80  NULL, /* base_init */
81  NULL, /* base_finalize */
82  (GClassInitFunc) gnc_plugin_class_init,
83  NULL, /* class_finalize */
84  NULL, /* class_data */
85  sizeof (GncPlugin),
86  0, /* n_preallocs */
87  (GInstanceInitFunc) gnc_plugin_init,
88  };
89 
90  gnc_plugin_type = g_type_register_static (G_TYPE_OBJECT,
91  GNC_PLUGIN_NAME,
92  &our_info, 0);
93  }
94 
95  return gnc_plugin_type;
96 }
void gnc_plugin_init_short_names ( GtkActionGroup *  action_group,
action_toolbar_labels toolbar_labels 
)

Add "short" labels to existing actions. The "short" label is the string used on toolbar buttons when the action is visible.

See gnc-plugin.h for documentation on the function arguments.

Add "short" labels to existing actions. The "short" label is the string used on toolbar buttons when the action is visible. All toolbar buttons are homogeneous in size and are sized to fit the longest label. Therefore, this structure should be used if an action name is more than one word. This way the menu can have the label "Whizzy Feature", while the toolbar button only has the label "Whizzy".

Parameters
action_groupThe group of all actions associated with a plugin or plugin page. All actions to me modified must be in this group.
toolbar_labelsA pointer to a NULL terminated array of data action_toolbar_labels items.

Definition at line 263 of file gnc-plugin.c.

265 {
266  GtkAction *action;
267  GValue value = { 0, };
268  gint i;
269 
270  g_value_init (&value, G_TYPE_STRING);
271 
272  for (i = 0; toolbar_labels[i].action_name; i++)
273  {
274  /* Add a couple of short labels for the toolbar */
275  action = gtk_action_group_get_action (action_group,
276  toolbar_labels[i].action_name);
277  g_value_set_static_string (&value, gettext(toolbar_labels[i].label));
278  g_object_set_property (G_OBJECT(action), "short_label", &value);
279  }
280 }
const char * action_name
Definition: gnc-plugin.h:231
void gnc_plugin_remove_from_window ( GncPlugin plugin,
GncMainWindow window,
GQuark  type 
)

Remove the specified plugin from the specified window. This function will call the plugin to perform any plugin specific actions and remove the page's user interface from the window.

Parameters
pluginThe plugin to be removed.
windowThe window the plugin should be removed from.
typeAn identifier for the type of window specified.

Definition at line 209 of file gnc-plugin.c.

212 {
213  GncPluginClass *klass;
214 
215  g_return_if_fail (GNC_IS_PLUGIN (plugin));
216  klass = GNC_PLUGIN_GET_CLASS (plugin);
217  ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
218  plugin, window);
219 
220  /*
221  * Do plugin specific actions.
222  */
223  if (GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window)
224  {
225  DEBUG ("Calling child class function %p",
226  GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window);
227  GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window (plugin, window, type);
228  }
229 
230  /*
231  * Update window to remove UI items
232  */
233  if (klass->actions_name)
234  {
235  DEBUG ("%s: %d actions to unmerge",
236  klass->actions_name, (klass->n_actions + klass->n_toggle_actions));
238  }
239  LEAVE ("");
240 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
void gnc_main_window_unmerge_actions(GncMainWindow *window, const gchar *group_name)
#define ENTER(format, args...)
Definition: qoflog.h:261
guint n_toggle_actions
Definition: gnc-plugin.h:129
const gchar * gnc_plugin_get_name(GncPlugin *plugin)
Definition: gnc-plugin.c:246
const gchar * actions_name
Definition: gnc-plugin.h:119
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_plugin_set_important_actions ( GtkActionGroup *  action_group,
const gchar **  name 
)

Mark certain actions as "important". This means that their labels will appear when the toolbar is set to "Icons and important text" (e.g. GTK_TOOLBAR_BOTH_HORIZ) mode.

See gnc-plugin.h for documentation on the function arguments.

Mark certain actions as "important". This means that their labels will appear when the toolbar is set to "Icons and important text" (e.g. GTK_TOOLBAR_BOTH_HORIZ) mode.

Parameters
action_groupThe group of all actions associated with a plugin or plugin page. All actions to me modified must be in this group.
nameA list of actions names to be marked important. This list must be NULL terminated.

Definition at line 289 of file gnc-plugin.c.

291 {
292  GtkAction *action;
293  gint i;
294 
295  for (i = 0; name[i]; i++)
296  {
297  action = gtk_action_group_get_action (action_group, name[i]);
298  g_object_set (G_OBJECT(action), "is_important", TRUE, NULL);
299  }
300 
301  /* If this trips, you've got too many "important" actions. That
302  * can't *all* be that important, can they? */
303  g_assert(i <= 3);
304 }
void gnc_plugin_update_actions ( GtkActionGroup *  action_group,
const gchar **  action_names,
const gchar *  property_name,
gboolean  value 
)

Update a property on a set of existing GtkActions. This function can be easily used to make a list of actions visible, invisible, sensitive, or insensitive.

Parameters
action_groupThe group of all actions associated with a plugin or plugin page. All actions to be modified must be contained in this group.
action_namesA NULL terminated list of actions names that should modified.
property_nameThe property name to be changed on the specified actions. The only two GtkAction properties that it makes sense to modify are "visible" and "sensitive".
valueA boolean specifying the new state for the specified property.

Definition at line 313 of file gnc-plugin.c.

317 {
318  GtkAction *action;
319  GValue gvalue = { 0 };
320  gint i;
321 
322  g_value_init (&gvalue, G_TYPE_BOOLEAN);
323  g_value_set_boolean (&gvalue, value);
324 
325  for (i = 0; action_names[i]; i++)
326  {
327  action = gtk_action_group_get_action (action_group, action_names[i]);
328  if (action)
329  {
330  g_object_set_property (G_OBJECT(action), property_name, &gvalue);
331  }
332  else
333  {
334  g_warning("No such action with name '%s' in action group %s (size %d)",
335  action_names[i], gtk_action_group_get_name(action_group),
336  g_list_length(gtk_action_group_list_actions(action_group)));
337  }
338  }
339 }