48 #include <glib/gi18n.h> 54 #include "dialog-sx-editor.h" 55 #include "dialog-utils.h" 57 #include "gnc-component-manager.h" 59 #include "gnc-dense-cal.h" 63 #include "gnc-icons.h" 65 #include "gnc-plugin-page-sx-list.h" 66 #include "gnc-session.h" 67 #include "gnc-sx-instance-dense-cal-adapter.h" 69 #include "gnc-sx-list-tree-model-adapter.h" 76 #define G_LOG_DOMAIN "gnc.gui.plugin-page.sx-list" 78 G_GNUC_UNUSED
static QofLogModule log_module = GNC_MOD_GUI_SX;
80 #define PLUGIN_PAGE_SX_LIST_CM_CLASS "plugin-page-sx-list" 81 #define STATE_SECTION "SX Transaction List" 88 gint gnc_component_id;
90 GncSxInstanceDenseCalAdapter *dense_cal_model;
94 GtkTreeView* tree_view;
99 #define GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(o) \ 100 ((GncPluginPageSxListPrivate*)g_type_instance_get_private ((GTypeInstance*)o, GNC_TYPE_PLUGIN_PAGE_SX_LIST)) 102 static GObjectClass *parent_class = NULL;
110 static void gnc_plugin_page_sx_list_dispose (GObject *
object);
111 static void gnc_plugin_page_sx_list_finalize (GObject *
object);
113 static GtkWidget *gnc_plugin_page_sx_list_create_widget (
GncPluginPage *plugin_page);
114 static void gnc_plugin_page_sx_list_destroy_widget (
GncPluginPage *plugin_page);
115 static void gnc_plugin_page_sx_list_save_page (
GncPluginPage *plugin_page, GKeyFile *file,
const gchar *group);
116 static GncPluginPage *gnc_plugin_page_sx_list_recreate_page (GtkWidget *window, GKeyFile *file,
const gchar *group);
118 static void gppsl_row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
120 static void gnc_plugin_page_sx_list_cmd_new (GtkAction *action,
GncPluginPageSxList *page);
121 static void gnc_plugin_page_sx_list_cmd_edit (GtkAction *action,
GncPluginPageSxList *page);
122 static void gnc_plugin_page_sx_list_cmd_delete (GtkAction *action,
GncPluginPageSxList *page);
123 static void gnc_plugin_page_sx_list_cmd_refresh (GtkAction *action,
GncPluginPageSxList *page);
126 static GtkActionEntry gnc_plugin_page_sx_list_actions [] =
128 {
"SxListAction", NULL, N_(
"_Scheduled"), NULL, NULL, NULL },
130 "SxListNewAction", GNC_ICON_NEW_ACCOUNT, N_(
"_New"), NULL,
131 N_(
"Create a new scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new)
134 "SxListEditAction", GNC_ICON_EDIT_ACCOUNT, N_(
"_Edit"), NULL,
135 N_(
"Edit the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit)
138 "SxListDeleteAction", GNC_ICON_DELETE_ACCOUNT, N_(
"_Delete"), NULL,
139 N_(
"Delete the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_delete)
145 "ViewRefreshAction",
"view-refresh", N_(
"_Refresh"),
"<primary>r",
146 N_(
"Refresh this window"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_refresh)
150 static guint gnc_plugin_page_sx_list_n_actions = G_N_ELEMENTS(gnc_plugin_page_sx_list_actions);
157 if (
object && GNC_IS_PLUGIN_PAGE_SX_LIST (object->data))
158 plugin_page = GNC_PLUGIN_PAGE_SX_LIST (object->data);
163 return GNC_PLUGIN_PAGE(plugin_page);
172 gnc_plugin_page_sx_list_focus_widget (
GncPluginPage *sx_plugin_page)
174 if (GNC_IS_PLUGIN_PAGE_SX_LIST(sx_plugin_page))
177 GtkTreeView *tree_view = priv->tree_view;
179 if (GTK_IS_TREE_VIEW(tree_view))
181 if (!gtk_widget_is_focus (GTK_WIDGET(tree_view)))
182 gtk_widget_grab_focus (GTK_WIDGET(tree_view));
188 G_DEFINE_TYPE_WITH_PRIVATE(
GncPluginPageSxList, gnc_plugin_page_sx_list, GNC_TYPE_PLUGIN_PAGE)
193 GObjectClass *object_class = G_OBJECT_CLASS(klass);
196 parent_class = g_type_class_peek_parent(klass);
198 object_class->dispose = gnc_plugin_page_sx_list_dispose;
199 object_class->finalize = gnc_plugin_page_sx_list_finalize;
201 gnc_plugin_class->
tab_icon = GNC_ICON_ACCOUNT;
202 gnc_plugin_class->
plugin_name = GNC_PLUGIN_PAGE_SX_LIST_NAME;
203 gnc_plugin_class->
create_widget = gnc_plugin_page_sx_list_create_widget;
204 gnc_plugin_class->
destroy_widget = gnc_plugin_page_sx_list_destroy_widget;
205 gnc_plugin_class->
save_page = gnc_plugin_page_sx_list_save_page;
206 gnc_plugin_class->
recreate_page = gnc_plugin_page_sx_list_recreate_page;
214 GtkActionGroup *action_group;
218 parent = GNC_PLUGIN_PAGE(plugin_page);
219 g_object_set(G_OBJECT(plugin_page),
220 "page-name", _(
"Scheduled Transactions"),
221 "page-uri",
"default:",
222 "ui-description",
"gnc-plugin-page-sx-list-ui.xml",
228 "GncPluginPageSxListActions");
229 gtk_action_group_add_actions (action_group,
230 gnc_plugin_page_sx_list_actions,
231 gnc_plugin_page_sx_list_n_actions,
238 gnc_plugin_page_sx_list_dispose (GObject *
object)
243 page = GNC_PLUGIN_PAGE_SX_LIST(
object);
244 g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
245 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
246 g_return_if_fail (priv != NULL);
248 g_return_if_fail (!priv->disposed);
249 priv->disposed = TRUE;
251 g_object_unref (G_OBJECT(priv->dense_cal_model));
252 priv->dense_cal_model = NULL;
253 g_object_unref (GTK_WIDGET(priv->gdcal));
255 g_object_unref (G_OBJECT(priv->instances));
256 priv->instances = NULL;
258 G_OBJECT_CLASS(parent_class)->dispose (
object);
263 gnc_plugin_page_sx_list_finalize (GObject *
object)
268 page = GNC_PLUGIN_PAGE_SX_LIST(
object);
269 g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
270 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
271 g_return_if_fail (priv != NULL);
273 G_OBJECT_CLASS(parent_class)->finalize (
object);
279 gnc_plugin_page_sx_list_refresh_cb (GHashTable *changes, gpointer user_data)
284 g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
290 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
291 gtk_widget_queue_draw (priv->widget);
296 gnc_plugin_page_sx_list_close_cb (gpointer user_data)
304 gppsl_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
307 GtkAction *edit_action, *delete_action;
308 gboolean selection_state = TRUE;
310 page = GNC_PLUGIN_PAGE(user_data);
314 = gtk_tree_selection_count_selected_rows (selection) == 0
317 gtk_action_set_sensitive (edit_action, selection_state);
318 gtk_action_set_sensitive (delete_action, selection_state);
327 if (reset && priv->selected_list)
329 g_list_free (priv->selected_list);
330 priv->selected_list = NULL;
333 priv->selected_list = g_list_prepend (priv->selected_list, sx);
341 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->tree_view));
342 gboolean found = FALSE;
344 if (priv->selected_list)
347 for (GList *list = priv->selected_list; list != NULL; list = list->next)
349 SchedXaction *sx = list->data;
350 GtkTreePath *path = gtk_tree_path_new_first ();
353 while (gnc_tree_view_path_is_valid (GNC_TREE_VIEW(priv->tree_view), path))
355 SchedXaction *sx_tmp = gnc_tree_view_sx_list_get_sx_from_path (
356 GNC_TREE_VIEW_SX_LIST(priv->tree_view), path);
362 gtk_tree_path_next (path);
365 gtk_tree_selection_select_path (selection, path);
367 gtk_tree_path_free (path);
373 GtkTreePath *path = gtk_tree_path_new_first ();
374 gtk_tree_selection_select_path (selection, path);
375 gtk_tree_path_free (path);
381 gnc_plugin_page_sx_list_create_widget (
GncPluginPage *plugin_page)
390 page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
391 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
392 if (priv->widget != NULL)
396 widget = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
397 priv->widget = widget;
398 gtk_widget_show (priv->widget);
401 gtk_widget_set_name (GTK_WIDGET(priv->widget),
"gnc-id-sx-page");
404 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
405 gtk_box_set_homogeneous (GTK_BOX(vbox), FALSE);
406 gtk_paned_pack1 (GTK_PANED(widget), vbox, TRUE, FALSE);
408 label = gtk_label_new (_(
"Transactions"));
409 gnc_widget_style_context_add_class (GTK_WIDGET(label),
"gnc-class-strong");
410 gtk_widget_set_margin_start (GTK_WIDGET(label), 6);
411 gnc_label_set_alignment (label, 0.0, 0);
412 gtk_widget_show (label);
413 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
414 gtk_widget_show (vbox);
417 swin = gtk_scrolled_window_new (NULL, NULL);
418 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(swin),
419 GTK_POLICY_AUTOMATIC,
420 GTK_POLICY_AUTOMATIC);
421 gtk_box_pack_start (GTK_BOX(vbox), swin, TRUE, TRUE, 5);
422 gtk_widget_show (swin);
428 gtk_paned_set_position (GTK_PANED(priv->widget), 160);
433 g_date_clear (&end, 1);
435 g_date_add_years (&end, 1);
440 GtkAction *edit_action, *delete_action;
443 gtk_action_set_sensitive (edit_action, FALSE);
444 gtk_action_set_sensitive (delete_action, FALSE);
448 GtkTreeSelection *selection;
449 GtkTreePath *path = gtk_tree_path_new_first ();
451 priv->tree_view = GTK_TREE_VIEW(gnc_tree_view_sx_list_new (priv->instances));
452 g_object_set (G_OBJECT(priv->tree_view),
453 "state-section", STATE_SECTION,
454 "show-column-menu", TRUE,
456 gtk_container_add (GTK_CONTAINER( swin ), GTK_WIDGET(priv->tree_view));
458 selection = gtk_tree_view_get_selection (priv->tree_view);
459 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
460 gtk_tree_selection_select_path (selection, path);
461 gtk_tree_path_free (path);
463 g_signal_connect (G_OBJECT(selection),
"changed", (GCallback)gppsl_selection_changed_cb, (gpointer)page);
464 g_signal_connect (G_OBJECT(priv->tree_view),
"row-activated", (GCallback)gppsl_row_activated_cb, (gpointer)page);
465 g_signal_connect (G_OBJECT(gtk_tree_view_get_model (GTK_TREE_VIEW(priv->tree_view))),
466 "model-populated", (GCallback)gppsl_model_populated_cb, (gpointer)page);
470 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
471 gtk_box_set_homogeneous (GTK_BOX(vbox), FALSE);
472 gtk_paned_pack2 (GTK_PANED(widget), vbox, TRUE, FALSE);
474 label = gtk_label_new (_(
"Upcoming Transactions"));
475 gnc_widget_style_context_add_class (GTK_WIDGET(label),
"gnc-class-strong");
476 gtk_widget_set_margin_start (GTK_WIDGET(label), 6);
477 gnc_label_set_alignment (label, 0.0, 0);
478 gtk_widget_show (label);
480 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
481 gtk_widget_show (vbox);
484 swin = gtk_scrolled_window_new (NULL, NULL);
485 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(swin),
486 GTK_POLICY_AUTOMATIC,
487 GTK_POLICY_AUTOMATIC);
488 gtk_box_pack_start (GTK_BOX(vbox), swin, TRUE, TRUE, 5);
489 gtk_widget_show (swin);
492 priv->dense_cal_model = gnc_sx_instance_dense_cal_adapter_new (GNC_SX_INSTANCE_MODEL(priv->instances));
493 priv->gdcal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model (GNC_DENSE_CAL_MODEL(priv->dense_cal_model)));
494 g_object_ref_sink (priv->gdcal);
496 gnc_dense_cal_set_months_per_col (priv->gdcal, 4);
497 gnc_dense_cal_set_num_months (priv->gdcal, 12);
499 gtk_container_add (GTK_CONTAINER(swin), GTK_WIDGET(priv->gdcal));
502 priv->gnc_component_id = gnc_register_gui_component (
"plugin-page-sx-list",
503 gnc_plugin_page_sx_list_refresh_cb,
504 gnc_plugin_page_sx_list_close_cb,
506 gnc_gui_component_set_session (priv->gnc_component_id,
507 gnc_get_current_session ());
509 g_signal_connect (G_OBJECT(plugin_page),
"inserted",
518 gnc_plugin_page_sx_list_destroy_widget (
GncPluginPage *plugin_page)
523 page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
524 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
530 g_idle_remove_by_data (plugin_page);
534 g_object_unref (G_OBJECT(priv->widget));
538 if (priv->selected_list)
539 g_list_free (priv->selected_list);
541 if (priv->gnc_component_id)
543 gnc_unregister_gui_component (priv->gnc_component_id);
544 priv->gnc_component_id = 0;
557 gnc_plugin_page_sx_list_save_page (
GncPluginPage *plugin_page,
559 const gchar *group_name)
564 g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(plugin_page));
565 g_return_if_fail (key_file != NULL);
566 g_return_if_fail (group_name != NULL);
568 page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
569 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
571 g_key_file_set_integer (key_file, group_name,
"dense_cal_num_months",
572 gnc_dense_cal_get_num_months (priv->gdcal));
574 g_key_file_set_integer (key_file, group_name,
"paned_position",
575 gtk_paned_get_position (GTK_PANED(priv->widget)));
588 gnc_plugin_page_sx_list_recreate_page (GtkWidget *window,
590 const gchar *group_name)
595 g_return_val_if_fail (key_file, NULL);
596 g_return_val_if_fail (group_name, NULL);
600 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
607 gint num_months = g_key_file_get_integer (key_file, group_name,
"dense_cal_num_months", &err);
609 gnc_dense_cal_set_num_months (priv->gdcal, num_months);
616 gint paned_position = g_key_file_get_integer (key_file, group_name,
617 "paned_position", &err);
619 gtk_paned_set_position (GTK_PANED(priv->widget), paned_position);
624 return GNC_PLUGIN_PAGE(page);
632 SchedXaction *new_sx;
633 gboolean new_sx_flag = TRUE;
641 g_date_clear (&now, 1);
643 recurrenceSet (r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE);
645 schedule = g_list_append (schedule, r);
648 gnc_ui_scheduled_xaction_editor_dialog_create (window, new_sx, new_sx_flag);
649 gppsl_update_selected_list (page, TRUE, new_sx);
657 g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
659 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
660 gtk_widget_queue_draw (priv->widget);
664 _edit_sx(gpointer data, gpointer user_data)
666 gnc_ui_scheduled_xaction_editor_dialog_create (GTK_WINDOW(user_data),
667 (SchedXaction*)data, FALSE);
671 _argument_reorder_fn (GtkTreePath* list_path_data,
GncTreeViewSxList* user_tree_view)
673 return gnc_tree_view_sx_list_get_sx_from_path (user_tree_view, list_path_data);
682 GtkTreeSelection *selection;
683 GList *selected_paths, *to_edit;
686 selection = gtk_tree_view_get_selection (priv->tree_view);
687 selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
690 g_warning (
"no selection edit.");
695 (GncGMapFunc)_argument_reorder_fn,
698 gppsl_update_selected_list (page, TRUE, NULL);
699 for (GList *list = to_edit; list != NULL; list = list->next)
701 DEBUG (
"to-edit [%s]\n", xaccSchedXactionGetName ((SchedXaction*)list->data));
702 gppsl_update_selected_list (page, FALSE, list->data);
705 g_list_foreach (to_edit, (GFunc)_edit_sx, window);
706 g_list_free (to_edit);
707 g_list_foreach (selected_paths, (GFunc)gtk_tree_path_free, NULL);
708 g_list_free (selected_paths);
712 gppsl_row_activated_cb (GtkTreeView *tree_view,
714 GtkTreeViewColumn *column,
721 SchedXaction *sx = gnc_tree_view_sx_list_get_sx_from_path (
722 GNC_TREE_VIEW_SX_LIST(priv->tree_view), path);
723 gnc_ui_scheduled_xaction_editor_dialog_create (window, sx, FALSE);
724 gppsl_update_selected_list (page, TRUE, sx);
729 _destroy_sx(gpointer data, gpointer user_data)
732 SchedXaction *sx = (SchedXaction*)data;
734 book = gnc_get_current_book ();
735 sxes = gnc_book_get_schedxactions (book);
736 gnc_sxes_del_sx (sxes, sx);
737 gnc_sx_begin_edit (sx);
746 GtkTreeSelection *selection;
747 GList *selected_paths, *to_delete = NULL;
750 gchar *message = NULL;
753 selection = gtk_tree_view_get_selection (priv->tree_view);
754 selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
757 g_warning (
"no selection for delete.");
762 (GncGMapFunc)_argument_reorder_fn,
767 length = g_list_length (to_delete);
770 message = g_strdup_printf (ngettext (
"Do you really want to delete this scheduled transaction?",
771 "Do you really want to delete %d scheduled transactions?",
774 if (gnc_verify_dialog (window, FALSE,
"%s", message))
776 gppsl_update_selected_list (page, TRUE, NULL);
777 for (GList *list = to_delete; list != NULL; list = list->next)
779 DEBUG(
"to-delete [%s]\n", xaccSchedXactionGetName ((SchedXaction*)list->data));
780 gppsl_update_selected_list (page, FALSE, list->data);
782 g_list_foreach (to_delete, (GFunc)_destroy_sx, NULL);
786 g_list_free (to_delete);
787 g_list_foreach (selected_paths, (GFunc)gtk_tree_path_free, NULL);
788 g_list_free (selected_paths);
GtkWidget * gnc_plugin_page_get_window(GncPluginPage *page)
Retrieve a pointer to the GncMainWindow (GtkWindow) containing this page.
void gnc_sx_set_schedule(SchedXaction *sx, GList *schedule)
GList * gnc_g_list_map(GList *list, GncGMapFunc fn, gpointer user_data)
const gchar * tab_icon
The relative name of the icon that should be shown on the tab for this page.
gboolean(* focus_page_function)(GncPluginPage *plugin_page)
This function performs specific actions to set the focus on a specific widget.
GList * gnc_sx_get_schedule(const SchedXaction *sx)
The instance data structure for a content plugin.
const GList * gnc_gobject_tracking_get_list(const gchar *name)
Get a list of all known objects of a specified type.
Date and Time handling routines.
utility functions for the GnuCash UI
GncTreeView implementation for Scheduled Transaction List.
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...
#define DEBUG(format, args...)
Print a debugging message.
Functions that are supported by all types of windows.
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
API for Transactions and Splits (journal entries)
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
Functions for adding content to a window.
void(* destroy_widget)(GncPluginPage *plugin_page)
Function called to destroy the display widget for a particular type of plugin.
The class data structure for a content plugin.
void gnc_plugin_page_disconnect_page_changed(GncPluginPage *page)
Disconnect the page_changed_id signal callback.
Anchor Scheduled Transaction info in a book.
const gchar * plugin_name
The textual name of this plugin.
GtkWidget *(* create_widget)(GncPluginPage *plugin_page)
Function called to create the display widget for a particular type of plugin.
Additional event handling code.
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...
GtkAction * gnc_plugin_page_get_action(GncPluginPage *page, const gchar *name)
Retrieve a GtkAction object associated with this page.
GncSxInstanceModel * gnc_sx_get_instances(const GDate *range_end, gboolean include_disabled)
Allocates a new SxInstanceModel and fills it with generated instances for all scheduled transactions ...
void gnc_plugin_page_inserted_cb(GncPluginPage *page, gpointer user_data)
Set up the page_changed callback for when the current page is changed.
void gnc_main_window_close_page(GncPluginPage *page)
Remove a data plugin page from a window and display the previous page.
#define GNC_TYPE_PLUGIN_PAGE_SX_LIST
Functions providing a list of scheduled transactions as a plugin page.
GncPluginPage * gnc_plugin_page_sx_list_new(void)
void gnc_plugin_page_add_book(GncPluginPage *page, QofBook *book)
Add a book reference to the specified page.
SchedXaction * xaccSchedXactionMalloc(QofBook *book)
Creates and initializes a scheduled transaction.
GtkActionGroup * gnc_plugin_page_create_action_group(GncPluginPage *page, const gchar *group_name)
Create the GtkActionGroup object associated with this page.
gint gnc_list_length_cmp(const GList *list, size_t len)
Scans the GList elements the minimum number of iterations required to test it against a specified siz...
API for Transactions and Splits (journal entries)
void xaccSchedXactionDestroy(SchedXaction *sx)
Cleans up and frees a SchedXaction and its associated data.
Commodity handling public routines.