diff --git a/ChangeLog b/ChangeLog index 8be8ae2797..535df35658 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-03-08 Christian Stimming + + * src/import-export/hbci/dialog-hbcitrans.c, dialog-hbcitrans.h, + glade/hbci.glade, gnc-hbci-transfer.c: Transfer template management + GUI added by Bernd Wagner + 2004-03-03 Derek Atkins * src/register/ledger-core/split-register-load.c: make the code a diff --git a/src/import-export/hbci/dialog-hbcitrans.c b/src/import-export/hbci/dialog-hbcitrans.c index f35b3843db..3a540d38d7 100644 --- a/src/import-export/hbci/dialog-hbcitrans.c +++ b/src/import-export/hbci/dialog-hbcitrans.c @@ -1,6 +1,8 @@ /********************************************************************\ * dialog-hbcitrans.c -- dialog for hbci transaction * * Copyright (C) 2002 Christian Stimming * + * Copyright (C) 2004 Bernd Wagner (changes for * + * online transaction templates) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -67,12 +69,18 @@ struct _trans_data /* Recipient's bank name (may be filled in automatically sometime later) */ GtkWidget *recp_bankname_label; - /* The template choosing option menu */ - GtkWidget *template_option; + /* The template choosing GtkList */ + GtkWidget *template_gtk_list; + /* The selected template in the list */ + GtkWidget *selected_template; + /* GList of GNCTransTempl */ GList *templ; + /* Flag, if template list has been changed */ + gboolean templ_changed; + /* The HBCI transaction that got created here */ HBCI_Transaction *hbci_trans; @@ -98,6 +106,8 @@ void gnc_hbci_dialog_delete(HBCITransDialog *td) if (td->hbci_trans) HBCI_Transaction_delete (td->hbci_trans); + td->selected_template = NULL; + gtk_widget_destroy (GTK_WIDGET (td->dialog)); #if HAVE_KTOBLZCHECK_H AccountNumberCheck_delete(td->blzcheck); @@ -124,6 +134,11 @@ Transaction *gnc_hbci_dialog_get_gtrans(const HBCITransDialog *td) g_assert(td); return td->gnc_trans; } +gboolean gnc_hbci_dialog_get_templ_changed(const HBCITransDialog *td) +{ + g_assert(td); + return td->templ_changed; +} void gnc_hbci_dialog_hide(HBCITransDialog *td) { g_assert(td); @@ -146,8 +161,17 @@ gboolean check_ktoblzcheck(GtkWidget *parent, const HBCITransDialog *td, const HBCI_Transaction *trans); +void on_template_list_select_child(GtkList *list, GtkWidget *widget, gpointer user_data); +void on_template_list_selection_changed(GtkList *list, gpointer user_data); +void on_template_list_unselect_child(GtkList *list, GtkWidget *widget, gpointer user_data); + void template_selection_cb(GtkButton *b, gpointer user_data); void add_template_cb(GtkButton *b, gpointer user_data); +void moveup_template_cb(GtkButton *button, gpointer user_data); +void movedown_template_cb(GtkButton *button, gpointer user_data); +void sort_template_cb(GtkButton *button, gpointer user_data); +void del_template_cb(GtkButton *button, gpointer user_data); + void blz_changed_cb(GtkEditable *e, gpointer user_data); @@ -162,20 +186,20 @@ void blz_changed_cb(GtkEditable *e, gpointer user_data); * constructor */ -static void fill_template_menu_func(gpointer data, gpointer user_data) +static void fill_template_list_func(gpointer data, gpointer user_data) { GNCTransTempl *templ = data; - GtkMenu *menu = user_data; + GtkList *list = user_data; GtkWidget *item; g_assert(templ); - g_assert(menu); + g_assert(list); - item = gtk_menu_item_new_with_label(gnc_trans_templ_get_name(templ)); + item = gtk_list_item_new_with_label(gnc_trans_templ_get_name(templ)); g_assert(item); gtk_object_set_user_data(GTK_OBJECT(item), templ); - gtk_menu_append(menu, item); + gtk_container_add(GTK_CONTAINER(list), item ); } HBCITransDialog * @@ -226,6 +250,10 @@ gnc_hbci_dialog_new (GtkWidget *parent, GtkWidget *orig_bankcode_heading; GtkWidget *exec_later_button; GtkWidget *add_templ_button; + GtkWidget *moveup_templ_button; + GtkWidget *movedown_templ_button; + GtkWidget *sort_templ_button; + GtkWidget *del_templ_button; g_assert (heading_label = glade_xml_get_widget (xml, "heading_label")); @@ -268,9 +296,17 @@ gnc_hbci_dialog_new (GtkWidget *parent, 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")); + (td->template_gtk_list = glade_xml_get_widget (xml, "template_list")); g_assert (add_templ_button = glade_xml_get_widget (xml, "add_templ_button")); + g_assert + (moveup_templ_button = glade_xml_get_widget (xml, "moveup_templ_button")); + g_assert + (movedown_templ_button = glade_xml_get_widget (xml, "movedown_templ_button")); + g_assert + (sort_templ_button = glade_xml_get_widget (xml, "sort_templ_button")); + g_assert + (del_templ_button = glade_xml_get_widget (xml, "del_templ_button")); td->amount_edit = gnc_amount_edit_new(); gtk_box_pack_start_defaults(GTK_BOX(amount_hbox), td->amount_edit); @@ -330,17 +366,41 @@ gnc_hbci_dialog_new (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))); + /* fill list for choosing a transaction template */ + g_list_foreach(td->templ, fill_template_list_func, + GTK_LIST (td->template_gtk_list)); + + td->selected_template = NULL; + td->templ_changed = FALSE; /* Connect signals */ - gnc_option_menu_init_w_signal (td->template_option, +/* gnc_option_menu_init_w_signal (td->template_option, GTK_SIGNAL_FUNC(template_selection_cb), - td); + td); */ + gtk_signal_connect (GTK_OBJECT (td->template_gtk_list), "select_child", + GTK_SIGNAL_FUNC (on_template_list_select_child), + td); + gtk_signal_connect(GTK_OBJECT (add_templ_button), "clicked", GTK_SIGNAL_FUNC(add_template_cb), td); + + gtk_signal_connect (GTK_OBJECT (moveup_templ_button), "clicked", + GTK_SIGNAL_FUNC (moveup_template_cb), + td); + + gtk_signal_connect (GTK_OBJECT (movedown_templ_button), "clicked", + GTK_SIGNAL_FUNC (movedown_template_cb), + td); + + gtk_signal_connect (GTK_OBJECT (sort_templ_button), "clicked", + GTK_SIGNAL_FUNC (sort_template_cb), + td); + + gtk_signal_connect (GTK_OBJECT (del_templ_button), "clicked", + GTK_SIGNAL_FUNC (del_template_cb), + td); + + gtk_signal_connect(GTK_OBJECT (td->recp_bankcode_entry), "changed", GTK_SIGNAL_FUNC(blz_changed_cb), td); @@ -619,31 +679,53 @@ 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) + +void +on_template_list_select_child (GtkList *list, + GtkWidget *widget, + gpointer user_data) { HBCITransDialog *td = user_data; - unsigned index; g_assert(td); - 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));*/ + + td->selected_template = widget; + + GNCTransTempl *templ = gtk_object_get_user_data (GTK_OBJECT(widget)) ; 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_amount_edit_set_amount (GNC_AMOUNT_EDIT (td->amount_edit), gnc_trans_templ_get_amount (templ)); - } + +} + + +void +on_template_list_selection_changed (GtkList *list, + gpointer user_data) +{ + +} + + +void +on_template_list_unselect_child (GtkList *list, + GtkWidget *widget, + gpointer user_data) +{ + HBCITransDialog *td = user_data; + g_assert(td); + + td->selected_template = NULL; + } + + void blz_changed_cb(GtkEditable *e, gpointer user_data) { #if HAVE_KTOBLZCHECK_H @@ -694,6 +776,8 @@ void add_template_cb(GtkButton *b, GtkWidget *dlg; char *name; int retval = -1; + GNCTransTempl *t; + gint index; g_assert(td); dlg = gnome_request_dialog(FALSE, @@ -713,22 +797,167 @@ void add_template_cb(GtkButton *b, 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); + if (td->selected_template) { + t = gtk_object_get_user_data(GTK_OBJECT(td->selected_template)); + + index = 1+gtk_list_child_position(GTK_LIST(td->template_gtk_list), td->selected_template); + } + else index = 0; + + td->templ = g_list_insert(td->templ, r, index); - /* 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); + td->templ_changed = TRUE; + + gtk_list_clear_items(GTK_LIST(td->template_gtk_list), 0, -1); + + /* fill list for choosing a transaction template */ + g_list_foreach(td->templ, fill_template_list_func, + GTK_LIST (td->template_gtk_list)); + + gtk_list_select_item(GTK_LIST(td->template_gtk_list), index); + + /* the show_all is necessary since otherwise the new item doesn't show up */ + gtk_widget_show_all (GTK_WIDGET ( GTK_LIST (td->template_gtk_list))); } } + +void +moveup_template_cb(GtkButton *button, + gpointer user_data) +{ + HBCITransDialog *td = user_data; + GNCTransTempl *t; + gint index; + g_assert(td); + + if (td->selected_template) { + t = gtk_object_get_user_data(GTK_OBJECT(td->selected_template)); + + index = gtk_list_child_position(GTK_LIST(td->template_gtk_list), td->selected_template); + + if (index > 0) { + td->templ = g_list_remove( td->templ, t); + td->templ = g_list_insert( td->templ, t, index-1); + + td->templ_changed = TRUE; + gtk_list_clear_items(GTK_LIST(td->template_gtk_list), 0, -1); + + /* fill list for choosing a transaction template */ + g_list_foreach(td->templ, fill_template_list_func, + GTK_LIST (td->template_gtk_list)); + + gtk_list_select_item(GTK_LIST(td->template_gtk_list), index-1); + + gtk_widget_show_all (GTK_WIDGET ( GTK_LIST (td->template_gtk_list))); + } + } +} + + +void +movedown_template_cb(GtkButton *button, + gpointer user_data) +{ + HBCITransDialog *td = user_data; + GNCTransTempl *t; + gint index; + g_assert(td); + + if (td->selected_template) { + t = gtk_object_get_user_data(GTK_OBJECT(td->selected_template)); + + index = gtk_list_child_position(GTK_LIST(td->template_gtk_list), td->selected_template); + + if (index < g_list_length(td->templ)-1) { + td->templ = g_list_remove( td->templ, t); + td->templ = g_list_insert( td->templ, t, index+1); + + td->templ_changed = TRUE; + gtk_list_clear_items(GTK_LIST(td->template_gtk_list), 0, -1); + + /* fill list for choosing a transaction template */ + g_list_foreach(td->templ, fill_template_list_func, + GTK_LIST (td->template_gtk_list)); + + gtk_list_select_item(GTK_LIST(td->template_gtk_list), index+1); + + gtk_widget_show_all (GTK_WIDGET ( GTK_LIST (td->template_gtk_list))); + } + } +} + +static gint comparefunc(const gconstpointer e1, + const gconstpointer e2) +{ + return g_strcasecmp(gnc_trans_templ_get_name((GNCTransTempl*)e1), + gnc_trans_templ_get_name((GNCTransTempl*)e2)); + +} + +void +sort_template_cb(GtkButton *button, + gpointer user_data) +{ + HBCITransDialog *td = user_data; + g_assert(td); + + if (gnc_verify_dialog (td->parent, + FALSE, "%s", _("Do you really want to sort the list of templates?"))) { + + td->templ = g_list_sort( td->templ, comparefunc); + + td->templ_changed = TRUE; + + gtk_list_clear_items(GTK_LIST(td->template_gtk_list), 0, -1); + + /* fill list for choosing a transaction template */ + g_list_foreach(td->templ, fill_template_list_func, + GTK_LIST (td->template_gtk_list)); + + gtk_list_unselect_all ( GTK_LIST (td->template_gtk_list) ); + + gtk_widget_show_all (GTK_WIDGET ( GTK_LIST (td->template_gtk_list))); + } +} + + + +void +del_template_cb(GtkButton *button, + gpointer user_data) +{ + HBCITransDialog *td = user_data; + GNCTransTempl *t; + gint index; + g_assert(td); + + if (td->selected_template) { + + t = gtk_object_get_user_data(GTK_OBJECT(td->selected_template)); + + index = gtk_list_child_position(GTK_LIST(td->template_gtk_list), td->selected_template); + + if (gnc_verify_dialog (td->parent, + FALSE, _("Do you really want to delete the template '%s'?"), + gnc_trans_templ_get_name(g_list_nth_data(td->templ, index)))) { + gtk_list_clear_items(GTK_LIST(td->template_gtk_list), index, index+1); + + td->templ = g_list_remove( td->templ, t); + td->templ_changed = TRUE; + + gnc_trans_templ_delete(t); + + gtk_list_unselect_all ( GTK_LIST (td->template_gtk_list) ); + + gtk_widget_show_all (GTK_WIDGET ( GTK_LIST (td->template_gtk_list))); + + } + } +} + + + void gnc_hbci_dialog_xfer_cb(Transaction *trans, gpointer user_data) { HBCITransDialog *td = user_data; diff --git a/src/import-export/hbci/dialog-hbcitrans.h b/src/import-export/hbci/dialog-hbcitrans.h index e64f498640..9de15e3425 100644 --- a/src/import-export/hbci/dialog-hbcitrans.h +++ b/src/import-export/hbci/dialog-hbcitrans.h @@ -1,6 +1,8 @@ /********************************************************************\ * dialog-hbcitrans.h -- dialog for HBCI transaction data * * Copyright (C) 2002 Christian Stimming * + * Copyright (C) 2004 Bernd Wagner (changes for * + * online transaction templates) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -68,6 +70,8 @@ void gnc_hbci_dialog_delete(HBCITransDialog *td); GtkWidget *gnc_hbci_dialog_get_parent(const HBCITransDialog *td); /** Return the GList of transaction templates. */ GList *gnc_hbci_dialog_get_templ(const HBCITransDialog *td); +/** Return the change status of the template list */ +gboolean gnc_hbci_dialog_get_templ_changed(const HBCITransDialog *td) ; /** Return the HBCI_Transaction. */ const HBCI_Transaction *gnc_hbci_dialog_get_htrans(const HBCITransDialog *td); /** Return the gnucash Transaction. */ diff --git a/src/import-export/hbci/glade/hbci.glade b/src/import-export/hbci/glade/hbci.glade index f5a3ce27bb..8432cee46b 100644 --- a/src/import-export/hbci/glade/hbci.glade +++ b/src/import-export/hbci/glade/hbci.glade @@ -1746,7 +1746,7 @@ Press 'Finish' now. GtkTable table6 - 20 + 21 3 False 0 @@ -1907,25 +1907,6 @@ Press 'Finish' now. - - GtkHSeparator - hseparator5 - - 0 - 3 - 6 - 7 - 0 - 0 - False - True - False - False - True - True - - - GtkLabel recp_bankname_heading @@ -2384,8 +2365,8 @@ Press 'Finish' now. 0 3 - 19 - 20 + 20 + 21 0 0 False @@ -2397,33 +2378,156 @@ Press 'Finish' now. - GtkButton - add_templ_button - 2 - True - - GTK_RELIEF_NORMAL + GtkVBox + vbox158 + False + 0 0 False False GTK_PACK_END + + + GtkButton + add_templ_button + 2 + True + + clicked + add_template_cb + Sun, 19 Oct 2003 19:52:26 GMT + + + GTK_RELIEF_NORMAL + + 0 + False + False + + + + + GtkButton + moveup_templ_button + 2 + True + + clicked + moveup_templ_cb + Sun, 08 Feb 2004 17:48:19 GMT + + GNOME_STOCK_BUTTON_UP + GTK_RELIEF_NORMAL + + 0 + False + False + + + + + GtkButton + movedown_templ_button + 2 + True + + clicked + movedown_templ_cb + Sun, 08 Feb 2004 17:48:35 GMT + + GNOME_STOCK_BUTTON_DOWN + GTK_RELIEF_NORMAL + + 0 + False + False + + + + + GtkButton + sort_templ_button + 2 + True + + clicked + sort_templ_cb + Sun, 08 Feb 2004 17:48:52 GMT + + + GTK_RELIEF_NORMAL + + 10 + False + False + + + + + GtkButton + del_templ_button + 2 + True + + clicked + del_template_cb + Sun, 19 Oct 2003 19:55:28 GMT + + + GTK_RELIEF_NORMAL + + 0 + False + False + + - GtkOptionMenu - template_optionmenu - True - -- No Template -- - - 0 + GtkScrolledWindow + template_scrolledwindow + 350 + 142 + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_UPDATE_CONTINUOUS + GTK_UPDATE_CONTINUOUS 0 False False GTK_PACK_END + + + GtkViewport + viewport1 + GTK_SHADOW_IN + + + GtkList + template_list + False + + select_child + on_template_list_select_child + Sun, 19 Oct 2003 20:56:25 GMT + + + selection_changed + on_template_list_selection_changed + Sun, 19 Oct 2003 20:57:16 GMT + + + unselect_child + on_template_list_unselect_child + Sun, 19 Oct 2003 20:57:22 GMT + + GTK_SELECTION_SINGLE + + @@ -2444,6 +2548,44 @@ Press 'Finish' now. + + + GtkHSeparator + hseparator8 + + 0 + 3 + 19 + 20 + 0 + 1 + False + True + False + False + True + True + + + + + GtkHSeparator + hseparator5 + + 0 + 3 + 6 + 7 + 0 + 1 + False + True + False + False + True + True + + diff --git a/src/import-export/hbci/gnc-hbci-transfer.c b/src/import-export/hbci/gnc-hbci-transfer.c index 32e7385eb5..b9c9835757 100644 --- a/src/import-export/hbci/gnc-hbci-transfer.c +++ b/src/import-export/hbci/gnc-hbci-transfer.c @@ -1,6 +1,8 @@ /********************************************************************\ * gnc-hbci-transfer.c -- hbci transfer functions * * Copyright (C) 2002 Christian Stimming * + * Copyright (C) 2004 Bernd Wagner (minor changes for * + * online transaction templates) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -84,7 +86,6 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc, gnc_trans_templ_glist_from_kvp_glist ( gnc_hbci_get_book_template_list ( xaccAccountGetBook(gnc_acc))); - unsigned nr_templates; int result; gboolean successful; HBCITransDialog *td; @@ -99,16 +100,14 @@ gnc_hbci_maketrans (GtkWidget *parent, Account *gnc_acc, /* Repeat until HBCI action was successful or user pressed cancel */ do { - nr_templates = g_list_length(template_list); - /* Let the user enter the values. If cancel is pressed, -1 is returned. */ result = gnc_hbci_dialog_run_until_ok(td, h_acc); /* Set the template list in case it got modified. */ template_list = gnc_hbci_dialog_get_templ(td); - /* New templates? If yes, store them */ - if (nr_templates < g_list_length(template_list)) - maketrans_save_templates(parent, gnc_acc, template_list, (result >= 0)); + /* templates changed? If yes, store them */ + if (gnc_hbci_dialog_get_templ_changed(td) ) + maketrans_save_templates(parent, gnc_acc, template_list, (result >= 0)); if (result < 0) { break; @@ -184,9 +183,9 @@ void maketrans_save_templates(GtkWidget *parent, Account *gnc_acc, (parent, FALSE, "%s", - _("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?"))) { + _("You have changed the list of online transfer templates,\n" + "but you cancelled the transfer dialog.\n" + "Do you nevertheless want to store the changes?"))) { 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),