import homebank-5.1.2
[chaz/homebank] / src / ui-assist-import.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 "hb-import.h"
23 #include "ui-assist-import.h"
24
25 #include "list_account.h"
26 #include "list_operation.h"
27
28 #include "ui-account.h"
29 #include "dsp_mainwindow.h"
30
31
32
33 /****************************************************************************/
34 /* Debug macros */
35 /****************************************************************************/
36 #define MYDEBUG 0
37
38 #if MYDEBUG
39 #define DB(x) (x);
40 #else
41 #define DB(x);
42 #endif
43
44 #define FORCE_SIZE 1
45 #define HEAD_IMAGE 0
46 #define SIDE_IMAGE 0
47
48
49 /* our global datas */
50 extern struct HomeBank *GLOBALS;
51 extern struct Preferences *PREFS;
52
53
54 static gchar *page_titles[] =
55 {
56 N_("Welcome"),
57 N_("Select file"),
58 N_("Import"),
59 N_("Properties"),
60 N_("Account"),
61 N_("Transaction"),
62 N_("Confirmation")
63 };
64
65
66 extern gchar *CYA_IMPORT_DATEORDER[];
67
68
69 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
70 /* account affect listview */
71 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
72
73
74 static guint32
75 ui_acc_affect_listview_get_selected_key(GtkTreeView *treeview)
76 {
77 GtkTreeSelection *selection;
78 GtkTreeModel *model;
79 GtkTreeIter iter;
80
81 selection = gtk_tree_view_get_selection(treeview);
82 if (gtk_tree_selection_get_selected(selection, &model, &iter))
83 {
84 Account *item;
85
86 gtk_tree_model_get(model, &iter, 0, &item, -1);
87
88 if( item!= NULL )
89 return item->key;
90 }
91 return 0;
92 }
93
94
95 static void
96 ui_acc_affect_listview_srcname_cell_data_function (GtkTreeViewColumn *col,
97 GtkCellRenderer *renderer,
98 GtkTreeModel *model,
99 GtkTreeIter *iter,
100 gpointer user_data)
101 {
102 Account *entry;
103 gchar *name;
104 gchar *string;
105
106 gtk_tree_model_get(model, iter, 0, &entry, -1);
107
108 name = entry->imp_name;
109
110 #if MYDEBUG
111 string = g_markup_printf_escaped("<i>[%d] %s</i>", entry->key, name );
112 #else
113 string = g_markup_printf_escaped("<i>%s</i>", name);
114 #endif
115 g_object_set(renderer, "markup", string, NULL);
116 g_free(string);
117 }
118
119 static void
120 ui_acc_affect_listview_new_cell_data_function (GtkTreeViewColumn *col,
121 GtkCellRenderer *renderer,
122 GtkTreeModel *model,
123 GtkTreeIter *iter,
124 gpointer user_data)
125 {
126 Account *entry;
127 gchar *name;
128
129 gtk_tree_model_get(model, iter, 0, &entry, -1);
130 name = NULL;
131 if(entry->imp_key == 0)
132 name = _("create new");
133 else
134 name = _("use existing");
135
136 g_object_set(renderer, "markup", name, NULL);
137
138 }
139
140 static void
141 ui_acc_affect_listview_dstname_cell_data_function (GtkTreeViewColumn *col,
142 GtkCellRenderer *renderer,
143 GtkTreeModel *model,
144 GtkTreeIter *iter,
145 gpointer user_data)
146 {
147 Account *entry, *dst_entry;
148 gchar *name;
149 #if MYDEBUG
150 gchar *string;
151 #endif
152
153 gtk_tree_model_get(model, iter, 0, &entry, -1);
154 name = NULL;
155 if(entry->imp_key == 0)
156 name = entry->name;
157 else
158 {
159 dst_entry = da_acc_get(entry->imp_key);
160 if( dst_entry != NULL )
161 name = dst_entry->name;
162 }
163
164 #if MYDEBUG
165 string = g_strdup_printf ("[%d] %s", entry->imp_key, name );
166 g_object_set(renderer, "text", string, NULL);
167 g_free(string);
168 #else
169 g_object_set(renderer, "text", name, NULL);
170 #endif
171
172 }
173
174 static void
175 ui_acc_affect_listview_add(GtkTreeView *treeview, Account *item)
176 {
177 if( item->name != NULL )
178 {
179 GtkTreeModel *model;
180 GtkTreeIter iter;
181
182 model = gtk_tree_view_get_model(treeview);
183
184 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
185 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
186 0, item,
187 -1);
188
189 //gtk_tree_selection_select_iter (gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), &iter);
190
191 }
192 }
193
194
195 static GtkWidget *
196 ui_acc_affect_listview_new(void)
197 {
198 GtkListStore *store;
199 GtkWidget *treeview;
200 GtkCellRenderer *renderer;
201 GtkTreeViewColumn *column;
202
203 // create list store
204 store = gtk_list_store_new(1,
205 G_TYPE_POINTER
206 );
207
208 // treeview
209 treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
210 g_object_unref(store);
211
212 // column: import account
213 renderer = gtk_cell_renderer_text_new ();
214 column = gtk_tree_view_column_new();
215 gtk_tree_view_column_pack_start(column, renderer, TRUE);
216 gtk_tree_view_column_set_title(column, _("Name in the file"));
217 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_acc_affect_listview_srcname_cell_data_function, NULL, NULL);
218 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
219
220 // column: target account
221 renderer = gtk_cell_renderer_text_new ();
222 column = gtk_tree_view_column_new();
223 gtk_tree_view_column_pack_start(column, renderer, TRUE);
224 gtk_tree_view_column_set_title(column, _("Action"));
225 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_acc_affect_listview_new_cell_data_function, NULL, NULL);
226 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
227
228 // column: target account
229 renderer = gtk_cell_renderer_text_new ();
230 column = gtk_tree_view_column_new();
231 gtk_tree_view_column_pack_start(column, renderer, TRUE);
232 gtk_tree_view_column_set_title(column, _("Name in HomeBank"));
233 gtk_tree_view_column_set_cell_data_func(column, renderer, ui_acc_affect_listview_dstname_cell_data_function, NULL, NULL);
234 gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column);
235
236
237
238 // treeviewattribute
239 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(treeview), TRUE);
240
241 //gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), ui_acc_listview_compare_func, NULL, NULL);
242 //gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
243
244 return treeview;
245 }
246
247
248
249 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
250
251 //old stuf for transition waiting import rewrite
252 static void da_obsolete_transaction_destroy(GList *list)
253 {
254 GList *tmplist = g_list_first(list);
255
256 while (tmplist != NULL)
257 {
258 Transaction *item = tmplist->data;
259 da_transaction_free(item);
260 tmplist = g_list_next(tmplist);
261 }
262 g_list_free(list);
263 }
264
265 static GQueue *da_obsolete_transaction_get_partial(guint32 minjulian)
266 {
267 GList *lst_acc, *lnk_acc;
268 GList *lnk_txn;
269 GQueue *txn_queue;
270
271 txn_queue = g_queue_new ();
272
273 lst_acc = g_hash_table_get_values(GLOBALS->h_acc);
274 lnk_acc = g_list_first(lst_acc);
275 while (lnk_acc != NULL)
276 {
277 Account *acc = lnk_acc->data;
278
279 lnk_txn = g_queue_peek_tail_link(acc->txn_queue);
280 while (lnk_txn != NULL)
281 {
282 Transaction *txn = lnk_txn->data;
283
284 if( txn->date < minjulian ) //no need to go below mindate
285 break;
286
287 g_queue_push_head (txn_queue, txn);
288
289 lnk_txn = g_list_previous(lnk_txn);
290 }
291
292 lnk_acc = g_list_next(lnk_acc);
293 }
294 g_list_free(lst_acc);
295
296 return txn_queue;
297 }
298
299
300
301
302 /* count account to be imported */
303 static void _import_context_count(struct import_data *data)
304 {
305 ImportContext *ictx = &data->ictx;
306 GList *lacc, *list;
307
308 DB( g_print("\n[import] context count\n") );
309
310 ictx->nb_src_acc = ictx->nb_new_acc = 0;
311
312 ictx->cnt_new_ope = 0;
313
314 /* count account */
315 lacc = list = g_hash_table_get_values(GLOBALS->h_acc);
316 while (list != NULL)
317 {
318 Account *item = list->data;
319
320 if( item->imported == TRUE )
321 {
322 ictx->nb_src_acc++;
323 if( item->imp_key == 0 )
324 ictx->nb_new_acc++;
325 }
326 list = g_list_next(list);
327 }
328 g_list_free(lacc);
329
330 /* count transaction */
331 ictx->cnt_new_ope = g_list_length(ictx->trans_list);
332
333 }
334
335
336 static void _import_context_clear(ImportContext *ictx)
337 {
338 DB( g_print("\n[import] context clear\n") );
339
340 if(ictx->trans_list)
341 da_obsolete_transaction_destroy(ictx->trans_list);
342 ictx->trans_list = NULL;
343 ictx->next_acc_key = da_acc_length();
344 ictx->datefmt = PREFS->dtex_datefmt;
345 ictx->encoding = NULL;
346
347 ictx->cnt_err_date = 0;
348 ictx->cnt_new_pay = 0;
349 ictx->cnt_new_cat = 0;
350 }
351
352
353 #if MYDEBUG
354 static void _import_context_debug(ImportContext *ictx)
355 {
356 DB( g_print("\n[import] context debug\n") );
357
358 DB( g_print(
359 " -> txnlist=%p, maxacckey=%d\n"
360 " -> nb-acc=%d, nb-newacc=%d\n"
361 " -> ntxn=%d, npay=%d, ncat=%d\n"
362 " -> datefmt=%d, encoding='%s', errdate=%d, ndup=%d\n",
363 ictx->trans_list, ictx->next_acc_key,
364 ictx->nb_src_acc, ictx->nb_new_acc,
365 ictx->cnt_new_ope,
366 ictx->cnt_new_pay,
367 ictx->cnt_new_cat,
368 ictx->datefmt,
369 ictx->encoding,
370 ictx->cnt_err_date,
371 ictx->nb_duplicate
372 )
373 );
374 }
375 #endif
376
377
378
379
380
381
382
383 static GList *homebank_qif_import(gchar *filename, ImportContext *ictx)
384 {
385 GList *list = NULL;
386
387 DB( g_print("\n[import] homebank QIF\n") );
388
389 //todo: context ?
390 list = account_import_qif(filename, ictx);
391
392 return list;
393 }
394
395
396
397
398 static void import_clearall(struct import_data *data)
399 {
400 GList *lxxx, *list;
401 GtkTreeModel *model;
402
403 DB( g_print("\n[import] clear all\n") );
404
405 // clear account & transactions
406 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc));
407 gtk_list_store_clear (GTK_LIST_STORE(model));
408 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->imported_ope));
409 gtk_list_store_clear (GTK_LIST_STORE(model));
410 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->duplicat_ope));
411 gtk_list_store_clear (GTK_LIST_STORE(model));
412
413
414 // 1: delete imported accounts
415 lxxx = list = g_hash_table_get_values(GLOBALS->h_acc);
416 while (list != NULL)
417 {
418 Account *item = list->data;
419
420 if( item->imported == TRUE )
421 {
422 DB( g_print(" -> delete acc %p '%s'\n", item, item->name) );
423 da_acc_remove(item->key);
424 }
425 list = g_list_next(list);
426 }
427 g_list_free(lxxx);
428
429 // 2: delete imported payees
430 lxxx = list = g_hash_table_get_values(GLOBALS->h_pay);
431 while (list != NULL)
432 {
433 Payee *item = list->data;
434
435 if( item->imported == TRUE )
436 {
437 DB( g_print(" -> delete pay '%s'\n", item->name) );
438 da_pay_remove(item->key);
439 }
440 list = g_list_next(list);
441 }
442 g_list_free(lxxx);
443
444 // 3: delete imported category
445 lxxx = list = g_hash_table_get_values(GLOBALS->h_cat);
446 while (list != NULL)
447 {
448 Category *item = list->data;
449
450 if( item->imported == TRUE )
451 {
452 DB( g_print(" -> delete cat '%s'\n", item->name) );
453 da_cat_remove(item->key);
454 }
455 list = g_list_next(list);
456 }
457 g_list_free(lxxx);
458
459 _import_context_clear(&data->ictx);
460
461 }
462
463
464 static gboolean ui_import_panel_transaction_is_duplicate(Transaction *impope, Transaction *ope, gint maxgap)
465 {
466 Account *dstacc;
467 guint dstkacc;
468 gboolean retval = FALSE;
469
470 //common tests
471 if( (impope->amount == ope->amount) &&
472 (ope->date <= (impope->date + maxgap)) && (ope->date >= (impope->date - maxgap)) )
473 {
474
475 //we focus the test on impope->acc->imp_key (and not impope->kacc)
476 dstkacc = impope->kacc;
477 dstacc = da_acc_get(dstkacc);
478 if( dstacc && dstacc->imp_key > 0 )
479 {
480 dstkacc = dstacc->imp_key;
481 }
482
483 DB( g_print("--------\n -> dstkacc=%d, amount & date are similar\n", dstkacc) );
484
485 DB( g_print(" -> impope: kacc=%d, %s kxfer=%d, kxferacc=%d\n", impope->kacc, impope->wording, impope->kxfer, impope->kxferacc) );
486 DB( g_print(" -> ope: kacc=%d, %s kxfer=%d, kxferacc=%d\n", ope->kacc, ope->wording, ope->kxfer, ope->kxferacc) );
487
488
489 if(impope->paymode != PAYMODE_INTXFER)
490 {
491 if( dstkacc == ope->kacc )
492 {
493 DB( g_print(" -> impope is not a xfer and acc are similar\n") );
494 retval = TRUE;
495 }
496 }
497 else
498 {
499 if( ( (impope->kxferacc == ope->kxferacc) && ope->kxfer != 0) ||
500 ( impope->kxferacc == 0 )
501 )
502 retval = TRUE;
503 }
504 }
505 return retval;
506 }
507
508
509 static void ui_import_panel_transaction_find_duplicate(struct import_data *data)
510 {
511 ImportContext *ictx = &data->ictx;
512 GList *tmplist, *implist;
513 Transaction *item;
514 guint32 mindate;
515 guint maxgap;
516
517 DB( g_print("\n[import] find duplicate\n") );
518
519 ictx->nb_duplicate = 0;
520 if( ictx->trans_list )
521 {
522 /* 1: get import min bound date */
523 tmplist = g_list_first(ictx->trans_list);
524 item = tmplist->data;
525 mindate = item->date;
526 maxgap = gtk_spin_button_get_value(GTK_SPIN_BUTTON(data->NB_maxgap));
527
528 /* clear any previous same txn */
529 implist = g_list_first(ictx->trans_list);
530 while (implist != NULL)
531 {
532 Transaction *impope = implist->data;
533
534 if(impope->same != NULL)
535 {
536 g_list_free(impope->same);
537 impope->same = NULL;
538 }
539 implist = g_list_next(implist);
540 }
541
542
543 GQueue *txn_queue = da_obsolete_transaction_get_partial(mindate);
544
545 //tmplist = g_list_first(GLOBALS->ope_list);
546 tmplist = g_queue_peek_head_link(txn_queue);
547 while (tmplist != NULL)
548 {
549 Transaction *ope = tmplist->data;
550
551 if( ope->date >= mindate )
552 {
553 //DB( g_print("should check here %d: %s\n", ope->date, ope->wording) );
554
555 implist = g_list_first(ictx->trans_list);
556 while (implist != NULL)
557 {
558 Transaction *impope = implist->data;
559
560 if( ui_import_panel_transaction_is_duplicate(impope, ope, maxgap) )
561 {
562 //DB( g_print(" found %d: %s\n", impope->date, impope->wording) );
563
564 impope->same = g_list_append(impope->same, ope);
565 ictx->nb_duplicate++;
566 }
567
568 implist = g_list_next(implist);
569 }
570 }
571
572 tmplist = g_list_next(tmplist);
573 }
574
575 g_queue_free (txn_queue);
576
577 }
578
579 DB( g_print(" nb_duplicate = %d\n", ictx->nb_duplicate) );
580
581
582 }
583
584
585 static void ui_import_panel_account_fill(struct import_data *data)
586 {
587 ImportContext *ictx = &data->ictx;
588 gchar *label = NULL;
589 gchar *icon_name = NULL;
590 GList *lacc, *list;
591
592 DB( g_print("\n[import] panel account fill\n") );
593
594 if(ictx->nb_new_acc == 0)
595 {
596 icon_name = ICONNAME_INFO;
597 label = g_strdup( _("All seems all right here, your validation is optional!") );
598 }
599 else
600 {
601 gchar *tmpstr;
602
603 /* file name & path */
604 tmpstr = g_path_get_basename(data->filename);
605
606
607
608 icon_name = ICONNAME_WARNING;
609 label = g_strdup_printf(
610 _("No account information has been found into the file '%s'.\n"
611 "Please select the appropriate action for account below."),
612 tmpstr);
613
614 g_free(tmpstr);
615 }
616
617 gtk_label_set_text(GTK_LABEL(data->LB_acc), label);
618 gtk_image_set_from_icon_name(GTK_IMAGE(data->IM_acc), icon_name, GTK_ICON_SIZE_BUTTON);
619
620 g_free(label);
621
622 gtk_list_store_clear (GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(data->LV_acc))));
623
624 lacc = list = g_hash_table_get_values(GLOBALS->h_acc);
625 while (list != NULL)
626 {
627 Account *item = list->data;
628
629 if( item->imported == TRUE )
630 {
631 ui_acc_affect_listview_add(GTK_TREE_VIEW(data->LV_acc), item);
632 }
633 list = g_list_next(list);
634 }
635 g_list_free(lacc);
636
637 DB( _import_context_debug(&data->ictx) );
638 }
639
640
641 /* count transaction with checkbox 'import' */
642 static void import_count_changes(struct import_data *data)
643 {
644 GList *lacc, *list;
645 GtkTreeModel *model;
646 GtkTreeIter iter;
647 gboolean valid;
648
649 DB( g_print("\n[import] count_final_changes\n") );
650
651 data->imp_cnt_acc = 0;
652
653 lacc = list = g_hash_table_get_values(GLOBALS->h_acc);
654 while (list != NULL)
655 {
656 Account *item = list->data;
657
658 if( item->imported == TRUE && item->imp_key != 0)
659 {
660 data->imp_cnt_acc++;
661 }
662 list = g_list_next(list);
663 }
664 g_list_free(lacc);
665
666
667 // then import transactions
668 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->imported_ope));
669
670 data->imp_cnt_trn = 0;
671
672 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
673 while (valid)
674 {
675 gboolean toimport;
676
677 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
678 LST_OPE_IMPTOGGLE, &toimport,
679 -1);
680
681 if(toimport == TRUE)
682 data->imp_cnt_trn++;
683
684 /* Make iter point to the next row in the list store */
685 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
686 }
687 }
688
689
690 static void import_apply(struct import_data *data)
691 {
692 GtkTreeModel *model;
693 GtkTreeIter iter;
694 gboolean valid;
695 GList *lxxx, *list;
696
697 DB( g_print("\n[import] apply\n") );
698
699 // 1: persist imported accounts
700 lxxx = list = g_hash_table_get_values(GLOBALS->h_acc);
701 while (list != NULL)
702 {
703 Account *item = list->data;
704
705 if( item->imported == TRUE )
706 {
707 //only persist user selected to new account
708 if( item->imp_key == 0)
709 {
710 //DB( g_print(" -> persist acc %x '%s'\n", item, item->name) );
711 item->imported = FALSE;
712 g_free(item->imp_name);
713 item->imp_name = NULL;
714 }
715 }
716 list = g_list_next(list);
717 }
718 g_list_free(lxxx);
719
720 // 2: persist imported payees
721 lxxx = list = g_hash_table_get_values(GLOBALS->h_pay);
722 while (list != NULL)
723 {
724 Payee *item = list->data;
725
726 if( item->imported == TRUE )
727 {
728 //DB( g_print(" -> persist pay '%s'\n", item->name) );
729 item->imported = FALSE;
730 }
731 list = g_list_next(list);
732 }
733 g_list_free(lxxx);
734
735 // 3: persist imported categories
736 lxxx = list = g_hash_table_get_values(GLOBALS->h_cat);
737 while (list != NULL)
738 {
739 Category *item = list->data;
740
741 if( item->imported == TRUE )
742 {
743 //DB( g_print(" -> persist cat '%s'\n", item->name) );
744 item->imported = FALSE;
745 }
746 list = g_list_next(list);
747 }
748 g_list_free(lxxx);
749
750 // 4: insert every transactions
751 model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->imported_ope));
752 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), &iter);
753 while (valid)
754 {
755 Transaction *item;
756 gboolean toimport;
757
758 gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
759 LST_DSPOPE_DATAS, &item,
760 LST_OPE_IMPTOGGLE, &toimport,
761 -1);
762
763 if(toimport == TRUE)
764 {
765 Account *acc;
766
767 //DB(g_print("import %d to acc: %d\n", data->total, item->account) );
768 //todo: here also test imp_key on account and change the key into the transaction
769 acc = da_acc_get(item->kacc);
770 if( acc != NULL)
771 {
772 if( acc->imp_key > 0)
773 {
774 item->kacc = acc->imp_key;
775 }
776 }
777
778 transaction_add(item, NULL, 0);
779 }
780
781 /* Make iter point to the next row in the list store */
782 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter);
783 }
784
785
786 }
787
788 /*
789 **
790 */
791 static gboolean
792 ui_import_assistant_dispose(GtkWidget *widget, gpointer user_data)
793 {
794 struct import_data *data = user_data;
795
796 DB( g_print("\n[import] dispose\n") );
797
798 #if MYDEBUG == 1
799 gpointer data2 = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
800 g_print(" user_data=%08x to be free, data2=%x\n", (gint)user_data, (gint)data2);
801 #endif
802
803 g_free( data->filename );
804
805 import_clearall(data);
806
807
808
809
810 // todo: optimize this
811 if(data->imp_cnt_trn > 0)
812 {
813 GLOBALS->changes_count += data->imp_cnt_trn;
814
815 //our global list has changed, so update the treeview
816 ui_mainwindow_update(GLOBALS->mainwindow, GINT_TO_POINTER(UF_TITLE+UF_SENSITIVE+UF_BALANCE+UF_REFRESHALL));
817 }
818
819
820 g_free(user_data);
821
822
823 //delete-event TRUE abort/FALSE destroy
824 return FALSE;
825 }
826
827
828 static void ui_import_panel_transaction_fill(struct import_data *data)
829 {
830 ImportContext *ictx = &data->ictx;
831 GtkWidget *view;
832 GtkTreeModel *model;
833 GtkTreeIter iter;
834 GList *tmplist;
835 gchar *label = NULL;
836 gchar *icon_name = NULL;
837
838 //DB( g_print("\n[import] fill imp operatoin\n") );
839
840 if(ictx->nb_duplicate == 0)
841 {
842 icon_name = ICONNAME_INFO;
843 label = _("All seems all right here, your validation is optional!");
844 }
845 else
846 {
847 icon_name = ICONNAME_WARNING;
848 label =
849 _("Possible duplicate of existing transaction have been found, and disabled for import.\n"
850 "Please check and choose the ones that have to be imported.");
851 }
852
853 gtk_label_set_text(GTK_LABEL(data->LB_txn), label);
854 gtk_image_set_from_icon_name(GTK_IMAGE(data->IM_txn), icon_name, GTK_ICON_SIZE_BUTTON);
855
856
857 view = data->imported_ope;
858 model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
859
860 gtk_list_store_clear (GTK_LIST_STORE(model));
861
862 g_object_ref(model); /* Make sure the model stays with us after the tree view unrefs it */
863 gtk_tree_view_set_model(GTK_TREE_VIEW(view), NULL); /* Detach model from view */
864
865 tmplist = g_list_first(ictx->trans_list);
866 while (tmplist != NULL)
867 {
868 Transaction *item = tmplist->data;
869
870 /* append to our treeview */
871 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
872
873 //DB( g_print(" populate: %s\n", ope->ope_Word) );
874
875 gtk_list_store_set (GTK_LIST_STORE(model), &iter,
876 LST_DSPOPE_DATAS, item,
877 LST_OPE_IMPTOGGLE, item->same == NULL ? TRUE : FALSE,
878 -1);
879
880 //DB( g_print(" - fill: %d, %s %.2f %x\n", item->account, item->wording, item->amount, item->same) );
881
882 tmplist = g_list_next(tmplist);
883 }
884
885 gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); /* Re-attach model to view */
886
887 g_object_unref(model);
888
889
890
891 }
892
893
894 static void ui_import_panel_account_change_action_toggled_cb(GtkRadioButton *radiobutton, gpointer user_data)
895 {
896 struct import_target_data *data;
897 gboolean new_account;
898
899
900 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(GTK_WIDGET(radiobutton), GTK_TYPE_WINDOW)), "inst_data");
901
902 DB( g_print("\n[import] account type toggle\n") );
903
904 new_account = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->radio[0]));
905
906 gtk_widget_set_sensitive(data->label1, new_account);
907 gtk_widget_set_sensitive(data->getwidget1, new_account);
908
909 gtk_widget_set_sensitive(data->label2, new_account^1);
910 gtk_widget_set_sensitive(data->getwidget2, new_account^1);
911
912 }
913
914
915 static void ui_import_panel_account_change_action(GtkWidget *widget, gpointer user_data)
916 {
917 struct import_data *data;
918 struct import_target_data ddata;
919 ImportContext *ictx;
920 GtkWidget *dialog, *content_area, *group_grid, *label ;
921 guint32 key;
922 gint row;
923
924 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
925 DB( g_print("\n[import] account_change_action\n") );
926
927 ictx = &data->ictx;
928
929 key = ui_acc_affect_listview_get_selected_key(GTK_TREE_VIEW(data->LV_acc));
930 if( key > 0 )
931 {
932 Account *item;
933
934 item = da_acc_get( key );
935
936 dialog = gtk_dialog_new_with_buttons (_("Change account action"),
937 GTK_WINDOW (data->assistant),
938 0,
939 _("_Cancel"),
940 GTK_RESPONSE_REJECT,
941 _("_OK"),
942 GTK_RESPONSE_ACCEPT,
943 NULL);
944
945 //store our window private data
946 g_object_set_data(G_OBJECT(dialog), "inst_data", (gpointer)&ddata);
947
948 content_area = gtk_dialog_get_content_area(GTK_DIALOG (dialog));
949
950 // group :: dialog
951 group_grid = gtk_grid_new ();
952 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
953 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
954 gtk_container_set_border_width (GTK_CONTAINER(group_grid), SPACING_MEDIUM);
955 gtk_box_pack_start (GTK_BOX (content_area), group_grid, TRUE, TRUE, SPACING_SMALL);
956
957 row = 0;
958 ddata.radio[0] = gtk_radio_button_new_with_label (NULL, _("create new"));
959 gtk_grid_attach (GTK_GRID (group_grid), ddata.radio[0], 0, row, 3, 1);
960
961 row++;
962 label = make_label(_("_Name:"), 0, 0.5);
963 ddata.label1 = label;
964 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
965
966 ddata.getwidget1 = gtk_entry_new();
967 gtk_grid_attach (GTK_GRID (group_grid), ddata.getwidget1, 2, row, 1, 1);
968
969 row++;
970 ddata.radio[1] = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (ddata.radio[0]), _("use existing"));
971 gtk_grid_attach (GTK_GRID (group_grid), ddata.radio[1], 0, row, 3, 1);
972
973 row++;
974 label = make_label(_("A_ccount:"), 0, 0.5);
975 ddata.label2 = label;
976 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
977
978 ddata.getwidget2 = ui_acc_comboboxentry_new(NULL);
979 gtk_grid_attach (GTK_GRID (group_grid), ddata.getwidget2, 2, row, 1, 1);
980
981 //initialize
982 if( ictx->next_acc_key > 0 ) //if there were already some accounts
983 {
984 gtk_widget_set_sensitive(ddata.radio[1], TRUE);
985 if( item->imp_key > 0 )
986 {
987 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ddata.radio[1]), TRUE);
988 }
989 }
990 else
991 {
992 gtk_widget_set_sensitive(ddata.radio[1], FALSE);
993
994 }
995
996 gtk_entry_set_text(GTK_ENTRY(ddata.getwidget1), item->name);
997 ui_acc_comboboxentry_populate(GTK_COMBO_BOX(ddata.getwidget2), GLOBALS->h_acc, ACC_LST_INSERT_NORMAL);
998 ui_acc_comboboxentry_set_active(GTK_COMBO_BOX(ddata.getwidget2), item->imp_key);
999
1000 ui_import_panel_account_change_action_toggled_cb(GTK_RADIO_BUTTON (ddata.radio[0]), NULL);
1001
1002 gtk_widget_show_all(group_grid);
1003
1004 g_signal_connect (ddata.radio[0], "toggled", G_CALLBACK (ui_import_panel_account_change_action_toggled_cb), NULL);
1005
1006
1007 //wait for the user
1008 gint result = gtk_dialog_run (GTK_DIALOG (dialog));
1009
1010 if(result == GTK_RESPONSE_ACCEPT)
1011 {
1012 gchar *name;
1013 gboolean bnew;
1014 guint key;
1015
1016 key = ui_acc_comboboxentry_get_key(GTK_COMBO_BOX(ddata.getwidget2));
1017
1018 bnew = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ddata.radio[0]));
1019 if( bnew )
1020 {
1021
1022 name = (gchar *)gtk_entry_get_text(GTK_ENTRY(ddata.getwidget1));
1023
1024 if(strcasecmp(name, item->name))
1025 {
1026
1027 DB( g_print("name '%s', existing acc %d\n", name, key) );
1028
1029 if (name && *name)
1030 {
1031 if( account_rename(item, name) == FALSE )
1032 {
1033 ui_dialog_msg_infoerror(GTK_WINDOW(dialog), GTK_MESSAGE_ERROR,
1034 _("Error"),
1035 _("Cannot rename this Account,\n"
1036 "from '%s' to '%s',\n"
1037 "this name already exists."),
1038 item->name,
1039 name
1040 );
1041 }
1042 }
1043 }
1044 else
1045 {
1046 item->imp_key = 0;
1047 }
1048 }
1049 else
1050 {
1051 item->imp_key = key;
1052 }
1053
1054 //we should refresh duplicate
1055 ui_import_panel_transaction_find_duplicate(data);
1056 ui_import_panel_transaction_fill(data);
1057
1058 }
1059
1060 // cleanup and destroy
1061 gtk_widget_destroy (dialog);
1062 }
1063
1064 }
1065
1066
1067 static void ui_import_panel_filechooser_selection_changed(GtkWidget *widget, gpointer user_data)
1068 {
1069 struct import_data *data = user_data;
1070 gint page_number;
1071 GtkWidget *current_page;
1072 gchar *filename;
1073
1074 page_number = gtk_assistant_get_current_page (GTK_ASSISTANT(data->assistant));
1075
1076 DB( g_print("\n[import] selchange (page %d)\n", page_number+1) );
1077
1078 data->valid = FALSE;
1079
1080 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data->filechooser));
1081 if( filename == NULL )
1082 {
1083 gtk_label_set_text(GTK_LABEL(data->user_info), _("Please select a file..."));
1084 //current_page = gtk_assistant_get_nth_page (GTK_ASSISTANT(data->assistant), page_number);
1085 //gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), current_page, FALSE);
1086 }
1087 else
1088 {
1089 if( page_number == PAGE_SELECTFILE )
1090 {
1091 if(data->filename)
1092 g_free( data->filename );
1093 data->filename = filename;
1094 //DB( g_print(" filename -> %s\n", data->filename) );
1095
1096 data->filetype = homebank_alienfile_recognize(data->filename);
1097 switch(data->filetype)
1098 {
1099 case FILETYPE_QIF:
1100 gtk_label_set_text(GTK_LABEL(data->user_info), _("QIF file recognised !"));
1101 data->valid = TRUE;
1102 break;
1103
1104 case FILETYPE_OFX:
1105 #ifndef NOOFX
1106 gtk_label_set_text(GTK_LABEL(data->user_info), _("OFX file recognised !"));
1107 data->valid = TRUE;
1108 #else
1109 gtk_label_set_text(GTK_LABEL(data->user_info), _("** OFX support is disabled **"));
1110 #endif
1111 break;
1112
1113 case FILETYPE_CSV_HB:
1114 gtk_label_set_text(GTK_LABEL(data->user_info), _("CSV transaction file recognised !"));
1115 data->valid = TRUE;
1116 break;
1117
1118 default:
1119 data->filetype = FILETYPE_UNKNOW;
1120 gtk_label_set_text(GTK_LABEL(data->user_info), _("Unknown/Invalid file..."));
1121 break;
1122 }
1123
1124 current_page = gtk_assistant_get_nth_page (GTK_ASSISTANT(data->assistant), page_number);
1125 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), current_page, data->valid);
1126
1127 }
1128
1129 }
1130
1131 if(data->valid == TRUE)
1132 {
1133 gtk_widget_show(data->ok_image);
1134 gtk_widget_hide(data->ko_image);
1135 }
1136 else
1137 {
1138 gtk_widget_show(data->ko_image);
1139 gtk_widget_hide(data->ok_image);
1140 }
1141
1142 }
1143
1144
1145
1146 static void ui_import_panel_transaction_fill_same(GtkTreeSelection *treeselection, gpointer user_data)
1147 {
1148 struct import_data *data;
1149 GtkTreeSelection *selection;
1150 GtkTreeModel *model, *newmodel;
1151 GtkTreeIter iter, newiter;
1152 GList *tmplist;
1153 GtkWidget *view, *widget;
1154
1155 widget = GTK_WIDGET(gtk_tree_selection_get_tree_view (treeselection));
1156
1157
1158 //DB( g_print("\n[import] fillsame\n") );
1159
1160 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1161
1162 view = data->duplicat_ope;
1163
1164 newmodel = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
1165
1166 gtk_list_store_clear (GTK_LIST_STORE(newmodel));
1167
1168
1169
1170 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(data->imported_ope));
1171 //if true there is a selected node
1172 if (gtk_tree_selection_get_selected(selection, &model, &iter))
1173 {
1174 Transaction *item;
1175
1176 gtk_tree_model_get(model, &iter, LST_DSPOPE_DATAS, &item, -1);
1177
1178 if( item->same != NULL )
1179 {
1180 tmplist = g_list_first(item->same);
1181 while (tmplist != NULL)
1182 {
1183 Transaction *tmp = tmplist->data;
1184
1185 /* append to our treeview */
1186 gtk_list_store_append (GTK_LIST_STORE(newmodel), &newiter);
1187
1188 gtk_list_store_set (GTK_LIST_STORE(newmodel), &newiter,
1189 LST_DSPOPE_DATAS, tmp,
1190 -1);
1191
1192 //DB( g_print(" - fill: %s %.2f %x\n", item->wording, item->amount, (unsigned int)item->same) );
1193
1194 tmplist = g_list_next(tmplist);
1195 }
1196 }
1197
1198 }
1199
1200
1201
1202
1203 }
1204
1205
1206 static void ui_import_panel_properties_fill(struct import_data *data)
1207 {
1208 ImportContext *ictx = &data->ictx;
1209 gchar *tmpstr;
1210
1211 /* file name & path */
1212 tmpstr = g_path_get_basename(data->filename);
1213 gtk_label_set_text(GTK_LABEL(data->TX_filename), tmpstr);
1214 g_free(tmpstr);
1215
1216 tmpstr = g_path_get_dirname(data->filename);
1217 gtk_label_set_text(GTK_LABEL(data->TX_filepath), tmpstr);
1218 g_free(tmpstr);
1219
1220 gtk_label_set_text(GTK_LABEL(data->TX_encoding), ictx->encoding);
1221
1222 gtk_label_set_text(GTK_LABEL(data->TX_datefmt), CYA_IMPORT_DATEORDER[ictx->datefmt]);
1223
1224 /* file content detail */
1225 //TODO: difficult translation here
1226 tmpstr = g_strdup_printf(_("account: %d - transaction: %d - payee: %d - categorie: %d"),
1227 ictx->nb_src_acc,
1228 ictx->cnt_new_ope,
1229 ictx->cnt_new_pay,
1230 ictx->cnt_new_cat
1231 );
1232 gtk_label_set_text(GTK_LABEL(data->TX_filedetails), tmpstr);
1233 g_free(tmpstr);
1234
1235 DB( _import_context_debug(&data->ictx) );
1236
1237 }
1238
1239
1240 static void ui_import_panel_confirmation_fill(struct import_data *data)
1241 {
1242 ImportContext *ictx = &data->ictx;
1243
1244 /* account summary */
1245 ui_label_set_integer(GTK_LABEL(data->TX_acc_upd), data->imp_cnt_acc);
1246 ui_label_set_integer(GTK_LABEL(data->TX_acc_new), ictx->nb_src_acc - data->imp_cnt_acc);
1247
1248 /* transaction summary */
1249 ui_label_set_integer(GTK_LABEL(data->TX_trn_imp), data->imp_cnt_trn);
1250 ui_label_set_integer(GTK_LABEL(data->TX_trn_nop), ictx->cnt_new_ope - data->imp_cnt_trn);
1251 ui_label_set_integer(GTK_LABEL(data->TX_trn_asg), data->imp_cnt_asg);
1252
1253 }
1254
1255 static void
1256 ui_import_assistant_apply (GtkWidget *widget, gpointer user_data)
1257 {
1258 struct import_data *data;
1259
1260 DB( g_print("\n[import] apply\n") );
1261
1262 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1263
1264
1265 import_apply(data);
1266
1267 }
1268
1269 static void
1270 ui_import_assistant_close_cancel (GtkWidget *widget, gpointer user_data)
1271 {
1272 struct import_data *data;
1273 GtkWidget *assistant = (GtkWidget *) user_data;
1274
1275 DB( g_print("\n[import] close\n") );
1276
1277 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1278
1279 ui_import_assistant_dispose(widget, data);
1280
1281
1282 //g_free(data);
1283
1284
1285 gtk_widget_destroy (assistant);
1286 //assistant = NULL;
1287 }
1288
1289
1290 static void _import_tryload_file(struct import_data *data)
1291 {
1292 ImportContext *ictx = &data->ictx;
1293
1294 DB( g_print("\n[import] try load file\n") );
1295
1296 DB( g_print(" -> encoding='%s'\n", ictx->encoding) );
1297 DB( g_print(" -> date format='%s' (%d)\n", CYA_IMPORT_DATEORDER[ictx->datefmt], ictx->datefmt) );
1298
1299
1300 switch(data->filetype)
1301 {
1302 #ifndef NOOFX
1303 /* ofx_acc_list & ofx_ope_list are filled here */
1304 case FILETYPE_OFX:
1305 ictx->trans_list = homebank_ofx_import(data->filename, &data->ictx);
1306 break;
1307 #endif
1308 case FILETYPE_QIF:
1309 ictx->trans_list = homebank_qif_import(data->filename, &data->ictx);
1310 break;
1311
1312 case FILETYPE_CSV_HB:
1313 ictx->trans_list = homebank_csv_import(data->filename, &data->ictx);
1314 break;
1315 }
1316
1317 DB( g_print(" -> result: nbtrans=%d, date errors=%d\n", ictx->cnt_new_ope, ictx->cnt_err_date) );
1318
1319
1320 }
1321
1322
1323 static void import_file_import(struct import_data *data)
1324 {
1325 ImportContext *ictx = &data->ictx;
1326
1327 DB( g_print("\n[import] real import\n") );
1328
1329 import_clearall(data);
1330 ictx->encoding = homebank_file_getencoding(data->filename);
1331 _import_tryload_file(data);
1332
1333 // if fail, try to load with different date format
1334 if( ictx->cnt_err_date > 0)
1335 {
1336 const gchar *encoding = ictx->encoding;
1337 gint i;
1338
1339 for(i=0;i<NUM_PRF_DATEFMT;i++)
1340 {
1341 gboolean do_fix;
1342
1343 if(i != PREFS->dtex_datefmt) //don't reload with user pref date format
1344 {
1345 do_fix = ui_dialog_msg_question(
1346 GTK_WINDOW(data->assistant),
1347 _("Some date convertion failed"),
1348 _("Reload using date order: '%s' ?"),
1349 CYA_IMPORT_DATEORDER[i]
1350 );
1351
1352 if(do_fix == GTK_RESPONSE_YES)
1353 {
1354 DB( g_print(" fail, reload with '%s'\n", CYA_IMPORT_DATEORDER[i]) );
1355 //#1448549
1356 import_clearall(data);
1357 ictx->encoding = encoding; //#1425986 keep encoding with us
1358 ictx->datefmt = i;
1359 _import_tryload_file(data);
1360
1361 DB( g_print(" -> reloaded: nbtrans=%d, date errors=%d\n", ictx->cnt_new_ope, ictx->cnt_err_date) );
1362
1363 if(ictx->cnt_err_date == 0)
1364 break;
1365 }
1366
1367 }
1368 }
1369
1370 }
1371
1372 DB( g_print(" end of try import\n") );
1373
1374 // sort by date
1375 ictx->trans_list = da_transaction_sort(ictx->trans_list);
1376
1377 }
1378
1379 /**
1380 * ui_import_assistant_forward_page_func:
1381 *
1382 * define the page to be called when the user forward
1383 *
1384 * Return value: the page number
1385 *
1386 */
1387 static gint
1388 ui_import_assistant_forward_page_func(gint current_page, gpointer func_data)
1389 {
1390 gint next_page;
1391
1392 DB( g_print("---------------------------\n") );
1393 DB( g_print("\n[import] forward page func :: page %d\n", current_page) );
1394
1395 DB( g_print(" -> current: %d %s\n", current_page, page_titles[MIN(current_page, NUM_PAGE-1)] ) );
1396
1397 #ifdef MYDEBUG
1398 /*
1399 struct import_data *data = func_data;
1400 gint i
1401 for(i=0;i<NUM_PAGE;i++)
1402 {
1403 g_print("%d: %d '%s'\n", i,
1404 gtk_assistant_get_page_complete(GTK_ASSISTANT(data->assistant), data->pages[i]),
1405 page_titles[i]
1406 );
1407 }*/
1408 #endif
1409
1410 DB( g_print(" -> current: %d %s\n", current_page, page_titles[MIN(current_page, NUM_PAGE-1)] ) );
1411
1412 next_page = current_page + 1;
1413
1414 switch(current_page)
1415 {
1416 /*case PAGE_IMPORT:
1417 // if no new account, skip the account page
1418 if(ictx->nb_new_acc == 0)
1419 next_page = PAGE_TRANSACTION;
1420 break;*/
1421 }
1422
1423 DB( g_print(" -> next: %d %s\n", next_page, page_titles[MIN(next_page, NUM_PAGE-1)] ) );
1424
1425 return next_page;
1426 }
1427
1428
1429
1430
1431 static void
1432 ui_import_assistant_prepare (GtkWidget *widget, GtkWidget *page, gpointer user_data)
1433 {
1434 struct import_data *data;
1435 ImportContext *ictx;
1436 gint current_page, n_pages;
1437 gchar *title;
1438
1439 data = g_object_get_data(G_OBJECT(gtk_widget_get_ancestor(widget, GTK_TYPE_WINDOW)), "inst_data");
1440
1441 ictx = &data->ictx;
1442
1443 current_page = gtk_assistant_get_current_page (GTK_ASSISTANT(data->assistant));
1444 n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT(data->assistant));
1445
1446 DB( g_print("\n[import] prepare %d of %d\n", current_page, n_pages) );
1447
1448 switch( current_page )
1449 {
1450 case PAGE_WELCOME:
1451 DB( g_print(" -> 1 intro\n") );
1452 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1453 break;
1454
1455 case PAGE_SELECTFILE:
1456 DB( g_print(" -> 2 file choose\n") );
1457
1458 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, FALSE);
1459 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), data->pages[PAGE_ACCOUNT], FALSE);
1460 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), data->pages[PAGE_TRANSACTION], FALSE);
1461 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), data->pages[PAGE_CONFIRM], FALSE);
1462
1463 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(data->filechooser), PREFS->path_import);
1464 DB( g_print(" -> set current folder '%s'\n", PREFS->path_import) );
1465
1466 // the page complete is contextual in ui_import_panel_filechooser_selection_changed
1467 break;
1468
1469 case PAGE_IMPORT:
1470 DB( g_print(" -> 3 real import\n") );
1471
1472 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, FALSE);
1473 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), data->pages[PAGE_ACCOUNT], FALSE);
1474
1475 /* remind folder to preference */
1476 gchar *folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(data->filechooser));
1477 DB( g_print(" -> store folder '%s'\n", folder) );
1478 g_free(PREFS->path_import);
1479 PREFS->path_import = folder;
1480
1481 import_file_import(data);
1482 _import_context_count(data);
1483
1484 if( ictx->cnt_new_ope > 0 && ictx->cnt_err_date <= 0 )
1485 {
1486 if(ictx->nb_new_acc == 0)
1487 {
1488 DB( g_print(" -> jump to Transaction page\n") );
1489 //gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), data->pages[PAGE_ACCOUNT], TRUE);
1490 gtk_assistant_next_page(GTK_ASSISTANT(data->assistant));
1491 gtk_assistant_next_page(GTK_ASSISTANT(data->assistant));
1492 gtk_assistant_next_page(GTK_ASSISTANT(data->assistant));
1493 //gtk_assistant_set_current_page (GTK_ASSISTANT(data->assistant), PAGE_TRANSACTION);
1494 }
1495 else
1496 {
1497 DB( g_print(" -> jump to Account page\n") );
1498 //gtk_assistant_set_current_page (GTK_ASSISTANT(data->assistant), PAGE_ACCOUNT);
1499 gtk_assistant_next_page(GTK_ASSISTANT(data->assistant));
1500 gtk_assistant_next_page(GTK_ASSISTANT(data->assistant));
1501 }
1502
1503 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1504 }
1505 break;
1506
1507 case PAGE_PROPERTIES:
1508 DB( g_print(" -> 4 properties\n") );
1509
1510
1511 ui_import_panel_properties_fill(data);
1512
1513 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1514 break;
1515
1516 case PAGE_ACCOUNT:
1517 DB( g_print(" -> 5 account\n") );
1518
1519 ui_import_panel_account_fill(data);
1520
1521 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1522 break;
1523
1524 case PAGE_TRANSACTION:
1525 DB( g_print(" -> 6 transaction\n") );
1526
1527 //todo: should be optional
1528 data->imp_cnt_asg = transaction_auto_assign(ictx->trans_list, 0);
1529
1530 ui_import_panel_transaction_find_duplicate(data);
1531
1532 ui_import_panel_transaction_fill(data);
1533
1534 if( ictx->nb_duplicate > 0 )
1535 {
1536 gtk_widget_show(data->GR_duplicate);
1537 gtk_expander_set_expanded(GTK_EXPANDER(data->GR_duplicate), TRUE);
1538 }
1539 else
1540 {
1541 gtk_widget_hide(data->GR_duplicate);
1542 }
1543
1544 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1545 break;
1546
1547 case PAGE_CONFIRM:
1548 {
1549 DB( g_print(" -> 7 confirmation\n") );
1550
1551 //todo:rework this
1552 import_count_changes(data);
1553
1554 ui_import_panel_confirmation_fill(data);
1555
1556
1557
1558 gtk_assistant_set_page_complete (GTK_ASSISTANT(data->assistant), page, TRUE);
1559 break;
1560 }
1561 }
1562
1563 title = g_strdup_printf ( _("Import assistant (%d of %d)"), current_page + 1 , n_pages );
1564 gtk_window_set_title (GTK_WINDOW (data->assistant), title);
1565 g_free (title);
1566 }
1567
1568
1569
1570
1571
1572
1573 static void
1574 ui_import_panel_transaction_refresh (GtkWidget *widget, gpointer data)
1575 {
1576
1577 DB( g_print("\n[import] refresh transaction\n") );
1578
1579 ui_import_panel_transaction_find_duplicate(data);
1580 ui_import_panel_transaction_fill(data);
1581
1582 }
1583
1584
1585 static void ui_acc_affect_listview_onRowActivated (GtkTreeView *treeview,
1586 GtkTreePath *path,
1587 GtkTreeViewColumn *col,
1588 gpointer userdata)
1589 {
1590 //GtkTreeModel *model;
1591
1592 //model = gtk_tree_view_get_model(treeview);
1593 //gtk_tree_model_get_iter_first(model, &iter);
1594 //if(gtk_tree_selection_iter_is_selected(gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)), &iter) == FALSE)
1595 //{
1596 ui_import_panel_account_change_action(GTK_WIDGET(treeview), NULL);
1597 //}
1598 }
1599
1600
1601 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
1602
1603
1604 static GtkWidget *
1605 ui_import_panel_welcome_create(GtkWidget *assistant, struct import_data *data)
1606 {
1607 GtkWidget *vbox, *label, *align;
1608
1609 align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
1610 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 0, 0, 0);
1611
1612 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
1613 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
1614 gtk_container_add(GTK_CONTAINER(align), vbox);
1615
1616 label = make_label(
1617 _("Welcome to the HomeBank Import Assistant.\n\n" \
1618 "With this assistant you will be guided throught the process\n" \
1619 "of importing an external file into HomeBank.\n\n" \
1620 "No changes will be made until you click \"Apply\" at the end\n" \
1621 "of this assistant.")
1622 , 0., 0.0);
1623 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, SPACING_SMALL);
1624
1625 /* supported format */
1626
1627
1628 label = make_label(
1629 _("HomeBank can import files in the following formats:\n" \
1630 "- QIF\n" \
1631 "- OFX/QFX (optional at compilation time)\n" \
1632 "- CSV (format is specific to HomeBank, see the documentation)\n" \
1633 ), 0.0, 0.0);
1634
1635 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, SPACING_SMALL);
1636
1637
1638 gtk_widget_show_all (align);
1639
1640 gtk_assistant_append_page (GTK_ASSISTANT (assistant), align);
1641 gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), align, GTK_ASSISTANT_PAGE_INTRO);
1642 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), align, _(page_titles[PAGE_WELCOME]));
1643 //gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), align, TRUE);
1644
1645 return align;
1646 }
1647
1648
1649 static GtkWidget *
1650 ui_import_panel_filechooser_create (GtkWidget *assistant, struct import_data *data)
1651 {
1652 GtkWidget *vbox, *hbox, *align, *widget, *label;
1653 GtkFileFilter *filter;
1654
1655 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
1656 //gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
1657
1658
1659 // widget = gtk_file_chooser_button_new ("Pick a File", GTK_FILE_CHOOSER_ACTION_OPEN);
1660
1661 widget = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
1662
1663
1664
1665 data->filechooser = widget;
1666 gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0);
1667
1668 filter = gtk_file_filter_new ();
1669 gtk_file_filter_set_name (filter, _("Known files"));
1670 gtk_file_filter_add_pattern (filter, "*.[Qq][Ii][Ff]");
1671 #ifndef NOOFX
1672 gtk_file_filter_add_pattern (filter, "*.[OoQq][Ff][Xx]");
1673 #endif
1674 gtk_file_filter_add_pattern (filter, "*.[Cc][Ss][Vv]");
1675 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
1676 if(data->filetype == FILETYPE_UNKNOW)
1677 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(widget), filter);
1678
1679 filter = gtk_file_filter_new ();
1680 gtk_file_filter_set_name (filter, _("QIF files"));
1681 gtk_file_filter_add_pattern (filter, "*.[Qq][Ii][Ff]");
1682 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
1683 if(data->filetype == FILETYPE_QIF)
1684 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(widget), filter);
1685
1686 #ifndef NOOFX
1687 filter = gtk_file_filter_new ();
1688 gtk_file_filter_set_name (filter, _("OFX/QFX files"));
1689 gtk_file_filter_add_pattern (filter, "*.[OoQq][Ff][Xx]");
1690 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
1691 if(data->filetype == FILETYPE_OFX)
1692 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(widget), filter);
1693 #endif
1694
1695 filter = gtk_file_filter_new ();
1696 gtk_file_filter_set_name (filter, _("CSV files"));
1697 gtk_file_filter_add_pattern (filter, "*.[Cc][Ss][Vv]");
1698 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
1699 if(data->filetype == FILETYPE_CSV_HB)
1700 gtk_file_chooser_set_filter (GTK_FILE_CHOOSER(widget), filter);
1701
1702
1703 filter = gtk_file_filter_new ();
1704 gtk_file_filter_set_name (filter, _("All files"));
1705 gtk_file_filter_add_pattern (filter, "*");
1706 gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(widget), filter);
1707
1708
1709 /* our addon message */
1710 align = gtk_alignment_new(0.65, 0, 0, 0);
1711 gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 0);
1712
1713 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
1714 gtk_container_add(GTK_CONTAINER(align), hbox);
1715
1716 label = gtk_label_new("");
1717 data->user_info = label;
1718 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, SPACING_SMALL);
1719
1720 gimp_label_set_attributes (GTK_LABEL (label),
1721 PANGO_ATTR_SCALE, PANGO_SCALE_LARGE,
1722 PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
1723 -1);
1724
1725
1726
1727 widget = gtk_image_new_from_icon_name(ICONNAME_HB_FILE_VALID, GTK_ICON_SIZE_LARGE_TOOLBAR);
1728 data->ok_image = widget;
1729 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1730
1731 widget = gtk_image_new_from_icon_name(ICONNAME_HB_FILE_INVALID, GTK_ICON_SIZE_LARGE_TOOLBAR);
1732 data->ko_image = widget;
1733 gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
1734
1735
1736 gtk_widget_show_all (vbox);
1737 gtk_widget_hide(data->ok_image);
1738 gtk_widget_hide(data->ko_image);
1739
1740
1741 gtk_assistant_append_page (GTK_ASSISTANT (assistant), vbox);
1742 //gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), vbox, GTK_ASSISTANT_PAGE_CONTENT);
1743 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), vbox, _(page_titles[PAGE_SELECTFILE]));
1744
1745
1746
1747 return vbox;
1748 }
1749
1750
1751 static GtkWidget *
1752 ui_import_panel_import_create (GtkWidget *assistant, struct import_data *data)
1753 {
1754 GtkWidget *align, *content_grid;
1755 GtkWidget *label, *widget;
1756 gchar *txt;
1757
1758 align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
1759
1760 content_grid = gtk_grid_new();
1761 gtk_grid_set_column_spacing (GTK_GRID (content_grid), SPACING_MEDIUM);
1762 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
1763 gtk_container_add(GTK_CONTAINER(align), content_grid);
1764
1765 widget = gtk_image_new_from_icon_name(ICONNAME_ERROR, GTK_ICON_SIZE_DIALOG );
1766 gtk_grid_attach (GTK_GRID (content_grid), widget, 0, 0, 1, 1);
1767
1768 txt = _("A general error occured, and this file cannot be loaded.");
1769 label = gtk_label_new(txt);
1770 gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
1771 gtk_grid_attach (GTK_GRID (content_grid), label, 1, 0, 1, 1);
1772
1773 gtk_widget_show_all (align);
1774 gtk_assistant_append_page (GTK_ASSISTANT (assistant), align);
1775 //gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), align, GTK_ASSISTANT_PAGE_PROGRESS);
1776 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), align, _(page_titles[PAGE_IMPORT]));
1777
1778 return align;
1779 }
1780
1781
1782
1783 static GtkWidget *
1784 ui_import_panel_properties_create (GtkWidget *assistant, struct import_data *data)
1785 {
1786 GtkWidget *content_grid, *group_grid;
1787 GtkWidget *label, *widget;
1788 gint crow, row;
1789
1790 content_grid = gtk_grid_new();
1791 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
1792 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
1793
1794 crow = 0;
1795 // group :: File properties
1796 group_grid = gtk_grid_new ();
1797 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1798 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1799 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1800
1801 label = make_label_group(_("File properties"));
1802 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
1803
1804 row = 1;
1805 label = make_label(_("Name:"), 0.0, 0.5);
1806 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1807 widget = make_label(NULL, 0.0, 0.5);
1808 data->TX_filename = widget;
1809 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1810
1811 row++;
1812 label = make_label(_("Path:"), 0.0, 0.5);
1813 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1814 widget = make_label(NULL, 0.0, 0.5);
1815 data->TX_filepath = widget;
1816 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1817
1818 row++;
1819 label = make_label(_("Encoding:"), 0.0, 0.5);
1820 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1821 widget = make_label(NULL, 0.0, 0.5);
1822 data->TX_encoding = widget;
1823 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1824
1825 row++;
1826 label = make_label(_("Date format:"), 0.0, 0.5);
1827 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1828 widget = make_label(NULL, 0.0, 0.5);
1829 data->TX_datefmt = widget;
1830 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1831
1832 // group :: File content
1833 group_grid = gtk_grid_new ();
1834 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1835 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1836 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1837
1838 label = make_label_group(_("File content"));
1839 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
1840
1841 row = 1;
1842 label = make_label(_("Content:"), 0.0, 0.5);
1843 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 1, 1);
1844 widget = make_label(NULL, 0.0, 0.5);
1845 data->TX_filedetails = widget;
1846 gtk_grid_attach (GTK_GRID (group_grid), widget, 2, row, 1, 1);
1847
1848 /*
1849 expander = gtk_expander_new (_("File content"));
1850 gtk_box_pack_start (GTK_BOX (container), expander, TRUE, TRUE, 0);
1851 scrollwin = gtk_scrolled_window_new(NULL,NULL);
1852 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1853 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
1854 widget = gtk_text_view_new ();
1855 gtk_container_add(GTK_CONTAINER(scrollwin), widget);
1856 gtk_container_add(GTK_CONTAINER(expander), scrollwin);
1857 */
1858
1859
1860 gtk_widget_show_all (content_grid);
1861
1862 gtk_assistant_append_page (GTK_ASSISTANT (assistant), content_grid);
1863 //set page type to intro to avoid going back once that point over
1864 gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), content_grid, GTK_ASSISTANT_PAGE_INTRO);
1865 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), content_grid, _(page_titles[PAGE_PROPERTIES]));
1866
1867 return content_grid;
1868 }
1869
1870
1871 static GtkWidget *
1872 ui_import_panel_account_create (GtkWidget *assistant, struct import_data *data)
1873 {
1874 GtkWidget *content_grid, *group_grid;
1875 GtkWidget *label, *widget, *scrollwin;
1876 gint crow, row;
1877
1878 content_grid = gtk_grid_new();
1879 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
1880 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
1881
1882 crow = 0;
1883 // group :: Title
1884 group_grid = gtk_grid_new ();
1885
1886 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1887 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1888 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1889
1890 //label = make_label_group(_("Title"));
1891 //gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 2, 1);
1892
1893 row = 1;
1894 widget = gtk_image_new ();
1895 data->IM_acc = widget;
1896 gtk_widget_set_valign(widget, GTK_ALIGN_START);
1897 gtk_grid_attach (GTK_GRID (group_grid), widget, 0, row, 1, 1);
1898 label = make_label(NULL, 0, 0.5);
1899 data->LB_acc = label;
1900 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 2, 1);
1901
1902 // group :: Account list
1903 group_grid = gtk_grid_new ();
1904 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1905 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1906 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1907
1908 label = make_label_group(_("Choose the action for accounts"));
1909 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 1, 1);
1910
1911 row = 1;
1912 scrollwin = gtk_scrolled_window_new(NULL,NULL);
1913 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1914 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
1915 gtk_widget_set_size_request(scrollwin, -1, HB_MINWIDTH_LIST);
1916
1917 widget = ui_acc_affect_listview_new();
1918 data->LV_acc = widget;
1919 gtk_container_add(GTK_CONTAINER(scrollwin), widget);
1920 gtk_widget_set_hexpand(scrollwin, TRUE);
1921 gtk_grid_attach (GTK_GRID (group_grid), scrollwin, 0, row, 1, 1);
1922
1923 row++;
1924 widget = gtk_button_new_with_mnemonic (_("Change _action"));
1925 data->BT_edit = widget;
1926 gtk_widget_set_halign(widget, GTK_ALIGN_START);
1927 gtk_grid_attach (GTK_GRID (group_grid), widget, 0, row, 1, 1);
1928
1929 /* signal and other stuff */
1930 g_signal_connect (G_OBJECT (data->BT_edit), "clicked", G_CALLBACK (ui_import_panel_account_change_action), data);
1931 g_signal_connect (GTK_TREE_VIEW(data->LV_acc), "row-activated", G_CALLBACK (ui_acc_affect_listview_onRowActivated), NULL);
1932
1933 gtk_widget_show_all (content_grid);
1934 gtk_assistant_append_page (GTK_ASSISTANT (assistant), content_grid);
1935 //gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), content_grid, GTK_ASSISTANT_PAGE_INTRO);
1936 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), content_grid, _(page_titles[PAGE_ACCOUNT]));
1937
1938 return content_grid;
1939 }
1940
1941
1942 static GtkWidget *
1943 ui_import_panel_transaction_create (GtkWidget *assistant, struct import_data *data)
1944 {
1945 GtkWidget *content_grid, *group_grid;
1946 GtkWidget *label, *scrollwin, *widget, *expander;
1947 gint crow, row;
1948
1949 content_grid = gtk_grid_new();
1950 gtk_grid_set_row_spacing (GTK_GRID (content_grid), SPACING_LARGE);
1951 gtk_orientable_set_orientation(GTK_ORIENTABLE(content_grid), GTK_ORIENTATION_VERTICAL);
1952
1953 crow = 0;
1954 // group :: Title
1955 group_grid = gtk_grid_new ();
1956 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1957 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1958 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1959
1960 //label = make_label_group(_("Title"));
1961 //gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 3, 1);
1962
1963 row = 1;
1964 widget = gtk_image_new ();
1965 data->IM_txn = widget;
1966 gtk_widget_set_valign(widget, GTK_ALIGN_START);
1967 gtk_grid_attach (GTK_GRID (group_grid), widget, 0, row, 1, 1);
1968 label = make_label(NULL, 0, 0.5);
1969 data->LB_txn = label;
1970 gtk_grid_attach (GTK_GRID (group_grid), label, 1, row, 2, 1);
1971
1972 // group :: Transactions to import
1973 group_grid = gtk_grid_new ();
1974 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1975 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1976 gtk_grid_attach (GTK_GRID (content_grid), group_grid, 0, crow++, 1, 1);
1977
1978 label = make_label_group(_("Choose transactions to import"));
1979 gtk_grid_attach (GTK_GRID (group_grid), label, 0, 0, 2, 1);
1980
1981 row = 1;
1982 scrollwin = gtk_scrolled_window_new (NULL, NULL);
1983 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
1984 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1985 gtk_widget_set_hexpand(scrollwin, TRUE);
1986 gtk_widget_set_vexpand(scrollwin, TRUE);
1987 widget = create_list_import_transaction(TRUE);
1988 data->imported_ope = widget;
1989 gtk_container_add (GTK_CONTAINER (scrollwin), widget);
1990 gtk_grid_attach (GTK_GRID (group_grid), scrollwin, 0, row, 2, 1);
1991
1992 expander = gtk_expander_new (_("Detail of existing transaction (possible duplicate)"));
1993 data->GR_duplicate = expander;
1994 gtk_grid_attach (GTK_GRID (group_grid), expander, 0, crow++, 2, 1);
1995
1996 group_grid = gtk_grid_new ();
1997 gtk_grid_set_row_spacing (GTK_GRID (group_grid), SPACING_SMALL);
1998 gtk_grid_set_column_spacing (GTK_GRID (group_grid), SPACING_MEDIUM);
1999 gtk_container_add (GTK_CONTAINER (expander), group_grid);
2000
2001 row = 0;
2002 scrollwin = gtk_scrolled_window_new (NULL, NULL);
2003 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollwin), GTK_SHADOW_ETCHED_IN);
2004 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2005 gtk_widget_set_hexpand(scrollwin, TRUE);
2006 //widget = create_list_transaction(LIST_TXN_TYPE_IMPORT, list_imptxn_columns);
2007 widget = create_list_import_transaction(FALSE);
2008 data->duplicat_ope = widget;
2009 gtk_container_add (GTK_CONTAINER (scrollwin), widget);
2010 gtk_widget_set_size_request(scrollwin, -1, HB_MINWIDTH_LIST/2);
2011 gtk_grid_attach (GTK_GRID (group_grid), scrollwin, 0, row, 6, 1);
2012
2013 row++;
2014 label = make_label(_("Date _tolerance:"), 0, 0.5);
2015 gtk_grid_attach (GTK_GRID (group_grid), label, 0, row, 1, 1);
2016
2017 widget = make_numeric(label, 0.0, 14.0);
2018 data->NB_maxgap = widget;
2019 gtk_grid_attach (GTK_GRID (group_grid), widget, 1, row, 1, 1);
2020
2021 //TRANSLATORS: there is a spinner on the left of this label, and so you have 0....x days of date tolerance
2022 label = make_label(_("days"), 0, 0.5);
2023 gtk_grid_attach (GTK_GRID (group_grid), label, 2, row, 1, 1);
2024
2025 widget = gtk_button_new_with_mnemonic (_("_Refresh"));
2026 gtk_grid_attach (GTK_GRID (group_grid), widget, 3, row, 1, 1);
2027 g_signal_connect (widget, "clicked",
2028 G_CALLBACK (ui_import_panel_transaction_refresh), data);
2029
2030 widget = gtk_image_new_from_icon_name(ICONNAME_INFO, GTK_ICON_SIZE_SMALL_TOOLBAR );
2031 gtk_widget_set_hexpand(widget, FALSE);
2032 gtk_grid_attach (GTK_GRID (group_grid), widget, 4, row, 1, 1);
2033
2034 label = make_label (_(
2035 "The match is done in order: by account, amount and date.\n" \
2036 "A date tolerance of 0 day means an exact match"), 0, 0.5);
2037 gimp_label_set_attributes (GTK_LABEL (label),
2038 PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
2039 -1);
2040 gtk_widget_set_hexpand(label, TRUE);
2041 gtk_grid_attach (GTK_GRID (group_grid), label, 5, row, 1, 1);
2042
2043
2044 gtk_widget_show_all (content_grid);
2045
2046 gtk_assistant_append_page (GTK_ASSISTANT (assistant), content_grid);
2047 // gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), content_grid, GTK_ASSISTANT_PAGE_PROGRESS);
2048 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), content_grid, _(page_titles[PAGE_TRANSACTION]));
2049
2050 return content_grid;
2051 }
2052
2053
2054 static GtkWidget *
2055 ui_import_panel_confirmation_create(GtkWidget *assistant, struct import_data *data)
2056 {
2057 GtkWidget *vbox, *label, *align, *widget, *table;
2058 gint row;
2059
2060 align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
2061 gtk_alignment_set_padding(GTK_ALIGNMENT(align), 0, 0, 0, 0);
2062
2063 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, SPACING_SMALL);
2064 gtk_container_set_border_width (GTK_CONTAINER(vbox), SPACING_MEDIUM);
2065 gtk_container_add(GTK_CONTAINER(align), vbox);
2066
2067 label = make_label(
2068 _("Click \"Apply\" to update your accounts.\n"), 0.5, 0.5);
2069 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
2070
2071 /* the summary */
2072 table = gtk_grid_new ();
2073 gtk_container_set_border_width (GTK_CONTAINER (table), SPACING_SMALL);
2074 gtk_grid_set_row_spacing (GTK_GRID (table), SPACING_SMALL/2);
2075 gtk_grid_set_column_spacing (GTK_GRID (table), SPACING_MEDIUM);
2076 gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
2077
2078 row = 0;
2079 label = make_label(_("Accounts"), 0.0, 0.5);
2080 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
2081 gtk_grid_attach (GTK_GRID (table), label, 0, row, 3, 1);
2082
2083 /* acc update */
2084 row++;
2085 label = make_label(NULL, 0.0, 0.5);
2086 //gtk_misc_set_padding (GTK_MISC (label), SPACING_SMALL, 0);
2087 gtk_grid_attach (GTK_GRID (table), label, 0, row, 1, 1);
2088 widget = make_label(NULL, 1.0, 0.5);
2089 data->TX_acc_upd = widget;
2090 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
2091 label = make_label(_("to update"), 0.0, 0.5);
2092 gtk_grid_attach (GTK_GRID (table), label, 2, row, 1, 1);
2093
2094 /* acc create */
2095 row++;
2096 widget = make_label(NULL, 1.0, 0.5);
2097 data->TX_acc_new = widget;
2098 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
2099 label = make_label(_("to create"), 0.0, 0.5);
2100 gtk_grid_attach (GTK_GRID (table), label, 2, row, 1, 1);
2101
2102 row++;
2103 label = make_label(_("Transactions"), 0.0, 0.5);
2104 gimp_label_set_attributes(GTK_LABEL(label), PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD, -1);
2105 gtk_grid_attach (GTK_GRID (table), label, 0, row, 3, 1);
2106
2107 /* trn import */
2108 row++;
2109 widget = make_label(NULL, 1.0, 0.5);
2110 data->TX_trn_imp = widget;
2111 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
2112 label = make_label(_("to import"), 0.0, 0.5);
2113 gtk_grid_attach (GTK_GRID (table), label, 2, row, 1, 1);
2114
2115 /* trn reject */
2116 row++;
2117 widget = make_label(NULL, 1.0, 0.5);
2118 data->TX_trn_nop = widget;
2119 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
2120 label = make_label(_("to reject"), 0.0, 0.5);
2121 gtk_grid_attach (GTK_GRID (table), label, 2, row, 1, 1);
2122
2123 /* trn auto-assigned */
2124 row++;
2125 widget = make_label(NULL, 1.0, 0.5);
2126 data->TX_trn_asg = widget;
2127 gtk_grid_attach (GTK_GRID (table), widget, 1, row, 1, 1);
2128 label = make_label(_("auto-assigned"), 0.0, 0.5);
2129 gtk_grid_attach (GTK_GRID (table), label, 2, row, 1, 1);
2130
2131
2132 gtk_widget_show_all (align);
2133
2134 gtk_assistant_append_page (GTK_ASSISTANT (assistant), align);
2135 gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), align, GTK_ASSISTANT_PAGE_CONFIRM);
2136 //gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), label, TRUE);
2137 gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), align, _(page_titles[PAGE_CONFIRM]));
2138
2139 return align;
2140 }
2141
2142
2143 /* starting point of import */
2144 GtkWidget *ui_import_assistant_new (gint filetype)
2145 {
2146 struct import_data *data;
2147 GtkWidget *assistant;
2148 gint w, h, pos;
2149
2150 data = g_malloc0(sizeof(struct import_data));
2151 if(!data) return NULL;
2152
2153 data->filetype = filetype;
2154
2155 assistant = gtk_assistant_new ();
2156 data->assistant = assistant;
2157
2158 //store our window private data
2159 g_object_set_data(G_OBJECT(assistant), "inst_data", (gpointer)data);
2160 //DB( g_print("** \n[import] window=%x, inst_data=%x\n", assistant, data) );
2161
2162
2163 gtk_window_set_modal(GTK_WINDOW (assistant), TRUE);
2164 gtk_window_set_transient_for(GTK_WINDOW(assistant), GTK_WINDOW(GLOBALS->mainwindow));
2165
2166 //set a nice dialog size
2167 gtk_window_get_size(GTK_WINDOW(GLOBALS->mainwindow), &w, &h);
2168 gtk_window_set_default_size (GTK_WINDOW(assistant), w*0.8, h*0.8);
2169
2170
2171 pos = 0;
2172 data->pages[pos++] = ui_import_panel_welcome_create (assistant, data);
2173 data->pages[pos++] = ui_import_panel_filechooser_create (assistant, data);
2174 data->pages[pos++] = ui_import_panel_import_create (assistant, data);
2175 data->pages[pos++] = ui_import_panel_properties_create (assistant, data);
2176 data->pages[pos++] = ui_import_panel_account_create (assistant, data);
2177 data->pages[pos++] = ui_import_panel_transaction_create (assistant, data);
2178 data->pages[pos++] = ui_import_panel_confirmation_create (assistant, data);
2179
2180 gtk_assistant_set_forward_page_func(GTK_ASSISTANT(assistant), ui_import_assistant_forward_page_func, data, NULL);
2181
2182 //setup
2183
2184 ui_import_panel_filechooser_selection_changed(assistant, data);
2185
2186 //connect all our signals
2187 //g_signal_connect (window, "delete-event", G_CALLBACK (hbfile_dispose), (gpointer)data);
2188
2189 g_signal_connect (G_OBJECT (assistant), "cancel", G_CALLBACK (ui_import_assistant_close_cancel), assistant);
2190
2191 g_signal_connect (G_OBJECT (assistant), "close", G_CALLBACK (ui_import_assistant_close_cancel), assistant);
2192
2193 g_signal_connect (G_OBJECT (assistant), "apply", G_CALLBACK (ui_import_assistant_apply), NULL);
2194
2195 g_signal_connect (G_OBJECT (assistant), "prepare", G_CALLBACK (ui_import_assistant_prepare), NULL);
2196
2197 g_signal_connect (G_OBJECT (data->filechooser), "selection-changed",
2198 G_CALLBACK (ui_import_panel_filechooser_selection_changed), (gpointer)data);
2199
2200 g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(data->imported_ope)), "changed",
2201 G_CALLBACK (ui_import_panel_transaction_fill_same), NULL);
2202
2203 gtk_widget_show (assistant);
2204
2205 gtk_assistant_set_page_complete (GTK_ASSISTANT(assistant), data->pages[PAGE_WELCOME], TRUE );
2206 gtk_assistant_set_current_page(GTK_ASSISTANT(assistant), PAGE_SELECTFILE);
2207
2208 return assistant;
2209 }
2210
2211
2212
2213
This page took 0.188223 seconds and 5 git commands to generate.