From b50c8a57fa539bd50e61739511e28f60e8a09dfc Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 18 Jun 2018 17:37:32 +0100 Subject: [PATCH] Show whether there is a filter on the right of the summary bar On the right of the summary bar indicate whether there is a filter and if there is display a tooltip with the settings. Also the filter label can be altered by the css class "gnc-class-highlight". --- gnucash/gnome/gnc-plugin-page-register.c | 152 +++++++++++++++++++++++ gnucash/gnome/gnc-split-reg.c | 31 ++++- gnucash/gnome/gnc-split-reg.h | 2 + 3 files changed, 184 insertions(+), 1 deletion(-) diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index d3e72831e4..04c5ab4927 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -133,6 +133,7 @@ static time64 gnc_plugin_page_register_filter_dmy2time (char *date_string); static gchar *gnc_plugin_page_register_filter_time2dmy (time64 raw_time); static gchar *gnc_plugin_page_register_get_filter (GncPluginPage *plugin_page); void gnc_plugin_page_register_set_filter (GncPluginPage *plugin_page, const gchar *filter); +static void gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister *page); static void gnc_ppr_update_status_query (GncPluginPageRegister *page); static void gnc_ppr_update_date_query (GncPluginPageRegister *page); @@ -1208,6 +1209,9 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page) gnc_ppr_update_date_query(page); } + // Set filter tooltip for summary bar + gnc_plugin_page_register_set_filter_tooltip (page); + plugin_page->summarybar = gsr_create_summary_bar(priv->gsr); if (plugin_page->summarybar) { @@ -2159,6 +2163,9 @@ gnc_ppr_update_status_query (GncPluginPageRegister *page) if (priv->fd.cleared_match != CLEARED_ALL) xaccQueryAddClearedMatch(query, priv->fd.cleared_match, QOF_QUERY_AND); + // Set filter tooltip for summary bar + gnc_plugin_page_register_set_filter_tooltip (page); + gnc_ledger_display_refresh (priv->ledger); LEAVE(" "); } @@ -2215,6 +2222,9 @@ gnc_ppr_update_date_query (GncPluginPageRegister *page) QOF_QUERY_AND); } + // Set filter tooltip for summary bar + gnc_plugin_page_register_set_filter_tooltip (page); + gnc_ledger_display_refresh (priv->ledger); LEAVE(" "); } @@ -2659,6 +2669,148 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog *dialog, LEAVE(" "); } +static gchar* +gpp_get_cleared_match_filter_text (gchar *text_in, gboolean *first, const gchar *text) +{ + gchar *result; + gchar *temp = g_strdup (text_in); + g_free (text_in); + + if (*first) + { + result = g_strconcat (temp, text, NULL); + *first = FALSE; + } + else + result = g_strconcat (temp, ", ", text, NULL); + g_free (temp); + + return result; +} + +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; + + g_return_if_fail(GNC_IS_PLUGIN_PAGE_REGISTER(page)); + + ENTER(" "); + priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(page); + plugin_page = GNC_PLUGIN_PAGE(page); + + // filtered start time + 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); + g_free (sdate); + } + // 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); + g_free (edate); + } + // filtered match items + if (priv->fd.cleared_match != 31) + { + gchar *show = g_strdup (""); + gchar *hide = g_strdup (""); + + gboolean first_show = TRUE, first_hide = TRUE; + + if ((priv->fd.cleared_match & 0x01) == 0x01) + show = gpp_get_cleared_match_filter_text (show, &first_show, _("Unreconciled")); + else + hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Unreconciled")); + + if ((priv->fd.cleared_match & 0x02) == 0x02) + show = gpp_get_cleared_match_filter_text (show, &first_show, _("Cleared")); + else + hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Cleared")); + + if ((priv->fd.cleared_match & 0x04) == 0x04) + show = gpp_get_cleared_match_filter_text (show, &first_show, _("Reconciled")); + else + hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Reconciled")); + + if ((priv->fd.cleared_match & 0x08) == 0x08) + show = gpp_get_cleared_match_filter_text (show, &first_show, _("Frozen")); + else + hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Frozen")); + + if ((priv->fd.cleared_match & 0x10) == 0x10) + show = gpp_get_cleared_match_filter_text (show, &first_show, _("Voided")); + else + hide = gpp_get_cleared_match_filter_text (hide, &first_hide, _("Voided")); + + if (g_strcmp0 (show, "") == 0) + text_cleared = g_strconcat (_("Hide:"), " ", hide, NULL); + else + text_cleared = g_strconcat (_("Show:"), " ", show, "\n", _("Hide:"), " ", hide, NULL); + + 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 (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); + } + } + + if (text_cleared != NULL) + { + 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); + } + } + } + // 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); + + LEAVE(" "); +} /************************************************************/ /* Report Helper Functions */ diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c index 4f87827c91..6e207480ac 100644 --- a/gnucash/gnome/gnc-split-reg.c +++ b/gnucash/gnome/gnc-split-reg.c @@ -351,6 +351,7 @@ gnc_split_reg_init( GNCSplitReg *gsr ) gsr->sort_type = BY_STANDARD; gsr->sort_rev = FALSE; gsr->sort_arrow_handler_id = 0; + gsr->filter_text = NULL; gsr->width = -1; gsr->height = -1; gsr->numRows = 10; @@ -447,6 +448,10 @@ gsr_setup_status_widgets( GNCSplitReg *gsr ) void gnc_split_reg_destroy_cb(GtkWidget *widget, gpointer data) { + GNCSplitReg *gsr = data; + + if (gsr->filter_text) + g_free (gsr->filter_text); } /** @@ -615,6 +620,26 @@ gsr_redraw_all_cb (GnucashRegister *g_reg, gpointer data) gtk_label_set_text (GTK_LABEL(gsr->sort_label), text); } + // Filter label + if (gsr->filter_label != NULL) + { + gchar *old_tt_text = gtk_widget_get_tooltip_text (GTK_WIDGET(gsr->filter_label)); + + // check for a change in text + if (g_strcmp0 (old_tt_text, gsr->filter_text) != 0) + { + if (gsr->filter_text != NULL) + gtk_label_set_text (GTK_LABEL(gsr->filter_label), _("Filtered")); + else + gtk_label_set_text (GTK_LABEL(gsr->filter_label), ""); + + gtk_widget_set_tooltip_text (GTK_WIDGET(gsr->filter_label), gsr->filter_text); + + if (old_tt_text) + g_free (old_tt_text); + } + } + if (gsr->shares_label == NULL && gsr->value_label == NULL) return; amount = xaccAccountGetBalance( leader ); @@ -2092,7 +2117,7 @@ add_summary_label (GtkWidget *summarybar, gboolean pack_start, const char *label label = gtk_label_new( "" ); gnc_label_set_alignment(label, 1.0, 0.5 ); gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, FALSE, 0 ); - + if (extra != NULL) gtk_box_pack_start( GTK_BOX(hbox), extra, FALSE, FALSE, 0 ); @@ -2123,6 +2148,7 @@ gsr_create_summary_bar( GNCSplitReg *gsr ) gsr->projectedminimum_label = NULL; gsr->sort_label = NULL; gsr->sort_arrow = NULL; + gsr->filter_label = NULL; gsr->shares_label = NULL; gsr->value_label = NULL; @@ -2150,8 +2176,11 @@ gsr_create_summary_bar( GNCSplitReg *gsr ) gsr->value_label = add_summary_label (summarybar, TRUE, _("Current Value:"), NULL); } + gsr->filter_label = add_summary_label (summarybar, FALSE, "", NULL); gsr->sort_arrow = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_SMALL_TOOLBAR); gsr->sort_label = add_summary_label (summarybar, FALSE, _("Sort By: "), gsr->sort_arrow); + + gnc_widget_set_style_context (GTK_WIDGET(gsr->filter_label), "gnc-class-highlight"); gnc_widget_set_style_context (GTK_WIDGET(gsr->sort_arrow), "gnc-class-highlight"); gsr->summarybar = summarybar; diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h index a8e2d26932..6dd048ec5b 100644 --- a/gnucash/gnome/gnc-split-reg.h +++ b/gnucash/gnome/gnc-split-reg.h @@ -76,6 +76,7 @@ struct _GNCSplitReg GtkWidget *value_label; GtkWidget *sort_label; GtkWidget *sort_arrow; + GtkWidget *filter_label; /** The current ledger display. **/ GNCLedgerDisplay *ledger; @@ -87,6 +88,7 @@ struct _GNCSplitReg guint sort_type; gboolean sort_rev; gulong sort_arrow_handler_id; + gchar *filter_text; gboolean read_only; };