]> git.0d.be Git - empathy.git/blob - src/empathy-event-manager.c
event-manager: become an approver for auth channels
[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 dummy_process_func (EventPriv *event)
869 {
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 (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
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       EmpathyTpCall *call = empathy_tp_call_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       /* We need a process function or this will time out after
1019        * NOTIFICATION_TIMEOUT seconds, which is undesirable. */
1020       event_manager_add (approval->manager, account, NULL, EMPATHY_EVENT_TYPE_AUTH,
1021           NULL, NULL, NULL, approval, dummy_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 available"),
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   gchar *header = NULL;
1101   EmpathyIdle *idle;
1102   GtkWidget *window = empathy_main_window_dup ();
1103
1104   account = empathy_contact_get_account (contact);
1105   idle = empathy_idle_dup_singleton ();
1106
1107   if (empathy_idle_account_is_just_connected (idle, account))
1108     goto out;
1109
1110   if (tp_connection_presence_type_cmp_availability (previous,
1111         TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1112     {
1113       /* contact was online */
1114       if (tp_connection_presence_type_cmp_availability (current,
1115           TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
1116         {
1117           /* someone is logging off */
1118           empathy_sound_manager_play (priv->sound_mgr, window,
1119               EMPATHY_SOUND_CONTACT_DISCONNECTED);
1120
1121           if (g_settings_get_boolean (priv->gsettings_notif,
1122                 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT))
1123             {
1124               header = g_strdup_printf (_("%s is now offline."),
1125                   empathy_contact_get_alias (contact));
1126
1127               event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_PRESENCE,
1128                   EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL);
1129             }
1130         }
1131     }
1132   else
1133     {
1134       /* contact was offline */
1135       if (tp_connection_presence_type_cmp_availability (current,
1136             TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1137         {
1138           /* someone is logging in */
1139           empathy_sound_manager_play (priv->sound_mgr, window,
1140               EMPATHY_SOUND_CONTACT_CONNECTED);
1141
1142           if (g_settings_get_boolean (priv->gsettings_notif,
1143                 EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN))
1144             {
1145               header = g_strdup_printf (_("%s is now online."),
1146                   empathy_contact_get_alias (contact));
1147
1148               event_manager_add (manager, NULL, contact, EMPATHY_EVENT_TYPE_PRESENCE,
1149                   EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL);
1150             }
1151         }
1152     }
1153   g_free (header);
1154
1155 out:
1156   g_object_unref (idle);
1157   g_object_unref (window);
1158 }
1159
1160 static void
1161 event_manager_members_changed_cb (EmpathyContactList  *list,
1162     EmpathyContact *contact,
1163     EmpathyContact *actor,
1164     guint reason,
1165     gchar *message,
1166     gboolean is_member,
1167     EmpathyEventManager *manager)
1168 {
1169   if (is_member)
1170     g_signal_connect (contact, "presence-changed",
1171         G_CALLBACK (event_manager_presence_changed_cb), manager);
1172   else
1173     g_signal_handlers_disconnect_by_func (contact,
1174         event_manager_presence_changed_cb, manager);
1175 }
1176
1177 static GObject *
1178 event_manager_constructor (GType type,
1179                            guint n_props,
1180                            GObjectConstructParam *props)
1181 {
1182         GObject *retval;
1183
1184         if (manager_singleton) {
1185                 retval = g_object_ref (manager_singleton);
1186         } else {
1187                 retval = G_OBJECT_CLASS (empathy_event_manager_parent_class)->constructor
1188                         (type, n_props, props);
1189
1190                 manager_singleton = EMPATHY_EVENT_MANAGER (retval);
1191                 g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
1192         }
1193
1194         return retval;
1195 }
1196
1197 static void
1198 event_manager_finalize (GObject *object)
1199 {
1200   EmpathyEventManagerPriv *priv = GET_PRIV (object);
1201
1202   if (priv->ringing > 0)
1203     empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_INCOMING);
1204
1205   g_slist_foreach (priv->events, (GFunc) event_free, NULL);
1206   g_slist_free (priv->events);
1207   g_slist_foreach (priv->approvals, (GFunc) event_manager_approval_free, NULL);
1208   g_slist_free (priv->approvals);
1209   g_object_unref (priv->contact_manager);
1210   g_object_unref (priv->approver);
1211   g_object_unref (priv->auth_approver);
1212   g_object_unref (priv->gsettings_notif);
1213   g_object_unref (priv->gsettings_ui);
1214   g_object_unref (priv->sound_mgr);
1215 }
1216
1217 static void
1218 empathy_event_manager_class_init (EmpathyEventManagerClass *klass)
1219 {
1220   GObjectClass *object_class = G_OBJECT_CLASS (klass);
1221
1222   object_class->finalize = event_manager_finalize;
1223   object_class->constructor = event_manager_constructor;
1224
1225   signals[EVENT_ADDED] =
1226     g_signal_new ("event-added",
1227       G_TYPE_FROM_CLASS (klass),
1228       G_SIGNAL_RUN_LAST,
1229       0,
1230       NULL, NULL,
1231       g_cclosure_marshal_VOID__POINTER,
1232       G_TYPE_NONE,
1233       1, G_TYPE_POINTER);
1234
1235   signals[EVENT_REMOVED] =
1236   g_signal_new ("event-removed",
1237       G_TYPE_FROM_CLASS (klass),
1238       G_SIGNAL_RUN_LAST,
1239       0,
1240       NULL, NULL,
1241       g_cclosure_marshal_VOID__POINTER,
1242       G_TYPE_NONE, 1, G_TYPE_POINTER);
1243
1244   signals[EVENT_UPDATED] =
1245   g_signal_new ("event-updated",
1246       G_TYPE_FROM_CLASS (klass),
1247       G_SIGNAL_RUN_LAST,
1248       0,
1249       NULL, NULL,
1250       g_cclosure_marshal_VOID__POINTER,
1251       G_TYPE_NONE, 1, G_TYPE_POINTER);
1252
1253   g_type_class_add_private (object_class, sizeof (EmpathyEventManagerPriv));
1254 }
1255
1256 static void
1257 empathy_event_manager_init (EmpathyEventManager *manager)
1258 {
1259   EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
1260     EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
1261   TpDBusDaemon *dbus;
1262   GError *error = NULL;
1263
1264   manager->priv = priv;
1265
1266   priv->gsettings_notif = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1267   priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
1268
1269   priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1270
1271   priv->contact_manager = empathy_contact_manager_dup_singleton ();
1272   g_signal_connect (priv->contact_manager, "pendings-changed",
1273     G_CALLBACK (event_manager_pendings_changed_cb), manager);
1274
1275   g_signal_connect (priv->contact_manager, "members-changed",
1276     G_CALLBACK (event_manager_members_changed_cb), manager);
1277
1278   dbus = tp_dbus_daemon_dup (&error);
1279   if (dbus == NULL)
1280     {
1281       DEBUG ("Failed to get TpDBusDaemon: %s", error->message);
1282       g_error_free (error);
1283       return;
1284     }
1285
1286   priv->approver = tp_simple_approver_new (dbus, "Empathy.EventManager", FALSE,
1287       approve_channels, manager, NULL);
1288
1289   /* EmpathyTpChat relies on this feature being prepared */
1290   tp_base_client_add_connection_features_varargs (priv->approver,
1291     TP_CONNECTION_FEATURE_CAPABILITIES, 0);
1292
1293   /* Private text channels */
1294   tp_base_client_take_approver_filter (priv->approver,
1295       tp_asv_new (
1296         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1297         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1298         NULL));
1299
1300   /* Muc text channels */
1301   tp_base_client_take_approver_filter (priv->approver,
1302       tp_asv_new (
1303         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1304         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
1305         NULL));
1306
1307   /* File transfer */
1308   tp_base_client_take_approver_filter (priv->approver,
1309       tp_asv_new (
1310         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1311           TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
1312         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1313         NULL));
1314
1315   /* Calls */
1316   tp_base_client_take_approver_filter (priv->approver,
1317       tp_asv_new (
1318         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1319           TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
1320         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1321         NULL));
1322
1323   /* I don't feel good about doing this, and I'm sorry, but the
1324    * capabilities connection feature is added earlier because it's
1325    * needed for EmpathyTpChat. If the capabilities feature is required
1326    * then preparing an auth channel (which of course appears in the
1327    * CONNECTING state) will never be prepared. So the options are
1328    * either to create another approver like I've done, or to port
1329    * EmpathyTpChat and its users to not depend on the connection being
1330    * prepared with capabilities. I chose the former, obviously. :-) */
1331
1332   priv->auth_approver = tp_simple_approver_new (dbus,
1333       "Empathy.AuthEventManager", FALSE, approve_channels, manager,
1334       NULL);
1335
1336   /* SASL auth channels */
1337   tp_base_client_take_approver_filter (priv->auth_approver,
1338       tp_asv_new (
1339         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1340           TP_IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION,
1341         TP_PROP_CHANNEL_TYPE_SERVER_AUTHENTICATION_AUTHENTICATION_METHOD,
1342           G_TYPE_STRING,
1343           TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION,
1344         NULL));
1345
1346   if (!tp_base_client_register (priv->approver, &error))
1347     {
1348       DEBUG ("Failed to register Approver: %s", error->message);
1349       g_error_free (error);
1350     }
1351
1352   if (!tp_base_client_register (priv->auth_approver, &error))
1353     {
1354       DEBUG ("Failed to register auth Approver: %s", error->message);
1355       g_error_free (error);
1356     }
1357
1358   g_object_unref (dbus);
1359 }
1360
1361 EmpathyEventManager *
1362 empathy_event_manager_dup_singleton (void)
1363 {
1364   return g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL);
1365 }
1366
1367 GSList *
1368 empathy_event_manager_get_events (EmpathyEventManager *manager)
1369 {
1370   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1371
1372   g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1373
1374   return priv->events;
1375 }
1376
1377 EmpathyEvent *
1378 empathy_event_manager_get_top_event (EmpathyEventManager *manager)
1379 {
1380   EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1381
1382   g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1383
1384   return priv->events ? priv->events->data : NULL;
1385 }
1386
1387 void
1388 empathy_event_activate (EmpathyEvent *event_public)
1389 {
1390   EventPriv *event = (EventPriv *) event_public;
1391
1392   g_return_if_fail (event_public != NULL);
1393
1394   if (event->func)
1395     event->func (event);
1396   else
1397     event_remove (event);
1398 }
1399
1400 void
1401 empathy_event_inhibit_updates (EmpathyEvent *event_public)
1402 {
1403   EventPriv *event = (EventPriv *) event_public;
1404
1405   g_return_if_fail (event_public != NULL);
1406
1407   event->inhibit = TRUE;
1408 }
1409
1410 void
1411 empathy_event_approve (EmpathyEvent *event_public)
1412 {
1413   EventPriv *event = (EventPriv *) event_public;
1414
1415   g_return_if_fail (event_public != NULL);
1416
1417   event_manager_approval_approve (event->approval);
1418 }
1419
1420 void
1421 empathy_event_decline (EmpathyEvent *event_public)
1422 {
1423   EventPriv *event = (EventPriv *) event_public;
1424
1425   g_return_if_fail (event_public != NULL);
1426
1427   reject_approval (event->approval);
1428 }