diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c index 291cffd8b6d..60cef1d7421 100644 --- a/gnucash/gnome/gnc-plugin-page-register.c +++ b/gnucash/gnome/gnc-plugin-page-register.c @@ -149,6 +149,10 @@ void gnc_plugin_page_register_set_sort_reversed (GncPluginPage* plugin_page, /* Callbacks for the "Filter By" dialog */ void gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button, GncPluginPageRegister* page); +void gnc_plugin_page_register_filter_desc_changed_cb (GtkEntry *entry, + GncPluginPageRegister* page); +void gnc_plugin_page_register_desc_filter_clear_cb (GtkButton *button, + GncPluginPageRegister* page); void gnc_plugin_page_register_filter_start_cb (GtkWidget* radio, GncPluginPageRegister* page); void gnc_plugin_page_register_filter_end_cb (GtkWidget* radio, @@ -468,6 +472,7 @@ typedef struct GncPluginPageRegisterPrivate gint original_days; gboolean original_save_filter; gboolean save_filter; + const char* desc_filter; } fd; } GncPluginPageRegisterPrivate; @@ -652,6 +657,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->enable_refresh = TRUE; priv->search_query = NULL; priv->filter_query = NULL; @@ -1315,6 +1321,13 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page) filter_changed = filter_changed + 1; } + if (filtersize > 4 && !g_strcmp0 (filter[4], "0")) + { + PINFO ("Loaded Description Filter is %s", filter[4]); + priv->fd.desc_filter = filter[4]; + ++filter_changed; + } + if (filter_changed != 0) priv->fd.save_filter = TRUE; @@ -2647,6 +2660,50 @@ gnc_ppr_update_date_query (GncPluginPageRegister* page) LEAVE (" "); } +static void +gnc_ppr_update_text_query (GncPluginPageRegister* page) +{ + ENTER (" "); + + GncPluginPageRegisterPrivate* priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page); + if (!priv || !priv->ledger) + { + LEAVE ("no ledger"); + return; + } + + // check if this a search register and save query + gnc_ppr_update_for_search_query (page); + + Query* query = gnc_ledger_display_get_query (priv->ledger); + if (!query) + { + LEAVE ("no query"); + return; + } + + SplitRegister *reg = gnc_ledger_display_get_split_register (priv->ledger); + if (reg->type != SEARCH_LEDGER) + { + GSList *param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DESCRIPTION, NULL); + qof_query_purge_terms (query, param_list); + g_slist_free (param_list); + } + xaccQueryAddDescriptionMatch (query, priv->fd.desc_filter, TRUE, FALSE, + QOF_COMPARE_CONTAINS, QOF_QUERY_AND); + + // Set filter tooltip for summary bar + gnc_plugin_page_register_set_filter_tooltip (page); + + // clear previous filter query and save current + qof_query_destroy (priv->filter_query); + priv->filter_query = qof_query_copy (query); + + if (priv->enable_refresh) + gnc_ledger_display_refresh (priv->ledger); + LEAVE (" "); +} + /* This function converts a time64 value date to a string */ static gchar* @@ -2881,6 +2938,39 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button, LEAVE (" "); } +void +gnc_plugin_page_register_filter_desc_changed_cb (GtkEntry *entry, + GncPluginPageRegister* page) +{ + + g_return_if_fail (GTK_IS_ENTRY (entry)); + g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (page)); + + 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 (" "); +} + +void gnc_plugin_page_register_desc_filter_clear_cb (GtkButton *button, + GncPluginPageRegister* page) +{ + g_return_if_fail (GTK_IS_BUTTON (button)); + g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (page)); + + ENTER ("(button %p, page %p)", button, page); + + /* GncPluginPageRegisterPrivate* priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page); */ + /* gtk_entry_set_text (entry); */ + gnc_ppr_update_text_query (page); + + LEAVE (" "); +} + + void gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page) { @@ -2894,6 +2984,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 = (gint)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16); + priv->fd.desc_filter = NULL; gnc_ppr_update_date_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page)); } @@ -3150,6 +3241,11 @@ 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)); + else + 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); @@ -3248,6 +3344,14 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page) g_list_free_full (hide, g_free); } + // filtered end time + const char *desc_filter = priv->fd.desc_filter; + if (desc_filter && *desc_filter) + { + t_list = g_list_prepend + (t_list, g_strdup_printf ("%s %s", _("Desciption Filter:"), desc_filter)); + } + t_list = g_list_reverse (t_list); if (t_list) diff --git a/gnucash/gtkbuilder/gnc-plugin-page-register.glade b/gnucash/gtkbuilder/gnc-plugin-page-register.glade index 939a0f8faa8..a7588b75c92 100644 --- a/gnucash/gtkbuilder/gnc-plugin-page-register.glade +++ b/gnucash/gtkbuilder/gnc-plugin-page-register.glade @@ -517,6 +517,92 @@ If 0, all previous days included False + + + True + False + vertical + + + + True + False + + + True + False + Description + + + 0 + 0 + + + + + True + True + + + + 1 + 0 + + + + + Clear + True + True + True + + + 2 + 0 + + + + + + + + + + + + + + + + + + + + + + + False + True + 0 + + + + + 2 + + + + + True + False + Text + True + + + 2 + False + + True