Store account "hidden" and "placeholder" flags as booleans in the account record and with new

<hidden> and <placeholder> tags in the XML file.  The values are still stored in the slots as
well for backward compatibility.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18246 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-08-13 00:05:37 +00:00
parent 7998d0571d
commit e1318e0c1e
6 changed files with 63 additions and 0 deletions

View File

@ -73,6 +73,8 @@ static const GncSqlColumnTableEntry col_table[] =
(QofAccessFunc)get_parent, set_parent },
{ "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, "code" },
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
{ "hidden", CT_BOOLEAN, 0, 0, "hidden" },
{ "placeholder", CT_BOOLEAN, 0, 0, "placeholder" },
{ NULL }
/*@ +full_init_block @*/
};

View File

@ -68,6 +68,8 @@ const gchar *account_version_string = "2.0.0";
#define act_currency_scu_string "act:currency-scu"
#define act_security_string "act:security"
#define act_security_scu_string "act:security-scu"
#define act_hidden_string "act:hidden"
#define act_placeholder_string "act:placeholder"
xmlNodePtr
gnc_account_dom_tree_create(Account *act,
@ -95,6 +97,13 @@ gnc_account_dom_tree_create(Account *act,
act_type_string,
xaccAccountTypeEnumAsString(xaccAccountGetType(act))));
xmlAddChild(ret, boolean_to_dom_tree(
act_hidden_string,
xaccAccountGetHidden(act)));
xmlAddChild(ret, boolean_to_dom_tree(
act_placeholder_string,
xaccAccountGetPlaceholder(act)));
acct_commodity = xaccAccountGetCommodity(act);
if (acct_commodity != NULL)
{
@ -243,6 +252,30 @@ account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
return TRUE;
}
static gboolean
account_hidden_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gboolean val;
dom_tree_to_boolean(node, &val);
xaccAccountSetHidden(pdata->account, val);
return TRUE;
}
static gboolean
account_placeholder_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gboolean val;
dom_tree_to_boolean(node, &val);
xaccAccountSetPlaceholder(pdata->account, val);
return TRUE;
}
static gboolean
account_non_standard_scu_handler (xmlNodePtr node, gpointer act_pdata)
{
@ -400,6 +433,8 @@ static struct dom_tree_handler account_handlers_v2[] = {
{ act_slots_string, account_slots_handler, 0, 0 },
{ act_parent_string, account_parent_handler, 0, 0 },
{ act_lots_string, account_lots_handler, 0, 0 },
{ act_hidden_string, account_hidden_handler, 0, 0 },
{ act_placeholder_string, account_placeholder_handler, 0, 0 },
/* These should not appear in newer xml files; only in old
* (circa gnucash-1.6) xml files. We maintain them for backward

View File

@ -33,6 +33,12 @@
static QofLogModule log_module = GNC_MOD_IO;
xmlNodePtr
boolean_to_dom_tree(const char* tag, gboolean val)
{
return text_to_dom_tree(tag, val ? "TRUE" : "FALSE");
}
xmlNodePtr
text_to_dom_tree(const char *tag, const char *str)
{

View File

@ -35,6 +35,7 @@
xmlNodePtr text_to_dom_tree(const char *tag, const char *str);
xmlNodePtr int_to_dom_tree(const char *tag, gint64 val);
xmlNodePtr boolean_to_dom_tree(const char* tag, gboolean val);
xmlNodePtr guid_to_dom_tree(const char *tag, const GUID* gid);
xmlNodePtr commodity_ref_to_dom_tree(const char *tag, const gnc_commodity *c);
xmlNodePtr timespec_to_dom_tree(const char *tag, const Timespec *spec);

View File

@ -138,6 +138,24 @@ dom_tree_to_guint(xmlNodePtr node, guint *i)
return ret;
}
gboolean
dom_tree_to_boolean(xmlNodePtr node, gboolean* b)
{
gchar* text;
text = dom_tree_to_text(node);
if (strcasecmp(text, "true") == 0) {
*b = TRUE;
return TRUE;
} else if(strcasecmp(text, "false") == 0) {
*b = FALSE;
return TRUE;
} else {
*b = FALSE;
return FALSE;
}
}
kvp_value*
dom_tree_to_double_kvp_value(xmlNodePtr node)
{

View File

@ -64,6 +64,7 @@ kvp_value* dom_tree_to_frame_kvp_value(xmlNodePtr node);
gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint);
gboolean dom_tree_to_guint16(xmlNodePtr node, guint16 *i);
gboolean dom_tree_to_guint(xmlNodePtr node, guint *i);
gboolean dom_tree_to_boolean(xmlNodePtr node, gboolean* b);
/* higher level structures */
Account* dom_tree_to_account(xmlNodePtr node, QofBook *book);