]> git.0d.be Git - empathy.git/blob - src/empathy-event-manager.c
empathy-tp-chat: ensure that we get a TpTextChannel
[empathy.git] / src / empathy-event-manager.c
1 /*
2  * Copyright (C) 2007-2008 Collabora Ltd.
3  *
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.
8  *
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.
13  *
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
17  *
18  * Authors: Xavier Claessens <xclaesse@gmail.com>
19  *          Sjoerd Simons <sjoerd.simons@collabora.co.uk>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25 #include <glib/gi18n.h>
26
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>
31
32 #include <libempathy/empathy-presence-manager.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-streamed-media.h>
37 #include <libempathy/empathy-tp-file.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-gsettings.h>
40
41 #include <extensions/extensions.h>
42
43 #include <libempathy-gtk/empathy-images.h>
44 #include <libempathy-gtk/empathy-contact-dialogs.h>
45 #include <libempathy-gtk/empathy-sound-manager.h>
46
47 #include "empathy-event-manager.h"
48 #include "empathy-main-window.h"
49
50 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
51 #include <libempathy/empathy-debug.h>
52
53 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyEventManager)
54
55 #define NOTIFICATION_TIMEOUT 2 /* seconds */
56
57 /* The time interval in milliseconds between 2 incoming rings */
58 #define MS_BETWEEN_RING 500
59
60 typedef struct {
61   EmpathyEventManager *manager;
62   TpChannelDispatchOperation *operation;
63   gulong invalidated_handler;
64   /* Remove contact if applicable */
65   EmpathyContact *contact;
66   /* option signal handler and it's instance */
67   gulong handler;
68   GObject *handler_instance;
69   /* optional accept widget */
70   GtkWidget *dialog;
71   /* Channel of the CDO that will be used during the approval */
72   TpChannel *main_channel;
73   gboolean auto_approved;
74 } EventManagerApproval;
75
76 typedef struct {
77   TpBaseClient *approver;
78   TpBaseClient *auth_approver;
79   EmpathyContactManager *contact_manager;
80   GSList *events;
81   /* Ongoing approvals */
82   GSList *approvals;
83
84   gint ringing;
85
86   GSettings *gsettings_notif;
87   GSettings *gsettings_ui;
88
89   EmpathySoundManager *sound_mgr;
90 } EmpathyEventManagerPriv;
91
92 typedef struct _EventPriv EventPriv;
93 typedef void (*EventFunc) (EventPriv *event);
94
95 struct _EventPriv {
96   EmpathyEvent public;
97   EmpathyEventManager *manager;
98   EventManagerApproval *approval;
99   EventFunc func;
100   gboolean inhibit;
101   gpointer user_data;
102   guint autoremove_timeout_id;
103 };
104
105 enum {
106   EVENT_ADDED,
107   EVENT_REMOVED,
108   EVENT_UPDATED,
109   LAST_SIGNAL
110 };
111
112 static guint signals[LAST_SIGNAL];
113
114 G_DEFINE_TYPE (EmpathyEventManager, empathy_event_manager, G_TYPE_OBJECT);
115
116 static EmpathyEventManager * manager_singleton = NULL;
117
118 static EventManagerApproval *
119 event_manager_approval_new (EmpathyEventManager *manager,
120   TpChannelDispatchOperation *operation,
121   TpChannel *main_channel)
122 {
123   EventManagerApproval *result = g_slice_new0 (EventManagerApproval);
124   result->operation = g_object_ref (operation);
125   result->manager = manager;
126   result->main_channel = g_object_ref (main_channel);
127
128   return result;
129 }
130
131 static void
132 event_manager_approval_free (EventManagerApproval *approval)
133 {
134   g_signal_handler_disconnect (approval->operation,
135     approval->invalidated_handler);
136   g_object_unref (approval->operation);
137
138   g_object_unref (approval->main_channel);
139
140   if (approval->handler != 0)
141     g_signal_handler_disconnect (approval->handler_instance,
142       approval->handler);
143
144   if (approval->handler_instance != NULL)
145     g_object_unref (approval->handler_instance);
146
147   if (approval->contact != NULL)
148     g_object_unref (approval->contact);
149
150   if (approval->dialog != NULL)
151     {
152       gtk_widget_destroy (approval->dialog);
153     }
154
155   g_slice_free (EventManagerApproval, approval);
156 }
157
158 static void
159 event_free (EventPriv *event)
160 {
161   g_free (event->public.icon_name);
162   g_free (event->public.header);
163   g_free (event->public.message);
164
165   if (event->autoremove_timeout_id != 0)
166     g_source_remove (event->autoremove_timeout_id);
167
168   tp_clear_object (&(event->public.contact));
169   tp_clear_object (&(event->public.account));
170
171   g_slice_free (EventPriv, event);
172 }
173
174 static void
175 event_remove (EventPriv *event)
176 {
177   EmpathyEventManagerPriv *priv = GET_PRIV (event->manager);
178
179   DEBUG ("Removing event %p", event);
180
181   priv->events = g_slist_remove (priv->events, event);
182   g_signal_emit (event->manager, signals[EVENT_REMOVED], 0, event);
183   event_free (event);
184 }
185
186 void
187 empathy_event_remove (EmpathyEvent *event_public)
188 {
189   EventPriv *event = (EventPriv *) event_public;
190
191   event_remove (event);
192 }
193
194 static gboolean
195 autoremove_event_timeout_cb (EventPriv *event)
196 {
197   event->autoremove_timeout_id = 0;
198   event_remove (event);
199   return FALSE;
200 }
201
202 static gboolean
203 display_notify_area (EmpathyEventManager *self)
204 {
205   EmpathyEventManagerPriv *priv = GET_PRIV (self);
206
207   return g_settings_get_boolean (priv->gsettings_ui,
208       EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA);
209 }
210
211 static void
212 event_manager_add (EmpathyEventManager *manager,
213     TpAccount *account,
214     EmpathyContact *contact,
215     EmpathyEventType type,
216     const gchar *icon_name,
217     const gchar *header,
218     const gchar *message,
219     EventManagerApproval *approval,
220     EventFunc func,
221     gpointer user_data)
222 {
223   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
224   EventPriv               *event;
225
226   event = g_slice_new0 (EventPriv);
227   event->public.account = account != NULL ? g_object_ref (account) : NULL;
228   event->public.contact = contact ? g_object_ref (contact) : NULL;
229   event->public.type = type;
230   event->public.icon_name = g_strdup (icon_name);
231   event->public.header = g_strdup (header);
232   event->public.message = g_strdup (message);
233   event->public.must_ack = (func != NULL);
234   event->inhibit = FALSE;
235   event->func = func;
236   event->user_data = user_data;
237   event->manager = manager;
238   event->approval = approval;
239
240   DEBUG ("Adding event %p", event);
241   priv->events = g_slist_prepend (priv->events, event);
242
243   if (!display_notify_area (manager))
244     {
245       /* Don't fire the 'event-added' signal as we activate the event now */
246       if (approval != NULL)
247         approval->auto_approved = TRUE;
248
249       empathy_event_activate (&event->public);
250       return;
251     }
252
253   g_signal_emit (event->manager, signals[EVENT_ADDED], 0, event);
254
255   if (!event->public.must_ack)
256     {
257       event->autoremove_timeout_id = g_timeout_add_seconds (
258           NOTIFICATION_TIMEOUT, (GSourceFunc) autoremove_event_timeout_cb,
259           event);
260     }
261 }
262
263 static void
264 handle_with_cb (GObject *source,
265     GAsyncResult *result,
266     gpointer user_data)
267 {
268   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
269   GError *error = NULL;
270
271   if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
272     {
273       DEBUG ("HandleWith failed: %s\n", error->message);
274       g_error_free (error);
275     }
276 }
277
278 static void
279 handle_with_time_cb (GObject *source,
280     GAsyncResult *result,
281     gpointer user_data)
282 {
283   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
284   GError *error = NULL;
285
286   if (!tp_channel_dispatch_operation_handle_with_time_finish (cdo, result,
287         &error))
288     {
289       if (g_error_matches (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED))
290         {
291           EventManagerApproval *approval = user_data;
292
293           DEBUG ("HandleWithTime() is not implemented, falling back to "
294               "HandleWith(). Please upgrade to telepathy-mission-control "
295               "5.5.0 or later");
296
297           tp_channel_dispatch_operation_handle_with_async (approval->operation,
298               NULL, handle_with_cb, approval);
299         }
300       else
301         {
302           DEBUG ("HandleWithTime failed: %s\n", error->message);
303         }
304       g_error_free (error);
305     }
306 }
307
308 static void
309 event_manager_approval_approve (EventManagerApproval *approval)
310 {
311   gint64 timestamp;
312
313   if (approval->auto_approved)
314     {
315       timestamp = TP_USER_ACTION_TIME_NOT_USER_ACTION;
316     }
317   else
318     {
319       timestamp = tp_user_action_time_from_x11 (gtk_get_current_event_time ());
320     }
321
322   g_assert (approval->operation != NULL);
323
324   tp_channel_dispatch_operation_handle_with_time_async (approval->operation,
325       NULL, timestamp, handle_with_time_cb, approval);
326 }
327
328 static void
329 event_channel_process_func (EventPriv *event)
330 {
331   event_manager_approval_approve (event->approval);
332 }
333
334 static void
335 event_text_channel_process_func (EventPriv *event)
336 {
337   EmpathyTpChat *tp_chat;
338   gint64 timestamp;
339
340   timestamp = tp_user_action_time_from_x11 (gtk_get_current_event_time ());
341
342   if (event->approval->handler != 0)
343     {
344       tp_chat = EMPATHY_TP_CHAT (event->approval->handler_instance);
345
346       g_signal_handler_disconnect (tp_chat, event->approval->handler);
347       event->approval->handler = 0;
348     }
349
350   event_manager_approval_approve (event->approval);
351 }
352
353 static EventPriv *
354 event_lookup_by_approval (EmpathyEventManager *manager,
355   EventManagerApproval *approval)
356 {
357   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
358   GSList *l;
359   EventPriv *retval = NULL;
360
361   for (l = priv->events; l; l = l->next)
362     {
363       EventPriv *event = l->data;
364
365       if (event->approval == approval)
366         {
367           retval = event;
368           break;
369         }
370     }
371
372   return retval;
373 }
374
375 static void
376 event_update (EmpathyEventManager *manager, EventPriv *event,
377   const char *icon_name, const char *header, const char *msg)
378 {
379   g_free (event->public.icon_name);
380   g_free (event->public.header);
381   g_free (event->public.message);
382
383   event->public.icon_name = g_strdup (icon_name);
384   event->public.header = g_strdup (header);
385   event->public.message = g_strdup (msg);
386
387   g_signal_emit (manager, signals[EVENT_UPDATED], 0, event);
388 }
389
390 static void
391 reject_channel_claim_cb (GObject *source,
392     GAsyncResult *result,
393     gpointer user_data)
394 {
395   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
396   GError *error = NULL;
397
398   if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error))
399     {
400       DEBUG ("Failed to claim channel: %s", error->message);
401
402       g_error_free (error);
403       goto out;
404     }
405
406   if (EMPATHY_IS_TP_STREAMED_MEDIA (user_data))
407     {
408       empathy_tp_streamed_media_close (user_data);
409     }
410   else if (EMPATHY_IS_TP_CHAT (user_data))
411     {
412       empathy_tp_chat_leave (user_data, "");
413     }
414   else if (EMPATHY_IS_TP_FILE (user_data))
415     {
416       empathy_tp_file_close (user_data);
417     }
418
419 out:
420   g_object_unref (user_data);
421 }
422
423 static void
424 reject_auth_channel_claim_cb (GObject *source,
425     GAsyncResult *result,
426     gpointer user_data)
427 {
428   TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
429   GError *error = NULL;
430
431   if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error))
432     {
433       DEBUG ("Failed to claim channel: %s", error->message);
434
435       g_error_free (error);
436       return;
437     }
438
439   tp_cli_channel_call_close (TP_CHANNEL (user_data), -1,
440       NULL, NULL, NULL, NULL);
441 }
442
443 static void
444 reject_approval (EventManagerApproval *approval)
445 {
446   /* We have to claim the channel before closing it */
447
448   /* Unfortunately, we need to special case the auth channels for the
449    * time being as they don't have a wrapper object handler in
450    * approval->handler_instance as they're not actually handled by
451    * this process, so we can just use a noddy callback to call Close()
452    * directly. */
453   if (approval->handler_instance != NULL)
454     {
455       tp_channel_dispatch_operation_claim_async (approval->operation,
456           reject_channel_claim_cb, g_object_ref (approval->handler_instance));
457     }
458   else if (tp_channel_get_channel_type_id (approval->main_channel)
459       == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION)
460     {
461       tp_channel_dispatch_operation_claim_async (approval->operation,
462           reject_auth_channel_claim_cb, approval->main_channel);
463     }
464 }
465
466 static void
467 event_manager_call_window_confirmation_dialog_response_cb (GtkDialog *dialog,
468   gint response, gpointer user_data)
469 {
470   EventManagerApproval *approval = user_data;
471
472   gtk_widget_destroy (approval->dialog);
473   approval->dialog = NULL;
474
475   if (response != GTK_RESPONSE_ACCEPT)
476     {
477       reject_approval (approval);
478     }
479   else
480     {
481       event_manager_approval_approve (approval);
482     }
483 }
484
485 static void
486 event_channel_process_voip_func (EventPriv *event)
487 {
488   GtkWidget *dialog;
489   GtkWidget *button;
490   GtkWidget *image;
491   EmpathyTpStreamedMedia *call;
492   gboolean video;
493   gchar *title;
494
495   if (event->approval->dialog != NULL)
496     {
497       gtk_window_present (GTK_WINDOW (event->approval->dialog));
498       return;
499     }
500
501   call = EMPATHY_TP_STREAMED_MEDIA (event->approval->handler_instance);
502
503   video = empathy_tp_streamed_media_has_initial_video (call);
504
505   dialog = gtk_message_dialog_new (NULL, 0,
506       GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
507       video ? _("Incoming video call"): _("Incoming call"));
508
509   gtk_message_dialog_format_secondary_text (
510     GTK_MESSAGE_DIALOG (dialog), video ?
511       _("%s is video calling you. Do you want to answer?"):
512       _("%s is calling you. Do you want to answer?"),
513       empathy_contact_get_alias (event->approval->contact));
514
515   title = g_strdup_printf (_("Incoming call from %s"),
516       empathy_contact_get_alias (event->approval->contact));
517
518   gtk_window_set_title (GTK_WINDOW (dialog), title);
519   g_free (title);
520
521   /* Set image of the dialog */
522   if (video)
523     {
524       image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
525           GTK_ICON_SIZE_DIALOG);
526     }
527   else
528     {
529       image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
530           GTK_ICON_SIZE_DIALOG);
531     }
532
533   gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
534   gtk_widget_show (image);
535
536   gtk_dialog_set_default_response (GTK_DIALOG (dialog),
537       GTK_RESPONSE_OK);
538
539   button = gtk_dialog_add_button (GTK_DIALOG (dialog),
540       _("_Reject"), GTK_RESPONSE_REJECT);
541   image = gtk_image_new_from_icon_name ("call-stop",
542     GTK_ICON_SIZE_BUTTON);
543   gtk_button_set_image (GTK_BUTTON (button), image);
544
545   button = gtk_dialog_add_button (GTK_DIALOG (dialog),
546       _("_Answer"), GTK_RESPONSE_ACCEPT);
547
548   image = gtk_image_new_from_icon_name ("call-start", GTK_ICON_SIZE_BUTTON);
549   gtk_button_set_image (GTK_BUTTON (button), image);
550
551   g_signal_connect (dialog, "response",
552       G_CALLBACK (event_manager_call_window_confirmation_dialog_response_cb),
553       event->approval);
554
555   gtk_widget_show (dialog);
556
557   event->approval->dialog = dialog;
558 }
559
560 static void
561 event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat,
562   EmpathyMessage *message,
563   EventManagerApproval *approval)
564 {
565   GtkWidget       *window;
566   EmpathyContact  *sender;
567   const gchar     *header;
568   const gchar     *msg;
569   TpChannel       *channel;
570   EventPriv       *event;
571   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
572
573   /* try to update the event if it's referring to a chat which is already in the
574    * queue. */
575   event = event_lookup_by_approval (approval->manager, approval);
576
577   sender = empathy_message_get_sender (message);
578
579   /* We only want to show incoming messages */
580   if (empathy_contact_is_user (sender))
581     return;
582
583   header = empathy_contact_get_alias (sender);
584   msg = empathy_message_get_body (message);
585
586   channel = empathy_tp_chat_get_channel (tp_chat);
587
588   if (event != NULL)
589     event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header,
590         msg);
591   else
592     event_manager_add (approval->manager, NULL, sender,
593         EMPATHY_EVENT_TYPE_CHAT, EMPATHY_IMAGE_NEW_MESSAGE, header, msg,
594         approval, event_text_channel_process_func, NULL);
595
596   window = empathy_main_window_dup ();
597
598   empathy_sound_manager_play (priv->sound_mgr, window,
599       EMPATHY_SOUND_CONVERSATION_NEW);
600
601   g_object_unref (window);
602 }
603
604 static void
605 event_manager_approval_done (EventManagerApproval *approval)
606 {
607   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
608   GSList                  *l;
609
610   if (approval->operation != NULL)
611     {
612       GQuark channel_type;
613
614       channel_type = tp_channel_get_channel_type_id (approval->main_channel);
615
616       if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
617         {
618           priv->ringing--;
619           if (priv->ringing == 0)
620             empathy_sound_manager_stop (priv->sound_mgr,
621                 EMPATHY_SOUND_PHONE_INCOMING);
622         }
623     }
624
625   priv->approvals = g_slist_remove (priv->approvals, approval);
626
627   for (l = priv->events; l; l = l->next)
628     {
629       EventPriv *event = l->data;
630
631       if (event->approval == approval)
632         {
633           event_remove (event);
634           break;
635         }
636     }
637
638   event_manager_approval_free (approval);
639 }
640
641 static void
642 cdo_invalidated_cb (TpProxy *cdo,
643     guint domain,
644     gint code,
645     gchar *message,
646     EventManagerApproval *approval)
647 {
648   DEBUG ("ChannelDispatchOperation has been invalidated: %s", message);
649
650   event_manager_approval_done (approval);
651 }
652
653 static void
654 event_manager_media_channel_got_contact (EventManagerApproval *approval)
655 {
656   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
657   GtkWidget *window = empathy_main_window_dup ();
658   gchar *header;
659   EmpathyTpStreamedMedia *call;
660   gboolean video;
661
662   call = EMPATHY_TP_STREAMED_MEDIA (approval->handler_instance);
663
664   video = empathy_tp_streamed_media_has_initial_video (call);
665
666   header = g_strdup_printf (
667     video ? _("Incoming video call from %s") :_("Incoming call from %s"),
668     empathy_contact_get_alias (approval->contact));
669
670   event_manager_add (approval->manager, NULL,
671       approval->contact, EMPATHY_EVENT_TYPE_VOIP,
672       video ? EMPATHY_IMAGE_VIDEO_CALL : EMPATHY_IMAGE_VOIP,
673       header, NULL, approval,
674       event_channel_process_voip_func, NULL);
675
676   g_free (header);
677
678   priv->ringing++;
679   if (priv->ringing == 1)
680     empathy_sound_manager_start_playing (priv->sound_mgr, window,
681         EMPATHY_SOUND_PHONE_INCOMING, MS_BETWEEN_RING);
682
683   g_object_unref (window);
684 }
685
686 static void
687 event_manager_media_channel_contact_changed_cb (EmpathyTpStreamedMedia *call,
688   GParamSpec *param, EventManagerApproval *approval)
689 {
690   EmpathyContact *contact;
691
692   g_object_get (G_OBJECT (call), "contact", &contact, NULL);
693
694   if (contact == NULL)
695     return;
696
697   approval->contact = contact;
698   event_manager_media_channel_got_contact (approval);
699 }
700
701 static void
702 invite_dialog_response_cb (GtkDialog *dialog,
703                            gint response,
704                            EventManagerApproval *approval)
705 {
706   EmpathyTpChat *tp_chat;
707
708   gtk_widget_destroy (GTK_WIDGET (approval->dialog));
709   approval->dialog = NULL;
710
711   tp_chat = EMPATHY_TP_CHAT (approval->handler_instance);
712
713   if (response != GTK_RESPONSE_OK)
714     {
715       /* close channel */
716       DEBUG ("Muc invitation rejected");
717
718       reject_approval (approval);
719
720       return;
721     }
722
723   DEBUG ("Muc invitation accepted");
724
725   /* We'll join the room when handling the channel */
726   event_manager_approval_approve (approval);
727 }
728
729 static void
730 event_room_channel_process_func (EventPriv *event)
731 {
732   GtkWidget *dialog, *button, *image;
733   TpChannel *channel = event->approval->main_channel;
734   gchar *title;
735
736   if (event->approval->dialog != NULL)
737     {
738       gtk_window_present (GTK_WINDOW (event->approval->dialog));
739       return;
740     }
741
742   /* create dialog */
743   dialog = gtk_message_dialog_new (NULL, 0,
744       GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Room invitation"));
745
746   title = g_strdup_printf (_("Invitation to join %s"),
747       tp_channel_get_identifier (channel));
748
749   gtk_window_set_title (GTK_WINDOW (dialog), title);
750   g_free (title);
751
752   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
753       _("%s is inviting you to join %s"),
754       empathy_contact_get_alias (event->approval->contact),
755       tp_channel_get_identifier (channel));
756
757   gtk_dialog_set_default_response (GTK_DIALOG (dialog),
758       GTK_RESPONSE_OK);
759
760   button = gtk_dialog_add_button (GTK_DIALOG (dialog),
761       _("_Decline"), GTK_RESPONSE_CANCEL);
762   image = gtk_image_new_from_icon_name (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
763   gtk_button_set_image (GTK_BUTTON (button), image);
764
765   button = gtk_dialog_add_button (GTK_DIALOG (dialog),
766       _("_Join"), GTK_RESPONSE_OK);
767   image = gtk_image_new_from_icon_name (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
768   gtk_button_set_image (GTK_BUTTON (button), image);
769
770   g_signal_connect (dialog, "response",
771       G_CALLBACK (invite_dialog_response_cb), event->approval);
772
773   gtk_widget_show (dialog);
774
775   event->approval->dialog = dialog;
776 }
777
778 static void
779 display_invite_room_dialog (EventManagerApproval *approval)
780 {
781   GtkWidget *window = empathy_main_window_dup ();
782   const gchar *invite_msg;
783   gchar *msg;
784   TpHandle self_handle;
785   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
786
787   self_handle = tp_channel_group_get_self_handle (approval->main_channel);
788   tp_channel_group_get_local_pending_info (approval->main_channel, self_handle,
789       NULL, NULL, &invite_msg);
790
791   if (approval->contact != NULL)
792     {
793       msg = g_strdup_printf (_("%s invited you to join %s"),
794           empathy_contact_get_alias (approval->contact),
795           tp_channel_get_identifier (approval->main_channel));
796     }
797   else
798     {
799       msg = g_strdup_printf (_("You have been invited to join %s"),
800           tp_channel_get_identifier (approval->main_channel));
801     }
802
803   event_manager_add (approval->manager, NULL,
804       approval->contact, EMPATHY_EVENT_TYPE_INVITATION,
805       EMPATHY_IMAGE_GROUP_MESSAGE, msg, invite_msg, approval,
806       event_room_channel_process_func, NULL);
807
808   empathy_sound_manager_play (priv->sound_mgr, window,
809       EMPATHY_SOUND_CONVERSATION_NEW);
810
811   g_free (msg);
812   g_object_unref (window);
813 }
814
815 static void
816 event_manager_muc_invite_got_contact_cb (TpConnection *connection,
817                                          EmpathyContact *contact,
818                                          const GError *error,
819                                          gpointer user_data,
820                                          GObject *object)
821 {
822   EventManagerApproval *approval = (EventManagerApproval *) user_data;
823
824   if (error != NULL)
825     {
826       DEBUG ("Error: %s", error->message);
827     }
828   else
829     {
830       approval->contact = g_object_ref (contact);
831     }
832
833   display_invite_room_dialog (approval);
834 }
835
836 static void
837 event_manager_ft_got_contact_cb (TpConnection *connection,
838                                  EmpathyContact *contact,
839                                  const GError *error,
840                                  gpointer user_data,
841                                  GObject *object)
842 {
843   EventManagerApproval *approval = (EventManagerApproval *) user_data;
844   GtkWidget *window = empathy_main_window_dup ();
845   char *header;
846   EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
847
848   approval->contact = g_object_ref (contact);
849
850   header = g_strdup_printf (_("Incoming file transfer from %s"),
851                             empathy_contact_get_alias (approval->contact));
852
853   event_manager_add (approval->manager, NULL,
854       approval->contact, EMPATHY_EVENT_TYPE_TRANSFER,
855       EMPATHY_IMAGE_DOCUMENT_SEND, header, NULL,
856       approval, event_channel_process_func, NULL);
857
858   /* FIXME better sound for incoming file transfers ?*/
859   empathy_sound_manager_play (priv->sound_mgr, window,
860       EMPATHY_SOUND_CONVERSATION_NEW);
861
862   g_free (header);
863   g_object_unref (window);
864 }
865
866 static void
867 event_manager_auth_process_func (EventPriv *event)
868 {
869   empathy_event_approve ((EmpathyEvent *) event);
870 }
871
872 /* If there is a file-transfer, media, or auth channel consider it as
873  * the main one. */
874 static TpChannel *
875 find_main_channel (GList *channels)
876 {
877   GList *l;
878   TpChannel *text = NULL;
879
880   for (l = channels; l != NULL; l = g_list_next (l))
881     {
882       TpChannel *channel = l->data;
883       GQuark channel_type;
884
885       if (tp_proxy_get_invalidated (channel) != NULL)
886         continue;
887
888       channel_type = tp_channel_get_channel_type_id (channel);
889
890       if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA ||
891           channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER ||
892           channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION)
893         return channel;
894
895       else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
896         text = channel;
897     }
898
899   return text;
900 }
901
902 static void
903 approve_channels (TpSimpleApprover *approver,
904     TpAccount *account,
905     TpConnection *connection,
906     GList *channels,
907     TpChannelDispatchOperation *dispatch_operation,
908     TpAddDispatchOperationContext *context,
909     gpointer user_data)
910 {
911   EmpathyEventManager *self = user_data;
912   EmpathyEventManagerPriv *priv = GET_PRIV (self);
913   TpChannel *channel;
914   EventManagerApproval *approval;
915   GQuark channel_type;
916
917   channel = find_main_channel (channels);
918   if (channel == NULL)
919     {
920       GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
921           "Unknown channel type" };
922
923       DEBUG ("Failed to find the main channel; ignoring");
924
925       tp_add_dispatch_operation_context_fail (context, &error);
926       return;
927     }
928
929   approval = event_manager_approval_new (self, dispatch_operation, channel);
930   priv->approvals = g_slist_prepend (priv->approvals, approval);
931
932   approval->invalidated_handler = g_signal_connect (dispatch_operation,
933       "invalidated", G_CALLBACK (cdo_invalidated_cb), approval);
934
935   channel_type = tp_channel_get_channel_type_id (channel);
936
937   if (TP_IS_TEXT_CHANNEL (channel))
938     {
939       EmpathyTpChat *tp_chat;
940
941       tp_chat = empathy_tp_chat_new (account, channel);
942       approval->handler_instance = G_OBJECT (tp_chat);
943
944       if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
945         {
946           /* Are we in local-pending ? */
947           TpHandle inviter;
948
949           if (empathy_tp_chat_is_invited (tp_chat, &inviter))
950             {
951               /* We are invited to a room */
952               DEBUG ("Have been invited to %s. Ask user if he wants to accept",
953                   tp_channel_get_identifier (channel));
954
955               if (inviter != 0)
956                 {
957                   empathy_tp_contact_factory_get_from_handle (connection,
958                       inviter, event_manager_muc_invite_got_contact_cb,
959                       approval, NULL, G_OBJECT (self));
960                 }
961               else
962                 {
963                   display_invite_room_dialog (approval);
964                 }
965
966               goto out;
967             }
968
969           /* We are not invited, approve the channel right now */
970           tp_add_dispatch_operation_context_accept (context);
971
972           approval->auto_approved = TRUE;
973           event_manager_approval_approve (approval);
974           return;
975         }
976
977       /* 1-1 text channel, wait for the first message */
978       approval->handler = g_signal_connect (tp_chat, "message-received",
979         G_CALLBACK (event_manager_chat_message_received_cb), approval);
980     }
981   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
982     {
983       EmpathyContact *contact;
984       EmpathyTpStreamedMedia *call = empathy_tp_streamed_media_new (account, channel);
985
986       approval->handler_instance = G_OBJECT (call);
987
988       g_object_get (G_OBJECT (call), "contact", &contact, NULL);
989
990       if (contact == NULL)
991         {
992           g_signal_connect (call, "notify::contact",
993             G_CALLBACK (event_manager_media_channel_contact_changed_cb),
994             approval);
995         }
996       else
997         {
998           approval->contact = contact;
999           event_manager_media_channel_got_contact (approval);
1000         }
1001
1002     }
1003   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
1004     {
1005       TpHandle handle;
1006       EmpathyTpFile *tp_file = empathy_tp_file_new (channel);
1007
1008       approval->handler_instance = G_OBJECT (tp_file);
1009
1010       handle = tp_channel_get_handle (channel, NULL);
1011
1012       connection = tp_channel_borrow_connection (channel);
1013       empathy_tp_contact_factory_get_from_handle (connection, handle,
1014         event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (self));
1015     }
1016   else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_AUTHENTICATION)
1017     {
1018       event_manager_add (approval->manager, account, NULL, EMPATHY_EVENT_TYPE_AUTH,
1019           GTK_STOCK_DIALOG_AUTHENTICATION, tp_account_get_display_name (account),
1020           _("Password required"), approval,
1021           event_manager_auth_process_func, NULL);
1022     }
1023   else
1024     {
1025       GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
1026           "Invalid channel type" };
1027
1028       DEBUG ("Unknown channel type (%s), ignoring..",
1029           g_quark_to_string (channel_type));
1030
1031       tp_add_dispatch_operation_context_fail (context, &error);
1032       return;
1033     }
1034
1035 out:
1036   tp_add_dispatch_operation_context_accept (context);
1037 }
1038
1039 static void
1040 event_pending_subscribe_func (EventPriv *event)
1041 {
1042   empathy_subscription_dialog_show (event->public.contact, event->public.header,
1043       NULL);
1044   event_remove (event);
1045 }
1046
1047 static void
1048 event_manager_pendings_changed_cb (EmpathyContactList  *list,
1049   EmpathyContact *contact, EmpathyContact *actor,
1050   guint reason, gchar *message, gboolean is_pending,
1051   EmpathyEventManager *manager)
1052 {
1053   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1054   gchar                   *header, *event_msg;
1055
1056   if (!is_pending)
1057     {
1058       GSList *l;
1059
1060       for (l = priv->events; l; l = l->next)
1061         {
1062           EventPriv *event = l->data;
1063
1064           if (event->public.contact == contact &&
1065               event->func == event_pending_subscribe_func)
1066             {
1067               event_remove (event);
1068               break;
1069             }
1070         }
1071
1072       return;
1073     }
1074
1075   header = g_strdup_printf (
1076       _("%s would like permission to see when you are online"),
1077       empathy_contact_get_alias (contact));
1078
1079   if (!EMP_STR_EMPTY (message))
1080     event_msg = g_strdup_printf (_("\nMessage: %s"), message);
1081   else
1082     event_msg = NULL;
1083
1084   event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_SUBSCRIPTION,
1085       GTK_STOCK_DIALOG_QUESTION, header, event_msg, NULL,
1086       event_pending_subscribe_func, NULL);
1087
1088   g_free (event_msg);
1089   g_free (header);
1090 }
1091
1092 static void
1093 event_manager_presence_changed_cb (EmpathyContact *contact,
1094     TpConnectionPresenceType current,
1095     TpConnectionPresenceType previous,
1096     EmpathyEventManager *manager)
1097 {
1098   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1099   TpAccount *account;
1100   EmpathyPresenceManager *presence_mgr;
1101   GtkWidget *window = empathy_main_window_dup ();
1102
1103   account = empathy_contact_get_account (contact);
1104   presence_mgr = empathy_presence_manager_dup_singleton ();
1105
1106   if (empathy_presence_manager_account_is_just_connected (presence_mgr, account))
1107     goto out;
1108
1109   if (tp_connection_presence_type_cmp_availability (previous,
1110         TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1111     {
1112       /* contact was online */
1113       if (tp_connection_presence_type_cmp_availability (current,
1114           TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
1115         {
1116           /* someone is logging off */
1117           empathy_sound_manager_play (priv->sound_mgr, window,
1118               EMPATHY_SOUND_CONTACT_DISCONNECTED);
1119
1120           if (g_settings_get_boolean (priv->gsettings_notif,
1121                 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT))
1122             {
1123               event_manager_add (manager, NULL, contact,
1124                   EMPATHY_EVENT_TYPE_PRESENCE_OFFLINE,
1125                   EMPATHY_IMAGE_AVATAR_DEFAULT,
1126                   empathy_contact_get_alias (contact), _("Disconnected"),
1127                   NULL, NULL, NULL);
1128             }
1129         }
1130     }
1131   else
1132     {
1133       /* contact was offline */
1134       if (tp_connection_presence_type_cmp_availability (current,
1135             TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1136         {
1137           /* someone is logging in */
1138           empathy_sound_manager_play (priv->sound_mgr, window,
1139               EMPATHY_SOUND_CONTACT_CONNECTED);
1140
1141           if (g_settings_get_boolean (priv->gsettings_notif,
1142                 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN))
1143             {
1144               event_manager_add (manager, NULL, contact,
1145                   EMPATHY_EVENT_TYPE_PRESENCE_ONLINE,
1146                   EMPATHY_IMAGE_AVATAR_DEFAULT,
1147                   empathy_contact_get_alias (contact), _("Connected"),
1148                   NULL, NULL, NULL);
1149             }
1150         }
1151     }
1152
1153 out:
1154   g_object_unref (presence_mgr);
1155   g_object_unref (window);
1156 }
1157
1158 static void
1159 event_manager_members_changed_cb (EmpathyContactList  *list,
1160     EmpathyContact *contact,
1161     EmpathyContact *actor,
1162     guint reason,
1163     gchar *message,
1164     gboolean is_member,
1165     EmpathyEventManager *manager)
1166 {
1167   if (is_member)
1168     g_signal_connect (contact, "presence-changed",
1169         G_CALLBACK (event_manager_presence_changed_cb), manager);
1170   else
1171     g_signal_handlers_disconnect_by_func (contact,
1172         event_manager_presence_changed_cb, manager);
1173 }
1174
1175 static GObject *
1176 event_manager_constructor (GType type,
1177                            guint n_props,
1178                            GObjectConstructParam *props)
1179 {
1180         GObject *retval;
1181
1182         if (manager_singleton) {
1183                 retval = g_object_ref (manager_singleton);
1184         } else {
1185                 retval = G_OBJECT_CLASS (empathy_event_manager_parent_class)->constructor
1186                         (type, n_props, props);
1187
1188                 manager_singleton = EMPATHY_EVENT_MANAGER (retval);
1189                 g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
1190         }
1191
1192         return retval;
1193 }
1194
1195 static void
1196 event_manager_finalize (GObject *object)
1197 {
1198   EmpathyEventManagerPriv *priv = GET_PRIV (object);
1199
1200   if (priv->ringing > 0)
1201     empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_INCOMING);
1202
1203   g_slist_foreach (priv->events, (GFunc) event_free, NULL);
1204   g_slist_free (priv->events);
1205   g_slist_foreach (priv->approvals, (GFunc) event_manager_approval_free, NULL);
1206   g_slist_free (priv->approvals);
1207   g_object_unref (priv->contact_manager);
1208   g_object_unref (priv->approver);
1209   g_object_unref (priv->auth_approver);
1210   g_object_unref (priv->gsettings_notif);
1211   g_object_unref (priv->gsettings_ui);
1212   g_object_unref (priv->sound_mgr);
1213 }
1214
1215 static void
1216 empathy_event_manager_class_init (EmpathyEventManagerClass *klass)
1217 {
1218   GObjectClass *object_class = G_OBJECT_CLASS (klass);
1219
1220   object_class->finalize = event_manager_finalize;
1221   object_class->constructor = event_manager_constructor;
1222
1223   signals[EVENT_ADDED] =
1224     g_signal_new ("event-added",
1225       G_TYPE_FROM_CLASS (klass),
1226       G_SIGNAL_RUN_LAST,
1227       0,
1228       NULL, NULL,
1229       g_cclosure_marshal_VOID__POINTER,
1230       G_TYPE_NONE,
1231       1, G_TYPE_POINTER);
1232
1233   signals[EVENT_REMOVED] =
1234   g_signal_new ("event-removed",
1235       G_TYPE_FROM_CLASS (klass),
1236       G_SIGNAL_RUN_LAST,
1237       0,
1238       NULL, NULL,
1239       g_cclosure_marshal_VOID__POINTER,
1240       G_TYPE_NONE, 1, G_TYPE_POINTER);
1241
1242   signals[EVENT_UPDATED] =
1243   g_signal_new ("event-updated",
1244       G_TYPE_FROM_CLASS (klass),
1245       G_SIGNAL_RUN_LAST,
1246       0,
1247       NULL, NULL,
1248       g_cclosure_marshal_VOID__POINTER,
1249       G_TYPE_NONE, 1, G_TYPE_POINTER);
1250
1251   g_type_class_add_private (object_class, sizeof (EmpathyEventManagerPriv));
1252 }
1253
1254 static void
1255 empathy_event_manager_init (EmpathyEventManager *manager)
1256 {
1257   EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
1258     EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
1259   TpDBusDaemon *dbus;
1260   GError *error = NULL;
1261
1262   manager->priv = priv;
1263
1264   priv->gsettings_notif = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1265   priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1266
1267   priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1268
1269   priv->contact_manager = empathy_contact_manager_dup_singleton ();
1270   g_signal_connect (priv->contact_manager, "pendings-changed",
1271     G_CALLBACK (event_manager_pendings_changed_cb), manager);
1272
1273   g_signal_connect (priv->contact_manager, "members-changed",
1274     G_CALLBACK (event_manager_members_changed_cb), manager);
1275
1276   dbus = tp_dbus_daemon_dup (&error);
1277   if (dbus == NULL)
1278     {
1279       DEBUG ("Failed to get TpDBusDaemon: %s", error->message);
1280       g_error_free (error);
1281       return;
1282     }
1283
1284   priv->approver = tp_simple_approver_new (dbus, "Empathy.EventManager", FALSE,
1285       approve_channels, manager, NULL);
1286
1287   /* EmpathyTpChat relies on this feature being prepared */
1288   tp_base_client_add_connection_features_varargs (priv->approver,
1289     TP_CONNECTION_FEATURE_CAPABILITIES, 0);
1290
1291   /* Private text channels */
1292   tp_base_client_take_approver_filter (priv->approver,
1293       tp_asv_new (
1294         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1295         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1296         NULL));
1297
1298   /* Muc text channels */
1299   tp_base_client_take_approver_filter (priv->approver,
1300       tp_asv_new (
1301         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1302         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
1303         NULL));
1304
1305   /* File transfer */
1306   tp_base_client_take_approver_filter (priv->approver,
1307       tp_asv_new (
1308         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1309           TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
1310         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1311         NULL));
1312
1313   /* Calls */
1314   tp_base_client_take_approver_filter (priv->approver,
1315       tp_asv_new (
1316         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1317           TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
1318         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1319         NULL));
1320
1321   /* I don't feel good about doing this, and I'm sorry, but the
1322    * capabilities connection feature is added earlier because it's
1323    * needed for EmpathyTpChat. If the capabilities feature is required
1324    * then preparing an auth channel (which of course appears in the
1325    * CONNECTING state) will never be prepared. So the options are
1326    * either to create another approver like I've done, or to port
1327    * EmpathyTpChat and its users to not depend on the connection being
1328    * prepared with capabilities. I chose the former, obviously. :-) */
1329
1330   priv->auth_approver = tp_simple_approver_new (dbus,
1331       "Empathy.AuthEventManager", FALSE, approve_channels, manager,
1332       NULL);
1333
1334   /* SASL auth channels */
1335   tp_base_client_take_approver_filter (priv->auth_approver,
1336       tp_asv_new (
1337         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1338           TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION,
1339         TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION_AUTHENTICATION_METHOD,
1340           G_TYPE_STRING,
1341           TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION,
1342         NULL));
1343
1344   if (!tp_base_client_register (priv->approver, &error))
1345     {
1346       DEBUG ("Failed to register Approver: %s", error->message);
1347       g_error_free (error);
1348     }
1349
1350   if (!tp_base_client_register (priv->auth_approver, &error))
1351     {
1352       DEBUG ("Failed to register auth Approver: %s", error->message);
1353       g_error_free (error);
1354     }
1355
1356   g_object_unref (dbus);
1357 }
1358
1359 EmpathyEventManager *
1360 empathy_event_manager_dup_singleton (void)
1361 {
1362   return g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL);
1363 }
1364
1365 GSList *
1366 empathy_event_manager_get_events (EmpathyEventManager *manager)
1367 {
1368   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1369
1370   g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1371
1372   return priv->events;
1373 }
1374
1375 EmpathyEvent *
1376 empathy_event_manager_get_top_event (EmpathyEventManager *manager)
1377 {
1378   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1379
1380   g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1381
1382   return priv->events ? priv->events->data : NULL;
1383 }
1384
1385 void
1386 empathy_event_activate (EmpathyEvent *event_public)
1387 {
1388   EventPriv *event = (EventPriv *) event_public;
1389
1390   g_return_if_fail (event_public != NULL);
1391
1392   if (event->func)
1393     event->func (event);
1394   else
1395     event_remove (event);
1396 }
1397
1398 void
1399 empathy_event_inhibit_updates (EmpathyEvent *event_public)
1400 {
1401   EventPriv *event = (EventPriv *) event_public;
1402
1403   g_return_if_fail (event_public != NULL);
1404
1405   event->inhibit = TRUE;
1406 }
1407
1408 void
1409 empathy_event_approve (EmpathyEvent *event_public)
1410 {
1411   EventPriv *event = (EventPriv *) event_public;
1412
1413   g_return_if_fail (event_public != NULL);
1414
1415   event_manager_approval_approve (event->approval);
1416 }
1417
1418 void
1419 empathy_event_decline (EmpathyEvent *event_public)
1420 {
1421   EventPriv *event = (EventPriv *) event_public;
1422
1423   g_return_if_fail (event_public != NULL);
1424
1425   reject_approval (event->approval);
1426 }