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 |
Defines | |
| #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" |
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) |
| 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.
Definition at line 351 of file gnc-plugin.c.
00354 { 00355 GError *error = NULL; 00356 gchar *pathname; 00357 gint merge_id; 00358 00359 g_return_val_if_fail (ui_merge, 0); 00360 g_return_val_if_fail (action_group, 0); 00361 g_return_val_if_fail (filename, 0); 00362 00363 ENTER("ui_merge %p, action_group %p, filename %s", 00364 ui_merge, action_group, filename); 00365 gtk_ui_manager_insert_action_group (ui_merge, action_group, 0); 00366 00367 pathname = gnc_gnome_locate_ui_file (filename); 00368 if (pathname == NULL) 00369 { 00370 LEAVE("fail"); 00371 return 0; 00372 } 00373 00374 merge_id = gtk_ui_manager_add_ui_from_file (ui_merge, pathname, &error); 00375 DEBUG("merge_id is %d", merge_id); 00376 00377 g_assert(merge_id || error); 00378 if (merge_id) { 00379 gtk_ui_manager_ensure_update (ui_merge); 00380 } else { 00381 g_critical("Failed to load ui file.\n Filename %s\n Error %s", 00382 filename, error->message); 00383 g_error_free(error); 00384 } 00385 00386 g_free(pathname); 00387 LEAVE(" "); 00388 return merge_id; 00389 }
| 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, set up gconf notifications if the page uses gconf, and call the plugin to perform any plugin specific actions.
See gnc-plugin.h for documentation on the function arguments.
Definition at line 161 of file gnc-plugin.c.
00164 { 00165 GncPluginClass *class; 00166 GtkActionGroup *action_group; 00167 00168 g_return_if_fail (GNC_IS_PLUGIN (plugin)); 00169 class = GNC_PLUGIN_GET_CLASS (plugin); 00170 ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin), 00171 plugin, window); 00172 00173 /* 00174 * Update window with additional UI items 00175 */ 00176 if (class->actions_name) { 00177 DEBUG ("%s: %d actions to merge with gui from %s", 00178 class->actions_name, class->n_actions, class->ui_filename); 00179 gnc_main_window_merge_actions (window, class->actions_name, 00180 class->actions, class->n_actions, 00181 class->ui_filename, plugin); 00182 00183 00184 if (class->important_actions) { 00185 action_group = 00186 gnc_main_window_get_action_group(window, class->actions_name); 00187 gnc_plugin_set_important_actions(action_group, 00188 class->important_actions); 00189 } 00190 } 00191 00192 /* 00193 * Setup gconf notifications if requested 00194 */ 00195 if (class->gconf_section && class->gconf_notifications) { 00196 DEBUG ("Requesting notification for section %s", class->gconf_section); 00197 gnc_gconf_add_notification(G_OBJECT(window), class->gconf_section, 00198 class->gconf_notifications, GNC_PLUGIN_NAME); 00199 } 00200 00201 /* 00202 * Do plugin specific actions. 00203 */ 00204 if (GNC_PLUGIN_GET_CLASS (plugin)->add_to_window) { 00205 DEBUG ("Calling child class function %p", GNC_PLUGIN_GET_CLASS (plugin)->add_to_window); 00206 GNC_PLUGIN_GET_CLASS (plugin)->add_to_window (plugin, window, type); 00207 } 00208 LEAVE (""); 00209 }
| const gchar * gnc_plugin_get_name | ( | GncPlugin * | plugin | ) |
Retrieve the textual name of a plugin.
Definition at line 263 of file gnc-plugin.c.
00264 { 00265 g_return_val_if_fail (GNC_IS_PLUGIN (plugin), NULL); 00266 return (GNC_PLUGIN_GET_CLASS(plugin)->plugin_name); 00267 }
| GType gnc_plugin_get_type | ( | void | ) |
Get the type of a gnc window plugin.
Definition at line 70 of file gnc-plugin.c.
00071 { 00072 static GType gnc_plugin_type = 0; 00073 00074 if (gnc_plugin_type == 0) { 00075 static const GTypeInfo our_info = { 00076 sizeof (GncPluginClass), 00077 NULL, /* base_init */ 00078 NULL, /* base_finalize */ 00079 (GClassInitFunc) gnc_plugin_class_init, 00080 NULL, /* class_finalize */ 00081 NULL, /* class_data */ 00082 sizeof (GncPlugin), 00083 0, /* n_preallocs */ 00084 (GInstanceInitFunc) gnc_plugin_init, 00085 }; 00086 00087 gnc_plugin_type = g_type_register_static (G_TYPE_OBJECT, 00088 GNC_PLUGIN_NAME, 00089 &our_info, 0); 00090 } 00091 00092 return gnc_plugin_type; 00093 }
| 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.
Definition at line 280 of file gnc-plugin.c.
00282 { 00283 GtkAction *action; 00284 GValue value = { 0, }; 00285 gint i; 00286 00287 g_value_init (&value, G_TYPE_STRING); 00288 00289 for (i = 0; toolbar_labels[i].action_name; i++) { 00290 /* Add a couple of short labels for the toolbar */ 00291 action = gtk_action_group_get_action (action_group, 00292 toolbar_labels[i].action_name); 00293 g_value_set_static_string (&value, gettext(toolbar_labels[i].label)); 00294 g_object_set_property (G_OBJECT(action), "short_label", &value); 00295 } 00296 }
| 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, remove any gconf notifications that were set up for the page, and remove the page's user interface from the window.
| plugin | The plugin to be removed. | |
| window | The window the plugin should be removed from. | |
| type | An identifier for the type of window specified. |
Definition at line 219 of file gnc-plugin.c.
00222 { 00223 GncPluginClass *class; 00224 00225 g_return_if_fail (GNC_IS_PLUGIN (plugin)); 00226 class = GNC_PLUGIN_GET_CLASS (plugin); 00227 ENTER (": plugin %s(%p), window %p", gnc_plugin_get_name(plugin), 00228 plugin, window); 00229 00230 /* 00231 * Do plugin specific actions. 00232 */ 00233 if (GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window) { 00234 DEBUG ("Calling child class function %p", 00235 GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window); 00236 GNC_PLUGIN_GET_CLASS (plugin)->remove_from_window (plugin, window, type); 00237 } 00238 00239 /* 00240 * Remove any gconf notifications 00241 */ 00242 if (class->gconf_section && class->gconf_notifications) { 00243 DEBUG ("Remove notification for section %s", class->gconf_section); 00244 gnc_gconf_remove_notification (G_OBJECT(window), class->gconf_section, 00245 GNC_PLUGIN_NAME); 00246 } 00247 00248 /* 00249 * Update window to remove UI items 00250 */ 00251 if (class->actions_name) { 00252 DEBUG ("%s: %d actions to unmerge", 00253 class->actions_name, class->n_actions); 00254 gnc_main_window_unmerge_actions (window, class->actions_name); 00255 } 00256 LEAVE (""); 00257 }
| void gnc_plugin_set_important_actions | ( | GtkActionGroup * | action_group, | |
| const gchar ** | names | |||
| ) |
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.
Definition at line 305 of file gnc-plugin.c.
00307 { 00308 GtkAction *action; 00309 gint i; 00310 00311 for (i = 0; name[i]; i++) { 00312 action = gtk_action_group_get_action (action_group, name[i]); 00313 g_object_set (G_OBJECT(action), "is_important", TRUE, NULL); 00314 } 00315 00316 /* If this trips, you've got too many "important" actions. That 00317 * can't *all* be that important, can they? */ 00318 g_assert(i <= 3); 00319 }
| 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.
| action_group | The group of all actions associated with a plugin or plugin page. All actions to be modified must be contained in this group. | |
| action_names | A NULL terminated list of actions names that should modified. | |
| property_name | The property name to be changed on the specified actions. The only two GtkAction properties that it makes sense to modify are "visible" and "sensitive". | |
| value | A boolean specifying the new state for the specified property. |
Definition at line 328 of file gnc-plugin.c.
00332 { 00333 GtkAction *action; 00334 GValue gvalue = { 0 }; 00335 gint i; 00336 00337 g_value_init (&gvalue, G_TYPE_BOOLEAN); 00338 g_value_set_boolean (&gvalue, value); 00339 00340 for (i = 0; action_names[i]; i++) { 00341 action = gtk_action_group_get_action (action_group, action_names[i]); 00342 g_object_set_property (G_OBJECT(action), property_name, &gvalue); 00343 } 00344 }
1.5.2