~ubuntu-branches/ubuntu/natty/empathy/natty-updates

« back to all changes in this revision

Viewing changes to libempathy-gtk/empathy-status-icon.c

Tags: upstream-0.22.0
ImportĀ upstreamĀ versionĀ 0.22.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
2
/*
3
 
 * Copyright (C) 2007 Collabora Ltd.
 
3
 * Copyright (C) 2007-2008 Collabora Ltd.
4
4
 *
5
5
 * This library is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU Lesser General Public
63
63
        GtkStatusIcon         *icon;
64
64
        EmpathyContactManager *manager;
65
65
        EmpathyFilter         *text_filter;
 
66
        EmpathyFilter         *call_filter;
66
67
        EmpathyIdle           *idle;
67
68
        MissionControl        *mc;
68
69
        GList                 *events;
90
91
static void       empathy_status_icon_class_init  (EmpathyStatusIconClass *klass);
91
92
static void       empathy_status_icon_init        (EmpathyStatusIcon      *icon);
92
93
static void       status_icon_finalize            (GObject                *object);
93
 
static void       status_icon_filter_new_channel  (EmpathyFilter          *filter,
 
94
static void       status_icon_text_filter_new_channel (EmpathyFilter          *filter,
 
95
                                                   TpConn                 *tp_conn,
 
96
                                                   TpChan                 *tp_chan,
 
97
                                                   EmpathyStatusIcon      *icon);
 
98
static void       status_icon_call_filter_new_channel (EmpathyFilter          *filter,
94
99
                                                   TpConn                 *tp_conn,
95
100
                                                   TpChan                 *tp_chan,
96
101
                                                   EmpathyStatusIcon      *icon);
193
198
                                                TP_IFACE_CHANNEL_TYPE_TEXT,
194
199
                                                MC_FILTER_PRIORITY_DIALOG,
195
200
                                                MC_FILTER_FLAG_INCOMING);
 
201
        priv->call_filter = empathy_filter_new ("org.gnome.Empathy.CallFilter",
 
202
                                                "/org/gnome/Empathy/CallFilter",
 
203
                                                TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
 
204
                                                MC_FILTER_PRIORITY_DIALOG,
 
205
                                                MC_FILTER_FLAG_INCOMING);
196
206
 
197
207
        /* Setup EmpathyIdle */
198
208
        priv->idle = empathy_idle_new ();
216
226
        status_icon_idle_notify_cb (icon);
217
227
 
218
228
        g_signal_connect (priv->text_filter, "new-channel",
219
 
                          G_CALLBACK (status_icon_filter_new_channel),
 
229
                          G_CALLBACK (status_icon_text_filter_new_channel),
 
230
                          icon);
 
231
        g_signal_connect (priv->call_filter, "new-channel",
 
232
                          G_CALLBACK (status_icon_call_filter_new_channel),
220
233
                          icon);
221
234
        g_signal_connect_swapped (priv->idle, "notify",
222
235
                                  G_CALLBACK (status_icon_idle_notify_cb),
267
280
        g_object_unref (priv->idle);
268
281
        g_object_unref (priv->manager);
269
282
        g_object_unref (priv->mc);
 
283
        g_object_unref (priv->text_filter);
 
284
        g_object_unref (priv->call_filter);
270
285
}
271
286
 
272
287
EmpathyStatusIcon *
299
314
}
300
315
 
301
316
static void
302
 
status_icon_filter_new_channel (EmpathyFilter     *filter,
303
 
                                TpConn            *tp_conn,
304
 
                                TpChan            *tp_chan,
305
 
                                EmpathyStatusIcon *icon)
 
317
status_icon_text_filter_new_channel (EmpathyFilter     *filter,
 
318
                                     TpConn            *tp_conn,
 
319
                                     TpChan            *tp_chan,
 
320
                                     EmpathyStatusIcon *icon)
306
321
{
307
322
        EmpathyStatusIconPriv *priv;
308
323
        McAccount             *account;
309
324
        EmpathyTpChat         *tp_chat;
310
 
        GList                 *messages;
311
325
 
312
326
        priv = GET_PRIV (icon);
313
327
 
320
334
        g_object_set_data (G_OBJECT (tp_chat), "filter", filter);
321
335
        g_object_unref (account);
322
336
 
323
 
        messages = empathy_tp_chat_get_pendings (tp_chat);
324
 
        if (!messages) {
325
 
                empathy_debug (DEBUG_DOMAIN, "No pending msg, waiting...");
326
 
                g_signal_connect (tp_chat, "message-received",
327
 
                                  G_CALLBACK (status_icon_message_received_cb),
328
 
                                  icon);
329
 
                return;
330
 
        }
331
 
 
332
 
        status_icon_message_received_cb (tp_chat, messages->data, icon);
333
 
 
334
 
        g_list_foreach (messages, (GFunc) g_object_unref, NULL);
335
 
        g_list_free (messages);
 
337
        g_signal_connect (tp_chat, "message-received",
 
338
                          G_CALLBACK (status_icon_message_received_cb),
 
339
                          icon);
336
340
}
337
341
 
