2
* Copyright (C) 2007-2008 Collabora Ltd.
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.
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.
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
18
* Authors: Xavier Claessens <xclaesse@gmail.com>
19
* Sjoerd Simons <sjoerd.simons@collabora.co.uk>
25
#include <glib/gi18n.h>
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>
32
#include <libempathy/empathy-idle.h>
33
#include <libempathy/empathy-tp-contact-factory.h>
34
#include <libempathy/empathy-contact-manager.h>
35
#include <libempathy/empathy-tp-chat.h>
36
#include <libempathy/empathy-tp-call.h>
37
#include <libempathy/empathy-tp-file.h>
38
#include <libempathy/empathy-utils.h>
39
#include <libempathy/empathy-call-factory.h>
40
#include <libempathy/empathy-gsettings.h>
42
#include <extensions/extensions.h>
44
#include <libempathy-gtk/empathy-images.h>
45
#include <libempathy-gtk/empathy-contact-dialogs.h>
46
#include <libempathy-gtk/empathy-sound.h>
48
#include "empathy-event-manager.h"
49
#include "empathy-main-window.h"
51
#define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
52
#include <libempathy/empathy-debug.h>
54
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyEventManager)
56
#define NOTIFICATION_TIMEOUT 2 /* seconds */
58
/* The time interval in milliseconds between 2 incoming rings */
59
#define MS_BETWEEN_RING 500
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 */
69
GObject *handler_instance;
70
/* optional accept widget */
72
/* Channel of the CDO that will be used during the approval */
73
TpChannel *main_channel;
74
gboolean auto_approved;
75
} EventManagerApproval;
78
TpBaseClient *approver;
79
EmpathyContactManager *contact_manager;
81
/* Ongoing approvals */
85
} EmpathyEventManagerPriv;
87
typedef struct _EventPriv EventPriv;
88
typedef void (*EventFunc) (EventPriv *event);
92
EmpathyEventManager *manager;
93
EventManagerApproval *approval;
97
guint autoremove_timeout_id;
107
static guint signals[LAST_SIGNAL];
109
G_DEFINE_TYPE (EmpathyEventManager, empathy_event_manager, G_TYPE_OBJECT);
111
static EmpathyEventManager * manager_singleton = NULL;
113
static EventManagerApproval *
114
event_manager_approval_new (EmpathyEventManager *manager,
115
TpChannelDispatchOperation *operation,
116
TpChannel *main_channel)
118
EventManagerApproval *result = g_slice_new0 (EventManagerApproval);
119
result->operation = g_object_ref (operation);
120
result->manager = manager;
121
result->main_channel = g_object_ref (main_channel);
127
event_manager_approval_free (EventManagerApproval *approval)
129
g_signal_handler_disconnect (approval->operation,
130
approval->invalidated_handler);
131
g_object_unref (approval->operation);
133
g_object_unref (approval->main_channel);
135
if (approval->handler != 0)
136
g_signal_handler_disconnect (approval->handler_instance,
139
if (approval->handler_instance != NULL)
140
g_object_unref (approval->handler_instance);
142
if (approval->contact != NULL)
143
g_object_unref (approval->contact);
145
if (approval->dialog != NULL)
147
gtk_widget_destroy (approval->dialog);
150
g_slice_free (EventManagerApproval, approval);
153
static void event_remove (EventPriv *event);
156
event_free (EventPriv *event)
158
g_free (event->public.icon_name);
159
g_free (event->public.header);
160
g_free (event->public.message);
162
if (event->autoremove_timeout_id != 0)
163
g_source_remove (event->autoremove_timeout_id);
165
if (event->public.contact)
167
g_object_unref (event->public.contact);
170
g_slice_free (EventPriv, event);
174
event_remove (EventPriv *event)
176
EmpathyEventManagerPriv *priv = GET_PRIV (event->manager);
178
DEBUG ("Removing event %p", event);
180
priv->events = g_slist_remove (priv->events, event);
181
g_signal_emit (event->manager, signals[EVENT_REMOVED], 0, event);
186
autoremove_event_timeout_cb (EventPriv *event)
188
event->autoremove_timeout_id = 0;
189
event_remove (event);
194
display_notify_area (void)
197
GSettings *gsettings;
200
gsettings = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
202
result = g_settings_get_boolean (gsettings,
203
EMPATHY_PREFS_UI_EVENTS_NOTIFY_AREA);
204
g_object_unref (gsettings);
210
event_manager_add (EmpathyEventManager *manager,
211
EmpathyContact *contact,
212
EmpathyEventType type,
213
const gchar *icon_name,
215
const gchar *message,
216
EventManagerApproval *approval,
220
EmpathyEventManagerPriv *priv = GET_PRIV (manager);
223
event = g_slice_new0 (EventPriv);
224
event->public.contact = contact ? g_object_ref (contact) : NULL;
225
event->public.type = type;
226
event->public.icon_name = g_strdup (icon_name);
227
event->public.header = g_strdup (header);
228
event->public.message = g_strdup (message);
229
event->public.must_ack = (func != NULL);
230
event->inhibit = FALSE;
232
event->user_data = user_data;
233
event->manager = manager;
234
event->approval = approval;
236
DEBUG ("Adding event %p", event);
237
priv->events = g_slist_prepend (priv->events, event);
239
if (!display_notify_area ())
241
/* Don't fire the 'event-added' signal as we activate the event now */
242
if (approval != NULL)
243
approval->auto_approved = TRUE;
245
empathy_event_activate (&event->public);
249
g_signal_emit (event->manager, signals[EVENT_ADDED], 0, event);
251
if (!event->public.must_ack)
253
event->autoremove_timeout_id = g_timeout_add_seconds (
254
NOTIFICATION_TIMEOUT, (GSourceFunc) autoremove_event_timeout_cb,
260
handle_with_cb (GObject *source,
261
GAsyncResult *result,
264
TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
265
GError *error = NULL;
267
if (!tp_channel_dispatch_operation_handle_with_finish (cdo, result, &error))
269
DEBUG ("HandleWith failed: %s\n", error->message);
270
g_error_free (error);
275
handle_with_time_cb (GObject *source,
276
GAsyncResult *result,
279
TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
280
GError *error = NULL;
282
if (!tp_channel_dispatch_operation_handle_with_time_finish (cdo, result,
285
if (g_error_matches (error, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED))
287
EventManagerApproval *approval = user_data;
289
DEBUG ("HandleWithTime() is not implemented, falling back to "
290
"HandleWith(). Please upgrade to telepathy-mission-control "
293
tp_channel_dispatch_operation_handle_with_async (approval->operation,
294
NULL, handle_with_cb, approval);
298
DEBUG ("HandleWithTime failed: %s\n", error->message);
300
g_error_free (error);
305
event_manager_approval_approve (EventManagerApproval *approval)
309
if (approval->auto_approved)
311
timestamp = TP_USER_ACTION_TIME_NOT_USER_ACTION;
315
timestamp = tp_user_action_time_from_x11 (gtk_get_current_event_time ());
318
g_assert (approval->operation != NULL);
320
tp_channel_dispatch_operation_handle_with_time_async (approval->operation,
321
NULL, timestamp, handle_with_time_cb, approval);
325
event_channel_process_func (EventPriv *event)
327
event_manager_approval_approve (event->approval);
331
event_text_channel_process_func (EventPriv *event)
333
EmpathyTpChat *tp_chat;
336
timestamp = tp_user_action_time_from_x11 (gtk_get_current_event_time ());
338
if (event->approval->handler != 0)
340
tp_chat = EMPATHY_TP_CHAT (event->approval->handler_instance);
342
g_signal_handler_disconnect (tp_chat, event->approval->handler);
343
event->approval->handler = 0;
346
event_manager_approval_approve (event->approval);
350
event_lookup_by_approval (EmpathyEventManager *manager,
351
EventManagerApproval *approval)
353
EmpathyEventManagerPriv *priv = GET_PRIV (manager);
355
EventPriv *retval = NULL;
357
for (l = priv->events; l; l = l->next)
359
EventPriv *event = l->data;
361
if (event->approval == approval)
372
event_update (EmpathyEventManager *manager, EventPriv *event,
373
const char *icon_name, const char *header, const char *msg)
375
g_free (event->public.icon_name);
376
g_free (event->public.header);
377
g_free (event->public.message);
379
event->public.icon_name = g_strdup (icon_name);
380
event->public.header = g_strdup (header);
381
event->public.message = g_strdup (msg);
383
g_signal_emit (manager, signals[EVENT_UPDATED], 0, event);
387
reject_channel_claim_cb (GObject *source,
388
GAsyncResult *result,
391
TpChannelDispatchOperation *cdo = TP_CHANNEL_DISPATCH_OPERATION (source);
392
GError *error = NULL;
394
if (!tp_channel_dispatch_operation_claim_finish (cdo, result, &error))
396
DEBUG ("Failed to claim channel: %s", error->message);
398
g_error_free (error);
402
if (EMPATHY_IS_TP_CALL (user_data))
404
empathy_tp_call_close (user_data);
406
else if (EMPATHY_IS_TP_CHAT (user_data))
408
empathy_tp_chat_leave (user_data);
410
else if (EMPATHY_IS_TP_FILE (user_data))
412
empathy_tp_file_close (user_data);
416
g_object_unref (user_data);
420
reject_approval (EventManagerApproval *approval)
422
/* We have to claim the channel before closing it */
423
tp_channel_dispatch_operation_claim_async (approval->operation,
424
reject_channel_claim_cb, g_object_ref (approval->handler_instance));
428
event_manager_call_window_confirmation_dialog_response_cb (GtkDialog *dialog,
429
gint response, gpointer user_data)
431
EventManagerApproval *approval = user_data;
433
gtk_widget_destroy (approval->dialog);
434
approval->dialog = NULL;
436
if (response != GTK_RESPONSE_ACCEPT)
438
reject_approval (approval);
442
event_manager_approval_approve (approval);
447
event_channel_process_voip_func (EventPriv *event)
456
if (event->approval->dialog != NULL)
458
gtk_window_present (GTK_WINDOW (event->approval->dialog));
462
call = EMPATHY_TP_CALL (event->approval->handler_instance);
464
video = empathy_tp_call_has_initial_video (call);
466
dialog = gtk_message_dialog_new (NULL, 0,
467
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
468
video ? _("Incoming video call"): _("Incoming call"));
470
gtk_message_dialog_format_secondary_text (
471
GTK_MESSAGE_DIALOG (dialog), video ?
472
_("%s is video calling you. Do you want to answer?"):
473
_("%s is calling you. Do you want to answer?"),
474
empathy_contact_get_alias (event->approval->contact));
476
title = g_strdup_printf (_("Incoming call from %s"),
477
empathy_contact_get_alias (event->approval->contact));
479
gtk_window_set_title (GTK_WINDOW (dialog), title);
482
/* Set image of the dialog */
485
image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
486
GTK_ICON_SIZE_DIALOG);
490
image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
491
GTK_ICON_SIZE_DIALOG);
494
gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
495
gtk_widget_show (image);
497
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
500
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
501
_("_Reject"), GTK_RESPONSE_REJECT);
502
image = gtk_image_new_from_icon_name ("call-stop",
503
GTK_ICON_SIZE_BUTTON);
504
gtk_button_set_image (GTK_BUTTON (button), image);
506
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
507
_("_Answer"), GTK_RESPONSE_ACCEPT);
509
image = gtk_image_new_from_icon_name ("call-start", GTK_ICON_SIZE_BUTTON);
510
gtk_button_set_image (GTK_BUTTON (button), image);
512
g_signal_connect (dialog, "response",
513
G_CALLBACK (event_manager_call_window_confirmation_dialog_response_cb),
516
gtk_widget_show (dialog);
518
event->approval->dialog = dialog;
522
event_manager_chat_message_received_cb (EmpathyTpChat *tp_chat,
523
EmpathyMessage *message,
524
EventManagerApproval *approval)
526
GtkWidget *window = empathy_main_window_dup ();
527
EmpathyContact *sender;
533
/* try to update the event if it's referring to a chat which is already in the
535
event = event_lookup_by_approval (approval->manager, approval);
537
sender = empathy_message_get_sender (message);
538
header = empathy_contact_get_alias (sender);
539
msg = empathy_message_get_body (message);
541
channel = empathy_tp_chat_get_channel (tp_chat);
544
event_update (approval->manager, event, EMPATHY_IMAGE_NEW_MESSAGE, header,
547
event_manager_add (approval->manager, sender, EMPATHY_EVENT_TYPE_CHAT,
548
EMPATHY_IMAGE_NEW_MESSAGE, header, msg, approval,
549
event_text_channel_process_func, NULL);
551
empathy_sound_play (window, EMPATHY_SOUND_CONVERSATION_NEW);
553
g_object_unref (window);
557
event_manager_approval_done (EventManagerApproval *approval)
559
EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
562
if (approval->operation != NULL)
566
channel_type = tp_channel_get_channel_type_id (approval->main_channel);
568
if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
571
if (priv->ringing == 0)
572
empathy_sound_stop (EMPATHY_SOUND_PHONE_INCOMING);
576
priv->approvals = g_slist_remove (priv->approvals, approval);
578
for (l = priv->events; l; l = l->next)
580
EventPriv *event = l->data;
582
if (event->approval == approval)
584
event_remove (event);
589
event_manager_approval_free (approval);
593
cdo_invalidated_cb (TpProxy *cdo,
597
EventManagerApproval *approval)
599
DEBUG ("ChannelDispatchOperation has been invalidated: %s", message);
601
event_manager_approval_done (approval);
605
event_manager_media_channel_got_contact (EventManagerApproval *approval)
607
EmpathyEventManagerPriv *priv = GET_PRIV (approval->manager);
608
GtkWidget *window = empathy_main_window_dup ();
613
call = EMPATHY_TP_CALL (approval->handler_instance);
615
video = empathy_tp_call_has_initial_video (call);
617
header = g_strdup_printf (
618
video ? _("Incoming video call from %s") :_("Incoming call from %s"),
619
empathy_contact_get_alias (approval->contact));
621
event_manager_add (approval->manager, approval->contact,
622
EMPATHY_EVENT_TYPE_VOIP,
623
video ? EMPATHY_IMAGE_VIDEO_CALL : EMPATHY_IMAGE_VOIP,
624
header, NULL, approval,
625
event_channel_process_voip_func, NULL);
630
if (priv->ringing == 1)
631
empathy_sound_start_playing (window,
632
EMPATHY_SOUND_PHONE_INCOMING, MS_BETWEEN_RING);
634
g_object_unref (window);
638
event_manager_media_channel_contact_changed_cb (EmpathyTpCall *call,
639
GParamSpec *param, EventManagerApproval *approval)
641
EmpathyContact *contact;
643
g_object_get (G_OBJECT (call), "contact", &contact, NULL);
648
approval->contact = contact;
649
event_manager_media_channel_got_contact (approval);
653
invite_dialog_response_cb (GtkDialog *dialog,
655
EventManagerApproval *approval)
657
EmpathyTpChat *tp_chat;
659
gtk_widget_destroy (GTK_WIDGET (approval->dialog));
660
approval->dialog = NULL;
662
tp_chat = EMPATHY_TP_CHAT (approval->handler_instance);
664
if (response != GTK_RESPONSE_OK)
667
DEBUG ("Muc invitation rejected");
669
reject_approval (approval);
674
DEBUG ("Muc invitation accepted");
676
/* We'll join the room when handling the channel */
677
event_manager_approval_approve (approval);
681
event_room_channel_process_func (EventPriv *event)
683
GtkWidget *dialog, *button, *image;
684
TpChannel *channel = event->approval->main_channel;
687
if (event->approval->dialog != NULL)
689
gtk_window_present (GTK_WINDOW (event->approval->dialog));
694
dialog = gtk_message_dialog_new (NULL, 0,
695
GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Room invitation"));
697
title = g_strdup_printf (_("Invitation to join %s"),
698
tp_channel_get_identifier (channel));
700
gtk_window_set_title (GTK_WINDOW (dialog), title);
703
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
704
_("%s is inviting you to join %s"),
705
empathy_contact_get_alias (event->approval->contact),
706
tp_channel_get_identifier (channel));
708
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
711
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
712
_("_Decline"), GTK_RESPONSE_CANCEL);
713
image = gtk_image_new_from_icon_name (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
714
gtk_button_set_image (GTK_BUTTON (button), image);
716
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
717
_("_Join"), GTK_RESPONSE_OK);
718
image = gtk_image_new_from_icon_name (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
719
gtk_button_set_image (GTK_BUTTON (button), image);
721
g_signal_connect (dialog, "response",
722
G_CALLBACK (invite_dialog_response_cb), event->approval);
724
gtk_widget_show (dialog);
726
event->approval->dialog = dialog;
730
display_invite_room_dialog (EventManagerApproval *approval)
732
GtkWidget *window = empathy_main_window_dup ();
733
const gchar *invite_msg;
735
TpHandle self_handle;
737
self_handle = tp_channel_group_get_self_handle (approval->main_channel);
738
tp_channel_group_get_local_pending_info (approval->main_channel, self_handle,
739
NULL, NULL, &invite_msg);
741
if (approval->contact != NULL)
743
msg = g_strdup_printf (_("%s invited you to join %s"),
744
empathy_contact_get_alias (approval->contact),
745
tp_channel_get_identifier (approval->main_channel));
749
msg = g_strdup_printf (_("You have been invited to join %s"),
750
tp_channel_get_identifier (approval->main_channel));
753
event_manager_add (approval->manager, approval->contact,
754
EMPATHY_EVENT_TYPE_INVITATION, EMPATHY_IMAGE_GROUP_MESSAGE, msg,
755
invite_msg, approval, event_room_channel_process_func, NULL);
757
empathy_sound_play (window, EMPATHY_SOUND_CONVERSATION_NEW);
760
g_object_unref (window);
764
event_manager_muc_invite_got_contact_cb (TpConnection *connection,
765
EmpathyContact *contact,
770
EventManagerApproval *approval = (EventManagerApproval *) user_data;
774
DEBUG ("Error: %s", error->message);
778
approval->contact = g_object_ref (contact);
781
display_invite_room_dialog (approval);
785
event_manager_ft_got_contact_cb (TpConnection *connection,
786
EmpathyContact *contact,
791
EventManagerApproval *approval = (EventManagerApproval *) user_data;
792
GtkWidget *window = empathy_main_window_dup ();
795
approval->contact = g_object_ref (contact);
797
header = g_strdup_printf (_("Incoming file transfer from %s"),
798
empathy_contact_get_alias (approval->contact));
800
event_manager_add (approval->manager, approval->contact,
801
EMPATHY_EVENT_TYPE_TRANSFER, EMPATHY_IMAGE_DOCUMENT_SEND, header, NULL,
802
approval, event_channel_process_func, NULL);
804
/* FIXME better sound for incoming file transfers ?*/
805
empathy_sound_play (window, EMPATHY_SOUND_CONVERSATION_NEW);
808
g_object_unref (window);
811
/* If there is a file-transfer or media channel consider it as the
814
find_main_channel (GList *channels)
817
TpChannel *text = NULL;
819
for (l = channels; l != NULL; l = g_list_next (l))
821
TpChannel *channel = l->data;
824
if (tp_proxy_get_invalidated (channel) != NULL)
827
channel_type = tp_channel_get_channel_type_id (channel);
829
if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA ||
830
channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
833
else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
841
approve_channels (TpSimpleApprover *approver,
843
TpConnection *connection,
845
TpChannelDispatchOperation *dispatch_operation,
846
TpAddDispatchOperationContext *context,
849
EmpathyEventManager *self = user_data;
850
EmpathyEventManagerPriv *priv = GET_PRIV (self);
852
EventManagerApproval *approval;
855
channel = find_main_channel (channels);
858
GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
859
"Unknown channel type" };
861
DEBUG ("Failed to find the main channel; ignoring");
863
tp_add_dispatch_operation_context_fail (context, &error);
867
approval = event_manager_approval_new (self, dispatch_operation, channel);
868
priv->approvals = g_slist_prepend (priv->approvals, approval);
870
approval->invalidated_handler = g_signal_connect (dispatch_operation,
871
"invalidated", G_CALLBACK (cdo_invalidated_cb), approval);
873
channel_type = tp_channel_get_channel_type_id (channel);
875
if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
877
EmpathyTpChat *tp_chat;
879
tp_chat = empathy_tp_chat_new (account, channel);
880
approval->handler_instance = G_OBJECT (tp_chat);
882
if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))
884
/* Are we in local-pending ? */
887
if (empathy_tp_chat_is_invited (tp_chat, &inviter))
889
/* We are invited to a room */
890
DEBUG ("Have been invited to %s. Ask user if he wants to accept",
891
tp_channel_get_identifier (channel));
895
empathy_tp_contact_factory_get_from_handle (connection,
896
inviter, event_manager_muc_invite_got_contact_cb,
897
approval, NULL, G_OBJECT (self));
901
display_invite_room_dialog (approval);
907
/* We are not invited, approve the channel right now */
908
tp_add_dispatch_operation_context_accept (context);
910
approval->auto_approved = TRUE;
911
event_manager_approval_approve (approval);
915
/* 1-1 text channel, wait for the first message */
916
approval->handler = g_signal_connect (tp_chat, "message-received",
917
G_CALLBACK (event_manager_chat_message_received_cb), approval);
919
else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
921
EmpathyContact *contact;
922
EmpathyTpCall *call = empathy_tp_call_new (account, channel);
924
approval->handler_instance = G_OBJECT (call);
926
g_object_get (G_OBJECT (call), "contact", &contact, NULL);
930
g_signal_connect (call, "notify::contact",
931
G_CALLBACK (event_manager_media_channel_contact_changed_cb),
936
approval->contact = contact;
937
event_manager_media_channel_got_contact (approval);
941
else if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_FILE_TRANSFER)
944
EmpathyTpFile *tp_file = empathy_tp_file_new (channel);
946
approval->handler_instance = G_OBJECT (tp_file);
948
handle = tp_channel_get_handle (channel, NULL);
950
connection = tp_channel_borrow_connection (channel);
951
empathy_tp_contact_factory_get_from_handle (connection, handle,
952
event_manager_ft_got_contact_cb, approval, NULL, G_OBJECT (self));
956
GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
957
"Invalid channel type" };
959
DEBUG ("Unknown channel type (%s), ignoring..",
960
g_quark_to_string (channel_type));
962
tp_add_dispatch_operation_context_fail (context, &error);
967
tp_add_dispatch_operation_context_accept (context);
971
event_pending_subscribe_func (EventPriv *event)
973
empathy_subscription_dialog_show (event->public.contact, NULL);
974
event_remove (event);
978
event_manager_pendings_changed_cb (EmpathyContactList *list,
979
EmpathyContact *contact, EmpathyContact *actor,
980
guint reason, gchar *message, gboolean is_pending,
981
EmpathyEventManager *manager)
983
EmpathyEventManagerPriv *priv = GET_PRIV (manager);
984
gchar *header, *event_msg;
990
for (l = priv->events; l; l = l->next)
992
EventPriv *event = l->data;
994
if (event->public.contact == contact &&
995
event->func == event_pending_subscribe_func)
997
event_remove (event);
1005
header = g_strdup_printf (_("Subscription requested by %s"),
1006
empathy_contact_get_alias (contact));
1008
if (!EMP_STR_EMPTY (message))
1009
event_msg = g_strdup_printf (_("\nMessage: %s"), message);
1013
event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_SUBSCRIPTION,
1014
GTK_STOCK_DIALOG_QUESTION, header, event_msg, NULL,
1015
event_pending_subscribe_func, NULL);
1022
event_manager_presence_changed_cb (EmpathyContact *contact,
1023
TpConnectionPresenceType current,
1024
TpConnectionPresenceType previous,
1025
EmpathyEventManager *manager)
1028
gchar *header = NULL;
1030
GSettings *gsettings = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
1031
GtkWidget *window = empathy_main_window_dup ();
1033
account = empathy_contact_get_account (contact);
1034
idle = empathy_idle_dup_singleton ();
1036
if (empathy_idle_account_is_just_connected (idle, account))
1039
if (tp_connection_presence_type_cmp_availability (previous,
1040
TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1042
/* contact was online */
1043
if (tp_connection_presence_type_cmp_availability (current,
1044
TP_CONNECTION_PRESENCE_TYPE_OFFLINE) <= 0)
1046
/* someone is logging off */
1047
empathy_sound_play (window, EMPATHY_SOUND_CONTACT_DISCONNECTED);
1049
if (g_settings_get_boolean (gsettings,
1050
EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNOUT))
1052
header = g_strdup_printf (_("%s is now offline."),
1053
empathy_contact_get_alias (contact));
1055
event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE,
1056
EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL);
1062
/* contact was offline */
1063
if (tp_connection_presence_type_cmp_availability (current,
1064
TP_CONNECTION_PRESENCE_TYPE_OFFLINE) > 0)
1066
/* someone is logging in */
1067
empathy_sound_play (window, EMPATHY_SOUND_CONTACT_CONNECTED);
1069
if (g_settings_get_boolean (gsettings,
1070
EMPATHY_PREFS_NOTIFICATIONS_CONTACT_SIGNIN))
1072
header = g_strdup_printf (_("%s is now online."),
1073
empathy_contact_get_alias (contact));
1075
event_manager_add (manager, contact, EMPATHY_EVENT_TYPE_PRESENCE,
1076
EMPATHY_IMAGE_AVATAR_DEFAULT, header, NULL, NULL, NULL, NULL);
1083
g_object_unref (idle);
1084
g_object_unref (gsettings);
1085
g_object_unref (window);
1089
event_manager_members_changed_cb (EmpathyContactList *list,
1090
EmpathyContact *contact,
1091
EmpathyContact *actor,
1095
EmpathyEventManager *manager)
1098
g_signal_connect (contact, "presence-changed",
1099
G_CALLBACK (event_manager_presence_changed_cb), manager);
1101
g_signal_handlers_disconnect_by_func (contact,
1102
event_manager_presence_changed_cb, manager);
1106
event_manager_constructor (GType type,
1108
GObjectConstructParam *props)
1112
if (manager_singleton) {
1113
retval = g_object_ref (manager_singleton);
1115
retval = G_OBJECT_CLASS (empathy_event_manager_parent_class)->constructor
1116
(type, n_props, props);
1118
manager_singleton = EMPATHY_EVENT_MANAGER (retval);
1119
g_object_add_weak_pointer (retval, (gpointer) &manager_singleton);
1126
event_manager_finalize (GObject *object)
1128
EmpathyEventManagerPriv *priv = GET_PRIV (object);
1130
if (priv->ringing > 0)
1131
empathy_sound_stop (EMPATHY_SOUND_PHONE_INCOMING);
1133
g_slist_foreach (priv->events, (GFunc) event_free, NULL);
1134
g_slist_free (priv->events);
1135
g_slist_foreach (priv->approvals, (GFunc) event_manager_approval_free, NULL);
1136
g_slist_free (priv->approvals);
1137
g_object_unref (priv->contact_manager);
1138
g_object_unref (priv->approver);
1142
empathy_event_manager_class_init (EmpathyEventManagerClass *klass)
1144
GObjectClass *object_class = G_OBJECT_CLASS (klass);
1146
object_class->finalize = event_manager_finalize;
1147
object_class->constructor = event_manager_constructor;
1149
signals[EVENT_ADDED] =
1150
g_signal_new ("event-added",
1151
G_TYPE_FROM_CLASS (klass),
1155
g_cclosure_marshal_VOID__POINTER,
1159
signals[EVENT_REMOVED] =
1160
g_signal_new ("event-removed",
1161
G_TYPE_FROM_CLASS (klass),
1165
g_cclosure_marshal_VOID__POINTER,
1166
G_TYPE_NONE, 1, G_TYPE_POINTER);
1168
signals[EVENT_UPDATED] =
1169
g_signal_new ("event-updated",
1170
G_TYPE_FROM_CLASS (klass),
1174
g_cclosure_marshal_VOID__POINTER,
1175
G_TYPE_NONE, 1, G_TYPE_POINTER);
1178
g_type_class_add_private (object_class, sizeof (EmpathyEventManagerPriv));
1182
empathy_event_manager_init (EmpathyEventManager *manager)
1184
EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
1185
EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
1187
GError *error = NULL;
1189
manager->priv = priv;
1191
priv->contact_manager = empathy_contact_manager_dup_singleton ();
1192
g_signal_connect (priv->contact_manager, "pendings-changed",
1193
G_CALLBACK (event_manager_pendings_changed_cb), manager);
1195
g_signal_connect (priv->contact_manager, "members-changed",
1196
G_CALLBACK (event_manager_members_changed_cb), manager);
1198
dbus = tp_dbus_daemon_dup (&error);
1201
DEBUG ("Failed to get TpDBusDaemon: %s", error->message);
1202
g_error_free (error);
1206
priv->approver = tp_simple_approver_new (dbus, "Empathy.EventManager", FALSE,
1207
approve_channels, manager, NULL);
1209
/* Private text channels */
1210
tp_base_client_take_approver_filter (priv->approver,
1212
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1213
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1216
/* Muc text channels */
1217
tp_base_client_take_approver_filter (priv->approver,
1219
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
1220
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_ROOM,
1224
tp_base_client_take_approver_filter (priv->approver,
1226
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1227
TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER,
1228
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1232
tp_base_client_take_approver_filter (priv->approver,
1234
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
1235
TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
1236
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
1239
if (!tp_base_client_register (priv->approver, &error))
1241
DEBUG ("Failed to register Approver: %s", error->message);
1242
g_error_free (error);
1245
g_object_unref (dbus);
1248
EmpathyEventManager *
1249
empathy_event_manager_dup_singleton (void)
1251
return g_object_new (EMPATHY_TYPE_EVENT_MANAGER, NULL);
1255
empathy_event_manager_get_events (EmpathyEventManager *manager)
1257
EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1259
g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1261
return priv->events;
1265
empathy_event_manager_get_top_event (EmpathyEventManager *manager)
1267
EmpathyEventManagerPriv *priv = GET_PRIV (manager);
1269
g_return_val_if_fail (EMPATHY_IS_EVENT_MANAGER (manager), NULL);
1271
return priv->events ? priv->events->data : NULL;
1275
empathy_event_activate (EmpathyEvent *event_public)
1277
EventPriv *event = (EventPriv *) event_public;
1279
g_return_if_fail (event_public != NULL);
1282
event->func (event);
1284
event_remove (event);
1288
empathy_event_inhibit_updates (EmpathyEvent *event_public)
1290
EventPriv *event = (EventPriv *) event_public;
1292
g_return_if_fail (event_public != NULL);
1294
event->inhibit = TRUE;
1298
empathy_event_approve (EmpathyEvent *event_public)
1300
EventPriv *event = (EventPriv *) event_public;
1302
g_return_if_fail (event_public != NULL);
1304
event_manager_approval_approve (event->approval);
1308
empathy_event_decline (EmpathyEvent *event_public)
1310
EventPriv *event = (EventPriv *) event_public;
1312
g_return_if_fail (event_public != NULL);
1314
reject_approval (event->approval);