44 static QofLogModule log_module = GNC_MOD_GUI;
46 static void gnc_plugin_page_constructed (GObject *
object);
47 static void gnc_plugin_page_finalize (GObject *
object);
48 static void gnc_plugin_page_set_property (GObject *
object,
52 static void gnc_plugin_page_get_property (GObject *
object,
57 static void gnc_plugin_page_default_focus (
GncPluginPage *plugin_page,
58 gboolean on_current_page);
80 static guint signals[LAST_SIGNAL] = { 0 };
84 typedef struct _GncPluginPagePrivate
90 GSimpleActionGroup *simple_action_group;
91 const gchar *simple_action_group_name;
92 const gchar *menu_qualifier;
93 const gchar *menu_popup_qualifier;
97 gboolean use_new_window;
100 gchar *page_long_name;
103 gchar *statusbar_text;
105 gulong page_changed_id;
106 guint focus_source_id;
110 G_DEFINE_TYPE_WITH_CODE(
GncPluginPage, gnc_plugin_page, G_TYPE_OBJECT,
113 #define GNC_PLUGIN_PAGE_GET_PRIVATE(o) \ 114 ((GncPluginPagePrivate*)gnc_plugin_page_get_instance_private((GncPluginPage*)o)) 127 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page), NULL);
129 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
130 g_return_val_if_fail (klass != NULL, NULL);
142 g_object_ref (widget);
156 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
158 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
159 g_return_if_fail (klass != NULL);
171 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
190 const gchar *group_name)
194 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
195 g_return_if_fail (key_file != NULL);
196 g_return_if_fail (group_name != NULL);
199 klass = GNC_PLUGIN_PAGE_GET_CLASS(page);
200 g_return_if_fail (klass != NULL);
201 g_return_if_fail (klass->
save_page != NULL);
203 klass->
save_page (page, key_file, group_name);
213 const gchar *page_type,
215 const gchar *page_group)
221 ENTER(
"type %s, keyfile %p, group %s", page_type, key_file, page_group);
222 type = g_type_from_name (page_type);
225 LEAVE(
"Cannot find type named %s", page_type);
229 klass = g_type_class_ref (type);
232 const gchar *type_name = g_type_name (type);
233 LEAVE(
"Cannot create class %s(%s)", page_type, type_name ? type_name :
"invalid type");
239 LEAVE(
"Class %shas no recreate function.", page_type);
240 g_type_class_unref (klass);
245 g_type_class_unref (klass);
255 GError *error = NULL;
258 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
260 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
263 priv->builder = gtk_builder_new ();
265 resource = g_strconcat (GNUCASH_RESOURCE_PREFIX
"/", priv->
ui_description, NULL);
267 gtk_builder_set_translation_domain (priv->builder, PROJECT_NAME);
269 gtk_builder_add_from_resource (priv->builder, resource, &error);
273 g_critical (
"Failed to load ui resource %s, Error %s", resource, error->message);
274 g_error_free (error);
285 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
286 g_return_val_if_fail (name != NULL, NULL);
288 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
289 if (!priv->simple_action_group)
291 return g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group), name);
301 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page), NULL);
303 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
304 g_return_val_if_fail (klass != NULL, NULL);
314 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
316 g_signal_emit (G_OBJECT(plugin_page), signals[INSERTED], 0);
322 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
324 g_signal_emit (G_OBJECT(plugin_page), signals[REMOVED], 0);
330 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
332 g_signal_emit (G_OBJECT(plugin_page), signals[SELECTED], 0);
338 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
340 g_signal_emit (G_OBJECT(plugin_page), signals[UNSELECTED], 0);
353 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
355 gobject_class->constructed = gnc_plugin_page_constructed;
356 gobject_class->finalize = gnc_plugin_page_finalize;
357 gobject_class->set_property = gnc_plugin_page_set_property;
358 gobject_class->get_property = gnc_plugin_page_get_property;
362 klass->
focus_page = gnc_plugin_page_default_focus;
364 g_object_class_install_property
367 g_param_spec_string (
"page-name",
369 "The name of this page. This value is " 370 "used to generate the notebook tab and " 371 "menu items, and also the window title " 372 "when this page is visible.",
376 g_object_class_install_property
379 g_param_spec_string (
"page-color",
381 "The color of this page. This value is " 382 "used to generate the notebook tab color " 383 "when this page is visible.",
387 g_object_class_install_property
390 g_param_spec_string (
"statusbar-text",
392 "The text to be displayed in the statusbar " 393 "at the bottom of the window when this page " 398 g_object_class_install_property
401 g_param_spec_boolean (
"use-new-window",
403 "When TRUE a new top level window will be " 404 "created to hold this page.",
408 g_object_class_install_property
411 g_param_spec_string (
"ui-description",
412 "UI Description File",
413 "The filename containing the XML data that " 414 "describes this pages menus and toolbars.",
420 signals[INSERTED] = g_signal_new (
"inserted",
421 G_OBJECT_CLASS_TYPE (klass),
425 g_cclosure_marshal_VOID__VOID,
428 signals[REMOVED] = g_signal_new (
"removed",
429 G_OBJECT_CLASS_TYPE (klass),
433 g_cclosure_marshal_VOID__VOID,
436 signals[SELECTED] = g_signal_new (
"selected",
437 G_OBJECT_CLASS_TYPE (klass),
441 g_cclosure_marshal_VOID__VOID,
444 signals[UNSELECTED] = g_signal_new (
"unselected",
445 G_OBJECT_CLASS_TYPE (klass),
449 g_cclosure_marshal_VOID__VOID,
464 priv->page_name = NULL;
465 priv->page_color = NULL;
466 priv->page_changed_id = 0;
467 priv->focus_source_id = 0;
468 priv->menu_qualifier = NULL;
481 gnc_plugin_page_constructed (GObject *obj)
485 G_OBJECT_CLASS (gnc_plugin_page_parent_class)->constructed (obj);
496 gnc_plugin_page_finalize (GObject *
object)
501 page = GNC_PLUGIN_PAGE(
object);
503 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
509 g_free (priv->page_name);
511 if (priv->page_long_name)
512 g_free (priv->page_long_name);
514 if (priv->page_color)
515 g_free (priv->page_color);
517 if (priv->statusbar_text)
518 g_free (priv->statusbar_text);
522 g_list_free (priv->books);
527 g_object_unref (priv->builder);
532 G_OBJECT_CLASS(gnc_plugin_page_parent_class)->finalize (
object);
563 gnc_plugin_page_get_property (GObject *
object,
571 g_return_if_fail(GNC_IS_PLUGIN_PAGE(
object));
573 page = GNC_PLUGIN_PAGE(
object);
574 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
578 g_value_set_string (value, priv->page_name);
580 case PROP_PAGE_COLOR:
581 g_value_set_string (value, priv->page_color);
583 case PROP_STATUSBAR_TEXT:
584 g_value_set_string (value, priv->statusbar_text);
586 case PROP_USE_NEW_WINDOW:
587 g_value_set_boolean (value, priv->use_new_window);
589 case PROP_UI_DESCRIPTION:
593 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
616 gnc_plugin_page_set_property (GObject *
object,
623 g_return_if_fail(GNC_IS_PLUGIN_PAGE(
object));
625 page = GNC_PLUGIN_PAGE(
object);
632 case PROP_PAGE_COLOR:
635 case PROP_STATUSBAR_TEXT:
638 case PROP_USE_NEW_WINDOW:
641 case PROP_UI_DESCRIPTION:
645 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
660 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
661 g_return_if_fail (book != NULL);
663 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
664 priv->books = g_list_append (priv->books, book);
675 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
676 g_return_val_if_fail (book != NULL, FALSE);
678 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
679 for (item = priv->books; item; item = g_list_next (item))
681 if (item->data == book)
696 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
698 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
699 return (priv->books != NULL);
708 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
721 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
723 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
724 return priv->page_name;
736 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
738 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
740 g_free (priv->page_name);
742 priv->page_name = g_strdup (name);
745 klass = GNC_PLUGIN_PAGE_GET_CLASS (page);
761 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
763 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
764 return priv->page_long_name;
775 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
777 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
778 if (priv->page_long_name)
779 g_free (priv->page_long_name);
781 priv->page_long_name = g_strdup (name);
791 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
793 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
794 return priv->page_color;
804 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
806 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
807 if (priv->page_color)
808 g_free (priv->page_color);
811 priv->page_color = g_strdup (color);
816 gnc_plugin_page_focus_idle_destroy (
GncPluginPage *plugin_page)
819 priv->focus_source_id = 0;
825 gboolean on_current_page)
829 if (!on_current_page)
832 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
834 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(plugin_page);
836 if (G_LIKELY(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function))
841 if (priv->focus_source_id > 0)
842 g_source_remove (priv->focus_source_id);
844 priv->focus_source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
845 (GSourceFunc)(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function),
846 GNC_PLUGIN_PAGE(plugin_page),
847 (GDestroyNotify)gnc_plugin_page_focus_idle_destroy);
854 gnc_plugin_page_main_window_changed (GtkWindow *window,
858 GncPluginPage *current_plugin_page = GNC_PLUGIN_PAGE(
object);
860 gboolean on_current_page = FALSE;
863 if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE(current_plugin_page))
867 if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
870 if (current_plugin_page == plugin_page)
871 on_current_page = TRUE;
873 (GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page)(plugin_page, on_current_page);
885 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
887 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
889 priv->page_changed_id = g_signal_connect (G_OBJECT(page->
window),
"page_changed",
890 G_CALLBACK(gnc_plugin_page_main_window_changed),
895 (GNC_PLUGIN_PAGE_GET_CLASS(page)->focus_page)(page, TRUE);
905 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
907 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
909 if (priv->page_changed_id > 0)
911 g_signal_handler_disconnect (G_OBJECT(page->
window), priv->page_changed_id);
912 priv->page_changed_id = 0;
923 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
925 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
926 return priv->statusbar_text;
936 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
938 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
939 if (priv->statusbar_text)
940 g_free (priv->statusbar_text);
942 priv->statusbar_text = g_strdup (message);
952 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
954 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
955 return priv->use_new_window;
968 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
970 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
971 priv->use_new_window = use_new;
981 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
983 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
992 const char *ui_filename)
996 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
998 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1012 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1014 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1015 return priv->builder;
1025 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1027 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1028 return priv->menu_qualifier;
1033 const char *menu_qualifier)
1037 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
1039 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1041 priv->menu_qualifier = menu_qualifier;
1049 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1051 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1052 return priv->menu_popup_qualifier;
1057 const char *menu_qualifier)
1061 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
1063 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1065 priv->menu_popup_qualifier = menu_qualifier;
1069 GSimpleActionGroup *
1074 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1076 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1077 return priv->simple_action_group;
1080 GSimpleActionGroup *
1085 priv->simple_action_group = g_simple_action_group_new ();
1086 priv->simple_action_group_name = group_name;
1088 return priv->simple_action_group;
1096 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1098 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1100 return priv->simple_action_group_name;
1109 if (!GNC_IS_PLUGIN_PAGE(page))
1112 if (!GNC_PLUGIN_PAGE_GET_CLASS(page)->finish_pending)
1115 return (GNC_PLUGIN_PAGE_GET_CLASS(page)->finish_pending)(page);
GncPluginPage * gnc_plugin_page_recreate_page(GtkWidget *window, const gchar *page_type, GKeyFile *key_file, const gchar *page_group)
This function looks up a specific plugin type by name, and then calls a plugin specific function to c...
GtkWidget * gnc_plugin_page_get_window(GncPluginPage *page)
Retrieve a pointer to the GncMainWindow (GtkWindow) containing this page.
gboolean gnc_plugin_page_has_books(GncPluginPage *page)
Query a page to see if it has a reference to any book.
gboolean gnc_plugin_page_get_use_new_window(GncPluginPage *page)
Retrieve the "use new window" setting associated with this page.
const gchar * tab_icon
The relative name of the icon that should be shown on the tab for this page.
void gnc_plugin_page_set_menu_qualifier(GncPluginPage *page, const char *menu_qualifier)
Set a qualifier string for this page.
gboolean gnc_plugin_page_finish_pending(GncPluginPage *page)
Tell a page to finish any outstanding activities.
void(* focus_page)(GncPluginPage *plugin_page, gboolean on_current_page)
Perform plugin specific actions to set the focus.
void gnc_plugin_page_destroy_widget(GncPluginPage *plugin_page)
Destroy the display widget that corresponds to this plugin.
The instance data structure for a content plugin.
void gnc_plugin_page_set_statusbar_text(GncPluginPage *page, const char *name)
Set the statusbar text associated with this page.
void gnc_plugin_page_merge_actions(GncPluginPage *page)
Add the actions for a content page to the specified window.
GncPluginPage *(* recreate_page)(GtkWidget *window, GKeyFile *file, const gchar *group)
Create a new page based on the information saved during a previous instantiation of gnucash...
const gchar * gnc_plugin_page_get_page_long_name(GncPluginPage *page)
Retrieve the long name of this page.
void gnc_gobject_tracking_forget(GObject *object)
Tell gnucash to remember this object in the database.
void gnc_plugin_page_set_ui_description(GncPluginPage *page, const char *ui_filename)
Set an alternate UI for the specified page.
const gchar * gnc_plugin_page_get_page_name(GncPluginPage *page)
Retrieve the name of this page.
GSimpleActionGroup * gnc_plugin_page_get_action_group(GncPluginPage *page)
Retrieve the GSimpleActionGroup object associated with this page.
GtkBuilder * gnc_plugin_page_get_builder(GncPluginPage *page)
Retrieve the GtkBuilder object associated with this page.
char * ui_description
The group of all actions provided by this plugin.
GtkWidget * window
The window that contains the display widget for this plugin.
const gchar * gnc_plugin_page_get_page_color(GncPluginPage *page)
Retrieve the color of this page.
gboolean gnc_main_window_is_restoring_pages(GncMainWindow *window)
Check if the main window is restoring the plugin pages.
void gnc_plugin_page_set_page_long_name(GncPluginPage *page, const char *name)
Set the long name of this page.
const gchar * gnc_plugin_page_get_ui_description(GncPluginPage *page)
Retrieve the name of the XML UI file associated with this page.
GSimpleActionGroup * gnc_plugin_page_create_action_group(GncPluginPage *page, const gchar *group_name)
Create the GSimpleActionGroup object associated with this page.
const gchar * gnc_plugin_page_get_menu_qualifier(GncPluginPage *page)
Retrieve the menu qualifier for this page.
#define ENTER(format, args...)
Print a function entry debugging message.
const gchar * gnc_plugin_page_get_menu_popup_qualifier(GncPluginPage *page)
Retrieve the menu popup qualifier for this page.
void(* destroy_widget)(GncPluginPage *plugin_page)
Function called to destroy the display widget for a particular type of plugin.
void gnc_gobject_tracking_remember(GObject *object)
Tell gnucash to remember this object in the database.
The class data structure for a content plugin.
void gnc_plugin_page_set_use_new_window(GncPluginPage *page, gboolean use_new)
Set the "use new window" setting associated with this page.
void gnc_plugin_page_disconnect_page_changed(GncPluginPage *page)
Disconnect the page_changed_id signal callback.
gboolean gnc_plugin_page_has_book(GncPluginPage *page, QofBook *book)
Query a page to see if it has a reference to a given book.
const gchar * plugin_name
The textual name of this plugin.
Functions for adding plugins to a GnuCash window.
GtkWidget *(* create_widget)(GncPluginPage *plugin_page)
Function called to create the display widget for a particular type of plugin.
const gchar * gnc_plugin_page_get_simple_action_group_name(GncPluginPage *page)
Retrieve the simple action group name associated with this plugin page.
const gchar * gnc_plugin_page_get_statusbar_text(GncPluginPage *page)
Retrieve the statusbar text associated with this page.
void(* page_name_changed)(GncPluginPage *plugin_page, const gchar *name)
This function vector allows page specific actions to occur when the page name is changed.
void gnc_plugin_page_save_page(GncPluginPage *page, GKeyFile *key_file, const gchar *group_name)
Call the plugin specific function that will save the state of a content page to a disk...
All type declarations for the whole Gnucash engine.
void(* save_page)(GncPluginPage *page, GKeyFile *file, const gchar *group)
Save enough information about this page so that it can be recreated next time the user starts gnucash...
The instance private data for a content plugin.
void gnc_plugin_page_set_page_color(GncPluginPage *page, const char *color)
Set the color of this page.
void gnc_plugin_page_set_menu_popup_qualifier(GncPluginPage *page, const char *menu_qualifier)
Set a qualifier string for this page.
void gnc_plugin_page_inserted_cb(GncPluginPage *page, gpointer user_data)
Set up the page_changed callback for when the current page is changed.
Functions for adding plugins to a GnuCash window.
#define LEAVE(format, args...)
Print a function exit debugging message.
void gnc_plugin_page_set_page_name(GncPluginPage *page, const char *name)
Set the name of this page.
void gnc_plugin_page_add_book(GncPluginPage *page, QofBook *book)
Add a book reference to the specified page.
GAction * gnc_plugin_page_get_action(GncPluginPage *page, const gchar *name)
Retrieve a GAction object associated with this page.
void gnc_plugin_page_show_summarybar(GncPluginPage *page, gboolean visible)
Show/hide the summarybar associated with this page.
GtkWidget * summarybar
The summary bar widget (if any) that is associated with this plugin.
GtkWidget * gnc_plugin_page_create_widget(GncPluginPage *plugin_page)
Create the display widget that corresponds to this plugin.
const gchar * gnc_plugin_page_get_plugin_name(GncPluginPage *plugin_page)
Retrieve the textual name of a plugin.