diff options
-rw-r--r-- | libempathy/empathy-dispatch-operation.c | 50 | ||||
-rw-r--r-- | libempathy/empathy-dispatch-operation.h | 4 | ||||
-rw-r--r-- | libempathy/empathy-dispatcher.c | 53 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.c | 5 | ||||
-rw-r--r-- | libempathy/empathy-tp-chat.h | 3 | ||||
-rw-r--r-- | src/empathy-event-manager.c | 383 | ||||
-rw-r--r-- | src/empathy.c | 2 |
7 files changed, 279 insertions, 221 deletions
diff --git a/libempathy/empathy-dispatch-operation.c b/libempathy/empathy-dispatch-operation.c index 78438125b..68777a50e 100644 --- a/libempathy/empathy-dispatch-operation.c +++ b/libempathy/empathy-dispatch-operation.c @@ -51,8 +51,6 @@ enum { /* Ready for dispatching */ READY, - /* Approved by an approver, can only happens on incoming operations */ - APPROVED, /* Claimed by a handler */ CLAIMED, /* Error, channel went away, inspecting it failed etc */ @@ -87,7 +85,6 @@ struct _EmpathyDispatchOperationPriv EmpathyDispatchOperationState status; gboolean incoming; gint64 user_action_time; - gboolean approved; gulong invalidated_handler; gulong ready_handler; }; @@ -295,14 +292,6 @@ empathy_dispatch_operation_class_init ( g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals[APPROVED] = g_signal_new ("approved", - G_OBJECT_CLASS_TYPE(empathy_dispatch_operation_class), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - signals[CLAIMED] = g_signal_new ("claimed", G_OBJECT_CLASS_TYPE(empathy_dispatch_operation_class), G_SIGNAL_RUN_LAST, @@ -567,47 +556,10 @@ empathy_dispatch_operation_start (EmpathyDispatchOperation *operation) g_return_if_fail ( priv->status == EMPATHY_DISPATCHER_OPERATION_STATE_PENDING); - if (priv->incoming && !priv->approved) - empathy_dispatch_operation_set_status (operation, - EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING); - else - empathy_dispatch_operation_set_status (operation, + empathy_dispatch_operation_set_status (operation, EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING); } -void -empathy_dispatch_operation_approve (EmpathyDispatchOperation *operation) -{ - EmpathyDispatchOperationPriv *priv; - - g_return_if_fail (EMPATHY_IS_DISPATCH_OPERATION (operation)); - - priv = GET_PRIV (operation); - - if (priv->status == EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING) - { - DEBUG ("Approving operation %s", - empathy_dispatch_operation_get_object_path (operation)); - - empathy_dispatch_operation_set_status (operation, - EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING); - - g_signal_emit (operation, signals[APPROVED], 0); - } - else if (priv->status < EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING) - { - DEBUG ("Pre-approving operation %s", - empathy_dispatch_operation_get_object_path (operation)); - priv->approved = TRUE; - } - else - { - DEBUG ( - "Ignoring approval for %s as it's already past the approval stage", - empathy_dispatch_operation_get_object_path (operation)); - } -} - /* Returns whether or not the operation was successfully claimed */ gboolean empathy_dispatch_operation_claim (EmpathyDispatchOperation *operation) diff --git a/libempathy/empathy-dispatch-operation.h b/libempathy/empathy-dispatch-operation.h index f199be521..b7614234f 100644 --- a/libempathy/empathy-dispatch-operation.h +++ b/libempathy/empathy-dispatch-operation.h @@ -45,8 +45,6 @@ typedef enum { EMPATHY_DISPATCHER_OPERATION_STATE_PREPARING = 0, /* Information gathered ready to be dispatched */ EMPATHY_DISPATCHER_OPERATION_STATE_PENDING, - /* Send to approving bits for approval */ - EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING, /* Send to handlers for dispatching */ EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING, /* somebody claimed the channel */ @@ -89,8 +87,6 @@ EmpathyDispatchOperation *empathy_dispatch_operation_new_with_wrapper ( * channels and DISPATCHING for outgoing ones */ void empathy_dispatch_operation_start (EmpathyDispatchOperation *operation); -void empathy_dispatch_operation_approve (EmpathyDispatchOperation *operation); - /* Returns whether or not the operation was successfully claimed */ gboolean empathy_dispatch_operation_claim (EmpathyDispatchOperation *operation); diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c index c8943c9df..ce234e452 100644 --- a/libempathy/empathy-dispatcher.c +++ b/libempathy/empathy-dispatcher.c @@ -110,7 +110,6 @@ enum enum { OBSERVE, - APPROVE, DISPATCH, LAST_SIGNAL }; @@ -431,16 +430,6 @@ dispatcher_channel_invalidated_cb (TpProxy *proxy, } static void -dispatch_operation_approved_cb (EmpathyDispatchOperation *operation, - EmpathyDispatcher *self) -{ - g_assert (empathy_dispatch_operation_is_incoming (operation)); - DEBUG ("Send of for dispatching: %s", - empathy_dispatch_operation_get_object_path (operation)); - g_signal_emit (self, signals[DISPATCH], 0, operation); -} - -static void dispatch_operation_claimed_cb (EmpathyDispatchOperation *operation, EmpathyDispatcher *self) { @@ -480,9 +469,6 @@ dispatch_operation_ready_cb (EmpathyDispatchOperation *operation, ConnectionData *cd; EmpathyDispatchOperationState status; - g_signal_connect (operation, "approved", - G_CALLBACK (dispatch_operation_approved_cb), self); - g_signal_connect (operation, "claimed", G_CALLBACK (dispatch_operation_claimed_cb), self); @@ -508,19 +494,10 @@ dispatch_operation_ready_cb (EmpathyDispatchOperation *operation, if (status == EMPATHY_DISPATCHER_OPERATION_STATE_CLAIMED) return; - if (status == EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING) - { - DEBUG ("Send to approvers: %s", - empathy_dispatch_operation_get_object_path (operation)); - g_signal_emit (self, signals[APPROVE], 0, operation); - } - else - { - g_assert (status == EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING); - DEBUG ("Send of for dispatching: %s", - empathy_dispatch_operation_get_object_path (operation)); - g_signal_emit (self, signals[DISPATCH], 0, operation); - } + g_assert (status == EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING); + DEBUG ("Send of for dispatching: %s", + empathy_dispatch_operation_get_object_path (operation)); + g_signal_emit (self, signals[DISPATCH], 0, operation); g_object_unref (self); } @@ -608,15 +585,6 @@ dispatcher_connection_new_channel (EmpathyDispatcher *self, DEBUG ("%s channel of type %s on %s", incoming ? "incoming" : "outgoing", channel_type, object_path); - if ((operation = g_hash_table_lookup (cd->dispatching_channels, - object_path)) != NULL) - { - /* This operation was already being dispatched, assume we got the channel - * again because something asked for it and approve it right away */ - empathy_dispatch_operation_approve (operation); - return; - } - if (properties == NULL) channel = tp_channel_new (connection, object_path, channel_type, handle_type, handle, NULL); @@ -680,9 +648,6 @@ dispatcher_connection_new_channel (EmpathyDispatcher *self, } } - if (g_hash_table_lookup (cd->dispatched_channels, object_path) != NULL) - empathy_dispatch_operation_approve (operation); - dispatcher_start_dispatching (dispatcher, operation, cd); } @@ -1093,16 +1058,6 @@ empathy_dispatcher_class_init (EmpathyDispatcherClass *klass) G_TYPE_NONE, 1, EMPATHY_TYPE_DISPATCH_OPERATION); - signals[APPROVE] = - g_signal_new ("approve", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, - 1, EMPATHY_TYPE_DISPATCH_OPERATION); - signals[DISPATCH] = g_signal_new ("dispatch", G_TYPE_FROM_CLASS (klass), diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c index 858cfae27..a9a63f548 100644 --- a/libempathy/empathy-tp-chat.c +++ b/libempathy/empathy-tp-chat.c @@ -1868,7 +1868,8 @@ empathy_tp_chat_join (EmpathyTpChat *self) } gboolean -empathy_tp_chat_is_invited (EmpathyTpChat *self) +empathy_tp_chat_is_invited (EmpathyTpChat *self, + TpHandle *inviter) { EmpathyTpChatPriv *priv = GET_PRIV (self); TpHandle self_handle; @@ -1881,5 +1882,5 @@ empathy_tp_chat_is_invited (EmpathyTpChat *self) return FALSE; return tp_channel_group_get_local_pending_info (priv->channel, self_handle, - NULL, NULL, NULL); + inviter, NULL, NULL); } diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h index e5abe936f..3ac5eaf58 100644 --- a/libempathy/empathy-tp-chat.h +++ b/libempathy/empathy-tp-chat.h @@ -101,7 +101,8 @@ gboolean empathy_tp_chat_can_add_contact (EmpathyTpChat *self); void empathy_tp_chat_leave (EmpathyTpChat *chat); void empathy_tp_chat_join (EmpathyTpChat *chat); -gboolean empathy_tp_chat_is_invited (EmpathyTpChat *chat); +gboolean empathy_tp_chat_is_invited (EmpathyTpChat *chat, + TpHandle *inviter); G_END_DECLS diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c index 14c52981b..1a91c22fa 100644 --- a/src/empathy-event-manager.c +++ b/src/empathy-event-manager.c @@ -27,6 +27,7 @@ #include <telepathy-glib/account-manager.h> #include <telepathy-glib/util.h> #include <telepathy-glib/interfaces.h> +#include <telepathy-glib/simple-approver.h> #include <libempathy/empathy-dispatcher.h> #include <libempathy/empathy-idle.h> @@ -60,9 +61,7 @@ typedef struct { EmpathyEventManager *manager; - EmpathyDispatchOperation *operation; - gulong approved_handler; - gulong claimed_handler; + TpChannelDispatchOperation *operation; gulong invalidated_handler; /* Remove contact if applicable */ EmpathyContact *contact; @@ -71,10 +70,13 @@ typedef struct { GObject *handler_instance; /* optional accept widget */ GtkWidget *dialog; + /* Channel of the CDO that will be used during the approval */ + TpChannel *main_channel; } EventManagerApproval; typedef struct { EmpathyDispatcher *dispatcher; + TpBaseClient *approver; EmpathyContactManager *contact_manager; GSList *events; /* Ongoing approvals */ @@ -111,11 +113,13 @@ static EmpathyEventManager * manager_singleton = NULL; static EventManagerApproval * event_manager_approval_new (EmpathyEventManager *manager, - EmpathyDispatchOperation *operation) + TpChannelDispatchOperation *operation, + TpChannel *main_channel) { EventManagerApproval *result = g_slice_new0 (EventManagerApproval); result->operation = g_object_ref (operation); result->manager = manager; + result->main_channel = g_object_ref (main_channel); return result; } @@ -124,17 +128,18 @@ static void event_manager_approval_free (EventManagerApproval *approval) { g_signal_handler_disconnect (approval->operation, - approval->approved_handler); - g_signal_handler_disconnect (approval->operation, - approval->claimed_handler); - g_signal_handler_disconnect (approval->operation, approval->invalidated_handler); g_object_unref (approval->operation); + g_object_unref (approval->main_channel); + if (approval->handler != 0) g_signal_handler_disconnect (approval->handler_instance, approval->handler); + if (approval->handler_instance != NULL) + g_object_unref (approval->handler_instance); + if (approval->contact != NULL) g_object_unref (approval->contact); @@ -226,15 +231,68 @@ event_manager_add (EmpathyEventManager *manager, } static void -event_channel_process_func (EventPriv *event) +handle_with_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source); + GError *error = NULL; + + if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error)) + { + DEBUG ("HandleWith failed: %s\n", error->message); + g_error_free (error); + } +} + +static void +handle_with_time_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source); + GError *error = NULL; + + if (!tp_channel_dispatch_operation_handle_with_time_finish (cdo, result, + &error)) + { + if (g_error_matches (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED)) + { + EventManagerApproval *approval = user_data; + + DEBUG ("HandleWithTime() is not implemented, falling back to " + "HandleWith(). Please upgrade to telepathy-mission-control " + "5.5.0 or later"); + + tp_channel_dispatch_operation_handle_with_async (approval->operation, + NULL, handle_with_cb, approval); + } + else + { + DEBUG ("HandleWithTime failed: %s\n", error->message); + } + g_error_free (error); + } +} + +static void +event_manager_approval_approve (EventManagerApproval *approval) { gint64 timestamp = gtk_get_current_event_time (); + if (timestamp == GDK_CURRENT_TIME) timestamp = EMPATHY_DISPATCHER_CURRENT_TIME; - empathy_dispatch_operation_set_user_action_time (event->approval->operation, - timestamp); - empathy_dispatch_operation_approve (event->approval->operation); + g_assert (approval->operation != NULL); + + tp_channel_dispatch_operation_handle_with_time_async (approval->operation, + NULL, timestamp, handle_with_time_cb, approval); +} + +static void +event_channel_process_func (EventPriv *event) +{ + event_manager_approval_approve (event->approval); } static void @@ -245,19 +303,15 @@ event_text_channel_process_func (EventPriv *event) if (timestamp == GDK_CURRENT_TIME) timestamp = EMPATHY_DISPATCHER_CURRENT_TIME; - empathy_dispatch_operation_set_user_action_time (event->approval->operation, - timestamp); - if (event->approval->handler != 0) { - tp_chat = EMPATHY_TP_CHAT - (empathy_dispatch_operation_get_channel_wrapper (event->approval->operation)); + tp_chat = EMPATHY_TP_CHAT (event->approval->handler_instance); g_signal_handler_disconnect (tp_chat, event->approval->handler); event->approval->handler = 0; } - empathy_dispatch_operation_approve (event->approval->operation); + event_manager_approval_approve (event->approval); } static EventPriv * @@ -298,6 +352,43 @@ event_update (EmpathyEventManager *manager, EventPriv *event, } static void +reject_channel_claim_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source); + GError *error = NULL; + + if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error)) + { + DEBUG ("Failed to claim channel: %s", error->message); + + g_error_free (error); + goto out; + } + + if (EMPATHY_IS_TP_CALL (user_data)) + { + empathy_tp_call_close (user_data); + } + else if (EMPATHY_IS_TP_CHAT (user_data)) + { + empathy_tp_chat_leave (user_data); + } + +out: + g_object_unref (user_data); +} + +static void +reject_approval (EventManagerApproval *approval) +{ + /* We have to claim the channel before closing it */ + tp_channel_dispatch_operation_claim_async (approval->operation, + reject_channel_claim_cb, g_object_ref (approval->handler_instance)); +} + +static void event_manager_call_window_confirmation_dialog_response_cb (GtkDialog *dialog, gint response, gpointer user_data) { @@ -308,21 +399,11 @@ event_manager_call_window_confirmation_dialog_response_cb (GtkDialog *dialog, if (response != GTK_RESPONSE_ACCEPT) { - EmpathyTpCall *call = - EMPATHY_TP_CALL ( - empathy_dispatch_operation_get_channel_wrapper ( - approval->operation)); - - g_object_ref (call); - if (empathy_dispatch_operation_claim (approval->operation)) - empathy_tp_call_close (call); - g_object_unref (call); - + reject_approval (approval); } else { - EmpathyCallFactory *factory = empathy_call_factory_get (); - empathy_call_factory_claim_channel (factory, approval->operation); + event_manager_approval_approve (approval); } } @@ -341,8 +422,7 @@ event_channel_process_voip_func (EventPriv *event) return; } - call = EMPATHY_TP_CALL (empathy_dispatch_operation_get_channel_wrapper ( - event->approval->operation)); + call = EMPATHY_TP_CALL (event->approval->handler_instance); video = empathy_tp_call_has_initial_video (call); @@ -397,7 +477,8 @@ event_channel_process_voip_func (EventPriv *event) static void event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat, - EmpathyMessage *message, EventManagerApproval *approval) + EmpathyMessage *message, + EventManagerApproval *approval) { EmpathyContact *sender; const gchar *header; @@ -416,7 +497,8 @@ event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat, channel = empathy_tp_chat_get_channel (tp_chat); if (event != NULL) - event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, msg); + event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, + msg); else event_manager_add (approval->manager, sender, EMPATHY_EVENT_TYPE_CHAT, EMPATHY_IMAGE_NEW_MESSAGE, header, msg, approval, @@ -436,8 +518,8 @@ event_manager_approval_done (EventManagerApproval *approval) { GQuark channel_type; - channel_type = empathy_dispatch_operation_get_channel_type_id ( - approval->operation); + channel_type = tp_channel_get_channel_type_id (approval->main_channel); + if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) { priv->ringing--; @@ -463,24 +545,14 @@ event_manager_approval_done (EventManagerApproval *approval) } static void -event_manager_operation_approved_cb (EmpathyDispatchOperation *operation, - EventManagerApproval *approval) +cdo_invalidated_cb (TpProxy *cdo, + guint domain, + gint code, + gchar *message, + EventManagerApproval *approval) { - event_manager_approval_done (approval); -} + DEBUG ("ChannelDispatchOperation has been invalidated: %s", message); -static void -event_manager_operation_claimed_cb (EmpathyDispatchOperation *operation, - EventManagerApproval *approval) -{ - event_manager_approval_done (approval); -} - -static void -event_manager_operation_invalidated_cb (EmpathyDispatchOperation *operation, - guint domain, gint code, gchar *message, - EventManagerApproval *approval) -{ event_manager_approval_done (approval); } @@ -492,8 +564,7 @@ event_manager_media_channel_got_contact (EventManagerApproval *approval) EmpathyTpCall *call; gboolean video; - call = EMPATHY_TP_CALL (empathy_dispatch_operation_get_channel_wrapper ( - approval->operation)); + call = EMPATHY_TP_CALL (approval->handler_instance); video = empathy_tp_call_has_initial_video (call); @@ -536,43 +607,33 @@ invite_dialog_response_cb (GtkDialog *dialog, EventManagerApproval *approval) { EmpathyTpChat *tp_chat; - gint64 timestamp; gtk_widget_destroy (GTK_WIDGET (approval->dialog)); approval->dialog = NULL; - tp_chat = EMPATHY_TP_CHAT (empathy_dispatch_operation_get_channel_wrapper ( - approval->operation)); + tp_chat = EMPATHY_TP_CHAT (approval->handler_instance); if (response != GTK_RESPONSE_OK) { /* close channel */ DEBUG ("Muc invitation rejected"); - if (empathy_dispatch_operation_claim (approval->operation)) - empathy_tp_chat_leave (tp_chat); + reject_approval (approval); + return; } DEBUG ("Muc invitation accepted"); /* We'll join the room when handling the channel */ - - timestamp = gtk_get_current_event_time (); - if (timestamp == GDK_CURRENT_TIME) - timestamp = EMPATHY_DISPATCHER_CURRENT_TIME; - - empathy_dispatch_operation_set_user_action_time (approval->operation, - timestamp); - empathy_dispatch_operation_approve (approval->operation); + event_manager_approval_approve (approval); } static void event_room_channel_process_func (EventPriv *event) { GtkWidget *dialog, *button, *image; - TpChannel *channel = empathy_dispatch_operation_get_channel ( - event->approval->operation); + TpChannel *channel = event->approval->main_channel; if (event->approval->dialog != NULL) { @@ -618,7 +679,6 @@ event_manager_muc_invite_got_contact_cb (TpConnection *connection, GObject *object) { EventManagerApproval *approval = (EventManagerApproval *) user_data; - TpChannel *channel; const gchar *invite_msg; gchar *msg; TpHandle self_handle; @@ -631,15 +691,14 @@ event_manager_muc_invite_got_contact_cb (TpConnection *connection, } approval->contact = g_object_ref (contact); - channel = empathy_dispatch_operation_get_channel (approval->operation); - self_handle = tp_channel_group_get_self_handle (channel); - tp_channel_group_get_local_pending_info (channel, self_handle, NULL, NULL, - &invite_msg); + self_handle = tp_channel_group_get_self_handle (approval->main_channel); + tp_channel_group_get_local_pending_info (approval->main_channel, self_handle, + NULL, NULL, &invite_msg); msg = g_strdup_printf (_("%s invited you to join %s"), empathy_contact_get_name (approval->contact), - tp_channel_get_identifier (channel)); + tp_channel_get_identifier (approval->main_channel)); event_manager_add (approval->manager, approval->contact, EMPATHY_EVENT_TYPE_CHAT, EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg, @@ -677,57 +736,93 @@ event_manager_ft_got_contact_cb (TpConnection *connection, g_free (header); } +/* If there is a file-transfer or media channel consider it as the + * main one. */ +static TpChannel * +find_main_channel (GList *channels) +{ + GList *l; + TpChannel *text = NULL; + + for (l = channels; l != NULL; l = g_list_next (l)) + { + TpChannel *channel = l->data; + GQuark channel_type; + + if (tp_proxy_get_invalidated (channel) != NULL) + continue; + + channel_type = tp_channel_get_channel_type_id (channel); + + if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA || + channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) + return channel; + + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT) + text = channel; + } + + return text; +} + static void -event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher, - EmpathyDispatchOperation *operation, EmpathyEventManager *manager) +approve_channels (TpSimpleApprover *approver, + TpAccount *account, + TpConnection *connection, + GList *channels, + TpChannelDispatchOperation *dispatch_operation, + TpAddDispatchOperationContext *context, + gpointer user_data) { - const gchar *channel_type; + EmpathyEventManager *self = user_data; + EmpathyEventManagerPriv *priv = GET_PRIV (self); + TpChannel *channel; EventManagerApproval *approval; - EmpathyEventManagerPriv *priv = GET_PRIV (manager); + GQuark channel_type; - channel_type = empathy_dispatch_operation_get_channel_type (operation); + channel = find_main_channel (channels); + if (channel == NULL) + { + GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, + "Unknown channel type" }; - approval = event_manager_approval_new (manager, operation); - priv->approvals = g_slist_prepend (priv->approvals, approval); + DEBUG ("Failed to find the main channel; ignoring"); - approval->approved_handler = g_signal_connect (operation, "approved", - G_CALLBACK (event_manager_operation_approved_cb), approval); + tp_add_dispatch_operation_context_fail (context, &error); + return; + } - approval->claimed_handler = g_signal_connect (operation, "claimed", - G_CALLBACK (event_manager_operation_claimed_cb), approval); + approval = event_manager_approval_new (self, dispatch_operation, channel); + priv->approvals = g_slist_prepend (priv->approvals, approval); + + approval->invalidated_handler = g_signal_connect (dispatch_operation, + "invalidated", G_CALLBACK (cdo_invalidated_cb), approval); - approval->invalidated_handler = g_signal_connect (operation, "invalidated", - G_CALLBACK (event_manager_operation_invalidated_cb), approval); + channel_type = tp_channel_get_channel_type_id (channel); - if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) + if (channel_type == TP_IFACE_QUARK_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); + EmpathyTpChat *tp_chat; + + tp_chat = empathy_tp_chat_new (channel); + approval->handler_instance = G_OBJECT (tp_chat); if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP)) { /* Are we in local-pending ? */ - TpHandle self_handle, inviter; + TpHandle 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)) + if (empathy_tp_chat_is_invited (tp_chat, &inviter)) { /* We are invited to a room */ - 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); empathy_tp_contact_factory_get_from_handle (connection, inviter, event_manager_muc_invite_got_contact_cb, - approval, NULL, G_OBJECT (manager)); + approval, NULL, G_OBJECT (self)); - return; + goto out; } /* if we are not invited, let's wait for the first message */ @@ -736,13 +831,13 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher, /* 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)) + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA) { EmpathyContact *contact; - EmpathyTpCall *call = EMPATHY_TP_CALL ( - empathy_dispatch_operation_get_channel_wrapper (operation)); + EmpathyTpCall *call = empathy_tp_call_new (channel); + + approval->handler_instance = G_OBJECT (call); g_object_get (G_OBJECT (call), "contact", &contact, NULL); @@ -759,23 +854,30 @@ event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher, } } - else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) + else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER) { - TpChannel *channel; - TpConnection *connection; TpHandle handle; - channel = empathy_dispatch_operation_get_channel (operation); handle = tp_channel_get_handle (channel, NULL); connection = tp_channel_borrow_connection (channel); empathy_tp_contact_factory_get_from_handle (connection, handle, - event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (manager)); + event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (self)); } else { - DEBUG ("Unknown channel type (%s), ignoring..", channel_type); + GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, + "Invalid channel type" }; + + DEBUG ("Unknown channel type (%s), ignoring..", + g_quark_to_string (channel_type)); + + tp_add_dispatch_operation_context_fail (context, &error); + return; } + +out: + tp_add_dispatch_operation_context_accept (context); } static void @@ -947,6 +1049,7 @@ event_manager_finalize (GObject *object) g_slist_free (priv->approvals); g_object_unref (priv->contact_manager); g_object_unref (priv->dispatcher); + g_object_unref (priv->approver); } static void @@ -994,17 +1097,67 @@ empathy_event_manager_init (EmpathyEventManager *manager) { EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager, EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv); + TpDBusDaemon *dbus; + GError *error = NULL; manager->priv = priv; priv->dispatcher = empathy_dispatcher_dup_singleton (); priv->contact_manager = empathy_contact_manager_dup_singleton (); - g_signal_connect (priv->dispatcher, "approve", - G_CALLBACK (event_manager_approve_channel_cb), manager); g_signal_connect (priv->contact_manager, "pendings-changed", G_CALLBACK (event_manager_pendings_changed_cb), manager); + g_signal_connect (priv->contact_manager, "members-changed", G_CALLBACK (event_manager_members_changed_cb), manager); + + dbus = tp_dbus_daemon_dup (&error); + if (dbus == NULL) + { + DEBUG ("Failed to get TpDBusDaemon: %s", error->message); + g_error_free (error); + return; + } + + priv->approver = tp_simple_approver_new (dbus, "EmpathyEventManager", FALSE, + approve_channels, manager, NULL); + + /* Private text channels */ + tp_base_client_take_approver_filter (priv->approver, + tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, + NULL)); + + /* Muc text channels */ + tp_base_client_take_approver_filter (priv->approver, + tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM, + NULL)); + + /* File transfer */ + tp_base_client_take_approver_filter (priv->approver, + tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, + NULL)); + + /* Calls */ + tp_base_client_take_approver_filter (priv->approver, + tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT, + NULL)); + + if (!tp_base_client_register (priv->approver, &error)) + { + DEBUG ("Failed to register Approver: %s", error->message); + g_error_free (error); + } + + g_object_unref (dbus); } EmpathyEventManager * diff --git a/src/empathy.c b/src/empathy.c index 5a6b13199..2c7ea2a7f 100644 --- a/src/empathy.c +++ b/src/empathy.c @@ -131,7 +131,7 @@ dispatch_cb (EmpathyDispatcher *dispatcher, empathy_chat_window_present_chat (chat, empathy_dispatch_operation_get_user_action_time (operation)); - if (empathy_tp_chat_is_invited (tp_chat)) + if (empathy_tp_chat_is_invited (tp_chat, NULL)) { /* We have been invited to the room. Add ourself as member as this * channel has been approved. */ |