gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Jun 20 16:37:31 EDT 2017


Updated	 via  https://github.com/Gnucash/gnucash/commit/c80dad74 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4032d33b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/cc3010d8 (commit)
	from  https://github.com/Gnucash/gnucash/commit/b5b0f603 (commit)



commit c80dad742e4390b053dfbb028874982ed568158c
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Jun 20 21:35:10 2017 +0200

    Bug 603379 - Prevent changing some Account Options if it has transactions - followup
    
    Relax the account type change restrictions again. In the new implementation
    account types can't be changed for an account with splits:
    - if the change woud force a commodity change (to/from normal accounts from/to stock related accounts)
    - for immutable accounts
    
    At the time of this commit the following account types are considered immutable:
    - Accounts Receivable
    - Accounts Payable
    - Trading accounts

diff --git a/src/engine/Account.c b/src/engine/Account.c
index 9099978..9a4e396 100644
--- a/src/engine/Account.c
+++ b/src/engine/Account.c
@@ -4030,6 +4030,46 @@ xaccAccountGetTypeStr(GNCAccountType type)
 \********************************************************************/
 
 guint32
+xaccAccountTypesCompatibleWith (GNCAccountType type)
+{
+    switch (type)
+    {
+        case ACCT_TYPE_BANK:
+        case ACCT_TYPE_CASH:
+        case ACCT_TYPE_ASSET:
+        case ACCT_TYPE_CREDIT:
+        case ACCT_TYPE_LIABILITY:
+        case ACCT_TYPE_INCOME:
+        case ACCT_TYPE_EXPENSE:
+        case ACCT_TYPE_EQUITY:
+            return
+            (1 << ACCT_TYPE_BANK)       |
+            (1 << ACCT_TYPE_CASH)       |
+            (1 << ACCT_TYPE_ASSET)      |
+            (1 << ACCT_TYPE_CREDIT)     |
+            (1 << ACCT_TYPE_LIABILITY)  |
+            (1 << ACCT_TYPE_INCOME)     |
+            (1 << ACCT_TYPE_EXPENSE)    |
+            (1 << ACCT_TYPE_EQUITY);
+        case ACCT_TYPE_STOCK:
+        case ACCT_TYPE_MUTUAL:
+        case ACCT_TYPE_CURRENCY:
+            return
+            (1 << ACCT_TYPE_STOCK)      |
+            (1 << ACCT_TYPE_MUTUAL)     |
+            (1 << ACCT_TYPE_CURRENCY);
+        case ACCT_TYPE_RECEIVABLE:
+            return (1 << ACCT_TYPE_RECEIVABLE);
+        case ACCT_TYPE_PAYABLE:
+            return (1 << ACCT_TYPE_PAYABLE);
+        case ACCT_TYPE_TRADING:
+            return (1 << ACCT_TYPE_TRADING);
+        default:
+            PERR("bad account type: %d", type);
+            return 0;
+    }
+}
+guint32
 xaccParentAccountTypesCompatibleWith (GNCAccountType type)
 {
     switch (type)
diff --git a/src/engine/Account.h b/src/engine/Account.h
index e776110..e4828c3 100644
--- a/src/engine/Account.h
+++ b/src/engine/Account.h
@@ -926,6 +926,11 @@ GNCAccountType xaccAccountStringToEnum (const char* str);
  *  to the local language. */
 const char * xaccAccountGetTypeStr (GNCAccountType type);
 
+/** Return the bitmask of account types compatible with a given type.
+ *  That is, you could switch to any of the account types in the compatible
+ *  list without unwanted side-effects. */
+guint32 xaccAccountTypesCompatibleWith (GNCAccountType type);
+
 /** Return the bitmask of parent account types compatible with a given type. */
 guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type);
 
diff --git a/src/engine/test/utest-Account.c b/src/engine/test/utest-Account.c
index 6284d18..45be1e3 100644
--- a/src/engine/test/utest-Account.c
+++ b/src/engine/test/utest-Account.c
@@ -2189,6 +2189,7 @@ test_xaccAccountType_Stuff (void)
 }
 /* xaccParentAccountTypesCompatibleWith
  * xaccAccountTypesCompatible
+ * xaccAccountTypesCompatibleWith
 guint32
 xaccParentAccountTypesCompatibleWith (GNCAccountType type)// C: 5 in 3 */
 static void
