29 #include "gnc-xml-helper.h" 31 #include "sixtp-utils.h" 32 #include "sixtp-parsers.h" 33 #include "sixtp-utils.h" 34 #include "sixtp-dom-parsers.h" 35 #include "sixtp-dom-generators.h" 38 #include "io-gncxml-gen.h" 41 static QofLogModule log_module = GNC_MOD_IO;
43 const gchar* budget_version_string =
"2.0.0";
46 #define gnc_budget_string "gnc:budget" 47 #define bgt_id_string "bgt:id" 48 #define bgt_name_string "bgt:name" 49 #define bgt_description_string "bgt:description" 50 #define bgt_num_periods_string "bgt:num-periods" 51 #define bgt_recurrence_string "bgt:recurrence" 52 #define bgt_slots_string "bgt:slots" 55 gnc_budget_dom_tree_create (GncBudget* bgt)
59 ENTER (
"(budget=%p)", bgt);
61 ret = xmlNewNode (NULL, BAD_CAST gnc_budget_string);
62 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST budget_version_string);
65 xmlAddChild (ret, guid_to_dom_tree (bgt_id_string,
66 gnc_budget_get_guid (bgt)));
68 xmlAddChild (ret, text_to_dom_tree (bgt_name_string,
69 gnc_budget_get_name (bgt)));
71 xmlAddChild (ret, text_to_dom_tree (bgt_description_string,
72 gnc_budget_get_description (bgt)));
74 xmlAddChild (ret, guint_to_dom_tree (bgt_num_periods_string,
75 gnc_budget_get_num_periods (bgt)));
77 xmlAddChild (ret, recurrence_to_dom_tree (bgt_recurrence_string,
78 gnc_budget_get_recurrence (bgt)));
80 xmlAddChild (ret, qof_instance_slots_to_dom_tree (bgt_slots_string,
88 static inline gboolean
89 set_string (xmlNodePtr node, GncBudget* bgt,
90 void (*func) (GncBudget* bgt,
const gchar* txt))
92 gchar* txt = dom_tree_to_text (node);
93 g_return_val_if_fail (txt, FALSE);
101 budget_id_handler (xmlNodePtr node, gpointer bgt)
105 guid = dom_tree_to_guid (node);
106 g_return_val_if_fail (guid, FALSE);
107 qof_instance_set_guid (QOF_INSTANCE (bgt), guid);
113 budget_name_handler (xmlNodePtr node, gpointer bgt)
119 budget_description_handler (xmlNodePtr node, gpointer bgt)
125 budget_num_periods_handler (xmlNodePtr node, gpointer bgt)
129 if (dom_tree_to_guint (node, &num_periods))
139 budget_recurrence_handler (xmlNodePtr node, gpointer bgt)
143 if ((r = dom_tree_to_recurrence (node)) == NULL)
146 gnc_budget_set_recurrence (GNC_BUDGET (bgt), r);
152 budget_slots_handler (xmlNodePtr node, gpointer bgt)
154 return dom_tree_create_instance_slots (node, QOF_INSTANCE (bgt));
159 { bgt_id_string, budget_id_handler, 1, 0 },
160 { bgt_name_string, budget_name_handler, 0, 0 },
161 { bgt_description_string, budget_description_handler, 0, 0 },
162 { bgt_num_periods_string, budget_num_periods_handler, 1, 0 },
163 { bgt_recurrence_string, budget_recurrence_handler, 1, 0 },
164 { bgt_slots_string, budget_slots_handler, 0, 0},
169 gnc_budget_end_handler (gpointer data_for_children,
170 GSList* data_from_children, GSList* sibling_data,
171 gpointer parent_data, gpointer global_data,
172 gpointer* result,
const gchar* tag)
175 xmlNodePtr tree = (xmlNodePtr)data_for_children;
176 gxpf_data* gdata = (gxpf_data*)global_data;
177 QofBook* book =
static_cast<decltype (book)
> (gdata->bookdata);
191 g_return_val_if_fail (tree, FALSE);
193 bgt = dom_tree_to_budget (tree, book);
198 gdata->cb (tag, gdata->parsedata, bgt);
206 dom_tree_to_budget (xmlNodePtr node, QofBook* book)
211 if (!dom_tree_generic_parse (node, budget_handlers, bgt))
213 PERR (
"failed to parse budget tree");
221 gnc_budget_sixtp_parser_create (
void)
223 return sixtp_dom_parser_new (gnc_budget_end_handler, NULL, NULL);
void gnc_budget_set_num_periods(GncBudget *budget, guint num_periods)
Set/Get the number of periods in the Budget.
void gnc_budget_destroy(GncBudget *budget)
Deletes the given budget object.
GncBudget * gnc_budget_new(QofBook *book)
Creates and initializes a Budget.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
api for GnuCash version 2 XML-based file format
void gnc_budget_set_name(GncBudget *budget, const gchar *name)
Set/Get the name of the Budget.
void gnc_budget_set_description(GncBudget *budget, const gchar *description)
Set/Get the description of the Budget.
#define LEAVE(format, args...)
Print a function exit debugging message.
The type used to store guids in C.