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" 47 static QofLogModule log_module = GNC_MOD_IO;
49 const 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" 74 gnc_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));
174 static inline gboolean
175 set_string (xmlNodePtr node,
Account* act,
176 void (*func) (
Account* act,
const gchar* txt))
178 gchar* txt = dom_tree_to_text (node);
179 g_return_val_if_fail (txt, FALSE);
189 account_name_handler (xmlNodePtr node, gpointer act_pdata)
191 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
197 account_id_handler (xmlNodePtr node, gpointer act_pdata)
199 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
202 guid = dom_tree_to_guid (node);
203 g_return_val_if_fail (guid, FALSE);
205 xaccAccountSetGUID (pdata->account, guid);
213 account_type_handler (xmlNodePtr node, gpointer act_pdata)
215 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
219 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
229 account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
231 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
235 ref = dom_tree_to_commodity_ref (node, pdata->book);
242 account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
244 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
247 dom_tree_to_integer (node, &val);
254 account_hidden_handler (xmlNodePtr node, gpointer act_pdata)
256 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
259 dom_tree_to_boolean (node, &val);
266 account_placeholder_handler (xmlNodePtr node, gpointer act_pdata)
268 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
271 dom_tree_to_boolean (node, &val);
278 account_non_standard_scu_handler (xmlNodePtr node, gpointer act_pdata)
280 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
292 deprecated_account_currency_handler (xmlNodePtr node, gpointer act_pdata)
294 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
297 PWARN (
"Account %s: Obsolete xml tag 'act:currency' will not be preserved.",
299 ref = dom_tree_to_commodity_ref_no_engine (node, pdata->book);
306 deprecated_account_currency_scu_handler (xmlNodePtr node, gpointer act_pdata)
308 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
309 PWARN (
"Account %s: Obsolete xml tag 'act:currency-scu' will not be preserved.",
315 deprecated_account_security_handler (xmlNodePtr node, gpointer act_pdata)
317 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
320 PWARN (
"Account %s: Obsolete xml tag 'act:security' will not be preserved.",
328 ref = dom_tree_to_commodity_ref_no_engine (node, pdata->book);
340 deprecated_account_security_scu_handler (xmlNodePtr node, gpointer act_pdata)
342 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
345 PWARN (
"Account %s: Obsolete xml tag 'act:security-scu' will not be preserved.",
349 dom_tree_to_integer (node, &val);
359 account_slots_handler (xmlNodePtr node, gpointer act_pdata)
361 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
362 return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->account));
366 account_parent_handler (xmlNodePtr node, gpointer act_pdata)
368 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
372 gid = dom_tree_to_guid (node);
373 g_return_val_if_fail (gid, FALSE);
379 g_return_val_if_fail (parent, FALSE);
390 account_code_handler (xmlNodePtr node, gpointer act_pdata)
392 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
398 account_description_handler (xmlNodePtr node, gpointer act_pdata)
400 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
406 account_lots_handler (xmlNodePtr node, gpointer act_pdata)
408 struct account_pdata* pdata =
static_cast<decltype (pdata)
> (act_pdata);
411 g_return_val_if_fail (node, FALSE);
412 g_return_val_if_fail (node->xmlChildrenNode, FALSE);
414 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
418 if (g_strcmp0 (
"text", (
char*) mark->name) == 0)
421 lot = dom_tree_to_lot (mark, pdata->book);
437 { act_name_string, account_name_handler, 1, 0 },
438 { act_id_string, account_id_handler, 1, 0 },
439 { act_type_string, account_type_handler, 1, 0 },
440 { act_commodity_string, account_commodity_handler, 0, 0 },
441 { act_commodity_scu_string, account_commodity_scu_handler, 0, 0 },
442 { act_non_standard_scu_string, account_non_standard_scu_handler, 0, 0 },
443 { act_code_string, account_code_handler, 0, 0 },
444 { act_description_string, account_description_handler, 0, 0},
445 { act_slots_string, account_slots_handler, 0, 0 },
446 { act_parent_string, account_parent_handler, 0, 0 },
447 { act_lots_string, account_lots_handler, 0, 0 },
448 { act_hidden_string, account_hidden_handler, 0, 0 },
449 { act_placeholder_string, account_placeholder_handler, 0, 0 },
454 { act_currency_string, deprecated_account_currency_handler, 0, 0 },
455 { act_currency_scu_string, deprecated_account_currency_scu_handler, 0, 0 },
456 { act_security_string, deprecated_account_security_handler, 0, 0 },
457 { act_security_scu_string, deprecated_account_security_scu_handler, 0, 0 },
462 gnc_account_end_handler (gpointer data_for_children,
463 GSList* data_from_children, GSList* sibling_data,
464 gpointer parent_data, gpointer global_data,
465 gpointer* result,
const gchar* tag)
468 xmlNodePtr tree = (xmlNodePtr)data_for_children;
469 gxpf_data* gdata = (gxpf_data*)global_data;
470 QofBook* book =
static_cast<decltype (book)
> (gdata->bookdata);
486 g_return_val_if_fail (tree, FALSE);
488 acc = dom_tree_to_account (tree, book);
491 gdata->cb (tag, gdata->parsedata, acc);
508 root = gnc_book_get_root_account (book);
524 dom_tree_to_account (xmlNodePtr node, QofBook* book)
533 act_pdata.account = accToRet;
534 act_pdata.book = book;
536 successful = dom_tree_generic_parse (node, account_handlers_v2,
544 PERR (
"failed to parse account tree");
553 gnc_account_sixtp_parser_create (
void)
555 return sixtp_dom_parser_new (gnc_account_end_handler, NULL, NULL);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
This is the private header for the account structure.
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...
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
gboolean gnc_account_is_root(const Account *account)
This routine indicates whether the specified account is the root node of an account tree...
gboolean xaccAccountGetNonStdSCU(const Account *acc)
Return boolean, indicating whether this account uses a non-standard SCU.
int xaccAccountGetCommoditySCUi(const Account *acc)
Return the 'internal' SCU setting.
#define PINFO(format, args...)
Print an informational note.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Account * gnc_account_create_root(QofBook *book)
Create a new root level account.
void xaccAccountSetCode(Account *acc, const char *str)
Set the account's accounting code.
const char * xaccAccountTypeEnumAsString(GNCAccountType type)
Conversion routines for the account types to/from strings that are used in persistent storage...
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
void xaccAccountDestroy(Account *acc)
The xaccAccountDestroy() routine can be used to get rid of an account.
#define PWARN(format, args...)
Log a warning.
#define xaccAccountGetGUID(X)
Account handling public routines.
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
Set the "placeholder" flag for an account.
api for GnuCash version 2 XML-based file format
const char * xaccAccountGetDescription(const Account *acc)
Get the account's description.
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...
void xaccAccountSetCommoditySCU(Account *acc, int scu)
Set the SCU for the account.
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
void xaccAccountSetHidden(Account *acc, gboolean val)
Set the "hidden" flag for an account.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
#define LEAVE(format, args...)
Print a function exit debugging message.
Account * xaccMallocAccount(QofBook *book)
Constructor.
void xaccAccountSetDescription(Account *acc, const char *str)
Set the account's description.
void DxaccAccountSetCurrency(Account *acc, gnc_commodity *currency)
void xaccAccountSetNonStdSCU(Account *acc, gboolean flag)
Set the flag indicating that this account uses a non-standard SCU.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
The type used to store guids in C.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
The hidden root account of an account tree.
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...