]> Dogcows Code - chaz/homebank/blob - src/ui-archive.c
import homebank-5.1.3
[chaz/homebank] / src / ui-archive.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2017 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 #include "homebank.h"
22
23 #include "ui-archive.h"
24 #include "ui-account.h"
25 #include "ui-category.h"
26 #include "ui-payee.h"
27 #include "ui-split.h"
28
29 #include "gtk-dateentry.h"
30
31 /****************************************************************************/
32 /* Debug macros */
33 /****************************************************************************/
34 #define MYDEBUG 0
35
36 #if MYDEBUG
37 #define DB(x) (x);
38 #else
39 #define DB(x);
40 #endif
41
42 /* our global datas */
43 extern struct HomeBank *GLOBALS;
44 extern struct Preferences *PREFS;
45
46
47 gchar *CYA_ARCHIVE_TYPE[] = {
48 N_("Scheduled"),
49 N_("Template"),
50 NULL
51 };
52
53
54 gchar *CYA_UNIT[] = { N_("Day"), N_("Week"), N_("Month"), N_("Year"), NULL };
55
56 gchar *CYA_SCHED_WEEKEND[] = { N_("Possible"), N_("Before"), N_("After"), NULL };
57
58 extern gchar *CYA_TXN_STATUS[];
59
60 static GtkWidget *ui_arc_listview_new(void);
61
62
63
64
65 static void ui_arc_listview_populate(GtkWidget *view, gint type)
66 {
67 GtkTreeModel *model;
68 GtkTreeIter iter;
69 GList *list;
70 gint i;
71
72 DB( g_print("ui_arc_listview_populate()\n") );
73
74 DB( g_print(" - type=%d\n", type) );
75
76
77 //insert all glist item into treeview
78 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
79
80
81 gtk_list_store_clear (GTK_LIST_STORE(model));
82
83 i=0;
84 list = g_list_first(GLOBALS->arc_list);
85 while (list != NULL)
86 {
87 Archive *item = list->data;
88
89 if( (type == ARC_TYPE_SCHEDULED) && !(item->flags & OF_AUTO) )
90 goto next;
91
92 if( (type == ARC_TYPE_TEMPLATE) && (item->flags & OF_AUTO) )
93 goto next;
94
95 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
96 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
97 LST_DEFARC_DATAS, item, //data struct
98 LST_DEFARC_OLDPOS, i, //oldpos
99 -1);
100
101 //DB( g_print(" populate_treeview: %d %08x\n", i, list->data) );
102 next:
103 i++; list = g_list_next(list);
104 }
105
106 }
107
108
109 static void ui_arc_listview_select_by_pointer(GtkTreeView *treeview, gpointer user_data)
110 {
111 GtkTreeModel *model;
112 GtkTreeIter iter;
113 GtkTreeSelection *selection;
114 gboolean valid;
115 Archive *arc = user_data;
116
117 model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
118 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
119
120 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
121 while (valid)
122 {
123 Archive *tmp_arc;
124
125 gtk_tree_model_get (model, &iter, LST_DEFARC_DATAS, &tmp_arc, -1);
126 if( arc == tmp_arc )
127 {
128 gtk_tree_selection_select_iter (selection, &iter);
129 break;
130 }
131
132 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
133 }
134 }
135
136
137 /*
138 **
139 ** The function should return:
140 ** a negative integer if the first value comes before the second,
141 ** 0 if they are equal,
142 ** or a positive integer if the first value comes after the second.
143 */
144 static gint ui_arc_listview_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
145 {
146 gint sortcol = GPOINTER_TO_INT(userdata);
147 Archive *entry1, *entry2;
148 gint retval = 0;
149
150 gtk_tree_model_get(model, a, LST_DEFARC_DATAS, &entry1, -1);
151 gtk_tree_model_get(model, b, LST_DEFARC_DATAS, &entry2, -1);
152
153 switch (sortcol)
154 {
155 case LST_DEFARC_SORT_MEMO:
156 retval = (entry1->flags & GF_INCOME) - (entry2->flags & GF_INCOME);
157 if(!retval)
158 {
159 retval = hb_string_utf8_compare(entry1->wording, entry2->wording);
160 }
161 break;
162 case LST_DEFARC_SORT_PAYEE:
163 {
164 Payee *p1, *p2;
165
166 p1 = da_pay_get(entry1->kpay);
167 p2 = da_pay_get(entry2->kpay);
168 if( p1 != NULL && p2 != NULL )
169 {
170 retval = hb_string_utf8_compare(p1->name, p2->name);
171 }
172 }
173 break;
174 default:
175 g_return_val_if_reached(0);
176 }
177 return retval;
178 }
179
180
181 /*
182 **
183 */
184 static void ui_arc_listview_auto_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
185 {
186 Archive *item;
187 gchar *iconname = NULL;
188
189 // get the transaction
190 gtk_tree_model_get(model, iter, LST_DEFARC_DATAS, &item, -1);
191
192 iconname = ( item->flags & OF_AUTO ) ? ICONNAME_HB_OPE_AUTO : NULL;
193
194 g_object_set(renderer, "icon-name", iconname, NULL);
195 }
196
197
198 /*
199 ** draw some text from the stored data structure
200 */
201 static void ui_arc_listview_cell_data_function_memo (GtkTreeViewColumn *col,
202 GtkCellRenderer *renderer,
203 GtkTreeModel *model,
204 GtkTreeIter *iter,
205 gpointer user_data)
206 {
207 Archive *item;
208 gchar *name;
209
210 gtk_tree_model_get(model, iter, LST_DEFARC_DATAS, &item, -1);
211
212 name = item->wording;
213
214 g_object_set(renderer, "text", name, NULL);
215 }
216
217
218
219 static void ui_arc_listview_cell_data_function_payee (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
220 {
221 Archive *arc;
222 Payee *pay;
223
224 gtk_tree_model_get(model, iter,
225 LST_DEFARC_DATAS, &arc,
226 -1);
227
228 if(arc)
229 {
230
231 pay = da_pay_get(arc->kpay);
232
233 if(pay != NULL)
234 g_object_set(renderer, "text", pay->name, NULL);
235 }
236 else
237 g_object_set(renderer, "text", NULL, NULL);
238
239 }
240
241 /*
242 **
243 */
244 static GtkWidget *ui_arc_listview_new(void)
245 {
246 GtkListStore *store;
247 GtkWidget *view;
248 GtkCellRenderer *renderer;
249 GtkTreeViewColumn *column;
250
251 //store
252 store = gtk_list_store_new (
253 NUM_LST_DEFARC,
254 G_TYPE_POINTER,
255 G_TYPE_UINT,
256 G_TYPE_BOOLEAN
257 );
258
259 //treeview
260 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
261 g_object_unref(store);
262
263 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (view), PREFS->grid_lines);
264
265 /* column: Memo */
266 renderer = gtk_cell_renderer_text_new ();
267 g_object_set(renderer,
268 "ellipsize", PANGO_ELLIPSIZE_END,
269 "ellipsize-set", TRUE,
270 NULL);
271
272 column = gtk_tree_view_column_new();
273 gtk_tree_view_column_set_title(column, _("Memo"));
274 gtk_tree_view_column_pack_start(column, renderer, TRUE);
275 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_arc_listview_cell_data_function_memo, GINT_TO_POINTER(LST_DEFARC_SORT_MEMO), NULL);
276 gtk_tree_view_column_set_sort_column_id (column, LST_DEFARC_SORT_MEMO);
277 gtk_tree_view_column_set_alignment (column, 0.5);
278 gtk_tree_view_column_set_min_width(column, HB_MINWIDTH_LIST);
279 gtk_tree_view_column_set_resizable(column, TRUE);
280 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
281
282 /* column: Payee */
283 renderer = gtk_cell_renderer_text_new ();
284 g_object_set(renderer,
285 "ellipsize", PANGO_ELLIPSIZE_END,
286 "ellipsize-set", TRUE,
287 NULL);
288 column = gtk_tree_view_column_new();
289 gtk_tree_view_column_set_title(column, _("Payee"));
290 gtk_tree_view_column_pack_start(column, renderer, TRUE);
291 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_arc_listview_cell_data_function_payee, GINT_TO_POINTER(LST_DEFARC_SORT_PAYEE), NULL);
292 gtk_tree_view_column_set_resizable(column, TRUE);
293 //gtk_tree_view_column_add_attribute(column, renderer, "text", 1);
294 gtk_tree_view_column_set_sort_column_id (column, LST_DEFARC_SORT_PAYEE);
295 gtk_tree_view_column_set_alignment (column, 0.5);
296 gtk_tree_view_column_set_min_width(column, HB_MINWIDTH_LIST);
297 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
298
299
300 /* column: Scheduled icon */
301 column = gtk_tree_view_column_new();
302 renderer = gtk_cell_renderer_pixbuf_new ();
303 //gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
304 gtk_tree_view_column_pack_start(column, renderer, TRUE);
305 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_arc_listview_auto_cell_data_function, NULL, NULL);
306 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
307
308
309 //sortable
310 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFARC_SORT_MEMO, ui_arc_listview_compare_func, GINT_TO_POINTER(LST_DEFARC_SORT_MEMO), NULL);
311 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFARC_SORT_PAYEE, ui_arc_listview_compare_func, GINT_TO_POINTER(LST_DEFARC_SORT_PAYEE), NULL);
312
313
314 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), LST_DEFARC_SORT_MEMO, GTK_SORT_ASCENDING);
315
316 //gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
317 //gtk_tree_view_set_reorderable (GTK_TREE_VIEW(view), TRUE);
318
319 return(view);
320 }
321
322
323 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
324
325
326
327 /*
328 ** add an empty new account to our temp GList and treeview
329 */
330 static void ui_arc_manage_add(GtkWidget *widget, gpointer user_data)
331 {
332 struct ui_arc_manage_data *data;
333 GtkTreeModel *model;
334 GtkTreeIter iter;
335 Archive *item;
336 gint type;
337
338 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
339 DB( g_print("\n[ui_scheduled] add\n") );
340
341 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_arc));
342
343 item = da_archive_malloc();
344 item->wording = g_strdup_printf(_("(template %d)"), g_list_length(GLOBALS->arc_list) + 1);
345 item->unit = 2;
346
347 type = radio_get_active(GTK_CONTAINER(data->RA_type)) == 1 ? ARC_TYPE_TEMPLATE : ARC_TYPE_SCHEDULED;
348 if( type == ARC_TYPE_SCHEDULED )
349 item->flags |= OF_AUTO;
350
351 GLOBALS->arc_list = g_list_append(GLOBALS->arc_list, item);
352
353 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
354 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
355 LST_DEFARC_DATAS, item,
356 LST_DEFARC_OLDPOS, 0,
357 -1);
358
359 gtk_tree_selection_select_iter (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc)), &iter);
360
361 data->change++;
362 }
363
364 /*
365 ** delete the selected account to our treeview and temp GList
366 */
367 static void ui_arc_manage_delete(GtkWidget *widget, gpointer user_data)
368 {
369 struct ui_arc_manage_data *data;
370 GtkTreeSelection *selection;
371 GtkTreeModel *model;
372 GtkTreeIter iter;
373 Archive *item;
374 gint result;
375
376 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
377 DB( g_print("\n[ui_scheduled] delete (data=%p)\n", data) );
378
379 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
380 //if true there is a selected node
381 if (gtk_tree_selection_get_selected(selection, &model, &iter))
382 {
383 gchar *title;
384 gchar *secondtext;
385
386 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
387
388 title = g_strdup_printf (
389 _("Are you sure you want to permanently delete '%s'?"), item->wording);
390
391 secondtext = _("If you delete a scheduled/template, it will be permanently lost.");
392
393 result = ui_dialog_msg_confirm_alert(
394 GTK_WINDOW(data->window),
395 title,
396 secondtext,
397 _("_Delete")
398 );
399
400 g_free(title);
401
402 if( result == GTK_RESPONSE_OK )
403 {
404 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
405
406 GLOBALS->arc_list = g_list_remove(GLOBALS->arc_list, item);
407
408 data->change++;
409
410 }
411 //DB( g_print(" delete =%08x (pos=%d)\n", entry, g_list_index(data->tmp_list, entry) ) );
412 }
413 }
414
415
416 /*
417 ** update the archive name everytime it changes
418 */
419 static void ui_arc_manage_rename(GtkWidget *widget, gpointer user_data)
420 {
421 struct ui_arc_manage_data *data;
422 GtkTreeSelection *selection;
423 GtkTreeModel *model;
424 GtkTreeIter iter;
425 gchar *txt;
426 Archive *item;
427
428 DB( g_print("\n[ui_scheduled] rename\n") );
429
430 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
431
432 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
433 //if true there is a selected node
434 if (gtk_tree_selection_get_selected(selection, &model, &iter))
435 {
436 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
437
438 DB( g_print(" -> %s\n", item->wording) );
439
440 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_word));
441 // ignore if entry is empty
442 if (txt && *txt)
443 {
444 g_free(item->wording);
445 item->wording = g_strdup(txt);
446 }
447
448 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_arc));
449
450 }
451
452 }
453
454
455
456
457 /*
458 ** set widgets contents from the selected account
459 */
460 static void ui_arc_manage_set(GtkWidget *widget, gpointer user_data)
461 {
462 struct ui_arc_manage_data *data;
463 GtkTreeSelection *selection;
464 GtkTreeModel *model;
465 GtkTreeIter iter;
466
467 Archive *item;
468
469 DB( g_print("\n[ui_scheduled] set\n") );
470
471 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
472
473 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
474 //if true there is a selected node
475 if (gtk_tree_selection_get_selected(selection, &model, &iter))
476 {
477 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
478
479 g_signal_handler_block(data->ST_word, data->handler_id[HID_ARC_MEMO]);
480 gtk_entry_set_text(GTK_ENTRY(data->ST_word), item->wording);
481 g_signal_handler_unblock(data->ST_word, data->handler_id[HID_ARC_MEMO]);
482
483 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), item->amount);
484
485
486
487 radio_set_active(GTK_CONTAINER(data->RA_status), item->status );
488
489
490 /*g_signal_handler_block(data->CM_valid, data->handler_id[HID_ARC_VALID]);
491 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_valid), (item->flags & OF_VALID) ? 1 : 0);
492 g_signal_handler_unblock(data->CM_valid, data->handler_id[HID_ARC_VALID]);
493
494 g_signal_handler_block(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
495 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_remind), (item->flags & OF_REMIND) ? 1 : 0);
496 g_signal_handler_unblock(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
497 */
498
499 gtk_combo_box_set_active(GTK_COMBO_BOX(data->NU_mode), item->paymode);
500
501 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_cheque), (item->flags & OF_CHEQ2) ? 1 : 0);
502
503 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), item->kcat);
504
505 DB( g_print(" -> set payee %d\n", item->kpay) );
506 ui_pay_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_pay), item->kpay);
507
508 DB( g_print(" -> PO_acc %d\n", item->kacc) );
509 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_acc), item->kacc);
510
511 DB( g_print(" -> PO_accto %d\n", item->kxferacc) );
512 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_accto), item->kxferacc);
513
514 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_auto), (item->flags & OF_AUTO) ? 1 : 0);
515
516 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NB_every), item->every);
517
518 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_unit), item->unit);
519
520 gtk_date_entry_set_date(GTK_DATE_ENTRY(data->PO_next), item->nextdate);
521
522 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_limit), (item->flags & OF_LIMIT) ? 1 : 0);
523
524
525 DB( g_print("nb_limit = %d %g\n", item->limit, (gdouble)item->limit) );
526
527 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NB_limit), (gdouble)item->limit);
528
529 radio_set_active(GTK_CONTAINER(data->CY_weekend), item->weekend);
530
531 }
532
533 }
534
535 /*
536 ** get widgets contents to the selected account
537 */
538 static void ui_arc_manage_getlast(struct ui_arc_manage_data *data)
539 {
540 Archive *item;
541 gchar *txt;
542 gdouble value;
543 gint active;
544
545
546 DB( g_print("\n[ui_scheduled] getlast\n") );
547
548 item = data->lastarcitem;
549
550 if( item != NULL )
551 {
552 DB( g_print(" -> %s\n", item->wording) );
553
554 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_arc));
555
556 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_word));
557 // ignore if entry is empty
558 if (txt && *txt)
559 {
560 g_free(item->wording);
561 item->wording = g_strdup(txt);
562 }
563
564 gtk_spin_button_update(GTK_SPIN_BUTTON(data->ST_amount));
565 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
566 item->amount = value;
567
568 item->paymode = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
569 item->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_grp));
570 item->kpay = ui_pay_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_pay));
571 item->kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
572 item->kxferacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
573
574 item->status = radio_get_active(GTK_CONTAINER(data->RA_status));
575
576 //#1615245: moved here, after get combo entry key
577 if( item->paymode != PAYMODE_INTXFER )
578 {
579 //#677351: revert kxferacc to 0
580 item->kxferacc = 0;
581 }
582
583 /* flags */
584 //item->flags = 0;
585 item->flags &= (OF_SPLIT); //(split is set in hb_archive)
586
587 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cheque));
588 if(active == 1) item->flags |= OF_CHEQ2;
589
590 //active = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_amount));
591 active = item->amount > 0 ? TRUE : FALSE;
592 if(active == TRUE) item->flags |= OF_INCOME;
593
594
595 /* -- automated -- */
596
597 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_auto));
598 if(active == 1) item->flags |= OF_AUTO;
599
600 gtk_spin_button_update(GTK_SPIN_BUTTON(data->NB_every));
601 item->every = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->NB_every));
602 item->unit = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_unit));
603 item->nextdate = gtk_date_entry_get_date(GTK_DATE_ENTRY(data->PO_next));
604
605 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_limit));
606 if(active == 1) item->flags |= OF_LIMIT;
607
608 gtk_spin_button_update(GTK_SPIN_BUTTON(data->NB_limit));
609 item->limit = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->NB_limit));
610
611 item->weekend = radio_get_active(GTK_CONTAINER(data->CY_weekend));
612
613 data->change++;
614 }
615 }
616
617
618 static void ui_arc_manage_update_accto(GtkWidget *widget, gpointer user_data)
619 {
620 struct ui_arc_manage_data *data;
621 guint kacc, kdst;
622
623 DB( g_print("\n\n[ui_scheduled] update accto\n") );
624
625 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
626
627 kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
628 kdst = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
629
630 DB( g_print(" ksrc=%d, kdst=%d\n", kacc, kdst) );
631
632 ui_acc_comboboxentry_populate_except(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, kacc, ACC_LST_INSERT_NORMAL);
633
634 if( (kacc == 0) || (kacc == kdst) )
635 {
636 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_accto), 0);
637 }
638
639 }
640
641
642 /*
643 **
644 */
645 static void ui_arc_manage_paymode(GtkWidget *widget, gpointer user_data)
646 {
647 struct ui_arc_manage_data *data;
648 gint payment;
649 gint page;
650 gboolean sensitive;
651
652 DB( g_print("\n[ui_scheduled] paymode\n") );
653
654 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
655
656 //DB( g_print(" widget=%p, data=%p\n", widget, data) );
657
658
659 payment = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
660 page = 0;
661
662 if(payment == PAYMODE_CHECK)
663 page = 1;
664
665 sensitive = page == 1 ? TRUE : FALSE;
666 hb_widget_visible(data->CM_cheque, sensitive);
667
668 if(payment == PAYMODE_INTXFER)
669 {
670 page = 2;
671 ui_arc_manage_update_accto(widget, user_data);
672 }
673
674 DB( g_print(" payment: %d, page: %d\n", payment, page) );
675
676 sensitive = page == 2 ? TRUE : FALSE;
677 hb_widget_visible(data->LB_accto, sensitive);
678 hb_widget_visible(data->PO_accto, sensitive);
679
680 DB( g_print(" visible: %d\n", sensitive) );
681
682 }
683
684 /*
685 **
686 */
687 static void ui_arc_manage_scheduled(GtkWidget *widget, gpointer user_data)
688 {
689 struct ui_arc_manage_data *data;
690 Archive *arcitem;
691 GtkTreeModel *model;
692 GtkTreeIter iter;
693 GtkTreePath *path;
694 gboolean selected, sensitive;
695
696 DB( g_print("\n[ui_scheduled] scheduled\n") );
697
698 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
699
700 sensitive = FALSE;
701
702
703 selected = gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc)), &model, &iter);
704 if(selected)
705 {
706 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &arcitem, -1);
707
708 arcitem->flags &= ~(OF_AUTO);
709 sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_auto)) ? TRUE : FALSE;
710 if(sensitive)
711 arcitem->flags |= OF_AUTO;
712 }
713
714
715
716 gtk_widget_set_sensitive(data->LB_next, sensitive);
717 gtk_widget_set_sensitive(data->PO_next, sensitive);
718
719 gtk_widget_set_sensitive(data->LB_every, sensitive);
720 gtk_widget_set_sensitive(data->NB_every, sensitive);
721
722 gtk_widget_set_sensitive(data->LB_weekend, sensitive);
723 gtk_widget_set_sensitive(data->CY_weekend, sensitive);
724
725 gtk_widget_set_sensitive(data->CY_unit, sensitive);
726 gtk_widget_set_sensitive(data->CM_limit, sensitive);
727
728 gtk_widget_set_sensitive(data->LB_posts, sensitive);
729
730
731 sensitive = (sensitive == TRUE) ? gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_limit)) : sensitive;
732 gtk_widget_set_sensitive(data->NB_limit, sensitive);
733
734 if(selected)
735 {
736 /* redraw the row to display/hide the icon */
737 path = gtk_tree_model_get_path(model, &iter);
738 gtk_tree_model_row_changed(model, path, &iter);
739 gtk_tree_path_free (path);
740
741 // gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_arc));
742 //gtk_widget_queue_draw (GTK_WIDGET(data->LV_arc));
743 }
744
745 }
746
747 static void ui_arc_manage_update_post_split(GtkWidget *widget, gdouble amount)
748 {
749 struct ui_arc_manage_data *data;
750 gboolean sensitive = TRUE;
751
752 DB( g_print("(ui_arc_manage) update _post_split\n") );
753
754 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
755
756 DB( g_print("- amount=%.2f\n", amount) );
757
758 data->lastarcitem->amount = amount;
759 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), amount);
760
761 data->lastarcitem->flags &= ~(OF_SPLIT); //First set flag that Splits are cleared
762
763 if (da_splits_count(data->lastarcitem->splits) > 0)
764 {
765 /* disable category if split is set */
766 data->lastarcitem->flags |= OF_SPLIT; //Then set flag that Splits are active
767 sensitive = FALSE;
768 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), 0);
769 }
770 gtk_widget_set_sensitive(data->ST_amount, sensitive);
771
772 //# 1416624 empty category when split
773 if( (data->lastarcitem->flags & (OF_SPLIT)) )
774 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), 0);
775 gtk_widget_set_sensitive(data->PO_grp, sensitive);
776
777 }
778 /*
779 ** update the widgets status and contents from action/selection value
780 */
781 static void ui_arc_manage_update(GtkWidget *widget, gpointer user_data)
782 {
783 struct ui_arc_manage_data *data;
784 GtkTreeModel *model;
785 GtkTreeIter iter;
786 gboolean selected, sensitive;
787 gboolean split_sensitive = TRUE;
788 Archive *arcitem;
789
790
791 DB( g_print("\n[ui_scheduled] update\n") );
792
793 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
794 //window = gtk_widget_get_ancestor(GTK_WIDGET(treeview), GTK_TYPE_WINDOW);
795 //DB( g_print("\n[ui_scheduled] widget=%08lx, window=%08lx, inst_data=%08lx\n", treeview, window, data) );
796
797 //if true there is a selected node
798 selected = gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc)), &model, &iter);
799
800 DB( g_print(" selected = %d\n", selected) );
801
802 sensitive = (selected == TRUE) ? TRUE : FALSE;
803
804 gtk_widget_set_sensitive(data->GR_txnleft, sensitive);
805
806 gtk_widget_set_sensitive(data->CM_auto, sensitive);
807
808 gtk_widget_set_sensitive(data->BT_rem, sensitive);
809
810 if(selected)
811 {
812 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &arcitem, -1);
813
814 if(data->lastarcitem != NULL && arcitem != data->lastarcitem)
815 {
816 DB( g_print(" -> should do a get for last selected (%s)\n", data->lastarcitem->wording) );
817 ui_arc_manage_getlast(data);
818 }
819 data->lastarcitem = arcitem;
820
821 if (da_splits_count(data->lastarcitem->splits) > 0)
822 {
823
824 data->lastarcitem->flags |= OF_SPLIT; //Then set flag that Splits are active
825 split_sensitive = FALSE;
826 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), 0);
827 }
828
829 gtk_widget_set_sensitive(data->ST_amount, split_sensitive);
830 gtk_widget_set_sensitive(data->PO_grp, split_sensitive);
831
832 DB( g_print(" - call set\n") );
833 ui_arc_manage_set(widget, NULL);
834 }
835 else
836 {
837 data->lastarcitem = NULL;
838 }
839
840 //gtk_widget_set_sensitive(data->LB_schedinsert, sensitive);
841
842
843 DB( g_print(" - call scheduled\n") );
844 ui_arc_manage_scheduled(widget, NULL);
845 DB( g_print(" - call paymode\n") );
846 ui_arc_manage_paymode(widget,NULL);
847
848
849 }
850
851
852
853 /*
854 **
855 */
856 static void ui_arc_manage_toggleamount(GtkWidget *widget, GtkEntryIconPosition icon_pos, GdkEvent *event, gpointer user_data)
857 {
858 struct ui_arc_manage_data *data;
859 gdouble value;
860
861 DB( g_print("\n[ui_scheduled] toggleamount\n") );
862
863 if(icon_pos == GTK_ENTRY_ICON_PRIMARY)
864 {
865
866 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
867
868 gtk_spin_button_update(GTK_SPIN_BUTTON(data->ST_amount));
869
870 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
871 value *= -1;
872 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), value);
873
874 /*
875 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
876 type = gtk_widget_get_sensitive(data->CY_amount);
877
878 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), value * type);
879 */
880 }
881
882 }
883
884
885 static void defarchive_button_split_cb(GtkWidget *widget, gpointer user_data)
886 {
887 struct ui_arc_manage_data *data;
888 gdouble amount;
889
890 DB( g_print("\n[ui_scheduled] doing split\n") );
891
892 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
893
894 amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
895
896 ui_split_dialog(data->window, data->lastarcitem->splits, amount, &ui_arc_manage_update_post_split);
897
898 }
899
900
901 static void ui_arc_manage_selection(GtkTreeSelection *treeselection, gpointer user_data)
902 {
903 DB( g_print("\n[ui_scheduled] selection\n") );
904
905 DB( g_print(" - call update\n") );
906 ui_arc_manage_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), NULL);
907 }
908
909
910 static void ui_arc_manage_populate_listview(struct ui_arc_manage_data *data)
911 {
912 gint type;
913
914 DB( g_print("\n[ui_scheduled] populate listview\n") );
915
916 type = radio_get_active(GTK_CONTAINER(data->RA_type)) == 1 ? ARC_TYPE_TEMPLATE : ARC_TYPE_SCHEDULED;
917 ui_arc_listview_populate(data->LV_arc, type);
918 gtk_tree_view_expand_all (GTK_TREE_VIEW(data->LV_arc));
919 }
920
921
922
923
924 static gboolean ui_arc_manage_cleanup(struct ui_arc_manage_data *data, gint result)
925 {
926 gboolean doupdate = FALSE;
927
928 DB( g_print("\n[ui_scheduled] cleanup\n") );
929
930
931 if(data->lastarcitem != NULL)
932 {
933 DB( g_print(" -> should do a get for last selected (%s)\n", data->lastarcitem->wording) );
934 ui_arc_manage_getlast(data);
935 }
936
937 GLOBALS->arc_list = da_archive_sort(GLOBALS->arc_list);
938
939 GLOBALS->changes_count += data->change;
940
941 return doupdate;
942 }
943
944 /*
945 **
946 */
947 static void ui_arc_manage_setup(struct ui_arc_manage_data *data)
948 {
949
950 DB( g_print("\n[ui_scheduled] setup\n") );
951
952 //init GList
953 data->tmp_list = NULL; //hb-glist_clone_list(GLOBALS->arc_list, sizeof(struct _Archive));
954 data->change = 0;
955 data->lastarcitem = NULL;
956
957 //hb-glist_populate_treeview(data->tmp_list, data->LV_arc, LST_DEFARC_DATAS, LST_DEFARC_OLDPOS);
958
959 //insert all glist item into treeview
960 ui_arc_manage_populate_listview(data);
961
962 DB( g_print(" - populate boxentries\n") );
963
964 ui_pay_comboboxentry_populate(GTK_COMBO_BOX(data->PO_pay) , GLOBALS->h_pay);
965 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_grp) , GLOBALS->h_cat);
966 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_acc) , GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
967 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
968 }
969
970
971 static GtkWidget *ui_arc_manage_create_left_txn(struct ui_arc_manage_data *data)
972 {
973 GtkWidget *group_grid, *hbox, *label, *widget, *image;
974 gint row;
975
976 // group :: Transaction detail
977 group_grid = gtk_grid_new ();
978 data->GR_txnleft = group_grid;
979 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
980 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
981
982 row = 0;
983 label = make_label_widget(_("_Amount:"));
984 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
985 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
986 gtk_grid_attach (GTK_GRID (group_grid), hbox, 1, row, 1, 1);
987
988 widget = make_amount(label);
989 data->ST_amount = widget;
990 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(widget), GTK_ENTRY_ICON_PRIMARY, ICONNAME_HB_TOGGLE_SIGN);
991 gtk_entry_set_icon_tooltip_text(GTK_ENTRY(widget), GTK_ENTRY_ICON_PRIMARY, _("Toggle amount sign"));
992 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
993
994 image = gtk_image_new_from_icon_name (ICONNAME_HB_BUTTON_SPLIT, GTK_ICON_SIZE_MENU);
995 widget = gtk_button_new();
996 g_object_set (widget, "image", image, NULL);
997 data->BT_split = widget;
998 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
999 gtk_widget_set_tooltip_text(widget, _("Transaction splits"));
1000
1001 row++;
1002 label = make_label_widget(_("Pay_ment:"));
1003 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1004 widget = make_paymode(label);
1005 data->NU_mode = widget;
1006 gtk_widget_set_halign (widget, GTK_ALIGN_START);
1007 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1008
1009 row++;
1010 widget = gtk_check_button_new_with_mnemonic(_("Of notebook _2"));
1011 data->CM_cheque = widget;
1012 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 2, 1);
1013
1014 /* info should be here some day */
1015
1016 row++;
1017 label = make_label_widget(_("A_ccount:"));
1018 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1019 widget = ui_acc_comboboxentry_new(label);
1020 data->PO_acc = widget;
1021 gtk_widget_set_hexpand (widget, TRUE);
1022 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1023
1024 row++;
1025 label = make_label_widget(_("_To account:"));
1026 data->LB_accto = label;
1027 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1028 widget = ui_acc_comboboxentry_new(label);
1029 data->PO_accto = widget;
1030 gtk_widget_set_hexpand (widget, TRUE);
1031 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1032
1033 row++;
1034 label = make_label_widget(_("_Payee:"));
1035 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1036 widget = ui_pay_comboboxentry_new(label);
1037 data->PO_pay = widget;
1038 gtk_widget_set_hexpand (widget, TRUE);
1039 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1040
1041 row++;
1042 label = make_label_widget(_("_Category:"));
1043 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1044 widget = ui_cat_comboboxentry_new(label);
1045 data->PO_grp = widget;
1046 gtk_widget_set_hexpand (widget, TRUE);
1047 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1048
1049 row++;
1050 label = make_label_widget(_("_Status:"));
1051 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1052 widget = make_radio(CYA_TXN_STATUS, TRUE, GTK_ORIENTATION_HORIZONTAL);
1053 data->RA_status = widget;
1054 gtk_widget_set_halign (widget, GTK_ALIGN_START);
1055 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1056
1057 row++;
1058 label = make_label_widget(_("_Memo:"));
1059 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
1060 widget = make_string(label);
1061 gtk_widget_set_hexpand (widget, TRUE);
1062 data->ST_word = widget;
1063 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
1064
1065 /* tags should be here some day */
1066
1067
1068 return group_grid;
1069 }
1070
1071
1072 static GtkWidget *ui_arc_manage_create_scheduling(struct ui_arc_manage_data *data)
1073 {
1074 GtkWidget *group_grid, *hbox, *label, *widget;
1075 gint row;
1076
1077 // group :: Scheduled insertion
1078 group_grid = gtk_grid_new ();
1079 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1080 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1081
1082 label = make_label_group(_("Scheduled insertion"));
1083 data->LB_schedinsert = label;
1084 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
1085
1086 row = 1;
1087 widget = gtk_check_button_new_with_mnemonic(_("_Activate"));
1088 data->CM_auto = widget;
1089 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 2, 1);
1090
1091 row++;
1092 label = gtk_label_new_with_mnemonic (_("Next _date:"));
1093 data->LB_next = label;
1094 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1095 widget = gtk_date_entry_new();
1096 data->PO_next = widget;
1097 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1098
1099 row++;
1100 label = make_label_widget(_("Ever_y:"));
1101 data->LB_every = label;
1102 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1103
1104 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
1105 gtk_grid_attach (GTK_GRID (group_grid), hbox, 2, row, 1, 1);
1106 widget = make_numeric(label, 1, 100);
1107 data->NB_every = widget;
1108 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1109 //label = gtk_label_new_with_mnemonic (_("_Unit:"));
1110 //gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1111 widget = make_cycle(label, CYA_UNIT);
1112 data->CY_unit = widget;
1113 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1114
1115 row++;
1116 label = make_label_widget(_("Week end:"));
1117 data->LB_weekend = label;
1118 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1119
1120 widget = make_radio(CYA_SCHED_WEEKEND, FALSE, GTK_ORIENTATION_HORIZONTAL);
1121 data->CY_weekend = widget;
1122 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1123
1124 row++;
1125 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, SPACING_SMALL);
1126 gtk_grid_attach (GTK_GRID (group_grid), hbox, 1, row, 3, 1);
1127
1128 widget = gtk_check_button_new_with_mnemonic(_("_Stop after:"));
1129 data->CM_limit = widget;
1130 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1131
1132 widget = make_numeric(label, 1, 366);
1133 data->NB_limit = widget;
1134 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1135
1136 label = gtk_label_new_with_mnemonic (_("posts"));
1137 data->LB_posts = label;
1138 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1139
1140 return group_grid;
1141 }
1142
1143 static void ui_arc_manage_type_changed_cb (GtkToggleButton *button, gpointer user_data)
1144 {
1145 ui_arc_manage_populate_listview(user_data);
1146 //g_print(" toggle type=%d\n", gtk_toggle_button_get_active(button));
1147 }
1148
1149
1150 GtkWidget *ui_arc_manage_dialog (Archive *ext_arc)
1151 {
1152 struct ui_arc_manage_data data;
1153 GtkWidget *dialog, *content_area, *table, *bbox;
1154 GtkWidget *content_grid, *group_grid, *hgrid, *treeview, *scrollwin;
1155 GtkWidget *widget, *hpaned;
1156 gint w, h, row;
1157
1158 dialog = gtk_dialog_new_with_buttons (_("Manage scheduled/template transactions"),
1159 GTK_WINDOW(GLOBALS->mainwindow),
1160 0,
1161 _("_Close"),
1162 GTK_RESPONSE_ACCEPT,
1163 NULL);
1164
1165 data.window = dialog;
1166
1167 gtk_window_set_icon_name(GTK_WINDOW (dialog), ICONNAME_HB_ARCHIVE);
1168
1169 //set a nice dialog size
1170 gtk_window_get_size(GTK_WINDOW(GLOBALS->mainwindow), &w, &h);
1171 gtk_window_set_default_size (GTK_WINDOW(dialog), -1, h/PHI);
1172
1173
1174 //store our dialog private data
1175 g_object_set_data(G_OBJECT(dialog), "inst_data", (gpointer)&data);
1176 DB( g_print("\n[ui_scheduled] dialog=%p, inst_data=%p\n", dialog, &data) );
1177
1178 //dialog content
1179 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog)); // return a vbox
1180
1181 //our table
1182 table = gtk_grid_new ();
1183 gtk_grid_set_row_spacing (GTK_GRID (table), SPACING_MEDIUM);
1184 gtk_grid_set_column_spacing (GTK_GRID (table), SPACING_MEDIUM);
1185 g_object_set(table, "margin", SPACING_MEDIUM, NULL);
1186 gtk_box_pack_start (GTK_BOX (content_area), table, TRUE, TRUE, 0);
1187
1188 row = 0;
1189 bbox = make_radio(CYA_ARCHIVE_TYPE, TRUE, GTK_ORIENTATION_HORIZONTAL);
1190 data.RA_type = bbox;
1191 gtk_widget_set_halign (bbox, GTK_ALIGN_CENTER);
1192 gtk_grid_attach (GTK_GRID (table), bbox, 0, row, 2, 1);
1193
1194 widget = radio_get_nth_widget(GTK_CONTAINER(bbox), 1);
1195 if(widget)
1196 g_signal_connect (widget, "toggled", G_CALLBACK (ui_arc_manage_type_changed_cb), &data);
1197
1198 row++;
1199 hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
1200 //gtk_container_set_border_width (GTK_CONTAINER(hpaned), SPACING_MEDIUM);
1201 gtk_grid_attach (GTK_GRID (table), hpaned, 0, row, 2, 1);
1202
1203
1204 /* left area */
1205 hgrid = gtk_grid_new ();
1206 gtk_grid_set_row_spacing (GTK_GRID (hgrid), SPACING_SMALL);
1207 gtk_grid_set_column_spacing (GTK_GRID (hgrid), SPACING_MEDIUM);
1208 gtk_widget_set_margin_right(hgrid, SPACING_SMALL);
1209 gtk_paned_pack1 (GTK_PANED(hpaned), hgrid, FALSE, FALSE);
1210
1211 // listview
1212 scrollwin = gtk_scrolled_window_new(NULL,NULL);
1213 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
1214 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1215 treeview = (GtkWidget *)ui_arc_listview_new();
1216 data.LV_arc = treeview;
1217 gtk_widget_set_size_request(treeview, HB_MINWIDTH_LIST, -1);
1218 gtk_container_add(GTK_CONTAINER(scrollwin), treeview);
1219 gtk_widget_set_hexpand (scrollwin, TRUE);
1220 gtk_widget_set_vexpand (scrollwin, TRUE);
1221 gtk_grid_attach (GTK_GRID (hgrid), scrollwin, 0, 0, 2, 1);
1222
1223 widget = gtk_button_new_with_mnemonic(_("_Add"));
1224 data.BT_add = widget;
1225 gtk_grid_attach (GTK_GRID (hgrid), widget, 0, 1, 1, 1);
1226
1227 widget = gtk_button_new_with_mnemonic(_("_Delete"));
1228 data.BT_rem = widget;
1229 gtk_grid_attach (GTK_GRID (hgrid), widget, 1, 1, 1, 1);
1230
1231
1232 /* right area */
1233 content_grid = gtk_grid_new();
1234 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
1235 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
1236 //gtk_container_set_border_width (GTK_CONTAINER(content_grid), SPACING_MEDIUM);
1237 gtk_widget_set_margin_left(content_grid, SPACING_SMALL);
1238 gtk_paned_pack2 (GTK_PANED(hpaned), content_grid, FALSE, FALSE);
1239
1240 group_grid = ui_arc_manage_create_left_txn(&data);
1241 //gtk_widget_set_hexpand (GTK_WIDGET(group_grid), FALSE);
1242 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, 0, 1, 1);
1243
1244 /* sheduling */
1245 group_grid = ui_arc_manage_create_scheduling(&data);
1246 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, 1, 1, 1);
1247
1248 /* set default periodicity to month */
1249 //todo: move elsewhere
1250 gtk_combo_box_set_active(GTK_COMBO_BOX(data.CY_unit), 2);
1251
1252 gtk_widget_show_all(content_area);
1253 gtk_widget_hide(data.CM_cheque);
1254 gtk_widget_hide(data.PO_accto);
1255
1256 //connect all our signals
1257 g_signal_connect (dialog, "destroy", G_CALLBACK (gtk_widget_destroyed), &dialog);
1258
1259 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data.LV_arc)), "changed", G_CALLBACK (ui_arc_manage_selection), NULL);
1260 g_signal_connect (G_OBJECT (data.ST_amount), "icon-release", G_CALLBACK (ui_arc_manage_toggleamount), NULL);
1261
1262 g_signal_connect (G_OBJECT (data.BT_add), "clicked", G_CALLBACK (ui_arc_manage_add), NULL);
1263 g_signal_connect (G_OBJECT (data.BT_rem), "clicked", G_CALLBACK (ui_arc_manage_delete), NULL);
1264
1265 data.handler_id[HID_ARC_MEMO] = g_signal_connect (G_OBJECT (data.ST_word), "changed", G_CALLBACK (ui_arc_manage_rename), NULL);
1266 g_signal_connect (data.NU_mode, "changed", G_CALLBACK (ui_arc_manage_paymode), NULL);
1267 g_signal_connect (data.PO_acc, "changed", G_CALLBACK (ui_arc_manage_update_accto), NULL);
1268 //data.handler_id[HID_ARC_VALID] = g_signal_connect (data.CM_valid , "toggled", G_CALLBACK (ui_arc_manage_togglestatus), GINT_TO_POINTER(HID_ARC_VALID));
1269 //data.handler_id[HID_ARC_REMIND] = g_signal_connect (data.CM_remind, "toggled", G_CALLBACK (ui_arc_manage_togglestatus), GINT_TO_POINTER(HID_ARC_REMIND));
1270
1271 g_signal_connect (data.CM_auto, "toggled", G_CALLBACK (ui_arc_manage_scheduled), NULL);
1272 g_signal_connect (data.CM_limit, "toggled", G_CALLBACK (ui_arc_manage_scheduled), NULL);
1273
1274 g_signal_connect (G_OBJECT (data.BT_split), "clicked", G_CALLBACK (defarchive_button_split_cb), NULL);
1275
1276 //setup, init and show dialog
1277 ui_arc_manage_setup(&data);
1278 ui_arc_manage_update(data.LV_arc, NULL);
1279
1280 gtk_widget_show (dialog);
1281
1282 if(ext_arc != NULL)
1283 ui_arc_listview_select_by_pointer(GTK_TREE_VIEW(data.LV_arc), ext_arc);
1284
1285 //wait for the user
1286 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
1287
1288 switch (result)
1289 {
1290 case GTK_RESPONSE_ACCEPT:
1291 //do_application_specific_something ();
1292 break;
1293 default:
1294 //do_nothing_since_dialog_was_cancelled ();
1295 break;
1296 }
1297
1298 // cleanup and destroy
1299 ui_arc_manage_cleanup(&data, result);
1300 gtk_widget_destroy (dialog);
1301
1302 return NULL;
1303 }
1304
1305
This page took 0.090726 seconds and 5 git commands to generate.