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

This commit is contained in:
Geert Janssens 2017-06-20 12:06:14 +02:00
parent cc3010d89b
commit 4032d33b48
8 changed files with 15 additions and 14 deletions

View File

@ -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

View File

@ -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 );

View File

@ -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"

View File

@ -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"

View File

@ -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;
}

View File

@ -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);

View File

@ -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 */

View File

@ -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 */