43 #include "gnc-component-manager.h"
48 #define ITER_IS_NAMESPACE GINT_TO_POINTER(1)
49 #define ITER_IS_COMMODITY GINT_TO_POINTER(2)
57 static void gnc_tree_model_commodity_finalize (GObject *
object);
58 static void gnc_tree_model_commodity_dispose (GObject *
object);
60 static void gnc_tree_model_commodity_tree_model_init (GtkTreeModelIface *iface);
61 static GtkTreeModelFlags gnc_tree_model_commodity_get_flags (GtkTreeModel *tree_model);
62 static int gnc_tree_model_commodity_get_n_columns (GtkTreeModel *tree_model);
63 static GType gnc_tree_model_commodity_get_column_type (GtkTreeModel *tree_model,
65 static gboolean gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
68 static GtkTreePath *gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
70 static void gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
74 static gboolean gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
76 static gboolean gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
79 static gboolean gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
81 static int gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
83 static gboolean gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
87 static gboolean gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
90 static void gnc_tree_model_commodity_event_handler (
QofInstance *entity,
100 gint event_handler_id;
103 #define GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(o) \
104 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_MODEL_COMMODITY, GncTreeModelCommodityPrivate))
107 static GtkObjectClass *parent_class = NULL;
112 static GType gnc_tree_model_commodity_type = 0;
114 if (gnc_tree_model_commodity_type == 0)
116 static const GTypeInfo our_info =
121 (GClassInitFunc) gnc_tree_model_commodity_class_init,
126 (GInstanceInitFunc) gnc_tree_model_commodity_init
129 static const GInterfaceInfo tree_model_info =
131 (GInterfaceInitFunc) gnc_tree_model_commodity_tree_model_init,
136 gnc_tree_model_commodity_type = g_type_register_static (GNC_TYPE_TREE_MODEL,
137 GNC_TREE_MODEL_COMMODITY_NAME,
140 g_type_add_interface_static (gnc_tree_model_commodity_type,
145 return gnc_tree_model_commodity_type;
151 GObjectClass *o_class = G_OBJECT_CLASS (klass);
153 parent_class = g_type_class_peek_parent (klass);
155 o_class->finalize = gnc_tree_model_commodity_finalize;
156 o_class->dispose = gnc_tree_model_commodity_dispose;
164 while (model->
stamp == 0)
166 model->
stamp = g_random_int ();
171 gnc_tree_model_commodity_finalize (GObject *
object)
176 g_return_if_fail (
object != NULL);
177 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (
object));
179 ENTER(
"model %p",
object);
181 model = GNC_TREE_MODEL_COMMODITY (
object);
182 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
184 priv->commodity_table = NULL;
186 G_OBJECT_CLASS (parent_class)->finalize (
object);
191 gnc_tree_model_commodity_dispose (GObject *
object)
196 g_return_if_fail (
object != NULL);
197 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (
object));
199 ENTER(
"model %p",
object);
200 model = GNC_TREE_MODEL_COMMODITY (
object);
201 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
203 if (priv->event_handler_id)
206 priv->event_handler_id = 0;
209 if (G_OBJECT_CLASS (parent_class)->dispose)
210 G_OBJECT_CLASS (parent_class)->dispose (
object);
224 for ( ; item; item = g_list_next(item))
227 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
228 if (priv->commodity_table == ct)
230 g_object_ref(G_OBJECT(model));
231 LEAVE(
"returning existing model %p", model);
232 return GTK_TREE_MODEL(model);
236 model = g_object_new (GNC_TYPE_TREE_MODEL_COMMODITY, NULL);
237 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
239 priv->commodity_table = ct;
241 priv->event_handler_id =
245 return GTK_TREE_MODEL (model);
252 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
253 g_return_val_if_fail (iter != NULL, FALSE);
254 g_return_val_if_fail (iter->user_data != NULL, FALSE);
255 g_return_val_if_fail (iter->stamp == model->
stamp, FALSE);
257 return (iter->user_data == ITER_IS_NAMESPACE);
264 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
265 g_return_val_if_fail (iter != NULL, FALSE);
266 g_return_val_if_fail (iter->user_data != NULL, FALSE);
267 g_return_val_if_fail (iter->stamp == model->
stamp, FALSE);
269 return (iter->user_data == ITER_IS_COMMODITY);
276 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
277 g_return_val_if_fail (iter != NULL, NULL);
278 g_return_val_if_fail (iter->user_data != NULL, NULL);
279 g_return_val_if_fail (iter->stamp == model->
stamp, NULL);
281 if (iter->user_data != ITER_IS_NAMESPACE)
290 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
291 g_return_val_if_fail (iter != NULL, NULL);
292 g_return_val_if_fail (iter->user_data != NULL, NULL);
293 g_return_val_if_fail (iter->stamp == model->
stamp, NULL);
295 if (iter->user_data != ITER_IS_COMMODITY)
304 #define debug_path(fn, path) { \
305 gchar *path_string = gtk_tree_path_to_string(path); \
306 fn("tree path %s", path_string? path_string : "NULL"); \
307 g_free(path_string); \
310 #define ITER_STRING_LEN 128
313 iter_to_string (GtkTreeIter *iter)
317 #ifdef G_THREADS_ENABLED
318 #ifndef HAVE_GLIB_2_32
319 static GStaticPrivate gtmits_buffer_key = G_STATIC_PRIVATE_INIT;
322 string = g_static_private_get (>mits_buffer_key);
325 string = g_malloc(ITER_STRING_LEN + 1);
326 g_static_private_set (>mits_buffer_key,
string, g_free);
329 static GPrivate gtmits_buffer_key = G_PRIVATE_INIT(g_free);
332 string = g_private_get (>mits_buffer_key);
335 string = g_malloc(ITER_STRING_LEN + 1);
336 g_private_set (>mits_buffer_key,
string);
340 static char string[ITER_STRING_LEN + 1];
344 switch (GPOINTER_TO_INT(iter->user_data))
346 case GPOINTER_TO_INT(ITER_IS_NAMESPACE):
348 snprintf(
string, ITER_STRING_LEN,
349 "[stamp:%x data:%d (NAMESPACE), %p (%s), %d]",
350 iter->stamp, GPOINTER_TO_INT(iter->user_data),
352 GPOINTER_TO_INT(iter->user_data3));
355 case GPOINTER_TO_INT(ITER_IS_COMMODITY):
357 snprintf(
string, ITER_STRING_LEN,
358 "[stamp:%x data:%d (COMMODITY), %p (%s), %d]",
359 iter->stamp, GPOINTER_TO_INT(iter->user_data),
361 GPOINTER_TO_INT(iter->user_data3));
365 snprintf(
string, ITER_STRING_LEN,
366 "[stamp:%x data:%d (UNKNOWN), %p, %d]",
368 GPOINTER_TO_INT(iter->user_data),
370 GPOINTER_TO_INT(iter->user_data3));
383 gnc_tree_model_commodity_tree_model_init (GtkTreeModelIface *iface)
385 iface->get_flags = gnc_tree_model_commodity_get_flags;
386 iface->get_n_columns = gnc_tree_model_commodity_get_n_columns;
387 iface->get_column_type = gnc_tree_model_commodity_get_column_type;
388 iface->get_iter = gnc_tree_model_commodity_get_iter;
389 iface->get_path = gnc_tree_model_commodity_get_path;
390 iface->get_value = gnc_tree_model_commodity_get_value;
391 iface->iter_next = gnc_tree_model_commodity_iter_next;
392 iface->iter_children = gnc_tree_model_commodity_iter_children;
393 iface->iter_has_child = gnc_tree_model_commodity_iter_has_child;
394 iface->iter_n_children = gnc_tree_model_commodity_iter_n_children;
395 iface->iter_nth_child = gnc_tree_model_commodity_iter_nth_child;
396 iface->iter_parent = gnc_tree_model_commodity_iter_parent;
399 static GtkTreeModelFlags
400 gnc_tree_model_commodity_get_flags (GtkTreeModel *tree_model)
406 gnc_tree_model_commodity_get_n_columns (GtkTreeModel *tree_model)
408 return GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS;
412 gnc_tree_model_commodity_get_column_type (GtkTreeModel *tree_model,
415 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), G_TYPE_INVALID);
416 g_return_val_if_fail ((index < GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS) && (index >= 0), G_TYPE_INVALID);
420 case GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC:
421 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
422 case GNC_TREE_MODEL_COMMODITY_COL_FULLNAME:
423 case GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME:
424 case GNC_TREE_MODEL_COMMODITY_COL_CUSIP:
425 case GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME:
426 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE:
427 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ:
428 case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
429 return G_TYPE_STRING;
430 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
432 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
433 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
434 return G_TYPE_BOOLEAN;
436 g_assert_not_reached ();
437 return G_TYPE_INVALID;
442 gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
455 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
456 g_return_val_if_fail (iter != NULL, FALSE);
457 g_return_val_if_fail (path != NULL, FALSE);
459 depth = gtk_tree_path_get_depth (path);
460 ENTER(
"model %p, iter %p, path %p (depth %d)", tree_model, iter, path, depth);
461 debug_path(
DEBUG, path);
466 LEAVE(
"depth too small");
471 LEAVE(
"depth too big");
476 model = GNC_TREE_MODEL_COMMODITY (tree_model);
477 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
478 ct = priv->commodity_table;
481 LEAVE(
"no commodity table");
487 i = gtk_tree_path_get_indices (path)[0];
488 name_space = g_list_nth_data (list, i);
491 LEAVE(
"invalid path at namespace");
498 iter->stamp = model->
stamp;
499 iter->user_data = ITER_IS_NAMESPACE;
500 iter->user_data2 = name_space;
501 iter->user_data3 = GINT_TO_POINTER(i);
502 LEAVE(
"iter (ns) %s", iter_to_string(iter));
508 i = gtk_tree_path_get_indices (path)[1];
509 commodity = g_list_nth_data (list, i);
512 LEAVE(
"invalid path at commodity");
517 iter->stamp = model->
stamp;
518 iter->user_data = ITER_IS_COMMODITY;
519 iter->user_data2 = commodity;
520 iter->user_data3 = GINT_TO_POINTER(i);
521 LEAVE(
"iter (cm) %s", iter_to_string(iter));
526 gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
536 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), NULL);
537 model = GNC_TREE_MODEL_COMMODITY (tree_model);
538 g_return_val_if_fail (iter != NULL, NULL);
539 g_return_val_if_fail (iter->user_data != NULL, NULL);
540 g_return_val_if_fail (iter->user_data2 != NULL, NULL);
541 g_return_val_if_fail (iter->stamp == model->
stamp, NULL);
542 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
545 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
546 ct = priv->commodity_table;
549 LEAVE(
"no commodity table");
553 if (iter->user_data == ITER_IS_NAMESPACE)
557 path = gtk_tree_path_new ();
558 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
559 debug_path(
LEAVE, path);
568 path = gtk_tree_path_new ();
569 gtk_tree_path_append_index (path, g_list_index (ns_list, name_space));
570 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
571 debug_path(
LEAVE, path);
576 gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
586 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model));
587 g_return_if_fail (iter != NULL);
588 g_return_if_fail (iter->user_data != NULL);
589 g_return_if_fail (iter->user_data2 != NULL);
590 g_return_if_fail (iter->stamp == model->
stamp);
592 if (iter->user_data == ITER_IS_NAMESPACE)
597 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
598 g_value_init (value, G_TYPE_STRING);
602 g_value_init (value, G_TYPE_STRING);
603 g_value_set_string (value,
"");
605 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
606 g_value_init (value, G_TYPE_INT);
607 g_value_set_int (value, 0);
609 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
610 g_value_init (value, G_TYPE_BOOLEAN);
611 g_value_set_boolean (value, FALSE);
613 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
614 g_value_init (value, G_TYPE_BOOLEAN);
615 g_value_set_boolean (value, FALSE);
624 case GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC:
625 g_value_init (value, G_TYPE_STRING);
629 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
630 g_value_init (value, G_TYPE_STRING);
633 g_value_set_string (value, NULL);
635 case GNC_TREE_MODEL_COMMODITY_COL_FULLNAME:
636 g_value_init (value, G_TYPE_STRING);
640 case GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME:
641 g_value_init (value, G_TYPE_STRING);
645 case GNC_TREE_MODEL_COMMODITY_COL_CUSIP:
646 g_value_init (value, G_TYPE_STRING);
650 case GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME:
651 g_value_init (value, G_TYPE_STRING);
655 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
656 g_value_init (value, G_TYPE_INT);
660 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
661 g_value_init (value, G_TYPE_BOOLEAN);
665 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE:
666 g_value_init (value, G_TYPE_STRING);
675 g_value_set_static_string (value,
"");
678 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ:
679 g_value_init (value, G_TYPE_STRING);
687 g_value_set_static_string (value,
"");
690 case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
691 g_value_init (value, G_TYPE_STRING);
695 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
696 g_value_init (value, G_TYPE_BOOLEAN);
697 g_value_set_boolean (value, TRUE);
700 g_assert_not_reached ();
705 gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
715 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
716 model = GNC_TREE_MODEL_COMMODITY (tree_model);
717 g_return_val_if_fail (iter != NULL, FALSE);
718 g_return_val_if_fail (iter->user_data != NULL, FALSE);
719 g_return_val_if_fail (iter->user_data2 != NULL, FALSE);
720 g_return_val_if_fail (iter->stamp == model->
stamp, FALSE);
722 ENTER(
"model %p, iter %p(%s)", tree_model, iter, iter_to_string(iter));
723 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
724 if (iter->user_data == ITER_IS_NAMESPACE)
726 ct = priv->commodity_table;
729 else if (iter->user_data == ITER_IS_COMMODITY)
736 LEAVE(
"unknown iter type");
740 n = GPOINTER_TO_INT(iter->user_data3) + 1;
741 iter->user_data2 = g_list_nth_data(list, n);
742 if (iter->user_data2 == NULL)
744 LEAVE(
"no next iter");
747 iter->user_data3 = GINT_TO_POINTER(n);
748 LEAVE(
"iter %p(%s)", iter, iter_to_string(iter));
754 gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
764 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
766 ENTER(
"model %p, iter %p, parent %p (%s)",
767 tree_model, iter, parent, iter_to_string(parent));
768 model = GNC_TREE_MODEL_COMMODITY (tree_model);
769 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
773 ct = priv->commodity_table;
777 LEAVE(
"no namespaces");
781 iter->stamp = model->
stamp;
782 iter->user_data = ITER_IS_NAMESPACE;
783 iter->user_data2 = g_list_nth_data(list, 0);
784 iter->user_data3 = GINT_TO_POINTER(0);
785 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
789 if (parent->user_data == ITER_IS_NAMESPACE)
795 LEAVE(
"no commodities");
799 iter->stamp = model->
stamp;
800 iter->user_data = ITER_IS_COMMODITY;
801 iter->user_data2 = g_list_nth_data(list, 0);
802 iter->user_data3 = GINT_TO_POINTER(0);
803 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
812 gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
818 g_return_val_if_fail (iter != NULL, FALSE);
819 ENTER(
"model %p, iter %p (%s)", tree_model,
820 iter, iter_to_string(iter));
822 if (iter->user_data != ITER_IS_NAMESPACE)
824 LEAVE(
"no children (not ns)");
830 LEAVE(
"%s children", list ?
"has" :
"no");
835 gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
844 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), -1);
846 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
847 model = GNC_TREE_MODEL_COMMODITY (tree_model);
848 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
852 ct = priv->commodity_table;
854 LEAVE(
"ns list length %d", g_list_length(list));
855 return g_list_length (list);
858 if (iter->user_data == ITER_IS_NAMESPACE)
862 LEAVE(
"cm list length %d", g_list_length(list));
863 return g_list_length (list);
871 gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
882 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
883 g_return_val_if_fail (iter != NULL, FALSE);
885 ENTER(
"model %p, iter %p, parent %p (%s)",
886 tree_model, iter, parent, iter_to_string(parent));
887 model = GNC_TREE_MODEL_COMMODITY (tree_model);
888 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
892 ct = priv->commodity_table;
895 iter->stamp = model->
stamp;
896 iter->user_data = ITER_IS_NAMESPACE;
897 iter->user_data2 = g_list_nth_data(list, n);
898 iter->user_data3 = GINT_TO_POINTER(n);
899 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
900 return iter->user_data2 != NULL;
903 if (parent->user_data == ITER_IS_NAMESPACE)
908 iter->stamp = model->
stamp;
909 iter->user_data = ITER_IS_COMMODITY;
910 iter->user_data2 = g_list_nth_data(list, n);
911 iter->user_data3 = GINT_TO_POINTER(n);
912 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
913 return iter->user_data2 != NULL;
922 gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
932 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
933 g_return_val_if_fail (iter != NULL, FALSE);
934 g_return_val_if_fail (child != NULL, FALSE);
936 ENTER(
"model %p, iter %p, child %p (%s)",
937 tree_model, iter, child, iter_to_string(child));
938 model = GNC_TREE_MODEL_COMMODITY (tree_model);
939 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
941 if (child->user_data == ITER_IS_NAMESPACE)
943 LEAVE(
"ns has no parent");
947 ct = priv->commodity_table;
951 iter->stamp = model->
stamp;
952 iter->user_data = ITER_IS_NAMESPACE;
953 iter->user_data2 = name_space;
954 iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space));
955 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
977 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
978 g_return_val_if_fail ((commodity != NULL), FALSE);
979 g_return_val_if_fail ((iter != NULL), FALSE);
981 ENTER(
"model %p, commodity %p, iter %p", model, commodity, iter);
984 if (name_space == NULL)
986 LEAVE(
"no namespace");
997 n = g_list_index(list, commodity);
1000 LEAVE(
"not in list");
1004 iter->stamp = model->
stamp;
1005 iter->user_data = ITER_IS_COMMODITY;
1006 iter->user_data2 = commodity;
1007 iter->user_data3 = GINT_TO_POINTER(n);
1008 LEAVE(
"iter %s", iter_to_string(iter));
1021 GtkTreeIter tree_iter;
1022 GtkTreePath *tree_path;
1024 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
1025 g_return_val_if_fail (commodity != NULL, NULL);
1026 ENTER(
"model %p, commodity %p", model, commodity);
1034 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &tree_iter);
1037 gchar *path_string = gtk_tree_path_to_string(tree_path);
1038 LEAVE(
"path (2) %s", path_string);
1039 g_free(path_string);
1062 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
1063 g_return_val_if_fail ((name_space != NULL), FALSE);
1064 g_return_val_if_fail ((iter != NULL), FALSE);
1066 ENTER(
"model %p, namespace %p, iter %p", model, name_space, iter);
1068 priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
1076 n = g_list_index(list, name_space);
1083 iter->stamp = model->
stamp;
1084 iter->user_data = ITER_IS_NAMESPACE;
1085 iter->user_data2 = name_space;
1086 iter->user_data3 = GINT_TO_POINTER(n);
1087 LEAVE(
"iter %s", iter_to_string(iter));
1102 static GSList *pending_removals = NULL;
1120 GtkTreeModel *tree_model;
1121 GtkTreeIter tmp_iter;
1123 ENTER(
"model %p, iter (%p)%s", model, iter, iter_to_string(iter));
1133 while (model->
stamp == 0);
1134 iter->stamp = model->
stamp;
1137 tree_model = GTK_TREE_MODEL(model);
1138 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1139 gtk_tree_model_row_inserted(tree_model, path, iter);
1146 if (gtk_tree_path_up(path) &&
1147 gtk_tree_path_get_depth(path) > 0 &&
1148 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1151 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1154 if (gtk_tree_model_iter_n_children(tree_model, &tmp_iter) == 1)
1155 gtk_tree_model_row_has_child_toggled(tree_model, path, &tmp_iter);
1158 while (gtk_tree_path_up(path) &&
1159 gtk_tree_path_get_depth(path) > 0 &&
1160 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1162 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1165 gtk_tree_path_free(path);
1171 if (gnc_tree_model_commodity_iter_has_child(tree_model, iter))
1173 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1174 gtk_tree_model_row_has_child_toggled(tree_model, path, iter);
1175 gtk_tree_path_free(path);
1196 GtkTreeModel *tree_model;
1199 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1200 g_return_if_fail(path);
1202 debug_path(
ENTER, path);
1204 tree_model = GTK_TREE_MODEL(model);
1214 while (model->
stamp == 0);
1217 gtk_tree_model_row_deleted(tree_model, path);
1220 if (gtk_tree_path_up(path) &&
1221 gtk_tree_path_get_depth(path) > 0 &&
1222 gtk_tree_model_get_iter(tree_model, &iter, path) &&
1223 !gtk_tree_model_iter_has_child(tree_model, &iter))
1225 DEBUG(
"parent toggled, iter %s", iter_to_string(&iter));
1226 gtk_tree_model_row_has_child_toggled(tree_model, path, &iter);
1250 gnc_tree_model_commodity_do_deletions (gpointer unused)
1255 while (pending_removals)
1258 pending_removals = g_slist_delete_link(pending_removals, pending_removals);
1262 debug_path(
DEBUG, data->path);
1265 gnc_tree_model_commodity_row_delete(data->model, data->path);
1267 gtk_tree_path_free(data->path);
1310 gnc_tree_model_commodity_event_handler (
QofInstance *entity,
1313 gpointer event_data)
1324 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1326 ENTER(
"entity %p, event %d, model %p, event data %p",
1327 entity, event_type, user_data, event_data);
1330 if (pending_removals)
1331 gnc_tree_model_commodity_do_deletions(NULL);
1334 if (GNC_IS_COMMODITY(entity))
1338 commodity = GNC_COMMODITY(entity);
1340 if (event_type != QOF_EVENT_DESTROY)
1349 else if (GNC_IS_COMMODITY_NAMESPACE(entity))
1353 name_space = GNC_COMMODITY_NAMESPACE(entity);
1355 if (event_type != QOF_EVENT_DESTROY)
1374 DEBUG(
"add %s", name);
1375 gnc_tree_model_commodity_row_add (model, &iter);
1378 case QOF_EVENT_REMOVE:
1380 DEBUG(
"remove %s", name);
1381 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1384 LEAVE(
"not in model");
1389 data->model = model;
1391 pending_removals = g_slist_append (pending_removals, data);
1392 g_idle_add_full(G_PRIORITY_HIGH_IDLE,
1393 gnc_tree_model_commodity_do_deletions, NULL, NULL);
1398 case QOF_EVENT_MODIFY:
1399 DEBUG(
"change %s", name);
1400 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1403 LEAVE(
"not in model");
1406 gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
1407 gtk_tree_path_free(path);
1412 LEAVE(
"ignored event for %s", name);
GtkTreeModel implementation for gnucash commodities.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
gnc_commodity * gnc_tree_model_commodity_get_commodity(GncTreeModelCommodity *model, GtkTreeIter *iter)
gboolean gnc_tree_model_commodity_get_iter_from_commodity(GncTreeModelCommodity *model, gnc_commodity *commodity, GtkTreeIter *iter)
const GList * gnc_gobject_tracking_get_list(const gchar *name)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
GtkTreePath * gnc_tree_model_commodity_get_path_from_commodity(GncTreeModelCommodity *model, gnc_commodity *commodity)
utility functions for the GnuCash UI
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
#define DEBUG(format, args...)
gnc_commodity_namespace * gnc_tree_model_commodity_get_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
#define ENTER(format, args...)
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
gint qof_event_register_handler(QofEventHandler handler, gpointer handler_data)
Register a handler for events.
GType gnc_tree_model_commodity_get_type(void)
void qof_event_unregister_handler(gint handler_id)
Unregister an event handler.
GtkTreeModel * gnc_tree_model_commodity_new(QofBook *book, gnc_commodity_table *ct)
gboolean gnc_tree_model_commodity_get_iter_from_namespace(GncTreeModelCommodity *model, gnc_commodity_namespace *name_space, GtkTreeIter *iter)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
All type declarations for the whole Gnucash engine.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
gboolean gnc_tree_model_commodity_iter_is_commodity(GncTreeModelCommodity *model, GtkTreeIter *iter)
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
gboolean gnc_tree_model_commodity_iter_is_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
gnc_commodity_namespace * gnc_commodity_get_namespace_ds(const gnc_commodity *cm)
#define LEAVE(format, args...)
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *table)
const gchar * QofLogModule