]> Dogcows Code - chaz/homebank/blob - src/list_operation.c
import homebank-5.1.3
[chaz/homebank] / src / list_operation.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 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
21 #include "homebank.h"
22
23 #include "list_operation.h"
24
25 /****************************************************************************/
26 /* Debug macros */
27 /****************************************************************************/
28 #define MYDEBUG 0
29
30 #if MYDEBUG
31 #define DB(x) (x);
32 #else
33 #define DB(x);
34 #endif
35
36 /* our global datas */
37 extern struct HomeBank *GLOBALS;
38 extern struct Preferences *PREFS;
39
40
41
42 gchar *list_txn_column_label[] = {
43 "----", //datas
44 "----", //status
45 "----", //date
46 N_("Info" ),
47 N_("Payee" ),
48 N_("Memo" ),
49 N_("Amount" ),
50 N_("Expense" ),
51 N_("Income" ),
52 N_("Category"),
53 N_("Tags" ),
54 N_("Balance" ),
55 N_("Status"),
56 NULL
57 };
58
59
60 //debug
61 //extern gboolean minor_active;
62
63 /* This is not pretty. Of course you can also use a
64 * separate compare function for each sort ID value */
65
66 static gint list_txn_sort_iter_compare_strings(gchar *s1, gchar *s2)
67 {
68 return hb_string_utf8_compare(s1, s2);
69 }
70
71
72 static gint
73 list_txn_sort_iter_compare_func (GtkTreeModel *model,
74 GtkTreeIter *a,
75 GtkTreeIter *b,
76 gpointer userdata)
77 {
78 gint sortcol = GPOINTER_TO_INT(userdata);
79 gint retval = 0;
80 Transaction *ope1, *ope2;
81 gdouble tmpval = 0;
82
83 gtk_tree_model_get(model, a, LST_DSPOPE_DATAS, &ope1, -1);
84 gtk_tree_model_get(model, b, LST_DSPOPE_DATAS, &ope2, -1);
85
86 switch (sortcol)
87 {
88 case LST_DSPOPE_STATUS:
89 if(!(retval = (ope1->flags & OF_ADDED) - (ope2->flags & OF_ADDED) ) )
90 {
91 retval = (ope1->flags & OF_CHANGED) - (ope2->flags & OF_CHANGED);
92 }
93 break;
94
95 case LST_DSPOPE_DATE:
96 if(! (retval = ope1->date - ope2->date) )
97 {
98 //g_print("sort on balance d1=%d, d2=%d %f %f\n", ope1->date, ope2->date, ope1->balance , ope2->balance);
99
100 tmpval = ope1->pos - ope2->pos;
101 retval = tmpval > 0 ? 1 : -1;
102 }
103 //g_print("ret=%d\n", ret);
104 break;
105
106 case LST_DSPOPE_ACCOUNT:
107 {
108 Account *a1, *a2;
109
110 a1 = da_acc_get(ope1->kacc);
111 a2 = da_acc_get(ope2->kacc);
112 if( a1 != NULL && a2 != NULL )
113 {
114 retval = list_txn_sort_iter_compare_strings(a1->name, a2->name);
115 }
116 }
117 break;
118
119 case LST_DSPOPE_INFO:
120 if(!(retval = ope1->paymode - ope2->paymode))
121 {
122 retval = list_txn_sort_iter_compare_strings(ope1->info, ope2->info);
123 }
124 break;
125
126 case LST_DSPOPE_PAYEE:
127 {
128 Payee *p1, *p2;
129
130 p1 = da_pay_get(ope1->kpay);
131 p2 = da_pay_get(ope2->kpay);
132 if( p1 != NULL && p2 != NULL )
133 {
134 retval = list_txn_sort_iter_compare_strings(p1->name, p2->name);
135 }
136 }
137 break;
138
139 case LST_DSPOPE_WORDING:
140 retval = list_txn_sort_iter_compare_strings(ope1->wording, ope2->wording);
141 break;
142
143 case LST_DSPOPE_CLR:
144 retval = ope1->status - ope2->status;
145 break;
146
147 case LST_DSPOPE_AMOUNT:
148 case LST_DSPOPE_EXPENSE:
149 case LST_DSPOPE_INCOME:
150 tmpval = ope1->amount - ope2->amount;
151 retval = tmpval > 0 ? 1 : -1;
152 break;
153
154 case LST_DSPOPE_CATEGORY:
155 {
156 Category *c1, *c2;
157 gchar *name1, *name2;
158
159 c1 = da_cat_get(ope1->kcat);
160 c2 = da_cat_get(ope2->kcat);
161 if( c1 != NULL && c2 != NULL )
162 {
163 name1 = da_cat_get_fullname(c1);
164 name2 = da_cat_get_fullname(c2);
165 retval = list_txn_sort_iter_compare_strings(name1, name2);
166 g_free(name2);
167 g_free(name1);
168 }
169 }
170 break;
171
172 case LST_DSPOPE_TAGS:
173 {
174 gchar *t1, *t2;
175
176 t1 = transaction_tags_tostring(ope1);
177 t2 = transaction_tags_tostring(ope2);
178 retval = list_txn_sort_iter_compare_strings(t1, t2);
179 g_free(t1);
180 g_free(t2);
181 }
182 break;
183
184 default:
185 g_return_val_if_reached(0);
186 }
187
188 return retval;
189 }
190
191 static void list_txn_eval_future(GtkCellRenderer *renderer, Transaction *txn)
192 {
193
194 //it seems we are not able to get a valid GdkRGBA
195 //nor to set/use the alpha
196 /*GdkRGBA *rgba;
197 g_object_get(renderer, "foreground-rgba", &rgba, NULL);
198 g_print("forcol: %p %f %f %f %f\n", rgba, rgba->red, rgba->green, rgba->blue, rgba->alpha);
199 rgba->red = 1.0;
200 rgba->alpha = 0.1;
201 g_object_set(renderer, "foreground-set", TRUE,
202 "foreground-rgba", rgba,
203 NULL);
204 gdk_rgba_free(rgba);
205 */
206
207 if(txn->date > GLOBALS->today)
208 {
209 g_object_set(renderer,
210 "scale-set", TRUE,
211 "scale", 0.8,
212 "style-set", TRUE,
213 "style", PANGO_STYLE_OBLIQUE,
214 NULL);
215 }
216 else
217 {
218 g_object_set(renderer, "scale-set", FALSE, "style-set", FALSE,
219 NULL);
220 }
221 }
222
223
224 /*
225 ** date cell function
226 */
227 static void list_txn_status_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
228 {
229 Transaction *entry;
230 gchar *iconname = NULL;
231
232 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &entry, -1);
233
234 /*
235 stat[0] = ( entry->ope_Flags & OF_ADDED ) ? data->istatus[2] : data->istatus[0];
236 stat[1] = ( entry->ope_Flags & OF_CHANGED) ? data->istatus[3] : data->istatus[0];
237 stat[2] = ( entry->ope_Flags & OF_VALID ) ? data->istatus[4] : data->istatus[0];
238 if( entry->ope_Flags & OF_REMIND ) stat[2] = data->istatus[1];
239 */
240
241 switch(GPOINTER_TO_INT(user_data))
242 {
243 case 1:
244 iconname = ( entry->flags & OF_AUTO ) ? ICONNAME_HB_OPE_AUTO : ( entry->flags & OF_ADDED ) ? ICONNAME_NEW : NULL;
245 break;
246 case 2:
247 iconname = ( entry->flags & OF_CHANGED ) ? ICONNAME_HB_OPE_EDIT : NULL;
248 break;
249 /*case 3:
250 if( entry->flags & OF_VALID )
251 iconname = ICONNAME_HB_OPE_VALID;
252 else
253 {
254 if( entry->flags & OF_REMIND )
255 iconname = ICONNAME_HB_OPE_REMIND;
256 }
257 break;*/
258 }
259 g_object_set(renderer, "icon-name", iconname, NULL);
260 }
261
262
263 /*
264 ** account cell function
265 */
266 static void list_txn_account_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
267 {
268 Transaction *ope;
269 Account *acc;
270
271 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
272
273 acc = da_acc_get(ope->kacc);
274 if( acc )
275 {
276 g_object_set(renderer, "text", acc->name, NULL);
277 }
278 else
279 g_object_set(renderer, "text", "", NULL);
280 }
281
282 /*
283 ** date cell function
284 */
285 static void list_txn_date_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
286 {
287 Transaction *ope;
288 gchar buffer[256];
289 GDate date;
290
291 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
292 list_txn_eval_future(renderer, ope);
293
294 if(ope->date > 0)
295 {
296 g_date_set_julian (&date, ope->date);
297 g_date_strftime (buffer, 256-1, PREFS->date_format, &date);
298
299 //g_snprintf(buf, sizeof(buf), "%d", ope->ope_Date);
300
301 g_object_set(renderer, "text", buffer, NULL);
302 }
303 else
304 g_object_set(renderer, "text", "????", NULL);
305 }
306
307 /*
308 ** info cell function
309 */
310 static void list_txn_info_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
311 {
312 Transaction *ope;
313
314 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
315
316 switch(GPOINTER_TO_INT(user_data))
317 {
318 case 1:
319 g_object_set(renderer, "icon-name", get_paymode_icon_name(ope->paymode), NULL);
320 break;
321 case 2:
322 list_txn_eval_future(renderer, ope);
323 g_object_set(renderer, "text", ope->info, NULL);
324 break;
325 }
326 }
327
328 /*
329 ** payee cell function
330 */
331 static void list_txn_payee_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
332 {
333 Transaction *ope;
334
335 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
336 list_txn_eval_future(renderer, ope);
337
338 //#926782
339 if(ope->paymode == PAYMODE_INTXFER)
340 {
341 Account *acc = da_acc_get(ope->kxferacc);
342
343 g_object_set(renderer, "text", (acc != NULL) ? acc->name : "", NULL);
344 }
345 else
346 {
347 Payee *pay = da_pay_get(ope->kpay);
348
349 g_object_set(renderer, "text", pay != NULL ? pay->name : "", NULL);
350 }
351 }
352
353 /*
354 ** tags cell function
355 */
356 static void list_txn_tags_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
357 {
358 Transaction *ope;
359 gchar *str;
360
361 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
362 list_txn_eval_future(renderer, ope);
363
364 if(ope->tags != NULL)
365 {
366 str = transaction_tags_tostring(ope);
367 g_object_set(renderer, "text", str, NULL);
368 g_free(str);
369 }
370 else
371 g_object_set(renderer, "text", "", NULL);
372
373
374 }
375
376
377 /*
378 ** wording cell function
379 */
380 static void list_txn_wording_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
381 {
382 Transaction *ope;
383
384 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
385 list_txn_eval_future(renderer, ope);
386
387 g_object_set(renderer, "text", ope->wording, NULL);
388 }
389
390
391 /*
392 ** clr cell function
393 */
394 static void list_txn_clr_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
395 {
396 Transaction *ope;
397 gchar *iconname = NULL;
398 //const gchar *c = "";
399
400 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
401 switch(ope->status)
402 {
403 /*case TXN_STATUS_CLEARED: c = "c"; break;
404 case TXN_STATUS_RECONCILED: c = "R"; break;
405 case TXN_STATUS_REMIND: c = "!"; break;*/
406 case TXN_STATUS_CLEARED: iconname = ICONNAME_HB_OPE_CLEARED; break;
407 case TXN_STATUS_RECONCILED: iconname = ICONNAME_HB_OPE_RECONCILED; break;
408 case TXN_STATUS_REMIND: iconname = ICONNAME_HB_OPE_REMIND; break;
409
410 }
411
412 //g_object_set(renderer, "text", c, NULL);
413 g_object_set(renderer, "icon-name", iconname, NULL);
414
415 }
416
417
418 /*
419 ** amount cell function
420 */
421 static void list_txn_amount_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
422 {
423 Transaction *ope;
424 gint column = GPOINTER_TO_INT(user_data);
425 gchar buf[G_ASCII_DTOSTR_BUF_SIZE];
426 gint type;
427 gdouble amount;
428 gchar *color;
429
430 // get the transaction
431 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
432 list_txn_eval_future(renderer, ope);
433
434 if(column == LST_DSPOPE_BALANCE)
435 amount = ope->balance;
436 else
437 amount = ope->amount;
438
439 if(column == LST_DSPOPE_INCOME || column == LST_DSPOPE_EXPENSE)
440 {
441 type = (ope->flags & OF_INCOME) ? LST_DSPOPE_INCOME : LST_DSPOPE_EXPENSE;
442 if( type != column)
443 {
444 g_object_set(renderer, "markup", NULL, NULL);
445 return;
446 }
447 }
448
449 //if(amount != 0)
450 //{
451 hb_strfmon(buf, G_ASCII_DTOSTR_BUF_SIZE-1, amount, ope->kcur, GLOBALS->minor);
452 color = get_normal_color_amount(amount);
453
454 g_object_set(renderer,
455 "foreground", color,
456 "text", buf,
457 NULL);
458 //}
459
460
461 }
462
463
464 /*
465 ** category cell function
466 */
467 static void list_txn_category_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
468 {
469 Transaction *ope;
470 Category *cat;
471 gchar *fullname;
472
473 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
474 list_txn_eval_future(renderer, ope);
475
476 if(ope->flags & OF_SPLIT)
477 {
478 g_object_set(renderer, "text", _("- split -"), NULL);
479 }
480 else
481 {
482 cat = da_cat_get(ope->kcat);
483 if( cat != NULL )
484 {
485 fullname = da_cat_get_fullname(cat);
486 g_object_set(renderer, "text", fullname, NULL);
487 g_free(fullname);
488 }
489 else
490 g_object_set(renderer, "text", "", NULL);
491
492 }
493
494 }
495
496
497 /* = = = = = = = = = = = = = = = = */
498 gboolean list_txn_column_id_isvisible(GtkTreeView *treeview, gint sort_id)
499 {
500 GtkTreeViewColumn *column;
501 gint n, id;
502
503 for(n=0; n < NUM_LST_DSPOPE-1 ; n++ ) // -1 cause account not to be processed
504 {
505 column = gtk_tree_view_get_column (treeview, n);
506 if(column == NULL)
507 continue;
508
509 if( gtk_tree_view_column_get_visible(column) )
510 {
511 id = gtk_tree_view_column_get_sort_column_id (column);
512 if( sort_id == id )
513 return TRUE;
514 }
515 }
516
517 return FALSE;
518 }
519
520
521 static GtkTreeViewColumn *list_txn_get_column(GList *list, gint search_id)
522 {
523 GtkTreeViewColumn *column = NULL;
524 GList *tmp;
525 gint id;
526
527 tmp = g_list_first(list);
528 while (tmp != NULL)
529 {
530 id = gtk_tree_view_column_get_sort_column_id(tmp->data);
531 if( search_id == id)
532 {
533 column = tmp->data;
534 break;
535 }
536 tmp = g_list_next(tmp);
537 }
538 return column;
539 }
540
541
542 guint list_txn_get_quicksearch_column_mask(GtkTreeView *treeview)
543 {
544 GtkTreeViewColumn *column;
545 guint n, mask;
546 gint id;
547
548 mask = 0;
549 for(n=0; n < NUM_LST_DSPOPE-1 ; n++ ) // -1 cause account not to be processed
550 {
551 column = gtk_tree_view_get_column (treeview, n);
552 if(column == NULL)
553 continue;
554
555 if( gtk_tree_view_column_get_visible(column) )
556 {
557 id = gtk_tree_view_column_get_sort_column_id (column);
558 switch(id)
559 {
560 case LST_DSPOPE_WORDING: mask |= FLT_QSEARCH_MEMO; break;
561 case LST_DSPOPE_INFO: mask |= FLT_QSEARCH_INFO; break;
562 case LST_DSPOPE_PAYEE: mask |= FLT_QSEARCH_PAYEE; break;
563 case LST_DSPOPE_CATEGORY: mask |= FLT_QSEARCH_CATEGORY; break;
564 case LST_DSPOPE_TAGS: mask |= FLT_QSEARCH_TAGS; break;
565 }
566 }
567 }
568
569 return mask;
570 }
571
572
573 void list_txn_set_save_column_width(GtkTreeView *treeview, gboolean save_column_width)
574 {
575 struct list_txn_data *data;
576
577 data = g_object_get_data(G_OBJECT(treeview), "inst_data");
578 if( data )
579 {
580 data->save_column_width = save_column_width;
581 }
582 }
583
584
585 void list_txn_sort_force(GtkTreeSortable *sortable, gpointer user_data)
586 {
587 gint sort_column_id;
588 GtkSortType order;
589
590 DB( g_print("list_txn_sort_force\n") );
591
592 gtk_tree_sortable_get_sort_column_id(sortable, &sort_column_id, &order);
593 DB( g_print(" - id %d order %d\n", sort_column_id, order) );
594
595 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortable), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, order);
596 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(sortable), sort_column_id, order);
597 }
598
599
600 static void list_txn_get_columns(GtkTreeView *treeview)
601 {
602 struct list_txn_data *data;
603 GtkTreeViewColumn *column;
604 gint i, col_id;
605
606 DB( g_print("\n[list_txn] get columns order/width\n") );
607
608 data = g_object_get_data(G_OBJECT(treeview), "inst_data");
609
610 DB( g_print(" nbcol=%d, nbsortid=%d\n", NUM_LST_DSPOPE, gtk_tree_view_get_n_columns (treeview)) );
611
612 for(i=0 ; i < NUM_LST_DSPOPE-1 ; i++ ) // -1 'caus: account and blank column
613 {
614 column = gtk_tree_view_get_column(treeview, i);
615 if(column != NULL)
616 {
617 col_id = gtk_tree_view_column_get_sort_column_id (column);
618 if( col_id >= 0 )
619 {
620 gboolean visible;
621
622 visible = gtk_tree_view_column_get_visible (column);
623 if( col_id == LST_DSPOPE_BALANCE) //keep initial state of balance
624 visible = data->tvc_is_visible;
625
626 if( visible )
627 PREFS->lst_ope_columns[i] = col_id;
628 else
629 PREFS->lst_ope_columns[i] = -col_id;
630
631 PREFS->lst_ope_col_size[col_id-1] = gtk_tree_view_column_get_width(column);
632
633 DB( g_print(" col-%2d => %2d '%s' w=%d\n", i, col_id, gtk_tree_view_column_get_title(column), PREFS->lst_ope_col_size[col_id-1] ) );
634 }
635 else //should not occurs
636 PREFS->lst_ope_columns[i] = 0;
637 }
638 }
639 }
640
641
642 static void list_txn_set_columns(GtkTreeView *treeview, gint *col_id)
643 {
644 struct list_txn_data *data;
645 GtkTreeViewColumn *column, *base;
646 gboolean visible;
647 GList *list;
648 gint i = 0;
649 gint id;
650
651 DB( g_print("\n[list_txn] set columns order/width\n") );
652
653 data = g_object_get_data(G_OBJECT(treeview), "inst_data");
654
655 #if MYDEBUG == 1
656 DB( g_print("\n debug column sortid\n") );
657
658 for(i=0; i < NUM_LST_DSPOPE-1 ; i++ ) // -1 cause account not to be processed
659 {
660 DB( g_print(" - pos:%2d sortid:%2d\n", i, col_id[i]) );
661 }
662 #endif
663
664
665 DB( g_print("\n apply column prefs\n") );
666
667 list = gtk_tree_view_get_columns( treeview );
668
669 base = NULL;
670
671 for(i=0; i < NUM_LST_DSPOPE-1 ; i++ ) // -1 cause account not to be processed
672 {
673 /* hidden are stored as col_id negative */
674 id = ABS(col_id[i]);
675 column = list_txn_get_column(list, id);
676
677 //DB( g_print(" - get column %d %p\n", id, column) );
678
679 if( column != NULL )
680 {
681 DB( g_print(" - pos:%2d sortid:%2d (%s)\n", i, col_id[i], gtk_tree_view_column_get_title(column)) );
682
683 gtk_tree_view_move_column_after(treeview, column, base);
684 base = column;
685
686 visible = col_id[i] < 0 ? FALSE : TRUE;
687
688 /* display exception for detail/import list */
689 if(data->list_type != LIST_TXN_TYPE_BOOK)
690 {
691 if( id == LST_DSPOPE_AMOUNT )
692 visible = TRUE;
693
694 if( id == LST_DSPOPE_STATUS || id == LST_DSPOPE_EXPENSE || id == LST_DSPOPE_INCOME )
695 visible = FALSE;
696 }
697
698 gtk_tree_view_column_set_visible (column, visible);
699 if( id == LST_DSPOPE_BALANCE )
700 {
701 data->tvc_is_visible = visible;
702 }
703
704 if( id == LST_DSPOPE_INFO
705 || id == LST_DSPOPE_PAYEE
706 || id == LST_DSPOPE_WORDING
707 || id == LST_DSPOPE_CATEGORY
708 || id == LST_DSPOPE_TAGS
709 || id == LST_DSPOPE_ACCOUNT )
710 {
711 gtk_tree_view_column_set_fixed_width( column, PREFS->lst_ope_col_size[id - 1]);
712 }
713 }
714
715 }
716
717 g_list_free(list );
718 }
719
720
721 static void list_txn_sort_column_changed(GtkTreeSortable *sortable, gpointer user_data)
722 {
723 struct list_txn_data *data = user_data;
724 gint id;
725 GtkSortType order;
726 gboolean showBalance;
727
728 gtk_tree_sortable_get_sort_column_id(sortable, &id, &order);
729
730 DB( g_print("list_txn_columns_changed %d %d\n", id, order) );
731
732 //here save the transaction list columnid and sort order
733 PREFS->lst_ope_sort_id = id;
734 PREFS->lst_ope_sort_order = order;
735
736 //manage visibility of balance column
737 //showBalance = (id == LST_DSPOPE_DATE && order == GTK_SORT_ASCENDING) ? data->tvc_is_visible : FALSE;
738 showBalance = (id == LST_DSPOPE_DATE) ? data->tvc_is_visible : FALSE;
739 gtk_tree_view_column_set_visible (data->tvc_balance, showBalance);
740 }
741
742
743 static void
744 list_txn_column_popup_menuitem_on_activate (GtkCheckMenuItem *checkmenuitem,
745 gpointer user_data)
746 {
747 GtkTreeViewColumn *column = user_data;
748
749 DB( g_print("toggled\n") );
750
751 gtk_tree_view_column_set_visible(column, gtk_check_menu_item_get_active(checkmenuitem) );
752 }
753
754
755 static gboolean list_txn_column_popup_callback ( GtkWidget *button,
756 GdkEventButton *ev,
757 gpointer user_data )
758 {
759 struct list_txn_data *data = user_data;
760 GtkWidget *menu, *menuitem;
761 GtkTreeViewColumn *column;
762 gint i, col_id;
763
764
765 if( ev->button == 3 )
766 {
767 DB( g_print("should popup\n") );
768
769 menu = gtk_menu_new ();
770
771 //note: deactive this disable any menuitem action
772 g_signal_connect (menu, "selection-done", G_CALLBACK (gtk_widget_destroy), NULL);
773
774 for(i=0 ; i < NUM_LST_DSPOPE-1 ; i++ ) // -1 'caus: account and blank column
775 {
776 column = gtk_tree_view_get_column(GTK_TREE_VIEW(data->treeview), i);
777 if( column != NULL )
778 {
779 col_id = gtk_tree_view_column_get_sort_column_id (column);
780
781 if( (col_id == -1)
782 || (col_id == LST_DSPOPE_STATUS)
783 || (col_id == LST_DSPOPE_ACCOUNT)
784 || (col_id == LST_DSPOPE_DATE)
785 || (col_id == LST_DSPOPE_BALANCE)
786 )
787 continue;
788 //if( (data->tvc_is_visible == FALSE) && (col_id == LST_DSPOPE_BALANCE) )
789 // continue;
790
791 if( (data->list_type == LIST_TXN_TYPE_DETAIL) &&
792 ( (col_id == LST_DSPOPE_AMOUNT)
793 || (col_id == LST_DSPOPE_EXPENSE)
794 || (col_id == LST_DSPOPE_INCOME)
795 )
796 )
797 continue;
798
799 menuitem = gtk_check_menu_item_new_with_label ( gtk_tree_view_column_get_title (column) );
800 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
801 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), gtk_tree_view_column_get_visible (column) );
802 gtk_widget_show (menuitem);
803
804 g_signal_connect (menuitem, "activate",
805 G_CALLBACK (list_txn_column_popup_menuitem_on_activate), column);
806 }
807
808 }
809
810 gtk_menu_attach_to_widget (GTK_MENU (menu), button, NULL);
811 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
812 ev->button, ev->time);
813 }
814
815 return FALSE;
816 }
817
818
819
820 static GtkTreeViewColumn *
821 list_txn_column_amount_create(gint list_type, gchar *title, gint sortcolumnid, GtkTreeCellDataFunc func)
822 {
823 GtkTreeViewColumn *column;
824 GtkCellRenderer *renderer;
825
826 renderer = gtk_cell_renderer_text_new ();
827 g_object_set(renderer, "xalign", 1.0, NULL);
828
829 column = gtk_tree_view_column_new_with_attributes(title, renderer, NULL);
830
831 gtk_tree_view_column_set_alignment (column, 0.5);
832 //gtk_tree_view_column_set_resizable(column, TRUE);
833 gtk_tree_view_column_set_sort_column_id (column, sortcolumnid);
834 if(list_type == LIST_TXN_TYPE_BOOK)
835 {
836 gtk_tree_view_column_set_reorderable(column, TRUE);
837 }
838 gtk_tree_view_column_set_cell_data_func(column, renderer, func, GINT_TO_POINTER(sortcolumnid), NULL);
839
840 return column;
841 }
842
843
844 static GtkTreeViewColumn *
845 list_txn_column_text_create(gint list_type, gchar *title, gint sortcolumnid, GtkTreeCellDataFunc func, gpointer user_data)
846 {
847 GtkTreeViewColumn *column;
848 GtkCellRenderer *renderer;
849
850 renderer = gtk_cell_renderer_text_new ();
851 /*g_object_set(renderer,
852 "ellipsize", PANGO_ELLIPSIZE_END,
853 "ellipsize-set", TRUE,
854 NULL);*/
855
856 column = gtk_tree_view_column_new_with_attributes(title, renderer, NULL);
857
858 gtk_tree_view_column_set_alignment (column, 0.5);
859 gtk_tree_view_column_set_resizable(column, TRUE);
860
861 gtk_tree_view_column_set_sort_column_id (column, sortcolumnid);
862 if(list_type == LIST_TXN_TYPE_BOOK)
863 {
864 gtk_tree_view_column_set_reorderable(column, TRUE);
865 gtk_tree_view_column_set_min_width (column, HB_MINWIDTH_COLUMN);
866 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
867 }
868 gtk_tree_view_column_set_cell_data_func(column, renderer, func, user_data, NULL);
869
870 return column;
871 }
872
873
874 static GtkTreeViewColumn *
875 list_txn_column_info_create(gint list_type)
876 {
877 GtkTreeViewColumn *column;
878 GtkCellRenderer *renderer;
879
880 column = gtk_tree_view_column_new();
881 gtk_tree_view_column_set_title(column, _("Info"));
882
883 renderer = gtk_cell_renderer_pixbuf_new ();
884 gtk_tree_view_column_pack_start(column, renderer, FALSE);
885 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_info_cell_data_function, GINT_TO_POINTER(1), NULL);
886
887 renderer = gtk_cell_renderer_text_new ();
888 /*g_object_set(renderer,
889 "ellipsize", PANGO_ELLIPSIZE_END,
890 "ellipsize-set", TRUE,
891 NULL);*/
892 gtk_tree_view_column_pack_start(column, renderer, TRUE);
893 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_info_cell_data_function, GINT_TO_POINTER(2), NULL);
894
895 gtk_tree_view_column_set_alignment (column, 0.5);
896 gtk_tree_view_column_set_resizable(column, TRUE);
897 gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_INFO);
898 if(list_type == LIST_TXN_TYPE_BOOK)
899 {
900 gtk_tree_view_column_set_reorderable(column, TRUE);
901 gtk_tree_view_column_set_min_width (column, HB_MINWIDTH_COLUMN);
902 gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED);
903 }
904
905 return column;
906 }
907
908
909 static void list_txn_destroy( GtkWidget *widget, gpointer user_data )
910 {
911 struct list_txn_data *data;
912
913 data = g_object_get_data(G_OBJECT(widget), "inst_data");
914
915 DB( g_print ("\n[list_transaction] destroy event occurred\n") );
916
917 if( data->save_column_width )
918 {
919 list_txn_get_columns(GTK_TREE_VIEW(data->treeview));
920 }
921
922 DB( g_print(" - view=%p, inst_data=%p\n", widget, data) );
923 g_free(data);
924 }
925
926
927 Transaction *list_txn_get_active_transaction(GtkTreeView *treeview)
928 {
929 GtkTreeModel *model;
930 GList *list;
931 Transaction *ope;
932
933 ope = NULL;
934
935 model = gtk_tree_view_get_model(treeview);
936 list = gtk_tree_selection_get_selected_rows(gtk_tree_view_get_selection(treeview), &model);
937
938 if(list != NULL)
939 {
940 GtkTreeIter iter;
941
942 gtk_tree_model_get_iter(model, &iter, list->data);
943 gtk_tree_model_get(model, &iter, LST_DSPOPE_DATAS, &ope, -1);
944 }
945
946 g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
947 g_list_free(list);
948
949 return ope;
950 }
951
952
953 /*
954 ** create our transaction list
955 ** Status, Date, Info, Payee, Wording, (Amount), Expense, Income, Category
956 */
957 GtkWidget *create_list_transaction(gint list_type, gboolean *pref_columns)
958 {
959 struct list_txn_data *data;
960 GtkListStore *store;
961 GtkWidget *treeview;
962 GtkCellRenderer *renderer;
963 GtkTreeViewColumn *column, *col_acc = NULL, *col_status = NULL;
964
965
966 data = g_malloc0(sizeof(struct list_txn_data));
967 if(!data) return NULL;
968
969 data->list_type = list_type;
970 data->save_column_width = FALSE;
971
972 /* create list store */
973 store = gtk_list_store_new(
974 NUM_LST_DSPOPE,
975 G_TYPE_POINTER, /*only really used columns, other are fake */
976 G_TYPE_BOOLEAN,
977 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
978 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
979 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
980 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
981 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
982 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
983 G_TYPE_BOOLEAN, G_TYPE_BOOLEAN
984 );
985
986 //treeview
987 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
988 data->treeview = treeview;
989 g_object_unref(store);
990
991 //store our window private data
992 g_object_set_data(G_OBJECT(treeview), "inst_data", (gpointer)data);
993 DB( g_print(" - treeview=%p, inst_data=%p\n", treeview, data) );
994
995 // connect our dispose function
996 g_signal_connect (treeview, "destroy", G_CALLBACK (list_txn_destroy), (gpointer)data);
997
998 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview), PREFS->grid_lines);
999 //gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
1000 // COLUMN_DESCRIPTION);
1001
1002 if(list_type == LIST_TXN_TYPE_BOOK)
1003 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), GTK_SELECTION_MULTIPLE);
1004
1005 /* column 1: Changes */
1006 column = gtk_tree_view_column_new();
1007 //gtk_tree_view_column_set_title(column, _("Status"));
1008 col_status = column;
1009
1010 renderer = gtk_cell_renderer_pixbuf_new ();
1011 //gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
1012 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1013 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_status_cell_data_function, GINT_TO_POINTER(1), NULL);
1014
1015 renderer = gtk_cell_renderer_pixbuf_new ();
1016 //gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
1017 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1018 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_status_cell_data_function, GINT_TO_POINTER(2), NULL);
1019
1020 renderer = gtk_cell_renderer_pixbuf_new ();
1021 //gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
1022 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1023 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_status_cell_data_function, GINT_TO_POINTER(3), NULL);
1024
1025 gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_STATUS);
1026 //gtk_tree_view_column_set_resizable(column, TRUE);
1027 gtk_tree_view_column_set_alignment (column, 0.5);
1028 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1029
1030 if(list_type == LIST_TXN_TYPE_DETAIL)
1031 {
1032 column = list_txn_column_text_create(list_type, _("Account"), LST_DSPOPE_ACCOUNT, list_txn_account_cell_data_function, NULL);
1033 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1034 col_acc = column;
1035 // add column popup
1036 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1037 "button-press-event",
1038 G_CALLBACK ( list_txn_column_popup_callback ),
1039 data );
1040 }
1041
1042 /* column 2: Date */
1043 column = gtk_tree_view_column_new();
1044 gtk_tree_view_column_set_title(column, _("Date"));
1045 renderer = gtk_cell_renderer_text_new ();
1046 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1047 g_object_set(renderer, "xalign", 1.0, NULL);
1048 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_date_cell_data_function, NULL, NULL);
1049 gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_DATE);
1050 //gtk_tree_view_column_set_resizable(column, TRUE);
1051 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1052 // add column popup
1053 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1054 "button-press-event",
1055 G_CALLBACK ( list_txn_column_popup_callback ),
1056 data );
1057
1058
1059 column = list_txn_column_info_create(list_type);
1060 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1061 // add column popup
1062 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1063 "button-press-event",
1064 G_CALLBACK ( list_txn_column_popup_callback ),
1065 data );
1066
1067 column = list_txn_column_text_create(list_type, _("Payee"), LST_DSPOPE_PAYEE, list_txn_payee_cell_data_function, NULL);
1068 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1069 // add column popup
1070 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1071 "button-press-event",
1072 G_CALLBACK ( list_txn_column_popup_callback ),
1073 data );
1074
1075 column = list_txn_column_text_create(list_type, _("Memo"), LST_DSPOPE_WORDING, list_txn_wording_cell_data_function, NULL);
1076 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1077 // add column popup
1078 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1079 "button-press-event",
1080 G_CALLBACK ( list_txn_column_popup_callback ),
1081 data );
1082
1083 /* column status CLR */
1084 column = gtk_tree_view_column_new();
1085 gtk_tree_view_column_set_title(column, _("Status"));
1086 //renderer = gtk_cell_renderer_text_new ();
1087 renderer = gtk_cell_renderer_pixbuf_new();
1088 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1089 g_object_set(renderer, "xalign", 1.0, NULL);
1090 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_clr_cell_data_function, NULL, NULL);
1091 gtk_tree_view_column_set_reorderable(column, TRUE);
1092 gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_CLR);
1093 //gtk_tree_view_column_set_sort_indicator (column, FALSE);
1094 //gtk_tree_view_column_set_resizable(column, TRUE);
1095 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1096 // add column popup
1097 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1098 "button-press-event",
1099 G_CALLBACK ( list_txn_column_popup_callback ),
1100 data );
1101
1102
1103 column = list_txn_column_amount_create(list_type, _("Amount"), LST_DSPOPE_AMOUNT, list_txn_amount_cell_data_function);
1104 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1105 // add column popup
1106 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1107 "button-press-event",
1108 G_CALLBACK ( list_txn_column_popup_callback ),
1109 data );
1110
1111 column = list_txn_column_amount_create(list_type, _("Expense"), LST_DSPOPE_EXPENSE, list_txn_amount_cell_data_function);
1112 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1113 // add column popup
1114 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1115 "button-press-event",
1116 G_CALLBACK ( list_txn_column_popup_callback ),
1117 data );
1118
1119 column = list_txn_column_amount_create(list_type, _("Income"), LST_DSPOPE_INCOME, list_txn_amount_cell_data_function);
1120 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1121 // add column popup
1122 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1123 "button-press-event",
1124 G_CALLBACK ( list_txn_column_popup_callback ),
1125 data );
1126
1127 column = list_txn_column_text_create(list_type, _("Category"), LST_DSPOPE_CATEGORY, list_txn_category_cell_data_function, NULL);
1128 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1129 // add column popup
1130 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1131 "button-press-event",
1132 G_CALLBACK ( list_txn_column_popup_callback ),
1133 data );
1134
1135 column = list_txn_column_text_create(list_type, _("Tags"), LST_DSPOPE_TAGS, list_txn_tags_cell_data_function, NULL);
1136 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1137 // add column popup
1138 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1139 "button-press-event",
1140 G_CALLBACK ( list_txn_column_popup_callback ),
1141 data );
1142
1143 if(list_type == LIST_TXN_TYPE_BOOK)
1144 {
1145 column = list_txn_column_amount_create(list_type, _("Balance"), LST_DSPOPE_BALANCE, list_txn_amount_cell_data_function);
1146 data->tvc_balance = column;
1147 gtk_tree_view_column_set_clickable(column, FALSE);
1148 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1149 // add column popup
1150 g_signal_connect ( G_OBJECT (gtk_tree_view_column_get_button (column)),
1151 "button-press-event",
1152 G_CALLBACK ( list_txn_column_popup_callback ),
1153 data );
1154 }
1155
1156 /* column 9: empty */
1157 column = gtk_tree_view_column_new();
1158 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1159
1160 /* sort */
1161 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_STATUS , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_STATUS), NULL);
1162 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_DATE , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_DATE), NULL);
1163 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_INFO , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_INFO), NULL);
1164 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_PAYEE , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_PAYEE), NULL);
1165 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_WORDING , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_WORDING), NULL);
1166 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_AMOUNT , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_AMOUNT), NULL);
1167 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_EXPENSE , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_EXPENSE), NULL);
1168 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_INCOME , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_INCOME), NULL);
1169 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_CATEGORY, list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_CATEGORY), NULL);
1170 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_TAGS , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_TAGS), NULL);
1171 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_CLR , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_CLR), NULL);
1172 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DSPOPE_ACCOUNT , list_txn_sort_iter_compare_func, GINT_TO_POINTER(LST_DSPOPE_ACCOUNT), NULL);
1173
1174 /* apply user preference for columns */
1175 list_txn_set_columns(GTK_TREE_VIEW(treeview), pref_columns);
1176
1177 /* force account column for detail treeview */
1178 if(list_type == LIST_TXN_TYPE_DETAIL)
1179 {
1180 gtk_tree_view_move_column_after(GTK_TREE_VIEW(treeview), col_acc, col_status);
1181 }
1182
1183 /* set initial sort order */
1184 DB( g_print("set sort to %d %d\n", PREFS->lst_ope_sort_id, PREFS->lst_ope_sort_order) );
1185 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), PREFS->lst_ope_sort_id, PREFS->lst_ope_sort_order);
1186
1187
1188 /* signals */
1189 if(list_type == LIST_TXN_TYPE_BOOK)
1190 g_signal_connect (GTK_TREE_SORTABLE(store), "sort-column-changed", G_CALLBACK (list_txn_sort_column_changed), data);
1191
1192 return(treeview);
1193 }
1194
1195
1196 /* ---------------------------------------------- */
1197 /* import list : soon obsolete */
1198 /* ---------------------------------------------- */
1199
1200 /*
1201 ** account cell function
1202 */
1203 static void ope_importaccount_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1204 {
1205 Transaction *ope;
1206 Account *acc, *dacc;
1207
1208 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
1209
1210 acc = da_acc_get(ope->kacc);
1211 if( acc )
1212 {
1213 if(acc->imp_key > 0)
1214 {
1215 dacc = da_acc_get(acc->imp_key);
1216 if( dacc )
1217 g_object_set(renderer, "text", dacc->name, NULL);
1218 }
1219 else
1220 g_object_set(renderer, "text", acc->name, NULL);
1221
1222 }
1223 }
1224
1225 /*
1226 ** amount cell function
1227 */
1228 static void ope_importamount_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1229 {
1230 Transaction *ope;
1231 gchar formatd_buf[G_ASCII_DTOSTR_BUF_SIZE];
1232 gchar *color;
1233
1234 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
1235
1236 //mystrfnum(buf, G_ASCII_DTOSTR_BUF_SIZE-1, ope->amount, GLOBALS->minor);
1237 //hb_strfmon(buf, G_ASCII_DTOSTR_BUF_SIZE-1, ope->amount, GLOBALS->minor);
1238 g_ascii_formatd(formatd_buf, G_ASCII_DTOSTR_BUF_SIZE-1, "%.2f", ope->amount);
1239
1240 color = get_normal_color_amount(ope->amount);
1241
1242 g_object_set(renderer,
1243 "foreground", color,
1244 "text", formatd_buf,
1245 NULL);
1246
1247 }
1248
1249
1250 static void ope_importstatus_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
1251 {
1252 Transaction *ope;
1253 gchar *iconname = NULL;
1254
1255 // get the transaction
1256 gtk_tree_model_get(model, iter, LST_DSPOPE_DATAS, &ope, -1);
1257
1258 iconname = ( ope->same != NULL ) ? ICONNAME_WARNING : NULL;
1259
1260 g_object_set(renderer, "icon-name", iconname, NULL);
1261 }
1262
1263
1264 static void
1265 ope_importfixed_toggled (GtkCellRendererToggle *cell,
1266 gchar *path_str,
1267 gpointer data)
1268 {
1269 GtkTreeModel *model = (GtkTreeModel *)data;
1270 GtkTreeIter iter;
1271 GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
1272 gboolean fixed;
1273
1274 /* get toggled iter */
1275 gtk_tree_model_get_iter (model, &iter, path);
1276 gtk_tree_model_get (model, &iter, LST_OPE_IMPTOGGLE, &fixed, -1);
1277
1278 /* do something with the value */
1279 fixed ^= 1;
1280
1281 /* set new value */
1282 gtk_list_store_set (GTK_LIST_STORE (model), &iter, LST_OPE_IMPTOGGLE, fixed, -1);
1283
1284 /* clean up */
1285 gtk_tree_path_free (path);
1286 }
1287
1288 /*
1289 ** create our transaction list
1290 */
1291 GtkWidget *create_list_import_transaction(gboolean enable_choose)
1292 {
1293 GtkListStore *store;
1294 GtkWidget *treeview;
1295 GtkCellRenderer *renderer;
1296 GtkTreeViewColumn *column;
1297
1298 /* create list store */
1299 store = gtk_list_store_new(
1300 10,
1301 G_TYPE_POINTER,
1302 G_TYPE_BOOLEAN,
1303 G_TYPE_BOOLEAN,
1304 G_TYPE_BOOLEAN,
1305 G_TYPE_BOOLEAN,
1306 G_TYPE_BOOLEAN,
1307 G_TYPE_BOOLEAN,
1308 G_TYPE_BOOLEAN,
1309 G_TYPE_BOOLEAN,
1310 G_TYPE_BOOLEAN
1311 );
1312
1313 //treeview
1314 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
1315 g_object_unref(store);
1316
1317 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview), PREFS->grid_lines);
1318 //gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview),
1319 // COLUMN_DESCRIPTION);
1320
1321 //gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)), GTK_SELECTION_MULTIPLE);
1322
1323 /* column: Selection */
1324 if(enable_choose)
1325 {
1326 renderer = gtk_cell_renderer_toggle_new ();
1327
1328 g_signal_connect (renderer, "toggled", G_CALLBACK (ope_importfixed_toggled), store);
1329
1330
1331 column = gtk_tree_view_column_new_with_attributes (NULL,
1332 renderer,
1333 "active", LST_OPE_IMPTOGGLE,
1334 NULL);
1335
1336 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1337
1338 /* column: Duplicate */
1339 column = gtk_tree_view_column_new();
1340 //gtk_tree_view_column_set_title(column, _("Import ?"));
1341 renderer = gtk_cell_renderer_pixbuf_new ();
1342 //gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
1343 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1344 gtk_tree_view_column_set_cell_data_func(column, renderer, ope_importstatus_cell_data_function, NULL, NULL);
1345 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1346 }
1347
1348 //#ifndef NOOFX
1349 /* column: Account */
1350 column = gtk_tree_view_column_new();
1351 gtk_tree_view_column_set_title(column, _("Account"));
1352 renderer = gtk_cell_renderer_text_new ();
1353 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1354 gtk_tree_view_column_set_cell_data_func(column, renderer, ope_importaccount_cell_data_function, NULL, NULL);
1355 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_DATE);
1356 gtk_tree_view_column_set_resizable(column, TRUE);
1357 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1358 //#endif
1359
1360 /* column: Date */
1361 column = gtk_tree_view_column_new();
1362 gtk_tree_view_column_set_title(column, _("Date"));
1363 renderer = gtk_cell_renderer_text_new ();
1364 g_object_set(renderer, "xalign", 1.0, NULL);
1365 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1366 gtk_tree_view_column_set_cell_data_func(column, renderer, list_txn_date_cell_data_function, NULL, NULL);
1367 //gtk_tree_view_column_set_sort_column_id (column, LST_DSPOPE_DATE);
1368 gtk_tree_view_column_set_resizable(column, TRUE);
1369 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1370
1371 column = list_txn_column_text_create(LIST_TXN_TYPE_IMPORT, _("Memo"), -1, list_txn_wording_cell_data_function, NULL);
1372 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1373
1374 column = list_txn_column_amount_create(LIST_TXN_TYPE_IMPORT, _("Amount"), -1, ope_importamount_cell_data_function);
1375 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1376
1377 column = list_txn_column_info_create(LIST_TXN_TYPE_IMPORT);
1378 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1379
1380 column = list_txn_column_text_create(LIST_TXN_TYPE_IMPORT, _("Payee"), -1, list_txn_payee_cell_data_function, NULL);
1381 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1382
1383 column = list_txn_column_text_create(LIST_TXN_TYPE_IMPORT, _("Category"), -1, list_txn_category_cell_data_function, NULL);
1384 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1385
1386 column = gtk_tree_view_column_new();
1387 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
1388
1389 return(treeview);
1390 }
This page took 0.093842 seconds and 4 git commands to generate.