Added text search filter

This commit is contained in:
Markus Koch 2017-02-03 20:57:14 +01:00
parent ec7a072920
commit 1101026d19

View File

@ -182,9 +182,41 @@ static void mainWindow_list_add_entry(struct mainWindow *mainWindow,
*/
static gboolean mainWindow_list_entry_visible(GtkTreeModel *model, GtkTreeIter *iter, struct mainWindow *mainWindow)
{
GRegex *regex;
GMatchInfo *match_info;
gchar *searchString;
gchar *temp;
gboolean search_matched = 0;
GDateTime *datetime;
guint time;
/* Check text search */
searchString = (gchar *)gtk_entry_get_text(GTK_ENTRY(mainWindow->searchEntry));
if (searchString[0] != 0) {
regex = g_regex_new(searchString, G_REGEX_CASELESS, 0, NULL);
gtk_tree_model_get(model, iter, COL_TEXT, &temp, -1);
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
gtk_tree_model_get(model, iter, COL_TAGS_TEXT, &temp, -1);
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
gtk_tree_model_get(model, iter, COL_TITLE, &temp, -1);
if (g_regex_match(regex, temp, 0, &match_info) && g_match_info_matches(match_info))
search_matched = 1;
g_free(temp);
if (!search_matched)
return 0;
}
/* Check time span */
gtk_tree_model_get(model, iter, COL_TIMESTAMP, &datetime, -1);
if (datetime) {
time = g_date_time_to_unix(datetime);
@ -515,9 +547,6 @@ void mainWindow_filterChanged(GtkWidget *widget, gpointer user_data)
g_date_time_unref(datetime);
}
}
if (!widget || widget == mainWindow->searchEntry) {
NULL;
}
gtk_tree_model_filter_refilter(mainWindow->entryListFiltered);
}