1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 Maxime DOYEN
4 * This file is part of HomeBank.
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "list_account.h"
25 /****************************************************************************/
27 /****************************************************************************/
36 /* our global datas */
37 extern struct HomeBank
*GLOBALS
;
38 extern struct Preferences
*PREFS
;
40 extern gchar
*CYA_ACC_TYPE
[]; //in ui_account.c
43 ** draw some icons according to the stored data structure
46 status_cell_data_function (GtkTreeViewColumn
*col
,
47 GtkCellRenderer
*renderer
,
53 gchar
*iconname
= NULL
;
56 gtk_tree_model_get(model
, iter
,
57 LST_DSPACC_DATATYPE
, &dt
,
58 LST_DSPACC_DATAS
, &acc
,
61 if( dt
== DSPACC_TYPE_NORMAL
)
64 switch(GPOINTER_TO_INT(user_data
))
67 iconname
= (acc
->flags
& AF_ADDED
) ? ICONNAME_NEW
: NULL
;
70 iconname
= (acc
->flags
& AF_CHANGED
) ? ICONNAME_HB_OPE_EDIT
: NULL
;
75 g_object_set(renderer
, "icon-name", iconname
, NULL
);
79 ** draw some text from the stored data structure
83 acc_type_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
88 gtk_tree_model_get(model, iter,
89 LST_DSPACC_DATATYPE, &dt,
90 LST_DSPACC_DATAS, &acc,
93 if( dt == DSPACC_TYPE_NORMAL && acc->type > 0 )
95 g_object_set(renderer, "text", _(CYA_ACC_TYPE[acc->type]), NULL);
98 g_object_set(renderer, "text", NULL, NULL);
103 ** draw some text from the stored data structure
106 text_cell_data_function (GtkTreeViewColumn
*col
,
107 GtkCellRenderer
*renderer
,
116 gtk_tree_model_get(model
, iter
,
117 LST_DSPACC_DATATYPE
, &dt
,
118 LST_DSPACC_DATAS
, &acc
,
119 LST_DSPACC_NAME
, &groupname
,
122 if( dt
== DSPACC_TYPE_NORMAL
)
124 switch(GPOINTER_TO_INT(user_data
))
127 g_object_set(renderer
, "weight", PANGO_WEIGHT_NORMAL
, "text", acc
->name
, NULL
);
130 //g_object_set(renderer, "text", acc->number, NULL);
136 g_object_set(renderer
,
137 "weight", PANGO_WEIGHT_BOLD
,
144 float_cell_data_function (GtkTreeViewColumn
*col
, GtkCellRenderer
*renderer
, GtkTreeModel
*model
, GtkTreeIter
*iter
, gpointer user_data
)
147 gchar buf
[G_ASCII_DTOSTR_BUF_SIZE
];
153 gtk_tree_model_get(model
, iter
,
154 LST_DSPACC_DATATYPE
, &dt
,
155 LST_DSPACC_DATAS
, &acc
,
156 GPOINTER_TO_INT(user_data
), &value
, //LST_DSPACC_(BANK/TODAY/FUTURE)
159 guint32 kcur
= (acc
!= NULL
) ? acc
->kcur
: GLOBALS
->kcur
;
161 if( dt
== DSPACC_TYPE_HEADER
)
166 tp
= gtk_tree_model_get_path(model
, iter
);
167 expanded
= gtk_tree_view_row_expanded(GTK_TREE_VIEW(gtk_tree_view_column_get_tree_view(col
)), tp
);
171 hb_strfmon(buf
, G_ASCII_DTOSTR_BUF_SIZE
-1, value
, kcur
, GLOBALS
->minor
);
172 color
= get_normal_color_amount(value
);
173 g_object_set(renderer
,
174 "weight", PANGO_WEIGHT_NORMAL
,
180 g_object_set(renderer
, "text", NULL
,
186 hb_strfmon(buf
, G_ASCII_DTOSTR_BUF_SIZE
-1, value
, kcur
, GLOBALS
->minor
);
189 weight
= PANGO_WEIGHT_NORMAL
;
191 if( dt
== DSPACC_TYPE_NORMAL
)
193 color
= get_minimum_color_amount(value
, acc
->minimum
);
197 color
= get_normal_color_amount(value
);
198 weight
= PANGO_WEIGHT_BOLD
;
201 //g_print("value='%.2f' buf='%s' color='%s'\n", value, buf, color);
203 g_object_set(renderer
,
213 static GtkTreeViewColumn
*amount_list_account_column(gchar
*name
, gint id
)
215 GtkTreeViewColumn
*column
;
216 GtkCellRenderer
*renderer
;
218 column
= gtk_tree_view_column_new();
219 gtk_tree_view_column_set_title(column
, name
);
221 renderer
= gtk_cell_renderer_text_new ();
222 g_object_set(renderer
, "xalign", 1.0, NULL
);
223 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
224 gtk_tree_view_column_set_cell_data_func(column
, renderer
, float_cell_data_function
, GINT_TO_POINTER(id
), NULL
);
225 gtk_tree_view_column_set_sizing(column
, GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
226 gtk_tree_view_column_set_alignment (column
, 0.5);
227 gtk_tree_view_column_set_spacing( column
, 16 );
228 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPACC_BANK);
234 list_account_compare_func (GtkTreeModel
*model
, GtkTreeIter
*a
, GtkTreeIter
*b
, gpointer userdata
)
238 Account
*entry1
, *entry2
;
239 gchar
*name1
, *name2
;
241 gtk_tree_model_get(model
, a
,
242 LST_DSPACC_DATATYPE
, &dt1
,
243 LST_DSPACC_DATAS
, &entry1
,
244 LST_DSPACC_NAME
, &name1
,
246 gtk_tree_model_get(model
, b
,
247 LST_DSPACC_DATATYPE
, &dt2
,
248 LST_DSPACC_DATAS
, &entry2
,
249 LST_DSPACC_NAME
, &name2
,
252 if( dt1
== DSPACC_TYPE_NORMAL
&& dt2
== DSPACC_TYPE_NORMAL
)
254 retval
= entry1
->pos
- entry2
->pos
;
257 if( dt1
== DSPACC_TYPE_HEADER
&& dt2
== DSPACC_TYPE_HEADER
)
259 retval
= hb_string_utf8_compare(name1
, name2
);
273 gboolean
list_account_selectionfunc(
274 GtkTreeSelection
*selection
, GtkTreeModel
*model
, GtkTreePath
*path
, gboolean path_currently_selected
, gpointer data
)
278 if( gtk_tree_path_get_depth( path
) < 2 )
281 if(gtk_tree_model_get_iter(model
, &iter
, path
))
285 gtk_tree_model_get(model
, &iter
,
286 LST_DSPACC_DATATYPE
, &dt
,
289 if( dt
!= DSPACC_TYPE_NORMAL
)
297 static void list_account_destroy(GtkTreeView
*treeview
, gpointer user_data
)
299 GtkTreeViewColumn
*column
;
301 //todo: unsafe to use direct column index
302 column
= gtk_tree_view_get_column(treeview
, LST_DSPACC_NAME
);
305 PREFS
->pnl_acc_col_acc_width
= gtk_tree_view_column_get_width(column
);
310 GtkWidget
*create_list_account(void)
314 GtkCellRenderer
*renderer
;
315 GtkTreeViewColumn
*column
;
317 /* create list store */
318 store
= gtk_tree_store_new(
320 G_TYPE_INT
, /* fake: status */
321 G_TYPE_STRING
, /* fake: name */
325 G_TYPE_POINTER
, /* datas*/
326 G_TYPE_INT
/* datatype */
330 view
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
331 g_object_unref(store
);
333 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view
), PREFS
->grid_lines
);
334 //gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
335 // COLUMN_DESCRIPTION);
337 //gtk_tree_view_set_enable_tree_lines(GTK_TREE_VIEW (view), TRUE);
339 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view
)), GTK_SELECTION_SINGLE
);
342 column
= gtk_tree_view_column_new();
343 //gtk_tree_view_column_set_title(column, _("Status"));
345 renderer
= gtk_cell_renderer_pixbuf_new ();
346 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
347 gtk_tree_view_column_set_cell_data_func(column
, renderer
, status_cell_data_function
, GINT_TO_POINTER(1), NULL
);
349 renderer
= gtk_cell_renderer_pixbuf_new ();
350 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
351 gtk_tree_view_column_set_cell_data_func(column
, renderer
, status_cell_data_function
, GINT_TO_POINTER(2), NULL
);
353 gtk_tree_view_column_set_alignment (column
, 0.5);
354 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
357 renderer
= gtk_cell_renderer_text_new ();
358 g_object_set(renderer
,
359 "ellipsize", PANGO_ELLIPSIZE_END
,
360 "ellipsize-set", TRUE
,
363 column
= gtk_tree_view_column_new();
364 gtk_tree_view_column_set_title(column
, _("Accounts"));
365 gtk_tree_view_column_pack_start(column
, renderer
, TRUE
);
366 gtk_tree_view_column_set_cell_data_func(column
, renderer
, text_cell_data_function
, GINT_TO_POINTER(LST_DSPACC_NAME
), NULL
);
367 gtk_tree_view_column_set_alignment (column
, 0.5);
368 gtk_tree_view_column_set_min_width(column
, HB_MINWIDTH_LIST
/2);
369 gtk_tree_view_column_set_resizable(column
, TRUE
);
370 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
372 gtk_tree_view_column_set_fixed_width(column
, PREFS
->pnl_acc_col_acc_width
);
373 gtk_tree_view_set_expander_column(GTK_TREE_VIEW (view
), column
);
376 column
= amount_list_account_column(_("Bank"), LST_DSPACC_BANK
);
377 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
380 column
= amount_list_account_column(_("Today"), LST_DSPACC_TODAY
);
381 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
384 column
= amount_list_account_column(_("Future"), LST_DSPACC_FUTURE
);
385 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
387 /* column 7: empty */
388 column
= gtk_tree_view_column_new();
389 gtk_tree_view_append_column (GTK_TREE_VIEW(view
), column
);
392 /* disable selection for level 1 of the tree */
394 gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(view
)), list_account_selectionfunc
, NULL
, NULL
);
397 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store
), list_account_compare_func
, NULL
, NULL
);
398 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store
), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID
, GTK_SORT_ASCENDING
);
400 g_signal_connect (view
, "destroy", G_CALLBACK (list_account_destroy
), NULL
);