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