From 15b50f49d41501da5bc70bbf6f981b8d33e57fb5 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Tue, 27 May 2003 23:36:35 +0000 Subject: [PATCH] 2003-05-28 Christian Stimming * src/import-export/hbci/gnc-hbci-transfer.c, dialog-hbcitrans.c, glade/hbci.glade: Add coarse GUI so that transfer templates are somehow usable. * src/import-export/hbci/gnc-hbci-kvp.[hc]: Store the online transfer templates in the book's kvp_frame. * src/import-export/hbci/gnc-hbci-trans-templ.[hc]: Add data type for online transfer templates. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8414 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 12 + src/import-export/hbci/Makefile.am | 2 + src/import-export/hbci/dialog-hbcitrans.c | 212 ++++++++++++-- src/import-export/hbci/dialog-hbcitrans.h | 3 +- src/import-export/hbci/glade/hbci.glade | 72 ++++- src/import-export/hbci/gnc-hbci-kvp.c | 18 +- src/import-export/hbci/gnc-hbci-kvp.h | 7 +- src/import-export/hbci/gnc-hbci-trans-templ.c | 273 ++++++++++++++++++ src/import-export/hbci/gnc-hbci-trans-templ.h | 90 ++++++ src/import-export/hbci/gnc-hbci-transfer.c | 30 +- 10 files changed, 687 insertions(+), 32 deletions(-) create mode 100644 src/import-export/hbci/gnc-hbci-trans-templ.c create mode 100644 src/import-export/hbci/gnc-hbci-trans-templ.h diff --git a/ChangeLog b/ChangeLog index e9b5681360..9c42e16a6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-05-28 Christian Stimming + + * src/import-export/hbci/gnc-hbci-transfer.c, dialog-hbcitrans.c, + glade/hbci.glade: Add coarse GUI so that transfer templates are + somehow usable. + + * src/import-export/hbci/gnc-hbci-kvp.[hc]: Store the online + transfer templates in the book's kvp_frame. + + * src/import-export/hbci/gnc-hbci-trans-templ.[hc]: Add data type + for online transfer templates. + 2003-05-26 Derek Atkins * src/register/ledger-core/dialog-dup-trans.c: If the "number" is diff --git a/src/import-export/hbci/Makefile.am b/src/import-export/hbci/Makefile.am index e2f0337510..6f8e17a199 100644 --- a/src/import-export/hbci/Makefile.am +++ b/src/import-export/hbci/Makefile.am @@ -12,6 +12,7 @@ libgncmod_hbci_la_SOURCES = \ gnc-hbci-utils.c \ gnc-hbci-cb.c \ gnc-hbci-transfer.c \ + gnc-hbci-trans-templ.c \ gnc-hbci-getbalance.c \ gnc-hbci-gettrans.c \ hbci-interaction.c \ @@ -36,6 +37,7 @@ noinst_HEADERS = \ gnc-hbci-gettrans.h \ gnc-hbci-kvp.h \ gnc-hbci-transfer.h \ + gnc-hbci-trans-templ.h \ gnc-hbci-utils.h \ hbci-interaction.h \ hbci-interactionP.h diff --git a/src/import-export/hbci/dialog-hbcitrans.c b/src/import-export/hbci/dialog-hbcitrans.c index c157d1b977..fcdd6ff7fb 100644 --- a/src/import-export/hbci/dialog-hbcitrans.c +++ b/src/import-export/hbci/dialog-hbcitrans.c @@ -32,15 +32,70 @@ #include "gnc-amount-edit.h" #include "gnc-hbci-utils.h" +#include "gnc-hbci-trans-templ.h" #include "dialog-hbcitrans.h" +/* -------------------------------------- */ +/* Data structure */ +/* -------------------------------------- */ +struct _trans_data +{ + GtkWidget *parent; + /* Recipient */ + GtkWidget *recp_name_entry; + GtkWidget *recp_account_entry; + GtkWidget *recp_bankcode_entry; + + /* Amount */ + GtkWidget *amount_edit; + + /* Purpose, description */ + GtkWidget *purpose_entry; + GtkWidget *purpose_cont_entry; + + /* Recipient's bank name (may be filled in automatically sometime later) */ + GtkWidget *recp_bankname_label; + + /* The template choosing option menu */ + GtkWidget *template_option; + + /* GList of GNCTransTempl */ + GList *templ; +}; +typedef struct _trans_data TransData; + + + + +/* -------------------------------------- */ +/* Prototypes; callbacks for dialog function */ +/* -------------------------------------- */ + +void template_selection_cb(GtkButton *b, gpointer user_data); +void add_template_cb(GtkButton *b, gpointer user_data); + +static void fill_template_menu_func(gpointer data, gpointer user_data) +{ + GNCTransTempl *templ = data; + GtkMenu *menu = user_data; + GtkWidget *item = gtk_menu_item_new_with_label(gnc_trans_templ_get_name(templ)); + gtk_object_set_user_data(GTK_OBJECT(item), templ); + gtk_menu_append(menu, item); +} + + +/* -------------------------------------- */ +/* Main dialog function */ +/* -------------------------------------- */ + HBCI_Transaction * gnc_hbci_trans (GtkWidget *parent, HBCI_API *api, GNCInteractor *interactor, const HBCI_Account *h_acc, const HBCI_Customer *customer, - GNC_HBCI_Transtype trans_type) + GNC_HBCI_Transtype trans_type, + GList **templ) { GtkWidget *dialog; GladeXML *xml; @@ -48,7 +103,10 @@ gnc_hbci_trans (GtkWidget *parent, gint result; const HBCI_Bank *bank; gboolean successful; - + TransData td; + + td.parent = parent; + td.templ = *templ; g_assert (api); g_assert (h_acc); g_assert (customer); @@ -64,16 +122,10 @@ gnc_hbci_trans (GtkWidget *parent, { GtkWidget *heading_label; - GtkWidget *recp_name_entry; - GtkWidget *recp_account_entry; - GtkWidget *recp_bankcode_entry; - GtkWidget *recp_bankname_label; GtkWidget *recp_name_heading; GtkWidget *recp_account_heading; GtkWidget *recp_bankcode_heading; GtkWidget *amount_hbox; - GtkWidget *purpose_entry; - GtkWidget *purpose_cont_entry; GtkWidget *orig_name_label; GtkWidget *orig_account_label; GtkWidget *orig_bankname_label; @@ -82,31 +134,31 @@ gnc_hbci_trans (GtkWidget *parent, GtkWidget *orig_account_heading; GtkWidget *orig_bankname_heading; GtkWidget *orig_bankcode_heading; - GtkWidget *amount_edit; GtkWidget *exec_later_button; - + GtkWidget *add_templ_button; + g_assert (heading_label = glade_xml_get_widget (xml, "heading_label")); g_assert - (recp_name_entry = glade_xml_get_widget (xml, "recp_name_entry")); + (td.recp_name_entry = glade_xml_get_widget (xml, "recp_name_entry")); g_assert (recp_name_heading = glade_xml_get_widget (xml, "recp_name_heading")); g_assert - (recp_account_entry = glade_xml_get_widget (xml, "recp_account_entry")); + (td.recp_account_entry = glade_xml_get_widget (xml, "recp_account_entry")); g_assert (recp_account_heading = glade_xml_get_widget (xml, "recp_account_heading")); g_assert - (recp_bankcode_entry = glade_xml_get_widget (xml, "recp_bankcode_entry")); + (td.recp_bankcode_entry = glade_xml_get_widget (xml, "recp_bankcode_entry")); g_assert (recp_bankcode_heading = glade_xml_get_widget (xml, "recp_bankcode_heading")); g_assert - (recp_bankname_label = glade_xml_get_widget (xml, "recp_bankname_label")); + (td.recp_bankname_label = glade_xml_get_widget (xml, "recp_bankname_label")); g_assert (amount_hbox = glade_xml_get_widget (xml, "amount_hbox")); g_assert - (purpose_entry = glade_xml_get_widget (xml, "purpose_entry")); + (td.purpose_entry = glade_xml_get_widget (xml, "purpose_entry")); g_assert - (purpose_cont_entry = glade_xml_get_widget (xml, "purpose_cont_entry")); + (td.purpose_cont_entry = glade_xml_get_widget (xml, "purpose_cont_entry")); g_assert (orig_name_label = glade_xml_get_widget (xml, "orig_name_label")); g_assert @@ -125,10 +177,14 @@ gnc_hbci_trans (GtkWidget *parent, (orig_bankcode_heading = glade_xml_get_widget (xml, "orig_bankcode_heading")); g_assert (exec_later_button = glade_xml_get_widget (xml, "exec_later_button")); + g_assert + (td.template_option = glade_xml_get_widget (xml, "template_optionmenu")); + g_assert + (add_templ_button = glade_xml_get_widget (xml, "add_templ_button")); - amount_edit = gnc_amount_edit_new(); - gtk_box_pack_start_defaults(GTK_BOX(amount_hbox), amount_edit); - gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount_edit), + td.amount_edit = gnc_amount_edit_new(); + gtk_box_pack_start_defaults(GTK_BOX(amount_hbox), td.amount_edit); + gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (td.amount_edit), TRUE); /* Check for what kind of transaction this should be, and change @@ -182,10 +238,22 @@ gnc_hbci_trans (GtkWidget *parent, gtk_label_set_text (GTK_LABEL (orig_bankcode_label), HBCI_Bank_bankCode (bank)); + /* fill OptionMenu for choosing a transaction template */ + g_list_foreach(td.templ, fill_template_menu_func, + gtk_option_menu_get_menu + ( GTK_OPTION_MENU (td.template_option))); + + /* Connect signals */ + gnc_option_menu_init_w_signal (td.template_option, + GTK_SIGNAL_FUNC(template_selection_cb), + &td); + gtk_signal_connect(GTK_OBJECT (add_templ_button), "clicked", + GTK_SIGNAL_FUNC(add_template_cb), &td); + /* Default button */ gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gtk_widget_grab_focus (recp_name_entry); + gtk_widget_grab_focus (td.recp_name_entry); /* Hide on close instead of destroy since we still need the values from the boxes. */ @@ -201,6 +269,8 @@ gnc_hbci_trans (GtkWidget *parent, /*result = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));*/ /* printf("hbci_trans: result button was %d.\n", result); */ + *templ = td.templ; + /* Was cancel pressed or dialog closed? 0 == execute now, 1 == scheduled for later execution (currently unimplemented) */ if ((result != 0) && (result != 1)) { @@ -228,24 +298,24 @@ gnc_hbci_trans (GtkWidget *parent, HBCI_Transaction_setOtherCountryCode (trans, 280); HBCI_Transaction_setOtherBankCode - (trans, gtk_entry_get_text (GTK_ENTRY (recp_bankcode_entry))); + (trans, gtk_entry_get_text (GTK_ENTRY (td.recp_bankcode_entry))); /* printf("Got otherBankCode %s.\n", HBCI_Transaction_otherBankCode (trans)); */ HBCI_Transaction_setOtherAccountId - (trans, gtk_entry_get_text (GTK_ENTRY (recp_account_entry))); + (trans, gtk_entry_get_text (GTK_ENTRY (td.recp_account_entry))); /* printf("Got otherAccountId %s.\n", HBCI_Transaction_otherAccountId (trans)); */ HBCI_Transaction_addOtherName - (trans, gtk_entry_get_text (GTK_ENTRY (recp_name_entry))); + (trans, gtk_entry_get_text (GTK_ENTRY (td.recp_name_entry))); HBCI_Transaction_addDescription - (trans, gtk_entry_get_text (GTK_ENTRY (purpose_entry))); + (trans, gtk_entry_get_text (GTK_ENTRY (td.purpose_entry))); HBCI_Transaction_addDescription - (trans, gtk_entry_get_text (GTK_ENTRY (purpose_cont_entry))); + (trans, gtk_entry_get_text (GTK_ENTRY (td.purpose_cont_entry))); HBCI_Transaction_setValue (trans, HBCI_Value_new_double - (gnc_amount_edit_get_damount (GNC_AMOUNT_EDIT (amount_edit)), "EUR")); + (gnc_amount_edit_get_damount (GNC_AMOUNT_EDIT (td.amount_edit)), "EUR")); /* FIXME: Replace "EUR" by account-dependent string here. */ /*printf("dialog-hbcitrans: Got value as %s .\n", HBCI_Value_toReadableString (HBCI_Transaction_value (trans)));*/ @@ -330,3 +400,93 @@ gnc_hbci_trans (GtkWidget *parent, gtk_widget_destroy (GTK_WIDGET (dialog)); return trans; } + + + +/* -------------------------------------- */ +/* Callbacks */ +/* -------------------------------------- */ +static void fill_entry(const char *str, GtkWidget *entry) { + gtk_entry_set_text (GTK_ENTRY (entry), str ? str : ""); +} + +void template_selection_cb(GtkButton *b, + gpointer user_data) +{ + TransData *td = user_data; + g_assert(td); + unsigned index = gnc_option_menu_get_active (td->template_option); + /*printf("template_selection_cd: %d is active \n", index);*/ + if ((index > 0) && (index <= g_list_length(td->templ))) + { + GNCTransTempl *templ = g_list_nth_data(td->templ, index-1); + /*printf("template_selection_cd: using template %s \n", + gnc_trans_templ_get_name(templ));*/ + + fill_entry(gnc_trans_templ_get_recp_name(templ), td->recp_name_entry); + fill_entry(gnc_trans_templ_get_recp_account(templ), td->recp_account_entry); + fill_entry(gnc_trans_templ_get_recp_bankcode(templ), td->recp_bankcode_entry); + fill_entry(gnc_trans_templ_get_purpose(templ), td->purpose_entry); + fill_entry(gnc_trans_templ_get_purpose_cont(templ), td->purpose_cont_entry); + + gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (td->amount_edit), + gnc_trans_templ_get_amount (templ)); + } +} + +/* -------------------------------------- */ +/* -------------------------------------- */ +/* Copied from window-help.c */ +static void +goto_string_cb(char * string, gpointer data) +{ + if(!data) return; + if(!string) { + *(char **)data = NULL; + } + else { + *(char **)data = g_strdup(string); + } +} +void add_template_cb(GtkButton *b, + gpointer user_data) +{ + TransData *td = user_data; + GtkWidget *dlg; + char *name; + int retval = -1; + g_assert(td); + + dlg = gnome_request_dialog(FALSE, + _("Enter name for new template:"), "", 250, + &goto_string_cb, &name, GTK_WINDOW(td->parent)); + retval = gnome_dialog_run_and_close(GNOME_DIALOG(dlg)); + + if ((retval == 0) && name && (strlen(name) > 0)) { + GNCTransTempl *r; + /*printf("add_template_cb: adding template '%s'\n", name);*/ + r = gnc_trans_templ_new_full + (name, + gtk_entry_get_text (GTK_ENTRY (td->recp_name_entry)), + gtk_entry_get_text (GTK_ENTRY (td->recp_account_entry)), + gtk_entry_get_text (GTK_ENTRY (td->recp_bankcode_entry)), + gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT (td->amount_edit)), + gtk_entry_get_text (GTK_ENTRY (td->purpose_entry)), + gtk_entry_get_text (GTK_ENTRY (td->purpose_cont_entry))); + + /* Append new template to the list. */ + td->templ = g_list_append(td->templ, r); + + /* Also append that template to the OptionMenu */ + fill_template_menu_func(r, + gtk_option_menu_get_menu + ( GTK_OPTION_MENU (td->template_option))); + /* the show_all is necessary since otherwise the new item doesn't show up */ + gtk_widget_show_all (GTK_WIDGET (gtk_option_menu_get_menu + ( GTK_OPTION_MENU (td->template_option)))); + gnc_option_menu_init_w_signal (td->template_option, + GTK_SIGNAL_FUNC(template_selection_cb), + td); + } +} + diff --git a/src/import-export/hbci/dialog-hbcitrans.h b/src/import-export/hbci/dialog-hbcitrans.h index b12e7054a3..82f861679a 100644 --- a/src/import-export/hbci/dialog-hbcitrans.h +++ b/src/import-export/hbci/dialog-hbcitrans.h @@ -44,7 +44,8 @@ gnc_hbci_trans (GtkWidget *parent, GNCInteractor *interactor, const HBCI_Account *h_acc, const HBCI_Customer *customer, - GNC_HBCI_Transtype type); + GNC_HBCI_Transtype type, + GList **templ); diff --git a/src/import-export/hbci/glade/hbci.glade b/src/import-export/hbci/glade/hbci.glade index c3183de310..86c23bfacb 100644 --- a/src/import-export/hbci/glade/hbci.glade +++ b/src/import-export/hbci/glade/hbci.glade @@ -1709,7 +1709,7 @@ Press 'Finish' now. GtkTable table6 - 19 + 20 3 False 0 @@ -2337,6 +2337,76 @@ Press 'Finish' now. Placeholder + + + GtkHBox + hbox117 + 2 + False + 4 + + 0 + 3 + 19 + 20 + 0 + 0 + False + True + False + False + True + True + + + + GtkButton + add_templ_button + 2 + True + + GTK_RELIEF_NORMAL + + 0 + False + False + GTK_PACK_END + + + + + GtkOptionMenu + template_optionmenu + True + -- No Template -- + + 0 + + 0 + False + False + GTK_PACK_END + + + + + GtkLabel + label8877442 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + GTK_PACK_END + + + diff --git a/src/import-export/hbci/gnc-hbci-kvp.c b/src/import-export/hbci/gnc-hbci-kvp.c index 0d5215fc24..c3dd9f8668 100644 --- a/src/import-export/hbci/gnc-hbci-kvp.c +++ b/src/import-export/hbci/gnc-hbci-kvp.c @@ -26,7 +26,6 @@ #define HBCI_ACCOUNT_ID "account-id" #define HBCI_BANK_CODE "bank-code" #define HBCI_COUNTRY_CODE "country-code" -#define HBCI_CONFIGFILE "config-filename" #define HBCI_TRANS_RETRIEVAL "trans-retrieval" /* Account */ @@ -90,6 +89,9 @@ void gnc_hbci_set_account_trans_retrieval (Account *a, Timespec time) /* GNCBook */ +#define HBCI_CONFIGFILE "config-filename" +#define HBCI_TEMPLATES "template-list" + char *gnc_hbci_get_book_configfile (GNCBook *b) { kvp_frame *frame = gnc_hbci_get_book_kvp (b); @@ -103,6 +105,20 @@ void gnc_hbci_set_book_configfile (GNCBook *b, const char *filename) kvp_frame_set_slot_nc (frame, HBCI_CONFIGFILE, value); gnc_book_kvp_changed (b); } +GList *gnc_hbci_get_book_template_list (GNCBook *b) +{ + kvp_frame *frame = gnc_hbci_get_book_kvp (b); + kvp_value *value = kvp_frame_get_slot (frame, HBCI_TEMPLATES); + return kvp_value_get_glist (value); +} +void gnc_hbci_set_book_template_list (GNCBook *b, GList *template_list) +{ + kvp_frame *frame = gnc_hbci_get_book_kvp (b); + kvp_value *value = kvp_value_new_glist_nc (template_list); + kvp_frame_set_slot_nc (frame, HBCI_TEMPLATES, value); + gnc_book_kvp_changed (b); +} + /* lowlevel */ /* getters for kvp frame in book */ diff --git a/src/import-export/hbci/gnc-hbci-kvp.h b/src/import-export/hbci/gnc-hbci-kvp.h index 1026018b35..a813a837c9 100644 --- a/src/import-export/hbci/gnc-hbci-kvp.h +++ b/src/import-export/hbci/gnc-hbci-kvp.h @@ -23,7 +23,6 @@ #ifndef GNC_HBCI_KVP_H #define GNC_HBCI_KVP_H -//#include #include #include "kvp_frame.h" #include "Account.h" @@ -70,6 +69,12 @@ char *gnc_hbci_get_book_configfile (GNCBook *b); * will be stored. The Book will be marked as "dirty". */ void gnc_hbci_set_book_configfile (GNCBook *b, const char *filename); +/** Returns a non-copied pointer to the GList of kvp_frames which + * eventually are the template transactions, stored in the given + * book. */ +GList *gnc_hbci_get_book_template_list (GNCBook *b); +void gnc_hbci_set_book_template_list (GNCBook *b, GList *template_list); + /* lowlevel */ /* internal getter for kvp frame in book */ diff --git a/src/import-export/hbci/gnc-hbci-trans-templ.c b/src/import-export/hbci/gnc-hbci-trans-templ.c new file mode 100644 index 0000000000..482830a84a --- /dev/null +++ b/src/import-export/hbci/gnc-hbci-trans-templ.c @@ -0,0 +1,273 @@ +/********************************************************************\ + * gnc-hbci-trans-template.c -- Templates for HBCI transactions * + * Copyright (C) 2003 Christian Stimming * + * * + * 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 * +\********************************************************************/ + +#include "config.h" + +#include "gnc-hbci-trans-templ.h" +#include + +struct _trans_data +{ + /* Name of this Template */ + gchar *name; + + /* Recipient */ + gchar *recp_name; + gchar *recp_account; + gchar *recp_bankcode; + + /* Amount */ + gnc_numeric amount; + + /* Purpose, description */ + gchar *purpose; + gchar *purpose_cont; +}; + + +GNCTransTempl *gnc_trans_templ_new() +{ + GNCTransTempl *r = g_new0(GNCTransTempl, 1); + r->amount = gnc_numeric_zero(); + return r; +} +GNCTransTempl *gnc_trans_templ_new_full(const char *name, + const char *recp_name, + const char *recp_account, + const char *recp_bankcode, + gnc_numeric amount, + const char *purpose, + const char *purpose_cont) +{ + GNCTransTempl *r = g_new0(GNCTransTempl, 1); + r->name = g_strdup(name); + r->recp_name = g_strdup(recp_name); + r->recp_account = g_strdup(recp_account); + r->recp_bankcode = g_strdup(recp_bankcode); + r->amount = amount; + r->purpose = g_strdup(purpose); + r->purpose_cont = g_strdup(purpose_cont); + return r; +} + +void gnc_trans_templ_delete(GNCTransTempl *t) +{ + if (!t) return; + if (t->name) g_free(t->name); + if (t->recp_name) g_free(t->recp_name); + if (t->recp_account) g_free(t->recp_account); + if (t->recp_bankcode) g_free(t->recp_bankcode); + if (t->purpose) g_free(t->purpose); + if (t->purpose_cont) g_free(t->purpose_cont); + g_free(t); +} +static void delete_glist_func(gpointer data, gpointer user_data) +{ + GNCTransTempl *t = data; + gnc_trans_templ_delete(t); +} +void gnc_trans_templ_delete_glist(GList *l) +{ + g_list_foreach(l, delete_glist_func, NULL); + g_list_free(l); +} + + +/* kvp_frame slot names */ +#define TT_NAME "name" +#define TT_RNAME "rnam" +#define TT_RACC "racc" +#define TT_RBCODE "rbcd" +#define TT_PURPOS "purp" +#define TT_PURPOSCT "purc" +#define TT_AMOUNT "amou" + +/** Constructor from a kvp_frame */ +GNCTransTempl *gnc_trans_templ_from_kvp(kvp_frame *k) +{ + GNCTransTempl *res = gnc_trans_templ_new(); + g_assert(k); + + res->name = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_NAME))); + res->recp_name = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_RNAME))); + res->recp_account = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_RACC))); + res->recp_bankcode = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_RBCODE))); + res->purpose = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_PURPOS))); + res->purpose_cont = g_strdup(kvp_value_get_string + (kvp_frame_get_slot(k, TT_PURPOSCT))); + res->amount = kvp_value_get_numeric(kvp_frame_get_slot(k, TT_AMOUNT)); + return res; +} + +/** Creates a kvp_frame from this TransTempl */ +kvp_frame *gnc_trans_templ_to_kvp(const GNCTransTempl *t) +{ + kvp_frame *k = kvp_frame_new(); + g_assert(t); + + kvp_frame_set_slot(k, TT_NAME, kvp_value_new_string(t->name)); + kvp_frame_set_slot(k, TT_RNAME, kvp_value_new_string(t->recp_name)); + kvp_frame_set_slot(k, TT_RACC, kvp_value_new_string(t->recp_account)); + kvp_frame_set_slot(k, TT_RBCODE, kvp_value_new_string(t->recp_bankcode)); + kvp_frame_set_slot(k, TT_PURPOS, kvp_value_new_string(t->purpose)); + kvp_frame_set_slot(k, TT_PURPOSCT, kvp_value_new_string(t->purpose_cont)); + kvp_frame_set_slot(k, TT_AMOUNT, kvp_value_new_gnc_numeric(t->amount)); + return k; +} + +/** Creates a GList of GNCTransTempl from a GList of kvp_values which + in turn contain a kvp_frame. */ +static void glist_from_kvp_func(gpointer data, gpointer user_data) +{ + GList **tmp = user_data; + GList *res = *tmp; + kvp_value *k = data; + *tmp = g_list_append(res, gnc_trans_templ_from_kvp(kvp_value_get_frame(k))); +} +/** Creates a GList of GNCTransTempl from a GList of kvp_values which + in turn contain a kvp_frame. */ +GList *gnc_trans_templ_glist_from_kvp_glist(GList *v) +{ + GList *res = NULL; + if (!v) return NULL; + + g_list_foreach (v, glist_from_kvp_func, &res); + return res; +} + + +/** Creates a GList of kvp_value (which in turn contain a kvp_frame) + from a GList of GNCTransTempl. */ +static void glist_to_kvp_func(gpointer data, gpointer user_data) +{ + GList **tmp = user_data; + GList *res = *tmp; + GNCTransTempl *g = data; + *tmp = g_list_append(res, + kvp_value_new_frame_nc(gnc_trans_templ_to_kvp(g))); +} +/** Creates a GList of kvp_value (which in turn contain a kvp_frame) + from a GList of GNCTransTempl. */ +GList *gnc_trans_templ_kvp_glist_from_glist(GList *k) +{ + GList *res = NULL; + if (!k) return NULL; + + g_list_foreach (k, glist_to_kvp_func, &res); + return res; +} + + + +/* Value accessors. + * + * Gee, how I *HATE* OO programming in C! This STINKS! barf barf barf */ +const char *gnc_trans_templ_get_name(const GNCTransTempl *t) +{ + g_assert(t); + return t->name; +} +const char *gnc_trans_templ_get_recp_name(const GNCTransTempl *t) +{ + g_assert(t); + return t->recp_name; +} +const char *gnc_trans_templ_get_recp_account(const GNCTransTempl *t) +{ + g_assert(t); + return t->recp_account; +} +const char *gnc_trans_templ_get_recp_bankcode(const GNCTransTempl *t) +{ + g_assert(t); + return t->recp_bankcode; +} +gnc_numeric gnc_trans_templ_get_amount(const GNCTransTempl *t) +{ + g_assert(t); + return t->amount; +} +const char *gnc_trans_templ_get_purpose(const GNCTransTempl *t) +{ + g_assert(t); + return t->purpose; +} +const char *gnc_trans_templ_get_purpose_cont(const GNCTransTempl *t) +{ + g_assert(t); + return t->purpose_cont; +} +/** value storing. This sucks even more. barf barf barf again */ +void gnc_trans_templ_set_amount(GNCTransTempl *t, gnc_numeric n) +{ + g_assert(t); + t->amount = n; +} +void gnc_trans_templ_set_name(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->name) + g_free(t->name); + t->name = g_strdup(c); +} +void gnc_trans_templ_set_recp_name(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->recp_name) + g_free(t->recp_name); + t->recp_name = g_strdup(c); +} +void gnc_trans_templ_set_recp_account(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->recp_account) + g_free(t->recp_account); + t->recp_account = g_strdup(c); +} +void gnc_trans_templ_set_recp_bankcode(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->recp_bankcode) + g_free(t->recp_bankcode); + t->recp_bankcode = g_strdup(c); +} +void gnc_trans_templ_set_purpose(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->purpose) + g_free(t->purpose); + t->purpose = g_strdup(c); +} +void gnc_trans_templ_set_purpose_cont(GNCTransTempl *t, const char *c) +{ + g_assert(t); + if (t->purpose_cont) + g_free(t->purpose_cont); + t->purpose_cont = g_strdup(c); +} + + diff --git a/src/import-export/hbci/gnc-hbci-trans-templ.h b/src/import-export/hbci/gnc-hbci-trans-templ.h new file mode 100644 index 0000000000..acb3b720ae --- /dev/null +++ b/src/import-export/hbci/gnc-hbci-trans-templ.h @@ -0,0 +1,90 @@ +/********************************************************************\ + * gnc-hbci-trans-templ.h -- Templates for HBCI transactions * + * Copyright (C) 2003 Christian Stimming * + * * + * 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 * +\********************************************************************/ + +/** @file gnc-hbci-trans-templ.h Templates for HBCI transactions */ + +#include "gnc-numeric.h" +#include "kvp_frame.h" + +/** A template for a HBCI transaction */ +typedef struct _trans_data GNCTransTempl; + +/** @name Constructor */ +/*@{*/ +GNCTransTempl *gnc_trans_templ_new(void); +GNCTransTempl *gnc_trans_templ_new_full(const char *name, + const char *recp_name, + const char *recp_account, + const char *recp_bankcode, + gnc_numeric amount, + const char *purpose, + const char *purpose_cont); + +void gnc_trans_templ_delete(GNCTransTempl *t); +void gnc_trans_templ_delete_glist(GList *l); +/*@}*/ + +/** @name Serialization -- to kvp_frame and back */ +/*@{*/ +/** Constructor from a kvp_frame (the kvp_frame is left unchanged) */ +GNCTransTempl *gnc_trans_templ_from_kvp(kvp_frame *k); +/** Creates a kvp_frame from this TransTempl */ +kvp_frame *gnc_trans_templ_to_kvp(const GNCTransTempl *t); + +/** Creates a GList of GNCTransTempl from a GList of kvp_values which + in turn contain a kvp_frame. */ +GList *gnc_trans_templ_glist_from_kvp_glist(GList *v); +/** Creates a GList of kvp_value (which in turn contain a kvp_frame) + from a GList of GNCTransTempl. */ +GList *gnc_trans_templ_kvp_glist_from_glist(GList *k); +/*@}*/ + +/** @name GNCTransTempl value access */ +/*@{*/ +const char *gnc_trans_templ_get_name(const GNCTransTempl *t); +const char *gnc_trans_templ_get_recp_name(const GNCTransTempl *t); +const char *gnc_trans_templ_get_recp_account(const GNCTransTempl *t); +const char *gnc_trans_templ_get_recp_bankcode(const GNCTransTempl *t); + +/** Amount */ +gnc_numeric gnc_trans_templ_get_amount(const GNCTransTempl *t); + +/** Purpose, description */ +const char *gnc_trans_templ_get_purpose(const GNCTransTempl *t); +const char *gnc_trans_templ_get_purpose_cont(const GNCTransTempl *t); +/*@}*/ + +/** @name GNCTransTempl value storing */ +/*@{*/ +void gnc_trans_templ_set_name(GNCTransTempl *t, const char *); +void gnc_trans_templ_set_recp_name(GNCTransTempl *t, const char *); +void gnc_trans_templ_set_recp_account(GNCTransTempl *t, const char *); +void gnc_trans_templ_set_recp_bankcode(GNCTransTempl *t, const char *); + +/** Amount */ +void gnc_trans_templ_set_amount(GNCTransTempl *t, gnc_numeric ); + +/** Purpose, description */ +void gnc_trans_templ_set_purpose(GNCTransTempl *t, const char *); +void gnc_trans_templ_set_purpose_cont(GNCTransTempl *t, const char *); +/*@}*/ + diff --git a/src/import-export/hbci/gnc-hbci-transfer.c b/src/import-export/hbci/gnc-hbci-transfer.c index 13682271fd..606d34c7e9 100644 --- a/src/import-export/hbci/gnc-hbci-transfer.c +++ b/src/import-export/hbci/gnc-hbci-transfer.c @@ -34,7 +34,8 @@ #include "hbci-interaction.h" #include "gnc-hbci-utils.h" - +#include "gnc-hbci-trans-templ.h" +#include "gnc-hbci-kvp.h" void @@ -91,10 +92,35 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc, HBCI_Customer_custId ((HBCI_Customer *)customer));*/ { + GList *template_list = + gnc_trans_templ_glist_from_kvp_glist + ( gnc_hbci_get_book_template_list + ( xaccAccountGetBook(gnc_acc))); + unsigned nr_templates = g_list_length(template_list); + /* Now open the HBCI_trans_dialog. */ HBCI_Transaction *h_trans = gnc_hbci_trans (parent, api, interactor, h_acc, customer, - trans_type); + trans_type, &template_list); + + /* New templates? If yes, store them */ + if (nr_templates < g_list_length(template_list)) { + if (h_trans || (gnc_verify_dialog_parented + (parent, + FALSE, + _("You have created a new online transfer template, but \n" + "you cancelled the transfer dialog. Do you nevertheless \n" + "want to store the new online transfer template?")))) { + GList *kvp_list = gnc_trans_templ_kvp_glist_from_glist (template_list); + /*printf ("Now having %d templates. List: '%s'\n", + g_list_length(template_list), + kvp_value_glist_to_string(kvp_list));*/ + gnc_hbci_set_book_template_list + (xaccAccountGetBook(gnc_acc), kvp_list); + } + } + gnc_trans_templ_delete_glist (template_list); + if (!h_trans) return;