void
tax_table_delete_entry_cb (GtkButton *button, TaxTableWindow *ttw)
{
    g_return_if_fail (ttw);
    if (!ttw->current_table || !ttw->current_entry)
        return;

    if (g_list_length (gncTaxTableGetEntries (ttw->current_table)) <= 1)
    {
        char *message = _("You cannot remove the last entry from the tax table. "
                          "Try deleting the tax table if you want to do that.");
        gnc_error_dialog (ttw->dialog, "%s", message);
        return;
    }

    if (gnc_verify_dialog (ttw->dialog, FALSE, "%s",
                           _("Are you sure you want to delete this entry?")))
    {
        /* Ok, let's remove it */
        gnc_suspend_gui_refresh ();
        gncTaxTableBeginEdit (ttw->current_table);
        gncTaxTableRemoveEntry (ttw->current_table, ttw->current_entry);
        gncTaxTableEntryDestroy (ttw->current_entry);
        gncTaxTableChanged (ttw->current_table);
        gncTaxTableCommitEdit (ttw->current_table);
        ttw->current_entry = NULL;
        gnc_resume_gui_refresh ();
    }
}
Example #2
0
static void
gncTaxTableFree (GncTaxTable *table)
{
    GList *list;
    GncTaxTable *child;

    if (!table) return;

    qof_event_gen (&table->inst, QOF_EVENT_DESTROY, NULL);
    CACHE_REMOVE (table->name);
    remObj (table);

    /* destroy the list of entries */
    for (list = table->entries; list; list = list->next)
        gncTaxTableEntryDestroy (list->data);
    g_list_free (table->entries);

    if (!qof_instance_get_destroying(table))
        PERR("free a taxtable without do_free set!");

    /* disconnect from parent */
    if (table->parent)
        gncTaxTableRemoveChild(table->parent, table);

    /* disconnect from the children */
    for (list = table->children; list; list = list->next)
    {
        child = list->data;
        gncTaxTableSetParent(child, NULL);
    }
    g_list_free(table->children);

    /* qof_instance_release (&table->inst); */
    g_object_unref (table);
}
static GncTaxTableEntry*
dom_tree_to_ttentry (xmlNodePtr node, QofBook *book)
{
    struct ttentry_pdata ttentry_pdata;
    gboolean successful;

    ttentry_pdata.ttentry = gncTaxTableEntryCreate ();
    ttentry_pdata.book = book;

    successful = dom_tree_generic_parse (node, ttentry_handlers_v2,
                                         &ttentry_pdata);

    if (!successful)
    {
        PERR ("failed to parse tax table entry tree");
        gncTaxTableEntryDestroy (ttentry_pdata.ttentry);
        ttentry_pdata.ttentry = NULL;
    }

    return ttentry_pdata.ttentry;
}