]> git.0d.be Git - empathy.git/blob - src/empathy-call-window.c
CallWindow: add an avatar to the top toolbar
[empathy.git] / src / empathy-call-window.c
1 /*
2  * empathy-call-window.c - Source for EmpathyCallWindow
3  * Copyright (C) 2008-2011 Collabora Ltd.
4  * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 #include <math.h>
26
27 #include <gdk/gdkkeysyms.h>
28 #include <gst/gst.h>
29 #include <gtk/gtk.h>
30 #include <glib/gi18n.h>
31
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
35
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
39
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
42
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-tp-contact-factory.h>
45 #include <libempathy/empathy-utils.h>
46 #include <libempathy-gtk/empathy-avatar-image.h>
47 #include <libempathy-gtk/empathy-ui-utils.h>
48 #include <libempathy-gtk/empathy-sound-manager.h>
49 #include <libempathy-gtk/empathy-geometry.h>
50 #include <libempathy-gtk/empathy-images.h>
51
52 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
53 #include <libempathy/empathy-debug.h>
54
55 #include "empathy-call-window.h"
56 #include "empathy-call-window-fullscreen.h"
57 #include "empathy-call-factory.h"
58 #include "empathy-video-widget.h"
59 #include "empathy-audio-src.h"
60 #include "empathy-audio-sink.h"
61 #include "empathy-video-src.h"
62 #include "ev-sidebar.h"
63
64 #define CONTENT_HBOX_BORDER_WIDTH 6
65 #define CONTENT_HBOX_SPACING 3
66 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
67
68 #define SELF_VIDEO_SECTION_WIDTH 120
69 #define SELF_VIDEO_SECTION_HEIGTH 90
70
71 /* The avatar's default width and height are set to the same value because we
72    want a square icon. */
73 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
74 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
75   EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
76
77 #define SMALL_TOOLBAR_SIZE 36
78
79 /* If an video input error occurs, the error message will start with "v4l" */
80 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
81
82 /* The time interval in milliseconds between 2 outgoing rings */
83 #define MS_BETWEEN_RING 500
84
85 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
86
87 enum {
88   PROP_CALL_HANDLER = 1,
89 };
90
91 typedef enum {
92   CONNECTING,
93   CONNECTED,
94   HELD,
95   DISCONNECTED,
96   REDIALING
97 } CallState;
98
99 typedef enum {
100   CAMERA_STATE_OFF = 0,
101   CAMERA_STATE_ON,
102 } CameraState;
103
104 struct _EmpathyCallWindowPriv
105 {
106   gboolean dispose_has_run;
107   EmpathyCallHandler *handler;
108
109   EmpathyContact *contact;
110
111   EmpathyCameraMonitor *camera_monitor;
112
113   guint call_state;
114   gboolean outgoing;
115
116   GtkUIManager *ui_manager;
117   GtkWidget *errors_vbox;
118   /* widget displays the video received from the remote user. This widget is
119    * alive only during call. */
120   ClutterActor *video_output;
121   ClutterActor *video_preview;
122   ClutterActor *preview_hidden_button;
123   GtkWidget *video_container;
124   GtkWidget *remote_user_avatar_widget;
125   GtkWidget *remote_user_avatar_toolbar;
126   GtkWidget *sidebar;
127   GtkWidget *volume_item;
128   GtkWidget *status_label;
129   GtkWidget *redial_button;
130   GtkWidget *mic_button;
131   GtkWidget *camera_button;
132   GtkWidget *dialpad_button;
133   GtkWidget *toolbar;
134   GtkWidget *bottom_toolbar;
135   GtkWidget *pane;
136   GtkAction *redial;
137   GtkAction *menu_sidebar;
138   GtkAction *menu_fullscreen;
139
140   /* The box that contains self and remote avatar and video
141      input/output. When we redial, we destroy and re-create the box */
142   ClutterActor *video_box;
143   ClutterLayoutManager *video_layout;
144
145   /* We keep a reference on the hbox which contains the main content so we can
146      easilly repack everything when toggling fullscreen */
147   GtkWidget *content_hbox;
148
149   gulong video_output_motion_handler_id;
150   guint bus_message_source_id;
151
152   gdouble volume;
153   GtkWidget *volume_scale;
154   GtkWidget *volume_progress_bar;
155   GtkAdjustment *audio_input_adj;
156
157   GtkWidget *dtmf_panel;
158
159   /* Details vbox */
160   GtkWidget *details_vbox;
161   GtkWidget *vcodec_encoding_label;
162   GtkWidget *acodec_encoding_label;
163   GtkWidget *vcodec_decoding_label;
164   GtkWidget *acodec_decoding_label;
165
166   GtkWidget *audio_remote_candidate_label;
167   GtkWidget *audio_local_candidate_label;
168   GtkWidget *video_remote_candidate_label;
169   GtkWidget *video_local_candidate_label;
170   GtkWidget *video_remote_candidate_info_img;
171   GtkWidget *video_local_candidate_info_img;
172   GtkWidget *audio_remote_candidate_info_img;
173   GtkWidget *audio_local_candidate_info_img;
174
175   GstElement *video_input;
176   GstElement *video_preview_sink;
177   GstElement *video_output_sink;
178   GstElement *audio_input;
179   GstElement *audio_output;
180   GstElement *pipeline;
181   GstElement *video_tee;
182
183   GstElement *funnel;
184
185   GList *notifiers;
186
187   GTimer *timer;
188   guint timer_id;
189
190   GtkWidget *video_contrast;
191   GtkWidget *video_brightness;
192   GtkWidget *video_gamma;
193
194   GMutex *lock;
195   gboolean call_started;
196   gboolean sending_video;
197   CameraState camera_state;
198
199   EmpathyCallWindowFullscreen *fullscreen;
200   gboolean is_fullscreen;
201
202   gboolean got_video;
203   guint got_video_src;
204
205   /* Those fields represent the state of the window before it actually was in
206      fullscreen mode. */
207   gboolean sidebar_was_visible_before_fs;
208   gint original_width_before_fs;
209   gint original_height_before_fs;
210
211   gint x, y, w, h, sidebar_width;
212   gboolean maximized;
213
214   /* TRUE if the call should be started when the pipeline is playing */
215   gboolean start_call_when_playing;
216   /* TRUE if we requested to set the pipeline in the playing state */
217   gboolean pipeline_playing;
218
219   EmpathySoundManager *sound_mgr;
220 };
221
222 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
223
224 static void empathy_call_window_realized_cb (GtkWidget *widget,
225   EmpathyCallWindow *window);
226
227 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
228   GdkEvent *event, EmpathyCallWindow *window);
229
230 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
231   GdkEventWindowState *event, EmpathyCallWindow *window);
232
233 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
234   CameraState state);
235
236 static void empathy_call_window_mic_toggled_cb (
237   GtkToggleToolButton *toggle, EmpathyCallWindow *window);
238
239 static void empathy_call_window_sidebar_cb (GtkToggleAction *menu,
240   EmpathyCallWindow *self);
241
242 static void empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
243   EmpathyCallWindow *window);
244
245 static void empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
246   EmpathyCallWindow *window);
247
248 static void empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
249   const gchar *page,
250   EmpathyCallWindow *window);
251
252 static void empathy_call_window_hangup_cb (gpointer object,
253   EmpathyCallWindow *window);
254
255 static void empathy_call_window_fullscreen_cb (gpointer object,
256   EmpathyCallWindow *window);
257
258 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
259
260 static gboolean empathy_call_window_video_button_press_cb (
261   GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
262
263 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
264   GdkEventKey *event, EmpathyCallWindow *window);
265
266 static gboolean empathy_call_window_video_output_motion_notify (
267   GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
268
269 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
270   guint button);
271
272 static void empathy_call_window_redial_cb (gpointer object,
273   EmpathyCallWindow *window);
274
275 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
276   EmpathyCallWindow *window);
277
278 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
279
280 static void empathy_call_window_status_message (EmpathyCallWindow *window,
281   gchar *message);
282
283 static gboolean empathy_call_window_bus_message (GstBus *bus,
284   GstMessage *message, gpointer user_data);
285
286 static void
287 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
288   gdouble value, EmpathyCallWindow *window);
289
290 static void
291 empathy_call_window_setup_toolbars (EmpathyCallWindow *self)
292 {
293   EmpathyCallWindowPriv *priv = GET_PRIV (self);
294   GtkWidget *volume_button;
295   GtkToolItem *tool_item;
296
297   /* Add an empty expanded GtkToolItem to the top toolbar */
298   tool_item = gtk_tool_item_new ();
299   gtk_tool_item_set_expand (tool_item, TRUE);
300   gtk_widget_show (GTK_WIDGET (tool_item));
301   gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
302
303   /* Set the remote avatar */
304   tool_item = gtk_tool_item_new ();
305   priv->remote_user_avatar_toolbar = gtk_image_new ();
306   gtk_container_add (GTK_CONTAINER (tool_item),
307       priv->remote_user_avatar_toolbar);
308   gtk_widget_show_all (GTK_WIDGET (tool_item));
309   gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
310
311   /* Set the volume button */
312   volume_button = gtk_volume_button_new ();
313   /* FIXME listen to the audiosinks signals and update the button according to
314    * that, for now starting out at 1.0 and assuming only the app changes the
315    * volume will do */
316   gtk_scale_button_set_value (GTK_SCALE_BUTTON (volume_button), 1.0);
317   g_signal_connect (G_OBJECT (volume_button), "value-changed",
318     G_CALLBACK (empathy_call_window_volume_changed_cb), self);
319
320   gtk_container_add (GTK_CONTAINER (priv->volume_item),
321       volume_button);
322   gtk_widget_show (GTK_WIDGET (volume_button));
323
324   /* Add an empty expanded GtkToolItem so the label is at the end */
325   tool_item = gtk_tool_item_new ();
326   gtk_tool_item_set_expand (tool_item, TRUE);
327   gtk_widget_show (GTK_WIDGET (tool_item));
328   gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
329
330   /* Set the status label */
331   tool_item = gtk_tool_item_new ();
332   priv->status_label = gtk_label_new (NULL);
333   gtk_container_add (GTK_CONTAINER (tool_item),
334       priv->status_label);
335   gtk_widget_show_all (GTK_WIDGET (tool_item));
336   gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
337 }
338
339 static void
340 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
341 {
342   EmpathyCallWindowPriv *priv = GET_PRIV (window);
343   TpyCallChannel *call;
344   GQuark button_quark;
345   TpDTMFEvent event;
346
347   g_object_get (priv->handler, "call-channel", &call, NULL);
348
349   button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
350   event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
351     button_quark));
352
353   tpy_call_channel_dtmf_start_tone (call, event);
354
355   g_object_unref (call);
356 }
357
358 static void
359 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
360 {
361   EmpathyCallWindowPriv *priv = GET_PRIV (window);
362   TpyCallChannel *call;
363
364   g_object_get (priv->handler, "call-channel", &call, NULL);
365
366   tpy_call_channel_dtmf_stop_tone (call);
367
368   g_object_unref (call);
369 }
370
371 static GtkWidget *
372 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
373   gchar *label_text, GtkWidget *bin)
374 {
375    GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
376    GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
377    GtkWidget *label = gtk_label_new (label_text);
378
379    gtk_widget_set_sensitive (scale, FALSE);
380
381    gtk_container_add (GTK_CONTAINER (bin), vbox);
382
383    gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
384    gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
385    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
386
387    return scale;
388 }
389
390 static void
391 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
392   EmpathyCallWindow *self)
393
394 {
395   EmpathyCallWindowPriv *priv = GET_PRIV (self);
396
397   empathy_video_src_set_channel (priv->video_input,
398     EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
399 }
400
401 static void
402 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
403   EmpathyCallWindow *self)
404
405 {
406   EmpathyCallWindowPriv *priv = GET_PRIV (self);
407
408   empathy_video_src_set_channel (priv->video_input,
409     EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
410 }
411
412 static void
413 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
414   EmpathyCallWindow *self)
415
416 {
417   EmpathyCallWindowPriv *priv = GET_PRIV (self);
418
419   empathy_video_src_set_channel (priv->video_input,
420     EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
421 }
422
423
424 static GtkWidget *
425 empathy_call_window_create_video_input (EmpathyCallWindow *self)
426 {
427   EmpathyCallWindowPriv *priv = GET_PRIV (self);
428   GtkWidget *hbox;
429
430   hbox = gtk_hbox_new (TRUE, 3);
431
432   priv->video_contrast = empathy_call_window_create_video_input_add_slider (
433     self,  _("Contrast"), hbox);
434
435   priv->video_brightness = empathy_call_window_create_video_input_add_slider (
436     self,  _("Brightness"), hbox);
437
438   priv->video_gamma = empathy_call_window_create_video_input_add_slider (
439     self,  _("Gamma"), hbox);
440
441   return hbox;
442 }
443
444 static void
445 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
446 {
447   EmpathyCallWindowPriv *priv = GET_PRIV (self);
448   guint supported;
449   GtkAdjustment *adj;
450
451   supported = empathy_video_src_get_supported_channels (priv->video_input);
452
453   if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
454     {
455       adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
456
457       gtk_adjustment_set_value (adj,
458         empathy_video_src_get_channel (priv->video_input,
459           EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
460
461       g_signal_connect (G_OBJECT (adj), "value-changed",
462         G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
463
464       gtk_widget_set_sensitive (priv->video_contrast, TRUE);
465     }
466
467   if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
468     {
469       adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
470
471       gtk_adjustment_set_value (adj,
472         empathy_video_src_get_channel (priv->video_input,
473           EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
474
475       g_signal_connect (G_OBJECT (adj), "value-changed",
476         G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
477       gtk_widget_set_sensitive (priv->video_brightness, TRUE);
478     }
479
480   if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
481     {
482       adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
483
484       gtk_adjustment_set_value (adj,
485         empathy_video_src_get_channel (priv->video_input,
486           EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
487
488       g_signal_connect (G_OBJECT (adj), "value-changed",
489         G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
490       gtk_widget_set_sensitive (priv->video_gamma, TRUE);
491     }
492 }
493
494 static void
495 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
496   EmpathyCallWindow *self)
497 {
498   EmpathyCallWindowPriv *priv = GET_PRIV (self);
499   gdouble volume;
500
501   volume = gtk_adjustment_get_value (adj)/100.0;
502
503   /* Don't store the volume because of muting */
504   if (volume > 0 || gtk_toggle_tool_button_get_active (
505         GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
506     priv->volume = volume;
507
508   /* Ensure that the toggle button is active if the volume is > 0 and inactive
509    * if it's smaller than 0 */
510   if ((volume > 0) != gtk_toggle_tool_button_get_active (
511         GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
512     gtk_toggle_tool_button_set_active (
513       GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
514
515   empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
516     volume);
517 }
518
519 static void
520 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
521   gdouble level, EmpathyCallWindow *window)
522 {
523   gdouble value;
524   EmpathyCallWindowPriv *priv = GET_PRIV (window);
525
526   value = CLAMP (pow (10, level / 20), 0.0, 1.0);
527   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
528       value);
529 }
530
531 static GtkWidget *
532 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
533 {
534   EmpathyCallWindowPriv *priv = GET_PRIV (self);
535   GtkWidget *hbox, *vbox, *label;
536
537   hbox = gtk_hbox_new (TRUE, 3);
538
539   vbox = gtk_vbox_new (FALSE, 3);
540   gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
541
542   priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
543   gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
544   label = gtk_label_new (_("Volume"));
545
546   priv->audio_input_adj = gtk_range_get_adjustment (
547     GTK_RANGE (priv->volume_scale));
548   priv->volume =  empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
549     (priv->audio_input));
550   gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
551
552   g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
553     G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
554
555   gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
556   gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
557
558   priv->volume_progress_bar = gtk_progress_bar_new ();
559
560   gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
561       GTK_ORIENTATION_VERTICAL);
562
563   gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
564       0);
565
566   gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
567       3);
568
569   return hbox;
570 }
571
572 static void
573 empathy_call_window_show_video_output (EmpathyCallWindow *self,
574     gboolean show)
575 {
576   if (self->priv->video_output != NULL)
577     g_object_set (self->priv->video_output, "visible", show, NULL);
578
579   gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
580 }
581
582 static void
583 create_video_output_widget (EmpathyCallWindow *self)
584 {
585   EmpathyCallWindowPriv *priv = GET_PRIV (self);
586
587   g_assert (priv->video_output == NULL);
588   g_assert (priv->pipeline != NULL);
589
590   priv->video_output = clutter_texture_new ();
591
592   clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
593       TRUE);
594
595   priv->video_output_sink = clutter_gst_video_sink_new (
596       CLUTTER_TEXTURE (priv->video_output));
597
598   clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
599       priv->video_output);
600
601   gtk_widget_add_events (priv->video_container,
602       GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
603   g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
604       G_CALLBACK (empathy_call_window_video_button_press_cb), self);
605 }
606
607 static void
608 create_video_input (EmpathyCallWindow *self)
609 {
610   EmpathyCallWindowPriv *priv = GET_PRIV (self);
611
612   g_assert (priv->video_input == NULL);
613   priv->video_input = empathy_video_src_new ();
614   gst_object_ref (priv->video_input);
615   gst_object_sink (priv->video_input);
616 }
617
618 static void
619 create_audio_input (EmpathyCallWindow *self)
620 {
621   EmpathyCallWindowPriv *priv = GET_PRIV (self);
622
623   g_assert (priv->audio_input == NULL);
624   priv->audio_input = empathy_audio_src_new ();
625   gst_object_ref (priv->audio_input);
626   gst_object_sink (priv->audio_input);
627
628   tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
629     G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
630     self, 0);
631 }
632
633 static void
634 add_video_preview_to_pipeline (EmpathyCallWindow *self)
635 {
636   EmpathyCallWindowPriv *priv = GET_PRIV (self);
637   GstElement *preview;
638
639   g_assert (priv->video_preview != NULL);
640   g_assert (priv->pipeline != NULL);
641   g_assert (priv->video_input != NULL);
642   g_assert (priv->video_tee != NULL);
643
644   preview = priv->video_preview_sink;
645
646   if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
647     {
648       g_warning ("Could not add video input to pipeline");
649       return;
650     }
651
652   if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
653     {
654       g_warning ("Could not add video preview to pipeline");
655       return;
656     }
657
658   if (!gst_element_link (priv->video_input, priv->video_tee))
659     {
660       g_warning ("Could not link video input to video tee");
661       return;
662     }
663
664   if (!gst_element_link (priv->video_tee, preview))
665     {
666       g_warning ("Could not link video tee to video preview");
667       return;
668     }
669 }
670
671 static void
672 empathy_call_window_disable_camera_cb (GtkAction *action,
673     EmpathyCallWindow *self)
674 {
675   clutter_actor_destroy (self->priv->preview_hidden_button);
676
677   gtk_toggle_tool_button_set_active (
678       GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
679 }
680
681 static void
682 empathy_call_window_minimise_camera_cb (GtkAction *action,
683     EmpathyCallWindow *self)
684 {
685   clutter_actor_hide (self->priv->video_preview);
686   clutter_actor_show (self->priv->preview_hidden_button);
687 }
688
689 static void
690 empathy_call_window_maximise_camera_cb (GtkAction *action,
691     EmpathyCallWindow *self)
692 {
693   clutter_actor_show (self->priv->video_preview);
694   clutter_actor_hide (self->priv->preview_hidden_button);
695 }
696
697 static void
698 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
699     EmpathyCallWindow *self)
700 {
701   GtkWidget *menu;
702
703   menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
704       "/preview-menu");
705   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
706       0, gtk_get_current_event_time ());
707   gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
708 }
709
710 static void
711 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
712     EmpathyCallWindow *self)
713 {
714   GtkWidget *menu;
715
716   menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
717       "/preview-hidden-menu");
718   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
719       0, gtk_get_current_event_time ());
720   gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
721 }
722
723 static void
724 create_video_preview (EmpathyCallWindow *self)
725 {
726   EmpathyCallWindowPriv *priv = GET_PRIV (self);
727   ClutterLayoutManager *layout, *layout_center;
728   ClutterActor *preview;
729   ClutterActor *box;
730   ClutterActor *b;
731   GtkWidget *button;
732
733   g_assert (priv->video_preview == NULL);
734
735   preview = clutter_texture_new ();
736   clutter_actor_set_size (preview,
737       SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
738   priv->video_preview_sink = clutter_gst_video_sink_new (
739       CLUTTER_TEXTURE (preview));
740
741   /* Flip the video preview */
742   clutter_actor_set_rotation (preview,
743       CLUTTER_Y_AXIS,
744       180,
745       SELF_VIDEO_SECTION_WIDTH * 0.5,
746       0.0,
747       0.0);
748
749   /* Add a little offset to the video preview */
750   layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
751       CLUTTER_BIN_ALIGNMENT_START);
752   priv->video_preview = clutter_box_new (layout);
753   clutter_actor_set_size (priv->video_preview,
754       SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
755
756   layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
757       CLUTTER_BIN_ALIGNMENT_CENTER);
758   box = clutter_box_new (layout_center);
759   clutter_actor_set_size (box,
760       SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
761
762   clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
763   clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
764
765   g_object_set (priv->video_preview_sink,
766       "sync", FALSE,
767       "async", TRUE,
768       NULL);
769
770   /* Translators: this is an "Info" label. It should be as short
771    * as possible. */
772   button = gtk_button_new_with_label (_("i"));
773   b = gtk_clutter_actor_new_with_contents (button);
774
775   clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
776       b,
777       CLUTTER_BIN_ALIGNMENT_END,
778       CLUTTER_BIN_ALIGNMENT_END);
779
780   g_signal_connect (button, "clicked",
781       G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
782       self);
783
784   /* Translators: this is an "Info" label. It should be as short
785    * as possible. */
786   button = gtk_button_new_with_label (_("i"));
787   priv->preview_hidden_button =
788       gtk_clutter_actor_new_with_contents (button);
789
790   clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
791       priv->preview_hidden_button,
792       CLUTTER_BIN_ALIGNMENT_START,
793       CLUTTER_BIN_ALIGNMENT_END);
794
795   clutter_actor_hide (priv->preview_hidden_button);
796
797   g_signal_connect (button, "clicked",
798       G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
799       self);
800
801   clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
802       priv->video_preview,
803       CLUTTER_BIN_ALIGNMENT_START,
804       CLUTTER_BIN_ALIGNMENT_END);
805 }
806
807 static void
808 play_camera (EmpathyCallWindow *window,
809     gboolean play)
810 {
811   EmpathyCallWindowPriv *priv = GET_PRIV (window);
812   GstElement *preview;
813   GstState state;
814
815   if (priv->video_preview == NULL)
816     {
817       create_video_preview (window);
818       add_video_preview_to_pipeline (window);
819     }
820
821   if (play)
822     state = GST_STATE_PLAYING;
823   else
824     state = GST_STATE_NULL;
825
826   preview = priv->video_preview_sink;
827
828   gst_element_set_state (preview, state);
829   gst_element_set_state (priv->video_input, state);
830   gst_element_set_state (priv->video_tee, state);
831 }
832
833 static void
834 display_video_preview (EmpathyCallWindow *self,
835     gboolean display)
836 {
837   EmpathyCallWindowPriv *priv = GET_PRIV (self);
838
839   if (display)
840     {
841       /* Display the video preview */
842       DEBUG ("Show video preview");
843
844       play_camera (self, TRUE);
845       clutter_actor_show (priv->video_preview);
846     }
847   else
848     {
849       /* Hide the video preview */
850       DEBUG ("Hide video preview");
851
852       if (priv->video_preview != NULL)
853         {
854           clutter_actor_hide (priv->video_preview);
855           play_camera (self, FALSE);
856         }
857     }
858 }
859
860 static void
861 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
862 {
863   EmpathyCallWindowPriv *priv = GET_PRIV (window);
864
865   empathy_call_window_status_message (window, _("Connecting…"));
866   priv->call_state = CONNECTING;
867
868   if (priv->outgoing)
869     empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
870         EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
871 }
872
873 static void
874 disable_camera (EmpathyCallWindow *self)
875 {
876   EmpathyCallWindowPriv *priv = GET_PRIV (self);
877
878   if (priv->camera_state == CAMERA_STATE_OFF)
879     return;
880
881   DEBUG ("Disable camera");
882
883   display_video_preview (self, FALSE);
884
885   if (priv->camera_state == CAMERA_STATE_ON)
886     empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
887
888   priv->camera_state = CAMERA_STATE_OFF;
889 }
890
891 static void
892 enable_camera (EmpathyCallWindow *self)
893 {
894   EmpathyCallWindowPriv *priv = GET_PRIV (self);
895
896   if (priv->camera_state == CAMERA_STATE_ON)
897     return;
898
899   if (priv->video_input == NULL)
900     {
901       DEBUG ("Can't enable camera, no input");
902       return;
903     }
904
905   DEBUG ("Enable camera");
906
907   empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
908
909   priv->camera_state = CAMERA_STATE_ON;
910 }
911
912 static void
913 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
914   EmpathyCallWindow *self)
915 {
916   if (gtk_toggle_tool_button_get_active (toggle))
917     enable_camera (self);
918   else
919     disable_camera (self);
920 }
921
922 static void
923 create_pipeline (EmpathyCallWindow *self)
924 {
925   EmpathyCallWindowPriv *priv = GET_PRIV (self);
926   GstBus *bus;
927
928   g_assert (priv->pipeline == NULL);
929
930   priv->pipeline = gst_pipeline_new (NULL);
931   priv->pipeline_playing = FALSE;
932
933   priv->video_tee = gst_element_factory_make ("tee", NULL);
934   gst_object_ref (priv->video_tee);
935   gst_object_sink (priv->video_tee);
936
937   gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
938
939   bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
940   priv->bus_message_source_id = gst_bus_add_watch (bus,
941       empathy_call_window_bus_message, self);
942
943   g_object_unref (bus);
944 }
945
946 static gboolean
947 empathy_call_window_configure_event_cb (GtkWidget *widget,
948     GdkEvent  *event,
949     EmpathyCallWindow *self)
950 {
951   GdkWindow *gdk_window;
952   GdkWindowState window_state;
953
954   gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
955   gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
956
957   gtk_widget_get_preferred_width (self->priv->sidebar,
958       &self->priv->sidebar_width, NULL);
959
960   gdk_window = gtk_widget_get_window (widget);
961   window_state = gdk_window_get_state (gdk_window);
962   self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
963
964   return FALSE;
965 }
966
967 static void
968 empathy_call_window_destroyed_cb (GtkWidget *object,
969     EmpathyCallWindow *self)
970 {
971   if (gtk_widget_get_visible (self->priv->sidebar))
972     {
973       /* Save the geometry as if the sidebar was hidden. */
974       empathy_geometry_save_values (GTK_WINDOW (self),
975           self->priv->x, self->priv->y,
976           self->priv->w - self->priv->sidebar_width, self->priv->h,
977           self->priv->maximized);
978     }
979 }
980
981 static void
982 empathy_call_window_init (EmpathyCallWindow *self)
983 {
984   EmpathyCallWindowPriv *priv;
985   GtkBuilder *gui;
986   GtkWidget *top_vbox;
987   GtkWidget *page;
988   gchar *filename;
989   GtkWidget *scroll;
990   ClutterConstraint *size_constraint;
991   ClutterActor *remote_avatar;
992   GtkStyleContext *context;
993   GdkRGBA rgba;
994   ClutterColor bg;
995
996   priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
997     EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
998
999   filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1000   gui = empathy_builder_get_file (filename,
1001     "call_window_vbox", &top_vbox,
1002     "errors_vbox", &priv->errors_vbox,
1003     "pane", &priv->pane,
1004     "redial", &priv->redial_button,
1005     "volume", &priv->volume_item,
1006     "microphone", &priv->mic_button,
1007     "camera", &priv->camera_button,
1008     "dialpad", &priv->dialpad_button,
1009     "toolbar", &priv->toolbar,
1010     "bottom_toolbar", &priv->bottom_toolbar,
1011     "menuredial", &priv->redial,
1012     "menusidebar", &priv->menu_sidebar,
1013     "ui_manager", &priv->ui_manager,
1014     "menufullscreen", &priv->menu_fullscreen,
1015     "details_vbox",  &priv->details_vbox,
1016     "vcodec_encoding_label", &priv->vcodec_encoding_label,
1017     "acodec_encoding_label", &priv->acodec_encoding_label,
1018     "acodec_decoding_label", &priv->acodec_decoding_label,
1019     "vcodec_decoding_label", &priv->vcodec_decoding_label,
1020     "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1021     "audio_local_candidate_label", &priv->audio_local_candidate_label,
1022     "video_remote_candidate_label", &priv->video_remote_candidate_label,
1023     "video_local_candidate_label", &priv->video_local_candidate_label,
1024     "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1025     "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1026     "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1027     "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1028     NULL);
1029   g_free (filename);
1030
1031   empathy_builder_connect (gui, self,
1032     "menuhangup", "activate", empathy_call_window_hangup_cb,
1033     "hangup", "clicked", empathy_call_window_hangup_cb,
1034     "menuredial", "activate", empathy_call_window_redial_cb,
1035     "redial", "clicked", empathy_call_window_redial_cb,
1036     "menusidebar", "toggled", empathy_call_window_sidebar_cb,
1037     "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1038     "camera", "toggled", empathy_call_window_camera_toggled_cb,
1039     "dialpad", "toggled", empathy_call_window_dialpad_cb,
1040     "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1041     "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1042     "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1043     "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1044     NULL);
1045
1046   gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1047
1048   priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1049
1050   g_object_bind_property (priv->camera_monitor, "available",
1051       priv->camera_button, "sensitive",
1052       G_BINDING_SYNC_CREATE);
1053
1054   priv->lock = g_mutex_new ();
1055
1056   gtk_container_add (GTK_CONTAINER (self), top_vbox);
1057
1058   priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1059   gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1060                                   CONTENT_HBOX_BORDER_WIDTH);
1061   gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1062
1063   /* avatar/video box */
1064   priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1065       CLUTTER_BIN_ALIGNMENT_CENTER);
1066
1067   priv->video_box = clutter_box_new (priv->video_layout);
1068
1069   priv->video_container = gtk_clutter_embed_new ();
1070
1071   /* Set the background color to that of the rest of the window */
1072   context = gtk_widget_get_style_context (priv->content_hbox);
1073   gtk_style_context_get_background_color (context,
1074       GTK_STATE_FLAG_NORMAL, &rgba);
1075   bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1076   bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1077   bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1078   bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1079   clutter_stage_set_color (
1080       CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1081           GTK_CLUTTER_EMBED (priv->video_container))),
1082       &bg);
1083
1084   clutter_container_add (
1085       CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1086           GTK_CLUTTER_EMBED (priv->video_container))),
1087       priv->video_box,
1088       NULL);
1089
1090   size_constraint = clutter_bind_constraint_new (
1091       gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1092       CLUTTER_BIND_SIZE, 0);
1093   clutter_actor_add_constraint (priv->video_box, size_constraint);
1094
1095   priv->remote_user_avatar_widget = gtk_image_new ();
1096   remote_avatar = gtk_clutter_actor_new_with_contents (
1097       priv->remote_user_avatar_widget);
1098
1099   clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1100       remote_avatar);
1101
1102   gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1103       priv->video_container, TRUE, TRUE,
1104       CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1105
1106   create_pipeline (self);
1107   create_video_output_widget (self);
1108   create_audio_input (self);
1109   create_video_input (self);
1110
1111   /* The call will be started as soon the pipeline is playing */
1112   priv->start_call_when_playing = TRUE;
1113
1114   empathy_call_window_setup_toolbars (self);
1115
1116   priv->sidebar = ev_sidebar_new ();
1117   g_signal_connect (G_OBJECT (priv->sidebar),
1118     "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1119   g_signal_connect (G_OBJECT (priv->sidebar),
1120     "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1121   g_signal_connect (G_OBJECT (priv->sidebar), "changed",
1122     G_CALLBACK (empathy_call_window_sidebar_changed_cb), self);
1123   gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1124
1125   page = empathy_call_window_create_audio_input (self);
1126   ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1127       _("Audio input"), page);
1128
1129   page = empathy_call_window_create_video_input (self);
1130   ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1131       _("Video input"), page);
1132
1133   priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1134       G_CALLBACK (dtmf_button_pressed_cb),
1135       G_CALLBACK (dtmf_button_released_cb));
1136   ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1137       _("Dialpad"), priv->dtmf_panel);
1138
1139   gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1140
1141   /* Put the details vbox in a scroll window as it can require a lot of
1142    * horizontal space. */
1143   scroll = gtk_scrolled_window_new (NULL, NULL);
1144   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1145       priv->details_vbox);
1146
1147   ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details", _("Details"),
1148     scroll);
1149
1150   gtk_widget_show_all (top_vbox);
1151
1152   gtk_widget_hide (priv->sidebar);
1153
1154   priv->fullscreen = empathy_call_window_fullscreen_new (self);
1155
1156   empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1157       priv->video_container);
1158
1159   g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1160       "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1161
1162   g_signal_connect (G_OBJECT (self), "realize",
1163     G_CALLBACK (empathy_call_window_realized_cb), self);
1164
1165   g_signal_connect (G_OBJECT (self), "delete-event",
1166     G_CALLBACK (empathy_call_window_delete_cb), self);
1167
1168   g_signal_connect (G_OBJECT (self), "window-state-event",
1169     G_CALLBACK (empathy_call_window_state_event_cb), self);
1170
1171   g_signal_connect (G_OBJECT (self), "key-press-event",
1172       G_CALLBACK (empathy_call_window_key_press_cb), self);
1173
1174   priv->timer = g_timer_new ();
1175
1176   g_object_ref (priv->ui_manager);
1177   g_object_unref (gui);
1178
1179   priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1180
1181   empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1182   /* These signals are used to track the window position and save it
1183    * when the window is destroyed. We need to do this as we don't want
1184    * the window geometry to be saved with the sidebar taken into account. */
1185   g_signal_connect (self, "destroy",
1186       G_CALLBACK (empathy_call_window_destroyed_cb), self);
1187   g_signal_connect (self, "configure-event",
1188       G_CALLBACK (empathy_call_window_configure_event_cb), self);
1189   g_signal_connect (self, "window-state-event",
1190       G_CALLBACK (empathy_call_window_configure_event_cb), self);
1191 }
1192
1193 /* Instead of specifying a width and a height, we specify only one size. That's
1194    because we want a square avatar icon.  */
1195 static void
1196 init_contact_avatar_with_size (EmpathyContact *contact,
1197     GtkWidget *image_widget,
1198     gint size)
1199 {
1200   GdkPixbuf *pixbuf_avatar = NULL;
1201
1202   if (contact != NULL)
1203     {
1204       pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1205         size, size);
1206     }
1207
1208   if (pixbuf_avatar == NULL)
1209     {
1210       pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1211           EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1212     }
1213
1214   gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1215
1216   if (pixbuf_avatar != NULL)
1217     g_object_unref (pixbuf_avatar);
1218 }
1219
1220 static void
1221 set_window_title (EmpathyCallWindow *self)
1222 {
1223   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1224   gchar *tmp;
1225
1226   if (priv->contact != NULL)
1227     {
1228       /* translators: Call is a noun and %s is the contact name. This string
1229        * is used in the window title */
1230       tmp = g_strdup_printf (_("Call with %s"),
1231           empathy_contact_get_alias (priv->contact));
1232       gtk_window_set_title (GTK_WINDOW (self), tmp);
1233       g_free (tmp);
1234     }
1235   else
1236     {
1237       gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1238     }
1239 }
1240
1241 static void
1242 contact_name_changed_cb (EmpathyContact *contact,
1243     GParamSpec *pspec, EmpathyCallWindow *self)
1244 {
1245   set_window_title (self);
1246 }
1247
1248 static void
1249 contact_avatar_changed_cb (EmpathyContact *contact,
1250     GParamSpec *pspec,
1251     EmpathyCallWindow *self)
1252 {
1253   int size;
1254   GtkAllocation allocation;
1255   GtkWidget *avatar_widget;
1256
1257   avatar_widget = self->priv->remote_user_avatar_widget;
1258
1259   gtk_widget_get_allocation (avatar_widget, &allocation);
1260   size = allocation.height;
1261
1262   if (size == 0)
1263     {
1264       /* the widget is not allocated yet, set a default size */
1265       size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1266           REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1267     }
1268
1269   init_contact_avatar_with_size (contact, avatar_widget, size);
1270
1271   avatar_widget = self->priv->remote_user_avatar_toolbar;
1272
1273   gtk_widget_get_allocation (avatar_widget, &allocation);
1274   size = allocation.height;
1275
1276   if (size == 0)
1277     {
1278       /* the widget is not allocated yet, set a default size */
1279       size = SMALL_TOOLBAR_SIZE;
1280     }
1281
1282   init_contact_avatar_with_size (contact, avatar_widget, size);
1283 }
1284
1285 static void
1286 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1287     EmpathyCallHandler *handler)
1288 {
1289   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1290
1291   g_signal_connect (priv->contact, "notify::name",
1292       G_CALLBACK (contact_name_changed_cb), self);
1293   g_signal_connect (priv->contact, "notify::avatar",
1294     G_CALLBACK (contact_avatar_changed_cb), self);
1295
1296   set_window_title (self);
1297
1298   init_contact_avatar_with_size (priv->contact,
1299       priv->remote_user_avatar_widget,
1300       MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1301           REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1302
1303   init_contact_avatar_with_size (priv->contact,
1304       priv->remote_user_avatar_toolbar,
1305       SMALL_TOOLBAR_SIZE);
1306
1307   /* The remote avatar is shown by default and will be hidden when we receive
1308      video from the remote side. */
1309   clutter_actor_hide (priv->video_output);
1310   gtk_widget_show (priv->remote_user_avatar_widget);
1311 }
1312
1313 static void
1314 update_send_codec (EmpathyCallWindow *self,
1315     gboolean audio)
1316 {
1317   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1318   FsCodec *codec;
1319   GtkWidget *widget;
1320   gchar *tmp;
1321
1322   if (audio)
1323     {
1324       codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1325       widget = priv->acodec_encoding_label;
1326     }
1327   else
1328     {
1329       codec = empathy_call_handler_get_send_video_codec (priv->handler);
1330       widget = priv->vcodec_encoding_label;
1331     }
1332
1333   if (codec == NULL)
1334     return;
1335
1336   tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1337   gtk_label_set_text (GTK_LABEL (widget), tmp);
1338   g_free (tmp);
1339 }
1340
1341 static void
1342 send_audio_codec_notify_cb (GObject *object,
1343     GParamSpec *pspec,
1344     gpointer user_data)
1345 {
1346   EmpathyCallWindow *self = user_data;
1347
1348   update_send_codec (self, TRUE);
1349 }
1350
1351 static void
1352 send_video_codec_notify_cb (GObject *object,
1353     GParamSpec *pspec,
1354     gpointer user_data)
1355 {
1356   EmpathyCallWindow *self = user_data;
1357
1358   update_send_codec (self, FALSE);
1359 }
1360
1361 static void
1362 update_recv_codec (EmpathyCallWindow *self,
1363     gboolean audio)
1364 {
1365   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1366   GList *codecs, *l;
1367   GtkWidget *widget;
1368   GString *str = NULL;
1369
1370   if (audio)
1371     {
1372       codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1373       widget = priv->acodec_decoding_label;
1374     }
1375   else
1376     {
1377       codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1378       widget = priv->vcodec_decoding_label;
1379     }
1380
1381   if (codecs == NULL)
1382     return;
1383
1384   for (l = codecs; l != NULL; l = g_list_next (l))
1385     {
1386       FsCodec *codec = l->data;
1387
1388       if (str == NULL)
1389         str = g_string_new (NULL);
1390       else
1391         g_string_append (str, ", ");
1392
1393       g_string_append_printf (str, "%s/%u", codec->encoding_name,
1394           codec->clock_rate);
1395     }
1396
1397   gtk_label_set_text (GTK_LABEL (widget), str->str);
1398   g_string_free (str, TRUE);
1399 }
1400
1401 static void
1402 recv_audio_codecs_notify_cb (GObject *object,
1403     GParamSpec *pspec,
1404     gpointer user_data)
1405 {
1406   EmpathyCallWindow *self = user_data;
1407
1408   update_recv_codec (self, TRUE);
1409 }
1410
1411 static void
1412 recv_video_codecs_notify_cb (GObject *object,
1413     GParamSpec *pspec,
1414     gpointer user_data)
1415 {
1416   EmpathyCallWindow *self = user_data;
1417
1418   update_recv_codec (self, FALSE);
1419 }
1420
1421 static const gchar *
1422 candidate_type_to_str (FsCandidate *candidate)
1423 {
1424   switch (candidate->type)
1425     {
1426       case FS_CANDIDATE_TYPE_HOST:
1427         return "host";
1428       case FS_CANDIDATE_TYPE_SRFLX:
1429         return "server reflexive";
1430       case FS_CANDIDATE_TYPE_PRFLX:
1431         return "peer reflexive";
1432       case FS_CANDIDATE_TYPE_RELAY:
1433         return "relay";
1434       case FS_CANDIDATE_TYPE_MULTICAST:
1435         return "multicast";
1436     }
1437
1438   return NULL;
1439 }
1440
1441 static const gchar *
1442 candidate_type_to_desc (FsCandidate *candidate)
1443 {
1444   switch (candidate->type)
1445     {
1446       case FS_CANDIDATE_TYPE_HOST:
1447         return _("The IP address as seen by the machine");
1448       case FS_CANDIDATE_TYPE_SRFLX:
1449         return _("The IP address as seen by a server on the Internet");
1450       case FS_CANDIDATE_TYPE_PRFLX:
1451         return _("The IP address of the peer as seen by the other side");
1452       case FS_CANDIDATE_TYPE_RELAY:
1453         return _("The IP address of a relay server");
1454       case FS_CANDIDATE_TYPE_MULTICAST:
1455         return _("The IP address of the multicast group");
1456     }
1457
1458   return NULL;
1459 }
1460
1461 static void
1462 update_candidat_widget (EmpathyCallWindow *self,
1463     GtkWidget *label,
1464     GtkWidget *img,
1465     FsCandidate *candidate)
1466 {
1467   gchar *str;
1468
1469   g_assert (candidate != NULL);
1470   str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1471       candidate->port, candidate_type_to_str (candidate));
1472
1473   gtk_label_set_text (GTK_LABEL (label), str);
1474   gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1475
1476   g_free (str);
1477 }
1478
1479 static void
1480 candidates_changed_cb (GObject *object,
1481     FsMediaType type,
1482     EmpathyCallWindow *self)
1483 {
1484   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1485   FsCandidate *candidate = NULL;
1486
1487   if (type == FS_MEDIA_TYPE_VIDEO)
1488     {
1489       /* Update remote candidate */
1490       candidate = empathy_call_handler_get_video_remote_candidate (
1491           priv->handler);
1492
1493       update_candidat_widget (self, priv->video_remote_candidate_label,
1494           priv->video_remote_candidate_info_img, candidate);
1495
1496       /* Update local candidate */
1497       candidate = empathy_call_handler_get_video_local_candidate (
1498           priv->handler);
1499
1500       update_candidat_widget (self, priv->video_local_candidate_label,
1501           priv->video_local_candidate_info_img, candidate);
1502     }
1503   else
1504     {
1505       /* Update remote candidate */
1506       candidate = empathy_call_handler_get_audio_remote_candidate (
1507           priv->handler);
1508
1509       update_candidat_widget (self, priv->audio_remote_candidate_label,
1510           priv->audio_remote_candidate_info_img, candidate);
1511
1512       /* Update local candidate */
1513       candidate = empathy_call_handler_get_audio_local_candidate (
1514           priv->handler);
1515
1516       update_candidat_widget (self, priv->audio_local_candidate_label,
1517           priv->audio_local_candidate_info_img, candidate);
1518     }
1519 }
1520
1521 static void
1522 empathy_call_window_constructed (GObject *object)
1523 {
1524   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1525   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1526   TpyCallChannel *call;
1527
1528   g_assert (priv->handler != NULL);
1529
1530   g_object_get (priv->handler, "call-channel", &call, NULL);
1531   priv->outgoing = (call == NULL);
1532   if (call != NULL)
1533     g_object_unref (call);
1534
1535   g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1536   g_assert (priv->contact != NULL);
1537
1538   empathy_call_window_setup_avatars (self, priv->handler);
1539   empathy_call_window_set_state_connecting (self);
1540
1541   if (!empathy_call_handler_has_initial_video (priv->handler))
1542     {
1543       gtk_toggle_tool_button_set_active (
1544           GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1545     }
1546   /* If call has InitialVideo, the preview will be started once the call has
1547    * been started (start_call()). */
1548
1549   update_send_codec (self, TRUE);
1550   update_send_codec (self, FALSE);
1551   update_recv_codec (self, TRUE);
1552   update_recv_codec (self, FALSE);
1553
1554   tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1555       G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1556   tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1557       G_CALLBACK (send_video_codec_notify_cb), self, 0);
1558   tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1559       G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1560   tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1561       G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1562
1563   tp_g_signal_connect_object (priv->handler, "candidates-changed",
1564       G_CALLBACK (candidates_changed_cb), self, 0);
1565 }
1566
1567 static void empathy_call_window_dispose (GObject *object);
1568 static void empathy_call_window_finalize (GObject *object);
1569
1570 static void
1571 empathy_call_window_set_property (GObject *object,
1572   guint property_id, const GValue *value, GParamSpec *pspec)
1573 {
1574   EmpathyCallWindowPriv *priv = GET_PRIV (object);
1575
1576   switch (property_id)
1577     {
1578       case PROP_CALL_HANDLER:
1579         priv->handler = g_value_dup_object (value);
1580         break;
1581       default:
1582         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1583     }
1584 }
1585
1586 static void
1587 empathy_call_window_get_property (GObject *object,
1588   guint property_id, GValue *value, GParamSpec *pspec)
1589 {
1590   EmpathyCallWindowPriv *priv = GET_PRIV (object);
1591
1592   switch (property_id)
1593     {
1594       case PROP_CALL_HANDLER:
1595         g_value_set_object (value, priv->handler);
1596         break;
1597       default:
1598         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1599     }
1600 }
1601
1602 static void
1603 empathy_call_window_class_init (
1604   EmpathyCallWindowClass *empathy_call_window_class)
1605 {
1606   GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1607   GParamSpec *param_spec;
1608
1609   g_type_class_add_private (empathy_call_window_class,
1610     sizeof (EmpathyCallWindowPriv));
1611
1612   object_class->constructed = empathy_call_window_constructed;
1613   object_class->set_property = empathy_call_window_set_property;
1614   object_class->get_property = empathy_call_window_get_property;
1615
1616   object_class->dispose = empathy_call_window_dispose;
1617   object_class->finalize = empathy_call_window_finalize;
1618
1619   param_spec = g_param_spec_object ("handler",
1620     "handler", "The call handler",
1621     EMPATHY_TYPE_CALL_HANDLER,
1622     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1623   g_object_class_install_property (object_class,
1624     PROP_CALL_HANDLER, param_spec);
1625 }
1626
1627 void
1628 empathy_call_window_dispose (GObject *object)
1629 {
1630   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1631   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1632
1633   if (priv->dispose_has_run)
1634     return;
1635
1636   priv->dispose_has_run = TRUE;
1637
1638   if (priv->handler != NULL)
1639     {
1640       empathy_call_handler_stop_call (priv->handler);
1641       tp_clear_object (&priv->handler);
1642     }
1643
1644   if (priv->bus_message_source_id != 0)
1645     {
1646       g_source_remove (priv->bus_message_source_id);
1647       priv->bus_message_source_id = 0;
1648     }
1649
1650   if (priv->got_video_src > 0)
1651     {
1652       g_source_remove (priv->got_video_src);
1653       priv->got_video_src = 0;
1654     }
1655
1656   tp_clear_object (&priv->pipeline);
1657   tp_clear_object (&priv->video_input);
1658   tp_clear_object (&priv->audio_input);
1659   tp_clear_object (&priv->video_tee);
1660   tp_clear_object (&priv->ui_manager);
1661   tp_clear_object (&priv->fullscreen);
1662   tp_clear_object (&priv->camera_monitor);
1663
1664   g_list_free_full (priv->notifiers, g_object_unref);
1665
1666   if (priv->timer_id != 0)
1667     g_source_remove (priv->timer_id);
1668   priv->timer_id = 0;
1669
1670   if (priv->contact != NULL)
1671     {
1672       g_signal_handlers_disconnect_by_func (priv->contact,
1673           contact_name_changed_cb, self);
1674       priv->contact = NULL;
1675     }
1676
1677
1678   tp_clear_object (&priv->sound_mgr);
1679
1680   G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1681 }
1682
1683 static void
1684 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1685 {
1686   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1687
1688   if (priv->video_output_motion_handler_id != 0)
1689     {
1690       g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1691           priv->video_output_motion_handler_id);
1692       priv->video_output_motion_handler_id = 0;
1693     }
1694 }
1695
1696 void
1697 empathy_call_window_finalize (GObject *object)
1698 {
1699   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1700   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1701
1702   disconnect_video_output_motion_handler (self);
1703
1704   /* free any data held directly by the object here */
1705   g_mutex_free (priv->lock);
1706
1707   g_timer_destroy (priv->timer);
1708
1709   G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1710 }
1711
1712
1713 EmpathyCallWindow *
1714 empathy_call_window_new (EmpathyCallHandler *handler)
1715 {
1716   return EMPATHY_CALL_WINDOW (
1717     g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1718 }
1719
1720 static void
1721 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1722   GstElement *conference, gpointer user_data)
1723 {
1724   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1725   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1726   FsElementAddedNotifier *notifier;
1727   GKeyFile *keyfile;
1728
1729   DEBUG ("Conference added");
1730
1731   /* Add notifier to set the various element properties as needed */
1732   notifier = fs_element_added_notifier_new ();
1733   keyfile = fs_utils_get_default_element_properties (conference);
1734
1735   if (keyfile != NULL)
1736     fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1737
1738   fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1739
1740   priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1741
1742   gst_bin_add (GST_BIN (priv->pipeline), conference);
1743   gst_element_set_state (conference, GST_STATE_PLAYING);
1744 }
1745
1746 static void
1747 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1748   GstElement *conference, gpointer user_data)
1749 {
1750   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1751   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1752
1753   gst_bin_remove (GST_BIN (priv->pipeline), conference);
1754   gst_element_set_state (conference, GST_STATE_NULL);
1755 }
1756
1757 static gboolean
1758 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1759 {
1760   GstStateChangeReturn state_change_return;
1761   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1762
1763   if (priv->pipeline == NULL)
1764     return TRUE;
1765
1766   if (priv->bus_message_source_id != 0)
1767     {
1768       g_source_remove (priv->bus_message_source_id);
1769       priv->bus_message_source_id = 0;
1770     }
1771
1772   state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1773
1774   if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1775         state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1776     {
1777       if (priv->pipeline != NULL)
1778         g_object_unref (priv->pipeline);
1779       priv->pipeline = NULL;
1780
1781       g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1782           empathy_call_window_mic_volume_changed_cb, self);
1783
1784       if (priv->audio_output != NULL)
1785         g_object_unref (priv->audio_output);
1786       priv->audio_output = NULL;
1787
1788       if (priv->video_tee != NULL)
1789         g_object_unref (priv->video_tee);
1790       priv->video_tee = NULL;
1791
1792       if (priv->video_preview != NULL)
1793         clutter_actor_destroy (priv->video_preview);
1794       priv->video_preview = NULL;
1795
1796       priv->funnel = NULL;
1797
1798       create_pipeline (self);
1799       /* Call will be started when user will hit the 'redial' button */
1800       priv->start_call_when_playing = FALSE;
1801       gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1802
1803       return TRUE;
1804     }
1805   else
1806     {
1807       g_message ("Error: could not destroy pipeline. Closing call window");
1808       gtk_widget_destroy (GTK_WIDGET (self));
1809
1810       return FALSE;
1811     }
1812 }
1813
1814 static void
1815 reset_details_pane (EmpathyCallWindow *self)
1816 {
1817   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1818
1819   gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1820   gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1821   gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1822   gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1823 }
1824
1825 static gboolean
1826 empathy_call_window_disconnected (EmpathyCallWindow *self,
1827     gboolean restart)
1828 {
1829   gboolean could_disconnect = FALSE;
1830   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1831   gboolean could_reset_pipeline;
1832
1833   /* Leave full screen mode if needed */
1834   gtk_window_unfullscreen (GTK_WINDOW (self));
1835
1836   gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1837   gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1838
1839   could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1840
1841   if (priv->call_state == CONNECTING)
1842       empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1843
1844   if (priv->call_state != REDIALING)
1845     priv->call_state = DISCONNECTED;
1846
1847   if (could_reset_pipeline)
1848     {
1849       g_mutex_lock (priv->lock);
1850
1851       g_timer_stop (priv->timer);
1852
1853       if (priv->timer_id != 0)
1854         g_source_remove (priv->timer_id);
1855       priv->timer_id = 0;
1856
1857       g_mutex_unlock (priv->lock);
1858
1859       if (!restart)
1860         /* We are about to destroy the window, no need to update it or create
1861          * a video preview */
1862         return TRUE;
1863
1864       empathy_call_window_status_message (self, _("Disconnected"));
1865
1866       gtk_action_set_sensitive (priv->redial, TRUE);
1867       gtk_widget_set_sensitive (priv->redial_button, TRUE);
1868
1869       /* Unsensitive the camera and mic button */
1870       gtk_widget_set_sensitive (priv->camera_button, FALSE);
1871       gtk_widget_set_sensitive (priv->mic_button, FALSE);
1872
1873       /* Be sure that the mic button is enabled */
1874       gtk_toggle_tool_button_set_active (
1875           GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1876
1877       if (priv->camera_state == CAMERA_STATE_ON)
1878         {
1879           /* Restart the preview with the new pipeline. */
1880           display_video_preview (self, TRUE);
1881         }
1882
1883       gtk_progress_bar_set_fraction (
1884           GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1885
1886       /* destroy the video output; it will be recreated when we'll redial */
1887       disconnect_video_output_motion_handler (self);
1888       if (priv->video_output != NULL)
1889         clutter_actor_destroy (priv->video_output);
1890       priv->video_output = NULL;
1891       if (priv->got_video_src > 0)
1892         {
1893           g_source_remove (priv->got_video_src);
1894           priv->got_video_src = 0;
1895         }
1896
1897       gtk_widget_show (priv->remote_user_avatar_widget);
1898
1899       reset_details_pane (self);
1900
1901       priv->sending_video = FALSE;
1902       priv->call_started = FALSE;
1903
1904       could_disconnect = TRUE;
1905
1906       /* TODO: display the self avatar of the preview (depends if the "Always
1907        * Show Video Preview" is enabled or not) */
1908     }
1909
1910   return could_disconnect;
1911 }
1912
1913
1914 static void
1915 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1916     gpointer user_data)
1917 {
1918   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1919   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1920
1921   if (empathy_call_window_disconnected (self, TRUE) &&
1922       priv->call_state == REDIALING)
1923       empathy_call_window_restart_call (self);
1924 }
1925
1926 static gboolean
1927 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1928     GstPad *sink,
1929     FsMediaType media_type,
1930     EmpathyCallWindow *self)
1931 {
1932   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1933
1934   DEBUG ("removing content");
1935
1936   /*
1937    * This assumes that there is only one video stream per channel...
1938    */
1939
1940   if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
1941     {
1942       if (priv->funnel != NULL)
1943         {
1944           GstElement *output;
1945
1946           output = priv->video_output_sink;
1947
1948           gst_element_set_state (output, GST_STATE_NULL);
1949           gst_element_set_state (priv->funnel, GST_STATE_NULL);
1950
1951           gst_bin_remove (GST_BIN (priv->pipeline), output);
1952           gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
1953           priv->funnel = NULL;
1954           return TRUE;
1955         }
1956     }
1957   else if (media_type == FS_MEDIA_TYPE_AUDIO)
1958     {
1959       if (priv->audio_output != NULL)
1960         {
1961           gst_element_set_state (priv->audio_output, GST_STATE_NULL);
1962
1963           gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
1964           priv->audio_output = NULL;
1965           return TRUE;
1966         }
1967     }
1968
1969   return FALSE;
1970 }
1971
1972 /* Called with global lock held */
1973 static GstPad *
1974 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
1975 {
1976   EmpathyCallWindowPriv *priv = GET_PRIV (self);
1977   GstPad *pad;
1978   GstElement *output;
1979
1980   if (priv->funnel == NULL)
1981     {
1982       output = priv->video_output_sink;
1983
1984       priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
1985
1986       if (!priv->funnel)
1987         {
1988           g_warning ("Could not create fsfunnel");
1989           return NULL;
1990         }
1991
1992       if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
1993         {
1994           gst_object_unref (priv->funnel);
1995           priv->funnel = NULL;
1996           g_warning ("Could  not add funnel to pipeline");
1997           return NULL;
1998         }
1999
2000       if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2001         {
2002           g_warning ("Could not add the video output widget to the pipeline");
2003           goto error;
2004         }
2005
2006       if (!gst_element_link (priv->funnel, output))
2007         {
2008           g_warning ("Could not link output sink to funnel");
2009           goto error_output_added;
2010         }
2011
2012       if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2013         {
2014           g_warning ("Could not start video sink");
2015           goto error_output_added;
2016         }
2017
2018       if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2019         {
2020           g_warning ("Could not start funnel");
2021           goto error_output_added;
2022         }
2023     }
2024
2025   pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2026
2027   if (!pad)
2028     g_warning ("Could not get request pad from funnel");
2029
2030   return pad;
2031
2032
2033  error_output_added:
2034
2035   gst_element_set_locked_state (priv->funnel, TRUE);
2036   gst_element_set_locked_state (output, TRUE);
2037
2038   gst_element_set_state (priv->funnel, GST_STATE_NULL);
2039   gst_element_set_state (output, GST_STATE_NULL);
2040
2041   gst_bin_remove (GST_BIN (priv->pipeline), output);
2042   gst_element_set_locked_state (output, FALSE);
2043
2044  error:
2045
2046   gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2047   priv->funnel = NULL;
2048
2049   return NULL;
2050 }
2051
2052 /* Called with global lock held */
2053 static GstPad *
2054 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2055 {
2056   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2057   GstPad *pad;
2058   GstPadTemplate *template;
2059
2060   if (priv->audio_output == NULL)
2061     {
2062       priv->audio_output = empathy_audio_sink_new ();
2063       g_object_ref_sink (priv->audio_output);
2064
2065       if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2066         {
2067           g_warning ("Could not add audio sink to pipeline");
2068           g_object_unref (priv->audio_output);
2069           goto error_add_output;
2070         }
2071
2072       if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2073         {
2074           g_warning ("Could not start audio sink");
2075           goto error;
2076         }
2077     }
2078
2079   template = gst_element_class_get_pad_template (
2080     GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2081
2082   pad = gst_element_request_pad (priv->audio_output,
2083     template, NULL, NULL);
2084
2085   if (pad == NULL)
2086     {
2087       g_warning ("Could not get sink pad from sink");
2088       return NULL;
2089     }
2090
2091   return pad;
2092
2093 error:
2094   gst_element_set_locked_state (priv->audio_output, TRUE);
2095   gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2096   gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2097   priv->audio_output = NULL;
2098
2099 error_add_output:
2100
2101   return NULL;
2102 }
2103
2104 static gboolean
2105 empathy_call_window_update_timer (gpointer user_data)
2106 {
2107   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2108   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2109   gchar *str;
2110   gdouble time_;
2111
2112   time_ = g_timer_elapsed (priv->timer, NULL);
2113
2114   /* Translators: 'status - minutes:seconds' the caller has been connected */
2115   str = g_strdup_printf (_("%s â€” %d:%02dm"),
2116       priv->call_state == HELD ? _("On hold") : _("Connected"),
2117       (int) time_ / 60, (int) time_ % 60);
2118   empathy_call_window_status_message (self, str);
2119   g_free (str);
2120
2121   return TRUE;
2122 }
2123
2124 #if 0
2125 static void
2126 display_error (EmpathyCallWindow *self,
2127     TpyCallChannel *call,
2128     const gchar *img,
2129     const gchar *title,
2130     const gchar *desc,
2131     const gchar *details)
2132 {
2133   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2134   GtkWidget *info_bar;
2135   GtkWidget *content_area;
2136   GtkWidget *hbox;
2137   GtkWidget *vbox;
2138   GtkWidget *image;
2139   GtkWidget *label;
2140   gchar *txt;
2141
2142   /* Create info bar */
2143   info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2144       NULL);
2145
2146   gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2147
2148   content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2149
2150   /* hbox containing the image and the messages vbox */
2151   hbox = gtk_hbox_new (FALSE, 3);
2152   gtk_container_add (GTK_CONTAINER (content_area), hbox);
2153
2154   /* Add image */
2155   image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2156   gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2157
2158   /* vbox containing the main message and the details expander */
2159   vbox = gtk_vbox_new (FALSE, 3);
2160   gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2161
2162   /* Add text */
2163   txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2164
2165   label = gtk_label_new (NULL);
2166   gtk_label_set_markup (GTK_LABEL (label), txt);
2167   gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2168   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2169   g_free (txt);
2170
2171   gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2172
2173   /* Add details */
2174   if (details != NULL)
2175     {
2176       GtkWidget *expander;
2177
2178       expander = gtk_expander_new (_("Technical Details"));
2179
2180       txt = g_strdup_printf ("<i>%s</i>", details);
2181
2182       label = gtk_label_new (NULL);
2183       gtk_label_set_markup (GTK_LABEL (label), txt);
2184       gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2185       gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2186       g_free (txt);
2187
2188       gtk_container_add (GTK_CONTAINER (expander), label);
2189       gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2190     }
2191
2192   g_signal_connect (info_bar, "response",
2193       G_CALLBACK (gtk_widget_destroy), NULL);
2194
2195   gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2196       FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2197   gtk_widget_show_all (info_bar);
2198 }
2199
2200 static gchar *
2201 media_stream_error_to_txt (EmpathyCallWindow *self,
2202     TpyCallChannel *call,
2203     gboolean audio,
2204     TpMediaStreamError error)
2205 {
2206   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2207   const gchar *cm = NULL;
2208   gchar *url;
2209   gchar *result;
2210
2211   switch (error)
2212     {
2213       case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2214         if (audio)
2215           return g_strdup_printf (
2216               _("%s's software does not understand any of the audio formats "
2217                 "supported by your computer"),
2218             empathy_contact_get_alias (priv->contact));
2219         else
2220           return g_strdup_printf (
2221               _("%s's software does not understand any of the video formats "
2222                 "supported by your computer"),
2223             empathy_contact_get_alias (priv->contact));
2224
2225       case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2226         return g_strdup_printf (
2227             _("Can't establish a connection to %s. "
2228               "One of you might be on a network that does not allow "
2229               "direct connections."),
2230           empathy_contact_get_alias (priv->contact));
2231
2232       case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2233           return g_strdup (_("There was a failure on the network"));
2234
2235       case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2236         if (audio)
2237           return g_strdup (_("The audio formats necessary for this call "
2238                 "are not installed on your computer"));
2239         else
2240           return g_strdup (_("The video formats necessary for this call "
2241                 "are not installed on your computer"));
2242
2243       case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2244         tp_connection_parse_object_path (
2245             tp_channel_borrow_connection (TP_CHANNEL (call)),
2246             NULL, &cm);
2247
2248         url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2249             "product=Telepathy&amp;component=%s", cm);
2250
2251         result = g_strdup_printf (
2252             _("Something unexpected happened in a Telepathy component. "
2253               "Please <a href=\"%s\">report this bug</a> and attach "
2254               "logs gathered from the 'Debug' window in the Help menu."), url);
2255
2256         g_free (url);
2257         g_free (cm);
2258         return result;
2259
2260       case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2261         return g_strdup (_("There was a failure in the call engine"));
2262
2263       case TP_MEDIA_STREAM_ERROR_EOS:
2264         return g_strdup (_("The end of the stream was reached"));
2265
2266       case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2267       default:
2268         return NULL;
2269     }
2270 }
2271
2272 static void
2273 empathy_call_window_stream_error (EmpathyCallWindow *self,
2274     TpyCallChannel *call,
2275     gboolean audio,
2276     guint code,
2277     const gchar *msg,
2278     const gchar *icon,
2279     const gchar *title)
2280 {
2281   gchar *desc;
2282
2283   desc = media_stream_error_to_txt (self, call, audio, code);
2284   if (desc == NULL)
2285     {
2286       /* No description, use the error message. That's not great as it's not
2287        * localized but it's better than nothing. */
2288       display_error (self, call, icon, title, msg, NULL);
2289     }
2290   else
2291     {
2292       display_error (self, call, icon, title, desc, msg);
2293       g_free (desc);
2294     }
2295 }
2296
2297 static void
2298 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2299     guint code,
2300     const gchar *msg,
2301     EmpathyCallWindow *self)
2302 {
2303   empathy_call_window_stream_error (self, call, TRUE, code, msg,
2304       "gnome-stock-mic", _("Can't establish audio stream"));
2305 }
2306
2307 static void
2308 empathy_call_window_video_stream_error (TpyCallChannel *call,
2309     guint code,
2310     const gchar *msg,
2311     EmpathyCallWindow *self)
2312 {
2313   empathy_call_window_stream_error (self, call, FALSE, code, msg,
2314       "camera-web", _("Can't establish video stream"));
2315 }
2316 #endif
2317
2318 static void
2319 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2320     TpyCallState state,
2321     EmpathyCallWindow *self)
2322 {
2323   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2324   TpyCallChannel *call;
2325   gboolean can_send_video;
2326
2327   if (state != TPY_CALL_STATE_ACCEPTED)
2328     return;
2329
2330   if (priv->call_state == CONNECTED)
2331     return;
2332
2333   g_timer_start (priv->timer);
2334   priv->call_state = CONNECTED;
2335
2336   empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2337
2338   can_send_video = priv->video_input != NULL &&
2339     empathy_contact_can_voip_video (priv->contact) &&
2340     empathy_camera_monitor_get_available (priv->camera_monitor);
2341
2342   g_object_get (priv->handler, "call-channel", &call, NULL);
2343
2344   if (tpy_call_channel_has_dtmf (call))
2345     gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2346
2347   if (priv->video_input == NULL)
2348     empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2349
2350   gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2351
2352   gtk_action_set_sensitive (priv->redial, FALSE);
2353   gtk_widget_set_sensitive (priv->redial_button, FALSE);
2354
2355   gtk_widget_set_sensitive (priv->mic_button, TRUE);
2356
2357   clutter_actor_hide (priv->video_output);
2358   gtk_widget_show (priv->remote_user_avatar_widget);
2359
2360   g_object_unref (call);
2361
2362   g_mutex_lock (priv->lock);
2363
2364   priv->timer_id = g_timeout_add_seconds (1,
2365     empathy_call_window_update_timer, self);
2366
2367   g_mutex_unlock (priv->lock);
2368
2369   empathy_call_window_update_timer (self);
2370
2371   gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2372 }
2373
2374 static gboolean
2375 empathy_call_window_show_video_output_cb (gpointer user_data)
2376 {
2377   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2378
2379   if (self->priv->video_output != NULL)
2380     {
2381       gtk_widget_hide (self->priv->remote_user_avatar_widget);
2382       clutter_actor_show (self->priv->video_output);
2383     }
2384
2385   return FALSE;
2386 }
2387
2388 static gboolean
2389 empathy_call_window_check_video_cb (gpointer data)
2390 {
2391   EmpathyCallWindow *self = data;
2392
2393   if (self->priv->got_video)
2394     {
2395       self->priv->got_video = FALSE;
2396       return TRUE;
2397     }
2398
2399   /* No video in the last N seconds, display the remote avatar */
2400   empathy_call_window_show_video_output (self, FALSE);
2401
2402   return TRUE;
2403 }
2404
2405 /* Called from the streaming thread */
2406 static gboolean
2407 empathy_call_window_video_probe_cb (GstPad *pad,
2408     GstMiniObject *mini_obj,
2409     EmpathyCallWindow *self)
2410 {
2411   /* Ignore events */
2412   if (GST_IS_EVENT (mini_obj))
2413     return TRUE;
2414
2415   if (G_UNLIKELY (!self->priv->got_video))
2416     {
2417       /* show the remote video */
2418       g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2419           empathy_call_window_show_video_output_cb,
2420           g_object_ref (self), g_object_unref);
2421
2422       self->priv->got_video = TRUE;
2423     }
2424
2425   return TRUE;
2426 }
2427
2428 /* Called from the streaming thread */
2429 static gboolean
2430 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2431   GstPad *src, guint media_type, gpointer user_data)
2432 {
2433   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2434   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2435   gboolean retval = FALSE;
2436
2437   GstPad *pad;
2438
2439   g_mutex_lock (priv->lock);
2440
2441   switch (media_type)
2442     {
2443       case TP_MEDIA_STREAM_TYPE_AUDIO:
2444         pad = empathy_call_window_get_audio_sink_pad (self);
2445         break;
2446       case TP_MEDIA_STREAM_TYPE_VIDEO:
2447         g_idle_add (empathy_call_window_show_video_output_cb, self);
2448         pad = empathy_call_window_get_video_sink_pad (self);
2449
2450         gst_pad_add_data_probe (src,
2451             G_CALLBACK (empathy_call_window_video_probe_cb), self);
2452         if (priv->got_video_src > 0)
2453           g_source_remove (priv->got_video_src);
2454         priv->got_video_src = g_timeout_add_seconds (5,
2455             empathy_call_window_check_video_cb, self);
2456         break;
2457       default:
2458         g_assert_not_reached ();
2459     }
2460
2461   if (pad == NULL)
2462     goto out;
2463
2464   if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2465       g_warning ("Could not link %s sink pad",
2466           media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2467   else
2468       retval = TRUE;
2469
2470   gst_object_unref (pad);
2471
2472  out:
2473
2474   /* If no sink could be linked, try to add fakesink to prevent the whole call
2475    * aborting */
2476
2477   if (!retval)
2478     {
2479       GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2480
2481       if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2482         {
2483           GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2484           if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2485               GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2486             {
2487               gst_element_set_locked_state (fakesink, TRUE);
2488               gst_element_set_state (fakesink, GST_STATE_NULL);
2489               gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2490             }
2491           else
2492             {
2493               DEBUG ("Could not link real sink, linked fakesink instead");
2494             }
2495           gst_object_unref (sinkpad);
2496         }
2497       else
2498         {
2499           gst_object_unref (fakesink);
2500         }
2501     }
2502
2503
2504   g_mutex_unlock (priv->lock);
2505
2506   return TRUE;
2507 }
2508
2509 static gboolean
2510 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2511   GstPad *sink, FsMediaType media_type, gpointer user_data)
2512 {
2513   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2514   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2515   GstPad *pad;
2516   gboolean retval = FALSE;
2517
2518   switch (media_type)
2519     {
2520       case FS_MEDIA_TYPE_AUDIO:
2521         if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2522           {
2523             g_warning ("Could not add audio source to pipeline");
2524             break;
2525           }
2526
2527         pad = gst_element_get_static_pad (priv->audio_input, "src");
2528         if (!pad)
2529           {
2530             gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2531             g_warning ("Could not get source pad from audio source");
2532             break;
2533           }
2534
2535         if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2536           {
2537             gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2538             g_warning ("Could not link audio source to farsight");
2539             break;
2540           }
2541
2542         if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2543           {
2544             g_warning ("Could not start audio source");
2545             gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2546             gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2547             break;
2548           }
2549
2550         retval = TRUE;
2551         break;
2552       case FS_MEDIA_TYPE_VIDEO:
2553         if (priv->video_tee != NULL)
2554           {
2555             pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2556             if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2557               {
2558                 g_warning ("Could not link video source input pipeline");
2559                 break;
2560               }
2561             gst_object_unref (pad);
2562           }
2563
2564         retval = TRUE;
2565         break;
2566       default:
2567         g_assert_not_reached ();
2568     }
2569
2570   return retval;
2571 }
2572
2573 static void
2574 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2575 {
2576   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2577   GstElement *preview;
2578
2579   disable_camera (self);
2580
2581   DEBUG ("remove video input");
2582   preview = priv->video_preview_sink;
2583
2584   gst_element_set_state (priv->video_input, GST_STATE_NULL);
2585   gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2586   gst_element_set_state (preview, GST_STATE_NULL);
2587
2588   gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2589     preview, NULL);
2590
2591   g_object_unref (priv->video_input);
2592   priv->video_input = NULL;
2593   g_object_unref (priv->video_tee);
2594   priv->video_tee = NULL;
2595   clutter_actor_destroy (priv->video_preview);
2596   priv->video_preview = NULL;
2597
2598   gtk_widget_set_sensitive (priv->camera_button, FALSE);
2599 }
2600
2601 static void
2602 start_call (EmpathyCallWindow *self)
2603 {
2604   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2605
2606   priv->call_started = TRUE;
2607   empathy_call_handler_start_call (priv->handler,
2608       gtk_get_current_event_time ());
2609
2610   if (empathy_call_handler_has_initial_video (priv->handler))
2611     {
2612       TpyCallChannel *call;
2613       TpySendingState s;
2614
2615       g_object_get (priv->handler, "call-channel", &call, NULL);
2616       s = tpy_call_channel_get_video_state (call);
2617
2618       if (s == TPY_SENDING_STATE_PENDING_SEND ||
2619           s == TPY_SENDING_STATE_SENDING)
2620         {
2621           /* Enable 'send video' buttons and display the preview */
2622           gtk_toggle_tool_button_set_active (
2623             GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2624         }
2625       else
2626         {
2627           gtk_toggle_tool_button_set_active (
2628             GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2629
2630           if (priv->video_preview == NULL)
2631             {
2632               create_video_preview (self);
2633               add_video_preview_to_pipeline (self);
2634             }
2635         }
2636
2637       g_object_unref (call);
2638     }
2639 }
2640
2641 static gboolean
2642 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2643   gpointer user_data)
2644 {
2645   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2646   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2647   GstState newstate;
2648
2649   empathy_call_handler_bus_message (priv->handler, bus, message);
2650
2651   switch (GST_MESSAGE_TYPE (message))
2652     {
2653       case GST_MESSAGE_STATE_CHANGED:
2654         if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2655           {
2656             gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2657             if (newstate == GST_STATE_PAUSED)
2658                 empathy_call_window_setup_video_input (self);
2659           }
2660         if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2661             !priv->call_started)
2662           {
2663             gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2664             if (newstate == GST_STATE_PAUSED)
2665               {
2666                 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2667                 priv->pipeline_playing = TRUE;
2668
2669                 if (priv->start_call_when_playing)
2670                   start_call (self);
2671               }
2672           }
2673         break;
2674       case GST_MESSAGE_ERROR:
2675         {
2676           GError *error = NULL;
2677           GstElement *gst_error;
2678           gchar *debug;
2679
2680           gst_message_parse_error (message, &error, &debug);
2681           gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2682
2683           g_message ("Element error: %s -- %s\n", error->message, debug);
2684
2685           if (g_str_has_prefix (gst_element_get_name (gst_error),
2686                 VIDEO_INPUT_ERROR_PREFIX))
2687             {
2688               /* Remove the video input and continue */
2689               if (priv->video_input != NULL)
2690                 empathy_call_window_remove_video_input (self);
2691               gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2692             }
2693           else
2694             {
2695               empathy_call_window_disconnected (self, TRUE);
2696             }
2697           g_error_free (error);
2698           g_free (debug);
2699         }
2700       case GST_MESSAGE_UNKNOWN:
2701       case GST_MESSAGE_EOS:
2702       case GST_MESSAGE_WARNING:
2703       case GST_MESSAGE_INFO:
2704       case GST_MESSAGE_TAG:
2705       case GST_MESSAGE_BUFFERING:
2706       case GST_MESSAGE_STATE_DIRTY:
2707       case GST_MESSAGE_STEP_DONE:
2708       case GST_MESSAGE_CLOCK_PROVIDE:
2709       case GST_MESSAGE_CLOCK_LOST:
2710       case GST_MESSAGE_NEW_CLOCK:
2711       case GST_MESSAGE_STRUCTURE_CHANGE:
2712       case GST_MESSAGE_STREAM_STATUS:
2713       case GST_MESSAGE_APPLICATION:
2714       case GST_MESSAGE_ELEMENT:
2715       case GST_MESSAGE_SEGMENT_START:
2716       case GST_MESSAGE_SEGMENT_DONE:
2717       case GST_MESSAGE_DURATION:
2718       case GST_MESSAGE_ANY:
2719       default:
2720         break;
2721     }
2722
2723   return TRUE;
2724 }
2725
2726 static void
2727 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2728     GHashTable *members,
2729     EmpathyCallWindow *self)
2730 {
2731   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2732   GHashTableIter iter;
2733   gpointer key, value;
2734   gboolean held = FALSE;
2735
2736   g_hash_table_iter_init (&iter, members);
2737   while (g_hash_table_iter_next (&iter, &key, &value))
2738     {
2739       if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2740         {
2741           /* This assumes this is a 1-1 call, otherwise one participant
2742            * putting the call on hold wouldn't mean the call is on hold
2743            * for everyone. */
2744           held = TRUE;
2745           break;
2746         }
2747     }
2748
2749   if (held)
2750     priv->call_state = HELD;
2751   else if (priv->call_state == HELD)
2752     priv->call_state = CONNECTED;
2753 }
2754
2755 static void
2756 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2757     GParamSpec *spec,
2758     EmpathyCallWindow *self)
2759 {
2760   EmpathyCallWindowPriv *priv = GET_PRIV (self);
2761   TpyCallChannel *call;
2762
2763   g_object_get (priv->handler, "call-channel", &call, NULL);
2764   if (call == NULL)
2765     return;
2766
2767 /* FIXME
2768   tp_g_signal_connect_object (call, "audio-stream-error",
2769       G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2770   tp_g_signal_connect_object (call, "video-stream-error",
2771       G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2772 */
2773
2774   tp_g_signal_connect_object (call, "members-changed",
2775       G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2776
2777   g_object_unref (call);
2778 }
2779
2780 static void
2781 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2782 {
2783   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2784   TpyCallChannel *call;
2785
2786   g_signal_connect (priv->handler, "state-changed",
2787     G_CALLBACK (empathy_call_window_state_changed_cb), window);
2788   g_signal_connect (priv->handler, "conference-added",
2789     G_CALLBACK (empathy_call_window_conference_added_cb), window);
2790   g_signal_connect (priv->handler, "conference-removed",
2791     G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2792   g_signal_connect (priv->handler, "closed",
2793     G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2794   g_signal_connect (priv->handler, "src-pad-added",
2795     G_CALLBACK (empathy_call_window_src_added_cb), window);
2796   g_signal_connect (priv->handler, "sink-pad-added",
2797     G_CALLBACK (empathy_call_window_sink_added_cb), window);
2798   g_signal_connect (priv->handler, "sink-pad-removed",
2799     G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2800
2801   g_object_get (priv->handler, "call-channel", &call, NULL);
2802   if (call != NULL)
2803     {
2804       call_handler_notify_call_cb (priv->handler, NULL, window);
2805       g_object_unref (call);
2806     }
2807   else
2808     {
2809       /* call-channel doesn't exist yet, we'll connect signals once it has been
2810        * set */
2811       g_signal_connect (priv->handler, "notify::call-channel",
2812         G_CALLBACK (call_handler_notify_call_cb), window);
2813     }
2814
2815   gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2816 }
2817
2818 static gboolean
2819 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2820   EmpathyCallWindow *window)
2821 {
2822   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2823
2824   if (priv->pipeline != NULL)
2825     {
2826       if (priv->bus_message_source_id != 0)
2827         {
2828           g_source_remove (priv->bus_message_source_id);
2829           priv->bus_message_source_id = 0;
2830         }
2831
2832       gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2833     }
2834
2835   if (priv->call_state == CONNECTING)
2836     empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2837
2838   return FALSE;
2839 }
2840
2841 static void
2842 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2843 {
2844   GtkWidget *menu;
2845   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2846
2847   menu = gtk_ui_manager_get_widget (priv->ui_manager,
2848             "/menubar1");
2849
2850   if (set_fullscreen)
2851     {
2852       gtk_widget_hide (priv->sidebar);
2853       gtk_widget_hide (menu);
2854       gtk_widget_hide (priv->toolbar);
2855     }
2856   else
2857     {
2858       if (priv->sidebar_was_visible_before_fs)
2859         gtk_widget_show (priv->sidebar);
2860
2861       gtk_widget_show (menu);
2862       gtk_widget_show (priv->toolbar);
2863
2864       gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2865           priv->original_height_before_fs);
2866     }
2867 }
2868
2869 static void
2870 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2871 {
2872   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2873
2874   gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2875       set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2876   gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2877       set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2878
2879   if (priv->video_output != NULL)
2880     {
2881 #if 0
2882       gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2883           priv->video_output, TRUE, TRUE,
2884           set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2885           GTK_PACK_START);
2886 #endif
2887     }
2888 }
2889
2890 static gboolean
2891 empathy_call_window_state_event_cb (GtkWidget *widget,
2892   GdkEventWindowState *event, EmpathyCallWindow *window)
2893 {
2894   if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2895     {
2896       EmpathyCallWindowPriv *priv = GET_PRIV (window);
2897       gboolean set_fullscreen = event->new_window_state &
2898         GDK_WINDOW_STATE_FULLSCREEN;
2899
2900       if (set_fullscreen)
2901         {
2902           gboolean sidebar_was_visible;
2903           GtkAllocation allocation;
2904           gint original_width, original_height;
2905
2906           gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2907           original_width = allocation.width;
2908           original_height = allocation.height;
2909
2910           g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2911
2912           priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2913           priv->original_width_before_fs = original_width;
2914           priv->original_height_before_fs = original_height;
2915
2916           if (priv->video_output_motion_handler_id == 0 &&
2917                 priv->video_output != NULL)
2918             {
2919               priv->video_output_motion_handler_id = g_signal_connect (
2920                   G_OBJECT (priv->video_container), "motion-notify-event",
2921                   G_CALLBACK (empathy_call_window_video_output_motion_notify),
2922                   window);
2923             }
2924         }
2925       else
2926         {
2927           disconnect_video_output_motion_handler (window);
2928         }
2929
2930       empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
2931           set_fullscreen);
2932       show_controls (window, set_fullscreen);
2933       show_borders (window, set_fullscreen);
2934       gtk_action_set_stock_id (priv->menu_fullscreen,
2935           (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
2936       priv->is_fullscreen = set_fullscreen;
2937   }
2938
2939   return FALSE;
2940 }
2941
2942 static void
2943 empathy_call_window_update_sidebar_buttons (EmpathyCallWindow *window,
2944     gboolean toggled)
2945 {
2946   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2947
2948   /* Update dialpad button */
2949   g_signal_handlers_block_by_func (priv->dialpad_button,
2950       empathy_call_window_dialpad_cb, window);
2951   gtk_toggle_tool_button_set_active (
2952       GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button),
2953       toggled);
2954   g_signal_handlers_unblock_by_func (priv->dialpad_button,
2955       empathy_call_window_dialpad_cb, window);
2956
2957   /* Update sidebar menu */
2958   g_signal_handlers_block_by_func (priv->menu_sidebar,
2959       empathy_call_window_sidebar_cb, window);
2960   gtk_toggle_action_set_active (
2961       GTK_TOGGLE_ACTION (priv->menu_sidebar),
2962       gtk_widget_get_visible (priv->sidebar));
2963   g_signal_handlers_unblock_by_func (priv->menu_sidebar,
2964       empathy_call_window_sidebar_cb, window);
2965 }
2966
2967 static void
2968 empathy_call_window_show_sidebar (EmpathyCallWindow *window,
2969     gboolean active)
2970 {
2971   EmpathyCallWindowPriv *priv = GET_PRIV (window);
2972   int w, h, sidebar_width, handle_size;
2973   GtkAllocation allocation;
2974   gchar *page;
2975   gboolean dialpad_shown;
2976
2977   gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2978   w = allocation.width;
2979   h = allocation.height;
2980
2981   gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
2982
2983   gtk_widget_get_preferred_width (priv->sidebar, &sidebar_width, NULL);
2984
2985   if (active)
2986     {
2987       gtk_widget_show (priv->sidebar);
2988       w += sidebar_width + handle_size;
2989     }
2990   else
2991     {
2992       w -= sidebar_width + handle_size;
2993       gtk_widget_hide (priv->sidebar);
2994     }
2995
2996   if (w > 0 && h > 0)
2997     gtk_window_resize (GTK_WINDOW (window), w, h);
2998
2999   /* Update the 'Dialpad' menu */
3000   page = ev_sidebar_get_current_page (EV_SIDEBAR (priv->sidebar));
3001   dialpad_shown = active && !tp_strdiff (page, "dialpad");
3002   g_free (page);
3003
3004   empathy_call_window_update_sidebar_buttons (window, dialpad_shown);
3005 }
3006
3007 static void
3008 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3009   CameraState state)
3010 {
3011   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3012   TpyCallChannel *call;
3013
3014   priv->sending_video = (state == CAMERA_STATE_ON);
3015
3016   if (state == CAMERA_STATE_ON)
3017     {
3018       /* When we start sending video, we want to show the video preview by
3019          default. */
3020       display_video_preview (window, TRUE);
3021     }
3022   else
3023     {
3024       display_video_preview (window, FALSE);
3025     }
3026
3027   if (priv->call_state != CONNECTED)
3028     return;
3029
3030   g_object_get (priv->handler, "call-channel", &call, NULL);
3031   DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3032   tpy_call_channel_send_video (call, priv->sending_video);
3033   g_object_unref (call);
3034 }
3035
3036 static void
3037 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3038   EmpathyCallWindow *window)
3039 {
3040   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3041   gboolean active;
3042
3043   active = (gtk_toggle_tool_button_get_active (toggle));
3044
3045   if (active)
3046     {
3047       empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3048         priv->volume);
3049       gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3050     }
3051   else
3052     {
3053       /* TODO, Instead of setting the input volume to 0 we should probably
3054        * stop sending but this would cause the audio call to drop if both
3055        * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3056        * in the future. GNOME #574574
3057        */
3058       empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3059         0);
3060       gtk_adjustment_set_value (priv->audio_input_adj, 0);
3061     }
3062 }
3063
3064 static void
3065 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3066   EmpathyCallWindow *window)
3067 {
3068   empathy_call_window_show_sidebar (window, FALSE);
3069 }
3070
3071 static void
3072 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3073   EmpathyCallWindow *window)
3074 {
3075   empathy_call_window_show_sidebar (window, TRUE);
3076 }
3077
3078 static void
3079 empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
3080   const gchar *page,
3081   EmpathyCallWindow *window)
3082 {
3083   empathy_call_window_update_sidebar_buttons (window,
3084       !tp_strdiff (page, "dialpad"));
3085 }
3086
3087 static void
3088 empathy_call_window_hangup_cb (gpointer object,
3089                                EmpathyCallWindow *window)
3090 {
3091   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3092
3093   empathy_call_handler_stop_call (priv->handler);
3094
3095   if (empathy_call_window_disconnected (window, FALSE))
3096     gtk_widget_destroy (GTK_WIDGET (window));
3097 }
3098
3099 static void
3100 empathy_call_window_restart_call (EmpathyCallWindow *window)
3101 {
3102   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3103
3104   /* Remove error info bars */
3105   gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3106       (GtkCallback) gtk_widget_destroy, NULL);
3107
3108   create_video_output_widget (window);
3109
3110   g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3111       G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3112
3113   /* While the call was disconnected, the input volume might have changed.
3114    * However, since the audio_input source was destroyed, its volume has not
3115    * been updated during that time. That's why we manually update it here */
3116   empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3117
3118   priv->outgoing = TRUE;
3119   empathy_call_window_set_state_connecting (window);
3120
3121   if (priv->pipeline_playing)
3122     start_call (window);
3123   else
3124     /* call will be started when the pipeline is ready */
3125     priv->start_call_when_playing = TRUE;
3126
3127
3128   empathy_call_window_setup_avatars (window, priv->handler);
3129
3130   gtk_action_set_sensitive (priv->redial, FALSE);
3131   gtk_widget_set_sensitive (priv->redial_button, FALSE);
3132 }
3133
3134 static void
3135 empathy_call_window_redial_cb (gpointer object,
3136     EmpathyCallWindow *window)
3137 {
3138   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3139
3140   if (priv->call_state == CONNECTED)
3141     priv->call_state = REDIALING;
3142
3143   empathy_call_handler_stop_call (priv->handler);
3144
3145   if (priv->call_state != CONNECTED)
3146     empathy_call_window_restart_call (window);
3147 }
3148
3149 static void
3150 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3151     EmpathyCallWindow *window)
3152 {
3153   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3154   gboolean active;
3155
3156   active = gtk_toggle_tool_button_get_active (button);
3157
3158   if (active)
3159     ev_sidebar_set_current_page (EV_SIDEBAR (priv->sidebar), "dialpad");
3160
3161   empathy_call_window_show_sidebar (window, active);
3162 }
3163
3164 static void
3165 empathy_call_window_sidebar_cb (GtkToggleAction *menu,
3166     EmpathyCallWindow *self)
3167 {
3168   empathy_call_window_show_sidebar (self,
3169       gtk_toggle_action_get_active (menu));
3170 }
3171
3172 static void
3173 empathy_call_window_fullscreen_cb (gpointer object,
3174                                    EmpathyCallWindow *window)
3175 {
3176   empathy_call_window_fullscreen_toggle (window);
3177 }
3178
3179 static void
3180 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3181 {
3182   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3183
3184   if (priv->is_fullscreen)
3185     gtk_window_unfullscreen (GTK_WINDOW (window));
3186   else
3187     gtk_window_fullscreen (GTK_WINDOW (window));
3188 }
3189
3190 static gboolean
3191 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3192   GdkEventButton *event, EmpathyCallWindow *window)
3193 {
3194   if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3195     {
3196       empathy_call_window_video_menu_popup (window, event->button);
3197       return TRUE;
3198     }
3199
3200   return FALSE;
3201 }
3202
3203 static gboolean
3204 empathy_call_window_key_press_cb (GtkWidget *video_output,
3205   GdkEventKey *event, EmpathyCallWindow *window)
3206 {
3207   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3208
3209   if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3210     {
3211       /* Since we are in fullscreen mode, toggling will bring us back to
3212          normal mode. */
3213       empathy_call_window_fullscreen_toggle (window);
3214       return TRUE;
3215     }
3216
3217   return FALSE;
3218 }
3219
3220 static gboolean
3221 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3222     GdkEventMotion *event, EmpathyCallWindow *window)
3223 {
3224   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3225
3226   if (priv->is_fullscreen)
3227     {
3228       empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3229       return TRUE;
3230     }
3231   return FALSE;
3232 }
3233
3234 static void
3235 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3236   guint button)
3237 {
3238   GtkWidget *menu;
3239   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3240
3241   menu = gtk_ui_manager_get_widget (priv->ui_manager,
3242             "/video-popup");
3243   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3244       button, gtk_get_current_event_time ());
3245   gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3246 }
3247
3248 static void
3249 empathy_call_window_status_message (EmpathyCallWindow *self,
3250   gchar *message)
3251 {
3252   gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3253 }
3254
3255 static void
3256 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3257   gdouble value, EmpathyCallWindow *window)
3258 {
3259   EmpathyCallWindowPriv *priv = GET_PRIV (window);
3260
3261   if (priv->audio_output == NULL)
3262     return;
3263
3264   empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3265     value);
3266 }