Bug 723145 - Currency display does not respect locale

Use the system-provided symbol for the locale currency
This commit is contained in:
Frédéric Perrin
2014-05-20 16:18:21 +02:00
committed by Geert Janssens
parent 1992e5fb1f
commit 733e6e91da
6 changed files with 78 additions and 24 deletions
-13
View File
@@ -1747,19 +1747,6 @@ printable_value (gdouble val, gint denom)
return xaccPrintAmount (num, info);
}
const char*
gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
{
const char *nice_symbol;
if (!cm) return NULL;
nice_symbol = gnc_commodity_get_user_symbol(cm);
if (nice_symbol && *nice_symbol)
return nice_symbol;
else
return gnc_commodity_get_mnemonic(cm);
}
/********************************************************************\
* xaccParseAmount *
* parses amount strings using locale data *
-1
View File
@@ -259,7 +259,6 @@ const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
const gchar *printable_value(gdouble val, gint denom);
const char*gnc_commodity_get_nice_symbol(const gnc_commodity *cm);
gchar *number_to_words(gdouble val, gint64 denom);
gchar *numeric_to_words(gnc_numeric val);
+52 -4
View File
@@ -35,6 +35,7 @@
#include <regex.h>
#include "gnc-commodity.h"
#include "gnc-locale-utils.h"
#include "gnc-prefs.h"
static QofLogModule log_module = GNC_MOD_COMMODITY;
@@ -1140,18 +1141,51 @@ gnc_commodity_get_quote_tz(const gnc_commodity *cm)
/********************************************************************
* gnc_commodity_get_user_symbol
********************************************************************/
const char*
gnc_commodity_get_user_symbol(const gnc_commodity *cm)
{
const char *str;
if (!cm) return NULL;
str = kvp_frame_get_string(cm->inst.kvp_data, "user_symbol");
if (str && *str)
return str;
return kvp_frame_get_string(cm->inst.kvp_data, "user_symbol");
}
/********************************************************************
* gnc_commodity_get_default_symbol
*******************************************************************/
const char*
gnc_commodity_get_default_symbol(const gnc_commodity *cm)
{
const char *str;
if (!cm) return NULL;
return GET_PRIVATE(cm)->default_symbol;
}
/********************************************************************
* gnc_commodity_get_nice_symbol
*******************************************************************/
const char*
gnc_commodity_get_nice_symbol (const gnc_commodity *cm)
{
const char *nice_symbol;
struct lconv *lc;
if (!cm) return NULL;
nice_symbol = gnc_commodity_get_user_symbol(cm);
if (nice_symbol && *nice_symbol)
return nice_symbol;
lc = gnc_localeconv();
nice_symbol = lc->currency_symbol;
if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
return nice_symbol;
nice_symbol = gnc_commodity_get_default_symbol(cm);
if (nice_symbol && *nice_symbol)
return nice_symbol;
return gnc_commodity_get_mnemonic(cm);
}
/********************************************************************
* gnc_commodity_set_mnemonic
********************************************************************/
@@ -1393,11 +1427,25 @@ gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
void
gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
{
struct lconv *lc;
if (!cm) return;
ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
gnc_commodity_begin_edit(cm);
lc = gnc_localeconv();
if (!user_symbol || !*user_symbol)
user_symbol = NULL;
else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
!g_strcmp0(lc->currency_symbol, user_symbol))
/* if the user gives the ISO symbol for the locale currency or the
* default symbol, actually remove the user symbol */
user_symbol = NULL;
else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
user_symbol = NULL;
kvp_frame_set_string(cm->inst.kvp_data, "user_symbol", user_symbol);
mark_commodity_dirty(cm);
gnc_commodity_commit_edit(cm);
+23
View File
@@ -470,6 +470,29 @@ const char* gnc_commodity_get_quote_tz(const gnc_commodity *cm);
* should not be freed by the caller.
*/
const char* gnc_commodity_get_user_symbol(const gnc_commodity *cm);
/** Retrieve the default symbol for the specified commodity. This will
* be a pointer to a nul terminated string like "£", "US$", etc. Note
* that for the locale currency, you probably want to look at the
* system-provided symbol first. See gnc_commodity_get_nice_symbol.
*
* @param cm A pointer to a commodity data structure.
*
* @return A pointer to the default symbol for this commodity.
*/
const char* gnc_commodity_get_default_symbol(const gnc_commodity *cm);
/** Retrieve a symbol for the specified commodity, suitable for
* display to the user. This will be a pointer to a nul terminated
* string like "£", "US$", etc. That function is locale-aware and
* will base its choice of symbol on the user-configured symbol,
* the locale a
*
* @param cm A pointer to a commodity data structure.
*
* @return A pointer to the symbol for this commodity.
*/
const char*gnc_commodity_get_nice_symbol(const gnc_commodity *cm);
/** @} */
/** @name Commodity Accessor Routines - Set
+2 -5
View File
@@ -1157,7 +1157,7 @@ gnc_ui_common_commodity_modal(gnc_commodity *commodity,
namespace = gnc_commodity_get_namespace (commodity);
fullname = gnc_commodity_get_fullname (commodity);
mnemonic = gnc_commodity_get_mnemonic (commodity);
user_symbol = gnc_commodity_get_user_symbol (commodity);
user_symbol = gnc_commodity_get_nice_symbol (commodity);
cusip = gnc_commodity_get_cusip (commodity);
fraction = gnc_commodity_get_fraction (commodity);
}
@@ -1316,10 +1316,7 @@ gnc_ui_commodity_dialog_to_object(CommodityWindow * w)
else
gnc_commodity_set_quote_tz(c, NULL);
if (user_symbol && *user_symbol)
gnc_commodity_set_user_symbol(c, user_symbol);
else
gnc_commodity_set_user_symbol(c, NULL);
gnc_commodity_set_user_symbol(c, user_symbol);
gnc_commodity_commit_edit(c);
return TRUE;
+1 -1
View File
@@ -690,7 +690,7 @@ gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
case GNC_TREE_MODEL_COMMODITY_COL_USER_SYMBOL:
g_value_init (value, G_TYPE_STRING);
g_value_set_string (value, gnc_commodity_get_user_symbol (commodity));
g_value_set_string (value, gnc_commodity_get_nice_symbol (commodity));
break;
case GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY:
g_value_init (value, G_TYPE_BOOLEAN);