add gitignore
[chaz/homebank] / src / list_upcoming.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20 #include "homebank.h"
21
22 #include "list_upcoming.h"
23
24 /* our global datas */
25 extern struct HomeBank *GLOBALS;
26 extern struct Preferences *PREFS;
27
28
29 static void
30 sched_lateicon_cell_data_function (GtkTreeViewColumn *col,
31 GtkCellRenderer *renderer,
32 GtkTreeModel *model,
33 GtkTreeIter *iter,
34 gpointer user_data)
35 {
36 gint nblate;
37
38 gtk_tree_model_get(model, iter,
39 LST_DSPUPC_NB_LATE, &nblate,
40 -1);
41
42 if( nblate > 0 )
43 {
44 g_object_set(renderer, "pixbuf", GLOBALS->lst_pixbuf[LST_PIXBUF_WARNING], NULL, NULL);
45 }
46 else
47 g_object_set(renderer, "pixbuf", NULL, NULL);
48
49 }
50
51
52
53 /*
54 ** remaining cell function
55 */
56 static void sched_latetext_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
57 {
58 Archive *arc;
59 gchar *markuptxt;
60 gchar *color;
61 gint nblate;
62 //gint weight;
63
64 gtk_tree_model_get(model, iter,
65 LST_DSPUPC_DATAS, &arc,
66 LST_DSPUPC_NB_LATE, &nblate,
67 -1);
68
69 if(arc && nblate > 0)
70 {
71 markuptxt = g_strdup_printf(nblate < 10 ? "%d" : "+10", nblate);
72
73 color = NULL;
74 //weight = PANGO_WEIGHT_NORMAL;
75
76 if(nblate > 0 && PREFS->custom_colors == TRUE)
77 {
78 color = PREFS->color_warn;
79 }
80
81 g_object_set(renderer,
82 //"weight", weight,
83 "foreground", color,
84 "text", markuptxt,
85 NULL);
86
87 g_free(markuptxt);
88 }
89 else
90 g_object_set(renderer, "text", NULL, NULL);
91
92 }
93
94 /*
95 ** remaining cell function
96 */
97
98 /*static void remaining_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
99 {
100 Archive *arc;
101 gchar *markuptxt;
102 guint remaining;
103
104 gtk_tree_model_get(model, iter,
105 LST_DSPUPC_DATAS, &arc,
106 LST_DSPUPC_REMAINING, &remaining,
107 -1);
108
109 if(arc && remaining > 0)
110 {
111 markuptxt = g_strdup_printf("%d", remaining);
112 g_object_set(renderer, "markup", markuptxt, NULL);
113 g_free(markuptxt);
114 }
115 else
116 g_object_set(renderer, "text", NULL, NULL);
117
118 }*/
119
120
121 /*
122 ** date cell function
123 */
124 static void date_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
125 {
126 Archive *arc;
127 gchar buffer[256];
128 GDate *date;
129
130 gtk_tree_model_get(model, iter,
131 LST_DSPUPC_DATAS, &arc,
132 -1);
133
134 if(arc)
135 {
136 date = g_date_new_julian (arc->nextdate);
137 g_date_strftime (buffer, 256-1, PREFS->date_format, date);
138 g_date_free(date);
139
140 //g_snprintf(buf, sizeof(buf), "%d", ope->ope_Date);
141
142 g_object_set(renderer, "text", buffer, NULL);
143
144 }
145 else
146 g_object_set(renderer, "text", NULL, NULL);
147
148 }
149
150 /*
151 ** payee cell function
152 */
153 static void payee_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
154 {
155 Archive *arc;
156 Payee *pay;
157
158 gtk_tree_model_get(model, iter,
159 LST_DSPUPC_DATAS, &arc,
160 -1);
161
162 if(arc)
163 {
164
165 pay = da_pay_get(arc->kpay);
166
167 if(pay != NULL)
168 g_object_set(renderer, "text", pay->name, NULL);
169 }
170 else
171 g_object_set(renderer, "text", NULL, NULL);
172
173 }
174
175 /*
176 ** wording cell function
177 */
178 static void wording_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
179 {
180 Archive *arc;
181 gchar *txt;
182 gint weight;
183
184 gtk_tree_model_get(model, iter,
185 LST_DSPUPC_DATAS, &arc,
186 LST_DSPUPC_WORDING, &txt,
187 -1);
188
189 weight = arc == NULL ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
190
191 g_object_set(renderer, "weight", weight, "text", txt, NULL);
192
193 }
194
195
196 /*
197 ** amount cell function
198 */
199 static void amount_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
200 {
201 Archive *arc;
202 gdouble expense, income, amount;
203 gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
204 gint column = GPOINTER_TO_INT(user_data);
205 gchar *color;
206 gint weight;
207
208 gtk_tree_model_get(model, iter,
209 LST_DSPUPC_DATAS, &arc,
210 LST_DSPUPC_EXPENSE, &expense,
211 LST_DSPUPC_INCOME, &income,
212 -1);
213
214 amount = column == -1 ? expense : income;
215
216 if( amount != 0.0)
217 {
218 //hb_strfmon(buf, G_ASCII_DTOSTR_BUF_SIZE-1, amount, kcur);
219 mystrfmon(buf, G_ASCII_DTOSTR_BUF_SIZE-1, amount, GLOBALS->minor);
220 color = get_normal_color_amount(amount);
221
222 weight = arc == NULL ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
223
224 g_object_set(renderer,
225 "weight", weight,
226 "foreground", color,
227 "text", buf,
228 NULL);
229 }
230 else
231 {
232 g_object_set(renderer, "text", NULL, NULL);
233 }
234
235 }
236
237 /*
238 ** account cell function
239 */
240 static void account_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
241 {
242 Archive *arc;
243 Account *acc;
244 gchar *name = NULL;
245
246 gtk_tree_model_get(model, iter, LST_DSPUPC_DATAS, &arc, -1);
247 if(arc)
248 {
249 acc = da_acc_get(arc->kacc);
250 if( acc )
251 {
252 name = acc->name;
253 }
254 }
255
256 g_object_set(renderer, "text", name, NULL);
257
258 }
259
260
261 static
262 gboolean list_account_selectionfunc(
263 GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer data)
264 {
265 GtkTreeIter iter;
266 Archive *arc;
267
268 if(gtk_tree_model_get_iter(model, &iter, path))
269 {
270 gtk_tree_model_get(model, &iter,
271 LST_DSPUPC_DATAS, &arc,
272 -1);
273
274 if( arc == NULL )
275 return FALSE;
276 }
277
278 return TRUE;
279 }
280
281
282
283 GtkWidget *create_list_upcoming(void)
284 {
285 GtkListStore *store;
286 GtkWidget *view;
287 GtkCellRenderer *renderer;
288 GtkTreeViewColumn *column;
289
290 /* create list store */
291 store = gtk_list_store_new(
292 NUM_LST_DSPUPC,
293 G_TYPE_POINTER,
294 G_TYPE_BOOLEAN, /* payee */
295 G_TYPE_STRING, /* wording */
296 G_TYPE_DOUBLE, /* expense */
297 G_TYPE_DOUBLE, /* income */
298 G_TYPE_BOOLEAN, /* account */
299 G_TYPE_BOOLEAN, /* next on */
300 G_TYPE_INT, /* remaining */
301 G_TYPE_INT /* nb late */
302 );
303
304 //treeview
305 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
306 g_object_unref(store);
307
308 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), PREFS->rules_hint);
309 //gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
310 // COLUMN_DESCRIPTION);
311
312 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), GTK_SELECTION_SINGLE);
313
314 /* column : Late */
315 column = gtk_tree_view_column_new();
316 gtk_tree_view_column_set_title(column, _("Late"));
317
318 renderer = gtk_cell_renderer_pixbuf_new ();
319 gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
320 gtk_tree_view_column_pack_start(column, renderer, TRUE);
321 gtk_tree_view_column_set_cell_data_func(column, renderer, sched_lateicon_cell_data_function, NULL, NULL);
322
323 renderer = gtk_cell_renderer_text_new ();
324 g_object_set(renderer, "xalign", 1.0, NULL);
325 gtk_tree_view_column_pack_start(column, renderer, TRUE);
326 gtk_tree_view_column_set_cell_data_func(column, renderer, sched_latetext_cell_data_function, NULL, NULL);
327
328 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPUPC_NB_LATE);
329 //gtk_tree_view_column_set_resizable(column, TRUE);
330 gtk_tree_view_column_set_alignment (column, 0.5);
331 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
332
333 /* column : Remaining */
334 /*column = gtk_tree_view_column_new();
335 gtk_tree_view_column_set_title(column, _("In"));
336
337 renderer = gtk_cell_renderer_text_new ();
338 g_object_set(renderer, "xalign", 1.0, NULL);
339 gtk_tree_view_column_pack_start(column, renderer, TRUE);
340 gtk_tree_view_column_set_cell_data_func(column, renderer, remaining_cell_data_function, NULL, NULL);
341 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPUPC_REMAINING);
342 //gtk_tree_view_column_set_resizable(column, TRUE);
343 gtk_tree_view_column_set_alignment (column, 0.5);
344 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
345 */
346
347 /* column: Next on */
348 column = gtk_tree_view_column_new();
349 gtk_tree_view_column_set_title(column, _("Next date"));
350 renderer = gtk_cell_renderer_text_new ();
351 gtk_tree_view_column_pack_start(column, renderer, TRUE);
352 gtk_tree_view_column_set_cell_data_func(column, renderer, date_cell_data_function, NULL, NULL);
353 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPUPC_DATE);
354 gtk_tree_view_column_set_resizable(column, TRUE);
355 gtk_tree_view_column_set_alignment (column, 0.5);
356 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
357
358 /* column: Payee */
359 column = gtk_tree_view_column_new();
360 gtk_tree_view_column_set_title(column, _("Payee"));
361 renderer = gtk_cell_renderer_text_new ();
362 gtk_tree_view_column_pack_start(column, renderer, TRUE);
363 gtk_tree_view_column_set_cell_data_func(column, renderer, payee_cell_data_function, NULL, NULL);
364 //gtk_tree_view_column_add_attribute(column, renderer, "text", 1);
365 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPACC_NAME);
366 gtk_tree_view_column_set_resizable(column, TRUE);
367 gtk_tree_view_column_set_alignment (column, 0.5);
368 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
369
370 /* column: Wording */
371 column = gtk_tree_view_column_new();
372 gtk_tree_view_column_set_title(column, _("Memo"));
373 renderer = gtk_cell_renderer_text_new ();
374 gtk_tree_view_column_pack_start(column, renderer, TRUE);
375 gtk_tree_view_column_set_cell_data_func(column, renderer, wording_cell_data_function, NULL, NULL);
376 //gtk_tree_view_column_add_attribute(column, renderer, "text", 2);
377 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPACC_NAME);
378 gtk_tree_view_column_set_resizable(column, TRUE);
379 gtk_tree_view_column_set_alignment (column, 0.5);
380 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
381
382 /* column: Amount */
383 column = gtk_tree_view_column_new();
384 gtk_tree_view_column_set_title(column, _("Expense"));
385 renderer = gtk_cell_renderer_text_new ();
386 g_object_set(renderer, "xalign", 1.0, NULL);
387 gtk_tree_view_column_pack_start(column, renderer, TRUE);
388 gtk_tree_view_column_set_cell_data_func(column, renderer, amount_cell_data_function, GINT_TO_POINTER(-1), NULL);
389 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPACC_NAME);
390 gtk_tree_view_column_set_resizable(column, TRUE);
391 gtk_tree_view_column_set_alignment (column, 0.5);
392 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
393
394 /* column: Amount */
395 column = gtk_tree_view_column_new();
396 gtk_tree_view_column_set_title(column, _("Income"));
397 renderer = gtk_cell_renderer_text_new ();
398 g_object_set(renderer, "xalign", 1.0, NULL);
399 gtk_tree_view_column_pack_start(column, renderer, TRUE);
400 gtk_tree_view_column_set_cell_data_func(column, renderer, amount_cell_data_function, GINT_TO_POINTER(1), NULL);
401 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPACC_NAME);
402 gtk_tree_view_column_set_resizable(column, TRUE);
403 gtk_tree_view_column_set_alignment (column, 0.5);
404 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
405
406 /* column: Account */
407 column = gtk_tree_view_column_new();
408 gtk_tree_view_column_set_title(column, _("Account"));
409 renderer = gtk_cell_renderer_text_new ();
410 g_object_set(renderer, "xalign", 1.0, NULL);
411 gtk_tree_view_column_pack_start(column, renderer, TRUE);
412 gtk_tree_view_column_set_cell_data_func(column, renderer, account_cell_data_function, NULL, NULL);
413 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_DATE);
414 gtk_tree_view_column_set_resizable(column, TRUE);
415 gtk_tree_view_column_set_alignment (column, 0.5);
416 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
417
418
419
420
421
422 /* column: empty */
423 column = gtk_tree_view_column_new();
424 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
425
426 gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), list_account_selectionfunc, NULL, NULL);
427
428
429 /* set initial sort order */
430 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), LST_DSPUPC_REMAINING, GTK_SORT_ASCENDING);
431
432 return(view);
433 }
434
This page took 0.061125 seconds and 4 git commands to generate.