]> git.0d.be Git - empathy.git/blob - libempathy/empathy-tp-call.c
auth-client: improve the password request dialog
[empathy.git] / libempathy / empathy-tp-call.c
1 /*
2  * Copyright (C) 2007 Elliot Fairweather
3  * Copyright (C) 2007-2008 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
20  *          Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <string.h>
24
25 #include <telepathy-glib/proxy-subclass.h>
26 #include <telepathy-glib/dbus.h>
27 #include <telepathy-glib/interfaces.h>
28 #include <telepathy-glib/util.h>
29
30 #include "empathy-tp-call.h"
31 #include "empathy-tp-contact-factory.h"
32 #include "empathy-utils.h"
33 #include "empathy-marshal.h"
34
35 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
36 #include "empathy-debug.h"
37
38 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpCall)
39 typedef struct
40 {
41   gboolean dispose_has_run;
42   TpAccount *account;
43   TpChannel *channel;
44   EmpathyContact *contact;
45   gboolean is_incoming;
46   guint status;
47
48   EmpathyTpCallStream *audio;
49   EmpathyTpCallStream *video;
50 } EmpathyTpCallPriv;
51
52 /* signal enum */
53 enum {
54   AUDIO_STREAM_ERROR,
55   VIDEO_STREAM_ERROR,
56   LAST_SIGNAL
57 };
58
59 static guint signals[LAST_SIGNAL] = {0};
60
61 enum
62 {
63   PROP_0,
64   PROP_ACCOUNT,
65   PROP_CHANNEL,
66   PROP_CONTACT,
67   PROP_STATUS,
68   PROP_AUDIO_STREAM,
69   PROP_VIDEO_STREAM
70 };
71
72 G_DEFINE_TYPE (EmpathyTpCall, empathy_tp_call, G_TYPE_OBJECT)
73
74 static void
75 tp_call_add_stream (EmpathyTpCall *call,
76                     guint stream_id,
77                     guint contact_handle,
78                     guint stream_type,
79                     guint stream_state,
80                     guint stream_direction)
81 {
82   EmpathyTpCallPriv *priv = GET_PRIV (call);
83
84   switch (stream_type)
85     {
86       case TP_MEDIA_STREAM_TYPE_AUDIO:
87         DEBUG ("Audio stream - id: %d, state: %d, direction: %d",
88             stream_id, stream_state, stream_direction);
89         priv->audio->exists = TRUE;
90         priv->audio->id = stream_id;
91         priv->audio->state = stream_state;
92         priv->audio->direction = stream_direction;
93         g_object_notify (G_OBJECT (call), "audio-stream");
94         break;
95       case TP_MEDIA_STREAM_TYPE_VIDEO:
96         DEBUG ("Video stream - id: %d, state: %d, direction: %d",
97             stream_id, stream_state, stream_direction);
98         priv->video->exists = TRUE;
99         priv->video->id = stream_id;
100         priv->video->state = stream_state;
101         priv->video->direction = stream_direction;
102         g_object_notify (G_OBJECT (call), "video-stream");
103         break;
104       default:
105         DEBUG ("Unknown stream type: %d", stream_type);
106     }
107 }
108
109 static void
110 tp_call_stream_added_cb (TpChannel *channel,
111                          guint stream_id,
112                          guint contact_handle,
113                          guint stream_type,
114                          gpointer user_data,
115                          GObject *call)
116 {
117   DEBUG ("Stream added - stream id: %d, contact handle: %d, stream type: %d",
118       stream_id, contact_handle, stream_type);
119
120   tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
121       stream_type, TP_MEDIA_STREAM_STATE_DISCONNECTED,
122       TP_MEDIA_STREAM_DIRECTION_NONE);
123 }
124
125 static void
126 tp_call_stream_removed_cb (TpChannel *channel,
127                            guint stream_id,
128                            gpointer user_data,
129                            GObject *call)
130 {
131   EmpathyTpCallPriv *priv = GET_PRIV (call);
132
133   DEBUG ("Stream removed - stream id: %d", stream_id);
134
135   if (stream_id == priv->audio->id)
136     {
137       priv->audio->exists = FALSE;
138       g_object_notify (call, "audio-stream");
139     }
140   else if (stream_id == priv->video->id)
141     {
142       priv->video->exists = FALSE;
143       g_object_notify (call, "video-stream");
144     }
145 }
146
147 static void
148 tp_call_stream_state_changed_cb (TpChannel *proxy,
149                                  guint stream_id,
150                                  guint stream_state,
151                                  gpointer user_data,
152                                  GObject *call)
153 {
154   EmpathyTpCallPriv *priv = GET_PRIV (call);
155
156   DEBUG ("Stream state changed - stream id: %d, state state: %d",
157       stream_id, stream_state);
158
159   if (stream_id == priv->audio->id)
160     {
161       priv->audio->state = stream_state;
162       g_object_notify (call, "audio-stream");
163     }
164   else if (stream_id == priv->video->id)
165     {
166       priv->video->state = stream_state;
167       g_object_notify (call, "video-stream");
168     }
169 }
170
171 static void
172 tp_call_stream_direction_changed_cb (TpChannel *channel,
173                                      guint stream_id,
174                                      guint stream_direction,
175                                      guint pending_flags,
176                                      gpointer user_data,
177                                      GObject *call)
178 {
179   EmpathyTpCallPriv *priv = GET_PRIV (call);
180
181   DEBUG ("Stream direction changed - stream: %d, direction: %d",
182       stream_id, stream_direction);
183
184   if (stream_id == priv->audio->id)
185     {
186       priv->audio->direction = stream_direction;
187       g_object_notify (call, "audio-stream");
188     }
189   else if (stream_id == priv->video->id)
190     {
191       priv->video->direction = stream_direction;
192       g_object_notify (call, "video-stream");
193     }
194 }
195
196 static void
197 tp_call_request_streams_cb (TpChannel *channel,
198                             const GPtrArray *streams,
199                             const GError *error,
200                             gpointer user_data,
201                             GObject *call)
202 {
203   guint i;
204
205   if (error)
206     {
207       DEBUG ("Error requesting streams: %s", error->message);
208       return;
209     }
210
211   for (i = 0; i < streams->len; i++)
212     {
213       GValueArray *values;
214       guint stream_id;
215       guint contact_handle;
216       guint stream_type;
217       guint stream_state;
218       guint stream_direction;
219
220       values = g_ptr_array_index (streams, i);
221       stream_id = g_value_get_uint (g_value_array_get_nth (values, 0));
222       contact_handle = g_value_get_uint (g_value_array_get_nth (values, 1));
223       stream_type = g_value_get_uint (g_value_array_get_nth (values, 2));
224       stream_state = g_value_get_uint (g_value_array_get_nth (values, 3));
225       stream_direction = g_value_get_uint (g_value_array_get_nth (values, 4));
226
227       tp_call_add_stream (EMPATHY_TP_CALL (call), stream_id, contact_handle,
228           stream_type, stream_state, stream_direction);
229   }
230 }
231
232 static void
233 tp_call_request_streams_for_capabilities (EmpathyTpCall *call,
234                                           EmpathyCapabilities capabilities)
235 {
236   EmpathyTpCallPriv *priv = GET_PRIV (call);
237   GArray *stream_types;
238   guint handle;
239   guint stream_type;
240
241   if (capabilities == EMPATHY_CAPABILITIES_UNKNOWN)
242       capabilities = EMPATHY_CAPABILITIES_AUDIO | EMPATHY_CAPABILITIES_VIDEO;
243
244   DEBUG ("Requesting new stream for capabilities %d",
245       capabilities);
246
247   stream_types = g_array_new (FALSE, FALSE, sizeof (guint));
248   handle = empathy_contact_get_handle (priv->contact);
249
250   if (capabilities & EMPATHY_CAPABILITIES_AUDIO)
251     {
252       stream_type = TP_MEDIA_STREAM_TYPE_AUDIO;
253       g_array_append_val (stream_types, stream_type);
254     }
255   if (capabilities & EMPATHY_CAPABILITIES_VIDEO)
256     {
257       stream_type = TP_MEDIA_STREAM_TYPE_VIDEO;
258       g_array_append_val (stream_types, stream_type);
259     }
260
261   tp_cli_channel_type_streamed_media_call_request_streams (priv->channel, -1,
262       handle, stream_types, tp_call_request_streams_cb, NULL, NULL,
263       G_OBJECT (call));
264
265   g_array_free (stream_types, TRUE);
266 }
267
268 static void
269 tp_call_got_contact_cb (TpConnection            *connection,
270                         EmpathyContact          *contact,
271                         const GError            *error,
272                         gpointer                 user_data,
273                         GObject                 *call)
274 {
275   EmpathyTpCallPriv *priv = GET_PRIV (call);
276
277   if (error)
278     {
279       DEBUG ("Error: %s", error->message);
280       return;
281     }
282
283   priv->contact = g_object_ref (contact);
284
285   if (priv->status < EMPATHY_TP_CALL_STATUS_PENDING)
286     {
287       priv->status = EMPATHY_TP_CALL_STATUS_PENDING;
288       g_object_notify (G_OBJECT (call), "status");
289     }
290
291   g_object_notify (G_OBJECT (call), "contact");
292 }
293
294 static void
295 tp_call_update_status (EmpathyTpCall *call)
296 {
297   EmpathyTpCallPriv *priv = GET_PRIV (call);
298   TpHandle self_handle;
299   const TpIntSet *set;
300   TpIntSetIter iter;
301
302   g_object_ref (call);
303
304   self_handle = tp_channel_group_get_self_handle (priv->channel);
305   set = tp_channel_group_get_members (priv->channel);
306   tp_intset_iter_init (&iter, set);
307   while (tp_intset_iter_next (&iter))
308     {
309       if (priv->status == EMPATHY_TP_CALL_STATUS_PENDING &&
310           ((priv->is_incoming && iter.element == self_handle) ||
311            (!priv->is_incoming && iter.element != self_handle)))
312         {
313           priv->status = EMPATHY_TP_CALL_STATUS_ACCEPTED;
314           g_object_notify (G_OBJECT (call), "status");
315         }
316     }
317
318   g_object_unref (call);
319 }
320
321 static void
322 tp_call_channel_invalidated_cb (TpChannel     *channel,
323                                 GQuark         domain,
324                                 gint           code,
325                                 gchar         *message,
326                                 EmpathyTpCall *call)
327 {
328   EmpathyTpCallPriv *priv = GET_PRIV (call);
329
330   DEBUG ("Channel invalidated: %s", message);
331   priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
332   g_object_notify (G_OBJECT (call), "status");
333 }
334
335 static void
336 tp_call_async_cb (TpProxy *proxy,
337                   const GError *error,
338                   gpointer user_data,
339                   GObject *call)
340 {
341   if (error)
342       DEBUG ("Error %s: %s", (gchar *) user_data, error->message);
343 }
344
345 static void
346 tp_call_stream_error_cb (TpChannel *channel,
347     guint stream_id,
348     guint error_code,
349     const gchar *msg,
350     gpointer user_data,
351     GObject *call)
352 {
353   EmpathyTpCall *self = EMPATHY_TP_CALL (call);
354   EmpathyTpCallPriv *priv = GET_PRIV (self);
355
356   DEBUG ("Stream error on stream %u: %s (code: %u)", stream_id, msg,
357       error_code);
358
359   if (priv->audio->id == stream_id)
360     {
361       g_signal_emit (call, signals[AUDIO_STREAM_ERROR], 0, error_code, msg);
362     }
363   else if (priv->video->id == stream_id)
364     {
365       g_signal_emit (call, signals[VIDEO_STREAM_ERROR], 0, error_code, msg);
366     }
367   else
368     {
369       DEBUG ("Unknown stream id: %u", stream_id);
370     }
371 }
372
373 static GObject *
374 tp_call_constructor (GType type,
375                      guint n_construct_params,
376                      GObjectConstructParam *construct_params)
377 {
378   GObject *object;
379   EmpathyTpCall *call;
380   EmpathyTpCallPriv *priv;
381
382   object = G_OBJECT_CLASS (empathy_tp_call_parent_class)->constructor (type,
383       n_construct_params, construct_params);
384
385   call = EMPATHY_TP_CALL (object);
386   priv = GET_PRIV (call);
387
388   /* Setup streamed media channel */
389   g_signal_connect (priv->channel, "invalidated",
390       G_CALLBACK (tp_call_channel_invalidated_cb), call);
391   tp_cli_channel_type_streamed_media_connect_to_stream_added (priv->channel,
392       tp_call_stream_added_cb, NULL, NULL, G_OBJECT (call), NULL);
393   tp_cli_channel_type_streamed_media_connect_to_stream_removed (priv->channel,
394       tp_call_stream_removed_cb, NULL, NULL, G_OBJECT (call), NULL);
395   tp_cli_channel_type_streamed_media_connect_to_stream_state_changed (priv->channel,
396       tp_call_stream_state_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
397   tp_cli_channel_type_streamed_media_connect_to_stream_direction_changed (priv->channel,
398       tp_call_stream_direction_changed_cb, NULL, NULL, G_OBJECT (call), NULL);
399   tp_cli_channel_type_streamed_media_connect_to_stream_error (priv->channel,
400       tp_call_stream_error_cb, NULL, NULL, G_OBJECT (call), NULL);
401   tp_cli_channel_type_streamed_media_call_list_streams (priv->channel, -1,
402       tp_call_request_streams_cb, NULL, NULL, G_OBJECT (call));
403
404   /* Is the call incoming? */
405   priv->is_incoming = !tp_channel_get_requested (priv->channel);
406
407   /* Get the remote contact */
408   empathy_tp_contact_factory_get_from_handle (
409       tp_channel_borrow_connection (priv->channel),
410       tp_channel_get_handle (priv->channel, NULL), tp_call_got_contact_cb,
411       NULL, NULL, object);
412
413   /* Update status when members changes */
414   tp_call_update_status (call);
415   tp_g_signal_connect_object (priv->channel, "group-members-changed",
416       G_CALLBACK (tp_call_update_status), call, G_CONNECT_SWAPPED);
417
418   return object;
419 }
420 static void
421 tp_call_dispose (GObject *object)
422 {
423   EmpathyTpCallPriv *priv = GET_PRIV (object);
424
425   DEBUG ("Disposing: %p, %d", object, priv->dispose_has_run);
426
427   if (priv->dispose_has_run)
428     return;
429
430   priv->dispose_has_run = TRUE;
431
432   if (priv->channel != NULL)
433     {
434       g_signal_handlers_disconnect_by_func (priv->channel,
435         tp_call_channel_invalidated_cb, object);
436
437       g_object_unref (priv->channel);
438       priv->channel = NULL;
439     }
440
441   if (priv->contact != NULL)
442       g_object_unref (priv->contact);
443
444   tp_clear_object (&priv->account);
445
446   if (G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose)
447     G_OBJECT_CLASS (empathy_tp_call_parent_class)->dispose (object);
448 }
449
450 static void
451 tp_call_finalize (GObject *object)
452 {
453   EmpathyTpCallPriv *priv = GET_PRIV (object);
454
455   DEBUG ("Finalizing: %p", object);
456
457   g_slice_free (EmpathyTpCallStream, priv->audio);
458   g_slice_free (EmpathyTpCallStream, priv->video);
459
460   (G_OBJECT_CLASS (empathy_tp_call_parent_class)->finalize) (object);
461 }
462
463 static void
464 tp_call_set_property (GObject *object,
465                       guint prop_id,
466                       const GValue *value,
467                       GParamSpec *pspec)
468 {
469   EmpathyTpCallPriv *priv = GET_PRIV (object);
470
471   switch (prop_id)
472     {
473     case PROP_ACCOUNT:
474       priv->account = g_value_dup_object (value);
475       break;
476     case PROP_CHANNEL:
477       priv->channel = g_value_dup_object (value);
478       break;
479     default:
480       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
481       break;
482   }
483 }
484
485 static void
486 tp_call_get_property (GObject *object,
487                       guint prop_id,
488                       GValue *value,
489                       GParamSpec *pspec)
490 {
491   EmpathyTpCallPriv *priv = GET_PRIV (object);
492
493   switch (prop_id)
494     {
495     case PROP_ACCOUNT:
496       g_value_set_object (value, priv->channel);
497       break;
498     case PROP_CHANNEL:
499       g_value_set_object (value, priv->channel);
500       break;
501     case PROP_CONTACT:
502       g_value_set_object (value, priv->contact);
503       break;
504     case PROP_STATUS:
505       g_value_set_uint (value, priv->status);
506       break;
507     case PROP_AUDIO_STREAM:
508       g_value_set_pointer (value, priv->audio);
509       break;
510     case PROP_VIDEO_STREAM:
511       g_value_set_pointer (value, priv->video);
512       break;
513     default:
514       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
515       break;
516   }
517 }
518
519 static void
520 empathy_tp_call_class_init (EmpathyTpCallClass *klass)
521 {
522   GObjectClass *object_class = G_OBJECT_CLASS (klass);
523
524   object_class->constructor = tp_call_constructor;
525   object_class->dispose = tp_call_dispose;
526   object_class->finalize = tp_call_finalize;
527   object_class->set_property = tp_call_set_property;
528   object_class->get_property = tp_call_get_property;
529
530   g_type_class_add_private (klass, sizeof (EmpathyTpCallPriv));
531
532   g_object_class_install_property (object_class, PROP_ACCOUNT,
533       g_param_spec_object ("account", "TpAccount", "TpAccount",
534       TP_TYPE_ACCOUNT,
535       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
536       G_PARAM_STATIC_STRINGS));
537
538   g_object_class_install_property (object_class, PROP_CHANNEL,
539       g_param_spec_object ("channel", "channel", "channel",
540       TP_TYPE_CHANNEL,
541       G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
542       G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
543
544   g_object_class_install_property (object_class, PROP_CONTACT,
545       g_param_spec_object ("contact", "Call contact", "Call contact",
546       EMPATHY_TYPE_CONTACT,
547       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
548
549   g_object_class_install_property (object_class, PROP_STATUS,
550       g_param_spec_uint ("status", "Call status",
551       "Call status", 0, 255, 0, G_PARAM_READABLE | G_PARAM_STATIC_NICK |
552       G_PARAM_STATIC_BLURB));
553
554   g_object_class_install_property (object_class, PROP_AUDIO_STREAM,
555       g_param_spec_pointer ("audio-stream", "Audio stream data",
556       "Audio stream data",
557       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
558
559   g_object_class_install_property (object_class, PROP_VIDEO_STREAM,
560       g_param_spec_pointer ("video-stream", "Video stream data",
561       "Video stream data",
562       G_PARAM_READABLE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
563
564   signals[AUDIO_STREAM_ERROR] =
565     g_signal_new ("audio-stream-error",
566       G_TYPE_FROM_CLASS (klass),
567       G_SIGNAL_RUN_LAST, 0,
568       NULL, NULL,
569       _empathy_marshal_VOID__UINT_STRING,
570       G_TYPE_NONE,
571       2, G_TYPE_UINT, G_TYPE_STRING);
572
573   signals[VIDEO_STREAM_ERROR] =
574     g_signal_new ("video-stream-error",
575       G_TYPE_FROM_CLASS (klass),
576       G_SIGNAL_RUN_LAST, 0,
577       NULL, NULL,
578       _empathy_marshal_VOID__UINT_STRING,
579       G_TYPE_NONE,
580       2, G_TYPE_UINT, G_TYPE_STRING);
581 }
582
583 static void
584 empathy_tp_call_init (EmpathyTpCall *call)
585 {
586   EmpathyTpCallPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (call,
587     EMPATHY_TYPE_TP_CALL, EmpathyTpCallPriv);
588
589   call->priv = priv;
590   priv->status = EMPATHY_TP_CALL_STATUS_READYING;
591   priv->contact = NULL;
592   priv->audio = g_slice_new0 (EmpathyTpCallStream);
593   priv->video = g_slice_new0 (EmpathyTpCallStream);
594   priv->audio->exists = FALSE;
595   priv->video->exists = FALSE;
596 }
597
598 EmpathyTpCall *
599 empathy_tp_call_new (TpAccount *account,
600     TpChannel *channel)
601 {
602   g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
603   g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
604
605   return g_object_new (EMPATHY_TYPE_TP_CALL,
606       "account", account,
607       "channel", channel,
608       NULL);
609 }
610
611 void
612 empathy_tp_call_accept_incoming_call (EmpathyTpCall *call)
613 {
614   EmpathyTpCallPriv *priv = GET_PRIV (call);
615   TpHandle self_handle;
616   GArray handles = {(gchar *) &self_handle, 1};
617
618   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
619   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_PENDING);
620
621   if (!priv->is_incoming)
622     return;
623
624   DEBUG ("Accepting incoming call");
625
626   self_handle = tp_channel_group_get_self_handle (priv->channel);
627   tp_cli_channel_interface_group_call_add_members (priv->channel, -1,
628       &handles, NULL, NULL, NULL, NULL, NULL);
629 }
630
631 void
632 empathy_tp_call_close (EmpathyTpCall *call)
633 {
634   EmpathyTpCallPriv *priv = GET_PRIV (call);
635
636   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
637
638   if (priv->status == EMPATHY_TP_CALL_STATUS_CLOSED)
639       return;
640
641   DEBUG ("Closing channel");
642
643   tp_cli_channel_call_close (priv->channel, -1,
644       NULL, NULL, NULL, NULL);
645
646   priv->status = EMPATHY_TP_CALL_STATUS_CLOSED;
647   g_object_notify (G_OBJECT (call), "status");
648 }
649
650 void
651 empathy_tp_call_request_video_stream_direction (EmpathyTpCall *call,
652                                                 gboolean is_sending)
653 {
654   EmpathyTpCallPriv *priv = GET_PRIV (call);
655   guint new_direction;
656
657   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
658   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
659
660   DEBUG ("Requesting video stream direction - is_sending: %d", is_sending);
661
662   if (!priv->video->exists)
663     {
664       if (is_sending)
665           tp_call_request_streams_for_capabilities (call,
666               EMPATHY_CAPABILITIES_VIDEO);
667       return;
668     }
669
670   if (is_sending)
671       new_direction = priv->video->direction | TP_MEDIA_STREAM_DIRECTION_SEND;
672   else
673       new_direction = priv->video->direction & ~TP_MEDIA_STREAM_DIRECTION_SEND;
674
675   tp_cli_channel_type_streamed_media_call_request_stream_direction (priv->channel,
676       -1, priv->video->id, new_direction,
677       (tp_cli_channel_type_streamed_media_callback_for_request_stream_direction)
678       tp_call_async_cb, NULL, NULL, G_OBJECT (call));
679 }
680
681 void
682 empathy_tp_call_start_tone (EmpathyTpCall *call, TpDTMFEvent event)
683 {
684   EmpathyTpCallPriv *priv = GET_PRIV (call);
685
686   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
687   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
688
689   if (!priv->audio->exists)
690       return;
691
692   tp_cli_channel_interface_dtmf_call_start_tone (priv->channel, -1,
693       priv->audio->id, event,
694       (tp_cli_channel_interface_dtmf_callback_for_start_tone) tp_call_async_cb,
695       "starting tone", NULL, G_OBJECT (call));
696 }
697
698 void
699 empathy_tp_call_stop_tone (EmpathyTpCall *call)
700 {
701   EmpathyTpCallPriv *priv = GET_PRIV (call);
702
703   g_return_if_fail (EMPATHY_IS_TP_CALL (call));
704   g_return_if_fail (priv->status == EMPATHY_TP_CALL_STATUS_ACCEPTED);
705
706   if (!priv->audio->exists)
707       return;
708
709   tp_cli_channel_interface_dtmf_call_stop_tone (priv->channel, -1,
710       priv->audio->id,
711       (tp_cli_channel_interface_dtmf_callback_for_stop_tone) tp_call_async_cb,
712       "stoping tone", NULL, G_OBJECT (call));
713 }
714
715 gboolean
716 empathy_tp_call_has_dtmf (EmpathyTpCall *call)
717 {
718   EmpathyTpCallPriv *priv = GET_PRIV (call);
719
720   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
721
722   return tp_proxy_has_interface_by_id (priv->channel,
723       TP_IFACE_QUARK_CHANNEL_INTERFACE_DTMF);
724 }
725
726 /**
727  * empathy_tp_call_is_receiving_video:
728  * @call: the call
729  *
730  * Indicates if the call is receiving video or not.
731  *
732  * Returns: %TRUE if the call is currently receiving video, %FALSE otherwise.
733  */
734 gboolean
735 empathy_tp_call_is_receiving_video (EmpathyTpCall *call)
736 {
737   EmpathyTpCallPriv *priv = GET_PRIV (call);
738
739   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
740
741   if (!priv->video->exists)
742     return FALSE;
743
744   return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE ?
745       TRUE : FALSE;
746 }
747
748 /**
749  * empathy_tp_call_is_sending_video:
750  * @call: the call
751  *
752  * Indicates if the call is sending video or not.
753  *
754  * Returns: %TRUE if the call is currently sending video, %FALSE otherwise.
755  */
756 gboolean
757 empathy_tp_call_is_sending_video (EmpathyTpCall *call)
758 {
759   EmpathyTpCallPriv *priv = GET_PRIV (call);
760
761   g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), FALSE);
762
763   if (!priv->video->exists)
764     return FALSE;
765
766   return priv->video->direction & TP_MEDIA_STREAM_DIRECTION_SEND ?
767       TRUE : FALSE;
768 }
769
770 const gchar *
771 empathy_tp_call_get_connection_manager (EmpathyTpCall *self)
772 {
773   EmpathyTpCallPriv *priv = GET_PRIV (self);
774
775   return tp_account_get_connection_manager (priv->account);
776 }
777
778 gboolean
779 empathy_tp_call_has_initial_video (EmpathyTpCall *self)
780 {
781   EmpathyTpCallPriv *priv = GET_PRIV (self);
782   GHashTable *props;
783   gboolean initial_video;
784   gboolean valid;
785
786   if (priv->channel == NULL)
787     return FALSE;
788
789   g_object_get (priv->channel, "channel-properties", &props, NULL);
790
791   initial_video = tp_asv_get_boolean (props,
792     TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA ".InitialVideo", &valid);
793   if (!valid)
794     initial_video = FALSE;
795
796   g_hash_table_unref (props);
797   return initial_video;
798 }
799
800 static void
801 leave_remove_members_cb (TpChannel *proxy,
802     const GError *error,
803     gpointer user_data,
804     GObject *weak_object)
805 {
806   EmpathyTpCall *self = user_data;
807
808   if (error == NULL)
809     return;
810
811   DEBUG ("RemoveMembers failed (%s); closing the channel", error->message);
812   empathy_tp_call_close (self);
813 }
814
815 void
816 empathy_tp_call_leave (EmpathyTpCall *self)
817 {
818   EmpathyTpCallPriv *priv = GET_PRIV (self);
819   TpHandle self_handle;
820   GArray array = { (gchar *) &self_handle, 1 };
821
822   if (!tp_proxy_has_interface_by_id (priv->channel,
823         TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP))
824     {
825       empathy_tp_call_close (self);
826       return;
827     }
828
829   self_handle = tp_channel_group_get_self_handle (priv->channel);
830   if (self_handle == 0)
831     {
832       /* we are not member of the channel */
833       empathy_tp_call_close (self);
834       return;
835     }
836
837   tp_cli_channel_interface_group_call_remove_members (priv->channel, -1, &array,
838       "", leave_remove_members_cb, self, NULL, G_OBJECT (self));
839 }
840
841 EmpathyTpCallStatus
842 empathy_tp_call_get_status (EmpathyTpCall *self)
843 {
844   EmpathyTpCallPriv *priv = GET_PRIV (self);
845
846   return priv->status;
847 }
848
849 TpAccount *
850 empathy_tp_call_get_account (EmpathyTpCall *self)
851 {
852   EmpathyTpCallPriv *priv = GET_PRIV (self);
853
854   return priv->account;
855 }