GnuCash de0bfde+
Loading...
Searching...
No Matches
reconcile-view.c
1/********************************************************************\
2 * reconcile-view.c -- A view of accounts to be reconciled for *
3 * GnuCash. *
4 * Copyright (C) 1998,1999 Jeremy Collins *
5 * Copyright (C) 1998-2000 Linas Vepstas *
6 * Copyright (C) 2012 Robert Fewell *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License as *
10 * published by the Free Software Foundation; either version 2 of *
11 * the License, or (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License*
19 * along with this program; if not, contact: *
20 * *
21 * Free Software Foundation Voice: +1-617-542-5942 *
22 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
23 * Boston, MA 02110-1301, USA gnu@gnu.org *
24\********************************************************************/
25
26#include <config.h>
27
28#include <gtk/gtk.h>
29#include <glib/gi18n.h>
30#include <gdk/gdkkeysyms.h>
31
32#include "gnc-date.h"
33#include "qof.h"
34#include "qofbook.h"
35#include "Transaction.h"
36#include "gnc-ui-util.h"
37#include "gnc-prefs.h"
38#include "reconcile-view.h"
39#include "search-param.h"
40#include "gnc-component-manager.h"
41
42#define GNC_PREF_CHECK_CLEARED "check-cleared"
43
44/* Signal codes */
45enum
46{
47 TOGGLE_RECONCILED,
48 LINE_SELECTED,
49 DOUBLE_CLICK_SPLIT,
50 LAST_SIGNAL
51};
52
53
55static guint reconcile_view_signals[LAST_SIGNAL] = {0};
56
58static void gnc_reconcile_view_finalize (GObject *object);
59static gpointer gnc_reconcile_view_is_reconciled (gpointer item,
60 gpointer user_data);
61static void gnc_reconcile_view_line_toggled (GNCQueryView *qview,
62 gpointer item,
63 gpointer user_data);
64static void gnc_reconcile_view_double_click_entry (GNCQueryView *qview,
65 gpointer item,
66 gpointer user_data);
67static void gnc_reconcile_view_row_selected (GNCQueryView *qview,
68 gpointer item,
69 gpointer user_data);
70static gboolean gnc_reconcile_view_key_press_cb (GtkWidget *widget,
71 GdkEventKey *event,
72 gpointer user_data);
73static gboolean gnc_reconcile_view_tooltip_cb (GNCQueryView *qview,
74 gint x, gint y,
75 gboolean keyboard_mode,
76 GtkTooltip* tooltip,
77 gpointer* user_data);
78
79G_DEFINE_TYPE (GNCReconcileView, gnc_reconcile_view, GNC_TYPE_QUERY_VIEW)
80
81static gboolean
82gnc_reconcile_view_tooltip_cb (GNCQueryView *qview, gint x, gint y,
83 gboolean keyboard_mode, GtkTooltip *tooltip,
84 gpointer *user_data)
85{
86 GtkTreeModel* model;
87 GtkTreeIter iter;
88
89 // If the Description is longer than can be display, show it in a tooltip
90 if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW(qview), &x, &y,
91 keyboard_mode, &model, NULL, &iter))
92 {
93 GtkTreeViewColumn *col;
94 GList *cols;
95 gint col_pos, col_width;
96 gchar* desc_text = NULL;
97
98 /* Are we in keyboard tooltip mode, displays tooltip below/above treeview CTRL+F1 */
99 if (keyboard_mode == FALSE)
100 {
101 if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(qview), x, y,
102 NULL, &col, NULL, NULL) == FALSE)
103 return FALSE;
104 }
105 else
106 gtk_tree_view_get_cursor (GTK_TREE_VIEW(qview), NULL, &col);
107
108 cols = gtk_tree_view_get_columns (GTK_TREE_VIEW(qview));
109 col_width = gtk_tree_view_column_get_width (col);
110 col_pos = g_list_index (cols, col);
111 g_list_free (cols);
112
113 /* If column is not description, do not show tooltip */
114 if (col_pos != (REC_DESC - 1)) // allow for the pointer model column at 0
115 return FALSE;
116
117 gtk_tree_model_get (model, &iter, REC_DESC, &desc_text, -1);
118
119 if (desc_text)
120 {
121 PangoLayout* layout;
122 gint text_width;
123 gint root_x, root_y;
124 gint cur_x, cur_y;
125
126 layout = gtk_widget_create_pango_layout (GTK_WIDGET(qview), desc_text);
127 pango_layout_get_pixel_size (layout, &text_width, NULL);
128 g_object_unref (layout);
129
130 /* If text_width + 10 <= column_width, do not show tooltip */
131 if ((text_width + 10) <= col_width)
132 {
133 g_free (desc_text);
134 return FALSE;
135 }
136
137 if (keyboard_mode == FALSE)
138 {
139 GdkSeat *seat;
140 GdkDevice *pointer;
141 GtkWindow *tip_win = NULL;
142 GdkWindow *parent_window;
143 GList *win_list, *node;
144
145 parent_window = gtk_widget_get_parent_window (GTK_WIDGET(qview));
146
147 seat = gdk_display_get_default_seat (gdk_window_get_display (parent_window));
148 pointer = gdk_seat_get_pointer (seat);
149
150 gdk_window_get_device_position (parent_window, pointer, &cur_x, &cur_y, NULL);
151
152 gdk_window_get_origin (parent_window, &root_x, &root_y);
153
154 /* Get a list of toplevel windows */
155 win_list = gtk_window_list_toplevels ();
156
157 /* Look for the gtk-tooltip window, we do this as gtk_widget_get_tooltip_window
158 does not seem to work for the default tooltip window, custom yes */
159 for (node = win_list; node != NULL; node = node->next)
160 {
161 if (g_strcmp0 (gtk_widget_get_name (node->data), "gtk-tooltip") == 0)
162 tip_win = node->data;
163 }
164 g_list_free (win_list);
165
166 gtk_tooltip_set_text (tooltip, desc_text);
167
168 if (GTK_IS_WINDOW(tip_win))
169 {
170 GdkMonitor *mon;
171 GdkRectangle monitor;
172 GtkRequisition requisition;
173 gint x, y;
174
175 gtk_widget_get_preferred_size (GTK_WIDGET(tip_win), &requisition, NULL);
176
177 x = root_x + cur_x + 10;
178 y = root_y + cur_y + 10;
179
180 mon = gdk_display_get_monitor_at_point (gdk_window_get_display (parent_window), x, y);
181 gdk_monitor_get_geometry (mon, &monitor);
182
183 if (x + requisition.width > monitor.x + monitor.width)
184 x -= x - (monitor.x + monitor.width) + requisition.width;
185 else if (x < monitor.x)
186 x = monitor.x;
187
188 if (y + requisition.height > monitor.y + monitor.height)
189 y -= y - (monitor.y + monitor.height) + requisition.height;
190
191 gtk_window_move (tip_win, x, y);
192 }
193 }
194 gtk_tooltip_set_text (tooltip, desc_text);
195 g_free (desc_text);
196 return TRUE;
197 }
198 }
199 return FALSE;
200}
201
202gint
203gnc_reconcile_view_get_column_width (GNCReconcileView *view, gint column)
204{
205 GNCQueryView *qview = GNC_QUERY_VIEW(view);
206 GtkTreeViewColumn *col;
207
208 // allow for pointer model column at column 0
209 col = gtk_tree_view_get_column (GTK_TREE_VIEW(qview), (column - 1));
210 return gtk_tree_view_column_get_width (col);
211}
212
213void
214gnc_reconcile_view_add_padding (GNCReconcileView *view, gint column, gint xpadding)
215{
216 GNCQueryView *qview = GNC_QUERY_VIEW(view);
217 GtkTreeViewColumn *col;
218 GList *renderers;
219 GtkCellRenderer *cr0;
220 gint xpad, ypad;
221
222 // allow for pointer model column at column 0
223 col = gtk_tree_view_get_column (GTK_TREE_VIEW(qview), (column - 1));
224 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(col));
225 cr0 = g_list_nth_data (renderers, 0);
226 g_list_free (renderers);
227
228 gtk_cell_renderer_get_padding (cr0, &xpad, &ypad);
229 gtk_cell_renderer_set_padding (cr0, xpadding, ypad);
230}
231
232/****************************************************************************\
233 * gnc_reconcile_view_new *
234 * creates the account tree *
235 * *
236 * Args: account - the account to use in filling up the splits. *
237 * type - the type of view, RECLIST_DEBIT or RECLIST_CREDIT *
238 * statement_date - date of statement *
239 * Returns: the account tree widget, or NULL if there was a problem. *
240\****************************************************************************/
241static void
242gnc_reconcile_view_construct (GNCReconcileView *view, Query *query)
243{
244 GNCQueryView *qview = GNC_QUERY_VIEW(view);
245 GtkTreeViewColumn *col_desc, *col_num;
246 GtkTreeSelection *selection;
247 GList *renderers;
248 GtkCellRenderer *cr_desc, *cr_num;
249 gboolean inv_sort = FALSE;
250
251 if (view->view_type == RECLIST_CREDIT)
252 inv_sort = TRUE;
253
254 /* Construct the view */
255 gnc_query_view_construct (qview, view->column_list, query);
256 gnc_query_view_set_numerics (qview, TRUE, inv_sort);
257
258 /* Set the description field to have spare space,
259 REC_DESC -1 to allow for the pointer model column at 0 */
260 col_desc = gtk_tree_view_get_column (GTK_TREE_VIEW(qview), (REC_DESC - 1));
261 col_num = gtk_tree_view_get_column (GTK_TREE_VIEW(qview), (REC_NUM - 1));
262 gtk_tree_view_column_set_expand (col_desc, TRUE);
263 gtk_tree_view_column_set_expand (col_num, FALSE);
264
265 /* Get the renderer of the description column and set ellipsize value */
266 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(col_desc));
267 cr_desc = g_list_nth_data (renderers, 0);
268 g_list_free (renderers);
269 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(col_num));
270 cr_num = g_list_nth_data (renderers, 0);
271 g_list_free (renderers);
272 g_object_set (cr_desc, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
273 g_object_set (cr_num, "ellipsize", PANGO_ELLIPSIZE_END, NULL );
274
275 gtk_widget_set_has_tooltip (GTK_WIDGET(qview), TRUE);
276
277 /* Set the selection method */
278 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
279 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
280
281 /* Now set up the signals for the QueryView */
282 g_signal_connect (G_OBJECT (qview), "column_toggled",
283 G_CALLBACK (gnc_reconcile_view_line_toggled), view);
284 g_signal_connect (G_OBJECT(qview), "double_click_entry",
285 G_CALLBACK(gnc_reconcile_view_double_click_entry), view);
286 g_signal_connect (G_OBJECT(qview), "row_selected",
287 G_CALLBACK(gnc_reconcile_view_row_selected), view);
288 g_signal_connect (G_OBJECT(qview), "key_press_event",
289 G_CALLBACK(gnc_reconcile_view_key_press_cb), view);
290 g_signal_connect (G_OBJECT(qview), "query-tooltip",
291 G_CALLBACK(gnc_reconcile_view_tooltip_cb), view);
292}
293
294static gint
295sort_date_helper (time64 date_a, time64 date_b)
296{
297 gint ret = 0;
298
299 if (date_a < date_b)
300 ret = -1;
301 else if (date_a > date_b)
302 ret = 1;
303
304 return ret;
305}
306
307static gint
308sort_iter_compare_func (GtkTreeModel *model,
309 GtkTreeIter *a,
310 GtkTreeIter *b,
311 gpointer user_data)
312{
313 gboolean rec_a, rec_b;
314 Split *split_a, *split_b;
315 time64 date_a, date_b;
316 gint ret = 0;
317
318 gtk_tree_model_get (model, a, REC_POINTER, &split_a, REC_RECN, &rec_a, -1);
319 gtk_tree_model_get (model, b, REC_POINTER, &split_b, REC_RECN, &rec_b, -1);
320
321 date_a = xaccTransGetDate (xaccSplitGetParent (split_a));
322 date_b = xaccTransGetDate (xaccSplitGetParent (split_b));
323
324 if (rec_a > rec_b)
325 ret = -1;
326 else if (rec_b > rec_a)
327 ret = 1;
328 else ret = sort_date_helper (date_a, date_b);
329
330 return ret;
331}
332
333GtkWidget *
334gnc_reconcile_view_new (Account *account, GNCReconcileViewType type,
335 time64 statement_date)
336{
337 GNCReconcileView *view;
338 GtkListStore *liststore;
339 GtkTreeSortable *sortable;
340 gboolean include_children, auto_check;
341 GList *accounts = NULL;
342 GList *splits;
343 Query *query;
344 QofNumericMatch sign;
345
346 g_return_val_if_fail (account, NULL);
347 g_return_val_if_fail ((type == RECLIST_DEBIT) ||
348 (type == RECLIST_CREDIT), NULL);
349
350 view = g_object_new (GNC_TYPE_RECONCILE_VIEW, NULL);
351
352 /* Create the list store with 6 columns and add to treeview,
353 column 0 will be a pointer to the entry */
354 liststore = gtk_list_store_new (6, G_TYPE_POINTER, G_TYPE_STRING,
355 G_TYPE_STRING, G_TYPE_STRING,
356 G_TYPE_STRING, G_TYPE_BOOLEAN);
357
358 gtk_tree_view_set_model (GTK_TREE_VIEW(view), GTK_TREE_MODEL(liststore));
359 g_object_unref (liststore);
360
361 view->account = account;
362 view->view_type = type;
363 view->statement_date = statement_date;
364
365 query = qof_query_create_for (GNC_ID_SPLIT);
366 qof_query_set_book (query, gnc_get_current_book ());
367
368 include_children = xaccAccountGetReconcileChildrenStatus (account);
369 if (include_children)
370 accounts = gnc_account_get_descendants (account);
371
372 /* match the account */
373 accounts = g_list_prepend (accounts, account);
374
375 xaccQueryAddAccountMatch (query, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND);
376
377 g_list_free (accounts);
378
379 sign = (type == RECLIST_CREDIT) ? QOF_NUMERIC_MATCH_CREDIT :
380 QOF_NUMERIC_MATCH_DEBIT;
381
382 xaccQueryAddNumericMatch (query, gnc_numeric_zero (), sign, QOF_COMPARE_GTE,
383 QOF_QUERY_AND, SPLIT_AMOUNT, NULL);
384
385 /* limit the matches only to Cleared and Non-reconciled splits */
386 xaccQueryAddClearedMatch (query, CLEARED_NO | CLEARED_CLEARED, QOF_QUERY_AND);
387
388 /* Initialize the QueryList */
389 gnc_reconcile_view_construct (view, query);
390
391 /* find the list of splits to auto-reconcile */
392 auto_check = gnc_prefs_get_bool (GNC_PREFS_GROUP_RECONCILE, GNC_PREF_CHECK_CLEARED);
393
394 if (auto_check)
395 {
396 time64 statement_date_day_end = gnc_time64_get_day_end (statement_date);
397 for (splits = qof_query_run (query); splits; splits = splits->next)
398 {
399 Split *split = splits->data;
400 char recn = xaccSplitGetReconcile (split);
401 time64 trans_date = xaccTransGetDate (xaccSplitGetParent (split));
402
403 /* Just an extra verification that our query is correct ;) */
404 g_assert (recn == NREC || recn == CREC);
405
406 if (recn == CREC && trans_date <= statement_date_day_end)
407 g_hash_table_insert (view->reconciled, split, split);
408 }
409 }
410
411 /* set up a separate sort function for the recn column as it is
412 * derived from a search function */
413 sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model (GTK_TREE_VIEW(view)));
414 gtk_tree_sortable_set_sort_func (sortable, REC_RECN, sort_iter_compare_func,
415 GINT_TO_POINTER (REC_RECN), NULL);
416
417 /* Free the query -- we don't need it anymore */
418 qof_query_destroy (query);
419
420 return GTK_WIDGET(view);
421}
422
423static void
424gnc_reconcile_view_init (GNCReconcileView *view)
425{
426 GNCSearchParamSimple *param;
427 GList *columns = NULL;
428 gboolean num_action = qof_book_use_split_action_for_num_field (gnc_get_current_book());
429
430 view->reconciled = g_hash_table_new (NULL, NULL);
431 view->account = NULL;
432 view->sibling = NULL;
433
434 param = gnc_search_param_simple_new ();
435 gnc_search_param_set_param_fcn (param, QOF_TYPE_BOOLEAN,
436 gnc_reconcile_view_is_reconciled, view);
437 gnc_search_param_set_title ((GNCSearchParam *) param, C_("Column header for 'Reconciled'", "R"));
438 gnc_search_param_set_justify ((GNCSearchParam *) param, GTK_JUSTIFY_CENTER);
439 gnc_search_param_set_passive ((GNCSearchParam *) param, FALSE);
440 gnc_search_param_set_non_resizeable ((GNCSearchParam *) param, TRUE);
441 columns = g_list_prepend (columns, param);
442
443 columns = gnc_search_param_prepend_with_justify (columns, _("Amount"),
444 GTK_JUSTIFY_RIGHT,
445 NULL, GNC_ID_SPLIT,
446 SPLIT_AMOUNT, NULL);
447 columns = gnc_search_param_prepend (columns, _("Description"), NULL,
448 GNC_ID_SPLIT, SPLIT_TRANS,
449 TRANS_DESCRIPTION, NULL);
450 columns = num_action ?
451 gnc_search_param_prepend_with_justify (columns, _("Num"),
452 GTK_JUSTIFY_CENTER,
453 NULL, GNC_ID_SPLIT,
454 SPLIT_ACTION, NULL) :
455 gnc_search_param_prepend_with_justify (columns, _("Num"),
456 GTK_JUSTIFY_CENTER,
457 NULL, GNC_ID_SPLIT,
458 SPLIT_TRANS, TRANS_NUM, NULL);
459 columns = gnc_search_param_prepend (columns, _("Date"),
460 NULL, GNC_ID_SPLIT,
461 SPLIT_TRANS,
462 TRANS_DATE_POSTED, NULL);
463
464 view->column_list = columns;
465}
466
467static void
468gnc_reconcile_view_class_init (GNCReconcileViewClass *klass)
469{
470 GObjectClass *object_class;
471
472 object_class = G_OBJECT_CLASS(klass);
473
474 reconcile_view_signals[TOGGLE_RECONCILED] =
475 g_signal_new ("toggle_reconciled",
476 G_OBJECT_CLASS_TYPE(object_class),
477 G_SIGNAL_RUN_FIRST,
478 G_STRUCT_OFFSET(GNCReconcileViewClass,
479 toggle_reconciled),
480 NULL, NULL,
481 g_cclosure_marshal_VOID__POINTER,
482 G_TYPE_NONE, 1,
483 G_TYPE_POINTER);
484
485 reconcile_view_signals[LINE_SELECTED] =
486 g_signal_new ("line_selected",
487 G_OBJECT_CLASS_TYPE(object_class),
488 G_SIGNAL_RUN_FIRST,
489 G_STRUCT_OFFSET(GNCReconcileViewClass,
490 line_selected),
491 NULL, NULL,
492 g_cclosure_marshal_VOID__POINTER,
493 G_TYPE_NONE, 1,
494 G_TYPE_POINTER);
495
496 reconcile_view_signals[DOUBLE_CLICK_SPLIT] =
497 g_signal_new ("double_click_split",
498 G_OBJECT_CLASS_TYPE(object_class),
499 G_SIGNAL_RUN_FIRST,
500 G_STRUCT_OFFSET(GNCReconcileViewClass,
501 double_click_split),
502 NULL, NULL,
503 g_cclosure_marshal_VOID__POINTER,
504 G_TYPE_NONE, 1,
505 G_TYPE_POINTER);
506
507 object_class->finalize = gnc_reconcile_view_finalize;
508
509 klass->toggle_reconciled = NULL;
510 klass->line_selected = NULL;
511 klass->double_click_split = NULL;
512}
513
514static void
515gnc_reconcile_view_toggle_split (GNCReconcileView *view, Split *split)
516{
517 Split *current;
518
519 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
520 g_return_if_fail (view->reconciled != NULL);
521
522 current = g_hash_table_lookup (view->reconciled, split);
523
524 if (current == NULL)
525 g_hash_table_insert (view->reconciled, split, split);
526 else
527 g_hash_table_remove (view->reconciled, split);
528}
529
530static void
531gnc_reconcile_view_toggle (GNCReconcileView *view, Split *split)
532{
533 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
534 g_return_if_fail (view->reconciled != NULL);
535
536 gnc_reconcile_view_toggle_split (view, split);
537
538 g_signal_emit (G_OBJECT(view),
539 reconcile_view_signals[TOGGLE_RECONCILED], 0, split);
540}
541
542void
543gnc_reconcile_view_unclear_all (GNCReconcileView *view)
544{
545 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
546 g_hash_table_remove_all (view->reconciled);
547}
548
549void
550gnc_reconcile_view_set_cleared (GNCReconcileView *view, Split *split)
551{
552 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
553 g_hash_table_add (view->reconciled, split);
554}
555
556static gboolean
557follow_select_tree_path (GNCReconcileView *view)
558{
559 if (view->rowref)
560 {
561 GtkTreePath *tree_path = gtk_tree_row_reference_get_path (view->rowref);
562 GNCQueryView qview = view->qview;
563 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(&qview));
564
565 gtk_tree_selection_unselect_all (selection);
566 gtk_tree_selection_select_path (selection, tree_path);
567
568 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(&qview),
569 tree_path, NULL, FALSE, 0.0, 0.0);
570
571 gtk_tree_path_free (tree_path);
572 gtk_tree_row_reference_free (view->rowref);
573 view->rowref = NULL;
574 }
575 return FALSE;
576}
577
578static void
579gnc_reconcile_view_line_toggled (GNCQueryView *qview,
580 gpointer item,
581 gpointer user_data)
582{
583 GNCReconcileView *view;
584 GtkTreeModel *model;
585 GtkTreeIter iter;
586 gpointer entry;
587 GtkTreePath *tree_path;
588
589 g_return_if_fail (user_data);
590 g_return_if_fail (GNC_IS_QUERY_VIEW(qview));
591
592 view = user_data;
593
594 model = gtk_tree_view_get_model (GTK_TREE_VIEW(qview));
595 gtk_tree_model_iter_nth_child (model, &iter, NULL, qview->toggled_row);
596
597 tree_path = gtk_tree_model_get_path (model, &iter);
598 view->rowref = gtk_tree_row_reference_new (model, tree_path);
599 gtk_tree_path_free (tree_path);
600
601 gtk_list_store_set (GTK_LIST_STORE(model), &iter, qview->toggled_column,
602 GPOINTER_TO_INT(item), -1);
603
604 tree_path = gtk_tree_row_reference_get_path (view->rowref);
605
606 if (gtk_tree_model_get_iter (model, &iter, tree_path))
607 {
608 gtk_tree_model_get (model, &iter, REC_POINTER, &entry, -1);
609 gnc_reconcile_view_toggle (view, entry);
610 }
611
612 // See if sorting on rec column, -1 to allow for the model pointer column at 0
613 if (qview->sort_column == REC_RECN - 1)
614 g_idle_add ((GSourceFunc)follow_select_tree_path, view);
615 else
616 {
617 gtk_tree_row_reference_free (view->rowref);
618 view->rowref = NULL;
619 }
620
621 gtk_tree_path_free (tree_path);
622}
623
624static void
625gnc_reconcile_view_double_click_entry (GNCQueryView *qview,
626 gpointer item,
627 gpointer user_data)
628{
629 GNCReconcileView *view;
630
631 /* item is the entry */
632 g_return_if_fail (user_data);
633 g_return_if_fail (GNC_IS_QUERY_VIEW(qview));
634
635 view = user_data;
636
637 g_signal_emit(G_OBJECT(view),
638 reconcile_view_signals[DOUBLE_CLICK_SPLIT], 0, item);
639}
640
641static void
642gnc_reconcile_view_row_selected (GNCQueryView *qview,
643 gpointer item,
644 gpointer user_data)
645{
646 GNCReconcileView *view;
647
648 /* item is the number of selected entries */
649 g_return_if_fail (user_data);
650 g_return_if_fail (GNC_IS_QUERY_VIEW(qview));
651
652 view = user_data;
653
654 g_signal_emit (G_OBJECT(view),
655 reconcile_view_signals[LINE_SELECTED], 0, item);
656}
657
658void
659gnc_reconcile_view_set_list (GNCReconcileView *view, gboolean reconcile)
660{
661 GNCQueryView *qview = GNC_QUERY_VIEW(view);
662 GtkTreeSelection *selection;
663 GtkTreeModel *model;
664 gpointer entry;
665 gboolean toggled;
666 GList *node;
667 GList *list_of_rows;
668 GList *rr_list = NULL;
669 GtkTreePath *last_tree_path = NULL;
670
671 model = gtk_tree_view_get_model (GTK_TREE_VIEW(qview));
672 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
673 list_of_rows = gtk_tree_selection_get_selected_rows (selection, &model);
674
675 /* First create a list of Row references */
676 for (node = list_of_rows; node; node = node->next)
677 {
678 GtkTreeRowReference *rowref = gtk_tree_row_reference_new (model, node->data);
679 rr_list = g_list_prepend (rr_list, rowref);
680 gtk_tree_path_free (node->data);
681 }
682
683 rr_list = g_list_reverse (rr_list);
684 for (node = rr_list; node; node = node->next)
685 {
686 GtkTreeIter iter;
687 GtkTreePath *path;
688 GtkTreeRowReference *rowref = node->data;
689
690 path = gtk_tree_row_reference_get_path (rowref);
691
692 if (gtk_tree_model_get_iter (model, &iter, path))
693 {
694 /* now iter is a valid row iterator */
695 gtk_tree_model_get (model, &iter, REC_POINTER, &entry,
696 REC_RECN, &toggled, -1);
697
698 gtk_list_store_set (GTK_LIST_STORE(model), &iter, REC_RECN, reconcile, -1);
699
700 if (last_tree_path)
701 gtk_tree_path_free (last_tree_path);
702 last_tree_path = gtk_tree_row_reference_get_path (rowref);
703
704 if (reconcile != toggled)
705 gnc_reconcile_view_toggle (view, entry);
706 }
707 gtk_tree_path_free (path);
708 }
709
710 if (last_tree_path)
711 {
712 // See if sorting on rec column, -1 to allow for the model pointer column at 0
713 if (qview->sort_column == REC_RECN -1)
714 {
715 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(qview),
716 last_tree_path, NULL, FALSE, 0.0, 0.0);
717 }
718 gtk_tree_path_free (last_tree_path);
719 last_tree_path = NULL;
720 }
721 g_list_foreach (rr_list, (GFunc) gtk_tree_row_reference_free, NULL);
722 g_list_free (rr_list);
723
724 // Out of site toggles on selected rows may not appear correctly drawn so
725 // queue a draw for the treeview widget
726 gtk_widget_queue_draw (GTK_WIDGET(qview));
727 g_list_free (list_of_rows);
728}
729
730gint
731gnc_reconcile_view_num_selected (GNCReconcileView *view )
732{
733 GNCQueryView *qview = GNC_QUERY_VIEW(view);
734 GtkTreeSelection *selection;
735
736 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
737 return gtk_tree_selection_count_selected_rows (selection);
738}
739
740static gboolean
741gnc_reconcile_view_set_toggle (GNCReconcileView *view)
742{
743 GNCQueryView *qview = GNC_QUERY_VIEW(view);
744 GtkTreeSelection *selection;
745 GtkTreeModel *model;
746 gboolean toggled;
747 GList *node;
748 GList *list_of_rows;
749 gint num_toggled = 0;
750 gint num_selected = 0;
751
752 model = gtk_tree_view_get_model (GTK_TREE_VIEW(qview));
753 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(qview));
754 list_of_rows = gtk_tree_selection_get_selected_rows (selection, &model);
755 num_selected = gtk_tree_selection_count_selected_rows (selection);
756
757 /* We get a list of TreePaths */
758 for (node = list_of_rows; node; node = node->next)
759 {
760 GtkTreeIter iter;
761 toggled = FALSE;
762 if (gtk_tree_model_get_iter (model, &iter, node->data))
763 {
764 /* now iter is a valid row iterator */
765 gtk_tree_model_get (model, &iter, REC_RECN, &toggled, -1);
766
767 if (toggled)
768 num_toggled++;
769 }
770 gtk_tree_path_free (node->data);
771 }
772 g_list_free (list_of_rows);
773
774 if (num_toggled == num_selected)
775 return FALSE;
776 else
777 return TRUE;
778}
779
780static gboolean
781gnc_reconcile_view_key_press_cb (GtkWidget *widget, GdkEventKey *event,
782 gpointer user_data)
783{
784 GNCReconcileView *view = GNC_RECONCILE_VIEW(user_data);
785 gboolean toggle;
786
787 switch (event->keyval)
788 {
789 case GDK_KEY_space:
790 g_signal_stop_emission_by_name (widget, "key_press_event");
791
792 toggle = gnc_reconcile_view_set_toggle (view);
793 gnc_reconcile_view_set_list (view, toggle);
794 return TRUE;
795 break;
796
797 default:
798 return FALSE;
799 }
800}
801
802static void
803gnc_reconcile_view_finalize (GObject *object)
804{
805 GNCReconcileView *view = GNC_RECONCILE_VIEW(object);
806
807 g_list_free_full (view->column_list, g_object_unref);
808 if (view->reconciled != NULL)
809 {
810 g_hash_table_destroy (view->reconciled);
811 view->reconciled = NULL;
812 }
813 G_OBJECT_CLASS(gnc_reconcile_view_parent_class)->finalize (object);
814}
815
816gint
817gnc_reconcile_view_get_num_splits (GNCReconcileView *view)
818{
819 g_return_val_if_fail (view != NULL, 0);
820 g_return_val_if_fail (GNC_IS_RECONCILE_VIEW(view), 0);
821
822 return gnc_query_view_get_num_entries (GNC_QUERY_VIEW(view));
823}
824
825Split *
826gnc_reconcile_view_get_current_split (GNCReconcileView *view)
827{
828 g_return_val_if_fail (view != NULL, NULL);
829 g_return_val_if_fail (GNC_IS_RECONCILE_VIEW(view), NULL);
830
831 return gnc_query_view_get_selected_entry (GNC_QUERY_VIEW(view));
832}
833
834/********************************************************************\
835 * gnc_reconcile_view_is_reconciled *
836 * Is the item a reconciled split? *
837 * *
838 * Args: item - the split to be checked *
839 * user_data - a pointer to the GNCReconcileView *
840 * Returns: whether the split is to be reconciled. *
841\********************************************************************/
842static gpointer
843gnc_reconcile_view_is_reconciled (gpointer item, gpointer user_data)
844{
845 GNCReconcileView *view = user_data;
846 Split *current;
847
848 g_return_val_if_fail (item, NULL);
849 g_return_val_if_fail (view, NULL);
850 g_return_val_if_fail (GNC_IS_RECONCILE_VIEW(view), NULL);
851
852 if (!view->reconciled)
853 return NULL;
854
855 current = g_hash_table_lookup (view->reconciled, item);
856 return GINT_TO_POINTER(current != NULL);
857}
858
859/********************************************************************\
860 * gnc_reconcile_view_refresh *
861 * refreshes the view *
862 * *
863 * Args: view - view to refresh *
864 * Returns: nothing *
865\********************************************************************/
866static gboolean
867grv_refresh_helper (gpointer key, gpointer value, gpointer user_data)
868{
869 GNCQueryView *qview = user_data;
870
871 return !gnc_query_view_item_in_view (qview, key);
872}
873
874void
875gnc_reconcile_view_refresh (GNCReconcileView *view)
876{
877 GNCQueryView *qview;
878
879 g_return_if_fail (view != NULL);
880 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
881
882 qview = GNC_QUERY_VIEW(view);
883 gnc_query_view_refresh (qview);
884
885 /* Ensure last selected split, if any, can be seen */
886 gnc_query_force_scroll_to_selection (qview);
887
888 /* Now verify that everything in the reconcile hash is still in qview */
889 if (view->reconciled)
890 g_hash_table_foreach_remove (view->reconciled, grv_refresh_helper, qview);
891}
892
893/********************************************************************\
894 * gnc_reconcile_view_reconciled_balance *
895 * returns the reconciled balance of the view *
896 * *
897 * Args: view - view to get reconciled balance of *
898 * Returns: reconciled balance (gnc_numeric) *
899\********************************************************************/
900static void
901grv_balance_hash_helper (gpointer key, gpointer value, gpointer user_data)
902{
903 Split *split = key;
904 gnc_numeric *total = user_data;
905
906 *total = gnc_numeric_add_fixed (*total, xaccSplitGetAmount (split));
907}
908
909gnc_numeric
910gnc_reconcile_view_reconciled_balance (GNCReconcileView *view)
911{
912 gnc_numeric total = gnc_numeric_zero ();
913
914 g_return_val_if_fail (view != NULL, total);
915 g_return_val_if_fail (GNC_IS_RECONCILE_VIEW(view), total);
916
917 if (view->reconciled == NULL)
918 return total;
919
920 g_hash_table_foreach (view->reconciled, grv_balance_hash_helper, &total);
921
922 return gnc_numeric_abs (total);
923}
924
925/********************************************************************\
926 * gnc_reconcile_view_commit *
927 * Commit the reconcile information in the view. Only change the *
928 * state of those items marked as reconciled. All others should *
929 * retain their previous state (none, cleared, voided, etc.). *
930 * *
931 * Args: view - view to commit *
932 * date - date to set as the reconcile date *
933 * Returns: nothing *
934\********************************************************************/
935static void
936grv_commit_hash_helper (gpointer key, gpointer value, gpointer user_data)
937{
938 Split *split = key;
939 time64 *date = user_data;
940
942 xaccSplitSetDateReconciledSecs (split, *date);
943}
944
945void
946gnc_reconcile_view_commit (GNCReconcileView *view, time64 date)
947{
948 g_return_if_fail (view != NULL);
949 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
950
951 if (view->reconciled == NULL)
952 return;
953
954 gnc_suspend_gui_refresh ();
955 g_hash_table_foreach (view->reconciled, grv_commit_hash_helper, &date);
956 gnc_resume_gui_refresh ();
957}
958
959/********************************************************************\
960 * gnc_reconcile_view_postpone *
961 * postpone the reconcile information in the view by setting *
962 * reconciled splits to cleared status *
963 * *
964 * Args: view - view to commit *
965 * Returns: nothing *
966\********************************************************************/
967void
968gnc_reconcile_view_postpone (GNCReconcileView *view)
969{
970 GtkTreeModel *model;
971 GtkTreeIter iter;
972 int num_splits;
973 int i;
974 gpointer entry = NULL;
975
976 g_return_if_fail (view != NULL);
977 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
978
979 if (view->reconciled == NULL)
980 return;
981
982 model = gtk_tree_view_get_model (GTK_TREE_VIEW(GNC_QUERY_VIEW(view)));
983 gtk_tree_model_get_iter_first (model, &iter);
984
985 num_splits = gnc_query_view_get_num_entries (GNC_QUERY_VIEW(view));
986
987 gnc_suspend_gui_refresh ();
988 for (i = 0; i < num_splits; i++)
989 {
990 char recn;
991
992 gtk_tree_model_get (model, &iter, REC_POINTER, &entry, -1);
993
994 // Don't change splits past reconciliation date that haven't been
995 // set to be reconciled
996 if (view->statement_date >= xaccTransGetDate (xaccSplitGetParent (entry)) ||
997 g_hash_table_lookup (view->reconciled, entry))
998 {
999 recn = g_hash_table_lookup (view->reconciled, entry) ? CREC : NREC;
1000 xaccSplitSetReconcile (entry, recn);
1001 }
1002 gtk_tree_model_iter_next (model, &iter);
1003 }
1004 gnc_resume_gui_refresh ();
1005}
1006
1007/********************************************************************\
1008 * gnc_reconcile_view_unselect_all *
1009 * unselect all splits in the view *
1010 * *
1011 * Args: view - view to unselect all *
1012 * Returns: nothing *
1013\********************************************************************/
1014void
1015gnc_reconcile_view_unselect_all (GNCReconcileView *view)
1016{
1017 g_return_if_fail (view != NULL);
1018 g_return_if_fail (GNC_IS_RECONCILE_VIEW(view));
1019
1020 gnc_query_view_unselect_all (GNC_QUERY_VIEW(view));
1021}
1022
1023/********************************************************************\
1024 * gnc_reconcile_view_changed *
1025 * returns true if any splits have been reconciled *
1026 * *
1027 * Args: view - view to get changed status for *
1028 * Returns: true if any reconciled splits *
1029\********************************************************************/
1030gboolean
1031gnc_reconcile_view_changed (GNCReconcileView *view)
1032{
1033 g_return_val_if_fail (view != NULL, FALSE);
1034 g_return_val_if_fail (GNC_IS_RECONCILE_VIEW(view), FALSE);
1035
1036 return g_hash_table_size (view->reconciled) != 0;
1037}
API for Transactions and Splits (journal entries).
Date and Time handling routines.
Generic api to store and retrieve preferences.
utility functions for the GnuCash UI
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
Definition Account.cpp:3025
gboolean xaccAccountGetReconcileChildrenStatus(const Account *acc)
DOCUMENT ME!
Definition Account.cpp:4876
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction nu...
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
time64 gnc_time64_get_day_end(time64 time_val)
The gnc_time64_get_day_end() routine will take the given time in seconds and adjust it to the last se...
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
gnc_numeric gnc_numeric_abs(gnc_numeric a)
Returns a newly created gnc_numeric that is the absolute value of the given gnc_numeric value.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
QofNumericMatch
Comparisons for QOF_TYPE_NUMERIC, QOF_TYPE_DEBCRED.
void qof_query_set_book(QofQuery *query, QofBook *book)
Set the book to be searched.
void qof_query_destroy(QofQuery *query)
Frees the resources associate with a Query object.
GList * qof_query_run(QofQuery *query)
Perform the query, return the results.
@ QOF_GUID_MATCH_ANY
These expect a single object and expect the QofAccessFunc returns GncGUID*.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
void xaccSplitSetDateReconciledSecs(Split *split, time64 secs)
Set the date on which this split was reconciled by specifying the time as time64.
#define NREC
not reconciled or cleared
Definition Split.h:76
#define CREC
The Split has been cleared.
Definition Split.h:73
#define YREC
The Split has been reconciled.
Definition Split.h:74
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
Encapsulate all the information about a dataset.
STRUCTS.