GnuCash  5.6-133-gc519490283+
Files | Data Structures | Macros | 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
 The instance private data for a menu-only plugin. More...
 
struct  _GncPluginClass
 The class data structure for a menu-only plugin. More...
 
struct  action_toolbar_labels
 A structure for defining alternate action names for use in the toolbar. More...
 

Macros

#define GNC_TYPE_PLUGIN   (gnc_plugin_get_type ())
 
#define GNC_PLUGIN_NAME   "GncPlugin"
 

Functions

 G_DEFINE_TYPE_WITH_CODE (GncPlugin, gnc_plugin, G_TYPE_OBJECT, G_ADD_PRIVATE(GncPlugin))
 Initialize the class for the new gnucash plugin object. More...
 
void gnc_plugin_add_to_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
 Add the specified plugin from the specified window. More...
 
void gnc_plugin_remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
 Remove the specified plugin from the specified window. More...
 
const gchar * gnc_plugin_get_name (GncPlugin *plugin)
 Retrieve the textual name of a plugin. More...
 
void gnc_plugin_init_short_names (GtkWidget *toolbar, GncToolBarShortNames *toolbar_labels)
 Add "short" labels to existing actions. More...
 
void gnc_plugin_set_actions_enabled (GActionMap *action_map, const gchar **action_names, gboolean enable)
 This function sets the sensitivity of a GAction in a specific group. More...
 
void gnc_plugin_add_menu_tooltip_callbacks (GtkWidget *menubar, GMenuModel *menubar_model, GtkWidget *statusbar)
 This function adds the tooltip callbacks to make the tooltips appear in the status bar. More...
 
void gnc_plugin_add_toolbar_tooltip_callbacks (GtkWidget *toolbar, GtkWidget *statusbar)
 This function adds the tooltip callbacks to make the tooltips appear in the status bar. More...
 

Detailed Description

Function Documentation

◆ G_DEFINE_TYPE_WITH_CODE()

G_DEFINE_TYPE_WITH_CODE ( GncPlugin  ,
gnc_plugin  ,
G_TYPE_OBJECT  ,
G_ADD_PRIVATE(GncPlugin)   
)

Initialize the class for the new gnucash plugin object.

This will set up any function pointers that override functions in the parent class, and also installs the proprieties that are unique to this class.

Parameters
klassThe new class structure created by the object system.

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

76 {
77  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
78 
79  gobject_class->constructed = gnc_plugin_constructed;
80  gobject_class->finalize = gnc_plugin_finalize;
81 }

◆ gnc_plugin_add_menu_tooltip_callbacks()

void gnc_plugin_add_menu_tooltip_callbacks ( GtkWidget *  menubar,
GMenuModel *  menubar_model,
GtkWidget *  statusbar 
)

This function adds the tooltip callbacks to make the tooltips appear in the status bar.

Parameters
menubarThe main window menu bar widget.
menubar_modelThe GMenuModel used to create the menubar.
statusbarThe status bar widget in the main window.

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

271 {
272  GList *menu_item_list;
273 
274  g_return_if_fail (G_IS_MENU_MODEL(menubar_model));
275  g_return_if_fail (GTK_IS_STATUSBAR(statusbar));
276 
277  menu_item_list = gnc_menu_get_items (menubar);
278 
279  for (GList *node = menu_item_list; node; node = node->next)
280  {
281  GtkWidget *menu_item = node->data;
282 
284  }
285  g_object_set_data (G_OBJECT(statusbar), "menu-model", menubar_model);
286  g_list_free (menu_item_list);
287 }
GList * gnc_menu_get_items(GtkWidget *menu)
Return a list of GtkMenuItems.
void gnc_menu_item_setup_tooltip_to_statusbar_callback(GtkWidget *menu_item, GtkWidget *statusbar)
Setup the callbacks for menu bar items so the tooltip can be displayed in the status bar...

◆ gnc_plugin_add_to_window()

void gnc_plugin_add_to_window ( GncPlugin *  plugin,
GncMainWindow window,
GQuark  type 
)

Add the specified plugin from the specified window.

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.

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

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 133 of file gnc-plugin.c.

