r19657 - gnucash/trunk/src/app-utils - Rework two nearly identical fuctions into a common function with parameters.
Geert Janssens
gjanssens at code.gnucash.org
Thu Oct 14 17:00:46 EDT 2010
Author: gjanssens
Date: 2010-10-14 17:00:46 -0400 (Thu, 14 Oct 2010)
New Revision: 19657
Trac: http://svn.gnucash.org/trac/changeset/19657
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
Log:
Rework two nearly identical fuctions into a common function with parameters.
Keep the old function names as convenience wrappers around the new function.
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2010-10-14 20:41:00 UTC (rev 19656)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2010-10-14 21:00:46 UTC (rev 19657)
@@ -1014,21 +1014,22 @@
}
-gnc_commodity *
-gnc_default_currency (void)
+static gnc_commodity *
+gnc_default_currency_common (gchar *requested_currency,
+ const gchar *gconf_section)
{
gnc_commodity *currency = NULL;
gchar *choice, *mnemonic;
- if (user_default_currency)
+ if (requested_currency)
return gnc_commodity_table_lookup(gnc_get_current_commodities(),
GNC_COMMODITY_NS_CURRENCY,
- user_default_currency);
+ requested_currency);
- choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_CHOICE, NULL);
- if (choice && strcmp(choice, "other") == 0)
+ choice = gnc_gconf_get_string(gconf_section, KEY_CURRENCY_CHOICE, NULL);
+ if (g_strcmp0(choice, "other") == 0)
{
- mnemonic = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_OTHER, NULL);
+ mnemonic = gnc_gconf_get_string(gconf_section, KEY_CURRENCY_OTHER, NULL);
currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
GNC_COMMODITY_NS_CURRENCY, mnemonic);
DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
@@ -1040,48 +1041,25 @@
currency = gnc_locale_default_currency ();
if (currency)
{
- mnemonic = user_default_currency;
- user_default_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
+ mnemonic = requested_currency;
+ requested_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
g_free(mnemonic);
}
return currency;
}
gnc_commodity *
-gnc_default_report_currency (void)
+gnc_default_currency (void)
{
- gnc_commodity *currency = NULL;
- gchar *choice, *mnemonic;
+ return gnc_default_currency_common (user_default_currency, GCONF_GENERAL);
+}
- if (user_report_currency)
- return gnc_commodity_table_lookup(gnc_get_current_commodities(),
- GNC_COMMODITY_NS_CURRENCY,
- user_report_currency);
- choice = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
- KEY_CURRENCY_CHOICE, NULL);
- if (choice && strcmp(choice, "other") == 0)
- {
- mnemonic = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
- KEY_CURRENCY_OTHER, NULL);
- currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
- GNC_COMMODITY_NS_CURRENCY, mnemonic);
- DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
- g_free(mnemonic);
- }
- g_free(choice);
-
- if (!currency)
- currency = gnc_locale_default_currency ();
- if (currency)
- {
- mnemonic = user_report_currency;
- user_report_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
- g_free(mnemonic);
- }
- return currency;
+gnc_commodity *
+gnc_default_report_currency (void)
+{
+ return gnc_default_currency_common (user_report_currency, GCONF_GENERAL_REPORT);
}
-
static void
gnc_currency_changed_cb (GConfEntry *entry, gpointer user_data)
{
More information about the gnucash-changes
mailing list