/* HomeBank -- Free, easy, personal accounting for everyone.
- * Copyright (C) 1995-2017 Maxime DOYEN
+ * Copyright (C) 1995-2019 Maxime DOYEN
*
* This file is part of HomeBank.
*
extern struct Preferences *PREFS;
-gchar *CYA_CAT_TYPE[] = {
- N_("Expense"),
- N_("Income"),
- NULL
-};
+extern gchar *CYA_CAT_TYPE[];
+
static void ui_cat_manage_populate_listview(struct ui_cat_manage_dialog_data *data);
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
-/**
- * ui_cat_comboboxentry_get_name:
- *
- * get the name of the active category or -1
- *
- * Return value: a new allocated name tobe freed with g_free
- *
- */
-gchar *
-ui_cat_comboboxentry_get_name(GtkComboBox *entry_box)
-{
-gchar *cbname;
-gchar *name = NULL;
-
- DB( g_print ("ui_cat_comboboxentry_get_name()\n") );
-
- cbname = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
- if( cbname != NULL)
- {
- name = g_strdup(cbname);
- g_strstrip(name);
- }
-
- return name;
-}
-
-
/**
* ui_cat_comboboxentry_get_key:
*
- * get the key of the active category or -1
+ * get the key of the active category or 0
*
- * Return value: the key or -1
+ * Return value: the key or 0
*
*/
guint32
name = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
- if( name == NULL)
- return -1;
-
item = da_cat_get_by_fullname(name);
- if(item == NULL)
- {
- /* automatic add */
- //todo: check prefs + ask the user here 1st time
- item = da_cat_append_ifnew_by_fullname(name, FALSE);
+ if(item != NULL)
+ return item->key;
+ item = da_cat_append_ifnew_by_fullname(name);
+ if( item != NULL )
+ {
ui_cat_comboboxentry_add(entry_box, item);
+ return item->key;
}
- return item->key;
+ return 0;
}
/**
* ui_cat_comboboxentry_get_key:
*
- * get the key of the active category or -1
+ * get the key of the active category or 0
*
- * Return value: the key or -1
+ * Return value: the key or 0
*
*/
guint32
DB( g_print ("ui_cat_comboboxentry_get_key()\n") );
name = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
- if( name == NULL)
- return -1;
item = da_cat_get_by_fullname(name);
if(item != NULL)
return item->key;
- return -1;
+ return 0;
}
DB( g_print ("ui_cat_comboboxentry_get_key()\n") );
name = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
- if(name == NULL)
- return NULL;
item = da_cat_get_by_fullname(name);
ui_cat_comboboxentry_set_active(GtkComboBox *entry_box, guint32 key)
{
Category *item;
-gchar *fullname;
DB( g_print ("ui_cat_comboboxentry_set_active()\n") );
gtk_entry_set_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))), item->name);
else
{
- fullname = da_cat_get_fullname(item);
- gtk_entry_set_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))), fullname);
- g_free(fullname);
+ gtk_entry_set_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))), item->fullname);
}
return TRUE;
}
gchar *fullname, *name;
- fullname = da_cat_get_fullname(item);
+ fullname = item->fullname;
model = gtk_combo_box_get_model(GTK_COMBO_BOX(entry_box));
if( item->parent == 0 )
LST_CMBCAT_SUBCAT, item->parent == 0 ? 1 : 0,
-1);
- g_free(fullname);
g_free(name);
}
{
pitem = da_cat_get(item->parent);
- type = (item->flags & GF_INCOME) ? '+' : '-';
- fullname = da_cat_get_fullname(item);
+ type = category_get_type_char(item);
+ fullname = item->fullname;
sortname = NULL;
name = NULL;
DB( g_print(" - add [%2d:%2d] '%-12s' '%-12s' '%s' '%s' %d\n", item->parent, item->key, pitem->name, name, fullname, sortname, item->parent == 0 ? 1 : 0) );
g_free(sortname);
- g_free(fullname);
g_free(name);
}
"style", style,
"text", name,
NULL);
+
+ //leak
+ g_free(name);
+
}
gchar *path_str,
gpointer data)
{
- GtkTreeModel *model = (GtkTreeModel *)data;
- GtkTreeIter iter;
- GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
- gboolean fixed;
+GtkTreeModel *model = (GtkTreeModel *)data;
+GtkTreeIter iter, child;
+GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
+gboolean fixed;
+gint n_child;
- /* get toggled iter */
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, LST_DEFCAT_TOGGLE, &fixed, -1);
+ /* get toggled iter */
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter, LST_DEFCAT_TOGGLE, &fixed, -1);
- /* do something with the value */
- fixed ^= 1;
+ /* do something with the value */
+ fixed ^= 1;
- /* set new value */
- gtk_tree_store_set (GTK_TREE_STORE (model), &iter, LST_DEFCAT_TOGGLE, fixed, -1);
+ /* set new value */
+ gtk_tree_store_set (GTK_TREE_STORE (model), &iter, LST_DEFCAT_TOGGLE, fixed, -1);
- /* clean up */
- gtk_tree_path_free (path);
+ /* propagate to child */
+ n_child = gtk_tree_model_iter_n_children (GTK_TREE_MODEL(model), &iter);
+ gtk_tree_model_iter_children (GTK_TREE_MODEL(model), &child, &iter);
+ while(n_child > 0)
+ {
+ gtk_tree_store_set (GTK_TREE_STORE (model), &child, LST_DEFCAT_TOGGLE, fixed, -1);
+
+ n_child--;
+ gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &child);
+ }
+
+ /* clean up */
+ gtk_tree_path_free (path);
}
+
static gint
ui_cat_listview_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
{
else
name = entry->name;
- gchar type = (entry->flags & GF_INCOME) ? '+' : '-';
+ gchar type = category_get_type_char(entry);
#if MYDEBUG
- string = g_markup_printf_escaped ("%d > [%d] %s [%c] %d", entry->key, entry->parent, name, type, entry->flags );
+ string = g_markup_printf_escaped ("%d > [%d] %s [%c] %d %c", entry->key, entry->parent, name, type, entry->flags, (entry->flags & GF_MIXED) ?'m':' ' );
#else
if(entry->key == 0)
string = g_strdup(name);
g_object_unref(store);
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview), PREFS->grid_lines);
-
+ gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW (treeview), TRUE);
+
// column 1: toggle
if( withtoggle == TRUE )
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_set_cell_data_func(column, renderer, ui_cat_listview_text_cell_data_function, GINT_TO_POINTER(LST_DEFCAT_NAME), NULL);
gtk_tree_view_column_set_alignment (column, 0.5);
- gtk_tree_view_column_set_min_width(column, HB_MINWIDTH_LIST);
+ gtk_tree_view_column_set_min_width(column, HB_MINWIDTH_LIST*2);
gtk_tree_view_column_set_sort_column_id (column, LST_DEFCAT_SORT_NAME);
gtk_tree_view_column_set_resizable(column, TRUE);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_set_cell_data_func(column, renderer, ui_cat_listview_count_cell_data_function, GINT_TO_POINTER(LST_DEFCAT_DATAS), NULL);
gtk_tree_view_column_set_alignment (column, 0.5);
+ //gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_sort_column_id (column, LST_DEFCAT_SORT_USED);
gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
}
g_strstrip(item->name);
- /* if cat use new id */
- if(subcat == FALSE)
+ if( strlen(item->name) > 0 )
{
- type = radio_get_active(GTK_CONTAINER(data->RA_type));
- if(type == 1)
- item->flags |= GF_INCOME;
-
- if( da_cat_append(item) )
+ /* if cat use new id */
+ if(subcat == FALSE)
{
- DB( g_print(" => add cat: %p %d, %s type=%d\n", item, subcat, item->name, type) );
- ui_cat_listview_add(GTK_TREE_VIEW(data->LV_cat), item, NULL);
+ type = hbtk_radio_get_active(GTK_CONTAINER(data->RA_type));
+ if(type == 1)
+ item->flags |= GF_INCOME;
+
+ if( da_cat_append(item) )
+ {
+ DB( g_print(" => add cat: %p %d, %s type=%d\n", item, subcat, item->name, type) );
+ ui_cat_listview_add(GTK_TREE_VIEW(data->LV_cat), item, NULL);
+ }
}
- }
- /* if subcat use parent id & gf_income */
- else
- {
- paritem = ui_cat_listview_get_selected_parent(GTK_TREE_VIEW(data->LV_cat), &parent_iter);
- if(paritem)
+ /* if subcat use parent id & gf_income */
+ else
{
- DB( g_print(" => selitem parent: %d, %s\n", paritem->key, paritem->name) );
+ paritem = ui_cat_listview_get_selected_parent(GTK_TREE_VIEW(data->LV_cat), &parent_iter);
+ if(paritem)
+ {
+ DB( g_print(" => selitem parent: %d, %s\n", paritem->key, paritem->name) );
- item->parent = paritem->key;
- item->flags |= (paritem->flags & GF_INCOME);
- item->flags |= GF_SUB;
+ item->parent = paritem->key;
+ item->flags |= (paritem->flags & GF_INCOME);
+ item->flags |= GF_SUB;
- if(da_cat_append(item))
- {
- DB( g_print(" => add subcat: %p %d, %s\n", item, subcat, item->name) );
- ui_cat_listview_add(GTK_TREE_VIEW(data->LV_cat), item, &parent_iter);
+ if(da_cat_append(item))
+ {
+ DB( g_print(" => add subcat: %p %d, %s\n", item, subcat, item->name) );
+ ui_cat_listview_add(GTK_TREE_VIEW(data->LV_cat), item, &parent_iter);
+ }
}
}
}
+ else
+ da_cat_free(item);
gtk_entry_set_text(GTK_ENTRY(tmpwidget),"");
}
Category *parent;
gchar *fromname, *toname = NULL;
- fromname = da_cat_get_fullname(item);
+ fromname = item->fullname;
if( item->parent == 0)
toname = g_strdup(name);
toname
);
- g_free(fromname);
g_free(toname);
}
newcat = da_cat_get (dstcatkey);
+ //#1771720: update count
+ newcat->usage_count += srccat->usage_count;
+ srccat->usage_count = 0;
+
//keep the income type with us
parent = da_cat_get(srccat->parent);
if(parent != NULL && (parent->flags & GF_INCOME))
gint result;
data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
- DB( g_print("\n(defcategory) delete (data=%x)\n", (guint)data) );
+ DB( g_print("\n(defcategory) delete (data=%p)\n", data) );
item = ui_cat_listview_get_selected(GTK_TREE_VIEW(data->LV_cat));
if( item != NULL )
if( result == GTK_RESPONSE_OK )
{
- category_move(item->key, 0);
ui_cat_listview_remove(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_cat)), item->key);
+ category_move(item->key, 0);
da_cat_remove(item->key);
data->change++;
}
struct ui_cat_manage_dialog_data *data;
data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
- DB( g_print("\n(defcategory) expand all (data=%x)\n", (guint)data) );
+ DB( g_print("\n(defcategory) expand all (data=%p)\n", data) );
gtk_tree_view_expand_all(GTK_TREE_VIEW(data->LV_cat));
struct ui_cat_manage_dialog_data *data;
data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
- DB( g_print("\n(defcategory) collapse all (data=%x)\n", (guint)data) );
+ DB( g_print("\n(defcategory) collapse all (data=%p)\n", data) );
gtk_tree_view_collapse_all(GTK_TREE_VIEW(data->LV_cat));
{
gint type;
- type = radio_get_active(GTK_CONTAINER(data->RA_type)) == 1 ? CAT_TYPE_INCOME : CAT_TYPE_EXPENSE;
+ type = hbtk_radio_get_active(GTK_CONTAINER(data->RA_type)) == 1 ? CAT_TYPE_INCOME : CAT_TYPE_EXPENSE;
ui_cat_listview_populate(data->LV_cat, type);
gtk_tree_view_expand_all (GTK_TREE_VIEW(data->LV_cat));
}
{
struct ui_cat_manage_dialog_data data;
GtkWidget *window, *content, *mainvbox, *bbox, *table, *hbox, *vbox, *label, *scrollwin, *treeview;
-GtkWidget *menu, *menuitem, *widget, *image, *tbar;
+GtkWidget *menu, *menuitem, *widget, *image, *tbar, *addreveal;
GtkToolItem *toolitem;
gint w, h, row;
//store our window private data
g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)&data);
- DB( g_print("(defcategory) window=%x, inst_data=%x\n", (guint)window, (guint)&data) );
+ DB( g_print("(defcategory) window=%p, inst_data=%p\n", window, &data) );
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
gtk_box_pack_start (GTK_BOX (mainvbox), table, TRUE, TRUE, 0);
row = 0;
- bbox = make_radio(CYA_CAT_TYPE, TRUE, GTK_ORIENTATION_HORIZONTAL);
+ bbox = hbtk_radio_new(CYA_CAT_TYPE, TRUE);
data.RA_type = bbox;
gtk_widget_set_halign (bbox, GTK_ALIGN_CENTER);
gtk_grid_attach (GTK_GRID (table), bbox, 0, row, 2, 1);
- widget = radio_get_nth_widget(GTK_CONTAINER(bbox), 1);
- if(widget)
- g_signal_connect (widget, "toggled", G_CALLBACK (ui_cat_manage_type_changed_cb), &data);
+ hbtk_radio_connect (GTK_CONTAINER(bbox), "toggled", G_CALLBACK (ui_cat_manage_type_changed_cb), &data);
menu = gtk_menu_new ();
gtk_widget_set_halign (menu, GTK_ALIGN_END);
gtk_widget_set_halign (widget, GTK_ALIGN_END);
gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
- row++;
- widget = gtk_entry_new ();
- data.ST_name1 = widget;
- gtk_entry_set_placeholder_text(GTK_ENTRY(data.ST_name1), _("new category") );
- gtk_widget_set_hexpand (widget, TRUE);
- gtk_grid_attach (GTK_GRID (table), widget, 0, row, 2, 1);
-
- // subcategory + add button
- row++;
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
- gtk_grid_attach (GTK_GRID (table), hbox, 0, row, 2, 1);
- data.LA_category = gtk_label_new(NULL);
- gtk_box_pack_start (GTK_BOX (hbox), data.LA_category, FALSE, FALSE, 0);
- label = gtk_label_new(":");
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- data.ST_name2 = gtk_entry_new ();
- gtk_entry_set_placeholder_text(GTK_ENTRY(data.ST_name2), _("new subcategory") );
- gtk_box_pack_start (GTK_BOX (hbox), data.ST_name2, TRUE, TRUE, 0);
-
//list
row++;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
data.BT_collapse = widget;
gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+ // subcategory + add button
+ row++;
+ addreveal = gtk_revealer_new ();
+ gtk_grid_attach (GTK_GRID (table), addreveal, 0, row, 2, 1);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
+ gtk_container_add(GTK_CONTAINER(addreveal), vbox);
+
+ widget = gtk_entry_new ();
+ data.ST_name1 = widget;
+ gtk_entry_set_placeholder_text(GTK_ENTRY(data.ST_name1), _("new category") );
+ gtk_widget_set_hexpand (widget, TRUE);
+ gtk_container_add (GTK_CONTAINER (vbox), widget);
+
+ row++;
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+ data.LA_category = gtk_label_new(NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), data.LA_category, FALSE, FALSE, 0);
+ label = gtk_label_new(":");
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ data.ST_name2 = gtk_entry_new ();
+ gtk_entry_set_placeholder_text(GTK_ENTRY(data.ST_name2), _("new subcategory") );
+ gtk_box_pack_start (GTK_BOX (hbox), data.ST_name2, TRUE, TRUE, 0);
+
row++;
bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
gtk_box_set_spacing (GTK_BOX (bbox), SPACING_SMALL);
gtk_grid_attach (GTK_GRID (table), bbox, 0, row, 2, 1);
+ data.BT_add = gtk_toggle_button_new_with_mnemonic(_("_Add"));
+ gtk_container_add (GTK_CONTAINER (bbox), data.BT_add);
+
+ //todo: useless ?
data.BT_edit = gtk_button_new_with_mnemonic(_("_Edit"));
gtk_container_add (GTK_CONTAINER (bbox), data.BT_edit);
data.BT_delete = gtk_button_new_with_mnemonic(_("_Delete"));
gtk_container_add (GTK_CONTAINER (bbox), data.BT_delete);
-
- /*row++;
- widget = gtk_check_button_new_with_mnemonic(_("I_ncome"));
- data.CM_type = widget;
- gtk_grid_attach (GTK_GRID (table), widget, 0, row, 3, 1);*/
-
-
//connect all our signals
+ g_object_bind_property (data.BT_add, "active", addreveal, "reveal-child", G_BINDING_BIDIRECTIONAL);
+
g_signal_connect (G_OBJECT (data.ST_name1), "activate", G_CALLBACK (ui_cat_manage_dialog_add), GINT_TO_POINTER(FALSE));
g_signal_connect (G_OBJECT (data.ST_name2), "activate", G_CALLBACK (ui_cat_manage_dialog_add), GINT_TO_POINTER(TRUE));