33#include <glib/gi18n.h>
43#include "engine-helpers.h"
46#include "dialog-utils.h"
47#include "dialog-lot-viewer.h"
48#include "gnc-component-manager.h"
52#include "gnc-session.h"
54#include "misc-gnome-utils.h"
55#include "tree-view-utils.h"
57#define LOT_VIEWER_CM_CLASS "dialog-lot-viewer"
77 SPLIT_COL_DESCRIPTION,
79 SPLIT_COL_AMOUNT_DOUBLE,
81 SPLIT_COL_VALUE_DOUBLE,
83 SPLIT_COL_GAIN_LOSS_DOUBLE,
85 SPLIT_COL_BALANCE_DOUBLE,
90#define RESPONSE_VIEW 1
91#define RESPONSE_DELETE 2
92#define RESPONSE_SCRUB_LOT 3
93#define RESPONSE_SCRUB_ACCOUNT 4
94#define RESPONSE_NEW_LOT 5
96#define GNC_PREFS_GROUP "dialogs.lot-viewer"
97#define GNC_PREF_HPOS "hpane-position"
98#define GNC_PREF_VPOS "vpane-position"
103#ifdef LOTS_READY_FOR_SHOWTIME
104 GtkButton * regview_button;
106 GtkButton * delete_button;
107 GtkButton * scrub_lot_button;
108 GtkButton * new_lot_button;
109 GtkTreeView * lot_view;
110 GtkListStore * lot_store;
111 GtkTextView * lot_notes;
112 GtkEntry * title_entry;
113 GtkTreeView * split_in_lot_view;
114 GtkListStore * split_in_lot_store;
115 GtkTreeView * split_free_view;
116 GtkListStore * split_free_store;
117 GtkWidget * split_hpaned;
118 GtkButton * add_split_to_lot_button;
119 GtkButton * remove_split_from_lot_button;
120 GtkToggleButton * only_show_open_lots_checkbutton;
121 GtkToggleButton * show_adjusted_amounts_checkbutton;
124 GNCLot * selected_lot;
129static void gnc_lot_viewer_fill (GNCLotViewer *lv);
130static void gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store,
SplitList *split_list);
135void lv_title_entry_changed_cb (GtkEntry *ent, gpointer user_data);
136void lv_response_cb (GtkDialog *dialog, gint response, gpointer data);
137void lv_window_destroy_cb (GtkWidget *
object, gpointer user_data);
146static gnc_commodity *
147find_first_currency (GNCLot *lot)
152 for (node = split_list; node; node = node->next)
154 Split *s = node->data;
164get_realized_gains (GNCLot *lot, gnc_commodity *currency)
166 gnc_numeric zero = gnc_numeric_zero ();
167 gnc_numeric gains = zero;
170 if (!currency)
return zero;
173 for (node = split_list; node; node = node->next)
175 Split *s = node->data;
192lv_show_splits_in_lot (GNCLotViewer *lv)
194 GNCLot *lot = lv->selected_lot;
197 if (NULL == lot)
return;
200 gnc_split_viewer_fill (lv, lv->split_in_lot_store, split_list);
207lv_show_splits_free (GNCLotViewer *lv)
216 for (node = split_list; node; node = node->next)
218 Split *split = node->data;
221 filtered_list = g_list_prepend (filtered_list, split);
224 filtered_list = g_list_reverse (filtered_list);
227 gnc_split_viewer_fill (lv, lv->split_free_store, filtered_list);
228 g_list_free (filtered_list);
229 g_list_free (split_list);
236lv_save_current_lot (GNCLotViewer *lv)
238 GNCLot *lot = lv->selected_lot;
244 gnc_lot_begin_edit (lot);
247 str = gtk_entry_get_text (lv->title_entry);
248 gnc_lot_set_title (lot, str);
251 notes = xxxgtk_textview_get_text (lv->lot_notes);
252 gnc_lot_set_notes (lot, notes);
255 gnc_lot_commit_edit (lot);
263lv_unset_lot (GNCLotViewer *lv)
266 lv->selected_lot = NULL;
269 gtk_entry_set_text (lv->title_entry,
"");
270 gtk_editable_set_editable (GTK_EDITABLE(lv->title_entry), FALSE);
273 xxxgtk_textview_set_text (lv->lot_notes,
"");
274 gtk_text_view_set_editable (lv->lot_notes, FALSE);
277 gtk_list_store_clear (lv->split_in_lot_store);
279#ifdef LOTS_READY_FOR_SHOWTIME
280 gtk_widget_set_sensitive (GTK_WIDGET(lv->regview_button), FALSE);
282 gtk_widget_set_sensitive (GTK_WIDGET(lv->delete_button), FALSE);
283 gtk_widget_set_sensitive (GTK_WIDGET(lv->scrub_lot_button), FALSE);
290lv_select_row (GNCLotViewer *lv,
295 lv_save_current_lot (lv);
297 str = gnc_lot_get_title (lot);
299 gtk_entry_set_text (lv->title_entry, str);
300 gtk_editable_set_editable (GTK_EDITABLE(lv->title_entry), TRUE);
303 str = gnc_lot_get_notes (lot);
305 xxxgtk_textview_set_text (lv->lot_notes, str);
306 gtk_text_view_set_editable (lv->lot_notes, TRUE);
309 lv->selected_lot = lot;
310 lv_show_splits_in_lot (lv);
312#ifdef LOTS_READY_FOR_SHOWTIME
313 gtk_widget_set_sensitive (GTK_WIDGET(lv->regview_button), TRUE);
315 gtk_widget_set_sensitive (GTK_WIDGET(lv->delete_button), TRUE);
316 gtk_widget_set_sensitive (GTK_WIDGET(lv->scrub_lot_button), TRUE);
323lv_unselect_row (GNCLotViewer *lv)
325 lv_save_current_lot (lv);
333gnc_lot_viewer_fill (GNCLotViewer *lv)
336 GNCLot *this_lot, *selected_lot = NULL;
340 GtkTreeSelection *selection = gtk_tree_view_get_selection (lv->lot_view);
341 gboolean found = FALSE;
343 gboolean show_only_open_lots = gtk_toggle_button_get_active (lv->only_show_open_lots_checkbutton);
345 if (gtk_tree_selection_get_selected (selection, &model, &iter))
346 gtk_tree_model_get (model, &iter, LOT_COL_PNTR, &selected_lot, -1);
349 gtk_list_store_clear (lv->lot_store);
351 for (
LotList *node = lot_list; node; node = node->next)
356 GNCLot *lot = node->data;
359 gnc_commodity *currency = find_first_currency (lot);
360 gnc_numeric gains_baln = get_realized_gains (lot, currency);
368 store = lv->lot_store;
369 gtk_list_store_append (store, &iter);
373 if ( NULL != gncInvoiceGetInvoiceFromLot (lot) )
375 snprintf (type_buff, 200,
"I");
377 gtk_list_store_set (store, &iter, LOT_COL_TYPE, type_buff, -1);
384 gtk_list_store_set (store, &iter, LOT_COL_OPEN, open_date, -1);
387 gtk_list_store_set (store, &iter, LOT_COL_OPEN, G_MININT64, -1);
396 gtk_list_store_set (store, &iter, LOT_COL_CLOSE, close_date, -1);
400 gtk_list_store_set (store, &iter, LOT_COL_CLOSE, G_MAXINT64, -1);
404 gtk_list_store_set (store, &iter, LOT_COL_TITLE, gnc_lot_get_title (lot), -1);
408 gnc_account_print_info (lv->account, is_business_lot));
409 gtk_list_store_set (store, &iter, LOT_COL_BALN, baln_buff, -1);
414 gnc_commodity_print_info (currency, TRUE));
415 gtk_list_store_set (store, &iter, LOT_COL_GAINS, gain_buff, -1);
419 gtk_list_store_set (store, &iter, LOT_COL_PNTR, lot, -1);
421 g_list_free (lot_list);
427 model = GTK_TREE_MODEL (lv->lot_store);
428 if (gtk_tree_model_get_iter_first (model, &iter))
432 gtk_tree_model_get (model, &iter, LOT_COL_PNTR, &this_lot, -1);
433 if (this_lot == selected_lot)
435 gtk_tree_selection_select_iter (selection, &iter);
440 while (gtk_tree_model_iter_next (model, &iter));
445 gtk_tree_selection_unselect_all (selection);
452lv_get_selected_split (GNCLotViewer *lv, GtkTreeView *view)
456 GtkTreeSelection *selection;
459 selection = gtk_tree_view_get_selection (view);
460 if (gtk_tree_selection_get_selected (selection, &model, &iter))
462 gtk_tree_model_get (model, &iter, SPLIT_COL_PNTR, &split, -1);
472lv_can_remove_split_from_lot (Split * split, GNCLot * lot)
474 GncInvoice *lot_invoice, *txn_invoice;
480 if ( lot_invoice != NULL && lot_invoice == txn_invoice )
490gnc_split_viewer_fill (GNCLotViewer *lv, GtkListStore *store,
SplitList *split_list)
493 gboolean show_adjusted_amounts = gtk_toggle_button_get_active (lv->show_adjusted_amounts_checkbutton);
494 gnc_numeric baln = gnc_numeric_zero ();
496 gtk_list_store_clear (store);
498 for (
SplitList *node = split_list; node; node = node->next)
500 Split *split = node->data;
505 gnc_commodity *currency;
509 gnc_numeric value, gain;
517 gtk_list_store_append (store, &iter);
520 gtk_list_store_set (store, &iter, SPLIT_COL_DATE, date, -1);
523 gtk_list_store_set (store, &iter, SPLIT_COL_NUM,
524 gnc_get_num_action (trans, split), -1);
531 gnc_account_print_info (lv->account, is_business_lot));
532 gtk_list_store_set (store, &iter, SPLIT_COL_AMOUNT, amtbuff, -1);
540 if (lv->selected_lot && !is_business_lot && (node != split_list))
543 gnc_commodity_print_info (currency, TRUE));
544 gtk_list_store_set (store, &iter, SPLIT_COL_VALUE, valbuff, -1);
548 gain = (store == lv->split_in_lot_store) ?
557 gnc_commodity_print_info (currency, TRUE));
559 gtk_list_store_set (store, &iter, SPLIT_COL_GAIN_LOSS, gainbuff, -1);
563 baln = gnc_numeric_add_fixed (baln, amnt);
571 gnc_account_print_info (lv->account, is_business_lot));
573 gtk_list_store_set (store, &iter, SPLIT_COL_BALANCE, balnbuff, -1);
577 gtk_list_store_set (store, &iter, SPLIT_COL_PNTR, split, -1);
584lv_update_split_buttons (GNCLotViewer *lv)
587 gtk_widget_set_sensitive (GTK_WIDGET(lv->add_split_to_lot_button), FALSE);
588 gtk_widget_set_sensitive (GTK_WIDGET(lv->remove_split_from_lot_button), FALSE);
589 if (NULL != lv->selected_lot)
591 if (NULL != lv_get_selected_split (lv, lv->split_free_view) )
593 gtk_widget_set_sensitive (GTK_WIDGET(lv->add_split_to_lot_button), TRUE);
595 split = lv_get_selected_split (lv, lv->split_in_lot_view);
596 if (NULL != split && TRUE == lv_can_remove_split_from_lot (split, lv->selected_lot))
598 gtk_widget_set_sensitive (GTK_WIDGET(lv->remove_split_from_lot_button), TRUE);
603static void set_window_title (GNCLotViewer *lv)
605 gchar *win_title = g_strdup_printf (
_(
"Lots in Account %s"),
xaccAccountGetName (lv->account));
606 gtk_window_set_title (GTK_WINDOW (lv->window), win_title);
610static void set_adjusted_ammounts_checkbutton_visibility (GNCLotViewer *lv)
612 GtkWidget *widget = GTK_WIDGET(lv->show_adjusted_amounts_checkbutton);
615 gtk_widget_set_visible (widget, has_stock_split);
616 gtk_widget_set_no_show_all (widget, !has_stock_split);
619static void lv_refresh (GNCLotViewer *lv)
621 gnc_lot_viewer_fill (lv);
622 lv_show_splits_free (lv);
623 lv_show_splits_in_lot (lv);
624 set_window_title (lv);
625 set_adjusted_ammounts_checkbutton_visibility (lv);
631lv_refresh_handler (GHashTable *changes, gpointer user_data)
633 GNCLotViewer *lv = user_data;
637 const EventInfo *info = gnc_gui_get_entity_events (changes, &lv->account_id);
638 if (info && (info->event_mask & QOF_EVENT_DESTROY))
640 gnc_close_gui_component (lv->component_id);
649lv_close_handler (gpointer user_data)
651 GNCLotViewer *lv = user_data;
653 lv_save_current_lot (lv);
655 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(lv->window));
656 gtk_widget_destroy (lv->window);
664lv_title_entry_changed_cb (GtkEntry *ent, gpointer user_data)
666 GNCLotViewer *lv = user_data;
669 GtkTreeSelection *selection;
671 title = gtk_entry_get_text (lv->title_entry);
673 selection = gtk_tree_view_get_selection (lv->lot_view);
674 if (gtk_tree_selection_get_selected (selection, &model, &iter))
676 gtk_list_store_set (GTK_LIST_STORE(model), &iter, LOT_COL_TITLE, title, -1);
684lv_selection_changed_cb (GtkTreeSelection *selection,
691 if (gtk_tree_selection_get_selected (selection, &model, &iter))
693 gtk_tree_model_get (model, &iter, LOT_COL_PNTR, &lot, -1);
694 lv_select_row (lv, lot);
698 lv_unselect_row (lv);
700 lv_update_split_buttons (lv);
707lv_window_destroy_cb (GtkWidget *
object, gpointer user_data)
709 GNCLotViewer *lv = user_data;
711 gnc_unregister_gui_component (lv->component_id);
717lv_split_selection_changed_cb (GtkTreeSelection *selection,
720 lv_update_split_buttons (lv);
724lv_add_split_to_lot_cb (GtkWidget *widget, GNCLotViewer * lv)
728 if ( NULL == lv->selected_lot )
return;
729 split = lv_get_selected_split (lv, lv->split_free_view);
730 if ( NULL == split )
return;
732 gnc_suspend_gui_refresh ();
736 gnc_resume_gui_refresh ();
742lv_remove_split_from_lot_cb (GtkWidget *widget, GNCLotViewer * lv)
746 if ( NULL == lv->selected_lot )
return;
747 split = lv_get_selected_split (lv, lv->split_in_lot_view);
748 if ( NULL == split )
return;
750 if ( FALSE == lv_can_remove_split_from_lot (split, lv->selected_lot) )
753 gnc_suspend_gui_refresh ();
757 gnc_resume_gui_refresh ();
763lv_only_show_open_lots_changed_cb (GtkWidget *widget, GNCLotViewer * lv)
769lv_show_adjusted_amounts_changed_cb (GtkWidget *widget, GNCLotViewer * lv)
778lv_response_cb (GtkDialog *dialog, gint response, gpointer data)
780 GNCLotViewer *lv = data;
781 GNCLot *lot = lv->selected_lot;
785 case GTK_RESPONSE_CLOSE:
786 gnc_close_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
792 printf (
"UNIMPLEMENTED: need to display register showing only this one lot.\n");
795 case RESPONSE_DELETE:
799 if (NULL != gncInvoiceGetInvoiceFromLot (lot))
802 gnc_lot_destroy (lot);
804 gnc_lot_viewer_fill (lv);
807 case RESPONSE_SCRUB_LOT:
814 gnc_lot_viewer_fill (lv);
815 lv_show_splits_in_lot (lv);
818 case RESPONSE_SCRUB_ACCOUNT:
819 gnc_suspend_gui_refresh ();
824 gnc_resume_gui_refresh ();
828 case RESPONSE_NEW_LOT:
829 lv_save_current_lot (lv);
838static gchar* lot_get_open_date (GNCLot *lot)
840 g_return_val_if_fail (lot, NULL);
843 return g_strdup (
_(
"Empty"));
848static gchar* lot_get_closing_date (GNCLot *lot)
850 g_return_val_if_fail (lot, NULL);
855 return g_strdup (C_(
"Adjective",
"Open"));
860typedef gchar* (*LotToDateFunc) (GNCLot *lot);
862static void lot_print_date (GtkTreeViewColumn *tree_column,
863 GtkCellRenderer *cell,
864 GtkTreeModel *tree_model,
866 LotToDateFunc lot_to_date)
871 g_return_if_fail (cell && iter && tree_model);
872 gtk_tree_model_get (tree_model, iter, LOT_COL_PNTR, &lot, -1);
875 str = lot_to_date (lot);
877 g_object_set (G_OBJECT (cell),
"text", str, NULL);
881static void print_date (GtkTreeViewColumn *tree_column,
882 GtkCellRenderer *cell,
883 GtkTreeModel *tree_model,
889 gint col = GPOINTER_TO_INT(data);
891 g_return_if_fail (cell && iter && tree_model);
893 gtk_tree_model_get (tree_model, iter, col, &doc_date_time, -1);
896 g_object_set (G_OBJECT (cell),
"text", doc_date_str, NULL);
897 g_free (doc_date_str);
901configure_number_columns (GtkTreeViewColumn *column,
902 GtkCellRenderer *renderer, gint sort_column)
904 gtk_tree_view_column_set_sort_column_id (column, sort_column);
905 gtk_cell_renderer_set_alignment (renderer, 1.0, 0.5);
906 gtk_tree_view_column_set_alignment (column, 1.0);
907 gtk_cell_renderer_set_padding (renderer, 5, 0);
911lv_init_lot_view (GNCLotViewer *lv)
915 GtkTreeViewColumn *column;
916 GtkTreeSelection *selection;
917 GtkCellRenderer *renderer;
919 g_return_if_fail (GTK_IS_TREE_VIEW(lv->lot_view));
922 store = gtk_list_store_new (NUM_LOT_COLS, G_TYPE_STRING, G_TYPE_INT64,
923 G_TYPE_INT64, G_TYPE_STRING,
924 G_TYPE_STRING, G_TYPE_DOUBLE,
925 G_TYPE_STRING,G_TYPE_DOUBLE,
927 gtk_tree_view_set_model (view, GTK_TREE_MODEL(store));
928 g_object_unref (store);
929 lv->lot_store = store;
932 renderer = gtk_cell_renderer_text_new ();
933 column = gtk_tree_view_column_new_with_attributes (
_(
"Type"), renderer,
934 "text", LOT_COL_TYPE, NULL);
935 gtk_tree_view_column_set_sort_column_id (column, LOT_COL_TYPE);
936 gtk_tree_view_append_column (view, column);
938 renderer = gtk_cell_renderer_text_new ();
939 column = gtk_tree_view_column_new_with_attributes (
_(
"Opened"), renderer,
940 "text", LOT_COL_OPEN, NULL);
941 gtk_tree_view_column_set_sort_column_id (column, LOT_COL_OPEN);
943 gtk_tree_view_column_set_cell_data_func (column, renderer,
944 (GtkTreeCellDataFunc) lot_print_date,
945 lot_get_open_date, NULL);
946 gtk_tree_view_append_column (view, column);
948 renderer = gtk_cell_renderer_text_new ();
949 column = gtk_tree_view_column_new_with_attributes (
_(
"Closed"), renderer,
950 "text", LOT_COL_CLOSE, NULL);
951 gtk_tree_view_column_set_sort_column_id (column, LOT_COL_CLOSE);
953 gtk_tree_view_column_set_cell_data_func (column, renderer,
954 (GtkTreeCellDataFunc) lot_print_date,
955 lot_get_closing_date, NULL);
956 gtk_tree_view_append_column (view, column);
958 renderer = gtk_cell_renderer_text_new ();
959 column = gtk_tree_view_column_new_with_attributes (
_(
"Title"), renderer,
960 "text", LOT_COL_TITLE, NULL);
961 gtk_tree_view_column_set_sort_column_id (column, LOT_COL_TITLE);
962 gtk_tree_view_column_set_expand (column, TRUE);
963 gtk_tree_view_append_column (view, column);
965 renderer = gtk_cell_renderer_text_new ();
966 column = gtk_tree_view_column_new_with_attributes (
_(
"Balance"), renderer,
967 "text", LOT_COL_BALN, NULL);
968 configure_number_columns (column, renderer, LOT_COL_BALN_DOUBLE);
969 gtk_tree_view_append_column (view, column);
971 renderer = gtk_cell_renderer_text_new ();
972 column = gtk_tree_view_column_new_with_attributes (
_(
"Gains"), renderer,
973 "text", LOT_COL_GAINS, NULL);
974 configure_number_columns (column, renderer, LOT_COL_GAINS_DOUBLE);
975 gtk_tree_view_append_column (view, column);
978 selection = gtk_tree_view_get_selection (view);
979 g_signal_connect (selection,
"changed",
980 G_CALLBACK(lv_selection_changed_cb), lv);
986lv_init_split_view (GNCLotViewer *lv, GtkTreeView *view)
989 GtkTreeViewColumn *column;
990 GtkTreeSelection *selection;
991 GtkCellRenderer *renderer;
993 g_return_val_if_fail (GTK_IS_TREE_VIEW(view), NULL);
995 store = gtk_list_store_new (NUM_SPLIT_COLS, G_TYPE_INT64,
996 G_TYPE_STRING, G_TYPE_STRING,
997 G_TYPE_STRING, G_TYPE_DOUBLE,
998 G_TYPE_STRING, G_TYPE_DOUBLE,
999 G_TYPE_STRING, G_TYPE_DOUBLE,
1000 G_TYPE_STRING, G_TYPE_DOUBLE,
1002 gtk_tree_view_set_model (view, GTK_TREE_MODEL(store));
1003 g_object_unref (store);
1006 renderer = gtk_cell_renderer_text_new ();
1007 column = gtk_tree_view_column_new_with_attributes (
_(
"Date"), renderer,
1008 "text", SPLIT_COL_DATE, NULL);
1009 gtk_tree_view_column_set_sort_column_id (column, SPLIT_COL_DATE);
1011 gtk_tree_view_column_set_cell_data_func (column, renderer,
1012 (GtkTreeCellDataFunc) print_date,
1013 GINT_TO_POINTER (SPLIT_COL_DATE), NULL);
1014 gtk_tree_view_append_column (view, column);
1016 renderer = gtk_cell_renderer_text_new ();
1017 column = gtk_tree_view_column_new_with_attributes (
_(
"Num"), renderer,
1018 "text", SPLIT_COL_NUM, NULL);
1019 gtk_tree_view_column_set_sort_column_id (column, SPLIT_COL_NUM);
1020 gtk_tree_view_append_column (view, column);
1022 renderer = gtk_cell_renderer_text_new ();
1023 column = gtk_tree_view_column_new_with_attributes (
_(
"Description"), renderer,
1024 "text", SPLIT_COL_DESCRIPTION, NULL);
1026 g_object_set (renderer,
"ellipsize", PANGO_ELLIPSIZE_END, NULL);
1029 gtk_tree_view_column_set_min_width (column, 200);
1031 gtk_tree_view_column_set_sort_column_id (column, SPLIT_COL_DESCRIPTION);
1032 gtk_tree_view_column_set_expand (column, TRUE);
1033 gtk_tree_view_column_set_resizable (column, TRUE);
1034 gtk_tree_view_append_column (view, column);
1036 renderer = gtk_cell_renderer_text_new ();
1037 column = gtk_tree_view_column_new_with_attributes (
_(
"Amount"), renderer,
1038 "text", SPLIT_COL_AMOUNT, NULL);
1039 configure_number_columns (column, renderer, SPLIT_COL_AMOUNT_DOUBLE);
1040 gtk_tree_view_append_column (view, column);
1042 renderer = gtk_cell_renderer_text_new ();
1043 column = gtk_tree_view_column_new_with_attributes (
_(
"Value"), renderer,
1044 "text", SPLIT_COL_VALUE, NULL);
1045 configure_number_columns (column, renderer, SPLIT_COL_VALUE_DOUBLE);
1046 gtk_tree_view_append_column (view, column);
1048 renderer = gtk_cell_renderer_text_new ();
1049 column = gtk_tree_view_column_new_with_attributes (
_(
"Gain/Loss"), renderer,
1050 "text", SPLIT_COL_GAIN_LOSS, NULL);
1051 configure_number_columns (column, renderer, SPLIT_COL_GAIN_LOSS_DOUBLE);
1052 gtk_tree_view_append_column (view, column);
1054 renderer = gtk_cell_renderer_text_new ();
1055 column = gtk_tree_view_column_new_with_attributes (
_(
"Balance"), renderer,
1056 "text", SPLIT_COL_BALANCE, NULL);
1057 configure_number_columns (column, renderer, SPLIT_COL_BALANCE_DOUBLE);
1058 gtk_tree_view_append_column (view, column);
1061 selection = gtk_tree_view_get_selection (view);
1062 g_signal_connect (selection,
"changed",
1063 G_CALLBACK(lv_split_selection_changed_cb), lv);
1069lv_init_split_views (GNCLotViewer *lv)
1071 lv->split_free_store = lv_init_split_view (lv, lv->split_free_view);
1072 lv->split_in_lot_store = lv_init_split_view (lv, lv->split_in_lot_view);
1076lv_init_split_buttons (GNCLotViewer *lv)
1079 g_signal_connect (G_OBJECT(lv->add_split_to_lot_button),
"clicked",
1080 G_CALLBACK(lv_add_split_to_lot_cb), lv);
1081 g_signal_connect (G_OBJECT(lv->remove_split_from_lot_button),
"clicked",
1082 G_CALLBACK(lv_remove_split_from_lot_cb), lv);
1088window_realize_set_split_paned_position_cb (GtkWidget *widget, gpointer user_data)
1090 GNCLotViewer *lv = user_data;
1093 gtk_window_get_size (GTK_WINDOW(lv->window), &width, NULL);
1094 gtk_paned_set_position (GTK_PANED(lv->split_hpaned), width / 2);
1098lv_create (GNCLotViewer *lv, GtkWindow *parent)
1100 GtkBuilder *builder;
1102 builder = gtk_builder_new ();
1103 gnc_builder_add_from_file (builder,
"dialog-lot-viewer.glade",
"lot_viewer_dialog");
1105 lv->window = GTK_WIDGET(gtk_builder_get_object (builder,
"lot_viewer_dialog"));
1107 gtk_window_set_transient_for (GTK_WINDOW (lv->window), parent);
1110 gtk_widget_set_name (GTK_WIDGET(lv->window),
"gnc-id-lot-viewer");
1112#ifdef LOTS_READY_FOR_SHOWTIME
1113 lv->regview_button = GTK_BUTTON(glade_xml_get_widget (builder,
"regview_button"));
1115 lv->delete_button = GTK_BUTTON(gtk_builder_get_object (builder,
"delete_button"));
1116 lv->scrub_lot_button = GTK_BUTTON(gtk_builder_get_object (builder,
"scrub_lot_button"));
1117 lv->new_lot_button = GTK_BUTTON(gtk_builder_get_object (builder,
"new_lot_button"));
1119 lv->only_show_open_lots_checkbutton = GTK_TOGGLE_BUTTON(gtk_builder_get_object (builder,
"only_show_open_lots_checkbutton"));
1120 g_signal_connect (lv->only_show_open_lots_checkbutton,
"toggled", G_CALLBACK(lv_only_show_open_lots_changed_cb), lv);
1122 lv->show_adjusted_amounts_checkbutton = GTK_TOGGLE_BUTTON(gtk_builder_get_object (builder,
"show_adjusted_amounts_checkbutton"));
1123 g_signal_connect (lv->show_adjusted_amounts_checkbutton,
"toggled", G_CALLBACK(lv_show_adjusted_amounts_changed_cb), lv);
1124 set_adjusted_ammounts_checkbutton_visibility (lv);
1126 lv->lot_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"lot_view"));
1127 lv_init_lot_view (lv);
1128 lv->lot_notes = GTK_TEXT_VIEW(gtk_builder_get_object (builder,
"lot_notes_text"));
1129 lv->title_entry = GTK_ENTRY (gtk_builder_get_object (builder,
"lot_title_entry"));
1131 lv->split_in_lot_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"split_in_lot_view"));
1132 lv->split_free_view = GTK_TREE_VIEW(gtk_builder_get_object (builder,
"split_free_view"));
1133 lv->split_hpaned = GTK_WIDGET(gtk_builder_get_object (builder,
"split_hpaned"));
1134 lv_init_split_views (lv);
1136 lv->add_split_to_lot_button = GTK_BUTTON(gtk_builder_get_object (builder,
"add_split_to_lot_button"));
1137 lv->remove_split_from_lot_button = GTK_BUTTON(gtk_builder_get_object (builder,
"remove_split_from_lot_button"));
1138 lv_init_split_buttons (lv);
1141 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(lv->lot_view), gnc_tree_view_get_grid_lines_pref ());
1144 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(lv->split_in_lot_view), gnc_tree_view_get_grid_lines_pref ());
1147 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(lv->split_free_view), gnc_tree_view_get_grid_lines_pref ());
1153 object = gtk_builder_get_object (builder,
"lot_vpaned");
1154 gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_VPOS, NULL,
object,
"position");
1156 object = gtk_builder_get_object (builder,
"lot_hpaned");
1157 gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_HPOS, NULL,
object,
"position");
1160 lv->selected_lot = NULL;
1163 g_signal_connect (G_OBJECT(lv->window),
"realize",
1164 G_CALLBACK(window_realize_set_split_paned_position_cb), lv);
1167 gtk_builder_connect_signals (builder, lv);
1168 g_object_unref (G_OBJECT(builder));
1170 lv_update_split_buttons (lv);
1172 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(lv->window), parent);
1173 gtk_widget_show_all (lv->window);
1174 gnc_window_adjust_for_screen (GTK_WINDOW(lv->window));
1180gnc_lot_viewer_dialog (GtkWindow *parent,
Account *account)
1184 if (!account)
return NULL;
1186 lv = g_new0 (GNCLotViewer, 1);
1187 lv->account = account;
1188 lv_create (lv, parent);
1191 lv->component_id = gnc_register_gui_component (LOT_VIEWER_CM_CLASS, lv_refresh_handler, lv_close_handler, lv);
1194 gnc_gui_component_set_session (lv->component_id, gnc_get_current_session ());
1195 gnc_gui_component_watch_entity_type (lv->component_id, GNC_ID_LOT,
1196 QOF_EVENT_CREATE | QOF_EVENT_ADD | QOF_EVENT_REMOVE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1197 gnc_gui_component_watch_entity (lv->component_id, &lv->account_id,
1198 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY | GNC_EVENT_ITEM_CHANGED);
Account handling public routines.
High-Level API for imposing Lot constraints.
Cleanup functions for business objects.
API for Transactions and Splits (journal entries)
Utilities to Automatically Compute Capital Gains/Losses.
Commodity handling public routines.
Additional event handling code.
Generic api to store and retrieve preferences.
utility functions for the GnuCash UI
Functions that are supported by all types of windows.
Business Invoice Interface.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
#define xaccAccountGetGUID(X)
gboolean xaccAccountHasStockSplit(const Account *acc)
Returns true if the account has a stock split, otherwise false.
gnc_numeric xaccSplitGetCapGains(Split *split)
The xaccSplitGetCapGains() method returns the value of capital gains (if any) associated with the ind...
gnc_numeric xaccLotFreeSplitCapGain(Split *split, GNCLot *lot)
The xaccLotFreeSplitCapGain() method returns the value of capital gain (if any) associated with the i...
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
char * qof_print_date(time64 t)
Convenience; calls through to qof_print_date_dmy_buff().
LotList * xaccAccountGetLotList(const Account *acc)
The xaccAccountGetLotList() routine returns a list of all lots in this account.
GList LotList
GList of GNCLots.
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
gboolean xaccAccountIsAPARType(GNCAccountType t)
Convenience function to check if the account is a valid business account type (meaning an Accounts Pa...
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
GList SplitList
GList of Split.
SplitList * xaccAccountGetSplitList(const Account *acc)
The xaccAccountGetSplitList() routine returns a pointer to a GList of the splits in the account.
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
void tree_view_column_set_default_width(GtkTreeView *view, GtkTreeViewColumn *column, const gchar *sizing_text)
Set default width for a treeview column.
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
GncInvoice * gncInvoiceGetInvoiceFromTxn(const Transaction *txn)
Given a transaction, find and return the Invoice.
GncInvoice * gncInvoiceGetInvoiceFromLot(GNCLot *lot)
Given a LOT, find and return the Invoice attached to the lot.
Split * gnc_lot_get_latest_split(GNCLot *lot)
Convenience routineto identify the date this lot was closed.
GNCLot * gnc_lot_make_default(Account *acc)
void gnc_lot_add_split(GNCLot *lot, Split *split)
Adds a split to this lot.
Account * gnc_lot_get_account(const GNCLot *lot)
Returns the account with which this lot is associated.
gnc_numeric gnc_lot_get_balance(GNCLot *lot)
Returns the lot balance.
void gnc_lot_remove_split(GNCLot *lot, Split *split)
Adds a split from this lot.
SplitList * gnc_lot_get_split_list(const GNCLot *lot)
Returns a list of all the splits in this lot.
gboolean gnc_lot_is_closed(GNCLot *lot)
Returns closed status of the given lot.
Split * gnc_lot_get_earliest_split(GNCLot *lot)
Convenience routine to identify the earliest date in the lot.
double gnc_numeric_to_double(gnc_numeric in)
Convert numeric to floating-point value.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, const gchar *pref_value, gpointer object, const gchar *property)
Bind a setting to a g_object property.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
void xaccAccountScrubLots(Account *acc)
The xaccAccountScrubLots() routine makes sure that every split in the account is assigned to a lot,...
gboolean xaccScrubLot(GNCLot *lot)
The xaccScrubLot() routine makes sure that the indicated lot is self-consistent and properly balanced...
void gncScrubBusinessAccountLots(Account *acc, QofPercentageFunc percentagefunc)
The gncScrubBusinessAccountLots() function will call gncScrubBusinessLot() on each lot in the given a...
gboolean gncScrubBusinessLot(GNCLot *lot)
The gncScrubBusinessLot() function makes sure that the indicated lot has all the correct properties r...
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
GNCLot * xaccSplitGetLot(const Split *split)
Returns the pointer to the debited/credited Lot where this split belongs to, or NULL if it doesn't be...
gnc_numeric xaccSplitGetValue(const Split *split)
Returns the value of this split in the transaction's commodity.
gnc_numeric xaccSplitGetAdjustedAmount(const Split *s)
Returns the stock-split adjusted amount of the split in the account's commodity.
gboolean xaccSplitIsStockSplit(Split *s)
Returns true if the split is of type stock split.
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.
The type used to store guids in C.