Skip to content

Commit

Permalink
store widget instead of const char*, less leaky
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Feb 26, 2024
1 parent 9eddfe0 commit 2af48ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
33 changes: 21 additions & 12 deletions gnucash/gnome/gnc-plugin-page-register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 (" ");
Expand All @@ -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 (" ");
Expand All @@ -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));
}
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions gnucash/gtkbuilder/gnc-plugin-page-register.glade
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ If 0, all previous days included</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="gnc_plugin_page_register_desc_filter_clear_cb" swapped="no"/>
</object>
<packing>
<property name="left-attach">2</property>
Expand Down

0 comments on commit 2af48ed

Please sign in to comment.