[Gnucash-changes] HBCI behaviour and encoding improvements.

Christian Stimming cstim at cvs.gnucash.org
Sun Mar 20 08:02:08 EST 2005


Log Message:
-----------
HBCI behaviour and encoding improvements.

2005-03-20  Christian Stimming  <stimming at tuhh.de>

	* src/import-export/hbci/gnc-hbci-utils.c: Retrieve the current
	book's character encoding which so far is identical to the
	locale's encoding by nl_langinfo().

	* src/import-export/hbci/hbci-interaction.c: Fixed ignored 'abort'
	button.

Tags:
----
gnucash-1-8-branch

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/import-export/hbci:
        dialog-hbcitrans.c
        gnc-hbci-utils.c
        gnc-hbci-utils.h
        hbci-interaction.c

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1461.2.405
retrieving revision 1.1461.2.406
diff -LChangeLog -LChangeLog -u -r1.1461.2.405 -r1.1461.2.406
--- ChangeLog
+++ ChangeLog
@@ -1,10 +1,17 @@
+2005-03-20  Christian Stimming  <stimming at tuhh.de>
+
+	* src/import-export/hbci/gnc-hbci-utils.c: Retrieve the current
+	book's character encoding which so far is identical to the
+	locale's encoding by nl_langinfo().
+
+	* src/import-export/hbci/hbci-interaction.c: Fixed ignored 'abort'
+	button.
+
 2005-03-19  Christian Stimming  <stimming at tuhh.de>
 
 	* src/import-export/hbci/gnc-hbci-utils.c (gnc_hbci_descr_tognc):
 	Correctly convert imported transaction description from utf-8 to
-	iso-8859-15 which currently comes closest to gnucash's internal
-	encoding. This needs to be changed again for the gnome2 port, but
-	I'll think of that early enough.
+	the local encoding.
 
 2005-03-13  Christian Stimming  <stimming at tuhh.de>
 
Index: hbci-interaction.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/hbci-interaction.c,v
retrieving revision 1.16.2.21
retrieving revision 1.16.2.22
diff -Lsrc/import-export/hbci/hbci-interaction.c -Lsrc/import-export/hbci/hbci-interaction.c -u -r1.16.2.21 -r1.16.2.22
--- src/import-export/hbci/hbci-interaction.c
+++ src/import-export/hbci/hbci-interaction.c
@@ -58,7 +58,8 @@
      needs to be fixed for the gnome2 version; the target encoding is
      then probably utf-8 as well. iconv is also used in
      gnc_hbci_descr_tognc() in gnc-hbci-utils.c. */
-  data->gnc_iconv_handler = iconv_open("ISO8859-15", "UTF-8");
+  data->gnc_iconv_handler = 
+    iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
   g_assert(data->gnc_iconv_handler != (iconv_t)(-1));
   data->keepAlive = TRUE;
   data->cache_pin = 
@@ -111,6 +112,7 @@
   data->state = RUNNING;
   gtk_widget_set_sensitive (GTK_WIDGET (data->abort_button), TRUE);
   gtk_widget_set_sensitive (GTK_WIDGET (data->close_button), FALSE);
+  data->keepAlive = TRUE;
 }
 static void GNCInteractor_setFinished (GNCInteractor *data)
 {
@@ -266,9 +268,7 @@
 
 char *gnc_hbci_utf8ToLatin1(GNCInteractor *data, const char *utf)
 {
-  int inbytes, outbytes;
   char *utf8extracted, *latin1;
-  char *inbuffer, *outbuffer;
 
   g_assert(data);
   if (!utf) return g_strdup("");
@@ -277,16 +277,7 @@
   utf8extracted = gnc__extractText(utf);
 /*   printf("Extracted \"%s\" into \"%s\"\n", utf, utf8extracted); */
 
-  inbuffer = utf8extracted;
-  inbytes = strlen(inbuffer);
-  outbytes = inbytes + 2;
-  latin1 = g_strndup(inbuffer, outbytes);
-  outbuffer = latin1;
-
-  iconv(data->gnc_iconv_handler, &inbuffer, &inbytes,
-	&outbuffer, &outbytes);
-  if (outbytes > 0)
-    *outbuffer = '\0';
+  latin1 = gnc_call_iconv(data->gnc_iconv_handler, utf8extracted);
 
 /*   printf("Converted \"%s\" into \"%s\"\n", utf8extracted, latin1); */
   g_free(utf8extracted);
@@ -644,8 +635,7 @@
 				   progress/data->action_max);
   }
 
-  keepAlive(data);
-  return 0;
+  return !keepAlive(data);
 }
 
 
@@ -669,8 +659,7 @@
   GNCInteractor_add_log_text (data, text);
 
   g_free(text);
-  keepAlive(data);
-  return 0;
+  return !keepAlive(data);
 }
 
 static int progressEndCB(AB_BANKING *ab, GWEN_TYPE_UINT32 id)
