mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[gnc-plugin-page-register.cpp] add Desc substring filter
This commit is contained in:
parent
01bffa485a
commit
c8e7f0a735
@ -156,6 +156,8 @@ extern "C"
|
|||||||
/* Callbacks for the "Filter By" dialog */
|
/* Callbacks for the "Filter By" dialog */
|
||||||
void gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button,
|
void gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button,
|
||||||
GncPluginPageRegister* page);
|
GncPluginPageRegister* page);
|
||||||
|
void gnc_plugin_page_register_filter_desc_changed_cb (GtkEntry *entry,
|
||||||
|
GncPluginPageRegister* page);
|
||||||
void gnc_plugin_page_register_filter_start_cb (GtkWidget* radio,
|
void gnc_plugin_page_register_filter_start_cb (GtkWidget* radio,
|
||||||
GncPluginPageRegister* page);
|
GncPluginPageRegister* page);
|
||||||
void gnc_plugin_page_register_filter_end_cb (GtkWidget* radio,
|
void gnc_plugin_page_register_filter_end_cb (GtkWidget* radio,
|
||||||
@ -175,12 +177,14 @@ void gnc_plugin_page_register_filter_days_changed_cb (GtkSpinButton* button,
|
|||||||
static time64 gnc_plugin_page_register_filter_dmy2time (char* date_string);
|
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_filter_time2dmy (time64 raw_time);
|
||||||
static gchar* gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page);
|
static gchar* gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page);
|
||||||
|
static gchar* gnc_plugin_page_register_get_desc_filter (GncPluginPage* plugin_page);
|
||||||
void gnc_plugin_page_register_set_filter (GncPluginPage* plugin_page,
|
void gnc_plugin_page_register_set_filter (GncPluginPage* plugin_page,
|
||||||
const gchar* filter);
|
const gchar* filter);
|
||||||
static void gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page);
|
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_status_query (GncPluginPageRegister* page);
|
||||||
static void gnc_ppr_update_date_query (GncPluginPageRegister* page);
|
static void gnc_ppr_update_date_query (GncPluginPageRegister* page);
|
||||||
|
static void gnc_ppr_update_text_query (GncPluginPageRegister* page);
|
||||||
|
|
||||||
/* Command callbacks */
|
/* Command callbacks */
|
||||||
static void gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple, GVariant *paramter, gpointer user_data);
|
static void gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple, GVariant *paramter, gpointer user_data);
|
||||||
@ -465,6 +469,7 @@ typedef struct GncPluginPageRegisterPrivate
|
|||||||
GtkWidget* end_date_today;
|
GtkWidget* end_date_today;
|
||||||
GtkWidget* end_date;
|
GtkWidget* end_date;
|
||||||
GtkWidget* num_days;
|
GtkWidget* num_days;
|
||||||
|
GString* desc_filter;
|
||||||
cleared_match_t original_cleared_match;
|
cleared_match_t original_cleared_match;
|
||||||
cleared_match_t cleared_match;
|
cleared_match_t cleared_match;
|
||||||
time64 original_start_time;
|
time64 original_start_time;
|
||||||
@ -476,6 +481,10 @@ typedef struct GncPluginPageRegisterPrivate
|
|||||||
gboolean original_save_filter;
|
gboolean original_save_filter;
|
||||||
gboolean save_filter;
|
gboolean save_filter;
|
||||||
} fd;
|
} fd;
|
||||||
|
|
||||||
|
void set_desc_filter (const char *new_str) { g_string_assign (fd.desc_filter, new_str); };
|
||||||
|
const char *get_desc_filter () const { return fd.desc_filter ? fd.desc_filter->str : nullptr; };
|
||||||
|
|
||||||
} GncPluginPageRegisterPrivate;
|
} GncPluginPageRegisterPrivate;
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (GncPluginPageRegister, gnc_plugin_page_register,
|
G_DEFINE_TYPE_WITH_PRIVATE (GncPluginPageRegister, gnc_plugin_page_register,
|
||||||
@ -660,6 +669,7 @@ gnc_plugin_page_register_init (GncPluginPageRegister* plugin_page)
|
|||||||
priv->read_only = FALSE;
|
priv->read_only = FALSE;
|
||||||
priv->fd.cleared_match = CLEARED_ALL;
|
priv->fd.cleared_match = CLEARED_ALL;
|
||||||
priv->fd.days = 0;
|
priv->fd.days = 0;
|
||||||
|
priv->fd.desc_filter = g_string_new ("");
|
||||||
priv->enable_refresh = TRUE;
|
priv->enable_refresh = TRUE;
|
||||||
priv->search_query = NULL;
|
priv->search_query = NULL;
|
||||||
priv->filter_query = NULL;
|
priv->filter_query = NULL;
|
||||||
@ -1341,6 +1351,15 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page)
|
|||||||
filter_changed = filter_changed + 1;
|
filter_changed = filter_changed + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto desc_filter = gnc_plugin_page_register_get_desc_filter (plugin_page);
|
||||||
|
if (desc_filter && *desc_filter)
|
||||||
|
{
|
||||||
|
PINFO ("Loaded Description Filter is %s", desc_filter);
|
||||||
|
priv->set_desc_filter (desc_filter);
|
||||||
|
++filter_changed;
|
||||||
|
}
|
||||||
|
g_free (desc_filter);
|
||||||
|
|
||||||
if (filter_changed != 0)
|
if (filter_changed != 0)
|
||||||
priv->fd.save_filter = TRUE;
|
priv->fd.save_filter = TRUE;
|
||||||
|
|
||||||
@ -1387,6 +1406,7 @@ gnc_plugin_page_register_create_widget (GncPluginPage* plugin_page)
|
|||||||
/* Update Query with Filter Status and Dates */
|
/* Update Query with Filter Status and Dates */
|
||||||
gnc_ppr_update_status_query (page);
|
gnc_ppr_update_status_query (page);
|
||||||
gnc_ppr_update_date_query (page);
|
gnc_ppr_update_date_query (page);
|
||||||
|
gnc_ppr_update_text_query (page);
|
||||||
|
|
||||||
/* Now do the refresh if this is a new page instead of restore */
|
/* Now do the refresh if this is a new page instead of restore */
|
||||||
if (create_new_page)
|
if (create_new_page)
|
||||||
@ -1492,6 +1512,7 @@ gnc_plugin_page_register_destroy_widget (GncPluginPage* plugin_page)
|
|||||||
if (priv->fd.dialog)
|
if (priv->fd.dialog)
|
||||||
{
|
{
|
||||||
gtk_widget_destroy (priv->fd.dialog);
|
gtk_widget_destroy (priv->fd.dialog);
|
||||||
|
g_string_free (priv->fd.desc_filter, true);
|
||||||
memset (&priv->fd, 0, sizeof (priv->fd));
|
memset (&priv->fd, 0, sizeof (priv->fd));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2027,6 +2048,43 @@ gnc_plugin_page_register_get_filter (GncPluginPage* plugin_page)
|
|||||||
"0", "0", get_filter_default_num_of_days (ledger_type));
|
"0", "0", get_filter_default_num_of_days (ledger_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* KEY_FILE_DESC_FILTER = "register_desc_filter";
|
||||||
|
|
||||||
|
static gchar*
|
||||||
|
gnc_plugin_page_register_get_desc_filter (GncPluginPage* plugin_page)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page), nullptr);
|
||||||
|
|
||||||
|
auto priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
|
||||||
|
auto state_file = gnc_state_get_current();
|
||||||
|
auto state_section = gsr_get_register_state_section (priv->gsr);
|
||||||
|
GError* error = NULL;
|
||||||
|
auto filter = g_key_file_get_string (state_file, state_section,
|
||||||
|
KEY_FILE_DESC_FILTER, &error);
|
||||||
|
if (error)
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
|
g_free (state_section);
|
||||||
|
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gnc_plugin_page_register_set_desc_filter (GncPluginPage* plugin_page, const char *desc_filter)
|
||||||
|
{
|
||||||
|
auto state_file = gnc_state_get_current();
|
||||||
|
auto priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
|
||||||
|
auto state_section = gsr_get_register_state_section (priv->gsr);
|
||||||
|
if (desc_filter && *desc_filter)
|
||||||
|
g_key_file_set_string (state_file, state_section, KEY_FILE_DESC_FILTER, desc_filter);
|
||||||
|
else if (g_key_file_has_key (state_file, state_section, KEY_FILE_DESC_FILTER, nullptr))
|
||||||
|
{
|
||||||
|
g_key_file_remove_key (state_file, state_section, KEY_FILE_DESC_FILTER, nullptr);
|
||||||
|
gnc_plugin_page_register_check_for_empty_group (state_file, state_section);
|
||||||
|
}
|
||||||
|
g_free (state_section);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gnc_plugin_page_register_set_filter_gcm (GNCSplitReg *gsr, const gchar* filter,
|
gnc_plugin_page_register_set_filter_gcm (GNCSplitReg *gsr, const gchar* filter,
|
||||||
gchar* default_filter)
|
gchar* default_filter)
|
||||||
@ -2674,6 +2732,52 @@ gnc_ppr_update_date_query (GncPluginPageRegister* page)
|
|||||||
LEAVE (" ");
|
LEAVE (" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gnc_ppr_update_text_query (GncPluginPageRegister* page)
|
||||||
|
{
|
||||||
|
ENTER (" ");
|
||||||
|
|
||||||
|
auto 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);
|
||||||
|
|
||||||
|
auto query = gnc_ledger_display_get_query (priv->ledger);
|
||||||
|
if (!query)
|
||||||
|
{
|
||||||
|
LEAVE ("no query");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gnc_ledger_display_get_split_register (priv->ledger)->type != SEARCH_LEDGER)
|
||||||
|
{
|
||||||
|
auto param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DESCRIPTION, NULL);
|
||||||
|
qof_query_purge_terms (query, param_list);
|
||||||
|
g_slist_free (param_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto desc_filter = priv->get_desc_filter ();
|
||||||
|
if (desc_filter && *desc_filter)
|
||||||
|
xaccQueryAddDescriptionMatch (query, 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 */
|
/* This function converts a time64 value date to a string */
|
||||||
static gchar*
|
static gchar*
|
||||||
@ -2908,6 +3012,24 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button,
|
|||||||
LEAVE (" ");
|
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);
|
||||||
|
|
||||||
|
auto priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (page);
|
||||||
|
priv->set_desc_filter (gtk_entry_get_text (entry));
|
||||||
|
gnc_ppr_update_text_query (page);
|
||||||
|
|
||||||
|
LEAVE (" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page)
|
gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page)
|
||||||
{
|
{
|
||||||
@ -2921,8 +3043,10 @@ gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page)
|
|||||||
priv->fd.start_time = 0;
|
priv->fd.start_time = 0;
|
||||||
priv->fd.end_time = 0;
|
priv->fd.end_time = 0;
|
||||||
priv->fd.cleared_match = (cleared_match_t)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16);
|
priv->fd.cleared_match = (cleared_match_t)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16);
|
||||||
|
priv->set_desc_filter("");
|
||||||
|
|
||||||
gnc_ppr_update_date_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
|
gnc_ppr_update_date_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
|
||||||
|
gnc_ppr_update_text_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This function is called when the "number of days" spin button is
|
/** This function is called when the "number of days" spin button is
|
||||||
@ -3140,6 +3264,7 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog,
|
|||||||
priv->fd.days = priv->fd.original_days;
|
priv->fd.days = priv->fd.original_days;
|
||||||
priv->fd.save_filter = priv->fd.original_save_filter;
|
priv->fd.save_filter = priv->fd.original_save_filter;
|
||||||
gnc_ppr_update_date_query (page);
|
gnc_ppr_update_date_query (page);
|
||||||
|
gnc_ppr_update_text_query (page);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3183,6 +3308,8 @@ gnc_plugin_page_register_filter_response_cb (GtkDialog* dialog,
|
|||||||
gnc_plugin_page_register_set_filter (plugin_page, filter);
|
gnc_plugin_page_register_set_filter (plugin_page, filter);
|
||||||
g_free (filter);
|
g_free (filter);
|
||||||
g_list_free_full (flist, g_free);
|
g_list_free_full (flist, g_free);
|
||||||
|
|
||||||
|
gnc_plugin_page_register_set_desc_filter (plugin_page, priv->get_desc_filter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
priv->fd.dialog = NULL;
|
priv->fd.dialog = NULL;
|
||||||
@ -3275,6 +3402,14 @@ gnc_plugin_page_register_set_filter_tooltip (GncPluginPageRegister* page)
|
|||||||
g_list_free_full (hide, g_free);
|
g_list_free_full (hide, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filtered end time
|
||||||
|
const char *desc_filter = priv->get_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);
|
t_list = g_list_reverse (t_list);
|
||||||
|
|
||||||
if (t_list)
|
if (t_list)
|
||||||
@ -4170,6 +4305,8 @@ gnc_plugin_page_register_cmd_view_filter_by (GSimpleAction *simple,
|
|||||||
"end_date_choose"));
|
"end_date_choose"));
|
||||||
priv->fd.end_date_today = GTK_WIDGET (gtk_builder_get_object (builder,
|
priv->fd.end_date_today = GTK_WIDGET (gtk_builder_get_object (builder,
|
||||||
"end_date_today"));
|
"end_date_today"));
|
||||||
|
gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder, "desc_filter_entry")),
|
||||||
|
priv->get_desc_filter());
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Start date info */
|
/* Start date info */
|
||||||
|
@ -517,6 +517,77 @@ If 0, all previous days included</property>
|
|||||||
<property name="tab-fill">False</property>
|
<property name="tab-fill">False</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<!-- n-columns=2 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="GtkSearchEntry" id="desc_filter_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="primary-icon-name">edit-find-symbolic</property>
|
||||||
|
<property name="primary-icon-activatable">False</property>
|
||||||
|
<property name="primary-icon-sensitive">False</property>
|
||||||
|
<signal name="search-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>
|
||||||
|
<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>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
|
Loading…
Reference in New Issue
Block a user