]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-roster-view.c
Use a flat namespace for internal includes
[empathy.git] / libempathy-gtk / empathy-roster-view.c
index 90d7296ebc01113366550b12caaec2fa2aa2f625..336f629c7b95eefab22467486e162818cbb1f465 100644 (file)
@@ -4,21 +4,24 @@
 
 #include <glib/gi18n-lib.h>
 
-#include <libempathy-gtk/empathy-roster-contact.h>
-#include <libempathy-gtk/empathy-roster-group.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-contact-groups.h"
 
-#include <libempathy/empathy-utils.h>
+#include "empathy-roster-contact.h"
+#include "empathy-roster-group.h"
+#include "empathy-ui-utils.h"
 
 G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX)
 
 /* Flashing delay for icons (milliseconds). */
 #define FLASH_TIMEOUT 500
 
+/* Delay in milliseconds between the last stroke on the keyboard and the start
+ * of the live search. */
+#define SEARCH_TIMEOUT 500
+
 enum
 {
-  PROP_MANAGER = 1,
-  PROP_MODEL,
+  PROP_MODEL = 1,
   PROP_SHOW_OFFLINE,
   PROP_SHOW_GROUPS,
   PROP_EMPTY,
@@ -40,8 +43,6 @@ static guint signals[LAST_SIGNAL];
 
 struct _EmpathyRosterViewPriv
 {
-  EmpathyIndividualManager *manager;
-
   /* FolksIndividual (borrowed) -> GHashTable (
    * (gchar * group_name) -> EmpathyRosterContact (borrowed))
    *
@@ -62,6 +63,8 @@ struct _EmpathyRosterViewPriv
   guint flash_id;
   gboolean display_flash_event;
 
+  guint search_id;
+
   gboolean show_offline;
   gboolean show_groups;
   gboolean empty;
@@ -114,9 +117,6 @@ empathy_roster_view_get_property (GObject *object,
 
   switch (property_id)
     {
-      case PROP_MANAGER:
-        g_value_set_object (value, self->priv->manager);
-        break;
       case PROP_MODEL:
         g_value_set_object (value, self->priv->model);
         break;
@@ -145,10 +145,6 @@ empathy_roster_view_set_property (GObject *object,
 
   switch (property_id)
     {
-      case PROP_MANAGER:
-        g_assert (self->priv->manager == NULL); /* construct only */
-        self->priv->manager = g_value_dup_object (value);
-        break;
       case PROP_MODEL:
         g_assert (self->priv->model == NULL);
         self->priv->model = g_value_dup_object (value);
@@ -173,27 +169,6 @@ roster_contact_changed_cb (GtkWidget *child,
   egg_list_box_child_changed (EGG_LIST_BOX (self), child);
 }
 
-static gboolean
-is_xmpp_local_contact (FolksIndividual *individual)
-{
-  EmpathyContact *contact;
-  TpConnection *connection;
-  const gchar *protocol_name = NULL;
-  gboolean result;
-
-  contact = empathy_contact_dup_from_folks_individual (individual);
-
-  if (contact == NULL)
-    return FALSE;
-
-  connection = empathy_contact_get_connection (contact);
-  protocol_name = tp_connection_get_protocol_name (connection);
-  result = !tp_strdiff (protocol_name, "local-xmpp");
-  g_object_unref (contact);
-
-  return result;
-}
-
 static GtkWidget *
 add_roster_contact (EmpathyRosterView *self,
     FolksIndividual *individual,
@@ -231,6 +206,9 @@ group_expanded_cb (EmpathyRosterGroup *group,
     }
 
   g_list_free (widgets);
+
+  empathy_contact_group_set_expanded (empathy_roster_group_get_name (group),
+      gtk_expander_get_expanded (GTK_EXPANDER (group)));
 }
 
 static EmpathyRosterGroup *
@@ -250,13 +228,16 @@ ensure_roster_group (EmpathyRosterView *self,
   if (roster_group != NULL)
     return EMPATHY_ROSTER_GROUP (roster_group);
 
-  if (!tp_strdiff (group, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+  if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
     roster_group = empathy_roster_group_new (group, "emblem-favorite-symbolic");
-  else if (!tp_strdiff (group, EMPATHY_ROSTER_VIEW_GROUP_PEOPLE_NEARBY))
+  else if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_PEOPLE_NEARBY))
     roster_group = empathy_roster_group_new (group, "im-local-xmpp");
   else
     roster_group = empathy_roster_group_new (group, NULL);
 
+  gtk_expander_set_expanded (GTK_EXPANDER (roster_group),
+      empathy_contact_group_get_expanded (group));
+
   g_signal_connect (roster_group, "notify::expanded",
       G_CALLBACK (group_expanded_cb), self);
 
@@ -269,6 +250,53 @@ ensure_roster_group (EmpathyRosterView *self,
   return EMPATHY_ROSTER_GROUP (roster_group);
 }
 
+static void
+update_empty (EmpathyRosterView *self,
+    gboolean empty)
+{
+  if (self->priv->empty == empty)
+    return;
+
+  self->priv->empty = empty;
+  g_object_notify (G_OBJECT (self), "empty");
+}
+
+static gboolean filter_group (EmpathyRosterView *self,
+    EmpathyRosterGroup *group);
+
+static gboolean
+at_least_one_group_displayed (EmpathyRosterView *self)
+{
+  GHashTableIter iter;
+  gpointer v;
+
+  g_hash_table_iter_init (&iter, self->priv->roster_groups);
+  while (g_hash_table_iter_next (&iter, NULL, &v))
+    {
+      EmpathyRosterGroup *group = EMPATHY_ROSTER_GROUP (v);
+
+      if (filter_group (self, group))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+check_if_empty (EmpathyRosterView *self)
+{
+  /* Roster is considered as empty if there is no contact *and* no group
+   * currently displayed. */
+  if (g_hash_table_size (self->priv->displayed_contacts) != 0 ||
+      at_least_one_group_displayed (self))
+    {
+      update_empty (self, FALSE);
+      return;
+    }
+
+  update_empty (self, TRUE);
+}
+
 static void
 update_group_widgets (EmpathyRosterView *self,
     EmpathyRosterGroup *group,
@@ -285,7 +313,11 @@ update_group_widgets (EmpathyRosterView *self,
     count = empathy_roster_group_remove_widget (group, GTK_WIDGET (contact));
 
   if (count != old_count)
-    egg_list_box_child_changed (EGG_LIST_BOX (self), GTK_WIDGET (group));
+    {
+      egg_list_box_child_changed (EGG_LIST_BOX (self), GTK_WIDGET (group));
+
+      check_if_empty (self);
+    }
 }
 
 static void
@@ -301,6 +333,9 @@ add_to_group (EmpathyRosterView *self,
   if (contacts == NULL)
     return;
 
+  if (g_hash_table_lookup (contacts, group) != NULL)
+    return;
+
   if (tp_strdiff (group, NO_GROUP))
     roster_group = ensure_roster_group (self, group);
 
@@ -314,6 +349,32 @@ add_to_group (EmpathyRosterView *self,
     }
 }
 
+static void
+individual_favourite_change_cb (FolksIndividual *individual,
+    GParamSpec *spec,
+    EmpathyRosterView *self)
+{
+  /* We may have to refilter the contact as only favorite contacts are always
+   * displayed regardless of their presence. */
+  GHashTable *contacts;
+  GtkWidget *contact;
+
+  contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
+  if (contacts == NULL)
+    return;
+
+  if (self->priv->show_groups)
+    contact = g_hash_table_lookup (contacts,
+        EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP);
+  else
+    contact = g_hash_table_lookup (contacts, NO_GROUP);
+
+  if (contact == NULL)
+    return;
+
+  egg_list_box_child_changed (EGG_LIST_BOX (self), contact);
+}
+
 static void
 individual_added (EmpathyRosterView *self,
     FolksIndividual *individual)
@@ -332,49 +393,31 @@ individual_added (EmpathyRosterView *self,
     {
       add_to_group (self, individual, NO_GROUP);
     }
-  else if (is_xmpp_local_contact (individual))
-    {
-      add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_PEOPLE_NEARBY);
-    }
   else
     {
-      GeeSet *groups;
-      GList *tops;
-
-      tops = empathy_individual_manager_get_top_individuals (
-          self->priv->manager);
-
-      if (folks_favourite_details_get_is_favourite (
-            FOLKS_FAVOURITE_DETAILS (individual)) ||
-          g_list_index (tops, individual) != -1)
-        {
-          add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-        }
+      GList *groups, *l;
 
-      groups = folks_group_details_get_groups (
-          FOLKS_GROUP_DETAILS (individual));
+      groups = empathy_roster_model_dup_groups_for_individual (self->priv->model,
+          individual);
 
-      if (gee_collection_get_size (GEE_COLLECTION (groups)) > 0)
+      if (g_list_length (groups) > 0)
         {
-          GeeIterator *iter = gee_iterable_iterator (GEE_ITERABLE (groups));
-
-          while (iter != NULL && gee_iterator_next (iter))
+          for (l = groups; l != NULL; l = g_list_next (l))
             {
-              gchar *group = gee_iterator_get (iter);
-
-              add_to_group (self, individual, group);
-
-              g_free (group);
+              add_to_group (self, individual, l->data);
             }
-
-          g_clear_object (&iter);
         }
       else
         {
           /* No group, adds to Ungrouped */
-          add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED);
+          add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
         }
+
+      g_list_free_full (groups, g_free);
     }
+
+  tp_g_signal_connect_object (individual, "notify::is-favourite",
+      G_CALLBACK (individual_favourite_change_cb), self, 0);
 }
 
 static void
@@ -536,6 +579,41 @@ individual_removed_cb (EmpathyRosterModel *model,
   individual_removed (self, individual);
 }
 
+static gboolean
+contact_in_top (EmpathyRosterView *self,
+    EmpathyRosterContact *contact)
+{
+  if (!self->priv->show_groups)
+    {
+      /* Always display top contacts in non-group mode. */
+      GList *groups;
+      FolksIndividual *individual;
+      gboolean result = FALSE;
+
+      individual = empathy_roster_contact_get_individual (contact);
+
+      groups = empathy_roster_model_dup_groups_for_individual (
+          self->priv->model, individual);
+
+      if (g_list_find_custom (groups, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP,
+            (GCompareFunc) g_strcmp0) != NULL)
+        result = TRUE;
+
+      g_list_free_full (groups, g_free);
+
+      return result;
+    }
+
+  if (!tp_strdiff (empathy_roster_contact_get_group (contact),
+          EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
+    /* If we are displaying contacts, we only want to *always* display the
+     * RosterContact which is displayed at the top; not the ones displayed in
+     * the 'normal' group sections */
+    return TRUE;
+
+  return FALSE;
+}
+
 static gint
 compare_roster_contacts_by_alias (EmpathyRosterContact *a,
     EmpathyRosterContact *b)
@@ -552,37 +630,6 @@ compare_roster_contacts_by_alias (EmpathyRosterContact *a,
   return g_ascii_strcasecmp (alias_a, alias_b);
 }
 
-static gboolean
-contact_is_favourite (EmpathyRosterContact *contact)
-{
-  FolksIndividual *individual;
-
-  individual = empathy_roster_contact_get_individual (contact);
-
-  return folks_favourite_details_get_is_favourite (
-      FOLKS_FAVOURITE_DETAILS (individual));
-}
-
-static gboolean
-contact_in_top (EmpathyRosterView *self,
-    EmpathyRosterContact *contact)
-{
-  FolksIndividual *individual;
-  GList *tops;
-
-  if (contact_is_favourite (contact))
-    return TRUE;
-
-  individual = empathy_roster_contact_get_individual (contact);
-
-  tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
-
-  if (g_list_index (tops, individual) != -1)
-    return TRUE;
-
-  return FALSE;
-}
-
 static gint
 compare_roster_contacts_no_group (EmpathyRosterView *self,
     EmpathyRosterContact *a,
@@ -607,15 +654,15 @@ static gint
 compare_group_names (const gchar *group_a,
     const gchar *group_b)
 {
-  if (!tp_strdiff (group_a, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+  if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
     return -1;
 
-  if (!tp_strdiff (group_b, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+  if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
     return 1;
 
-  if (!tp_strdiff (group_a, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED))
+  if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
     return 1;
-  else if (!tp_strdiff (group_b, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED))
+  else if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
     return -1;
 
   return g_ascii_strcasecmp (group_a, group_b);
@@ -731,17 +778,6 @@ is_searching (EmpathyRosterView *self)
   return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
 }
 
-static void
-update_empty (EmpathyRosterView *self,
-    gboolean empty)
-{
-  if (self->priv->empty == empty)
-    return;
-
-  self->priv->empty = empty;
-  g_object_notify (G_OBJECT (self), "empty");
-}
-
 static void
 add_to_displayed (EmpathyRosterView *self,
     EmpathyRosterContact *contact)
@@ -788,8 +824,18 @@ remove_from_displayed (EmpathyRosterView *self,
 {
   g_hash_table_remove (self->priv->displayed_contacts, contact);
 
-  if (g_hash_table_size (self->priv->displayed_contacts) == 0)
-    update_empty (self, TRUE);
+  check_if_empty (self);
+}
+
+static gboolean
+contact_is_favorite (EmpathyRosterContact *contact)
+{
+  FolksIndividual *individual;
+
+  individual = empathy_roster_contact_get_individual (contact);
+
+  return folks_favourite_details_get_is_favourite (
+      FOLKS_FAVOURITE_DETAILS (individual));
 }
 
 /**
@@ -814,21 +860,10 @@ contact_should_be_displayed (EmpathyRosterView *self,
   if (self->priv->show_offline)
       return TRUE;
 
-  if (contact_is_favourite (contact))
-    {
-      const gchar *group_name;
-
-      if (!self->priv->show_groups)
-        /* Always display favourite contacts in non-group mode. */
-        return TRUE;
-
-      group_name = empathy_roster_contact_get_group (contact);
-
-      if (!tp_strdiff (group_name, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
-        /* Always display favourite contact in group mode only in the
-         * 'top group'*/
-        return TRUE;
-    }
+  if (contact_in_top (self, contact) &&
+      contact_is_favorite (contact))
+    /* Favorite top contacts are always displayed */
+    return TRUE;
 
   return empathy_roster_contact_is_online (contact);
 }
@@ -876,6 +911,7 @@ filter_group (EmpathyRosterView *self,
     EmpathyRosterGroup *group)
 {
   GList *widgets, *l;
+  gboolean result = FALSE;
 
   /* Display the group if it contains at least one displayed contact */
   widgets = empathy_roster_group_get_widgets (group);
@@ -884,10 +920,15 @@ filter_group (EmpathyRosterView *self,
       EmpathyRosterContact *contact = l->data;
 
       if (contact_should_be_displayed (self, contact))
-        return TRUE;
+        {
+          result = TRUE;
+          break;
+        }
     }
 
-  return FALSE;
+  g_list_free (widgets);
+
+  return result;
 }
 
 static gboolean
@@ -905,27 +946,6 @@ filter_list (GtkWidget *child,
   g_return_val_if_reached (FALSE);
 }
 
-/* @list: GList of EmpathyRosterContact
- *
- * Returns: %TRUE if @list contains an EmpathyRosterContact associated with
- * @individual */
-static gboolean
-individual_in_list (FolksIndividual *individual,
-    GList *list)
-{
-  GList *l;
-
-  for (l = list; l != NULL; l = g_list_next (l))
-    {
-      EmpathyRosterContact *contact = l->data;
-
-      if (empathy_roster_contact_get_individual (contact) == individual)
-        return TRUE;
-    }
-
-  return FALSE;
-}
-
 static void
 populate_view (EmpathyRosterView *self)
 {
@@ -963,7 +983,7 @@ remove_from_group (EmpathyRosterView *self,
 
   if (g_hash_table_size (contacts) == 0)
     {
-      add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED);
+      add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
     }
 
   roster_group = lookup_roster_group (self, group);
@@ -978,77 +998,18 @@ remove_from_group (EmpathyRosterView *self,
 }
 
 static void
-update_top_contacts (EmpathyRosterView *self)
+groups_changed_cb (EmpathyRosterModel *model,
+    FolksIndividual *individual,
+    const gchar *group,
+    gboolean is_member,
+    EmpathyRosterView *self)
 {
-  GList *tops, *l;
-  GList *to_add = NULL, *to_remove = NULL;
-  EmpathyRosterGroup *group;
-
   if (!self->priv->show_groups)
     {
       egg_list_box_resort (EGG_LIST_BOX (self));
       return;
     }
 
-  tops = empathy_individual_manager_get_top_individuals (self->priv->manager);
-
-  group = g_hash_table_lookup (self->priv->roster_groups,
-      EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-  if (group == NULL)
-    {
-      to_add = g_list_copy (tops);
-    }
-  else
-    {
-      GList *contacts;
-
-      contacts = empathy_roster_group_get_widgets (group);
-
-      /* Check which EmpathyRosterContact have to be removed */
-      for (l = contacts; l != NULL; l = g_list_next (l))
-        {
-          EmpathyRosterContact *contact = l->data;
-          FolksIndividual *individual;
-
-          if (contact_is_favourite (contact))
-            continue;
-
-          individual = empathy_roster_contact_get_individual (contact);
-
-          if (g_list_find (tops, individual) == NULL)
-            to_remove = g_list_prepend (to_remove, individual);
-        }
-
-      /* Check which EmpathyRosterContact have to be added */
-      for (l = tops; l != NULL; l = g_list_next (l))
-        {
-          FolksIndividual *individual = l->data;
-
-          if (!individual_in_list (individual, contacts))
-            to_add = g_list_prepend (to_add, individual);
-        }
-    }
-
-  for (l = to_add; l != NULL; l = g_list_next (l))
-    add_to_group (self, l->data, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-
-  for (l = to_remove; l != NULL; l = g_list_next (l))
-    remove_from_group (self, l->data, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-
-  g_list_free (to_add);
-  g_list_free (to_remove);
-}
-
-static void
-groups_changed_cb (EmpathyIndividualManager *manager,
-    FolksIndividual *individual,
-    gchar *group,
-    gboolean is_member,
-    EmpathyRosterView *self)
-{
-  if (!self->priv->show_groups)
-    return;
-
   if (is_member)
     {
       add_to_group (self, individual, group);
@@ -1059,46 +1020,6 @@ groups_changed_cb (EmpathyIndividualManager *manager,
     }
 }
 
-static void
-top_individuals_changed_cb (EmpathyIndividualManager *manager,
-    GParamSpec *spec,
-    EmpathyRosterView *self)
-{
-  update_top_contacts (self);
-}
-
-static void
-favourites_changed_cb (EmpathyIndividualManager *manager,
-    FolksIndividual *individual,
-    gboolean favourite,
-    EmpathyRosterView *self)
-{
-  GHashTable *contacts;
-
-  contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
-  if (contacts == NULL)
-    return;
-
-  if (self->priv->show_groups)
-    {
-      if (favourite)
-        add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-      else
-        remove_from_group (self, individual,
-            EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-    }
-  else
-    {
-      GtkWidget *contact;
-
-      contact = g_hash_table_lookup (contacts, NO_GROUP);
-      if (contact == NULL)
-        return;
-
-      egg_list_box_child_changed (EGG_LIST_BOX (self), contact);
-    }
-}
-
 static void
 empathy_roster_view_constructed (GObject *object)
 {
@@ -1109,21 +1030,19 @@ empathy_roster_view_constructed (GObject *object)
   if (chain_up != NULL)
     chain_up (object);
 
-  g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager));
   g_assert (EMPATHY_IS_ROSTER_MODEL (self->priv->model));
 
+  /* Get saved group states. */
+  empathy_contact_groups_get_all ();
+
   populate_view (self);
 
   tp_g_signal_connect_object (self->priv->model, "individual-added",
       G_CALLBACK (individual_added_cb), self, 0);
   tp_g_signal_connect_object (self->priv->model, "individual-removed",
       G_CALLBACK (individual_removed_cb), self, 0);
-  tp_g_signal_connect_object (self->priv->manager, "groups-changed",
+  tp_g_signal_connect_object (self->priv->model, "groups-changed",
       G_CALLBACK (groups_changed_cb), self, 0);
-  tp_g_signal_connect_object (self->priv->manager, "notify::top-individuals",
-      G_CALLBACK (top_individuals_changed_cb), self, 0);
-  tp_g_signal_connect_object (self->priv->manager, "notify::favourites-changed",
-      G_CALLBACK (favourites_changed_cb), self, 0);
 
   egg_list_box_set_sort_func (EGG_LIST_BOX (self),
       roster_view_sort, self, NULL);
@@ -1136,6 +1055,17 @@ empathy_roster_view_constructed (GObject *object)
   egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
 }
 
+static void
+clear_view (EmpathyRosterView *self)
+{
+  g_hash_table_remove_all (self->priv->roster_contacts);
+  g_hash_table_remove_all (self->priv->roster_groups);
+  g_hash_table_remove_all (self->priv->displayed_contacts);
+
+  gtk_container_foreach (GTK_CONTAINER (self),
+      (GtkCallback) gtk_widget_destroy, NULL);
+}
+
 static void
 empathy_roster_view_dispose (GObject *object)
 {
@@ -1143,12 +1073,21 @@ empathy_roster_view_dispose (GObject *object)
   void (*chain_up) (GObject *) =
       ((GObjectClass *) empathy_roster_view_parent_class)->dispose;
 
+  /* Start by clearing the view so our internal hash tables are cleared from
+   * objects being destroyed. */
+  clear_view (self);
+
   stop_flashing (self);
 
   empathy_roster_view_set_live_search (self, NULL);
-  g_clear_object (&self->priv->manager);
   g_clear_object (&self->priv->model);
 
+  if (self->priv->search_id != 0)
+    {
+      g_source_remove (self->priv->search_id);
+      self->priv->search_id = 0;
+    }
+
   if (chain_up != NULL)
     chain_up (object);
 }
@@ -1374,12 +1313,6 @@ empathy_roster_view_class_init (
 
   box_class->child_activated = empathy_roster_view_child_activated;
 
-  spec = g_param_spec_object ("manager", "Manager",
-      "EmpathyIndividualManager",
-      EMPATHY_TYPE_INDIVIDUAL_MANAGER,
-      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (oclass, PROP_MANAGER, spec);
-
   spec = g_param_spec_object ("model", "Model",
       "EmpathyRosterModel",
       EMPATHY_TYPE_ROSTER_MODEL,
@@ -1453,24 +1386,15 @@ empathy_roster_view_init (EmpathyRosterView *self)
 }
 
 GtkWidget *
-empathy_roster_view_new (EmpathyIndividualManager *manager,
-    EmpathyRosterModel *model)
+empathy_roster_view_new (EmpathyRosterModel *model)
 {
-  g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
   g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (model), NULL);
 
   return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
-      "manager", manager,
       "model", model,
       NULL);
 }
 
-EmpathyIndividualManager *
-empathy_roster_view_get_manager (EmpathyRosterView *self)
-{
-  return self->priv->manager;
-}
-
 void
 empathy_roster_view_show_offline (EmpathyRosterView *self,
     gboolean show)
@@ -1484,17 +1408,6 @@ empathy_roster_view_show_offline (EmpathyRosterView *self,
   g_object_notify (G_OBJECT (self), "show-offline");
 }
 
-static void
-clear_view (EmpathyRosterView *self)
-{
-  gtk_container_foreach (GTK_CONTAINER (self),
-      (GtkCallback) gtk_widget_destroy, NULL);
-
-  g_hash_table_remove_all (self->priv->roster_contacts);
-  g_hash_table_remove_all (self->priv->roster_groups);
-  g_hash_table_remove_all (self->priv->displayed_contacts);
-}
-
 void
 empathy_roster_view_show_groups (EmpathyRosterView *self,
     gboolean show)
@@ -1534,14 +1447,27 @@ select_first_contact (EmpathyRosterView *self)
   g_list_free (children);
 }
 
+static gboolean
+search_timeout_cb (EmpathyRosterView *self)
+{
+  egg_list_box_refilter (EGG_LIST_BOX (self));
+
+  select_first_contact (self);
+
+  self->priv->search_id = 0;
+  return G_SOURCE_REMOVE;
+}
+
 static void
 search_text_notify_cb (EmpathyLiveSearch *search,
     GParamSpec *pspec,
     EmpathyRosterView *self)
 {
-  egg_list_box_refilter (EGG_LIST_BOX (self));
+  if (self->priv->search_id != 0)
+    g_source_remove (self->priv->search_id);
 
-  select_first_contact (self);
+  self->priv->search_id = g_timeout_add (SEARCH_TIMEOUT,
+      (GSourceFunc) search_timeout_cb, self);
 }
 
 static void