32 #include "gnc-xml-helper.h"
34 #include "sixtp-utils.h"
35 #include "sixtp-parsers.h"
36 #include "sixtp-utils.h"
37 #include "sixtp-dom-parsers.h"
38 #include "sixtp-dom-generators.h"
41 #include "io-gncxml-gen.h"
44 #include "sixtp-dom-parsers.h"
50 const gchar *account_version_string =
"2.0.0";
53 #define gnc_account_string "gnc:account"
54 #define act_name_string "act:name"
55 #define act_id_string "act:id"
56 #define act_type_string "act:type"
57 #define act_commodity_string "act:commodity"
58 #define act_commodity_scu_string "act:commodity-scu"
59 #define act_non_standard_scu_string "act:non-standard-scu"
60 #define act_code_string "act:code"
61 #define act_description_string "act:description"
62 #define act_slots_string "act:slots"
63 #define act_parent_string "act:parent"
64 #define act_lots_string "act:lots"
67 #define act_currency_string "act:currency"
68 #define act_currency_scu_string "act:currency-scu"
69 #define act_security_string "act:security"
70 #define act_security_scu_string "act:security-scu"
71 #define act_hidden_string "act:hidden"
72 #define act_placeholder_string "act:placeholder"
78 gnc_account_dom_tree_create(
Account *act,
80 gboolean allow_incompat)
89 ENTER (
"(account=%p)", act);
91 ret = xmlNewNode(NULL, BAD_CAST gnc_account_string);
92 xmlSetProp(ret, BAD_CAST
"version", BAD_CAST account_version_string);
94 xmlAddChild(ret, text_to_dom_tree(act_name_string,
99 xmlAddChild(ret, text_to_dom_tree(
116 if (acct_commodity != NULL)
118 xmlAddChild(ret, commodity_ref_to_dom_tree(act_commodity_string,
121 xmlAddChild(ret, int_to_dom_tree(act_commodity_scu_string,
125 xmlNewChild(ret, NULL, BAD_CAST act_non_standard_scu_string, NULL);
129 if (str && strlen(str) > 0)
131 xmlAddChild(ret, text_to_dom_tree(act_code_string, str));
135 if (str && strlen(str) > 0)
137 xmlAddChild(ret, text_to_dom_tree(act_description_string, str));
140 kf = qof_instance_get_slots (QOF_INSTANCE (act));
143 xmlNodePtr kvpnode = kvp_frame_to_dom_tree(act_slots_string, kf);
146 xmlAddChild(ret, kvpnode);
154 xmlAddChild(ret, guid_to_dom_tree(act_parent_string,
159 PINFO (
"lot list=%p", lots);
160 if (lots && !exporting)
162 xmlNodePtr toaddto = xmlNewChild(ret, NULL, BAD_CAST act_lots_string, NULL);
166 for (n = lots; n; n = n->next)
169 xmlAddChild(toaddto, gnc_lot_dom_tree_create(lot));
186 static inline gboolean
187 set_string(xmlNodePtr node,
Account* act,
188 void (*func)(
Account *act,
const gchar *txt))
190 gchar* txt = dom_tree_to_text(node);
191 g_return_val_if_fail(txt, FALSE);
201 account_name_handler (xmlNodePtr node, gpointer act_pdata)
209 account_id_handler (xmlNodePtr node, gpointer act_pdata)
214 guid = dom_tree_to_guid(node);
215 g_return_val_if_fail(guid, FALSE);
217 xaccAccountSetGUID(pdata->account, guid);
225 account_type_handler (xmlNodePtr node, gpointer act_pdata)
231 string = (
char*) xmlNodeGetContent (node->xmlChildrenNode);
241 account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
247 ref = dom_tree_to_commodity_ref(node, pdata->book);
254 account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
259 dom_tree_to_integer(node, &val);
266 account_hidden_handler (xmlNodePtr node, gpointer act_pdata)
271 dom_tree_to_boolean(node, &val);
278 account_placeholder_handler (xmlNodePtr node, gpointer act_pdata)
283 dom_tree_to_boolean(node, &val);
290 account_non_standard_scu_handler (xmlNodePtr node, gpointer act_pdata)
304 deprecated_account_currency_handler (xmlNodePtr node, gpointer act_pdata)
309 PWARN(
"Account %s: Obsolete xml tag 'act:currency' will not be preserved.",
311 ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
318 deprecated_account_currency_scu_handler (xmlNodePtr node, gpointer act_pdata)
321 PWARN(
"Account %s: Obsolete xml tag 'act:currency-scu' will not be preserved.",
327 deprecated_account_security_handler (xmlNodePtr node, gpointer act_pdata)
332 PWARN(
"Account %s: Obsolete xml tag 'act:security' will not be preserved.",
340 ref = dom_tree_to_commodity_ref_no_engine(node, pdata->book);
352 deprecated_account_security_scu_handler (xmlNodePtr node, gpointer act_pdata)
357 PWARN(
"Account %s: Obsolete xml tag 'act:security-scu' will not be preserved.",
361 dom_tree_to_integer(node, &val);
371 account_slots_handler (xmlNodePtr node, gpointer act_pdata)
375 return dom_tree_to_kvp_frame_given
376 (node, qof_instance_get_slots (QOF_INSTANCE (pdata->account)));
380 account_parent_handler (xmlNodePtr node, gpointer act_pdata)
386 gid = dom_tree_to_guid(node);
387 g_return_val_if_fail(gid, FALSE);
393 g_return_val_if_fail(parent, FALSE);
404 account_code_handler(xmlNodePtr node, gpointer act_pdata)
412 account_description_handler(xmlNodePtr node, gpointer act_pdata)
420 account_lots_handler(xmlNodePtr node, gpointer act_pdata)
425 g_return_val_if_fail(node, FALSE);
426 g_return_val_if_fail(node->xmlChildrenNode, FALSE);
428 for (mark = node->xmlChildrenNode; mark; mark = mark->next)
432 if (g_strcmp0(
"text", (
char*) mark->name) == 0)
435 lot = dom_tree_to_lot(mark, pdata->book);
451 { act_name_string, account_name_handler, 1, 0 },
452 { act_id_string, account_id_handler, 1, 0 },
453 { act_type_string, account_type_handler, 1, 0 },
454 { act_commodity_string, account_commodity_handler, 0, 0 },
455 { act_commodity_scu_string, account_commodity_scu_handler, 0, 0 },
456 { act_non_standard_scu_string, account_non_standard_scu_handler, 0, 0 },
457 { act_code_string, account_code_handler, 0, 0 },
458 { act_description_string, account_description_handler, 0, 0},
459 { act_slots_string, account_slots_handler, 0, 0 },
460 { act_parent_string, account_parent_handler, 0, 0 },
461 { act_lots_string, account_lots_handler, 0, 0 },
462 { act_hidden_string, account_hidden_handler, 0, 0 },
463 { act_placeholder_string, account_placeholder_handler, 0, 0 },
468 { act_currency_string, deprecated_account_currency_handler, 0, 0 },
469 { act_currency_scu_string, deprecated_account_currency_scu_handler, 0, 0 },
470 { act_security_string, deprecated_account_security_handler, 0, 0 },
471 { act_security_scu_string, deprecated_account_security_scu_handler, 0, 0 },
476 gnc_account_end_handler(gpointer data_for_children,
477 GSList* data_from_children, GSList* sibling_data,
478 gpointer parent_data, gpointer global_data,
479 gpointer *result,
const gchar *tag)
482 xmlNodePtr tree = (xmlNodePtr)data_for_children;
484 QofBook *book = gdata->bookdata;
500 g_return_val_if_fail(tree, FALSE);
502 acc = dom_tree_to_account(tree, book);
505 gdata->cb(tag, gdata->parsedata, acc);
522 root = gnc_book_get_root_account(book);
538 dom_tree_to_account (xmlNodePtr node,
QofBook *book)
547 act_pdata.account = accToRet;
548 act_pdata.book = book;
550 successful = dom_tree_generic_parse (node, account_handlers_v2,
558 PERR (
"failed to parse account tree");
567 gnc_account_sixtp_parser_create(
void)
569 return sixtp_dom_parser_new(gnc_account_end_handler, NULL, NULL);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Account * gnc_account_get_parent(const Account *acc)
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
void gnc_account_append_child(Account *new_parent, Account *child)
gboolean gnc_account_is_root(const Account *account)
gboolean xaccAccountGetNonStdSCU(const Account *acc)
int xaccAccountGetCommoditySCUi(const Account *acc)
#define PINFO(format, args...)
GNCAccountType xaccAccountGetType(const Account *acc)
int xaccAccountGetCommoditySCU(const Account *acc)
const char * xaccAccountGetCode(const Account *acc)
Account * gnc_account_create_root(QofBook *book)
void xaccAccountSetCode(Account *acc, const char *str)
const char * xaccAccountTypeEnumAsString(GNCAccountType type)
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
#define PERR(format, args...)
#define ENTER(format, args...)
void xaccAccountDestroy(Account *acc)
#define PWARN(format, args...)
#define xaccAccountGetGUID(X)
Account handling public routines.
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
api for GnuCash version 2 XML-based file format
const char * xaccAccountGetDescription(const Account *acc)
LotList * xaccAccountGetLotList(const Account *acc)
gboolean xaccAccountStringToType(const char *str, GNCAccountType *type)
void xaccAccountSetCommoditySCU(Account *acc, int scu)
void xaccAccountSetHidden(Account *acc, gboolean val)
void xaccAccountBeginEdit(Account *acc)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
gint qof_instance_guid_compare(const gconstpointer ptr1, const gconstpointer ptr2)
struct KvpFrameImpl KvpFrame
#define LEAVE(format, args...)
Account * xaccMallocAccount(QofBook *book)
void xaccAccountSetDescription(Account *acc, const char *str)
void DxaccAccountSetCurrency(Account *acc, gnc_commodity *currency)
void xaccAccountSetNonStdSCU(Account *acc, gboolean flag)
const char * xaccAccountGetName(const Account *acc)
void xaccAccountCommitEdit(Account *acc)
void xaccAccountSetName(Account *acc, const char *str)
const gchar * QofLogModule
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)