import homebank-5.1.7
[chaz/homebank] / src / ui-widgets.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2018 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 "gtk-chart.h"
24 #include "ui-widgets.h"
25
26 /****************************************************************************/
27 /* Debug macros */
28 /****************************************************************************/
29 #define MYDEBUG 0
30
31 #if MYDEBUG
32 #define DB(x) (x);
33 #else
34 #define DB(x);
35 #endif
36
37 /* our global datas */
38 extern struct HomeBank *GLOBALS;
39
40
41 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
42
43
44 extern gchar *CYA_FLT_RANGE[];
45
46
47
48
49 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
50
51
52
53 void
54 gimp_label_set_attributes (GtkLabel *label,
55 ...)
56 {
57 PangoAttribute *attr = NULL;
58 PangoAttrList *attrs;
59 va_list args;
60
61 g_return_if_fail (GTK_IS_LABEL (label));
62
63 attrs = pango_attr_list_new ();
64
65 va_start (args, label);
66
67 do
68 {
69 PangoAttrType attr_type = va_arg (args, PangoAttrType);
70
71 if (attr_type <= 0)
72 attr_type = PANGO_ATTR_INVALID;
73
74 switch (attr_type)
75 {
76 case PANGO_ATTR_LANGUAGE:
77 attr = pango_attr_language_new (va_arg (args, PangoLanguage *));
78 break;
79
80 case PANGO_ATTR_FAMILY:
81 attr = pango_attr_family_new (va_arg (args, const gchar *));
82 break;
83
84 case PANGO_ATTR_STYLE:
85 attr = pango_attr_style_new (va_arg (args, PangoStyle));
86 break;
87
88 case PANGO_ATTR_WEIGHT:
89 attr = pango_attr_weight_new (va_arg (args, PangoWeight));
90 break;
91
92 case PANGO_ATTR_VARIANT:
93 attr = pango_attr_variant_new (va_arg (args, PangoVariant));
94 break;
95
96 case PANGO_ATTR_STRETCH:
97 attr = pango_attr_stretch_new (va_arg (args, PangoStretch));
98 break;
99
100 case PANGO_ATTR_SIZE:
101 attr = pango_attr_size_new (va_arg (args, gint));
102 break;
103
104 case PANGO_ATTR_FONT_DESC:
105 attr = pango_attr_font_desc_new (va_arg (args,
106 const PangoFontDescription *));
107 break;
108
109 case PANGO_ATTR_FOREGROUND:
110 {
111 const PangoColor *color = va_arg (args, const PangoColor *);
112
113 attr = pango_attr_foreground_new (color->red,
114 color->green,
115 color->blue);
116 }
117 break;
118
119 case PANGO_ATTR_BACKGROUND:
120 {
121 const PangoColor *color = va_arg (args, const PangoColor *);
122
123 attr = pango_attr_background_new (color->red,
124 color->green,
125 color->blue);
126 }
127 break;
128
129 case PANGO_ATTR_UNDERLINE:
130 attr = pango_attr_underline_new (va_arg (args, PangoUnderline));
131 break;
132
133 case PANGO_ATTR_STRIKETHROUGH:
134 attr = pango_attr_strikethrough_new (va_arg (args, gboolean));
135 break;
136
137 case PANGO_ATTR_RISE:
138 attr = pango_attr_rise_new (va_arg (args, gint));
139 break;
140
141 case PANGO_ATTR_SCALE:
142 attr = pango_attr_scale_new (va_arg (args, gdouble));
143 break;
144
145 default:
146 //g_warning ("%s: invalid PangoAttribute type %d", G_STRFUNC, attr_type);
147 case PANGO_ATTR_INVALID:
148 attr = NULL;
149 break;
150 }
151
152 if (attr)
153 {
154 attr->start_index = 0;
155 attr->end_index = -1;
156 pango_attr_list_insert (attrs, attr);
157 }
158 }
159 while (attr);
160
161 va_end (args);
162
163 gtk_label_set_attributes (label, attrs);
164 pango_attr_list_unref (attrs);
165 }
166
167
168 void hb_widget_visible(GtkWidget *widget, gboolean visible)
169 {
170 if(!GTK_IS_WIDGET(widget))
171 return;
172
173 if(visible)
174 {
175 gtk_widget_show(widget);
176 }
177 else
178 {
179 gtk_widget_hide(widget);
180 }
181 }
182
183
184 void ui_label_set_integer(GtkLabel *label, gint value)
185 {
186 gchar buf[16];
187
188 g_snprintf(buf, 16, "%d", value);
189 gtk_label_set_text (label, buf);
190 }
191
192
193 void ui_gtk_entry_set_text(GtkWidget *widget, gchar *text)
194 {
195 DB( g_print(" set text to '%s'\n", text) );
196
197 if( text != NULL )
198 gtk_entry_set_text(GTK_ENTRY(widget), text);
199 else
200 gtk_entry_set_text(GTK_ENTRY(widget), "");
201 }
202
203 void ui_gtk_entry_replace_text(GtkWidget *widget, gchar **storage)
204 {
205 const gchar *text;
206
207 DB( g_print(" storage is '%p' at '%p'\n", *storage, storage) );
208
209 /* free any previous string */
210 if( *storage != NULL )
211 {
212 g_free(*storage);
213 }
214
215 *storage = NULL;
216 text = gtk_entry_get_text(GTK_ENTRY(widget));
217 *storage = g_strdup(text);
218 }
219
220
221 GtkWidget *make_clicklabel(gchar *id, gchar *str)
222 {
223 GtkWidget *label;
224 gchar buffer[255];
225
226 g_snprintf(buffer, 254, "<a href=\"%s\">%s</a>", id, str);
227 label = gtk_label_new(buffer);
228 gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
229 gtk_label_set_track_visited_links(GTK_LABEL(label), FALSE);
230 gtk_widget_set_halign(label, GTK_ALIGN_START);
231
232 return GTK_WIDGET(label);
233 }
234
235
236 GtkWidget *make_label_group(gchar *str)
237 {
238 GtkWidget *label = gtk_label_new (str);
239
240 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
241 gtk_widget_set_halign (label, GTK_ALIGN_START);
242 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
243 return label;
244 }
245
246
247 GtkWidget *make_label_widget(char *str)
248 {
249 GtkWidget *label = gtk_label_new_with_mnemonic (str);
250
251 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
252 gtk_widget_set_halign (label, GTK_ALIGN_END);
253 return label;
254 }
255
256
257 GtkWidget *make_label(char *str, gfloat xalign, gfloat yalign)
258 {
259 GtkWidget *label = gtk_label_new_with_mnemonic (str);
260
261 //todo: deprecated in 3.14
262 gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
263 //gtk_label_set_xalign(GTK_LABEL(label), xalign);
264 //gtk_label_set_yalign(GTK_LABEL(label), yalign);
265 return label;
266 }
267
268
269 /*
270 **
271 */
272 GtkWidget *make_text(gfloat xalign)
273 {
274 GtkWidget *entry;
275
276 entry = gtk_entry_new ();
277 gtk_editable_set_editable (GTK_EDITABLE(entry), FALSE);
278 g_object_set(entry, "xalign", xalign, NULL);
279 return entry;
280 }
281
282
283 GtkWidget *make_search(GtkWidget *label)
284 {
285 GtkWidget *search;
286
287 search = gtk_search_entry_new();
288 gtk_entry_set_placeholder_text(GTK_ENTRY(search), _("Search...") );
289
290 if(label)
291 gtk_label_set_mnemonic_widget (GTK_LABEL(label), search);
292
293 return search;
294 }
295
296
297
298 /*
299 **
300 */
301 GtkWidget *make_string(GtkWidget *label)
302 {
303 GtkWidget *entry;
304
305 entry = gtk_entry_new ();
306
307 if(label)
308 gtk_label_set_mnemonic_widget (GTK_LABEL(label), entry);
309
310 return entry;
311 }
312
313
314 GtkWidget *make_image_button(gchar *icon_name, gchar *tooltip_text)
315 {
316 GtkWidget *button, *image;
317
318 //todo 3.10 use gtk_button_new_from_icon_name
319
320 button = gtk_button_new();
321 image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
322 g_object_set (button, "image", image, NULL);
323 if(tooltip_text != NULL)
324 gtk_widget_set_tooltip_text(button, tooltip_text);
325
326 return button;
327 }
328
329
330
331 /*
332 **
333 */
334 GtkWidget *make_memo_entry(GtkWidget *label)
335 {
336 GtkListStore *store;
337 GtkWidget *entry;
338 GtkEntryCompletion *completion;
339 GList *lmem, *list;
340
341 store = gtk_list_store_new (1, G_TYPE_STRING);
342
343 completion = gtk_entry_completion_new ();
344 gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(store));
345 gtk_entry_completion_set_text_column (completion, 0);
346
347 entry = gtk_entry_new ();
348 gtk_entry_set_completion (GTK_ENTRY (entry), completion);
349
350 g_object_unref(store);
351
352 //populate
353 //gtk_list_store_clear (GTK_LIST_STORE(store));
354
355 lmem = list = g_hash_table_get_keys(GLOBALS->h_memo);
356 while (list != NULL)
357 {
358 GtkTreeIter iter;
359
360 //gtk_list_store_append (GTK_LIST_STORE(store), &iter);
361 //gtk_list_store_set (GTK_LIST_STORE(store), &iter, 0, list->data, -1);
362 gtk_list_store_insert_with_values(GTK_LIST_STORE(store), &iter, -1,
363 0, list->data,
364 -1);
365
366 list = g_list_next(list);
367 }
368
369 g_list_free(lmem);
370
371 if(label)
372 gtk_label_set_mnemonic_widget (GTK_LABEL(label), entry);
373
374 return entry;
375 }
376
377
378 /*
379 **
380 */
381 GtkWidget *make_string_maxlength(GtkWidget *label, guint max_length)
382 {
383 GtkWidget *entry;
384
385 entry = make_string(label);
386 gtk_entry_set_width_chars(GTK_ENTRY(entry), max_length+2);
387 gtk_entry_set_max_length(GTK_ENTRY(entry), max_length);
388
389 return entry;
390 }
391
392
393
394 static void hb_amount_insert_text_handler (GtkEntry *entry, const gchar *text, gint length, gint *position, gpointer data)
395 {
396 GtkEditable *editable = GTK_EDITABLE(entry);
397 int i, count=0, dcpos=-1;
398 gchar *result = g_new0 (gchar, length+1);
399 int digits = 2;
400 const gchar *numtext;
401
402 //g_message("insert_text-handler: text:%s - pos:%d - length:%d", text, *position, length);
403
404 digits = gtk_spin_button_get_digits(GTK_SPIN_BUTTON(entry));
405 numtext = gtk_entry_get_text(entry);
406 for (i=0 ; numtext[i]!='\0' ; i++)
407 {
408 if(numtext[i]==',' || numtext[i]=='.')
409 dcpos = i;
410 }
411
412 //g_message("previous text='%s' dcpos:'%d'", numtext, dcpos);
413 for (i=0 ; i < length ; i++)
414 {
415 if( isdigit(text[i]) && ( (*position <= dcpos + digits) || dcpos < 0) )
416 goto inserttext;
417
418 if( text[i]=='-' && *position==0 ) /* minus sign only at position 0 */
419 goto inserttext;
420
421 if( dcpos < 0 && (text[i]=='.' || text[i]==',') ) /* decimal separator if not in previous string */
422 result[count++] = '.';
423
424 continue;
425
426 inserttext:
427 result[count++] = text[i];
428 }
429
430 if (count > 0) {
431 g_signal_handlers_block_by_func (G_OBJECT (editable), G_CALLBACK (hb_amount_insert_text_handler), data);
432 gtk_editable_insert_text (editable, result, count, position);
433 g_signal_handlers_unblock_by_func (G_OBJECT (editable), G_CALLBACK (hb_amount_insert_text_handler), data);
434 }
435 g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
436
437 g_free (result);
438 }
439
440 /*
441 **
442 */
443 GtkWidget *make_amount(GtkWidget *label)
444 {
445 GtkWidget *spinner;
446 GtkAdjustment *adj;
447
448 //adj = (GtkAdjustment *) gtk_adjustment_new (0.0, -G_MAXDOUBLE, G_MAXDOUBLE, 0.01, 1.0, 0.0);
449 adj = (GtkAdjustment *) gtk_adjustment_new (0.0, -8589934588, 8589934588, 0.01, 1.0, 0.0);
450 spinner = gtk_spin_button_new (adj, 1.0, 2);
451 g_object_set(spinner, "xalign", 1.0, NULL);
452
453 if(label)
454 gtk_label_set_mnemonic_widget (GTK_LABEL(label), spinner);
455
456 g_signal_connect(G_OBJECT(spinner), "insert-text",
457 G_CALLBACK(hb_amount_insert_text_handler),
458 NULL);
459
460 return spinner;
461 }
462
463
464 GtkWidget *make_exchange_rate(GtkWidget *label)
465 {
466 GtkWidget *spinner;
467 GtkAdjustment *adj;
468
469 adj = (GtkAdjustment *) gtk_adjustment_new (0.0, 0.0, 99999, 0.01, 1.0, 0.0);
470 spinner = gtk_spin_button_new (adj, 1.0, 6);
471 //gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
472 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinner), TRUE);
473 g_object_set(spinner, "xalign", 1.0, NULL);
474
475 if(label)
476 gtk_label_set_mnemonic_widget (GTK_LABEL(label), spinner);
477
478 return spinner;
479 }
480
481 /*
482 **
483 */
484 GtkWidget *make_numeric(GtkWidget *label, gdouble min, gdouble max)
485 {
486 GtkWidget *spinner;
487 GtkAdjustment *adj;
488
489 adj = (GtkAdjustment *) gtk_adjustment_new (0.0, min, max, 1.0, 10.0, 0.0);
490 spinner = gtk_spin_button_new (adj, 0, 0);
491 //gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
492 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinner), TRUE);
493 g_object_set(spinner, "xalign", 1.0, NULL);
494
495 if(label)
496 gtk_label_set_mnemonic_widget (GTK_LABEL(label), spinner);
497
498 return spinner;
499 }
500
501 /*
502 **
503 */
504 GtkWidget *make_scale(GtkWidget *label)
505 {
506 GtkWidget *scale;
507
508 scale = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, GTK_CHART_MINBARW, GTK_CHART_SPANBARW, 1.0);
509 gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE);
510 gtk_range_set_value(GTK_RANGE(scale), GTK_CHART_BARW);
511
512 if(label)
513 gtk_label_set_mnemonic_widget (GTK_LABEL(label), scale);
514
515 return scale;
516 }
517
518 /*
519 **
520 */
521 GtkWidget *make_long(GtkWidget *label)
522 {
523 GtkWidget *spinner;
524
525 spinner = make_numeric(label, 0.0, G_MAXINT);
526 return spinner;
527 }
528
529
530 GtkWidget *make_year(GtkWidget *label)
531 {
532 GtkWidget *spinner;
533 GtkAdjustment *adj;
534
535 adj = (GtkAdjustment *) gtk_adjustment_new (0.0, 1900, 2200, 1.0, 10.0, 0.0);
536 spinner = gtk_spin_button_new (adj, 0, 0);
537 gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner), TRUE);
538 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinner), TRUE);
539 g_object_set(spinner, "xalign", 1.0, NULL);
540
541 if(label)
542 gtk_label_set_mnemonic_widget (GTK_LABEL(label), spinner);
543
544 return spinner;
545 }
546
547
548 static gboolean
549 is_separator (GtkTreeModel *model,
550 GtkTreeIter *iter,
551 gpointer data)
552 {
553 //GtkTreePath *path;
554 gboolean retval;
555 gchar *txt;
556
557 gtk_tree_model_get (model, iter, 0, &txt, -1);
558
559 retval = *txt == 0 ? TRUE : FALSE;
560 //path = gtk_tree_model_get_path (model, iter);
561 //result = gtk_tree_path_get_indices (path)[0] == 4;
562 //gtk_tree_path_free (path);
563
564 //leak
565 g_free(txt);
566
567
568 return retval;
569 }
570
571 static void
572 set_sensitive (GtkCellLayout *cell_layout,
573 GtkCellRenderer *cell,
574 GtkTreeModel *tree_model,
575 GtkTreeIter *iter,
576 gpointer data)
577 {
578 GtkTreePath *path;
579 gint *indices;
580 gboolean sensitive;
581
582 path = gtk_tree_model_get_path (tree_model, iter);
583 indices = gtk_tree_path_get_indices (path);
584 sensitive = indices[0] != FLT_RANGE_OTHER;
585 gtk_tree_path_free (path);
586
587 g_object_set (cell, "sensitive", sensitive, NULL);
588 }
589
590
591 GtkWidget *make_cycle(GtkWidget *label, gchar **items)
592 {
593 GtkWidget *combobox;
594 guint i;
595
596 combobox = gtk_combo_box_text_new ();
597
598 for (i = 0; items[i] != NULL; i++)
599 {
600 if(*items[i] != 0)
601 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), _(items[i]));
602 else
603 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), "");
604 }
605 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
606 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL);
607
608 if(label)
609 gtk_label_set_mnemonic_widget (GTK_LABEL(label), combobox);
610
611 return combobox;
612 }
613
614
615 GtkWidget *make_daterange(GtkWidget *label, gboolean custom)
616 {
617 GtkWidget *combobox;
618 GList *renderers, *list;
619 GtkCellRenderer *renderer;
620 gchar **items = CYA_FLT_RANGE;
621 guint i;
622
623 combobox = gtk_combo_box_text_new ();
624
625 for (i = 0; items[i] != NULL; i++)
626 {
627 if(*items[i] != 0)
628 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), _(items[i]));
629 else
630 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(combobox), "");
631 }
632 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
633
634 if(label)
635 gtk_label_set_mnemonic_widget (GTK_LABEL(label), combobox);
636
637 // special stuffs
638 renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT(combobox));
639 if(g_list_length(renderers) == 1 && custom == FALSE)
640 {
641 list = g_list_first(renderers);
642 renderer = list->data;
643
644
645 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
646 renderer,
647 set_sensitive,
648 NULL, NULL);
649 }
650 g_list_free(renderers);
651
652 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combobox), is_separator, NULL, NULL);
653
654 return combobox;
655 }
656
657 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
658
659 /*
660 **
661 */
662 GtkWidget *make_radio(gchar **items, gboolean buttonstyle, GtkOrientation orientation)
663 {
664 GtkWidget *box, *button;
665 guint i;
666
667 box = gtk_box_new (orientation, 0);
668
669 button = gtk_radio_button_new_with_label (NULL, _(items[0]));
670 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), !buttonstyle);
671 gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
672 for (i = 1; items[i] != NULL; i++)
673 {
674 button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (button), _(items[i]));
675 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), !buttonstyle);
676 gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
677 }
678
679 if(buttonstyle)
680 {
681 gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LINKED);
682 gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_RAISED);
683 }
684
685 return box;
686 }
687
688
689 gint radio_get_active (GtkContainer *container)
690 {
691 GList *lchild, *list;
692 GtkWidget *radio;
693 gint i, retval = 0;
694
695 if(!GTK_IS_CONTAINER(container))
696 return -1;
697
698 lchild = list = gtk_container_get_children (container);
699 for(i=0;list != NULL;i++)
700 {
701 radio = list->data;
702 if(GTK_IS_TOGGLE_BUTTON(radio))
703 {
704 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio)) == TRUE )
705 {
706 retval = i;
707 break;
708 }
709 }
710 list = g_list_next(list);
711 }
712 g_list_free(lchild);
713
714 return retval;
715 }
716
717 GtkWidget *radio_get_nth_widget (GtkContainer *container, gint nth)
718 {
719 GList *lchild, *list;
720 GtkWidget *radio;
721
722 if(!GTK_IS_CONTAINER(container))
723 return NULL;
724
725 lchild = list = gtk_container_get_children (container);
726 radio = g_list_nth_data (list, nth);
727 g_list_free(lchild);
728 return radio; //may return NULL
729 }
730
731
732
733 void radio_set_active (GtkContainer *container, gint active)
734 {
735 GList *lchild, *list;
736 GtkWidget *radio;
737
738 if(!GTK_IS_CONTAINER(container))
739 return;
740
741 lchild = list = gtk_container_get_children (container);
742 radio = g_list_nth_data (list, active);
743 if(radio != NULL && GTK_IS_TOGGLE_BUTTON(radio))
744 {
745 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio), TRUE);
746 }
747 g_list_free(lchild);
748 }
749
750
751 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
752
753 /*
754 id ofx english french
755 ---------------------------------------------------------------------
756 0 -------- (none) (aucun)
757 1 -------- credit card carte de crédit
758 2 OFX_CHECK Check cheque
759 3 OFX_CASH Cash withdrawal retrait espece
760 4 OFX_XFER Transfer virement
761 5 -------- internal transfer virement compte
762 6 -------- (debit card) (carte de paiement
763 7 OFX_REPEATPMT Repeating payment/standing order Paiement recurrent/Virement auto.
764
765 8 OFX_PAYMENT Electronic payment télépaiement
766 9 OFX_DEP Deposit dépôt
767 10 OFX_FEE FI fee frais bancaires
768
769
770 OFX_DIRECTDEBIT Merchant initiated debit prelevement
771 OFX_OTHER Somer other type of transaction autre
772
773 other OFX values:
774
775 OFX_CREDIT Generic credit
776 OFX_DEBIT Generic debit
777 OFX_INT Interest earned or paid (Note: Depends on signage of amount)
778 OFX_DIV Dividend
779 OFX_SRVCHG Service charge
780 -OFX_DEP Deposit
781 OFX_ATM ATM debit or credit (Note: Depends on signage of amount)
782 OFX_POS Point of sale debit or credit (Note: Depends on signage of amount)
783 -OFX_XFER Transfer
784 -OFX_CHECK Check
785 -OFX_PAYMENT Electronic payment
786 -OFX_CASH Cash withdrawal
787 OFX_DIRECTDEP Direct deposit
788 OFX_DIRECTDEBIT Merchant initiated debit
789 -OFX_REPEATPMT Repeating payment/standing order
790 OFX_OTHER Somer other type of transaction
791 */
792
793 enum
794 {
795 LST_PAYMODE_ICONNAME,
796 LST_PAYMODE_LABEL,
797 NUM_LST_PAYMODE
798 };
799
800 char *paymode_iconnames[NUM_PAYMODE_MAX] =
801 {
802 "pm-none",
803 "pm-ccard",
804 "pm-check",
805 "pm-cash" ,
806 "pm-transfer",
807 "pm-intransfer",
808 "pm-dcard",
809 "pm-standingorder",
810 "pm-epayment",
811 "pm-deposit",
812 "pm-fifee",
813 "pm-directdebit"
814 };
815
816 char *paymode_label_names[NUM_PAYMODE_MAX] =
817 {
818 N_("(none)"),
819 N_("Credit card"),
820 N_("Check"),
821 N_("Cash"),
822 N_("Transfer"),
823 N_("Internal transfer"),
824 N_("Debit card"),
825 N_("Standing order"),
826 N_("Electronic payment"),
827 N_("Deposit"),
828 //TRANSLATORS: Financial institution fee
829 N_("FI fee"),
830 N_("Direct Debit")
831 };
832
833 /* nota: used in ui-filter */
834 gchar *get_paymode_icon_name(gint index)
835 {
836 if(index >= NUM_PAYMODE_MAX)
837 return NULL;
838
839 return paymode_iconnames[index];
840 }
841
842
843 /*
844 ** Make a paymode combobox widget
845 */
846
847 static void
848 paymode_set_sensitive (GtkCellLayout *cell_layout,
849 GtkCellRenderer *cell,
850 GtkTreeModel *tree_model,
851 GtkTreeIter *iter,
852 gpointer data)
853 {
854 GtkTreePath *path;
855 gint *indices;
856 gboolean sensitive;
857
858 path = gtk_tree_model_get_path (tree_model, iter);
859 indices = gtk_tree_path_get_indices (path);
860 sensitive = (indices[0] == PAYMODE_INTXFER) ? FALSE : TRUE;
861 gtk_tree_path_free (path);
862
863
864 g_object_set (cell, "sensitive", sensitive, NULL);
865 }
866
867
868
869 static GtkWidget *make_paymode_internal(GtkWidget *label, gboolean intxfer)
870 {
871 GtkListStore *store;
872 GtkTreeIter iter;
873 GtkWidget *combobox;
874 GtkCellRenderer *renderer, *r1, *r2;
875 guint i;
876
877 store = gtk_list_store_new (
878 NUM_LST_PAYMODE,
879 G_TYPE_STRING,
880 G_TYPE_STRING
881 );
882
883 combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
884
885 renderer = r1 = gtk_cell_renderer_pixbuf_new();
886 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, FALSE);
887 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(combobox), renderer, "icon-name", LST_PAYMODE_ICONNAME);
888
889 renderer = r2 = gtk_cell_renderer_text_new();
890 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, FALSE);
891 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(combobox), renderer, "text", LST_PAYMODE_LABEL);
892
893
894 if( intxfer == FALSE )
895 {
896 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
897 r1,
898 paymode_set_sensitive,
899 NULL, NULL);
900 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combobox),
901 r2,
902 paymode_set_sensitive,
903 NULL, NULL);
904 }
905
906 //populate our combobox model
907 for(i=0;i<NUM_PAYMODE_MAX;i++)
908 {
909 gtk_list_store_append(store, &iter);
910 gtk_list_store_set(store, &iter,
911 LST_PAYMODE_ICONNAME, paymode_iconnames[i],
912 LST_PAYMODE_LABEL, _(paymode_label_names[i]),
913 -1);
914 }
915
916 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
917
918 if(label)
919 gtk_label_set_mnemonic_widget (GTK_LABEL(label), combobox);
920
921 return combobox;
922 }
923
924
925
926 GtkWidget *make_paymode(GtkWidget *label)
927 {
928 return make_paymode_internal(label, TRUE);
929 }
930
931 GtkWidget *make_paymode_nointxfer(GtkWidget *label)
932 {
933 return make_paymode_internal(label, FALSE);
934 }
935
936
937 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
938
939 #define NUM_NAINEX_MAX 3
940
941 enum
942 {
943 LST_NAINEX_ICONNAME,
944 LST_NAINEX_LABEL,
945 NUM_LST_NAINEX
946 };
947
948 char *nainex_iconnames[NUM_NAINEX_MAX] =
949 {
950 "flt-inactive",
951 "flt-include",
952 "flt-exclude",
953 };
954
955 char *nainex_label_names[NUM_NAINEX_MAX] =
956 {
957 N_("Inactive"),
958 N_("Include"),
959 N_("Exclude"),
960 };
961
962
963 /*
964 ** Make a nainex combobox widget
965 */
966 GtkWidget *make_nainex(GtkWidget *label)
967 {
968 GtkListStore *store;
969 GtkTreeIter iter;
970 GtkWidget *combobox;
971 GtkCellRenderer *renderer;
972 guint i;
973
974 //store
975 store = gtk_list_store_new (
976 NUM_LST_NAINEX,
977 G_TYPE_STRING,
978 G_TYPE_STRING
979 );
980
981 //combobox
982 combobox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
983
984 //column 1
985 renderer = gtk_cell_renderer_pixbuf_new();
986 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, FALSE);
987 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(combobox), renderer, "icon-name", LST_NAINEX_ICONNAME);
988
989 renderer = gtk_cell_renderer_text_new();
990 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox), renderer, FALSE);
991 gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(combobox), renderer, "text", LST_NAINEX_LABEL);
992
993 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
994
995 //populate our combobox model
996 for(i=0;i<NUM_NAINEX_MAX;i++)
997 {
998 gtk_list_store_append(store, &iter);
999 gtk_list_store_set(store, &iter,
1000 LST_NAINEX_ICONNAME, nainex_iconnames[i],
1001 LST_NAINEX_LABEL, _(nainex_label_names[i]),
1002 -1);
1003 }
1004 gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), 0);
1005
1006 if(label)
1007 gtk_label_set_mnemonic_widget (GTK_LABEL(label), combobox);
1008
1009 return combobox;
1010 }
1011
This page took 0.096533 seconds and 4 git commands to generate.