gnucash maint: Bug 723145 - Currency display does not respect locale

Geert Janssens gjanssens at code.gnucash.org
Tue May 20 10:19:08 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/733e6e91 (commit)
	from  https://github.com/Gnucash/gnucash/commit/1992e5fb (commit)



commit 733e6e91dad9729b604da8d4e68851819a42fcbe
Author: Frédéric Perrin <frederic.perrin at resel.fr>
Date:   Wed Mar 26 00:07:49 2014 +0000

    Bug 723145 - Currency display does not respect locale
    
    Use the system-provided symbol for the locale currency

diff --git a/src/app-utils/gnc-ui-util.c b/src/app-utils/gnc-ui-util.c
index 09593b0..668e1b4 100644
--- a/src/app-utils/gnc-ui-util.c
+++ b/src/app-utils/gnc-ui-util.c
@@ -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                        *
diff --git a/src/app-utils/gnc-ui-util.h b/src/app-utils/gnc-ui-util.h
index 83fa84f..281ffc6 100644
--- a/src/app-utils/gnc-ui-util.h
+++ b/src/app-utils/gnc-ui-util.h
@@ -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);
 
diff --git a/src/engine/gnc-commodity.c b/src/engine/gnc-commodity.c
index 77c643b..54b52a2 100644
--- a/src/engine/gnc-commodity.c
+++ b/src/engine/gnc-commodity.c
@@ -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,19 +1141,52 @@ 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);
diff --git a/src/engine/gnc-commodity.h b/src/engine/gnc-commodity.h
index bb023b9..f64684c 100644
--- a/src/engine/gnc-commodity.h
+++ b/src/engine/gnc-commodity.h
@@ -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
diff --git a/src/gnome-utils/dialog-commodity.c b/src/gnome-utils/dialog-commodity.c
index 35507d7..86f01e0 100644
--- a/src/gnome-utils/dialog-commodity.c
+++ b/src/gnome-utils/dialog-commodity.c
@@ -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;
diff --git a/src/gnome-utils/gnc-tree-model-commodity.c b/src/gnome-utils/gnc-tree-model-commodity.c
index e52e1dc..a3a8934 100644
--- a/src/gnome-utils/gnc-tree-model-commodity.c
+++ b/src/gnome-utils/gnc-tree-model-commodity.c
@@ -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);



Summary of changes:
 src/app-utils/gnc-ui-util.c                | 13 -------
 src/app-utils/gnc-ui-util.h                |  1 -
 src/engine/gnc-commodity.c                 | 56 +++++++++++++++++++++++++++---
 src/engine/gnc-commodity.h                 | 23 ++++++++++++
 src/gnome-utils/dialog-commodity.c         |  7 ++--
 src/gnome-utils/gnc-tree-model-commodity.c |  2 +-
 6 files changed, 78 insertions(+), 24 deletions(-)



More information about the gnucash-changes mailing list