GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-tree-view-commodity.c
1 /********************************************************************\
2  * gnc-tree-view-commodity.c -- GtkTreeView implementation to *
3  * display commodities in a GtkTreeView. *
4  * Copyright (C) 2003,2005 David Hampton <[email protected]> *
5  * *
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU General Public License as *
8  * published by the Free Software Foundation; either version 2 of *
9  * the License, or (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License*
17  * along with this program; if not, contact: *
18  * *
19  * Free Software Foundation Voice: +1-617-542-5942 *
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
21  * Boston, MA 02110-1301, USA [email protected] *
22  * *
23 \********************************************************************/
24 
25 #include "config.h"
26 
27 #include <gtk/gtk.h>
28 #include <glib/gi18n.h>
29 #include <string.h>
30 
31 #include "gnc-tree-view.h"
34 
35 #include "gnc-commodity.h"
36 #include "gnc-component-manager.h"
37 #include "gnc-engine.h"
38 #include "gnc-glib-utils.h"
39 #include "gnc-gnome-utils.h"
40 #include "gnc-icons.h"
41 #include "gnc-ui-util.h"
42 
43 
46 /* This static indicates the debugging module that this .o belongs to. */
47 static QofLogModule log_module = GNC_MOD_GUI;
48 
50 static void gnc_tree_view_commodity_class_init (GncTreeViewCommodityClass *klass);
51 static void gnc_tree_view_commodity_init (GncTreeViewCommodity *view);
52 static void gnc_tree_view_commodity_finalize (GObject *object);
53 static void gnc_tree_view_commodity_destroy (GtkObject *object);
54 
56 {
57  gpointer dummy;
59 
60 #define GNC_TREE_VIEW_COMMODITY_GET_PRIVATE(o) \
61  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_VIEW_COMMODITY, GncTreeViewCommodityPrivate))
62 
63 
64 /************************************************************/
65 /* g_object required functions */
66 /************************************************************/
67 
68 static GObjectClass *parent_class = NULL;
69 
70 GType
71 gnc_tree_view_commodity_get_type (void)
72 {
73  static GType gnc_tree_view_commodity_type = 0;
74 
75  if (gnc_tree_view_commodity_type == 0)
76  {
77  static const GTypeInfo our_info =
78  {
80  NULL,
81  NULL,
82  (GClassInitFunc) gnc_tree_view_commodity_class_init,
83  NULL,
84  NULL,
85  sizeof (GncTreeViewCommodity),
86  0,
87  (GInstanceInitFunc) gnc_tree_view_commodity_init
88  };
89 
90  gnc_tree_view_commodity_type = g_type_register_static (GNC_TYPE_TREE_VIEW,
91  "GncTreeViewCommodity",
92  &our_info, 0);
93  }
94 
95  return gnc_tree_view_commodity_type;
96 }
97 
98 static void
99 gnc_tree_view_commodity_class_init (GncTreeViewCommodityClass *klass)
100 {
101  GObjectClass *o_class;
102  GtkObjectClass *object_class;
103 
104  parent_class = g_type_class_peek_parent (klass);
105 
106  o_class = G_OBJECT_CLASS (klass);
107  object_class = GTK_OBJECT_CLASS (klass);
108 
109  /* GObject signals */
110  o_class->finalize = gnc_tree_view_commodity_finalize;
111 
112  /* GtkObject signals */
113  object_class->destroy = gnc_tree_view_commodity_destroy;
114 
115  g_type_class_add_private(klass, sizeof(GncTreeViewCommodityPrivate));
116 }
117 
118 static void
119 gnc_tree_view_commodity_init (GncTreeViewCommodity *view)
120 {
121 }
122 
123 static void
124 gnc_tree_view_commodity_finalize (GObject *object)
125 {
126  g_return_if_fail (object != NULL);
127  g_return_if_fail (GNC_IS_TREE_VIEW_COMMODITY (object));
128 
129  ENTER("view %p", object);
130  if (G_OBJECT_CLASS (parent_class)->finalize)
131  (* G_OBJECT_CLASS (parent_class)->finalize) (object);
132  LEAVE(" ");
133 }
134 
135 static void
136 gnc_tree_view_commodity_destroy (GtkObject *object)
137 {
138  g_return_if_fail (object != NULL);
139  g_return_if_fail (GNC_IS_TREE_VIEW_COMMODITY (object));
140 
141  ENTER("view %p", object);
142 
143  if (GTK_OBJECT_CLASS (parent_class)->destroy)
144  (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
145  LEAVE(" ");
146 }
147 
148 
149 /************************************************************/
150 /* sort functions */
151 /************************************************************/
152 
153 static gboolean
154 get_commodities_w_iters (GtkTreeModel *f_model,
155  GtkTreeIter *f_iter_a,
156  GtkTreeIter *f_iter_b,
157  GtkTreeModel **model_p,
158  GtkTreeIter *iter_a,
159  GtkTreeIter *iter_b,
160  gnc_commodity **comm_a,
161  gnc_commodity **comm_b)
162 {
163  GncTreeModelCommodity *model;
164  GtkTreeModel *tree_model;
165 
166  tree_model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
167  model = GNC_TREE_MODEL_COMMODITY(tree_model);
168 
169  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
170  iter_a,
171  f_iter_a);
172 
173  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
174  iter_b,
175  f_iter_b);
176 
177  /* Both iters must point to commodities for this to be meaningful */
178  if (!gnc_tree_model_commodity_iter_is_commodity (model, iter_a))
179  return FALSE;
180  if (!gnc_tree_model_commodity_iter_is_commodity (model, iter_b))
181  return FALSE;
182 
183  *comm_a = gnc_tree_model_commodity_get_commodity (model, iter_a);
184  *comm_b = gnc_tree_model_commodity_get_commodity (model, iter_b);
185  if (model_p)
186  *model_p = tree_model;
187  return TRUE;
188 }
189 
190 static gboolean
191 get_commodities (GtkTreeModel *f_model,
192  GtkTreeIter *f_iter_a,
193  GtkTreeIter *f_iter_b,
194  GtkTreeModel **model_p,
195  gnc_commodity **comm_a,
196  gnc_commodity **comm_b)
197 {
198  GtkTreeIter iter_a, iter_b;
199 
200  return get_commodities_w_iters(f_model, f_iter_a, f_iter_b, model_p,
201  &iter_a, &iter_b, comm_a, comm_b);
202 }
203 
204 static gint
205 sort_namespace (GtkTreeModel *f_model,
206  GtkTreeIter *f_iter_a,
207  GtkTreeIter *f_iter_b)
208 {
209  GncTreeModelCommodity *model;
210  GtkTreeModel *tree_model;
211  GtkTreeIter iter_a, iter_b;
212  gnc_commodity_namespace *ns_a, *ns_b;
213 
214  tree_model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
215  model = GNC_TREE_MODEL_COMMODITY(tree_model);
216 
217  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
218  &iter_a,
219  f_iter_a);
220  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
221  &iter_b,
222  f_iter_b);
223 
224  ns_a = gnc_tree_model_commodity_get_namespace (model, &iter_a);
225  ns_b = gnc_tree_model_commodity_get_namespace (model, &iter_b);
228 }
229 
230 static gint
231 default_sort (gnc_commodity *comm_a, gnc_commodity *comm_b)
232 {
233  gint fraction_a, fraction_b, result;
234 
236  gnc_commodity_get_namespace (comm_b));
237  if (result != 0) return result;
238 
240  gnc_commodity_get_mnemonic (comm_b));
241  if (result != 0) return result;
242 
244  gnc_commodity_get_fullname (comm_b));
245  if (result != 0) return result;
246 
247  result = safe_utf8_collate (gnc_commodity_get_cusip (comm_a),
248  gnc_commodity_get_cusip (comm_b));
249  if (result != 0) return result;
250 
251  fraction_a = gnc_commodity_get_fraction (comm_a);
252  fraction_b = gnc_commodity_get_fraction (comm_b);
253 
254  if (fraction_a < fraction_b)
255  return -1;
256 
257  if (fraction_b < fraction_a)
258  return 1;
259 
260  return 0;
261 }
262 
263 static gint
264 sort_by_commodity_string (GtkTreeModel *f_model,
265  GtkTreeIter *f_iter_a,
266  GtkTreeIter *f_iter_b,
267  gpointer user_data)
268 {
269  GtkTreeModel *model;
270  GtkTreeIter iter_a, iter_b;
271  gnc_commodity *comm_a, *comm_b;
272  gchar *str1, *str2;
273  gint column = GPOINTER_TO_INT(user_data);
274  gint result;
275 
276  if (!get_commodities_w_iters(f_model, f_iter_a, f_iter_b,
277  &model, &iter_a, &iter_b, &comm_a, &comm_b))
278  return sort_namespace (f_model, f_iter_a, f_iter_b);
279 
280  /* Get the strings. */
281  gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_a, column, &str1, -1);
282  gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_b, column, &str2, -1);
283 
284  result = safe_utf8_collate(str1, str2);
285  g_free(str1);
286  g_free(str2);
287  if (result != 0)
288  return result;
289  return default_sort(comm_a, comm_b);
290 }
291 
292 
293 static gint
294 sort_by_fraction (GtkTreeModel *f_model,
295  GtkTreeIter *f_iter_a,
296  GtkTreeIter *f_iter_b,
297  gpointer user_data)
298 {
299  gnc_commodity *comm_a, *comm_b;
300  gint fraction_a, fraction_b;
301 
302  if (!get_commodities (f_model, f_iter_a, f_iter_b, NULL, &comm_a, &comm_b))
303  return sort_namespace (f_model, f_iter_a, f_iter_b);
304 
305  fraction_a = gnc_commodity_get_fraction (comm_a);
306  fraction_b = gnc_commodity_get_fraction (comm_b);
307 
308  if (fraction_a < fraction_b)
309  return -1;
310 
311  if (fraction_b < fraction_a)
312  return 1;
313 
314  return default_sort(comm_a, comm_b);
315 }
316 
317 static gint
318 sort_by_quote_flag (GtkTreeModel *f_model,
319  GtkTreeIter *f_iter_a,
320  GtkTreeIter *f_iter_b,
321  gpointer user_data)
322 {
323  gnc_commodity *comm_a, *comm_b;
324  gboolean flag_a, flag_b;
325 
326  if (!get_commodities (f_model, f_iter_a, f_iter_b, NULL, &comm_a, &comm_b))
327  return sort_namespace (f_model, f_iter_a, f_iter_b);
328 
329  flag_a = gnc_commodity_get_quote_flag(comm_a);
330  flag_b = gnc_commodity_get_quote_flag(comm_b);
331 
332  if (flag_a < flag_b)
333  return -1;
334  else if (flag_a > flag_b)
335  return 1;
336  return default_sort(comm_a, comm_b);
337 }
338 
339 /************************************************************/
340 /* New View Creation */
341 /************************************************************/
342 
343 /*
344  * Create a new commodity tree view with (optional) top level root node.
345  * This view will be based on a model that is common to all view of
346  * the same set of books, but will have its own private filter on that
347  * model.
348  */
349 GtkTreeView *
351  const gchar *first_property_name,
352  ...)
353 {
354  GncTreeView *view;
355  GtkTreeModel *model, *f_model, *s_model;
356  GtkTreeViewColumn *col;
358  va_list var_args;
359 
360  ENTER(" ");
361  /* Create/get a pointer to the existing model for this set of books. */
362  ct = gnc_commodity_table_get_table (book);
363  model = gnc_tree_model_commodity_new (book, ct);
364 
365  /* Set up the view private filter on the common model. */
366  f_model = gtk_tree_model_filter_new (model, NULL);
367  g_object_unref(G_OBJECT(model));
368  s_model = gtk_tree_model_sort_new_with_model (f_model);
369  g_object_unref(G_OBJECT(f_model));
370 
371  /* Create our view */
372  view = g_object_new (GNC_TYPE_TREE_VIEW_COMMODITY,
373  "name", "commodity_tree", NULL);
374  gtk_tree_view_set_model (GTK_TREE_VIEW (view), s_model);
375  g_object_unref(G_OBJECT(s_model));
376 
377  DEBUG("model ref count is %d", G_OBJECT(model)->ref_count);
378  DEBUG("f_model ref count is %d", G_OBJECT(f_model)->ref_count);
379  DEBUG("s_model ref count is %d", G_OBJECT(s_model)->ref_count);
380 
381  /* Set default visibilities */
382  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
383 
385  view, _("Namespace"), "namespace", NULL, "NASDAQ",
386  GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE,
387  GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
388  sort_by_commodity_string);
390  view, _("Symbol"), "symbol", NULL, "ACMEACME",
391  GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC,
392  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
393  sort_by_commodity_string);
394  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
396  view, _("Name"), "name", NULL, "Acme Corporation, Inc.",
397  GNC_TREE_MODEL_COMMODITY_COL_FULLNAME,
398  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
399  sort_by_commodity_string);
400  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
402  view, _("Print Name"), "printname", NULL,
403  "ACMEACME (Acme Corporation, Inc.)",
404  GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME,
405  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
406  sort_by_commodity_string);
408  view, _("Display symbol"), "user_symbol", NULL, "ACME",
409  GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL,
410  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
411  sort_by_commodity_string);
412  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
414  view, _("Unique Name"), "uniquename", NULL,
415  "NASDAQ::ACMEACME", GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME,
416  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
417  sort_by_commodity_string);
419  /* Translators: Again replace CUSIP by the name of your
420  National Securities Identifying Number. */
421  view, _("ISIN/CUSIP"), "cusip_code", NULL, "QWERTYUIOP",
422  GNC_TREE_MODEL_COMMODITY_COL_CUSIP,
423  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
424  sort_by_commodity_string);
425  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
427  view, _("Fraction"), "fraction", "10000",
428  GNC_TREE_MODEL_COMMODITY_COL_FRACTION,
429  GNC_TREE_VIEW_COLUMN_COLOR_NONE,
430  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
431  sort_by_fraction);
432  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
434  view, _("Get Quotes"),
435  /* Translators: This string has a context prefix; the translation
436  must only contain the part after the | character. */
437  Q_("Column letter for 'Get Quotes'|Q"), "quote_flag",
438  GNC_TREE_MODEL_COMMODITY_COL_QUOTE_FLAG,
439  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
440  sort_by_quote_flag,
441  NULL);
443  view, _("Source"), "quote_source", NULL, "yahoo",
444  GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE,
445  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
446  sort_by_commodity_string);
448  view, _("Timezone"), "quote_timezone", NULL, "America/New_York",
449  GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ,
450  GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
451  sort_by_commodity_string);
452  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
453 
455 
456  /* Set properties */
457  va_start (var_args, first_property_name);
458  g_object_set_valist (G_OBJECT(view), first_property_name, var_args);
459  va_end (var_args);
460 
461  /* Sort on the name column by default. This allows for a consistent
462  * sort if commodities are briefly removed and re-added. */
463  if (!gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(s_model),
464  NULL, NULL))
465  {
466  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(s_model),
467  GNC_TREE_MODEL_COMMODITY_COL_FULLNAME,
468  GTK_SORT_ASCENDING);
469  }
470 
471  gtk_widget_show(GTK_WIDGET(view));
472  LEAVE(" %p", view);
473  return GTK_TREE_VIEW(view);
474 }
475 
476 /************************************************************/
477 /* Auxiliary Functions */
478 /************************************************************/
479 
480 #define debug_path(fn, path) { \
481  gchar *path_string = gtk_tree_path_to_string(path); \
482  fn("tree path %s", path_string); \
483  g_free(path_string); \
484  }
485 
486 #if 0 /* Not Used */
487 static gboolean
488 gnc_tree_view_commodity_get_iter_from_commodity (GncTreeViewCommodity *view,
489  gnc_commodity *commodity,
490  GtkTreeIter *s_iter)
491 {
492  GtkTreeModel *model, *f_model, *s_model;
493  GtkTreeIter iter, f_iter;
494 
495  g_return_val_if_fail(GNC_IS_TREE_VIEW_COMMODITY(view), FALSE);
496  g_return_val_if_fail(commodity != NULL, FALSE);
497  g_return_val_if_fail(s_iter != NULL, FALSE);
498 
499  ENTER("view %p, commodity %p (%s)", view, commodity, gnc_commodity_get_mnemonic(commodity));
500 
501  /* Reach down to the real model and get an iter for this commodity */
502  s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
503  f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
504  model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
505  if (!gnc_tree_model_commodity_get_iter_from_commodity (GNC_TREE_MODEL_COMMODITY(model), commodity, &iter))
506  {
507  LEAVE("model_get_iter_from_commodity failed");
508  return FALSE;
509  }
510 
511  /* convert back to a sort iter */
512  gtk_tree_model_filter_convert_child_iter_to_iter (GTK_TREE_MODEL_FILTER(f_model),
513  &f_iter, &iter);
514  gtk_tree_model_sort_convert_child_iter_to_iter (GTK_TREE_MODEL_SORT(s_model),
515  s_iter, &f_iter);
516  LEAVE(" ");
517  return TRUE;
518 }
519 #endif /* Not Used */
520 
521 /************************************************************/
522 /* Commodity Tree View Visibility Filter */
523 /************************************************************/
524 
525 typedef struct
526 {
527  gnc_tree_view_commodity_ns_filter_func user_ns_fn;
528  gnc_tree_view_commodity_cm_filter_func user_cm_fn;
529  gpointer user_data;
530  GDestroyNotify user_destroy;
532 
533 static void
534 gnc_tree_view_commodity_filter_destroy (gpointer data)
535 {
536  filter_user_data *fd = data;
537 
538  if (fd->user_destroy)
539  fd->user_destroy(fd->user_data);
540  g_free(fd);
541 }
542 
543 static gboolean
544 gnc_tree_view_commodity_filter_helper (GtkTreeModel *model,
545  GtkTreeIter *iter,
546  gpointer data)
547 {
548  gnc_commodity_namespace *name_space;
549  gnc_commodity *commodity;
550  filter_user_data *fd = data;
551 
552  g_return_val_if_fail (GNC_IS_TREE_MODEL_COMMODITY (model), FALSE);
553  g_return_val_if_fail (iter != NULL, FALSE);
554 
555  if (gnc_tree_model_commodity_iter_is_namespace (GNC_TREE_MODEL_COMMODITY(model), iter))
556  {
557  if (fd->user_ns_fn)
558  {
559  name_space = gnc_tree_model_commodity_get_namespace (GNC_TREE_MODEL_COMMODITY(model), iter);
560  return fd->user_ns_fn(name_space, fd->user_data);
561  }
562  return TRUE;
563  }
564 
565  if (gnc_tree_model_commodity_iter_is_commodity (GNC_TREE_MODEL_COMMODITY(model), iter))
566  {
567  if (fd->user_cm_fn)
568  {
569  commodity = gnc_tree_model_commodity_get_commodity (GNC_TREE_MODEL_COMMODITY(model), iter);
570  return fd->user_cm_fn(commodity, fd->user_data);
571  }
572  return TRUE;
573  }
574 
575  return FALSE;
576 }
577 
578 /*
579  * Set an GtkTreeModel visible filter on this commodity. This filter will be
580  * called for each commodity that the tree is about to show, and the
581  * commodity will be passed to the callback function.
582  */
583 void
585  gnc_tree_view_commodity_ns_filter_func ns_func,
586  gnc_tree_view_commodity_cm_filter_func cm_func,
587  gpointer data,
588  GDestroyNotify destroy)
589 {
590  GtkTreeModel *f_model, *s_model;
591  filter_user_data *fd = data;
592 
593  g_return_if_fail(GNC_IS_TREE_VIEW_COMMODITY(view));
594  g_return_if_fail((ns_func != NULL) || (cm_func != NULL));
595 
596  ENTER("view %p, ns func %p, cm func %p, data %p, destroy %p",
597  view, ns_func, cm_func, data, destroy);
598 
599  fd = g_malloc(sizeof(filter_user_data));
600  fd->user_ns_fn = ns_func;
601  fd->user_cm_fn = cm_func;
602  fd->user_data = data;
603  fd->user_destroy = destroy;
604 
605  s_model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
606  f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
607  gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (f_model),
608  gnc_tree_view_commodity_filter_helper,
609  fd,
610  gnc_tree_view_commodity_filter_destroy);
611 
612  /* Whack any existing levels. The top two levels have been created
613  * before this routine can be called. */
614  gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (f_model));
615  LEAVE(" ");
616 }
617 
618 /*
619  * Forces the entire commodity tree to be re-evaluated for visibility.
620  */
621 void
623 {
624  GtkTreeModel *f_model, *s_model;
625 
626  g_return_if_fail(GNC_IS_TREE_VIEW_COMMODITY(view));
627 
628  ENTER("view %p", view);
629  s_model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
630  f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model));
631  gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (f_model));
632  LEAVE(" ");
633 }
634 
635 
636 /************************************************************/
637 /* Commodity Tree View Get/Set Functions */
638 /************************************************************/
639 
640 /*
641  * Retrieve the selected commodity from an commodity tree view. The
642  * commodity tree must be in single selection mode.
643  */
646 {
647  GtkTreeSelection *selection;
648  GtkTreeModel *model, *f_model, *s_model;
649  GtkTreeIter iter, f_iter, s_iter;
650  gnc_commodity *commodity;
651 
652  g_return_val_if_fail (GNC_IS_TREE_VIEW_COMMODITY (view), NULL);
653 
654  ENTER("view %p", view);
655 
656  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
657  if (!gtk_tree_selection_get_selected (selection, &s_model, &s_iter))
658  {
659  LEAVE("no commodity, get_selected failed");
660  return FALSE;
661  }
662 
663  gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (s_model),
664  &f_iter, &s_iter);
665 
666  f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
667  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (f_model),
668  &iter, &f_iter);
669 
670  model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
671  commodity = gnc_tree_model_commodity_get_commodity (GNC_TREE_MODEL_COMMODITY(model),
672  &iter);
673  LEAVE("commodity %p (%s)", commodity,
674  commodity ? gnc_commodity_get_mnemonic(commodity) : "");
675  return commodity;
676 }
677 
678 
679 #if 0 /* Not Used */
680 /*
681  * This helper function is called once for each row in the tree view
682  * that is currently selected. Its task is to an the corresponding
683  * commodity to the end of a glist.
684  */
685 static void
686 get_selected_commodities_helper (GtkTreeModel *s_model,
687  GtkTreePath *s_path,
688  GtkTreeIter *s_iter,
689  gpointer data)
690 {
691  GList **return_list = data;
692  GtkTreeModel *model, *f_model;
693  GtkTreeIter iter, f_iter;
694  gnc_commodity *commodity;
695 
696  gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (s_model),
697  &f_iter, s_iter);
698 
699  f_model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(s_model));
700  gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (f_model),
701  &iter, &f_iter);
702 
703  model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
704  commodity = gnc_tree_model_commodity_get_commodity (GNC_TREE_MODEL_COMMODITY(model),
705  &iter);
706  *return_list = g_list_append(*return_list, commodity);
707 }
708 #endif /* Not Used */
GtkTreeModel implementation for gnucash commodities.
GtkTreeView * gnc_tree_view_commodity_new(QofBook *book, const gchar *first_property_name,...)
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
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 char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *stock_icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
void gnc_tree_view_commodity_set_filter(GncTreeViewCommodity *view, gnc_tree_view_commodity_ns_filter_func ns_func, gnc_tree_view_commodity_cm_filter_func cm_func, gpointer data, GDestroyNotify destroy)
utility functions for the GnuCash UI
int safe_utf8_collate(const char *da, const char *db)
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
common utilities for manipulating a GtkTreeView within gnucash
#define DEBUG(format, args...)
Definition: qoflog.h:255
gnc_commodity_namespace * gnc_tree_model_commodity_get_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
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)
#define ENTER(format, args...)
Definition: qoflog.h:261
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
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)
void gnc_tree_view_configure_columns(GncTreeView *view)
GtkTreeModel * gnc_tree_model_commodity_new(QofBook *book, gnc_commodity_table *ct)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Gnome specific utility functions.
All type declarations for the whole Gnucash engine.
GLib helper routines.
gboolean gnc_tree_model_commodity_iter_is_commodity(GncTreeModelCommodity *model, GtkTreeIter *iter)
gboolean gnc_tree_model_commodity_iter_is_namespace(GncTreeModelCommodity *model, GtkTreeIter *iter)
gnc_commodity * gnc_tree_view_commodity_get_selected_commodity(GncTreeViewCommodity *view)
#define LEAVE(format, args...)
Definition: qoflog.h:271
GtkTreeView implementation for gnucash commodity tree.
void gnc_tree_view_commodity_refilter(GncTreeViewCommodity *view)
Commodity handling public routines.
const gchar * QofLogModule
Definition: qofid.h:89