GnuCash  4.11-354-g0815ab64c1
gnc-plugin-page-sx-list.c
1 /********************************************************************\
2  * gnc-plugin-page-sx-list.c : scheduled transaction plugin *
3  * *
4  * Copyright (C) 2006 Joshua Sled <jsled@asynchronous.org> *
5  * Copyright (C) 2011 Robert Fewell *
6  * *
7  * This program is free software; you can redistribute it and/or *
8  * modify it under the terms of version 2 and/or version 3 of the *
9  * GNU General Public License as published by the Free Software *
10  * Foundation. *
11  * *
12  * As a special exception, permission is granted to link the binary *
13  * module resultant from this code with the OpenSSL project's *
14  * "OpenSSL" library (or modified versions of it that use the same *
15  * license as the "OpenSSL" library), and distribute the linked *
16  * executable. You must obey the GNU General Public License in all *
17  * respects for all of the code used other than "OpenSSL". If you *
18  * modify this file, you may extend this exception to your version *
19  * of the file, but you are not obligated to do so. If you do not *
20  * wish to do so, delete this exception statement from your version *
21  * of this file. *
22  * *
23  * This program is distributed in the hope that it will be useful, *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26  * GNU General Public License for more details. *
27  * *
28  * You should have received a copy of the GNU General Public License*
29  * along with this program; if not, contact: *
30  * *
31  * Free Software Foundation Voice: +1-617-542-5942 *
32  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
33  * Boston, MA 02110-1301, USA gnu@gnu.org *
34 \********************************************************************/
35 
44 #include <config.h>
45 
46 #include <gtk/gtk.h>
47 #include <glib.h>
48 #include <glib/gi18n.h>
49 
50 #include <gnc-gobject-utils.h>
51 #include "SX-book.h"
52 #include "Split.h"
53 #include "Transaction.h"
54 #include "dialog-sx-editor.h"
55 #include "dialog-utils.h"
56 #include "gnc-commodity.h"
57 #include "gnc-component-manager.h"
58 #include "gnc-date.h"
59 #include "gnc-dense-cal.h"
60 #include "gnc-engine.h"
61 #include "gnc-event.h"
62 #include "gnc-glib-utils.h"
63 #include "gnc-icons.h"
64 #include "gnc-main-window.h"
65 #include "gnc-plugin-page-sx-list.h"
66 #include "gnc-session.h"
67 #include "gnc-sx-instance-dense-cal-adapter.h"
68 #include "gnc-sx-instance-model.h"
69 #include "gnc-sx-list-tree-model-adapter.h"
70 #include "gnc-tree-view-sx-list.h"
71 #include "gnc-ui-util.h"
72 #include "gnc-ui.h"
73 #include "gnc-window.h"
74 
75 #undef G_LOG_DOMAIN
76 #define G_LOG_DOMAIN "gnc.gui.plugin-page.sx-list"
77 
78 G_GNUC_UNUSED static QofLogModule log_module = GNC_MOD_GUI_SX;
79 
80 #define PLUGIN_PAGE_SX_LIST_CM_CLASS "plugin-page-sx-list"
81 #define STATE_SECTION "SX Transaction List"
82 
84 {
85  gboolean disposed;
86 
87  GtkWidget* widget;
88  gint gnc_component_id;
89 
90  GncSxInstanceDenseCalAdapter *dense_cal_model;
91  GncDenseCal* gdcal;
92 
93  GncSxInstanceModel* instances;
94  GtkTreeView* tree_view;
95  GList *selected_list;
96 
98 
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))
101 
102 static GObjectClass *parent_class = NULL;
103 
104 /************************************************************
105  * Prototypes *
106  ************************************************************/
107 /* Plugin Actions */
108 static void gnc_plugin_page_sx_list_class_init (GncPluginPageSxListClass *klass);
109 static void gnc_plugin_page_sx_list_init (GncPluginPageSxList *plugin_page);
110 static void gnc_plugin_page_sx_list_dispose (GObject *object);
111 static void gnc_plugin_page_sx_list_finalize (GObject *object);
112 
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);
117 
118 static void gppsl_row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data);
119 
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);
124 
125 /* Command callbacks */
126 static GtkActionEntry gnc_plugin_page_sx_list_actions [] =
127 {
128  { "SxListAction", NULL, N_("_Scheduled"), NULL, NULL, NULL },
129  {
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)
132  },
133  {
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)
136  },
137  {
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)
140  },
141 
142  /* View menu */
143 
144  {
145  "ViewRefreshAction", "view-refresh", N_("_Refresh"), "<primary>r",
146  N_("Refresh this window"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_refresh)
147  },
148 };
150 static guint gnc_plugin_page_sx_list_n_actions = G_N_ELEMENTS(gnc_plugin_page_sx_list_actions);
151 
154 {
155  GncPluginPageSxList *plugin_page;
156  const GList *object = gnc_gobject_tracking_get_list (GNC_PLUGIN_PAGE_SX_LIST_NAME);
157  if (object && GNC_IS_PLUGIN_PAGE_SX_LIST (object->data))
158  plugin_page = GNC_PLUGIN_PAGE_SX_LIST (object->data);
159  else
160  {
161  plugin_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_SX_LIST, NULL);
162  }
163  return GNC_PLUGIN_PAGE(plugin_page);
164 }
165 
166 
171 static gboolean
172 gnc_plugin_page_sx_list_focus_widget (GncPluginPage *sx_plugin_page)
173 {
174  if (GNC_IS_PLUGIN_PAGE_SX_LIST(sx_plugin_page))
175  {
176  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(sx_plugin_page);
177  GtkTreeView *tree_view = priv->tree_view;
178 
179  if (GTK_IS_TREE_VIEW(tree_view))
180  {
181  if (!gtk_widget_is_focus (GTK_WIDGET(tree_view)))
182  gtk_widget_grab_focus (GTK_WIDGET(tree_view));
183  }
184  }
185  return FALSE;
186 }
187 
188 G_DEFINE_TYPE_WITH_PRIVATE(GncPluginPageSxList, gnc_plugin_page_sx_list, GNC_TYPE_PLUGIN_PAGE)
189 
190 static void
191 gnc_plugin_page_sx_list_class_init (GncPluginPageSxListClass *klass)
192 {
193  GObjectClass *object_class = G_OBJECT_CLASS(klass);
194  GncPluginPageClass *gnc_plugin_class = GNC_PLUGIN_PAGE_CLASS(klass);
195 
196  parent_class = g_type_class_peek_parent(klass);
197 
198  object_class->dispose = gnc_plugin_page_sx_list_dispose;
199  object_class->finalize = gnc_plugin_page_sx_list_finalize;
200 
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;
207  gnc_plugin_class->focus_page_function = gnc_plugin_page_sx_list_focus_widget;
208 }
209 
210 
211 static void
212 gnc_plugin_page_sx_list_init (GncPluginPageSxList *plugin_page)
213 {
214  GtkActionGroup *action_group;
215  GncPluginPage *parent;
216 
217  /* Init parent declared variables */
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",
223  NULL);
224 
225  gnc_plugin_page_add_book (parent, gnc_get_current_book());
226  action_group =
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,
232  plugin_page);
233  /* gnc_plugin_init_short_names (action_group, toolbar_labels); */
234 }
235 
236 
237 static void
238 gnc_plugin_page_sx_list_dispose (GObject *object)
239 {
240  GncPluginPageSxList *page;
242 
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);
247 
248  g_return_if_fail (!priv->disposed);
249  priv->disposed = TRUE;
250 
251  g_object_unref (G_OBJECT(priv->dense_cal_model));
252  priv->dense_cal_model = NULL;
253  g_object_unref (GTK_WIDGET(priv->gdcal));
254  priv->gdcal = NULL;
255  g_object_unref (G_OBJECT(priv->instances));
256  priv->instances = NULL;
257 
258  G_OBJECT_CLASS(parent_class)->dispose (object);
259 }
260 
261 
262 static void
263 gnc_plugin_page_sx_list_finalize (GObject *object)
264 {
265  GncPluginPageSxList *page;
267 
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);
272 
273  G_OBJECT_CLASS(parent_class)->finalize (object);
274 }
275 
276 
277 /* Virtual Functions */
278 static void
279 gnc_plugin_page_sx_list_refresh_cb (GHashTable *changes, gpointer user_data)
280 {
281  GncPluginPageSxList *page = user_data;
283 
284  g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
285 
286  /* We're only looking for forced updates here. */
287  if (changes)
288  return;
289 
290  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
291  gtk_widget_queue_draw (priv->widget);
292 }
293 
294 
295 static void
296 gnc_plugin_page_sx_list_close_cb (gpointer user_data)
297 {
298  GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(user_data);
299  gnc_main_window_close_page (plugin_page);
300 }
301 
302 
303 static void
304 gppsl_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
305 {
306  GncPluginPage *page;
307  GtkAction *edit_action, *delete_action;
308  gboolean selection_state = TRUE;
309 
310  page = GNC_PLUGIN_PAGE(user_data);
311  edit_action = gnc_plugin_page_get_action (page, "SxListEditAction");
312  delete_action = gnc_plugin_page_get_action (page, "SxListDeleteAction");
313  selection_state
314  = gtk_tree_selection_count_selected_rows (selection) == 0
315  ? FALSE
316  : TRUE;
317  gtk_action_set_sensitive (edit_action, selection_state);
318  gtk_action_set_sensitive (delete_action, selection_state);
319 }
320 
321 
322 static void
323 gppsl_update_selected_list (GncPluginPageSxList *page, gboolean reset, SchedXaction *sx)
324 {
325  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
326 
327  if (reset && priv->selected_list)
328  {
329  g_list_free (priv->selected_list);
330  priv->selected_list = NULL;
331  }
332  if (sx)
333  priv->selected_list = g_list_prepend (priv->selected_list, sx);
334 }
335 
336 
337 static void
338 gppsl_model_populated_cb (GtkTreeModel *tree_model, GncPluginPageSxList *page)
339 {
340  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
341  GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->tree_view));
342  gboolean found = FALSE;
343 
344  if (priv->selected_list)
345  {
346  // walk the list to see if we can reselect the sx
347  for (GList *list = priv->selected_list; list != NULL; list = list->next)
348  {
349  SchedXaction *sx = list->data;
350  GtkTreePath *path = gtk_tree_path_new_first ();
351 
352  // loop through the model trying to find selected sx's
353  while (gnc_tree_view_path_is_valid (GNC_TREE_VIEW(priv->tree_view), path))
354  {
355  SchedXaction *sx_tmp = gnc_tree_view_sx_list_get_sx_from_path (
356  GNC_TREE_VIEW_SX_LIST(priv->tree_view), path);
357  if (sx_tmp == sx)
358  {
359  found = TRUE;
360  break;
361  }
362  gtk_tree_path_next (path);
363  }
364  if (found)
365  gtk_tree_selection_select_path (selection, path);
366 
367  gtk_tree_path_free (path);
368  }
369  }
370  // this could be on load or if sx is deleted
371  if (!found)
372  {
373  GtkTreePath *path = gtk_tree_path_new_first ();
374  gtk_tree_selection_select_path (selection, path);
375  gtk_tree_path_free (path);
376  }
377 }
378 
379 
380 static GtkWidget *
381 gnc_plugin_page_sx_list_create_widget (GncPluginPage *plugin_page)
382 {
383  GncPluginPageSxList *page;
385  GtkWidget *widget;
386  GtkWidget *vbox;
387  GtkWidget *label;
388  GtkWidget *swin;
389 
390  page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
391  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
392  if (priv->widget != NULL)
393  return priv->widget;
394 
395  /* Create Vpaned widget for top level */
396  widget = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
397  priv->widget = widget;
398  gtk_widget_show (priv->widget);
399 
400  // Set the name for this widget so it can be easily manipulated with css
401  gtk_widget_set_name (GTK_WIDGET(priv->widget), "gnc-id-sx-page");
402 
403  /* Add vbox and label */
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);
407 
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);
415 
416  /* Create scrolled window for top area */
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);
423 
424  {
425  // gint half_way;
426  // half_way = plugin_page->notebook_page->allocation.height * 0.5;
427  // fixme; get a real value:
428  gtk_paned_set_position (GTK_PANED(priv->widget), 160);
429  }
430 
431  {
432  GDate end;
433  g_date_clear (&end, 1);
434  gnc_gdate_set_today (&end);
435  g_date_add_years (&end, 1);
436  priv->instances = GNC_SX_INSTANCE_MODEL(gnc_sx_get_instances (&end, TRUE));
437  }
438 
439  {
440  GtkAction *edit_action, *delete_action;
441  edit_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), "SxListEditAction");
442  delete_action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page), "SxListDeleteAction");
443  gtk_action_set_sensitive (edit_action, FALSE);
444  gtk_action_set_sensitive (delete_action, FALSE);
445  }
446 
447  {
448  GtkTreeSelection *selection;
449  GtkTreePath *path = gtk_tree_path_new_first ();
450 
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,
455  NULL);
456  gtk_container_add (GTK_CONTAINER( swin ), GTK_WIDGET(priv->tree_view));
457 
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);
462 
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);
467  }
468 
469  /* Add vbox and label */
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);
473 
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);
479 
480  gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
481  gtk_widget_show (vbox);
482 
483  /* Create scrolled window for bottom area */
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);
490 
491  {
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);
495 
496  gnc_dense_cal_set_months_per_col (priv->gdcal, 4);
497  gnc_dense_cal_set_num_months (priv->gdcal, 12);
498 
499  gtk_container_add (GTK_CONTAINER(swin), GTK_WIDGET(priv->gdcal));
500  }
501 
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,
505  page);
506  gnc_gui_component_set_session (priv->gnc_component_id,
507  gnc_get_current_session ());
508 
509  g_signal_connect (G_OBJECT(plugin_page), "inserted",
510  G_CALLBACK(gnc_plugin_page_inserted_cb),
511  NULL);
512 
513  return priv->widget;
514 }
515 
516 
517 static void
518 gnc_plugin_page_sx_list_destroy_widget (GncPluginPage *plugin_page)
519 {
520  GncPluginPageSxList *page;
522 
523  page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
524  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
525 
526  // Remove the page_changed signal callback
527  gnc_plugin_page_disconnect_page_changed (GNC_PLUGIN_PAGE(plugin_page));
528 
529  // Remove the page focus idle function if present
530  g_idle_remove_by_data (plugin_page);
531 
532  if (priv->widget)
533  {
534  g_object_unref (G_OBJECT(priv->widget));
535  priv->widget = NULL;
536  }
537 
538  if (priv->selected_list)
539  g_list_free (priv->selected_list);
540 
541  if (priv->gnc_component_id)
542  {
543  gnc_unregister_gui_component (priv->gnc_component_id);
544  priv->gnc_component_id = 0;
545  }
546 }
547 
548 
556 static void
557 gnc_plugin_page_sx_list_save_page (GncPluginPage *plugin_page,
558  GKeyFile *key_file,
559  const gchar *group_name)
560 {
561  GncPluginPageSxList *page;
563 
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);
567 
568  page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
569  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
570 
571  g_key_file_set_integer (key_file, group_name, "dense_cal_num_months",
572  gnc_dense_cal_get_num_months (priv->gdcal));
573 
574  g_key_file_set_integer (key_file, group_name, "paned_position",
575  gtk_paned_get_position (GTK_PANED(priv->widget)));
576 }
577 
578 
587 static GncPluginPage *
588 gnc_plugin_page_sx_list_recreate_page (GtkWidget *window,
589  GKeyFile *key_file,
590  const gchar *group_name)
591 {
592  GncPluginPageSxList *page;
594 
595  g_return_val_if_fail (key_file, NULL);
596  g_return_val_if_fail (group_name, NULL);
597 
598  /* Create the new page. */
599  page = GNC_PLUGIN_PAGE_SX_LIST(gnc_plugin_page_sx_list_new ());
600  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
601 
602  /* Install it now so we can them manipulate the created widget */
603  gnc_main_window_open_page (GNC_MAIN_WINDOW(window), GNC_PLUGIN_PAGE(page));
604 
605  {
606  GError *err = NULL;
607  gint num_months = g_key_file_get_integer (key_file, group_name, "dense_cal_num_months", &err);
608  if (err == NULL)
609  gnc_dense_cal_set_num_months (priv->gdcal, num_months);
610  else
611  g_error_free (err);
612  }
613 
614  {
615  GError *err = NULL;
616  gint paned_position = g_key_file_get_integer (key_file, group_name,
617  "paned_position", &err);
618  if (err == NULL)
619  gtk_paned_set_position (GTK_PANED(priv->widget), paned_position);
620  else
621  g_error_free (err);
622  }
623 
624  return GNC_PLUGIN_PAGE(page);
625 }
626 
627 
628 static void
629 gnc_plugin_page_sx_list_cmd_new (GtkAction *action, GncPluginPageSxList *page)
630 {
631  GtkWindow *window = GTK_WINDOW(gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(page)));
632  SchedXaction *new_sx;
633  gboolean new_sx_flag = TRUE;
634 
635  new_sx = xaccSchedXactionMalloc (gnc_get_current_book());
636  {
637  GDate now;
638  Recurrence *r = g_new0 (Recurrence, 1);
639  GList *schedule;
640 
641  g_date_clear (&now, 1);
642  gnc_gdate_set_today (&now);
643  recurrenceSet (r, 1, PERIOD_MONTH, &now, WEEKEND_ADJ_NONE);
644  schedule = gnc_sx_get_schedule (new_sx);
645  schedule = g_list_append (schedule, r);
646  gnc_sx_set_schedule (new_sx, schedule);
647  }
648  gnc_ui_scheduled_xaction_editor_dialog_create (window, new_sx, new_sx_flag);
649  gppsl_update_selected_list (page, TRUE, new_sx);
650 }
651 
652 static void
653 gnc_plugin_page_sx_list_cmd_refresh (GtkAction *action, GncPluginPageSxList *page)
654 {
656 
657  g_return_if_fail (GNC_IS_PLUGIN_PAGE_SX_LIST(page));
658 
659  priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
660  gtk_widget_queue_draw (priv->widget);
661 }
662 
663 static void
664 _edit_sx(gpointer data, gpointer user_data)
665 {
666  gnc_ui_scheduled_xaction_editor_dialog_create (GTK_WINDOW(user_data),
667  (SchedXaction*)data, FALSE);
668 }
669 
670 static SchedXaction*
671 _argument_reorder_fn (GtkTreePath* list_path_data, GncTreeViewSxList* user_tree_view)
672 {
673  return gnc_tree_view_sx_list_get_sx_from_path (user_tree_view, list_path_data);
674 }
675 
676 
677 static void
678 gnc_plugin_page_sx_list_cmd_edit (GtkAction *action, GncPluginPageSxList *page)
679 {
680  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
681  GtkWindow *window = GTK_WINDOW(gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(page)));
682  GtkTreeSelection *selection;
683  GList *selected_paths, *to_edit;
684  GtkTreeModel *model;
685 
686  selection = gtk_tree_view_get_selection (priv->tree_view);
687  selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
688  if (!gnc_list_length_cmp (selected_paths, 0))
689  {
690  g_warning ("no selection edit.");
691  return;
692  }
693 
694  to_edit = gnc_g_list_map (selected_paths,
695  (GncGMapFunc)_argument_reorder_fn,
696  priv->tree_view);
697 
698  gppsl_update_selected_list (page, TRUE, NULL);
699  for (GList *list = to_edit; list != NULL; list = list->next)
700  {
701  DEBUG ("to-edit [%s]\n", xaccSchedXactionGetName ((SchedXaction*)list->data));
702  gppsl_update_selected_list (page, FALSE, list->data);
703  }
704 
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);
709 }
710 
711 static void
712 gppsl_row_activated_cb (GtkTreeView *tree_view,
713  GtkTreePath *path,
714  GtkTreeViewColumn *column,
715  gpointer user_data)
716 {
717  GncPluginPageSxList *page = GNC_PLUGIN_PAGE_SX_LIST(user_data);
718  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
719  GtkWindow *window = GTK_WINDOW(gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(page)));
720 
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);
725 }
726 
727 
728 static void
729 _destroy_sx(gpointer data, gpointer user_data)
730 {
731  SchedXactions *sxes;
732  SchedXaction *sx = (SchedXaction*)data;
733  QofBook *book;
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);
739 }
740 
741 
742 static void
743 gnc_plugin_page_sx_list_cmd_delete (GtkAction *action, GncPluginPageSxList *page)
744 {
745  GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
746  GtkTreeSelection *selection;
747  GList *selected_paths, *to_delete = NULL;
748  GtkTreeModel *model;
749  GtkWindow *window;
750  gchar *message = NULL;
751  gint length;
752 
753  selection = gtk_tree_view_get_selection (priv->tree_view);
754  selected_paths = gtk_tree_selection_get_selected_rows (selection, &model);
755  if (!gnc_list_length_cmp (selected_paths, 0))
756  {
757  g_warning ("no selection for delete.");
758  return;
759  }
760 
761  to_delete = gnc_g_list_map (selected_paths,
762  (GncGMapFunc)_argument_reorder_fn,
763  priv->tree_view);
764 
765  window = GTK_WINDOW(gnc_plugin_page_get_window (GNC_PLUGIN_PAGE(page)));
766 
767  length = g_list_length (to_delete);
768 
769  /* Translators: This is a ngettext(3) message, %d is the number of scheduled transactions deleted */
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?",
772  length), length);
773 
774  if (gnc_verify_dialog (window, FALSE, "%s", message))
775  {
776  gppsl_update_selected_list (page, TRUE, NULL);
777  for (GList *list = to_delete; list != NULL; list = list->next)
778  {
779  DEBUG("to-delete [%s]\n", xaccSchedXactionGetName ((SchedXaction*)list->data));
780  gppsl_update_selected_list (page, FALSE, list->data);
781  }
782  g_list_foreach (to_delete, (GFunc)_destroy_sx, NULL);
783  }
784 
785  g_free (message);
786  g_list_free (to_delete);
787  g_list_foreach (selected_paths, (GFunc)gtk_tree_path_free, NULL);
788  g_list_free (selected_paths);
789 }
790 
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)
Definition: SchedXaction.c:567
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)
Definition: SchedXaction.c:561
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.
Definition: qoflog.h:264
Functions that are supported by all types of windows.
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
Definition: gnc-date.cpp:1239
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.
Gobject helper routines.
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...
GLib helper routines.
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.
Definition: SchedXaction.c:405
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.
Definition: SchedXaction.c:475
Commodity handling public routines.