33#include "gnc-xml-helper.h"
35#include "sixtp-utils.h"
36#include "sixtp-parsers.h"
37#include "sixtp-utils.h"
38#include "sixtp-dom-parsers.h"
39#include "sixtp-dom-generators.h"
42#include "io-gncxml-gen.h"
45#include "sixtp-dom-parsers.h"
47static QofLogModule log_module = GNC_MOD_IO;
49const gchar* account_version_string =
"2.0.0";
52#define gnc_account_string "gnc:account"
53#define act_name_string "act:name"
54#define act_id_string "act:id"
55#define act_type_string "act:type"
56#define act_commodity_string "act:commodity"
57#define act_commodity_scu_string "act:commodity-scu"
58#define act_non_standard_scu_string "act:non-standard-scu"
59#define act_code_string "act:code"
60#define act_description_string "act:description"
61#define act_slots_string "act:slots"
62#define act_parent_string "act:parent"
63#define act_lots_string "act:lots"
66#define act_currency_string "act:currency"
67#define act_currency_scu_string "act:currency-scu"
68#define act_security_string "act:security"
69#define act_security_scu_string "act:security-scu"
70#define act_hidden_string "act:hidden"
71#define act_placeholder_string "act:placeholder"
74gnc_account_dom_tree_create (
Account* act,
76 gboolean allow_incompat)
82 gnc_commodity* acct_commodity;
84 ENTER (
"(account=%p)", act);
86 ret = xmlNewNode (NULL, BAD_CAST gnc_account_string);
87 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST account_version_string);
89 xmlAddChild (ret, text_to_dom_tree (act_name_string,
94 xmlAddChild (ret, text_to_dom_tree (
111 if (acct_commodity != NULL)
113 xmlAddChild (ret, commodity_ref_to_dom_tree (act_commodity_string,
116 xmlAddChild (ret, int_to_dom_tree (act_commodity_scu_string,
120 xmlNewChild (ret, NULL, BAD_CAST act_non_standard_scu_string, NULL);
126 xmlAddChild (ret, text_to_dom_tree (act_code_string, str));
132 xmlAddChild (ret, text_to_dom_tree (act_description_string, str));
136 xmlAddChild (ret, qof_instance_slots_to_dom_tree (act_slots_string,
137 QOF_INSTANCE (act)));
142 xmlAddChild (ret, guid_to_dom_tree (act_parent_string,
147 PINFO (
"lot list=%p", lots);
148 if (lots && !exporting)
150 xmlNodePtr toaddto = xmlNewChild (ret, NULL, BAD_CAST act_lots_string, NULL);
154 for (n = lots; n; n = n->next)
156 GNCLot* lot =
static_cast<decltype (lot)
> (n->data);
157 xmlAddChild (toaddto, gnc_lot_dom_tree_create (lot));
175account_name_handler (xmlNodePtr node, gpointer act_pdata)
177 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
183account_id_handler (xmlNodePtr node, gpointer act_pdata)
185 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
187 auto guid = dom_tree_to_guid (node);
188 g_return_val_if_fail (guid, FALSE);
190 xaccAccountSetGUID (pdata->account, &*guid);
196account_type_handler (xmlNodePtr node, gpointer act_pdata)
198 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
202 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
212account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
214 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
218 ref = dom_tree_to_commodity_ref (node, pdata->book);
225account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
227 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
230 dom_tree_to_integer (node, &val);
237account_hidden_handler (xmlNodePtr node, gpointer act_pdata)
239 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
242 dom_tree_to_boolean (node, &val);
249account_placeholder_handler (xmlNodePtr node, gpointer act_pdata)
251 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
254 dom_tree_to_boolean (node, &val);
261account_non_standard_scu_handler (xmlNodePtr node, gpointer act_pdata)
263 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
275deprecated_account_currency_handler (xmlNodePtr node, gpointer act_pdata)
277 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
280 PWARN (
"Account %s: Obsolete xml tag 'act:currency' will not be preserved.",
282 ref = dom_tree_to_commodity_ref_no_engine (node, pdata->book);
289deprecated_account_currency_scu_handler (xmlNodePtr node, gpointer act_pdata)
291 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
292 PWARN (
"Account %s: Obsolete xml tag 'act:currency-scu' will not be preserved.",
298deprecated_account_security_handler (xmlNodePtr node, gpointer act_pdata)
300 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
303 PWARN (
"Account %s: Obsolete xml tag 'act:security' will not be preserved.",
311 ref = dom_tree_to_commodity_ref_no_engine (node, pdata->book);
323deprecated_account_security_scu_handler (xmlNodePtr node, gpointer act_pdata)
325 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
328 PWARN (
"Account %s: Obsolete xml tag 'act:security-scu' will not be preserved.",
332 dom_tree_to_integer (node, &val);
342account_slots_handler (xmlNodePtr node, gpointer act_pdata)
344 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
345 return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->account));
349account_parent_handler (xmlNodePtr node, gpointer act_pdata)
351 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
354 auto gid = dom_tree_to_guid (node);
355 g_return_val_if_fail (gid, FALSE);
360 g_return_val_if_fail (parent, FALSE);
369account_code_handler (xmlNodePtr node, gpointer act_pdata)
371 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
377account_description_handler (xmlNodePtr node, gpointer act_pdata)
379 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
385account_lots_handler (xmlNodePtr node, gpointer act_pdata)
387 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
390 g_return_val_if_fail (node, FALSE);
391 g_return_val_if_fail (node->xmlChildrenNode, FALSE);
393 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
397 if (g_strcmp0 (
"text", (
char*) mark->name) == 0)
400 lot = dom_tree_to_lot (mark, pdata->book);
416 { act_name_string, account_name_handler, 1, 0 },
417 { act_id_string, account_id_handler, 1, 0 },
418 { act_type_string, account_type_handler, 1, 0 },
419 { act_commodity_string, account_commodity_handler, 0, 0 },
420 { act_commodity_scu_string, account_commodity_scu_handler, 0, 0 },
421 { act_non_standard_scu_string, account_non_standard_scu_handler, 0, 0 },
422 { act_code_string, account_code_handler, 0, 0 },
423 { act_description_string, account_description_handler, 0, 0},
424 { act_slots_string, account_slots_handler, 0, 0 },
425 { act_parent_string, account_parent_handler, 0, 0 },
426 { act_lots_string, account_lots_handler, 0, 0 },
427 { act_hidden_string, account_hidden_handler, 0, 0 },
428 { act_placeholder_string, account_placeholder_handler, 0, 0 },
433 { act_currency_string, deprecated_account_currency_handler, 0, 0 },
434 { act_currency_scu_string, deprecated_account_currency_scu_handler, 0, 0 },
435 { act_security_string, deprecated_account_security_handler, 0, 0 },
436 { act_security_scu_string, deprecated_account_security_scu_handler, 0, 0 },
441gnc_account_end_handler (gpointer data_for_children,
442 GSList* data_from_children, GSList* sibling_data,
443 gpointer parent_data, gpointer global_data,
444 gpointer* result,
const gchar* tag)
447 xmlNodePtr tree = (xmlNodePtr)data_for_children;
448 gxpf_data* gdata = (gxpf_data*)global_data;
449 QofBook* book =
static_cast<decltype (book)
> (gdata->bookdata);
465 g_return_val_if_fail (tree, FALSE);
467 acc = dom_tree_to_account (tree, book);
470 gdata->cb (tag, gdata->parsedata, acc);
485 if (type != ACCT_TYPE_ROOT)
487 root = gnc_book_get_root_account (book);
503dom_tree_to_account (xmlNodePtr node,
QofBook* book)
512 act_pdata.account = accToRet;
513 act_pdata.book = book;
515 successful = dom_tree_generic_parse (node, account_handlers_v2,
523 PERR (
"failed to parse account tree");
532gnc_account_sixtp_parser_create (
void)
534 return sixtp_dom_parser_new (gnc_account_end_handler, NULL, NULL);
This is the private header for the account structure.
Account handling public routines.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
const char * xaccAccountGetDescription(const Account *acc)
Get the account's description.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed.
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship,...
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
int xaccAccountGetCommoditySCUi(const Account *acc)
Return the 'internal' SCU setting.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
void xaccAccountSetCommoditySCU(Account *acc, int scu)
Set the SCU for the account.
gboolean gnc_account_is_root(const Account *account)
This routine indicates whether the specified account is the root node of an account tree.
void xaccAccountSetNonStdSCU(Account *acc, gboolean flag)
Set the flag indicating that this account uses a non-standard SCU.
Account * gnc_account_create_root(QofBook *book)
Create a new root level account.
#define xaccAccountGetGUID(X)
void xaccAccountSetDescription(Account *acc, const char *str)
Set the account's description.
void xaccAccountDestroy(Account *acc)
The xaccAccountDestroy() routine can be used to get rid of an account.
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
Account * xaccMallocAccount(QofBook *book)
Constructor.
void xaccAccountSetCode(Account *acc, const char *str)
Set the account's accounting code.
gboolean xaccAccountGetNonStdSCU(const Account *acc)
Return boolean, indicating whether this account uses a non-standard SCU.
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account's commodity.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id,...
@ ACCT_TYPE_INVALID
Not a type.
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency.
LotList * xaccAccountGetLotList(const Account *acc)
The xaccAccountGetLotList() routine returns a list of all lots in this account.
gboolean xaccAccountStringToType(const char *str, GNCAccountType *type)
Conversion routines for the account types to/from strings that are used in persistent storage,...
const char * xaccAccountTypeEnumAsString(GNCAccountType type)
Conversion routines for the account types to/from strings that are used in persistent storage,...
void DxaccAccountSetCurrency(Account *acc, gnc_commodity *currency)
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
void xaccAccountSetHidden(Account *acc, gboolean val)
Set the "hidden" flag for an account.
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
Set the "placeholder" flag for an account.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
#define PINFO(format, args...)
Print an informational note.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define PERR(format, args...)
Log a serious error.
#define PWARN(format, args...)
Log a warning.
#define ENTER(format, args...)
Print a function entry debugging message.
api for GnuCash version 2 XML-based file format