Example #1
0
int
polari_room_compare (PolariRoom *room,
                     PolariRoom *other)
{
  TpAccount *account1, *account2;
  TpHandleType type1, type2;
  TpConnection *conn;

  g_return_val_if_fail (POLARI_IS_ROOM (room) && POLARI_IS_ROOM (other), 0);
  g_return_val_if_fail (room->priv->channel && other->priv->channel, 0);

  conn = tp_channel_get_connection (room->priv->channel);
  account1 = tp_connection_get_account (conn);

  conn = tp_channel_get_connection (other->priv->channel);
  account2 = tp_connection_get_account (conn);

  if (account1 != account2)
    return strcmp (tp_account_get_display_name (account1),
                   tp_account_get_display_name (account2));

  tp_channel_get_handle (room->priv->channel, &type1);
  tp_channel_get_handle (other->priv->channel, &type2);

  if (type1 != type2)
    return type1 == TP_HANDLE_TYPE_ROOM ? -1 : 1;

  return strcmp (room->priv->display_name, other->priv->display_name);
}
static void remmina_tp_channel_handler_channel_ready(TpChannel *channel, const GError *channel_error, gpointer user_data)
{
	RemminaTpChannelHandler *chandler = (RemminaTpChannelHandler *) user_data;
	TpHandle handle;
	GError *error = NULL;
	TpContactFeature features[] =
	{ TP_CONTACT_FEATURE_ALIAS, TP_CONTACT_FEATURE_AVATAR_TOKEN };

	if (channel_error != NULL)
	{
		g_print("remmina_tp_channel_handler_channel_ready: %s\n", channel_error->message);
		remmina_tp_channel_handler_free(chandler);
		return;
	}

	if (tp_cli_channel_connect_to_closed(channel, remmina_tp_channel_handler_channel_closed, chandler, NULL, NULL, &error)
			== NULL)
	{
		g_print("tp_cli_channel_connect_to_closed: %s\n", channel_error->message);
		remmina_tp_channel_handler_free(chandler);
		return;
	}
	g_print("remmina_tp_channel_handler_channel_ready: %s\n", chandler->channel_path);

	handle = tp_channel_get_handle(channel, NULL);
	tp_connection_get_contacts_by_handle(chandler->connection, 1, &handle, G_N_ELEMENTS(features), features,
			remmina_tp_channel_handler_get_contacts, chandler, NULL, NULL);
}
Example #3
0
static void
chatroom_manager_observe_channel_cb (EmpathyDispatcher *dispatcher,
  EmpathyDispatchOperation *operation, gpointer manager)
{
  EmpathyChatroomManagerPriv *priv = GET_PRIV (manager);
  EmpathyChatroom *chatroom;
  TpChannel *channel;
  EmpathyTpChat *chat;
  const gchar *roomname;
  GQuark channel_type;
  TpHandleType handle_type;
  EmpathyAccount *account;
  TpConnection *connection;

  channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

  /* Observe Text channels to rooms only */
  if (channel_type != TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
    return;

  channel = empathy_dispatch_operation_get_channel (operation);
  tp_channel_get_handle (channel, &handle_type);

  if (handle_type != TP_HANDLE_TYPE_ROOM)
    return;

  chat = EMPATHY_TP_CHAT (
    empathy_dispatch_operation_get_channel_wrapper (operation));
  connection = empathy_tp_chat_get_connection (chat);
  account = empathy_account_manager_get_account_for_connection (
      priv->account_manager, connection);

  roomname = empathy_tp_chat_get_id (chat);

  chatroom = empathy_chatroom_manager_find (manager, account, roomname);

  if (chatroom == NULL)
    {
      chatroom = empathy_chatroom_new_full (account, roomname, roomname,
        FALSE);
      empathy_chatroom_set_tp_chat (chatroom, chat);
      empathy_chatroom_manager_add (manager, chatroom);
      g_object_unref (chatroom);
    }
  else
    {
        empathy_chatroom_set_tp_chat (chatroom, chat);
    }

  /* A TpChat is always destroyed as it only gets unreffed after the channel
   * has been invalidated in the dispatcher..  */
  g_signal_connect (chat, "destroy",
    G_CALLBACK (chatroom_manager_chat_destroyed_cb),
    manager);
}
Example #4
0
static void
tp_chat_update_remote_contact (EmpathyTpChat *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	EmpathyContact *contact = NULL;
	TpHandle self_handle;
	TpHandleType handle_type;
	GList *l;

	/* If this is a named chatroom, never pretend it is a private chat */
	tp_channel_get_handle (priv->channel, &handle_type);
	if (handle_type == TP_HANDLE_TYPE_ROOM) {
		return;
	}

	/* This is an MSN-like chat where anyone can join the chat at anytime.
	 * If there is only one non-self contact member, we are in a private
	 * chat and we set the "remote-contact" property to that contact. If
	 * there are more, set the "remote-contact" property to NULL and the
	 * UI will display a contact list. */
	self_handle = tp_channel_group_get_self_handle (priv->channel);
	for (l = priv->members; l; l = l->next) {
		/* Skip self contact if member */
		if (empathy_contact_get_handle (l->data) == self_handle) {
			continue;
		}

		/* We have more than one remote contact, break */
		if (contact != NULL) {
			contact = NULL;
			break;
		}

		/* If we didn't find yet a remote contact, keep this one */
		contact = l->data;
	}

	if (priv->remote_contact == contact) {
		return;
	}

	DEBUG ("Changing remote contact from %p to %p",
		priv->remote_contact, contact);

	if (priv->remote_contact) {
		g_object_unref (priv->remote_contact);
	}

	priv->remote_contact = contact ? g_object_ref (contact) : NULL;
	g_object_notify (G_OBJECT (chat), "remote-contact");
}
static void
channel_get_all_properties_cb (TpProxy *proxy,
    GHashTable *properties,
    const GError *error,
    gpointer user_data,
    GObject *weak_object)
{
  CallbacksData *cb_data = user_data;
  EmpathyFTHandler *handler = EMPATHY_FT_HANDLER (weak_object);
  EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
  TpHandle c_handle;

  if (error != NULL)
    {
      if (!g_cancellable_is_cancelled (priv->cancellable))
        g_cancellable_cancel (priv->cancellable);

      cb_data->callback (handler, (GError *) error, cb_data->user_data);

      callbacks_data_free (cb_data);
      return;
    }

  priv->total_bytes = g_value_get_uint64 (
      g_hash_table_lookup (properties, "Size"));

  priv->transferred_bytes = g_value_get_uint64 (
      g_hash_table_lookup (properties, "TransferredBytes"));

  priv->filename = g_value_dup_string (
      g_hash_table_lookup (properties, "Filename"));

  priv->content_hash = g_value_dup_string (
      g_hash_table_lookup (properties, "ContentHash"));

  priv->content_hash_type = g_value_get_uint (
      g_hash_table_lookup (properties, "ContentHashType"));

  priv->content_type = g_value_dup_string (
      g_hash_table_lookup (properties, "ContentType"));

  priv->description = g_value_dup_string (
      g_hash_table_lookup (properties, "Description"));

  c_handle = tp_channel_get_handle (TP_CHANNEL (proxy), NULL);
  empathy_tp_contact_factory_get_from_handle (
      tp_channel_borrow_connection (TP_CHANNEL (proxy)), c_handle,
      contact_factory_contact_cb, cb_data, callbacks_data_free,
      G_OBJECT (handler));
}
static void
display_reject_notification (EmpathyCallObserver *self,
    TpChannel *channel)
{
  TpHandle handle;
  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
      TP_CONTACT_FEATURE_AVATAR_DATA };

  handle = tp_channel_get_handle (channel, NULL);

  tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (channel),
      1, &handle, G_N_ELEMENTS (features), features, get_contact_cb,
      g_object_ref (channel), g_object_unref, G_OBJECT (self));
}
static GObject *
tp_streamed_media_constructor (GType type,
                     guint n_construct_params,
                     GObjectConstructParam *construct_params)
{
  GObject *object;
  EmpathyTpStreamedMedia *call;
  EmpathyTpStreamedMediaPriv *priv;

  object = G_OBJECT_CLASS (empathy_tp_streamed_media_parent_class)->constructor (type,
      n_construct_params, construct_params);

  call = EMPATHY_TP_STREAMED_MEDIA (object);
  priv = GET_PRIV (call);

  /* Setup streamed media channel */
  g_signal_connect (priv->channel, "invalidated",
      G_CALLBACK (tp_streamed_media_channel_invalidated_cb), call);
  tp_cli_channel_type_streamed_media_connect_to_stream_added (priv->channel,
      tp_streamed_media_stream_added_cb, NULL, NULL, G_OBJECT (call), NULL);
  tp_cli_channel_type_streamed_media_connect_to_stream_removed (priv->channel,
      tp_streamed_media_stream_removed_cb, NULL, NULL, G_OBJECT (call), NULL);
  tp_cli_channel_type_streamed_media_connect_to_stream_state_changed (priv->channel,
      tp_streamed_media_stream_state_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
  tp_cli_channel_type_streamed_media_connect_to_stream_direction_changed (priv->channel,
      tp_streamed_media_stream_direction_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
  tp_cli_channel_type_streamed_media_connect_to_stream_error (priv->channel,
      tp_streamed_media_stream_error_cb, NULL, NULL, G_OBJECT (call), NULL);
  tp_cli_channel_type_streamed_media_call_list_streams (priv->channel, -1,
      tp_streamed_media_request_streams_cb, NULL, NULL, G_OBJECT (call));

  /* Is the call incoming? */
  priv->is_incoming = !tp_channel_get_requested (priv->channel);

  /* Get the remote contact */
  empathy_tp_contact_factory_get_from_handle (
      tp_channel_borrow_connection (priv->channel),
      tp_channel_get_handle (priv->channel, NULL), tp_streamed_media_got_contact_cb,
      NULL, NULL, object);

  /* Update status when members changes */
  tp_streamed_media_update_status (call);
  tp_g_signal_connect_object (priv->channel, "group-members-changed",
      G_CALLBACK (tp_streamed_media_update_status), call, G_CONNECT_SWAPPED);

  return object;
}
static gboolean
can_identify_contact (TpStreamTubeChannel *self)
{
  TpHandleType handle_type;

  tp_channel_get_handle (TP_CHANNEL (self), &handle_type);

  /* With contact stream tube, it's always the same contact connecting to the
   * tube */
  if (handle_type == TP_HANDLE_TYPE_CONTACT)
    return TRUE;

  /* Room stream tube, we need either the Credentials or Port access control
   * to properly identify connections. */
  if (self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_CREDENTIALS ||
      self->priv->access_control == TP_SOCKET_ACCESS_CONTROL_PORT)
    return TRUE;

  return FALSE;
}
static void
mex_telepathy_channel_initialize_channel (MexTelepathyChannel *self)
{
  MexTelepathyChannelPrivate *priv = self->priv;

  GstBus *bus;
  GstElement *pipeline;
  GstStateChangeReturn ret;
  gboolean ready;

  TpHandle contactHandle = tp_channel_get_handle (priv->channel, NULL);
  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
                                  TP_CONTACT_FEATURE_AVATAR_DATA,
                                  TP_CONTACT_FEATURE_AVATAR_TOKEN};

  MEX_INFO ("New channel");

  if (contactHandle)
    tp_connection_get_contacts_by_handle (
      priv->connection, 1, &contactHandle, 1,
      features,
      mex_telepathy_channel_on_contact_fetched,
      self, NULL, NULL);

  pipeline = gst_pipeline_new (NULL);

  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);

  if (ret == GST_STATE_CHANGE_FAILURE)
    {
      tp_channel_close_async (TP_CHANNEL (priv->channel), NULL, NULL);
      g_object_unref (pipeline);
      MEX_WARNING ("Failed to start an empty pipeline !?");
      return;
    }

  priv->pipeline = pipeline;

  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  priv->buswatch = gst_bus_add_watch (bus, mex_telepathy_channel_on_bus_watch,
                                      self);
  g_object_unref (bus);

  tf_channel_new_async (priv->channel, mex_telepathy_channel_new_tf_channel,
                        self);

  tpy_cli_channel_type_call_call_accept (TP_PROXY (priv->channel), -1,
                                         NULL, NULL, NULL, NULL);

  priv->channel = g_object_ref (priv->channel);
  g_signal_connect (priv->channel, "notify::ready",
                    G_CALLBACK (mex_telepathy_channel_on_ready),
                    self);
  g_signal_connect (priv->channel, "invalidated",
                    G_CALLBACK (mex_telepathy_channel_on_proxy_invalidated),
                    self);

  g_signal_connect (TPY_CALL_CHANNEL (priv->channel), "state-changed",
                    G_CALLBACK (mex_telepathy_channel_on_call_state_changed),
                    self);

  g_object_get (priv->channel, "ready", &ready, NULL);
  if (ready)
    mex_telepathy_channel_on_ready (TPY_CALL_CHANNEL (priv->channel), NULL, self);
}
Example #10
0
static GObject *
tp_chat_constructor (GType                  type,
		     guint                  n_props,
		     GObjectConstructParam *props)
{
	GObject           *chat;
	EmpathyTpChatPriv *priv;
	TpConnection      *connection;
	TpHandle           handle;

	chat = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);

	priv = GET_PRIV (chat);

	connection = tp_channel_borrow_connection (priv->channel);
	priv->factory = empathy_tp_contact_factory_dup_singleton (connection);
	g_signal_connect (priv->channel, "invalidated",
			  G_CALLBACK (tp_chat_invalidated_cb),
			  chat);

	if (tp_proxy_has_interface_by_id (priv->channel,
					  TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
		const TpIntSet *members;
		GArray *handles;

		/* Get self contact from the group's self handle */
		handle = tp_channel_group_get_self_handle (priv->channel);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_self_contact_cb,
			NULL, NULL, chat);

		/* Get initial member contacts */
		members = tp_channel_group_get_members (priv->channel);
		handles = tp_intset_to_array (members);
		empathy_tp_contact_factory_get_from_handles (priv->factory,
			handles->len, (TpHandle *) handles->data,
			tp_chat_got_added_contacts_cb, NULL, NULL, chat);

		g_signal_connect (priv->channel, "group-members-changed",
			G_CALLBACK (tp_chat_group_members_changed_cb), chat);
	} else {
		/* Get the self contact from the connection's self handle */
		handle = tp_connection_get_self_handle (connection);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_self_contact_cb,
			NULL, NULL, chat);

		/* Get the remote contact */
		handle = tp_channel_get_handle (priv->channel, NULL);
		empathy_tp_contact_factory_get_from_handle (priv->factory,
			handle, tp_chat_got_remote_contact_cb,
			NULL, NULL, chat);
	}

	if (tp_proxy_has_interface_by_id (priv->channel,
					  TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
		tp_cli_properties_interface_call_list_properties (priv->channel, -1,
								  tp_chat_list_properties_cb,
								  NULL, NULL,
								  G_OBJECT (chat));
		tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
									   tp_chat_properties_changed_cb,
									   NULL, NULL,
									   G_OBJECT (chat), NULL);
		tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
									       tp_chat_property_flags_changed_cb,
									       NULL, NULL,
									       G_OBJECT (chat), NULL);
	}

	return chat;
}
static void
_new_remote_connection (TpChannel *channel,
    guint handle,
    const GValue *param,
    guint connection_id,
    gpointer user_data,
    GObject *obj)
{
  TpStreamTubeChannel *self = (TpStreamTubeChannel *) obj;
  GSList *l;
  ConnWaitingSig *found_conn = NULL;
  SigWaitingConn *sig;
  TpHandle chan_handle;
  TpHandleType handle_type;
  gboolean rejected = FALSE;

  chan_handle = tp_channel_get_handle (channel, &handle_type);
  if (handle_type == TP_HANDLE_TYPE_CONTACT &&
      handle != chan_handle)
    {
      DEBUG ("CM claimed that handle %u connected to the stream tube, "
          "but as a contact stream tube we should only get connection from "
          "handle %u", handle, chan_handle);

      rejected = TRUE;
    }

  sig = sig_waiting_conn_new (handle, param, connection_id, rejected);

  for (l = self->priv->conn_waiting_sig; l != NULL && found_conn == NULL;
      l = g_slist_next (l))
    {
      ConnWaitingSig *conn = l->data;

      if (sig_match_conn (self, sig, conn))
        found_conn = conn;

    }

  if (found_conn == NULL)
    {
      DEBUG ("Didn't find any connection for %u. Waiting for more",
          connection_id);

      /* Pass ownership of sig to the list */
      self->priv->sig_waiting_conn = g_slist_append (
          self->priv->sig_waiting_conn, sig);
      return;
    }

  /* We found a connection */
  self->priv->conn_waiting_sig = g_slist_remove (
      self->priv->conn_waiting_sig, found_conn);

  if (rejected)
    connection_rejected (self, found_conn->conn, handle, connection_id);
  else
    connection_identified (self, found_conn->conn, handle, connection_id);

  sig_waiting_conn_free (sig);
  conn_waiting_sig_free (found_conn);
}