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);
427 LEAVE(
"invalid path at namespace");
434 iter->stamp = model->stamp;
435 iter->user_data = ITER_IS_NAMESPACE;
436 iter->user_data2 = name_space;
437 iter->user_data3 = GINT_TO_POINTER(i);
438 LEAVE(
"iter (ns) %s", iter_to_string(iter));
444 i = gtk_tree_path_get_indices (path)[1];
445 commodity = g_list_nth_data (list, i);
448 LEAVE(
"invalid path at commodity");
453 iter->stamp = model->stamp;
454 iter->user_data = ITER_IS_COMMODITY;
455 iter->user_data2 = commodity;
456 iter->user_data3 = GINT_TO_POINTER(i);
457 LEAVE(
"iter (cm) %s", iter_to_string(iter));
462 gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
465 GncTreeModelCommodity *model;
467 gnc_commodity_table *ct;
468 gnc_commodity_namespace *name_space;
471 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), NULL);
472 model = GNC_TREE_MODEL_COMMODITY (tree_model);
473 g_return_val_if_fail (iter != NULL, NULL);
474 g_return_val_if_fail (iter->user_data != NULL, NULL);
475 g_return_val_if_fail (iter->user_data2 != NULL, NULL);
476 g_return_val_if_fail (iter->stamp == model->stamp, NULL);
477 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
480 ct = model->commodity_table;
483 LEAVE(
"no commodity table");
487 if (iter->user_data == ITER_IS_NAMESPACE)
491 path = gtk_tree_path_new ();
492 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
493 debug_path(
LEAVE, path);
502 path = gtk_tree_path_new ();
503 gtk_tree_path_append_index (path, g_list_index (ns_list, name_space));
504 gtk_tree_path_append_index (path, GPOINTER_TO_INT(iter->user_data3));
505 debug_path(
LEAVE, path);
510 gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
515 GncTreeModelCommodity *model = GNC_TREE_MODEL_COMMODITY (tree_model);
516 gnc_commodity_namespace *name_space;
517 gnc_commodity *commodity;
518 gnc_quote_source *source;
520 g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model));
521 g_return_if_fail (iter != NULL);
522 g_return_if_fail (iter->user_data != NULL);
523 g_return_if_fail (iter->user_data2 != NULL);
524 g_return_if_fail (iter->stamp == model->stamp);
526 if (iter->user_data == ITER_IS_NAMESPACE)
528 name_space = (gnc_commodity_namespace *)iter->user_data2;
531 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
532 g_value_init (value, G_TYPE_STRING);
536 g_value_init (value, G_TYPE_STRING);
537 g_value_set_string (value,
"");
539 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
540 g_value_init (value, G_TYPE_INT);
541 g_value_set_int (value, 0);
543 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
544 g_value_init (value, G_TYPE_BOOLEAN);
545 g_value_set_boolean (value, FALSE);
547 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
548 g_value_init (value, G_TYPE_BOOLEAN);
549 g_value_set_boolean (value, FALSE);
555 commodity = (gnc_commodity *)iter->user_data2;
558 case GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC:
559 g_value_init (value, G_TYPE_STRING);
563 case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
564 g_value_init (value, G_TYPE_STRING);
567 g_value_set_string (value, NULL);
569 case GNC_TREE_MODEL_COMMODITY_COL_FULLNAME:
570 g_value_init (value, G_TYPE_STRING);
574 case GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME:
575 g_value_init (value, G_TYPE_STRING);
579 case GNC_TREE_MODEL_COMMODITY_COL_CUSIP:
580 g_value_init (value, G_TYPE_STRING);
584 case GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME:
585 g_value_init (value, G_TYPE_STRING);
589 case GNC_TREE_MODEL_COMMODITY_COL_FRACTION:
590 g_value_init (value, G_TYPE_INT);
594 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG:
595 g_value_init (value, G_TYPE_BOOLEAN);
599 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE:
600 g_value_init (value, G_TYPE_STRING);
609 g_value_set_static_string (value,
"");
612 case GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ:
613 g_value_init (value, G_TYPE_STRING);
621 g_value_set_static_string (value,
"");
624 case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
625 g_value_init (value, G_TYPE_STRING);
629 case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
630 g_value_init (value, G_TYPE_BOOLEAN);
631 g_value_set_boolean (value, TRUE);
634 g_assert_not_reached ();
639 gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
642 GncTreeModelCommodity *model;
643 gnc_commodity_table *ct;
644 gnc_commodity_namespace *name_space;
648 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
649 model = GNC_TREE_MODEL_COMMODITY (tree_model);
650 g_return_val_if_fail (iter != NULL, FALSE);
651 g_return_val_if_fail (iter->user_data != NULL, FALSE);
652 g_return_val_if_fail (iter->user_data2 != NULL, FALSE);
653 g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
655 ENTER(
"model %p, iter %p(%s)", tree_model, iter, iter_to_string(iter));
656 if (iter->user_data == ITER_IS_NAMESPACE)
658 ct = model->commodity_table;
661 else if (iter->user_data == ITER_IS_COMMODITY)
668 LEAVE(
"unknown iter type");
672 n = GPOINTER_TO_INT(iter->user_data3) + 1;
673 iter->user_data2 = g_list_nth_data(list, n);
674 if (iter->user_data2 == NULL)
676 LEAVE(
"no next iter");
679 iter->user_data3 = GINT_TO_POINTER(n);
680 LEAVE(
"iter %p(%s)", iter, iter_to_string(iter));
686 gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
690 GncTreeModelCommodity *model;
691 gnc_commodity_table *ct;
692 gnc_commodity_namespace *name_space;
695 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
697 ENTER(
"model %p, iter %p, parent %p (%s)",
698 tree_model, iter, parent, iter_to_string(parent));
699 model = GNC_TREE_MODEL_COMMODITY (tree_model);
703 ct = model->commodity_table;
707 LEAVE(
"no namespaces");
711 iter->stamp = model->stamp;
712 iter->user_data = ITER_IS_NAMESPACE;
713 iter->user_data2 = g_list_nth_data(list, 0);
714 iter->user_data3 = GINT_TO_POINTER(0);
715 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
719 if (parent->user_data == ITER_IS_NAMESPACE)
721 name_space = (gnc_commodity_namespace *)parent->user_data2;
725 LEAVE(
"no commodities");
729 iter->stamp = model->stamp;
730 iter->user_data = ITER_IS_COMMODITY;
731 iter->user_data2 = g_list_nth_data(list, 0);
732 iter->user_data3 = GINT_TO_POINTER(0);
733 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
742 gnc_tree_model_commodity_iter_has_child (GtkTreeModel *tree_model,
745 gnc_commodity_namespace *name_space;
748 g_return_val_if_fail (iter != NULL, FALSE);
749 ENTER(
"model %p, iter %p (%s)", tree_model,
750 iter, iter_to_string(iter));
752 if (iter->user_data != ITER_IS_NAMESPACE)
754 LEAVE(
"no children (not ns)");
758 name_space = (gnc_commodity_namespace *)iter->user_data2;
760 LEAVE(
"%s children", list ?
"has" :
"no");
765 gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
768 GncTreeModelCommodity *model;
769 gnc_commodity_table *ct;
770 gnc_commodity_namespace *name_space;
773 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), -1);
775 ENTER(
"model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
776 model = GNC_TREE_MODEL_COMMODITY (tree_model);
780 ct = model->commodity_table;
782 LEAVE(
"ns list length %d", g_list_length(list));
783 return g_list_length (list);
786 if (iter->user_data == ITER_IS_NAMESPACE)
788 name_space = (gnc_commodity_namespace *)iter->user_data2;
790 LEAVE(
"cm list length %d", g_list_length(list));
791 return g_list_length (list);
799 gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
804 GncTreeModelCommodity *model;
805 gnc_commodity_table *ct;
806 gnc_commodity_namespace *name_space;
809 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
810 g_return_val_if_fail (iter != NULL, FALSE);
812 ENTER(
"model %p, iter %p, parent %p (%s)",
813 tree_model, iter, parent, iter_to_string(parent));
814 model = GNC_TREE_MODEL_COMMODITY (tree_model);
818 ct = model->commodity_table;
821 iter->stamp = model->stamp;
822 iter->user_data = ITER_IS_NAMESPACE;
823 iter->user_data2 = g_list_nth_data(list, n);
824 iter->user_data3 = GINT_TO_POINTER(n);
825 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
826 return iter->user_data2 != NULL;
829 if (parent->user_data == ITER_IS_NAMESPACE)
831 name_space = (gnc_commodity_namespace *)parent->user_data2;
834 iter->stamp = model->stamp;
835 iter->user_data = ITER_IS_COMMODITY;
836 iter->user_data2 = g_list_nth_data(list, n);
837 iter->user_data3 = GINT_TO_POINTER(n);
838 LEAVE(
"cm iter %p (%s)", iter, iter_to_string(iter));
839 return iter->user_data2 != NULL;
848 gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
852 GncTreeModelCommodity *model;
853 gnc_commodity_table *ct;
854 gnc_commodity_namespace *name_space;
857 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (tree_model), FALSE);
858 g_return_val_if_fail (iter != NULL, FALSE);
859 g_return_val_if_fail (child != NULL, FALSE);
861 ENTER(
"model %p, iter %p, child %p (%s)",
862 tree_model, iter, child, iter_to_string(child));
863 model = GNC_TREE_MODEL_COMMODITY (tree_model);
865 if (child->user_data == ITER_IS_NAMESPACE)
867 LEAVE(
"ns has no parent");
871 ct = model->commodity_table;
875 iter->stamp = model->stamp;
876 iter->user_data = ITER_IS_NAMESPACE;
877 iter->user_data2 = name_space;
878 iter->user_data3 = GINT_TO_POINTER(g_list_index(list, name_space));
879 LEAVE(
"ns iter %p (%s)", iter, iter_to_string(iter));
894 gnc_commodity *commodity,
897 gnc_commodity_namespace *name_space;
901 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
902 g_return_val_if_fail ((commodity != NULL), FALSE);
903 g_return_val_if_fail ((iter != NULL), FALSE);
905 ENTER(
"model %p, commodity %p, iter %p", model, commodity, iter);
908 if (name_space == NULL)
910 LEAVE(
"no namespace");
921 n = g_list_index(list, commodity);
924 LEAVE(
"not in list");
928 iter->stamp = model->stamp;
929 iter->user_data = ITER_IS_COMMODITY;
930 iter->user_data2 = commodity;
931 iter->user_data3 = GINT_TO_POINTER(n);
932 LEAVE(
"iter %s", iter_to_string(iter));
943 gnc_commodity *commodity)
945 GtkTreeIter tree_iter;
946 GtkTreePath *tree_path;
948 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), NULL);
949 g_return_val_if_fail (commodity != NULL, NULL);
950 ENTER(
"model %p, commodity %p", model, commodity);
958 tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &tree_iter);
961 gchar *path_string = gtk_tree_path_to_string(tree_path);
962 LEAVE(
"path (2) %s", path_string);
979 gnc_commodity_namespace *name_space,
985 g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
986 g_return_val_if_fail ((name_space != NULL), FALSE);
987 g_return_val_if_fail ((iter != NULL), FALSE);
989 ENTER(
"model %p, namespace %p, iter %p", model, name_space, iter);
998 n = g_list_index(list, name_space);
1005 iter->stamp = model->stamp;
1006 iter->user_data = ITER_IS_NAMESPACE;
1007 iter->user_data2 = name_space;
1008 iter->user_data3 = GINT_TO_POINTER(n);
1009 LEAVE(
"iter %s", iter_to_string(iter));
1018 typedef struct _remove_data
1020 GncTreeModelCommodity *model;
1024 static GSList *pending_removals = NULL;
1038 gnc_tree_model_commodity_row_add (GncTreeModelCommodity *model,
1042 GtkTreeModel *tree_model;
1043 GtkTreeIter tmp_iter;
1045 ENTER(
"model %p, iter (%p)%s", model, iter, iter_to_string(iter));
1055 while (model->stamp == 0);
1056 iter->stamp = model->stamp;
1059 tree_model = GTK_TREE_MODEL(model);
1060 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1061 gtk_tree_model_row_inserted(tree_model, path, iter);
1068 if (gtk_tree_path_up(path) &&
1069 gtk_tree_path_get_depth(path) > 0 &&
1070 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1073 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1076 if (gtk_tree_model_iter_n_children(tree_model, &tmp_iter) == 1)
1077 gtk_tree_model_row_has_child_toggled(tree_model, path, &tmp_iter);
1080 while (gtk_tree_path_up(path) &&
1081 gtk_tree_path_get_depth(path) > 0 &&
1082 gtk_tree_model_get_iter(tree_model, &tmp_iter, path))
1084 gtk_tree_model_row_changed(tree_model, path, &tmp_iter);
1087 gtk_tree_path_free(path);
1093 if (gnc_tree_model_commodity_iter_has_child(tree_model, iter))
1095 path = gnc_tree_model_commodity_get_path(tree_model, iter);
1096 gtk_tree_model_row_has_child_toggled(tree_model, path, iter);
1097 gtk_tree_path_free(path);
1115 gnc_tree_model_commodity_row_delete (GncTreeModelCommodity *model,
1118 GtkTreeModel *tree_model;
1121 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1122 g_return_if_fail(path);
1124 debug_path(
ENTER, path);
1126 tree_model = GTK_TREE_MODEL(model);
1136 while (model->stamp == 0);
1139 gtk_tree_model_row_deleted(tree_model, path);
1142 if (gtk_tree_path_up(path) &&
1143 gtk_tree_path_get_depth(path) > 0 &&
1144 gtk_tree_model_get_iter(tree_model, &iter, path) &&
1145 !gtk_tree_model_iter_has_child(tree_model, &iter))
1147 DEBUG(
"parent toggled, iter %s", iter_to_string(&iter));
1148 gtk_tree_model_row_has_child_toggled(tree_model, path, &iter);
1172 gnc_tree_model_commodity_do_deletions (gpointer unused)
1177 while (pending_removals)
1180 pending_removals = g_slist_delete_link(pending_removals, pending_removals);
1184 debug_path(
DEBUG, data->path);
1187 gnc_tree_model_commodity_row_delete(data->model, data->path);
1189 gtk_tree_path_free(data->path);
1232 gnc_tree_model_commodity_event_handler (
QofInstance *entity,
1235 gpointer event_data)
1237 GncTreeModelCommodity *model;
1243 model = (GncTreeModelCommodity *)user_data;
1246 g_return_if_fail(GNC_IS_TREE_MODEL_COMMODITY(model));
1248 ENTER(
"entity %p, event %d, model %p, event data %p",
1249 entity, event_type, user_data, event_data);
1252 if (pending_removals)
1253 gnc_tree_model_commodity_do_deletions(NULL);
1256 if (GNC_IS_COMMODITY(entity))
1258 gnc_commodity *commodity;
1260 commodity = GNC_COMMODITY(entity);
1262 if (event_type != QOF_EVENT_DESTROY)
1271 else if (GNC_IS_COMMODITY_NAMESPACE(entity))
1273 gnc_commodity_namespace *name_space;
1275 name_space = GNC_COMMODITY_NAMESPACE(entity);
1277 if (event_type != QOF_EVENT_DESTROY)
1296 DEBUG(
"add %s", name);
1297 gnc_tree_model_commodity_row_add (model, &iter);
1300 case QOF_EVENT_REMOVE:
1302 DEBUG(
"remove %s", name);
1303 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1306 LEAVE(
"not in model");
1311 data->model = model;
1313 pending_removals = g_slist_append (pending_removals, data);
1314 g_idle_add_full(G_PRIORITY_HIGH_IDLE,
1315 gnc_tree_model_commodity_do_deletions, NULL, NULL);
1320 case QOF_EVENT_MODIFY:
1321 DEBUG(
"change %s", name);
1322 path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter);
1325 LEAVE(
"not in model");
1328 gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter);
1329 gtk_tree_path_free(path);
1334 LEAVE(
"ignored event for %s", name);
1337 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.