static gint
sort_personas (FolksPersona *persona_a,
    FolksPersona *persona_b)
{
  EmpathyContact *contact;
  TpAccount *account_a, *account_b;
  gint ret_val;

  g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);

  /* alias */
  ret_val = g_utf8_collate (
      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_a)),
      folks_aliasable_get_alias (FOLKS_ALIASABLE (persona_b)));

  if (ret_val != 0)
    goto out;

  /* identifier */
  ret_val = g_utf8_collate (folks_persona_get_display_id (persona_a),
          folks_persona_get_display_id (persona_b));

  if (ret_val != 0)
    goto out;

  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
      TPF_PERSONA (persona_a)));
  account_a = empathy_contact_get_account (contact);
  g_object_unref (contact);

  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
      TPF_PERSONA (persona_b)));
  account_b = empathy_contact_get_account (contact);
  g_object_unref (contact);

  /* protocol */
  ret_val = strcmp (tp_account_get_protocol (account_a),
        tp_account_get_protocol (account_a));

  if (ret_val != 0)
    goto out;

  /* account ID */
  ret_val = strcmp (tp_proxy_get_object_path (account_a),
        tp_proxy_get_object_path (account_a));

out:
  return ret_val;
}
Beispiel #2
0
/* @words = tpaw_live_search_strip_utf8_string (@text);
 *
 * User has to pass both so we don't have to compute @words ourself each time
 * this function is called. */
