Account* gnc_sx_get_template_transaction_account(SchedXaction *sx) { Account *template_root, *sx_template_acct; char sx_guid_str[GUID_ENCODING_LENGTH+1]; template_root = gnc_book_get_template_root(gnc_get_current_book()); guid_to_string_buff(xaccSchedXactionGetGUID(sx), sx_guid_str); sx_template_acct = gnc_account_lookup_by_name(template_root, sx_guid_str); return sx_template_acct; }
xmlNodePtr gnc_schedXaction_dom_tree_create(SchedXaction *sx) { xmlNodePtr ret; const GDate *date; gint instCount; const GncGUID *templ_acc_guid; gboolean allow_2_2_incompat = TRUE; gchar *name = g_strdup (xaccSchedXactionGetName(sx)); 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); if (allow_2_2_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, xaccSchedXactionGetGUID(sx)) ); xmlNewTextChild( ret, NULL, BAD_CAST SX_NAME, checked_char_cast (name)); g_free (name); if (allow_2_2_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)); xmlAddChild(ret, int_to_dom_tree(SX_ADVANCE_REMIND_DAYS, sx->advanceRemindDays)); instCount = gnc_sx_get_instance_count( sx, NULL ); xmlAddChild( ret, int_to_dom_tree( SX_INSTANCE_COUNT, instCount ) ); xmlAddChild( ret, gdate_to_dom_tree( SX_START, xaccSchedXactionGetStartDate(sx) ) ); date = xaccSchedXactionGetLastOccurDate(sx); if ( g_date_valid( date ) ) { xmlAddChild( ret, gdate_to_dom_tree( SX_LAST, date ) ); } if ( xaccSchedXactionHasOccurDef(sx) ) { xmlAddChild(ret, int_to_dom_tree( SX_NUM_OCCUR, xaccSchedXactionGetNumOccur(sx))); xmlAddChild(ret, int_to_dom_tree( SX_REM_OCCUR, xaccSchedXactionGetRemOccur(sx))); } else if ( xaccSchedXactionHasEndDate(sx) ) { xmlAddChild( ret, gdate_to_dom_tree( SX_END, xaccSchedXactionGetEndDate(sx) ) ); } /* output template account GncGUID */ xmlAddChild( ret, guid_to_dom_tree(SX_TEMPL_ACCT, templ_acc_guid)); if (allow_2_2_incompat) { xmlNodePtr schedule_node = xmlNewNode(NULL, BAD_CAST "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; SXTmpStateData *tsd; GList *l; for ( l = gnc_sx_get_defer_instances( sx ); l; l = l->next ) { tsd = (SXTmpStateData*)l->data; instNode = xmlNewNode( NULL, BAD_CAST SX_DEFER_INSTANCE ); if ( g_date_valid( &tsd->last_date ) ) { xmlAddChild( instNode, gdate_to_dom_tree( SX_LAST, &tsd->last_date ) ); } xmlAddChild( instNode, int_to_dom_tree( SX_REM_OCCUR, tsd->num_occur_rem ) ); xmlAddChild( instNode, int_to_dom_tree( SX_INSTANCE_COUNT, tsd->num_inst ) ); xmlAddChild( ret, instNode ); } } /* output kvp_frame */ { xmlNodePtr kvpnode = kvp_frame_to_dom_tree( SX_SLOTS, xaccSchedXactionGetSlots(sx) ); if ( kvpnode ) { xmlAddChild(ret, kvpnode); } } return ret; }
static gboolean gnc_schedXaction_end_handler(gpointer data_for_children, GSList* data_from_children, GSList* sibling_data, gpointer parent_data, gpointer global_data, gpointer *result, const gchar *tag) { SchedXaction *sx; gboolean successful = FALSE; xmlNodePtr tree = (xmlNodePtr)data_for_children; gxpf_data *gdata = (gxpf_data*)global_data; struct sx_pdata sx_pdata; if ( parent_data ) { return TRUE; } if ( !tag ) { return TRUE; } g_return_val_if_fail( tree, FALSE ); sx = xaccSchedXactionMalloc( gdata->bookdata ); memset(&sx_pdata, 0, sizeof(sx_pdata)); sx_pdata.sx = sx; sx_pdata.book = gdata->bookdata; g_assert( sx_dom_handlers != NULL ); successful = dom_tree_generic_parse( tree, sx_dom_handlers, &sx_pdata ); if (!successful) { g_critical("failed to parse scheduled xaction"); xmlElemDump( stdout, NULL, tree ); gnc_sx_begin_edit( sx ); xaccSchedXactionDestroy( sx ); goto done; } if (tree->properties) { gchar *sx_name = xaccSchedXactionGetName(sx); xmlAttr *attr; for (attr = tree->properties; attr != NULL; attr = attr->next) { xmlChar *attr_value = attr->children->content; g_debug("sx attribute name[%s] value[%s]", attr->name, attr_value); if (strcmp((const char *)attr->name, "version") != 0) { g_warning("unknown sx attribute [%s]", attr->name); continue; } // if version == 1.0.0: ensure freqspec, no recurrence // if version == 2.0.0: ensure recurrence, no freqspec. if (strcmp((const char *)attr_value, schedxaction_version_string) == 0) { if (!sx_pdata.saw_freqspec) g_critical("did not see freqspec in version 1 sx [%s]", sx_name); if (sx_pdata.saw_recurrence) g_warning("saw recurrence in supposedly version 1 sx [%s]", sx_name); } if (strcmp((const char *)attr_value, schedxaction_version2_string) == 0) { if (sx_pdata.saw_freqspec) g_warning("saw freqspec in version 2 sx [%s]", sx_name); if (!sx_pdata.saw_recurrence) g_critical("did not find recurrence in version 2 sx [%s]", sx_name); } } } // generic_callback -> book_callback: insert the SX in the book gdata->cb( tag, gdata->parsedata, sx ); /* FIXME: this should be removed somewhere near 1.8 release time. */ if ( sx->template_acct == NULL ) { Account *ra = NULL; const char *id = NULL; Account *acct = NULL; sixtp_gdv2 *sixdata = gdata->parsedata; QofBook *book; book = sixdata->book; /* We're dealing with a pre-200107<near-end-of-month> rgmerk change re: storing template accounts. */ /* Fix: get account with name of our GncGUID from the template accounts. Make that our template_acct pointer. */ /* THREAD-UNSAFE */ id = guid_to_string( xaccSchedXactionGetGUID( sx ) ); ra = gnc_book_get_template_root(book); if ( ra == NULL ) { g_warning( "Error getting template root account from being-parsed Book." ); xmlFreeNode( tree ); return FALSE; } acct = gnc_account_lookup_by_name( ra, id ); if ( acct == NULL ) { g_warning("no template account with name [%s]", id); xmlFreeNode( tree ); return FALSE; } g_debug("template account name [%s] for SX with GncGUID [%s]", xaccAccountGetName( acct ), id ); /* FIXME: free existing template account. * HUH????? We only execute this if there isn't * currently an existing template account, don't we? * <rgmerk> */ sx->template_acct = acct; } done: xmlFreeNode( tree ); return successful; }