gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Wed Apr 6 19:19:24 EDT 2022
Updated via https://github.com/Gnucash/gnucash/commit/a4b18277 (commit)
via https://github.com/Gnucash/gnucash/commit/5ff0bc1b (commit)
from https://github.com/Gnucash/gnucash/commit/26b009c0 (commit)
commit a4b1827793b146e9d0fd8db87c76cb5caa211dc6
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Mar 26 21:48:59 2022 +0800
[gnc-plugin-page-register] use gnc_g_list_stringjoin to store .gcm
for gnc_plugin_page_register_filter_response_cb
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 1fa6ad4c0..136dd52b3 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -3344,52 +3344,38 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog,
if (priv->fd.save_filter)
{
- gchar* filter = g_strdup_printf ("0x%04x",
- priv->fd.cleared_match); // cleared match
- gchar* tmp = g_strdup (filter);
+ gchar *filter;
+ GList *flist = NULL;
+
+ // cleared match
+ flist = g_list_prepend
+ (flist, g_strdup_printf ("0x%04x", priv->fd.cleared_match));
// start time
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (
- priv->fd.start_date_choose)) && priv->fd.start_time != 0)
- {
- gchar* timeval = gnc_plugin_page_register_filter_time2dmy (
- priv->fd.start_time);
- filter = g_strconcat (tmp, ",", timeval, NULL);
- g_free (timeval);
- }
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->fd.start_date_choose)) && priv->fd.start_time != 0)
+ flist = g_list_prepend (flist, gnc_plugin_page_register_filter_time2dmy (priv->fd.start_time));
else
- filter = g_strconcat (tmp, ",0", NULL);
-
- g_free (tmp);
- tmp = g_strdup (filter);
- g_free (filter);
+ flist = g_list_prepend (flist, g_strdup ("0"));
// end time
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->fd.end_date_choose))
&& priv->fd.end_time != 0)
- {
- gchar* timeval = gnc_plugin_page_register_filter_time2dmy (priv->fd.end_time);
- filter = g_strconcat (tmp, ",", timeval, NULL);
- g_free (timeval);
- }
+ flist = g_list_prepend (flist, gnc_plugin_page_register_filter_time2dmy (priv->fd.end_time));
else
- filter = g_strconcat (tmp, ",0", NULL);
-
- g_free (tmp);
- tmp = g_strdup (filter);
- g_free (filter);
+ flist = g_list_prepend (flist, g_strdup ("0"));
// number of days
if (priv->fd.days > 0)
- filter = g_strdup_printf ("%s,%d", tmp, priv->fd.days);
+ flist = g_list_prepend (flist, g_strdup_printf ("%d", priv->fd.days));
else
- filter = g_strconcat (tmp, ",0", NULL);
-
- g_free (tmp);
+ flist = g_list_prepend (flist, g_strdup ("0"));
+ flist = g_list_reverse (flist);
+ filter = gnc_g_list_stringjoin (flist, ",");
PINFO ("The filter to save is %s", filter);
gnc_plugin_page_register_set_filter (plugin_page, filter);
g_free (filter);
+ g_list_free_full (flist, g_free);
}
}
priv->fd.dialog = NULL;
commit 5ff0bc1b3cc19cbafa2636f60a19bb734ff84d29
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sat Mar 26 21:48:35 2022 +0800
[gnc-plugin-page-register] use gnc_g_list_stringjoin to set tooltip
instead of repeated g_free g_strconcat in
gnc_plugin_page_register_set_filter_tooltip
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index ccdaeb4a3..1fa6ad4c0 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -66,6 +66,7 @@
#include "gnc-engine.h"
#include "gnc-event.h"
#include "gnc-features.h"
+#include "gnc-glib-utils.h"
#include "gnc-gnome-utils.h"
#include "gnc-gobject-utils.h"
#include "gnc-gui-query.h"
@@ -3398,42 +3399,19 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog,
static void
gpp_update_match_filter_text (cleared_match_t match, const guint mask,
- const gchar* filter_name, gchar** show, gchar** hide)
+ const gchar* filter_name, GList **show, GList **hide)
{
if ((match & mask) == mask)
- {
- if (*show == NULL)
- *show = g_strdup (filter_name);
- else
- {
- gchar* temp = g_strdup (*show);
- g_free (*show);
- *show = g_strconcat (temp, ", ", filter_name, NULL);
- }
- }
+ *show = g_list_prepend (*show, g_strdup (filter_name));
else
- {
- if (*hide == NULL)
- *hide = g_strdup (filter_name);
- else
- {
- gchar* temp = g_strdup (*hide);
- g_free (*hide);
- *hide = g_strconcat (temp, ", ", filter_name, NULL);
- }
- }
+ *hide = g_list_prepend (*hide, g_strdup (filter_name));
}
static void
gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
{
GncPluginPageRegisterPrivate* priv;
- GncPluginPage* plugin_page;
- gchar* text = NULL;
- gchar* text_header = g_strdup_printf ("%s", _ ("Filter By:"));
- gchar* text_start = NULL;
- gchar* text_end = NULL;
- gchar* text_cleared = NULL;
+ GList *t_list = NULL;
g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (page));
@@ -3444,28 +3422,31 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
if (priv->fd.start_time != 0)
{
gchar* sdate = qof_print_date (priv->fd.start_time);
- text_start = g_strdup_printf ("%s %s", _ ("Start Date:"), sdate);
+ t_list = g_list_prepend
+ (t_list, g_strdup_printf ("%s %s", _("Start Date:"), sdate));
g_free (sdate);
}
// filtered number of days
if (priv->fd.days > 0)
- text_start = g_strdup_printf ("%s %d", _ ("Show previous number of days:"),
- priv->fd.days);
+ t_list = g_list_prepend
+ (t_list, g_strdup_printf ("%s %d", _("Show previous number of days:"),
+ priv->fd.days));
// filtered end time
if (priv->fd.end_time != 0)
{
gchar* edate = qof_print_date (priv->fd.end_time);
- text_end = g_strdup_printf ("%s %s", _ ("End Date:"), edate);
+ t_list = g_list_prepend
+ (t_list, g_strdup_printf ("%s %s", _("End Date:"), edate));
g_free (edate);
}
// filtered match items
- if (priv->fd.cleared_match != 31)
+ if (priv->fd.cleared_match != CLEARED_ALL)
{
- gchar* show = NULL;
- gchar* hide = NULL;
+ GList *show = NULL;
+ GList *hide = NULL;
gpp_update_match_filter_text (priv->fd.cleared_match, 0x01, _ ("Unreconciled"),
&show, &hide);
@@ -3478,62 +3459,42 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
gpp_update_match_filter_text (priv->fd.cleared_match, 0x10, _ ("Voided"),
&show, &hide);
- if (show == NULL)
- text_cleared = g_strconcat (_ ("Hide:"), " ", hide, NULL);
- else
- text_cleared = g_strconcat (_ ("Show:"), " ", show, "\n", _ ("Hide:"), " ",
- hide, NULL);
+ show = g_list_reverse (show);
+ hide = g_list_reverse (hide);
- g_free (show);
- g_free (hide);
- }
- // create the tooltip based on created text variables
- if ((text_start != NULL) || (text_end != NULL) || (text_cleared != NULL))
- {
- if (text_start != NULL)
- text = g_strconcat (text_header, "\n", text_start, NULL);
-
- if (text_end != NULL)
+ if (show)
{
- if (text == NULL)
- text = g_strconcat (text_header, "\n", text_end, NULL);
- else
- {
- gchar* temp = g_strdup (text);
- g_free (text);
- text = g_strconcat (temp, "\n", text_end, NULL);
- g_free (temp);
- }
+ char *str = gnc_g_list_stringjoin (show, ", ");
+ t_list = g_list_prepend
+ (t_list, g_strdup_printf ("%s %s", _("Show:"), str));
+ g_free (str);
}
- if (text_cleared != NULL)
+ if (hide)
{
- if (text == NULL)
- text = g_strconcat (text_header, "\n", text_cleared, NULL);
- else
- {
- gchar* temp = g_strdup (text);
- g_free (text);
- text = g_strconcat (temp, "\n", text_cleared, NULL);
- g_free (temp);
- }
+ char *str = gnc_g_list_stringjoin (hide, ", ");
+ t_list = g_list_prepend
+ (t_list, g_strdup_printf ("%s %s", _("Hide:"), str));
+ g_free (str);
}
+
+ g_list_free_full (show, g_free);
+ g_list_free_full (hide, g_free);
}
+
+ t_list = g_list_reverse (t_list);
+
+ if (t_list)
+ t_list = g_list_prepend (t_list, g_strdup (_("Filter By:")));
+
// free the existing text if present
if (priv->gsr->filter_text != NULL)
g_free (priv->gsr->filter_text);
// set the tooltip text variable in the gsr
- priv->gsr->filter_text = g_strdup (text);
-
- if (text_start)
- g_free (text_start);
- if (text_end)
- g_free (text_end);
- if (text_cleared)
- g_free (text_cleared);
- g_free (text_header);
- g_free (text);
+ priv->gsr->filter_text = gnc_g_list_stringjoin (t_list, "\n");
+
+ g_list_free_full (t_list, g_free);
LEAVE (" ");
}
Summary of changes:
gnucash/gnome/gnc-plugin-page-register.c | 163 +++++++++++--------------------
1 file changed, 55 insertions(+), 108 deletions(-)
More information about the gnucash-changes
mailing list