+static void
+event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
+ EmpathyDispatchOperation *operation, EmpathyEventManager *manager)
+{
+ const gchar *channel_type;
+ EventManagerApproval *approval;
+ EmpathyEventManagerPriv *priv = GET_PRIV (manager);
+
+ channel_type = empathy_dispatch_operation_get_channel_type (operation);
+
+ approval = event_manager_approval_new (manager, operation);
+ priv->approvals = g_slist_prepend (priv->approvals, approval);
+
+ approval->approved_handler = g_signal_connect (operation, "approved",
+ G_CALLBACK (event_manager_operation_approved_cb), approval);
+
+ approval->claimed_handler = g_signal_connect (operation, "claimed",
+ G_CALLBACK (event_manager_operation_claimed_cb), approval);
+
+ approval->invalidated_handler = g_signal_connect (operation, "invalidated",
+ G_CALLBACK (event_manager_operation_invalidated_cb), approval);
+
+ if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT))
+ {
+ EmpathyTpChat *tp_chat =
+ EMPATHY_TP_CHAT (
+ empathy_dispatch_operation_get_channel_wrapper (operation));
+ TpChannel *channel = empathy_tp_chat_get_channel (tp_chat);
+
+ if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
+ {
+ /* Are we in local-pending ? */
+ TpHandle self_handle, inviter;
+
+ self_handle = tp_channel_group_get_self_handle (channel);
+
+ if (self_handle != 0 && tp_channel_group_get_local_pending_info (
+ channel, self_handle, &inviter, NULL, NULL))
+ {
+ /* We are invited to a room */
+ EmpathyTpContactFactory *factory;
+ TpConnection *connection;
+
+ DEBUG ("Have been invited to %s. Ask user if he wants to accept",
+ tp_channel_get_identifier (channel));
+
+ connection = empathy_tp_chat_get_connection (tp_chat);
+ factory = empathy_tp_contact_factory_dup_singleton (connection);
+
+ empathy_tp_contact_factory_get_from_handle (factory,
+ inviter, event_manager_muc_invite_got_contact_cb,
+ approval, NULL, G_OBJECT (manager));
+
+ g_object_unref (factory);
+ return;
+ }
+
+ /* if we are not invited, let's wait for the first message */
+ }
+
+ /* 1-1 text channel, wait for the first message */
+ approval->handler = g_signal_connect (tp_chat, "message-received",
+ G_CALLBACK (event_manager_chat_message_received_cb), approval);
+ approval->handler_instance = G_OBJECT (tp_chat);
+ }
+ else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
+ {
+ EmpathyContact *contact;
+ EmpathyTpCall *call = EMPATHY_TP_CALL (
+ empathy_dispatch_operation_get_channel_wrapper (operation));
+
+ g_object_get (G_OBJECT (call), "contact", &contact, NULL);
+
+ if (contact == NULL)
+ {
+ g_signal_connect (call, "notify::contact",
+ G_CALLBACK (event_manager_media_channel_contact_changed_cb),
+ approval);
+ }
+ else
+ {
+ approval->contact = contact;
+ event_manager_media_channel_got_contact (approval);
+ }
+
+ }
+ else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
+ {
+ EmpathyTpFile *file;
+ gchar *header;
+
+ file = EMPATHY_TP_FILE (empathy_dispatch_operation_get_channel_wrapper (operation));
+ approval->contact = g_object_ref (empathy_tp_file_get_contact (file));
+
+ header = g_strdup_printf (_("Incoming file transfer from %s"),
+ empathy_contact_get_name (approval->contact));
+
+ event_manager_add (manager, approval->contact, EMPATHY_IMAGE_DOCUMENT_SEND,
+ header, NULL, approval, event_channel_process_func, NULL);
+
+ /* FIXME better sound for incoming file transfers ?*/
+ empathy_sound_play (empathy_main_window_get (),
+ EMPATHY_SOUND_CONVERSATION_NEW);
+
+ g_free (header);
+ }
+ else if (!tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_STREAM_TUBE) ||
+ !tp_strdiff (channel_type, EMP_IFACE_CHANNEL_TYPE_DBUS_TUBE))
+ {
+ TpChannel *channel;
+ TpHandle handle;
+ TpHandleType handle_type;
+ TpConnection *connection;
+ EmpathyTpContactFactory *factory;
+
+ channel = empathy_dispatch_operation_get_channel (operation);
+ handle = tp_channel_get_handle (channel, &handle_type);
+
+ /* Only understand p2p tubes */
+ if (handle_type != TP_HANDLE_TYPE_CONTACT)
+ return;
+
+ approval->tube_dispatch = empathy_tube_dispatch_new (operation);
+ connection = tp_channel_borrow_connection (channel);
+ factory = empathy_tp_contact_factory_dup_singleton (connection);
+ empathy_tp_contact_factory_get_from_handle (factory, handle,
+ event_manager_tube_got_contact_cb, approval, NULL, G_OBJECT (manager));
+ }
+ else
+ {
+ DEBUG ("Unknown channel type, ignoring..");
+ }
+}