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 604150 - subclassing GtkTreeModelFilter
subclassing GtkTreeModelFilter
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.19.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2009-12-09 09:40 UTC by Danielle Madeley
Modified: 2010-05-04 01:55 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
implementation (6.92 KB, patch)
2009-12-09 09:40 UTC, Danielle Madeley
committed Details | Review

Description Danielle Madeley 2009-12-09 09:40:20 UTC
Created attachment 149411 [details] [review]
implementation

As it stands, GtkTreeModelFilter doesn't provide its visible and modify functions as vcalls you can implement in a subclass. If you want to provide a class with some filtering options, you have to set the function in init(), which makes it possible for someone to accidentally replace the filtering function, and break your subclass.

This patch exposes the visible() and modify() methods as vcalls in the class structure, allowing them to be implemented by a subclass. The subclass can then choose whether or not to chain-up the parent implementation (e.g. for additional custom filtering).

Here is an example from the upcoming Telepathy-Gtk, where the user can set the show_hidden property (more properties to come in the future) and then still add additional custom filtering if she wishes:

static gboolean
tp_gtk_roster_model_filter_visible (GtkTreeModelFilter *self,
                                    GtkTreeModel       *child_model,
                                    GtkTreeIter        *iter)
{
  TpGtkRosterModelFilterPrivate *priv = GET_PRIVATE (self);
  TpGtkRosterModelColumnType type;
  TpConnectionPresenceType state;
  gboolean v;
 
  gtk_tree_model_get (child_model, iter,
      TP_GTK_ROSTER_MODEL_CONTACT, &type,
      TP_GTK_ROSTER_MODEL_STATE, &state,
      -1);

  v = (priv->show_hidden || type == TP_GTK_ROSTER_MODEL_COLUMN_TYPE_GROUP ||
      (state != TP_CONNECTION_PRESENCE_TYPE_UNSET &&
       state != TP_CONNECTION_PRESENCE_TYPE_OFFLINE &&
       state != TP_CONNECTION_PRESENCE_TYPE_UNKNOWN &&
       state != TP_CONNECTION_PRESENCE_TYPE_ERROR));

  return v &&
    GTK_TREE_MODEL_FILTER_CLASS (tp_gtk_roster_model_filter_parent_class)->visible (self, child_model, iter);
}

http://git.collabora.co.uk/?p=user/danni/gtk%2B.git;a=commitdiff;h=850f2681cdf632d5afa616538d4403c2b9e40854
Comment 1 Kristian Rietveld 2009-12-13 13:31:06 UTC
Patch seems fine, but please make sure the test suite for the filter model still passes.  See also my mail to gtk-devel-list.
Comment 2 Javier Jardón (IRC: jjardon) 2010-01-12 14:56:28 UTC
Danielle,

Did you verify that the test suite for the filter model still passes?
Comment 3 Javier Jardón (IRC: jjardon) 2010-01-18 23:08:46 UTC
Comment on attachment 149411 [details] [review]
implementation

I tried the patch here and all gtk/tests/filtermodel tests are paseed.
But the patch introduces some compilation warnings that would be great get fixed
Comment 4 Javier Jardón (IRC: jjardon) 2010-05-04 01:54:18 UTC
For reference, this is the kris mail: http://mail.gnome.org/archives/gtk-devel-list/2009-December/msg00048.html
Comment 5 Javier Jardón (IRC: jjardon) 2010-05-04 01:54:58 UTC
Comment on attachment 149411 [details] [review]
implementation

commit 227d59c19015d488eda2895c1022b95ac1463d2a
Comment 6 Javier Jardón (IRC: jjardon) 2010-05-04 01:55:19 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.