HBCI behaviour and encoding improvements.

2005-03-20  Christian Stimming  <stimming@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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10937 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2005-03-20 13:04:25 +00:00
parent ba04a3577e
commit 803907e022
5 changed files with 101 additions and 46 deletions

View File

@ -1,10 +1,17 @@
2005-03-20 Christian Stimming <stimming@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@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@tuhh.de>

View File

@ -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 @@ int gnc_hbci_dialog_run_until_ok(HBCITransDialog *td,
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 @@ hbci_trans_fill_values(const AB_ACCOUNT *h_acc, HBCITransDialog *td)
{
/* 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 @@ hbci_trans_fill_values(const AB_ACCOUNT *h_acc, HBCITransDialog *td)
/* 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 @@ hbci_trans_fill_values(const AB_ACCOUNT *h_acc, HBCITransDialog *td)
AB_Transaction_SetTextKey (trans, 51);
}
iconv_close(gnc_iconv_handler);
return trans;
}

View File

@ -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 @@ static void *gnc_list_string_cb (const char *string, void *user_data)
{
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 @@ char *gnc_hbci_descr_tognc (const AB_TRANSACTION *h_trans)
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 @@ char *gnc_AB_VALUE_toReadableString(const AB_VALUE *v)
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";
}

View File

@ -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 @@ char *gnc_hbci_memo_tognc (const AB_TRANSACTION *h_trans);
/** 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

View File

@ -58,7 +58,8 @@ GNCInteractor *gnc_AB_BANKING_interactors (AB_BANKING *api, GtkWidget *parent)
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 @@ static void GNCInteractor_setRunning (GNCInteractor *data)
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 @@ gchar *gnc__extractText(const char *text)
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 @@ char *gnc_hbci_utf8ToLatin1(GNCInteractor *data, const char *utf)
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 @@ static int progressAdvanceCB(AB_BANKING *ab, GWEN_TYPE_UINT32 id,
progress/data->action_max);
}
keepAlive(data);
return 0;
return !keepAlive(data);
}
@ -669,8 +659,7 @@ static int progressLogCB(AB_BANKING *ab, GWEN_TYPE_UINT32 id,
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)