40 #include <glib/gi18n.h> 44 #include "dialog-utils.h" 47 #include "gnc-gui-query.h" 52 static QofLogModule log_module = GNC_MOD_GUI;
57 SOURCE_COL_FQ_SUPPORTED,
64 GtkWidget * namespace_combo;
65 GtkWidget * commodity_combo;
66 GtkWidget * select_user_prompt;
67 GtkWidget * ok_button;
69 gnc_commodity * selection;
71 const char * default_cusip;
72 const char * default_fullname;
73 const char * default_mnemonic;
74 const char * default_user_symbol;
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;
96 guint comm_section_top;
97 guint comm_section_bottom;
98 guint comm_symbol_line;
100 guint fq_section_bottom;
102 gboolean is_currency;
103 gnc_commodity *edit_commodity;
110 static SelectCommodityWindow *
111 gnc_ui_select_commodity_create(
const gnc_commodity * orig_sel,
122 void gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data);
123 void gnc_ui_commodity_quote_info_cb(GtkWidget *w, gpointer data);
125 gboolean gnc_ui_commodity_dialog_to_object(CommodityWindow * w);
128 static void gnc_ui_select_commodity_response_cb (GtkDialog * dialog, gint response, gpointer data);
138 const char * user_message,
140 const char * fullname,
141 const char * mnemonic)
143 gnc_commodity * retval =
nullptr;
144 const gchar *initial;
145 gchar *user_prompt_text;
146 SelectCommodityWindow * win;
150 win = gnc_ui_select_commodity_create(orig_sel, mode);
151 win->default_cusip = cusip;
152 win->default_fullname = fullname;
153 win->default_mnemonic = mnemonic;
154 win->default_user_symbol =
"";
157 gtk_window_set_transient_for (GTK_WINDOW (win->dialog), GTK_WINDOW (parent));
159 if (user_message !=
nullptr)
160 initial = user_message;
161 else if ((cusip !=
nullptr) || (fullname !=
nullptr) || (mnemonic !=
nullptr))
162 initial = _(
"\nPlease select a commodity to match");
167 g_strdup_printf(
"%s%s%s%s%s%s%s",
169 fullname ? _(
"\nCommodity: ") :
"",
170 fullname ? fullname :
"",
176 cusip ? _(
"\nExchange code (ISIN, CUSIP or similar): ") :
"",
178 mnemonic ? _(
"\nMnemonic (Ticker symbol or similar): ") :
"",
179 mnemonic ? mnemonic :
"");
180 gtk_label_set_text ((GtkLabel *)(win->select_user_prompt),
182 g_free(user_prompt_text);
188 switch (value = gtk_dialog_run(GTK_DIALOG(win->dialog)))
190 case GTK_RESPONSE_OK:
192 retval = win->selection;
195 case GNC_RESPONSE_NEW:
200 DEBUG(
"default: %d", value);
206 gtk_widget_destroy (GTK_WIDGET (win->dialog));
234 static SelectCommodityWindow *
235 gnc_ui_select_commodity_create(
const gnc_commodity * orig_sel,
238 SelectCommodityWindow * retval = g_new0(SelectCommodityWindow, 1);
240 const char *title, *text;
242 GtkWidget *button, *label;
244 builder = gtk_builder_new();
245 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"liststore1");
246 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"liststore2");
247 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"security_selector_dialog");
249 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, retval);
251 retval->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"security_selector_dialog"));
252 retval->namespace_combo = GTK_WIDGET(gtk_builder_get_object (builder,
"ss_namespace_cbwe"));
253 retval->commodity_combo = GTK_WIDGET(gtk_builder_get_object (builder,
"ss_commodity_cbwe"));
254 retval->select_user_prompt = GTK_WIDGET(gtk_builder_get_object (builder,
"select_user_prompt"));
255 retval->ok_button = GTK_WIDGET(gtk_builder_get_object (builder,
"ss_ok_button"));
256 label = GTK_WIDGET(gtk_builder_get_object (builder,
"item_label"));
259 gtk_widget_set_name (GTK_WIDGET(retval->dialog),
"gnc-id-security-select");
260 gnc_widget_style_context_add_class (GTK_WIDGET(retval->dialog),
"gnc-class-securities");
262 gnc_cbwe_require_list_item(GTK_COMBO_BOX(retval->namespace_combo));
263 gnc_cbwe_require_list_item(GTK_COMBO_BOX(retval->commodity_combo));
265 gtk_label_set_text (GTK_LABEL (retval->select_user_prompt),
"");
268 g_signal_connect (G_OBJECT (retval->dialog),
"close",
269 G_CALLBACK (select_commodity_close), retval);
270 g_signal_connect (G_OBJECT (retval->dialog),
"response",
271 G_CALLBACK (gnc_ui_select_commodity_response_cb), retval);
277 title = _(
"Select security/currency");
278 text = _(
"_Security/currency");
282 title = _(
"Select security");
283 text = _(
"_Security");
287 title = _(
"Select currency");
288 text = _(
"Cu_rrency");
289 button = GTK_WIDGET(gtk_builder_get_object (builder,
"ss_new_button"));
290 gtk_widget_destroy(button);
293 gtk_window_set_title (GTK_WINDOW(retval->dialog), title);
294 gtk_label_set_text_with_mnemonic (GTK_LABEL(label), text);
304 g_object_unref(G_OBJECT(builder));
329 auto w =
static_cast<SelectCommodityWindow*
>(user_data);
333 const gnc_commodity * new_commodity =
339 w->default_user_symbol,
340 w->default_fraction);
373 auto w =
static_cast<SelectCommodityWindow*
>(user_data);
375 const gchar *fullname;
378 ENTER(
"cbwe=%p, user_data=%p", cbwe, user_data);
380 fullname = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(w->commodity_combo)))));
382 DEBUG(
"namespace=%s, name=%s", name_space, fullname);
383 w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(),
384 name_space, fullname);
387 ok = (w->selection !=
nullptr);
388 gtk_widget_set_sensitive(w->ok_button, ok);
389 gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2);
390 LEAVE(
"sensitive=%d, default = %d", ok, ok ? 0 : 2);
414 auto w =
static_cast<SelectCommodityWindow*
>(user_data);
417 ENTER(
"cbwe=%p, user_data=%p", cbwe, user_data);
419 DEBUG(
"name_space=%s", name_space);
430 collate(gconstpointer a, gconstpointer b)
436 return g_utf8_collate (static_cast<const char*>(a), static_cast<const char*>(b));
442 const gchar * name_space,
443 const gchar * init_string)
446 GList * iterator =
nullptr;
447 GList * commodity_items =
nullptr;
448 GtkComboBox *combo_box;
452 gnc_commodity_table *
table;
453 gint current = 0, match = 0;
456 g_return_if_fail(GTK_IS_COMBO_BOX(cbwe));
457 g_return_if_fail(name_space);
460 combo_box = GTK_COMBO_BOX(cbwe);
461 model = gtk_combo_box_get_model(combo_box);
462 gtk_list_store_clear(GTK_LIST_STORE(model));
465 entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
466 gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
468 gtk_combo_box_set_active(combo_box, -1);
472 for (iterator = commodities; iterator; iterator = iterator->next)
475 g_list_prepend (commodity_items,
478 g_list_free(commodities);
480 commodity_items = g_list_sort(commodity_items, collate);
481 for (iterator = commodity_items; iterator; iterator = iterator->next)
483 name = (
char *)iterator->data;
484 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
485 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1);
487 if (init_string && g_utf8_collate(name, init_string) == 0)
492 gtk_combo_box_set_active(combo_box, match);
493 g_list_free(commodity_items);
505 gnc_set_commodity_section_sensitivity (GtkWidget *widget, gpointer user_data)
507 auto cw =
static_cast<CommodityWindow*
>(user_data);
510 gtk_container_child_get(GTK_CONTAINER(cw->table), widget,
511 "top-attach", &offset,
514 if ((offset < cw->comm_section_top) || (offset >= cw->comm_section_bottom))
517 gtk_widget_set_sensitive(widget, offset == cw->comm_symbol_line);
521 gnc_ui_update_commodity_info (CommodityWindow *cw)
523 gtk_container_foreach(GTK_CONTAINER(cw->table),
524 gnc_set_commodity_section_sensitivity, cw);
529 gnc_set_fq_sensitivity (GtkWidget *widget, gpointer user_data)
531 auto cw =
static_cast<CommodityWindow*
>(user_data);
534 gtk_container_child_get(GTK_CONTAINER(cw->table), widget,
535 "top-attach", &offset,
538 if ((offset < cw->fq_section_top) || (offset >= cw->fq_section_bottom))
540 g_object_set(widget,
"sensitive", FALSE,
nullptr);
545 gnc_ui_update_fq_info (CommodityWindow *cw)
547 gtk_container_foreach(GTK_CONTAINER(cw->table),
548 gnc_set_fq_sensitivity, cw);
557 const char * init_string,
560 GtkComboBox *combo_box;
562 GtkTreeIter iter, match;
563 GList *namespaces, *node;
564 gboolean matched = FALSE;
566 g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
569 combo_box = GTK_COMBO_BOX(cbwe);
570 model = gtk_combo_box_get_model(combo_box);
571 gtk_list_store_clear(GTK_LIST_STORE(model));
585 node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_CURRENCY, collate);
588 namespaces = g_list_remove_link (namespaces, node);
589 g_list_free_1 (node);
593 init_string =
nullptr;
598 namespaces = g_list_prepend (
nullptr, (gpointer)GNC_COMMODITY_NS_CURRENCY);
605 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
606 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
607 _(GNC_COMMODITY_NS_ISO_GUI), -1);
610 (g_utf8_collate(GNC_COMMODITY_NS_ISO_GUI, init_string) == 0))
620 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
621 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
622 GNC_COMMODITY_NS_NONISO_GUI, -1);
626 namespaces = g_list_sort(namespaces, collate);
627 for (node = namespaces; node; node = node->next)
629 auto ns =
static_cast<const char*
>(node->data);
633 (g_utf8_collate(ns, GNC_COMMODITY_NS_TEMPLATE ) == 0) ||
634 (g_utf8_collate(ns, GNC_COMMODITY_NS_CURRENCY ) == 0))
637 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
638 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, ns, -1);
641 (g_utf8_collate(ns, init_string) == 0))
649 matched = gtk_tree_model_get_iter_first (model, &match);
652 gtk_combo_box_set_active_iter (combo_box, &match);
653 g_list_free(namespaces);
660 const gchar *name_space;
662 g_return_val_if_fail(GTK_IS_COMBO_BOX (cbwe),
nullptr);
664 name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
667 if ((g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0) ||
668 (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
669 (g_strcmp0 (name_space, _(GNC_COMMODITY_NS_ISO_GUI)) == 0))
670 return g_strdup(GNC_COMMODITY_NS_CURRENCY);
672 return g_strdup(name_space);
680 gnc_ui_commodity_quote_info_cb (GtkWidget *w, gpointer data)
682 auto cw =
static_cast<CommodityWindow*
>(data);
683 gboolean get_quote, allow_src, active;
688 get_quote = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
690 text = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cw->namespace_combo)))));
694 gtk_widget_set_sensitive(cw->source_label, get_quote && allow_src);
698 if (!cw->source_button[i])
701 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw->source_button[i]));
702 gtk_widget_set_sensitive(cw->source_button[i], get_quote && allow_src);
703 gtk_widget_set_sensitive(cw->source_menu[i], get_quote && allow_src && active);
705 gtk_widget_set_sensitive(cw->quote_tz_label, get_quote);
706 gtk_widget_set_sensitive(cw->quote_tz_menu, get_quote);
712 gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data)
714 auto w =
static_cast<CommodityWindow*
>(user_data);
716 const char * fullname;
717 const char * mnemonic;
720 ENTER(
"widget=%p, user_data=%p", dummy, user_data);
724 fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
725 mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
726 DEBUG(
"namespace=%s, name=%s, mnemonic=%s", name_space, fullname, mnemonic);
727 ok = (fullname && name_space && mnemonic &&
728 fullname[0] && name_space[0] && mnemonic[0]);
735 gtk_widget_set_sensitive(w->ok_button, ok);
736 gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 1);
737 LEAVE(
"sensitive=%d, default = %d", ok, ok ? 0 : 1);
757 GtkCellRenderer *renderer;
758 gnc_quote_source *source;
760 store = gtk_list_store_new(NUM_SOURCE_COLS, G_TYPE_STRING, G_TYPE_BOOLEAN);
763 gtk_list_store_append(store, &iter);
764 gtk_list_store_set(store, &iter,
765 SOURCE_COL_NAME, _(
"Currency"),
766 SOURCE_COL_FQ_SUPPORTED, TRUE,
772 for (i = 0; i < max; i++)
775 if (source ==
nullptr)
779 gtk_list_store_append(store, &iter);
780 gtk_list_store_set(store, &iter,
781 SOURCE_COL_NAME, g_dpgettext2(NULL,
"FQ Source", name),
782 SOURCE_COL_FQ_SUPPORTED, supported,
787 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
788 g_object_unref(store);
789 renderer = gtk_cell_renderer_text_new();
790 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
791 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), renderer,
792 "text", SOURCE_COL_NAME);
793 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(combo), renderer,
794 "sensitive", SOURCE_COL_FQ_SUPPORTED);
795 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
796 gtk_widget_show(combo);
818 gnc_find_timezone_menu_position(
const gchar *timezone)
821 gboolean found = FALSE;
823 while (!found && known_timezones[i])
825 if (g_strcmp0(timezone, known_timezones[i]) != 0)
834 if (found)
return i + 1;
840 gnc_timezone_menu_position_to_string(guint pos)
842 if (pos == 0)
return nullptr;
843 return known_timezones[pos - 1];
848 gnc_ui_quote_tz_menu_create(
void)
851 const gchar **itemstr;
859 combo = gtk_combo_box_text_new();
860 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _(
"Use local time"));
861 for (itemstr = &known_timezones[0]; *itemstr; itemstr++)
863 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), *itemstr);
866 gtk_widget_show(combo);
874 static CommodityWindow *
875 gnc_ui_build_commodity_dialog(
const char * selected_namespace,
877 const char * fullname,
878 const char * mnemonic,
879 const char * user_symbol,
884 CommodityWindow * retval = g_new0(CommodityWindow, 1);
887 GtkWidget *widget, *sec_label;
889 gboolean include_iso;
893 ENTER(
"widget=%p, selected namespace=%s, fullname=%s, mnemonic=%s",
894 parent, selected_namespace, fullname, mnemonic);
896 builder = gtk_builder_new();
897 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"liststore2");
898 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"adjustment1");
899 gnc_builder_add_from_file (builder,
"dialog-commodity.glade",
"security_dialog");
901 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, retval);
903 retval->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"security_dialog"));
906 gtk_widget_set_name (GTK_WIDGET(retval->dialog),
"gnc-id-security");
907 gnc_widget_style_context_add_class (GTK_WIDGET(retval->dialog),
"gnc-class-securities");
909 if (parent !=
nullptr)
910 gtk_window_set_transient_for (GTK_WINDOW (retval->dialog), GTK_WINDOW (parent));
912 retval->edit_commodity =
nullptr;
915 retval->fullname_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"fullname_entry"));
916 retval->mnemonic_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"mnemonic_entry"));
917 retval->user_symbol_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"user_symbol_entry"));
918 retval->namespace_combo = GTK_WIDGET(gtk_builder_get_object (builder,
"namespace_cbwe"));
919 retval->code_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"code_entry"));
920 retval->fraction_spinbutton = GTK_WIDGET(gtk_builder_get_object (builder,
"fraction_spinbutton"));
921 retval->ok_button = GTK_WIDGET(gtk_builder_get_object (builder,
"ok_button"));
922 retval->get_quote_check = GTK_WIDGET(gtk_builder_get_object (builder,
"get_quote_check"));
923 retval->source_label = GTK_WIDGET(gtk_builder_get_object (builder,
"source_label"));
924 retval->source_button[
SOURCE_SINGLE] = GTK_WIDGET(gtk_builder_get_object (builder,
"single_source_button"));
925 retval->source_button[
SOURCE_MULTI] = GTK_WIDGET(gtk_builder_get_object (builder,
"multi_source_button"));
926 retval->quote_tz_label = GTK_WIDGET(gtk_builder_get_object (builder,
"quote_tz_label"));
929 retval->table = GTK_WIDGET(gtk_builder_get_object (builder,
"edit_table"));
930 sec_label = GTK_WIDGET(gtk_builder_get_object (builder,
"security_label"));
931 gtk_container_child_get(GTK_CONTAINER(retval->table), sec_label,
932 "top-attach", &retval->comm_section_top,
nullptr);
934 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"quote_label"));
935 gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
936 "top-attach", &retval->comm_section_bottom,
nullptr);
938 gtk_container_child_get(GTK_CONTAINER(retval->table),
939 retval->user_symbol_entry,
"top-attach",
940 &retval->comm_symbol_line,
nullptr);
943 box = GTK_WIDGET(gtk_builder_get_object (builder,
"single_source_box"));
953 gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
955 box = GTK_WIDGET(gtk_builder_get_object (builder,
"multi_source_box"));
958 gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
963 GTK_WIDGET(gtk_builder_get_object (builder,
"unknown_source_button"));
964 box = GTK_WIDGET(gtk_builder_get_object (builder,
"unknown_source_box"));
967 gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
971 gtk_grid_set_row_spacing(GTK_GRID(retval->table), 0);
973 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"unknown_source_alignment"));
974 gtk_widget_destroy(widget);
976 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"unknown_source_box"));
977 gtk_widget_destroy(widget);
980 box = GTK_WIDGET(gtk_builder_get_object (builder,
"quote_tz_box"));
981 retval->quote_tz_menu = gnc_ui_quote_tz_menu_create();
982 gtk_box_pack_start(GTK_BOX(box), retval->quote_tz_menu, TRUE, TRUE, 0);
987 retval->is_currency = TRUE;
988 gnc_ui_update_commodity_info (retval);
990 title = _(
"Edit currency");
991 text = g_strdup_printf(
"<b>%s</b>", _(
"Currency Information"));
996 title = edit ? _(
"Edit security") : _(
"New security");
997 text = g_strdup_printf(
"<b>%s</b>", _(
"Security Information"));
999 gtk_window_set_title(GTK_WINDOW(retval->dialog), title);
1000 gtk_label_set_markup(GTK_LABEL(sec_label), text);
1006 gtk_widget_destroy(GTK_WIDGET(gtk_builder_get_object (builder,
"finance_quote_warning")));
1011 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"fq_warning_alignment"));
1012 gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
1013 "top-attach", &retval->fq_section_top,
nullptr);
1015 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"bottom_alignment"));
1016 gtk_container_child_get(GTK_CONTAINER(retval->table), widget,
1017 "top-attach", &retval->fq_section_bottom,
nullptr);
1019 gnc_ui_update_fq_info (retval);
1023 g_signal_connect (G_OBJECT (retval->dialog),
"close",
1024 G_CALLBACK (commodity_close), retval);
1027 gtk_entry_set_text (GTK_ENTRY (retval->fullname_entry), fullname ? fullname :
"");
1028 gtk_entry_set_text (GTK_ENTRY (retval->mnemonic_entry), mnemonic ? mnemonic :
"");
1029 gtk_entry_set_text (GTK_ENTRY (retval->user_symbol_entry), user_symbol ? user_symbol :
"");
1030 gnc_cbwe_add_completion(GTK_COMBO_BOX(retval->namespace_combo));
1034 gtk_entry_set_text (GTK_ENTRY (retval->code_entry), cusip ? cusip :
"");
1037 gtk_spin_button_set_value (GTK_SPIN_BUTTON (retval->fraction_spinbutton),
1040 g_object_unref(G_OBJECT(builder));
1048 gnc_ui_commodity_update_quote_info(CommodityWindow *win,
1049 gnc_commodity *commodity)
1051 gnc_quote_source *source;
1053 gboolean has_quote_src;
1054 const char *quote_tz;
1060 if (source ==
nullptr)
1061 source = gnc_commodity_get_default_quote_source (commodity);
1064 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (win->get_quote_check),
1069 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(win->source_button[type]), TRUE);
1070 gtk_combo_box_set_active(GTK_COMBO_BOX(win->source_menu[type]),
1076 pos = gnc_find_timezone_menu_position(quote_tz);
1082 gtk_combo_box_set_active(GTK_COMBO_BOX(win->quote_tz_menu), pos);
1087 static gnc_commodity *
1088 gnc_ui_common_commodity_modal(gnc_commodity *commodity,
1090 const char * name_space,
1092 const char * fullname,
1093 const char * mnemonic,
1094 const char * user_symbol,
1097 CommodityWindow * win;
1098 gnc_commodity *retval =
nullptr;
1119 name_space =
nullptr;
1123 win = gnc_ui_build_commodity_dialog(name_space, parent, fullname,
1124 mnemonic, user_symbol, cusip,
1125 fraction, (commodity !=
nullptr));
1128 gnc_ui_commodity_update_quote_info(win, commodity);
1129 win->edit_commodity = commodity;
1132 gnc_ui_commodity_quote_info_cb(win->get_quote_check, win);
1138 value = gtk_dialog_run(GTK_DIALOG(win->dialog));
1141 case GTK_RESPONSE_OK:
1143 done = gnc_ui_commodity_dialog_to_object(win);
1144 retval = win->edit_commodity;
1146 case GTK_RESPONSE_HELP:
1148 gnc_gnome_help (GTK_WINDOW(win->dialog), DF_MANUAL, DL_COMMODITY);
1151 DEBUG(
"default: %d", value);
1157 gtk_widget_destroy (GTK_WIDGET (win->dialog));
1172 const char * fullname,
1173 const char * mnemonic,
1174 const char * user_symbol,
1177 gnc_commodity *result;
1180 result = gnc_ui_common_commodity_modal(
nullptr, parent, name_space, cusip,
1181 fullname, mnemonic, user_symbol,
1195 gnc_commodity *result;
1198 result = gnc_ui_common_commodity_modal(
nullptr, parent, default_namespace,
nullptr,
1199 nullptr,
nullptr,
nullptr, 0);
1217 gnc_commodity *result;
1220 result = gnc_ui_common_commodity_modal(commodity, parent,
nullptr,
nullptr,
1221 nullptr,
nullptr,
nullptr, 0);
1223 return result !=
nullptr;
1231 gnc_ui_commodity_dialog_to_object(CommodityWindow * w)
1233 gnc_quote_source *source;
1235 const char * fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
1237 const char * mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
1238 const char * user_symbol = gtk_entry_get_text(GTK_ENTRY(w->user_symbol_entry));
1239 const char * code = gtk_entry_get_text(GTK_ENTRY(w->code_entry));
1240 QofBook * book = gnc_get_current_book ();
1241 int fraction = gtk_spin_button_get_value_as_int
1242 (GTK_SPIN_BUTTON(w->fraction_spinbutton));
1251 if (w->edit_commodity)
1254 quote_set = gtk_toggle_button_get_active
1255 (GTK_TOGGLE_BUTTON (w->get_quote_check));
1256 c = w->edit_commodity;
1257 gnc_commodity_begin_edit(c);
1261 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1262 string = gnc_timezone_menu_position_to_string(selection);
1270 gnc_commodity_commit_edit(c);
1273 gnc_warning_dialog (GTK_WINDOW (w->dialog),
"%s",
1274 _(
"You may not create a new national currency."));
1281 if (g_utf8_collate(name_space, GNC_COMMODITY_NS_TEMPLATE) == 0)
1283 gnc_warning_dialog (GTK_WINDOW (w->dialog),
1284 _(
"%s is a reserved commodity type." 1285 " Please use something else."), GNC_COMMODITY_NS_TEMPLATE);
1289 if (fullname && fullname[0] &&
1290 name_space && name_space[0] &&
1291 mnemonic && mnemonic[0])
1293 c = gnc_commodity_table_lookup (gnc_get_current_commodities(),
1294 name_space, mnemonic);
1296 if ((!w->edit_commodity && c) ||
1297 (w->edit_commodity && c && (c != w->edit_commodity)))
1299 gnc_warning_dialog (GTK_WINDOW (w->dialog),
"%s", _(
"That commodity already exists."));
1304 if (!w->edit_commodity)
1307 w->edit_commodity = c;
1308 gnc_commodity_begin_edit(c);
1314 c = w->edit_commodity;
1315 gnc_commodity_begin_edit(c);
1328 (GTK_TOGGLE_BUTTON (w->get_quote_check)));
1330 for (type =
SOURCE_SINGLE; type < SOURCE_MAX; type = static_cast<QuoteSourceType>(type+1))
1332 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w->source_button[type])))
1335 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->source_menu[type]));
1339 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1340 string = gnc_timezone_menu_position_to_string(selection);
1342 gnc_commodity_commit_edit(c);
1349 gnc_warning_dialog (GTK_WINDOW (w->dialog),
"%s",
1350 _(
"You must enter a non-empty \"Full name\", " 1351 "\"Symbol/abbreviation\", " 1352 "and \"Type\" for the commodity."));
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
Dialog box should only allow selection of a currency.
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
Given a combo box, fill in all the known commodities for the specified namespace, and then select one...
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
const char * gnc_quote_source_get_user_name(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the user friendly name of this quote source...
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
This quote source pulls from a single specific web site.
Dialog box should allow selection of anything but a currency.
utility functions for the GnuCash UI
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
Given a combo box, return the currently selected namespaces.
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
gnc_commodity * gnc_ui_new_commodity_modal(const char *default_namespace, GtkWidget *parent)
Ask the user to provide the information necessary to create a new commodity.
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.
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
gboolean gnc_quote_source_get_supported(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the flag that indicates whether this particular quote...
gboolean gnc_ui_edit_commodity_modal(gnc_commodity *commodity, GtkWidget *parent)
Given an existing commodity, uses the gnc_ui_build_commodity_dialog() routine to build a basic edit d...
QuoteSourceType gnc_quote_source_get_type(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the type of this particular quote source...
The special currency quote source.
This is a locally installed quote source that gnucash knows nothing about.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
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)
Ask the user to provide the information necessary to create a new commodity.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
gnc_quote_source * gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint index)
Given the type/index of a quote source, find the data structure identified by this pair...
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_commodity_user_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity, based on user input.
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
Set a user-defined symbol for the specified commodity.
Dialog box should allow selection of anything.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
gint gnc_quote_source_num_entries(QuoteSourceType type)
Return the number of entries for a given type of quote source.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
Dialog box should allow selection of anything but a currency and should include the "ALL" namespace t...
void gnc_ui_select_commodity_new_cb(GtkButton *button, gpointer user_data)
This function is called whenever the user clicks on the "New" button in the commodity picker...
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
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)
Ask the user to select a commodity from the existing set of commodities.
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Create a new commodity.
dialog_commodity_mode
The dialog commodity types are used to determine what commodity namespaces the currency dialog will p...
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
void gnc_ui_select_commodity_changed_cb(GtkComboBox *cbwe, gpointer user_data)
This function is called whenever the commodity combo box is changed.
gnc_commodity * gnc_ui_select_commodity_modal(gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode)
Ask the user to select a commodity from the existing set of commodities.
void gnc_ui_select_commodity_namespace_changed_cb(GtkComboBox *cbwe, gpointer user_data)
This function is called whenever the commodity namespace combo box is changed.
All type declarations for the whole Gnucash engine.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
Return a list of all commodities in the commodity table that are in the given namespace.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
This quote source may pull from multiple web sites.
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source for the specified commodity.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
gint gnc_quote_source_get_index(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the index of this particular quote source within its ...
#define LEAVE(format, args...)
Print a function exit debugging message.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
void gnc_ui_update_namespace_picker(GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
Given a combo box, fill in the known commodity namespaces and then select one.
"select" and "new" commodity windows
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
gboolean gnc_quote_source_fq_installed(void)
This function indicates whether or not the Finance::Quote module is installed on a user's computer...