Example #1
0
/* Calculate whether the Individual can do audio or video calls.
 * FIXME: We can remove this once libfolks has grown capabilities support
 * again: bgo#626179. */
void
empathy_individual_can_audio_video_call (FolksIndividual *individual,
    gboolean *can_audio_call,
    gboolean *can_video_call,
    EmpathyContact **out_contact)
{
  GeeSet *personas;
  GeeIterator *iter;
  gboolean can_audio = FALSE, can_video = FALSE;

  personas = folks_individual_get_personas (individual);
  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
  while (gee_iterator_next (iter))
    {
      FolksPersona *persona = gee_iterator_get (iter);
      TpContact *tp_contact;

      if (!empathy_folks_persona_is_interesting (persona))
        goto while_finish;

      tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
      if (tp_contact != NULL)
        {
          EmpathyContact *contact;

          contact = empathy_contact_dup_from_tp_contact (tp_contact);
          empathy_contact_set_persona (contact, persona);

          can_audio = can_audio || empathy_contact_get_capabilities (contact) &
              EMPATHY_CAPABILITIES_AUDIO;
          can_video = can_video || empathy_contact_get_capabilities (contact) &
              EMPATHY_CAPABILITIES_VIDEO;

          if (out_contact != NULL)
            *out_contact = g_object_ref (contact);

          g_object_unref (contact);
        }

while_finish:
      g_clear_object (&persona);

      if (can_audio && can_video)
        break;
    }

  g_clear_object (&iter);

  if (can_audio_call != NULL)
    *can_audio_call = can_audio;

  if (can_video_call != NULL)
    *can_video_call = can_video;
}
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_contact_capabilities (EmpathyTpContactFactory *self,
			     GHashTable *caps)
{
	GHashTableIter iter;
	gpointer key, value;

	g_hash_table_iter_init (&iter, caps);
	while (g_hash_table_iter_next (&iter, &key, &value)) {
		TpHandle handle = GPOINTER_TO_UINT (key);
		GPtrArray *classes = value;
		EmpathyContact *contact;
		EmpathyCapabilities  capabilities;

		contact = tp_contact_factory_find_by_handle (self, handle);
		if (contact == NULL)
			continue;

		capabilities = empathy_contact_get_capabilities (contact);
		capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;

		capabilities |= channel_classes_to_capabilities (classes, TRUE);

		DEBUG ("Changing capabilities for contact %s (%d) to %d",
			empathy_contact_get_id (contact),
			empathy_contact_get_handle (contact),
			capabilities);

		empathy_contact_set_capabilities (contact, capabilities);
	}
}
static void
get_requestable_channel_classes_cb (TpProxy *connection,
				    const GValue *value,
				    const GError *error,
				    gpointer user_data,
				    GObject *weak_object)
{
	EmpathyTpContactFactory     *self = EMPATHY_TP_CONTACT_FACTORY (weak_object);
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
	GPtrArray                   *classes;
	GList                       *l;
	EmpathyCapabilities         capabilities;

	if (error != NULL) {
		DEBUG ("Error: %s", error->message);
		return;
	}

	classes = g_value_get_boxed (value);

	DEBUG ("ContactCapabilities is not implemented; use RCC");
	capabilities = channel_classes_to_capabilities (classes, FALSE);
	if ((capabilities & EMPATHY_CAPABILITIES_FT) != 0) {
		DEBUG ("Assume all contacts support FT as CM implements it");
		priv->can_request_ft = TRUE;
	}

	if ((capabilities & EMPATHY_CAPABILITIES_STREAM_TUBE) != 0) {
		DEBUG ("Assume all contacts support stream tubes as CM implements them");
		priv->can_request_st = TRUE;
	}

	if (!priv->can_request_ft && !priv->can_request_st)
		return ;

	/* Update the capabilities of all contacts */
	for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
		EmpathyContact *contact = l->data;
		EmpathyCapabilities caps;

		caps = empathy_contact_get_capabilities (contact);

		/* ContactCapabilities is not supported; assume all contacts can do file
		 * transfer if it's implemented in the CM */
		if (priv->can_request_ft)
			caps |= EMPATHY_CAPABILITIES_FT;

		if (priv->can_request_st)
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;

		empathy_contact_set_capabilities (contact, caps);
	}
}
static void
tp_contact_factory_update_capabilities (EmpathyTpContactFactory *tp_factory,
					guint                    handle,
					const gchar             *channel_type,
					guint                    generic,
					guint                    specific)
{
	EmpathyContact      *contact;
	EmpathyCapabilities  capabilities;

	contact = tp_contact_factory_find_by_handle (tp_factory, handle);
	if (!contact) {
		return;
	}

	capabilities = empathy_contact_get_capabilities (contact);
	capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;

	if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) == 0) {
		capabilities &= ~EMPATHY_CAPABILITIES_AUDIO;
		capabilities &= ~EMPATHY_CAPABILITIES_VIDEO;
		if (specific & TP_CHANNEL_MEDIA_CAPABILITY_AUDIO) {
			capabilities |= EMPATHY_CAPABILITIES_AUDIO;
		}
		if (specific & TP_CHANNEL_MEDIA_CAPABILITY_VIDEO) {
			capabilities |= EMPATHY_CAPABILITIES_VIDEO;
		}
	}

	DEBUG ("Changing capabilities for contact %s (%d) to %d",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact),
		capabilities);

	empathy_contact_set_capabilities (contact, capabilities);
}
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.
   */
}
static void
tp_contact_factory_add_contact (EmpathyTpContactFactory *tp_factory,
				EmpathyContact          *contact)
{
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
	TpHandle self_handle;
	TpHandle handle;
	GArray handles = {(gchar *) &handle, 1};
	EmpathyCapabilities caps;

	/* Keep a weak ref to that contact */
	g_object_weak_ref (G_OBJECT (contact),
			   tp_contact_factory_weak_notify,
			   tp_factory);
	priv->contacts = g_list_prepend (priv->contacts, contact);

	/* The contact keeps a ref to its factory */
	g_object_set_data_full (G_OBJECT (contact), "empathy-factory",
				g_object_ref (tp_factory),
				g_object_unref);

	caps = empathy_contact_get_capabilities (contact);

	/* Set the FT capability */
	if (!priv->contact_caps_supported) {
		/* ContactCapabilities is not supported; assume all contacts can do file
		 * transfer if it's implemented in the CM */
		if (priv->can_request_ft) {
			caps |= EMPATHY_CAPABILITIES_FT;
		}

		/* Set the Stream Tube capability */
		if (priv->can_request_st) {
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;
		}
	}

	empathy_contact_set_capabilities (contact, caps);

	/* Set is-user property. Note that it could still be the handle is
	 * different from the connection's self handle, in the case the handle
	 * comes from a group interface. */
	self_handle = tp_connection_get_self_handle (priv->connection);
	handle = empathy_contact_get_handle (contact);
	empathy_contact_set_is_user (contact, self_handle == handle);

	/* FIXME: This should be done by TpContact */
	if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS)) {
		tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (
			priv->connection, -1, &handles,
			tp_contact_factory_got_known_avatar_tokens, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	if (priv->contact_caps_supported) {
		tp_cli_connection_interface_contact_capabilities_call_get_contact_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_contact_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}
	else if (tp_proxy_has_interface_by_id (priv->connection,
			TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES)) {
		tp_cli_connection_interface_capabilities_call_get_capabilities (
			priv->connection, -1, &handles,
			tp_contact_factory_got_capabilities, NULL, NULL,
			G_OBJECT (tp_factory));
	}

	DEBUG ("Contact added: %s (%d)",
		empathy_contact_get_id (contact),
		empathy_contact_get_handle (contact));
}
static void
get_requestable_channel_classes_cb (TpProxy *connection,
				    const GValue *value,
				    const GError *error,
				    gpointer user_data,
				    GObject *weak_object)
{
	EmpathyTpContactFactory     *self = EMPATHY_TP_CONTACT_FACTORY (weak_object);
	EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
	GPtrArray                   *classes;
	guint                        i;
	GList                       *l;

	if (error != NULL) {
		DEBUG ("Error: %s", error->message);
		return;
	}

	classes = g_value_get_boxed (value);
	for (i = 0; i < classes->len; i++) {
		GValueArray *class_struct;
		GHashTable *fixed_prop;
		GValue *chan_type, *handle_type;

		class_struct = g_ptr_array_index (classes, i);
		fixed_prop = g_value_get_boxed (g_value_array_get_nth (class_struct, 0));

		handle_type = g_hash_table_lookup (fixed_prop,
			TP_IFACE_CHANNEL ".TargetHandleType");
		if (handle_type == NULL ||
		    g_value_get_uint (handle_type) != TP_HANDLE_TYPE_CONTACT)
			continue;

		chan_type = g_hash_table_lookup (fixed_prop,
			TP_IFACE_CHANNEL ".ChannelType");
		if (chan_type == NULL)
			continue;

		if (!tp_strdiff (g_value_get_string (chan_type),
		    TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
			priv->can_request_ft = TRUE;
		else if (!tp_strdiff (g_value_get_string (chan_type),
		         TP_IFACE_CHANNEL_TYPE_STREAM_TUBE))
			priv->can_request_st = TRUE;
	}

	if (!priv->can_request_ft && !priv->can_request_st)
		return ;

	/* Update the capabilities of all contacts */
	for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
		EmpathyContact *contact = l->data;
		EmpathyCapabilities caps;

		caps = empathy_contact_get_capabilities (contact);

		if (priv->can_request_ft)
			caps |= EMPATHY_CAPABILITIES_FT;

		if (priv->can_request_st)
			caps |= EMPATHY_CAPABILITIES_STREAM_TUBE;

		empathy_contact_set_capabilities (contact, caps);
	}
}
static void
contact_list_store_contact_update (EmpathyContactListStore *store,
				   EmpathyContact          *contact)
{
	EmpathyContactListStorePriv *priv;
	ShowActiveData             *data;
	GtkTreeModel               *model;
	GList                      *iters, *l;
	gboolean                    in_list;
	gboolean                    should_be_in_list;
	gboolean                    was_online = TRUE;
	gboolean                    now_online = FALSE;
	gboolean                    set_model = FALSE;
	gboolean                    do_remove = FALSE;
	gboolean                    do_set_active = FALSE;
	gboolean                    do_set_refresh = FALSE;
	gboolean                    show_avatar = FALSE;
	GdkPixbuf                  *pixbuf_avatar;

	priv = GET_PRIV (store);

	model = GTK_TREE_MODEL (store);

	iters = contact_list_store_find_contact (store, contact);
	if (!iters) {
		in_list = FALSE;
	} else {
		in_list = TRUE;
	}

	/* Get online state now. */
	now_online = empathy_contact_is_online (contact);

	if (priv->show_offline || now_online) {
		should_be_in_list = TRUE;
	} else {
		should_be_in_list = FALSE;
	}

	if (!in_list && !should_be_in_list) {
		/* Nothing to do. */
		DEBUG ("Contact:'%s' in list:NO, should be:NO",
			empathy_contact_get_name (contact));

		g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
		g_list_free (iters);
		return;
	}
	else if (in_list && !should_be_in_list) {
		DEBUG ("Contact:'%s' in list:YES, should be:NO",
			empathy_contact_get_name (contact));

		if (priv->show_active) {
			do_remove = TRUE;
			do_set_active = TRUE;
			do_set_refresh = TRUE;

			set_model = TRUE;
			DEBUG ("Remove item (after timeout)");
		} else {
			DEBUG ("Remove item (now)!");
			contact_list_store_remove_contact (store, contact);
		}
	}
	else if (!in_list && should_be_in_list) {
		DEBUG ("Contact:'%s' in list:NO, should be:YES",
			empathy_contact_get_name (contact));

		contact_list_store_add_contact (store, contact);

		if (priv->show_active) {
			do_set_active = TRUE;

			DEBUG ("Set active (contact added)");
		}
	} else {
		DEBUG ("Contact:'%s' in list:YES, should be:YES",
			empathy_contact_get_name (contact));

		/* Get online state before. */
		if (iters && g_list_length (iters) > 0) {
			gtk_tree_model_get (model, iters->data,
					    EMPATHY_CONTACT_LIST_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)");
			}
		}

		set_model = TRUE;
	}

	if (priv->show_avatars && !priv->is_compact) {
		show_avatar = TRUE;
	}
	pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
	for (l = iters; l && set_model; l = l->next) {
		gtk_tree_store_set (GTK_TREE_STORE (store), l->data,
				    EMPATHY_CONTACT_LIST_STORE_COL_ICON_STATUS, empathy_icon_name_for_contact (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
				    EMPATHY_CONTACT_LIST_STORE_COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_STATUS, empathy_contact_get_status (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, !priv->is_compact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, now_online,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    -1);
	}

	if (pixbuf_avatar) {
		g_object_unref (pixbuf_avatar);
	}

	if (priv->show_active && do_set_active) {
		contact_list_store_contact_set_active (store, contact, do_set_active, do_set_refresh);

		if (do_set_active) {
			data = contact_list_store_contact_active_new (store, contact, do_remove);
			g_timeout_add_seconds (ACTIVE_USER_SHOW_TIME,
					       (GSourceFunc) contact_list_store_contact_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.
	 */
	g_list_foreach (iters, (GFunc) gtk_tree_iter_free, NULL);
	g_list_free (iters);
}
static void
contact_list_store_add_contact (EmpathyContactListStore *store,
				EmpathyContact          *contact)
{
	EmpathyContactListStorePriv *priv;
	GtkTreeIter                 iter;
	GList                      *groups = NULL, *l;

	priv = GET_PRIV (store);
	
	if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
	    (!priv->show_offline && !empathy_contact_is_online (contact))) {
		return;
	}

	if (priv->show_groups) {
		groups = empathy_contact_list_get_groups (priv->list, contact);
	}

	/* If no groups just add it at the top level. */
	if (!groups) {
		gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    -1);
	}

	/* Else add to each group. */
	for (l = groups; l; l = l->next) {
		GtkTreeIter iter_group;

		contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);

		gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
					     &iter_group, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    -1);
		g_free (l->data);
	}
	g_list_free (groups);

	contact_list_store_contact_update (store, contact);

}
Example #11
0
static void
contact_list_store_add_contact (EmpathyContactListStore *store,
				EmpathyContact          *contact)
{
	EmpathyContactListStorePriv *priv;
	GtkTreeIter                 iter;
	GList                      *groups = NULL, *l;
	TpConnection               *connection;
	EmpathyContactListFlags     flags = 0;

	priv = GET_PRIV (store);

	if (EMP_STR_EMPTY (empathy_contact_get_name (contact)) ||
	    (!priv->show_offline && !empathy_contact_is_online (contact))) {
		return;
	}

	if (priv->show_groups) {
		groups = empathy_contact_list_get_groups (priv->list, contact);
	}

	connection = empathy_contact_get_connection (contact);
	if (EMPATHY_IS_CONTACT_MANAGER (priv->list)) {
		flags = empathy_contact_manager_get_flags_for_connection (
			EMPATHY_CONTACT_MANAGER (priv->list), connection);
	}
	/* If no groups just add it at the top level. */
	if (!groups) {
		GtkTreeModel *model = GTK_TREE_MODEL (store);

		if (gtk_tree_model_get_iter_first (model, &iter)) do {
			EmpathyContact *c;

			gtk_tree_model_get (model, &iter,
				EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &c,
				-1);

			if (c == contact) {
				g_object_unref (c);
				return;
			}
			if (c != NULL)
				g_object_unref (c);
		} while (gtk_tree_model_iter_next (model, &iter));

		gtk_tree_store_append (GTK_TREE_STORE (store), &iter, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
	}

	/* Else add to each group. */
	for (l = groups; l; l = l->next) {
		GtkTreeIter iter_group;

		contact_list_store_get_group (store, l->data, &iter_group, NULL, NULL);

		gtk_tree_store_insert_after (GTK_TREE_STORE (store), &iter,
					     &iter_group, NULL);
		gtk_tree_store_set (GTK_TREE_STORE (store), &iter,
				    EMPATHY_CONTACT_LIST_STORE_COL_NAME, empathy_contact_get_name (contact),
				    EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, contact,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_IS_SEPARATOR, FALSE,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_AUDIO,
				    EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL,
				      empathy_contact_get_capabilities (contact) &
				        EMPATHY_CAPABILITIES_VIDEO,
				    EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, flags,
				    -1);
		g_free (l->data);
	}
	g_list_free (groups);

	contact_list_store_contact_update (store, contact);

}