add gitignore
[chaz/homebank] / src / ui-assign.c
1 /* HomeBank -- Free, easy, personal ruleing for everyone.
2 * Copyright (C) 1995-2014 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "homebank.h"
21
22 #include "ui-assign.h"
23
24 #include "ui-category.h"
25 #include "ui-payee.h"
26
27 #define MYDEBUG 0
28
29 #if MYDEBUG
30 #define DB(x) (x);
31 #else
32 #define DB(x);
33 #endif
34
35 /* our global datas */
36 extern struct HomeBank *GLOBALS;
37
38 gchar *CYA_ASG_FIELD[] = {
39 N_("Memo"),
40 N_("Payee"),
41 NULL
42 };
43
44 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
45
46
47 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
48
49
50 static void
51 ui_asg_listview_toggled_cb (GtkCellRendererToggle *cell,
52 gchar *path_str,
53 gpointer data)
54 {
55 GtkTreeModel *model = (GtkTreeModel *)data;
56 GtkTreeIter iter;
57 GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
58 gboolean fixed;
59
60 /* get toggled iter */
61 gtk_tree_model_get_iter (model, &iter, path);
62 gtk_tree_model_get (model, &iter, LST_DEFASG_TOGGLE, &fixed, -1);
63
64 /* do something with the value */
65 fixed ^= 1;
66
67 /* set new value */
68 gtk_list_store_set (GTK_LIST_STORE (model), &iter, LST_DEFASG_TOGGLE, fixed, -1);
69
70 /* clean up */
71 gtk_tree_path_free (path);
72 }
73
74 static gint
75 ui_asg_listview_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
76 {
77 Assign *entry1, *entry2;
78
79 gtk_tree_model_get(model, a, LST_DEFASG_DATAS, &entry1, -1);
80 gtk_tree_model_get(model, b, LST_DEFASG_DATAS, &entry2, -1);
81
82 return hb_string_utf8_compare(entry1->name, entry2->name);
83 }
84
85 static void
86 ui_asg_listview_name_cell_data_function (GtkTreeViewColumn *col,
87 GtkCellRenderer *renderer,
88 GtkTreeModel *model,
89 GtkTreeIter *iter,
90 gpointer user_data)
91 {
92 Assign *entry;
93 gchar *name;
94 #if MYDEBUG
95 gchar *string;
96 #endif
97
98 gtk_tree_model_get(model, iter, LST_DEFASG_DATAS, &entry, -1);
99 if(entry->name == NULL)
100 name = _("(none)"); // can never occurs also
101 else
102 name = entry->name;
103
104 #if MYDEBUG
105 string = g_strdup_printf ("[%d] %s", entry->key, name );
106 g_object_set(renderer, "text", string, NULL);
107 g_free(string);
108 #else
109 g_object_set(renderer, "text", name, NULL);
110 #endif
111
112 }
113
114
115
116 /* = = = = = = = = = = = = = = = = */
117
118 /**
119 * rul_list_add:
120 *
121 * Add a single element (useful for dynamics add)
122 *
123 * Return value: --
124 *
125 */
126 void
127 ui_asg_listview_add(GtkTreeView *treeview, Assign *item)
128 {
129 if( item->name != NULL )
130 {
131 GtkTreeModel *model;
132 GtkTreeIter iter;
133
134 model = gtk_tree_view_get_model(treeview);
135
136 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
137 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
138 LST_DEFASG_TOGGLE, FALSE,
139 LST_DEFASG_DATAS, item,
140 -1);
141
142 gtk_tree_selection_select_iter (gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), &iter);
143
144 }
145 }
146
147 guint32
148 ui_asg_listview_get_selected_key(GtkTreeView *treeview)
149 {
150 GtkTreeSelection *selection;
151 GtkTreeModel *model;
152 GtkTreeIter iter;
153
154 selection = gtk_tree_view_get_selection(treeview);
155 if (gtk_tree_selection_get_selected(selection, &model, &iter))
156 {
157 Assign *item;
158
159 gtk_tree_model_get(model, &iter, LST_DEFASG_DATAS, &item, -1);
160
161 if( item!= NULL )
162 return item->key;
163 }
164 return 0;
165 }
166
167 void
168 ui_asg_listview_remove_selected(GtkTreeView *treeview)
169 {
170 GtkTreeSelection *selection;
171 GtkTreeModel *model;
172 GtkTreeIter iter;
173
174 selection = gtk_tree_view_get_selection(treeview);
175 if (gtk_tree_selection_get_selected(selection, &model, &iter))
176 {
177 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
178 }
179 }
180
181 /*
182 static gint ui_asg_glist_compare_func(Assign *a, Assign *b)
183 {
184 return 0; //((gint)a->pos - b->pos);
185 }
186 */
187
188 void ui_asg_listview_populate(GtkWidget *view)
189 {
190 GtkTreeModel *model;
191 GtkTreeIter iter;
192 GList *lrul, *list;
193
194 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
195
196 gtk_list_store_clear (GTK_LIST_STORE(model));
197
198 g_object_ref(model); /* Make sure the model stays with us after the tree view unrefs it */
199 gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL); /* Detach model from view */
200
201 /* populate */
202 //g_hash_table_foreach(GLOBALS->h_rul, (GHFunc)ui_asg_listview_populate_ghfunc, model);
203 lrul = list = g_hash_table_get_values(GLOBALS->h_rul);
204
205 //list = g_list_sort(list, (GCompareFunc)ui_asg_glist_compare_func);
206 while (list != NULL)
207 {
208 Assign *item = list->data;
209
210 DB( g_print(" populate: %d\n", item->key) );
211
212 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
213 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
214 LST_DEFASG_TOGGLE , FALSE,
215 LST_DEFASG_DATAS, item,
216 -1);
217
218 list = g_list_next(list);
219 }
220 g_list_free(lrul);
221
222 gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); /* Re-attach model to view */
223 g_object_unref(model);
224 }
225
226
227 GtkWidget *
228 ui_asg_listview_new(gboolean withtoggle)
229 {
230 GtkListStore *store;
231 GtkWidget *treeview;
232 GtkCellRenderer *renderer;
233 GtkTreeViewColumn *column;
234
235 // create list store
236 store = gtk_list_store_new(NUM_LST_DEFASG,
237 G_TYPE_BOOLEAN,
238 G_TYPE_POINTER
239 );
240
241 // treeview
242 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
243 g_object_unref(store);
244
245 //gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
246
247 // column 1: toggle
248 if( withtoggle == TRUE )
249 {
250 renderer = gtk_cell_renderer_toggle_new ();
251 column = gtk_tree_view_column_new_with_attributes (_("Visible"),
252 renderer,
253 "active", LST_DEFASG_TOGGLE,
254 NULL);
255 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
256
257 g_signal_connect (renderer, "toggled",
258 G_CALLBACK (ui_asg_listview_toggled_cb), store);
259
260 }
261
262 // column 2: name
263 renderer = gtk_cell_renderer_text_new ();
264 column = gtk_tree_view_column_new();
265 gtk_tree_view_column_pack_start(column, renderer, TRUE);
266 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_asg_listview_name_cell_data_function, GINT_TO_POINTER(LST_DEFASG_DATAS), NULL);
267 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
268
269 // treeviewattribute
270 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeview), FALSE);
271 gtk_tree_view_set_reorderable (GTK_TREE_VIEW(treeview), TRUE);
272
273 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), ui_asg_listview_compare_func, NULL, NULL);
274 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
275
276 return treeview;
277 }
278
279 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
280 //todo move this
281 static gboolean
282 assign_rename(Assign *item, gchar *newname)
283 {
284 Account *existitem;
285
286 existitem = da_acc_get_by_name(newname);
287 if( existitem == NULL )
288 {
289 g_free(item->name);
290 item->name = g_strdup(newname);
291 return TRUE;
292 }
293
294 return FALSE;
295 }
296
297
298
299 static void ui_asg_manage_getlast(struct ui_asg_manage_data *data)
300 {
301 gchar *txt;
302 gboolean bool;
303 Assign *item;
304 gint active;
305
306 DB( g_print("\n(ui_asg_manage_getlast)\n") );
307
308 DB( g_print(" -> for assign id=%d\n", data->lastkey) );
309
310 item = da_asg_get(data->lastkey);
311 if(item != NULL)
312 {
313 data->change++;
314
315 item->field = radio_get_active(GTK_CONTAINER(data->CY_field));
316
317 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_text));
318 if (txt && *txt)
319 {
320 bool = assign_rename(item, txt);
321 if(bool)
322 {
323 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_rul));
324 }
325 else
326 {
327 gtk_entry_set_text(GTK_ENTRY(data->ST_text), item->name);
328 }
329 }
330
331 item->flags = 0;
332
333 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_exact));
334 if(active == 1) item->flags |= ASGF_EXACT;
335
336 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_pay));
337 if(active == 1) item->flags |= ASGF_DOPAY;
338
339 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cat));
340 if(active == 1) item->flags |= ASGF_DOCAT;
341
342 item->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_cat));
343 item->kpay = ui_pay_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_pay));
344
345 }
346
347 }
348
349
350
351 /*
352 ** set widgets contents from the selected assign
353 */
354 static void ui_asg_manage_set(GtkWidget *widget, gpointer user_data)
355 {
356 struct ui_asg_manage_data *data;
357 GtkTreeSelection *selection;
358 GtkTreeModel *model;
359 GtkTreeIter iter;
360 Assign *item;
361
362 DB( g_print("\n(ui_asg_manage_set)\n") );
363
364 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
365
366 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_rul));
367 //if true there is a selected node
368 if (gtk_tree_selection_get_selected(selection, &model, &iter))
369 {
370 gtk_tree_model_get(model, &iter, LST_DEFASG_DATAS, &item, -1);
371
372 DB( g_print(" -> set rul id=%d\n", item->key) );
373
374 radio_set_active(GTK_CONTAINER(data->CY_field), item->field);
375
376 gtk_entry_set_text(GTK_ENTRY(data->ST_text), item->name);
377
378 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_exact), (item->flags & ASGF_EXACT) ? 1 : 0);
379
380 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_cat), (item->flags & ASGF_DOCAT) ? 1 : 0);
381 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_cat), item->kcat);
382
383 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_pay), (item->flags & ASGF_DOPAY) ? 1 : 0);
384 ui_pay_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_pay), item->kpay);
385
386
387 }
388
389 }
390
391 /*
392 static gboolean ui_asg_manage_focus_out(GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
393 {
394 ui_asg_manage_get(widget, user_data);
395 return FALSE;
396 }
397 */
398
399 static void ui_asg_manage_update_assignments(GtkWidget *widget, gpointer user_data)
400 {
401 struct ui_asg_manage_data *data;
402 gboolean active;
403
404 DB( g_print("\n(ui_asg_manage_update_assignments)\n") );
405
406 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
407
408 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_pay));
409 gtk_widget_set_sensitive(data->PO_pay, active);
410
411 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cat));
412 gtk_widget_set_sensitive(data->PO_cat, active);
413
414 //active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_mod));
415 //gtk_widget_set_sensitive(data->NU_mod, active);
416
417 }
418
419 /*
420 ** update the widgets status and contents from action/selection value
421 */
422 static void ui_asg_manage_update(GtkWidget *widget, gpointer user_data)
423 {
424 struct ui_asg_manage_data *data;
425 GtkTreeModel *model;
426 GtkTreeIter iter;
427 gboolean selected, sensitive;
428 guint32 key;
429 //todo: for stock assign
430 //gboolean is_new;
431
432 DB( g_print("\n(ui_asg_manage_update)\n") );
433
434 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
435 //window = gtk_widget_get_ancestor(GTK_WIDGET(treeview), GTK_TYPE_WINDOW);
436 //DB( g_print("(defpayee) widget=%08lx, window=%08lx, inst_data=%08lx\n", treeview, window, data) );
437
438 //if true there is a selected node
439 selected = gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_rul)), &model, &iter);
440 key = ui_asg_listview_get_selected_key(GTK_TREE_VIEW(data->LV_rul));
441
442 DB( g_print(" -> selected = %d action = %d key = %d\n", selected, data->action, key) );
443
444
445 sensitive = (selected == TRUE) ? TRUE : FALSE;
446 gtk_widget_set_sensitive(data->CY_field, sensitive);
447 gtk_widget_set_sensitive(data->ST_text, sensitive);
448 gtk_widget_set_sensitive(data->CM_exact, sensitive);
449
450 gtk_widget_set_sensitive(data->CM_pay, sensitive);
451 gtk_widget_set_sensitive(data->CM_cat, sensitive);
452
453 gtk_widget_set_sensitive(data->PO_pay, sensitive);
454 gtk_widget_set_sensitive(data->PO_cat, sensitive);
455
456
457 //sensitive = (data->action == 0) ? TRUE : FALSE;
458 //gtk_widget_set_sensitive(data->LV_rul, sensitive);
459 //gtk_widget_set_sensitive(data->BT_add, sensitive);
460
461 sensitive = (selected == TRUE && data->action == 0) ? TRUE : FALSE;
462 //gtk_widget_set_sensitive(data->BT_mod, sensitive);
463 gtk_widget_set_sensitive(data->BT_rem, sensitive);
464
465 if(selected)
466 {
467 if(key != data->lastkey)
468 {
469 DB( g_print(" -> should first do a get for assign %d\n", data->lastkey) );
470 ui_asg_manage_getlast(data);
471 }
472
473 ui_asg_manage_set(widget, NULL);
474 ui_asg_manage_update_assignments(widget, NULL);
475 }
476
477 data->lastkey = key;
478
479 }
480
481
482 /*
483 ** add an empty new assign to our temp GList and treeview
484 */
485 static void ui_asg_manage_add(GtkWidget *widget, gpointer user_data)
486 {
487 struct ui_asg_manage_data *data;
488 Assign *item;
489
490 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
491 DB( g_print("\n(ui_asg_manage_add) (data=%x)\n", (guint)data) );
492
493 item = da_asg_malloc();
494 item->name = g_strdup_printf( _("(assignment %d)"), da_asg_length()+1);
495
496 da_asg_append(item);
497 ui_asg_listview_add(GTK_TREE_VIEW(data->LV_rul), item);
498
499 data->change++;
500 }
501
502 /*
503 ** remove the selected assign to our treeview and temp GList
504 */
505 static void ui_asg_manage_remove(GtkWidget *widget, gpointer user_data)
506 {
507 struct ui_asg_manage_data *data;
508 guint32 key;
509 gboolean do_remove;
510
511 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
512 DB( g_print("\n(ui_asg_manage_remove) (data=%x)\n", (guint)data) );
513
514 do_remove = TRUE;
515 key = ui_asg_listview_get_selected_key(GTK_TREE_VIEW(data->LV_rul));
516 if( key > 0 )
517 {
518 if( do_remove )
519 {
520 da_asg_remove(key);
521 ui_asg_listview_remove_selected(GTK_TREE_VIEW(data->LV_rul));
522 data->change++;
523 }
524 }
525 }
526
527 /*
528 ** rename the selected assign to our treeview and temp GList
529 */
530 static void ui_asg_manage_rename(GtkWidget *widget, gpointer user_data)
531 {
532 struct ui_asg_manage_data *data;
533 guint32 key;
534 gboolean ok;
535 gchar *txt;
536
537 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
538 DB( g_print("\n(ui_asg_manage_rename) (data=%x)\n", (guint)data) );
539
540 key = ui_asg_listview_get_selected_key(GTK_TREE_VIEW(data->LV_rul));
541 if( key > 0 )
542 {
543 Assign *item = da_asg_get(key);
544 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_text));
545 if (txt && *txt)
546 {
547 ok = assign_rename(item, txt);
548 if(ok)
549 {
550 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_rul));
551 }
552
553 }
554
555 data->change++;
556 }
557 }
558
559
560
561
562
563 /*
564 **
565 */
566 static void ui_asg_manage_selection(GtkTreeSelection *treeselection, gpointer user_data)
567 {
568 ui_asg_manage_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), NULL);
569 }
570
571 //gint ui_asg_manage_list_sort(struct _Assign *a, struct _Assign *b) { return( a->rul_Id - b->rul_Id); }
572
573 /*
574 **
575 */
576 static gboolean ui_asg_manage_cleanup(struct ui_asg_manage_data *data, gint result)
577 {
578 guint32 key;
579 gboolean doupdate = FALSE;
580
581 DB( g_print("\n(ui_asg_manage_cleanup) %x\n", (guint)data) );
582
583 key = ui_asg_listview_get_selected_key(GTK_TREE_VIEW(data->LV_rul));
584 if(key > 0)
585 {
586 data->lastkey = key;
587 DB( g_print(" -> should first do a get for assign %d\n", data->lastkey) );
588 ui_asg_manage_getlast(data);
589 }
590
591 // test for change & store new position
592 /*
593 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_rul));
594 i=1; valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
595 while (valid)
596 {
597 Assign *item;
598
599 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
600 LST_DEFASG_DATAS, &item,
601 -1);
602
603 DB( g_print(" -> check rul %d, pos is %d, %s\n", i, item->pos, item->name) );
604
605 if(item->pos != i)
606 data->change++;
607
608 item->pos = i;
609
610 // Make iter point to the next row in the list store
611 i++; valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
612 }
613 */
614
615 GLOBALS->changes_count += data->change;
616
617 return doupdate;
618 }
619
620 /*
621 **
622 */
623 static void ui_asg_manage_setup(struct ui_asg_manage_data *data)
624 {
625
626 DB( g_print("\n(ui_asg_manage_setup)\n") );
627
628 //init GList
629 data->tmp_list = NULL; //hb-glist_clone_list(GLOBALS->rul_list, sizeof(struct _Assign));
630 data->action = 0;
631 data->change = 0;
632 data->lastkey = 0;
633
634 ui_asg_listview_populate(data->LV_rul);
635
636 ui_pay_comboboxentry_populate(GTK_COMBO_BOX(data->PO_pay), GLOBALS->h_pay);
637 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_cat), GLOBALS->h_cat);
638 }
639
640 /*
641 **
642 */
643 GtkWidget *ui_asg_manage_dialog (void)
644 {
645 struct ui_asg_manage_data data;
646 GtkWidget *window, *content, *mainbox;
647 GtkWidget *table, *label, *entry1;
648 GtkWidget *scrollwin;
649 GtkWidget *hpaned;
650 GtkWidget *alignment, *widget;
651 gint row;
652
653 window = gtk_dialog_new_with_buttons (_("Manage Assignments"),
654 GTK_WINDOW(GLOBALS->mainwindow),
655 0,
656 GTK_STOCK_CLOSE,
657 GTK_RESPONSE_ACCEPT,
658 NULL);
659
660 data.window = window;
661
662 //set the window icon
663 //homebank_window_set_icon_from_file(GTK_WINDOW (window), "assign.svg");
664 gtk_window_set_icon_name(GTK_WINDOW (window), HB_STOCK_ASSIGN);
665
666 //set a nice dialog size
667 //gint w, h;
668 //gtk_window_get_size(GTK_WINDOW(GLOBALS->mainwindow), &w, &h);
669 //gtk_window_set_default_size (GTK_WINDOW(window), w/PHI, h/PHI);
670
671 //store our window private data
672 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)&data);
673 DB( g_print("(ui_asg_manage_) window=%x, inst_data=%x\n", (guint)window, (guint)&data) );
674
675 //window contents
676 content = gtk_dialog_get_content_area(GTK_DIALOG (window));
677 mainbox = gtk_hbox_new (FALSE, HB_BOX_SPACING);
678 gtk_box_pack_start (GTK_BOX (content), mainbox, TRUE, TRUE, 0);
679 gtk_container_set_border_width (GTK_CONTAINER(mainbox), HB_MAINBOX_SPACING);
680
681 hpaned = gtk_hpaned_new();
682 gtk_box_pack_start (GTK_BOX (mainbox), hpaned, TRUE, TRUE, 0);
683
684 /* left area */
685 table = gtk_table_new (2, 2, FALSE);
686 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
687 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
688 gtk_paned_pack1 (GTK_PANED(hpaned), table, FALSE, FALSE);
689
690 row = 0;
691 scrollwin = gtk_scrolled_window_new(NULL,NULL);
692 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
693 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
694 data.LV_rul = ui_asg_listview_new(FALSE);
695 gtk_widget_set_size_request(data.LV_rul, HB_MINWIDTH_LIST, -1);
696 gtk_container_add(GTK_CONTAINER(scrollwin), data.LV_rul);
697 gtk_table_attach_defaults (GTK_TABLE (table), scrollwin, 0, 2, row, row+1);
698
699 // tools buttons
700 row++;
701 widget = gtk_button_new_from_stock(GTK_STOCK_ADD);
702 data.BT_add = widget;
703 gtk_table_attach (GTK_TABLE (table), widget, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (0), 0, 0);
704 widget = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
705 data.BT_rem = widget;
706 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (0), 0, 0);
707
708
709 /* right area */
710 table = gtk_table_new (12, 4, FALSE);
711 //gtk_container_set_border_width (GTK_CONTAINER (table), SP_BORDER);
712 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
713 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
714
715 // gtk_alignment_new(xalign, yalign, xscale, yscale)
716 alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
717 gtk_container_add(GTK_CONTAINER(alignment), table);
718 //gtk_box_pack_start (GTK_BOX (mainbox), alignment, TRUE, TRUE, 0);
719 gtk_paned_pack2 (GTK_PANED(hpaned), alignment, FALSE, FALSE);
720
721 row = 0;
722 label = make_label(_("Condition"), 0.0, 0.5);
723 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
724 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 4, row, row+1);
725
726 row++;
727 label = make_label(_("_Field:"), 0.0, 0.5);
728 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
729 widget = make_radio(label, CYA_ASG_FIELD, GTK_ORIENTATION_VERTICAL);
730 data.CY_field = widget;
731 gtk_table_attach (GTK_TABLE (table), widget, 2, 4, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
732
733 row++;
734 label = make_label(_("Con_tains:"), 0.0, 0.5);
735 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
736 entry1 = make_string(label);
737 data.ST_text = entry1;
738 gtk_table_attach (GTK_TABLE (table), entry1, 2, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
739
740 row++;
741 widget = gtk_check_button_new_with_mnemonic (_("Case _sensitive"));
742 data.CM_exact = widget;
743 gtk_table_attach (GTK_TABLE (table), widget, 1, 4, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
744
745
746 //other
747 row++;
748 label = make_label(NULL, 0.0, 0.5);
749 gtk_label_set_markup (GTK_LABEL(label), _("Assignments"));
750 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
751 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 4, row, row+1);
752
753 row++;
754 label = gtk_label_new_with_mnemonic (_("_Category:"));
755 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
756 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
757 widget = gtk_check_button_new();
758 data.CM_cat = widget;
759 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
760 widget = ui_cat_comboboxentry_new(label);
761 data.PO_cat = widget;
762 gtk_table_attach (GTK_TABLE (table), widget, 3, 4, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
763
764 gtk_widget_set_tooltip_text(widget, _("Autocompletion and direct seizure\nis available for Category"));
765
766
767 row++;
768 label = gtk_label_new_with_mnemonic (_("_Payee:"));
769 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
770 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
771 widget = gtk_check_button_new();
772 data.CM_pay = widget;
773 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
774 widget = ui_pay_comboboxentry_new(label);
775 data.PO_pay = widget;
776 gtk_table_attach_defaults (GTK_TABLE (table), widget, 3, 4, row, row+1);
777
778 gtk_widget_set_tooltip_text(widget, _("Autocompletion and direct seizure\nis available for Payee"));
779
780
781
782 //connect all our signals
783 g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
784
785 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data.LV_rul)), "changed", G_CALLBACK (ui_asg_manage_selection), NULL);
786
787 g_signal_connect (G_OBJECT (data.ST_text), "changed", G_CALLBACK (ui_asg_manage_rename), NULL);
788
789 g_signal_connect (G_OBJECT (data.CM_cat), "toggled", G_CALLBACK (ui_asg_manage_update_assignments), NULL);
790 g_signal_connect (G_OBJECT (data.CM_pay), "toggled", G_CALLBACK (ui_asg_manage_update_assignments), NULL);
791
792 g_signal_connect (G_OBJECT (data.BT_add), "clicked", G_CALLBACK (ui_asg_manage_add), NULL);
793 g_signal_connect (G_OBJECT (data.BT_rem), "clicked", G_CALLBACK (ui_asg_manage_remove), NULL);
794
795 //setup, init and show window
796 ui_asg_manage_setup(&data);
797 ui_asg_manage_update(data.LV_rul, NULL);
798
799 // gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
800
801 gtk_widget_show_all (window);
802
803 //wait for the user
804 gint result = gtk_dialog_run (GTK_DIALOG (window));
805
806 // cleanup and destroy
807 ui_asg_manage_cleanup(&data, result);
808 gtk_widget_destroy (window);
809
810 return NULL;
811 }
812
813
This page took 0.086552 seconds and 4 git commands to generate.