]> git.0d.be Git - empathy.git/commitdiff
roster-view: don't display offline not favorite top contacts
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 30 Aug 2012 08:10:38 +0000 (10:10 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 4 Sep 2012 08:08:53 +0000 (10:08 +0200)
We just want to always display the favorites offline contacts in the top
contact section.

One may say that we are kinda breaking the model group abstraction, which is
probably true. Ideally we may want to have a roster view subclass implementing
the top contact logic but life is too short.

https://bugzilla.gnome.org/show_bug.cgi?id=683022

libempathy-gtk/empathy-roster-view.c

index 557728527900b52cee7bd7ea7059be0edf71c4cd..bd62aadf6eb6467d2942019d2b7df1ad998d4501 100644 (file)
@@ -345,6 +345,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)
@@ -385,6 +411,9 @@ individual_added (EmpathyRosterView *self,
 
       g_list_free (groups);
     }
+
+  tp_g_signal_connect_object (individual, "notify::is-favourite",
+      G_CALLBACK (individual_favourite_change_cb), self, 0);
 }
 
 static void
@@ -793,6 +822,17 @@ remove_from_displayed (EmpathyRosterView *self,
   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));
+}
+
 /**
  * check if @contact should be displayed according to @self's current status
  * and without consideration for the state of @contact's groups.
@@ -815,7 +855,9 @@ contact_should_be_displayed (EmpathyRosterView *self,
   if (self->priv->show_offline)
       return TRUE;
 
-  if (contact_in_top (self, contact))
+  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);