[empathy] Filter out offline contacts
- From: Guillaume Desmottes <gdesmott src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy] Filter out offline contacts
- Date: Thu, 14 Jun 2012 07:48:57 +0000 (UTC)
commit ec9056604f24cd9811aaa2010be91eb32985efa1
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date: Thu May 24 16:24:32 2012 +0200
Filter out offline contacts
libempathy-gtk/empathy-roster-view.c | 55 ++++++++++++++++++++++++++++++++++
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 0e7bf51..966735e 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 2567e75..57fb809 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__*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]