diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-05-24 22:24:32 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-14 15:21:47 +0800 |
commit | ec9056604f24cd9811aaa2010be91eb32985efa1 (patch) | |
tree | 8fa49812c16b824d7347a87a013ac4471082bcbc /libempathy-gtk | |
parent | 2f9c2d7e591b876ac6c52953b687308b8aa06fe6 (diff) | |
download | gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar.gz gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar.bz2 gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar.lz gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar.xz gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.tar.zst gsoc2013-empathy-ec9056604f24cd9811aaa2010be91eb32985efa1.zip |
Filter out offline contacts
Diffstat (limited to 'libempathy-gtk')
-rw-r--r-- | libempathy-gtk/empathy-roster-view.c | 55 | ||||
-rw-r--r-- | libempathy-gtk/empathy-roster-view.h | 3 |
2 files changed, 58 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c index 0e7bf51f4..966735e70 100644 --- a/libempathy-gtk/empathy-roster-view.c +++ b/libempathy-gtk/empathy-roster-view.c @@ -10,6 +10,7 @@ G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX) enum { PROP_MANAGER = 1, + PROP_SHOW_OFFLINE, N_PROPS }; @@ -28,6 +29,8 @@ struct _EmpathyRosterViewPriv /* FolksIndividual (borrowed) -> EmpathyRosterItem (borrowed) */ GHashTable *items; + + gboolean show_offline; }; static void @@ -43,6 +46,9 @@ empathy_roster_view_get_property (GObject *object, case PROP_MANAGER: g_value_set_object (value, self->priv->manager); break; + case PROP_SHOW_OFFLINE: + g_value_set_boolean (value, self->priv->show_offline); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -63,6 +69,9 @@ empathy_roster_view_set_property (GObject *object, g_assert (self->priv->manager == NULL); /* construct only */ self->priv->manager = g_value_dup_object (value); break; + case PROP_SHOW_OFFLINE: + empathy_roster_view_show_offline (self, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -70,6 +79,14 @@ empathy_roster_view_set_property (GObject *object, } static void +item_changed_cb (GtkWidget *item, + GParamSpec *spec, + EmpathyRosterView *self) +{ + egg_list_box_child_changed (EGG_LIST_BOX (self), item); +} + +static void individual_added (EmpathyRosterView *self, FolksIndividual *individual) { @@ -81,6 +98,10 @@ individual_added (EmpathyRosterView *self, item = empathy_roster_item_new (individual); + /* Need to refilter if online is changed */ + g_signal_connect (item, "notify::online", + G_CALLBACK (item_changed_cb), self); + gtk_widget_show (item); gtk_container_add (GTK_CONTAINER (self), item); @@ -164,6 +185,19 @@ update_separator (GtkWidget **separator, g_object_ref_sink (*separator); } +static gboolean +filter_list (GtkWidget *child, + gpointer user_data) +{ + EmpathyRosterView *self = user_data; + EmpathyRosterItem *item = EMPATHY_ROSTER_ITEM (child); + + if (self->priv->show_offline) + return TRUE; + + return empathy_roster_item_is_online (item); +} + static void empathy_roster_view_constructed (GObject *object) { @@ -195,6 +229,8 @@ empathy_roster_view_constructed (GObject *object) egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator, self, NULL); + + egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL); } static void @@ -242,6 +278,12 @@ empathy_roster_view_class_init ( G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_property (oclass, PROP_MANAGER, spec); + spec = g_param_spec_boolean ("show-offline", "Show Offline", + "Show offline contacts", + FALSE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_property (oclass, PROP_SHOW_OFFLINE, spec); + g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv)); } @@ -269,3 +311,16 @@ empathy_roster_view_get_manager (EmpathyRosterView *self) { return self->priv->manager; } + +void +empathy_roster_view_show_offline (EmpathyRosterView *self, + gboolean show) +{ + if (self->priv->show_offline == show) + return; + + self->priv->show_offline = show; + egg_list_box_refilter (EGG_LIST_BOX (self)); + + g_object_notify (G_OBJECT (self), "show-offline"); +} diff --git a/libempathy-gtk/empathy-roster-view.h b/libempathy-gtk/empathy-roster-view.h index 2567e75d2..57fb8094b 100644 --- a/libempathy-gtk/empathy-roster-view.h +++ b/libempathy-gtk/empathy-roster-view.h @@ -53,6 +53,9 @@ GtkWidget * empathy_roster_view_new (EmpathyIndividualManager *manager); EmpathyIndividualManager * empathy_roster_view_get_manager ( EmpathyRosterView *self); +void empathy_roster_view_show_offline (EmpathyRosterView *self, + gboolean show); + G_END_DECLS #endif /* #ifndef __EMPATHY_ROSTER_VIEW_H__*/ |