Merge branch 'maint'

This commit is contained in:
Geert Janssens 2017-06-20 22:35:57 +02:00
commit 12d85ff647
16 changed files with 170 additions and 54 deletions

View File

@ -813,7 +813,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
@ -823,7 +823,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

@ -4146,6 +4146,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)
{

View File

@ -941,6 +941,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);

View File

@ -393,7 +393,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

@ -850,7 +850,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 "
@ -1680,6 +1680,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)
{
@ -1949,7 +1959,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 "
@ -2129,7 +2139,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)
@ -2451,8 +2461,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,16 +96,20 @@ 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 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 +808,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.
*

View File

@ -2214,6 +2214,7 @@ test_xaccAccountType_Stuff (void)
}
/* xaccParentAccountTypesCompatibleWith
* xaccAccountTypesCompatible
* xaccAccountTypesCompatibleWith
guint32
xaccParentAccountTypesCompatibleWith (GNCAccountType type)// C: 5 in 3 */
static void
@ -2235,6 +2236,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;
auto msg1 = g_strdup_printf ("[xaccParentAccountTypesCompatibleWith()] bad account type: %d", ACCT_TYPE_ROOT);
@ -2277,6 +2292,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,

View File

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

View File

@ -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, GNC_COMMODITY_NS_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);
}
@ -1266,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

@ -584,7 +584,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);

View File

@ -694,7 +694,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);

View File

@ -3280,7 +3280,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

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

View File

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

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