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