29 #include "gncCustomerP.h" 31 #include "gncVendorP.h" 32 #include "gncEmployeeP.h" 34 #include "gnc-xml-helper.h" 36 #include "sixtp-utils.h" 37 #include "sixtp-parsers.h" 38 #include "sixtp-utils.h" 39 #include "sixtp-dom-parsers.h" 40 #include "sixtp-dom-generators.h" 43 #include "io-gncxml-gen.h" 46 #include "gnc-owner-xml-v2.h" 48 static QofLogModule log_module = GNC_MOD_IO;
50 const gchar* owner_version_string =
"2.0.0";
53 #define owner_type_string "owner:type" 54 #define owner_id_string "owner:id" 57 gnc_owner_to_dom_tree (
const char* tag,
const GncOwner* owner)
64 case GNC_OWNER_CUSTOMER:
65 type_str = GNC_ID_CUSTOMER;
68 type_str = GNC_ID_JOB;
70 case GNC_OWNER_VENDOR:
71 type_str = GNC_ID_VENDOR;
73 case GNC_OWNER_EMPLOYEE:
74 type_str = GNC_ID_EMPLOYEE;
81 ret = xmlNewNode (NULL, BAD_CAST tag);
82 xmlSetProp (ret, BAD_CAST
"version", BAD_CAST owner_version_string);
84 xmlAddChild (ret, text_to_dom_tree (owner_type_string, type_str));
85 xmlAddChild (ret, guid_to_dom_tree (owner_id_string,
100 owner_type_handler (xmlNodePtr node, gpointer
owner_pdata)
103 char* txt = dom_tree_to_text (node);
104 g_return_val_if_fail (txt, FALSE);
106 if (!g_strcmp0 (txt, GNC_ID_CUSTOMER))
107 gncOwnerInitCustomer (pdata->owner, NULL);
108 else if (!g_strcmp0 (txt, GNC_ID_JOB))
109 gncOwnerInitJob (pdata->owner, NULL);
110 else if (!g_strcmp0 (txt, GNC_ID_VENDOR))
111 gncOwnerInitVendor (pdata->owner, NULL);
112 else if (!g_strcmp0 (txt, GNC_ID_EMPLOYEE))
113 gncOwnerInitEmployee (pdata->owner, NULL);
116 PWARN (
"Unknown owner type: %s", txt);
126 owner_id_handler (xmlNodePtr node, gpointer
owner_pdata)
131 guid = dom_tree_to_guid (node);
132 g_return_val_if_fail (guid, FALSE);
136 case GNC_OWNER_CUSTOMER:
138 GncCustomer* cust = gncCustomerLookup (pdata->book, guid);
141 cust = gncCustomerCreate (pdata->book);
142 gncCustomerSetGUID (cust, guid);
144 gncOwnerInitCustomer (pdata->owner, cust);
149 GncJob* job = gncJobLookup (pdata->book, guid);
152 job = gncJobCreate (pdata->book);
153 gncJobSetGUID (job, guid);
155 gncOwnerInitJob (pdata->owner, job);
158 case GNC_OWNER_VENDOR:
160 GncVendor* vendor = gncVendorLookup (pdata->book, guid);
163 vendor = gncVendorCreate (pdata->book);
164 gncVendorSetGUID (vendor, guid);
166 gncOwnerInitVendor (pdata->owner, vendor);
169 case GNC_OWNER_EMPLOYEE:
171 GncEmployee* employee = gncEmployeeLookup (pdata->book, guid);
174 employee = gncEmployeeCreate (pdata->book);
175 gncEmployeeSetGUID (employee, guid);
177 gncOwnerInitEmployee (pdata->owner, employee);
192 { owner_type_string, owner_type_handler, 1, 0 },
193 { owner_id_string, owner_id_handler, 1, 0 },
198 gnc_dom_tree_to_owner (xmlNodePtr node,
GncOwner* owner, QofBook* book)
206 successful = dom_tree_generic_parse (node, owner_handlers_v2,
211 PERR (
"failed to parse owner tree");
220 g_return_val_if_fail (out, FALSE);
221 return gnc_xml2_write_namespace_decl (out,
"owner");
225 gnc_owner_xml_initialize (
void)
227 static GncXmlDataType_t be_data =
229 GNC_FILE_BACKEND_VERS,
239 gnc_xml_register_backend (be_data);
const GncGUID * gncOwnerGetGUID(const GncOwner *owner)
Get the GncGUID of the immediate owner.
#define PERR(format, args...)
Log a serious error.
#define PWARN(format, args...)
Log a warning.
api for GnuCash version 2 XML-based file format
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
The type used to store guids in C.