@@ -2210,6 +2211,20 @@ test_xaccAccountType_Compatibility (void)
                               (1 << ACCT_TYPE_ROOT));
     guint32 equity_compat = ((1 << ACCT_TYPE_EQUITY) | (1 << ACCT_TYPE_ROOT));
     guint32 trading_compat = ((1 << ACCT_TYPE_TRADING) | (1 << ACCT_TYPE_ROOT));
+    guint32 currency_compat = ((1 << ACCT_TYPE_BANK)       |
+                               (1 << ACCT_TYPE_CASH)       |
+                               (1 << ACCT_TYPE_ASSET)      |
+                               (1 << ACCT_TYPE_CREDIT)     |
+                               (1 << ACCT_TYPE_LIABILITY)  |
+                               (1 << ACCT_TYPE_INCOME)     |
+                               (1 << ACCT_TYPE_EXPENSE)    |
+                               (1 << ACCT_TYPE_EQUITY));
+    guint32 stock_compat = ((1 << ACCT_TYPE_STOCK)      |
+                            (1 << ACCT_TYPE_MUTUAL)     |
+                            (1 << ACCT_TYPE_CURRENCY));
+    guint32 immutable_ar_compat = (1 << ACCT_TYPE_RECEIVABLE);
+    guint32 immutable_ap_compat = (1 << ACCT_TYPE_PAYABLE);
+    guint32 immutable_trading_compat = (1 << ACCT_TYPE_TRADING);
     guint32 compat;
     GNCAccountType  type;
     gchar *msg1 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_ROOT);
@@ -2252,6 +2267,19 @@ test_xaccAccountType_Compatibility (void)
                 g_assert (xaccAccountTypesCompatible (type, child));
             else
                 g_assert (!xaccAccountTypesCompatible (type, child));
+
+        compat = xaccAccountTypesCompatibleWith (type);
+        if (type <= ACCT_TYPE_LIABILITY ||
+            (type >= ACCT_TYPE_INCOME && type <= ACCT_TYPE_EQUITY))
+            g_assert_cmpint (compat, == , currency_compat);
+        else if (type >= ACCT_TYPE_STOCK && type <= ACCT_TYPE_CURRENCY)
+            g_assert_cmpint (compat, == , stock_compat);
+        else if (type == ACCT_TYPE_RECEIVABLE)
+            g_assert_cmpint (compat, == , immutable_ar_compat);
+        else if (type == ACCT_TYPE_PAYABLE)
+            g_assert_cmpint (compat, == , immutable_ap_compat);
+        else if (type == ACCT_TYPE_TRADING)
+            g_assert_cmpint (compat, == , immutable_trading_compat);
     }
 
     loghandler = g_log_set_handler (logdomain, loglevel,
diff --git a/src/gnome-utils/dialog-account.c b/src/gnome-utils/dialog-account.c
index 20c5231..a3ab6a1 100644
--- a/src/gnome-utils/dialog-account.c
+++ b/src/gnome-utils/dialog-account.c
@@ -1120,17 +1120,18 @@ gnc_account_type_changed_cb (GtkTreeSelection *selection, gpointer data)
 }
 
 static void
