#include "homebank.h"
#include "hb-category.h"
+#include "ext.h"
+#include "refcount.h"
+
/****************************************************************************/
/* Debug macros */
Category *
da_cat_clone(Category *src_item)
{
-Category *new_item = g_memdup(src_item, sizeof(Category));
+Category *new_item = rc_dup(src_item, sizeof(Category));
DB( g_print("da_cat_clone\n") );
if(new_item)
da_cat_free(Category *item)
{
DB( g_print("da_cat_free\n") );
- if(item != NULL)
+ if(rc_unref(item))
{
DB( g_print(" => %d, %s\n", item->key, item->name) );
g_free(item->name);
g_free(item->fullname);
- g_free(item);
+ rc_free(item);
}
}
da_cat_malloc(void)
{
DB( g_print("da_cat_malloc\n") );
- return g_malloc0(sizeof(Category));
+ return rc_alloc(sizeof(Category));
}
if( parent != NULL )
item->fullname = g_strconcat(parent->name, ":", item->name, NULL);
}
-
+
DB( g_print("- updated %d:'%s' fullname='%s'\n", item->key, item->name, item->fullname) );
}
{
DB( g_print("- renaming %s' => '%s'\n", item->name, newname) );
-
+
g_free(item->name);
item->name = g_strdup(newname);
da_cat_build_fullname(item);
-
+
if( item->parent == 0 )
{
GHashTableIter iter;
gpointer value;
DB( g_print("- updating subcat fullname\n") );
-
+
g_hash_table_iter_init (&iter, GLOBALS->h_cat);
while (g_hash_table_iter_next (&iter, NULL, &value))
{
Category *subcat = value;
-
+
if( subcat->parent == item->key )
da_cat_build_fullname(subcat);
}
DB( g_print("\nda_cat_insert\n") );
DB( g_print("- '%s'\n", item->name) );
-
+
new_key = g_new0(guint32, 1);
*new_key = item->key;
g_hash_table_insert(GLOBALS->h_cat, new_key, item);
da_cat_build_fullname(item);
-
+
return TRUE;
}
if( !cat->fullname )
da_cat_build_fullname(cat);
-
+
existitem = da_cat_get_by_fullname( cat->fullname );
if( existitem == NULL )
{
if( outlen != NULL )
*outlen = len;
-
+
if(len >= 1)
{
g_strstrip(partstr[0]);
Category *parent = NULL;
Category *retval = NULL;
guint len;
-
+
DB( g_print("\nda_cat_get_by_fullname\n") );
if( rawfullname )
parent = da_cat_get_by_name_find_internal(0, partstr[0]);
retval = parent;
}
-
+
if( len == 2 && parent != NULL )
{
retval = da_cat_get_by_name_find_internal(parent->key, partstr[1]);
g_strfreev(partstr);
}
}
-
+
return retval;
}
}
retval = parent;
}
-
+
/* if we have a subcategory - xxx:xxx */
if( len == 2 && parent != NULL )
{
}
retval = newcat;
}
-
+
g_strfreev(partstr);
}
}
g_warning("category consistency: fixed null name");
GLOBALS->changes_count++;
}
-
+
}
}
-void
+void
category_delete_unused(void)
{
GList *lcat, *list;
-
+
lcat = list = g_hash_table_get_values(GLOBALS->h_cat);
while (list != NULL)
{
}
-static void
+static void
category_fill_usage_count(guint32 kcat)
{
Category *cat = da_cat_get (kcat);
for(i=0;i<nbsplit;i++)
{
Split *split = da_splits_get(txn->splits, i);
-
+
category_fill_usage_count(split->kcat);
}
}
else
- category_fill_usage_count(txn->kcat);
+ category_fill_usage_count(txn->kcat);
lnk_txn = g_list_next(lnk_txn);
}
for(i=0;i<nbsplit;i++)
{
Split *split = da_splits_get(entry->splits, i);
-
+
category_fill_usage_count(split->kcat);
}
}
while (lnk_txn != NULL)
{
Transaction *txn = lnk_txn->data;
-
+
if(txn->kcat == key1)
{
txn->kcat = key2;
lnk_txn = g_list_next(lnk_txn);
}
-
+
lnk_acc = g_list_next(lnk_acc);
}
g_list_free(lst_acc);
}
-static gint
+static gint
category_change_type_eval(Category *item, gboolean isIncome)
{
if( (item->flags & (GF_INCOME)) && !isIncome )
}
-gint
+gint
category_change_type(Category *item, gboolean isIncome)
{
gint changes = 0;
GList *lcat, *list;
changes += category_change_type_eval(item, isIncome);
-
+
item->flags &= ~(GF_INCOME); //delete flag
if(isIncome == TRUE)
item->flags |= GF_INCOME;