Skip to content

Commit

Permalink
[gnc-plugin-page-register.c] add Desc substring filter
Browse files Browse the repository at this point in the history
very buggy
desc needs to be sanitized before saving into state file
  • Loading branch information
christopherlam committed Feb 23, 2024
1 parent 68b3f97 commit 8f99d2b
Show file tree
Hide file tree
Showing 2 changed files with 190 additions and 0 deletions.
104 changes: 104 additions & 0 deletions gnucash/gnome/gnc-plugin-page-register.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -468,6 +472,7 @@ typedef struct GncPluginPageRegisterPrivate
gint original_days;
gboolean original_save_filter;
gboolean save_filter;
const char* desc_filter;
} fd;
} GncPluginPageRegisterPrivate;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -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)
{
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
86 changes: 86 additions & 0 deletions gnucash/gtkbuilder/gnc-plugin-page-register.glade
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,92 @@ If 0, all previous days included</property>
<property name="tab-fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Description</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="desc_filter_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<signal name="changed" handler="gnc_plugin_page_register_filter_desc_changed_cb" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="desc_filter_clear">
<property name="label" translatable="yes">Clear</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="vbox105">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Text</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab-fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down

0 comments on commit 8f99d2b

Please sign in to comment.