]> Dogcows Code - chaz/homebank/blob - src/ui-dialogs.c
Merge branch 'master' into ext-perl
[chaz/homebank] / src / ui-dialogs.c
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2016 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "homebank.h"
21
22 #include "ui-dialogs.h"
23 #include "list_operation.h"
24
25 #include "hb-currency.h"
26 #include "ui-currency.h"
27
28
29 /* = = = = = = = = = = */
30 /* = = = = = = = = = = = = = = = = = = = = */
31 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
32 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
33
34 /****************************************************************************/
35 /* Debug macros */
36 /****************************************************************************/
37 #define MYDEBUG 0
38
39 #if MYDEBUG
40 #define DB(x) (x);
41 #else
42 #define DB(x);
43 #endif
44
45 /* our global datas */
46 extern struct HomeBank *GLOBALS;
47 extern struct Preferences *PREFS;
48
49
50
51 /* = = = = = = = = = = = = = = = = = = = = */
52
53 /* Confirmation Alert dialog */
54
55 gint ui_dialog_msg_confirm_alert(GtkWindow *parent, gchar *title, gchar *secondtext, gchar *actionverb)
56 {
57 GtkWidget *dialog;
58 gint retval;
59
60 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
61 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
62 GTK_MESSAGE_WARNING,
63 GTK_BUTTONS_NONE,
64 title,
65 NULL
66 );
67
68 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
69 _("_Cancel"), GTK_RESPONSE_CANCEL,
70 actionverb, GTK_RESPONSE_OK,
71 NULL);
72
73
74 if(secondtext)
75 {
76 g_object_set(GTK_MESSAGE_DIALOG (dialog), "secondary-text", secondtext, NULL);
77 //gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), secondtext);
78 }
79
80 gtk_dialog_set_default_response(GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
81
82 retval = gtk_dialog_run (GTK_DIALOG (dialog));
83
84 gtk_widget_destroy (dialog);
85
86 return retval;
87 }
88
89
90
91
92 /* Message dialog */
93
94
95
96
97 gint ui_dialog_msg_question(GtkWindow *parent, gchar *title, gchar *message_format, ...)
98 {
99 GtkWidget *dialog;
100 gchar* msg = NULL;
101 va_list args;
102 gint retval;
103
104 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
105 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
106 GTK_MESSAGE_QUESTION,
107 GTK_BUTTONS_YES_NO,
108 title,
109 NULL
110 );
111
112 if (message_format)
113 {
114 va_start (args, message_format);
115 msg = g_strdup_vprintf (message_format, args);
116 va_end (args);
117
118 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg);
119
120 g_free (msg);
121 }
122
123 gtk_dialog_set_default_response(GTK_DIALOG (dialog), GTK_RESPONSE_NO);
124
125 retval = gtk_dialog_run (GTK_DIALOG (dialog));
126
127 gtk_widget_destroy (dialog);
128
129 return retval;
130 }
131
132 /*
133 ** open a info/error dialog for user information purpose
134 */
135 void ui_dialog_msg_infoerror(GtkWindow *parent, GtkMessageType type, gchar *title, gchar *message_format, ...)
136 {
137 GtkWidget *dialog;
138 gchar* msg = NULL;
139 va_list args;
140
141
142 dialog = gtk_message_dialog_new (GTK_WINDOW(parent),
143 GTK_DIALOG_DESTROY_WITH_PARENT,
144 type,
145 GTK_BUTTONS_OK,
146 "%s",
147 title
148 );
149
150 if (message_format)
151 {
152 va_start (args, message_format);
153 msg = g_strdup_vprintf (message_format, args);
154 va_end (args);
155
156 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", msg);
157
158 g_free (msg);
159 }
160
161 gtk_dialog_run (GTK_DIALOG (dialog));
162 gtk_widget_destroy (dialog);
163 }
164
165
166 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
167
168
169 void ui_dialog_file_statistics(void)
170 {
171 GtkWidget *dialog, *content_area, *content_grid, *group_grid;
172 GtkWidget *label, *widget;
173 gchar *tmpstr;
174 gint crow, row, count;
175
176 dialog = gtk_dialog_new_with_buttons (_("File statistics"),
177 GTK_WINDOW (GLOBALS->mainwindow),
178 0,
179 _("_Close"),
180 GTK_RESPONSE_ACCEPT,
181 NULL);
182
183 gtk_window_set_default_size (GTK_WINDOW(dialog), HB_MINWIDTH_LIST, -1);
184
185 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
186
187 content_grid = gtk_grid_new();
188 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
189 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
190 gtk_container_set_border_width (GTK_CONTAINER(content_grid), SPACING_MEDIUM);
191 gtk_box_pack_start (GTK_BOX (content_area), content_grid, TRUE, TRUE, 0);
192
193 crow = 0;
194 // group :: file title
195 group_grid = gtk_grid_new ();
196 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
197 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
198 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
199
200 label = make_label_group(NULL);
201 tmpstr = g_path_get_basename(GLOBALS->xhb_filepath);
202 gtk_label_set_text(GTK_LABEL(label), tmpstr);
203 g_free(tmpstr);
204 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
205
206 row = 1;
207 label = make_label_widget(_("Account"));
208 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
209 widget = make_label(NULL, 1.0, 0.5);
210 count = da_acc_length ();
211 ui_label_set_integer(GTK_LABEL(widget), count);
212 gtk_widget_set_hexpand(widget, TRUE);
213 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
214
215 row++;
216 label = make_label_widget(_("Transaction"));
217 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
218 widget = make_label(NULL, 1.0, 0.5);
219 count = da_transaction_length();
220 ui_label_set_integer(GTK_LABEL(widget), count);
221 gtk_widget_set_hexpand(widget, TRUE);
222 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
223
224 row++;
225 label = make_label_widget(_("Payee"));
226 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
227 widget = make_label(NULL, 1.0, 0.5);
228 count = da_pay_length ();
229 ui_label_set_integer(GTK_LABEL(widget), count);
230 gtk_widget_set_hexpand(widget, TRUE);
231 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
232
233 row++;
234 label = make_label_widget(_("Category"));
235 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
236 widget = make_label(NULL, 1.0, 0.5);
237 count = da_cat_length ();
238 ui_label_set_integer(GTK_LABEL(widget), count);
239 gtk_widget_set_hexpand(widget, TRUE);
240 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
241
242 row++;
243 label = make_label_widget(_("Assignment"));
244 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
245 widget = make_label(NULL, 1.0, 0.5);
246 count = da_asg_length ();
247 ui_label_set_integer(GTK_LABEL(widget), count);
248 gtk_widget_set_hexpand(widget, TRUE);
249 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
250
251 gtk_widget_show_all(content_grid);
252
253 //wait for the user
254 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
255
256 if(result == GTK_RESPONSE_ACCEPT)
257 {
258
259 }
260
261 // cleanup and destroy
262 gtk_widget_destroy (dialog);
263
264 }
265
266
267 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
268
269 struct dialog_currency_data
270 {
271 GtkWidget *window;
272 GtkWidget *LB_currency;
273 GtkWidget *BT_change;
274 Currency4217 *curfmt;
275 };
276
277 static void ui_dialog_upgrade_choose_currency_change_action(GtkWidget *widget, gpointer user_data)
278 {
279 struct dialog_currency_data *data = user_data;
280 Currency4217 *curfmt;
281
282 data->curfmt = NULL;
283
284 curfmt = ui_cur_select_dialog_new(GTK_WINDOW(data->window), CUR_SELECT_MODE_BASE);
285 if( curfmt != NULL )
286 {
287 gchar label[128];
288 gchar *name;
289
290 DB( g_printf("- user selected: '%s' '%s'\n", curfmt->curr_iso_code, curfmt->name) );
291
292 data->curfmt = curfmt;
293
294 name = curfmt->name;
295
296 g_snprintf(label, 127, "%s - %s", curfmt->curr_iso_code, name);
297 gtk_label_set_text (GTK_LABEL(data->LB_currency), label);
298 }
299 }
300
301
302 static void ui_dialog_upgrade_choose_currency_fill(struct dialog_currency_data *data)
303 {
304 Currency *cur;
305 gchar label[128];
306
307 data->curfmt = NULL;
308
309 cur = da_cur_get (GLOBALS->kcur);
310
311 g_snprintf(label, 127, "%s - %s", cur->iso_code, cur->name);
312 gtk_label_set_text (GTK_LABEL(data->LB_currency), label);
313 }
314
315
316
317 void ui_dialog_upgrade_choose_currency(void)
318 {
319 struct dialog_currency_data data;
320 GtkWidget *dialog, *content_area, *content_grid, *group_grid;
321 GtkWidget *label, *widget;
322 gint crow, row;
323
324 dialog = gtk_dialog_new_with_buttons (_("Upgrade"),
325 GTK_WINDOW (GLOBALS->mainwindow),
326 0,
327 _("_Cancel"), GTK_RESPONSE_CANCEL,
328 _("_OK"), GTK_RESPONSE_ACCEPT,
329 NULL);
330
331 data.window = dialog;
332
333 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
334
335 content_grid = gtk_grid_new();
336 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
337 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
338 gtk_container_set_border_width (GTK_CONTAINER(content_grid), SPACING_MEDIUM);
339 gtk_box_pack_start (GTK_BOX (content_area), content_grid, TRUE, TRUE, 0);
340
341 crow = 0;
342 // group :: file title
343 group_grid = gtk_grid_new ();
344 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
345 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
346 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
347
348 row = 0;
349 label = make_label(_("Select a base currency"), 0, 0);
350 gimp_label_set_attributes(GTK_LABEL(label),
351 PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
352 PANGO_ATTR_SCALE, PANGO_SCALE_LARGE,
353 -1);
354 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 3, 1);
355
356 row++;
357 label = make_label(
358 _("Starting v5.1, HomeBank can manage several currencies\n" \
359 "if the currency below is not correct, please change it:"), 0, 0);
360 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 3, 1);
361
362 row++;
363 label = make_label_widget(_("Currency:"));
364 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
365 widget = make_label (NULL, 0, 0.5);
366 data.LB_currency = widget;
367 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
368 widget = gtk_button_new_with_mnemonic (_("_Change"));
369 data.BT_change = widget;
370 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
371
372 g_signal_connect (G_OBJECT (data.BT_change), "clicked", G_CALLBACK (ui_dialog_upgrade_choose_currency_change_action), &data);
373
374
375 ui_dialog_upgrade_choose_currency_fill(&data);
376
377 gtk_widget_show_all(content_grid);
378
379 //wait for the user
380 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
381
382 if(result == GTK_RESPONSE_ACCEPT)
383 {
384
385 if( data.curfmt != NULL )
386 {
387 hbfile_replace_basecurrency(data.curfmt);
388 }
389 }
390
391 // in any case set every accounts to base currency
392 GList *list;
393 list = g_hash_table_get_values(GLOBALS->h_acc);
394 while (list != NULL)
395 {
396 Account *acc = list->data;
397
398 account_set_currency(acc, GLOBALS->kcur);
399 list = g_list_next(list);
400 }
401 g_list_free(list);
402
403 // cleanup and destroy
404 gtk_widget_destroy (dialog);
405
406 }
407
408
409 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
410
411
412
413
414 static void ui_file_chooser_add_filter(GtkFileChooser *chooser, gchar *name, gchar *pattern)
415 {
416 GtkFileFilter *filter = gtk_file_filter_new ();
417 gtk_file_filter_set_name (filter, name);
418 gtk_file_filter_add_pattern (filter, pattern);
419 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(chooser), filter);
420 }
421
422
423 gboolean ui_file_chooser_qif(GtkWindow *parent, gchar **storage_ptr)
424 {
425 GtkWidget *chooser;
426 gboolean retval;
427
428 DB( g_print("(homebank) chooser save qif\n") );
429
430 chooser = gtk_file_chooser_dialog_new (
431 _("Export as QIF"),
432 GTK_WINDOW(parent),
433 GTK_FILE_CHOOSER_ACTION_SAVE,
434 _("_Cancel"), GTK_RESPONSE_CANCEL,
435 _("_Save"), GTK_RESPONSE_ACCEPT,
436 NULL);
437
438 //todo: change this ?
439 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(chooser), PREFS->path_export);
440 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("QIF files"), "*.[Qq][Ii][Ff]");
441 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("All files"), "*");
442
443 retval = FALSE;
444 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
445 {
446 gchar *tmpfilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
447
448 *storage_ptr = hb_util_filename_new_with_extension(tmpfilename, "qif");
449 g_free(tmpfilename);
450 retval = TRUE;
451 }
452
453 gtk_widget_destroy (chooser);
454
455 return retval;
456 }
457
458
459
460 /*
461 ** open a file chooser dialog and store filename to GLOBALS if OK
462 */
463 gboolean ui_file_chooser_csv(GtkWindow *parent, GtkFileChooserAction action, gchar **storage_ptr, gchar *name)
464 {
465 GtkWidget *chooser;
466 gchar *title;
467 gchar *button;
468 gboolean retval;
469 gchar *path;
470
471 DB( g_print("(hombank) csvfile chooser csv %d\n", action) );
472
473 if( action == GTK_FILE_CHOOSER_ACTION_OPEN )
474 {
475 title = _("Import from CSV");
476 button = _("_Open");
477 path = PREFS->path_import;
478 }
479 else
480 {
481 title = _("Export as CSV");
482 button = _("_Save");
483 path = PREFS->path_export;
484 }
485
486 chooser = gtk_file_chooser_dialog_new (title,
487 GTK_WINDOW(parent),
488 action, //GTK_FILE_CHOOSER_ACTION_OPEN,
489 _("_Cancel"), GTK_RESPONSE_CANCEL,
490 button, GTK_RESPONSE_ACCEPT,
491 NULL);
492
493 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(chooser), path);
494
495 if(name != NULL)
496 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(chooser), name);
497
498 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("CSV files"), "*.[Cc][Ss][Vv]");
499 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("All files"), "*");
500
501 retval = FALSE;
502 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
503 {
504 gchar *tmpfilename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
505
506 if( action == GTK_FILE_CHOOSER_ACTION_SAVE )
507 {
508 *storage_ptr = hb_util_filename_new_with_extension(tmpfilename, "csv");
509 g_free(tmpfilename);
510 }
511 else
512 {
513 *storage_ptr = tmpfilename;
514 }
515 retval = TRUE;
516 }
517
518 gtk_widget_destroy (chooser);
519
520 return retval;
521 }
522
523 /*
524 ** open a file chooser dialog and store filename to GLOBALS if OK
525 */
526 gboolean ui_file_chooser_xhb(GtkFileChooserAction action, gchar **storage_ptr)
527 {
528 GtkWidget *chooser;
529 gchar *title;
530 gchar *button;
531 gboolean retval;
532
533 DB( g_print("(ui-dialog) file chooser xhb %d\n", action) );
534
535 if( action == GTK_FILE_CHOOSER_ACTION_OPEN )
536 {
537 title = _("Open HomeBank file");
538 button = _("_Open");
539 }
540 else
541 {
542 title = _("Save HomeBank file as");
543 button = _("_Save");
544 }
545
546 chooser = gtk_file_chooser_dialog_new (title,
547 GTK_WINDOW(GLOBALS->mainwindow),
548 action, //GTK_FILE_CHOOSER_ACTION_OPEN,
549 _("_Cancel"), GTK_RESPONSE_CANCEL,
550 button, GTK_RESPONSE_ACCEPT,
551 NULL);
552
553 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("HomeBank files"), "*.[Xx][Hh][Bb]");
554 ui_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), _("All files"), "*");
555
556 if( action == GTK_FILE_CHOOSER_ACTION_OPEN )
557 {
558 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(chooser), PREFS->path_hbfile);
559 }
560 else /* save */
561 {
562 gchar *basename, *dirname;
563
564 basename = g_path_get_basename(GLOBALS->xhb_filepath);
565 dirname = g_path_get_dirname (GLOBALS->xhb_filepath);
566 //gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(chooser), GLOBALS->xhb_filepath);
567
568 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(chooser), dirname);
569 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(chooser), basename);
570
571 g_free(dirname);
572 g_free(basename);
573 }
574
575 retval = FALSE;
576 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
577 {
578 *storage_ptr = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
579 retval = TRUE;
580 }
581
582 gtk_widget_destroy (chooser);
583
584 return retval;
585 }
586
587 /*
588 **
589 */
590 gboolean ui_file_chooser_folder(GtkWindow *parent, gchar *title, gchar **storage_ptr)
591 {
592 GtkWidget *chooser;
593 gboolean retval;
594
595 DB( g_print("(ui-dialog) folder chooser\n") );
596
597 chooser = gtk_file_chooser_dialog_new (title,
598 parent,
599 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
600 _("_Cancel"), GTK_RESPONSE_CANCEL,
601 _("_Open"), GTK_RESPONSE_ACCEPT,
602 NULL);
603
604 DB( g_print(" - set folder %s\n", *storage_ptr) );
605
606 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(chooser), *storage_ptr);
607
608 retval = FALSE;
609 if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
610 {
611 gchar *filename;
612
613 //nb: filename must be freed with g_free
614 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
615
616 DB( g_print("- folder %s\n", filename) );
617
618 //todo: dangerous to do this here, review please !
619 g_free(*storage_ptr);
620 *storage_ptr = filename;
621
622 DB( g_print("- folder stored: %s\n", *storage_ptr) );
623
624
625 retval = TRUE;
626 }
627
628 gtk_widget_destroy (chooser);
629
630 return retval;
631 }
632
633
634
635 /*
636 ** request the user to save last change
637 */
638 gboolean ui_dialog_msg_savechanges(GtkWidget *widget, gpointer user_data)
639 {
640 gboolean retval = TRUE;
641 GtkWidget *dialog = NULL;
642
643
644 if(GLOBALS->changes_count)
645 {
646 gint result;
647
648 dialog = gtk_message_dialog_new
649 (
650 GTK_WINDOW(GLOBALS->mainwindow),
651 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
652 GTK_MESSAGE_WARNING,
653 //GTK_MESSAGE_INFO,
654 GTK_BUTTONS_NONE,
655 _("Save changes to the file before closing?")
656 );
657
658 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
659 _("If you don't save, changes will be permanently lost.\nNumber of changes: %d."),
660 GLOBALS->changes_count
661 );
662
663 gtk_dialog_add_buttons (GTK_DIALOG(dialog),
664 _("Close _without saving"), 0,
665 _("_Cancel"), 1,
666 _("_Save"), 2,
667 NULL);
668
669 gtk_dialog_set_default_response(GTK_DIALOG( dialog ), 2);
670
671 result = gtk_dialog_run( GTK_DIALOG( dialog ) );
672 gtk_widget_destroy( dialog );
673
674 if(result == 1 || result == GTK_RESPONSE_DELETE_EVENT)
675 {
676 retval = FALSE;
677 }
678 else
679 {
680 if(result == 2)
681 {
682 DB( g_print(" + should quick save %s\n", GLOBALS->xhb_filepath) );
683 homebank_save_xml(GLOBALS->xhb_filepath);
684 }
685 }
686
687
688
689 }
690 return retval;
691 }
692
693
694 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
695
696 struct xfer_data
697 {
698 GtkWidget *window;
699 GtkWidget *radio[2];
700 GtkWidget *srctreeview;
701 GtkWidget *treeview;
702 };
703
704
705 static void ui_dialog_transaction_xfer_select_child_cb(GtkWidget *radiobutton, gpointer user_data)
706 {
707 struct xfer_data *data;
708 GtkTreeSelection *selection;
709 gboolean btnew, sensitive;
710 gint count;
711
712
713 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(radiobutton), GTK_TYPE_WINDOW)), "inst_data");
714
715 DB( g_print("(import) account type toggle\n") );
716
717 btnew = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->radio[0]));
718 gtk_widget_set_sensitive(data->treeview, btnew^1);
719
720 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->treeview));
721 count = gtk_tree_selection_count_selected_rows(selection);
722
723
724 sensitive = (btnew || count > 0) ? TRUE : FALSE;
725
726 DB( g_print("test count %d btnew %d sensitive %d\n", count, btnew, sensitive) );
727
728
729 gtk_dialog_set_response_sensitive(GTK_DIALOG(data->window), GTK_RESPONSE_ACCEPT, sensitive);
730
731 }
732
733 static void ui_dialog_transaction_xfer_select_child_selection_cb(GtkTreeSelection *treeselection, gpointer user_data)
734 {
735 ui_dialog_transaction_xfer_select_child_cb(GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection)), NULL);
736 }
737
738
739 Transaction *ui_dialog_transaction_xfer_select_child(Transaction *stxn, GList *matchlist)
740 {
741 struct xfer_data data;
742 GtkWidget *window, *content, *mainvbox, *vbox, *sw, *label, *LB_several;
743 GtkTreeModel *newmodel;
744 GtkTreeIter newiter;
745 Transaction *retval = NULL;
746
747 window = gtk_dialog_new_with_buttons (
748 _("Select among possible transactions..."),
749 GTK_WINDOW (GLOBALS->mainwindow),
750 0,
751 _("_Cancel"),
752 GTK_RESPONSE_REJECT,
753 _("_OK"),
754 GTK_RESPONSE_ACCEPT,
755 NULL);
756
757 g_object_set_data(G_OBJECT(window), "inst_data", (gpointer)&data);
758 data.window = window;
759
760 //gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE);
761 gtk_window_set_default_size (GTK_WINDOW (window), 800, 494);
762
763 content = gtk_dialog_get_content_area(GTK_DIALOG (window));
764 mainvbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
765 gtk_box_pack_start (GTK_BOX (content), mainvbox, TRUE, TRUE, 0);
766 gtk_container_set_border_width (GTK_CONTAINER (mainvbox), SPACING_SMALL);
767
768 // source listview
769 sw = gtk_scrolled_window_new (NULL, NULL);
770 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
771 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
772 //gtk_widget_set_size_request(sw, -1, HB_MINWIDTH_LIST/2);
773
774 data.srctreeview = create_list_transaction(LIST_TXN_TYPE_DETAIL, PREFS->lst_ope_columns);
775 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(data.srctreeview)), GTK_SELECTION_NONE);
776 gtk_container_add (GTK_CONTAINER (sw), data.srctreeview);
777 gtk_box_pack_start (GTK_BOX (mainvbox), sw, TRUE, TRUE, 0);
778
779
780 // actions
781 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
782 gtk_box_pack_start (GTK_BOX (mainvbox), vbox, FALSE, TRUE, SPACING_SMALL);
783
784 label = make_label(_("Select an action:"), 0.0, 0.5);
785 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
786 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
787
788 data.radio[0] = gtk_radio_button_new_with_label (NULL, _("create a new transaction"));
789 gtk_box_pack_start (GTK_BOX (vbox), data.radio[0], FALSE, FALSE, 0);
790
791 data.radio[1] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (data.radio[0]), _("select an existing transaction"));
792 gtk_box_pack_start (GTK_BOX (vbox), data.radio[1], FALSE, FALSE, 0);
793
794
795 label = make_label(_(
796 "HomeBank has found some transaction that may be " \
797 "the associated transaction for the internal transfer."), 0.0, 0.5
798 );
799 LB_several = label;
800 gimp_label_set_attributes (GTK_LABEL (label),
801 PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
802 -1);
803 gtk_box_pack_start (GTK_BOX (mainvbox), label, FALSE, FALSE, SPACING_SMALL);
804
805 // target listview
806 sw = gtk_scrolled_window_new (NULL, NULL);
807 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
808 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
809
810 data.treeview = create_list_transaction(LIST_TXN_TYPE_DETAIL, PREFS->lst_ope_columns);
811 gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(data.treeview)), GTK_SELECTION_SINGLE);
812 gtk_container_add (GTK_CONTAINER (sw), data.treeview);
813 gtk_box_pack_start (GTK_BOX (mainvbox), sw, TRUE, TRUE, 0);
814
815 /* populate source */
816 if( stxn != NULL )
817 {
818 newmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(data.srctreeview));
819 gtk_list_store_clear (GTK_LIST_STORE(newmodel));
820
821 gtk_list_store_append (GTK_LIST_STORE(newmodel), &newiter);
822
823 gtk_list_store_set (GTK_LIST_STORE(newmodel), &newiter,
824 LST_DSPOPE_DATAS, stxn,
825 -1);
826 }
827
828 /* populate target */
829 newmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(data.treeview));
830 gtk_list_store_clear (GTK_LIST_STORE(newmodel));
831
832 GList *tmplist = g_list_first(matchlist);
833 while (tmplist != NULL)
834 {
835 Transaction *tmp = tmplist->data;
836
837 /* append to our treeview */
838 gtk_list_store_append (GTK_LIST_STORE(newmodel), &newiter);
839
840 gtk_list_store_set (GTK_LIST_STORE(newmodel), &newiter,
841 LST_DSPOPE_DATAS, tmp,
842 -1);
843
844 //DB( g_print(" - fill: %s %.2f %x\n", item->wording, item->amount, (unsigned int)item->same) );
845
846 tmplist = g_list_next(tmplist);
847 }
848
849
850 g_signal_connect (data.radio[0], "toggled", G_CALLBACK (ui_dialog_transaction_xfer_select_child_cb), NULL);
851 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data.treeview)), "changed", G_CALLBACK (ui_dialog_transaction_xfer_select_child_selection_cb), NULL);
852
853 gtk_widget_show_all(mainvbox);
854
855 //initialize
856 gtk_widget_set_sensitive (data.radio[1], TRUE);
857 if( g_list_length (matchlist) <= 0 )
858 {
859 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data.radio[0]), TRUE);
860 gtk_widget_set_sensitive (data.radio[1], FALSE);
861 gtk_widget_set_visible (LB_several, FALSE);
862 }
863 else
864 {
865 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data.radio[1]), TRUE);
866 gtk_widget_set_visible (LB_several, TRUE);
867 }
868
869 ui_dialog_transaction_xfer_select_child_cb(data.radio[0], NULL);
870
871 //wait for the user
872 gint result = gtk_dialog_run (GTK_DIALOG (window));
873
874 if(result == GTK_RESPONSE_ACCEPT)
875 {
876 gboolean bnew;
877
878 bnew = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data.radio[0]));
879 if( bnew == FALSE )
880 {
881 GtkTreeSelection *selection;
882 GtkTreeModel *model;
883 GtkTreeIter iter;
884
885 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data.treeview));
886 if (gtk_tree_selection_get_selected(selection, &model, &iter))
887 {
888 gtk_tree_model_get(model, &iter, LST_DSPOPE_DATAS, &retval, -1);
889 }
890 }
891
892 }
893
894 // cleanup and destroy
895 gtk_widget_destroy (window);
896
897 return retval;
898 }
899
900
901
This page took 0.074312 seconds and 5 git commands to generate.