diff --git a/AUTHORS b/AUTHORS index 04f1e1b6db..e0daf7ce54 100644 --- a/AUTHORS +++ b/AUTHORS @@ -88,6 +88,7 @@ Other Contributors: Andrew Arensburger for FreeBSD & other patches Matt Armstrong for misc fixes Fred Baube for attempted Java port/MoneyDance +Jan-Pascal van Best MT940 importer Dennis Björklund Swedish translation Andreas Bogk Postgres backend patch Per Bojsen several core dump fixes diff --git a/ChangeLog b/ChangeLog index 81f5b8a824..2a7e67d842 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-09-16 Christian Stimming + + * src/import-export/hbci/gnc-hbci-kvp.c: Fix broken compile due to + Linas' change of the kvp_frame_get_frame() arguments. By + Jan-Pascal van Best + + * src/import-export/hbci/gnc-hbci-gettrans.[hc]: Code + refactorization so that the mt940 importer can re-use the existing + import functions from the hbci module. By Jan-Pascal van Best + + + * src/import-export/mt940/gncmod-mt940-import.[hc]: Import module + for SWIFT MT940 files added. By Jan-Pascal van Best + + 2003-09-14 Derek Atkins * src/backend/postgres/test/run-tests.sh: small fix from diff --git a/configure.in b/configure.in index 28d39bbf84..60503e01e1 100644 --- a/configure.in +++ b/configure.in @@ -583,6 +583,16 @@ then AC_SUBST(HBCI_CFLAGS) fi AC_SUBST(HBCI_DIR) + +### -------------------------------------------------------------------------- +### MT940 +AC_ARG_ENABLE( mt940, + [ --enable-mt940 compile with MT940 support (needs --enable-hbci)], + if test "x$enableval" != "xno" ; then + MT940_DIR=mt940 + fi) +AC_SUBST(MT940_DIR) + ### -------------------------------------------------------------------------- ### i18n @@ -1137,6 +1147,7 @@ AC_OUTPUT( m4/Makefile intl/Makefile po/Makefile.in accounts/el_GR/Makefile accounts/es_ES/Makefile accounts/fr_FR/Makefile + accounts/it/Makefile accounts/pt_BR/Makefile accounts/pt_PT/Makefile accounts/sk/Makefile @@ -1205,6 +1216,7 @@ AC_OUTPUT( m4/Makefile intl/Makefile po/Makefile.in src/import-export/qif-io-core/test/Makefile src/import-export/ofx/Makefile src/import-export/ofx/test/Makefile + src/import-export/mt940/Makefile src/import-export/log-replay/Makefile src/import-export/hbci/Makefile src/import-export/hbci/glade/Makefile diff --git a/src/import-export/Makefile.am b/src/import-export/Makefile.am index c9ad91430d..f61ecb6456 100644 --- a/src/import-export/Makefile.am +++ b/src/import-export/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = . binary-import qif qif-import ${OFX_DIR} ${HBCI_DIR} log-replay test -DIST_SUBDIRS = binary-import qif qif-import qif-io-core ofx hbci log-replay test +SUBDIRS = . binary-import qif qif-import ${OFX_DIR} ${HBCI_DIR} ${MT940_DIR} log-replay test +DIST_SUBDIRS = binary-import qif qif-import qif-io-core ofx hbci mt940 log-replay test pkglib_LTLIBRARIES=libgncmod-generic-import.la diff --git a/src/import-export/hbci/gnc-hbci-gettrans.c b/src/import-export/hbci/gnc-hbci-gettrans.c index 6d7b97049f..067cd837ba 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.c +++ b/src/import-export/hbci/gnc-hbci-gettrans.c @@ -241,19 +241,29 @@ gnc_hbci_gettrans_final(GtkWidget *parent, static void *trans_list_cb (const HBCI_Transaction *h_trans, void *user_data) { - time_t current_time, tt1, tt2; - /*struct tm tm1, tm2;*/ Account *gnc_acc; - GNCBook *book; - Transaction *gnc_trans; - Split *split; struct trans_list_data *data = user_data; g_assert(data); g_assert(h_trans); gnc_acc = data->gnc_acc; g_assert(gnc_acc); - + + gnc_hbci_trans_import(h_trans,data->importer_generic,gnc_acc); + + return NULL; +} + +void gnc_hbci_trans_import(const HBCI_Transaction *h_trans, + GNCImportMainMatcher *importer_generic, + Account *gnc_acc) +{ + time_t current_time, tt1, tt2; + /*struct tm tm1, tm2;*/ + GNCBook *book; + Transaction *gnc_trans; + Split *split; + book = xaccAccountGetBook(gnc_acc); gnc_trans = xaccMallocTransaction(book); xaccTransBeginEdit(gnc_trans); @@ -321,8 +331,6 @@ static void *trans_list_cb (const HBCI_Transaction *h_trans, } /* Instead of xaccTransCommitEdit(gnc_trans) */ - g_assert (data->importer_generic); - gnc_gen_trans_list_add_trans (data->importer_generic, gnc_trans); - - return NULL; + g_assert (importer_generic); + gnc_gen_trans_list_add_trans (importer_generic, gnc_trans); } diff --git a/src/import-export/hbci/gnc-hbci-gettrans.h b/src/import-export/hbci/gnc-hbci-gettrans.h index 6986a56c04..253396e86f 100644 --- a/src/import-export/hbci/gnc-hbci-gettrans.h +++ b/src/import-export/hbci/gnc-hbci-gettrans.h @@ -25,7 +25,10 @@ #include #include +#include + #include "Account.h" +#include "import-main-matcher.h" /** Start a GetTrans job. */ void @@ -39,5 +42,10 @@ gnc_hbci_gettrans_final(GtkWidget *parent, const HBCI_OutboxJobGetTransactions *trans_job, gboolean run_until_done); +/** Import HBCI transaction into gnucash account using importer_generic + */ +void gnc_hbci_trans_import(const HBCI_Transaction *h_trans, + GNCImportMainMatcher *importer_generic, + Account *gnc_acc); #endif /* GNC_HBCI_GETTRANS_H */ diff --git a/src/import-export/hbci/gnc-hbci-kvp.c b/src/import-export/hbci/gnc-hbci-kvp.c index 8894d2495e..deaa25447b 100644 --- a/src/import-export/hbci/gnc-hbci-kvp.c +++ b/src/import-export/hbci/gnc-hbci-kvp.c @@ -125,7 +125,7 @@ void gnc_hbci_set_book_template_list (GNCBook *b, GList *template_list) kvp_frame *gnc_hbci_get_book_kvp (GNCBook *b) { kvp_frame *toplevel = gnc_book_get_slots (b); - return kvp_frame_get_frame (toplevel, HBCI_KEY, NULL); + return kvp_frame_get_frame (toplevel, HBCI_KEY); } @@ -134,5 +134,5 @@ kvp_frame *gnc_hbci_get_book_kvp (GNCBook *b) kvp_frame *gnc_hbci_get_account_kvp (Account *a) { kvp_frame *toplevel = xaccAccountGetSlots (a); - return kvp_frame_get_frame (toplevel, HBCI_KEY, NULL); + return kvp_frame_get_frame (toplevel, HBCI_KEY); } diff --git a/src/import-export/mt940/.cvsignore b/src/import-export/mt940/.cvsignore new file mode 100644 index 0000000000..88abab976f --- /dev/null +++ b/src/import-export/mt940/.cvsignore @@ -0,0 +1,7 @@ +.deps +.libs +.scm-links +*.la +*.lo +Makefile +Makefile.in diff --git a/src/import-export/mt940/Makefile.am b/src/import-export/mt940/Makefile.am new file mode 100644 index 0000000000..bb247b693a --- /dev/null +++ b/src/import-export/mt940/Makefile.am @@ -0,0 +1,48 @@ +SUBDIRS = . +# test + +pkglib_LTLIBRARIES=libgncmod-mt940.la + +libgncmod_mt940_la_SOURCES = \ + gnc-mt940-import.c \ + gncmod-mt940-import.c + +noinst_HEADERS = \ + gnc-mt940-import.h + +libgncmod_mt940_la_LDFLAGS = -module + +libgncmod_mt940_la_LIBADD = \ + ${top_builddir}/src/gnc-module/libgncmodule.la \ + ${top_builddir}/src/engine/libgncmod-engine.la \ + ${top_builddir}/src/import-export/libgncmod-generic-import.la \ + ${GLIB_LIBS} \ + $(HBCI_LIBS) + +gncscmdir = ${GNC_SCM_INSTALL_DIR}/mt940 + +gncscm_DATA = \ + mt940-import.scm + +AM_CFLAGS = \ + -I${top_srcdir}/src \ + -I${top_srcdir}/src/engine \ + -I${top_srcdir}/src/gnc-module \ + -I${top_srcdir}/src/app-utils \ + -I${top_srcdir}/src/app-file \ + -I${top_srcdir}/src/gnome \ + -I${top_srcdir}/src/gnome-utils \ + -I${top_srcdir}/src/import-export \ + -I$(top_srcdir)/src/import-export/hbci \ + ${GNOME_INCLUDEDIR} \ + ${GTKHTML_CFLAGS} \ + ${GLADE_CFLAGS} \ + ${GUILE_INCS} \ + ${GLIB_CFLAGS} \ + $(HBCI_CFLAGS) + +EXTRA_DIST = \ + .cvsignore \ + ${gncscm_DATA} + +CLEANFILES = mt940 import-export gnucash g-wrapped .scm-links diff --git a/src/import-export/mt940/gnc-mt940-import.c b/src/import-export/mt940/gnc-mt940-import.c new file mode 100644 index 0000000000..74c6781498 --- /dev/null +++ b/src/import-export/mt940/gnc-mt940-import.c @@ -0,0 +1,173 @@ +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ +/** @addtogroup Import_Export + @{ */ +/** @internal + @file gnc-mt940-import.c + @brief MT940 import module code + @author Copyright (c) 2002 Benoit Grégoire , Copyright (c) 2003 Jan-Pascal van Best + */ +#define _GNU_SOURCE + +#include "config.h" + +#include +#include +#include + +#include +#include + +#include + +#include "gnc-hbci-gettrans.h" +#include "import-account-matcher.h" +#include "import-main-matcher.h" + +#include "Account.h" +#include "Transaction.h" +#include "global-options.h" + +#include "gnc-engine-util.h" +#include "gnc-file-dialog.h" +#include "gnc-ui-util.h" +#include "gnc-hbci-utils.h" + +#include "gnc-mt940-import.h" + + +static short module = MOD_IMPORT; + +static void *trans_importer_cb (const HBCI_Transaction *h_trans, + void *user_data); + +/********************************************************************\ + * gnc_file_mt940_import + * Entry point +\********************************************************************/ + +SCM scm_gnc_file_mt940_import () +{ + gnc_file_mt940_import(); + return SCM_EOL; +} + +void gnc_file_mt940_import (void) +{ + const char *selected_filename; + char *default_dir; + FILE *mt940_file; + GNCImportMainMatcher *gnc_mt940_importer_gui = NULL; + + gnc_should_log(MOD_IMPORT, GNC_LOG_TRACE); + DEBUG("gnc_file_mt940_import(): Begin...\n"); + + default_dir = gnc_lookup_string_option("__paths", "Import MT940", NULL); + if (default_dir == NULL) + gnc_init_default_directory(&default_dir); + selected_filename = gnc_file_dialog(_("Select an MT940 file to process"), + NULL, + default_dir); + + if(selected_filename!=NULL) + { + /* Remember the directory as the default. */ + gnc_extract_directory(&default_dir, selected_filename); + gnc_set_string_option("__paths", "Import MT940", default_dir); + 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"); + + fseek(mt940_file,0,SEEK_END); + unsigned long filesize=ftell(mt940_file); + rewind(mt940_file); + + char *mt940_records=g_malloc(filesize+1); + + fread(mt940_records,1,filesize,mt940_file); + mt940_records[filesize]='\0'; + + DEBUG("Read file data: %s\n",mt940_records); + + { + int pos=0; + int result; + HBCI_transactionReport *tr; + const list_HBCI_Transaction *transactions; + /*list_HBCI_Transaction_iter *iter;*/ + + tr=HBCI_transactionReport_new(); + + while(pos + */ +#ifndef MT940_IMPORT_H +#define MT940_IMPORT_H + +/** The gnc_file_mt940_import() routine will pop up a standard file + * selection dialogue asking the user to pick an MT940 file. If one + * is selected then the MT940 file is opened and read. Its contents + * are merged into the existing session (if any). The current + * session continues to remain open for editing. */ +void gnc_file_mt940_import (void); +SCM scm_gnc_file_mt940_import (void); +#endif diff --git a/src/import-export/mt940/gncmod-mt940-import.c b/src/import-export/mt940/gncmod-mt940-import.c new file mode 100644 index 0000000000..d13ecd786f --- /dev/null +++ b/src/import-export/mt940/gncmod-mt940-import.c @@ -0,0 +1,92 @@ +/********************************************************************\ + * This program is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation; either version 2 of * + * the License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License* + * along with this program; if not, contact: * + * * + * Free Software Foundation Voice: +1-617-542-5942 * + * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * + * Boston, MA 02111-1307, USA gnu@gnu.org * +\********************************************************************/ +/** @addtogroup Import_Export + @{ */ + /**@internal + @file gncmod-mt940-import.c + @brief module definition/initialization for the mt940 importer + @author Copyright (c) 2002 Benoit Grégoire bock@step.polymtl.ca + */ +#include "config.h" +#include +#include +#include "guile-mappings.h" + +#include "gnc-mt940-import.h" +#include "gnc-module.h" +#include "gnc-module-api.h" + +/* version of the gnc module system interface we require */ +int libgncmod_mt940_LTX_gnc_module_system_interface = 0; + +/* module versioning uses libtool semantics. */ +int libgncmod_mt940_LTX_gnc_module_current = 0; +int libgncmod_mt940_LTX_gnc_module_revision = 0; +int libgncmod_mt940_LTX_gnc_module_age = 0; + +//static GNCModule bus_core; +//static GNCModule file; + +/* forward references */ +char *libgncmod_mt940_LTX_gnc_module_path(void); +char *libgncmod_mt940_LTX_gnc_module_description(void); +int libgncmod_mt940_LTX_gnc_module_init(int refcount); +int libgncmod_mt940_LTX_gnc_module_end(int refcount); + + +char * +libgncmod_mt940_LTX_gnc_module_path(void) +{ + return g_strdup("gnucash/import-export/mt940"); +} +char * +libgncmod_mt940_LTX_gnc_module_description(void) +{ + return g_strdup("Gnome GUI and C code for MT940 importer"); +} +int +libgncmod_mt940_LTX_gnc_module_init(int refcount) +{ + if(!gnc_module_load("gnucash/engine", 0)) + { + return FALSE; + } + if(!gnc_module_load("gnucash/app-utils", 0)) + { + return FALSE; + } + if(!gnc_module_load("gnucash/gnome-utils", 0)) + { + return FALSE; + } + if(!gnc_module_load("gnucash/import-export", 0)) + { + return FALSE; + } + scm_c_eval_string("(load-from-path \"mt940/mt940-import.scm\")"); + scm_c_define_gsubr("gnc:mt940-import", 0, 0, 0, scm_gnc_file_mt940_import); + return TRUE; +} + +int +libgncmod_mt940_LTX_gnc_module_end(int refcount) +{ + return TRUE; +} +/** @}*/ diff --git a/src/import-export/mt940/mt940-import.scm b/src/import-export/mt940/mt940-import.scm new file mode 100644 index 0000000000..7201df887d --- /dev/null +++ b/src/import-export/mt940/mt940-import.scm @@ -0,0 +1,10 @@ +(define (add-mt940-menu-item) + (gnc:add-extension + (gnc:make-menu-item(N_ "Import MT940") + (N_ "Process an MT940 response file") + (list gnc:window-name-main "File" "_Import" "") + (lambda () + (gnc:mt940-import))))) + +(gnc:hook-add-dangler gnc:*ui-startup-hook* add-mt940-menu-item) + diff --git a/src/scm/main.scm b/src/scm/main.scm index 3cb703eddb..5e8833f32b 100644 --- a/src/scm/main.scm +++ b/src/scm/main.scm @@ -428,6 +428,7 @@ string and 'directories' must be a list of strings." (load-module "gnucash/import-export/binary-import" 0 #f) (load-module "gnucash/import-export/qif-import" 0 #f) (load-module "gnucash/import-export/ofx" 0 #t) + (load-module "gnucash/import-export/mt940" 0 #t) (load-module "gnucash/import-export/log-replay" 0 #t) (load-module "gnucash/import-export/hbci" 0 #t) (load-module "gnucash/report/report-system" 0 #f)