]> git.0d.be Git - empathy.git/commitdiff
roster-view: display favorite contacts at the top of the roster as well
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 14 Jun 2012 13:50:15 +0000 (15:50 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 15 Jun 2012 11:07:18 +0000 (13:07 +0200)
I renamed the group to 'Top Contacts' but I'm open to a better suggestion.

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

libempathy-gtk/empathy-roster-view.c

index a035c897e567ecfa7644e4411e3b5bd5e027b8ec..130fbab0cd86bfaea737a16316f74122aae29b11 100644 (file)
@@ -34,7 +34,7 @@ static guint signals[LAST_SIGNAL];
 
 #define NO_GROUP "X-no-group"
 #define UNGROUPED _("Ungrouped")
-#define TOP_GROUP _("Most Used")
+#define TOP_GROUP _("Top Contacts")
 
 struct _EmpathyRosterViewPriv
 {
@@ -302,6 +302,12 @@ individual_added (EmpathyRosterView *self,
     {
       GeeSet *groups;
 
+      if (folks_favourite_details_get_is_favourite (
+            FOLKS_FAVOURITE_DETAILS (individual)))
+        {
+          add_to_group (self, individual, TOP_GROUP);
+        }
+
       groups = folks_group_details_get_groups (
           FOLKS_GROUP_DETAILS (individual));
 
@@ -512,6 +518,17 @@ 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)
@@ -519,6 +536,9 @@ contact_in_top (EmpathyRosterView *self,
   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);
@@ -748,6 +768,13 @@ contact_should_be_displayed (EmpathyRosterView *self,
         {
           return TRUE;
         }
+      else if (!self->priv->show_groups &&
+          contact_is_favourite (contact))
+        {
+          /* Always display favourite contacts in non-group mode. In the group
+           * mode we'll display only the one in the 'top' section. */
+          return TRUE;
+        }
       else
         {
           return empathy_roster_contact_is_online (contact);
@@ -771,6 +798,10 @@ filter_contact (EmpathyRosterView *self,
       group_name = empathy_roster_contact_get_group (contact);
       group = lookup_roster_group (self, group_name);
 
+      if (!tp_strdiff (group_name, TOP_GROUP) &&
+          contact_is_favourite (contact))
+        displayed = TRUE;
+
       if (group != NULL)
         {
           /* When searching, always display even if the group is closed */
@@ -930,6 +961,9 @@ update_top_contacts (EmpathyRosterView *self)
           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)
@@ -984,6 +1018,37 @@ top_individuals_changed_cb (EmpathyIndividualManager *manager,
   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, TOP_GROUP);
+      else
+        remove_from_group (self, individual, 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)
 {
@@ -1004,6 +1069,8 @@ empathy_roster_view_constructed (GObject *object)
       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);