2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
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.
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.
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
27 #include <gdk/gdkkeysyms.h>
30 #include <glib/gi18n.h>
32 #include <clutter/clutter.h>
33 #include <clutter-gtk/clutter-gtk.h>
34 #include <clutter-gst/clutter-gst.h>
36 #include <telepathy-glib/util.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/util.h>
40 #include <gst/farsight/fs-element-added-notifier.h>
41 #include <gst/farsight/fs-utils.h>
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>
52 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
53 #include <libempathy/empathy-debug.h>
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"
64 #define CONTENT_HBOX_BORDER_WIDTH 6
65 #define CONTENT_HBOX_SPACING 3
66 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
68 #define SELF_VIDEO_SECTION_WIDTH 120
69 #define SELF_VIDEO_SECTION_HEIGTH 90
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
77 #define SMALL_TOOLBAR_SIZE 36
79 /* If an video input error occurs, the error message will start with "v4l" */
80 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
82 /* The time interval in milliseconds between 2 outgoing rings */
83 #define MS_BETWEEN_RING 500
85 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
88 PROP_CALL_HANDLER = 1,
100 CAMERA_STATE_OFF = 0,
104 struct _EmpathyCallWindowPriv
106 gboolean dispose_has_run;
107 EmpathyCallHandler *handler;
109 EmpathyContact *contact;
111 EmpathyCameraMonitor *camera_monitor;
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 *remote_user_name_toolbar;
128 GtkWidget *volume_item;
129 GtkWidget *status_label;
130 GtkWidget *hangup_button;
131 GtkWidget *audio_call_button;
132 GtkWidget *video_call_button;
133 GtkWidget *mic_button;
134 GtkWidget *camera_button;
135 GtkWidget *dialpad_button;
137 GtkWidget *bottom_toolbar;
139 GtkAction *menu_sidebar;
140 GtkAction *menu_fullscreen;
142 /* The box that contains self and remote avatar and video
143 input/output. When we redial, we destroy and re-create the box */
144 ClutterActor *video_box;
145 ClutterLayoutManager *video_layout;
147 /* We keep a reference on the hbox which contains the main content so we can
148 easilly repack everything when toggling fullscreen */
149 GtkWidget *content_hbox;
151 gulong video_output_motion_handler_id;
152 guint bus_message_source_id;
155 GtkWidget *volume_scale;
156 GtkWidget *volume_progress_bar;
157 GtkAdjustment *audio_input_adj;
159 GtkWidget *dtmf_panel;
162 GtkWidget *details_vbox;
163 GtkWidget *vcodec_encoding_label;
164 GtkWidget *acodec_encoding_label;
165 GtkWidget *vcodec_decoding_label;
166 GtkWidget *acodec_decoding_label;
168 GtkWidget *audio_remote_candidate_label;
169 GtkWidget *audio_local_candidate_label;
170 GtkWidget *video_remote_candidate_label;
171 GtkWidget *video_local_candidate_label;
172 GtkWidget *video_remote_candidate_info_img;
173 GtkWidget *video_local_candidate_info_img;
174 GtkWidget *audio_remote_candidate_info_img;
175 GtkWidget *audio_local_candidate_info_img;
177 GstElement *video_input;
178 GstElement *video_preview_sink;
179 GstElement *video_output_sink;
180 GstElement *audio_input;
181 GstElement *audio_output;
182 GstElement *pipeline;
183 GstElement *video_tee;
192 GtkWidget *video_contrast;
193 GtkWidget *video_brightness;
194 GtkWidget *video_gamma;
197 gboolean call_started;
198 gboolean sending_video;
199 CameraState camera_state;
201 EmpathyCallWindowFullscreen *fullscreen;
202 gboolean is_fullscreen;
207 /* Those fields represent the state of the window before it actually was in
209 gboolean sidebar_was_visible_before_fs;
210 gint original_width_before_fs;
211 gint original_height_before_fs;
213 gint x, y, w, h, sidebar_width;
216 /* TRUE if the call should be started when the pipeline is playing */
217 gboolean start_call_when_playing;
218 /* TRUE if we requested to set the pipeline in the playing state */
219 gboolean pipeline_playing;
221 EmpathySoundManager *sound_mgr;
224 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
226 static void empathy_call_window_realized_cb (GtkWidget *widget,
227 EmpathyCallWindow *window);
229 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
230 GdkEvent *event, EmpathyCallWindow *window);
232 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
233 GdkEventWindowState *event, EmpathyCallWindow *window);
235 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
238 static void empathy_call_window_mic_toggled_cb (
239 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
241 static void empathy_call_window_sidebar_cb (GtkToggleAction *menu,
242 EmpathyCallWindow *self);
244 static void empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
245 EmpathyCallWindow *window);
247 static void empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
248 EmpathyCallWindow *window);
250 static void empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
252 EmpathyCallWindow *window);
254 static void empathy_call_window_hangup_cb (gpointer object,
255 EmpathyCallWindow *window);
257 static void empathy_call_window_fullscreen_cb (gpointer object,
258 EmpathyCallWindow *window);
260 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
262 static gboolean empathy_call_window_video_button_press_cb (
263 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
265 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
266 GdkEventKey *event, EmpathyCallWindow *window);
268 static gboolean empathy_call_window_video_output_motion_notify (
269 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
271 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
274 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
275 EmpathyCallWindow *window);
277 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
279 static void empathy_call_window_status_message (EmpathyCallWindow *window,
282 static gboolean empathy_call_window_bus_message (GstBus *bus,
283 GstMessage *message, gpointer user_data);
286 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
287 gdouble value, EmpathyCallWindow *window);
290 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
293 gtk_widget_set_visible (self->priv->hangup_button, show);
294 gtk_widget_set_visible (self->priv->audio_call_button, !show);
295 gtk_widget_set_visible (self->priv->video_call_button, !show);
299 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
300 EmpathyCallWindow *self)
302 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
303 empathy_call_window_restart_call (self);
307 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
308 EmpathyCallWindow *self)
310 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
311 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
312 empathy_call_window_restart_call (self);
316 empathy_call_window_setup_toolbars (EmpathyCallWindow *self)
318 EmpathyCallWindowPriv *priv = GET_PRIV (self);
319 GtkWidget *volume_button;
320 GtkToolItem *tool_item;
322 /* Add an empty expanded GtkToolItem to the top toolbar */
323 tool_item = gtk_tool_item_new ();
324 gtk_tool_item_set_expand (tool_item, TRUE);
325 gtk_widget_show (GTK_WIDGET (tool_item));
326 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
328 /* Set the remote name */
329 tool_item = gtk_tool_item_new ();
330 priv->remote_user_name_toolbar = gtk_label_new (NULL);
331 gtk_container_add (GTK_CONTAINER (tool_item),
332 priv->remote_user_name_toolbar);
333 gtk_widget_show_all (GTK_WIDGET (tool_item));
334 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
336 /* Add some space between the image and the name */
337 tool_item = gtk_separator_tool_item_new ();
338 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item),
340 gtk_widget_show (GTK_WIDGET (tool_item));
341 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
343 /* Set the remote avatar */
344 tool_item = gtk_tool_item_new ();
345 priv->remote_user_avatar_toolbar = gtk_image_new ();
346 gtk_container_add (GTK_CONTAINER (tool_item),
347 priv->remote_user_avatar_toolbar);
348 gtk_widget_show_all (GTK_WIDGET (tool_item));
349 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
351 /* Set the volume button */
352 volume_button = gtk_volume_button_new ();
353 /* FIXME listen to the audiosinks signals and update the button according to
354 * that, for now starting out at 1.0 and assuming only the app changes the
356 gtk_scale_button_set_value (GTK_SCALE_BUTTON (volume_button), 1.0);
357 g_signal_connect (G_OBJECT (volume_button), "value-changed",
358 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
360 gtk_container_add (GTK_CONTAINER (priv->volume_item),
362 gtk_widget_show (GTK_WIDGET (volume_button));
364 /* Add an empty expanded GtkToolItem so the label is at the end */
365 tool_item = gtk_tool_item_new ();
366 gtk_tool_item_set_expand (tool_item, TRUE);
367 gtk_widget_show (GTK_WIDGET (tool_item));
368 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
370 /* Set the status label */
371 tool_item = gtk_tool_item_new ();
372 priv->status_label = gtk_label_new (NULL);
373 gtk_container_add (GTK_CONTAINER (tool_item),
375 gtk_widget_show_all (GTK_WIDGET (tool_item));
376 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
380 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
382 EmpathyCallWindowPriv *priv = GET_PRIV (window);
383 TpyCallChannel *call;
387 g_object_get (priv->handler, "call-channel", &call, NULL);
389 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
390 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
393 tpy_call_channel_dtmf_start_tone (call, event);
395 g_object_unref (call);
399 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
401 EmpathyCallWindowPriv *priv = GET_PRIV (window);
402 TpyCallChannel *call;
404 g_object_get (priv->handler, "call-channel", &call, NULL);
406 tpy_call_channel_dtmf_stop_tone (call);
408 g_object_unref (call);
412 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
413 gchar *label_text, GtkWidget *bin)
415 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
416 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
417 GtkWidget *label = gtk_label_new (label_text);
419 gtk_widget_set_sensitive (scale, FALSE);
421 gtk_container_add (GTK_CONTAINER (bin), vbox);
423 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
424 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
425 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
431 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
432 EmpathyCallWindow *self)
435 EmpathyCallWindowPriv *priv = GET_PRIV (self);
437 empathy_video_src_set_channel (priv->video_input,
438 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
442 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
443 EmpathyCallWindow *self)
446 EmpathyCallWindowPriv *priv = GET_PRIV (self);
448 empathy_video_src_set_channel (priv->video_input,
449 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
453 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
454 EmpathyCallWindow *self)
457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
459 empathy_video_src_set_channel (priv->video_input,
460 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
465 empathy_call_window_create_video_input (EmpathyCallWindow *self)
467 EmpathyCallWindowPriv *priv = GET_PRIV (self);
470 hbox = gtk_hbox_new (TRUE, 3);
472 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
473 self, _("Contrast"), hbox);
475 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
476 self, _("Brightness"), hbox);
478 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
479 self, _("Gamma"), hbox);
485 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
487 EmpathyCallWindowPriv *priv = GET_PRIV (self);
491 supported = empathy_video_src_get_supported_channels (priv->video_input);
493 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
495 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
497 gtk_adjustment_set_value (adj,
498 empathy_video_src_get_channel (priv->video_input,
499 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
501 g_signal_connect (G_OBJECT (adj), "value-changed",
502 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
504 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
507 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
509 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
511 gtk_adjustment_set_value (adj,
512 empathy_video_src_get_channel (priv->video_input,
513 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
515 g_signal_connect (G_OBJECT (adj), "value-changed",
516 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
517 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
520 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
522 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
524 gtk_adjustment_set_value (adj,
525 empathy_video_src_get_channel (priv->video_input,
526 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
528 g_signal_connect (G_OBJECT (adj), "value-changed",
529 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
530 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
535 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
536 EmpathyCallWindow *self)
538 EmpathyCallWindowPriv *priv = GET_PRIV (self);
541 volume = gtk_adjustment_get_value (adj)/100.0;
543 /* Don't store the volume because of muting */
544 if (volume > 0 || gtk_toggle_tool_button_get_active (
545 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
546 priv->volume = volume;
548 /* Ensure that the toggle button is active if the volume is > 0 and inactive
549 * if it's smaller than 0 */
550 if ((volume > 0) != gtk_toggle_tool_button_get_active (
551 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
552 gtk_toggle_tool_button_set_active (
553 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
555 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
560 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
561 gdouble level, EmpathyCallWindow *window)
564 EmpathyCallWindowPriv *priv = GET_PRIV (window);
566 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
567 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
572 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
574 EmpathyCallWindowPriv *priv = GET_PRIV (self);
575 GtkWidget *hbox, *vbox, *label;
577 hbox = gtk_hbox_new (TRUE, 3);
579 vbox = gtk_vbox_new (FALSE, 3);
580 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
582 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
583 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
584 label = gtk_label_new (_("Volume"));
586 priv->audio_input_adj = gtk_range_get_adjustment (
587 GTK_RANGE (priv->volume_scale));
588 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
589 (priv->audio_input));
590 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
592 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
593 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
595 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
596 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
598 priv->volume_progress_bar = gtk_progress_bar_new ();
600 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
601 GTK_ORIENTATION_VERTICAL);
603 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
606 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
613 empathy_call_window_show_video_output (EmpathyCallWindow *self,
616 if (self->priv->video_output != NULL)
617 g_object_set (self->priv->video_output, "visible", show, NULL);
619 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
623 create_video_output_widget (EmpathyCallWindow *self)
625 EmpathyCallWindowPriv *priv = GET_PRIV (self);
627 g_assert (priv->video_output == NULL);
628 g_assert (priv->pipeline != NULL);
630 priv->video_output = clutter_texture_new ();
632 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
635 priv->video_output_sink = clutter_gst_video_sink_new (
636 CLUTTER_TEXTURE (priv->video_output));
638 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
641 gtk_widget_add_events (priv->video_container,
642 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
643 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
644 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
648 create_video_input (EmpathyCallWindow *self)
650 EmpathyCallWindowPriv *priv = GET_PRIV (self);
652 g_assert (priv->video_input == NULL);
653 priv->video_input = empathy_video_src_new ();
654 gst_object_ref (priv->video_input);
655 gst_object_sink (priv->video_input);
659 create_audio_input (EmpathyCallWindow *self)
661 EmpathyCallWindowPriv *priv = GET_PRIV (self);
663 g_assert (priv->audio_input == NULL);
664 priv->audio_input = empathy_audio_src_new ();
665 gst_object_ref (priv->audio_input);
666 gst_object_sink (priv->audio_input);
668 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
669 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
674 add_video_preview_to_pipeline (EmpathyCallWindow *self)
676 EmpathyCallWindowPriv *priv = GET_PRIV (self);
679 g_assert (priv->video_preview != NULL);
680 g_assert (priv->pipeline != NULL);
681 g_assert (priv->video_input != NULL);
682 g_assert (priv->video_tee != NULL);
684 preview = priv->video_preview_sink;
686 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
688 g_warning ("Could not add video input to pipeline");
692 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
694 g_warning ("Could not add video preview to pipeline");
698 if (!gst_element_link (priv->video_input, priv->video_tee))
700 g_warning ("Could not link video input to video tee");
704 if (!gst_element_link (priv->video_tee, preview))
706 g_warning ("Could not link video tee to video preview");
712 empathy_call_window_disable_camera_cb (GtkAction *action,
713 EmpathyCallWindow *self)
715 clutter_actor_destroy (self->priv->preview_hidden_button);
717 gtk_toggle_tool_button_set_active (
718 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
722 empathy_call_window_minimise_camera_cb (GtkAction *action,
723 EmpathyCallWindow *self)
725 clutter_actor_hide (self->priv->video_preview);
726 clutter_actor_show (self->priv->preview_hidden_button);
730 empathy_call_window_maximise_camera_cb (GtkAction *action,
731 EmpathyCallWindow *self)
733 clutter_actor_show (self->priv->video_preview);
734 clutter_actor_hide (self->priv->preview_hidden_button);
738 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
739 EmpathyCallWindow *self)
743 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
745 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
746 0, gtk_get_current_event_time ());
747 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
751 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
752 EmpathyCallWindow *self)
756 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
757 "/preview-hidden-menu");
758 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
759 0, gtk_get_current_event_time ());
760 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
764 create_video_preview (EmpathyCallWindow *self)
766 EmpathyCallWindowPriv *priv = GET_PRIV (self);
767 ClutterLayoutManager *layout, *layout_center;
768 ClutterActor *preview;
773 g_assert (priv->video_preview == NULL);
775 preview = clutter_texture_new ();
776 clutter_actor_set_size (preview,
777 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
778 priv->video_preview_sink = clutter_gst_video_sink_new (
779 CLUTTER_TEXTURE (preview));
781 /* Flip the video preview */
782 clutter_actor_set_rotation (preview,
785 SELF_VIDEO_SECTION_WIDTH * 0.5,
789 /* Add a little offset to the video preview */
790 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
791 CLUTTER_BIN_ALIGNMENT_START);
792 priv->video_preview = clutter_box_new (layout);
793 clutter_actor_set_size (priv->video_preview,
794 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
796 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
797 CLUTTER_BIN_ALIGNMENT_CENTER);
798 box = clutter_box_new (layout_center);
799 clutter_actor_set_size (box,
800 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
802 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
803 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
805 g_object_set (priv->video_preview_sink,
810 /* Translators: this is an "Info" label. It should be as short
812 button = gtk_button_new_with_label (_("i"));
813 b = gtk_clutter_actor_new_with_contents (button);
815 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
817 CLUTTER_BIN_ALIGNMENT_END,
818 CLUTTER_BIN_ALIGNMENT_END);
820 g_signal_connect (button, "clicked",
821 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
824 /* Translators: this is an "Info" label. It should be as short
826 button = gtk_button_new_with_label (_("i"));
827 priv->preview_hidden_button =
828 gtk_clutter_actor_new_with_contents (button);
830 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
831 priv->preview_hidden_button,
832 CLUTTER_BIN_ALIGNMENT_START,
833 CLUTTER_BIN_ALIGNMENT_END);
835 clutter_actor_hide (priv->preview_hidden_button);
837 g_signal_connect (button, "clicked",
838 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
841 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
843 CLUTTER_BIN_ALIGNMENT_START,
844 CLUTTER_BIN_ALIGNMENT_END);
848 play_camera (EmpathyCallWindow *window,
851 EmpathyCallWindowPriv *priv = GET_PRIV (window);
855 if (priv->video_preview == NULL)
857 create_video_preview (window);
858 add_video_preview_to_pipeline (window);
862 state = GST_STATE_PLAYING;
864 state = GST_STATE_NULL;
866 preview = priv->video_preview_sink;
868 gst_element_set_state (preview, state);
869 gst_element_set_state (priv->video_input, state);
870 gst_element_set_state (priv->video_tee, state);
874 display_video_preview (EmpathyCallWindow *self,
877 EmpathyCallWindowPriv *priv = GET_PRIV (self);
881 /* Display the video preview */
882 DEBUG ("Show video preview");
884 play_camera (self, TRUE);
885 clutter_actor_show (priv->video_preview);
889 /* Hide the video preview */
890 DEBUG ("Hide video preview");
892 if (priv->video_preview != NULL)
894 clutter_actor_hide (priv->video_preview);
895 play_camera (self, FALSE);
901 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
903 EmpathyCallWindowPriv *priv = GET_PRIV (window);
905 empathy_call_window_status_message (window, _("Connecting…"));
906 priv->call_state = CONNECTING;
909 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
910 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
914 disable_camera (EmpathyCallWindow *self)
916 EmpathyCallWindowPriv *priv = GET_PRIV (self);
918 if (priv->camera_state == CAMERA_STATE_OFF)
921 DEBUG ("Disable camera");
923 display_video_preview (self, FALSE);
925 if (priv->camera_state == CAMERA_STATE_ON)
926 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
928 priv->camera_state = CAMERA_STATE_OFF;
932 enable_camera (EmpathyCallWindow *self)
934 EmpathyCallWindowPriv *priv = GET_PRIV (self);
936 if (priv->camera_state == CAMERA_STATE_ON)
939 if (priv->video_input == NULL)
941 DEBUG ("Can't enable camera, no input");
945 DEBUG ("Enable camera");
947 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
949 priv->camera_state = CAMERA_STATE_ON;
953 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
954 EmpathyCallWindow *self)
956 if (gtk_toggle_tool_button_get_active (toggle))
957 enable_camera (self);
959 disable_camera (self);
963 create_pipeline (EmpathyCallWindow *self)
965 EmpathyCallWindowPriv *priv = GET_PRIV (self);
968 g_assert (priv->pipeline == NULL);
970 priv->pipeline = gst_pipeline_new (NULL);
971 priv->pipeline_playing = FALSE;
973 priv->video_tee = gst_element_factory_make ("tee", NULL);
974 gst_object_ref (priv->video_tee);
975 gst_object_sink (priv->video_tee);
977 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
979 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
980 priv->bus_message_source_id = gst_bus_add_watch (bus,
981 empathy_call_window_bus_message, self);
983 g_object_unref (bus);
987 empathy_call_window_configure_event_cb (GtkWidget *widget,
989 EmpathyCallWindow *self)
991 GdkWindow *gdk_window;
992 GdkWindowState window_state;
994 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
995 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
997 gtk_widget_get_preferred_width (self->priv->sidebar,
998 &self->priv->sidebar_width, NULL);
1000 gdk_window = gtk_widget_get_window (widget);
1001 window_state = gdk_window_get_state (gdk_window);
1002 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1008 empathy_call_window_destroyed_cb (GtkWidget *object,
1009 EmpathyCallWindow *self)
1011 if (gtk_widget_get_visible (self->priv->sidebar))
1013 /* Save the geometry as if the sidebar was hidden. */
1014 empathy_geometry_save_values (GTK_WINDOW (self),
1015 self->priv->x, self->priv->y,
1016 self->priv->w - self->priv->sidebar_width, self->priv->h,
1017 self->priv->maximized);
1022 empathy_call_window_init (EmpathyCallWindow *self)
1024 EmpathyCallWindowPriv *priv;
1026 GtkWidget *top_vbox;
1030 ClutterConstraint *size_constraint;
1031 ClutterActor *remote_avatar;
1032 GtkStyleContext *context;
1036 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1037 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1039 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1040 gui = empathy_builder_get_file (filename,
1041 "call_window_vbox", &top_vbox,
1042 "errors_vbox", &priv->errors_vbox,
1043 "pane", &priv->pane,
1044 "audiocall", &priv->audio_call_button,
1045 "videocall", &priv->video_call_button,
1046 "volume", &priv->volume_item,
1047 "microphone", &priv->mic_button,
1048 "camera", &priv->camera_button,
1049 "hangup", &priv->hangup_button,
1050 "dialpad", &priv->dialpad_button,
1051 "toolbar", &priv->toolbar,
1052 "bottom_toolbar", &priv->bottom_toolbar,
1053 "menusidebar", &priv->menu_sidebar,
1054 "ui_manager", &priv->ui_manager,
1055 "menufullscreen", &priv->menu_fullscreen,
1056 "details_vbox", &priv->details_vbox,
1057 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1058 "acodec_encoding_label", &priv->acodec_encoding_label,
1059 "acodec_decoding_label", &priv->acodec_decoding_label,
1060 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1061 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1062 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1063 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1064 "video_local_candidate_label", &priv->video_local_candidate_label,
1065 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1066 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1067 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1068 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1072 empathy_builder_connect (gui, self,
1073 "menuhangup", "activate", empathy_call_window_hangup_cb,
1074 "hangup", "clicked", empathy_call_window_hangup_cb,
1075 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1076 "videocall", "clicked", empathy_call_window_video_call_cb,
1077 "menusidebar", "toggled", empathy_call_window_sidebar_cb,
1078 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1079 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1080 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1081 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1082 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1083 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1084 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1087 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1089 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1091 g_object_bind_property (priv->camera_monitor, "available",
1092 priv->camera_button, "sensitive",
1093 G_BINDING_SYNC_CREATE);
1095 priv->lock = g_mutex_new ();
1097 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1099 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1100 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1101 CONTENT_HBOX_BORDER_WIDTH);
1102 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1104 /* avatar/video box */
1105 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1106 CLUTTER_BIN_ALIGNMENT_CENTER);
1108 priv->video_box = clutter_box_new (priv->video_layout);
1110 priv->video_container = gtk_clutter_embed_new ();
1112 /* Set the background color to that of the rest of the window */
1113 context = gtk_widget_get_style_context (priv->content_hbox);
1114 gtk_style_context_get_background_color (context,
1115 GTK_STATE_FLAG_NORMAL, &rgba);
1116 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1117 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1118 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1119 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1120 clutter_stage_set_color (
1121 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1122 GTK_CLUTTER_EMBED (priv->video_container))),
1125 clutter_container_add (
1126 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1127 GTK_CLUTTER_EMBED (priv->video_container))),
1131 size_constraint = clutter_bind_constraint_new (
1132 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1133 CLUTTER_BIND_SIZE, 0);
1134 clutter_actor_add_constraint (priv->video_box, size_constraint);
1136 priv->remote_user_avatar_widget = gtk_image_new ();
1137 remote_avatar = gtk_clutter_actor_new_with_contents (
1138 priv->remote_user_avatar_widget);
1140 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1143 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1144 priv->video_container, TRUE, TRUE,
1145 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1147 create_pipeline (self);
1148 create_video_output_widget (self);
1149 create_audio_input (self);
1150 create_video_input (self);
1152 /* The call will be started as soon the pipeline is playing */
1153 priv->start_call_when_playing = TRUE;
1155 empathy_call_window_setup_toolbars (self);
1157 priv->sidebar = ev_sidebar_new ();
1158 g_signal_connect (G_OBJECT (priv->sidebar),
1159 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1160 g_signal_connect (G_OBJECT (priv->sidebar),
1161 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1162 g_signal_connect (G_OBJECT (priv->sidebar), "changed",
1163 G_CALLBACK (empathy_call_window_sidebar_changed_cb), self);
1164 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1166 page = empathy_call_window_create_audio_input (self);
1167 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1168 _("Audio input"), page);
1170 page = empathy_call_window_create_video_input (self);
1171 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1172 _("Video input"), page);
1174 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1175 G_CALLBACK (dtmf_button_pressed_cb),
1176 G_CALLBACK (dtmf_button_released_cb));
1177 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1178 _("Dialpad"), priv->dtmf_panel);
1180 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1182 /* Put the details vbox in a scroll window as it can require a lot of
1183 * horizontal space. */
1184 scroll = gtk_scrolled_window_new (NULL, NULL);
1185 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1186 priv->details_vbox);
1188 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details", _("Details"),
1191 gtk_widget_show_all (top_vbox);
1193 gtk_widget_hide (priv->sidebar);
1195 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1197 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1198 priv->video_container);
1200 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1201 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1203 g_signal_connect (G_OBJECT (self), "realize",
1204 G_CALLBACK (empathy_call_window_realized_cb), self);
1206 g_signal_connect (G_OBJECT (self), "delete-event",
1207 G_CALLBACK (empathy_call_window_delete_cb), self);
1209 g_signal_connect (G_OBJECT (self), "window-state-event",
1210 G_CALLBACK (empathy_call_window_state_event_cb), self);
1212 g_signal_connect (G_OBJECT (self), "key-press-event",
1213 G_CALLBACK (empathy_call_window_key_press_cb), self);
1215 priv->timer = g_timer_new ();
1217 g_object_ref (priv->ui_manager);
1218 g_object_unref (gui);
1220 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1222 empathy_call_window_show_hangup_button (self, TRUE);
1224 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1225 /* These signals are used to track the window position and save it
1226 * when the window is destroyed. We need to do this as we don't want
1227 * the window geometry to be saved with the sidebar taken into account. */
1228 g_signal_connect (self, "destroy",
1229 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1230 g_signal_connect (self, "configure-event",
1231 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1232 g_signal_connect (self, "window-state-event",
1233 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1236 /* Instead of specifying a width and a height, we specify only one size. That's
1237 because we want a square avatar icon. */
1239 init_contact_avatar_with_size (EmpathyContact *contact,
1240 GtkWidget *image_widget,
1243 GdkPixbuf *pixbuf_avatar = NULL;
1245 if (contact != NULL)
1247 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1251 if (pixbuf_avatar == NULL)
1253 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1254 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1257 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1259 if (pixbuf_avatar != NULL)
1260 g_object_unref (pixbuf_avatar);
1264 set_window_title (EmpathyCallWindow *self)
1266 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1269 if (priv->contact != NULL)
1271 /* translators: Call is a noun and %s is the contact name. This string
1272 * is used in the window title */
1273 tmp = g_strdup_printf (_("Call with %s"),
1274 empathy_contact_get_alias (priv->contact));
1275 gtk_window_set_title (GTK_WINDOW (self), tmp);
1280 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1285 set_remote_user_name (EmpathyCallWindow *self,
1286 EmpathyContact *contact)
1288 const gchar *alias = empathy_contact_get_alias (contact);
1289 const gchar *status = empathy_contact_get_status (contact);
1292 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1293 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1299 contact_name_changed_cb (EmpathyContact *contact,
1301 EmpathyCallWindow *self)
1303 set_window_title (self);
1304 set_remote_user_name (self, contact);
1308 contact_presence_changed_cb (EmpathyContact *contact,
1310 EmpathyCallWindow *self)
1312 set_remote_user_name (self, contact);
1316 contact_avatar_changed_cb (EmpathyContact *contact,
1318 EmpathyCallWindow *self)
1321 GtkAllocation allocation;
1322 GtkWidget *avatar_widget;
1324 avatar_widget = self->priv->remote_user_avatar_widget;
1326 gtk_widget_get_allocation (avatar_widget, &allocation);
1327 size = allocation.height;
1331 /* the widget is not allocated yet, set a default size */
1332 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1333 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1336 init_contact_avatar_with_size (contact, avatar_widget, size);
1338 avatar_widget = self->priv->remote_user_avatar_toolbar;
1340 gtk_widget_get_allocation (avatar_widget, &allocation);
1341 size = allocation.height;
1345 /* the widget is not allocated yet, set a default size */
1346 size = SMALL_TOOLBAR_SIZE;
1349 init_contact_avatar_with_size (contact, avatar_widget, size);
1353 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1354 EmpathyCallHandler *handler)
1356 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1358 g_signal_connect (priv->contact, "notify::name",
1359 G_CALLBACK (contact_name_changed_cb), self);
1360 g_signal_connect (priv->contact, "notify::avatar",
1361 G_CALLBACK (contact_avatar_changed_cb), self);
1362 /* FIXME: There's no EmpathyContact::presence yet */
1363 g_signal_connect (priv->contact, "notify::presence",
1364 G_CALLBACK (contact_presence_changed_cb), self);
1366 set_window_title (self);
1367 set_remote_user_name (self, priv->contact);
1369 init_contact_avatar_with_size (priv->contact,
1370 priv->remote_user_avatar_widget,
1371 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1372 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1374 init_contact_avatar_with_size (priv->contact,
1375 priv->remote_user_avatar_toolbar,
1376 SMALL_TOOLBAR_SIZE);
1378 /* The remote avatar is shown by default and will be hidden when we receive
1379 video from the remote side. */
1380 clutter_actor_hide (priv->video_output);
1381 gtk_widget_show (priv->remote_user_avatar_widget);
1385 update_send_codec (EmpathyCallWindow *self,
1388 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1395 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1396 widget = priv->acodec_encoding_label;
1400 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1401 widget = priv->vcodec_encoding_label;
1407 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1408 gtk_label_set_text (GTK_LABEL (widget), tmp);
1413 send_audio_codec_notify_cb (GObject *object,
1417 EmpathyCallWindow *self = user_data;
1419 update_send_codec (self, TRUE);
1423 send_video_codec_notify_cb (GObject *object,
1427 EmpathyCallWindow *self = user_data;
1429 update_send_codec (self, FALSE);
1433 update_recv_codec (EmpathyCallWindow *self,
1436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1439 GString *str = NULL;
1443 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1444 widget = priv->acodec_decoding_label;
1448 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1449 widget = priv->vcodec_decoding_label;
1455 for (l = codecs; l != NULL; l = g_list_next (l))
1457 FsCodec *codec = l->data;
1460 str = g_string_new (NULL);
1462 g_string_append (str, ", ");
1464 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1468 gtk_label_set_text (GTK_LABEL (widget), str->str);
1469 g_string_free (str, TRUE);
1473 recv_audio_codecs_notify_cb (GObject *object,
1477 EmpathyCallWindow *self = user_data;
1479 update_recv_codec (self, TRUE);
1483 recv_video_codecs_notify_cb (GObject *object,
1487 EmpathyCallWindow *self = user_data;
1489 update_recv_codec (self, FALSE);
1492 static const gchar *
1493 candidate_type_to_str (FsCandidate *candidate)
1495 switch (candidate->type)
1497 case FS_CANDIDATE_TYPE_HOST:
1499 case FS_CANDIDATE_TYPE_SRFLX:
1500 return "server reflexive";
1501 case FS_CANDIDATE_TYPE_PRFLX:
1502 return "peer reflexive";
1503 case FS_CANDIDATE_TYPE_RELAY:
1505 case FS_CANDIDATE_TYPE_MULTICAST:
1512 static const gchar *
1513 candidate_type_to_desc (FsCandidate *candidate)
1515 switch (candidate->type)
1517 case FS_CANDIDATE_TYPE_HOST:
1518 return _("The IP address as seen by the machine");
1519 case FS_CANDIDATE_TYPE_SRFLX:
1520 return _("The IP address as seen by a server on the Internet");
1521 case FS_CANDIDATE_TYPE_PRFLX:
1522 return _("The IP address of the peer as seen by the other side");
1523 case FS_CANDIDATE_TYPE_RELAY:
1524 return _("The IP address of a relay server");
1525 case FS_CANDIDATE_TYPE_MULTICAST:
1526 return _("The IP address of the multicast group");
1533 update_candidat_widget (EmpathyCallWindow *self,
1536 FsCandidate *candidate)
1540 g_assert (candidate != NULL);
1541 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1542 candidate->port, candidate_type_to_str (candidate));
1544 gtk_label_set_text (GTK_LABEL (label), str);
1545 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1551 candidates_changed_cb (GObject *object,
1553 EmpathyCallWindow *self)
1555 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1556 FsCandidate *candidate = NULL;
1558 if (type == FS_MEDIA_TYPE_VIDEO)
1560 /* Update remote candidate */
1561 candidate = empathy_call_handler_get_video_remote_candidate (
1564 update_candidat_widget (self, priv->video_remote_candidate_label,
1565 priv->video_remote_candidate_info_img, candidate);
1567 /* Update local candidate */
1568 candidate = empathy_call_handler_get_video_local_candidate (
1571 update_candidat_widget (self, priv->video_local_candidate_label,
1572 priv->video_local_candidate_info_img, candidate);
1576 /* Update remote candidate */
1577 candidate = empathy_call_handler_get_audio_remote_candidate (
1580 update_candidat_widget (self, priv->audio_remote_candidate_label,
1581 priv->audio_remote_candidate_info_img, candidate);
1583 /* Update local candidate */
1584 candidate = empathy_call_handler_get_audio_local_candidate (
1587 update_candidat_widget (self, priv->audio_local_candidate_label,
1588 priv->audio_local_candidate_info_img, candidate);
1593 empathy_call_window_constructed (GObject *object)
1595 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1596 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1597 TpyCallChannel *call;
1599 g_assert (priv->handler != NULL);
1601 g_object_get (priv->handler, "call-channel", &call, NULL);
1602 priv->outgoing = (call == NULL);
1604 g_object_unref (call);
1606 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1607 g_assert (priv->contact != NULL);
1609 empathy_call_window_setup_avatars (self, priv->handler);
1610 empathy_call_window_set_state_connecting (self);
1612 if (!empathy_call_handler_has_initial_video (priv->handler))
1614 gtk_toggle_tool_button_set_active (
1615 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1617 /* If call has InitialVideo, the preview will be started once the call has
1618 * been started (start_call()). */
1620 update_send_codec (self, TRUE);
1621 update_send_codec (self, FALSE);
1622 update_recv_codec (self, TRUE);
1623 update_recv_codec (self, FALSE);
1625 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1626 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1627 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1628 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1629 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1630 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1631 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1632 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1634 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1635 G_CALLBACK (candidates_changed_cb), self, 0);
1638 static void empathy_call_window_dispose (GObject *object);
1639 static void empathy_call_window_finalize (GObject *object);
1642 empathy_call_window_set_property (GObject *object,
1643 guint property_id, const GValue *value, GParamSpec *pspec)
1645 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1647 switch (property_id)
1649 case PROP_CALL_HANDLER:
1650 priv->handler = g_value_dup_object (value);
1653 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1658 empathy_call_window_get_property (GObject *object,
1659 guint property_id, GValue *value, GParamSpec *pspec)
1661 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1663 switch (property_id)
1665 case PROP_CALL_HANDLER:
1666 g_value_set_object (value, priv->handler);
1669 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1674 empathy_call_window_class_init (
1675 EmpathyCallWindowClass *empathy_call_window_class)
1677 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1678 GParamSpec *param_spec;
1680 g_type_class_add_private (empathy_call_window_class,
1681 sizeof (EmpathyCallWindowPriv));
1683 object_class->constructed = empathy_call_window_constructed;
1684 object_class->set_property = empathy_call_window_set_property;
1685 object_class->get_property = empathy_call_window_get_property;
1687 object_class->dispose = empathy_call_window_dispose;
1688 object_class->finalize = empathy_call_window_finalize;
1690 param_spec = g_param_spec_object ("handler",
1691 "handler", "The call handler",
1692 EMPATHY_TYPE_CALL_HANDLER,
1693 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1694 g_object_class_install_property (object_class,
1695 PROP_CALL_HANDLER, param_spec);
1699 empathy_call_window_dispose (GObject *object)
1701 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1702 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1704 if (priv->dispose_has_run)
1707 priv->dispose_has_run = TRUE;
1709 if (priv->handler != NULL)
1711 empathy_call_handler_stop_call (priv->handler);
1712 tp_clear_object (&priv->handler);
1715 if (priv->bus_message_source_id != 0)
1717 g_source_remove (priv->bus_message_source_id);
1718 priv->bus_message_source_id = 0;
1721 if (priv->got_video_src > 0)
1723 g_source_remove (priv->got_video_src);
1724 priv->got_video_src = 0;
1727 tp_clear_object (&priv->pipeline);
1728 tp_clear_object (&priv->video_input);
1729 tp_clear_object (&priv->audio_input);
1730 tp_clear_object (&priv->video_tee);
1731 tp_clear_object (&priv->ui_manager);
1732 tp_clear_object (&priv->fullscreen);
1733 tp_clear_object (&priv->camera_monitor);
1735 g_list_free_full (priv->notifiers, g_object_unref);
1737 if (priv->timer_id != 0)
1738 g_source_remove (priv->timer_id);
1741 if (priv->contact != NULL)
1743 g_signal_handlers_disconnect_by_func (priv->contact,
1744 contact_name_changed_cb, self);
1745 priv->contact = NULL;
1749 tp_clear_object (&priv->sound_mgr);
1751 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1755 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1757 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1759 if (priv->video_output_motion_handler_id != 0)
1761 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1762 priv->video_output_motion_handler_id);
1763 priv->video_output_motion_handler_id = 0;
1768 empathy_call_window_finalize (GObject *object)
1770 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1771 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1773 disconnect_video_output_motion_handler (self);
1775 /* free any data held directly by the object here */
1776 g_mutex_free (priv->lock);
1778 g_timer_destroy (priv->timer);
1780 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1785 empathy_call_window_new (EmpathyCallHandler *handler)
1787 return EMPATHY_CALL_WINDOW (
1788 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1792 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1793 GstElement *conference, gpointer user_data)
1795 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1796 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1797 FsElementAddedNotifier *notifier;
1800 DEBUG ("Conference added");
1802 /* Add notifier to set the various element properties as needed */
1803 notifier = fs_element_added_notifier_new ();
1804 keyfile = fs_utils_get_default_element_properties (conference);
1806 if (keyfile != NULL)
1807 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1809 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1811 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1813 gst_bin_add (GST_BIN (priv->pipeline), conference);
1814 gst_element_set_state (conference, GST_STATE_PLAYING);
1818 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1819 GstElement *conference, gpointer user_data)
1821 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1822 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1824 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1825 gst_element_set_state (conference, GST_STATE_NULL);
1829 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1831 GstStateChangeReturn state_change_return;
1832 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1834 if (priv->pipeline == NULL)
1837 if (priv->bus_message_source_id != 0)
1839 g_source_remove (priv->bus_message_source_id);
1840 priv->bus_message_source_id = 0;
1843 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1845 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1846 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1848 if (priv->pipeline != NULL)
1849 g_object_unref (priv->pipeline);
1850 priv->pipeline = NULL;
1852 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1853 empathy_call_window_mic_volume_changed_cb, self);
1855 if (priv->audio_output != NULL)
1856 g_object_unref (priv->audio_output);
1857 priv->audio_output = NULL;
1859 if (priv->video_tee != NULL)
1860 g_object_unref (priv->video_tee);
1861 priv->video_tee = NULL;
1863 if (priv->video_preview != NULL)
1864 clutter_actor_destroy (priv->video_preview);
1865 priv->video_preview = NULL;
1867 priv->funnel = NULL;
1869 create_pipeline (self);
1870 /* Call will be started when user will hit the 'redial' button */
1871 priv->start_call_when_playing = FALSE;
1872 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1878 g_message ("Error: could not destroy pipeline. Closing call window");
1879 gtk_widget_destroy (GTK_WIDGET (self));
1886 reset_details_pane (EmpathyCallWindow *self)
1888 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1890 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1891 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1892 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1893 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1897 empathy_call_window_disconnected (EmpathyCallWindow *self,
1900 gboolean could_disconnect = FALSE;
1901 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1902 gboolean could_reset_pipeline;
1904 /* Leave full screen mode if needed */
1905 gtk_window_unfullscreen (GTK_WINDOW (self));
1907 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1908 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1910 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1912 if (priv->call_state == CONNECTING)
1913 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1915 if (priv->call_state != REDIALING)
1916 priv->call_state = DISCONNECTED;
1918 if (could_reset_pipeline)
1920 g_mutex_lock (priv->lock);
1922 g_timer_stop (priv->timer);
1924 if (priv->timer_id != 0)
1925 g_source_remove (priv->timer_id);
1928 g_mutex_unlock (priv->lock);
1931 /* We are about to destroy the window, no need to update it or create
1932 * a video preview */
1935 empathy_call_window_status_message (self, _("Disconnected"));
1937 empathy_call_window_show_hangup_button (self, FALSE);
1939 /* Unsensitive the camera and mic button */
1940 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1941 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1943 /* Be sure that the mic button is enabled */
1944 gtk_toggle_tool_button_set_active (
1945 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1947 if (priv->camera_state == CAMERA_STATE_ON)
1949 /* Restart the preview with the new pipeline. */
1950 display_video_preview (self, TRUE);
1953 gtk_progress_bar_set_fraction (
1954 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1956 /* destroy the video output; it will be recreated when we'll redial */
1957 disconnect_video_output_motion_handler (self);
1958 if (priv->video_output != NULL)
1959 clutter_actor_destroy (priv->video_output);
1960 priv->video_output = NULL;
1961 if (priv->got_video_src > 0)
1963 g_source_remove (priv->got_video_src);
1964 priv->got_video_src = 0;
1967 gtk_widget_show (priv->remote_user_avatar_widget);
1969 reset_details_pane (self);
1971 priv->sending_video = FALSE;
1972 priv->call_started = FALSE;
1974 could_disconnect = TRUE;
1976 /* TODO: display the self avatar of the preview (depends if the "Always
1977 * Show Video Preview" is enabled or not) */
1980 return could_disconnect;
1985 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1988 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1989 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1991 if (empathy_call_window_disconnected (self, TRUE) &&
1992 priv->call_state == REDIALING)
1993 empathy_call_window_restart_call (self);
1997 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1999 FsMediaType media_type,
2000 EmpathyCallWindow *self)
2002 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2004 DEBUG ("removing content");
2007 * This assumes that there is only one video stream per channel...
2010 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2012 if (priv->funnel != NULL)
2016 output = priv->video_output_sink;
2018 gst_element_set_state (output, GST_STATE_NULL);
2019 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2021 gst_bin_remove (GST_BIN (priv->pipeline), output);
2022 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2023 priv->funnel = NULL;
2027 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2029 if (priv->audio_output != NULL)
2031 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2033 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2034 priv->audio_output = NULL;
2042 /* Called with global lock held */
2044 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2046 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2050 if (priv->funnel == NULL)
2052 output = priv->video_output_sink;
2054 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2058 g_warning ("Could not create fsfunnel");
2062 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2064 gst_object_unref (priv->funnel);
2065 priv->funnel = NULL;
2066 g_warning ("Could not add funnel to pipeline");
2070 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2072 g_warning ("Could not add the video output widget to the pipeline");
2076 if (!gst_element_link (priv->funnel, output))
2078 g_warning ("Could not link output sink to funnel");
2079 goto error_output_added;
2082 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2084 g_warning ("Could not start video sink");
2085 goto error_output_added;
2088 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2090 g_warning ("Could not start funnel");
2091 goto error_output_added;
2095 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2098 g_warning ("Could not get request pad from funnel");
2105 gst_element_set_locked_state (priv->funnel, TRUE);
2106 gst_element_set_locked_state (output, TRUE);
2108 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2109 gst_element_set_state (output, GST_STATE_NULL);
2111 gst_bin_remove (GST_BIN (priv->pipeline), output);
2112 gst_element_set_locked_state (output, FALSE);
2116 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2117 priv->funnel = NULL;
2122 /* Called with global lock held */
2124 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2126 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2128 GstPadTemplate *template;
2130 if (priv->audio_output == NULL)
2132 priv->audio_output = empathy_audio_sink_new ();
2133 g_object_ref_sink (priv->audio_output);
2135 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2137 g_warning ("Could not add audio sink to pipeline");
2138 g_object_unref (priv->audio_output);
2139 goto error_add_output;
2142 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2144 g_warning ("Could not start audio sink");
2149 template = gst_element_class_get_pad_template (
2150 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2152 pad = gst_element_request_pad (priv->audio_output,
2153 template, NULL, NULL);
2157 g_warning ("Could not get sink pad from sink");
2164 gst_element_set_locked_state (priv->audio_output, TRUE);
2165 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2166 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2167 priv->audio_output = NULL;
2175 empathy_call_window_update_timer (gpointer user_data)
2177 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2178 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2182 time_ = g_timer_elapsed (priv->timer, NULL);
2184 /* Translators: 'status - minutes:seconds' the caller has been connected */
2185 str = g_strdup_printf (_("%s — %d:%02dm"),
2186 priv->call_state == HELD ? _("On hold") : _("Connected"),
2187 (int) time_ / 60, (int) time_ % 60);
2188 empathy_call_window_status_message (self, str);
2196 display_error (EmpathyCallWindow *self,
2197 TpyCallChannel *call,
2201 const gchar *details)
2203 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2204 GtkWidget *info_bar;
2205 GtkWidget *content_area;
2212 /* Create info bar */
2213 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2216 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2218 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2220 /* hbox containing the image and the messages vbox */
2221 hbox = gtk_hbox_new (FALSE, 3);
2222 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2225 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2226 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2228 /* vbox containing the main message and the details expander */
2229 vbox = gtk_vbox_new (FALSE, 3);
2230 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2233 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2235 label = gtk_label_new (NULL);
2236 gtk_label_set_markup (GTK_LABEL (label), txt);
2237 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2238 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2241 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2244 if (details != NULL)
2246 GtkWidget *expander;
2248 expander = gtk_expander_new (_("Technical Details"));
2250 txt = g_strdup_printf ("<i>%s</i>", details);
2252 label = gtk_label_new (NULL);
2253 gtk_label_set_markup (GTK_LABEL (label), txt);
2254 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2255 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2258 gtk_container_add (GTK_CONTAINER (expander), label);
2259 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2262 g_signal_connect (info_bar, "response",
2263 G_CALLBACK (gtk_widget_destroy), NULL);
2265 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2266 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2267 gtk_widget_show_all (info_bar);
2271 media_stream_error_to_txt (EmpathyCallWindow *self,
2272 TpyCallChannel *call,
2274 TpMediaStreamError error)
2276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2277 const gchar *cm = NULL;
2283 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2285 return g_strdup_printf (
2286 _("%s's software does not understand any of the audio formats "
2287 "supported by your computer"),
2288 empathy_contact_get_alias (priv->contact));
2290 return g_strdup_printf (
2291 _("%s's software does not understand any of the video formats "
2292 "supported by your computer"),
2293 empathy_contact_get_alias (priv->contact));
2295 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2296 return g_strdup_printf (
2297 _("Can't establish a connection to %s. "
2298 "One of you might be on a network that does not allow "
2299 "direct connections."),
2300 empathy_contact_get_alias (priv->contact));
2302 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2303 return g_strdup (_("There was a failure on the network"));
2305 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2307 return g_strdup (_("The audio formats necessary for this call "
2308 "are not installed on your computer"));
2310 return g_strdup (_("The video formats necessary for this call "
2311 "are not installed on your computer"));
2313 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2314 tp_connection_parse_object_path (
2315 tp_channel_borrow_connection (TP_CHANNEL (call)),
2318 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2319 "product=Telepathy&component=%s", cm);
2321 result = g_strdup_printf (
2322 _("Something unexpected happened in a Telepathy component. "
2323 "Please <a href=\"%s\">report this bug</a> and attach "
2324 "logs gathered from the 'Debug' window in the Help menu."), url);
2330 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2331 return g_strdup (_("There was a failure in the call engine"));
2333 case TP_MEDIA_STREAM_ERROR_EOS:
2334 return g_strdup (_("The end of the stream was reached"));
2336 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2343 empathy_call_window_stream_error (EmpathyCallWindow *self,
2344 TpyCallChannel *call,
2353 desc = media_stream_error_to_txt (self, call, audio, code);
2356 /* No description, use the error message. That's not great as it's not
2357 * localized but it's better than nothing. */
2358 display_error (self, call, icon, title, msg, NULL);
2362 display_error (self, call, icon, title, desc, msg);
2368 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2371 EmpathyCallWindow *self)
2373 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2374 "gnome-stock-mic", _("Can't establish audio stream"));
2378 empathy_call_window_video_stream_error (TpyCallChannel *call,
2381 EmpathyCallWindow *self)
2383 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2384 "camera-web", _("Can't establish video stream"));
2389 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2391 EmpathyCallWindow *self)
2393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2394 TpyCallChannel *call;
2395 gboolean can_send_video;
2397 if (state != TPY_CALL_STATE_ACCEPTED)
2400 if (priv->call_state == CONNECTED)
2403 g_timer_start (priv->timer);
2404 priv->call_state = CONNECTED;
2406 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2408 can_send_video = priv->video_input != NULL &&
2409 empathy_contact_can_voip_video (priv->contact) &&
2410 empathy_camera_monitor_get_available (priv->camera_monitor);
2412 g_object_get (priv->handler, "call-channel", &call, NULL);
2414 if (tpy_call_channel_has_dtmf (call))
2415 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2417 if (priv->video_input == NULL)
2418 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2420 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2422 empathy_call_window_show_hangup_button (self, TRUE);
2424 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2426 clutter_actor_hide (priv->video_output);
2427 gtk_widget_show (priv->remote_user_avatar_widget);
2429 g_object_unref (call);
2431 g_mutex_lock (priv->lock);
2433 priv->timer_id = g_timeout_add_seconds (1,
2434 empathy_call_window_update_timer, self);
2436 g_mutex_unlock (priv->lock);
2438 empathy_call_window_update_timer (self);
2440 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2444 empathy_call_window_show_video_output_cb (gpointer user_data)
2446 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2448 if (self->priv->video_output != NULL)
2450 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2451 clutter_actor_show (self->priv->video_output);
2458 empathy_call_window_check_video_cb (gpointer data)
2460 EmpathyCallWindow *self = data;
2462 if (self->priv->got_video)
2464 self->priv->got_video = FALSE;
2468 /* No video in the last N seconds, display the remote avatar */
2469 empathy_call_window_show_video_output (self, FALSE);
2474 /* Called from the streaming thread */
2476 empathy_call_window_video_probe_cb (GstPad *pad,
2477 GstMiniObject *mini_obj,
2478 EmpathyCallWindow *self)
2481 if (GST_IS_EVENT (mini_obj))
2484 if (G_UNLIKELY (!self->priv->got_video))
2486 /* show the remote video */
2487 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2488 empathy_call_window_show_video_output_cb,
2489 g_object_ref (self), g_object_unref);
2491 self->priv->got_video = TRUE;
2497 /* Called from the streaming thread */
2499 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2500 GstPad *src, guint media_type, gpointer user_data)
2502 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2503 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2504 gboolean retval = FALSE;
2508 g_mutex_lock (priv->lock);
2512 case TP_MEDIA_STREAM_TYPE_AUDIO:
2513 pad = empathy_call_window_get_audio_sink_pad (self);
2515 case TP_MEDIA_STREAM_TYPE_VIDEO:
2516 g_idle_add (empathy_call_window_show_video_output_cb, self);
2517 pad = empathy_call_window_get_video_sink_pad (self);
2519 gst_pad_add_data_probe (src,
2520 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2521 if (priv->got_video_src > 0)
2522 g_source_remove (priv->got_video_src);
2523 priv->got_video_src = g_timeout_add_seconds (5,
2524 empathy_call_window_check_video_cb, self);
2527 g_assert_not_reached ();
2533 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2534 g_warning ("Could not link %s sink pad",
2535 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2539 gst_object_unref (pad);
2543 /* If no sink could be linked, try to add fakesink to prevent the whole call
2548 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2550 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2552 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2553 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2554 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2556 gst_element_set_locked_state (fakesink, TRUE);
2557 gst_element_set_state (fakesink, GST_STATE_NULL);
2558 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2562 DEBUG ("Could not link real sink, linked fakesink instead");
2564 gst_object_unref (sinkpad);
2568 gst_object_unref (fakesink);
2573 g_mutex_unlock (priv->lock);
2579 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2580 GstPad *sink, FsMediaType media_type, gpointer user_data)
2582 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2583 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2585 gboolean retval = FALSE;
2589 case FS_MEDIA_TYPE_AUDIO:
2590 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2592 g_warning ("Could not add audio source to pipeline");
2596 pad = gst_element_get_static_pad (priv->audio_input, "src");
2599 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2600 g_warning ("Could not get source pad from audio source");
2604 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2606 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2607 g_warning ("Could not link audio source to farsight");
2611 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2613 g_warning ("Could not start audio source");
2614 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2615 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2621 case FS_MEDIA_TYPE_VIDEO:
2622 if (priv->video_tee != NULL)
2624 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2625 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2627 g_warning ("Could not link video source input pipeline");
2630 gst_object_unref (pad);
2636 g_assert_not_reached ();
2643 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2645 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2646 GstElement *preview;
2648 disable_camera (self);
2650 DEBUG ("remove video input");
2651 preview = priv->video_preview_sink;
2653 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2654 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2655 gst_element_set_state (preview, GST_STATE_NULL);
2657 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2660 g_object_unref (priv->video_input);
2661 priv->video_input = NULL;
2662 g_object_unref (priv->video_tee);
2663 priv->video_tee = NULL;
2664 clutter_actor_destroy (priv->video_preview);
2665 priv->video_preview = NULL;
2667 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2671 start_call (EmpathyCallWindow *self)
2673 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2675 priv->call_started = TRUE;
2676 empathy_call_handler_start_call (priv->handler,
2677 gtk_get_current_event_time ());
2679 if (empathy_call_handler_has_initial_video (priv->handler))
2681 TpyCallChannel *call;
2684 g_object_get (priv->handler, "call-channel", &call, NULL);
2685 s = tpy_call_channel_get_video_state (call);
2687 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2688 s == TPY_SENDING_STATE_SENDING)
2690 /* Enable 'send video' buttons and display the preview */
2691 gtk_toggle_tool_button_set_active (
2692 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2696 gtk_toggle_tool_button_set_active (
2697 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2699 if (priv->video_preview == NULL)
2701 create_video_preview (self);
2702 add_video_preview_to_pipeline (self);
2706 g_object_unref (call);
2711 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2714 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2715 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2718 empathy_call_handler_bus_message (priv->handler, bus, message);
2720 switch (GST_MESSAGE_TYPE (message))
2722 case GST_MESSAGE_STATE_CHANGED:
2723 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2725 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2726 if (newstate == GST_STATE_PAUSED)
2727 empathy_call_window_setup_video_input (self);
2729 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2730 !priv->call_started)
2732 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2733 if (newstate == GST_STATE_PAUSED)
2735 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2736 priv->pipeline_playing = TRUE;
2738 if (priv->start_call_when_playing)
2743 case GST_MESSAGE_ERROR:
2745 GError *error = NULL;
2746 GstElement *gst_error;
2749 gst_message_parse_error (message, &error, &debug);
2750 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2752 g_message ("Element error: %s -- %s\n", error->message, debug);
2754 if (g_str_has_prefix (gst_element_get_name (gst_error),
2755 VIDEO_INPUT_ERROR_PREFIX))
2757 /* Remove the video input and continue */
2758 if (priv->video_input != NULL)
2759 empathy_call_window_remove_video_input (self);
2760 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2764 empathy_call_window_disconnected (self, TRUE);
2766 g_error_free (error);
2769 case GST_MESSAGE_UNKNOWN:
2770 case GST_MESSAGE_EOS:
2771 case GST_MESSAGE_WARNING:
2772 case GST_MESSAGE_INFO:
2773 case GST_MESSAGE_TAG:
2774 case GST_MESSAGE_BUFFERING:
2775 case GST_MESSAGE_STATE_DIRTY:
2776 case GST_MESSAGE_STEP_DONE:
2777 case GST_MESSAGE_CLOCK_PROVIDE:
2778 case GST_MESSAGE_CLOCK_LOST:
2779 case GST_MESSAGE_NEW_CLOCK:
2780 case GST_MESSAGE_STRUCTURE_CHANGE:
2781 case GST_MESSAGE_STREAM_STATUS:
2782 case GST_MESSAGE_APPLICATION:
2783 case GST_MESSAGE_ELEMENT:
2784 case GST_MESSAGE_SEGMENT_START:
2785 case GST_MESSAGE_SEGMENT_DONE:
2786 case GST_MESSAGE_DURATION:
2787 case GST_MESSAGE_ANY:
2796 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2797 GHashTable *members,
2798 EmpathyCallWindow *self)
2800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2801 GHashTableIter iter;
2802 gpointer key, value;
2803 gboolean held = FALSE;
2805 g_hash_table_iter_init (&iter, members);
2806 while (g_hash_table_iter_next (&iter, &key, &value))
2808 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2810 /* This assumes this is a 1-1 call, otherwise one participant
2811 * putting the call on hold wouldn't mean the call is on hold
2819 priv->call_state = HELD;
2820 else if (priv->call_state == HELD)
2821 priv->call_state = CONNECTED;
2825 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2827 EmpathyCallWindow *self)
2829 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2830 TpyCallChannel *call;
2832 g_object_get (priv->handler, "call-channel", &call, NULL);
2837 tp_g_signal_connect_object (call, "audio-stream-error",
2838 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2839 tp_g_signal_connect_object (call, "video-stream-error",
2840 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2843 tp_g_signal_connect_object (call, "members-changed",
2844 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2846 g_object_unref (call);
2850 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2852 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2853 TpyCallChannel *call;
2856 /* Make the hangup button twice as wide */
2857 width = gtk_widget_get_allocated_width (priv->hangup_button);
2858 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2860 g_signal_connect (priv->handler, "state-changed",
2861 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2862 g_signal_connect (priv->handler, "conference-added",
2863 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2864 g_signal_connect (priv->handler, "conference-removed",
2865 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2866 g_signal_connect (priv->handler, "closed",
2867 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2868 g_signal_connect (priv->handler, "src-pad-added",
2869 G_CALLBACK (empathy_call_window_src_added_cb), window);
2870 g_signal_connect (priv->handler, "sink-pad-added",
2871 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2872 g_signal_connect (priv->handler, "sink-pad-removed",
2873 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2875 g_object_get (priv->handler, "call-channel", &call, NULL);
2878 call_handler_notify_call_cb (priv->handler, NULL, window);
2879 g_object_unref (call);
2883 /* call-channel doesn't exist yet, we'll connect signals once it has been
2885 g_signal_connect (priv->handler, "notify::call-channel",
2886 G_CALLBACK (call_handler_notify_call_cb), window);
2889 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2893 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2894 EmpathyCallWindow *window)
2896 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2898 if (priv->pipeline != NULL)
2900 if (priv->bus_message_source_id != 0)
2902 g_source_remove (priv->bus_message_source_id);
2903 priv->bus_message_source_id = 0;
2906 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2909 if (priv->call_state == CONNECTING)
2910 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2916 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2919 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2921 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2926 gtk_widget_hide (priv->sidebar);
2927 gtk_widget_hide (menu);
2928 gtk_widget_hide (priv->toolbar);
2932 if (priv->sidebar_was_visible_before_fs)
2933 gtk_widget_show (priv->sidebar);
2935 gtk_widget_show (menu);
2936 gtk_widget_show (priv->toolbar);
2938 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2939 priv->original_height_before_fs);
2944 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2946 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2948 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2949 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2950 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2951 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2953 if (priv->video_output != NULL)
2956 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2957 priv->video_output, TRUE, TRUE,
2958 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2965 empathy_call_window_state_event_cb (GtkWidget *widget,
2966 GdkEventWindowState *event, EmpathyCallWindow *window)
2968 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2970 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2971 gboolean set_fullscreen = event->new_window_state &
2972 GDK_WINDOW_STATE_FULLSCREEN;
2976 gboolean sidebar_was_visible;
2977 GtkAllocation allocation;
2978 gint original_width, original_height;
2980 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2981 original_width = allocation.width;
2982 original_height = allocation.height;
2984 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2986 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2987 priv->original_width_before_fs = original_width;
2988 priv->original_height_before_fs = original_height;
2990 if (priv->video_output_motion_handler_id == 0 &&
2991 priv->video_output != NULL)
2993 priv->video_output_motion_handler_id = g_signal_connect (
2994 G_OBJECT (priv->video_container), "motion-notify-event",
2995 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3001 disconnect_video_output_motion_handler (window);
3004 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3006 show_controls (window, set_fullscreen);
3007 show_borders (window, set_fullscreen);
3008 gtk_action_set_stock_id (priv->menu_fullscreen,
3009 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3010 priv->is_fullscreen = set_fullscreen;
3017 empathy_call_window_update_sidebar_buttons (EmpathyCallWindow *window,
3020 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3022 /* Update dialpad button */
3023 g_signal_handlers_block_by_func (priv->dialpad_button,
3024 empathy_call_window_dialpad_cb, window);
3025 gtk_toggle_tool_button_set_active (
3026 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button),
3028 g_signal_handlers_unblock_by_func (priv->dialpad_button,
3029 empathy_call_window_dialpad_cb, window);
3031 /* Update sidebar menu */
3032 g_signal_handlers_block_by_func (priv->menu_sidebar,
3033 empathy_call_window_sidebar_cb, window);
3034 gtk_toggle_action_set_active (
3035 GTK_TOGGLE_ACTION (priv->menu_sidebar),
3036 gtk_widget_get_visible (priv->sidebar));
3037 g_signal_handlers_unblock_by_func (priv->menu_sidebar,
3038 empathy_call_window_sidebar_cb, window);
3042 empathy_call_window_show_sidebar (EmpathyCallWindow *window,
3045 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3046 int w, h, sidebar_width, handle_size;
3047 GtkAllocation allocation;
3049 gboolean dialpad_shown;
3051 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3052 w = allocation.width;
3053 h = allocation.height;
3055 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
3057 gtk_widget_get_preferred_width (priv->sidebar, &sidebar_width, NULL);
3061 gtk_widget_show (priv->sidebar);
3062 w += sidebar_width + handle_size;
3066 w -= sidebar_width + handle_size;
3067 gtk_widget_hide (priv->sidebar);
3071 gtk_window_resize (GTK_WINDOW (window), w, h);
3073 /* Update the 'Dialpad' menu */
3074 page = ev_sidebar_get_current_page (EV_SIDEBAR (priv->sidebar));
3075 dialpad_shown = active && !tp_strdiff (page, "dialpad");
3078 empathy_call_window_update_sidebar_buttons (window, dialpad_shown);
3082 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3085 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3086 TpyCallChannel *call;
3088 priv->sending_video = (state == CAMERA_STATE_ON);
3090 if (state == CAMERA_STATE_ON)
3092 /* When we start sending video, we want to show the video preview by
3094 display_video_preview (window, TRUE);
3098 display_video_preview (window, FALSE);
3101 if (priv->call_state != CONNECTED)
3104 g_object_get (priv->handler, "call-channel", &call, NULL);
3105 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3106 tpy_call_channel_send_video (call, priv->sending_video);
3107 g_object_unref (call);
3111 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3112 EmpathyCallWindow *window)
3114 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3117 active = (gtk_toggle_tool_button_get_active (toggle));
3121 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3123 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3127 /* TODO, Instead of setting the input volume to 0 we should probably
3128 * stop sending but this would cause the audio call to drop if both
3129 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3130 * in the future. GNOME #574574
3132 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3134 gtk_adjustment_set_value (priv->audio_input_adj, 0);
3139 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3140 EmpathyCallWindow *window)
3142 empathy_call_window_show_sidebar (window, FALSE);
3146 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3147 EmpathyCallWindow *window)
3149 empathy_call_window_show_sidebar (window, TRUE);
3153 empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
3155 EmpathyCallWindow *window)
3157 empathy_call_window_update_sidebar_buttons (window,
3158 !tp_strdiff (page, "dialpad"));
3162 empathy_call_window_hangup_cb (gpointer object,
3163 EmpathyCallWindow *window)
3165 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3167 empathy_call_handler_stop_call (priv->handler);
3169 if (empathy_call_window_disconnected (window, FALSE))
3170 gtk_widget_destroy (GTK_WIDGET (window));
3174 empathy_call_window_restart_call (EmpathyCallWindow *window)
3176 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3178 /* Remove error info bars */
3179 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3180 (GtkCallback) gtk_widget_destroy, NULL);
3182 create_video_output_widget (window);
3184 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3185 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3187 /* While the call was disconnected, the input volume might have changed.
3188 * However, since the audio_input source was destroyed, its volume has not
3189 * been updated during that time. That's why we manually update it here */
3190 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3192 priv->outgoing = TRUE;
3193 empathy_call_window_set_state_connecting (window);
3195 if (priv->pipeline_playing)
3196 start_call (window);
3198 /* call will be started when the pipeline is ready */
3199 priv->start_call_when_playing = TRUE;
3201 empathy_call_window_setup_avatars (window, priv->handler);
3203 empathy_call_window_show_hangup_button (window, TRUE);
3207 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3208 EmpathyCallWindow *window)
3210 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3213 active = gtk_toggle_tool_button_get_active (button);
3216 ev_sidebar_set_current_page (EV_SIDEBAR (priv->sidebar), "dialpad");
3218 empathy_call_window_show_sidebar (window, active);
3222 empathy_call_window_sidebar_cb (GtkToggleAction *menu,
3223 EmpathyCallWindow *self)
3225 empathy_call_window_show_sidebar (self,
3226 gtk_toggle_action_get_active (menu));
3230 empathy_call_window_fullscreen_cb (gpointer object,
3231 EmpathyCallWindow *window)
3233 empathy_call_window_fullscreen_toggle (window);
3237 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3239 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3241 if (priv->is_fullscreen)
3242 gtk_window_unfullscreen (GTK_WINDOW (window));
3244 gtk_window_fullscreen (GTK_WINDOW (window));
3248 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3249 GdkEventButton *event, EmpathyCallWindow *window)
3251 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3253 empathy_call_window_video_menu_popup (window, event->button);
3261 empathy_call_window_key_press_cb (GtkWidget *video_output,
3262 GdkEventKey *event, EmpathyCallWindow *window)
3264 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3266 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3268 /* Since we are in fullscreen mode, toggling will bring us back to
3270 empathy_call_window_fullscreen_toggle (window);
3278 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3279 GdkEventMotion *event, EmpathyCallWindow *window)
3281 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3283 if (priv->is_fullscreen)
3285 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3292 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3296 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3298 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3300 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3301 button, gtk_get_current_event_time ());
3302 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3306 empathy_call_window_status_message (EmpathyCallWindow *self,
3309 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3313 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3314 gdouble value, EmpathyCallWindow *window)
3316 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3318 if (priv->audio_output == NULL)
3321 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),