r15612 - gnucash/trunk/src - Save/restore recurrence list (schedule) for SXes.
Josh Sled
jsled at cvs.gnucash.org
Sun Feb 18 18:16:06 EST 2007
Author: jsled
Date: 2007-02-18 18:16:05 -0500 (Sun, 18 Feb 2007)
New Revision: 15612
Trac: http://svn.gnucash.org/trac/changeset/15612
Modified:
gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c
gnucash/trunk/src/doc/sx.rst
gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
Log:
Save/restore recurrence list (schedule) for SXes.
Add "allow_file_incompatability" gconf key; emit incompatible elements (sx-enabled and recurrence/schedule) only if allowed.
Modified: gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c 2007-02-18 23:14:17 UTC (rev 15611)
+++ gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c 2007-02-18 23:16:05 UTC (rev 15612)
@@ -45,6 +45,8 @@
#include "sixtp-dom-parsers.h"
+#include "gnc-gconf-utils.h"
+
#define LOG_MOD "gnc.backend.file.sx"
static QofLogModule log_module = LOG_MOD;
#undef G_LOG_DOMAIN
@@ -156,13 +158,27 @@
GDate *date;
gint instCount;
const GUID *templ_acc_guid;
+ gboolean allow_incompat = FALSE;
+ GError *err = NULL;
+ allow_incompat = gnc_gconf_get_bool("dev", "allow_file_incompatability", &err);
+ if (err != NULL)
+ {
+ g_warning("error getting gconf value [%s]", err->message);
+ g_error_free(err);
+ allow_incompat = FALSE;
+ }
+ g_debug("allow_incompatability: [%s]", allow_incompat ? "true" : "false");
+
templ_acc_guid = xaccAccountGetGUID(sx->template_acct);
/* FIXME: this should be the same as the def in io-gncxml-v2.c */
ret = xmlNewNode( NULL, BAD_CAST GNC_SCHEDXACTION_TAG );
- xmlSetProp( ret, BAD_CAST "version", BAD_CAST schedxaction_version_string );
+ if (allow_incompat)
+ xmlSetProp(ret, BAD_CAST "version", BAD_CAST schedxaction_version2_string);
+ else
+ xmlSetProp(ret, BAD_CAST "version", BAD_CAST schedxaction_version_string);
xmlAddChild( ret,
guid_to_dom_tree(SX_ID,
@@ -170,15 +186,18 @@
xmlNewTextChild( ret, NULL, BAD_CAST SX_NAME, BAD_CAST xaccSchedXactionGetName(sx) );
- xmlNewTextChild( ret, NULL, BAD_CAST SX_ENABLED,
- BAD_CAST ( sx->enabled ? "y" : "n" ) );
+ if (allow_incompat)
+ {
+ xmlNewTextChild( ret, NULL, BAD_CAST SX_ENABLED,
+ BAD_CAST ( sx->enabled ? "y" : "n" ) );
+ }
xmlNewTextChild( ret, NULL, BAD_CAST SX_AUTOCREATE,
BAD_CAST ( sx->autoCreateOption ? "y" : "n" ) );
xmlNewTextChild( ret, NULL, BAD_CAST SX_AUTOCREATE_NOTIFY,
BAD_CAST ( sx->autoCreateNotify ? "y" : "n" ) );
xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_CREATE_DAYS,
- sx->advanceCreateDays));
+ sx->advanceCreateDays));
xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_REMIND_DAYS,
sx->advanceRemindDays));
@@ -212,7 +231,7 @@
xmlAddChild( ret,
guid_to_dom_tree(SX_TEMPL_ACCT,
templ_acc_guid));
-
+
/* output freq spec */
fsNode = xmlNewNode(NULL, BAD_CAST SX_FREQSPEC);
xmlAddChild( fsNode,
@@ -220,6 +239,17 @@
xaccSchedXactionGetFreqSpec(sx)) );
xmlAddChild( ret, fsNode );
+ if (allow_incompat)
+ {
+ xmlNodePtr schedule_node = xmlNewNode(NULL, "sx:schedule");
+ GList *schedule = gnc_sx_get_schedule(sx);
+ for (; schedule != NULL; schedule = schedule->next)
+ {
+ xmlAddChild(schedule_node, recurrence_to_dom_tree("gnc:recurrence", (Recurrence*)schedule->data));
+ }
+ xmlAddChild(ret, schedule_node);
+ }
+
/* Output deferred-instance list. */
{
xmlNodePtr instNode;
@@ -450,20 +480,36 @@
}
static gboolean
+sx_schedule_recurrence_handler(xmlNodePtr node, gpointer parsing_data)
+{
+ GList **schedule = (GList**)parsing_data;
+ Recurrence *r = dom_tree_to_recurrence(node);
+ g_return_val_if_fail(r, FALSE);
+ g_debug("parsed recurrence [%s]", recurrenceToString(r));
+ *schedule = g_list_append(*schedule, r);
+ return TRUE;
+}
+
+struct dom_tree_handler sx_recurrence_list_handlers[] = {
+ { "gnc:recurrence", sx_schedule_recurrence_handler, 0, 0 },
+ { NULL, NULL, 0, 0 }
+};
+
+static gboolean
sx_recurrence_handler(xmlNodePtr node, gpointer _pdata)
{
- struct sx_pdata *parsing_data = _pdata;
- GList *schedule;
+ struct sx_pdata *parsing_data = _pdata;
+ GList *schedule = NULL;
- g_return_val_if_fail(node, FALSE);
+ g_return_val_if_fail(node, FALSE);
- //schedule = dom_tree_to_recurrence(node);
- //g_return_val_if_fail(schedule, FALSE);
-
- //gnc_sx_set_schedule(parsing_data->sx, schedule);
- parsing_data->saw_recurrence = TRUE;
-
- return TRUE;
+ if (!dom_tree_generic_parse(node, sx_recurrence_list_handlers, &schedule))
+ return FALSE;
+ g_return_val_if_fail(schedule, FALSE);
+ g_debug("setting freshly-parsed schedule: [%s]", recurrenceListToString(schedule));
+ gnc_sx_set_schedule(parsing_data->sx, schedule);
+ parsing_data->saw_recurrence = TRUE;
+ return TRUE;
}
static
Modified: gnucash/trunk/src/doc/sx.rst
===================================================================
--- gnucash/trunk/src/doc/sx.rst 2007-02-18 23:14:17 UTC (rev 15611)
+++ gnucash/trunk/src/doc/sx.rst 2007-02-18 23:16:05 UTC (rev 15612)
@@ -111,7 +111,7 @@
- [#] type+ui-type -> type
- use Recurrence instead of FreqSpec
-! - [ ] XML migration, handling
+! - [x] XML migration, handling
- xml:freqSpec -> obj:Recurrence
- [x] none (Recurrence doesn't support)
- [x] once
@@ -122,7 +122,7 @@
- [x] weekly, multiple (composite)
- [x] monthly (+quarterly, tri-anually, semi-annually, yearly)
- [x] semi-monthly (composite)
- - [ ] write Recurrences into new-version SX
+ - [x] write Recurrences into new-version SX
- gnc-frequency
! - [x] Support Recurrence
- [x] in
Modified: gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in
===================================================================
--- gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in 2007-02-18 23:14:17 UTC (rev 15611)
+++ gnucash/trunk/src/gnome/schemas/apps_gnucash_general.schemas.in 2007-02-18 23:16:05 UTC (rev 15612)
@@ -494,5 +494,16 @@
</locale>
</schema>
+ <schema>
+ <key>/schemas/apps/gnucash/dev/allow_file_incompatability</key>
+ <applyto>/apps/gnucash/dev/allow_file_incompatability</applyto>
+ <owner>gnucash</owner>
+ <type>bool</type>
+ <default>false</default>
+ <locale name="C">
+ <short>If gnucash should allow file incompatability. If true, then gnucash will (be allowed to) intentionally break file compatability with old versions.</short>
+ </locale>
+ </schema>
+
</schemalist>
</gconfschemafile>
More information about the gnucash-changes
mailing list