28 #include <glib/gi18n.h> 38 #include "gnc-component-manager.h" 42 #include "gnc-hooks.h" 43 #include "gnc-session.h" 44 #include "gnc-icons.h" 45 #include "gnc-ui-balances.h" 46 #include "dialog-utils.h" 47 #include "window-main-summarybar.h" 49 #define SAMPLE_OWNER_VALUE "$1,000,000.00" 54 static QofLogModule log_module = GNC_MOD_GUI;
57 static void gnc_tree_view_owner_finalize (GObject *
object);
59 static void gtvo_update_column_names (GncTreeViewOwner *view);
60 static void gtvo_currency_changed_cb (
void);
62 static gboolean gnc_tree_view_owner_filter_helper (GtkTreeModel *model,
67 static void gtvo_setup_column_renderer_edited_cb(GncTreeViewOwner *owner_view,
68 GtkTreeViewColumn *column,
69 GtkCellRenderer *renderer,
70 GncTreeViewOwnerColumnTextEdited col_edited_cb);
75 GncTreeView gnc_tree_view;
82 GSourceFunc filter_destroy;
84 GtkTreeViewColumn *name_column;
85 GtkTreeViewColumn *id_column;
86 GtkTreeViewColumn *balance_report_column;
87 GtkTreeViewColumn *notes_column;
95 G_DEFINE_TYPE(GncTreeViewOwner, gnc_tree_view_owner, GNC_TYPE_TREE_VIEW)
98 gnc_tree_view_owner_class_init (GncTreeViewOwnerClass *klass)
100 GObjectClass *o_class;
103 o_class = G_OBJECT_CLASS (klass);
104 o_class->finalize = gnc_tree_view_owner_finalize;
106 gnc_hook_add_dangler(HOOK_CURRENCY_CHANGED,
107 (GFunc)gtvo_currency_changed_cb, NULL, NULL);
118 gnc_init_owner_view_info(OwnerViewInfo *ovi)
120 ovi->show_inactive = FALSE;
124 gnc_tree_view_owner_init (GncTreeViewOwner *view)
126 gnc_init_owner_view_info(&view->ovi);
130 gnc_tree_view_owner_finalize (GObject *
object)
132 ENTER(
"view %p",
object);
133 g_return_if_fail (
object != NULL);
134 g_return_if_fail (GNC_IS_TREE_VIEW_OWNER (
object));
136 GncTreeViewOwner *view = GNC_TREE_VIEW_OWNER (
object);
138 if (view->filter_destroy)
140 view->filter_destroy(view->filter_data);
141 view->filter_destroy = NULL;
143 view->filter_fn = NULL;
145 G_OBJECT_CLASS (gnc_tree_view_owner_parent_class)->finalize (
object);
154 gnc_tree_view_owner_active_toggled (GtkCellRendererToggle *cell,
155 const gchar *s_path_str,
158 GncTreeViewOwner *tree_view;
164 tree_view = user_data;
165 s_path = gtk_tree_path_new_from_string (s_path_str);
169 active = !gtk_cell_renderer_toggle_get_active (cell);
170 gncOwnerSetActive (owner, active);
174 gtk_tree_path_free (s_path);
182 static GtkTreeModel *
183 sort_cb_setup_w_iters (GtkTreeModel *f_model,
184 GtkTreeIter *f_iter_a,
185 GtkTreeIter *f_iter_b,
193 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
194 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
197 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
206 sort_cb_setup (GtkTreeModel *f_model,
207 GtkTreeIter *f_iter_a,
208 GtkTreeIter *f_iter_b,
212 GtkTreeIter iter_a, iter_b;
214 sort_cb_setup_w_iters (f_model, f_iter_a, f_iter_b,
215 &iter_a, &iter_b, owner_a, owner_b);
219 sort_by_string (GtkTreeModel *f_model,
220 GtkTreeIter *f_iter1,
221 GtkTreeIter *f_iter2,
225 GtkTreeIter iter1, iter2;
228 gint column = GPOINTER_TO_INT(user_data);
231 model = sort_cb_setup_w_iters(f_model, f_iter1, f_iter2, &iter1, &iter2, &owner1, &owner2);
234 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter1, column, &str1, -1);
235 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter2, column, &str2, -1);
246 sort_by_boolean (GtkTreeModel *f_model,
247 GtkTreeIter *f_iter1,
248 GtkTreeIter *f_iter2,
252 GtkTreeIter iter1, iter2;
254 gboolean *bool1, *bool2;
255 gint column = GPOINTER_TO_INT(user_data);
257 model = sort_cb_setup_w_iters(f_model, f_iter1, f_iter2, &iter1, &iter2, &owner1, &owner2);
260 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter1, column, &bool1, -1);
261 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter2, column, &bool2, -1);
277 sort_by_xxx_value (GtkTreeModel *f_model,
278 GtkTreeIter *f_iter_a,
279 GtkTreeIter *f_iter_b,
283 gnc_numeric balance_a, balance_b;
287 sort_cb_setup (f_model, f_iter_a, f_iter_b, (
const GncOwner**)&owner_a, (
const GncOwner**)&owner_b);
289 balance_a = gnc_ui_owner_get_balance_full(owner_a, NULL, NULL);
290 balance_b = gnc_ui_owner_get_balance_full(owner_b, NULL, NULL);
299 sort_by_balance_value (GtkTreeModel *f_model,
300 GtkTreeIter *f_iter_a,
301 GtkTreeIter *f_iter_b,
304 return sort_by_xxx_value (f_model, f_iter_a, f_iter_b, user_data);
321 GtkTreeModel *model, *f_model, *s_model;
322 const gchar *sample_type, *sample_currency;
323 const gchar *owner_name = NULL, * owner_id = NULL;
329 case GNC_OWNER_NONE :
330 case GNC_OWNER_UNDEFINED :
331 PWARN(
"missing owner_type");
332 owner_name = _(
"Name");
333 owner_id = _(
"ID #");
335 case GNC_OWNER_CUSTOMER :
336 owner_name = _(
"Company Name");
337 owner_id = _(
"Customer Number");
340 owner_name = _(
"Job Name");
341 owner_id = _(
"Job Number");
343 case GNC_OWNER_VENDOR :
344 owner_name = _(
"Company Name");
345 owner_id = _(
"Vendor Number");
347 case GNC_OWNER_EMPLOYEE :
348 owner_name = _(
"Employee Name");
349 owner_id = _(
"Employee Number");
353 GncTreeViewOwner *view = g_object_new (GNC_TYPE_TREE_VIEW_OWNER,
354 "name",
"gnc-id-owner-tree", NULL);
360 f_model = gtk_tree_model_filter_new (model, NULL);
363 g_object_unref(G_OBJECT(model));
366 s_model = gtk_tree_model_sort_new_with_model(f_model);
367 g_object_unref(G_OBJECT(f_model));
368 gtk_tree_view_set_model (GTK_TREE_VIEW (view), s_model);
369 g_object_unref(G_OBJECT(s_model));
372 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
379 NULL,
"GnuCash Inc.",
380 GNC_TREE_MODEL_OWNER_COL_NAME,
381 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
385 GNC_TREE_MODEL_OWNER_COL_TYPE,
386 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
391 GNC_TREE_MODEL_OWNER_COL_ID,
392 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
395 NULL, sample_currency,
396 GNC_TREE_MODEL_OWNER_COL_CURRENCY,
397 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
400 NULL,
"GnuCash Inc.",
401 GNC_TREE_MODEL_OWNER_COL_ADDRESS_NAME,
402 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
405 NULL,
"Free Software Foundation",
406 GNC_TREE_MODEL_OWNER_COL_ADDRESS_1,
407 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
410 NULL,
"51 Franklin Street, Fifth Floor",
411 GNC_TREE_MODEL_OWNER_COL_ADDRESS_2,
412 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
415 NULL,
"Boston, MA 02110-1301",
416 GNC_TREE_MODEL_OWNER_COL_ADDRESS_3,
417 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
421 GNC_TREE_MODEL_OWNER_COL_ADDRESS_4,
422 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
425 NULL,
"+1-617-542-5942",
426 GNC_TREE_MODEL_OWNER_COL_PHONE,
427 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
430 NULL,
"+1-617-542-2652",
431 GNC_TREE_MODEL_OWNER_COL_FAX,
432 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
436 GNC_TREE_MODEL_OWNER_COL_EMAIL,
437 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
441 GNC_TREE_MODEL_OWNER_COL_BALANCE,
442 GNC_TREE_MODEL_OWNER_COL_COLOR_BALANCE,
443 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
444 sort_by_balance_value);
446 view->balance_report_column
449 GNC_TREE_MODEL_OWNER_COL_BALANCE_REPORT,
450 GNC_TREE_MODEL_OWNER_COL_COLOR_BALANCE,
451 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
452 sort_by_balance_value);
456 "Sample owner notes.",
457 GNC_TREE_MODEL_OWNER_COL_NOTES,
458 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
461 C_(
"Column letter for 'Active'",
"A"),
462 GNC_OWNER_TREE_ACTIVE_COL,
463 GNC_TREE_MODEL_OWNER_COL_ACTIVE,
464 GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
466 gnc_tree_view_owner_active_toggled);
469 gtvo_update_column_names(view);
473 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (f_model),
474 gnc_tree_view_owner_filter_helper,
479 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(s_model),
480 GNC_TREE_MODEL_OWNER_COL_NAME,
483 gtk_widget_show(GTK_WIDGET(view));
485 return GTK_TREE_VIEW(view);
492 #define debug_path(fn, path) { \ 493 gchar *path_string = gtk_tree_path_to_string(path); \ 494 fn("tree path %s", path_string); \ 495 g_free(path_string); \ 500 gnc_tree_view_owner_get_path_from_owner (GncTreeViewOwner *view,
503 GtkTreeModel *model, *f_model, *s_model;
504 GtkTreePath *path, *f_path, *s_path;
506 ENTER(
"view %p, owner %p (%s)", view, owner, gncOwnerGetName(owner));
515 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
516 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
517 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
526 f_path = gtk_tree_model_filter_convert_child_path_to_path (GTK_TREE_MODEL_FILTER (f_model), path);
527 gtk_tree_path_free(path);
530 LEAVE(
"no filter path");
535 s_path = gtk_tree_model_sort_convert_child_path_to_path (GTK_TREE_MODEL_SORT (s_model), f_path);
536 gtk_tree_path_free(f_path);
537 debug_path(
LEAVE, s_path);
542 gnc_tree_view_owner_get_iter_from_owner (GncTreeViewOwner *view,
546 GtkTreeModel *model, *f_model, *s_model;
547 GtkTreeIter iter, f_iter;
549 g_return_val_if_fail(GNC_IS_TREE_VIEW_OWNER(view), FALSE);
550 g_return_val_if_fail(owner != NULL, FALSE);
551 g_return_val_if_fail(s_iter != NULL, FALSE);
553 ENTER(
"view %p, owner %p (%s)", view, owner, gncOwnerGetName(owner));
556 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
557 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
558 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
560 GNC_TREE_MODEL_OWNER(model), owner, &iter))
562 LEAVE(
"model_get_iter_from_owner failed");
567 gtk_tree_model_filter_convert_child_iter_to_iter (
568 GTK_TREE_MODEL_FILTER(f_model), &f_iter, &iter);
569 gtk_tree_model_sort_convert_child_iter_to_iter (GTK_TREE_MODEL_SORT(s_model),
581 gnc_tree_view_owner_filter_helper (GtkTreeModel *model,
586 GncTreeViewOwner *view = data;
588 g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (model), FALSE);
589 g_return_val_if_fail (iter != NULL, FALSE);
592 GNC_TREE_MODEL_OWNER(model), iter);
595 return view->filter_fn(owner, view->filter_data);
612 ENTER(
"view %p, filter func %p, data %p, destroy %p",
613 view, func, data, destroy);
615 g_return_if_fail(GNC_IS_TREE_VIEW_OWNER(view));
617 if (view->filter_destroy)
619 view->filter_destroy(view->filter_data);
621 view->filter_destroy = destroy;
622 view->filter_data = data;
623 view->filter_fn = func;
635 GtkTreeModel *f_model, *s_model;
637 g_return_if_fail(GNC_IS_TREE_VIEW_OWNER(view));
639 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
640 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
641 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (f_model));
656 GtkTreeModel *model, *f_model, *s_model;
657 GtkTreePath *path, *f_path;
661 ENTER(
"view %p", view);
662 g_return_val_if_fail (GNC_IS_TREE_VIEW_OWNER (view), NULL);
663 g_return_val_if_fail (s_path != NULL, NULL);
665 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
666 f_path = gtk_tree_model_sort_convert_path_to_child_path (
667 GTK_TREE_MODEL_SORT (s_model), s_path);
670 LEAVE(
"no filter path");
674 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
675 path = gtk_tree_model_filter_convert_path_to_child_path (
676 GTK_TREE_MODEL_FILTER (f_model), f_path);
677 gtk_tree_path_free(f_path);
684 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
685 if (!gtk_tree_model_get_iter (model, &iter, path))
691 owner = iter.user_data;
692 gtk_tree_path_free(path);
693 LEAVE(
"owner %p (%s)", owner, gncOwnerGetName (owner));
702 GtkTreeModel *model, *f_model;
703 GtkTreeIter iter, f_iter;
706 g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT(s_model), NULL);
707 g_return_val_if_fail (s_iter != NULL, NULL);
709 ENTER(
"model %p, iter %p", s_model, s_iter);
711 gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT(s_model),
714 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
715 gtk_tree_model_filter_convert_iter_to_child_iter (
716 GTK_TREE_MODEL_FILTER(f_model), &iter, &f_iter);
717 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
719 GNC_TREE_MODEL_OWNER(model), &iter);
720 LEAVE(
"owner %p (%s)", owner, gncOwnerGetName (owner));
732 GtkTreeSelection *selection;
733 GtkTreeModel *f_model, *s_model;
734 GtkTreeIter iter, f_iter, s_iter;
736 GtkSelectionMode mode;
738 ENTER(
"view %p", view);
739 g_return_val_if_fail (GNC_IS_TREE_VIEW_OWNER (view), NULL);
741 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
742 mode = gtk_tree_selection_get_mode(selection);
743 if ((mode != GTK_SELECTION_SINGLE) && (mode != GTK_SELECTION_BROWSE))
747 if (!gtk_tree_selection_get_selected (selection, &s_model, &s_iter))
749 LEAVE(
"no owner, get_selected failed");
753 gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (s_model),
756 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
757 gtk_tree_model_filter_convert_iter_to_child_iter (
758 GTK_TREE_MODEL_FILTER (f_model), &iter, &f_iter);
760 owner = iter.user_data;
761 LEAVE(
"owner %p (%s)", owner, gncOwnerGetName (owner));
773 GtkTreeModel *model, *f_model, *s_model;
774 GtkTreePath *path, *f_path, *s_path;
775 GtkTreeSelection *selection;
777 ENTER(
"view %p, owner %p (%s)", view,
778 owner, gncOwnerGetName (owner));
779 g_return_if_fail (GNC_IS_TREE_VIEW_OWNER (view));
782 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
783 gtk_tree_selection_unselect_all (selection);
788 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
789 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
790 model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
793 GNC_TREE_MODEL_OWNER(model), owner);
799 debug_path(
DEBUG, path);
801 f_path = gtk_tree_model_filter_convert_child_path_to_path (
802 GTK_TREE_MODEL_FILTER (f_model), path);
803 gtk_tree_path_free(path);
806 LEAVE(
"no filter path");
809 debug_path(
DEBUG, f_path);
811 s_path = gtk_tree_model_sort_convert_child_path_to_path (GTK_TREE_MODEL_SORT (s_model),
813 gtk_tree_path_free(f_path);
816 LEAVE(
"no sort path");
820 gtk_tree_selection_select_path (selection, s_path);
824 while (gtk_events_pending ())
825 gtk_main_iteration ();
826 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW(view), s_path, NULL, FALSE, 0.0, 0.0);
827 debug_path(
LEAVE, s_path);
828 gtk_tree_path_free(s_path);
835 GncTreeViewOwner* view;
845 get_selected_owners_helper (GtkTreeModel *s_model,
851 GtkTreeModel *f_model;
852 GtkTreeIter iter, f_iter;
855 gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (s_model),
858 f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
859 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (f_model),
861 owner = iter.user_data;
864 if (gtvsi->view->filter_fn == NULL || gtvsi->view->filter_fn(owner, gtvsi->view->filter_data))
866 gtvsi->return_list = g_list_append(gtvsi->return_list, owner);
876 gtvo_update_column_name (GtkTreeViewColumn *column,
878 const gchar *mnemonic)
882 g_return_if_fail(column);
884 name = g_strdup_printf(fmt, mnemonic);
885 gtk_tree_view_column_set_title(column, name);
891 gtvo_update_column_names (GncTreeViewOwner *view)
895 gtvo_update_column_name(view->balance_report_column,
897 _(
"Balance (%s)"), mnemonic);
904 gtvo_currency_changed_cb (
void)
906 const GList *views, *ptr;
909 for (ptr = views; ptr; ptr = g_list_next(ptr))
911 gtvo_update_column_names (ptr->data);
919 owner_cell_kvp_data_func (GtkTreeViewColumn *tree_column,
920 GtkCellRenderer *cell,
921 GtkTreeModel *s_model,
926 GValue v = G_VALUE_INIT;
928 g_return_if_fail (GTK_IS_TREE_MODEL_SORT (s_model));
931 if (G_VALUE_HOLDS_STRING)
932 g_object_set (G_OBJECT (cell),
933 "text", g_value_get_string (&v),
939 static void col_edited_helper(GtkCellRendererText *cell, gchar *path_string,
940 gchar *new_text, gpointer _s_model)
943 GtkTreeModel *s_model;
945 GncTreeViewOwnerColumnTextEdited col_edited_cb;
946 GtkTreeViewColumn *col;
948 col_edited_cb = g_object_get_data(G_OBJECT(cell),
949 "column_edited_callback");
950 col = GTK_TREE_VIEW_COLUMN(g_object_get_data(G_OBJECT(cell),
952 s_model = GTK_TREE_MODEL(_s_model);
954 if (!gtk_tree_model_get_iter_from_string(s_model, &s_iter, path_string))
958 col_edited_cb(owner, col, new_text);
961 static void col_source_helper(GtkTreeViewColumn *col, GtkCellRenderer *cell,
962 GtkTreeModel *s_model, GtkTreeIter *s_iter,
963 gpointer _col_source_cb)
967 GncTreeViewOwnerColumnSource col_source_cb;
969 g_return_if_fail (GTK_IS_TREE_MODEL_SORT (s_model));
970 col_source_cb = (GncTreeViewOwnerColumnSource) _col_source_cb;
972 text = col_source_cb(owner, col, cell);
973 g_object_set (G_OBJECT (cell),
"text", text,
"xalign", 1.0, NULL);
982 gtvo_setup_column_renderer_edited_cb(GncTreeViewOwner *owner_view,
983 GtkTreeViewColumn *column,
984 GtkCellRenderer *renderer,
985 GncTreeViewOwnerColumnTextEdited col_edited_cb)
987 GtkTreeModel *s_model;
989 if (col_edited_cb == NULL)
991 g_object_set(G_OBJECT(renderer),
"editable", FALSE, NULL);
992 g_object_set_data(G_OBJECT(renderer),
"column_edited_callback", col_edited_cb);
993 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(owner_view));
994 g_signal_handlers_disconnect_by_func(G_OBJECT(renderer), col_edited_cb, s_model);
995 g_object_set_data(G_OBJECT(renderer),
"column_view", column);
999 g_object_set(G_OBJECT(renderer),
"editable", TRUE, NULL);
1000 g_object_set_data(G_OBJECT(renderer),
"column_edited_callback",
1002 s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(owner_view));
1003 g_signal_connect(G_OBJECT(renderer),
"edited",
1004 (GCallback) col_edited_helper, s_model);
1005 g_object_set_data(G_OBJECT(renderer),
"column_view", column);
1011 #define FILTER_TREE_VIEW "types_tree_view" 1031 ENTER(
"owner %p:%s", owner, gncOwnerGetName(owner));
1033 if (!fd->show_inactive && !gncOwnerGetActive (owner))
1035 LEAVE(
" hide: inactive");
1039 if (!fd->show_zero_total)
1044 LEAVE(
" hide: zero balance");
1062 g_return_if_fail(GTK_IS_TOGGLE_BUTTON(button));
1064 ENTER(
"button %p", button);
1065 fd->show_inactive = !gtk_toggle_button_get_active(button);
1067 LEAVE(
"show_inactive %d", fd->show_inactive);
1080 g_return_if_fail(GTK_IS_TOGGLE_BUTTON(button));
1082 ENTER(
"button %p", button);
1083 fd->show_zero_total = gtk_toggle_button_get_active(button);
1085 LEAVE(
"show_zero %d", fd->show_zero_total);
1104 g_return_if_fail(GTK_IS_DIALOG(dialog));
1106 ENTER(
"dialog %p, response %d", dialog, response);
1108 if (response != GTK_RESPONSE_OK)
1110 fd->show_inactive = fd->original_show_inactive;
1111 fd->show_zero_total = fd->original_show_zero_total;
1116 gptemp = (gpointer)fd->dialog;
1117 g_atomic_pointer_compare_and_exchange(&gptemp,
1118 (gpointer)dialog, NULL);
1119 fd->dialog = gptemp;
1120 gtk_widget_destroy(dialog);
1127 GtkWidget *dialog, *button;
1128 GtkBuilder *builder;
1131 ENTER(
"(fd %p, page %p)", fd, page);
1135 gtk_window_present(GTK_WINDOW(fd->dialog));
1136 LEAVE(
"existing dialog");
1141 builder = gtk_builder_new();
1142 gnc_builder_add_from_file (builder,
"gnc-tree-view-owner.glade",
"filter_by_dialog");
1143 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"filter_by_dialog"));
1144 fd->dialog = dialog;
1145 gtk_window_set_transient_for(GTK_WINDOW(dialog),
1146 GTK_WINDOW(GNC_PLUGIN_PAGE(page)->window));
1148 title = g_strdup_printf(_(
"Filter %s by…"),
1150 gtk_window_set_title(GTK_WINDOW(dialog), title);
1154 fd->original_show_inactive = fd->show_inactive;
1155 fd->original_show_zero_total = fd->show_zero_total;
1158 button = GTK_WIDGET(gtk_builder_get_object (builder,
"show_inactive"));
1159 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button),
1160 !fd->show_inactive);
1161 button = GTK_WIDGET(gtk_builder_get_object (builder,
"show_zero"));
1162 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button),
1163 fd->show_zero_total);
1166 gtk_builder_connect_signals (builder, fd);
1167 g_object_unref(G_OBJECT(builder));
1170 gtk_widget_show_all (dialog);
1174 #define OWNER_SELECTED_LABEL "SelectedOwner" 1175 #define SHOW_INACTIVE_LABEL "ShowInactive" 1176 #define SHOW_ZERO_LABEL "ShowZeroTotal" 1181 const gchar *group_name;
1195 tree_save_selected_row (GncTreeViewOwner *view,
1199 bar_t *bar = user_data;
1200 const gchar *owner_name;
1206 owner_name = gncOwnerGetName (owner);
1207 if (owner_name == NULL)
1210 g_key_file_set_string(bar->key_file, bar->group_name, OWNER_SELECTED_LABEL,
1215 gnc_tree_view_owner_save(GncTreeViewOwner *view,
1217 GKeyFile *key_file,
const gchar *group_name)
1221 g_return_if_fail (key_file != NULL);
1222 g_return_if_fail (group_name != NULL);
1224 ENTER(
"view %p, key_file %p, group_name %s", view, key_file,
1227 g_key_file_set_boolean(key_file, group_name, SHOW_INACTIVE_LABEL,
1229 g_key_file_set_boolean(key_file, group_name, SHOW_ZERO_LABEL,
1230 fd->show_zero_total);
1232 bar.key_file = key_file;
1233 bar.group_name = group_name;
1234 tree_save_selected_row(view, &bar);
1247 tree_restore_selected_row (GncTreeViewOwner *view,
1248 GncOwnerType owner_type,
1249 const gchar *owner_guid_str)
1262 gnc_tree_view_owner_restore(GncTreeViewOwner *view,
1264 GKeyFile *key_file,
const gchar *group_name,
1265 GncOwnerType owner_type)
1267 GError *error = NULL;
1272 show = g_key_file_get_boolean(key_file, group_name, SHOW_INACTIVE_LABEL, &error);
1275 g_warning(
"error reading group %s key %s: %s",
1276 group_name, SHOW_INACTIVE_LABEL, error->message);
1277 g_error_free(error);
1281 fd->show_inactive = show;
1283 show = g_key_file_get_boolean(key_file, group_name, SHOW_ZERO_LABEL, &error);
1286 g_warning(
"error reading group %s key %s: %s",
1287 group_name, SHOW_ZERO_LABEL, error->message);
1288 g_error_free(error);
1292 fd->show_zero_total = show;
1295 value = g_key_file_get_string(key_file, group_name, OWNER_SELECTED_LABEL, NULL);
1298 tree_restore_selected_row(view, owner_type, value);
1308 gtvo_set_column_editor(GncTreeViewOwner *view,
1309 GtkTreeViewColumn *column,
1310 GncTreeViewOwnerColumnTextEdited edited_cb)
1312 GList *renderers_orig, *renderers;
1313 GtkCellRenderer *renderer;
1317 for (renderers_orig = renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
1318 renderers && !GTK_IS_CELL_RENDERER_TEXT(renderers->data);
1319 renderers = renderers->next);
1320 renderer = GTK_CELL_RENDERER(renderers->data);
1321 g_list_free(renderers_orig);
1322 g_return_if_fail(renderer != NULL);
1323 gtvo_setup_column_renderer_edited_cb(GNC_TREE_VIEW_OWNER(view), column, renderer, edited_cb);
void gnc_tree_view_owner_set_selected_owner(GncTreeViewOwner *view, GncOwner *owner)
This function selects an owner in the owner tree view.
GtkTreeView * gnc_tree_view_owner_new(GncOwnerType owner_type)
Create a new owner tree view for one type of owners.
Business Interface: Object OWNERs.
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.
void gnc_tree_view_owner_set_filter(GncTreeViewOwner *view, gnc_tree_view_owner_filter_func func, gpointer data, GSourceFunc destroy)
This function attaches a filter function to the given owner tree.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
void gnc_tree_view_owner_refilter(GncTreeViewOwner *view)
This function forces the owner tree filter to be evaluated.
GtkTreeView implementation for gnucash owner tree.
GtkTreeModel implementation for gnucash owner tree.
int safe_utf8_collate(const char *da, const char *db)
Collate two UTF-8 strings.
common utilities for manipulating a GtkTreeView within gnucash
GncOwner * gnc_tree_view_owner_get_owner_from_iter(GtkTreeModel *s_model, GtkTreeIter *s_iter)
This function returns the owner associated with the specified iter.
gboolean(* gnc_tree_view_owner_filter_func)(GncOwner *owner, gpointer data)
This is the description of a filter function used by the owner tree.
#define DEBUG(format, args...)
Print a debugging message.
const gchar * gnc_plugin_page_get_page_name(GncPluginPage *page)
Retrieve the name of this page.
gboolean string_to_guid(const gchar *string, GncGUID *guid)
Given a string, replace the given guid with the parsed one unless the given value is null...
void gppot_filter_response_cb(GtkWidget *dialog, gint response, OwnerFilterDialog *fd)
The Filter dialog was closed.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void gnc_tree_view_set_show_column_menu(GncTreeView *view, gboolean visible)
This function is called to set the "show-column-menu" property on this view.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
GtkTreeViewColumn * gnc_tree_view_add_numeric_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *sizing_text, gint model_data_column, gint model_color_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
This function adds a new numeric column to a GncTreeView base view.
#define ENTER(format, args...)
Print a function entry debugging message.
gnc_commodity * gnc_default_report_currency(void)
Return the default currency for use in reports, as set by the user.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
#define PWARN(format, args...)
Log a warning.
GtkTreeViewColumn * gnc_tree_view_add_toggle_column(GncTreeView *view, const gchar *column_title, const gchar *column_short_title, const gchar *pref_name, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn, renderer_toggled toggle_edited_cb)
This function adds a new toggle column to a GncTreeView base view.
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
GtkTreeModel * gnc_tree_model_owner_new(GncOwnerType owner_type)
Create a new GtkTreeModel for manipulating gnucash owners.
gnc_numeric gncOwnerGetBalanceInCurrency(const GncOwner *owner, const gnc_commodity *report_currency)
Given an owner, extract the open balance from the owner and then convert it to the desired currency...
void gnc_tree_view_configure_columns(GncTreeView *view)
Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.
General utilities for dealing with accounting periods.
int gncOwnerCompare(const GncOwner *a, const GncOwner *b)
Sort on name.
void gppot_filter_show_inactive_toggled_cb(GtkToggleButton *button, OwnerFilterDialog *fd)
The "only show active" button in the Filter dialog changed state.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
QofIdTypeConst gncOwnerTypeToQofIdType(GncOwnerType t)
Returns the QofIdType of the given GncOwnerType, or NULL if no suitable one exists.
GtkTreePath * gnc_tree_model_owner_get_path_from_owner(GncTreeModelOwner *model, GncOwner *owner)
Convert a model/owner pair into a gtk_tree_model_path.
GncOwner * gnc_tree_model_owner_get_owner(GncTreeModelOwner *model, GtkTreeIter *iter)
Convert a model/iter pair to a gnucash owner.
All type declarations for the whole Gnucash engine.
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
This function adds a new text column to a GncTreeView base view.
gboolean gnc_tree_model_owner_get_iter_from_owner(GncTreeModelOwner *model, GncOwner *owner, GtkTreeIter *iter)
Convert a model/owner pair into a gtk_tree_model_iter.
#define LEAVE(format, args...)
Print a function exit debugging message.
void gppot_filter_show_zero_toggled_cb(GtkToggleButton *button, OwnerFilterDialog *fd)
The "show zero totals" button in the Filter dialog changed state.
GncOwner * gnc_tree_view_owner_get_selected_owner(GncTreeViewOwner *view)
This function returns the owner associated with the selected item in the owner tree view...
GncOwner * gnc_tree_view_owner_get_owner_from_path(GncTreeViewOwner *view, GtkTreePath *s_path)
This function returns the owner associated with the specified path.
gboolean gnc_plugin_page_owner_tree_filter_owners(GncOwner *owner, gpointer user_data)
This function tells the owner tree view whether or not to filter out a particular owner...
The type used to store guids in C.
GncOwner * gncOwnerNew(void)
These two functions are mainly for the convenience of scheme code.
Commodity handling public routines.