45 static QofLogModule log_module = GNC_MOD_GUI;
47 static void gnc_plugin_page_constructed (GObject *
object);
48 static void gnc_plugin_page_finalize (GObject *
object);
49 static void gnc_plugin_page_set_property (GObject *
object,
53 static void gnc_plugin_page_get_property (GObject *
object,
58 static void gnc_plugin_page_default_focus (
GncPluginPage *plugin_page,
59 gboolean on_current_page);
81 static guint signals[LAST_SIGNAL] = { 0 };
85 typedef struct _GncPluginPagePrivate
91 GSimpleActionGroup *simple_action_group;
92 const gchar *simple_action_group_name;
93 const gchar *menu_qualifier;
94 const gchar *menu_popup_qualifier;
98 gboolean use_new_window;
101 gchar *page_long_name;
104 gchar *statusbar_text;
106 gulong page_changed_id;
107 guint focus_source_id;
111 G_DEFINE_TYPE_WITH_CODE(
GncPluginPage, gnc_plugin_page, G_TYPE_OBJECT,
114 #define GNC_PLUGIN_PAGE_GET_PRIVATE(o) \ 115 ((GncPluginPagePrivate*)gnc_plugin_page_get_instance_private((GncPluginPage*)o)) 128 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page), NULL);
130 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
131 g_return_val_if_fail (klass != NULL, NULL);
143 g_object_ref (widget);
157 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
159 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
160 g_return_if_fail (klass != NULL);
172 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
191 const gchar *group_name)
195 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
196 g_return_if_fail (key_file != NULL);
197 g_return_if_fail (group_name != NULL);
200 klass = GNC_PLUGIN_PAGE_GET_CLASS(page);
201 g_return_if_fail (klass != NULL);
202 g_return_if_fail (klass->
save_page != NULL);
204 klass->
save_page (page, key_file, group_name);
214 const gchar *page_type,
216 const gchar *page_group)
222 ENTER(
"type %s, keyfile %p, group %s", page_type, key_file, page_group);
223 type = g_type_from_name (page_type);
226 LEAVE(
"Cannot find type named %s", page_type);
230 klass = g_type_class_ref (type);
233 const gchar *type_name = g_type_name (type);
234 LEAVE(
"Cannot create class %s(%s)", page_type, type_name ? type_name :
"invalid type");
240 LEAVE(
"Class %shas no recreate function.", page_type);
241 g_type_class_unref (klass);
246 g_type_class_unref (klass);
256 GError *error = NULL;
259 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
261 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
264 priv->builder = gtk_builder_new ();
266 resource = g_strconcat (GNUCASH_RESOURCE_PREFIX
"/", priv->
ui_description, NULL);
268 gtk_builder_set_translation_domain (priv->builder, PROJECT_NAME);
270 gtk_builder_add_from_resource (priv->builder, resource, &error);
274 g_critical (
"Failed to load ui resource %s, Error %s", resource, error->message);
275 g_error_free (error);
286 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
287 g_return_val_if_fail (name != NULL, NULL);
289 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
290 if (!priv->simple_action_group)
292 return g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group), name);
302 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page), NULL);
304 klass = GNC_PLUGIN_PAGE_GET_CLASS(plugin_page);
305 g_return_val_if_fail (klass != NULL, NULL);
315 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
317 g_signal_emit (G_OBJECT(plugin_page), signals[INSERTED], 0);
323 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
325 g_signal_emit (G_OBJECT(plugin_page), signals[REMOVED], 0);
331 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
333 g_signal_emit (G_OBJECT(plugin_page), signals[SELECTED], 0);
339 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
341 g_signal_emit (G_OBJECT(plugin_page), signals[UNSELECTED], 0);
354 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
356 gobject_class->constructed = gnc_plugin_page_constructed;
357 gobject_class->finalize = gnc_plugin_page_finalize;
358 gobject_class->set_property = gnc_plugin_page_set_property;
359 gobject_class->get_property = gnc_plugin_page_get_property;
363 klass->
focus_page = gnc_plugin_page_default_focus;
365 g_object_class_install_property
368 g_param_spec_string (
"page-name",
370 "The name of this page. This value is " 371 "used to generate the notebook tab and " 372 "menu items, and also the window title " 373 "when this page is visible.",
377 g_object_class_install_property
380 g_param_spec_string (
"page-color",
382 "The color of this page. This value is " 383 "used to generate the notebook tab color " 384 "when this page is visible.",
388 g_object_class_install_property
391 g_param_spec_string (
"statusbar-text",
393 "The text to be displayed in the statusbar " 394 "at the bottom of the window when this page " 399 g_object_class_install_property
402 g_param_spec_boolean (
"use-new-window",
404 "When TRUE a new top level window will be " 405 "created to hold this page.",
409 g_object_class_install_property
412 g_param_spec_string (
"ui-description",
413 "UI Description File",
414 "The filename containing the XML data that " 415 "describes this pages menus and toolbars.",
421 signals[INSERTED] = g_signal_new (
"inserted",
422 G_OBJECT_CLASS_TYPE (klass),
426 g_cclosure_marshal_VOID__VOID,
429 signals[REMOVED] = g_signal_new (
"removed",
430 G_OBJECT_CLASS_TYPE (klass),
434 g_cclosure_marshal_VOID__VOID,
437 signals[SELECTED] = g_signal_new (
"selected",
438 G_OBJECT_CLASS_TYPE (klass),
442 g_cclosure_marshal_VOID__VOID,
445 signals[UNSELECTED] = g_signal_new (
"unselected",
446 G_OBJECT_CLASS_TYPE (klass),
450 g_cclosure_marshal_VOID__VOID,
465 priv->page_name = NULL;
466 priv->page_color = NULL;
467 priv->page_changed_id = 0;
468 priv->focus_source_id = 0;
469 priv->menu_qualifier = NULL;
482 gnc_plugin_page_constructed (GObject *obj)
486 G_OBJECT_CLASS (gnc_plugin_page_parent_class)->constructed (obj);
497 gnc_plugin_page_finalize (GObject *
object)
502 page = GNC_PLUGIN_PAGE(
object);
504 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
510 g_free (priv->page_name);
512 if (priv->page_long_name)
513 g_free (priv->page_long_name);
515 if (priv->page_color)
516 g_free (priv->page_color);
518 if (priv->statusbar_text)
519 g_free (priv->statusbar_text);
523 g_list_free (priv->books);
528 g_object_unref (priv->builder);
533 G_OBJECT_CLASS(gnc_plugin_page_parent_class)->finalize (
object);
564 gnc_plugin_page_get_property (GObject *
object,
572 g_return_if_fail(GNC_IS_PLUGIN_PAGE(
object));
574 page = GNC_PLUGIN_PAGE(
object);
575 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
579 g_value_set_string (value, priv->page_name);
581 case PROP_PAGE_COLOR:
582 g_value_set_string (value, priv->page_color);
584 case PROP_STATUSBAR_TEXT:
585 g_value_set_string (value, priv->statusbar_text);
587 case PROP_USE_NEW_WINDOW:
588 g_value_set_boolean (value, priv->use_new_window);
590 case PROP_UI_DESCRIPTION:
594 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
617 gnc_plugin_page_set_property (GObject *
object,
624 g_return_if_fail(GNC_IS_PLUGIN_PAGE(
object));
626 page = GNC_PLUGIN_PAGE(
object);
633 case PROP_PAGE_COLOR:
636 case PROP_STATUSBAR_TEXT:
639 case PROP_USE_NEW_WINDOW:
642 case PROP_UI_DESCRIPTION:
646 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
661 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
662 g_return_if_fail (book != NULL);
664 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
665 priv->books = g_list_append (priv->books, book);
676 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
677 g_return_val_if_fail (book != NULL, FALSE);
679 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
680 for (item = priv->books; item; item = g_list_next (item))
682 if (item->data == book)
697 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
699 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
700 return (priv->books != NULL);
709 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
722 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
724 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
725 return priv->page_name;
737 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
739 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
741 g_free (priv->page_name);
743 priv->page_name = g_strdup (name);
746 klass = GNC_PLUGIN_PAGE_GET_CLASS (page);
762 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
764 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
765 return priv->page_long_name;
776 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
778 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
779 if (priv->page_long_name)
780 g_free (priv->page_long_name);
782 priv->page_long_name = g_strdup (name);
792 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
794 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
795 return priv->page_color;
805 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
807 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
808 if (priv->page_color)
809 g_free (priv->page_color);
812 priv->page_color = g_strdup (color);
817 gnc_plugin_page_focus_idle_destroy (
GncPluginPage *plugin_page)
820 priv->focus_source_id = 0;
826 gboolean on_current_page)
830 if (!on_current_page)
833 g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));
835 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(plugin_page);
837 if (G_LIKELY(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function))
842 if (priv->focus_source_id > 0)
843 g_source_remove (priv->focus_source_id);
845 priv->focus_source_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
846 (GSourceFunc)(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function),
847 GNC_PLUGIN_PAGE(plugin_page),
848 (GDestroyNotify)gnc_plugin_page_focus_idle_destroy);
855 gnc_plugin_page_main_window_changed (GtkWindow *window,
859 GncPluginPage *current_plugin_page = GNC_PLUGIN_PAGE(
object);
861 gboolean on_current_page = FALSE;
864 if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE(current_plugin_page))
868 if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
871 if (current_plugin_page == plugin_page)
872 on_current_page = TRUE;
874 (GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page)(plugin_page, on_current_page);
886 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
888 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
890 priv->page_changed_id = g_signal_connect (G_OBJECT(page->
window),
"page_changed",
891 G_CALLBACK(gnc_plugin_page_main_window_changed),
896 (GNC_PLUGIN_PAGE_GET_CLASS(page)->focus_page)(page, TRUE);
906 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
908 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
910 if (priv->page_changed_id > 0)
912 g_signal_handler_disconnect (G_OBJECT(page->
window), priv->page_changed_id);
913 priv->page_changed_id = 0;
924 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
926 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
927 return priv->statusbar_text;
937 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
939 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
940 if (priv->statusbar_text)
941 g_free (priv->statusbar_text);
943 priv->statusbar_text = g_strdup (message);
953 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
955 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
956 return priv->use_new_window;
969 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
971 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
972 priv->use_new_window = use_new;
982 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), FALSE);
984 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
993 const char *ui_filename)
997 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
999 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1013 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1015 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1016 return priv->builder;
1026 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1028 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1029 return priv->menu_qualifier;
1034 const char *menu_qualifier)
1038 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
1040 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1042 priv->menu_qualifier = menu_qualifier;
1050 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1052 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1053 return priv->menu_popup_qualifier;
1058 const char *menu_qualifier)
1062 g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));
1064 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1066 priv->menu_popup_qualifier = menu_qualifier;
1070 GSimpleActionGroup *
1075 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1077 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1078 return priv->simple_action_group;
1081 GSimpleActionGroup *
1086 priv->simple_action_group = g_simple_action_group_new ();
1087 priv->simple_action_group_name = group_name;
1089 return priv->simple_action_group;
1097 g_return_val_if_fail (GNC_IS_PLUGIN_PAGE(page), NULL);
1099 priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
1101 return priv->simple_action_group_name;
1110 if (!GNC_IS_PLUGIN_PAGE(page))
1113 if (!GNC_PLUGIN_PAGE_GET_CLASS(page)->finish_pending)
1116 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.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
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.