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