After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 710204 - GListModel should have more advanced filtering helper
GListModel should have more advanced filtering helper
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on: 710414
Blocks:
 
 
Reported: 2013-10-15 17:30 UTC by Xavier Claessens
Modified: 2018-05-24 15:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkListsBox: Add filter on text helper (6.76 KB, patch)
2013-10-15 17:48 UTC, Xavier Claessens
none Details | Review
Improve search-bar example to demonstrate GtkListBox filtering (4.71 KB, patch)
2013-10-15 17:48 UTC, Xavier Claessens
none Details | Review

Description Xavier Claessens 2013-10-15 17:30:24 UTC
GLib now gained advanced matching function helpers (see bug #709753):
g_str_tokenize_and_fold()
g_str_match_string()

I think GtkListBox should make good use of them to help filtering the list when user search terms. We could add:

void gtk_list_box_row_add_search_text(GtkListBoxRow *row,
    const gchar *text,
    const gchar *translit_locale);
void gtk_list_box_set_filter_text(GtkListBox *list,
    const gchar *text,
    gboolean accept_alternates);

The internal function gtk_list_box_apply_filter() could then do filtering based on the text, similar than what g_str_match_string() does but with pre-computed tokens.
Comment 1 Matthias Clasen 2013-10-15 17:33:40 UTC
I'd rather leave that up to the user of the listbox, tbh
Comment 2 Xavier Claessens 2013-10-15 17:48:39 UTC
Created attachment 257377 [details] [review]
GtkListsBox: Add filter on text helper
Comment 3 Xavier Claessens 2013-10-15 17:48:42 UTC
Created attachment 257378 [details] [review]
Improve search-bar example to demonstrate GtkListBox filtering
Comment 4 Xavier Claessens 2013-10-15 17:51:07 UTC
(In reply to comment #1)
> I'd rather leave that up to the user of the listbox, tbh

IMO it is common and non trivial to get right enough that we want the toolkit to handle it for apps. Ryan agreed with me on IRC.
Comment 5 Xavier Claessens 2013-10-15 17:52:11 UTC
Note that my attached patches are not ready yet, they are missing doc at least. But I would like a consensus before finishing the work.
Comment 6 Xavier Claessens 2013-10-17 14:43:34 UTC
Hm, actually I've been thinking a bit more about this and I'm not sure about one thing: I hope that GtkListBox will get a model behind it at some point to create GtkListBoxRow widgets on the flight when scrolling to avoid performance problems when creating a huge list (lots of people have 5000+ contacts!). In that case I'm not sure how the filtering should work... Should we be filtering on the model before creating the rows, or should the view ask more rows until it gets visible rows?

So maybe this bug is premature and should wait for solutions for big lists first.
Comment 7 Allison Karlitskaya (desrt) 2013-10-17 19:34:06 UTC
Review of attachment 257377 [details] [review]:

::: gtk/gtklistbox.c
@@ +104,3 @@
+
+  /* HashSet<strv> */
+  GHashTable *tokens;

a hashtable _per row_?  this seems wrong... and when you use it, you just iterate...

if you do indexing at all, it should be on the level of the entire list.  for the rows, just store a gchar**.  you can either do a gchar**-vs-gchar** test per-row or build an index for the entire list.
Comment 8 Xavier Claessens 2013-10-17 19:54:27 UTC
Actually that comment is a lie, it's a GHashTable<string> not strv. It's a hashtable used as a set to make it easy to add more tokens. My use case for that is in empathy a row can be matched for multiple strings: email, fullname, etc... so each row has a contact and I can do:

gtk_list_box_row_add_search_text (row, "xclaesse@gmail.com");
gtk_list_box_row_add_search_text (row, "Xavier Claessens");

And the row will match when searching for "xclaesse" as well as "xavier".

I can implement that with a GPtrArray<string> of course, but then adding tokens is more boring :p
Comment 9 Matthias Clasen 2015-12-21 23:28:35 UTC
I think everybody wants filtering to work with models nowadays
Comment 10 Xavier Claessens 2015-12-22 15:08:04 UTC
(In reply to Matthias Clasen from comment #9)
> I think everybody wants filtering to work with models nowadays

Doesn't mean the bug is WONTFIX, just that it needs to be reassigned. It should be done on GListModel now indeed.
Comment 11 GNOME Infrastructure Team 2018-05-24 15:45:01 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/765.