48 #include <glib/gi18n.h>
55 #include "dialog-sx-editor.h"
57 #include "dialog-sx-editor2.h"
59 #include "dialog-utils.h"
61 #include "gnc-component-manager.h"
62 #include "gnc-dense-cal.h"
66 #include "gnc-icons.h"
68 #include "gnc-plugin-page-sx-list.h"
69 #include "gnc-session.h"
70 #include "gnc-sx-instance-dense-cal-adapter.h"
72 #include "gnc-sx-list-tree-model-adapter.h"
78 #define G_LOG_DOMAIN "gnc.gui.plugin-page.sx-list"
80 G_GNUC_UNUSED
static QofLogModule log_module = GNC_MOD_GUI_SX;
82 #define PLUGIN_PAGE_SX_LIST_CM_CLASS "plugin-page-sx-list"
83 #define STATE_SECTION "SX Transaction List"
90 gint gnc_component_id;
96 GtkTreeView* tree_view;
100 #define GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(o) \
101 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_PAGE_SX_LIST, GncPluginPageSxListPrivate))
103 static GObjectClass *parent_class = NULL;
111 static void gnc_plugin_page_sx_list_dispose(GObject *
object);
112 static void gnc_plugin_page_sx_list_finalize(GObject *
object);
114 static GtkWidget *gnc_plugin_page_sx_list_create_widget (
GncPluginPage *plugin_page);
115 static void gnc_plugin_page_sx_list_destroy_widget (
GncPluginPage *plugin_page);
116 static void gnc_plugin_page_sx_list_save_page (
GncPluginPage *plugin_page, GKeyFile *file,
const gchar *group);
117 static GncPluginPage *gnc_plugin_page_sx_list_recreate_page (GtkWidget *window, GKeyFile *file,
const gchar *group);
119 static void gppsl_row_activated_cb(GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
122 static void gnc_plugin_page_sx_list_cmd_edit(GtkAction *action,
GncPluginPageSxList *page);
124 static void gnc_plugin_page_sx_list_cmd_new2(GtkAction *action,
GncPluginPageSxList *page);
125 static void gnc_plugin_page_sx_list_cmd_edit2(GtkAction *action,
GncPluginPageSxList *page);
127 static void gnc_plugin_page_sx_list_cmd_delete(GtkAction *action,
GncPluginPageSxList *page);
130 static GtkActionEntry gnc_plugin_page_sx_list_actions [] =
132 {
"SxListAction", NULL, N_(
"_Scheduled"), NULL, NULL, NULL },
134 "SxListNewAction", GNC_STOCK_NEW_ACCOUNT, N_(
"_New"), NULL,
135 N_(
"Create a new scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new)
137 #ifdef REGISTER2_ENABLED
140 "SxListNewAction2", GNC_STOCK_NEW_ACCOUNT, N_(
"_New 2"), NULL,
141 N_(
"Create a new scheduled transaction 2"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new2)
146 "SxListEditAction", GNC_STOCK_EDIT_ACCOUNT, N_(
"_Edit"), NULL,
147 N_(
"Edit the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit)
149 #ifdef REGISTER2_ENABLED
152 "SxListEditAction2", GNC_STOCK_EDIT_ACCOUNT, N_(
"_Edit 2"), NULL,
153 N_(
"Edit the selected scheduled transaction 2"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit2)
158 "SxListDeleteAction", GNC_STOCK_DELETE_ACCOUNT, N_(
"_Delete"), NULL,
159 N_(
"Delete the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_delete)
163 static guint gnc_plugin_page_sx_list_n_actions = G_N_ELEMENTS (gnc_plugin_page_sx_list_actions);
169 static GType gnc_plugin_page_sx_list_type = 0;
171 if (gnc_plugin_page_sx_list_type == 0)
173 static const GTypeInfo our_info =
178 (GClassInitFunc) gnc_plugin_page_sx_list_class_init,
183 (GInstanceInitFunc) gnc_plugin_page_sx_list_init
186 gnc_plugin_page_sx_list_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
187 GNC_PLUGIN_PAGE_SX_LIST_NAME,
191 return gnc_plugin_page_sx_list_type;
200 if (
object && GNC_IS_PLUGIN_PAGE_SX_LIST (object->data))
201 plugin_page = GNC_PLUGIN_PAGE_SX_LIST (object->data);
206 return GNC_PLUGIN_PAGE(plugin_page);
213 GObjectClass *object_class = G_OBJECT_CLASS(klass);
216 parent_class = g_type_class_peek_parent(klass);
218 object_class->dispose = gnc_plugin_page_sx_list_dispose;
219 object_class->finalize = gnc_plugin_page_sx_list_finalize;
221 gnc_plugin_class->
tab_icon = GNC_STOCK_ACCOUNT;
222 gnc_plugin_class->
plugin_name = GNC_PLUGIN_PAGE_SX_LIST_NAME;
223 gnc_plugin_class->
create_widget = gnc_plugin_page_sx_list_create_widget;
224 gnc_plugin_class->
destroy_widget = gnc_plugin_page_sx_list_destroy_widget;
225 gnc_plugin_class->
save_page = gnc_plugin_page_sx_list_save_page;
226 gnc_plugin_class->
recreate_page = gnc_plugin_page_sx_list_recreate_page;
235 GtkActionGroup *action_group;
240 parent = GNC_PLUGIN_PAGE(plugin_page);
241 #ifdef REGISTER2_ENABLED
242 g_object_set(G_OBJECT(plugin_page),
243 "page-name", _(
"Scheduled Transactions"),
244 "page-uri",
"default:",
245 "ui-description",
"gnc-plugin-page-sx-list2-ui.xml",
248 g_object_set(G_OBJECT(plugin_page),
249 "page-name", _(
"Scheduled Transactions"),
250 "page-uri",
"default:",
251 "ui-description",
"gnc-plugin-page-sx-list-ui.xml",
258 "GncPluginPageSxListActions");
259 gtk_action_group_add_actions(action_group,
260 gnc_plugin_page_sx_list_actions,
261 gnc_plugin_page_sx_list_n_actions,
265 G_OBJECT_CLASS (klass));
270 gnc_plugin_page_sx_list_dispose(GObject *
object)
275 page = GNC_PLUGIN_PAGE_SX_LIST (
object);
276 g_return_if_fail(GNC_IS_PLUGIN_PAGE_SX_LIST (page));
277 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
278 g_return_if_fail(priv != NULL);
280 g_return_if_fail(!priv->disposed);
281 priv->disposed = TRUE;
283 g_object_unref(G_OBJECT(priv->dense_cal_model));
284 priv->dense_cal_model = NULL;
285 g_object_unref(GTK_WIDGET(priv->gdcal));
287 g_object_unref(G_OBJECT(priv->instances));
288 priv->instances = NULL;
290 G_OBJECT_CLASS (parent_class)->dispose(
object);
295 gnc_plugin_page_sx_list_finalize (GObject *
object)
300 page = GNC_PLUGIN_PAGE_SX_LIST (
object);
301 g_return_if_fail(GNC_IS_PLUGIN_PAGE_SX_LIST (page));
302 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
303 g_return_if_fail(priv != NULL);
306 G_OBJECT_CLASS (parent_class)->finalize (
object);
312 gnc_plugin_page_sx_list_refresh_cb (GHashTable *changes, gpointer user_data)
317 g_return_if_fail(GNC_IS_PLUGIN_PAGE_SX_LIST(page));
323 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
324 gtk_widget_queue_draw(priv->widget);
329 gnc_plugin_page_sx_list_close_cb (gpointer user_data)
337 gppsl_selection_changed_cb(GtkTreeSelection *selection, gpointer user_data)
340 GtkAction *edit_action, *delete_action;
341 gboolean selection_state = TRUE;
343 page = GNC_PLUGIN_PAGE(user_data);
347 = gtk_tree_selection_count_selected_rows(selection) == 0
350 gtk_action_set_sensitive(edit_action, selection_state);
351 gtk_action_set_sensitive(delete_action, selection_state);
356 gnc_plugin_page_sx_list_create_widget (
GncPluginPage *plugin_page)
367 page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
368 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
369 if (priv->widget != NULL)
373 widget = gtk_vpaned_new();
374 priv->widget = widget;
375 gtk_widget_show (priv->widget);
378 vbox = gtk_vbox_new(FALSE, 0);
379 gtk_paned_pack1( GTK_PANED(widget), vbox, TRUE, FALSE);
381 label = gtk_label_new(NULL);
382 text = g_strdup_printf(_(
"Transactions"));
383 markup = g_markup_printf_escaped (
"<b> %s</b>", text);
384 gtk_label_set_markup (GTK_LABEL (label), markup);
387 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0);
388 gtk_widget_show (label);
389 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, FALSE, 0);
390 gtk_widget_show (vbox);
393 swin = gtk_scrolled_window_new(NULL, NULL);
394 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
395 GTK_POLICY_AUTOMATIC,
396 GTK_POLICY_AUTOMATIC);
397 gtk_box_pack_start ( GTK_BOX(vbox), swin, TRUE, TRUE, 5);
398 gtk_widget_show (swin);
404 gtk_paned_set_position(GTK_PANED(priv->widget), 160);
409 g_date_clear(&end, 1);
411 g_date_add_years(&end, 1);
416 GtkAction *edit_action, *delete_action;
419 gtk_action_set_sensitive(edit_action, FALSE);
420 gtk_action_set_sensitive(delete_action, FALSE);
424 GtkTreeSelection *selection;
426 priv->tree_view = GTK_TREE_VIEW(gnc_tree_view_sx_list_new(priv->instances));
427 g_object_set(G_OBJECT(priv->tree_view),
428 "state-section", STATE_SECTION,
429 "show-column-menu", TRUE,
431 gtk_container_add(GTK_CONTAINER( swin ), GTK_WIDGET(priv->tree_view));
433 selection = gtk_tree_view_get_selection(priv->tree_view);
434 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
435 g_signal_connect(G_OBJECT(selection),
"changed", (GCallback)gppsl_selection_changed_cb, (gpointer)page);
436 g_signal_connect(G_OBJECT(priv->tree_view),
"row-activated", (GCallback)gppsl_row_activated_cb, (gpointer)page);
440 vbox = gtk_vbox_new(FALSE, 0);
441 gtk_paned_pack2( GTK_PANED(widget), vbox, TRUE, FALSE);
443 label = gtk_label_new(NULL);
444 text = g_strdup_printf(_(
"Upcoming Transactions"));
445 markup = g_markup_printf_escaped (
"<b> %s</b>", text);
446 gtk_label_set_markup (GTK_LABEL (label), markup);
449 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0);
450 gtk_widget_show (label);
452 gtk_box_pack_start ( GTK_BOX(vbox), label, FALSE, FALSE, 0);
453 gtk_widget_show (vbox);
456 swin = gtk_scrolled_window_new(NULL, NULL);
457 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
458 GTK_POLICY_AUTOMATIC,
459 GTK_POLICY_AUTOMATIC);
460 gtk_box_pack_start ( GTK_BOX(vbox), swin, TRUE, TRUE, 5);
461 gtk_widget_show (swin);
464 priv->dense_cal_model = gnc_sx_instance_dense_cal_adapter_new(GNC_SX_INSTANCE_MODEL(priv->instances));
465 priv->gdcal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(priv->dense_cal_model)));
466 g_object_ref_sink(priv->gdcal);
468 gnc_dense_cal_set_months_per_col(priv->gdcal, 4);
469 gnc_dense_cal_set_num_months(priv->gdcal, 12);
471 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(swin), GTK_WIDGET(priv->gdcal));
474 priv->gnc_component_id = gnc_register_gui_component(
"plugin-page-sx-list",
475 gnc_plugin_page_sx_list_refresh_cb,
476 gnc_plugin_page_sx_list_close_cb,
478 gnc_gui_component_set_session (priv->gnc_component_id,
479 gnc_get_current_session());
486 gnc_plugin_page_sx_list_destroy_widget (
GncPluginPage *plugin_page)
491 page = GNC_PLUGIN_PAGE_SX_LIST (plugin_page);
492 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
496 g_object_unref(G_OBJECT(priv->widget));
500 if (priv->gnc_component_id)
502 gnc_unregister_gui_component(priv->gnc_component_id);
503 priv->gnc_component_id = 0;
516 gnc_plugin_page_sx_list_save_page (
GncPluginPage *plugin_page,
518 const gchar *group_name)
523 g_return_if_fail(GNC_IS_PLUGIN_PAGE_SX_LIST(plugin_page));
524 g_return_if_fail(key_file != NULL);
525 g_return_if_fail(group_name != NULL);
527 page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
528 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
530 g_key_file_set_integer(key_file, group_name,
"dense_cal_num_months",
531 gnc_dense_cal_get_num_months(priv->gdcal));
533 g_key_file_set_integer(key_file, group_name,
"paned_position",
534 gtk_paned_get_position(GTK_PANED(priv->widget)));
547 gnc_plugin_page_sx_list_recreate_page (GtkWidget *window,
549 const gchar *group_name)
554 g_return_val_if_fail(key_file, NULL);
555 g_return_val_if_fail(group_name, NULL);
559 priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
566 gint num_months = g_key_file_get_integer(key_file, group_name,
"dense_cal_num_months", &err);
568 gnc_dense_cal_set_num_months(priv->gdcal, num_months);
575 gint paned_position = g_key_file_get_integer(key_file, group_name,
576 "paned_position", &err);
578 gtk_paned_set_position(GTK_PANED(priv->widget), paned_position);
583 return GNC_PLUGIN_PAGE(page);
591 gboolean new_sx_flag = TRUE;
599 g_date_clear(&now, 1);
601 recurrenceSet(r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE);
603 schedule = g_list_append(schedule, r);
606 gnc_ui_scheduled_xaction_editor_dialog_create(new_sx, new_sx_flag);
614 gboolean new_sx_flag = TRUE;
622 g_date_clear (&now, 1);
624 recurrenceSet(r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE);
626 schedule = g_list_append (schedule, r);
629 gnc_ui_scheduled_xaction_editor_dialog_create2 (new_sx, new_sx_flag);
634 _edit_sx(gpointer data, gpointer user_data)
636 gnc_ui_scheduled_xaction_editor_dialog_create((
SchedXaction*)data, FALSE);
641 _edit_sx2 (gpointer data, gpointer user_data)
643 gnc_ui_scheduled_xaction_editor_dialog_create2 ((
SchedXaction*)data, FALSE);
648 _argument_reorder_fn(GtkTreePath* list_path_data,
GncTreeViewSxList* user_tree_view)
650 return gnc_tree_view_sx_list_get_sx_from_path(user_tree_view, list_path_data);
658 GtkTreeSelection *selection;
659 GList *selected_paths, *to_edit;
662 selection = gtk_tree_view_get_selection(priv->tree_view);
663 selected_paths = gtk_tree_selection_get_selected_rows(selection, &model);
664 if (g_list_length(selected_paths) == 0)
666 g_warning(
"no selection edit.");
671 (GncGMapFunc)_argument_reorder_fn,
673 g_list_foreach(to_edit, (GFunc)_edit_sx, NULL);
674 g_list_free(to_edit);
675 g_list_foreach(selected_paths, (GFunc)gtk_tree_path_free, NULL);
676 g_list_free(selected_paths);
684 GtkTreeSelection *selection;
685 GList *selected_paths, *to_edit;
688 selection = gtk_tree_view_get_selection (priv->tree_view);
689 selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
690 if (g_list_length (selected_paths) == 0)
692 g_warning (
"no selection edit.");
697 (GncGMapFunc)_argument_reorder_fn,
699 g_list_foreach(to_edit, (GFunc)_edit_sx2, NULL);
700 g_list_free (to_edit);
701 g_list_foreach (selected_paths, (GFunc)gtk_tree_path_free, NULL);
702 g_list_free (selected_paths);
708 gppsl_row_activated_cb(GtkTreeView *tree_view,
710 GtkTreeViewColumn *column,
716 SchedXaction *sx = gnc_tree_view_sx_list_get_sx_from_path(GNC_TREE_VIEW_SX_LIST(priv->tree_view), path);
717 gnc_ui_scheduled_xaction_editor_dialog_create(sx, FALSE);
722 _destroy_sx(gpointer data, gpointer user_data)
727 book = gnc_get_current_book();
728 sxes = gnc_book_get_schedxactions(book);
729 gnc_sxes_del_sx(sxes, sx);
730 gnc_sx_begin_edit(sx);
739 GtkTreeSelection *selection;
740 GList *selected_paths, *to_delete = NULL;
743 selection = gtk_tree_view_get_selection(priv->tree_view);
744 selected_paths = gtk_tree_selection_get_selected_rows(selection, &model);
745 if (g_list_length(selected_paths) == 0)
747 g_warning(
"no selection for delete.");
752 (GncGMapFunc)_argument_reorder_fn,
756 for (list = to_delete; list != NULL; list = list->next)
758 g_debug(
"to-delete [%s]\n", xaccSchedXactionGetName((
SchedXaction*)list->data));
766 if (gnc_verify_dialog(NULL, FALSE,
"%s", _(
"Do you really want to delete this scheduled transaction?")))
768 g_list_foreach(to_delete, (GFunc)_destroy_sx, NULL);
771 g_list_free(to_delete);
772 g_list_foreach(selected_paths, (GFunc)gtk_tree_path_free, NULL);
773 g_list_free(selected_paths);
void gnc_gdate_set_today(GDate *gd)
void gnc_sx_set_schedule(SchedXaction *sx, GList *schedule)
GList * gnc_g_list_map(GList *list, GncGMapFunc fn, gpointer user_data)
GList * gnc_sx_get_schedule(const SchedXaction *sx)
const GList * gnc_gobject_tracking_get_list(const gchar *name)
GncPluginPage *(* recreate_page)(GtkWidget *window, GKeyFile *file, const gchar *group)
utility functions for the GnuCash UI
void gnc_gobject_tracking_remember(GObject *object, GObjectClass *klass)
GncTreeView implementation for Scheduled Transaction List.
void gnc_gobject_tracking_forget(GObject *object)
API for Transactions and Splits (journal entries)
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Functions for adding content to a window.
void(* destroy_widget)(GncPluginPage *plugin_page)
Anchor Scheduled Transaction info in a book. See src/doc/books.txt for design overview.
const gchar * plugin_name
Additional event handling code.
All type declarations for the whole Gnucash engine.
GtkAction * gnc_plugin_page_get_action(GncPluginPage *page, const gchar *name)
GncSxInstanceModel * gnc_sx_get_instances(const GDate *range_end, gboolean include_disabled)
GType gnc_plugin_page_sx_list_get_type(void)
GtkWidget *(* create_widget)(GncPluginPage *plugin_page)
void gnc_main_window_close_page(GncPluginPage *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(* save_page)(GncPluginPage *page, GKeyFile *file, const gchar *group)
void gnc_plugin_page_add_book(GncPluginPage *page, QofBook *book)
SchedXaction * xaccSchedXactionMalloc(QofBook *book)
GtkActionGroup * gnc_plugin_page_create_action_group(GncPluginPage *page, const gchar *group_name)
API for Transactions and Splits (journal entries)
void xaccSchedXactionDestroy(SchedXaction *sx)
Commodity handling public routines.
const gchar * QofLogModule