mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Consolidate all the tests for an ISO 4217 commodity into a pair of
functions. Use these functions throughout the code. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8252 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
e46d7c6b05
commit
2fc7cc7372
20
ChangeLog
20
ChangeLog
@ -1,3 +1,23 @@
|
||||
2003-04-28 David Hampton <hampton@employees.org>
|
||||
* src/engine/iso-4217-currencies.scm: Remove two duplicate
|
||||
commodities. The newer name for these commodities was retained.
|
||||
|
||||
* src/app-utils/gnc-euro.c:
|
||||
* src/app-utils/gnc-ui-util.c:
|
||||
* src/backend/file/io-gncxml-v2.c:
|
||||
* src/backend/postgres/test/test-db.c:
|
||||
* src/backend/rpc/RpcUtils.c:
|
||||
* src/engine/gnc-commodity.c:
|
||||
* src/engine/gnc-commodity.h:
|
||||
* src/engine/test-core/test-engine-stuff.c:
|
||||
* src/gnome/dialog-commodities.c:
|
||||
* src/gnome-utils/dialog-commodity.c:
|
||||
* src/gnome-utils/dialog-transfer.c:
|
||||
* src/import-export/binary-import/druid-commodity.c:
|
||||
* src/import-export/qif-import/druid-qif-import.c: Consolidate all
|
||||
the tests for an ISO 4217 commodity into a pair of functions. Use
|
||||
these functions throughout the code.
|
||||
|
||||
2003-04-26 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/backend/file/gnc-commodity-xml-v2.c: Consolidate duplicate
|
||||
|
@ -116,16 +116,11 @@ gboolean
|
||||
gnc_is_euro_currency(const gnc_commodity * currency)
|
||||
{
|
||||
gnc_euro_rate_struct *result;
|
||||
const char *namespace;
|
||||
|
||||
if (currency == NULL)
|
||||
return FALSE;
|
||||
|
||||
namespace = gnc_commodity_get_namespace (currency);
|
||||
if (namespace == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (strcmp (namespace, GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (!gnc_commodity_is_iso(currency))
|
||||
return FALSE;
|
||||
|
||||
result = bsearch(currency,
|
||||
@ -146,16 +141,11 @@ gnc_numeric
|
||||
gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
|
||||
{
|
||||
gnc_euro_rate_struct *result;
|
||||
const char *namespace;
|
||||
|
||||
if (currency == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
namespace = gnc_commodity_get_namespace (currency);
|
||||
if (namespace == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
if (strcmp (namespace, GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (!gnc_commodity_is_iso(currency))
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
result = bsearch(currency,
|
||||
@ -186,16 +176,11 @@ gnc_numeric
|
||||
gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
|
||||
{
|
||||
gnc_euro_rate_struct * result;
|
||||
const char *namespace;
|
||||
|
||||
if (currency == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
namespace = gnc_commodity_get_namespace (currency);
|
||||
if (namespace == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
if (strcmp (namespace, GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (!gnc_commodity_is_iso(currency))
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
result = bsearch(currency,
|
||||
@ -223,16 +208,11 @@ gnc_numeric
|
||||
gnc_euro_currency_get_rate (const gnc_commodity *currency)
|
||||
{
|
||||
gnc_euro_rate_struct * result;
|
||||
const char *namespace;
|
||||
|
||||
if (currency == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
namespace = gnc_commodity_get_namespace (currency);
|
||||
if (namespace == NULL)
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
if (strcmp (namespace, GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (!gnc_commodity_is_iso(currency))
|
||||
return gnc_numeric_zero ();
|
||||
|
||||
result = bsearch(currency,
|
||||
|
@ -1225,8 +1225,7 @@ gnc_commodity_print_info (const gnc_commodity *commodity,
|
||||
|
||||
info.commodity = commodity;
|
||||
|
||||
is_iso = (safe_strcmp (gnc_commodity_get_namespace (commodity),
|
||||
GNC_COMMODITY_NS_ISO) == 0);
|
||||
is_iso = gnc_commodity_is_iso (commodity);
|
||||
|
||||
if (is_decimal_fraction (gnc_commodity_get_fraction (commodity),
|
||||
&info.max_decimal_places))
|
||||
@ -1263,8 +1262,7 @@ gnc_account_print_info_helper(Account *account, gboolean use_symbol,
|
||||
|
||||
info.commodity = efffunc (account);
|
||||
|
||||
is_iso = (safe_strcmp (gnc_commodity_get_namespace (info.commodity),
|
||||
GNC_COMMODITY_NS_ISO) == 0);
|
||||
is_iso = gnc_commodity_is_iso (info.commodity);
|
||||
|
||||
scu = scufunc (account);
|
||||
|
||||
@ -1620,9 +1618,7 @@ xaccSPrintAmount (char * bufp, gnc_numeric val, GNCPrintAmountInfo info)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (info.commodity &&
|
||||
safe_strcmp (GNC_COMMODITY_NS_ISO,
|
||||
gnc_commodity_get_namespace (info.commodity)) != 0)
|
||||
if (info.commodity && !gnc_commodity_is_iso (info.commodity))
|
||||
is_shares = TRUE;
|
||||
|
||||
currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
|
||||
|
@ -909,7 +909,7 @@ write_commodities(FILE *out, GNCBook *book, sixtp_gdv2 *gd)
|
||||
}
|
||||
|
||||
space = (gchar *) lp->data;
|
||||
if(strcmp(GNC_COMMODITY_NS_ISO, space) != 0) {
|
||||
if(!gnc_commodity_namespace_is_iso(space)) {
|
||||
GList *comms = gnc_commodity_table_get_commodities(tbl, space);
|
||||
GList *lp2;
|
||||
|
||||
|
@ -278,9 +278,7 @@ add_commodity_to_delete(gnc_commodity * com, gpointer data)
|
||||
{
|
||||
CommodityDeleteInfo *cdi = data;
|
||||
|
||||
if (!g_hash_table_lookup(cdi->hash, com) &&
|
||||
safe_strcmp(gnc_commodity_get_namespace(com),
|
||||
GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (!g_hash_table_lookup(cdi->hash, com) && !gnc_commodity_is_iso(com))
|
||||
cdi->to_delete = g_list_prepend(cdi->to_delete, com);
|
||||
|
||||
return TRUE;
|
||||
|
@ -800,7 +800,7 @@ gnc_commoditylist * rpcend_build_gnccommoditylist (gnc_commodity_table *ct,
|
||||
GList *cl, *this_cl;
|
||||
|
||||
/* Ignore all the ISO4217 commodities */
|
||||
if (!strcmp (namespace, GNC_COMMODITY_NS_ISO))
|
||||
if (gnc_commodity_is_iso_namespace (namespace))
|
||||
continue;
|
||||
|
||||
cl = gnc_commodity_table_get_commodities (ct, namespace);
|
||||
|
@ -666,6 +666,18 @@ gnc_commodity_table_get_namespaces(const gnc_commodity_table * table)
|
||||
return g_hash_table_keys(table->table);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_commodity_namespace_is_iso(const char *namespace)
|
||||
{
|
||||
return (safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_commodity_is_iso(const gnc_commodity * cm)
|
||||
{
|
||||
if (!cm) return FALSE;
|
||||
return (safe_strcmp(cm->namespace, GNC_COMMODITY_NS_ISO) == 0);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_commodity_table_get_commodities
|
||||
|
@ -75,6 +75,11 @@ gboolean gnc_commodity_equiv(const gnc_commodity * a, const gnc_commodity * b);
|
||||
*/
|
||||
gboolean gnc_commodity_equal(const gnc_commodity * a, const gnc_commodity * b);
|
||||
|
||||
|
||||
gboolean gnc_commodity_namespace_is_iso(const char *namespace);
|
||||
gboolean gnc_commodity_is_iso(const gnc_commodity * comm);
|
||||
|
||||
|
||||
/* gnc_commodity_table functions : operate on a database of commodity
|
||||
* info */
|
||||
|
||||
|
@ -1182,7 +1182,7 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table)
|
||||
GList *commodities;
|
||||
GList *com_node;
|
||||
|
||||
if (strcmp (ns, GNC_COMMODITY_NS_ISO) == 0)
|
||||
if (gnc_commodity_namespace_is_iso (ns))
|
||||
continue;
|
||||
|
||||
commodities = gnc_commodity_table_get_commodities (table, ns);
|
||||
|
@ -454,8 +454,7 @@ gnc_ui_update_namespace_picker(GtkWidget * combobox,
|
||||
/* stick them in the combobox */
|
||||
gtk_combo_set_popdown_strings (GTK_COMBO (combobox), namespaces);
|
||||
|
||||
if (!include_iso &&
|
||||
safe_strcmp (init_string, GNC_COMMODITY_NS_ISO) == 0)
|
||||
if (!include_iso && gnc_commodity_namespace_is_iso (init_string))
|
||||
init_string = NULL;
|
||||
|
||||
/* set the entry text */
|
||||
@ -736,7 +735,7 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
|
||||
|
||||
gnc_commodity * c;
|
||||
|
||||
if (safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0)
|
||||
if (gnc_commodity_namespace_is_iso (namespace))
|
||||
{
|
||||
gnc_warning_dialog_parented(w->dialog,
|
||||
_("You may not create a new national "
|
||||
|
@ -1342,8 +1342,7 @@ gnc_xfer_dialog_ok_cb(GtkWidget * widget, gpointer data)
|
||||
return;
|
||||
}
|
||||
|
||||
if (safe_strcmp (gnc_commodity_get_namespace (xferData->from_commodity),
|
||||
GNC_COMMODITY_NS_ISO))
|
||||
if (!gnc_commodity_is_iso (xferData->from_commodity))
|
||||
{
|
||||
const char *message = _("You can't transfer from a non-currency account. "
|
||||
"Try reversing the \"from\" and \"to\" accounts "
|
||||
|
@ -106,8 +106,7 @@ gnc_load_namespace (gpointer data, gpointer user_data)
|
||||
GList *commodities;
|
||||
GList *node;
|
||||
|
||||
if (!cd->show_currencies &&
|
||||
safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0)
|
||||
if (!cd->show_currencies && gnc_commodity_namespace_is_iso (namespace))
|
||||
return;
|
||||
|
||||
ct = gnc_get_current_commodities ();
|
||||
@ -143,9 +142,7 @@ gnc_commodities_set_sensitives (CommoditiesDialog *cd)
|
||||
{
|
||||
gboolean sensitive;
|
||||
|
||||
if (cd->commodity &&
|
||||
safe_strcmp (gnc_commodity_get_namespace (cd->commodity),
|
||||
GNC_COMMODITY_NS_ISO) != 0)
|
||||
if (cd->commodity && !gnc_commodity_is_iso (cd->commodity))
|
||||
sensitive = TRUE;
|
||||
else
|
||||
sensitive = FALSE;
|
||||
|
@ -417,7 +417,7 @@ gnc_ui_commodity_druid_comm_check_cb(GnomeDruidPage * page, gpointer druid,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (safe_strcmp (new_type, GNC_COMMODITY_NS_ISO) == 0 &&
|
||||
if (gnc_commodity_namespace_is_iso (new_type) &&
|
||||
!gnc_commodity_table_lookup (gnc_get_current_commodities (),
|
||||
new_type, new_mnemonic))
|
||||
{
|
||||
|
@ -1407,7 +1407,7 @@ gnc_ui_qif_import_comm_check_cb(GnomeDruidPage * page,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0 &&
|
||||
if (gnc_commodity_namespace_is_iso (namespace) &&
|
||||
!gnc_commodity_table_lookup (gnc_get_current_commodities (),
|
||||
namespace, mnemonic))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user