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