2 * Copyright (C) 2007-2008 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Xavier Claessens <xclaesse@gmail.com>
19 * Sjoerd Simons <sjoerd.simons@collabora.co.uk>
25 #include <glib/gi18n.h>
27 #include <telepathy-glib/account-manager.h>
28 #include <telepathy-glib/util.h>
29 #include <telepathy-glib/interfaces.h>
30 #include <telepathy-glib/simple-approver.h>
32 #include <libempathy/empathy-presence-manager.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy/empathy-connection-aggregator.h>
35 #include <libempathy/empathy-tp-chat.h>
36 #include <libempathy/empathy-tp-streamed-media.h>
37 #include <libempathy/empathy-utils.h>
38 #include <libempathy/empathy-gsettings.h>
40 #include <extensions/extensions.h>
42 #include <libempathy-gtk/empathy-images.h>
43 #include <libempathy-gtk/empathy-contact-dialogs.h>
44 #include <libempathy-gtk/empathy-sound-manager.h>
45 #include <libempathy-gtk/empathy-ui-utils.h>
46 #include <libempathy-gtk/empathy-call-utils.h>
48 #include "empathy-event-manager.h"
49 #include "empathy-roster-window.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
52 #include <libempathy/empathy-debug.h>
54 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyEventManager)
56 #define NOTIFICATION_TIMEOUT 2 /* seconds */
58 #define ACCEPT_WITHOUT_VIDEO 1
60 /* The time interval in milliseconds between 2 incoming rings */
61 #define MS_BETWEEN_RING 500
64 EmpathyEventManager
*manager
;
65 TpChannelDispatchOperation
*operation
;
66 gulong invalidated_handler
;
67 /* Remove contact if applicable */
68 EmpathyContact
*contact
;
69 /* option signal handler and it's instance */
71 GObject
*handler_instance
;
72 /* optional accept widget */
74 /* Channel of the CDO that will be used during the approval */
75 TpChannel
*main_channel
;
76 gboolean auto_approved
;
77 } EventManagerApproval
;
80 TpBaseClient
*approver
;
81 TpBaseClient
*auth_approver
;
82 EmpathyConnectionAggregator
*conn_aggregator
;
84 /* Ongoing approvals */
89 GSettings
*gsettings_notif
;
90 GSettings
*gsettings_ui
;
92 EmpathySoundManager
*sound_mgr
;
94 /* TpContact -> EmpathyContact */
96 } EmpathyEventManagerPriv
;
98 typedef struct _EventPriv EventPriv
;
99 typedef void (*EventFunc
) (EventPriv
*event
);
103 EmpathyEventManager
*manager
;
104 EventManagerApproval
*approval
;
108 guint autoremove_timeout_id
;
118 static guint signals
[LAST_SIGNAL
];
120 G_DEFINE_TYPE (EmpathyEventManager
, empathy_event_manager
, G_TYPE_OBJECT
);
122 static EmpathyEventManager
* manager_singleton
= NULL
;
124 static EventManagerApproval
*
125 event_manager_approval_new (EmpathyEventManager
*manager
,
126 TpChannelDispatchOperation
*operation
,
127 TpChannel
*main_channel
)
129 EventManagerApproval
*result
= g_slice_new0 (EventManagerApproval
);
130 result
->operation
= g_object_ref (operation
);
131 result
->manager
= manager
;
132 result
->main_channel
= g_object_ref (main_channel
);
138 event_manager_approval_free (EventManagerApproval
*approval
)
140 g_signal_handler_disconnect (approval
->operation
,
141 approval
->invalidated_handler
);
142 g_object_unref (approval
->operation
);
144 g_object_unref (approval
->main_channel
);
146 if (approval
->handler
!= 0)
147 g_signal_handler_disconnect (approval
->handler_instance
,
150 if (approval
->handler_instance
!= NULL
)
151 g_object_unref (approval
->handler_instance
);
153 if (approval
->contact
!= NULL
)
154 g_object_unref (approval
->contact
);
156 if (approval
->dialog
!= NULL
)
158 gtk_widget_destroy (approval
->dialog
);
161 g_slice_free (EventManagerApproval
, approval
);
165 event_free (EventPriv
*event
)
167 g_free (event
->public.icon_name
);
168 g_free (event
->public.header
);
169 g_free (event
->public.message
);
171 if (event
->autoremove_timeout_id
!= 0)
172 g_source_remove (event
->autoremove_timeout_id
);
174 tp_clear_object (&(event
->public.contact
));
175 tp_clear_object (&(event
->public.account
));
177 g_slice_free (EventPriv
, event
);
181 event_remove (EventPriv
*event
)
183 EmpathyEventManagerPriv
*priv
= GET_PRIV (event
->manager
);
185 DEBUG ("Removing event %p", event
);
187 priv
->events
= g_slist_remove (priv
->events
, event
);
188 g_signal_emit (event
->manager
, signals
[EVENT_REMOVED
], 0, event
);
193 empathy_event_remove (EmpathyEvent
*event_public
)
195 EventPriv
*event
= (EventPriv
*) event_public
;
197 event_remove (event
);
201 autoremove_event_timeout_cb (EventPriv
*event
)
203 event
->autoremove_timeout_id
= 0;
204 event_remove (event
);
209 display_notify_area (EmpathyEventManager
*self
)
211 EmpathyEventManagerPriv
*priv
= GET_PRIV (self
);
213 return g_settings_get_boolean (priv
->gsettings_ui
,
214 EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA
);
218 event_manager_add (EmpathyEventManager
*manager
,
220 EmpathyContact
*contact
,
221 EmpathyEventType type
,
222 const gchar
*icon_name
,
224 const gchar
*message
,
225 EventManagerApproval
*approval
,
229 EmpathyEventManagerPriv
*priv
= GET_PRIV (manager
);
232 event
= g_slice_new0 (EventPriv
);
233 event
->public.account
= account
!= NULL
? g_object_ref (account
) : NULL
;
234 event
->public.contact
= contact
? g_object_ref (contact
) : NULL
;
235 event
->public.type
= type
;
236 event
->public.icon_name
= g_strdup (icon_name
);
237 event
->public.header
= g_strdup (header
);
238 event
->public.message
= g_strdup (message
);
239 event
->public.must_ack
= (func
!= NULL
);
240 if (approval
!= NULL
)
241 event
->public.handler_instance
= approval
->handler_instance
;
242 event
->inhibit
= FALSE
;
244 event
->user_data
= user_data
;
245 event
->manager
= manager
;
246 event
->approval
= approval
;
248 DEBUG ("Adding event %p", event
);
249 priv
->events
= g_slist_prepend (priv
->events
, event
);
251 if (!display_notify_area (manager
))
253 /* Don't fire the 'event-added' signal as we activate the event now */
254 if (approval
!= NULL
)
255 approval
->auto_approved
= TRUE
;
257 empathy_event_activate (&event
->public);
261 g_signal_emit (event
->manager
, signals
[EVENT_ADDED
], 0, event
);
263 if (!event
->public.must_ack
)
265 event
->autoremove_timeout_id
= g_timeout_add_seconds (
266 NOTIFICATION_TIMEOUT
, (GSourceFunc
) autoremove_event_timeout_cb
,
272 handle_with_cb (GObject
*source
,
273 GAsyncResult
*result
,
276 TpChannelDispatchOperation
*cdo
= TP_CHANNEL_DISPATCH_OPERATION (source
);
277 GError
*error
= NULL
;
279 if (!tp_channel_dispatch_operation_handle_with_finish (cdo
, result
, &error
))
281 DEBUG ("HandleWith failed: %s\n", error
->message
);
282 g_error_free (error
);
287 handle_with_time_cb (GObject
*source
,
288 GAsyncResult
*result
,
291 TpChannelDispatchOperation
*cdo
= TP_CHANNEL_DISPATCH_OPERATION (source
);
292 GError
*error
= NULL
;
294 if (!tp_channel_dispatch_operation_handle_with_time_finish (cdo
, result
,
297 if (g_error_matches (error
, TP_ERRORS
, TP_ERROR_NOT_IMPLEMENTED
))
299 EventManagerApproval
*approval
= user_data
;
301 DEBUG ("HandleWithTime() is not implemented, falling back to "
302 "HandleWith(). Please upgrade to telepathy-mission-control "
305 tp_channel_dispatch_operation_handle_with_async (approval
->operation
,
306 NULL
, handle_with_cb
, approval
);
310 DEBUG ("HandleWithTime failed: %s\n", error
->message
);
312 g_error_free (error
);
317 event_manager_approval_approve (EventManagerApproval
*approval
)
321 if (approval
->auto_approved
)
323 timestamp
= TP_USER_ACTION_TIME_NOT_USER_ACTION
;
327 timestamp
= empathy_get_current_action_time ();
330 g_assert (approval
->operation
!= NULL
);
332 tp_channel_dispatch_operation_handle_with_time_async (approval
->operation
,
333 NULL
, timestamp
, handle_with_time_cb
, approval
);
337 event_channel_process_func (EventPriv
*event
)
339 event_manager_approval_approve (event
->approval
);
343 event_text_channel_process_func (EventPriv
*event
)
345 EmpathyTpChat
*tp_chat
;
347 if (event
->approval
->handler
!= 0)
349 tp_chat
= EMPATHY_TP_CHAT (event
->approval
->handler_instance
);
351 g_signal_handler_disconnect (tp_chat
, event
->approval
->handler
);
352 event
->approval
->handler
= 0;
355 event_manager_approval_approve (event
->approval
);
359 event_lookup_by_approval (EmpathyEventManager
*manager
,
360 EventManagerApproval
*approval
)
362 EmpathyEventManagerPriv
*priv
= GET_PRIV (manager
);
364 EventPriv
*retval
= NULL
;
366 for (l
= priv
->events
; l
; l
= l
->next
)
368 EventPriv
*event
= l
->data
;
370 if (event
->approval
== approval
)
381 event_update (EmpathyEventManager
*manager
, EventPriv
*event
,
382 const char *icon_name
, const char *header
, const char *msg
)
384 g_free (event
->public.icon_name
);
385 g_free (event
->public.header
);
386 g_free (event
->public.message
);
388 event
->public.icon_name
= g_strdup (icon_name
);
389 event
->public.header
= g_strdup (header
);
390 event
->public.message
= g_strdup (msg
);
392 g_signal_emit (manager
, signals
[EVENT_UPDATED
], 0, event
);
396 reject_channel_claim_cb (GObject
*source
,
397 GAsyncResult
*result
,
400 TpChannelDispatchOperation
*cdo
= TP_CHANNEL_DISPATCH_OPERATION (source
);
401 GError
*error
= NULL
;
403 if (!tp_channel_dispatch_operation_claim_with_finish (cdo
, result
, &error
))
405 DEBUG ("Failed to claim channel: %s", error
->message
);
407 g_error_free (error
);
411 if (EMPATHY_IS_TP_STREAMED_MEDIA (user_data
))
413 empathy_tp_streamed_media_close (user_data
);
415 else if (TP_IS_CALL_CHANNEL (user_data
))
417 tp_call_channel_hangup_async (user_data
,
418 TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED
,
420 tp_channel_close_async (user_data
, NULL
, NULL
);
422 else if (EMPATHY_IS_TP_CHAT (user_data
))
424 empathy_tp_chat_leave (user_data
, "");
426 else if (TP_IS_FILE_TRANSFER_CHANNEL (user_data
))
428 tp_channel_close_async (user_data
, NULL
, NULL
);
432 g_object_unref (user_data
);
436 reject_approval (EventManagerApproval
*approval
)
438 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
440 /* We have to claim the channel before closing it */
442 /* Unfortunately, we need to special case the auth channels for the
443 * time being as they don't have a wrapper object handler in
444 * approval->handler_instance as they're not actually handled by
445 * this process, so we can just use a noddy callback to call Close()
447 if (approval
->handler_instance
!= NULL
)
449 tp_channel_dispatch_operation_claim_with_async (approval
->operation
,
450 priv
->approver
, reject_channel_claim_cb
,
451 g_object_ref (approval
->handler_instance
));
453 else if (tp_channel_get_channel_type_id (approval
->main_channel
)
454 == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION
)
456 tp_channel_dispatch_operation_close_channels_async (approval
->operation
,
462 event_manager_call_window_confirmation_dialog_response_cb (GtkDialog
*dialog
,
463 gint response
, gpointer user_data
)
465 EventManagerApproval
*approval
= user_data
;
467 gtk_widget_destroy (approval
->dialog
);
468 approval
->dialog
= NULL
;
470 if (response
== GTK_RESPONSE_ACCEPT
)
472 event_manager_approval_approve (approval
);
474 else if (response
== ACCEPT_WITHOUT_VIDEO
)
476 empathy_call_channel_send_video (TP_CALL_CHANNEL (approval
->main_channel
),
478 event_manager_approval_approve (approval
);
482 reject_approval (approval
);
487 event_channel_process_voip_func (EventPriv
*event
)
494 EmpathyEventType etype
= event
->public.type
;
496 if (event
->approval
->dialog
!= NULL
)
498 gtk_window_present (GTK_WINDOW (event
->approval
->dialog
));
502 if (etype
== EMPATHY_EVENT_TYPE_VOIP
)
504 EmpathyTpStreamedMedia
*call
;
505 call
= EMPATHY_TP_STREAMED_MEDIA (event
->approval
->handler_instance
);
506 video
= empathy_tp_streamed_media_has_initial_video (call
);
508 else if (etype
== EMPATHY_EVENT_TYPE_CALL
)
511 call
= TP_CALL_CHANNEL (event
->approval
->handler_instance
);
512 video
= tp_call_channel_has_initial_video (call
, NULL
);
516 g_warning ("Unknown event type: %d", event
->public.type
);
520 dialog
= gtk_message_dialog_new (NULL
, 0,
521 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_NONE
,
522 video
? _("Incoming video call"): _("Incoming call"));
524 gtk_message_dialog_format_secondary_text (
525 GTK_MESSAGE_DIALOG (dialog
), video
?
526 _("%s is video calling you. Do you want to answer?"):
527 _("%s is calling you. Do you want to answer?"),
528 empathy_contact_get_alias (event
->approval
->contact
));
530 title
= g_strdup_printf (_("Incoming call from %s"),
531 empathy_contact_get_alias (event
->approval
->contact
));
533 gtk_window_set_title (GTK_WINDOW (dialog
), title
);
536 /* Set image of the dialog */
539 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL
,
540 GTK_ICON_SIZE_DIALOG
);
544 image
= gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP
,
545 GTK_ICON_SIZE_DIALOG
);
548 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog
), image
);
549 gtk_widget_show (image
);
551 gtk_dialog_set_default_response (GTK_DIALOG (dialog
),
554 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
555 _("_Reject"), GTK_RESPONSE_REJECT
);
556 image
= gtk_image_new_from_icon_name ("call-stop",
557 GTK_ICON_SIZE_BUTTON
);
558 gtk_button_set_image (GTK_BUTTON (button
), image
);
560 if (video
&& etype
== EMPATHY_EVENT_TYPE_CALL
)
562 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
563 _("_Answer"), ACCEPT_WITHOUT_VIDEO
);
565 image
= gtk_image_new_from_icon_name ("call-start",
566 GTK_ICON_SIZE_BUTTON
);
567 gtk_button_set_image (GTK_BUTTON (button
), image
);
570 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
571 video
? _("_Answer with video") : _("_Answer"), GTK_RESPONSE_ACCEPT
);
573 image
= gtk_image_new_from_icon_name ("call-start",
574 GTK_ICON_SIZE_BUTTON
);
575 gtk_button_set_image (GTK_BUTTON (button
), image
);
577 g_signal_connect (dialog
, "response",
578 G_CALLBACK (event_manager_call_window_confirmation_dialog_response_cb
),
581 gtk_widget_show (dialog
);
583 event
->approval
->dialog
= dialog
;
587 event_manager_chat_message_received_cb (EmpathyTpChat
*tp_chat
,
588 EmpathyMessage
*message
,
589 EventManagerApproval
*approval
)
592 EmpathyContact
*sender
;
596 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
598 /* try to update the event if it's referring to a chat which is already in the
600 event
= event_lookup_by_approval (approval
->manager
, approval
);
602 sender
= empathy_message_get_sender (message
);
604 /* We only want to show incoming messages */
605 if (empathy_contact_is_user (sender
))
608 header
= empathy_contact_get_alias (sender
);
609 msg
= empathy_message_get_body (message
);
612 event_update (approval
->manager
, event
, EMPATHY_IMAGE_NEW_MESSAGE
, header
,
615 event_manager_add (approval
->manager
, NULL
, sender
,
616 EMPATHY_EVENT_TYPE_CHAT
, EMPATHY_IMAGE_NEW_MESSAGE
, header
, msg
,
617 approval
, event_text_channel_process_func
, NULL
);
619 window
= empathy_roster_window_dup ();
621 empathy_sound_manager_play (priv
->sound_mgr
, window
,
622 EMPATHY_SOUND_CONVERSATION_NEW
);
624 g_object_unref (window
);
628 event_manager_approval_done (EventManagerApproval
*approval
)
630 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
633 if (approval
->operation
!= NULL
)
637 channel_type
= tp_channel_get_channel_type_id (approval
->main_channel
);
639 if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA
||
640 channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_CALL
)
643 if (priv
->ringing
== 0)
644 empathy_sound_manager_stop (priv
->sound_mgr
,
645 EMPATHY_SOUND_PHONE_INCOMING
);
649 priv
->approvals
= g_slist_remove (priv
->approvals
, approval
);
651 for (l
= priv
->events
; l
; l
= l
->next
)
653 EventPriv
*event
= l
->data
;
655 if (event
->approval
== approval
)
657 event_remove (event
);
662 event_manager_approval_free (approval
);
666 cdo_invalidated_cb (TpProxy
*cdo
,
670 EventManagerApproval
*approval
)
672 DEBUG ("ChannelDispatchOperation has been invalidated: %s", message
);
674 event_manager_approval_done (approval
);
678 event_manager_call_state_changed_cb (TpCallChannel
*call
,
681 TpCallStateReason
*reason
,
683 EventManagerApproval
*approval
)
685 if (state
== TP_CALL_STATE_ENDED
)
687 DEBUG ("Call ended, seems we missed it :/");
688 reject_approval (approval
);
693 event_manager_call_channel_got_contact_cb (TpConnection
*connection
,
694 EmpathyContact
*contact
,
699 EventManagerApproval
*approval
= (EventManagerApproval
*) user_data
;
700 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
706 call
= TP_CALL_CHANNEL (approval
->handler_instance
);
710 DEBUG ("Can't get the contact for the call.. Rejecting?");
711 reject_approval (approval
);
715 if (tp_call_channel_get_state (call
, NULL
, NULL
, NULL
) == TP_CALL_STATE_ENDED
)
717 DEBUG ("Call already ended, seems we missed it :/");
718 reject_approval (approval
);
722 approval
->handler
= g_signal_connect (call
, "state-changed",
723 G_CALLBACK (event_manager_call_state_changed_cb
), approval
);
725 window
= empathy_roster_window_dup ();
726 approval
->contact
= g_object_ref (contact
);
728 g_object_get (G_OBJECT (call
), "initial-video", &video
, NULL
);
730 header
= g_strdup_printf (
731 video
? _("Incoming video call from %s") :_("Incoming call from %s"),
732 empathy_contact_get_alias (approval
->contact
));
734 event_manager_add (approval
->manager
, NULL
,
735 approval
->contact
, EMPATHY_EVENT_TYPE_CALL
,
736 video
? EMPATHY_IMAGE_VIDEO_CALL
: EMPATHY_IMAGE_VOIP
,
737 header
, NULL
, approval
,
738 event_channel_process_voip_func
, NULL
);
743 if (priv
->ringing
== 1)
744 empathy_sound_manager_start_playing (priv
->sound_mgr
, window
,
745 EMPATHY_SOUND_PHONE_INCOMING
, MS_BETWEEN_RING
);
747 g_object_unref (window
);
751 event_manager_media_channel_got_contact (EventManagerApproval
*approval
)
753 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
754 GtkWidget
*window
= empathy_roster_window_dup ();
756 EmpathyTpStreamedMedia
*call
;
759 call
= EMPATHY_TP_STREAMED_MEDIA (approval
->handler_instance
);
761 video
= empathy_tp_streamed_media_has_initial_video (call
);
763 header
= g_strdup_printf (
764 video
? _("Incoming video call from %s") :_("Incoming call from %s"),
765 empathy_contact_get_alias (approval
->contact
));
767 event_manager_add (approval
->manager
, NULL
,
768 approval
->contact
, EMPATHY_EVENT_TYPE_VOIP
,
769 video
? EMPATHY_IMAGE_VIDEO_CALL
: EMPATHY_IMAGE_VOIP
,
770 header
, NULL
, approval
,
771 event_channel_process_voip_func
, NULL
);
776 if (priv
->ringing
== 1)
777 empathy_sound_manager_start_playing (priv
->sound_mgr
, window
,
778 EMPATHY_SOUND_PHONE_INCOMING
, MS_BETWEEN_RING
);
780 g_object_unref (window
);
784 event_manager_media_channel_contact_changed_cb (EmpathyTpStreamedMedia
*call
,
785 GParamSpec
*param
, EventManagerApproval
*approval
)
787 EmpathyContact
*contact
;
789 g_object_get (G_OBJECT (call
), "contact", &contact
, NULL
);
794 approval
->contact
= contact
;
795 event_manager_media_channel_got_contact (approval
);
799 invite_dialog_response_cb (GtkDialog
*dialog
,
801 EventManagerApproval
*approval
)
803 gtk_widget_destroy (GTK_WIDGET (approval
->dialog
));
804 approval
->dialog
= NULL
;
806 if (response
!= GTK_RESPONSE_OK
)
809 DEBUG ("Muc invitation rejected");
811 reject_approval (approval
);
816 DEBUG ("Muc invitation accepted");
818 /* We'll join the room when handling the channel */
819 event_manager_approval_approve (approval
);
823 event_room_channel_process_func (EventPriv
*event
)
825 GtkWidget
*dialog
, *button
, *image
;
826 TpChannel
*channel
= event
->approval
->main_channel
;
829 if (event
->approval
->dialog
!= NULL
)
831 gtk_window_present (GTK_WINDOW (event
->approval
->dialog
));
836 dialog
= gtk_message_dialog_new (NULL
, 0,
837 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_NONE
, _("Room invitation"));
839 title
= g_strdup_printf (_("Invitation to join %s"),
840 tp_channel_get_identifier (channel
));
842 gtk_window_set_title (GTK_WINDOW (dialog
), title
);
845 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog
),
846 _("%s is inviting you to join %s"),
847 empathy_contact_get_alias (event
->approval
->contact
),
848 tp_channel_get_identifier (channel
));
850 gtk_dialog_set_default_response (GTK_DIALOG (dialog
),
853 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
854 _("_Decline"), GTK_RESPONSE_CANCEL
);
855 image
= gtk_image_new_from_icon_name (GTK_STOCK_CANCEL
, GTK_ICON_SIZE_BUTTON
);
856 gtk_button_set_image (GTK_BUTTON (button
), image
);
858 button
= gtk_dialog_add_button (GTK_DIALOG (dialog
),
859 _("_Join"), GTK_RESPONSE_OK
);
860 image
= gtk_image_new_from_icon_name (GTK_STOCK_APPLY
, GTK_ICON_SIZE_BUTTON
);
861 gtk_button_set_image (GTK_BUTTON (button
), image
);
863 g_signal_connect (dialog
, "response",
864 G_CALLBACK (invite_dialog_response_cb
), event
->approval
);
866 gtk_widget_show (dialog
);
868 event
->approval
->dialog
= dialog
;
872 display_invite_room_dialog (EventManagerApproval
*approval
)
874 GtkWidget
*window
= empathy_roster_window_dup ();
875 const gchar
*invite_msg
;
877 TpHandle self_handle
;
878 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
880 self_handle
= tp_channel_group_get_self_handle (approval
->main_channel
);
881 tp_channel_group_get_local_pending_info (approval
->main_channel
, self_handle
,
882 NULL
, NULL
, &invite_msg
);
884 if (approval
->contact
!= NULL
)
886 msg
= g_strdup_printf (_("%s invited you to join %s"),
887 empathy_contact_get_alias (approval
->contact
),
888 tp_channel_get_identifier (approval
->main_channel
));
892 msg
= g_strdup_printf (_("You have been invited to join %s"),
893 tp_channel_get_identifier (approval
->main_channel
));
896 event_manager_add (approval
->manager
, NULL
,
897 approval
->contact
, EMPATHY_EVENT_TYPE_INVITATION
,
898 EMPATHY_IMAGE_GROUP_MESSAGE
, msg
, invite_msg
, approval
,
899 event_room_channel_process_func
, NULL
);
901 empathy_sound_manager_play (priv
->sound_mgr
, window
,
902 EMPATHY_SOUND_CONVERSATION_NEW
);
905 g_object_unref (window
);
909 event_manager_muc_invite_got_contact_cb (TpConnection
*connection
,
910 EmpathyContact
*contact
,
915 EventManagerApproval
*approval
= (EventManagerApproval
*) user_data
;
919 DEBUG ("Error: %s", error
->message
);
923 approval
->contact
= g_object_ref (contact
);
926 display_invite_room_dialog (approval
);
930 event_manager_ft_got_contact_cb (TpConnection
*connection
,
931 EmpathyContact
*contact
,
936 EventManagerApproval
*approval
= (EventManagerApproval
*) user_data
;
937 GtkWidget
*window
= empathy_roster_window_dup ();
939 EmpathyEventManagerPriv
*priv
= GET_PRIV (approval
->manager
);
941 approval
->contact
= g_object_ref (contact
);
943 header
= g_strdup_printf (_("Incoming file transfer from %s"),
944 empathy_contact_get_alias (approval
->contact
));
946 event_manager_add (approval
->manager
, NULL
,
947 approval
->contact
, EMPATHY_EVENT_TYPE_TRANSFER
,
948 EMPATHY_IMAGE_DOCUMENT_SEND
, header
, NULL
,
949 approval
, event_channel_process_func
, NULL
);
951 /* FIXME better sound for incoming file transfers ?*/
952 empathy_sound_manager_play (priv
->sound_mgr
, window
,
953 EMPATHY_SOUND_CONVERSATION_NEW
);
956 g_object_unref (window
);
960 event_manager_auth_process_func (EventPriv
*event
)
962 empathy_event_approve ((EmpathyEvent
*) event
);
965 /* If there is a file-transfer, media, or auth channel consider it as
968 find_main_channel (GList
*channels
)
971 TpChannel
*text
= NULL
;
973 for (l
= channels
; l
!= NULL
; l
= g_list_next (l
))
975 TpChannel
*channel
= l
->data
;
978 if (tp_proxy_get_invalidated (channel
) != NULL
)
981 channel_type
= tp_channel_get_channel_type_id (channel
);
983 if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA
||
984 channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_CALL
||
985 channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER
||
986 channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION
)
989 else if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_TEXT
)
997 approve_channels (TpSimpleApprover
*approver
,
999 TpConnection
*connection
,
1001 TpChannelDispatchOperation
*dispatch_operation
,
1002 TpAddDispatchOperationContext
*context
,
1005 EmpathyEventManager
*self
= user_data
;
1006 EmpathyEventManagerPriv
*priv
= GET_PRIV (self
);
1008 EventManagerApproval
*approval
;
1009 GQuark channel_type
;
1011 channel
= find_main_channel (channels
);
1012 if (channel
== NULL
)
1014 GError error
= { TP_ERRORS
, TP_ERROR_INVALID_ARGUMENT
,
1015 "Unknown channel type" };
1017 DEBUG ("Failed to find the main channel; ignoring");
1019 tp_add_dispatch_operation_context_fail (context
, &error
);
1023 approval
= event_manager_approval_new (self
, dispatch_operation
, channel
);
1024 priv
->approvals
= g_slist_prepend (priv
->approvals
, approval
);
1026 approval
->invalidated_handler
= g_signal_connect (dispatch_operation
,
1027 "invalidated", G_CALLBACK (cdo_invalidated_cb
), approval
);
1029 channel_type
= tp_channel_get_channel_type_id (channel
);
1031 if (TP_IS_TEXT_CHANNEL (channel
))
1033 EmpathyTpChat
*tp_chat
= EMPATHY_TP_CHAT (channel
);
1034 GList
*messages
, *l
;
1036 approval
->handler_instance
= g_object_ref (tp_chat
);
1038 if (tp_proxy_has_interface (channel
, TP_IFACE_CHANNEL_INTERFACE_GROUP
))
1040 /* Are we in local-pending ? */
1043 if (empathy_tp_chat_is_invited (tp_chat
, &inviter
))
1045 /* We are invited to a room */
1046 DEBUG ("Have been invited to %s. Ask user if he wants to accept",
1047 tp_channel_get_identifier (channel
));
1051 empathy_tp_contact_factory_get_from_handle (connection
,
1052 inviter
, event_manager_muc_invite_got_contact_cb
,
1053 approval
, NULL
, G_OBJECT (self
));
1057 display_invite_room_dialog (approval
);
1063 /* We are not invited, approve the channel right now */
1064 tp_add_dispatch_operation_context_accept (context
);
1066 approval
->auto_approved
= TRUE
;
1067 event_manager_approval_approve (approval
);
1071 /* 1-1 text channel, wait for the first message */
1072 approval
->handler
= g_signal_connect (tp_chat
, "message-received-empathy",
1073 G_CALLBACK (event_manager_chat_message_received_cb
), approval
);
1075 messages
= (GList
*) empathy_tp_chat_get_pending_messages (tp_chat
);
1076 for (l
= messages
; l
!= NULL
; l
= g_list_next (l
))
1078 EmpathyMessage
*msg
= l
->data
;
1080 event_manager_chat_message_received_cb (tp_chat
, msg
, approval
);
1083 else if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA
)
1085 EmpathyContact
*contact
;
1086 EmpathyTpStreamedMedia
*call
= empathy_tp_streamed_media_new (account
,
1089 approval
->handler_instance
= G_OBJECT (call
);
1091 g_object_get (G_OBJECT (call
), "contact", &contact
, NULL
);
1093 if (contact
== NULL
)
1095 g_signal_connect (call
, "notify::contact",
1096 G_CALLBACK (event_manager_media_channel_contact_changed_cb
),
1101 approval
->contact
= contact
;
1102 event_manager_media_channel_got_contact (approval
);
1106 else if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_CALL
)
1108 TpCallChannel
*call
= TP_CALL_CHANNEL (channel
);
1111 approval
->handler_instance
= g_object_ref (call
);
1113 id
= tp_channel_get_identifier (channel
);
1115 empathy_tp_contact_factory_get_from_id (connection
, id
,
1116 event_manager_call_channel_got_contact_cb
,
1117 approval
, NULL
, G_OBJECT (self
));
1119 else if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER
)
1123 approval
->handler_instance
= g_object_ref (channel
);
1125 handle
= tp_channel_get_handle (channel
, NULL
);
1127 empathy_tp_contact_factory_get_from_handle (connection
, handle
,
1128 event_manager_ft_got_contact_cb
, approval
, NULL
, G_OBJECT (self
));
1130 else if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION
)
1133 const gchar
* const *available_mechanisms
;
1135 props
= tp_channel_borrow_immutable_properties (channel
);
1136 available_mechanisms
= tp_asv_get_boxed (props
,
1137 TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_AVAILABLE_MECHANISMS
,
1140 if (tp_strv_contains (available_mechanisms
, "X-TELEPATHY-PASSWORD"))
1142 event_manager_add (approval
->manager
, account
, NULL
,
1143 EMPATHY_EVENT_TYPE_AUTH
,
1144 GTK_STOCK_DIALOG_AUTHENTICATION
,
1145 tp_account_get_display_name (account
),
1146 _("Password required"), approval
,
1147 event_manager_auth_process_func
, NULL
);
1151 GError error
= { TP_ERRORS
, TP_ERROR_NOT_IMPLEMENTED
,
1152 "Support only X-TELEPATHY-PASSWORD auth method" };
1154 tp_add_dispatch_operation_context_fail (context
, &error
);
1160 GError error
= { TP_ERRORS
, TP_ERROR_INVALID_ARGUMENT
,
1161 "Invalid channel type" };
1163 DEBUG ("Unknown channel type (%s), ignoring..",
1164 g_quark_to_string (channel_type
));
1166 tp_add_dispatch_operation_context_fail (context
, &error
);
1171 tp_add_dispatch_operation_context_accept (context
);
1175 event_pending_subscribe_func (EventPriv
*event
)
1177 empathy_subscription_dialog_show (event
->public.contact
, event
->public.header
,
1179 event_remove (event
);
1183 check_publish_state (EmpathyEventManager
*self
,
1184 TpContact
*tp_contact
)
1186 EmpathyEventManagerPriv
*priv
= GET_PRIV (self
);
1187 gchar
*header
, *event_msg
;
1188 TpSubscriptionState state
;
1189 EmpathyContact
*contact
;
1190 const gchar
*message
;
1192 state
= tp_contact_get_publish_state (tp_contact
);
1194 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
1196 if (state
!= TP_SUBSCRIPTION_STATE_ASK
)
1200 for (l
= priv
->events
; l
; l
= l
->next
)
1202 EventPriv
*event
= l
->data
;
1204 if (event
->public.contact
== contact
&&
1205 event
->func
== event_pending_subscribe_func
)
1207 event_remove (event
);
1215 header
= g_strdup_printf (
1216 _("%s would like permission to see when you are online"),
1217 empathy_contact_get_alias (contact
));
1219 message
= tp_contact_get_publish_request (tp_contact
);
1221 if (!EMP_STR_EMPTY (message
))
1222 event_msg
= g_strdup_printf (_("\nMessage: %s"), message
);
1226 event_manager_add (self
, NULL
, contact
, EMPATHY_EVENT_TYPE_SUBSCRIPTION
,
1227 GTK_STOCK_DIALOG_QUESTION
, header
, event_msg
, NULL
,
1228 event_pending_subscribe_func
, NULL
);
1234 g_object_unref (contact
);
1238 event_manager_publish_state_changed_cb (TpContact
*contact
,
1240 EmpathyEventManager
*self
)
1242 check_publish_state (self
, contact
);
1246 event_manager_presence_changed_cb (EmpathyContact
*contact
,
1247 TpConnectionPresenceType current
,
1248 TpConnectionPresenceType previous
,
1249 EmpathyEventManager
*manager
)
1251 EmpathyEventManagerPriv
*priv
= GET_PRIV (manager
);
1253 EmpathyPresenceManager
*presence_mgr
;
1254 GtkWidget
*window
= empathy_roster_window_dup ();
1256 account
= empathy_contact_get_account (contact
);
1257 presence_mgr
= empathy_presence_manager_dup_singleton ();
1259 if (empathy_presence_manager_account_is_just_connected (presence_mgr
, account
))
1262 if (tp_connection_presence_type_cmp_availability (previous
,
1263 TP_CONNECTION_PRESENCE_TYPE_OFFLINE
) > 0)
1265 /* contact was online */
1266 if (tp_connection_presence_type_cmp_availability (current
,
1267 TP_CONNECTION_PRESENCE_TYPE_OFFLINE
) <= 0)
1269 /* someone is logging off */
1270 empathy_sound_manager_play (priv
->sound_mgr
, window
,
1271 EMPATHY_SOUND_CONTACT_DISCONNECTED
);
1273 if (g_settings_get_boolean (priv
->gsettings_notif
,
1274 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT
))
1276 event_manager_add (manager
, NULL
, contact
,
1277 EMPATHY_EVENT_TYPE_PRESENCE_OFFLINE
,
1278 EMPATHY_IMAGE_AVATAR_DEFAULT
,
1279 empathy_contact_get_alias (contact
), _("Disconnected"),
1286 /* contact was offline */
1287 if (tp_connection_presence_type_cmp_availability (current
,
1288 TP_CONNECTION_PRESENCE_TYPE_OFFLINE
) > 0)
1290 /* someone is logging in */
1291 empathy_sound_manager_play (priv
->sound_mgr
, window
,
1292 EMPATHY_SOUND_CONTACT_CONNECTED
);
1294 if (g_settings_get_boolean (priv
->gsettings_notif
,
1295 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN
))
1297 event_manager_add (manager
, NULL
, contact
,
1298 EMPATHY_EVENT_TYPE_PRESENCE_ONLINE
,
1299 EMPATHY_IMAGE_AVATAR_DEFAULT
,
1300 empathy_contact_get_alias (contact
), _("Connected"),
1307 g_object_unref (presence_mgr
);
1308 g_object_unref (window
);
1312 event_manager_constructor (GType type
,
1314 GObjectConstructParam
*props
)
1318 if (manager_singleton
) {
1319 retval
= g_object_ref (manager_singleton
);
1321 retval
= G_OBJECT_CLASS (empathy_event_manager_parent_class
)->constructor
1322 (type
, n_props
, props
);
1324 manager_singleton
= EMPATHY_EVENT_MANAGER (retval
);
1325 g_object_add_weak_pointer (retval
, (gpointer
) &manager_singleton
);
1332 event_manager_finalize (GObject
*object
)
1334 EmpathyEventManagerPriv
*priv
= GET_PRIV (object
);
1336 if (priv
->ringing
> 0)
1337 empathy_sound_manager_stop (priv
->sound_mgr
, EMPATHY_SOUND_PHONE_INCOMING
);
1339 g_slist_foreach (priv
->events
, (GFunc
) event_free
, NULL
);
1340 g_slist_free (priv
->events
);
1341 g_slist_foreach (priv
->approvals
, (GFunc
) event_manager_approval_free
, NULL
);
1342 g_slist_free (priv
->approvals
);
1343 g_object_unref (priv
->conn_aggregator
);
1344 g_object_unref (priv
->approver
);
1345 g_object_unref (priv
->auth_approver
);
1346 g_object_unref (priv
->gsettings_notif
);
1347 g_object_unref (priv
->gsettings_ui
);
1348 g_object_unref (priv
->sound_mgr
);
1349 g_hash_table_unref (priv
->contacts
);
1353 empathy_event_manager_class_init (EmpathyEventManagerClass
*klass
)
1355 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
1357 object_class
->finalize
= event_manager_finalize
;
1358 object_class
->constructor
= event_manager_constructor
;
1360 signals
[EVENT_ADDED
] =
1361 g_signal_new ("event-added",
1362 G_TYPE_FROM_CLASS (klass
),
1366 g_cclosure_marshal_generic
,
1370 signals
[EVENT_REMOVED
] =
1371 g_signal_new ("event-removed",
1372 G_TYPE_FROM_CLASS (klass
),
1376 g_cclosure_marshal_generic
,
1377 G_TYPE_NONE
, 1, G_TYPE_POINTER
);
1379 signals
[EVENT_UPDATED
] =
1380 g_signal_new ("event-updated",
1381 G_TYPE_FROM_CLASS (klass
),
1385 g_cclosure_marshal_generic
,
1386 G_TYPE_NONE
, 1, G_TYPE_POINTER
);
1388 g_type_class_add_private (object_class
, sizeof (EmpathyEventManagerPriv
));
1392 contact_list_changed_cb (EmpathyConnectionAggregator
*aggregator
,
1395 EmpathyEventManager
*self
)
1397 EmpathyEventManagerPriv
*priv
= GET_PRIV (self
);
1400 for (i
= 0; i
< added
->len
; i
++)
1402 TpContact
*tp_contact
= g_ptr_array_index (added
, i
);
1403 EmpathyContact
*contact
;
1405 if (g_hash_table_lookup (priv
->contacts
, tp_contact
) != NULL
)
1408 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
1410 tp_g_signal_connect_object (contact
, "presence-changed",
1411 G_CALLBACK (event_manager_presence_changed_cb
), self
, 0);
1413 tp_g_signal_connect_object (tp_contact
, "notify::publish-state",
1414 G_CALLBACK (event_manager_publish_state_changed_cb
), self
, 0);
1416 check_publish_state (self
, tp_contact
);
1418 /* Pass ownership to the hash table */
1419 g_hash_table_insert (priv
->contacts
, g_object_ref (tp_contact
), contact
);
1422 for (i
= 0; i
< removed
->len
; i
++)
1424 TpContact
*tp_contact
= g_ptr_array_index (removed
, i
);
1425 EmpathyContact
*contact
;
1427 contact
= g_hash_table_lookup (priv
->contacts
, tp_contact
);
1428 if (contact
== NULL
)
1431 g_signal_handlers_disconnect_by_func (contact
,
1432 event_manager_presence_changed_cb
, self
);
1434 g_signal_handlers_disconnect_by_func (tp_contact
,
1435 event_manager_publish_state_changed_cb
, self
);
1437 g_hash_table_remove (priv
->contacts
, tp_contact
);
1442 empathy_event_manager_init (EmpathyEventManager
*manager
)
1444 EmpathyEventManagerPriv
*priv
= G_TYPE_INSTANCE_GET_PRIVATE (manager
,
1445 EMPATHY_TYPE_EVENT_MANAGER
, EmpathyEventManagerPriv
);
1446 GError
*error
= NULL
;
1447 TpAccountManager
*am
;
1448 GPtrArray
*contacts
, *empty
;
1450 manager
->priv
= priv
;
1452 priv
->gsettings_notif
= g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA
);
1453 priv
->gsettings_ui
= g_settings_new (EMPATHY_PREFS_UI_SCHEMA
);
1455 priv
->sound_mgr
= empathy_sound_manager_dup_singleton ();
1457 priv
->contacts
= g_hash_table_new_full (NULL
, NULL
, g_object_unref
,
1460 priv
->conn_aggregator
= empathy_connection_aggregator_dup_singleton ();
1462 tp_g_signal_connect_object (priv
->conn_aggregator
, "contact-list-changed",
1463 G_CALLBACK (contact_list_changed_cb
), manager
, 0);
1465 contacts
= empathy_connection_aggregator_dup_all_contacts (
1466 priv
->conn_aggregator
);
1468 empty
= g_ptr_array_new ();
1470 contact_list_changed_cb (priv
->conn_aggregator
, contacts
, empty
, manager
);
1472 g_ptr_array_unref (contacts
);
1473 g_ptr_array_unref (empty
);
1475 am
= tp_account_manager_dup ();
1477 priv
->approver
= tp_simple_approver_new_with_am (am
, "Empathy.EventManager",
1478 FALSE
, approve_channels
, manager
, NULL
);
1480 /* Private text channels */
1481 tp_base_client_take_approver_filter (priv
->approver
,
1483 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
, TP_IFACE_CHANNEL_TYPE_TEXT
,
1484 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
1487 /* Muc text channels */
1488 tp_base_client_take_approver_filter (priv
->approver
,
1490 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
, TP_IFACE_CHANNEL_TYPE_TEXT
,
1491 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_ROOM
,
1495 tp_base_client_take_approver_filter (priv
->approver
,
1497 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1498 TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER
,
1499 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
1503 tp_base_client_take_approver_filter (priv
->approver
,
1505 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1506 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA
,
1507 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
1509 tp_base_client_take_approver_filter (priv
->approver
,
1511 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1512 TP_IFACE_CHANNEL_TYPE_CALL
,
1513 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
, G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
1516 /* I don't feel good about doing this, and I'm sorry, but the
1517 * capabilities connection feature is added earlier because it's
1518 * needed for EmpathyTpChat. If the capabilities feature is required
1519 * then preparing an auth channel (which of course appears in the
1520 * CONNECTING state) will never be prepared. So the options are
1521 * either to create another approver like I've done, or to port
1522 * EmpathyTpChat and its users to not depend on the connection being
1523 * prepared with capabilities. I chose the former, obviously. :-) */
1525 priv
->auth_approver
= tp_simple_approver_new_with_am (am
,
1526 "Empathy.AuthEventManager", FALSE
, approve_channels
, manager
,
1529 /* SASL auth channels */
1530 tp_base_client_take_approver_filter (priv
->auth_approver
,
1532 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1533 TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION
,
1534 TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION_AUTHENTICATION_METHOD
,
1536 TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION
,
1539 if (!tp_base_client_register (priv
->approver
, &error
))
1541 DEBUG ("Failed to register Approver: %s", error
->message
);
1542 g_error_free (error
);
1545 if (!tp_base_client_register (priv
->auth_approver
, &error
))
1547 DEBUG ("Failed to register auth Approver: %s", error
->message
);
1548 g_error_free (error
);
1551 g_object_unref (am
);
1554 EmpathyEventManager
*
1555 empathy_event_manager_dup_singleton (void)
1557 return g_object_new (EMPATHY_TYPE_EVENT_MANAGER
, NULL
);
1561 empathy_event_manager_get_events (EmpathyEventManager
*manager
)
1563 EmpathyEventManagerPriv
*priv
= GET_PRIV (manager
);
1565 g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager
), NULL
);
1567 return priv
->events
;
1571 empathy_event_manager_get_top_event (EmpathyEventManager
*manager
)
1573 EmpathyEventManagerPriv
*priv
= GET_PRIV (manager
);
1575 g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager
), NULL
);
1577 return priv
->events
? priv
->events
->data
: NULL
;
1581 empathy_event_activate (EmpathyEvent
*event_public
)
1583 EventPriv
*event
= (EventPriv
*) event_public
;
1585 g_return_if_fail (event_public
!= NULL
);
1588 event
->func (event
);
1590 event_remove (event
);
1594 empathy_event_inhibit_updates (EmpathyEvent
*event_public
)
1596 EventPriv
*event
= (EventPriv
*) event_public
;
1598 g_return_if_fail (event_public
!= NULL
);
1600 event
->inhibit
= TRUE
;
1604 empathy_event_approve (EmpathyEvent
*event_public
)
1606 EventPriv
*event
= (EventPriv
*) event_public
;
1608 g_return_if_fail (event_public
!= NULL
);
1610 event_manager_approval_approve (event
->approval
);
1614 empathy_event_decline (EmpathyEvent
*event_public
)
1616 EventPriv
*event
= (EventPriv
*) event_public
;
1618 g_return_if_fail (event_public
!= NULL
);
1620 reject_approval (event
->approval
);