GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-commodity.c
Go to the documentation of this file.
1 /********************************************************************
2  * dialog-commodity.c -- "select" and "new" commodity windows *
3  * (GnuCash) *
4  * Copyright (C) 2000 Bill Gribble <[email protected]> *
5  * Copyright (c) 2006 David Hampton <[email protected]> *
6  * Copyright (c) 2011 Robert Fewell *
7  * *
8  * This program is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License as *
10  * published by the Free Software Foundation; either version 2 of *
11  * the License, or (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License*
19  * along with this program; if not, contact: *
20  * *
21  * Free Software Foundation Voice: +1-617-542-5942 *
22  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
23  * Boston, MA 02110-1301, USA [email protected] *
24  ********************************************************************/
25 
37 #include "config.h"
38 
39 #include <gtk/gtk.h>
40 #include <glib/gi18n.h>
41 #include <stdio.h>
42 
43 #include "dialog-commodity.h"
44 #include "dialog-utils.h"
45 #include "gnc-engine.h"
46 #include "gnc-gtk-utils.h"
47 #include "gnc-gui-query.h"
48 #include "gnc-ui-util.h"
49 #include "gnc-ui.h"
50 
51 /* This static indicates the debugging module that this .o belongs to. */
52 static QofLogModule log_module = GNC_MOD_GUI;
53 
54 enum
55 {
56  SOURCE_COL_NAME = 0,
57  SOURCE_COL_FQ_SUPPORTED,
58  NUM_SOURCE_COLS
59 };
60 
62 {
63  GtkWidget * dialog;
64  GtkWidget * namespace_combo;
65  GtkWidget * commodity_combo;
66  GtkWidget * select_user_prompt;
67  GtkWidget * ok_button;
68 
69  gnc_commodity * selection;
70 
71  const char * default_cusip;
72  const char * default_fullname;
73  const char * default_mnemonic;
74  const char * default_user_symbol;
75  int default_fraction;
76 };
77 
79 {
80  GtkWidget * dialog;
81  GtkWidget * table;
82  GtkWidget * fullname_entry;
83  GtkWidget * mnemonic_entry;
84  GtkWidget * user_symbol_entry;
85  GtkWidget * namespace_combo;
86  GtkWidget * code_entry;
87  GtkWidget * fraction_spinbutton;
88  GtkWidget * get_quote_check;
89  GtkWidget * source_label;
90  GtkWidget * source_button[SOURCE_MAX];
91  GtkWidget * source_menu[SOURCE_MAX];
92  GtkWidget * quote_tz_label;
93  GtkWidget * quote_tz_menu;
94  GtkWidget * ok_button;
95 
96  guint comm_section_top;
97  guint comm_section_bottom;
98  guint comm_symbol_line;
99  guint fq_section_top;
100  guint fq_section_bottom;
101 
102  gboolean is_currency;
103  gnc_commodity *edit_commodity;
104 };
105 
107 typedef struct commodity_window CommodityWindow;
108 
109 static gnc_commodity_help_callback help_callback = NULL;
110 
111 
112 /* The commodity selection window */
113 static SelectCommodityWindow *
114 gnc_ui_select_commodity_create(const gnc_commodity * orig_sel,
115  dialog_commodity_mode mode);
116 void gnc_ui_select_commodity_new_cb(GtkButton * button,
117  gpointer user_data);
118 void gnc_ui_select_commodity_changed_cb(GtkComboBox *cbwe,
119  gpointer user_data);
120 void gnc_ui_select_commodity_namespace_changed_cb(GtkComboBox *cbwe,
121  gpointer user_data);
122 
123 /* The commodity creation window */
124 void gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data);
125 void gnc_ui_commodity_quote_info_cb(GtkWidget *w, gpointer data);
126 gboolean gnc_ui_commodity_dialog_to_object(CommodityWindow * w);
127 
128 #if 0
129 static void gnc_ui_select_commodity_response_cb (GtkDialog * dialog, gint response, gpointer data);
130 #endif
131 
132 
133 /********************************************************************
134  * gnc_ui_commodity_set_help_callback
135  ********************************************************************/
136 void
137 gnc_ui_commodity_set_help_callback (gnc_commodity_help_callback cb)
138 {
139  help_callback = cb;
140 }
141 
142 
143 /********************************************************************
144  * gnc_ui_select_commodity_modal_full()
145  ********************************************************************/
148  GtkWidget * parent,
150  const char * user_message,
151  const char * cusip,
152  const char * fullname,
153  const char * mnemonic)
154 {
155  gnc_commodity * retval = NULL;
156  const gchar *initial;
157  gchar *user_prompt_text;
158  SelectCommodityWindow * win;
159  gboolean done;
160  gint value;
161 
162  win = gnc_ui_select_commodity_create(orig_sel, mode);
163  win->default_cusip = cusip;
164  win->default_fullname = fullname;
165  win->default_mnemonic = mnemonic;
166  win->default_user_symbol = "";
167 
168  if (parent)
169  gtk_window_set_transient_for (GTK_WINDOW (win->dialog), GTK_WINDOW (parent));
170 
171  if (user_message != NULL)
172  initial = user_message;
173  else if ((cusip != NULL) || (fullname != NULL) || (mnemonic != NULL))
174  initial = _("\nPlease select a commodity to match:");
175  else
176  initial = "";
177 
178  user_prompt_text =
179  g_strdup_printf("%s%s%s%s%s%s%s",
180  initial,
181  fullname ? _("\nCommodity: ") : "",
182  fullname ? fullname : "",
183  /* Translators: Replace here and later CUSIP by the name of your local
184  National Securities Identifying Number
185  like gb:SEDOL, de:WKN, ch:Valorennummer, fr:SICOVAM ...
186  See http://en.wikipedia.org/wiki/ISIN for hints. */
187  cusip ? _("\nExchange code (ISIN, CUSIP or similar): ") : "",
188  cusip ? cusip : "",
189  mnemonic ? _("\nMnemonic (Ticker symbol or similar): ") : "",
190  mnemonic ? mnemonic : "");
191  gtk_label_set_text ((GtkLabel *)(win->select_user_prompt),
192  user_prompt_text);
193  g_free(user_prompt_text);
194 
195  /* Run the dialog, handling the terminal conditions. */
196  done = FALSE;
197  while (!done)
198  {
199  switch (value = gtk_dialog_run(GTK_DIALOG(win->dialog)))
200  {
201  case GTK_RESPONSE_OK:
202  DEBUG("case OK");
203  retval = win->selection;
204  done = TRUE;
205  break;
206  case GNC_RESPONSE_NEW:
207  DEBUG("case NEW");
209  break;
210  default: /* Cancel, Escape, Close, etc. */
211  DEBUG("default: %d", value);
212  retval = NULL;
213  done = TRUE;
214  break;
215  }
216  }
217  gtk_widget_destroy (GTK_WIDGET (win->dialog)); /* Close and destroy */
218  g_free(win);
219 
220  return retval;
221 }
222 
223 
224 /********************************************************************
225  * gnc_ui_select_commodity_modal()
226  ********************************************************************/
229  GtkWidget * parent,
231 {
232  return gnc_ui_select_commodity_modal_full(orig_sel,
233  parent,
234  mode,
235  NULL,
236  NULL,
237  NULL,
238  NULL);
239 }
240 
241 
242 /********************************************************************
243  * gnc_ui_select_commodity_create()
244  ********************************************************************/
245 static SelectCommodityWindow *
246 gnc_ui_select_commodity_create(const gnc_commodity * orig_sel,
248 {
249  SelectCommodityWindow * retval = g_new0(SelectCommodityWindow, 1);
250  GtkBuilder *builder;
251  const char *title, *text;
252  gchar *name_space;
253  GtkWidget *button, *label;
254 
255  builder = gtk_builder_new();
256  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "liststore1");
257  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "liststore2");
258  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "Security Selector Dialog");
259 
260  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, retval);
261 
262  retval->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Security Selector Dialog"));
263  retval->namespace_combo = GTK_WIDGET(gtk_builder_get_object (builder, "ss_namespace_cbwe"));
264  retval->commodity_combo = GTK_WIDGET(gtk_builder_get_object (builder, "ss_commodity_cbwe"));
265  retval->select_user_prompt = GTK_WIDGET(gtk_builder_get_object (builder, "select_user_prompt"));
266  retval->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "ss_ok_button"));
267  label = GTK_WIDGET(gtk_builder_get_object (builder, "item_label"));
268 
269  gnc_cbwe_require_list_item(GTK_COMBO_BOX(retval->namespace_combo));
270  gnc_cbwe_require_list_item(GTK_COMBO_BOX(retval->commodity_combo));
271 
272  gtk_label_set_text (GTK_LABEL (retval->select_user_prompt), "");
273 
274 #ifdef DRH
275  g_signal_connect (G_OBJECT (retval->dialog), "close",
276  G_CALLBACK (select_commodity_close), retval);
277  g_signal_connect (G_OBJECT (retval->dialog), "response",
278  G_CALLBACK (gnc_ui_select_commodity_response_cb), retval);
279 #endif
280 
281  switch (mode)
282  {
283  case DIAG_COMM_ALL:
284  title = _("Select security/currency");
285  text = _("_Security/currency:");
286  break;
288  title = _("Select security");
289  text = _("_Security:");
290  break;
291  case DIAG_COMM_CURRENCY:
292  default:
293  title = _("Select currency");
294  text = _("Cu_rrency:");
295  button = GTK_WIDGET(gtk_builder_get_object (builder, "ss_new_button"));
296  gtk_widget_destroy(button);
297  break;
298  }
299  gtk_window_set_title (GTK_WINDOW(retval->dialog), title);
300  gtk_label_set_text_with_mnemonic (GTK_LABEL(label), text);
301 
302  /* build the menus of namespaces and commodities */
303  gnc_ui_update_namespace_picker(retval->namespace_combo,
304  gnc_commodity_get_namespace(orig_sel),
305  mode);
306  name_space = gnc_ui_namespace_picker_ns(retval->namespace_combo);
307  gnc_ui_update_commodity_picker(retval->commodity_combo, name_space,
308  gnc_commodity_get_printname(orig_sel));
309 
310  g_object_unref(G_OBJECT(builder));
311 
312  g_free(name_space);
313  return retval;
314 }
315 
316 
331 void
333  gpointer user_data)
334 {
335  SelectCommodityWindow * w = user_data;
336 
337  gchar * name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
338 
339  const gnc_commodity * new_commodity =
341  w->dialog,
342  w->default_cusip,
343  w->default_fullname,
344  w->default_mnemonic,
345  w->default_user_symbol,
346  w->default_fraction);
347  if (new_commodity)
348  {
349  gnc_ui_update_namespace_picker(w->namespace_combo,
350  gnc_commodity_get_namespace(new_commodity),
351  DIAG_COMM_ALL);
352  gnc_ui_update_commodity_picker(w->commodity_combo,
353  gnc_commodity_get_namespace(new_commodity),
354  gnc_commodity_get_printname(new_commodity));
355  }
356  g_free(name_space);
357 }
358 
359 
375 void
377  gpointer user_data)
378 {
379  SelectCommodityWindow * w = user_data;
380  gchar *name_space;
381  const gchar *fullname;
382  gboolean ok;
383 
384  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
385  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
386  fullname = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(w->commodity_combo)))));
387 
388  DEBUG("namespace=%s, name=%s", name_space, fullname);
389  w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(),
390  name_space, fullname);
391  g_free(name_space);
392 
393  ok = (w->selection != NULL);
394  gtk_widget_set_sensitive(w->ok_button, ok);
395  gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2);
396  LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 2);
397 }
398 
399 
416 void
418  gpointer user_data)
419 {
420  SelectCommodityWindow * w = user_data;
421  gchar *name_space;
422 
423  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
424  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
425  DEBUG("name_space=%s", name_space);
426  gnc_ui_update_commodity_picker(w->commodity_combo, name_space, NULL);
427  g_free(name_space);
428  LEAVE(" ");
429 }
430 
431 
432 /********************************************************************
433  * gnc_ui_update_commodity_picker
434  ********************************************************************/
435 static int
436 collate(gconstpointer a, gconstpointer b)
437 {
438  if (!a)
439  return -1;
440  if (!b)
441  return 1;
442  return g_utf8_collate(a, b);
443 }
444 
445 
446 void
448  const gchar * name_space,
449  const gchar * init_string)
450 {
451  GList * commodities;
452  GList * iterator = NULL;
453  GList * commodity_items = NULL;
454  GtkComboBox *combo_box;
455  GtkEntry *entry;
456  GtkTreeModel *model;
457  GtkTreeIter iter;
459  gint current = 0, match = 0;
460  gchar *name;
461 
462  g_return_if_fail(GTK_IS_COMBO_BOX(cbwe));
463  g_return_if_fail(name_space);
464 
465  /* Erase the old entries */
466  combo_box = GTK_COMBO_BOX(cbwe);
467  model = gtk_combo_box_get_model(combo_box);
468  gtk_list_store_clear(GTK_LIST_STORE(model));
469 
470  /* Erase the entry text */
471  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
472  gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
473 
474  gtk_combo_box_set_active(combo_box, -1);
475 
476  table = gnc_commodity_table_get_table (gnc_get_current_book ());
477  commodities = gnc_commodity_table_get_commodities(table, name_space);
478  for (iterator = commodities; iterator; iterator = iterator->next)
479  {
480  commodity_items =
481  g_list_append(commodity_items,
482  (gpointer) gnc_commodity_get_printname(iterator->data));
483  }
484  g_list_free(commodities);
485 
486  commodity_items = g_list_sort(commodity_items, collate);
487  for (iterator = commodity_items; iterator; iterator = iterator->next)
488  {
489  name = (char *)iterator->data;
490  gtk_list_store_append(GTK_LIST_STORE(model), &iter);
491  gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1);
492 
493  if (init_string && g_utf8_collate(name, init_string) == 0)
494  match = current;
495  current++;
496  }
497 
498  gtk_combo_box_set_active(combo_box, match);
499  g_list_free(commodity_items);
500 }
501 
502 
503 /********************************************************************
504  * gnc_ui_select_commodity_destroy
505  ********************************************************************/
506 #if 0
507 void
508 gnc_ui_select_commodity_destroy(SelectCommodityWindow * w)
509 {
510  g_return_if_fail (w != NULL);
511 
512  gtk_widget_destroy (GTK_WIDGET (w->dialog));
513 }
514 
515 
516 /********************************************************************
517  * gnc_ui_select_commodity_response_cb
518  ********************************************************************/
519 static void
520 gnc_ui_select_commodity_response_cb (GtkDialog * dialog, gint response, gpointer data)
521 {
522  SelectCommodityWindow * w = data;
523  gchar *namespace;
524  const gchar *fullname;
525  gnc_commodity *commodity = NULL;
526 
527  switch (response)
528  {
529  case GTK_RESPONSE_OK:
530  namespace = gnc_ui_namespace_picker_ns (w->namespace_combo);
531  fullname = gtk_entry_get_text (GTK_ENTRY (w->commodity_entry));
532 
533  commodity = gnc_commodity_table_find_full (gnc_get_current_commodities (),
534  namespace, fullname);
535  g_free(namespace);
536 
537  if (commodity != NULL)
538  {
539  if (w->callback != NULL)
540  (w->callback) (commodity, w->callback_data);
541  gnc_ui_select_commodity_destroy (w);
542  }
543  else
544  {
545  gnc_warning_dialog (dialog,
546  _("You must select a commodity. "
547  "To create a new one, click \"New\""));
548  }
549  break;
550  case GNC_RESPONSE_NEW:
551  namespace = gnc_ui_namespace_picker_ns (w->namespace_combo);
552 
553  commodity = gnc_ui_new_commodity_modal_full (namespace,
554  w->dialog,
555  w->default_cusip,
556  w->default_fullname,
557  w->default_mnemonic,
558  w->default_fraction);
559  if (commodity != NULL)
560  {
561  namespace =
562  gnc_ui_update_namespace_picker (w->namespace_combo,
564  (commodity), TRUE, FALSE);
565  gnc_ui_update_commodity_picker (w->commodity_combo,
566  gnc_commodity_get_namespace (commodity),
567  gnc_commodity_get_printname (commodity));
568  }
569  g_free(namespace);
570  break;
571  default:
572  if (w->callback != NULL)
573  (w->callback) (NULL, w->callback_data);
574 
575  gnc_ui_select_commodity_destroy (w);
576  break;
577  }
578 }
579 #endif
580 
581 
582 /********************************************************************
583  *
584  * Commodity Selector dialog routines are above this line.
585  *
586  * Commodity New/Edit dialog routines are below this line.
587  *
588  ********************************************************************/
589 static void
590 gnc_set_commodity_section_sensitivity (GtkWidget *widget, gpointer user_data)
591 {
592  CommodityWindow *cw = user_data;
593  guint offset = 0;
594 
595  gtk_container_child_get(GTK_CONTAINER(cw->table), widget,
596  "top-attach", &offset,
597  NULL);
598 
599  if ((offset < cw->comm_section_top) || (offset >= cw->comm_section_bottom))
600  return;
601  if (cw->is_currency)
602  gtk_widget_set_sensitive(widget, offset == cw->comm_symbol_line);
603 }
604 
605 static void
606 gnc_ui_update_commodity_info (CommodityWindow *cw)
607 {
608  gtk_container_foreach(GTK_CONTAINER(cw->table),
609  gnc_set_commodity_section_sensitivity, cw);
610 }
611 
612 
613 static void
614 gnc_set_fq_sensitivity (GtkWidget *widget, gpointer user_data)
615 {
616  CommodityWindow *cw = user_data;
617  guint offset = 0;
618 
619  gtk_container_child_get(GTK_CONTAINER(cw->table), widget,
620  "top-attach", &offset,
621  NULL);
622 
623  if ((offset < cw->fq_section_top) || (offset >= cw->fq_section_bottom))
624  return;
625  g_object_set(widget, "sensitive", FALSE, NULL);
626 }
627 
628 
629 static void
630 gnc_ui_update_fq_info (CommodityWindow *cw)
631 {
632  gtk_container_foreach(GTK_CONTAINER(cw->table),
633  gnc_set_fq_sensitivity, cw);
634 }
635 
636 
637 /********************************************************************
638  * gnc_ui_update_namespace_picker
639  ********************************************************************/
640 void
641 gnc_ui_update_namespace_picker (GtkWidget *cbwe,
642  const char * init_string,
644 {
645  GtkComboBox *combo_box;
646  GtkTreeModel *model;
647  GtkTreeIter iter;
648  GList *namespaces, *node;
649  gint current = 0, match = 0;
650 
651  g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
652 
653  /* Erase the old entries */
654  combo_box = GTK_COMBO_BOX(cbwe);
655  model = gtk_combo_box_get_model(combo_box);
656  gtk_list_store_clear(GTK_LIST_STORE(model));
657  gtk_combo_box_set_active(combo_box, -1);
658 
659  /* fetch a list of the namespaces */
660  switch (mode)
661  {
662  case DIAG_COMM_ALL:
663  namespaces =
664  gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
665  break;
666 
668  namespaces =
669  gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
670  node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_CURRENCY, collate);
671  if (node)
672  {
673  namespaces = g_list_remove_link (namespaces, node);
674  g_list_free_1 (node);
675  }
676 
677  if (gnc_commodity_namespace_is_iso (init_string))
678  init_string = NULL;
679  break;
680 
681  case DIAG_COMM_CURRENCY:
682  default:
683  namespaces = g_list_prepend (NULL, GNC_COMMODITY_NS_CURRENCY);
684  break;
685  }
686 
687  /* add them to the combobox */
688  namespaces = g_list_sort(namespaces, collate);
689  for (node = namespaces; node; node = node->next)
690  {
691  if (g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0)
692  continue;
693  /* Hide the template entry */
694  if (g_utf8_collate(node->data, "template" ) != 0)
695  {
696  gtk_list_store_append(GTK_LIST_STORE(model), &iter);
697  gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, node->data, -1);
698  }
699 
700  if (init_string && (g_utf8_collate(node->data, init_string) == 0))
701  match = current;
702  current++;
703  }
704 
705  gtk_combo_box_set_active(combo_box, match);
706  g_list_free(namespaces);
707 }
708 
709 
710 gchar *
711 gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
712 {
713  const gchar *name_space;
714 
715  g_return_val_if_fail(GTK_IS_COMBO_BOX (cbwe), NULL);
716 
717  name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
718 
719  if (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0)
720  {
721  /* In case the user types in ISO4217, map it to CURRENCY. */
722  return g_strdup(GNC_COMMODITY_NS_CURRENCY);
723  }
724  else
725  return g_strdup(name_space);
726 }
727 
728 
729 /********************************************************************
730  * gnc_ui_commodity_quote_info_cb *
731  *******************************************************************/
732 void
733 gnc_ui_commodity_quote_info_cb (GtkWidget *w, gpointer data)
734 {
735  CommodityWindow *cw = data;
736  gboolean get_quote, allow_src, active;
737  const gchar *text;
738  gint i;
739 
740  ENTER(" ");
741  get_quote = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
742 
743  text = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cw->namespace_combo)))));
744 
745  allow_src = !gnc_commodity_namespace_is_iso(text);
746 
747  gtk_widget_set_sensitive(cw->source_label, get_quote && allow_src);
748 
749  for (i = SOURCE_SINGLE; i < SOURCE_MAX; i++)
750  {
751  if (!cw->source_button[i])
752  continue;
753  active =
754  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw->source_button[i]));
755  gtk_widget_set_sensitive(cw->source_button[i], get_quote && allow_src);
756  gtk_widget_set_sensitive(cw->source_menu[i], get_quote && allow_src && active);
757  }
758  gtk_widget_set_sensitive(cw->quote_tz_label, get_quote);
759  gtk_widget_set_sensitive(cw->quote_tz_menu, get_quote);
760  LEAVE(" ");
761 }
762 
763 
764 void
765 gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data)
766 {
767  CommodityWindow * w = user_data;
768  gchar *name_space;
769  const char * fullname;
770  const char * mnemonic;
771  gboolean ok;
772 
773  ENTER("widget=%p, user_data=%p", dummy, user_data);
774  if (!w->is_currency)
775  {
776  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
777  fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
778  mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
779  DEBUG("namespace=%s, name=%s, mnemonic=%s", name_space, fullname, mnemonic);
780  ok = (fullname && name_space && mnemonic &&
781  fullname[0] && name_space[0] && mnemonic[0]);
782  g_free(name_space);
783  }
784  else
785  {
786  ok = TRUE;
787  }
788  gtk_widget_set_sensitive(w->ok_button, ok);
789  gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 1);
790  LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 1);
791 }
792 
793 
794 /********************************************************************\
795  * gnc_ui_source_menu_create *
796  * create the menu of stock quote sources *
797  * *
798  * Args: account - account to use to set default choice *
799  * Returns: the menu *
800  \*******************************************************************/
801 static GtkWidget *
802 gnc_ui_source_menu_create(QuoteSourceType type)
803 {
804  gint i, max;
805  const gchar *name;
806  gboolean supported;
807  GtkListStore *store;
808  GtkTreeIter iter;
809  GtkWidget *combo;
810  GtkCellRenderer *renderer;
811  gnc_quote_source *source;
812 
813  store = gtk_list_store_new(NUM_SOURCE_COLS, G_TYPE_STRING, G_TYPE_BOOLEAN);
814  if (type == SOURCE_CURRENCY)
815  {
816  gtk_list_store_append(store, &iter);
817  gtk_list_store_set(store, &iter,
818  SOURCE_COL_NAME, _("Currency"),
819  SOURCE_COL_FQ_SUPPORTED, TRUE,
820  -1);
821  }
822  else
823  {
824  max = gnc_quote_source_num_entries(type);
825  for (i = 0; i < max; i++)
826  {
827  source = gnc_quote_source_lookup_by_ti(type, i);
828  if (source == NULL)
829  break;
830  name = gnc_quote_source_get_user_name(source);
831  supported = gnc_quote_source_get_supported(source);
832  gtk_list_store_append(store, &iter);
833  gtk_list_store_set(store, &iter,
834  SOURCE_COL_NAME, name,
835  SOURCE_COL_FQ_SUPPORTED, supported,
836  -1);
837  }
838  }
839 
840  combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
841  g_object_unref(store);
842  renderer = gtk_cell_renderer_text_new();
843  gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
844  gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), renderer,
845  "text", SOURCE_COL_NAME);
846  gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), renderer,
847  "sensitive", SOURCE_COL_FQ_SUPPORTED);
848  gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
849  gtk_widget_show(combo);
850  return combo;
851 }
852 
853 
854 /********************************************************************
855  * price quote timezone handling *
856  *******************************************************************/
857 static gchar *
858 known_timezones[] =
859 {
860  "Asia/Tokyo",
861  "Australia/Sydney",
862  "America/New_York",
863  "America/Chicago",
864  "Europe/London",
865  "Europe/Paris",
866  NULL
867 };
868 
869 
870 static guint
871 gnc_find_timezone_menu_position(const gchar *timezone)
872 {
873  /* returns 0 on failure, position otherwise. */
874  gboolean found = FALSE;
875  guint i = 0;
876  while (!found && known_timezones[i])
877  {
878  if (g_strcmp0(timezone, known_timezones[i]) != 0)
879  {
880  i++;
881  }
882  else
883  {
884  found = TRUE;
885  }
886  }
887  if (found) return i + 1;
888  return 0;
889 }
890 
891 
892 static gchar *
893 gnc_timezone_menu_position_to_string(guint pos)
894 {
895  if (pos == 0) return NULL;
896  return known_timezones[pos - 1];
897 }
898 
899 
900 static GtkWidget *
901 gnc_ui_quote_tz_menu_create(void)
902 {
903  GtkWidget *combo;
904  gchar **itemstr;
905 
906  /* add items here as needed, but bear in mind that right now these
907  must be timezones that GNU libc understands. Also, I'd prefer if
908  we only add things here we *know* we need. That's because in
909  order to be portable to non GNU OSes, we may have to support
910  whatever we add here manually on those systems. */
911 
912  combo = gtk_combo_box_text_new();
913  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Use local time"));
914  for (itemstr = &known_timezones[0]; *itemstr; itemstr++)
915  {
916  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), *itemstr);
917  }
918 
919  gtk_widget_show(combo);
920  return combo;
921 }
922 
923 
924 /*******************************************************
925  * Build the new/edit commodity dialog box *
926  *******************************************************/
927 static CommodityWindow *
928 gnc_ui_build_commodity_dialog(const char * selected_namespace,
929  GtkWidget *parent,
930  const char * fullname,
931  const char * mnemonic,
932  const char * user_symbol,
933  const char * cusip,
934  int fraction,
935  gboolean edit)
936 {
937  CommodityWindow * retval = g_new0(CommodityWindow, 1);
938  GtkWidget *help_button;
939  GtkWidget *box;
940  GtkWidget *menu;
941  GtkWidget *widget, *sec_label;
942  GtkBuilder *builder;
943  gboolean include_iso;
944  const gchar *title;
945  gchar *text;
946 
947  ENTER("widget=%p, selected namespace=%s, fullname=%s, mnemonic=%s",
948  parent, selected_namespace, fullname, mnemonic);
949 
950  builder = gtk_builder_new();
951  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "liststore2");
952  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "adjustment1");
953  gnc_builder_add_from_file (builder, "dialog-commodity.glade", "Security Dialog");
954 
955  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, retval);
956 
957  retval->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Security Dialog"));
958  if (parent != NULL)
959  gtk_window_set_transient_for (GTK_WINDOW (retval->dialog), GTK_WINDOW (parent));
960  retval->edit_commodity = NULL;
961 
962  help_button = GTK_WIDGET(gtk_builder_get_object (builder, "help_button"));
963  if (!help_callback)
964  gtk_widget_hide (help_button);
965 
966  /* Get widget pointers */
967  retval->fullname_entry = GTK_WIDGET(gtk_builder_get_object (builder, "fullname_entry"));
968  retval->mnemonic_entry = GTK_WIDGET(gtk_builder_get_object (builder, "mnemonic_entry"));
969  retval->user_symbol_entry = GTK_WIDGET(gtk_builder_get_object (builder, "user_symbol_entry"));
970  retval->namespace_combo = GTK_WIDGET(gtk_builder_get_object (builder, "namespace_cbwe"));
971  retval->code_entry = GTK_WIDGET(gtk_builder_get_object (builder, "code_entry"));
972  retval->fraction_spinbutton = GTK_WIDGET(gtk_builder_get_object (builder, "fraction_spinbutton"));
973  retval->ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "ok_button"));
974  retval->get_quote_check = GTK_WIDGET(gtk_builder_get_object (builder, "get_quote_check"));
975  retval->source_label = GTK_WIDGET(gtk_builder_get_object (builder, "source_label"));
976  retval->source_button[SOURCE_SINGLE] = GTK_WIDGET(gtk_builder_get_object (builder, "single_source_button"));
977  retval->source_button[SOURCE_MULTI] = GTK_WIDGET(gtk_builder_get_object (builder, "multi_source_button"));
978  retval->quote_tz_label = GTK_WIDGET(gtk_builder_get_object (builder, "quote_tz_label"));
979 
980  /* Determine the commodity section of the dialog */
981  retval->table = GTK_WIDGET(gtk_builder_get_object (builder, "edit_table"));
982  sec_label = GTK_WIDGET(gtk_builder_get_object (builder, "security_label"));
983  gtk_container_child_get(GTK_CONTAINER(retval->table), sec_label,
984  "bottom-attach", &retval->comm_section_top, NULL);
985  widget = GTK_WIDGET(gtk_builder_get_object (builder, "quote_label"));
986  gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
987  "top-attach", &retval->comm_section_bottom, NULL);
988  gtk_container_child_get(GTK_CONTAINER(retval->table),
989  retval->user_symbol_entry, "top-attach",
990  &retval->comm_symbol_line, NULL);
991 
992  /* Build custom widgets */
993  box = GTK_WIDGET(gtk_builder_get_object (builder, "single_source_box"));
994  if (gnc_commodity_namespace_is_iso(selected_namespace))
995  {
996  menu = gnc_ui_source_menu_create(SOURCE_CURRENCY);
997  }
998  else
999  {
1000  menu = gnc_ui_source_menu_create(SOURCE_SINGLE);
1001  }
1002  retval->source_menu[SOURCE_SINGLE] = menu;
1003  gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
1004 
1005  box = GTK_WIDGET(gtk_builder_get_object (builder, "multi_source_box"));
1006  menu = gnc_ui_source_menu_create(SOURCE_MULTI);
1007  retval->source_menu[SOURCE_MULTI] = menu;
1008  gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
1009 
1011  {
1012  retval->source_button[SOURCE_UNKNOWN] =
1013  GTK_WIDGET(gtk_builder_get_object (builder, "unknown_source_button"));
1014  box = GTK_WIDGET(gtk_builder_get_object (builder, "unknown_source_box"));
1015  menu = gnc_ui_source_menu_create(SOURCE_UNKNOWN);
1016  retval->source_menu[SOURCE_UNKNOWN] = menu;
1017  gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
1018  }
1019  else
1020  {
1021  guint row;
1022 
1023  widget = GTK_WIDGET(gtk_builder_get_object (builder, "unknown_source_alignment"));
1024  gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
1025  "top-attach", &row, NULL);
1026  gtk_table_set_row_spacing(GTK_TABLE(retval->table), row, 0);
1027  gtk_widget_destroy(widget);
1028  widget = GTK_WIDGET(gtk_builder_get_object (builder, "unknown_source_box"));
1029  gtk_widget_destroy(widget);
1030  }
1031 
1032  box = GTK_WIDGET(gtk_builder_get_object (builder, "quote_tz_box"));
1033  retval->quote_tz_menu = gnc_ui_quote_tz_menu_create();
1034  gtk_box_pack_start(GTK_BOX(box), retval->quote_tz_menu, TRUE, TRUE, 0);
1035 
1036  /* Commodity editing is next to nil */
1037  if (gnc_commodity_namespace_is_iso(selected_namespace))
1038  {
1039  retval->is_currency = TRUE;
1040  gnc_ui_update_commodity_info (retval);
1041  include_iso = TRUE;
1042  title = _("Edit currency");
1043  text = g_strdup_printf("<b>%s</b>", _("Currency Information"));
1044  }
1045  else
1046  {
1047  include_iso = FALSE;
1048  title = edit ? _("Edit security") : _("New security");
1049  text = g_strdup_printf("<b>%s</b>", _("Security Information"));
1050  }
1051  gtk_window_set_title(GTK_WINDOW(retval->dialog), title);
1052  gtk_label_set_markup(GTK_LABEL(sec_label), text);
1053  g_free(text);
1054 
1055  /* Are price quotes supported */
1057  {
1058  gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder, "finance_quote_warning")));
1059  }
1060  else
1061  {
1062  /* Determine the price quote of the dialog */
1063  widget = GTK_WIDGET(gtk_builder_get_object (builder, "fq_warning_alignment"));
1064  gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
1065  "bottom-attach", &retval->fq_section_top, NULL);
1066  widget = GTK_WIDGET(gtk_builder_get_object (builder, "quote_tz_alignment"));
1067  gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
1068  "bottom-attach", &retval->fq_section_bottom, NULL);
1069  gnc_ui_update_fq_info (retval);
1070  }
1071 
1072 #ifdef DRH
1073  g_signal_connect (G_OBJECT (retval->dialog), "close",
1074  G_CALLBACK (commodity_close), retval);
1075 #endif
1076  /* Fill in any data, top to bottom */
1077  gtk_entry_set_text (GTK_ENTRY (retval->fullname_entry), fullname ? fullname : "");
1078  gtk_entry_set_text (GTK_ENTRY (retval->mnemonic_entry), mnemonic ? mnemonic : "");
1079  gtk_entry_set_text (GTK_ENTRY (retval->user_symbol_entry), user_symbol ? user_symbol : "");
1080  gnc_cbwe_add_completion(GTK_COMBO_BOX(retval->namespace_combo));
1081  gnc_ui_update_namespace_picker(retval->namespace_combo,
1082  selected_namespace,
1083  include_iso ? DIAG_COMM_ALL : DIAG_COMM_NON_CURRENCY);
1084  gtk_entry_set_text (GTK_ENTRY (retval->code_entry), cusip ? cusip : "");
1085 
1086  if (fraction > 0)
1087  gtk_spin_button_set_value (GTK_SPIN_BUTTON (retval->fraction_spinbutton),
1088  fraction);
1089 
1090  g_object_unref(G_OBJECT(builder));
1091 
1092  LEAVE(" ");
1093  return retval;
1094 }
1095 
1096 
1097 static void
1098 gnc_ui_commodity_update_quote_info(CommodityWindow *win,
1099  gnc_commodity *commodity)
1100 {
1101  gnc_quote_source *source;
1102  QuoteSourceType type;
1103  gboolean has_quote_src;
1104  const char *quote_tz;
1105  int pos = 0;
1106 
1107  ENTER(" ");
1108  has_quote_src = gnc_commodity_get_quote_flag (commodity);
1109  source = gnc_commodity_get_quote_source (commodity);
1110  if (source == NULL)
1111  source = gnc_commodity_get_default_quote_source (commodity);
1112  quote_tz = gnc_commodity_get_quote_tz (commodity);
1113 
1114  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (win->get_quote_check),
1115  has_quote_src);
1116  if (!gnc_commodity_is_iso(commodity))
1117  {
1118  type = gnc_quote_source_get_type(source);
1119  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(win->source_button[type]), TRUE);
1120  gtk_combo_box_set_active(GTK_COMBO_BOX(win->source_menu[type]),
1121  gnc_quote_source_get_index(source));
1122  }
1123 
1124  if (quote_tz)
1125  {
1126  pos = gnc_find_timezone_menu_position(quote_tz);
1127 // if(pos == 0) {
1128 // PWARN("Unknown price quote timezone (%s), resetting to default.",
1129 // quote_tz ? quote_tz : "(null)");
1130 // }
1131  }
1132  gtk_combo_box_set_active(GTK_COMBO_BOX(win->quote_tz_menu), pos);
1133  LEAVE(" ");
1134 }
1135 
1136 
1137 static gnc_commodity *
1138 gnc_ui_common_commodity_modal(gnc_commodity *commodity,
1139  GtkWidget * parent,
1140  const char * name_space,
1141  const char * cusip,
1142  const char * fullname,
1143  const char * mnemonic,
1144  const char * user_symbol,
1145  int fraction)
1146 {
1147  CommodityWindow * win;
1148  gnc_commodity *retval = NULL;
1149  gboolean done;
1150  gint value;
1151 
1152  ENTER(" ");
1153 
1154  /* If a commodity was provided, copy out the existing info */
1155  if (commodity)
1156  {
1157  name_space = gnc_commodity_get_namespace (commodity);
1158  fullname = gnc_commodity_get_fullname (commodity);
1159  mnemonic = gnc_commodity_get_mnemonic (commodity);
1160  user_symbol = gnc_commodity_get_nice_symbol (commodity);
1161  cusip = gnc_commodity_get_cusip (commodity);
1162  fraction = gnc_commodity_get_fraction (commodity);
1163  }
1164  else
1165  {
1166  /* Not allowed to create new currencies */
1167  if (gnc_commodity_namespace_is_iso(name_space))
1168  {
1169  name_space = NULL;
1170  }
1171  }
1172 
1173  win = gnc_ui_build_commodity_dialog(name_space, parent, fullname,
1174  mnemonic, user_symbol, cusip,
1175  fraction, (commodity != NULL));
1176 
1177  /* Update stock quote info based on existing commodity */
1178  gnc_ui_commodity_update_quote_info(win, commodity);
1179  win->edit_commodity = commodity;
1180 
1181  /* Update stock quote sensitivities based on check box */
1182  gnc_ui_commodity_quote_info_cb(win->get_quote_check, win);
1183 
1184  /* Run the dialog, handling the terminal conditions. */
1185  done = FALSE;
1186  while (!done)
1187  {
1188  value = gtk_dialog_run(GTK_DIALOG(win->dialog));
1189  switch (value)
1190  {
1191  case GTK_RESPONSE_OK:
1192  DEBUG("case OK");
1193  done = gnc_ui_commodity_dialog_to_object(win);
1194  retval = win->edit_commodity;
1195  break;
1196  case GTK_RESPONSE_HELP:
1197  DEBUG("case HELP");
1198  if (help_callback)
1199  help_callback ();
1200  break;
1201  default: /* Cancel, Escape, Close, etc. */
1202  DEBUG("default: %d", value);
1203  retval = NULL;
1204  done = TRUE;
1205  break;
1206  }
1207  }
1208  gtk_widget_destroy (GTK_WIDGET (win->dialog)); /* Close and destroy */
1209  g_free(win);
1210 
1211  LEAVE(" ");
1212  return retval;
1213 }
1214 
1215 
1216 /********************************************************
1217  * Create and run the new/edit commodity dialog. *
1218  ********************************************************/
1219 gnc_commodity *
1220 gnc_ui_new_commodity_modal_full(const char * name_space,
1221  GtkWidget * parent,
1222  const char * cusip,
1223  const char * fullname,
1224  const char * mnemonic,
1225  const char * user_symbol,
1226  int fraction)
1227 {
1228  gnc_commodity *result;
1229 
1230  ENTER(" ");
1231  result = gnc_ui_common_commodity_modal(NULL, parent, name_space, cusip,
1232  fullname, mnemonic, user_symbol,
1233  10000);
1234  LEAVE(" ");
1235  return result;
1236 }
1237 
1238 
1239 /********************************************************************
1240  * External routine for popping up the new commodity dialog box. *
1241  ********************************************************************/
1242 gnc_commodity *
1243 gnc_ui_new_commodity_modal(const char * default_namespace,
1244  GtkWidget * parent)
1245 {
1246  gnc_commodity *result;
1247 
1248  ENTER(" ");
1249  result = gnc_ui_common_commodity_modal(NULL, parent, default_namespace, NULL,
1250  NULL, NULL, NULL, 0);
1251  LEAVE(" ");
1252  return result;
1253 }
1254 
1255 
1256 /********************************************************************
1257  * gnc_ui_edit_commodity_modal()
1258  ********************************************************************/
1264 gboolean
1266  GtkWidget * parent)
1267 {
1268  gnc_commodity *result;
1269 
1270  ENTER(" ");
1271  result = gnc_ui_common_commodity_modal(commodity, parent, NULL, NULL,
1272  NULL, NULL, NULL, 0);
1273  LEAVE(" ");
1274  return result != NULL;
1275 }
1276 
1277 
1278 /********************************************************************
1279  * gnc_ui_commodity_dialog_to_object()
1280  ********************************************************************/
1281 gboolean
1282 gnc_ui_commodity_dialog_to_object(CommodityWindow * w)
1283 {
1284  gnc_quote_source *source;
1285  QuoteSourceType type;
1286  const char * fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
1287  gchar *name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
1288  const char * mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
1289  const char * user_symbol = gtk_entry_get_text(GTK_ENTRY(w->user_symbol_entry));
1290  const char * code = gtk_entry_get_text(GTK_ENTRY(w->code_entry));
1291  QofBook * book = gnc_get_current_book ();
1292  int fraction = gtk_spin_button_get_value_as_int
1293  (GTK_SPIN_BUTTON(w->fraction_spinbutton));
1294  const char *string;
1295  gnc_commodity * c;
1296  gint selection;
1297 
1298  ENTER(" ");
1299  /* Special case currencies */
1300  if (gnc_commodity_namespace_is_iso (name_space))
1301  {
1302  if (w->edit_commodity)
1303  {
1304  gboolean quote_set;
1305  quote_set = gtk_toggle_button_get_active
1306  (GTK_TOGGLE_BUTTON (w->get_quote_check));
1307  c = w->edit_commodity;
1308  gnc_commodity_begin_edit(c);
1309  gnc_commodity_user_set_quote_flag (c, quote_set);
1310  if (quote_set)
1311  {
1312  selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1313  string = gnc_timezone_menu_position_to_string(selection);
1314  gnc_commodity_set_quote_tz(c, string);
1315  }
1316  else
1317  gnc_commodity_set_quote_tz(c, NULL);
1318 
1319  gnc_commodity_set_user_symbol(c, user_symbol);
1320 
1321  gnc_commodity_commit_edit(c);
1322  return TRUE;
1323  }
1324  gnc_warning_dialog(w->dialog, "%s",
1325  _("You may not create a new national currency."));
1326  return FALSE;
1327  }
1328 
1329  /* Don't allow user to create commodities in namespace
1330  * "template". That's reserved for scheduled transaction use.
1331  */
1332  if (g_utf8_collate(name_space, "template") == 0)
1333  {
1334  gnc_warning_dialog (w->dialog,
1335  _("%s is a reserved commodity type."
1336  " Please use something else."), "template");
1337  return FALSE;
1338  }
1339 
1340  if (fullname && fullname[0] &&
1341  name_space && name_space[0] &&
1342  mnemonic && mnemonic[0])
1343  {
1344  c = gnc_commodity_table_lookup (gnc_get_current_commodities(),
1345  name_space, mnemonic);
1346 
1347  if ((!w->edit_commodity && c) ||
1348  (w->edit_commodity && c && (c != w->edit_commodity)))
1349  {
1350  gnc_warning_dialog (w->dialog, "%s", _("That commodity already exists."));
1351  g_free(name_space);
1352  return FALSE;
1353  }
1354 
1355  if (!w->edit_commodity)
1356  {
1357  c = gnc_commodity_new(book, fullname, name_space, mnemonic, code, fraction);
1358  w->edit_commodity = c;
1359  gnc_commodity_begin_edit(c);
1360  }
1361  else
1362  {
1363  c = w->edit_commodity;
1364  gnc_commodity_begin_edit(c);
1365 
1366  gnc_commodity_table_remove (gnc_get_current_commodities(), c);
1367 
1368  gnc_commodity_set_fullname (c, fullname);
1369  gnc_commodity_set_mnemonic (c, mnemonic);
1370  gnc_commodity_set_namespace (c, name_space);
1371  gnc_commodity_set_cusip (c, code);
1372  gnc_commodity_set_fraction (c, fraction);
1373  }
1374 
1375  gnc_commodity_user_set_quote_flag (c, gtk_toggle_button_get_active
1376  (GTK_TOGGLE_BUTTON (w->get_quote_check)));
1377 
1378  for (type = SOURCE_SINGLE; type < SOURCE_MAX; type=type+1)
1379  {
1380  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w->source_button[type])))
1381  break;
1382  }
1383  selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->source_menu[type]));
1384  source = gnc_quote_source_lookup_by_ti (type, selection);
1385  gnc_commodity_set_quote_source(c, source);
1386 
1387  selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1388  string = gnc_timezone_menu_position_to_string(selection);
1389  gnc_commodity_set_quote_tz(c, string);
1390  gnc_commodity_commit_edit(c);
1391 
1392  /* remember the commodity */
1393  c = gnc_commodity_table_insert(gnc_get_current_commodities(), c);
1394  }
1395  else
1396  {
1397  gnc_warning_dialog(w->dialog, "%s",
1398  _("You must enter a non-empty \"Full name\", "
1399  "\"Symbol/abbreviation\", "
1400  "and \"Type\" for the commodity."));
1401  g_free(name_space);
1402  return FALSE;
1403  }
1404  g_free(name_space);
1405  LEAVE(" ");
1406  return TRUE;
1407 }
1408 
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
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)
const char * gnc_quote_source_get_user_name(const gnc_quote_source *source)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
utility functions for the GnuCash UI
gtk helper routines.
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
void gnc_ui_commodity_set_help_callback(gnc_commodity_help_callback cb)
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
gnc_commodity * gnc_ui_new_commodity_modal(const char *default_namespace, GtkWidget *parent)
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
#define DEBUG(format, args...)
Definition: qoflog.h:255
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
gboolean gnc_quote_source_get_supported(const gnc_quote_source *source)
gboolean gnc_ui_edit_commodity_modal(gnc_commodity *commodity, GtkWidget *parent)
QuoteSourceType gnc_quote_source_get_type(const gnc_quote_source *source)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
gnc_commodity * gnc_ui_new_commodity_modal_full(const char *name_space, GtkWidget *parent, const char *cusip, const char *fullname, const char *mnemonic, const char *user_symbol, int fraction)
QuoteSourceType
gnc_quote_source * gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint index)
#define ENTER(format, args...)
Definition: qoflog.h:261
void gnc_commodity_user_set_quote_flag(gnc_commodity *cm, const gboolean flag)
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
gint gnc_quote_source_num_entries(QuoteSourceType type)
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
void gnc_ui_select_commodity_new_cb(GtkButton *button, gpointer user_data)
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
gnc_commodity * gnc_ui_select_commodity_modal_full(gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode, const char *user_message, const char *cusip, const char *fullname, const char *mnemonic)
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
dialog_commodity_mode
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
#define GNC_COMMODITY_NS_LEGACY
Definition: gnc-commodity.h:97
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
void gnc_ui_select_commodity_changed_cb(GtkComboBox *cbwe, gpointer user_data)
gnc_commodity * gnc_ui_select_commodity_modal(gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode)
void gnc_ui_select_commodity_namespace_changed_cb(GtkComboBox *cbwe, gpointer user_data)
All type declarations for the whole Gnucash engine.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
gint gnc_quote_source_get_index(const gnc_quote_source *source)
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
void gnc_ui_update_namespace_picker(GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
"select" and "new" commodity windows
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
gboolean gnc_quote_source_fq_installed(void)
const gchar * QofLogModule
Definition: qofid.h:89