From 2af48ed8b81bc4cd3fcbb98249ed29af1140c973 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 26 Feb 2024 12:46:27 +0800 Subject: [PATCH] store widget instead of const char*, less leaky --- gnucash/gnome/gnc-plugin-page-register.cpp | 33 ++++++++++++------- .../gtkbuilder/gnc-plugin-page-register.glade | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/gnucash/gnome/gnc-plugin-page-register.cpp b/gnucash/gnome/gnc-plugin-page-register.cpp index 6d70701e9b4..3b6d797b8be 100644 --- a/gnucash/gnome/gnc-plugin-page-register.cpp +++ b/gnucash/gnome/gnc-plugin-page-register.cpp @@ -479,8 +479,16 @@ typedef struct GncPluginPageRegisterPrivate gint original_days; gboolean original_save_filter; gboolean save_filter; - const char* desc_filter; + GtkWidget* desc_filter_widget; } fd; + + const char *get_desc_filter () + { + if (!fd.desc_filter_widget) + return nullptr; + return gtk_entry_get_text (GTK_ENTRY(fd.desc_filter_widget)); + }; + } GncPluginPageRegisterPrivate; G_DEFINE_TYPE_WITH_PRIVATE (GncPluginPageRegister, gnc_plugin_page_register, @@ -665,7 +673,7 @@ gnc_plugin_page_register_init (GncPluginPageRegister* plugin_page) priv->read_only = FALSE; priv->fd.cleared_match = CLEARED_ALL; priv->fd.days = 0; - priv->fd.desc_filter = NULL; + priv->fd.desc_filter_widget = nullptr; priv->enable_refresh = TRUE; priv->search_query = NULL; priv->filter_query = NULL; @@ -1350,7 +1358,7 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page) if (filtersize > 4 && !g_strcmp0 (filter[4], "0")) { PINFO ("Loaded Description Filter is %s", filter[4]); - priv->fd.desc_filter = filter[4]; + gtk_entry_set_text (GTK_ENTRY(priv->fd.desc_filter_widget), filter[4]); ++filter_changed; } @@ -2716,7 +2724,7 @@ gnc_ppr_update_text_query (GncPluginPageRegister* page) qof_query_purge_terms (query, param_list); g_slist_free (param_list); } - xaccQueryAddDescriptionMatch (query, priv->fd.desc_filter, TRUE, FALSE, + xaccQueryAddDescriptionMatch (query, priv->get_desc_filter (), TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND); // Set filter tooltip for summary bar @@ -2975,8 +2983,6 @@ gnc_plugin_page_register_filter_desc_changed_cb (GtkEntry *entry, ENTER ("(entry %p, page %p)", entry, page); - GncPluginPageRegisterPrivate* priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page); - priv->fd.desc_filter = gtk_entry_get_text (entry); gnc_ppr_update_text_query (page); LEAVE (" "); @@ -2990,8 +2996,8 @@ void gnc_plugin_page_register_desc_filter_clear_cb (GtkButton *button, ENTER ("(button %p, page %p)", button, page); - /* GncPluginPageRegisterPrivate* priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page); */ - /* gtk_entry_set_text (entry); */ + GncPluginPageRegisterPrivate* priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page); + gtk_entry_set_text (GTK_ENTRY(priv->fd.desc_filter_widget), ""); gnc_ppr_update_text_query (page); LEAVE (" "); @@ -3011,7 +3017,7 @@ gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page) priv->fd.start_time = 0; priv->fd.end_time = 0; priv->fd.cleared_match = (cleared_match_t)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16); - priv->fd.desc_filter = NULL; + gtk_entry_set_text (GTK_ENTRY(priv->fd.desc_filter_widget), ""); gnc_ppr_update_date_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page)); } @@ -3268,8 +3274,10 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog, else flist = g_list_prepend (flist, g_strdup ("0")); - if (priv->fd.desc_filter) - flist = g_list_prepend (flist, g_strdup (priv->fd.desc_filter)); + const char *desc_filter = priv->get_desc_filter (); + + if (desc_filter && *desc_filter) + flist = g_list_prepend (flist, g_strdup (desc_filter)); else flist = g_list_prepend (flist, g_strdup ("0")); @@ -3372,7 +3380,7 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page) } // filtered end time - const char *desc_filter = priv->fd.desc_filter; + const char *desc_filter = priv->get_desc_filter (); if (desc_filter && *desc_filter) { t_list = g_list_prepend @@ -4274,6 +4282,7 @@ gnc_plugin_page_register_cmd_view_filter_by (GSimpleAction *simple, "end_date_choose")); priv->fd.end_date_today = GTK_WIDGET (gtk_builder_get_object (builder, "end_date_today")); + priv->fd.desc_filter_widget = GTK_WIDGET (gtk_builder_get_object (builder, "desc_filter_entry")); { /* Start date info */ diff --git a/gnucash/gtkbuilder/gnc-plugin-page-register.glade b/gnucash/gtkbuilder/gnc-plugin-page-register.glade index a7588b75c92..ccb3249fab3 100644 --- a/gnucash/gtkbuilder/gnc-plugin-page-register.glade +++ b/gnucash/gtkbuilder/gnc-plugin-page-register.glade @@ -555,6 +555,7 @@ If 0, all previous days included True True True + 2