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>
31 #include <libempathy/empathy-dispatcher.h>
32 #include <libempathy/empathy-idle.h>
33 #include <libempathy/empathy-tp-contact-factory.h>
34 #include <libempathy/empathy-contact-manager.h>
35 #include <libempathy/empathy-tp-chat.h>
36 #include <libempathy/empathy-tp-call.h>
37 #include <libempathy/empathy-tp-file.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-call-factory.h>
41 #include <extensions/extensions.h>
43 #include <libempathy-gtk/empathy-conf.h>
44 #include <libempathy-gtk/empathy-images.h>
45 #include <libempathy-gtk/empathy-contact-dialogs.h>
46 #include <libempathy-gtk/empathy-sound.h>
48 #include "empathy-event-manager.h"
49 #include "empathy-main-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 /* The time interval in milliseconds between 2 incoming rings */
59 #define MS_BETWEEN_RING 500
62 EmpathyEventManager *manager;
63 EmpathyDispatchOperation *operation;
64 gulong approved_handler;
65 gulong claimed_handler;
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 } EventManagerApproval;
77 EmpathyDispatcher *dispatcher;
78 EmpathyContactManager *contact_manager;
80 /* Ongoing approvals */
84 } EmpathyEventManagerPriv;
86 typedef struct _EventPriv EventPriv;
87 typedef void (*EventFunc) (EventPriv *event);
91 EmpathyEventManager *manager;
92 EventManagerApproval *approval;
96 guint autoremove_timeout_id;
106 static guint signals[LAST_SIGNAL];
108 G_DEFINE_TYPE (EmpathyEventManager, empathy_event_manager, G_TYPE_OBJECT);
110 static EmpathyEventManager * manager_singleton = NULL;
112 static EventManagerApproval *
113 event_manager_approval_new (EmpathyEventManager *manager,
114 EmpathyDispatchOperation *operation)
116 EventManagerApproval *result = g_slice_new0 (EventManagerApproval);
117 result->operation = g_object_ref (operation);
118 result->manager = manager;
124 event_manager_approval_free (EventManagerApproval *approval)
126 g_signal_handler_disconnect (approval->operation,
127 approval->approved_handler);
128 g_signal_handler_disconnect (approval->operation,
129 approval->claimed_handler);
130 g_signal_handler_disconnect (approval->operation,
131 approval->invalidated_handler);
132 g_object_unref (approval->operation);
134 if (approval->handler != 0)
135 g_signal_handler_disconnect (approval->handler_instance,
138 if (approval->contact != NULL)
139 g_object_unref (approval->contact);
141 if (approval->dialog != NULL)
143 gtk_widget_destroy (approval->dialog);
146 g_slice_free (EventManagerApproval, approval);
149 static void event_remove (EventPriv *event);
152 event_free (EventPriv *event)
154 g_free (event->public.icon_name);
155 g_free (event->public.header);
156 g_free (event->public.message);
158 if (event->autoremove_timeout_id != 0)
159 g_source_remove (event->autoremove_timeout_id);
161 if (event->public.contact)
163 g_object_unref (event->public.contact);
166 g_slice_free (EventPriv, event);
170 event_remove (EventPriv *event)
172 EmpathyEventManagerPriv *priv = GET_PRIV (event->manager);
174 DEBUG ("Removing event %p", event);
176 priv->events = g_slist_remove (priv->events, event);
177 g_signal_emit (event->manager, signals[EVENT_REMOVED], 0, event);
182 autoremove_event_timeout_cb (EventPriv *event)
184 event->autoremove_timeout_id = 0;
185 event_remove (event);
190 event_manager_add (EmpathyEventManager *manager,
191 EmpathyContact *contact,
192 EmpathyEventType type,
193 const gchar *icon_name,
195 const gchar *message,
196 EventManagerApproval *approval,
200 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
203 event = g_slice_new0 (EventPriv);
204 event->public.contact = contact ? g_object_ref (contact) : NULL;
205 event->public.type = type;
206 event->public.icon_name = g_strdup (icon_name);
207 event->public.header = g_strdup (header);
208 event->public.message = g_strdup (message);
209 event->public.must_ack = (func != NULL);
210 event->inhibit = FALSE;
212 event->user_data = user_data;
213 event->manager = manager;
214 event->approval = approval;
216 DEBUG ("Adding event %p", event);
217 priv->events = g_slist_prepend (priv->events, event);
218 g_signal_emit (event->manager, signals[EVENT_ADDED], 0, event);
220 if (!event->public.must_ack)
222 event->autoremove_timeout_id = g_timeout_add_seconds (
223 NOTIFICATION_TIMEOUT, (GSourceFunc) autoremove_event_timeout_cb,
229 event_channel_process_func (EventPriv *event)
231 empathy_dispatch_operation_approve (event->approval->operation);
235 event_text_channel_process_func (EventPriv *event)
237 EmpathyTpChat *tp_chat;
239 if (event->approval->handler != 0)
241 tp_chat = EMPATHY_TP_CHAT
242 (empathy_dispatch_operation_get_channel_wrapper (event->approval->operation));
244 g_signal_handler_disconnect (tp_chat, event->approval->handler);
245 event->approval->handler = 0;
248 empathy_dispatch_operation_approve (event->approval->operation);
252 event_lookup_by_approval (EmpathyEventManager *manager,
253 EventManagerApproval *approval)
255 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
257 EventPriv *retval = NULL;
259 for (l = priv->events; l; l = l->next)
261 EventPriv *event = l->data;
263 if (event->approval == approval)
274 event_update (EmpathyEventManager *manager, EventPriv *event,
275 const char *icon_name, const char *header, const char *msg)
277 g_free (event->public.icon_name);
278 g_free (event->public.header);
279 g_free (event->public.message);
281 event->public.icon_name = g_strdup (icon_name);
282 event->public.header = g_strdup (header);
283 event->public.message = g_strdup (msg);
285 g_signal_emit (manager, signals[EVENT_UPDATED], 0, event);
289 event_manager_call_window_confirmation_dialog_response_cb (GtkDialog *dialog,
290 gint response, gpointer user_data)
292 EventManagerApproval *approval = user_data;
294 gtk_widget_destroy (approval->dialog);
295 approval->dialog = NULL;
297 if (response != GTK_RESPONSE_ACCEPT)
299 EmpathyTpCall *call =
301 empathy_dispatch_operation_get_channel_wrapper (
302 approval->operation));
305 if (empathy_dispatch_operation_claim (approval->operation))
306 empathy_tp_call_close (call);
307 g_object_unref (call);
312 EmpathyCallFactory *factory = empathy_call_factory_get ();
313 empathy_call_factory_claim_channel (factory, approval->operation);
318 event_channel_process_voip_func (EventPriv *event)
326 if (event->approval->dialog != NULL)
328 gtk_window_present (GTK_WINDOW (event->approval->dialog));
332 call = EMPATHY_TP_CALL (empathy_dispatch_operation_get_channel_wrapper (
333 event->approval->operation));
335 video = empathy_tp_call_has_initial_video (call);
337 dialog = gtk_message_dialog_new (NULL, 0,
338 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
339 video ? _("Incoming video call"): _("Incoming call"));
341 gtk_message_dialog_format_secondary_text (
342 GTK_MESSAGE_DIALOG (dialog), video ?
343 _("%s is video calling you. Do you want to answer?"):
344 _("%s is calling you. Do you want to answer?"),
345 empathy_contact_get_name (event->approval->contact));
347 /* Set image of the dialog */
350 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
351 GTK_ICON_SIZE_DIALOG);
355 image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
356 GTK_ICON_SIZE_DIALOG);
359 gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
360 gtk_widget_show (image);
362 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
365 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
366 _("_Reject"), GTK_RESPONSE_REJECT);
367 image = gtk_image_new_from_icon_name ("call-stop",
368 GTK_ICON_SIZE_BUTTON);
369 gtk_button_set_image (GTK_BUTTON (button), image);
371 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
372 _("_Answer"), GTK_RESPONSE_ACCEPT);
374 image = gtk_image_new_from_icon_name ("call-start", GTK_ICON_SIZE_BUTTON);
375 gtk_button_set_image (GTK_BUTTON (button), image);
377 g_signal_connect (dialog, "response",
378 G_CALLBACK (event_manager_call_window_confirmation_dialog_response_cb),
381 gtk_widget_show (dialog);
383 event->approval->dialog = dialog;
387 event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat,
388 EmpathyMessage *message, EventManagerApproval *approval)
390 EmpathyContact *sender;
396 /* try to update the event if it's referring to a chat which is already in the
398 event = event_lookup_by_approval (approval->manager, approval);
400 sender = empathy_message_get_sender (message);
401 header = empathy_contact_get_name (sender);
402 msg = empathy_message_get_body (message);
404 channel = empathy_tp_chat_get_channel (tp_chat);
407 event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header, msg);
409 event_manager_add (approval->manager, sender, EMPATHY_EVENT_TYPE_CHAT,
410 EMPATHY_IMAGE_NEW_MESSAGE, header, msg, approval,
411 event_text_channel_process_func, NULL);
413 empathy_sound_play (empathy_main_window_get (),
414 EMPATHY_SOUND_CONVERSATION_NEW);
418 event_manager_approval_done (EventManagerApproval *approval)
420 EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
423 if (approval->operation != NULL)
427 channel_type = empathy_dispatch_operation_get_channel_type_id (
428 approval->operation);
429 if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
432 if (priv->ringing == 0)
433 empathy_sound_stop (EMPATHY_SOUND_PHONE_INCOMING);
437 priv->approvals = g_slist_remove (priv->approvals, approval);
439 for (l = priv->events; l; l = l->next)
441 EventPriv *event = l->data;
443 if (event->approval == approval)
445 event_remove (event);
450 event_manager_approval_free (approval);
454 event_manager_operation_approved_cb (EmpathyDispatchOperation *operation,
455 EventManagerApproval *approval)
457 event_manager_approval_done (approval);
461 event_manager_operation_claimed_cb (EmpathyDispatchOperation *operation,
462 EventManagerApproval *approval)
464 event_manager_approval_done (approval);
468 event_manager_operation_invalidated_cb (EmpathyDispatchOperation *operation,
469 guint domain, gint code, gchar *message,
470 EventManagerApproval *approval)
472 event_manager_approval_done (approval);
476 event_manager_media_channel_got_contact (EventManagerApproval *approval)
478 EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
483 call = EMPATHY_TP_CALL (empathy_dispatch_operation_get_channel_wrapper (
484 approval->operation));
486 video = empathy_tp_call_has_initial_video (call);
488 header = g_strdup_printf (
489 video ? _("Incoming video call from %s") :_("Incoming call from %s"),
490 empathy_contact_get_name (approval->contact));
492 event_manager_add (approval->manager, approval->contact,
493 EMPATHY_EVENT_TYPE_VOIP,
494 video ? EMPATHY_IMAGE_VIDEO_CALL : EMPATHY_IMAGE_VOIP,
495 header, NULL, approval,
496 event_channel_process_voip_func, NULL);
501 if (priv->ringing == 1)
502 empathy_sound_start_playing (empathy_main_window_get (),
503 EMPATHY_SOUND_PHONE_INCOMING, MS_BETWEEN_RING);
507 event_manager_media_channel_contact_changed_cb (EmpathyTpCall *call,
508 GParamSpec *param, EventManagerApproval *approval)
510 EmpathyContact *contact;
512 g_object_get (G_OBJECT (call), "contact", &contact, NULL);
517 approval->contact = contact;
518 event_manager_media_channel_got_contact (approval);
522 invite_dialog_response_cb (GtkDialog *dialog,
524 EventManagerApproval *approval)
526 EmpathyTpChat *tp_chat;
528 TpHandle self_handle;
531 gtk_widget_destroy (GTK_WIDGET (approval->dialog));
532 approval->dialog = NULL;
534 tp_chat = EMPATHY_TP_CHAT (empathy_dispatch_operation_get_channel_wrapper (
535 approval->operation));
537 if (response != GTK_RESPONSE_OK)
540 DEBUG ("Muc invitation rejected");
542 if (empathy_dispatch_operation_claim (approval->operation))
543 empathy_tp_chat_leave (tp_chat);
547 DEBUG ("Muc invitation accepted");
550 channel = empathy_tp_chat_get_channel (tp_chat);
552 self_handle = tp_channel_group_get_self_handle (channel);
553 members = g_array_sized_new (FALSE, FALSE, sizeof (TpHandle), 1);
554 g_array_append_val (members, self_handle);
556 tp_cli_channel_interface_group_call_add_members (channel, -1, members,
557 "", NULL, NULL, NULL, NULL);
559 empathy_dispatch_operation_approve (approval->operation);
561 g_array_free (members, TRUE);
565 event_room_channel_process_func (EventPriv *event)
567 GtkWidget *dialog, *button, *image;
568 TpChannel *channel = empathy_dispatch_operation_get_channel (
569 event->approval->operation);
571 if (event->approval->dialog != NULL)
573 gtk_window_present (GTK_WINDOW (event->approval->dialog));
578 dialog = gtk_message_dialog_new (NULL, 0,
579 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Room invitation"));
581 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
582 _("%s is inviting you to join %s"),
583 empathy_contact_get_name (event->approval->contact),
584 tp_channel_get_identifier (channel));
586 gtk_dialog_set_default_response (GTK_DIALOG (dialog),
589 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
590 _("_Decline"), GTK_RESPONSE_CANCEL);
591 image = gtk_image_new_from_icon_name (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
592 gtk_button_set_image (GTK_BUTTON (button), image);
594 button = gtk_dialog_add_button (GTK_DIALOG (dialog),
595 _("_Join"), GTK_RESPONSE_OK);
596 image = gtk_image_new_from_icon_name (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
597 gtk_button_set_image (GTK_BUTTON (button), image);
599 g_signal_connect (dialog, "response",
600 G_CALLBACK (invite_dialog_response_cb), event->approval);
602 gtk_widget_show (dialog);
604 event->approval->dialog = dialog;
608 event_manager_muc_invite_got_contact_cb (EmpathyTpContactFactory *factory,
609 EmpathyContact *contact,
614 EventManagerApproval *approval = (EventManagerApproval *) user_data;
616 const gchar *invite_msg;
618 TpHandle self_handle;
622 /* FIXME: We should probably still display the event */
623 DEBUG ("Error: %s", error->message);
627 approval->contact = g_object_ref (contact);
628 channel = empathy_dispatch_operation_get_channel (approval->operation);
630 self_handle = tp_channel_group_get_self_handle (channel);
631 tp_channel_group_get_local_pending_info (channel, self_handle, NULL, NULL,
634 msg = g_strdup_printf (_("%s invited you to join %s"),
635 empathy_contact_get_name (approval->contact),
636 tp_channel_get_identifier (channel));
638 event_manager_add (approval->manager, approval->contact,
639 EMPATHY_EVENT_TYPE_CHAT, EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg,
640 approval, event_room_channel_process_func, NULL);
642 empathy_sound_play (empathy_main_window_get (),
643 EMPATHY_SOUND_CONVERSATION_NEW);
649 event_manager_ft_got_contact_cb (EmpathyTpContactFactory *factory,
650 EmpathyContact *contact,
655 EventManagerApproval *approval = (EventManagerApproval *) user_data;
658 approval->contact = g_object_ref (contact);
660 header = g_strdup_printf (_("Incoming file transfer from %s"),
661 empathy_contact_get_name (approval->contact));
663 event_manager_add (approval->manager, approval->contact,
664 EMPATHY_EVENT_TYPE_TRANSFER, EMPATHY_IMAGE_DOCUMENT_SEND, header, NULL,
665 approval, event_channel_process_func, NULL);
667 /* FIXME better sound for incoming file transfers ?*/
668 empathy_sound_play (empathy_main_window_get (),
669 EMPATHY_SOUND_CONVERSATION_NEW);
675 event_manager_approve_channel_cb (EmpathyDispatcher *dispatcher,
676 EmpathyDispatchOperation *operation, EmpathyEventManager *manager)
678 const gchar *channel_type;
679 EventManagerApproval *approval;
680 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
682 channel_type = empathy_dispatch_operation_get_channel_type (operation);
684 approval = event_manager_approval_new (manager, operation);
685 priv->approvals = g_slist_prepend (priv->approvals, approval);
687 approval->approved_handler = g_signal_connect (operation, "approved",
688 G_CALLBACK (event_manager_operation_approved_cb), approval);
690 approval->claimed_handler = g_signal_connect (operation, "claimed",
691 G_CALLBACK (event_manager_operation_claimed_cb), approval);
693 approval->invalidated_handler = g_signal_connect (operation, "invalidated",
694 G_CALLBACK (event_manager_operation_invalidated_cb), approval);
696 if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT))
698 EmpathyTpChat *tp_chat =
700 empathy_dispatch_operation_get_channel_wrapper (operation));
701 TpChannel *channel = empathy_tp_chat_get_channel (tp_chat);
703 if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
705 /* Are we in local-pending ? */
706 TpHandle self_handle, inviter;
708 self_handle = tp_channel_group_get_self_handle (channel);
710 if (self_handle != 0 && tp_channel_group_get_local_pending_info (
711 channel, self_handle, &inviter, NULL, NULL))
713 /* We are invited to a room */
714 EmpathyTpContactFactory *factory;
715 TpConnection *connection;
717 DEBUG ("Have been invited to %s. Ask user if he wants to accept",
718 tp_channel_get_identifier (channel));
720 connection = empathy_tp_chat_get_connection (tp_chat);
721 factory = empathy_tp_contact_factory_dup_singleton (connection);
723 empathy_tp_contact_factory_get_from_handle (factory,
724 inviter, event_manager_muc_invite_got_contact_cb,
725 approval, NULL, G_OBJECT (manager));
727 g_object_unref (factory);
731 /* if we are not invited, let's wait for the first message */
734 /* 1-1 text channel, wait for the first message */
735 approval->handler = g_signal_connect (tp_chat, "message-received",
736 G_CALLBACK (event_manager_chat_message_received_cb), approval);
737 approval->handler_instance = G_OBJECT (tp_chat);
739 else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
741 EmpathyContact *contact;
742 EmpathyTpCall *call = EMPATHY_TP_CALL (
743 empathy_dispatch_operation_get_channel_wrapper (operation));
745 g_object_get (G_OBJECT (call), "contact", &contact, NULL);
749 g_signal_connect (call, "notify::contact",
750 G_CALLBACK (event_manager_media_channel_contact_changed_cb),
755 approval->contact = contact;
756 event_manager_media_channel_got_contact (approval);
760 else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
763 TpConnection *connection;
765 EmpathyTpContactFactory *factory;
767 channel = empathy_dispatch_operation_get_channel (operation);
768 handle = tp_channel_get_handle (channel, NULL);
770 connection = tp_channel_borrow_connection (channel);
771 factory = empathy_tp_contact_factory_dup_singleton (connection);
772 empathy_tp_contact_factory_get_from_handle (factory, handle,
773 event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (manager));
775 g_object_unref (factory);
779 DEBUG ("Unknown channel type (%s), ignoring..", channel_type);
784 event_pending_subscribe_func (EventPriv *event)
786 empathy_subscription_dialog_show (event->public.contact, NULL);
787 event_remove (event);
791 event_manager_pendings_changed_cb (EmpathyContactList *list,
792 EmpathyContact *contact, EmpathyContact *actor,
793 guint reason, gchar *message, gboolean is_pending,
794 EmpathyEventManager *manager)
796 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
797 gchar *header, *event_msg;
803 for (l = priv->events; l; l = l->next)
805 EventPriv *event = l->data;
807 if (event->public.contact == contact &&
808 event->func == event_pending_subscribe_func)
810 event_remove (event);
818 header = g_strdup_printf (_("Subscription requested by %s"),
819 empathy_contact_get_name (contact));
821 if (!EMP_STR_EMPTY (message))
822 event_msg = g_strdup_printf (_("\nMessage: %s"), message);
826 event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_SUBSCRIPTION,
827 GTK_STOCK_DIALOG_QUESTION, header, event_msg, NULL,
828 event_pending_subscribe_func, NULL);
835 event_manager_presence_changed_cb (EmpathyContactMonitor *monitor,
836 EmpathyContact *contact,
837 TpConnectionPresenceType current,
838 TpConnectionPresenceType previous,
839 EmpathyEventManager *manager)
842 gchar *header = NULL;
843 gboolean preference = FALSE;
846 account = empathy_contact_get_account (contact);
847 idle = empathy_idle_dup_singleton ();
849 if (empathy_idle_account_is_just_connected (idle, account))
852 if (tp_connection_presence_type_cmp_availability (previous,
853 TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
855 /* contact was online */
856 empathy_conf_get_bool (empathy_conf_get (),
857 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT, &preference);
858 if (preference && tp_connection_presence_type_cmp_availability (current,
859 TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
861 /* someone is logging off */
862 header = g_strdup_printf (_("%s is now offline."),
863 empathy_contact_get_name (contact));
865 event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE,
866 "stock_person", header, NULL, NULL, NULL, NULL);
871 /* contact was offline */
872 empathy_conf_get_bool (empathy_conf_get (),
873 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN, &preference);
874 if (preference && tp_connection_presence_type_cmp_availability (current,
875 TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
877 /* someone is logging in */
878 header = g_strdup_printf (_("%s is now online."),
879 empathy_contact_get_name (contact));
881 event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE,
882 "stock_person", header, NULL, NULL, NULL, NULL);
888 g_object_unref (idle);
893 event_manager_constructor (GType type,
895 GObjectConstructParam *props)
899 if (manager_singleton) {
900 retval = g_object_ref (manager_singleton);
902 retval = G_OBJECT_CLASS (empathy_event_manager_parent_class)->constructor
903 (type, n_props, props);
905 manager_singleton = EMPATHY_EVENT_MANAGER (retval);
906 g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
913 event_manager_finalize (GObject *object)
915 EmpathyEventManagerPriv *priv = GET_PRIV (object);
917 if (priv->ringing > 0)
918 empathy_sound_stop (EMPATHY_SOUND_PHONE_INCOMING);
920 g_slist_foreach (priv->events, (GFunc) event_free, NULL);
921 g_slist_free (priv->events);
922 g_slist_foreach (priv->approvals, (GFunc) event_manager_approval_free, NULL);
923 g_slist_free (priv->approvals);
924 g_object_unref (priv->contact_manager);
925 g_object_unref (priv->dispatcher);
929 empathy_event_manager_class_init (EmpathyEventManagerClass *klass)
931 GObjectClass *object_class = G_OBJECT_CLASS (klass);
933 object_class->finalize = event_manager_finalize;
934 object_class->constructor = event_manager_constructor;
936 signals[EVENT_ADDED] =
937 g_signal_new ("event-added",
938 G_TYPE_FROM_CLASS (klass),
942 g_cclosure_marshal_VOID__POINTER,
946 signals[EVENT_REMOVED] =
947 g_signal_new ("event-removed",
948 G_TYPE_FROM_CLASS (klass),
952 g_cclosure_marshal_VOID__POINTER,
953 G_TYPE_NONE, 1, G_TYPE_POINTER);
955 signals[EVENT_UPDATED] =
956 g_signal_new ("event-updated",
957 G_TYPE_FROM_CLASS (klass),
961 g_cclosure_marshal_VOID__POINTER,
962 G_TYPE_NONE, 1, G_TYPE_POINTER);
965 g_type_class_add_private (object_class, sizeof (EmpathyEventManagerPriv));
969 empathy_event_manager_init (EmpathyEventManager *manager)
971 EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
972 EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
973 EmpathyContactMonitor *monitor;
974 EmpathyContactList *list_iface;
976 list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_dup_singleton ());
977 monitor = empathy_contact_list_get_monitor (list_iface);
978 g_object_unref (list_iface);
980 manager->priv = priv;
982 priv->dispatcher = empathy_dispatcher_dup_singleton ();
983 priv->contact_manager = empathy_contact_manager_dup_singleton ();
984 g_signal_connect (priv->dispatcher, "approve",
985 G_CALLBACK (event_manager_approve_channel_cb), manager);
986 g_signal_connect (priv->contact_manager, "pendings-changed",
987 G_CALLBACK (event_manager_pendings_changed_cb), manager);
988 g_signal_connect (monitor, "contact-presence-changed",
989 G_CALLBACK (event_manager_presence_changed_cb), manager);
992 EmpathyEventManager *
993 empathy_event_manager_dup_singleton (void)
995 return g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL);
999 empathy_event_manager_get_events (EmpathyEventManager *manager)
1001 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1003 g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1005 return priv->events;
1009 empathy_event_manager_get_top_event (EmpathyEventManager *manager)
1011 EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1013 g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1015 return priv->events ? priv->events->data : NULL;
1019 empathy_event_activate (EmpathyEvent *event_public)
1021 EventPriv *event = (EventPriv *) event_public;
1023 g_return_if_fail (event_public != NULL);
1026 event->func (event);
1028 event_remove (event);
1032 empathy_event_inhibit_updates (EmpathyEvent *event_public)
1034 EventPriv *event = (EventPriv *) event_public;
1036 g_return_if_fail (event_public != NULL);
1038 event->inhibit = TRUE;