[empathy] factor out empathy_individual_match_words()



commit 5dc3feb4979804c710d4e872a1f05bc425fd9410
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Tue May 31 15:24:28 2011 +0200

    factor out empathy_individual_match_words()

 libempathy-gtk/empathy-individual-view.c |   34 +----------------------
 libempathy-gtk/empathy-ui-utils.c        |   42 ++++++++++++++++++++++++++++++
 libempathy-gtk/empathy-ui-utils.h        |    4 +++
 libempathy/empathy-utils.c               |    1 -
 4 files changed, 48 insertions(+), 33 deletions(-)
---
diff --git a/libempathy-gtk/empathy-individual-view.c b/libempathy-gtk/empathy-individual-view.c
index eb41996..ec63298 100644
--- a/libempathy-gtk/empathy-individual-view.c
+++ b/libempathy-gtk/empathy-individual-view.c
@@ -1692,7 +1692,6 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (self);
   EmpathyLiveSearch *live = EMPATHY_LIVE_SEARCH (priv->search_widget);
-  const gchar *str;
   GList *personas, *l;
   gboolean is_favorite, contains_interesting_persona = FALSE;
 
@@ -1729,37 +1728,8 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
     return (priv->show_offline || is_online);
   }
 
-  /* check alias name */
-  str = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual));
-
-  if (empathy_live_search_match (live, str))
-    return TRUE;
-
-  /* check contact id, remove the @server.com part */
-  for (l = personas; l; l = l->next)
-    {
-      const gchar *p;
-      gchar *dup_str = NULL;
-      gboolean visible;
-
-      if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
-        continue;
-
-      str = folks_persona_get_display_id (l->data);
-      p = strstr (str, "@");
-      if (p != NULL)
-        str = dup_str = g_strndup (str, p - str);
-
-      visible = empathy_live_search_match (live, str);
-      g_free (dup_str);
-      if (visible)
-        return TRUE;
-    }
-
-  /* FIXME: Add more rules here, we could check phone numbers in
-   * contact's vCard for example. */
-
-  return FALSE;
+  return empathy_individual_match_words (individual,
+      empathy_live_search_get_words (live));
 }
 
 static gchar *
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index a1bd50f..ee73c14 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -44,6 +44,7 @@
 
 #include "empathy-ui-utils.h"
 #include "empathy-images.h"
+#include "empathy-live-search.h"
 #include "empathy-smiley-manager.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
@@ -1947,3 +1948,44 @@ empathy_get_current_action_time (void)
 {
   return (tp_user_action_time_from_x11 (gtk_get_current_event_time ()));
 }
+
+gboolean
+empathy_individual_match_words (FolksIndividual *individual,
+    GPtrArray *words)
+{
+  const gchar *str;
+  GList *personas, *l;
+
+  /* check alias name */
+  str = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual));
+
+  if (empathy_live_search_match_words (str, words))
+    return TRUE;
+
+  personas = folks_individual_get_personas (individual);
+
+  /* check contact id, remove the @server.com part */
+  for (l = personas; l; l = l->next)
+    {
+      const gchar *p;
+      gchar *dup_str = NULL;
+      gboolean visible;
+
+      if (!empathy_folks_persona_is_interesting (FOLKS_PERSONA (l->data)))
+        continue;
+
+      str = folks_persona_get_display_id (l->data);
+      p = strstr (str, "@");
+      if (p != NULL)
+        str = dup_str = g_strndup (str, p - str);
+
+      visible = empathy_live_search_match_words (str, words);
+      g_free (dup_str);
+      if (visible)
+        return TRUE;
+    }
+
+  /* FIXME: Add more rules here, we could check phone numbers in
+   * contact's vCard for example. */
+  return FALSE;
+}
diff --git a/libempathy-gtk/empathy-ui-utils.h b/libempathy-gtk/empathy-ui-utils.h
index af48401..aa46e8e 100644
--- a/libempathy-gtk/empathy-ui-utils.h
+++ b/libempathy-gtk/empathy-ui-utils.h
@@ -149,6 +149,10 @@ GtkWidget * empathy_context_menu_new                    (GtkWidget *attach_to);
 
 gint64      empathy_get_current_action_time             (void);
 
+gboolean empathy_individual_match_words (
+    FolksIndividual *individual,
+    GPtrArray *words);
+
 G_END_DECLS
 
 #endif /*  __EMPATHY_UI_UTILS_H__ */
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 8173f78..d62066f 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -1031,4 +1031,3 @@ empathy_format_currency (gint         amount,
 
 	return money;
 }
-



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