Index: gnc-hbci-utils.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-utils.h,v
retrieving revision 1.12.2.5
retrieving revision 1.12.2.6
diff -Lsrc/import-export/hbci/gnc-hbci-utils.h -Lsrc/import-export/hbci/gnc-hbci-utils.h -u -r1.12.2.5 -r1.12.2.6
--- src/import-export/hbci/gnc-hbci-utils.h
+++ src/import-export/hbci/gnc-hbci-utils.h
@@ -25,6 +25,7 @@
 
 #include <glib.h>
 #include <gnome.h>
+#include <iconv.h>
 
 #include <aqbanking/banking.h>
 #include <aqbanking/transaction.h>
@@ -149,4 +150,16 @@
 /** Return a newly allocated string. */
 char *gnc_AB_VALUE_toReadableString(const AB_VALUE *v);
 
+/** Returns a newly allocated gchar, converted according to the given
+   handler */
+gchar *gnc_call_iconv(iconv_t handler, const char* input);
+
+/** Returns the encoding of the current book in the format as required
+    by iconv_open(3). */
+const char *gnc_hbci_book_encoding(void);
+
+/** Returns the encoding that is required by AqBanking in the format
+    as required by iconv_open(3). */
+const char *gnc_hbci_AQBANKING_encoding(void);
+
 #endif
Index: dialog-hbcitrans.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/dialog-hbcitrans.c,v
retrieving revision 1.9.2.19
retrieving revision 1.9.2.20
diff -Lsrc/import-export/hbci/dialog-hbcitrans.c -Lsrc/import-export/hbci/dialog-hbcitrans.c -u -r1.9.2.19 -r1.9.2.20
--- src/import-export/hbci/dialog-hbcitrans.c
+++ src/import-export/hbci/dialog-hbcitrans.c
@@ -30,6 +30,7 @@
 #include <aqbanking/account.h>
 #include <aqbanking/jobsingletransfer.h>
 #include <aqbanking/jobsingledebitnote.h>
+#include <iconv.h>
 
 #include "dialog-utils.h"
 #include "gnc-ui.h"
@@ -506,7 +507,6 @@
   return result;
 }
 
-
 /** Create a new AB_TRANSACTION, fill the values from the entry
     fields into it and return it. The caller must
     AB_TRANSACTION_free() it when finished. */
@@ -515,6 +515,15 @@
 {
   /* Fill in the user-entered values */
   AB_TRANSACTION *trans = AB_Transaction_new();
+  gchar *tmpchar;
+
+  /* FIXME: The internal source encoding is hard-coded so far. This
+     needs to be fixed for the gnome2 version; the source encoding is
+     then probably utf-8 as well. iconv is also used in
+     gnc_AB_BANKING_interactors() in hbci-interaction.c. */
+  iconv_t gnc_iconv_handler =
+    iconv_open(gnc_hbci_AQBANKING_encoding(), gnc_hbci_book_encoding());
+  g_assert(gnc_iconv_handler != (iconv_t)(-1));
 	
   /* OpenHBCI newer than 0.9.8: use account's bankCode values
    * instead of the bank's ones since this is what some banks
@@ -533,19 +542,32 @@
   /* printf("Got otherAccountId %s.\n",
      AB_Transaction_otherAccountId (trans)); */
   AB_Transaction_SetRemoteCountry (trans, "DE");
-  AB_Transaction_AddRemoteName
-    (trans, gtk_entry_get_text (GTK_ENTRY (td->recp_name_entry)), FALSE);
+
+  /* Convert the result of GTK_ENTRY into UTF-8 */
+  tmpchar = gnc_call_iconv(gnc_iconv_handler, 
+			   gtk_entry_get_text (GTK_ENTRY (td->recp_name_entry)));
+  AB_Transaction_AddRemoteName (trans, tmpchar, FALSE);
+  g_free (tmpchar);
 	
   /* The last argument means: If TRUE, then the string will be only be
      appended if it doesn't exist yet. */
-  AB_Transaction_AddPurpose
-    (trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_entry)), FALSE);
-  AB_Transaction_AddPurpose
-    (trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_cont_entry)), FALSE);
-  AB_Transaction_AddPurpose
-    (trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_cont2_entry)), FALSE);
-  AB_Transaction_AddPurpose
-    (trans, gtk_entry_get_text (GTK_ENTRY (td->purpose_cont3_entry)), FALSE);
+  /* Convert the result of GTK_ENTRY into UTF-8 */
+  tmpchar = gnc_call_iconv(gnc_iconv_handler, 
+			   gtk_entry_get_text (GTK_ENTRY (td->purpose_entry)));
+  AB_Transaction_AddPurpose (trans, tmpchar, FALSE);
+  g_free (tmpchar);
+  tmpchar = gnc_call_iconv(gnc_iconv_handler, 
+			   gtk_entry_get_text (GTK_ENTRY (td->purpose_cont_entry)));
+  AB_Transaction_AddPurpose (trans, tmpchar, FALSE);
+  g_free (tmpchar);
+  tmpchar = gnc_call_iconv(gnc_iconv_handler, 
+			   gtk_entry_get_text (GTK_ENTRY (td->purpose_cont2_entry)));
+  AB_Transaction_AddPurpose (trans, tmpchar, FALSE);
+  g_free (tmpchar);
+  tmpchar = gnc_call_iconv(gnc_iconv_handler, 
+			   gtk_entry_get_text (GTK_ENTRY (td->purpose_cont3_entry)));
+  AB_Transaction_AddPurpose (trans, tmpchar, FALSE);
+  g_free (tmpchar);
 	
   /* FIXME: Replace "EUR" by account-dependent string here. */
   AB_Transaction_SetValue 