-gnc_account_type_view_create (AccountWindow *aw)
+gnc_account_type_view_create (AccountWindow *aw, guint32 compat_types)
 {
     GtkTreeModel *model;
     GtkTreeSelection *selection;
     GtkCellRenderer *renderer;
     GtkTreeView *view;
 
+    aw->valid_types &= compat_types;
     if (aw->valid_types == 0)
     {
         /* no type restrictions, choose aw->type */
-        aw->valid_types = xaccAccountTypesValid () | (1 << aw->type);
+        aw->valid_types = compat_types | (1 << aw->type);
         aw->preferred_account_type = aw->type;
     }
     else if ((aw->valid_types & (1 << aw->type)) != 0)
@@ -1309,6 +1310,7 @@ gnc_account_window_create(AccountWindow *aw)
     GtkBuilder  *builder;
     GtkTreeSelection *selection;
     const gchar *tt = _("This Account contains Transactions.\nChanging this option is not possible.");
+    guint32 compat_types = xaccAccountTypesValid ();
 
     ENTER("aw %p, modal %d", aw, aw->modal);
     builder = gtk_builder_new();
@@ -1413,23 +1415,23 @@ gnc_account_window_create(AccountWindow *aw)
 
     /* This goes at the end so the select callback has good data. */
     aw->type_view = GTK_WIDGET(gtk_builder_get_object (builder, "type_view"));
-    gnc_account_type_view_create (aw);
 
-    // If the account has transactions, prevent changes by displaying a label and tooltip
+    // If the account has transactions, reduce the available account types
+    // to change the current account type to based on the following
+    // restrictions:
+    // - the new account type should not force a change of commodity
+    // - the old/new type is not an immutable type. Types are marked as
+    //   immutable if gnucash depends on details that would be lost/missing
+    //   if changing from/to such a type. At the time of this writing the
+    //   immutable types are AR, AP and trading types.
     if (xaccAccountCountSplits (aw_get_account (aw), FALSE) > 0)
     {
         GNCAccountType atype = xaccAccountGetType (aw_get_account (aw));
-        GtkWidget *label = gtk_label_new (xaccAccountGetTypeStr (atype));
-        GtkWidget *vbox = GTK_WIDGET(gtk_builder_get_object (builder, "type_vbox"));
-        GtkWidget *parent_widget = gtk_widget_get_parent (GTK_WIDGET(aw->type_view));
-
-        g_object_ref (G_OBJECT(aw->type_view));
-        gtk_container_remove (GTK_CONTAINER(vbox), parent_widget);
-        gtk_widget_set_tooltip_text (label, tt);
-        gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
-        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-        gtk_widget_show (label);
+        compat_types = xaccAccountTypesCompatibleWith (atype);
+        if (!compat_types)
+            compat_types = xaccAccountTypesValid ();
     }
+    gnc_account_type_view_create (aw, compat_types);
 
     gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
 

commit 4032d33b48c6e86845a1d41be23ddad1825b15cc
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Jun 20 12:06:14 2017 +0200

    Properly define the template namespace rather than using a local string everywhere

diff --git a/src/backend/xml/gnc-schedxaction-xml-v2.c b/src/backend/xml/gnc-schedxaction-xml-v2.c
index b604556..940d853 100644
--- a/src/backend/xml/gnc-schedxaction-xml-v2.c
+++ b/src/backend/xml/gnc-schedxaction-xml-v2.c
@@ -819,7 +819,7 @@ tt_act_handler( xmlNodePtr node, gpointer data )
 
             table = gnc_commodity_table_get_table( txd->book );
             com = gnc_commodity_table_lookup( table,
-                                              "template", "template" );
+                                              GNC_COMMODITY_NS_TEMPLATE, "template" );
 #else
             /* FIXME: This should first look in the table of the
                book, maybe? The right thing happens [WRT file
@@ -829,7 +829,7 @@ tt_act_handler( xmlNodePtr node, gpointer data )
                applies for
                SchedXaction.c:xaccSchedXactionInit... */
             com = gnc_commodity_new( txd->book,
-                                     "template", "template",
+                                     "template", GNC_COMMODITY_NS_TEMPLATE,
                                      "template", "template",
                                      1 );
 #endif
diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c
index 23ffb1f..af10919 100644
--- a/src/engine/SchedXaction.c
+++ b/src/engine/SchedXaction.c
@@ -388,7 +388,7 @@ xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
     xaccAccountSetCommodity
     (sx->template_acct,
      gnc_commodity_table_lookup( gnc_commodity_table_get_table(book),
-                                 "template", "template") );
+                                 GNC_COMMODITY_NS_TEMPLATE, "template") );
     xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
     xaccAccountCommitEdit( sx->template_acct );
     ra = gnc_book_get_template_root( book );
