]> Dogcows Code - chaz/homebank/blob - src/ui-payee.c
1ee6560d664b8930964fb3851b23f61cef13b4a6
[chaz/homebank] / src / ui-payee.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 "ui-payee.h"
24 #include "ui-category.h"
25
26 #define MYDEBUG 0
27
28 #if MYDEBUG
29 #define DB(x) (x);
30 #else
31 #define DB(x);
32 #endif
33
34 /* our global datas */
35 extern struct HomeBank *GLOBALS;
36 extern struct Preferences *PREFS;
37
38
39 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
40
41 /**
42 * ui_pay_comboboxentry_get_name:
43 *
44 * get the name of the active payee or -1
45 *
46 * Return value: a new allocated name tobe freed with g_free
47 *
48 */
49 gchar *
50 ui_pay_comboboxentry_get_name(GtkComboBox *entry_box)
51 {
52 gchar *cbname;
53 gchar *name = NULL;
54
55 DB( g_print ("ui_pay_comboboxentry_get_name()\n") );
56
57 cbname = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
58 if( cbname != NULL)
59 {
60 name = g_strdup(cbname);
61 g_strstrip(name);
62 }
63
64 return name;
65 }
66
67
68 /**
69 * ui_pay_comboboxentry_get_key_add_new:
70 *
71 * get the key of the active payee
72 * and create the payee if it do not exists
73 *
74 * Return value: the key or 0
75 *
76 */
77 guint32
78 ui_pay_comboboxentry_get_key_add_new(GtkComboBox *entry_box)
79 {
80 gchar *name;
81 Payee *item;
82
83 name = ui_pay_comboboxentry_get_name(entry_box);
84
85 item = da_pay_get_by_name(name);
86 if( item == NULL )
87 {
88 /* automatic add */
89 //todo: check prefs + ask the user here 1st time
90 item = da_pay_malloc();
91 item->name = g_strdup(name);
92 da_pay_append(item);
93 ui_pay_comboboxentry_add(entry_box, item);
94 }
95
96 g_free(name);
97
98 return item->key;
99 }
100
101 /**
102 * ui_pay_comboboxentry_get_key:
103 *
104 * get the key of the active payee
105 *
106 * Return value: the key or 0
107 *
108 */
109 guint32
110 ui_pay_comboboxentry_get_key(GtkComboBox *entry_box)
111 {
112 gchar *name;
113 Payee *item;
114
115 name = ui_pay_comboboxentry_get_name(entry_box);
116 item = da_pay_get_by_name(name);
117 g_free(name);
118
119 if( item != NULL )
120 return item->key;
121
122 return 0;
123 }
124
125
126 Payee
127 *ui_pay_comboboxentry_get(GtkComboBox *entry_box)
128 {
129 gchar *name;
130 Payee *item = NULL;
131
132 DB( g_print ("ui_pay_comboboxentry_get()\n") );
133
134 name = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
135 item = da_pay_get_by_name(name);
136
137 return item;
138 }
139
140
141 gboolean
142 ui_pay_comboboxentry_set_active(GtkComboBox *entry_box, guint32 key)
143 {
144 Payee *item;
145
146 if( key > 0 )
147 {
148 item = da_pay_get(key);
149 if( item != NULL)
150 {
151 gtk_entry_set_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))), item->name);
152 return TRUE;
153 }
154 }
155 gtk_entry_set_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))), "");
156 return FALSE;
157 }
158
159 /**
160 * ui_pay_comboboxentry_add:
161 *
162 * Add a single element (useful for dynamics add)
163 *
164 * Return value: --
165 *
166 */
167 void
168 ui_pay_comboboxentry_add(GtkComboBox *entry_box, Payee *pay)
169 {
170 if( pay->name != NULL )
171 {
172 GtkTreeModel *model;
173 GtkTreeIter iter;
174
175 model = gtk_combo_box_get_model(GTK_COMBO_BOX(entry_box));
176
177 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
178 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, pay->name, -1);
179 }
180 }
181
182 static void
183 ui_pay_comboboxentry_populate_ghfunc(gpointer key, gpointer value, struct payPopContext *ctx)
184 {
185 GtkTreeIter iter;
186 Payee *pay = value;
187
188 if( ( pay->key != ctx->except_key ) )
189 {
190 //gtk_list_store_append (GTK_LIST_STORE(ctx->model), &iter);
191 //gtk_list_store_set (GTK_LIST_STORE(ctx->model), &iter, 0, pay->name, -1);
192 gtk_list_store_insert_with_values(GTK_LIST_STORE(ctx->model), &iter, -1,
193 0, pay->name, -1);
194 }
195 }
196
197 /**
198 * ui_pay_comboboxentry_populate:
199 *
200 * Populate the list and completion
201 *
202 * Return value: --
203 *
204 */
205 void
206 ui_pay_comboboxentry_populate(GtkComboBox *entry_box, GHashTable *hash)
207 {
208 ui_pay_comboboxentry_populate_except(entry_box, hash, -1);
209 }
210
211 void
212 ui_pay_comboboxentry_populate_except(GtkComboBox *entry_box, GHashTable *hash, guint except_key)
213 {
214 GtkTreeModel *model;
215 //GtkEntryCompletion *completion;
216 struct payPopContext ctx;
217
218 DB( g_print ("ui_pay_comboboxentry_populate\n") );
219
220 model = gtk_combo_box_get_model(GTK_COMBO_BOX(entry_box));
221 //completion = gtk_entry_get_completion(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (entry_box))));
222
223 /* keep our model alive and detach from comboboxentry and completion */
224 //g_object_ref(model);
225 //gtk_combo_box_set_model(GTK_COMBO_BOX(entry_box), NULL);
226 //gtk_entry_completion_set_model (completion, NULL);
227
228 /* clear and populate */
229 ctx.model = model;
230 ctx.except_key = except_key;
231 gtk_list_store_clear (GTK_LIST_STORE(model));
232
233 //gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(GTK_LIST_STORE(model)), GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
234
235 g_hash_table_foreach(hash, (GHFunc)ui_pay_comboboxentry_populate_ghfunc, &ctx);
236
237 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
238
239 /* reatach our model */
240 //g_print("reattach\n");
241 //gtk_combo_box_set_model(GTK_COMBO_BOX(entry_box), model);
242 //gtk_entry_completion_set_model (completion, model);
243 //g_object_unref(model);
244
245 }
246
247
248 static gint
249 ui_pay_comboboxentry_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
250 {
251 gint retval = 0;
252 gchar *name1, *name2;
253
254 gtk_tree_model_get(model, a, 0, &name1, -1);
255 gtk_tree_model_get(model, b, 0, &name2, -1);
256
257 retval = hb_string_utf8_compare(name1, name2);
258
259 g_free(name2);
260 g_free(name1);
261
262 return retval;
263 }
264
265
266 static void
267 ui_pay_comboboxentry_test (GtkCellLayout *cell_layout,
268 GtkCellRenderer *cell,
269 GtkTreeModel *tree_model,
270 GtkTreeIter *iter,
271 gpointer data)
272 {
273 gchar *name;
274
275 gtk_tree_model_get(tree_model, iter,
276 0, &name,
277 -1);
278
279 if( !name )
280 g_object_set(cell, "text", _("(no payee)"), NULL);
281 else
282 g_object_set(cell, "text", name, NULL);
283
284 //leak
285 g_free(name);
286
287 }
288
289 /**
290 * ui_pay_comboboxentry_new:
291 *
292 * Create a new payee comboboxentry
293 *
294 * Return value: the new widget
295 *
296 */
297 GtkWidget *
298 ui_pay_comboboxentry_new(GtkWidget *label)
299 {
300 GtkListStore *store;
301 GtkWidget *comboboxentry;
302 GtkEntryCompletion *completion;
303 GtkCellRenderer *renderer;
304
305 DB( g_print ("ui_pay_comboboxentry_new()\n") );
306
307 store = gtk_list_store_new (1,
308 G_TYPE_STRING
309 );
310 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), ui_pay_comboboxentry_compare_func, NULL, NULL);
311
312 completion = gtk_entry_completion_new ();
313 gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(store));
314 g_object_set(completion, "text-column", 0, NULL);
315
316 renderer = gtk_cell_renderer_text_new ();
317 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), renderer, TRUE);
318 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (completion), renderer, "text", 0, NULL);
319
320 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
321 renderer,
322 ui_pay_comboboxentry_test,
323 NULL, NULL);
324
325 // dothe same for combobox
326
327 comboboxentry = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store));
328 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(comboboxentry), 0);
329
330 gtk_cell_layout_clear(GTK_CELL_LAYOUT (comboboxentry));
331
332 renderer = gtk_cell_renderer_text_new ();
333 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (comboboxentry), renderer, TRUE);
334 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (comboboxentry), renderer, "text", 0, NULL);
335
336 gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (comboboxentry),
337 renderer,
338 ui_pay_comboboxentry_test,
339 NULL, NULL);
340
341
342
343 gtk_entry_set_completion (GTK_ENTRY (gtk_bin_get_child(GTK_BIN (comboboxentry))), completion);
344
345 g_object_unref(store);
346
347 if(label)
348 gtk_label_set_mnemonic_widget (GTK_LABEL(label), comboboxentry);
349
350 gtk_widget_set_size_request(comboboxentry, HB_MINWIDTH_LIST, -1);
351
352 return comboboxentry;
353 }
354
355
356 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
357
358 static void
359 ui_pay_listview_toggled_cb (GtkCellRendererToggle *cell,
360 gchar *path_str,
361 gpointer data)
362 {
363 GtkTreeModel *model = (GtkTreeModel *)data;
364 GtkTreeIter iter;
365 GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
366 gboolean fixed;
367
368 /* get toggled iter */
369 gtk_tree_model_get_iter (model, &iter, path);
370 gtk_tree_model_get (model, &iter, LST_DEFPAY_TOGGLE, &fixed, -1);
371
372 /* do something with the value */
373 fixed ^= 1;
374
375 /* set new value */
376 gtk_list_store_set (GTK_LIST_STORE (model), &iter, LST_DEFPAY_TOGGLE, fixed, -1);
377
378 /* clean up */
379 gtk_tree_path_free (path);
380 }
381
382
383 static gint
384 ui_pay_listview_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
385 {
386 gint sortcol = GPOINTER_TO_INT(userdata);
387 Payee *entry1, *entry2;
388 gint retval = 0;
389
390 gtk_tree_model_get(model, a, LST_DEFPAY_DATAS, &entry1, -1);
391 gtk_tree_model_get(model, b, LST_DEFPAY_DATAS, &entry2, -1);
392
393 switch (sortcol)
394 {
395 case LST_DEFPAY_SORT_NAME:
396 retval = hb_string_utf8_compare(entry1->name, entry2->name);
397 break;
398 case LST_DEFPAY_SORT_USED:
399 retval = entry1->usage_count - entry2->usage_count;
400 break;
401 case LST_DEFPAY_SORT_DEFCAT:
402 {
403 Category *c1, *c2;
404 gchar *name1, *name2;
405
406 c1 = da_cat_get(entry1->kcat);
407 c2 = da_cat_get(entry2->kcat);
408 if( c1 != NULL && c2 != NULL )
409 {
410 name1 = da_cat_get_fullname(c1);
411 name2 = da_cat_get_fullname(c2);
412 retval = hb_string_utf8_compare(name1, name2);
413 g_free(name2);
414 g_free(name1);
415 }
416 }
417 break;
418 default:
419 g_return_val_if_reached(0);
420 }
421
422 return retval;
423 }
424
425
426 static void
427 ui_pay_listview_count_cell_data_function (GtkTreeViewColumn *col,
428 GtkCellRenderer *renderer,
429 GtkTreeModel *model,
430 GtkTreeIter *iter,
431 gpointer user_data)
432 {
433 Payee *entry;
434 gchar buffer[256];
435
436 gtk_tree_model_get(model, iter, LST_DEFPAY_DATAS, &entry, -1);
437 if(entry->usage_count > 0)
438 {
439 g_snprintf(buffer, 256-1, "%d", entry->usage_count);
440 g_object_set(renderer, "text", buffer, NULL);
441 }
442 else
443 g_object_set(renderer, "text", "", NULL);
444 }
445
446
447 static void
448 ui_pay_listview_defcat_cell_data_function (GtkTreeViewColumn *col,
449 GtkCellRenderer *renderer,
450 GtkTreeModel *model,
451 GtkTreeIter *iter,
452 gpointer user_data)
453 {
454 Payee *entry;
455 Category *cat;
456 gchar *fullname;
457
458 gtk_tree_model_get(model, iter, LST_DEFPAY_DATAS, &entry, -1);
459
460 cat = da_cat_get(entry->kcat);
461 if( cat != NULL )
462 {
463 fullname = da_cat_get_fullname(cat);
464 g_object_set(renderer, "text", fullname, NULL);
465 g_free(fullname);
466 }
467 else
468 g_object_set(renderer, "text", "", NULL);
469 }
470
471
472 static void
473 ui_pay_listview_name_cell_data_function (GtkTreeViewColumn *col,
474 GtkCellRenderer *renderer,
475 GtkTreeModel *model,
476 GtkTreeIter *iter,
477 gpointer user_data)
478 {
479 Payee *entry;
480 gchar *name;
481 #if MYDEBUG
482 gchar *string;
483 #endif
484
485 gtk_tree_model_get(model, iter, LST_DEFPAY_DATAS, &entry, -1);
486
487 if(entry->key == 0)
488 name = _("(no payee)");
489 else
490 name = entry->name;
491
492 #if MYDEBUG
493 string = g_strdup_printf ("%d > %s [ft=%d]", entry->key, name, entry->filter);
494 g_object_set(renderer, "text", string, NULL);
495 g_free(string);
496 #else
497 g_object_set(renderer, "text", name, NULL);
498 #endif
499
500 }
501
502
503 /* = = = = = = = = = = = = = = = = */
504
505
506 void
507 ui_pay_listview_add(GtkTreeView *treeview, Payee *item)
508 {
509 GtkTreeModel *model;
510 GtkTreeIter iter;
511
512 if( item->name != NULL )
513 {
514 model = gtk_tree_view_get_model(treeview);
515
516 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
517 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
518 LST_DEFPAY_TOGGLE, FALSE,
519 LST_DEFPAY_DATAS, item,
520 -1);
521 }
522 }
523
524 guint32
525 ui_pay_listview_get_selected_key(GtkTreeView *treeview)
526 {
527 GtkTreeSelection *selection;
528 GtkTreeModel *model;
529 GtkTreeIter iter;
530
531 selection = gtk_tree_view_get_selection(treeview);
532 if (gtk_tree_selection_get_selected(selection, &model, &iter))
533 {
534 Payee *item;
535
536 gtk_tree_model_get(model, &iter, LST_DEFPAY_DATAS, &item, -1);
537
538 if( item!= NULL )
539 return item->key;
540 }
541 return 0;
542 }
543
544 void
545 ui_pay_listview_remove_selected(GtkTreeView *treeview)
546 {
547 GtkTreeSelection *selection;
548 GtkTreeModel *model;
549 GtkTreeIter iter;
550
551 DB( g_print("ui_pay_listview_remove_selected() \n") );
552
553 selection = gtk_tree_view_get_selection(treeview);
554 if (gtk_tree_selection_get_selected(selection, &model, &iter))
555 {
556 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
557 }
558 }
559
560
561 static void ui_pay_listview_populate_ghfunc(gpointer key, gpointer value, GtkTreeModel *model)
562 {
563 GtkTreeIter iter;
564 Payee *item = value;
565
566 //DB( g_print(" populate: %p\n", key) );
567
568 //gtk_list_store_append (GTK_LIST_STORE(model), &iter);
569 //gtk_list_store_set (GTK_LIST_STORE(model), &iter,
570 gtk_list_store_insert_with_values(GTK_LIST_STORE(model), &iter, -1,
571 LST_DEFPAY_TOGGLE , FALSE,
572 LST_DEFPAY_DATAS, item,
573 -1);
574 }
575
576 void ui_pay_listview_populate(GtkWidget *view)
577 {
578 GtkTreeModel *model;
579
580 DB( g_print("ui_pay_listview_populate \n") );
581
582 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
583 gtk_list_store_clear (GTK_LIST_STORE(model));
584
585 //g_object_ref(model); /* Make sure the model stays with us after the tree view unrefs it */
586 //gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL); /* Detach model from view */
587
588 /* populate */
589 g_hash_table_foreach(GLOBALS->h_pay, (GHFunc)ui_pay_listview_populate_ghfunc, model);
590
591 //gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); /* Re-attach model to view */
592 //g_object_unref(model);
593 }
594
595
596 static gboolean ui_pay_listview_search_equal_func (GtkTreeModel *model,
597 gint column,
598 const gchar *key,
599 GtkTreeIter *iter,
600 gpointer search_data)
601 {
602 gboolean retval = TRUE;
603 gchar *normalized_string;
604 gchar *normalized_key;
605 gchar *case_normalized_string = NULL;
606 gchar *case_normalized_key = NULL;
607 Payee *item;
608
609 //gtk_tree_model_get_value (model, iter, column, &value);
610 gtk_tree_model_get(model, iter, LST_DEFPAY_DATAS, &item, -1);
611
612 if(item != NULL)
613 {
614 normalized_string = g_utf8_normalize (item->name, -1, G_NORMALIZE_ALL);
615 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
616
617 if (normalized_string && normalized_key)
618 {
619 case_normalized_string = g_utf8_casefold (normalized_string, -1);
620 case_normalized_key = g_utf8_casefold (normalized_key, -1);
621
622 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
623 retval = FALSE;
624 }
625
626 g_free (normalized_key);
627 g_free (normalized_string);
628 g_free (case_normalized_key);
629 g_free (case_normalized_string);
630 }
631 return retval;
632 }
633
634
635 GtkWidget *
636 ui_pay_listview_new(gboolean withtoggle, gboolean withcount)
637 {
638 GtkListStore *store;
639 GtkWidget *treeview;
640 GtkCellRenderer *renderer;
641 GtkTreeViewColumn *column;
642
643 DB( g_print("ui_pay_listview_new() \n") );
644
645 store = gtk_list_store_new(
646 NUM_LST_DEFPAY,
647 G_TYPE_BOOLEAN,
648 G_TYPE_POINTER
649 );
650
651 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
652 g_object_unref(store);
653
654 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview), PREFS->grid_lines);
655
656 // column: toggle
657 if( withtoggle == TRUE )
658 {
659 renderer = gtk_cell_renderer_toggle_new ();
660 column = gtk_tree_view_column_new_with_attributes (_("Visible"),
661 renderer, "active", LST_DEFPAY_TOGGLE, NULL);
662 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
663
664 g_signal_connect (G_OBJECT(renderer), "toggled",
665 G_CALLBACK (ui_pay_listview_toggled_cb), store);
666
667 }
668
669 // column: name
670 renderer = gtk_cell_renderer_text_new ();
671 g_object_set(renderer,
672 "ellipsize", PANGO_ELLIPSIZE_END,
673 "ellipsize-set", TRUE,
674 NULL);
675
676 column = gtk_tree_view_column_new();
677 gtk_tree_view_column_set_title(column, _("Name"));
678 gtk_tree_view_column_pack_start(column, renderer, TRUE);
679 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_pay_listview_name_cell_data_function, GINT_TO_POINTER(LST_DEFPAY_DATAS), NULL);
680 gtk_tree_view_column_set_alignment (column, 0.5);
681 gtk_tree_view_column_set_min_width(column, HB_MINWIDTH_LIST);
682 gtk_tree_view_column_set_sort_column_id (column, LST_DEFPAY_SORT_NAME);
683 gtk_tree_view_column_set_resizable(column, TRUE);
684 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
685
686 // column: usage
687 if( withcount == TRUE )
688 {
689 renderer = gtk_cell_renderer_text_new ();
690 g_object_set(renderer, "xalign", 0.5, NULL);
691
692 column = gtk_tree_view_column_new();
693 gtk_tree_view_column_set_title(column, _("Usage"));
694 gtk_tree_view_column_pack_start(column, renderer, TRUE);
695 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_pay_listview_count_cell_data_function, GINT_TO_POINTER(LST_DEFPAY_DATAS), NULL);
696 gtk_tree_view_column_set_alignment (column, 0.5);
697 gtk_tree_view_column_set_sort_column_id (column, LST_DEFPAY_SORT_USED);
698 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
699 }
700
701 // column: category
702 if( withtoggle == FALSE )
703 {
704 renderer = gtk_cell_renderer_text_new ();
705 g_object_set(renderer,
706 "ellipsize", PANGO_ELLIPSIZE_END,
707 "ellipsize-set", TRUE,
708 NULL);
709
710 column = gtk_tree_view_column_new();
711 gtk_tree_view_column_set_title(column, _("Default category"));
712 gtk_tree_view_column_pack_start(column, renderer, TRUE);
713 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_pay_listview_defcat_cell_data_function, GINT_TO_POINTER(LST_DEFPAY_DATAS), NULL);
714 gtk_tree_view_column_set_alignment (column, 0.5);
715 gtk_tree_view_column_set_sort_column_id (column, LST_DEFPAY_SORT_DEFCAT);
716 gtk_tree_view_column_set_resizable(column, TRUE);
717 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
718 }
719
720 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(treeview), ui_pay_listview_search_equal_func, NULL, NULL);
721
722 // treeview attribute
723 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeview), withcount);
724
725 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFPAY_SORT_NAME, ui_pay_listview_compare_func, GINT_TO_POINTER(LST_DEFPAY_SORT_NAME), NULL);
726 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFPAY_SORT_USED, ui_pay_listview_compare_func, GINT_TO_POINTER(LST_DEFPAY_SORT_USED), NULL);
727 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFPAY_SORT_DEFCAT, ui_pay_listview_compare_func, GINT_TO_POINTER(LST_DEFPAY_SORT_DEFCAT), NULL);
728
729 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), LST_DEFPAY_SORT_NAME, GTK_SORT_ASCENDING);
730
731 return treeview;
732 }
733
734
735 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
736
737 static void
738 ui_pay_manage_dialog_delete_unused( GtkWidget *widget, gpointer user_data)
739 {
740 struct ui_pay_manage_dialog_data *data = user_data;
741 gboolean result;
742
743 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(widget), GTK_TYPE_WINDOW)), "inst_data");
744
745 DB( g_print("(ui_pay_manage_dialog) delete unused - data %p\n", data) );
746
747 result = ui_dialog_msg_confirm_alert(
748 GTK_WINDOW(data->window),
749 _("Delete unused payee"),
750 _("Are you sure you want to\npermanently delete unused payee?"),
751 _("_Delete")
752 );
753
754 if( result == GTK_RESPONSE_OK )
755 {
756 GtkTreeModel *model;
757
758 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_pay));
759 gtk_list_store_clear (GTK_LIST_STORE(model));
760
761 payee_delete_unused();
762
763 ui_pay_listview_populate (data->LV_pay);
764 }
765 }
766
767
768 /**
769 * ui_pay_manage_dialog_load_csv:
770 *
771 */
772 static void
773 ui_pay_manage_dialog_load_csv( GtkWidget *widget, gpointer user_data)
774 {
775 struct ui_pay_manage_dialog_data *data = user_data;
776 gchar *filename = NULL;
777 gchar *error;
778
779 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(widget), GTK_TYPE_WINDOW)), "inst_data");
780
781 DB( g_print("(ui_pay_manage_dialog) load csv - data %p\n", data) );
782
783 if( ui_file_chooser_csv(GTK_WINDOW(data->window), GTK_FILE_CHOOSER_ACTION_OPEN, &filename, NULL) == TRUE )
784 {
785 DB( g_print(" + filename is %s\n", filename) );
786
787 if( !payee_load_csv(filename, &error) )
788 {
789 ui_dialog_msg_infoerror(GTK_WINDOW(data->window), GTK_MESSAGE_ERROR,
790 _("File format error"),
791 _("The CSV file must contains the exact numbers of column,\nseparated by a semi-colon, please see the help for more details.")
792 );
793 }
794
795 g_free( filename );
796 ui_pay_listview_populate(data->LV_pay);
797 }
798 }
799
800 /**
801 * ui_pay_manage_dialog_save_csv:
802 *
803 */
804 static void
805 ui_pay_manage_dialog_save_csv( GtkWidget *widget, gpointer user_data)
806 {
807 struct ui_pay_manage_dialog_data *data = user_data;
808 gchar *filename = NULL;
809
810 DB( g_print("(ui_pay_manage_dialog) save csv\n") );
811
812 //data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
813
814 if( ui_file_chooser_csv(GTK_WINDOW(data->window), GTK_FILE_CHOOSER_ACTION_SAVE, &filename, NULL) == TRUE )
815 {
816 DB( g_print(" + filename is %s\n", filename) );
817
818 payee_save_csv(filename);
819 g_free( filename );
820 }
821 }
822
823
824 /**
825 * ui_pay_manage_dialog_add:
826 *
827 */
828 static void
829 ui_pay_manage_dialog_add(GtkWidget *widget, gpointer user_data)
830 {
831 struct ui_pay_manage_dialog_data *data;
832 Payee *item;
833 gchar *name;
834
835 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
836 DB( g_print("(defayee) add (data=%p)\n", data) );
837
838 name = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_name));
839
840 if( payee_append_if_new(name, &item) )
841 {
842 if( item ) {
843 ui_pay_listview_add(GTK_TREE_VIEW(data->LV_pay), item);
844 data->change++;
845 }
846 }
847
848 gtk_entry_set_text(GTK_ENTRY(data->ST_name), "");
849 }
850
851
852 static void ui_pay_manage_dialog_edit_entry_cb(GtkEditable *editable, gpointer user_data)
853 {
854 GtkDialog *window = user_data;
855 const gchar *buffer;
856
857 buffer = gtk_entry_get_text(GTK_ENTRY(editable));
858 gtk_dialog_set_response_sensitive(GTK_DIALOG(window), GTK_RESPONSE_ACCEPT, strlen(buffer) > 0 ? TRUE : FALSE);
859 }
860
861
862 static void ui_pay_manage_dialog_edit(GtkWidget *dowidget, gpointer user_data)
863 {
864 struct ui_pay_manage_dialog_data *data;
865 GtkWidget *dialog, *content_area, *content_grid, *group_grid;
866 GtkWidget *label, *widget;
867 GtkWidget *ST_name, *PO_cat, *NU_mode;
868 gint crow, row;
869 guint32 key;
870
871 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(dowidget, GTK_TYPE_WINDOW)), "inst_data");
872 DB( g_print("(defayee) modify %p\n", data) );
873
874 key = ui_pay_listview_get_selected_key(GTK_TREE_VIEW(data->LV_pay));
875 if( key > 0 )
876 {
877 Payee *item;
878
879 item = da_pay_get( key );
880
881 dialog = gtk_dialog_new_with_buttons (_("Edit..."),
882 GTK_WINDOW (data->window),
883 0,
884 _("_Cancel"),
885 GTK_RESPONSE_REJECT,
886 _("_OK"),
887 GTK_RESPONSE_ACCEPT,
888 NULL);
889
890 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
891
892 content_grid = gtk_grid_new();
893 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
894 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
895 gtk_container_set_border_width (GTK_CONTAINER(content_grid), SPACING_MEDIUM);
896 gtk_box_pack_start (GTK_BOX (content_area), content_grid, TRUE, TRUE, 0);
897
898 crow = 0;
899 // group :: General
900 group_grid = gtk_grid_new ();
901 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
902 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
903 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
904
905 //label = make_label_group(_("General"));
906 //gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
907
908 row = 1;
909 label = make_label_widget(_("_Name:"));
910 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
911 widget = gtk_entry_new();
912 ST_name = widget;
913 gtk_widget_set_hexpand(widget, TRUE);
914 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
915
916 // group :: Default
917 group_grid = gtk_grid_new ();
918 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
919 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
920 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
921
922 label = make_label_group(_("Default"));
923 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 4, 1);
924
925 row = 1;
926 label = make_label_widget(_("_Category:"));
927 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
928 widget = ui_cat_comboboxentry_new(label);
929 PO_cat = widget;
930 gtk_widget_set_hexpand (widget, TRUE);
931 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
932
933 row++;
934 label = make_label_widget(_("Pa_yment:"));
935 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
936 widget = make_paymode(label);
937 NU_mode = widget;
938 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
939
940 //setup
941 gtk_entry_set_text(GTK_ENTRY(ST_name), item->name);
942 gtk_widget_grab_focus (ST_name);
943 gtk_entry_set_activates_default (GTK_ENTRY(ST_name), TRUE);
944
945 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(PO_cat), GLOBALS->h_cat);
946 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(PO_cat), item->kcat);
947
948 gtk_combo_box_set_active(GTK_COMBO_BOX(NU_mode), item->paymode);
949
950 g_signal_connect (G_OBJECT (ST_name), "changed", G_CALLBACK (ui_pay_manage_dialog_edit_entry_cb), dialog);
951
952 gtk_widget_show_all(content_grid);
953
954
955 gtk_dialog_set_default_response(GTK_DIALOG( dialog ), GTK_RESPONSE_ACCEPT);
956
957 //wait for the user
958 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
959
960 if(result == GTK_RESPONSE_ACCEPT)
961 {
962 const gchar *name;
963
964 // 1: manage renaming
965 name = gtk_entry_get_text(GTK_ENTRY(ST_name));
966 // ignore if item is empty
967 if (name && *name)
968 {
969 if( payee_rename(item, name) )
970 {
971 //to redraw the active entry
972 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_pay));
973 data->change++;
974 }
975 else
976 {
977 ui_dialog_msg_infoerror(GTK_WINDOW(dialog), GTK_MESSAGE_ERROR,
978 _("Error"),
979 _("Cannot rename this Payee,\n"
980 "from '%s' to '%s',\n"
981 "this name already exists."),
982 item->name,
983 name
984 );
985
986 }
987 }
988
989 item->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(PO_cat));
990 item->paymode = gtk_combo_box_get_active(GTK_COMBO_BOX(NU_mode));
991
992 }
993
994 // cleanup and destroy
995 gtk_widget_destroy (dialog);
996 }
997
998 }
999
1000
1001 static void ui_pay_manage_dialog_merge_entry_cb(GtkComboBox *widget, gpointer user_data)
1002 {
1003 GtkDialog *window = user_data;
1004 gchar *buffer;
1005
1006 buffer = (gchar *)gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (widget))));
1007 gtk_dialog_set_response_sensitive(GTK_DIALOG(window), GTK_RESPONSE_OK, strlen(buffer) > 0 ? TRUE : FALSE);
1008 }
1009
1010
1011 static void ui_pay_manage_dialog_merge(GtkWidget *widget, gpointer user_data)
1012 {
1013 struct ui_pay_manage_dialog_data *data;
1014 GtkWidget *dialog, *content, *mainvbox;
1015 GtkWidget *getwidget, *togglebutton;
1016 GtkTreeSelection *selection;
1017 GtkTreeModel *model;
1018 GtkTreeIter iter;
1019
1020 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1021 DB( g_print("(defayee) merge %p\n", data) );
1022
1023 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_pay));
1024 //if true there is a selected node
1025 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1026 {
1027 Payee *srcpay;
1028 gchar *title;
1029 gchar *secondtext;
1030
1031 gtk_tree_model_get(model, &iter, LST_DEFPAY_DATAS, &srcpay, -1);
1032
1033 title = g_strdup_printf (
1034 _("Merge payee '%s'"), srcpay->name);
1035
1036 dialog = gtk_message_dialog_new (GTK_WINDOW (data->window),
1037 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1038 GTK_MESSAGE_WARNING,
1039 GTK_BUTTONS_NONE,
1040 title,
1041 NULL
1042 );
1043
1044 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
1045 _("_Cancel"), GTK_RESPONSE_CANCEL,
1046 _("Merge"), GTK_RESPONSE_OK,
1047 NULL);
1048
1049 gtk_dialog_set_default_response(GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
1050
1051 content = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG (dialog));
1052 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
1053 gtk_box_pack_start (GTK_BOX (content), mainvbox, TRUE, TRUE, 0);
1054
1055 secondtext = _("Transactions assigned to this payee,\n"
1056 "will be moved to the payee selected below.");
1057
1058 g_object_set(GTK_MESSAGE_DIALOG (dialog), "secondary-text", secondtext, NULL);
1059 g_free(title);
1060
1061 getwidget = ui_pay_comboboxentry_new(NULL);
1062 gtk_box_pack_start (GTK_BOX (mainvbox), getwidget, FALSE, FALSE, 0);
1063
1064 secondtext = g_strdup_printf (
1065 _("_Delete the payee '%s'"), srcpay->name);
1066 togglebutton = gtk_check_button_new_with_mnemonic(secondtext);
1067 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(togglebutton), TRUE);
1068 g_free(secondtext);
1069 gtk_box_pack_start (GTK_BOX (mainvbox), togglebutton, FALSE, FALSE, 0);
1070
1071 //setup
1072 //gtk_combo_box_set_active(GTK_COMBO_BOX(getwidget), oldpos);
1073 g_signal_connect (G_OBJECT (getwidget), "changed", G_CALLBACK (ui_pay_manage_dialog_merge_entry_cb), dialog);
1074 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_OK, FALSE);
1075
1076 ui_pay_comboboxentry_populate_except(GTK_COMBO_BOX(getwidget), GLOBALS->h_pay, srcpay->key);
1077 gtk_widget_grab_focus (getwidget);
1078
1079 gtk_widget_show_all(mainvbox);
1080
1081 //wait for the user
1082 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
1083
1084 if(result == GTK_RESPONSE_OK)
1085 {
1086 GtkTreeModel *model;
1087 Payee *payee;
1088 guint dstpaykey;
1089
1090 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_pay));
1091 gtk_list_store_clear (GTK_LIST_STORE(model));
1092
1093 dstpaykey = ui_pay_comboboxentry_get_key_add_new(GTK_COMBO_BOX(getwidget));
1094
1095 payee_move(srcpay->key, dstpaykey);
1096
1097
1098 // add the new payee to listview
1099 payee = da_pay_get(dstpaykey);
1100 if(payee)
1101 ui_pay_listview_add(GTK_TREE_VIEW(data->LV_pay), payee);
1102
1103 // delete the old payee
1104 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(togglebutton)) )
1105 {
1106 DB( g_print(" -> delete %d '%s'\n", srcpay->key, srcpay->name ) );
1107
1108 da_pay_remove(srcpay->key);
1109 ui_pay_listview_remove_selected(GTK_TREE_VIEW(data->LV_pay));
1110 }
1111
1112
1113 data->change++;
1114
1115 ui_pay_listview_populate(data->LV_pay);
1116 }
1117
1118 // cleanup and destroy
1119 gtk_widget_destroy (dialog);
1120 }
1121
1122 }
1123
1124
1125 /*
1126 ** delete the selected payee to our treeview and temp GList
1127 */
1128 static void ui_pay_manage_dialog_delete(GtkWidget *widget, gpointer user_data)
1129 {
1130 struct ui_pay_manage_dialog_data *data;
1131 Payee *item;
1132 guint32 key;
1133 gint result;
1134
1135
1136 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1137 DB( g_print("(ui_pay_manage_dialog) delete (data=%p)\n", data) );
1138
1139 key = ui_pay_listview_get_selected_key(GTK_TREE_VIEW(data->LV_pay));
1140 if( key > 0 )
1141 {
1142 gchar *title;
1143 gchar *secondtext = NULL;
1144
1145 item = da_pay_get(key);
1146
1147 title = g_strdup_printf (
1148 _("Are you sure you want to permanently delete '%s'?"), item->name);
1149
1150 if( item->usage_count > 0 )
1151 {
1152 secondtext = _("This payee is used.\n"
1153 "Any transaction using that payee will be set to (no payee)");
1154 }
1155
1156 result = ui_dialog_msg_confirm_alert(
1157 GTK_WINDOW(data->window),
1158 title,
1159 secondtext,
1160 _("_Delete")
1161 );
1162
1163 g_free(title);
1164
1165 if( result == GTK_RESPONSE_OK )
1166 {
1167 payee_move(key, 0);
1168 ui_pay_listview_remove_selected(GTK_TREE_VIEW(data->LV_pay));
1169 da_pay_remove(key);
1170 data->change++;
1171 }
1172
1173 }
1174 }
1175
1176
1177 static void ui_pay_manage_dialog_update(GtkWidget *treeview, gpointer user_data)
1178 {
1179 struct ui_pay_manage_dialog_data *data;
1180 gboolean sensitive;
1181 guint32 key;
1182
1183 DB( g_print("\n(ui_pay_manage_dialog) cursor changed\n") );
1184
1185 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(treeview), GTK_TYPE_WINDOW)), "inst_data");
1186
1187 key = ui_pay_listview_get_selected_key(GTK_TREE_VIEW(data->LV_pay));
1188
1189 sensitive = (key > 0) ? TRUE : FALSE;
1190 gtk_widget_set_sensitive(data->BT_edit, sensitive);
1191 gtk_widget_set_sensitive(data->BT_merge, sensitive);
1192 gtk_widget_set_sensitive(data->BT_delete, sensitive);
1193
1194 }
1195
1196
1197 /*
1198 **
1199 */
1200 static void ui_pay_manage_dialog_selection(GtkTreeSelection *treeselection, gpointer user_data)
1201 {
1202 ui_pay_manage_dialog_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), NULL);
1203 }
1204
1205 static void ui_pay_manage_dialog_onRowActivated (GtkTreeView *treeview,
1206 GtkTreePath *path,
1207 GtkTreeViewColumn *col,
1208 gpointer user_data)
1209 {
1210 GtkTreeModel *model;
1211 GtkTreeIter iter;
1212
1213 DB( g_print("ui_pay_manage_dialog_onRowActivated()\n") );
1214
1215
1216 model = gtk_tree_view_get_model(treeview);
1217 gtk_tree_model_get_iter_first(model, &iter);
1218 if(gtk_tree_selection_iter_is_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), &iter) == FALSE)
1219 {
1220 ui_pay_manage_dialog_edit(GTK_WIDGET(treeview), NULL);
1221 }
1222 }
1223
1224
1225 GtkWidget *ui_pay_manage_dialog (void)
1226 {
1227 struct ui_pay_manage_dialog_data data;
1228 GtkWidget *window, *content, *mainvbox, *bbox, *treeview, *scrollwin, *table;
1229 GtkWidget *menu, *menuitem, *widget, *image;
1230 gint w, h, row;
1231
1232 window = gtk_dialog_new_with_buttons (_("Manage Payees"),
1233 GTK_WINDOW(GLOBALS->mainwindow),
1234 0,
1235 _("_Close"),
1236 GTK_RESPONSE_ACCEPT,
1237 NULL);
1238
1239 data.window = window;
1240 data.change = 0;
1241
1242 gtk_window_set_icon_name(GTK_WINDOW (window), ICONNAME_HB_PAYEE);
1243
1244 //set a nice dialog size
1245 gtk_window_get_size(GTK_WINDOW(GLOBALS->mainwindow), &w, &h);
1246 gtk_window_set_default_size (GTK_WINDOW(window), -1, h/PHI);
1247
1248
1249 //store our window private data
1250 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)&data);
1251 DB( g_print("(ui_pay_manage_dialog) window=%p, inst_data=%p\n", window, &data) );
1252
1253 g_signal_connect (window, "destroy",
1254 G_CALLBACK (gtk_widget_destroyed), &window);
1255
1256 //window contents
1257 content = gtk_dialog_get_content_area(GTK_DIALOG (window));
1258 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
1259 gtk_box_pack_start (GTK_BOX (content), mainvbox, TRUE, TRUE, 0);
1260 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), SPACING_MEDIUM);
1261
1262 //our table
1263 table = gtk_grid_new ();
1264 gtk_grid_set_row_spacing (GTK_GRID (table), SPACING_SMALL);
1265 gtk_grid_set_column_spacing (GTK_GRID (table), SPACING_MEDIUM);
1266 gtk_box_pack_start (GTK_BOX (mainvbox), table, TRUE, TRUE, 0);
1267
1268 row = 0;
1269 menu = gtk_menu_new ();
1270 gtk_widget_set_halign (menu, GTK_ALIGN_END);
1271
1272 menuitem = gtk_menu_item_new_with_mnemonic (_("_Import CSV"));
1273 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
1274 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (ui_pay_manage_dialog_load_csv), &data);
1275
1276 menuitem = gtk_menu_item_new_with_mnemonic (_("E_xport CSV"));
1277 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
1278 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (ui_pay_manage_dialog_save_csv), &data);
1279
1280 menuitem = gtk_separator_menu_item_new();
1281 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
1282
1283 menuitem = gtk_menu_item_new_with_mnemonic (_("_Delete unused"));
1284 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
1285 g_signal_connect (G_OBJECT (menuitem), "activate", G_CALLBACK (ui_pay_manage_dialog_delete_unused), &data);
1286
1287 gtk_widget_show_all (menu);
1288
1289 widget = gtk_menu_button_new();
1290 image = gtk_image_new_from_icon_name (ICONNAME_HB_BUTTON_MENU, GTK_ICON_SIZE_MENU);
1291
1292 //gchar *thename;
1293 //gtk_image_get_icon_name(image, &thename, NULL);
1294 //g_print("the name is %s\n", thename);
1295
1296 g_object_set (widget, "image", image, "popup", GTK_MENU(menu), NULL);
1297 gtk_widget_set_halign (widget, GTK_ALIGN_END);
1298 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
1299
1300 row++;
1301 data.ST_name = gtk_entry_new ();
1302 gtk_entry_set_placeholder_text(GTK_ENTRY(data.ST_name), _("new payee") );
1303 gtk_widget_set_hexpand (data.ST_name, TRUE);
1304 gtk_grid_attach (GTK_GRID (table), data.ST_name, 0, row, 2, 1);
1305
1306
1307 //list
1308 row++;
1309 scrollwin = gtk_scrolled_window_new(NULL,NULL);
1310 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
1311 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1312 gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scrollwin), HB_MINHEIGHT_LIST);
1313 treeview = ui_pay_listview_new(FALSE, TRUE);
1314 data.LV_pay = treeview;
1315 gtk_container_add(GTK_CONTAINER(scrollwin), treeview);
1316 gtk_widget_set_hexpand (scrollwin, TRUE);
1317 gtk_widget_set_vexpand (scrollwin, TRUE);
1318 gtk_grid_attach (GTK_GRID (table), scrollwin, 0, row, 2, 1);
1319
1320 row++;
1321 bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
1322 gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
1323 gtk_box_set_spacing (GTK_BOX (bbox), SPACING_SMALL);
1324 gtk_grid_attach (GTK_GRID (table), bbox, 0, row, 2, 1);
1325
1326 data.BT_edit = gtk_button_new_with_mnemonic(_("_Edit"));
1327 gtk_container_add (GTK_CONTAINER (bbox), data.BT_edit);
1328
1329 data.BT_merge = gtk_button_new_with_mnemonic(_("_Merge"));
1330 gtk_container_add (GTK_CONTAINER (bbox), data.BT_merge);
1331
1332 data.BT_delete = gtk_button_new_with_mnemonic(_("_Delete"));
1333 gtk_container_add (GTK_CONTAINER (bbox), data.BT_delete);
1334
1335
1336 //connect all our signals
1337 g_signal_connect (G_OBJECT (data.ST_name), "activate", G_CALLBACK (ui_pay_manage_dialog_add), NULL);
1338
1339 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data.LV_pay)), "changed", G_CALLBACK (ui_pay_manage_dialog_selection), NULL);
1340 g_signal_connect (GTK_TREE_VIEW(data.LV_pay), "row-activated", G_CALLBACK (ui_pay_manage_dialog_onRowActivated), NULL);
1341
1342 g_signal_connect (G_OBJECT (data.BT_edit), "clicked", G_CALLBACK (ui_pay_manage_dialog_edit), NULL);
1343 g_signal_connect (G_OBJECT (data.BT_merge), "clicked", G_CALLBACK (ui_pay_manage_dialog_merge), NULL);
1344 g_signal_connect (G_OBJECT (data.BT_delete), "clicked", G_CALLBACK (ui_pay_manage_dialog_delete), NULL);
1345
1346 //setup, init and show window
1347 payee_fill_usage();
1348 ui_pay_listview_populate(data.LV_pay);
1349 ui_pay_manage_dialog_update(data.LV_pay, NULL);
1350
1351 gtk_widget_show_all (window);
1352
1353 //wait for the user
1354 gint result = gtk_dialog_run (GTK_DIALOG (window));
1355
1356 switch (result)
1357 {
1358 case GTK_RESPONSE_ACCEPT:
1359 //do_application_specific_something ();
1360 break;
1361 default:
1362 //do_nothing_since_dialog_was_cancelled ();
1363 break;
1364 }
1365
1366 // cleanup and destroy
1367
1368 gtk_widget_destroy (window);
1369
1370 GLOBALS->changes_count += data.change;
1371
1372 return NULL;
1373 }
1374
1375
1376
This page took 0.096018 seconds and 4 git commands to generate.