@@ -564,6 +586,7 @@
     AB_Transaction_SetTextKey (trans, 51);
   }
 
+  iconv_close(gnc_iconv_handler);
   return trans;
 }
 
Index: gnc-hbci-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/import-export/hbci/gnc-hbci-utils.c,v
retrieving revision 1.23.2.16
retrieving revision 1.23.2.17
diff -Lsrc/import-export/hbci/gnc-hbci-utils.c -Lsrc/import-export/hbci/gnc-hbci-utils.c -u -r1.23.2.16 -r1.23.2.17
--- src/import-export/hbci/gnc-hbci-utils.c
+++ src/import-export/hbci/gnc-hbci-utils.c
@@ -26,6 +26,7 @@
 #include <gnome.h>
 #include <errno.h>
 #include <iconv.h>
+#include <langinfo.h>
 #include <gwenhywfar/directory.h>
 
 #include "gnc-ui.h"
@@ -486,18 +487,10 @@
 {
   struct cb_struct *u = user_data;
   gchar **res = u->result;
-  gchar *tmp1, *tmp2, *outbuffer;
-  char *inbuffer = (char*)string;
-  size_t inbytes = strlen(string), outbytes = inbytes+2;
+  gchar *tmp1, *tmp2;
 
   if (!string) return NULL;
-  tmp1 = g_strndup (string, outbytes);
-  outbuffer = tmp1;
-
-  iconv(u->gnc_iconv_handler, &inbuffer, &inbytes,
-	&outbuffer, &outbytes);
-  if (outbytes > 0)
-    *outbuffer = '\0';
+  tmp1 = gnc_call_iconv(u->gnc_iconv_handler, string);
 
   g_strstrip (tmp1);
   if (strlen (tmp1) > 0) {
@@ -528,11 +521,8 @@
   const GWEN_STRINGLIST *h_remotename = AB_Transaction_GetRemoteName (h_trans);
   struct cb_struct cb_object;
 
-  /* FIXME: The internal target encoding is hard-coded so far. This
-     needs to be fixed for the gnome2 version; the target encoding is
-     then probably utf-8 as well. iconv is also used in
-     gnc_AB_BANKING_interactors() in hbci-interaction.c. */
-  cb_object.gnc_iconv_handler = iconv_open("ISO8859-15", "UTF-8");
+  cb_object.gnc_iconv_handler = 
+    iconv_open(gnc_hbci_book_encoding(), gnc_hbci_AQBANKING_encoding());
   g_assert(cb_object.gnc_iconv_handler != (iconv_t)(-1));
 
   /* Don't use list_string_concat_delim here since we need to
@@ -873,3 +863,36 @@
     sprintf(tmp, "%.2f", 0.0);
   return g_strdup(tmp);
 }
+
+/* Returns a newly allocated gchar, converted according to the given
+   handler */
+gchar *gnc_call_iconv(iconv_t handler, const char* input)
+{
+  char *inbuffer = (char*)input;
+  char *outbuffer, *outbufferstart;
+  int inbytes, outbytes;
+
+  inbytes = strlen(inbuffer);
+  outbytes = inbytes + 2;
+  outbufferstart = g_strndup(inbuffer, outbytes);
+  outbuffer = outbufferstart;
+  iconv(handler, &inbuffer, &inbytes, &outbuffer, &outbytes);
+  if (outbytes > 0) 
+    *outbuffer = '\0';
+  return outbufferstart;
+}
+
+const char *gnc_hbci_book_encoding()
+{
+#if HAVE_LANGINFO_CODESET
+  char* encoding = nl_langinfo(CODESET);
+#else
+  char* encoding = "ISO8859-15";
+#endif
+  return encoding;
+}
+
+const char *gnc_hbci_AQBANKING_encoding()
+{
+  return "UTF-8";
+}


More information about the gnucash-changes mailing list