void tax_table_delete_table_cb (GtkButton *button, TaxTableWindow *ttw) { g_return_if_fail (ttw); if (!ttw->current_table) return; if (gncTaxTableGetRefcount (ttw->current_table) > 0) { char *message = g_strdup_printf (_("Tax table \"%s\" is in use. You cannot delete it."), gncTaxTableGetName (ttw->current_table)); gnc_error_dialog (ttw->dialog, "%s", message); g_free (message); return; } if (gnc_verify_dialog (ttw->dialog, FALSE, _("Are you sure you want to delete \"%s\"?"), gncTaxTableGetName (ttw->current_table))) { /* Ok, let's remove it */ gnc_suspend_gui_refresh (); gncTaxTableBeginEdit (ttw->current_table); gncTaxTableDestroy (ttw->current_table); ttw->current_table = NULL; ttw->current_entry = NULL; gnc_resume_gui_refresh (); } }
static gboolean taxtable_guid_handler (xmlNodePtr node, gpointer taxtable_pdata) { struct taxtable_pdata *pdata = taxtable_pdata; GncGUID *guid; GncTaxTable *table; guid = dom_tree_to_guid(node); g_return_val_if_fail (guid, FALSE); table = gncTaxTableLookup (pdata->book, guid); if (table) { gncTaxTableDestroy (pdata->table); pdata->table = table; gncTaxTableBeginEdit (table); } else { gncTaxTableSetGUID(pdata->table, guid); } g_free(guid); return TRUE; }
static void taxtable_scrub (QofBook *book) { GList *list = NULL; GList *node; GncTaxTable *parent, *table; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); qof_object_foreach (GNC_ID_ENTRY, book, taxtable_scrub_entries, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, taxtable_scrub_cust, ht); qof_object_foreach (GNC_ID_VENDOR, book, taxtable_scrub_vendor, ht); qof_object_foreach (GNC_ID_TAXTABLE, book, taxtable_scrub_cb, &list); /* destroy the list of "grandchildren" tax tables */ for (node = list; node; node = node->next) { gchar guidstr[GUID_ENCODING_LENGTH+1]; table = static_cast<decltype(table)>(node->data); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr); PINFO ("deleting grandchild taxtable: %s\n", guidstr); /* Make sure the parent has no children */ parent = gncTaxTableGetParent(table); gncTaxTableSetChild(parent, NULL); /* Destroy this tax table */ gncTaxTableBeginEdit(table); gncTaxTableDestroy(table); } /* reset the refcounts as necessary */ g_hash_table_foreach(ht, taxtable_reset_refcount, NULL); g_list_free(list); g_hash_table_destroy(ht); }
static GncTaxTable* dom_tree_to_taxtable (xmlNodePtr node, QofBook *book) { struct taxtable_pdata taxtable_pdata; gboolean successful; taxtable_pdata.table = gncTaxTableCreate (book); taxtable_pdata.book = book; gncTaxTableBeginEdit (taxtable_pdata.table); successful = dom_tree_generic_parse (node, taxtable_handlers_v2, &taxtable_pdata); if (successful) gncTaxTableCommitEdit (taxtable_pdata.table); else { PERR ("failed to parse tax table tree"); gncTaxTableDestroy (taxtable_pdata.table); taxtable_pdata.table = NULL; } return taxtable_pdata.table; }