GncTaxTable *gncTaxTableReturnChild (GncTaxTable *table, gboolean make_new) { GncTaxTable *child = NULL; if (!table) return NULL; if (table->child) return table->child; if (table->parent || table->invisible) return table; if (make_new) { child = gncTaxTableCopy (table); gncTaxTableSetChild (table, child); gncTaxTableSetParent (child, table); } return child; }
static void tt_set_parent( gpointer data, gpointer value ) { GncTaxTable* tt; GncTaxTable* parent; QofBook* pBook; GncGUID* guid = (GncGUID*)value; g_return_if_fail( data != NULL ); g_return_if_fail( GNC_IS_TAXTABLE(data) ); tt = GNC_TAXTABLE(data); pBook = qof_instance_get_book( QOF_INSTANCE(tt) ); if ( guid != NULL ) { parent = gncTaxTableLookup( pBook, guid ); if ( parent != NULL ) { gncTaxTableSetParent( tt, parent ); gncTaxTableSetChild( parent, tt ); } } }
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); }