From 38bafcce063bf9904b74e2b9e060cfe1e4ddafda Mon Sep 17 00:00:00 2001 From: "Dr. Peter Zimmerer" Date: Mon, 2 Mar 2020 16:54:03 +0100 Subject: [PATCH] Bug 797636 - Incorrect Online account matches cannot be deleted A push button with text "Delete selected matches" is added to the "Match Online accounts with GnuCash accounts" page of the "Online Banking Setup" tool. Additionally, the underlying tree view is set to multiple selection mode from single selection mode. Pushing the button will remove the matched GnuCash account from all selected AqBanking (Online) accounts. --- .../import-export/aqb/assistant-ab-initial.c | 73 +++++++++++++++++-- .../aqb/assistant-ab-initial.glade | 37 ++++++++-- 2 files changed, 97 insertions(+), 13 deletions(-) diff --git a/gnucash/import-export/aqb/assistant-ab-initial.c b/gnucash/import-export/aqb/assistant-ab-initial.c index 13425a67ca..946bf57319 100644 --- a/gnucash/import-export/aqb/assistant-ab-initial.c +++ b/gnucash/import-export/aqb/assistant-ab-initial.c @@ -89,6 +89,7 @@ gboolean aai_key_press_event_cb(GtkWidget *widget, GdkEventKey *event, gpointer void aai_wizard_page_prepare (GtkAssistant *assistant, gpointer user_data); void aai_wizard_button_clicked_cb(GtkButton *button, gpointer user_data); +void aai_match_delete_button_clicked_cb(GtkButton *button, gpointer user_data); #ifdef AQBANKING6 static guint aai_ab_account_hash(gconstpointer v); @@ -106,6 +107,8 @@ static gboolean find_gnc_acc_cb(gpointer key, gpointer value, gpointer user_data static gboolean clear_line_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data); static void account_list_clicked_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data); +static void delete_account_match(ABInitialInfo *info, RevLookupData *data); +static void delete_selected_match_cb(gpointer data, gpointer user_data); static void insert_acc_into_revhash_cb(gpointer ab_acc, gpointer gnc_acc, gpointer revhash); static void remove_acc_from_revhash_cb(gpointer ab_acc, gpointer gnc_acc, gpointer revhash); static void clear_kvp_acc_cb(gpointer key, gpointer value, gpointer user_data); @@ -305,6 +308,66 @@ aai_wizard_button_clicked_cb(GtkButton *button, gpointer user_data) LEAVE(" "); } +static void delete_account_match(ABInitialInfo *info, RevLookupData *data) +{ + g_return_if_fail(info && info->gnc_hash && + info->account_view && data && data->ab_acc); + + g_hash_table_remove(info->gnc_hash, data->ab_acc); + gtk_tree_model_foreach( + GTK_TREE_MODEL(info->account_store), + (GtkTreeModelForeachFunc) clear_line_cb, + data); +} + +static void +delete_selected_match_cb(gpointer data, gpointer user_data) +{ + GNC_AB_ACCOUNT_SPEC *ab_acc = NULL; + GtkTreeIter iter; + GtkTreeModel *model = NULL; + RevLookupData revLookupData = {NULL, NULL}; + + GtkTreePath *path = (GtkTreePath *) data; + ABInitialInfo *info = (ABInitialInfo *) user_data; + g_return_if_fail(path && info && info->account_view); + + model = gtk_tree_view_get_model(info->account_view); + g_return_if_fail(model); + + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gtk_tree_model_get(model, &iter, ACCOUNT_LIST_COL_AB_ACCT, &revLookupData.ab_acc, -1); + if (revLookupData.ab_acc) + delete_account_match(info, &revLookupData); + } +} + +void +aai_match_delete_button_clicked_cb(GtkButton *button, gpointer user_data) +{ + GList *selected_matches = NULL; + GtkTreeSelection *selection = NULL; + ABInitialInfo *info = (ABInitialInfo *) user_data; + + g_return_if_fail(info && info->api && info->account_view && info->gnc_hash); + + PINFO("Selected account matches are deleted"); + + selection = gtk_tree_view_get_selection (info->account_view); + if (selection) + { + selected_matches = gtk_tree_selection_get_selected_rows (selection, NULL); + if (selected_matches) + { + g_list_foreach (selected_matches, delete_selected_match_cb, info); + g_list_free_full ( + selected_matches, + (GDestroyNotify) gtk_tree_path_free); + } + } +} + #ifdef AQBANKING6 static guint aai_ab_account_hash (gconstpointer v) @@ -648,13 +711,7 @@ account_list_clicked_cb (GtkTreeView *view, GtkTreePath *path, g_hash_table_find(info->gnc_hash, (GHRFunc) find_gnc_acc_cb, &data); if (data.ab_acc) - { - g_hash_table_remove(info->gnc_hash, data.ab_acc); - gtk_tree_model_foreach( - GTK_TREE_MODEL(info->account_store), - (GtkTreeModelForeachFunc) clear_line_cb, - &data); - } + delete_account_match(info, &data); /* Map ab_acc to gnc_acc */ g_hash_table_insert(info->gnc_hash, ab_acc, gnc_acc); @@ -800,7 +857,7 @@ gnc_ab_initial_assistant_new(void) gtk_tree_view_append_column(info->account_view, column); selection = gtk_tree_view_get_selection(info->account_view); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window), gnc_ui_get_main_window(NULL)); diff --git a/gnucash/import-export/aqb/assistant-ab-initial.glade b/gnucash/import-export/aqb/assistant-ab-initial.glade index 0c9d085b80..928ed90cf3 100644 --- a/gnucash/import-export/aqb/assistant-ab-initial.glade +++ b/gnucash/import-export/aqb/assistant-ab-initial.glade @@ -125,6 +125,19 @@ Click on "Next" to proceed or "Cancel" to Abort Import. 12 vertical 12 + + + True + False + Double Click on the line of an Online Banking account name if you want to match it to a GnuCash account or select incorrect matches and click "Delete selected matches". Click "Next" when all desired accounts are matching. + True + + + False + True + 0 + + True @@ -143,20 +156,34 @@ Click on "Next" to proceed or "Cancel" to Abort Import. True True - 0 + 1 - + True False - Double Click on the line of an Online Banking account name if you want to match it to a GnuCash account. Click "Next" when all desired accounts are matching. - True + + + _Delete selected matches + True + True + True + start + True + + + + False + True + 0 + + False True - 1 + 2