diff --git a/src/import-export/hbci/gnc-hbci-gettrans.c b/src/import-export/hbci/gnc-hbci-gettrans.c index dd8e8f04ad..6b97818e6c 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.c +++ b/src/import-export/hbci/gnc-hbci-gettrans.c @@ -46,13 +46,7 @@ gboolean gettrans_dates(GtkWidget *parent, Account *gnc_acc, GWEN_TIME **from_date, GWEN_TIME **to_date); -static AB_TRANSACTION *trans_list_cb(AB_TRANSACTION *reportn, void *user_data); -struct trans_list_data -{ - Account *gnc_acc; - GNCImportMainMatcher *importer_generic; -}; void @@ -233,7 +227,7 @@ gnc_hbci_import_final(GtkWidget *parent, data.importer_generic = importer_generic_gui; data.gnc_acc = gnc_acc; - AB_Transaction_List2_ForEach (trans_list, trans_list_cb, &data); + AB_Transaction_List2_ForEach (trans_list, gnc_hbci_trans_list_cb, &data); if (run_until_done) return gnc_gen_trans_list_run (importer_generic_gui); @@ -243,7 +237,7 @@ gnc_hbci_import_final(GtkWidget *parent, /* list_AB_TRANSACTION_foreach callback. The Conversion from HBCI to GNC transaction is done here, once for each AB_TRANSACTION. */ -static AB_TRANSACTION *trans_list_cb(AB_TRANSACTION *h_trans, void *user_data) +AB_TRANSACTION *gnc_hbci_trans_list_cb(AB_TRANSACTION *h_trans, void *user_data) { time_t current_time; /* time_t tt1, tt2; */ diff --git a/src/import-export/hbci/gnc-hbci-gettrans.h b/src/import-export/hbci/gnc-hbci-gettrans.h index 9bd47e828e..5532256a7f 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.h +++ b/src/import-export/hbci/gnc-hbci-gettrans.h @@ -24,6 +24,8 @@ #define GNC_HBCI_GETTRANS_H #include + +#include "import-main-matcher.h" #include "Account.h" /** Start a GetTrans job. */ @@ -46,5 +48,17 @@ gnc_hbci_import_final(GtkWidget *parent, AB_TRANSACTION_LIST2 *trans_list, gboolean run_until_done); +/** user_data struct for the gnc_hbci_trans_list_cb() structure */ +struct trans_list_data +{ + Account *gnc_acc; + GNCImportMainMatcher *importer_generic; +}; + +/** AB_TRANSACTION_LIST2_foreach callback. The Conversion from HBCI to + GNC transaction is done here, once for each AB_TRANSACTION. */ +AB_TRANSACTION *gnc_hbci_trans_list_cb(AB_TRANSACTION *imported_trans, + void *user_data); + #endif /* GNC_HBCI_GETTRANS_H */ diff --git a/src/import-export/mt940/Makefile.am b/src/import-export/mt940/Makefile.am index 0e5b6223f6..3e59a02a25 100644 --- a/src/import-export/mt940/Makefile.am +++ b/src/import-export/mt940/Makefile.am @@ -14,10 +14,16 @@ noinst_HEADERS = \ libgncmod_mt940_la_LIBADD = \ ${top_builddir}/src/gnc-module/libgncmodule.la \ + ${top_builddir}/src/core-utils/libcore-utils.la \ ${top_builddir}/src/engine/libgncmod-engine.la \ ${top_builddir}/src/import-export/libgncmod-generic-import.la \ + ${top_builddir}/src/import-export/hbci/libgncmod-hbci.la \ + ${top_builddir}/src/gnome/libgncgnome.la \ + ${GNOME_LIBS} \ + ${GLADE_LIBS} \ + ${QOF_LIBS} \ ${GLIB_LIBS} \ - $(HBCI_LIBS) + ${HBCI_LIBS} AM_CFLAGS = \ -I${top_srcdir}/src \ @@ -28,12 +34,14 @@ AM_CFLAGS = \ -I${top_srcdir}/src/gnome-utils \ -I${top_srcdir}/src/import-export \ -I$(top_srcdir)/src/import-export/hbci \ + ${G_WRAP_COMPILE_ARGS} \ ${GUILE_INCS} \ - ${GLIB_CFLAGS} \ - ${GLADE_CFLAGS} \ ${GNOME_CFLAGS} \ ${GTKHTML_CFLAGS} \ - $(HBCI_CFLAGS) + ${GLADE_CFLAGS} \ + ${QOF_CFLAGS} \ + ${GLIB_CFLAGS} \ + ${HBCI_CFLAGS} uidir = $(GNC_UI_DIR) ui_DATA = \ diff --git a/src/import-export/mt940/gnc-mt940-import.c b/src/import-export/mt940/gnc-mt940-import.c index 35652f6aae..32a9c60fa1 100644 --- a/src/import-export/mt940/gnc-mt940-import.c +++ b/src/import-export/mt940/gnc-mt940-import.c @@ -35,18 +35,20 @@ #include -#include "gnc-hbci-gettrans.h" -#include "import-account-matcher.h" -#include "import-main-matcher.h" - -#include "Account.h" +#include "gnc-ui.h" +#include "qof.h" #include "Transaction.h" +#include "Account.h" #include "gnc-engine.h" #include "gnc-file.h" #include "gnc-ui-util.h" -#include "gnc-gconf-utils.h" -#include "gnc-hbci-utils.h" + +#include "gnc-hbci-gettrans.h" + +#include "import-main-matcher.h" +#include "import-account-matcher.h" +#include "gnc-hbci-gettrans.h" #include "gnc-mt940-import.h" @@ -54,9 +56,6 @@ static QofLogModule log_module = GNC_MOD_IMPORT; -static void *trans_importer_cb (const HBCI_Transaction *h_trans, - void *user_data); - /* Note: This file is broken. See http://bugzilla.gnome.org/show_bug.cgi?id=325170 . The patch from @@ -88,115 +87,109 @@ void gnc_file_mt940_import (void) GNC_FILE_DIALOG_IMPORT); g_free(default_dir); - if(selected_filename!=NULL) + if(selected_filename!=NULL) { + /* Remember the directory as the default. */ + gnc_extract_directory(&default_dir, selected_filename); + gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL); + g_free(default_dir); + + /*strncpy(file,selected_filename, 255);*/ + DEBUG("Filename found: %s",selected_filename); + + /* Create the Generic transaction importer GUI. */ + gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE); + + DEBUG("Opening selected file"); + mt940_file = fopen(selected_filename, "r"); + { - /* Remember the directory as the default. */ - gnc_extract_directory(&default_dir, selected_filename); - gnc_gconf_set_string(GCONF_SECTION, KEY_LAST_PATH, default_dir, NULL); - g_free(default_dir); + int result; + AB_BANKING *tr; + AB_IMEXPORTER *importer; + AB_IMEXPORTER_CONTEXT *ctx=0; + GWEN_BUFFEREDIO *buffio; + const list_HBCI_Transaction *transactions; + /*list_HBCI_Transaction_iter *iter;*/ - /*strncpy(file,selected_filename, 255);*/ - DEBUG("Filename found: %s",selected_filename); + tr=AB_Banking_new(); + /* get import module */ + importer=AB_Banking_GetImExporter(tr, "swift"); /* possible values: csv, swift, dtaus, */ + if (!importer) { + DEBUG("Import module swift not found"); + } - /* Create the Generic transaction importer GUI. */ - gnc_mt940_importer_gui = gnc_gen_trans_list_new(NULL, NULL, FALSE); + /* load the import profile */ + //dbProfiles=AB_Banking_GetImExporterProfiles(tr, "swift"); + dbProfile="default"; - DEBUG("Opening selected file"); - mt940_file = fopen(selected_filename, "r"); + /* import new context */ + ctx=AB_ImExporterContext_new(); - fseek(mt940_file,0,SEEK_END); - unsigned long filesize=ftell(mt940_file); - rewind(mt940_file); + /* Wrap file in gwen_bufferedio */ + buffio = GWEN_BufferedIO_File_new(mt940_file); - char *mt940_records=g_malloc(filesize+1); + result=AB_ImExporter_Import(importer, + ctx, + buffio, + dbProfile); - fread(mt940_records,1,filesize,mt940_file); - mt940_records[filesize]='\0'; + DEBUG("Parsing result: %d\n", result); - DEBUG("Read file data: %s\n",mt940_records); + GWEN_BufferedIO_Close(buffio); + GWEN_BufferedIO_free(buffio); { - int pos=0; - int result; - AB_BANKING *tr; - AB_IMEXPORTER *importer; - AB_IMEXPORTER_CONTEXT *ctx=0; - GWEN_DB_NODE *dbCtx; - const list_HBCI_Transaction *transactions; - /*list_HBCI_Transaction_iter *iter;*/ + /* Now get all accountinfos */ + AB_TRANSACTION *ab_trans; + struct trans_list_data data; + Account *gnc_acc; + AB_IMEXPORTER_ACCOUNTINFO * accinfo; - tr=AB_Banking_new(); - /* get import module */ - importer=AB_Banking_GetImExporter(tr, "swift"); /* possible values: csv, swift, dtaus, */ - if (!importer) { - DEBUG("Import module swift not found"); + /* Create importer GUI */ + importer_generic_gui = gnc_gen_trans_list_new(parent, NULL, TRUE, 14); + data.importer_generic = importer_generic_gui; + + /* Iterate through all accounts */ + accinfo = AB_ImExporterContext_GetFirstAccountInfo(ctx); + while (accinfo) { + /* FIXME: need to get account name from accinfo + structure here */ + gnc_acc = gnc_import_select_account(account_name, 1, NULL, NULL, + NO_TYPE, NULL, NULL); + /* Store chosen gnucash account in callback data */ + data.gnc_acc = gnc_acc; + + /* Iterate through all transactions */ + ab_trans = + AB_ImExporterAccountInfo_GetFirstTransaction (accinfo); + while (ab_trans) { + /* This callback in the hbci module will add the + imported transaction to gnucash's importer */ + gnc_hbci_trans_list_cb(ab_trans, &data); + ab_trans = + AB_ImExporterAccountInfo_GetNextTransaction (accinfo); + } + /* all transaction finished. */ + + accinfo = AB_ImExporterContext_GetNextAccountInfo(ctx); } + /* all accounts finished. */ + + AB_ImExporterContext_free(ctx); - /* load the import profile */ - //dbProfiles=AB_Banking_GetImExporterProfiles(tr, "swift"); - dbProfile="default"; + /* that's it */ + result=AB_Banking_Fini(ab); + if (result) + DEBUG("ERROR: Error on deinit (%d)\n",result); - /* import new context */ - ctx=AB_ImExporterContext_new(); - - while(pos