31 #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"
45 #include "gnc-job-xml-v2.h"
46 #include "gnc-owner-xml-v2.h"
47 #include "xml-helpers.h"
49 #define _GNC_MOD_NAME GNC_ID_JOB
53 const gchar *job_version_string =
"2.0.0";
56 #define gnc_job_string "gnc:GncJob"
57 #define job_guid_string "job:guid"
58 #define job_id_string "job:id"
59 #define job_name_string "job:name"
60 #define job_reference_string "job:reference"
61 #define job_owner_string "job:owner"
62 #define job_active_string "job:active"
63 #define job_slots_string "job:slots"
69 job_dom_tree_create (
GncJob *job)
74 ret = xmlNewNode(NULL, BAD_CAST gnc_job_string);
75 xmlSetProp(ret, BAD_CAST
"version", BAD_CAST job_version_string);
77 xmlAddChild(ret, guid_to_dom_tree(job_guid_string,
80 xmlAddChild(ret, text_to_dom_tree(job_id_string,
83 xmlAddChild(ret, text_to_dom_tree(job_name_string,
84 gncJobGetName (job)));
86 maybe_add_string (ret, job_reference_string, gncJobGetReference (job));
88 xmlAddChild(ret, gnc_owner_to_dom_tree (job_owner_string,
89 gncJobGetOwner (job)));
91 xmlAddChild(ret, int_to_dom_tree(job_active_string,
92 gncJobGetActive (job)));
94 kf = qof_instance_get_slots (QOF_INSTANCE(job));
97 xmlNodePtr kvpnode = kvp_frame_to_dom_tree(job_slots_string, kf);
100 xmlAddChild(ret, kvpnode);
116 set_string(xmlNodePtr node,
GncJob* job,
117 void (*func)(
GncJob *job,
const char *txt))
119 char* txt = dom_tree_to_text(node);
120 g_return_val_if_fail(txt, FALSE);
130 job_name_handler (xmlNodePtr node, gpointer
job_pdata)
132 struct job_pdata *pdata = job_pdata;
134 return set_string(node, pdata->job, gncJobSetName);
138 job_guid_handler (xmlNodePtr node, gpointer
job_pdata)
140 struct job_pdata *pdata = job_pdata;
144 guid = dom_tree_to_guid(node);
145 g_return_val_if_fail(guid, FALSE);
146 job = gncJobLookup (pdata->book, guid);
149 gncJobDestroy (pdata->job);
151 gncJobBeginEdit (job);
155 gncJobSetGUID(pdata->job, guid);
164 job_id_handler (xmlNodePtr node, gpointer job_pdata)
166 struct job_pdata *pdata = job_pdata;
168 return set_string(node, pdata->job, gncJobSetID);
172 job_reference_handler (xmlNodePtr node, gpointer job_pdata)
174 struct job_pdata *pdata = job_pdata;
176 return set_string(node, pdata->job, gncJobSetReference);
180 job_owner_handler (xmlNodePtr node, gpointer job_pdata)
182 struct job_pdata *pdata = job_pdata;
186 ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
188 gncJobSetOwner (pdata->job, &owner);
194 job_active_handler (xmlNodePtr node, gpointer job_pdata)
196 struct job_pdata *pdata = job_pdata;
200 ret = dom_tree_to_integer(node, &val);
202 gncJobSetActive(pdata->job, (gboolean)val);
208 job_slots_handler (xmlNodePtr node, gpointer job_pdata)
210 struct job_pdata *pdata = job_pdata;
212 return dom_tree_to_kvp_frame_given
213 (node, qof_instance_get_slots (QOF_INSTANCE (pdata->job)));
218 { job_guid_string, job_guid_handler, 1, 0 },
219 { job_id_string, job_id_handler, 1, 0 },
220 { job_name_string, job_name_handler, 1, 0 },
221 { job_reference_string, job_reference_handler, 0, 0 },
222 { job_owner_string, job_owner_handler, 1, 0 },
223 { job_active_string, job_active_handler, 1, 0 },
224 { job_slots_string, job_slots_handler, 0, 0 },
229 dom_tree_to_job (xmlNodePtr node,
QofBook *book)
231 struct job_pdata job_pdata;
234 job_pdata.job = gncJobCreate(book);
235 job_pdata.book = book;
236 gncJobBeginEdit (job_pdata.job);
238 successful = dom_tree_generic_parse (node, job_handlers_v2,
242 gncJobCommitEdit (job_pdata.job);
245 PERR (
"failed to parse job tree");
246 gncJobDestroy (job_pdata.job);
247 job_pdata.job = NULL;
250 return job_pdata.job;
254 gnc_job_end_handler(gpointer data_for_children,
255 GSList* data_from_children, GSList* sibling_data,
256 gpointer parent_data, gpointer global_data,
257 gpointer *result,
const gchar *tag)
260 xmlNodePtr tree = (xmlNodePtr)data_for_children;
262 QofBook *book = gdata->bookdata;
276 g_return_val_if_fail(tree, FALSE);
278 job = dom_tree_to_job(tree, book);
281 gdata->cb(tag, gdata->parsedata, job);
290 job_sixtp_parser_create(
void)
292 return sixtp_dom_parser_new(gnc_job_end_handler, NULL, NULL);
296 job_should_be_saved (
GncJob *job)
301 id = gncJobGetID (job);
302 if (
id == NULL || *
id ==
'\0')
311 int *count = count_p;
312 if (job_should_be_saved ((
GncJob *)job_p))
333 if (!job_should_be_saved (job))
336 node = job_dom_tree_create (job);
337 xmlElemDump(out, NULL, node);
339 if (ferror(out) || fprintf(out,
"\n") < 0)
344 job_write (FILE *out,
QofBook *book)
347 return ferror(out) == 0;
353 g_return_val_if_fail(out, FALSE);
358 gnc_job_xml_initialize (
void)
362 GNC_FILE_BACKEND_VERS,
364 job_sixtp_parser_create,
gboolean qof_object_register_backend(QofIdTypeConst type_name, const char *backend_name, gpointer be_data)
const GncGUID * qof_instance_get_guid(gconstpointer)
#define PERR(format, args...)
void qof_object_foreach_sorted(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
api for GnuCash version 2 XML-based file format
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
gboolean gnc_xml2_write_namespace_decl(FILE *out, const char *name_space)
struct KvpFrameImpl KvpFrame
const gchar * QofLogModule