[empathy] Moved contact_in_top and contact_is_favourite from view to model



commit af7910a9af2984973be248b769d74f09e84822d4
Author: Laurent Contzen <lcontzen gmail com>
Date:   Sat Aug 4 15:29:46 2012 +0200

    Moved contact_in_top and contact_is_favourite from view to model
    
    empathy-roster-model: new function _contact_in_top
    empathy-roster-model-manager: implemented _contact_in_top, new function contact_is_favourite
    empathy-roster-view: removed contact_in_top and contact_is_favourite functions, now calling model's _contact_in_top instead

 libempathy-gtk/empathy-roster-model-manager.c |   32 +++++++++++++++++++
 libempathy-gtk/empathy-roster-model.c         |   25 +++++++++++++++
 libempathy-gtk/empathy-roster-model.h         |    7 ++++
 libempathy-gtk/empathy-roster-view.c          |   41 ++++---------------------
 4 files changed, 70 insertions(+), 35 deletions(-)
---
diff --git a/libempathy-gtk/empathy-roster-model-manager.c b/libempathy-gtk/empathy-roster-model-manager.c
index f507173..ebf2693 100644
--- a/libempathy-gtk/empathy-roster-model-manager.c
+++ b/libempathy-gtk/empathy-roster-model-manager.c
@@ -81,6 +81,17 @@ is_xmpp_local_contact (FolksIndividual *individual)
   return result;
 }
 
+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 void
 members_changed_cb (EmpathyIndividualManager *manager,
     const gchar *message,
@@ -302,6 +313,26 @@ empathy_roster_model_manager_get_top_individuals (EmpathyRosterModel *model)
   return empathy_individual_manager_get_top_individuals (self->priv->manager);
 }
 
+static gboolean
+empathy_roster_model_manager_contact_in_top (EmpathyRosterModel *model,
+    EmpathyRosterContact *contact)
+{
+  FolksIndividual *individual;
+  GList *tops;
+
+  if (contact_is_favourite (contact))
+    return TRUE;
+
+  individual = empathy_roster_contact_get_individual (contact);
+
+  tops = empathy_roster_model_get_top_individuals (model);
+
+  if (g_list_index (tops, individual) != -1)
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 roster_model_iface_init (EmpathyRosterModelInterface *iface)
 {
@@ -309,4 +340,5 @@ roster_model_iface_init (EmpathyRosterModelInterface *iface)
   iface->get_groups_for_individual =
     empathy_roster_model_manager_get_groups_for_individual;
   iface->get_top_individuals = empathy_roster_model_manager_get_top_individuals;
+  iface->contact_in_top = empathy_roster_model_manager_contact_in_top;
 }
diff --git a/libempathy-gtk/empathy-roster-model.c b/libempathy-gtk/empathy-roster-model.c
index 671f4b1..2334c63 100644
--- a/libempathy-gtk/empathy-roster-model.c
+++ b/libempathy-gtk/empathy-roster-model.c
@@ -188,3 +188,28 @@ empathy_roster_model_get_top_individuals (EmpathyRosterModel *self)
 
   return (* iface->get_top_individuals) (self);
 }
+
+/**
+ * empathy_roster_model_contact_in_top:
+ * @self: a #EmpathyRosterModel
+ * @contact: a #EmpathyRosterContact
+ *
+ * Checks if the passed #EmpathyRosterContact should be displayed in
+ * top contacts.
+ *
+ * Return value: %TRUE if it should be displayed in top contacts, %FALSE
+ * if not
+ */
+gboolean
+empathy_roster_model_contact_in_top (EmpathyRosterModel *self,
+    EmpathyRosterContact *contact)
+{
+  EmpathyRosterModelInterface *iface;
+
+  g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (self), FALSE);
+
+  iface = EMPATHY_ROSTER_MODEL_GET_IFACE (self);
+  g_return_val_if_fail (iface->contact_in_top != NULL, FALSE);
+
+  return (* iface->contact_in_top) (self, contact);
+}
diff --git a/libempathy-gtk/empathy-roster-model.h b/libempathy-gtk/empathy-roster-model.h
index d4737b7..c624ca4 100644
--- a/libempathy-gtk/empathy-roster-model.h
+++ b/libempathy-gtk/empathy-roster-model.h
@@ -24,6 +24,8 @@
 
 #include <folks/folks.h>
 
+#include <libempathy-gtk/empathy-roster-contact.h>
+
 G_BEGIN_DECLS
 
 typedef struct _EmpathyRosterModel EmpathyRosterModel;
@@ -39,6 +41,8 @@ struct _EmpathyRosterModelInterface
   GList * (*get_groups_for_individual) (EmpathyRosterModel *self,
       FolksIndividual *individual);
   GList * (*get_top_individuals) (EmpathyRosterModel *self);
+  gboolean (*contact_in_top) (EmpathyRosterModel *self,
+      EmpathyRosterContact *contact);
 };
 
 GType empathy_roster_model_get_type (void);
@@ -86,6 +90,9 @@ GList * empathy_roster_model_get_groups_for_individual (EmpathyRosterModel *self
 
 GList * empathy_roster_model_get_top_individuals (EmpathyRosterModel *self);
 
+gboolean empathy_roster_model_contact_in_top (EmpathyRosterModel *self,
+    EmpathyRosterContact *contact);
+
 G_END_DECLS
 
 #endif /* #ifndef __EMPATHY_ROSTER_MODEL_H__*/
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c
index 06a4ebf..84bd5d4 100644
--- a/libempathy-gtk/empathy-roster-view.c
+++ b/libempathy-gtk/empathy-roster-view.c
@@ -510,37 +510,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_roster_model_get_top_individuals (self->priv->model);
-
-  if (g_list_index (tops, individual) != -1)
-    return TRUE;
-
-  return FALSE;
-}
-
 static gint
 compare_roster_contacts_no_group (EmpathyRosterView *self,
     EmpathyRosterContact *a,
@@ -548,8 +517,8 @@ compare_roster_contacts_no_group (EmpathyRosterView *self,
 {
   gboolean top_a, top_b;
 
-  top_a = contact_in_top (self, a);
-  top_b = contact_in_top (self, b);
+  top_a = empathy_roster_model_contact_in_top (self->priv->model, a);
+  top_b = empathy_roster_model_contact_in_top (self->priv->model, b);
 
   if (top_a == top_b)
     /* Both contacts are in the top of the roster (or not). Sort them
@@ -772,7 +741,8 @@ contact_should_be_displayed (EmpathyRosterView *self,
   if (self->priv->show_offline)
       return TRUE;
 
-  if (contact_is_favourite (contact))
+  if (empathy_roster_model_contact_in_top (self->priv->model,
+          contact))
     {
       const gchar *group_name;
 
@@ -968,7 +938,8 @@ update_top_contacts (EmpathyRosterView *self)
           EmpathyRosterContact *contact = l->data;
           FolksIndividual *individual;
 
-          if (contact_is_favourite (contact))
+          if (empathy_roster_model_contact_in_top (self->priv->model,
+                  contact))
             continue;
 
           individual = empathy_roster_contact_get_individual (contact);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]