diff --git a/src/engine/gnc-commodity.c b/src/engine/gnc-commodity.c
index 54ea771..a48cb79 100644
--- a/src/engine/gnc-commodity.c
+++ b/src/engine/gnc-commodity.c
@@ -848,7 +848,7 @@ gnc_commodity_new(QofBook *book, const char * fullname,
     if ( name_space != NULL )
     {
 	/* Prevent setting anything except template in namespace template. */
-	if (g_strcmp0 (name_space, "template") == 0 &&
+        if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
 	    g_strcmp0 (mnemonic, "template") != 0)
 	{
 	    PWARN("Converting commodity %s from namespace template to "
@@ -1939,7 +1939,7 @@ gnc_commodity_table_insert(gnc_commodity_table * table,
     }
 
     /* Prevent setting anything except template in namespace template. */
-    if (g_strcmp0 (ns_name, "template") == 0 &&
+    if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
 	g_strcmp0 (priv->mnemonic, "template") != 0)
     {
 	PWARN("Converting commodity %s from namespace template to "
@@ -2119,7 +2119,7 @@ commodity_table_get_all_noncurrency_commodities(const gnc_commodity_table* table
     {
         gnc_commodity_namespace *ns = NULL;
         if (g_strcmp0((char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
-            || g_strcmp0((char*)(node->data), "template") == 0)
+            || g_strcmp0((char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
             continue;
         ns = gnc_commodity_table_find_namespace(table, (char*)(node->data));
         if (!ns)
@@ -2441,8 +2441,8 @@ gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book)
     gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
     gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
     gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
-    gnc_commodity_table_add_namespace(table, "template", book);
-    c = gnc_commodity_new(book, "template", "template", "template", "template", 1);
+    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book);
+    c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1);
     gnc_commodity_table_insert(table, c);
 
 #include "iso-4217-currencies.c"
diff --git a/src/engine/gnc-commodity.h b/src/engine/gnc-commodity.h
index f353e7f..161996e 100644
--- a/src/engine/gnc-commodity.h
+++ b/src/engine/gnc-commodity.h
@@ -96,6 +96,7 @@ GType gnc_commodity_namespace_get_type(void);
  *  window.
  */
 #define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES"
+#define GNC_COMMODITY_NS_TEMPLATE "template"
 /* The ISO define is deprecated in favor of CURRENCY */
 #define GNC_COMMODITY_NS_ISO    "ISO4217"
 #define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
diff --git a/src/gnome-utils/dialog-commodity.c b/src/gnome-utils/dialog-commodity.c
index 843a155..0278166 100644
--- a/src/gnome-utils/dialog-commodity.c
+++ b/src/gnome-utils/dialog-commodity.c
@@ -636,7 +636,7 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
         /* Skip template, legacy and currency namespaces.
            The latter was added as first entry earlier */
         if ((g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0) ||
-            (g_utf8_collate(node->data, "template" ) == 0) ||
+            (g_utf8_collate(node->data, GNC_COMMODITY_NS_TEMPLATE ) == 0) ||
             (g_utf8_collate(node->data, GNC_COMMODITY_NS_CURRENCY ) == 0))
             continue;
 
@@ -1280,11 +1280,11 @@ gnc_ui_commodity_dialog_to_object(CommodityWindow * w)
     /* Don't allow user to create commodities in namespace
      * "template". That's reserved for scheduled transaction use.
      */
-    if (g_utf8_collate(name_space, "template") == 0)
+    if (g_utf8_collate(name_space, GNC_COMMODITY_NS_TEMPLATE) == 0)
     {
 	gnc_warning_dialog (w->dialog,
 			    _("%s is a reserved commodity type."
-			      " Please use something else."), "template");
+                            " Please use something else."), GNC_COMMODITY_NS_TEMPLATE);
 	return FALSE;
     }
 
diff --git a/src/gnome-utils/gnc-tree-model-split-reg.c b/src/gnome-utils/gnc-tree-model-split-reg.c
index e895a36..a7f8ae8 100644
--- a/src/gnome-utils/gnc-tree-model-split-reg.c
+++ b/src/gnome-utils/gnc-tree-model-split-reg.c
@@ -3292,7 +3292,7 @@ gnc_tree_model_split_reg_event_handler (QofInstance *entity,
             {
                 gnc_commodity *split_com;
                 split_com = xaccAccountGetCommodity (acc);
-                if (g_strcmp0 (gnc_commodity_get_namespace (split_com), "template") != 0)
+                if (g_strcmp0 (gnc_commodity_get_namespace (split_com), GNC_COMMODITY_NS_TEMPLATE) != 0)
                 {
                     DEBUG("Insert trans %p for gl (%s)", trans, name);
                     gtm_sr_insert_trans (model, trans, TRUE);
diff --git a/src/gnome/dialog-commodities.c b/src/gnome/dialog-commodities.c
index 1a0e385..2495cda 100644
--- a/src/gnome/dialog-commodities.c
+++ b/src/gnome/dialog-commodities.c
@@ -283,7 +283,7 @@ gnc_commodities_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
 
     /* Never show the template list */
     name = gnc_commodity_namespace_get_name (name_space);
-    if (g_strcmp0 (name, "template") == 0)
+    if (g_strcmp0 (name, GNC_COMMODITY_NS_TEMPLATE) == 0)
         return FALSE;
 
     /* Check whether or not to show commodities */
diff --git a/src/gnome/dialog-price-edit-db.c b/src/gnome/dialog-price-edit-db.c
index c79504b..7187e7f 100644
--- a/src/gnome/dialog-price-edit-db.c
+++ b/src/gnome/dialog-price-edit-db.c
@@ -356,7 +356,7 @@ gnc_price_dialog_filter_ns_func (gnc_commodity_namespace *name_space,
 
     /* Never show the template list */
     name = gnc_commodity_namespace_get_name (name_space);
-    if (g_strcmp0 (name, "template") == 0)
+    if (g_strcmp0 (name, GNC_COMMODITY_NS_TEMPLATE) == 0)
         return FALSE;
 
     /* See if this namespace has commodities */

commit cc3010d89b1e72524acb85510978d45ab2334892
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Jun 16 20:30:33 2017 +0200

    Bug 781634 followup - separate translatable commodity namespace strings from those uses in storage
    
    There is now a separate GNC_COMMODITY_NS_ISO_GUI label to be used
    everywhere the users needs to read 'Currency namespace'. It's currently
    set to 'Currencies' and can be translated. It may change in to future
    to better describe this namespace is restricted to ISO4217 defined
    currencies as opposed to all the non-formal currencies in vogue today
    (like bitcoin and friends).

diff --git a/src/engine/gnc-commodity.c b/src/engine/gnc-commodity.c
index ec6b529..54ea771 100644
--- a/src/engine/gnc-commodity.c
+++ b/src/engine/gnc-commodity.c
@@ -1660,6 +1660,16 @@ gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
     return ns->name;
 }
 
+const char *
+gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns)
+{
+    if (ns == NULL)
+        return NULL;
+    if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
+        return GNC_COMMODITY_NS_ISO_GUI;
+    return ns->name;
+}
+
 GList *
 gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
 {
diff --git a/src/engine/gnc-commodity.h b/src/engine/gnc-commodity.h
index d2624b6..f353e7f 100644
--- a/src/engine/gnc-commodity.h
+++ b/src/engine/gnc-commodity.h
@@ -98,14 +98,17 @@ GType gnc_commodity_namespace_get_type(void);
 #define GNC_COMMODITY_NS_LEGACY "GNC_LEGACY_CURRENCIES"
 /* The ISO define is deprecated in favor of CURRENCY */
 #define GNC_COMMODITY_NS_ISO    "ISO4217"
-#define GNC_COMMODITY_NS_CURRENCY N_("CURRENCY")
+#define GNC_COMMODITY_NS_CURRENCY "CURRENCY"
 #define GNC_COMMODITY_NS_NASDAQ "NASDAQ"
 #define GNC_COMMODITY_NS_NYSE   "NYSE"
 #define GNC_COMMODITY_NS_EUREX  "EUREX"
 #define GNC_COMMODITY_NS_MUTUAL "FUND"
 #define GNC_COMMODITY_NS_AMEX   "AMEX"
 #define GNC_COMMODITY_NS_ASX    "ASX"
-#define GNC_COMMODITY_NS_NONCURRENCY _("ALL NON-CURRENCY")
+#define GNC_COMMODITY_NS_NONCURRENCY _("All non-currency")
+/* Delay translation of this one, we use it in both translated and untranslated form
+   when presenting the currency related namespace to the user */
+#define GNC_COMMODITY_NS_ISO_GUI N_("Currencies")
 
 typedef GList CommodityList;
 
@@ -804,6 +807,19 @@ gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBoo
  *  owned by the engine and should not be freed by the caller. */
 const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns) ;
 
+/** Return the textual name of a namespace data strucure in a form suitable to
+ * present to the user.
+ *
+ *  @param ns A pointer to the namespace data strucure.
+ *
+ *  @return A pointer to the gui friendly name of the namespace.  This string is
+ *  owned by the engine and should not be freed by the caller.
+ *
+ *  @notes The returned string is marked for translation, but not translated yet.
+ *  If you want it translated pass the return value on to gettext.
+ */
+const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns) ;
+
 
 /** Return a list of all commodity data structures in the specified namespace.
  *
diff --git a/src/gnome-utils/dialog-commodity.c b/src/gnome-utils/dialog-commodity.c
index 6e041e9..843a155 100644
--- a/src/gnome-utils/dialog-commodity.c
+++ b/src/gnome-utils/dialog-commodity.c
@@ -605,27 +605,46 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
         namespaces = g_list_prepend (NULL, GNC_COMMODITY_NS_CURRENCY);
         break;
     }
-/* First insert "ALL" */
+
+    /* First insert "Currencies" entry if requested */
+    if (mode == DIAG_COMM_CURRENCY || mode == DIAG_COMM_ALL)
+    {
+        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+        gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
+                            _(GNC_COMMODITY_NS_ISO_GUI), -1);
+
+        if (init_string &&
+            (g_utf8_collate(GNC_COMMODITY_NS_ISO_GUI, init_string) == 0))
+        {
+            matched = TRUE;
+            match = iter;
+        }
+    }
+
+    /* Next insert insert "All non-currency" entry if requested */
     if (mode == DIAG_COMM_NON_CURRENCY_SELECT || mode == DIAG_COMM_ALL)
     {
         gtk_list_store_append(GTK_LIST_STORE(model), &iter);
         gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
                             GNC_COMMODITY_NS_NONCURRENCY, -1);
     }
-    /* add them to the combobox */
+
+    /* add all others to the combobox */
     namespaces = g_list_sort(namespaces, collate);
     for (node = namespaces; node; node = node->next)
     {
-        if (g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0)
+        /* Skip template, legacy and currency namespaces.
+           The latter was added as first entry earlier */
+        if ((g_utf8_collate(node->data, GNC_COMMODITY_NS_LEGACY) == 0) ||
+            (g_utf8_collate(node->data, "template" ) == 0) ||
+            (g_utf8_collate(node->data, GNC_COMMODITY_NS_CURRENCY ) == 0))
             continue;
-        /* Hide the template entry */
-        if (g_utf8_collate(node->data, "template" ) != 0)
-        {
-            gtk_list_store_append(GTK_LIST_STORE(model), &iter);
-            gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, _(node->data), -1);
-        }
 
-        if (init_string && (g_utf8_collate(node->data, init_string) == 0))
+        gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+        gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, node->data, -1);
+
+        if (init_string &&
+            (g_utf8_collate(node->data, init_string) == 0))
         {
             matched = TRUE;
             match = iter;
@@ -648,16 +667,11 @@ gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
 
     name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
 
-    if (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0)
-    {
-        /* In case the user types in ISO4217, map it to CURRENCY. */
+    /* Map several currency related names to one common namespace */
+    if ((g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0) ||
+        (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
+        (g_strcmp0 (name_space, _(GNC_COMMODITY_NS_ISO_GUI)) == 0))
         return g_strdup(GNC_COMMODITY_NS_CURRENCY);
-    }
-    else if (g_strcmp0 (name_space, _(GNC_COMMODITY_NS_CURRENCY)) == 0)
-    {
-        /* In case the user entered a translation of CURRENCY, return it untranslated. */
-        return g_strdup(GNC_COMMODITY_NS_CURRENCY);
-    }
     else
         return g_strdup(name_space);
 }
diff --git a/src/gnome-utils/gnc-tree-model-commodity.c b/src/gnome-utils/gnc-tree-model-commodity.c
index 5db3802..2085f67 100644
--- a/src/gnome-utils/gnc-tree-model-commodity.c
+++ b/src/gnome-utils/gnc-tree-model-commodity.c
@@ -596,7 +596,7 @@ gnc_tree_model_commodity_get_value (GtkTreeModel *tree_model,
         {
         case GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE:
             g_value_init (value, G_TYPE_STRING);
-            g_value_set_string (value, gnc_commodity_namespace_get_name (name_space));
+            g_value_set_string (value, _(gnc_commodity_namespace_get_gui_name (name_space)));
             break;
         default:
             g_value_init (value, G_TYPE_STRING);
diff --git a/src/gnome-utils/gnc-tree-model-price.c b/src/gnome-utils/gnc-tree-model-price.c
index 20a4409..de89599 100644
--- a/src/gnome-utils/gnc-tree-model-price.c
+++ b/src/gnome-utils/gnc-tree-model-price.c
@@ -708,7 +708,7 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
         {
         case GNC_TREE_MODEL_PRICE_COL_COMMODITY:
             g_value_init (value, G_TYPE_STRING);
-            g_value_set_string (value, gnc_commodity_namespace_get_name (name_space));
+            g_value_set_string (value, gnc_commodity_namespace_get_gui_name (name_space));
             break;
         case GNC_TREE_MODEL_PRICE_COL_VISIBILITY:
             g_value_init (value, G_TYPE_BOOLEAN);
diff --git a/src/gnome-utils/gnc-tree-view-commodity.c b/src/gnome-utils/gnc-tree-view-commodity.c
index eb9a9c2..a6d6f6c 100644
--- a/src/gnome-utils/gnc-tree-view-commodity.c
+++ b/src/gnome-utils/gnc-tree-view-commodity.c
@@ -223,8 +223,8 @@ sort_namespace (GtkTreeModel *f_model,
 
     ns_a = gnc_tree_model_commodity_get_namespace (model, &iter_a);
     ns_b = gnc_tree_model_commodity_get_namespace (model, &iter_b);
-    return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
-                              gnc_commodity_namespace_get_name (ns_b));
+    return safe_utf8_collate (gnc_commodity_namespace_get_gui_name (ns_a),
+                              gnc_commodity_namespace_get_gui_name (ns_b));
 }
 
 static gint
diff --git a/src/gnome-utils/gnc-tree-view-price.c b/src/gnome-utils/gnc-tree-view-price.c
index b0dc599..ae0c525 100644
--- a/src/gnome-utils/gnc-tree-view-price.c
+++ b/src/gnome-utils/gnc-tree-view-price.c
@@ -205,8 +205,8 @@ sort_ns_or_cm (GtkTreeModel *f_model,
     {
         ns_a = gnc_tree_model_price_get_namespace (model, &iter_a);
         ns_b = gnc_tree_model_price_get_namespace (model, &iter_b);
-        return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
-                                  gnc_commodity_namespace_get_name (ns_b));
+        return safe_utf8_collate (gnc_commodity_namespace_get_gui_name (ns_a),
+                                  gnc_commodity_namespace_get_gui_name (ns_b));
     }
 
     comm_a = gnc_tree_model_price_get_commodity (model, &iter_a);



Summary of changes:
 src/backend/xml/gnc-schedxaction-xml-v2.c  |  4 +--
 src/engine/Account.c                       | 40 +++++++++++++++++++++
 src/engine/Account.h                       |  5 +++
 src/engine/SchedXaction.c                  |  2 +-
 src/engine/gnc-commodity.c                 | 20 ++++++++---
 src/engine/gnc-commodity.h                 | 21 +++++++++--
 src/engine/test/utest-Account.c            | 28 +++++++++++++++
 src/gnome-utils/dialog-account.c           | 30 ++++++++--------
 src/gnome-utils/dialog-commodity.c         | 56 +++++++++++++++++++-----------
 src/gnome-utils/gnc-tree-model-commodity.c |  2 +-
 src/gnome-utils/gnc-tree-model-price.c     |  2 +-
 src/gnome-utils/gnc-tree-model-split-reg.c |  2 +-
 src/gnome-utils/gnc-tree-view-commodity.c  |  4 +--
 src/gnome-utils/gnc-tree-view-price.c      |  4 +--
 src/gnome/dialog-commodities.c             |  2 +-
 src/gnome/dialog-price-edit-db.c           |  2 +-
 16 files changed, 170 insertions(+), 54 deletions(-)



More information about the gnucash-changes mailing list