From 4bbe9d0b46012f37fef9191d4d229da3613da7d9 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Mon, 21 Aug 2006 20:30:41 +0000 Subject: [PATCH] More code refactoring of aqbanking module: Make importer name a function argument so that more menu items can be added easily. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@14702 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/import-export/hbci/gnc-dtaus-import.c | 18 +++++++++++++----- src/import-export/hbci/gnc-dtaus-import.h | 16 ++++++++++++++-- src/import-export/hbci/gnc-plugin-hbci.c | 2 +- src/import-export/mt940/gnc-mt940-import.c | 16 +++++++++++++--- src/import-export/mt940/gnc-mt940-import.h | 16 ++++++++++++++-- src/import-export/mt940/gnc-plugin-mt940.c | 2 +- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/src/import-export/hbci/gnc-dtaus-import.c b/src/import-export/hbci/gnc-dtaus-import.c index 6f2e88424a..723b326c11 100644 --- a/src/import-export/hbci/gnc-dtaus-import.c +++ b/src/import-export/hbci/gnc-dtaus-import.c @@ -141,7 +141,8 @@ AB_ImExporterAccountInfo_TransactionsForEach(AB_IMEXPORTER_ACCOUNTINFO *iea, * Entry point \********************************************************************/ -void gnc_file_dtaus_import (void) +void gnc_file_dtaus_import (const gchar *aqbanking_importername, + const gchar *aqbanking_profilename) { char *selected_filename; char *default_dir; @@ -184,10 +185,8 @@ void gnc_file_dtaus_import (void) GWEN_DB_NODE *dbProfiles; GWEN_DB_NODE *dbProfile; GNCInteractor *interactor = NULL; - const char *importerName = "dtaus"; /* possible values: csv, swift, dtaus, */ - const char *profileName = "default"; - /* Possible values for profile: "default" for most importers; - for swift this can be "swiftmt940" or "swiftmt942". */ + const char *importerName = aqbanking_importername; + const char *profileName = aqbanking_profilename; /* Get API */ ab = gnc_AB_BANKING_new_currentbook (NULL, &interactor); @@ -225,6 +224,15 @@ void gnc_file_dtaus_import (void) profileName, importerName); printf("Profile \"%s\" for importer \"%s\" not found\n", profileName, importerName); + /* For debugging: Print those available names that have been found. */ + dbProfile=GWEN_DB_GetFirstGroup(dbProfiles); + while(dbProfile) { + const char *name; + name=GWEN_DB_GetCharValue(dbProfile, "name", 0, 0); + g_assert(name); + printf("Only found profile \"%s\"\n", name); + dbProfile=GWEN_DB_GetNextGroup(dbProfile); + } return; } g_assert(dbProfile); diff --git a/src/import-export/hbci/gnc-dtaus-import.h b/src/import-export/hbci/gnc-dtaus-import.h index fc8dc497c3..98531d0f5d 100644 --- a/src/import-export/hbci/gnc-dtaus-import.h +++ b/src/import-export/hbci/gnc-dtaus-import.h @@ -29,6 +29,18 @@ * selection dialogue asking the user to pick an DTAUS file. If one * is selected then the DTAUS 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_dtaus_import (void); + * session continues to remain open for editing. + * + * @param aqbanking_importername The aqbanking importer module that + * should be used. Possible values: "dtaus", "csv", "swift". + * + * @param aqbanking_profilename In aqbanking, each importer has one or + * more "profiles" that define the actual data fields that should be + * used. Possible values for swift: "swift-mt940" or "swift-mt942", + * but for all others: "default", or more precisely: Look into + * $datadir/aqbanking/imexporters and look into the "name" field of + * the foo.conf files. + */ +void gnc_file_dtaus_import (const gchar *aqbanking_importername, + const gchar *aqbanking_profilename); #endif diff --git a/src/import-export/hbci/gnc-plugin-hbci.c b/src/import-export/hbci/gnc-plugin-hbci.c index 58e5529884..a72819739a 100644 --- a/src/import-export/hbci/gnc-plugin-hbci.c +++ b/src/import-export/hbci/gnc-plugin-hbci.c @@ -523,7 +523,7 @@ static void gnc_plugin_hbci_cmd_dtaus_import (GtkAction *action, GncMainWindowActionData *data) { - gnc_file_dtaus_import (); + gnc_file_dtaus_import ("dtaus", "default"); } /************************************************************ * Plugin Bootstrapping * diff --git a/src/import-export/mt940/gnc-mt940-import.c b/src/import-export/mt940/gnc-mt940-import.c index cff528e188..69e33b34d6 100644 --- a/src/import-export/mt940/gnc-mt940-import.c +++ b/src/import-export/mt940/gnc-mt940-import.c @@ -128,7 +128,8 @@ AB_ImExporterAccountInfo_TransactionsForEach(AB_IMEXPORTER_ACCOUNTINFO *iea, * Entry point \********************************************************************/ -void gnc_file_mt940_import (void) +void gnc_file_mt940_import (const gchar *aqbanking_importername, + const gchar *aqbanking_profilename) { char *selected_filename; char *default_dir; @@ -170,8 +171,8 @@ void gnc_file_mt940_import (void) GWEN_BUFFEREDIO *buffio; GWEN_DB_NODE *dbProfiles; GWEN_DB_NODE *dbProfile; - const char *importerName = "swift"; /* possible values: csv, swift, dtaus, */ - const char *profileName = "swift-mt940"; + const char *importerName = aqbanking_importername; + const char *profileName = aqbanking_profilename; /* "swift-mt940"; */ /* Possible values for profile: "swiftmt942", but for other importers: "default" */ @@ -206,6 +207,15 @@ void gnc_file_mt940_import (void) profileName, importerName); printf("Profile \"%s\" for importer \"%s\" not found\n", profileName, importerName); + /* For debugging: Print those available names that have been found. */ + dbProfile=GWEN_DB_GetFirstGroup(dbProfiles); + while(dbProfile) { + const char *name; + name=GWEN_DB_GetCharValue(dbProfile, "name", 0, 0); + g_assert(name); + printf("Only found profile \"%s\"\n", name); + dbProfile=GWEN_DB_GetNextGroup(dbProfile); + } return; } g_assert(dbProfile); diff --git a/src/import-export/mt940/gnc-mt940-import.h b/src/import-export/mt940/gnc-mt940-import.h index c784ef10d2..8ec61ff161 100644 --- a/src/import-export/mt940/gnc-mt940-import.h +++ b/src/import-export/mt940/gnc-mt940-import.h @@ -29,6 +29,18 @@ * 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); + * session continues to remain open for editing. + * + * @param aqbanking_importername The aqbanking importer module that + * should be used. Possible values: "dtaus", "csv", "swift". + * + * @param aqbanking_profilename In aqbanking, each importer has one or + * more "profiles" that define the actual data fields that should be + * used. Possible values for swift: "swift-mt940" or "swift-mt942", + * but for all others: "default", or more precisely: Look into + * $datadir/aqbanking/imexporters and look into the "name" field of + * the foo.conf files. + */ +void gnc_file_mt940_import (const gchar *aqbanking_importername, + const gchar *aqbanking_profilename); #endif diff --git a/src/import-export/mt940/gnc-plugin-mt940.c b/src/import-export/mt940/gnc-plugin-mt940.c index aed53159d7..8063df4cb9 100644 --- a/src/import-export/mt940/gnc-plugin-mt940.c +++ b/src/import-export/mt940/gnc-plugin-mt940.c @@ -145,7 +145,7 @@ static void gnc_plugin_mt940_cmd_import (GtkAction *action, GncMainWindowActionData *data) { - gnc_file_mt940_import (); + gnc_file_mt940_import ("swift", "swift-mt940"); }