gboolean
empathy_individual_match_string (FolksIndividual *individual,
    const char *text,
    GPtrArray *words)
{
  const gchar *str;
  GeeSet *personas;
  GeeIterator *iter;
  gboolean retval = FALSE;

  /* check alias name */
  str = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual));

  if (tpaw_live_search_match_words (str, words))
    return TRUE;

  personas = folks_individual_get_personas (individual);

  /* check contact id, remove the @server.com part */
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (retval == FALSE && gee_iterator_next (iter))
    {
      FolksPersona *persona = gee_iterator_get (iter);
      const gchar *p;

      if (empathy_folks_persona_is_interesting (persona))
        {
          str = folks_persona_get_display_id (persona);

          /* Accept the persona if @text is a full prefix of his ID; that allows
           * user to find, say, a jabber contact by typing his JID. */
          if (g_str_has_prefix (str, text))
            {
              retval = TRUE;
            }
          else
            {
              gchar *dup_str = NULL;
              gboolean visible;

              p = strstr (str, "@");
              if (p != NULL)
                str = dup_str = g_strndup (str, p - str);

              visible = tpaw_live_search_match_words (str, words);
              g_free (dup_str);
              if (visible)
                retval = TRUE;
            }
        }
      g_clear_object (&persona);
    }
  g_clear_object (&iter);

  /* FIXME: Add more rules here, we could check phone numbers in
   * contact's vCard for example. */
  return retval;
}
static void
add_persona (EmpathyPersonaStore *self,
    FolksPersona *persona)
{
  EmpathyPersonaStorePriv *priv;
  GtkTreeIter iter;
  GtkTreePath *path;
  FolksPersonaStore *store;
  EmpathyContact *contact;
  const gchar *alias;

  if (!TPF_IS_PERSONA (persona))
    return;

  priv = GET_PRIV (self);

  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));
  if (EMP_STR_EMPTY (alias))
    return;

  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
      TPF_PERSONA (persona)));
  store = folks_persona_get_store (persona);

  gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
      EMPATHY_PERSONA_STORE_COL_NAME, alias,
      EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
          folks_persona_store_get_display_name (store),
      EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
          folks_persona_get_display_id (persona),
      EMPATHY_PERSONA_STORE_COL_PERSONA, persona,
      EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
          empathy_contact_get_capabilities (contact) &
              EMPATHY_CAPABILITIES_AUDIO,
      EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
          empathy_contact_get_capabilities (contact) &
              EMPATHY_CAPABILITIES_VIDEO,
      -1);

  g_object_unref (contact);

  path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
  g_hash_table_replace (priv->personas, g_object_ref (persona),
      gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path));
  gtk_tree_path_free (path);

  update_persona (self, persona);
}
static void
update_persona (EmpathyPersonaStore *self,
    FolksPersona *persona)
{
  EmpathyPersonaStorePriv *priv = GET_PRIV (self);
  GtkTreePath *path;
  gboolean do_set_active = FALSE;
  gboolean do_set_refresh = FALSE;
  const gchar *alias;

  path = find_persona (self, persona);
  alias = folks_aliasable_get_alias (FOLKS_ALIASABLE (persona));

  if (path == NULL)
    {
      DEBUG ("Contact:'%s' in list:NO, should be:YES", alias);

      add_persona (self, persona);

      if (priv->show_active)
        {
          do_set_active = TRUE;
          DEBUG ("Set active (contact added)");
        }
    }
  else
    {
      FolksPersonaStore *store;
      EmpathyContact *contact;
      GtkTreeIter iter;
      GdkPixbuf *pixbuf_avatar;
      GdkPixbuf *pixbuf_status;
      gboolean now_online = FALSE;
      gboolean was_online = TRUE;

      DEBUG ("Contact:'%s' in list:YES, should be:YES", alias);

      gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
      gtk_tree_path_free (path);

      /* Get online state now. */
      now_online = folks_presence_is_online (FOLKS_PRESENCE (persona));

      /* Get online state before. */
      gtk_tree_model_get (GTK_TREE_MODEL (self), &iter,
          EMPATHY_PERSONA_STORE_COL_IS_ONLINE, &was_online,
          -1);

      /* Is this really an update or an online/offline. */
      if (priv->show_active)
        {
          if (was_online != now_online)
            {
              do_set_active = TRUE;
              do_set_refresh = TRUE;

              DEBUG ("Set active (contact updated %s)",
                  was_online ? "online  -> offline" : "offline -> online");
            }
          else
            {
              /* Was TRUE for presence updates. */
              /* do_set_active = FALSE;  */
              do_set_refresh = TRUE;
              DEBUG ("Set active (contact updated)");
            }
        }

      /* We still need to use EmpathyContact for the capabilities stuff */
      contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
          TPF_PERSONA (persona)));
      store = folks_persona_get_store (persona);

      pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
          32, 32);
      pixbuf_status = get_persona_status_icon (self, persona);

      gtk_list_store_set (GTK_LIST_STORE (self), &iter,
          EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
          EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
          EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
          EMPATHY_PERSONA_STORE_COL_NAME, alias,
          EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
              folks_persona_store_get_display_name (store),
          EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
              folks_persona_get_display_id (persona),
          EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
              folks_presence_get_presence_type (FOLKS_PRESENCE (persona)),
          EMPATHY_PERSONA_STORE_COL_STATUS,
              folks_presence_get_presence_message (FOLKS_PRESENCE (persona)),
          EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
          EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
              empathy_contact_get_capabilities (contact) &
                EMPATHY_CAPABILITIES_AUDIO,
          EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
              empathy_contact_get_capabilities (contact) &
                EMPATHY_CAPABILITIES_VIDEO,
          -1);

      g_object_unref (contact);

      if (pixbuf_avatar)
        g_object_unref (pixbuf_avatar);
    }

  if (priv->show_active && do_set_active)
    {
      persona_set_active (self, persona, do_set_active, do_set_refresh);

      if (do_set_active)
        {
          ShowActiveData *data;

          data = persona_active_new (self, persona, FALSE);
          data->timeout = g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
              (GSourceFunc) persona_active_cb,
              data);
        }
    }

  /* FIXME: when someone goes online then offline quickly, the
   * first timeout sets the user to be inactive and the second
   * timeout removes the user from the contact list, really we
   * should remove the first timeout.
   */
}