add gitignore
[chaz/homebank] / src / ui-transaction.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 ofdeftransaction_amountchanged
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-transaction.h"
23 #include "hb-transaction.h"
24 #include "gtk-dateentry.h"
25 #include "ui-payee.h"
26 #include "ui-category.h"
27 #include "ui-account.h"
28
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 extern struct Preferences *PREFS;
44
45
46 extern gchar *CYA_TYPE[];
47
48 gchar *CYA_OPERATION[] = {
49 N_("Add transaction"),
50 N_("Inherit transaction"),
51 N_("Modify transaction")
52 };
53
54 static void deftransaction_update(GtkWidget *widget, gpointer user_data);
55
56 #define GTK_RESPONSE_SPLIT_SUM 10880
57 #define GTK_RESPONSE_SPLIT_REM 10888
58
59 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
60
61 static void ui_txn_split_dialog_line_sensitive(guint line, gboolean sensitive, gpointer user_data)
62 {
63 struct ui_txn_split_dialog_data *data = user_data;
64
65 if( line > TXN_MAX_SPLIT )
66 return;
67
68 if( line == 0 ) // line 0 always active !
69 sensitive = TRUE;
70
71
72 gtk_widget_set_sensitive(data->PO_cat[line], sensitive);
73 gtk_widget_set_sensitive(data->ST_amount[line], sensitive);
74 gtk_widget_set_sensitive(data->ST_memo[line], sensitive);
75 if(data->BT_rem[line])
76 gtk_widget_set_sensitive(data->BT_rem[line], sensitive);
77 if(data->BT_add[line])
78 gtk_widget_set_sensitive(data->BT_add[line], sensitive);
79
80 if(sensitive == FALSE)
81 {
82 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_cat[line]), 0);
83 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount[line]), 0.0);
84 gtk_entry_set_text(GTK_ENTRY(data->ST_memo[line]), "");
85 }
86
87 if(sensitive == TRUE)
88 data->activeline = line;
89
90 }
91
92
93 static void ui_txn_split_dialog_compute(GtkWidget *widget, gpointer user_data)
94 {
95 struct ui_txn_split_dialog_data *data = user_data;
96 gint i, count, nbvalid;
97 //gint j;
98 gchar buf[48];
99 gboolean sensitive, active;
100 //guint32 cat[TXN_MAX_SPLIT];
101 gdouble amt[TXN_MAX_SPLIT];
102 gboolean valid[TXN_MAX_SPLIT];
103
104 DB( g_print("\n(ui_txn_split_dialog_compute)\n") );
105
106 data->sumsplit = data->remsplit = 0.0;
107 nbvalid = 0;
108 for(i=0;i<TXN_MAX_SPLIT;i++)
109 {
110 active = gtk_widget_get_sensitive(data->PO_cat[i]);
111 if(!active) break;
112
113 //cat[i] = ui_cat_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_cat[i]));
114 amt[i] = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount[i]));
115 data->sumsplit += amt[i];
116 valid[i] = TRUE;
117
118 if(!amt[i])
119 valid[i] = FALSE;
120
121 /* disable use same category several time
122 for(j=0;j<i;j++)
123 {
124 if(i == j) continue;
125 if( (cat[i] == cat[j]) )
126 {
127 valid[i] = FALSE;
128 break;
129 }
130 }*/
131 DB( g_print("- split %d : act.=%d val.=%d : amt=%.2f\n", i, active, valid[i], amt[i]) );
132
133 if(valid[i])
134 nbvalid++;
135
136 DB( g_print("- nbsplit %d\n", data->nbsplit) );
137
138 if(data->nbsplit == i)
139 {
140 DB( g_print("- set last split %d\n", i) );
141
142 if(data->BT_add[i])
143 gtk_widget_set_sensitive(data->BT_add[i], valid[i]);
144
145 if(data->BT_rem[i])
146 gtk_widget_set_sensitive(data->BT_rem[i], TRUE);
147 }
148 else
149 {
150 DB( g_print("- set off to %d\n", i) );
151
152 if(data->BT_add[i])
153 gtk_widget_set_sensitive(data->BT_add[i], FALSE);
154
155 if(data->BT_rem[i])
156 gtk_widget_set_sensitive(data->BT_rem[i], FALSE);
157 }
158 }
159
160 count = i;
161 DB( g_print("- count=%d, nbvalid=%d\n", count, nbvalid ) );
162
163
164 if(data->splittype == TXN_SPLIT_AMOUNT)
165 {
166 data->remsplit = data->amount - data->sumsplit;
167 }
168
169 //rules validation
170 sensitive = ((count == nbvalid) && (count > 1)) ? TRUE : FALSE;
171 if(data->splittype == TXN_SPLIT_NEW)
172 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->dialog), GTK_RESPONSE_SPLIT_SUM, sensitive);
173
174 if(data->splittype == TXN_SPLIT_AMOUNT)
175 {
176 sensitive = arrondi(data->remsplit, 2) != 0.0 ? FALSE : sensitive;
177 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->dialog), GTK_RESPONSE_ACCEPT, sensitive);
178
179 if(!data->remsplit)
180 g_sprintf(buf, "----");
181 else
182 g_snprintf(buf, 48, "%.2f", data->remsplit);
183
184 gtk_label_set_label(GTK_LABEL(data->LB_remain), buf);
185
186 g_snprintf(buf, 48, "%.2f", data->amount);
187 gtk_label_set_label(GTK_LABEL(data->LB_txnamount), buf);
188 }
189
190 g_snprintf(buf, 48, "%.2f", data->sumsplit);
191 gtk_label_set_text(GTK_LABEL(data->LB_sumsplit), buf);
192
193 }
194
195
196 static void ui_txn_split_dialog_inactiveline(GtkWidget *widget, gpointer user_data)
197 {
198 struct ui_txn_split_dialog_data *data;
199 gint line;
200
201 DB( g_print("\n(ui_txn_split_dialog_inactiveline)\n") );
202
203 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
204
205 if(data->nbsplit <= 0) //1st split always active
206 return;
207
208 line = data->nbsplit--;
209
210 DB( g_print("- nbsplit:%d off:%d\n", data->nbsplit, line) );
211
212 ui_txn_split_dialog_line_sensitive(line, FALSE, data);
213 ui_txn_split_dialog_compute(widget, data);
214 }
215
216
217 static void ui_txn_split_dialog_activeline(GtkWidget *widget, gpointer user_data)
218 {
219 struct ui_txn_split_dialog_data *data;
220 gint line;
221
222 DB( g_print("\n(ui_txn_split_dialog_activeline)\n") );
223
224 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
225
226 line = data->nbsplit;
227 if(line >= (TXN_MAX_SPLIT-1)) //bound
228 return;
229
230 line = ++data->nbsplit;
231
232 DB( g_print("- nbsplit:%d off:%d\n", data->nbsplit-1, line) );
233
234
235 ui_txn_split_dialog_line_sensitive(line, TRUE, data);
236
237 if(data->splittype == TXN_SPLIT_AMOUNT)
238 {
239 DB( g_print("- line %d :: affect remain\n", line) );
240 g_signal_handler_block(data->ST_amount[line], data->handler_id[line]);
241 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount[line]), data->remsplit);
242 g_signal_handler_unblock(data->ST_amount[line], data->handler_id[line]);
243 }
244
245 ui_txn_split_dialog_compute(widget, data);
246 }
247
248
249 static void ui_txn_split_dialog_get(struct ui_txn_split_dialog_data *data)
250 {
251 guint i;
252 Split *split;
253 guint32 kcat;
254 gchar *memo;
255 gdouble amount;
256
257 DB( g_print("(ui_txn_split_dialog_get)\n") );
258
259 da_transaction_splits_free(data->ope);
260
261 for(i=0;i<TXN_MAX_SPLIT;i++)
262 {
263 kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_cat[i]));
264 memo = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_memo[i]));
265 amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount[i]));
266
267 if(amount)
268 {
269 split = da_split_new(kcat, amount, memo);
270
271 DB( g_print("- get split %d : %d, %.2f, %s\n", i, split->kcat, split->amount, split->memo) );
272
273 da_transaction_splits_append (data->ope, split);
274 }
275 }
276 }
277
278
279 static void ui_txn_split_dialog_set(struct ui_txn_split_dialog_data *data)
280 {
281 guint count, i;
282 Split *split;
283 gchar *txt;
284
285 DB( g_print("(ui_txn_split_dialog_set)\n") );
286
287 for(i=0;i<TXN_MAX_SPLIT;i++)
288 {
289 ui_txn_split_dialog_line_sensitive(i, FALSE, data);
290 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_cat[i]), GLOBALS->h_cat);
291 //#1258821
292 //if( data->splittype == TXN_SPLIT_AMOUNT )
293 //{
294 //if(data->amount > 0.0)
295 // gtk_spin_button_set_range(GTK_SPIN_BUTTON(data->ST_amount[i]), 0.0, G_MAXDOUBLE);
296 //else
297 // gtk_spin_button_set_range(GTK_SPIN_BUTTON(data->ST_amount[i]), -G_MAXDOUBLE, 0.0);
298 //}
299 }
300
301
302 count = da_transaction_splits_count(data->ope);
303 data->nbsplit = count > 1 ? count-1 : 0;
304
305 DB( g_print("- count = %d\n", count) );
306
307
308 for(i=0;i<count;i++)
309 {
310 split = data->ope->splits[i];
311
312 DB( g_print("- set split %d : %d, %.2f, %s\n", i, split->kcat, split->amount, split->memo) );
313
314 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_cat[i]), split->kcat);
315 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount[i]), split->amount);
316 txt = (split->memo != NULL) ? split->memo : "";
317 gtk_entry_set_text(GTK_ENTRY(data->ST_memo[i]), txt);
318 ui_txn_split_dialog_line_sensitive(i, TRUE, data);
319 }
320
321 }
322
323
324
325
326 static GtkWidget *ui_txn_split_dialog (GtkWidget *parent, Transaction *ope, gdouble amount)
327 {
328 struct ui_txn_split_dialog_data data;
329 GtkWidget *dialog, *content, *mainvbox, *label;
330 GtkWidget *table, *widget;
331 gint row, i;
332
333
334 dialog = gtk_dialog_new_with_buttons (_("Transaction split"),
335 GTK_WINDOW(parent),
336 0,
337 GTK_STOCK_CANCEL,
338 GTK_RESPONSE_CANCEL,
339 NULL);
340
341 data.dialog = dialog;
342 data.ope = ope;
343 data.amount = amount;
344 data.splittype = amount ? TXN_SPLIT_AMOUNT : TXN_SPLIT_NEW;
345
346 //homebank_window_set_icon_from_file(GTK_WINDOW (dialog), "curee.svg");
347 //gtk_window_set_icon_name(GTK_WINDOW (dialog), HB_STOCK_CURRENCY);
348
349 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_REMOVE, GTK_RESPONSE_SPLIT_REM);
350
351 /* sum button must appear only when new split add */
352 //#1258821
353 //if(data.splittype == TXN_SPLIT_NEW)
354 gtk_dialog_add_button(GTK_DIALOG(dialog), _("Sum"), GTK_RESPONSE_SPLIT_SUM);
355
356
357 if(data.splittype == TXN_SPLIT_AMOUNT)
358 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
359
360 //store our dialog private data
361 g_object_set_data(G_OBJECT(dialog), "inst_data", (gpointer)&data);
362 DB( g_print("(ui_txn_split_dialog) dialog=%p, inst_data=%p\n", dialog, &data) );
363
364 g_signal_connect (dialog, "destroy",
365 G_CALLBACK (gtk_widget_destroyed), &dialog);
366
367 //dialog contents
368 content = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
369 mainvbox = gtk_vbox_new (FALSE, HB_BOX_SPACING);
370 gtk_box_pack_start (GTK_BOX (content), mainvbox, TRUE, TRUE, 0);
371 gtk_container_set_border_width (GTK_CONTAINER(mainvbox), HB_MAINBOX_SPACING);
372
373
374 table = gtk_table_new (TXN_MAX_SPLIT, 5, FALSE);
375 //gtk_container_set_border_width (GTK_CONTAINER (table), SP_BORDER);
376 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING/2);
377 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING/2);
378 gtk_box_pack_start (GTK_BOX (mainvbox), table, TRUE, TRUE, 0);
379
380 row = 0;
381 label = gtk_label_new(_("Category"));
382 gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1);
383 gtk_table_attach (GTK_TABLE (table), label, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
384
385 label = gtk_label_new(_("Memo"));
386 gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1);
387 gtk_table_attach (GTK_TABLE (table), label, 3, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
388
389 label = gtk_label_new(_("Amount"));
390 gimp_label_set_attributes (GTK_LABEL (label), PANGO_ATTR_SCALE, PANGO_SCALE_SMALL, -1);
391 gtk_table_attach (GTK_TABLE (table), label, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
392
393 for(i=0;i<TXN_MAX_SPLIT;i++)
394 {
395 row++;
396
397 data.BT_rem[i] = NULL;
398 data.BT_add[i] = NULL;
399
400 if(i > 0)
401 {
402 widget = gtk_button_new_with_label ("-");
403 data.BT_rem[i] = widget;
404 gtk_table_attach (GTK_TABLE (table), widget, 0, 1, row, row+1, (GtkAttachOptions) (0), (GtkAttachOptions) (0), 0, 0);
405 }
406
407 if( (i < (TXN_MAX_SPLIT-1)) )
408 {
409 widget = gtk_button_new_with_label ("+");
410 data.BT_add[i] = widget;
411 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (0), (GtkAttachOptions) (0), 0, 0);
412 }
413
414 widget = ui_cat_comboboxentry_new(NULL);
415 gtk_widget_set_size_request(widget, 180, -1);
416 data.PO_cat[i] = widget;
417 gtk_table_attach (GTK_TABLE (table), widget, 2, 3, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
418
419 widget = make_string(NULL);
420 gtk_widget_set_size_request(widget, 180, -1);
421 data.ST_memo[i] = widget;
422 gtk_table_attach (GTK_TABLE (table), widget, 3, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
423
424 widget = make_amount(NULL);
425 gtk_widget_set_size_request(widget, 100, -1);
426 data.ST_amount[i] = widget;
427 gtk_table_attach (GTK_TABLE (table), widget, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
428
429 //connect all our signals
430 g_signal_connect (data.PO_cat[i], "changed", G_CALLBACK (ui_txn_split_dialog_compute), &data);
431 data.handler_id[i] = g_signal_connect (G_OBJECT (data.ST_amount[i]), "value-changed", G_CALLBACK (ui_txn_split_dialog_compute), &data);
432 if(data.BT_rem[i])
433 g_signal_connect (data.BT_rem[i], "clicked", G_CALLBACK (ui_txn_split_dialog_inactiveline), GINT_TO_POINTER(i));
434 if(data.BT_add[i])
435 g_signal_connect (data.BT_add[i], "clicked", G_CALLBACK (ui_txn_split_dialog_activeline), GINT_TO_POINTER(i));
436 }
437
438 row++;
439 label = gtk_label_new(_("Sum of splits:"));
440 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
441 gtk_table_attach (GTK_TABLE (table), label, 3, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
442 label = gtk_label_new(NULL);
443 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
444 gtk_misc_set_padding(GTK_MISC(label), 20, 0);
445 data.LB_sumsplit = label;
446 gtk_table_attach (GTK_TABLE (table), label, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
447
448 if( data.splittype == TXN_SPLIT_AMOUNT )
449 {
450 row++;
451 label = gtk_label_new(_("Unassigned:"));
452 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
453 gtk_table_attach (GTK_TABLE (table), label, 3, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
454 label = gtk_label_new(NULL);
455 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
456 gtk_misc_set_padding(GTK_MISC(label), 20, 0);
457 data.LB_remain = label;
458 gtk_table_attach (GTK_TABLE (table), label, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
459
460 row++;
461 widget = gtk_hseparator_new();
462 gtk_table_attach (GTK_TABLE (table), widget, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
463
464 row++;
465 label = gtk_label_new(_("Transaction amount:"));
466 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
467 gtk_table_attach (GTK_TABLE (table), label, 3, 4, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
468 label = gtk_label_new(NULL);
469 gtk_misc_set_alignment (GTK_MISC(label), 1.0, 0.0);
470 gtk_misc_set_padding(GTK_MISC(label), 20, 0);
471 data.LB_txnamount = label;
472 gtk_table_attach (GTK_TABLE (table), label, 4, 5, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
473 }
474
475
476 //setup, init and show dialog
477 //ui_cur_manage_dialog_setup(&data);
478
479
480 ui_txn_split_dialog_set(&data);
481 ui_txn_split_dialog_compute(NULL, &data);
482
483
484 //ui_cur_manage_dialog_update(data.LV_cur, NULL);
485
486 gtk_window_set_default_size(GTK_WINDOW(dialog), 480, -1);
487
488 gtk_widget_show_all (dialog);
489
490 //wait for the user
491 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
492
493 switch (result)
494 {
495 case GTK_RESPONSE_ACCEPT:
496 //do_application_specific_something ();
497 ui_txn_split_dialog_get(&data);
498 deftransaction_update(parent, NULL);
499 break;
500 case GTK_RESPONSE_SPLIT_REM:
501 da_transaction_splits_free(ope);
502 deftransaction_update(parent, NULL);
503 break;
504 case GTK_RESPONSE_SPLIT_SUM: // sum split and alter txn amount
505 ui_txn_split_dialog_get(&data);
506 deftransaction_set_amount_from_split(parent, data.sumsplit);
507 deftransaction_update(parent, NULL);
508 break;
509 default:
510 //do_nothing_since_dialog_was_cancelled ();
511 break;
512 }
513
514 // debug
515 #if MYDEBUG == 1
516 {
517 guint i;
518
519 for(i=0;i<TXN_MAX_SPLIT;i++)
520 {
521 Split *split = data.ope->splits[i];
522 if(data.ope->splits[i] == NULL)
523 break;
524 g_print(" split %d : %d, %.2f, %s\n", i, split->kcat, split->amount, split->memo);
525 }
526 }
527 #endif
528
529 // cleanup and destroy
530 //GLOBALS->changes_count += data.change;
531 gtk_widget_destroy (dialog);
532
533 return NULL;
534 }
535
536 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
537
538 static void deftransaction_update(GtkWidget *widget, gpointer user_data)
539 {
540 struct deftransaction_data *data;
541 gboolean sensitive, bool;
542
543 DB( g_print("(ui_transaction) update\n") );
544
545 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
546
547 //valid & remind are exclusive
548 bool = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_valid));
549 sensitive = bool ? FALSE : TRUE;
550 gtk_widget_set_sensitive(data->CM_remind, sensitive);
551 if(bool)
552 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_remind), 0);
553
554 /* disable category if split is set */
555 sensitive = (data->ope->flags & (OF_SPLIT)) ? FALSE : TRUE;
556 gtk_widget_set_sensitive(data->ST_amount, sensitive);
557 gtk_widget_set_sensitive(data->PO_grp, sensitive);
558
559 }
560
561 void deftransaction_set_amount_from_split(GtkWidget *widget, gdouble amount)
562 {
563 struct deftransaction_data *data;
564
565 DB( g_print("(ui_transaction) set_amount_from_split\n") );
566
567 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
568
569 DB( g_print("- amount=%.2f\n", amount) );
570
571 data->ope->amount = amount;
572 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), amount);
573
574 }
575
576
577 static void deftransaction_set(GtkWidget *widget, gpointer user_data)
578 {
579 struct deftransaction_data *data;
580 Transaction *entry;
581 gchar *tagstr, *txt;
582
583 DB( g_print("(ui_transaction) set\n") );
584
585 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
586
587 entry = data->ope;
588
589 DB( g_print(" -> ope=%p data=%p tags:%p\n", data->ope, data, entry->tags) );
590
591 //DB( g_print(" set date to %d\n", entry->date) );
592 //g_object_set(GTK_DATE_ENTRY(data->PO_date), "date", (guint32)entry->ope_Date);
593 gtk_dateentry_set_date(GTK_DATE_ENTRY(data->PO_date), (guint)entry->date);
594
595 txt = (entry->wording != NULL) ? entry->wording : "";
596 gtk_entry_set_text(GTK_ENTRY(data->ST_word), txt);
597 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), entry->amount);
598 //gtk_combo_box_set_active(GTK_COMBO_BOX(data->CY_amount), (entry->ope_Flags & OF_INCOME) ? 1 : 0);
599 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_valid), (entry->flags & OF_VALID) ? 1 : 0);
600 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_remind), (entry->flags & OF_REMIND) ? 1 : 0);
601 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->CM_cheque), (entry->flags & OF_CHEQ2) ? 1 : 0);
602
603 txt = (entry->info != NULL) ? entry->info : "";
604 gtk_entry_set_text(GTK_ENTRY(data->ST_info), txt);
605 ui_cat_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_grp), entry->kcat);
606 ui_pay_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_pay), entry->kpay);
607
608 tagstr = transaction_tags_tostring(entry);
609
610 DB( g_print(" -> tags: '%s'\n", txt) );
611
612 txt = (tagstr != NULL) ? tagstr : "";
613 gtk_entry_set_text(GTK_ENTRY(data->ST_tags), txt);
614 g_free(tagstr);
615
616 //as we trigger an event on this
617 //let's place it at the end to avoid misvalue on the trigger function
618
619 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_acc), entry->kacc);
620 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(data->PO_accto), entry->kxferacc);
621
622 gtk_combo_box_set_active(GTK_COMBO_BOX(data->NU_mode), entry->paymode);
623
624 DB( g_print(" -> acc is: %d\n", gtk_combo_box_get_active(GTK_COMBO_BOX(data->PO_acc)) ) );
625 }
626
627
628 void deftransaction_get(GtkWidget *widget, gpointer user_data)
629 {
630 struct deftransaction_data *data;
631 Transaction *entry;
632 gchar *txt;
633 gdouble value;
634 gint active;
635
636 DB( g_print("(ui_transaction) get\n") );
637
638 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
639
640 entry = data->ope;
641
642 DB( g_print(" -> ope = %p\n", entry) );
643
644 //DB( g_print(" get date to %d\n", entry->ope_Date) );
645 entry->date = gtk_dateentry_get_date(GTK_DATE_ENTRY(data->PO_date));
646 //g_object_get(GTK_DATE_ENTRY(data->PO_date), "date", entry->ope_Date);
647
648 //free any previous string
649 if( entry->wording )
650 {
651 g_free(entry->wording);
652 entry->wording = NULL;
653 }
654 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_word));
655 // ignore if entry is empty
656 if (txt && *txt)
657 {
658 entry->wording = g_strdup(txt);
659 }
660
661 entry->paymode = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
662 if( entry->paymode != PAYMODE_INTXFER )
663 {
664 //#677351: revert kxferacc to 0
665 entry->kxferacc = 0;
666 }
667
668 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
669 entry->amount = value;
670
671 /* for internal transfer add, amount must be expense */
672 // #617936
673 /*
674 if( entry->paymode == PAYMODE_INTXFER && data->type == OPERATION_EDIT_ADD )
675 {
676 if( entry->amount > 0 )
677 entry->amount *= -1;
678 }
679 */
680
681 //free any previous string
682 if( entry->info )
683 {
684 g_free(entry->info);
685 entry->info = NULL;
686 }
687 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_info));
688 // ignore if entry is empty
689 if (txt && *txt)
690 {
691 entry->info = g_strdup(txt);
692 }
693
694 entry->kcat = ui_cat_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_grp));
695 entry->kpay = ui_pay_comboboxentry_get_key_add_new(GTK_COMBO_BOX(data->PO_pay));
696 entry->kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
697 entry->kxferacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
698
699 /* tags */
700 txt = (gchar *)gtk_entry_get_text(GTK_ENTRY(data->ST_tags));
701 DB( g_print(" -> tags: '%s'\n", txt) );
702 transaction_tags_parse(entry, txt);
703
704 /* flags */
705 //entry->flags = 0;
706 entry->flags &= (OF_SPLIT); //(split is set in hb_transaction)
707
708 if( data->type == TRANSACTION_EDIT_ADD || data->type == TRANSACTION_EDIT_INHERIT)
709 entry->flags |= OF_ADDED;
710
711 if( data->type == TRANSACTION_EDIT_MODIFY)
712 entry->flags |= OF_CHANGED;
713
714 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_valid));
715 if(active == 1) entry->flags |= OF_VALID;
716
717 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_remind));
718 if(active == 1) entry->flags |= OF_REMIND;
719
720 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cheque));
721 if(active == 1) entry->flags |= OF_CHEQ2;
722
723 //active = gtk_combo_box_get_active(GTK_COMBO_BOX(data->CY_amount));
724 active = entry->amount > 0 ? TRUE : FALSE;
725 if(active == TRUE) entry->flags |= OF_INCOME;
726
727 }
728
729
730
731
732 static gboolean deftransaction_amount_focusout(GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
733 {
734 struct deftransaction_data *data;
735 gushort paymode;
736 gdouble amount;
737
738 DB( g_print("(ui_transaction) amount focus-out-event %d\n", gtk_widget_is_focus(widget)) );
739
740 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
741
742 paymode = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
743
744 // for internal transfer add, amount must be expense by default
745 if( paymode == PAYMODE_INTXFER && data->type == TRANSACTION_EDIT_ADD )
746 {
747 amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
748 if(amount > 0)
749 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), amount *= -1);
750 }
751
752 return FALSE;
753 }
754
755
756 static void deftransaction_toggleamount(GtkWidget *widget, gpointer user_data)
757 {
758 struct deftransaction_data *data;
759 guint count, i;
760 Split *split;
761 gdouble value;
762
763 DB( g_print("(ui_transaction) toggleamount\n") );
764
765 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
766
767 value = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
768 value *= -1;
769 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), value);
770
771 if( data->ope->flags & OF_SPLIT )
772 {
773 count = da_transaction_splits_count(data->ope);
774 DB( g_print("- count = %d\n", count) );
775 for(i=0;i<count;i++)
776 {
777 split = data->ope->splits[i];
778 split->amount *= -1;
779 }
780 }
781
782 }
783
784
785 static void deftransaction_button_split_cb(GtkWidget *widget, gpointer user_data)
786 {
787 struct deftransaction_data *data;
788 gdouble amount;
789
790 DB( g_print("(ui_transaction) doing split\n") );
791
792 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
793
794 amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
795
796 ui_txn_split_dialog(data->window, data->ope, amount);
797
798 }
799
800
801 static void deftransaction_update_transfer(GtkWidget *widget, gpointer user_data)
802 {
803 struct deftransaction_data *data;
804 gboolean sensitive;
805 guint kacc, kdst;
806
807 DB( g_print("(ui_transaction) update transfer\n") );
808
809 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
810
811 sensitive = TRUE;
812
813 kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
814
815 if(kacc == 0) { sensitive = FALSE; goto end; }
816
817 /* coherent seizure
818 * - target account selected
819 * - source != target
820 * - same currency
821 */
822 if( gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode)) == PAYMODE_INTXFER )
823 {
824 kdst = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_accto));
825
826 if(kdst == 0) { sensitive = FALSE; goto end; }
827 if(kdst == kacc) {
828 sensitive = FALSE;
829 goto end;
830 }
831
832 /*
833 srcacc = da_acc_get(kacc);
834 dstacc = da_acc_get(kdst);
835 if(srcacc->kcur != dstacc->kcur) {
836 sensitive = FALSE;
837 }*/
838 }
839
840 end:
841 DB( g_print(" sensitive %d\n", sensitive) );
842
843 gtk_widget_set_sensitive(gtk_dialog_get_action_area(GTK_DIALOG (data->window)), sensitive);
844
845 }
846
847
848 static void deftransaction_update_accto(GtkWidget *widget, gpointer user_data)
849 {
850 struct deftransaction_data *data;
851 guint kacc;
852
853 DB( g_print("(ui_transaction) update accto\n") );
854
855 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
856
857 kacc = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
858
859 DB( g_print(" acc is %d\n", kacc) );
860
861
862 ui_acc_comboboxentry_populate_except(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, kacc, ACC_LST_INSERT_NORMAL);
863
864 deftransaction_update_transfer(widget, user_data);
865 }
866
867
868 /*
869 **
870 */
871 static void deftransaction_paymode(GtkWidget *widget, gpointer user_data)
872 {
873 struct deftransaction_data *data;
874 gint payment;
875 gint page;
876 gboolean sensitive;
877
878 DB( g_print("(ui_transaction) paymode change\n") );
879
880 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
881
882 payment = gtk_combo_box_get_active(GTK_COMBO_BOX(data->NU_mode));
883 page = 0;
884
885 /* todo: prefill the cheque number ? */
886 if( data->type != TRANSACTION_EDIT_MODIFY )
887 {
888 gboolean expense = (gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount)) > 0 ? FALSE : TRUE);
889
890 DB( g_print(" -> payment: %d\n", PAYMODE_CHECK) );
891 DB( g_print(" -> expense: %d\n", expense) );
892 DB( g_print(" -> acc is: %d\n", ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc)) ) );
893
894 if(payment == PAYMODE_CHECK)
895 {
896 if(expense == TRUE)
897 {
898 Account *acc;
899 gint active = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(data->PO_acc));
900 guint cheque;
901 gchar *cheque_str;
902
903 DB( g_print(" -> should fill cheque number for account %d\n", active) );
904
905 if( active != -1 )
906 {
907 acc = da_acc_get( active );
908 cheque = ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->CM_cheque))==TRUE ? acc->cheque2 : acc->cheque1 );
909 cheque_str = g_strdup_printf("%d", cheque + 1);
910 gtk_entry_set_text(GTK_ENTRY(data->ST_info), cheque_str);
911 g_free(cheque_str);
912 }
913 }
914
915 }
916 }
917
918
919 if(payment == PAYMODE_CHECK)
920 page = 1;
921
922 sensitive = (payment == PAYMODE_INTXFER) ? FALSE : TRUE;
923 gtk_widget_set_sensitive(data->BT_split, sensitive);
924
925 sensitive = page == 1 ? TRUE : FALSE;
926 hb_widget_visible(data->CM_cheque, sensitive);
927
928 if(payment == PAYMODE_INTXFER)
929 {
930 page = 2;
931 // for internal transfer add, amount must be expense by default
932 if( data->type == TRANSACTION_EDIT_ADD )
933 {
934 gdouble amount = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->ST_amount));
935 if(amount > 0)
936 gtk_spin_button_set_value(GTK_SPIN_BUTTON(data->ST_amount), amount *= -1);
937 }
938 }
939
940 deftransaction_update_accto(widget, user_data);
941 DB( g_print(" payment: %d, page: %d\n", payment, page) );
942
943 sensitive = page == 2 ? TRUE : FALSE;
944 hb_widget_visible(data->LB_accto, sensitive);
945 hb_widget_visible(data->PO_accto, sensitive);
946
947 }
948
949
950 static void deftransaction_fillfrom(GtkWidget *widget, gpointer user_data)
951 {
952 struct deftransaction_data *data;
953 Transaction *entry;
954 Archive *arc;
955 gint n_arc;
956
957 DB( g_print("(ui_transaction) fill from\n") );
958
959 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
960 entry = data->ope;
961
962 n_arc = gtk_combo_box_get_active(GTK_COMBO_BOX(data->PO_arc));
963
964 DB( g_print(" fill from %d\n", n_arc) );
965
966 if(n_arc > 0)
967 {
968 arc = g_list_nth_data(GLOBALS->arc_list, n_arc-1);
969
970 //fill it
971 entry->amount = arc->amount;
972 //#1258344 keep the current account if tpl is empty
973 if(arc->kacc)
974 entry->kacc = arc->kacc;
975 entry->kxferacc = arc->kxferacc;
976 entry->paymode = arc->paymode;
977 entry->flags = arc->flags;
978 entry->kpay = arc->kpay;
979 entry->kcat = arc->kcat;
980 entry->wording = g_strdup(arc->wording);
981 entry->info = NULL;
982
983 DB( g_print(" calls\n") );
984
985 deftransaction_set(widget, NULL);
986 deftransaction_paymode(widget, NULL);
987 deftransaction_update(widget, NULL);
988
989 gtk_combo_box_set_active(GTK_COMBO_BOX(data->PO_arc), 0);
990 }
991 }
992
993
994 /*
995 ** called from outside
996 */
997 void deftransaction_set_transaction(GtkWidget *widget, Transaction *ope)
998 {
999 struct deftransaction_data *data;
1000
1001
1002 DB( g_print("(ui_transaction) set out transaction\n") );
1003
1004 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1005
1006 data->ope = ope;
1007
1008 DB( g_print(" -> ope=%p data=%p\n", data->ope, data) );
1009
1010 DB( g_print(" -> call init\n") );
1011
1012 deftransaction_set(widget, NULL);
1013 deftransaction_paymode(widget, NULL);
1014 deftransaction_update(widget, NULL);
1015
1016 }
1017
1018
1019 void deftransaction_dispose(GtkWidget *widget, gpointer user_data)
1020 {
1021 struct deftransaction_data *data;
1022
1023 DB( g_print("(ui_transaction) dispose\n") );
1024
1025 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1026
1027 g_free(data);
1028 }
1029
1030
1031 static void deftransaction_setup(struct deftransaction_data *data)
1032 {
1033
1034 DB( g_print("(ui_transaction) setup\n") );
1035
1036 gtk_window_set_title (GTK_WINDOW (data->window), _(CYA_OPERATION[data->type]));
1037
1038 ui_pay_comboboxentry_populate(GTK_COMBO_BOX(data->PO_pay), GLOBALS->h_pay);
1039 ui_cat_comboboxentry_populate(GTK_COMBO_BOX(data->PO_grp), GLOBALS->h_cat);
1040 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_acc), GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
1041 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(data->PO_accto), GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
1042
1043 if( (data->type != TRANSACTION_EDIT_MODIFY) && (da_archive_length() > 0))
1044 make_poparchive_populate(GTK_COMBO_BOX(data->PO_arc), GLOBALS->arc_list);
1045
1046 }
1047
1048
1049 static GtkWidget *deftransaction_make_block1(struct deftransaction_data *data)
1050 {
1051 GtkWidget *table, *hbox, *label, *widget, *image;
1052 gint row;
1053
1054 table = gtk_table_new (7, 2, FALSE);
1055 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
1056 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
1057
1058 row = 0;
1059 label = make_label(_("_Date:"), 0.0, 0.5);
1060 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1061 widget = gtk_dateentry_new();
1062 data->PO_date = widget;
1063 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1064 gtk_widget_set_tooltip_text(widget, _("Date accepted here are:\nday,\nday/month or month/day,\nand complete date into your locale"));
1065
1066 row++;
1067 label = make_label(_("_Amount:"), 0.0, 0.5);
1068 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1069
1070 hbox = gtk_hbox_new (FALSE, 0);
1071 gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1072
1073 widget = gtk_button_new_with_label("+/-");
1074 data->BT_amount = widget;
1075 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1076 gtk_widget_set_tooltip_text(widget, _("Toggle amount sign"));
1077
1078 widget = make_amount(label);
1079 data->ST_amount = widget;
1080 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1081
1082 image = gtk_image_new_from_icon_name ("btn-split", GTK_ICON_SIZE_BUTTON);
1083 widget = gtk_button_new();
1084 g_object_set (widget, "image", image, NULL);
1085 data->BT_split = widget;
1086 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1087 gtk_widget_set_tooltip_text(widget, _("Category split"));
1088
1089 row++;
1090 label = make_label(_("Pa_yment:"), 0.0, 0.5);
1091 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1092 widget = make_paymode(label);
1093 data->NU_mode = widget;
1094 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1095
1096 row++;
1097 widget = gtk_check_button_new_with_mnemonic(_("Of notebook _2"));
1098 data->CM_cheque = widget;
1099 gtk_table_attach_defaults (GTK_TABLE (table), widget, 0, 2, row, row+1);
1100
1101 row++;
1102 label = make_label(_("_Info:"), 0.0, 0.5);
1103 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1104 widget = make_string(label);
1105 data->ST_info = widget;
1106 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1107
1108 row++;
1109 label = make_label(_("Acc_ount:"), 0.0, 0.5);
1110 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1111 widget = ui_acc_comboboxentry_new(label);
1112 data->PO_acc = widget;
1113 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1114
1115 row++;
1116 label = make_label(_("To acc_ount:"), 0.0, 0.5);
1117 data->LB_accto = label;
1118 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1119 widget = ui_acc_comboboxentry_new(label);
1120 data->PO_accto = widget;
1121 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1122
1123
1124 return table;
1125 }
1126
1127
1128 static GtkWidget *deftransaction_make_block2(struct deftransaction_data *data)
1129 {
1130 GtkWidget *table, *label, *widget;
1131 gint row;
1132
1133 table = gtk_table_new (6, 2, FALSE);
1134 gtk_table_set_row_spacings (GTK_TABLE (table), HB_TABROW_SPACING);
1135 gtk_table_set_col_spacings (GTK_TABLE (table), HB_TABCOL_SPACING);
1136
1137 row = 0;
1138 label = make_label(_("_Payee:"), 0.0, 0.5);
1139 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1140 widget = ui_pay_comboboxentry_new(label);
1141 data->PO_pay = widget;
1142 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1143 gtk_widget_set_tooltip_text(widget, _("Autocompletion and direct seizure\nis available for Payee"));
1144
1145 row++;
1146 label = make_label(_("_Category:"), 0.0, 0.5);
1147 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1148 widget = ui_cat_comboboxentry_new(label);
1149 data->PO_grp = widget;
1150 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1151
1152 gtk_widget_set_tooltip_text(widget, _("Autocompletion and direct seizure\nis available for Category"));
1153
1154 row++;
1155 label = make_label(_("M_emo:"), 0.0, 0.5);
1156 gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1157 widget = make_memo_entry(label);
1158 data->ST_word = widget;
1159 gtk_table_attach (GTK_TABLE (table), widget, 1, 2, row, row+1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1160
1161 row++;
1162 label = make_label(_("Ta_gs:"), 0.0, 0.5);
1163 gtk_table_attach (GTK_TABLE (table), label, 0,1, row, row+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
1164 widget = make_string(label);
1165 data->ST_tags = widget;
1166 gtk_table_attach_defaults (GTK_TABLE (table), widget, 1, 2, row, row+1);
1167
1168 row++;
1169 widget = gtk_check_button_new_with_mnemonic (_("_Reconciled"));
1170 data->CM_valid = widget;
1171 gtk_table_attach_defaults (GTK_TABLE (table), widget, 0, 2, row, row+1);
1172
1173 row++;
1174 widget = gtk_check_button_new_with_mnemonic (_("Re_mind"));
1175 data->CM_remind = widget;
1176 gtk_table_attach_defaults (GTK_TABLE (table), widget, 0, 2, row, row+1);
1177
1178 return table;
1179 }
1180
1181
1182 GtkWidget *create_deftransaction_window (GtkWindow *parent, gint type)
1183 {
1184 struct deftransaction_data *data;
1185 GtkWidget *window, *content, *hbox, *mainbox, *table;
1186 GtkWidget *alignment;
1187
1188 DB( g_print("(ui_transaction) new\n") );
1189
1190 data = g_malloc0(sizeof(struct deftransaction_data));
1191 if(!data) return NULL;
1192
1193
1194 window = gtk_dialog_new_with_buttons (NULL,
1195 GTK_WINDOW (parent),
1196 0,
1197 NULL,
1198 NULL);
1199
1200 //store our window private data
1201 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)data);
1202 DB( g_print(" -> window=%p, inst_data=%p\n", window, data) );
1203
1204 data->window = window;
1205 data->type = type;
1206
1207
1208 if(type == TRANSACTION_EDIT_MODIFY)
1209 {
1210 gtk_dialog_add_buttons (GTK_DIALOG(window),
1211 GTK_STOCK_CANCEL,
1212 GTK_RESPONSE_REJECT,
1213 GTK_STOCK_OK,
1214 GTK_RESPONSE_ACCEPT,
1215 NULL);
1216 }
1217 else
1218 {
1219 gtk_dialog_add_buttons (GTK_DIALOG(window),
1220 GTK_STOCK_CLOSE,
1221 GTK_RESPONSE_REJECT,
1222 GTK_STOCK_ADD,
1223 GTK_RESPONSE_ADD,
1224 NULL);
1225 }
1226
1227 switch(type)
1228 {
1229 case TRANSACTION_EDIT_ADD:
1230 //homebank_window_set_icon_from_file(GTK_WINDOW (window), "ope_add.svg");
1231 gtk_window_set_icon_name(GTK_WINDOW (window), HB_STOCK_OPE_ADD);
1232 break;
1233 case TRANSACTION_EDIT_INHERIT:
1234 //homebank_window_set_icon_from_file(GTK_WINDOW (window), "ope_herit.svg");
1235 gtk_window_set_icon_name(GTK_WINDOW (window), HB_STOCK_OPE_HERIT);
1236 break;
1237 case TRANSACTION_EDIT_MODIFY:
1238 //homebank_window_set_icon_from_file(GTK_WINDOW (window), "ope_edit.svg");
1239 gtk_window_set_icon_name(GTK_WINDOW (window), HB_STOCK_OPE_EDIT);
1240 break;
1241 }
1242
1243
1244 //window contents
1245 content = gtk_dialog_get_content_area(GTK_DIALOG (window));
1246 mainbox = gtk_vbox_new (FALSE, 0);
1247 gtk_box_pack_start (GTK_BOX (content), mainbox, TRUE, TRUE, HB_MAINBOX_SPACING);
1248 gtk_container_set_border_width (GTK_CONTAINER(mainbox), HB_MAINBOX_SPACING);
1249
1250 // parameters HB_BOX_SPACING
1251 hbox = gtk_hbox_new (TRUE, HB_HSPACE_SPACING);
1252 gtk_box_pack_start (GTK_BOX (mainbox), hbox, FALSE, FALSE, 0);
1253
1254 // block 1
1255 table = deftransaction_make_block1(data);
1256 // gtk_alignment_new(xalign, yalign, xscale, yscale)
1257 alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
1258 gtk_container_add(GTK_CONTAINER(alignment), table);
1259 gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
1260
1261
1262 // block 2
1263 table = deftransaction_make_block2(data);
1264 // gtk_alignment_new(xalign, yalign, xscale, yscale)
1265 alignment = gtk_alignment_new(0.5, 0.0, 1.0, 0.0);
1266 gtk_container_add(GTK_CONTAINER(alignment), table);
1267 gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
1268
1269 //fill from
1270 if( data->type != TRANSACTION_EDIT_MODIFY && da_archive_length() > 0)
1271 {
1272 GtkWidget *expander, *widget, *label;
1273
1274 expander = gtk_expander_new (_("Fill in with a template"));
1275 gtk_box_pack_start (GTK_BOX (mainbox), expander, FALSE, FALSE, 0);
1276
1277 hbox = gtk_hbox_new (FALSE, HB_BOX_SPACING);
1278 gtk_container_add (GTK_CONTAINER (expander), hbox);
1279
1280 label = make_label(_("_Template:"), 0, 0.5);
1281 widget = make_poparchive(label);
1282 data->PO_arc = widget;
1283 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1284 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
1285
1286 g_signal_connect (data->PO_arc, "changed", G_CALLBACK (deftransaction_fillfrom), NULL);
1287 }
1288
1289
1290 //connect all our signals
1291 g_signal_connect (G_OBJECT (data->ST_amount), "focus-out-event", G_CALLBACK (deftransaction_amount_focusout), data);
1292 g_signal_connect (G_OBJECT (data->BT_amount), "clicked", G_CALLBACK (deftransaction_toggleamount), NULL);
1293 g_signal_connect (G_OBJECT (data->BT_split), "clicked", G_CALLBACK (deftransaction_button_split_cb), NULL);
1294
1295 g_signal_connect (data->NU_mode, "changed", G_CALLBACK (deftransaction_paymode), NULL);
1296 g_signal_connect (data->CM_cheque, "toggled", G_CALLBACK (deftransaction_paymode), NULL);
1297 g_signal_connect (data->CM_valid, "toggled", G_CALLBACK (deftransaction_update), NULL);
1298 g_signal_connect (data->PO_acc, "changed", G_CALLBACK (deftransaction_update_accto), NULL);
1299 g_signal_connect (data->PO_accto, "changed", G_CALLBACK (deftransaction_update_transfer), NULL);
1300
1301 //setup, init and show window
1302 deftransaction_setup(data);
1303
1304 gtk_window_set_default_size(GTK_WINDOW(window), 640, -1);
1305
1306 gtk_widget_show_all (window);
1307
1308 return window;
1309 }
This page took 0.127304 seconds and 4 git commands to generate.