gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Sat Jul 30 23:41:04 EDT 2022
Updated via https://github.com/Gnucash/gnucash/commit/2443d8fa (commit)
via https://github.com/Gnucash/gnucash/commit/a43997cc (commit)
via https://github.com/Gnucash/gnucash/commit/dc77df35 (commit)
from https://github.com/Gnucash/gnucash/commit/688832b5 (commit)
commit 2443d8faf7c0d13a7ea564a8ee0376f2e159bcd8
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jul 31 10:19:55 2022 +0800
[import-main-matcher] tidy: free GList before going out of scope
...instead of in a separate function. This matches c++ RAII behaviour.
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index aaa0fb172..27cffb2ae 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -403,8 +403,6 @@ remove_top_matches (GNCImportMainMatcher* gui, GtkTreeModel* model, GList* confl
match_trans = g_list_remove (match_trans, match_trans->data);
gnc_import_TransInfo_set_match_list (trans_info, match_trans);
}
-
- g_list_free (conflicts);
}
static void
@@ -448,6 +446,8 @@ resolve_conflicts (GNCImportMainMatcher *info)
valid = gtk_tree_model_iter_next (model, &import_iter);
/* NOTE: The loop is guaranteed to terminate because whenever we go back to the top
* we remove at least 1 match, and there's a finite number of them. */
+
+ g_list_free (conflicts);
}
// Refresh all
commit a43997cc52edfb24a7362783675603880e848467
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jul 31 10:05:34 2022 +0800
[import-main-matcher] pull common add_string into 1 function
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index 9b65f72c3..aaa0fb172 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -1086,6 +1086,17 @@ input_new_fields (GNCImportMainMatcher *info, RowInfo *rowinfo,
return retval;
}
+static inline void
+maybe_add_string (GNCImportMainMatcher *info, GHashTable *hash, const char *str)
+{
+ char *new_string;
+ if (!str || !str[0] || g_hash_table_lookup (info->desc_hash, str))
+ return;
+ new_string = g_strdup (str);
+ info->new_strings = g_list_prepend (info->new_strings, new_string);
+ g_hash_table_insert (hash, new_string, one);
+}
+
static void
gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info)
{
@@ -1128,23 +1139,13 @@ gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info)
DOWNLOADED_COL_DESCRIPTION_STYLE, style,
-1);
xaccTransSetDescription (row->trans, new_desc);
- if (*new_desc && !g_hash_table_lookup (info->desc_hash, new_desc))
- {
- char *new_string = g_strdup (new_desc);
- info->new_strings = g_list_prepend (info->new_strings, new_string);
- g_hash_table_insert (info->desc_hash, new_string, one);
- }
+ maybe_add_string (info, info->desc_hash, new_desc);
}
if (info->edit_notes)
{
xaccTransSetNotes (row->trans, new_notes);
- if (*new_notes && !g_hash_table_lookup (info->notes_hash, new_notes))
- {
- char *new_string = g_strdup (new_notes);
- info->new_strings = g_list_prepend (info->new_strings, new_string);
- g_hash_table_insert (info->notes_hash, new_string, one);
- }
+ maybe_add_string (info, info->notes_hash, new_notes);
}
if (info->edit_memo)
@@ -1156,12 +1157,7 @@ gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info)
DOWNLOADED_COL_MEMO_STYLE, style,
-1);
xaccSplitSetMemo (row->split, new_memo);
- if (*new_memo && !g_hash_table_lookup (info->memo_hash, new_memo))
- {
- char *new_string = g_strdup (new_memo);
- info->new_strings = g_list_prepend (info->new_strings, new_string);
- g_hash_table_insert (info->memo_hash, new_string, one);
- }
+ maybe_add_string (info, info->memo_hash, new_memo);
}
}
g_free (new_desc);
commit dc77df352eb694c75de14e37b54bb9db3268fad1
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jul 31 10:06:16 2022 +0800
[import-main-matcher] add comments, tidier code
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index 69d77d8a8..9b65f72c3 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -1307,7 +1307,7 @@ gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
GtkWidget *menu, *menuitem;
GtkTreeModel *model;
GtkTreeSelection *selection;
- GList *selected_rows;
+ GList *selected_rows, *row_info_list;
const char *desc = NULL, *memo = NULL, *notes = NULL;
gboolean has_edits = FALSE;
@@ -1326,39 +1326,43 @@ gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
model = gtk_tree_view_get_model (treeview);
selection = gtk_tree_view_get_selection (treeview);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
+ row_info_list = gnc_g_list_map (selected_rows, (GncGMapFunc) row_get_info, info);
+
+ if (row_info_list) /* should never be NULL. collect from first row. */
+ {
+ RowInfo* first_rowinfo = row_info_list->data;
+ desc = xaccTransGetDescription (first_rowinfo->trans);
+ notes = xaccTransGetNotes (first_rowinfo->trans);
+ memo = xaccSplitGetMemo (first_rowinfo->split);
+ }
/* initialise */
info->edit_desc = TRUE;
info->edit_notes = TRUE;
info->edit_memo = TRUE;
- for (GList *n = selected_rows;
- (!has_edits || info->edit_desc || info->edit_notes || info->edit_memo) && n;
- n = g_list_next(n))
+ /* determine whether to enable editing fields (if all rows have
+ same field string) and resetting fields (if any row differs from
+ imported data) */
+ for (GList *n = row_info_list; n; n = g_list_next(n))
{
- RowInfo *rowinfo = row_get_info (n->data, info);
-
+ RowInfo *rowinfo = n->data;
if (!has_edits &&
(g_strcmp0 (xaccSplitGetMemo (rowinfo->split), rowinfo->orig_memo) ||
g_strcmp0 (xaccTransGetNotes (rowinfo->trans), rowinfo->orig_notes) ||
g_strcmp0 (xaccTransGetDescription (rowinfo->trans), rowinfo->orig_desc)))
has_edits = TRUE;
- if (!n->prev) /* only the first row */
- {
- desc = xaccTransGetDescription (rowinfo->trans);
- notes = xaccTransGetNotes (rowinfo->trans);
- memo = xaccSplitGetMemo (rowinfo->split);
- rowinfo_free (rowinfo);
- continue;
- }
if (info->edit_desc && g_strcmp0 (desc, xaccTransGetDescription (rowinfo->trans)))
info->edit_desc = FALSE;
if (info->edit_notes && g_strcmp0 (notes, xaccTransGetNotes (rowinfo->trans)))
info->edit_notes = FALSE;
if (info->edit_memo && g_strcmp0 (memo, xaccSplitGetMemo (rowinfo->split)))
info->edit_memo = FALSE;
- rowinfo_free (rowinfo);
+
+ /* all flags were switched. no need to scan remaining rows. */
+ if (has_edits && !info->edit_desc && !info->edit_notes && !info->edit_memo)
+ break;
}
/* Translators: Menu entry, no full stop */
@@ -1384,6 +1388,7 @@ gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
/* Note: event can be NULL here when called from view_onPopupMenu; */
gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent*)event);
+ g_list_free_full (row_info_list, (GDestroyNotify)rowinfo_free);
g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
LEAVE ("");
}
Summary of changes:
gnucash/import-export/import-main-matcher.c | 71 +++++++++++++++--------------
1 file changed, 36 insertions(+), 35 deletions(-)
More information about the gnucash-changes
mailing list