338
342
static void
358
362
        event = status_icon_event_new (icon, EMPATHY_IMAGE_NEW_MESSAGE, msg);
359
363
        event->func = status_icon_event_msg_cb;
360
364
        event->user_data = tp_chat;
 
365
        g_free (msg);
 
366
}
 
367
 
 
368
static void
 
369
status_icon_call_member_added_cb (EmpathyTpGroup    *group,
 
370
                                  EmpathyContact    *member,
 
371
                                  EmpathyContact    *actor,
 
372
                                  guint              reason,
 
373
                                  const gchar       *message,
 
374
                                  EmpathyStatusIcon *icon)
 
375
{
 
376
        EmpathyFilter *filter;
 
377
 
 
378
        if (empathy_contact_is_user (member)) {
 
379
                /* We are member, it's an outgoing call, we can dispatch
 
380
                 * the channel without asking the user */
 
381
                empathy_debug (DEBUG_DOMAIN, "Process OUTGOING call channel");
 
382
                filter = g_object_get_data (G_OBJECT (group), "filter");
 
383
                empathy_filter_process (filter,
 
384
                                        empathy_tp_group_get_channel (group),
 
385
                                        TRUE);
 
386
                g_object_unref (group);
 
387
        }
 
388
}
 
389
 
 
390
static void
 
391
status_icon_event_call_cb (StatusIconEvent *event)
 
392
{
 
393
        EmpathyFilter  *filter;
 
394
        EmpathyTpGroup *group;
 
395
 
 
396
        empathy_debug (DEBUG_DOMAIN, "Dispatching call channel");
 
397
 
 
398
        group = event->user_data;
 
399
        filter = g_object_get_data (G_OBJECT (group), "filter");
 
400
        empathy_filter_process (filter,
 
401
                                empathy_tp_group_get_channel (group),
 
402
                                TRUE);
 
403
        g_object_unref (group);
 
404
}
 
405
 
 
406
static void
 
407
status_icon_call_local_pending_cb (EmpathyTpGroup    *group,
 
408
                                   EmpathyContact    *member,
 
409
                                   EmpathyContact    *actor,
 
410
                                   guint              reason,
 
411
                                   const gchar       *message,
 
412
                                   EmpathyStatusIcon *icon)
 
413
{
 
414
        StatusIconEvent *event;
 
415
 
 
416
        if (empathy_contact_is_user (member)) {
 
417
                gchar *msg;
 
418
 
 
419
                /* We are local pending, it's an incoming call, we need to ask
 
420
                 * the user if he wants to accept the call. */
 
421
                empathy_debug (DEBUG_DOMAIN, "INCOMING call, add event");
 
422
 
 
423
                msg = g_strdup_printf (_("Incoming call from %s:\n%s"),
 
424
                                       empathy_contact_get_name (member),
 
425
                                       message);
 
426
 
 
427
                event = status_icon_event_new (icon, EMPATHY_IMAGE_VOIP, msg);
 
428
                event->func = status_icon_event_call_cb;
 
429
                event->user_data = group;
 
430
                g_free (msg);
 
431
        }
 
432
}
 
433
 
 
434
static void
 
435
status_icon_call_filter_new_channel (EmpathyFilter     *filter,
 
436
                                     TpConn            *tp_conn,
 
437
                                     TpChan            *tp_chan,
 
438
                                     EmpathyStatusIcon *icon)
 
439
{
 
440
        EmpathyStatusIconPriv *priv;
 
441
        McAccount             *account;
 
442
        EmpathyTpGroup        *group;
 
443
 
 
444
        priv = GET_PRIV (icon);
 
445
 
 
446
        account = mission_control_get_account_for_connection (priv->mc, tp_conn, NULL);
 
447
 
 
448
        empathy_debug (DEBUG_DOMAIN, "New media channel to be filtered");
 
449
 
 
450
        /* FIXME: We have to check if the user is member or local-pending to
 
451
         * know if it's an incoming or outgoing call because of the way we
 
452
         * request media channels MC can't know if it's incoming or outgoing */
 
453
        group = empathy_tp_group_new (account, tp_chan);
 
454
        g_object_set_data (G_OBJECT (group), "filter", filter);
 
455
        g_object_unref (account);
 
456
 
 
457
        g_signal_connect (group, "member-added",
 
458
                          G_CALLBACK (status_icon_call_member_added_cb),
 
459
                          icon);
 
460
        g_signal_connect (group, "local-pending",
 
461
                          G_CALLBACK (status_icon_call_local_pending_cb),
 
462
                          icon);
361
463
}
362
464
 
363
465
static void
670
772
        empathy_filter_process (filter,
671
773
                                empathy_tp_chat_get_channel (tp_chat),
672
774
                                TRUE);
 
775
 
673
776
        g_object_unref (tp_chat);
674
777
}
675
778