[Gnucash-changes] More hbci work.
Christian Stimming
cstim at cvs.gnucash.org
Sat Sep 11 06:06:19 EDT 2004
Log Message:
-----------
More hbci work.
Modified Files:
--------------
gnucash/src/import-export/hbci:
dialog-daterange.c
dialog-hbcitrans.c
druid-hbci-initial.c
gnc-hbci-getbalance.c
gnc-hbci-gettrans.c
gnc-hbci-transfer.c
gnc-hbci-utils.c
gnc-hbci-utils.h
hbci-interaction.c
Revision Data
-------------
Index: druid-hbci-initial.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/druid-hbci-initial.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -Lsrc/import-export/hbci/druid-hbci-initial.c -Lsrc/import-export/hbci/druid-hbci-initial.c -u -r1.49 -r1.50
--- src/import-export/hbci/druid-hbci-initial.c
+++ src/import-export/hbci/druid-hbci-initial.c
@@ -25,6 +25,7 @@
#include <gnome.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include "druid-hbci-initial.h"
@@ -289,8 +290,8 @@
HBCIInitialInfo *info = user_data;
/* FIXME: Need to choose a fixed ending procedure here */
- gnc_AB_BANKING_save (info->api);
- AB_Banking_Fini(info->api);
+ /* probably not saving because of 'cancel', but for now we save too */
+ gnc_AB_BANKING_fini (info->api);
delete_initial_druid(info);
}
@@ -306,9 +307,7 @@
if (successful && info->gnc_hash)
accounts_save_kvp (info->gnc_hash);
- /* FIXME: Need to choose a fixed ending procedure here */
- gnc_AB_BANKING_save (info->api);
- AB_Banking_Fini(info->api);
+ gnc_AB_BANKING_fini (info->api);
delete_initial_druid(info);
}
@@ -354,6 +353,10 @@
gpointer user_data)
{
HBCIInitialInfo *info = user_data;
+
+ /* Make sure the api reads in the current data */
+ AB_Banking_Fini (info->api);
+ AB_Banking_Init (info->api);
if (info->gnc_hash == NULL)
info->gnc_hash = gnc_hbci_new_hash_from_kvp (info->api);
@@ -464,11 +467,43 @@
GWEN_PluginDescription_List2_freeAll(l);
} */
+ druid_disable_next_button(info);
AB_Banking_DeactivateProvider(banking, backend_name);
if (strlen(GWEN_Buffer_GetStart(buf)) > 0) {
-
- /* FIXME: This program call has to be improved !!! */
- res = system(GWEN_Buffer_GetStart(buf));
+ const char *path = GWEN_Buffer_GetStart(buf);
+ int wait_status;
+ int wait_result = 0;
+
+ /* Call the kde wizard */
+ /* res = system(path); */
+ /* In gtk2, this would be g_spawn_async or similar. */
+ AB_Banking_Fini (info->api);
+ {
+ pid_t pid;
+ pid = fork();
+ switch (pid) {
+ case -1:
+ printf("Fork call failed. Cannot start AqHBCI setup wizard.");
+ res = -1;
+ AB_Banking_Init (info->api);
+ break;
+ case 0: /* child */
+ execl(path, path, NULL);
+ printf("Fork call failed. Cannot start AqHBCI setup wizard.");
+ _exit(0);
+ default: /* parent */
+ res = 0;
+ while (wait_result == 0) {
+ gtk_main_iteration();
+ wait_result = waitpid(pid, &wait_status, WNOHANG);
+ if ((wait_result == pid) && WIFEXITED(wait_status))
+ res = WEXITSTATUS(wait_status);
+ else
+ res = -8;
+ }
+ AB_Banking_Init (info->api);
+ }
+ }
if (res == 0) {
res = AB_Banking_ActivateProvider(banking, backend_name);
@@ -480,7 +515,7 @@
}
}
else {
- printf("on_aqhbci_button: Oops, aqhbci wizard return nonzero value: %d. The called program was \"%s\".\n", res, GWEN_Buffer_GetStart(buf));
+ printf("on_aqhbci_button: Oops, aqhbci wizard return nonzero value: %d. The called program was \"%s\".\n", res, path);
druid_disable_next_button(info);
}
} else {
Index: dialog-daterange.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/dialog-daterange.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lsrc/import-export/hbci/dialog-daterange.c -Lsrc/import-export/hbci/dialog-daterange.c -u -r1.2 -r1.3
--- src/import-export/hbci/dialog-daterange.c
+++ src/import-export/hbci/dialog-daterange.c
@@ -59,10 +59,10 @@
GtkWidget *first_button;
GtkWidget *now_button;
- xml = gnc_glade_xml_new ("hbci.glade", "GWEN_TIMErange_dialog");
+ xml = gnc_glade_xml_new ("hbci.glade", "HBCI_daterange_dialog");
g_assert
- (dialog = glade_xml_get_widget (xml, "GWEN_TIMErange_dialog"));
+ (dialog = glade_xml_get_widget (xml, "HBCI_daterange_dialog"));
if (parent)
gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (parent));
Index: gnc-hbci-utils.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-utils.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -Lsrc/import-export/hbci/gnc-hbci-utils.h -Lsrc/import-export/hbci/gnc-hbci-utils.h -u -r1.17 -r1.18
--- src/import-export/hbci/gnc-hbci-utils.h
+++ src/import-export/hbci/gnc-hbci-utils.h
@@ -38,27 +38,8 @@
#include "hbci-interaction.h"
-/** Create a new AB_BANKING and let it load its environment from the
- * configuration file filename. If the file doesn't exist and
- * allowNewFile is set to FALSE, this function returns NULL. If the
- * file exists, but OpenHBCI encountered an error upon opening, then
- * an error will be displayed, and NULL will be returned.
- *
- * @param filename The name of the OpenHBCI configuration file to use.
- * @param allowNewFile If true, non-existent filename is accepted as well.
- * @param parent When displaying dialogs, use this GtkWidget as parent.
- * @param inter Reference to a GNCInteractor-pointer in order to use this later.
- * May be NULL.
- */
-AB_BANKING * gnc_AB_BANKING_new (const char *filename,
- gboolean allowNewFile,
- GtkWidget *parent,
- GNCInteractor **inter);
-
-/** Same as above, but takes the filename already from the current
- * book's kvp frame AND caches a pointer to the api. Returns NULL if
- * the file from the book's kvp frame doesn't exist. Returns NULL also
- * when there was an error upon opening that file.
+/** Create a new AB_BANKING and let it load its environment from its
+ * default configuration.
*
* @param parent When displaying dialogs, use this GtkWidget as parent.
* @param inter Reference to a GNCInteractor-pointer in order to use this later.
@@ -72,10 +53,11 @@
void gnc_AB_BANKING_delete (AB_BANKING *api);
-/* Save this API to the config file given in the current book. Return
- * nonzero if an error occurred, or if no filename was found in the
- * current book. */
-int gnc_AB_BANKING_save (const AB_BANKING *api);
+/* Finish using the API for now. Let the API save its current
+ * state. Return nonzero if an error occurred. After this call, you
+ * may only call gnc_AB_BANKING_new_currentbook to get the api again
+ * in a properly initialized state. */
+int gnc_AB_BANKING_fini (AB_BANKING *api);
/* Get the corresponding HBCI account to a gnucash account. Of course
Index: dialog-hbcitrans.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/dialog-hbcitrans.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -Lsrc/import-export/hbci/dialog-hbcitrans.c -Lsrc/import-export/hbci/dialog-hbcitrans.c -u -r1.32 -r1.33
--- src/import-export/hbci/dialog-hbcitrans.c
+++ src/import-export/hbci/dialog-hbcitrans.c
@@ -362,7 +362,7 @@
gtk_label_set_text (GTK_LABEL (orig_account_label),
AB_Account_GetAccountNumber (h_acc));
gtk_label_set_text (GTK_LABEL (orig_bankname_label),
- (strlen(hbci_bankname)>0 ?
+ (hbci_bankname && (strlen(hbci_bankname)>0) ?
hbci_bankname :
_("(unknown)")));
gtk_label_set_text (GTK_LABEL (orig_bankcode_label),
Index: gnc-hbci-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-utils.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -Lsrc/import-export/hbci/gnc-hbci-utils.c -Lsrc/import-export/hbci/gnc-hbci-utils.c -u -r1.42 -r1.43
--- src/import-export/hbci/gnc-hbci-utils.c
+++ src/import-export/hbci/gnc-hbci-utils.c
@@ -39,135 +39,77 @@
/* Globale variables for AB_BANKING caching. */
static AB_BANKING *gnc_AB_BANKING = NULL;
-static char *gnc_hbci_configfile = NULL;
+static int gnc_AB_BANKING_refcnt = 0;
static GNCInteractor *gnc_hbci_inter = NULL;
-/* static GList *AB_ACCOUNTlist = NULL; */
-/* ------------------------------------------------------------ */
-AB_BANKING *
-gnc_AB_BANKING_new (const char *filename, gboolean allowNewFile,
- GtkWidget *parent, GNCInteractor **inter)
-{
- AB_BANKING *api = NULL;
-/* int *err = NULL; */
-/* char *errstring; */
-
- g_assert(inter);
-
-#if 0
- if (!filename)
- return NULL;
- if (!allowNewFile &&
- (!g_file_test (filename, G_FILE_TEST_ISFILE | G_FILE_TEST_ISLINK)))
- {
- /* ENOENT is "No such file or directory" */
- gchar *errstring = g_strdup_printf ("%s: %s", filename, strerror (ENOENT));
- gnc_warning_dialog
- (parent,
- /* Translators: Strings from this file are really only needed
- * inside Germany (HBCI is not supported anywhere else). You
- * may safely ignore strings from the import-export/hbci
- * subdirectory in other countries. */
- _("Error while loading OpenHBCI config file:\n %s\n"), errstring);
- g_free (errstring);
- return NULL;
- }
-#endif
-
- api = AB_Banking_new ("gnucash", 0);
- g_assert(api);
- {
- int r = AB_Banking_Init(api);
- if (r != 0)
- printf("gnc_AB_BANKING_new: Warning: Error %d on AB_Banking_init\n", r);
- }
- /* FIXME: The configfile is ignored here */
- g_assert(api);
-
- *inter = gnc_AB_BANKING_interactors (api, parent);
-
-#if 0
- {
- /* Well, currently gnucash doesn't offer a way to uniformly ask
- for the ~/.gnucash directory, so we have to generate that path
- here by hand. */
- gchar *homebuffer;
- gchar *databuffer;
-
- /* Get home directory */
- gnc_init_default_directory(&homebuffer);
-
- /* Join it with the directory name */
- databuffer = g_strjoin("", homebuffer, "/.gnucash/hbci");
-
- /*fprintf(stderr, "Setting log dir to %s\n", databuffer);*/
-/* HBCI_Hbci_setApplicationDataDir(AB_Banking_Hbci(api), databuffer); */
- /* FIXME: do we need to set this here? */
-
- g_free(databuffer);
- g_free(homebuffer);
- }
-#endif
-
- g_assert(api);
- return api;
-}
-
AB_BANKING * gnc_AB_BANKING_new_currentbook (GtkWidget *parent,
- GNCInteractor **inter)
+ GNCInteractor **inter)
{
if (gnc_AB_BANKING == NULL) {
/* No API cached -- create new one. */
- gnc_hbci_configfile =
- g_strdup (gnc_hbci_get_book_configfile (gnc_get_current_book ()));
- gnc_AB_BANKING = gnc_AB_BANKING_new (gnc_hbci_configfile,
- FALSE, parent, &gnc_hbci_inter);
+ AB_BANKING *api = NULL;
+
+ api = AB_Banking_new ("gnucash", 0);
+ g_assert(api);
+ {
+ int r = AB_Banking_Init(api);
+ if (r != 0)
+ printf("gnc_AB_BANKING_new: Warning: Error %d on AB_Banking_init\n", r);
+ }
+
+ gnc_hbci_inter = gnc_AB_BANKING_interactors (api, parent);
+ gnc_AB_BANKING = api;
+
if (inter)
*inter = gnc_hbci_inter;
+ gnc_AB_BANKING_refcnt = 1;
return gnc_AB_BANKING;
-
- } else if ((gnc_hbci_configfile != NULL) &&
- (strcmp(gnc_hbci_configfile,
- gnc_hbci_get_book_configfile (gnc_get_current_book ()))
- != 0)) {
- /* Wrong API cached -- delete old and create new. */
- gnc_AB_BANKING_delete (gnc_AB_BANKING);
- fprintf(stderr,
- "gnc_AB_BANKING_new_currentbook: Wrong AB_BANKING cached; creating new one.\n");
- return gnc_AB_BANKING_new_currentbook (parent, inter);
} else {
- /* Correct API cached. */
+ /* API cached. */
+
+ /* Init the API again. */
+ if (gnc_AB_BANKING_refcnt == 0)
+ AB_Banking_Init(gnc_AB_BANKING);
+
if (inter) {
*inter = gnc_hbci_inter;
GNCInteractor_reparent (*inter, parent);
}
+ gnc_AB_BANKING_refcnt++;
return gnc_AB_BANKING;
}
}
void gnc_AB_BANKING_delete (AB_BANKING *api)
{
- if (api == gnc_AB_BANKING) {
- gnc_AB_BANKING = NULL;
- gnc_hbci_inter = NULL;
- g_free (gnc_hbci_configfile);
- gnc_hbci_configfile = NULL;
- }
if (api == 0)
api = gnc_AB_BANKING;
+
if (api) {
- AB_Banking_Fini(api);
+ if (api == gnc_AB_BANKING) {
+ gnc_AB_BANKING = NULL;
+ gnc_hbci_inter = NULL;
+ if (gnc_AB_BANKING_refcnt > 0)
+ AB_Banking_Fini(api);
+ }
+
AB_Banking_free(api);
}
}
-int gnc_AB_BANKING_save (const AB_BANKING *api)
+int gnc_AB_BANKING_fini (AB_BANKING *api)
{
- /* FIXME: do something to save the current state */
+ if (api == gnc_AB_BANKING) {
+ gnc_AB_BANKING_refcnt--;
+ if (gnc_AB_BANKING_refcnt == 0)
+ return AB_Banking_Fini(api);
+ }
+ else
+ return AB_Banking_Fini(api);
return 0;
}
Index: gnc-hbci-getbalance.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-getbalance.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -Lsrc/import-export/hbci/gnc-hbci-getbalance.c -Lsrc/import-export/hbci/gnc-hbci-getbalance.c -u -r1.25 -r1.26
--- src/import-export/hbci/gnc-hbci-getbalance.c
+++ src/import-export/hbci/gnc-hbci-getbalance.c
@@ -116,7 +116,7 @@
/* Clean up after ourselves. */
AB_Banking_DequeueJob(api, job);
- gnc_AB_BANKING_save (api);
+ gnc_AB_BANKING_fini (api);
GNCInteractor_hide (interactor);
}
}
Index: hbci-interaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interaction.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -Lsrc/import-export/hbci/hbci-interaction.c -Lsrc/import-export/hbci/hbci-interaction.c -u -r1.36 -r1.37
--- src/import-export/hbci/hbci-interaction.c
+++ src/import-export/hbci/hbci-interaction.c
@@ -427,11 +427,12 @@
data = AB_Banking_GetUserData(ab);
g_assert(data);
- if ((id != 0) || (id != progress_id)) {
- printf("progressLogCB: Oops, wrong progress id -- ignored.\n");
+ if ((id != 0) && (id != progress_id)) {
+ printf("progressLogCB: Oops, wrong progress id %d -- ignored.\n", id);
}
if (progress != AB_BANKING_PROGRESS_NONE) {
+ printf("progressLogCB: Setting progress to %d out of %f.\n", progress, data->action_max);
gtk_progress_set_percentage (GTK_PROGRESS (data->action_progress),
progress/data->action_max);
}
@@ -450,8 +451,8 @@
data = AB_Banking_GetUserData(ab);
g_assert(data);
- if ((id != 0) || (id != progress_id)) {
- printf("progressLogCB: Oops, wrong progress id -- ignored.\n");
+ if ((id != 0) && (id != progress_id)) {
+ printf("progressLogCB: Oops, wrong progress id %d -- ignored.\n", id);
}
printf("progressLogCB: Logging msg: %s\n", text);
@@ -469,8 +470,8 @@
data = AB_Banking_GetUserData(ab);
g_assert(data);
- if ((id != 0) || (id != progress_id)) {
- printf("progressLogCB: Oops, wrong progress id -- ignored.\n");
+ if ((id != 0) && (id != progress_id)) {
+ printf("progressLogCB: Oops, wrong progress id %d -- ignored.\n", id);
}
GNCInteractor_setFinished(data);
Index: gnc-hbci-gettrans.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-gettrans.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -Lsrc/import-export/hbci/gnc-hbci-gettrans.c -Lsrc/import-export/hbci/gnc-hbci-gettrans.c -u -r1.29 -r1.30
--- src/import-export/hbci/gnc-hbci-gettrans.c
+++ src/import-export/hbci/gnc-hbci-gettrans.c
@@ -121,7 +121,7 @@
/* Clean up behind ourself. */
AB_Banking_DequeueJob(api, job);
- gnc_AB_BANKING_save (api);
+ gnc_AB_BANKING_fini (api);
GNCInteractor_hide (interactor);
}
}
Index: gnc-hbci-transfer.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-transfer.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -Lsrc/import-export/hbci/gnc-hbci-transfer.c -Lsrc/import-export/hbci/gnc-hbci-transfer.c -u -r1.18 -r1.19
--- src/import-export/hbci/gnc-hbci-transfer.c
+++ src/import-export/hbci/gnc-hbci-transfer.c
@@ -153,7 +153,7 @@
}*/
/* Just to be on the safe side, clear queue once again. */
- gnc_AB_BANKING_save (api);
+ gnc_AB_BANKING_fini (api);
gnc_hbci_dialog_delete(td);
gnc_trans_templ_delete_glist (template_list);
More information about the gnucash-changes
mailing list