39 #include <glib/gi18n.h> 44 #include "gnc-component-manager.h" 49 #define ITER_IS_NAMESPACE GINT_TO_POINTER(1) 50 #define ITER_IS_COMMODITY GINT_TO_POINTER(2) 53 static QofLogModule log_module = GNC_MOD_GUI;
56 static void gnc_tree_model_commodity_finalize (GObject *
object);
57 static void gnc_tree_model_commodity_dispose (GObject *
object);
59 static void gnc_tree_model_commodity_tree_model_init (GtkTreeModelIface *iface);
60 static GtkTreeModelFlags gnc_tree_model_commodity_get_flags (GtkTreeModel *tree_model);
61 static int gnc_tree_model_commodity_get_n_columns (GtkTreeModel *tree_model);
62 static GType gnc_tree_model_commodity_get_column_type (GtkTreeModel *tree_model,
64 static gboolean gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
67 static GtkTreePath *gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
69 static void gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
73 static gboolean gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
75 static gboolean gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
78 static gboolean gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
80 static int gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
82 static gboolean gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
86 static gboolean gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
89 static void gnc_tree_model_commodity_event_handler (
QofInstance *entity,
102 gnc_commodity_table *commodity_table;
103 gint event_handler_id;
107 G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
108 gnc_tree_model_commodity_tree_model_init))
111 gnc_tree_model_commodity_class_init (GncTreeModelCommodityClass *klass)
113 GObjectClass *o_class = G_OBJECT_CLASS (klass);
115 o_class->finalize = gnc_tree_model_commodity_finalize;
116 o_class->dispose = gnc_tree_model_commodity_dispose;
120 gnc_tree_model_commodity_init (GncTreeModelCommodity *model)
122 while (model->stamp == 0)
124 model->stamp = g_random_int ();
129 gnc_tree_model_commodity_finalize (GObject *
object)
131 GncTreeModelCommodity *model;
133 g_return_if_fail (
object != NULL);
134 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (
object));
136 ENTER(
"model %p",
object);
138 model = GNC_TREE_MODEL_COMMODITY (
object);
140 model->commodity_table = NULL;
142 G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->finalize (
object);
147 gnc_tree_model_commodity_dispose (GObject *
object)
149 GncTreeModelCommodity *model;
151 g_return_if_fail (
object != NULL);
152 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (
object));
154 ENTER(
"model %p",
object);
155 model = GNC_TREE_MODEL_COMMODITY (
object);
157 if (model->event_handler_id)
160 model->event_handler_id = 0;
163 G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->dispose (
object);
170 GncTreeModelCommodity *model;
176 for ( ; item; item = g_list_next(item))
178 model = (GncTreeModelCommodity *)item->data;
179 if (model->commodity_table == ct)
181 g_object_ref(G_OBJECT(model));
182 LEAVE(
"returning existing model %p", model);
183 return GTK_TREE_MODEL(model);
187 model = g_object_new (GNC_TYPE_TREE_MODEL_COMMODITY, NULL);
189 model->commodity_table = ct;
191 model->event_handler_id =
195 return GTK_TREE_MODEL (model);
202 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
203 g_return_val_if_fail (iter != NULL, FALSE);
204 g_return_val_if_fail (iter->user_data != NULL, FALSE);
205 g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
207 return (iter->user_data == ITER_IS_NAMESPACE);
214 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
215 g_return_val_if_fail (iter != NULL, FALSE);
216 g_return_val_if_fail (iter->user_data != NULL, FALSE);
217 g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
219 return (iter->user_data == ITER_IS_COMMODITY);
222 gnc_commodity_namespace *
226 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
227 g_return_val_if_fail (iter != NULL, NULL);
228 g_return_val_if_fail (iter->user_data != NULL, NULL);
229 g_return_val_if_fail (iter->stamp == model->stamp, NULL);
231 if (iter->user_data != ITER_IS_NAMESPACE)
233 return (gnc_commodity_namespace *)iter->user_data2;
240 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
241 g_return_val_if_fail (iter != NULL, NULL);
242 g_return_val_if_fail (iter->user_data != NULL, NULL);
243 g_return_val_if_fail (iter->stamp == model->stamp, NULL);
245 if (iter->user_data != ITER_IS_COMMODITY)
247 return (gnc_commodity *)iter->user_data2;
254 #define debug_path(fn, path) { \ 255 gchar *path_string = gtk_tree_path_to_string(path); \ 256 fn("tree path %s", path_string? path_string : "NULL"); \ 257 g_free(path_string); \ 260 #define ITER_STRING_LEN 128 263 iter_to_string (GtkTreeIter *iter)
265 gnc_commodity_namespace *name_space;
266 gnc_commodity *commodity = NULL;
267 #ifdef G_THREADS_ENABLED 268 static GPrivate gtmits_buffer_key = G_PRIVATE_INIT(g_free);
271 string = g_private_get (>mits_buffer_key);
274 string = g_malloc(ITER_STRING_LEN + 1);
275 g_private_set (>mits_buffer_key,
string);
278 static char string[ITER_STRING_LEN + 1];
282 switch (GPOINTER_TO_INT(iter->user_data))
284 case GPOINTER_TO_INT(ITER_IS_NAMESPACE):
285 name_space = (gnc_commodity_namespace *) iter->user_data2;
286 snprintf(
string, ITER_STRING_LEN,
287 "[stamp:%x data:%d (NAMESPACE), %p (%s), %d]",
288 iter->stamp, GPOINTER_TO_INT(iter->user_data),
290 GPOINTER_TO_INT(iter->user_data3));
293 case GPOINTER_TO_INT(ITER_IS_COMMODITY):
294 commodity = (gnc_commodity *) iter->user_data2;
295 snprintf(
string, ITER_STRING_LEN,
296 "[stamp:%x data:%d (COMMODITY), %p (%s), %d]",
297 iter->stamp, GPOINTER_TO_INT(iter->user_data),
299 GPOINTER_TO_INT(iter->user_data3));
303 snprintf(
string, ITER_STRING_LEN,
304 "[stamp:%x data:%d (UNKNOWN), %p, %d]",
306 GPOINTER_TO_INT(iter->user_data),
308 GPOINTER_TO_INT(iter->user_data3));
321 gnc_tree_model_commodity_tree_model_init (GtkTreeModelIface *iface)
323 iface->get_flags = gnc_tree_model_commodity_get_flags;
324 iface->get_n_columns = gnc_tree_model_commodity_get_n_columns;
325 iface->get_column_type = gnc_tree_model_commodity_get_column_type;
326 iface->get_iter = gnc_tree_model_commodity_get_iter;
327 iface->get_path = gnc_tree_model_commodity_get_path;
328 iface->get_value = gnc_tree_model_commodity_get_value;
329 iface->iter_next = gnc_tree_model_commodity_iter_next;
330 iface->iter_children = gnc_tree_model_commodity_iter_children;
331 iface->iter_has_child = gnc_tree_model_commodity_iter_has_child;
332 iface->iter_n_children = gnc_tree_model_commodity_iter_n_children;
333 iface->iter_nth_child = gnc_tree_model_commodity_iter_nth_child;
334 iface->iter_parent = gnc_tree_model_commodity_iter_parent;
337 static GtkTreeModelFlags
338 gnc_tree_model_commodity_get_flags (GtkTreeModel *tree_model)
344 gnc_tree_model_commodity_get_n_columns (GtkTreeModel *tree_model)
346 return GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS;
350 gnc_tree_model_commodity_get_column_type (GtkTreeModel *tree_model,
353 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), G_TYPE_INVALID);
354 g_return_val_if_fail ((index < GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS) && (index >= 0), G_TYPE_INVALID);
358 case GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC:
359 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
360 case GNC_TREE_MODEL_COMMODITY_COL_FULLNAME:
361 case GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME:
362 case GNC_TREE_MODEL_COMMODITY_COL_CUSIP:
363 case GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME:
364 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE:
365 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ:
366 case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
367 return G_TYPE_STRING;
368 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
370 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
371 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
372 return G_TYPE_BOOLEAN;
374 g_assert_not_reached ();
375 return G_TYPE_INVALID;
380 gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
384 GncTreeModelCommodity *model;
385 gnc_commodity_table *ct;
386 gnc_commodity_namespace *name_space;
387 gnc_commodity *commodity = NULL;
392 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
393 g_return_val_if_fail (iter != NULL, FALSE);
394 g_return_val_if_fail (path != NULL, FALSE);
396 depth = gtk_tree_path_get_depth (path);
397 ENTER(
"model %p, iter %p, path %p (depth %d)", tree_model, iter, path, depth);
398 debug_path(
DEBUG, path);
403 LEAVE(
"depth too small");
408 LEAVE(
"depth too big");
413 model = GNC_TREE_MODEL_COMMODITY (tree_model);
414 ct = model->commodity_table;
417 LEAVE(
"no commodity table");
423 i = gtk_tree_path_get_indices (path)[0];
424 name_space = g_list_nth_data (list, i);
428 LEAVE(
"invalid path at namespace");
435 iter->stamp = model->stamp;
436 iter->user_data = ITER_IS_NAMESPACE;
437 iter->user_data2 = name_space;
438 iter->user_data3 = GINT_TO_POINTER(i);
439 LEAVE(
"iter (ns) %s", iter_to_string(iter));
445 i = gtk_tree_path_get_indices (path)[1];
446 commodity = g_list_nth_data (list, i);
450 LEAVE(
"invalid path at commodity");
455 iter->stamp = model->stamp;
456 iter->user_data = ITER_IS_COMMODITY;
457 iter->user_data2 = commodity;
458 iter->user_data3 = GINT_TO_POINTER(i);
459 LEAVE(
"iter (cm) %s", iter_to_string(iter));
464 gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
467 GncTreeModelCommodity *model;
469 gnc_commodity_table *ct;
470 gnc_commodity_namespace *name_space;
473 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), NULL);
474 model = GNC_TREE_MODEL_COMMODITY (tree_model);
475 g_return_val_if_fail (iter != NULL, NULL);
476 g_return_val_if_fail (iter->user_data != NULL, NULL);
477 g_return_val_if_fail (iter->user_data2 != NULL, NULL);
478 g_return_val_if_fail (iter->stamp == model->stamp, NULL);
479 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
482 ct = model->commodity_table;
485 LEAVE(
"no commodity table");
489 if (iter->user_data == ITER_IS_NAMESPACE)
493 path = gtk_tree_path_new ();
494 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
495 debug_path(
LEAVE, path);
504 path = gtk_tree_path_new ();
505 gtk_tree_path_append_index (path, g_list_index (ns_list, name_space));
506 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
507 debug_path(
LEAVE, path);
508 g_list_free (ns_list);
513 gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
518 GncTreeModelCommodity *model = GNC_TREE_MODEL_COMMODITY (tree_model);
519 gnc_commodity_namespace *name_space;
520 gnc_commodity *commodity;
521 gnc_quote_source *source;
523 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model));
524 g_return_if_fail (iter != NULL);
525 g_return_if_fail (iter->user_data != NULL);
526 g_return_if_fail (iter->user_data2 != NULL);
527 g_return_if_fail (iter->stamp == model->stamp);
529 if (iter->user_data == ITER_IS_NAMESPACE)
531 name_space = (gnc_commodity_namespace *)iter->user_data2;
534 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
535 g_value_init (value, G_TYPE_STRING);
539 g_value_init (value, G_TYPE_STRING);
540 g_value_set_string (value,
"");
542 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
543 g_value_init (value, G_TYPE_INT);
544 g_value_set_int (value, 0);
546 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
547 g_value_init (value, G_TYPE_BOOLEAN);
548 g_value_set_boolean (value, FALSE);
550 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
551 g_value_init (value, G_TYPE_BOOLEAN);
552 g_value_set_boolean (value, FALSE);
558 commodity = (gnc_commodity *)iter->user_data2;
561 case GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC:
562 g_value_init (value, G_TYPE_STRING);
566 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
567 g_value_init (value, G_TYPE_STRING);
570 g_value_set_string (value, NULL);
572 case GNC_TREE_MODEL_COMMODITY_COL_FULLNAME:
573 g_value_init (value, G_TYPE_STRING);
577 case GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME:
578 g_value_init (value, G_TYPE_STRING);
582 case GNC_TREE_MODEL_COMMODITY_COL_CUSIP:
583 g_value_init (value, G_TYPE_STRING);
587 case GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME:
588 g_value_init (value, G_TYPE_STRING);
592 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
593 g_value_init (value, G_TYPE_INT);
597 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
598 g_value_init (value, G_TYPE_BOOLEAN);
602 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE:
603 g_value_init (value, G_TYPE_STRING);
612 g_value_set_static_string (value,
"");
615 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ:
616 g_value_init (value, G_TYPE_STRING);
624 g_value_set_static_string (value,
"");
627 case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
628 g_value_init (value, G_TYPE_STRING);
632 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
633 g_value_init (value, G_TYPE_BOOLEAN);
634 g_value_set_boolean (value, TRUE);
637 g_assert_not_reached ();
642 gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
645 GncTreeModelCommodity *model;
646 gnc_commodity_table *ct;
647 gnc_commodity_namespace *name_space;
651 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
652 model = GNC_TREE_MODEL_COMMODITY (tree_model);
653 g_return_val_if_fail (iter != NULL, FALSE);
654 g_return_val_if_fail (iter->user_data != NULL, FALSE);
655 g_return_val_if_fail (iter->user_data2 != NULL, FALSE);
656 g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
658 ENTER(
"model %p, iter %p(%s)", tree_model, iter, iter_to_string(iter));
659 if (iter->user_data == ITER_IS_NAMESPACE)
661 ct = model->commodity_table;
664 else if (iter->user_data == ITER_IS_COMMODITY)
671 LEAVE(
"unknown iter type");
675 n = GPOINTER_TO_INT(iter->user_data3) + 1;
676 iter->user_data2 = g_list_nth_data(list, n);
678 if (iter->user_data2 == NULL)
680 LEAVE(
"no next iter");
683 iter->user_data3 = GINT_TO_POINTER(n);
684 LEAVE(
"iter %p(%s)", iter, iter_to_string(iter));
690 gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
694 GncTreeModelCommodity *model;
695 gnc_commodity_table *ct;
696 gnc_commodity_namespace *name_space;
699 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
701 ENTER(
"model %p, iter %p, parent %p (%s)",
702 tree_model, iter, parent, iter_to_string(parent));
703 model = GNC_TREE_MODEL_COMMODITY (tree_model);
707 ct = model->commodity_table;
711 LEAVE(
"no namespaces");
715 iter->stamp = model->stamp;
716 iter->user_data = ITER_IS_NAMESPACE;
717 iter->user_data2 = g_list_nth_data(list, 0);
718 iter->user_data3 = GINT_TO_POINTER(0);
719 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
724 if (parent->user_data == ITER_IS_NAMESPACE)
726 name_space = (gnc_commodity_namespace *)parent->user_data2;
730 LEAVE(
"no commodities");
734 iter->stamp = model->stamp;
735 iter->user_data = ITER_IS_COMMODITY;
736 iter->user_data2 = g_list_nth_data(list, 0);
737 iter->user_data3 = GINT_TO_POINTER(0);
738 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
748 gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
751 gnc_commodity_namespace *name_space;
754 g_return_val_if_fail (iter != NULL, FALSE);
755 ENTER(
"model %p, iter %p (%s)", tree_model,
756 iter, iter_to_string(iter));
758 if (iter->user_data != ITER_IS_NAMESPACE)
760 LEAVE(
"no children (not ns)");
764 name_space = (gnc_commodity_namespace *)iter->user_data2;
766 LEAVE(
"%s children", list ?
"has" :
"no");
767 gboolean rv = (list != NULL);
773 gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
776 GncTreeModelCommodity *model;
777 gnc_commodity_table *ct;
778 gnc_commodity_namespace *name_space;
781 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), -1);
783 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
784 model = GNC_TREE_MODEL_COMMODITY (tree_model);
788 ct = model->commodity_table;
790 LEAVE(
"ns list length %d", g_list_length(list));
791 guint rv = g_list_length (list);
796 if (iter->user_data == ITER_IS_NAMESPACE)
798 name_space = (gnc_commodity_namespace *)iter->user_data2;
800 LEAVE(
"cm list length %d", g_list_length(list));
801 guint rv = g_list_length (list);
811 gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
816 GncTreeModelCommodity *model;
817 gnc_commodity_table *ct;
818 gnc_commodity_namespace *name_space;
821 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
822 g_return_val_if_fail (iter != NULL, FALSE);
824 ENTER(
"model %p, iter %p, parent %p (%s)",
825 tree_model, iter, parent, iter_to_string(parent));
826 model = GNC_TREE_MODEL_COMMODITY (tree_model);
830 ct = model->commodity_table;
833 iter->stamp = model->stamp;
834 iter->user_data = ITER_IS_NAMESPACE;
835 iter->user_data2 = g_list_nth_data(list, n);
836 iter->user_data3 = GINT_TO_POINTER(n);
837 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
839 return iter->user_data2 != NULL;
842 if (parent->user_data == ITER_IS_NAMESPACE)
844 name_space = (gnc_commodity_namespace *)parent->user_data2;
847 iter->stamp = model->stamp;
848 iter->user_data = ITER_IS_COMMODITY;
849 iter->user_data2 = g_list_nth_data(list, n);
850 iter->user_data3 = GINT_TO_POINTER(n);
851 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
853 return iter->user_data2 != NULL;
862 gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
866 GncTreeModelCommodity *model;
867 gnc_commodity_table *ct;
868 gnc_commodity_namespace *name_space;
871 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
872 g_return_val_if_fail (iter != NULL, FALSE);
873 g_return_val_if_fail (child != NULL, FALSE);
875 ENTER(
"model %p, iter %p, child %p (%s)",
876 tree_model, iter, child, iter_to_string(child));
877 model = GNC_TREE_MODEL_COMMODITY (tree_model);
879 if (child->user_data == ITER_IS_NAMESPACE)
881 LEAVE(
"ns has no parent");
885 ct = model->commodity_table;
889 iter->stamp = model->stamp;
890 iter->user_data = ITER_IS_NAMESPACE;
891 iter->user_data2 = name_space;
892 iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space));
893 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
909 gnc_commodity *commodity,
912 gnc_commodity_namespace *name_space;
916 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
917 g_return_val_if_fail ((commodity != NULL), FALSE);
918 g_return_val_if_fail ((iter != NULL), FALSE);
920 ENTER(
"model %p, commodity %p, iter %p", model, commodity, iter);
923 if (name_space == NULL)
925 LEAVE(
"no namespace");
936 n = g_list_index(list, commodity);
940 LEAVE(
"not in list");
944 iter->stamp = model->stamp;
945 iter->user_data = ITER_IS_COMMODITY;
946 iter->user_data2 = commodity;
947 iter->user_data3 = GINT_TO_POINTER(n);
948 LEAVE(
"iter %s", iter_to_string(iter));
959 gnc_commodity *commodity)
961 GtkTreeIter tree_iter;
962 GtkTreePath *tree_path;
964 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
965 g_return_val_if_fail (commodity != NULL, NULL);
966 ENTER(
"model %p, commodity %p", model, commodity);
974 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &tree_iter);
977 gchar *path_string = gtk_tree_path_to_string(tree_path);
978 LEAVE(
"path (2) %s", path_string);
995 gnc_commodity_namespace *name_space,
1001 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
1002 g_return_val_if_fail ((name_space != NULL), FALSE);
1003 g_return_val_if_fail ((iter != NULL), FALSE);
1005 ENTER(
"model %p, namespace %p, iter %p", model, name_space, iter);
1014 n = g_list_index(list, name_space);
1022 iter->stamp = model->stamp;
1023 iter->user_data = ITER_IS_NAMESPACE;
1024 iter->user_data2 = name_space;
1025 iter->user_data3 = GINT_TO_POINTER(n);
1026 LEAVE(
"iter %s", iter_to_string(iter));
1035 typedef struct _remove_data
1037 GncTreeModelCommodity *model;
1041 static GSList *pending_removals = NULL;
1055 gnc_tree_model_commodity_row_add (GncTreeModelCommodity *model,
1059 GtkTreeModel *tree_model;
1060 GtkTreeIter tmp_iter;
1062 ENTER(
"model %p, iter (%p)%s", model, iter, iter_to_string(iter));
1072 while (model->stamp == 0);
1073 iter->stamp = model->stamp;
1076 tree_model = GTK_TREE_MODEL(model);
1077 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1078 gtk_tree_model_row_inserted(tree_model, path, iter);
1085 if (gtk_tree_path_up(path) &&
1086 gtk_tree_path_get_depth(path) > 0 &&
1087 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1090 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1093 if (gtk_tree_model_iter_n_children(tree_model, &tmp_iter) == 1)
1094 gtk_tree_model_row_has_child_toggled(tree_model, path, &tmp_iter);
1097 while (gtk_tree_path_up(path) &&
1098 gtk_tree_path_get_depth(path) > 0 &&
1099 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1101 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1104 gtk_tree_path_free(path);
1110 if (gnc_tree_model_commodity_iter_has_child(tree_model, iter))
1112 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1113 gtk_tree_model_row_has_child_toggled(tree_model, path, iter);
1114 gtk_tree_path_free(path);
1132 gnc_tree_model_commodity_row_delete (GncTreeModelCommodity *model,
1135 GtkTreeModel *tree_model;
1138 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1139 g_return_if_fail(path);
1141 debug_path(
ENTER, path);
1143 tree_model = GTK_TREE_MODEL(model);
1153 while (model->stamp == 0);
1156 gtk_tree_model_row_deleted(tree_model, path);
1159 if (gtk_tree_path_up(path) &&
1160 gtk_tree_path_get_depth(path) > 0 &&
1161 gtk_tree_model_get_iter(tree_model, &iter, path) &&
1162 !gtk_tree_model_iter_has_child(tree_model, &iter))
1164 DEBUG(
"parent toggled, iter %s", iter_to_string(&iter));
1165 gtk_tree_model_row_has_child_toggled(tree_model, path, &iter);
1189 gnc_tree_model_commodity_do_deletions (gpointer unused)
1194 while (pending_removals)
1197 pending_removals = g_slist_delete_link(pending_removals, pending_removals);
1201 debug_path(
DEBUG, data->path);
1204 gnc_tree_model_commodity_row_delete(data->model, data->path);
1206 gtk_tree_path_free(data->path);
1249 gnc_tree_model_commodity_event_handler (
QofInstance *entity,
1252 gpointer event_data)
1254 GncTreeModelCommodity *model;
1260 model = (GncTreeModelCommodity *)user_data;
1263 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1265 ENTER(
"entity %p, event %d, model %p, event data %p",
1266 entity, event_type, user_data, event_data);
1269 if (pending_removals)
1270 gnc_tree_model_commodity_do_deletions(NULL);
1273 if (GNC_IS_COMMODITY(entity))
1275 gnc_commodity *commodity;
1277 commodity = GNC_COMMODITY(entity);
1279 if (event_type != QOF_EVENT_DESTROY)
1288 else if (GNC_IS_COMMODITY_NAMESPACE(entity))
1290 gnc_commodity_namespace *name_space;
1292 name_space = GNC_COMMODITY_NAMESPACE(entity);
1294 if (event_type != QOF_EVENT_DESTROY)
1313 DEBUG(
"add %s", name);
1314 gnc_tree_model_commodity_row_add (model, &iter);
1317 case QOF_EVENT_REMOVE:
1319 DEBUG(
"remove %s", name);
1320 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1323 LEAVE(
"not in model");
1328 data->model = model;
1330 pending_removals = g_slist_append (pending_removals, data);
1331 g_idle_add_full(G_PRIORITY_HIGH_IDLE,
1332 gnc_tree_model_commodity_do_deletions, NULL, NULL);
1337 case QOF_EVENT_MODIFY:
1338 DEBUG(
"change %s", name);
1339 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1342 LEAVE(
"not in model");
1345 gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
1346 gtk_tree_path_free(path);
1351 LEAVE(
"ignored event for %s", name);
1354 LEAVE(
" new stamp %u", model->stamp);
GtkTreeModel implementation for gnucash commodities.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
gnc_commodity * gnc_tree_model_commodity_get_commodity(GncTreeModelCommodity *model, GtkTreeIter *iter)
Convert a model/iter pair to a gnucash commodity.
gboolean gnc_tree_model_commodity_get_iter_from_commodity(GncTreeModelCommodity *model, gnc_commodity *commodity, GtkTreeIter *iter)
Convert a commodity pointer into a GtkTreeIter.
const GList * gnc_gobject_tracking_get_list(const gchar *name)
Get a list of all known objects of a specified type.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
GtkTreePath * gnc_tree_model_commodity_get_path_from_commodity(GncTreeModelCommodity *model, gnc_commodity *commodity)
Convert a commodity pointer into a GtkTreePath.
const char * gnc_commodity_namespace_get_gui_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure in a form suitable to present to the user...
utility functions for the GnuCash UI
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
GncTreeModel gnc_tree_model
The parent object data.
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
Retrieve the automatic price quote timezone for the specified commodity.
#define DEBUG(format, args...)
Print a debugging message.
gnc_commodity_namespace * gnc_tree_model_commodity_get_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
Convert a model/iter pair to a gnucash commodity namespace.
int stamp
The state of the model.
#define ENTER(format, args...)
Print a function entry debugging message.
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
Return a list of all commodity data structures in the specified namespace.
G_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_APPLICATION_WINDOW, G_IMPLEMENT_INTERFACE(GNC_TYPE_WINDOW, gnc_window_main_window_init)) static guint main_window_signals[LAST_SIGNAL]
A holding place for all the signals generated by the main window code.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
gint qof_event_register_handler(QofEventHandler handler, gpointer user_data)
Register a handler for events.
The instance data structure for a commodity tree model.
gint QofEventId
Define the type of events allowed.
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
GtkTreeModel * gnc_tree_model_commodity_new(QofBook *book, gnc_commodity_table *ct)
Create a new GtkTreeModel for manipulating gnucash commodities.
gboolean gnc_tree_model_commodity_get_iter_from_namespace(GncTreeModelCommodity *model, gnc_commodity_namespace *name_space, GtkTreeIter *iter)
Convert a commodity namespace pointer into a GtkTreeIter.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
All type declarations for the whole Gnucash engine.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gboolean gnc_tree_model_commodity_iter_is_commodity(GncTreeModelCommodity *model, GtkTreeIter *iter)
Determine whether or not the specified GtkTreeIter points to a commodity.
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source for the specified commodity.
gboolean gnc_tree_model_commodity_iter_is_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
Determine whether or not the specified GtkTreeIter points to a commodity namespace.
gnc_commodity_namespace * gnc_commodity_get_namespace_ds(const gnc_commodity *cm)
Retrieve the namespace data structure for the specified commodity.
#define LEAVE(format, args...)
Print a function exit debugging message.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the internal name of this quote source.
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *table)
Return a list of all namespace data structures in the commodity table.