Exemple #1
0
static void
dispatch_cb (EmpathyDispatcher *dispatcher,
	     EmpathyDispatchOperation *operation,
	     gpointer           user_data)
{
	GQuark channel_type;

	channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

	if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) {
		EmpathyTpChat *tp_chat;
		EmpathyChat   *chat = NULL;
		const gchar   *id;

		tp_chat = EMPATHY_TP_CHAT (
			empathy_dispatch_operation_get_channel_wrapper (operation));

		id = empathy_tp_chat_get_id (tp_chat);
		if (!id) {
			EmpathyContact *contact;

			contact = empathy_tp_chat_get_remote_contact (tp_chat);
			if (contact) {
				id = empathy_contact_get_id (contact);
			}
		}

		if (id) {
			McAccount *account;

			account = empathy_tp_chat_get_account (tp_chat);
			chat = empathy_chat_window_find_chat (account, id);
		}

		if (chat) {
			empathy_chat_set_tp_chat (chat, tp_chat);
		} else {
			chat = empathy_chat_new (tp_chat);
		}

		empathy_chat_window_present_chat (chat);

		empathy_dispatch_operation_claim (operation);
	} else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) {
		EmpathyCallFactory *factory;

		factory = empathy_call_factory_get ();
		empathy_call_factory_claim_channel (factory, operation);
	} else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) {
		EmpathyFTManager *ft_manager;
		EmpathyTpFile    *tp_file;

		ft_manager = empathy_ft_manager_dup_singleton ();
		tp_file = EMPATHY_TP_FILE (
			empathy_dispatch_operation_get_channel_wrapper (operation));
		empathy_ft_manager_add_tp_file (ft_manager, tp_file);
		empathy_dispatch_operation_claim (operation);
	}
}
Exemple #2
0
static void
chatroom_set_property (GObject      *object,
		       guint         param_id,
		       const GValue *value,
		       GParamSpec   *pspec)
{
	EmpathyChatroomPriv *priv;

	priv = GET_PRIV (object);

	switch (param_id) {
	case PROP_ACCOUNT:
		empathy_chatroom_set_account (EMPATHY_CHATROOM (object),
					     g_value_get_object (value));
		break;
	case PROP_ROOM:
		empathy_chatroom_set_room (EMPATHY_CHATROOM (object),
					  g_value_get_string (value));
		break;
	case PROP_NAME:
		empathy_chatroom_set_name (EMPATHY_CHATROOM (object),
					  g_value_get_string (value));
		break;
	case PROP_AUTO_CONNECT:
		empathy_chatroom_set_auto_connect (EMPATHY_CHATROOM (object),
						  g_value_get_boolean (value));
		break;
  case PROP_FAVORITE:
    priv->favorite = g_value_get_boolean (value);
    if (!priv->favorite)
      {
        empathy_chatroom_set_auto_connect (EMPATHY_CHATROOM (object),
            FALSE);
      }
    break;
	case PROP_TP_CHAT: {
		GObject *chat = g_value_dup_object (value);

		if (chat == (GObject *) priv->tp_chat)
			break;

		g_assert (chat == NULL || priv->tp_chat == NULL);

		if (priv->tp_chat != NULL) {
			g_object_unref (priv->tp_chat);
			priv->tp_chat = NULL;
		} else {
			priv->tp_chat = EMPATHY_TP_CHAT (chat);
		}
		break;
	}
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
		break;
	};
}
Exemple #3
0
static void
tp_chat_got_self_contact_cb (EmpathyTpContactFactory *factory,
			     EmpathyContact          *contact,
			     const GError            *error,
			     gpointer                 user_data,
			     GObject                 *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	if (error) {
		DEBUG ("Error: %s", error->message);
		empathy_tp_chat_close (EMPATHY_TP_CHAT (chat));
		return;
	}

	priv->user = g_object_ref (contact);
	empathy_contact_set_is_user (priv->user, TRUE);
	tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
}
Exemple #4
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);
}
Exemple #5
0
static void
tp_chat_got_added_contacts_cb (EmpathyTpContactFactory *factory,
			       guint                    n_contacts,
			       EmpathyContact * const * contacts,
			       guint                    n_failed,
			       const TpHandle          *failed,
			       const GError            *error,
			       gpointer                 user_data,
			       GObject                 *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	guint i;
	const TpIntSet *members;
	TpHandle handle;
	EmpathyContact *contact;

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

	members = tp_channel_group_get_members (priv->channel);
	for (i = 0; i < n_contacts; i++) {
		contact = contacts[i];
		handle = empathy_contact_get_handle (contact);

		/* Make sure the contact is still member */
		if (tp_intset_is_member (members, handle)) {
			priv->members = g_list_prepend (priv->members,
				g_object_ref (contact));
			g_signal_emit_by_name (chat, "members-changed",
					       contact, NULL, 0, NULL, TRUE);
		}
	}

	tp_chat_update_remote_contact (EMPATHY_TP_CHAT (chat));
	tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
}
Exemple #6
0
static void
tp_chat_dispose (GObject *object)
{
	EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
	EmpathyTpChatPriv *priv = GET_PRIV (self);

	if (priv->dispose_has_run)
		return;

	priv->dispose_has_run = TRUE;

	if (priv->channel != NULL) {
		g_signal_handlers_disconnect_by_func (priv->channel,
			tp_chat_invalidated_cb, self);
		g_object_unref (priv->channel);
	}
	priv->channel = NULL;

	if (priv->remote_contact != NULL)
		g_object_unref (priv->remote_contact);
	priv->remote_contact = NULL;

	if (priv->factory != NULL)
		g_object_unref (priv->factory);
	priv->factory = NULL;

	if (priv->user != NULL)
		g_object_unref (priv->user);
	priv->user = NULL;

	if (priv->contact_monitor)
		g_object_unref (priv->contact_monitor);
	priv->contact_monitor = NULL;

	g_queue_foreach (priv->messages_queue, (GFunc) g_object_unref, NULL);
	g_queue_clear (priv->messages_queue);

	g_queue_foreach (priv->pending_messages_queue,
		(GFunc) g_object_unref, NULL);
	g_queue_clear (priv->pending_messages_queue);

	if (G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose)
		G_OBJECT_CLASS (empathy_tp_chat_parent_class)->dispose (object);
}
Exemple #7
0
static void
tp_chat_received_cb (TpChannel   *channel,
		     guint        message_id,
		     guint        timestamp,
		     guint        from_handle,
		     guint        message_type,
		     guint        message_flags,
		     const gchar *message_body,
		     gpointer     user_data,
		     GObject     *chat_)
{
	EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	if (priv->channel == NULL)
		return;

	if (priv->listing_pending_messages) {
		return;
	}

 	DEBUG ("Message received: %s", message_body);

	if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
	    !tp_strdiff (message_body, "")) {
		GArray *ids;

		DEBUG ("Empty message with NonTextContent, ignoring and acking.");

		ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
		g_array_append_val (ids, message_id);
		acknowledge_messages (chat, ids);
		g_array_free (ids, TRUE);

		return;
	}

	tp_chat_build_message (chat,
			       message_id,
			       message_type,
			       timestamp,
			       from_handle,
			       message_body);
}
Exemple #8
0
static void
tp_chat_got_sender_cb (EmpathyTpContactFactory *factory,
		       EmpathyContact          *contact,
		       const GError            *error,
		       gpointer                 message,
		       GObject                 *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	if (error) {
		DEBUG ("Error: %s", error->message);
		/* Do not block the message queue, just drop this message */
		g_queue_remove (priv->messages_queue, message);
	} else {
		empathy_message_set_sender (message, contact);
	}

	tp_chat_emit_queued_messages (EMPATHY_TP_CHAT (chat));
}
Exemple #9
0
static void
tp_chat_send_error_cb (TpChannel   *channel,
		       guint        error_code,
		       guint        timestamp,
		       guint        message_type,
		       const gchar *message_body,
		       gpointer     user_data,
		       GObject     *chat)
{
	EmpathyTpChatPriv *priv = GET_PRIV (chat);

	if (priv->channel == NULL)
		return;

	DEBUG ("Message sent error: %s (%d)", message_body, error_code);

	tp_chat_build_message (EMPATHY_TP_CHAT (chat),
			       0,
			       message_type,
			       timestamp,
			       0,
			       message_body);
}
Exemple #10
0
static void
tp_chat_list_pending_messages_cb (TpChannel       *channel,
				  const GPtrArray *messages_list,
				  const GError    *error,
				  gpointer         user_data,
				  GObject         *chat_)
{
	EmpathyTpChat     *chat = EMPATHY_TP_CHAT (chat_);
	EmpathyTpChatPriv *priv = GET_PRIV (chat);
	guint              i;
	GArray            *empty_non_text_content_ids = NULL;

	priv->listing_pending_messages = FALSE;

	if (priv->channel == NULL)
		return;

	if (error) {
		DEBUG ("Error listing pending messages: %s", error->message);
		return;
	}

	for (i = 0; i < messages_list->len; i++) {
		GValueArray    *message_struct;
		const gchar    *message_body;
		guint           message_id;
		guint           timestamp;
		guint           from_handle;
		guint           message_type;
		guint           message_flags;

		message_struct = g_ptr_array_index (messages_list, i);

		message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
		timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
		from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
		message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
		message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
		message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));

		DEBUG ("Message pending: %s", message_body);

		if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
		    !tp_strdiff (message_body, "")) {
			DEBUG ("Empty message with NonTextContent, ignoring and acking.");

			if (empty_non_text_content_ids == NULL) {
				empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
			}

			g_array_append_val (empty_non_text_content_ids, message_id);
			continue;
		}

		tp_chat_build_message (chat,
				       message_id,
				       message_type,
				       timestamp,
				       from_handle,
				       message_body);
	}

	if (empty_non_text_content_ids != NULL) {
		acknowledge_messages (chat, empty_non_text_content_ids);
		g_array_free (empty_non_text_content_ids, TRUE);
	}
}
Exemple #11
0
static void
dispatch_cb (EmpathyDispatcher *dispatcher,
    EmpathyDispatchOperation *operation,
    gpointer user_data)
{
  GQuark channel_type;

  channel_type = empathy_dispatch_operation_get_channel_type_id (operation);

  if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
    {
      EmpathyTpChat *tp_chat;
      EmpathyChat   *chat = NULL;
      const gchar   *id;

      tp_chat = EMPATHY_TP_CHAT
        (empathy_dispatch_operation_get_channel_wrapper (operation));

      id = empathy_tp_chat_get_id (tp_chat);
      if (!EMP_STR_EMPTY (id))
        {
          TpConnection *connection;
          TpAccount *account;

          connection = empathy_tp_chat_get_connection (tp_chat);
          account = empathy_get_account_for_connection (connection);
          chat = empathy_chat_window_find_chat (account, id);
        }

      if (chat)
        {
          empathy_chat_set_tp_chat (chat, tp_chat);
        }
      else
        {
          chat = empathy_chat_new (tp_chat);
          /* empathy_chat_new returns a floating reference as EmpathyChat is
           * a GtkWidget. This reference will be taken by a container
           * (a GtkNotebook) when we'll call empathy_chat_window_present_chat */
        }

      empathy_chat_window_present_chat (chat);

      empathy_dispatch_operation_claim (operation);
    }
  else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
    {
      EmpathyCallFactory *factory;

      factory = empathy_call_factory_get ();
      empathy_call_factory_claim_channel (factory, operation);
    }
  else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
    {
      EmpathyFTFactory *factory;

      factory = empathy_ft_factory_dup_singleton ();

      /* if the operation is not incoming, don't claim it,
       * as it might have been triggered by another client, and
       * we are observing it.
       */
      if (empathy_dispatch_operation_is_incoming (operation))
        empathy_ft_factory_claim_channel (factory, operation);
    }
}