136 {
137  GncPluginClass *klass;
138 
139  g_return_if_fail (GNC_IS_PLUGIN (plugin));
140  klass = GNC_PLUGIN_GET_CLASS (plugin);
141  ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
142  plugin, window);
143 
144  /*
145  * Update window with additional UI items
146  */
147  if (klass->actions_name)
148  {
149  DEBUG ("%s: %d actions to merge with gui from %s",
150  klass->actions_name, klass->n_actions, klass->ui_filename);
151  gnc_main_window_merge_actions (window, klass->actions_name,
152  klass->actions, klass->n_actions,
153  klass->ui_updates,
154  klass->ui_filename, plugin);
155  }
156 
157  /*
158  * Do plugin specific actions.
159  */
160  if (GNC_PLUGIN_GET_CLASS (plugin)->add_to_window)
161  {
162  DEBUG ("Calling child class function %p", GNC_PLUGIN_GET_CLASS (plugin)->add_to_window);
163  GNC_PLUGIN_GET_CLASS (plugin)->add_to_window (plugin, window, type);
164  }
165  LEAVE ("");
166 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_main_window_merge_actions(GncMainWindow *window, const gchar *group_name, GActionEntry *actions, guint n_actions, const gchar **ui_updates, const gchar *ui_filename, gpointer user_data)
Add a set of actions to the specified window.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
const gchar * gnc_plugin_get_name(GncPlugin *plugin)
Retrieve the textual name of a plugin.
Definition: gnc-plugin.c:212
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_plugin_add_toolbar_tooltip_callbacks()

void gnc_plugin_add_toolbar_tooltip_callbacks ( GtkWidget *  toolbar,
GtkWidget *  statusbar 
)

This function adds the tooltip callbacks to make the tooltips appear in the status bar.

Parameters
toolbarThe main window tool bar widget.
statusbarThe status bar widget in the main window.

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

300 {
301  g_return_if_fail (GTK_IS_TOOLBAR(toolbar));
302  g_return_if_fail (GTK_IS_STATUSBAR(statusbar));
303 
304  gtk_container_foreach (GTK_CONTAINER(toolbar), for_each_tool_action, statusbar);
305 }

◆ gnc_plugin_get_name()

const gchar * gnc_plugin_get_name ( GncPlugin *  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 212 of file gnc-plugin.c.

213 {
214  g_return_val_if_fail (GNC_IS_PLUGIN (plugin), NULL);
215  return (GNC_PLUGIN_GET_CLASS(plugin)->plugin_name);
216 }

◆ gnc_plugin_init_short_names()

void gnc_plugin_init_short_names ( GtkWidget *  toolbar,
GncToolBarShortNames 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.

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 GncToolBarShortNames items.

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

231 {
232  g_return_if_fail (toolbar != NULL);
233  g_return_if_fail (toolbar_labels != NULL);
234 
235  for (gint i = 0; (toolbar_labels[i].action_name); i++)
236  {
237  GtkWidget *tool_item = gnc_find_toolbar_item (toolbar, toolbar_labels[i].action_name);
238 
239  if (!tool_item)
240  continue;
241 
242  gtk_tool_button_set_label (GTK_TOOL_BUTTON(tool_item), _(toolbar_labels[i].short_label));
243  gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON(tool_item), TRUE);
244  }
245 }
GtkWidget * gnc_find_toolbar_item(GtkWidget *toolbar, const gchar *action_name)
Search the toolbar for the tool item based on the action name.
const char * action_name
The name of the action.

◆ gnc_plugin_remove_from_window()

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 175 of file gnc-plugin.c.

178 {
179  GncPluginClass *klass;
180 
181  g_return_if_fail (GNC_IS_PLUGIN (plugin));
182  klass = GNC_PLUGIN_GET_CLASS (plugin);
183  ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin),
184  plugin, window);
185 
186  /*
187  * Do plugin specific actions.
188  */
189  if (GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window)
190  {
191  DEBUG ("Calling child class function %p",
192  GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window);
193  GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window (plugin, window, type);
194  }
195 
196  /*
197  * Update window to remove UI items
198  */
199  if (klass->actions_name && !window->just_plugin_prefs)
200  {
201  DEBUG ("%s: %d actions to unmerge",
202  klass->actions_name, (klass->n_actions));
203  gnc_main_window_unmerge_actions (window, klass->actions_name);
204  }
205  LEAVE ("");
206 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
void gnc_main_window_unmerge_actions(GncMainWindow *window, const gchar *group_name)
Remove a set of actions from the specified window.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
const gchar * gnc_plugin_get_name(GncPlugin *plugin)
Retrieve the textual name of a plugin.
Definition: gnc-plugin.c:212
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ gnc_plugin_set_actions_enabled()

void gnc_plugin_set_actions_enabled ( GActionMap *  action_map,
const gchar **  action_names,
gboolean  enable 
)

This function sets the sensitivity of a GAction in a specific group.

Parameters
action_mapThe action map associated with the window.
action_namesA NULL terminated list of actions names that should be modified.
enableA boolean specifying the new state for the specified property.

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

252 {
253  g_return_if_fail (action_map != NULL);
254 
255  for (gint i = 0; action_names[i]; i++)
256  {
257  GAction *action = g_action_map_lookup_action (G_ACTION_MAP(action_map),
258  action_names[i]);
259  if (action)
260  g_simple_action_set_enabled (G_SIMPLE_ACTION(action), enable);
261  else
262  PERR("No such action with name '%s' in action group %p)",
263  action_names[i], action_map);
264  }
265 }
#define PERR(format, args...)
Log a serious error.
Definition: qoflog.h:244