+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);
+ TpHandle handle;
+ TpHandleType handle_type;
+
+ handle = tp_channel_get_handle (channel, &handle_type);
+
+ if (handle_type == TP_HANDLE_TYPE_CONTACT)
+ {
+ /* 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);
+ }
+ else if (handle_type == TP_HANDLE_TYPE_ROOM)
+ {
+ gchar *msg;
+ const gchar *invite_msg;
+ TpHandle self_handle, inviter;
+ EmpathyContactFactory *contact_factory;
+ McAccount *account;
+
+ 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, &invite_msg))
+ {
+ DEBUG ("can't handle a incoming muc to which we have not been "
+ "invited");
+
+ if (empathy_dispatch_operation_claim (approval->operation))
+ empathy_tp_chat_close (tp_chat);
+ return;
+ }
+
+ account = empathy_tp_chat_get_account (tp_chat);
+ contact_factory = empathy_contact_factory_dup_singleton ();
+
+ approval->contact = empathy_contact_factory_get_from_handle (
+ contact_factory, account, inviter);
+
+ /* We are invited to a room */
+ msg = g_strdup_printf ("%s invited you to join %s",
+ empathy_contact_get_name (approval->contact),
+ tp_channel_get_identifier (channel));
+
+ event_manager_add (approval->manager,
+ approval->contact, EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg,
+ approval, event_room_channel_process_func, NULL);
+
+ empathy_sound_play (empathy_main_window_get (),
+ EMPATHY_SOUND_CONVERSATION_NEW);
+
+ g_object_unref (contact_factory);
+ }
+ }
+ 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, EMP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
+ {
+ EmpathyContact *contact;
+ gchar *header;
+ TpHandle handle;
+ McAccount *account;
+ EmpathyContactFactory *factory;
+ TpChannel *channel = empathy_dispatch_operation_get_channel (operation);
+
+ factory = empathy_contact_factory_dup_singleton ();
+ handle = tp_channel_get_handle (channel, NULL);
+ account = empathy_channel_get_account (channel);
+
+ contact = empathy_contact_factory_get_from_handle (factory, account,
+ handle);
+
+ empathy_contact_run_until_ready (contact,
+ EMPATHY_CONTACT_READY_NAME, NULL);
+
+ header = g_strdup_printf (_("Incoming file transfer from %s"),
+ empathy_contact_get_name (contact));
+
+ event_manager_add (manager, 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_object_unref (factory);
+ g_object_unref (account);
+ 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))
+ {
+ EmpathyContact *contact;
+ TpHandle handle;
+ TpHandleType handle_type;
+ McAccount *account;
+ EmpathyContactFactory *factory;
+ EmpathyTubeDispatch *tube_dispatch;
+ TpChannel *channel;
+
+ 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;
+
+ factory = empathy_contact_factory_dup_singleton ();
+ account = empathy_channel_get_account (channel);
+
+ contact = empathy_contact_factory_get_from_handle (factory, account,
+ handle);
+
+ tube_dispatch = empathy_tube_dispatch_new (operation);
+
+ approval->contact = contact;
+ approval->tube_dispatch = tube_dispatch;
+
+ empathy_contact_call_when_ready (contact,
+ EMPATHY_CONTACT_READY_NAME, event_manager_tube_got_contact_name_cb,
+ approval, NULL, G_OBJECT (manager));
+
+ g_object_unref (factory);
+ g_object_unref (account);
+ }
+ else
+ {
+ DEBUG ("Unknown channel type, ignoring..");
+ }
+}
+
+static void
+event_pending_subscribe_func (EventPriv *event)
+{
+ empathy_subscription_dialog_show (event->public.contact, NULL);
+ event_remove (event);
+}
+
+static void
+event_manager_pendings_changed_cb (EmpathyContactList *list,
+ EmpathyContact *contact, EmpathyContact *actor,
+ guint reason, gchar *message, gboolean is_pending,
+ EmpathyEventManager *manager)