2002-03-04 13:34:52 -06:00
|
|
|
/********************************************************************\
|
|
|
|
* gnc-order-xml-v2.c -- order xml i/o implementation *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2002 Derek Atkins <warlord@MIT.EDU> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
2005-11-16 23:35:02 -06:00
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
2002-03-04 13:34:52 -06:00
|
|
|
* *
|
|
|
|
\********************************************************************/
|
2015-11-29 19:11:29 -06:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-10-26 04:14:21 -05:00
|
|
|
#include <config.h>
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-11-29 19:11:29 -06:00
|
|
|
#include "gncOrderP.h"
|
|
|
|
}
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
#include "gnc-xml-helper.h"
|
|
|
|
#include "sixtp.h"
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
#include "sixtp-parsers.h"
|
|
|
|
#include "sixtp-utils.h"
|
|
|
|
#include "sixtp-dom-parsers.h"
|
|
|
|
#include "sixtp-dom-generators.h"
|
|
|
|
|
|
|
|
#include "gnc-xml.h"
|
|
|
|
#include "io-gncxml-gen.h"
|
|
|
|
#include "io-gncxml-v2.h"
|
|
|
|
|
|
|
|
#include "gnc-order-xml-v2.h"
|
|
|
|
#include "gnc-owner-xml-v2.h"
|
|
|
|
|
2014-05-07 10:55:42 -05:00
|
|
|
#define _GNC_MOD_NAME GNC_ID_ORDER
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2005-11-01 21:32:36 -06:00
|
|
|
static QofLogModule log_module = GNC_MOD_IO;
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
const gchar* order_version_string = "2.0.0";
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
/* ids */
|
|
|
|
#define gnc_order_string "gnc:GncOrder"
|
|
|
|
#define order_guid_string "order:guid"
|
|
|
|
#define order_id_string "order:id"
|
|
|
|
#define order_owner_string "order:owner"
|
|
|
|
#define order_opened_string "order:opened"
|
|
|
|
#define order_closed_string "order:closed"
|
|
|
|
#define order_notes_string "order:notes"
|
|
|
|
#define order_reference_string "order:reference"
|
|
|
|
#define order_active_string "order:active"
|
2003-09-11 12:37:01 -05:00
|
|
|
#define order_slots_string "order:slots"
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
static void
|
2016-03-12 16:04:40 -06:00
|
|
|
maybe_add_string (xmlNodePtr ptr, const char* tag, const char* str)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
if (str && strlen (str) > 0)
|
2010-03-02 15:41:05 -06:00
|
|
|
xmlAddChild (ptr, text_to_dom_tree (tag, str));
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static xmlNodePtr
|
2016-03-12 16:04:40 -06:00
|
|
|
order_dom_tree_create (GncOrder* order)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
xmlNodePtr ret;
|
|
|
|
Timespec ts;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ret = xmlNewNode (NULL, BAD_CAST gnc_order_string);
|
|
|
|
xmlSetProp (ret, BAD_CAST "version", BAD_CAST order_version_string);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, guid_to_dom_tree (order_guid_string,
|
|
|
|
qof_instance_get_guid (QOF_INSTANCE (order))));
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, text_to_dom_tree (order_id_string,
|
|
|
|
gncOrderGetID (order)));
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, gnc_owner_to_dom_tree (order_owner_string,
|
|
|
|
gncOrderGetOwner (order)));
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
ts = gncOrderGetDateOpened (order);
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, timespec_to_dom_tree (order_opened_string, &ts));
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
ts = gncOrderGetDateClosed (order);
|
|
|
|
if (ts.tv_sec || ts.tv_nsec)
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, timespec_to_dom_tree (order_closed_string, &ts));
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2002-03-04 13:34:52 -06:00
|
|
|
maybe_add_string (ret, order_notes_string, gncOrderGetNotes (order));
|
|
|
|
maybe_add_string (ret, order_reference_string, gncOrderGetReference (order));
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, int_to_dom_tree (order_active_string,
|
|
|
|
gncOrderGetActive (order)));
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2015-06-13 19:28:11 -05:00
|
|
|
/* xmlAddChild won't do anything with a NULL, so tests are superfluous. */
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlAddChild (ret, qof_instance_slots_to_dom_tree (order_slots_string,
|
|
|
|
QOF_INSTANCE (order)));
|
2014-04-23 22:56:29 -05:00
|
|
|
|
2002-03-04 13:34:52 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
struct order_pdata
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GncOrder* order;
|
|
|
|
QofBook* book;
|
2002-03-04 13:34:52 -06:00
|
|
|
};
|
|
|
|
|
2003-09-01 10:09:25 -05:00
|
|
|
static inline gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
set_string (xmlNodePtr node, GncOrder* order,
|
|
|
|
void (*func) (GncOrder* order, const char* txt))
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
char* txt = dom_tree_to_text (node);
|
|
|
|
g_return_val_if_fail (txt, FALSE);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
func (order, txt);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_free (txt);
|
2010-03-02 15:41:05 -06:00
|
|
|
return TRUE;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2003-09-01 10:09:25 -05:00
|
|
|
static inline gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
set_timespec (xmlNodePtr node, GncOrder* order,
|
|
|
|
void (*func) (GncOrder* order, Timespec ts))
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
Timespec ts = dom_tree_to_timespec (node);
|
|
|
|
if (!dom_tree_valid_timespec (&ts, node->name)) return FALSE;
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
func (order, ts);
|
2010-03-02 15:41:05 -06:00
|
|
|
return TRUE;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2006-11-29 09:13:02 -06:00
|
|
|
static gboolean
|
2002-03-04 13:34:52 -06:00
|
|
|
order_guid_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
|
|
|
GncGUID* guid;
|
|
|
|
GncOrder* order;
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
guid = dom_tree_to_guid (node);
|
2002-03-04 13:34:52 -06:00
|
|
|
g_return_val_if_fail (guid, FALSE);
|
|
|
|
order = gncOrderLookup (pdata->book, guid);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (order)
|
|
|
|
{
|
|
|
|
gncOrderDestroy (pdata->order);
|
|
|
|
pdata->order = order;
|
|
|
|
gncOrderBeginEdit (order);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
gncOrderSetGUID (pdata->order, guid);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_free (guid);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2002-03-04 13:34:52 -06:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_id_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
return set_string (node, pdata->order, gncOrderSetID);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_owner_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2010-03-02 15:41:05 -06:00
|
|
|
GncOwner owner;
|
|
|
|
gboolean ret;
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
ret = gnc_dom_tree_to_owner (node, &owner, pdata->book);
|
|
|
|
if (ret)
|
|
|
|
gncOrderSetOwner (pdata->order, &owner);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return ret;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_opened_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
return set_timespec (node, pdata->order, gncOrderSetDateOpened);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_closed_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
return set_timespec (node, pdata->order, gncOrderSetDateClosed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_notes_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
return set_string (node, pdata->order, gncOrderSetNotes);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_reference_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
return set_string (node, pdata->order, gncOrderSetReference);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
order_active_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
gint64 val;
|
|
|
|
gboolean ret;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
ret = dom_tree_to_integer (node, &val);
|
2002-03-04 13:34:52 -06:00
|
|
|
if (ret)
|
2016-03-12 16:04:40 -06:00
|
|
|
gncOrderSetActive (pdata->order, (gboolean)val);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:37:01 -05:00
|
|
|
static gboolean
|
|
|
|
order_slots_handler (xmlNodePtr node, gpointer order_pdata)
|
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
struct order_pdata* pdata = static_cast<decltype (pdata)> (order_pdata);
|
2014-04-23 22:56:29 -05:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
return dom_tree_create_instance_slots (node, QOF_INSTANCE (pdata->order));
|
2003-09-11 12:37:01 -05:00
|
|
|
}
|
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
static struct dom_tree_handler order_handlers_v2[] =
|
|
|
|
{
|
2002-03-04 13:34:52 -06:00
|
|
|
{ order_guid_string, order_guid_handler, 1, 0 },
|
|
|
|
{ order_id_string, order_id_handler, 1, 0 },
|
|
|
|
{ order_owner_string, order_owner_handler, 1, 0 },
|
|
|
|
{ order_opened_string, order_opened_handler, 1, 0 },
|
|
|
|
{ order_closed_string, order_closed_handler, 0, 0 },
|
|
|
|
{ order_notes_string, order_notes_handler, 0, 0 },
|
|
|
|
{ order_reference_string, order_reference_handler, 0, 0 },
|
|
|
|
{ order_active_string, order_active_handler, 1, 0 },
|
2003-09-11 12:37:01 -05:00
|
|
|
{ order_slots_string, order_slots_handler, 0, 0 },
|
2002-03-04 13:34:52 -06:00
|
|
|
{ NULL, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static GncOrder*
|
2016-03-12 16:04:40 -06:00
|
|
|
dom_tree_to_order (xmlNodePtr node, QofBook* book)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
struct order_pdata order_pdata;
|
|
|
|
gboolean successful;
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
order_pdata.order = gncOrderCreate (book);
|
2002-03-04 13:34:52 -06:00
|
|
|
order_pdata.book = book;
|
2002-11-03 14:21:42 -06:00
|
|
|
gncOrderBeginEdit (order_pdata.order);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
successful = dom_tree_generic_parse (node, order_handlers_v2,
|
|
|
|
&order_pdata);
|
|
|
|
|
2002-11-03 14:21:42 -06:00
|
|
|
if (successful)
|
2010-03-02 15:41:05 -06:00
|
|
|
gncOrderCommitEdit (order_pdata.order);
|
2002-11-03 14:21:42 -06:00
|
|
|
else
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
PERR ("failed to parse order tree");
|
2002-06-16 00:11:33 -05:00
|
|
|
gncOrderDestroy (order_pdata.order);
|
|
|
|
order_pdata.order = NULL;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2002-06-16 00:11:33 -05:00
|
|
|
return order_pdata.order;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
gnc_order_end_handler (gpointer data_for_children,
|
|
|
|
GSList* data_from_children, GSList* sibling_data,
|
|
|
|
gpointer parent_data, gpointer global_data,
|
|
|
|
gpointer* result, const gchar* tag)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
GncOrder* order;
|
2002-03-04 13:34:52 -06:00
|
|
|
xmlNodePtr tree = (xmlNodePtr)data_for_children;
|
2016-03-12 16:04:40 -06:00
|
|
|
gxpf_data* gdata = (gxpf_data*)global_data;
|
|
|
|
QofBook* book = static_cast<decltype (book)> (gdata->bookdata);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
if (parent_data)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK. For some messed up reason this is getting called again with a
|
|
|
|
NULL tag. So we ignore those cases */
|
2010-03-02 15:41:05 -06:00
|
|
|
if (!tag)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
g_return_val_if_fail (tree, FALSE);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
order = dom_tree_to_order (tree, book);
|
2010-03-02 15:41:05 -06:00
|
|
|
if (order != NULL)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
gdata->cb (tag, gdata->parsedata, order);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlFreeNode (tree);
|
2002-03-04 13:34:52 -06:00
|
|
|
|
|
|
|
return order != NULL;
|
|
|
|
}
|
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
static sixtp*
|
|
|
|
order_sixtp_parser_create (void)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
return sixtp_dom_parser_new (gnc_order_end_handler, NULL, NULL);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2003-01-07 14:37:04 -06:00
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
order_should_be_saved (GncOrder* order)
|
2003-01-07 14:37:04 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
const char* id;
|
2003-01-07 14:37:04 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
/* make sure this is a valid order before we save it -- should have an ID */
|
|
|
|
id = gncOrderGetID (order);
|
|
|
|
if (id == NULL || *id == '\0')
|
|
|
|
return FALSE;
|
2003-01-07 14:37:04 -06:00
|
|
|
|
2010-03-02 15:41:05 -06:00
|
|
|
return TRUE;
|
2003-01-07 14:37:04 -06:00
|
|
|
}
|
|
|
|
|
2002-03-04 13:34:52 -06:00
|
|
|
static void
|
2016-03-12 16:04:40 -06:00
|
|
|
do_count (QofInstance* order_p, gpointer count_p)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
int* count = static_cast<decltype (count)> (count_p);
|
|
|
|
if (order_should_be_saved ((GncOrder*) order_p))
|
2010-03-02 15:41:05 -06:00
|
|
|
(*count)++;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-03-12 16:04:40 -06:00
|
|
|
order_get_count (QofBook* book)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
int count = 0;
|
|
|
|
qof_object_foreach (_GNC_MOD_NAME, book, do_count, (gpointer) &count);
|
|
|
|
return count;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-03-12 16:04:40 -06:00
|
|
|
xml_add_order (QofInstance* order_p, gpointer out_p)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
xmlNodePtr node;
|
2016-03-12 16:04:40 -06:00
|
|
|
GncOrder* order = (GncOrder*) order_p;
|
|
|
|
FILE* out = static_cast<decltype (out)> (out_p);
|
2010-03-02 15:41:05 -06:00
|
|
|
|
2016-03-12 16:04:40 -06:00
|
|
|
if (ferror (out))
|
2010-03-02 15:41:05 -06:00
|
|
|
return;
|
|
|
|
if (!order_should_be_saved (order))
|
|
|
|
return;
|
|
|
|
|
|
|
|
node = order_dom_tree_create (order);
|
2016-03-12 16:04:40 -06:00
|
|
|
xmlElemDump (out, NULL, node);
|
2010-03-02 15:41:05 -06:00
|
|
|
xmlFreeNode (node);
|
2016-03-12 16:04:40 -06:00
|
|
|
if (ferror (out) || fprintf (out, "\n") < 0)
|
2010-03-02 15:41:05 -06:00
|
|
|
return;
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
order_write (FILE* out, QofBook* book)
|
2005-11-01 21:32:36 -06:00
|
|
|
{
|
Bug #638225: Sort when saving as XML
Patch by Jim Radford (with code beautified and re-indented by myself):
The attached patches sort the slots, lots, book accounts, bill terms,
customers, employees, entries, invoices, jobs, orders, tax tables and
vendors before saving them to the GnuCash XML file.
This is an attempt to make saves more idempotent thereby facilitating
the use of a revision control system on the GnuCash XML files.
With these patches most of the needless and seemingly random churn is
gone and I can add or remove a transaction and expect
there to be no unrelated changes to the GnuCash file.
I've been using and refining this patches for the last few years, so it has
received quite a bit of testing.
David Fraser adds: Without specific testing, I'm using this on an average-sized gnucash file
(5.7MB) without noticing any particular slowdown in saving, but a wonderful
reduction in diffs when comparing changes.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20067 57a11ea4-9604-0410-9ed3-97b8803252fd
2011-01-11 14:40:19 -06:00
|
|
|
qof_object_foreach_sorted (_GNC_MOD_NAME, book, xml_add_order, (gpointer) out);
|
2016-03-12 16:04:40 -06:00
|
|
|
return ferror (out) == 0;
|
2005-11-01 21:32:36 -06:00
|
|
|
}
|
|
|
|
|
2010-01-31 12:37:28 -06:00
|
|
|
static gboolean
|
2016-03-12 16:04:40 -06:00
|
|
|
order_ns (FILE* out)
|
2002-03-04 13:34:52 -06:00
|
|
|
{
|
2016-03-12 16:04:40 -06:00
|
|
|
g_return_val_if_fail (out, FALSE);
|
|
|
|
return gnc_xml2_write_namespace_decl (out, "order");
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gnc_order_xml_initialize (void)
|
|
|
|
{
|
2010-03-02 15:41:05 -06:00
|
|
|
static GncXmlDataType_t be_data =
|
|
|
|
{
|
|
|
|
GNC_FILE_BACKEND_VERS,
|
|
|
|
gnc_order_string,
|
|
|
|
order_sixtp_parser_create,
|
2016-03-12 16:04:40 -06:00
|
|
|
NULL, /* add_item */
|
2010-03-02 15:41:05 -06:00
|
|
|
order_get_count,
|
|
|
|
order_write,
|
2016-03-12 16:04:40 -06:00
|
|
|
NULL, /* scrub */
|
2010-03-02 15:41:05 -06:00
|
|
|
order_ns,
|
|
|
|
};
|
|
|
|
|
2016-08-04 16:41:40 -05:00
|
|
|
gnc_xml_register_backend(be_data);
|
2002-03-04 13:34:52 -06:00
|
|
|
}
|