mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use the name "Currency" internally instead of ISO4217. Make it
possible to edit the "get quotes" flag on currencies. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13731 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2006-04-03 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/backend/file/sixtp-dom-generators.c:
|
||||
* src/backend/file/gnc-commodity-xml-v2.c:
|
||||
* src/gnome-utils/dialog-commodity.c:
|
||||
* src/gnome/dialog-commodities.c:
|
||||
* src/engine/gnc-commodity.[ch]: Use the name "Currency"
|
||||
internally instead of ISO4217. Make it possible to edit the "get
|
||||
quotes" flag on currencies.
|
||||
|
||||
2006-04-02 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/register/ledger-core/split-register-model.c: Change the
|
||||
|
||||
@@ -65,33 +65,39 @@ gnc_commodity_dom_tree_create(const gnc_commodity *com)
|
||||
gnc_quote_source *source;
|
||||
const char *string;
|
||||
xmlNodePtr ret;
|
||||
gboolean currency = gnc_commodity_is_iso(com);
|
||||
|
||||
if (currency && !gnc_commodity_get_quote_flag(com))
|
||||
return NULL;
|
||||
|
||||
ret = xmlNewNode(NULL, BAD_CAST gnc_commodity_string);
|
||||
|
||||
xmlSetProp(ret, BAD_CAST "version", BAD_CAST commodity_version_string);
|
||||
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_namespace,
|
||||
gnc_commodity_get_namespace(com)));
|
||||
gnc_commodity_get_namespace_compat(com)));
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_id,
|
||||
gnc_commodity_get_mnemonic(com)));
|
||||
|
||||
if(gnc_commodity_get_fullname(com))
|
||||
{
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_name,
|
||||
gnc_commodity_get_fullname(com)));
|
||||
if (!currency) {
|
||||
if(gnc_commodity_get_fullname(com))
|
||||
{
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_name,
|
||||
gnc_commodity_get_fullname(com)));
|
||||
}
|
||||
|
||||
if(gnc_commodity_get_cusip(com) &&
|
||||
strlen(gnc_commodity_get_cusip(com)) > 0)
|
||||
{
|
||||
xmlAddChild(ret, text_to_dom_tree(
|
||||
cmdty_xcode,
|
||||
gnc_commodity_get_cusip(com)));
|
||||
}
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
|
||||
gnc_commodity_get_fraction(com)));
|
||||
}
|
||||
|
||||
if(gnc_commodity_get_cusip(com) &&
|
||||
strlen(gnc_commodity_get_cusip(com)) > 0)
|
||||
{
|
||||
xmlAddChild(ret, text_to_dom_tree(
|
||||
cmdty_xcode,
|
||||
gnc_commodity_get_cusip(com)));
|
||||
}
|
||||
|
||||
xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
|
||||
gnc_commodity_get_fraction(com)));
|
||||
|
||||
if (gnc_commodity_get_quote_flag(com)) {
|
||||
xmlNewChild(ret, NULL, BAD_CAST cmdty_get_quotes, NULL);
|
||||
source = gnc_commodity_get_quote_source(com);
|
||||
@@ -192,6 +198,31 @@ valid_commodity(gnc_commodity *com)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gnc_commodity *
|
||||
gnc_commodity_find_currency (QofBook *book, xmlNodePtr tree)
|
||||
{
|
||||
gnc_commodity_table * table;
|
||||
gchar *exchange = NULL, *mnemonic = NULL;
|
||||
xmlNodePtr node;
|
||||
|
||||
for(node = tree->xmlChildrenNode; node; node = node->next)
|
||||
{
|
||||
if (safe_strcmp((char*) node->name, cmdty_namespace) == 0)
|
||||
exchange = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
|
||||
if (safe_strcmp((char*) node->name, cmdty_id) == 0)
|
||||
mnemonic = (gchar*) xmlNodeGetContent (node->xmlChildrenNode);
|
||||
}
|
||||
|
||||
if (!exchange || !mnemonic)
|
||||
return NULL;
|
||||
|
||||
if (!gnc_commodity_namespace_is_iso(exchange))
|
||||
return NULL;
|
||||
|
||||
table = gnc_commodity_table_get_table(book);
|
||||
return gnc_commodity_table_lookup(table, exchange, mnemonic);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_commodity_end_handler(gpointer data_for_children,
|
||||
GSList* data_from_children, GSList* sibling_data,
|
||||
@@ -217,8 +248,10 @@ gnc_commodity_end_handler(gpointer data_for_children,
|
||||
}
|
||||
|
||||
g_return_val_if_fail(tree, FALSE);
|
||||
|
||||
com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
|
||||
|
||||
com = gnc_commodity_find_currency(book, tree);
|
||||
if (!com)
|
||||
com = gnc_commodity_new(book, NULL, NULL, NULL, NULL, 0);
|
||||
|
||||
for(achild = tree->xmlChildrenNode; achild; achild = achild->next)
|
||||
{
|
||||
|
||||
@@ -953,36 +953,26 @@ write_commodities(FILE *out, QofBook *book, sixtp_gdv2 *gd)
|
||||
|
||||
for(lp = namespaces; lp; lp = lp->next)
|
||||
{
|
||||
gchar *space;
|
||||
GList *comms, *lp2;
|
||||
xmlNodePtr comnode;
|
||||
|
||||
if(!lp->data) {
|
||||
g_list_free (namespaces);
|
||||
return;
|
||||
}
|
||||
comms = gnc_commodity_table_get_commodities(tbl, lp->data);
|
||||
comms = g_list_sort(comms, compare_commodity_ids);
|
||||
|
||||
space = (gchar *) lp->data;
|
||||
if(!gnc_commodity_namespace_is_iso(space))
|
||||
{
|
||||
GList *comms = gnc_commodity_table_get_commodities(tbl, space);
|
||||
GList *lp2;
|
||||
for(lp2 = comms; lp2; lp2 = lp2->next) {
|
||||
comnode = gnc_commodity_dom_tree_create(lp2->data);
|
||||
if (comnode == NULL)
|
||||
continue;
|
||||
|
||||
comms = g_list_sort(comms, compare_commodity_ids);
|
||||
xmlElemDump(out, NULL, comnode);
|
||||
fprintf(out, "\n");
|
||||
|
||||
for(lp2 = comms; lp2; lp2 = lp2->next)
|
||||
{
|
||||
xmlNodePtr comnode = gnc_commodity_dom_tree_create(
|
||||
(gnc_commodity *) lp2->data);
|
||||
xmlFreeNode(comnode);
|
||||
gd->counter.commodities_loaded++;
|
||||
run_callback(gd, "commodities");
|
||||
}
|
||||
|
||||
xmlElemDump(out, NULL, comnode);
|
||||
fprintf(out, "\n");
|
||||
|
||||
xmlFreeNode(comnode);
|
||||
gd->counter.commodities_loaded++;
|
||||
run_callback(gd, "commodities");
|
||||
}
|
||||
|
||||
g_list_free (comms);
|
||||
}
|
||||
g_list_free (comms);
|
||||
}
|
||||
|
||||
if (namespaces) g_list_free (namespaces);
|
||||
|
||||
@@ -110,7 +110,7 @@ commodity_ref_to_dom_tree(const char *tag, const gnc_commodity *c)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xmlNewTextChild(ret, NULL, BAD_CAST "cmdty:space", BAD_CAST gnc_commodity_get_namespace(c));
|
||||
xmlNewTextChild(ret, NULL, BAD_CAST "cmdty:space", BAD_CAST gnc_commodity_get_namespace_compat(c));
|
||||
xmlNewTextChild(ret, NULL, BAD_CAST "cmdty:id", BAD_CAST gnc_commodity_get_mnemonic(c));
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -69,7 +69,8 @@ struct gnc_commodity_namespace_s
|
||||
{
|
||||
QofInstance inst;
|
||||
|
||||
char * name;
|
||||
gchar * name;
|
||||
gboolean iso4217;
|
||||
GHashTable * cm_table;
|
||||
GList * cm_list;
|
||||
};
|
||||
@@ -528,6 +529,8 @@ gnc_commodity_new(QofBook *book, const char * fullname,
|
||||
|
||||
reset_printname(retval);
|
||||
reset_unique_name(retval);
|
||||
if (gnc_commodity_namespace_is_iso(namespace))
|
||||
retval->quote_source = gnc_quote_source_lookup_by_internal("currency");
|
||||
qof_event_gen (&retval->inst.entity, QOF_EVENT_CREATE, NULL);
|
||||
|
||||
return retval;
|
||||
@@ -638,6 +641,15 @@ gnc_commodity_get_namespace(const gnc_commodity * cm)
|
||||
return gnc_commodity_namespace_get_name(cm->namespace);
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_commodity_get_namespace_compat(const gnc_commodity * cm)
|
||||
{
|
||||
if (!cm || !cm->namespace) return NULL;
|
||||
if (cm->namespace->iso4217)
|
||||
return GNC_COMMODITY_NS_ISO;
|
||||
return gnc_commodity_namespace_get_name(cm->namespace);
|
||||
}
|
||||
|
||||
gnc_commodity_namespace *
|
||||
gnc_commodity_get_namespace_ds(const gnc_commodity * cm)
|
||||
{
|
||||
@@ -783,6 +795,8 @@ gnc_commodity_set_namespace(gnc_commodity * cm, const char * namespace)
|
||||
return;
|
||||
|
||||
cm->namespace = nsp;
|
||||
if (nsp->iso4217)
|
||||
cm->quote_source = gnc_quote_source_lookup_by_internal("currency");
|
||||
mark_commodity_dirty(cm);
|
||||
reset_printname(cm);
|
||||
reset_unique_name(cm);
|
||||
@@ -981,7 +995,16 @@ gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *namesp
|
||||
gboolean
|
||||
gnc_commodity_namespace_is_iso(const char *namespace)
|
||||
{
|
||||
return (safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0);
|
||||
return ((safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0) ||
|
||||
(safe_strcmp(namespace, GNC_COMMODITY_NS_CURRENCY) == 0));
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
gnc_commodity_table_map_namespace(const char * namespace)
|
||||
{
|
||||
if (safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0)
|
||||
return GNC_COMMODITY_NS_CURRENCY;
|
||||
return namespace;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@@ -1327,11 +1350,8 @@ gnc_commodity_table_get_namespaces_list(const gnc_commodity_table * table)
|
||||
gboolean
|
||||
gnc_commodity_is_iso(const gnc_commodity * cm)
|
||||
{
|
||||
const gchar *ns_name;
|
||||
|
||||
if (!cm) return FALSE;
|
||||
ns_name = gnc_commodity_namespace_get_name(cm->namespace);
|
||||
return (safe_strcmp(ns_name, GNC_COMMODITY_NS_ISO) == 0);
|
||||
if (!cm || !cm->namespace) return FALSE;
|
||||
return cm->namespace->iso4217;
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -1450,12 +1470,14 @@ gnc_commodity_table_add_namespace(gnc_commodity_table * table,
|
||||
|
||||
if (!table) return NULL;
|
||||
|
||||
namespace = gnc_commodity_table_map_namespace(namespace);
|
||||
ns = gnc_commodity_table_find_namespace(table, namespace);
|
||||
if(!ns)
|
||||
{
|
||||
ns = g_new0(gnc_commodity_namespace, 1);
|
||||
ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
ns->name = gnc_string_cache_insert((gpointer)namespace);
|
||||
ns->iso4217 = gnc_commodity_namespace_is_iso(namespace);
|
||||
qof_instance_init (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
|
||||
qof_event_gen (&ns->inst.entity, QOF_EVENT_CREATE, NULL);
|
||||
|
||||
@@ -1476,6 +1498,7 @@ gnc_commodity_table_find_namespace(const gnc_commodity_table * table,
|
||||
if (!table || !namespace)
|
||||
return NULL;
|
||||
|
||||
namespace = gnc_commodity_table_map_namespace(namespace);
|
||||
return g_hash_table_lookup(table->ns_table, (gpointer)namespace);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@
|
||||
*/
|
||||
#define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES"
|
||||
#define GNC_COMMODITY_NS_ISO "ISO4217"
|
||||
#define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
|
||||
#define GNC_COMMODITY_NS_NASDAQ "NASDAQ"
|
||||
#define GNC_COMMODITY_NS_NYSE "NYSE"
|
||||
#define GNC_COMMODITY_NS_EUREX "EUREX"
|
||||
@@ -313,6 +314,20 @@ const char * gnc_commodity_get_mnemonic(const gnc_commodity * cm);
|
||||
*/
|
||||
const char * gnc_commodity_get_namespace(const gnc_commodity * cm);
|
||||
|
||||
/** Retrieve the namespace for the specified commodity. This will be
|
||||
* a pointer to a null terminated string of the form "AMEX",
|
||||
* "NASDAQ", etc. The only difference between function and
|
||||
* gnc_commodity_get_namespace() is that this function returns
|
||||
* ISO4217 instead of CURRENCY for backward compatability with the
|
||||
* 1.8 data files.
|
||||
*
|
||||
* @param cm A pointer to a commodity data structure.
|
||||
*
|
||||
* @return A pointer to the namespace for this commodity. This string
|
||||
* is owned by the engine and should not be freed by the caller.
|
||||
*/
|
||||
const char * gnc_commodity_get_namespace_compat(const gnc_commodity * cm);
|
||||
|
||||
/** Retrieve the namespace data strucure for the specified commodity.
|
||||
* This will be a pointer to another data structure.
|
||||
*
|
||||
|
||||
@@ -581,20 +581,12 @@ gnc_ui_update_namespace_picker(GtkWidget * combobox,
|
||||
case DIAG_COMM_ALL:
|
||||
namespaces =
|
||||
gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
|
||||
|
||||
/* Replace the string "ISO4217" with "CURRENCY". */
|
||||
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_ISO, g_strcmp);
|
||||
if (node) {
|
||||
namespaces = g_list_remove_link (namespaces, node);
|
||||
g_list_free_1 (node);
|
||||
}
|
||||
namespaces = g_list_prepend (namespaces, "CURRENCY");
|
||||
break;
|
||||
|
||||
case DIAG_COMM_NON_CURRENCY:
|
||||
namespaces =
|
||||
gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
|
||||
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_ISO, g_strcmp);
|
||||
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_CURRENCY, g_strcmp);
|
||||
if (node) {
|
||||
namespaces = g_list_remove_link (namespaces, node);
|
||||
g_list_free_1 (node);
|
||||
@@ -606,7 +598,7 @@ gnc_ui_update_namespace_picker(GtkWidget * combobox,
|
||||
|
||||
case DIAG_COMM_CURRENCY:
|
||||
default:
|
||||
namespaces = g_list_prepend (NULL, "CURRENCY");
|
||||
namespaces = g_list_prepend (NULL, GNC_COMMODITY_NS_CURRENCY);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -629,8 +621,7 @@ gnc_ui_update_namespace_picker(GtkWidget * combobox,
|
||||
else
|
||||
active = "";
|
||||
|
||||
if (safe_strcmp (active, GNC_COMMODITY_NS_ISO) == 0 ||
|
||||
safe_strcmp (active, "CURRENCY") == 0 ||
|
||||
if (safe_strcmp (active, "CURRENCY") == 0 ||
|
||||
safe_strcmp (init_string, "CURRENCY") == 0)
|
||||
{
|
||||
active = "CURRENCY";
|
||||
@@ -650,8 +641,8 @@ gnc_ui_namespace_picker_ns (GtkWidget *combobox)
|
||||
|
||||
namespace = gtk_entry_get_text (GTK_ENTRY(GTK_COMBO (combobox)->entry));
|
||||
|
||||
if (safe_strcmp (namespace, "CURRENCY") == 0)
|
||||
return GNC_COMMODITY_NS_ISO;
|
||||
if (safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0)
|
||||
return GNC_COMMODITY_NS_CURRENCY;
|
||||
else
|
||||
return namespace;
|
||||
}
|
||||
@@ -730,16 +721,21 @@ gnc_ui_source_menu_create(QuoteSourceType type)
|
||||
menu = GTK_MENU(gtk_menu_new());
|
||||
gtk_widget_show(GTK_WIDGET(menu));
|
||||
|
||||
max = gnc_quote_source_num_entries(type);
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
source = gnc_quote_source_lookup_by_ti(type, i);
|
||||
if (source == NULL)
|
||||
break;
|
||||
item = gtk_menu_item_new_with_label(gnc_quote_source_get_user_name(source));
|
||||
gtk_widget_set_sensitive(item, gnc_quote_source_get_supported(source));
|
||||
if (type == SOURCE_CURRENCY) {
|
||||
item = gtk_menu_item_new_with_label(_("Currency"));
|
||||
gtk_widget_show(item);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
||||
} else {
|
||||
max = gnc_quote_source_num_entries(type);
|
||||
for (i = 0; i < max; i++) {
|
||||
source = gnc_quote_source_lookup_by_ti(type, i);
|
||||
if (source == NULL)
|
||||
break;
|
||||
item = gtk_menu_item_new_with_label(gnc_quote_source_get_user_name(source));
|
||||
gtk_widget_set_sensitive(item, gnc_quote_source_get_supported(source));
|
||||
gtk_widget_show(item);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
||||
}
|
||||
}
|
||||
|
||||
omenu = gtk_option_menu_new();
|
||||
@@ -885,7 +881,11 @@ gnc_ui_new_commodity_dialog(const char * selected_namespace,
|
||||
|
||||
/* Build custom widgets */
|
||||
box = glade_xml_get_widget (xml, "single_source_box");
|
||||
menu = gnc_ui_source_menu_create(SOURCE_SINGLE);
|
||||
if (gnc_commodity_namespace_is_iso(selected_namespace)) {
|
||||
menu = gnc_ui_source_menu_create(SOURCE_CURRENCY);
|
||||
} else {
|
||||
menu = gnc_ui_source_menu_create(SOURCE_SINGLE);
|
||||
}
|
||||
retval->source_menu[SOURCE_SINGLE] = menu;
|
||||
gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ edit_clicked (CommoditiesDialog *cd)
|
||||
gnc_commodity *commodity;
|
||||
|
||||
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
|
||||
if (commodity == NULL || gnc_commodity_is_iso (commodity))
|
||||
if (commodity == NULL || gnc_commodity_is_currency (commodity))
|
||||
return;
|
||||
|
||||
if (gnc_ui_edit_commodity_modal (commodity, cd->dialog))
|
||||
@@ -231,13 +231,13 @@ static void
|
||||
gnc_commodities_dialog_selection_changed (GtkTreeSelection *selection,
|
||||
CommoditiesDialog *cd)
|
||||
{
|
||||
gboolean sensitive = FALSE;
|
||||
gboolean remove_ok;
|
||||
gnc_commodity *commodity;
|
||||
|
||||
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
|
||||
sensitive = commodity && !gnc_commodity_is_iso(commodity);
|
||||
gtk_widget_set_sensitive (cd->edit_button, sensitive);
|
||||
gtk_widget_set_sensitive (cd->remove_button, sensitive);
|
||||
remove_ok = commodity && !gnc_commodity_is_iso(commodity);
|
||||
gtk_widget_set_sensitive (cd->edit_button, commodity != NULL);
|
||||
gtk_widget_set_sensitive (cd->remove_button, remove_ok);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user