static void
individual_personas_changed_cb (GObject *object,
    GList *added,
    GList *removed,
    EmpathyPersonaStore *self)
{
  GList *l;

  /* Remove the old personas. */
  for (l = removed; l != NULL; l = l->next)
    remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));

  /* Add each of the new personas to the tree model */
  for (l = added; l != NULL; l = l->next)
    add_persona_and_connect (self, FOLKS_PERSONA (l->data));
}
/**
 * empathy_persona_store_set_individual:
 * @self: an #EmpathyPersonaStore
 * @individual: the new individual to display in the store, or %NULL
 *
 * Set #EmpathyPersonaStore:individual to @individual, replacing the personas
 * which were in the store with the personas belonging to @individual, or with
 * nothing if @individual is %NULL.
 */
void
empathy_persona_store_set_individual (EmpathyPersonaStore *self,
    FolksIndividual *individual)
{
  EmpathyPersonaStorePriv *priv;

  g_return_if_fail (EMPATHY_IS_PERSONA_STORE (self));
  g_return_if_fail (individual == NULL || FOLKS_IS_INDIVIDUAL (individual));

  priv = GET_PRIV (self);

  /* Remove the old individual */
  if (priv->individual != NULL)
    {
      GList *personas, *l;

      g_signal_handlers_disconnect_by_func (priv->individual,
          (GCallback) individual_personas_changed_cb, self);

      /* Disconnect from and remove all personas belonging to this individual */
      personas = folks_individual_get_personas (priv->individual);
      for (l = personas; l != NULL; l = l->next)
        remove_persona_and_disconnect (self, FOLKS_PERSONA (l->data));

      g_object_unref (priv->individual);
    }

  priv->individual = individual;

  /* Add the new individual */
  if (individual != NULL)
    {
      GList *personas, *l;

      g_object_ref (individual);

      g_signal_connect (individual, "personas-changed",
          (GCallback) individual_personas_changed_cb, self);

      /* Add pre-existing Personas */
      personas = folks_individual_get_personas (individual);
      for (l = personas; l != NULL; l = l->next)
        add_persona_and_connect (self, FOLKS_PERSONA (l->data));
    }

  g_object_notify (G_OBJECT (self), "individual");
}
Esempio n. 3
0
/* Retrieve the EmpathyContact corresponding to the first TpContact contained
 * within the given Individual. Note that this is a temporary convenience. See
 * the TODO above. */
EmpathyContact *
empathy_contact_dup_from_folks_individual (FolksIndividual *individual)
{
  GeeSet *personas;
  GeeIterator *iter;
  EmpathyContact *contact = NULL;

  g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);

  personas = folks_individual_get_personas (individual);
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (gee_iterator_next (iter) && (contact == NULL))
    {
      TpfPersona *persona = gee_iterator_get (iter);

      if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
        {
          TpContact *tp_contact;

          tp_contact = tpf_persona_get_contact (persona);
          if (tp_contact != NULL)
            {
              contact = empathy_contact_dup_from_tp_contact (tp_contact);
              empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
            }
        }
      g_clear_object (&persona);
    }
  g_clear_object (&iter);

  if (contact == NULL)
    {
      DEBUG ("Can't create an EmpathyContact for Individual %s",
          folks_individual_get_id (individual));
    }

  return contact;
}
Esempio n. 4
0
/* Look for a FolksIndividual containing @contact as one of his persona
 * and create one if needed */
FolksIndividual *
empathy_ensure_individual_from_tp_contact (TpContact *contact)
{
  TpfPersona *persona;
  FolksIndividual *individual;

  persona = tpf_persona_dup_for_contact (contact);
  if (persona == NULL)
    {
      DEBUG ("Failed to get a persona for %s",
          tp_contact_get_identifier (contact));
      return NULL;
    }

  individual = folks_persona_get_individual (FOLKS_PERSONA (persona));

  if (individual != NULL)
    g_object_ref (individual);
  else
    individual = create_individual_from_persona (FOLKS_PERSONA (persona));

  g_object_unref (persona);
  return individual;
}