static gboolean
billterm_guid_handler (xmlNodePtr node, gpointer billterm_pdata)
{
    struct billterm_pdata *pdata = billterm_pdata;
    GncGUID *guid;
    GncBillTerm *term;

    guid = dom_tree_to_guid(node);
    g_return_val_if_fail (guid, FALSE);
    term = gncBillTermLookup (pdata->book, guid);
    if (term)
    {
        gncBillTermDestroy (pdata->term);
        pdata->term = term;
        gncBillTermBeginEdit (term);
    }
    else
    {
        gncBillTermSetGUID(pdata->term, guid);
    }

    g_free(guid);

    return TRUE;
}
GncBillTerm *
gnc_billterm_xml_find_or_create(QofBook *book, GncGUID *guid)
{
    GncBillTerm *term;

    g_return_val_if_fail(book, NULL);
    g_return_val_if_fail(guid, NULL);
    term = gncBillTermLookup(book, guid);
    DEBUG("looking for billterm %s, found %p", guid_to_string(guid), term);
    if (!term)
    {
        term = gncBillTermCreate(book);
        gncBillTermBeginEdit(term);
        gncBillTermSetGUID(term, guid);
        gncBillTermCommitEdit(term);
        DEBUG("Created term: %p", term);
    }
    else
        gncBillTermDecRef(term);

    return term;
}
示例#3
0
static gboolean
set_parent_child (xmlNodePtr node, struct billterm_pdata *pdata,
                  void (*func)(GncBillTerm *, GncBillTerm *))
{
    GncGUID *guid;
    GncBillTerm *term;

    guid = dom_tree_to_guid(node);
    g_return_val_if_fail (guid, FALSE);
    term = gncBillTermLookup (pdata->book, guid);
    if (!term)
    {
        term = gncBillTermCreate (pdata->book);
        gncBillTermBeginEdit (term);
        gncBillTermSetGUID (term, guid);
        gncBillTermCommitEdit (term);
    }
    g_free (guid);
    g_return_val_if_fail (term, FALSE);
    func (pdata->term, term);

    return TRUE;
}