add gitignore
[chaz/homebank] / src / ui-archive.c
1 /* HomeBank -- Free, easy, personal accounting 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
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
28 #include "gtk-dateentry.h"
29
30 /****************************************************************************/
31 /* Debug macros */
32 /****************************************************************************/
33 #define MYDEBUG 0
34
35 #if MYDEBUG
36 #define DB(x) (x);
37 #else
38 #define DB(x);
39 #endif
40
41 /* our global datas */
42 extern struct HomeBank *GLOBALS;
43
44
45
46 gchar *CYA_UNIT[] = { N_("Day"), N_("Week"), N_("Month"), N_("Year"), NULL };
47
48 gchar *CYA_SCHED_WEEKEND[] = { N_("Possible"), N_("Before"), N_("After"), NULL };
49
50
51 static GtkWidget *ui_arc_listview_new(void);
52
53
54
55
56 /*
57 **
58 ** The function should return:
59 ** a negative integer if the first value comes before the second,
60 ** 0 if they are equal,
61 ** or a positive integer if the first value comes after the second.
62 */
63 static gint ui_arc_listview_compare_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
64 {
65 Archive *entry1, *entry2;
66
67 gtk_tree_model_get(model, a, LST_DEFARC_DATAS, &entry1, -1);
68 gtk_tree_model_get(model, b, LST_DEFARC_DATAS, &entry2, -1);
69
70 return hb_string_utf8_compare(entry1->wording, entry2->wording);
71 }
72
73
74 /*
75 **
76 */
77 static void ui_arc_listview_auto_cell_data_function (GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
78 {
79 Archive *item;
80 GdkPixbuf *pixbuf = NULL;
81
82 // get the transaction
83 gtk_tree_model_get(model, iter, LST_DEFARC_DATAS, &item, -1);
84
85 if( item->flags & OF_AUTO )
86 pixbuf = GLOBALS->lst_pixbuf[LST_PIXBUF_AUTO];
87
88 g_object_set(renderer, "pixbuf", pixbuf, NULL);
89 }
90
91
92 /*
93 ** draw some text from the stored data structure
94 */
95 static void ui_arc_listview_text_cell_data_function (GtkTreeViewColumn *col,
96 GtkCellRenderer *renderer,
97 GtkTreeModel *model,
98 GtkTreeIter *iter,
99 gpointer user_data)
100 {
101 Archive *item;
102 gchar *name;
103
104 gtk_tree_model_get(model, iter, LST_DEFARC_DATAS, &item, -1);
105
106 name = item->wording;
107
108 g_object_set(renderer, "text", name, NULL);
109 }
110
111
112
113 /*
114 **
115 */
116 static GtkWidget *ui_arc_listview_new(void)
117 {
118 GtkListStore *store;
119 GtkWidget *view;
120 GtkCellRenderer *renderer;
121 GtkTreeViewColumn *column;
122
123 //store
124 store = gtk_list_store_new (
125 NUM_LST_DEFARC,
126 G_TYPE_POINTER,
127 G_TYPE_UINT,
128 G_TYPE_BOOLEAN
129 );
130
131 //sortable
132 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), LST_DEFARC_DATAS, ui_arc_listview_compare_func, GINT_TO_POINTER(LST_DEFARC_DATAS), NULL);
133
134
135 //treeview
136 view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
137 g_object_unref(store);
138
139 /* icon column */
140 column = gtk_tree_view_column_new();
141 renderer = gtk_cell_renderer_pixbuf_new ();
142 gtk_cell_renderer_set_fixed_size(renderer, GLOBALS->lst_pixbuf_maxwidth, -1);
143 gtk_tree_view_column_pack_start(column, renderer, TRUE);
144 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_arc_listview_auto_cell_data_function, NULL, NULL);
145 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
146
147 /* text column */
148 column = gtk_tree_view_column_new();
149 renderer = gtk_cell_renderer_text_new ();
150 gtk_tree_view_column_pack_start(column, renderer, TRUE);
151 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_arc_listview_text_cell_data_function, GINT_TO_POINTER(1), NULL);
152 gtk_tree_view_append_column (GTK_TREE_VIEW(view), column);
153
154 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
155 //gtk_tree_view_set_reorderable (GTK_TREE_VIEW(view), TRUE);
156
157 return(view);
158 }
159
160
161 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
162
163
164
165 /*
166 ** add an empty new account to our temp GList and treeview
167 */
168 static void ui_arc_manage_add(GtkWidget *widget, gpointer user_data)
169 {
170 struct ui_arc_manage_data *data;
171 GtkTreeModel *model;
172 GtkTreeIter iter;
173
174 Archive *item;
175
176 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
177 DB( g_print("\n[ui_scheduled] add\n") );
178
179 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_arc));
180
181 item = da_archive_malloc();
182 item->wording = g_strdup_printf(_("(archive %d)"), g_list_length(GLOBALS->arc_list) + 1);
183 item->unit = 2;
184
185 GLOBALS->arc_list = g_list_append(GLOBALS->arc_list, item);
186
187 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
188 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
189 LST_DEFARC_DATAS, item,
190 LST_DEFARC_OLDPOS, 0,
191 -1);
192
193 gtk_tree_selection_select_iter (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc)), &iter);
194
195 data->change++;
196 }
197
198 /*
199 ** remove the selected account to our treeview and temp GList
200 */
201 static void ui_arc_manage_remove(GtkWidget *widget, gpointer user_data)
202 {
203 struct ui_arc_manage_data *data;
204 GtkTreeSelection *selection;
205 GtkTreeModel *model;
206 GtkTreeIter iter;
207 Archive *item;
208
209 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
210 DB( g_print("\n[ui_scheduled] remove (data=%p)\n", data) );
211
212 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
213 //if true there is a selected node
214 if (gtk_tree_selection_get_selected(selection, &model, &iter))
215 {
216 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
217 gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
218
219 GLOBALS->arc_list = g_list_remove(GLOBALS->arc_list, item);
220
221 data->change++;
222 //DB( g_print(" remove =%08x (pos=%d)\n", entry, g_list_index(data->tmp_list, entry) ) );
223 }
224 }
225
226
227 /*
228 ** update the archive name everytime it changes
229 */
230 static void ui_arc_manage_rename(GtkWidget *widget, gpointer user_data)
231 {
232 struct ui_arc_manage_data *data;
233 GtkTreeSelection *selection;
234 GtkTreeModel *model;
235 GtkTreeIter iter;
236 gchar *txt;
237 Archive *item;
238
239 DB( g_print("\n[ui_scheduled] rename\n") );
240
241 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
242
243 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
244 //if true there is a selected node
245 if (gtk_tree_selection_get_selected(selection, &model, &iter))
246 {
247 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
248
249 DB( g_print(" -> %s\n", item->wording) );
250
251 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_word));
252 // ignore if entry is empty
253 if (txt && *txt)
254 {
255 g_free(item->wording);
256 item->wording = g_strdup(txt);
257 }
258
259 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_arc));
260
261 }
262
263 }
264
265
266
267
268 /*
269 ** set widgets contents from the selected account
270 */
271 static void ui_arc_manage_set(GtkWidget *widget, gpointer user_data)
272 {
273 struct ui_arc_manage_data *data;
274 GtkTreeSelection *selection;
275 GtkTreeModel *model;
276 GtkTreeIter iter;
277
278 Archive *item;
279
280 DB( g_print("\n[ui_scheduled] set\n") );
281
282 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
283
284 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc));
285 //if true there is a selected node
286 if (gtk_tree_selection_get_selected(selection, &model, &iter))
287 {
288 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &item, -1);
289
290 g_signal_handler_block(data->ST_word, data->handler_id[HID_ARC_MEMO]);
291 gtk_entry_set_text(GTK_ENTRY(data->ST_word), item->wording);
292 g_signal_handler_unblock(data->ST_word, data->handler_id[HID_ARC_MEMO]);
293
294 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), item->amount);
295
296 g_signal_handler_block(data->CM_valid, data->handler_id[HID_ARC_VALID]);
297 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_valid), (item->flags & OF_VALID) ? 1 : 0);
298 g_signal_handler_unblock(data->CM_valid, data->handler_id[HID_ARC_VALID]);
299
300 g_signal_handler_block(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
301 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_remind), (item->flags & OF_REMIND) ? 1 : 0);
302 g_signal_handler_unblock(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
303
304 gtk_combo_box_set_active(GTK_COMBO_BOX(data->NU_mode), item->paymode);
305
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_cheque), (item->flags & OF_CHEQ2) ? 1 : 0);
307
308 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), item->kcat);
309
310 DB( g_print(" -> set payee %d\n", item->kpay) );
311 ui_pay_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_pay), item->kpay);
312
313 DB( g_print(" -> PO_acc %d\n", item->kacc) );
314 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_acc), item->kacc);
315
316 DB( g_print(" -> PO_accto %d\n", item->kxferacc) );
317 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_accto), item->kxferacc);
318
319 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_auto), (item->flags & OF_AUTO) ? 1 : 0);
320
321 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NB_every), item->every);
322
323 gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_unit), item->unit);
324
325 gtk_dateentry_set_date(GTK_DATE_ENTRY(data->PO_next), item->nextdate);
326
327 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_limit), (item->flags & OF_LIMIT) ? 1 : 0);
328
329
330 DB( g_print("nb_limit = %d %g\n", item->limit, (gdouble)item->limit) );
331
332 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->NB_limit), (gdouble)item->limit);
333
334 radio_set_active(GTK_CONTAINER(data->CY_weekend), item->weekend);
335
336 }
337
338 }
339
340 /*
341 ** get widgets contents to the selected account
342 */
343 static void ui_arc_manage_getlast(struct ui_arc_manage_data *data)
344 {
345 gchar *txt;
346 gboolean bool;
347 gdouble value;
348 gint active;
349 Archive *item;
350
351 DB( g_print("\n[ui_scheduled] getlast\n") );
352
353 item = data->lastarcitem;
354
355 if( item != NULL )
356 {
357 DB( g_print(" -> %s\n", item->wording) );
358
359 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_word));
360 // ignore if entry is empty
361 if (txt && *txt)
362 {
363 g_free(item->wording);
364 item->wording = g_strdup(txt);
365 }
366
367 gtk_tree_view_columns_autosize (GTK_TREE_VIEW(data->LV_arc));
368
369 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
370 item->amount = value;
371
372 item->flags = 0;
373
374 active = item->amount > 0 ? TRUE : FALSE;
375 //active = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_amount));
376 if(active == 1) item->flags |= OF_INCOME;
377
378 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cheque));
379 if(bool) item->flags |= OF_CHEQ2;
380
381 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_valid));
382 if(bool) item->flags |= OF_VALID;
383
384 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_remind));
385 if(bool == 1) item->flags |= OF_REMIND;
386
387 item->paymode = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
388 item->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_grp));
389 item->kpay = ui_pay_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_pay));
390 item->kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
391 item->kxferacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
392
393 DB( g_print(" -> PO_acc %d\n", item->kacc) );
394 DB( g_print(" -> PO_accto %d\n", item->kxferacc) );
395
396 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_auto));
397 if(bool) item->flags |= OF_AUTO;
398
399 item->every = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->NB_every));
400 item->unit = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_unit));
401 item->nextdate = gtk_dateentry_get_date(GTK_DATE_ENTRY(data->PO_next));
402
403 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_limit));
404 if(bool) item->flags |= OF_LIMIT;
405
406 item->limit = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->NB_limit));
407
408 item->weekend = radio_get_active(GTK_CONTAINER(data->CY_weekend));
409
410 data->change++;
411 }
412 }
413
414
415 static void ui_arc_manage_update_accto(GtkWidget *widget, gpointer user_data)
416 {
417 struct ui_arc_manage_data *data;
418 guint kacc, kdst;
419
420 DB( g_print("\n\n[ui_scheduled] update accto\n") );
421
422 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
423
424 kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
425 kdst = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
426
427 DB( g_print(" ksrc=%d, kdst=%d\n", kacc, kdst) );
428
429 ui_acc_comboboxentry_populate_except(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, kacc, ACC_LST_INSERT_NORMAL);
430
431 if( (kacc == 0) || (kacc == kdst) )
432 {
433 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_accto), 0);
434 }
435
436 }
437
438
439 /*
440 **
441 */
442 static void ui_arc_manage_paymode(GtkWidget *widget, gpointer user_data)
443 {
444 struct ui_arc_manage_data *data;
445 gint payment;
446 gint page;
447 gboolean sensitive;
448
449 DB( g_print("\n[ui_scheduled] paymode\n") );
450
451 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
452
453 DB( g_print("\n[ui_scheduled] widget=%p, data=%p\n", widget, data) );
454
455
456 payment = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
457 page = 0;
458
459 if(payment == PAYMODE_CHECK)
460 page = 1;
461
462 sensitive = page == 1 ? TRUE : FALSE;
463 hb_widget_visible(data->CM_cheque, sensitive);
464
465 if(payment == PAYMODE_INTXFER)
466 {
467 page = 2;
468 ui_arc_manage_update_accto(widget, user_data);
469 }
470
471 DB( g_print(" payment: %d, page: %d\n", payment, page) );
472
473 sensitive = page == 2 ? TRUE : FALSE;
474 hb_widget_visible(data->LB_accto, sensitive);
475 hb_widget_visible(data->PO_accto, sensitive);
476
477 }
478
479 /*
480 **
481 */
482 static void ui_arc_manage_scheduled(GtkWidget *widget, gpointer user_data)
483 {
484 struct ui_arc_manage_data *data;
485 gboolean sensitive;
486
487 DB( g_print("\n[ui_scheduled] scheduled\n") );
488
489 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
490
491 //scheduled
492 sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_auto)) ? TRUE : FALSE;
493 gtk_widget_set_sensitive(data->PO_next, sensitive);
494 gtk_widget_set_sensitive(data->NB_every, sensitive);
495 gtk_widget_set_sensitive(data->CY_unit, sensitive);
496 gtk_widget_set_sensitive(data->CM_limit, sensitive);
497 gtk_widget_set_sensitive(data->CY_weekend, sensitive);
498
499 sensitive = (sensitive == TRUE) ? gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_limit)) : sensitive;
500 gtk_widget_set_sensitive(data->NB_limit, sensitive);
501
502
503 }
504
505
506 /*
507 ** update the widgets status and contents from action/selection value
508 */
509 static void ui_arc_manage_update(GtkWidget *widget, gpointer user_data)
510 {
511 struct ui_arc_manage_data *data;
512 GtkTreeModel *model;
513 GtkTreeIter iter;
514 gboolean selected, sensitive;
515 Archive *arcitem;
516
517
518 DB( g_print("\n[ui_scheduled] update\n") );
519
520 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
521 //window = gtk_widget_get_ancestor(GTK_WIDGET(treeview), GTK_TYPE_WINDOW);
522 //DB( g_print("\n[ui_scheduled] widget=%08lx, window=%08lx, inst_data=%08lx\n", treeview, window, data) );
523
524 //if true there is a selected node
525 selected = gtk_tree_selection_get_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(data->LV_arc)), &model, &iter);
526
527 DB( g_print(" selected = %d\n", selected) );
528
529 sensitive = (selected == TRUE) ? TRUE : FALSE;
530 gtk_widget_set_sensitive(data->PO_pay, sensitive);
531 gtk_widget_set_sensitive(data->ST_word, sensitive);
532 gtk_widget_set_sensitive(data->ST_amount, sensitive);
533 gtk_widget_set_sensitive(data->BT_amount, sensitive);
534 //gtk_widget_set_sensitive(data->BT_split, sensitive);
535
536 gtk_widget_set_sensitive(data->CM_valid, sensitive);
537 gtk_widget_set_sensitive(data->CM_remind, sensitive);
538
539 gtk_widget_set_sensitive(data->CM_cheque, sensitive);
540
541 gtk_widget_set_sensitive(data->NU_mode, sensitive);
542 gtk_widget_set_sensitive(data->PO_grp, sensitive);
543 gtk_widget_set_sensitive(data->PO_acc, sensitive);
544 gtk_widget_set_sensitive(data->PO_accto, sensitive);
545
546 gtk_widget_set_sensitive(data->CM_auto, sensitive);
547
548 gtk_widget_set_sensitive(data->BT_rem, sensitive);
549
550 if(selected)
551 {
552 gtk_tree_model_get(model, &iter, LST_DEFARC_DATAS, &arcitem, -1);
553
554 if(data->lastarcitem != NULL && arcitem != data->lastarcitem)
555 {
556 DB( g_print(" -> should do a get for last selected (%s)\n", data->lastarcitem->wording) );
557 ui_arc_manage_getlast(data);
558 }
559 data->lastarcitem = arcitem;
560
561 DB( g_print(" - call set\n") );
562 ui_arc_manage_set(widget, NULL);
563 }
564 else
565 {
566 data->lastarcitem = NULL;
567 }
568
569 DB( g_print(" - call scheduled\n") );
570 ui_arc_manage_scheduled(widget, NULL);
571 DB( g_print(" - call paymode\n") );
572 ui_arc_manage_paymode(widget,NULL);
573
574
575 }
576
577
578 static void ui_arc_manage_togglestatus(GtkWidget *widget, gpointer user_data)
579 {
580 struct ui_arc_manage_data *data;
581
582 DB( g_print("\n[ui_scheduled] togglestatus\n") );
583
584 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
585
586 //valid & remind are exclusive
587 switch( GPOINTER_TO_INT(user_data) )
588 {
589 case HID_ARC_VALID:
590 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_valid)) )
591 {
592 g_signal_handler_block(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_remind), FALSE);
594 g_signal_handler_unblock(data->CM_remind, data->handler_id[HID_ARC_REMIND]);
595 }
596 break;
597
598 case HID_ARC_REMIND:
599 if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_remind)) )
600 {
601 g_signal_handler_block(data->CM_valid, data->handler_id[HID_ARC_VALID]);
602 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_valid), FALSE);
603 g_signal_handler_unblock(data->CM_valid, data->handler_id[HID_ARC_VALID]);
604 }
605 }
606
607
608
609
610 }
611
612
613
614 /*
615 **
616 */
617 static void ui_arc_manage_toggleamount(GtkWidget *widget, gpointer user_data)
618 {
619 struct ui_arc_manage_data *data;
620 gdouble value;
621
622 DB( g_print("\n[ui_scheduled] toggleamount\n") );
623
624 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
625
626 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
627 value *= -1;
628 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), value);
629
630
631 /*
632 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
633 type = gtk_widget_get_sensitive(data->CY_amount);
634
635 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), value * type);
636 */
637 }
638
639
640 /*
641 **
642 */
643 static void ui_arc_manage_selection(GtkTreeSelection *treeselection, gpointer user_data)
644 {
645 DB( g_print("\n[ui_scheduled] selection\n") );
646
647 DB( g_print(" - call update\n") );
648 ui_arc_manage_update(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), NULL);
649 }
650
651 /*
652 **
653 */
654 static gboolean ui_arc_manage_cleanup(struct ui_arc_manage_data *data, gint result)
655 {
656 gboolean doupdate = FALSE;
657
658 DB( g_print("\n[ui_scheduled] cleanup\n") );
659
660
661 if(data->lastarcitem != NULL)
662 {
663 DB( g_print(" -> should do a get for last selected (%s)\n", data->lastarcitem->wording) );
664 ui_arc_manage_getlast(data);
665 }
666
667 GLOBALS->arc_list = da_archive_sort(GLOBALS->arc_list);
668
669 GLOBALS->changes_count += data->change;
670
671 return doupdate;
672 }
673
674 /*
675 **
676 */
677 static void ui_arc_manage_setup(struct ui_arc_manage_data *data)
678 {
679 GtkTreeModel *model;
680 GtkTreeIter iter;
681 GList *list;
682 gint i;
683
684 DB( g_print("\n[ui_scheduled] setup\n") );
685
686 //init GList
687 data->tmp_list = NULL; //hb-glist_clone_list(GLOBALS->arc_list, sizeof(struct _Archive));
688 data->change = 0;
689 data->lastarcitem = NULL;
690
691 //hb-glist_populate_treeview(data->tmp_list, data->LV_arc, LST_DEFARC_DATAS, LST_DEFARC_OLDPOS);
692
693 //insert all glist item into treeview
694 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_arc));
695 i=0;
696 list = g_list_first(GLOBALS->arc_list);
697 while (list != NULL)
698 {
699 Archive *item = list->data;
700
701 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
702 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
703 LST_DEFARC_DATAS, item, //data struct
704 LST_DEFARC_OLDPOS, i, //oldpos
705 -1);
706
707 //DB( g_print(" populate_treeview: %d %08x\n", i, list->data) );
708
709 i++; list = g_list_next(list);
710 }
711
712 DB( g_print(" - populate boxentries\n") );
713
714 ui_pay_comboboxentry_populate(GTK_COMBO_BOX(data->PO_pay) , GLOBALS->h_pay);
715 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_grp) , GLOBALS->h_cat);
716 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_acc) , GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
717 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
718
719
720 }
721
722
723 static GtkWidget *ui_arc_manage_create_left_txn(struct ui_arc_manage_data *data)
724 {
725 GtkWidget *table, *hbox, *label, *widget;
726 gint row;
727
728 table = gtk_table_new (2, 3, FALSE);
729 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
730 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
731
732 row = 0;
733 label = make_label(_("Transaction detail"), 0.0, 0.5);
734 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
735 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
736
737 row++;
738 label = make_label(_("_Amount:"), 0.0, 0.5);
739 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
740
741 hbox = gtk_hbox_new (FALSE, 0);
742
743 widget = gtk_button_new_with_label("+/-");
744 data->BT_amount = widget;
745 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
746 gtk_widget_set_tooltip_text(widget, _("Toggle amount sign"));
747
748 widget = make_amount(label);
749 data->ST_amount = widget;
750 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
751
752 gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
753
754 row++;
755 label = make_label(_("Pay_ment:"), 0.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 = make_paymode(label);
758 data->NU_mode = widget;
759 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
760
761 row++;
762 widget = gtk_check_button_new_with_mnemonic(_("Of notebook _2"));
763 data->CM_cheque = widget;
764 gtk_table_attach (GTK_TABLE (table), widget, 1, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
765
766 /* info should be here some day */
767
768 row++;
769 label = make_label(_("A_ccount:"), 0.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 = ui_acc_comboboxentry_new(label);
772 data->PO_acc = widget;
773 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
774
775 row++;
776 label = make_label(_("_To account:"), 0.0, 0.5);
777 data->LB_accto = label;
778 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
779 widget = ui_acc_comboboxentry_new(label);
780 data->PO_accto = widget;
781 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
782
783 return table;
784 }
785
786
787 static GtkWidget *ui_arc_manage_create_right_txn(struct ui_arc_manage_data *data)
788 {
789 GtkWidget *table, *label, *widget;
790 gint row;
791
792 table = gtk_table_new (2, 3, FALSE);
793 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
794 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
795
796 row = 0;
797 // keep this to avoid a shift
798 label = make_label(NULL, 0.0, 0.5);
799 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
800 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
801
802 row++;
803 label = make_label(_("_Payee:"), 0.0, 0.5);
804 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
805 widget = ui_pay_comboboxentry_new(label);
806 data->PO_pay = widget;
807 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
808
809 row++;
810 label = make_label(_("_Category:"), 0.0, 0.5);
811 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
812 widget = ui_cat_comboboxentry_new(label);
813 data->PO_grp = widget;
814 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
815
816 row++;
817 label = make_label(_("_Memo:"), 0.0, 0.5);
818 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
819 widget = make_string(label);
820 data->ST_word = widget;
821 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
822
823 /* tags should be here some day */
824
825 row++;
826 widget = gtk_check_button_new_with_mnemonic (_("_Reconciled"));
827 data->CM_valid = widget;
828 gtk_table_attach (GTK_TABLE (table), widget, 1, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
829
830 row++;
831 widget = gtk_check_button_new_with_mnemonic (_("Re_mind"));
832 data->CM_remind = widget;
833 gtk_table_attach (GTK_TABLE (table), widget, 1, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
834
835
836 return table;
837 }
838
839
840 static GtkWidget *ui_arc_manage_create_scheduling(struct ui_arc_manage_data *data)
841 {
842 GtkWidget *table, *hbox, *label, *widget;
843 gint row;
844
845 table = gtk_table_new (2, 3, FALSE);
846 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
847 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
848
849 row = 0;
850 label = make_label(_("Scheduled insertion"), 0.0, 0.5);
851 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
852 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 3, row, row+1);
853
854 row++;
855 widget = gtk_check_button_new_with_mnemonic(_("_Activate"));
856 data->CM_auto = widget;
857 gtk_table_attach (GTK_TABLE (table), widget, 1, 3, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
858
859 row++;
860 label = make_label(_("Next _date:"), 0.0, 0.5);
861 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
862 widget = gtk_dateentry_new();
863 data->PO_next = widget;
864 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
865
866 row++;
867 label = make_label(_("Ever_y:"), 0.0, 0.5);
868 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
869
870 hbox = gtk_hbox_new(FALSE, HB_BOX_SPACING);
871 gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
872 widget = make_numeric(label, 1, 100);
873 data->NB_every = widget;
874 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
875 //label = gtk_label_new_with_mnemonic (_("_Unit:"));
876 //gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
877 widget = make_cycle(label, CYA_UNIT);
878 data->CY_unit = widget;
879 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
880
881 row++;
882 label = make_label(_("Week end:"), 0.0, 0.5);
883 gtk_table_attach (GTK_TABLE (table), label, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
884
885 widget = make_radio(NULL, CYA_SCHED_WEEKEND, GTK_ORIENTATION_HORIZONTAL);
886 data->CY_weekend = widget;
887 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
888
889 row++;
890 hbox = gtk_hbox_new(FALSE, HB_BOX_SPACING);
891 gtk_table_attach (GTK_TABLE (table), hbox, 1, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
892
893 widget = gtk_check_button_new_with_mnemonic(_("_Stop after:"));
894 data->CM_limit = widget;
895 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
896
897 widget = make_numeric(label, 1, 366);
898 data->NB_limit = widget;
899 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
900
901 label = gtk_label_new_with_mnemonic (_("posts"));
902 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
903
904 return table;
905 }
906
907
908 GtkWidget *ui_arc_manage_dialog (void)
909 {
910 struct ui_arc_manage_data data;
911 GtkWidget *window, *content, *mainbox, *hbox, *vbox, *table;
912 GtkWidget *widget, *treeview, *scrollwin;
913 GtkWidget *alignment, *hpaned;
914 gint row;
915
916 window = gtk_dialog_new_with_buttons (_("Manage scheduled/template transactions"),
917 GTK_WINDOW(GLOBALS->mainwindow),
918 0,
919 GTK_STOCK_CLOSE,
920 GTK_RESPONSE_ACCEPT,
921 NULL);
922
923 //homebank_window_set_icon_from_file(GTK_WINDOW (window), "archive.svg");
924 gtk_window_set_icon_name(GTK_WINDOW (window), HB_STOCK_ARCHIVE);
925
926 //store our window private data
927 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)&data);
928 DB( g_print("\n[ui_scheduled] window=%p, inst_data=%p\n", window, &data) );
929
930 //window contents
931 content = gtk_dialog_get_content_area(GTK_DIALOG (window));
932 mainbox = gtk_hbox_new (FALSE, HB_BOX_SPACING);
933 gtk_box_pack_start (GTK_BOX (content), mainbox, TRUE, TRUE, 0);
934 gtk_container_set_border_width (GTK_CONTAINER(mainbox), HB_MAINBOX_SPACING);
935
936 hpaned = gtk_hpaned_new();
937 gtk_box_pack_start (GTK_BOX (mainbox), hpaned, TRUE, TRUE, 0);
938
939 /* left area */
940 table = gtk_table_new (2, 2, FALSE);
941 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
942 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
943 gtk_paned_pack1 (GTK_PANED(hpaned), table, FALSE, FALSE);
944
945 // listview
946 row = 0;
947 scrollwin = gtk_scrolled_window_new(NULL,NULL);
948 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
949 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
950 treeview = (GtkWidget *)ui_arc_listview_new();
951 data.LV_arc = treeview;
952 gtk_widget_set_size_request(treeview, HB_MINWIDTH_LIST, -1);
953 gtk_container_add(GTK_CONTAINER(scrollwin), treeview);
954 gtk_table_attach_defaults (GTK_TABLE (table), scrollwin, 0, 2, row, row+1);
955
956 // tools buttons
957 row++;
958 widget = gtk_button_new_from_stock(GTK_STOCK_ADD);
959 data.BT_add = widget;
960 gtk_table_attach (GTK_TABLE (table), widget, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (0), 0, 0);
961 widget = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
962 data.BT_rem = widget;
963 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (0), 0, 0);
964
965 /* right area */
966 vbox = gtk_vbox_new (FALSE, HB_BOX_SPACING);
967 //gtk_box_pack_start (GTK_BOX (mainbox), vbox, TRUE, TRUE, 0);
968 gtk_paned_pack2 (GTK_PANED(hpaned), vbox, FALSE, FALSE);
969
970 hbox = gtk_hbox_new (TRUE, HB_HSPACE_SPACING);
971 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
972
973
974 widget = ui_arc_manage_create_left_txn(&data);
975 // gtk_alignment_new(xalign, yalign, xscale, yscale)
976 alignment = gtk_alignment_new(0.0, 0.0, 1.0, 0.0);
977 gtk_container_add(GTK_CONTAINER(alignment), widget);
978 gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
979
980 widget = ui_arc_manage_create_right_txn(&data);
981 // gtk_alignment_new(xalign, yalign, xscale, yscale)
982 alignment = gtk_alignment_new(0.0, 0.0, 1.0, 0.0);
983 gtk_container_add(GTK_CONTAINER(alignment), widget);
984 gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
985
986 /* sheduling */
987 widget = ui_arc_manage_create_scheduling(&data);
988 // gtk_alignment_new(xalign, yalign, xscale, yscale)
989 alignment = gtk_alignment_new(0.0, 0.0, 0.20, 0.0);
990 gtk_container_add(GTK_CONTAINER(alignment), widget);
991 gtk_box_pack_start (GTK_BOX (vbox), alignment, TRUE, TRUE, 0);
992
993 /* set default periodicity to month */
994 //todo: move elsewhere
995 gtk_combo_box_set_active(GTK_COMBO_BOX(data.CY_unit), 2);
996
997
998
999 //connect all our signals
1000 g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
1001
1002 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data.LV_arc)), "changed", G_CALLBACK (ui_arc_manage_selection), NULL);
1003 g_signal_connect (G_OBJECT (data.BT_amount), "clicked", G_CALLBACK (ui_arc_manage_toggleamount), NULL);
1004
1005 g_signal_connect (G_OBJECT (data.BT_add), "clicked", G_CALLBACK (ui_arc_manage_add), NULL);
1006 g_signal_connect (G_OBJECT (data.BT_rem), "clicked", G_CALLBACK (ui_arc_manage_remove), NULL);
1007
1008 data.handler_id[HID_ARC_MEMO] = g_signal_connect (G_OBJECT (data.ST_word), "changed", G_CALLBACK (ui_arc_manage_rename), NULL);
1009 g_signal_connect (data.NU_mode, "changed", G_CALLBACK (ui_arc_manage_paymode), NULL);
1010 g_signal_connect (data.PO_acc, "changed", G_CALLBACK (ui_arc_manage_update_accto), NULL);
1011 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));
1012 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));
1013
1014 g_signal_connect (data.CM_auto, "toggled", G_CALLBACK (ui_arc_manage_scheduled), NULL);
1015 g_signal_connect (data.CM_limit, "toggled", G_CALLBACK (ui_arc_manage_scheduled), NULL);
1016
1017 //setup, init and show window
1018 ui_arc_manage_setup(&data);
1019 ui_arc_manage_update(data.LV_arc, NULL);
1020
1021 gtk_widget_show_all (window);
1022
1023 //wait for the user
1024 gint result = gtk_dialog_run (GTK_DIALOG (window));
1025
1026 switch (result)
1027 {
1028 case GTK_RESPONSE_ACCEPT:
1029 //do_application_specific_something ();
1030 break;
1031 default:
1032 //do_nothing_since_dialog_was_cancelled ();
1033 break;
1034 }
1035
1036 // cleanup and destroy
1037 ui_arc_manage_cleanup(&data, result);
1038 gtk_widget_destroy (window);
1039
1040 return NULL;
1041 }
1042
1043
This page took 0.109252 seconds and 4 git commands to generate.