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_geometry_bind (GTK_WINDOW (self), "call-window");
1223 /* These signals are used to track the window position and save it
1224 * when the window is destroyed. We need to do this as we don't want
1225 * the window geometry to be saved with the sidebar taken into account. */
1226 g_signal_connect (self, "destroy",
1227 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1228 g_signal_connect (self, "configure-event",
1229 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1230 g_signal_connect (self, "window-state-event",
1231 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1234 /* Instead of specifying a width and a height, we specify only one size. That's
1235 because we want a square avatar icon. */
1237 init_contact_avatar_with_size (EmpathyContact *contact,
1238 GtkWidget *image_widget,
1241 GdkPixbuf *pixbuf_avatar = NULL;
1243 if (contact != NULL)
1245 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1249 if (pixbuf_avatar == NULL)
1251 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1252 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1255 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1257 if (pixbuf_avatar != NULL)
1258 g_object_unref (pixbuf_avatar);
1262 set_window_title (EmpathyCallWindow *self)
1264 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1267 if (priv->contact != NULL)
1269 /* translators: Call is a noun and %s is the contact name. This string
1270 * is used in the window title */
1271 tmp = g_strdup_printf (_("Call with %s"),
1272 empathy_contact_get_alias (priv->contact));
1273 gtk_window_set_title (GTK_WINDOW (self), tmp);
1278 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1283 set_remote_user_name (EmpathyCallWindow *self,
1284 EmpathyContact *contact)
1286 const gchar *alias = empathy_contact_get_alias (contact);
1287 const gchar *status = empathy_contact_get_status (contact);
1290 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1291 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1297 contact_name_changed_cb (EmpathyContact *contact,
1299 EmpathyCallWindow *self)
1301 set_window_title (self);
1302 set_remote_user_name (self, contact);
1306 contact_presence_changed_cb (EmpathyContact *contact,
1308 EmpathyCallWindow *self)
1310 set_remote_user_name (self, contact);
1314 contact_avatar_changed_cb (EmpathyContact *contact,
1316 EmpathyCallWindow *self)
1319 GtkAllocation allocation;
1320 GtkWidget *avatar_widget;
1322 avatar_widget = self->priv->remote_user_avatar_widget;
1324 gtk_widget_get_allocation (avatar_widget, &allocation);
1325 size = allocation.height;
1329 /* the widget is not allocated yet, set a default size */
1330 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1331 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1334 init_contact_avatar_with_size (contact, avatar_widget, size);
1336 avatar_widget = self->priv->remote_user_avatar_toolbar;
1338 gtk_widget_get_allocation (avatar_widget, &allocation);
1339 size = allocation.height;
1343 /* the widget is not allocated yet, set a default size */
1344 size = SMALL_TOOLBAR_SIZE;
1347 init_contact_avatar_with_size (contact, avatar_widget, size);
1351 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1352 EmpathyCallHandler *handler)
1354 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1356 g_signal_connect (priv->contact, "notify::name",
1357 G_CALLBACK (contact_name_changed_cb), self);
1358 g_signal_connect (priv->contact, "notify::avatar",
1359 G_CALLBACK (contact_avatar_changed_cb), self);
1360 /* FIXME: There's no EmpathyContact::presence yet */
1361 g_signal_connect (priv->contact, "notify::presence",
1362 G_CALLBACK (contact_presence_changed_cb), self);
1364 set_window_title (self);
1365 set_remote_user_name (self, priv->contact);
1367 init_contact_avatar_with_size (priv->contact,
1368 priv->remote_user_avatar_widget,
1369 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1370 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1372 init_contact_avatar_with_size (priv->contact,
1373 priv->remote_user_avatar_toolbar,
1374 SMALL_TOOLBAR_SIZE);
1376 /* The remote avatar is shown by default and will be hidden when we receive
1377 video from the remote side. */
1378 clutter_actor_hide (priv->video_output);
1379 gtk_widget_show (priv->remote_user_avatar_widget);
1383 update_send_codec (EmpathyCallWindow *self,
1386 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1393 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1394 widget = priv->acodec_encoding_label;
1398 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1399 widget = priv->vcodec_encoding_label;
1405 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1406 gtk_label_set_text (GTK_LABEL (widget), tmp);
1411 send_audio_codec_notify_cb (GObject *object,
1415 EmpathyCallWindow *self = user_data;
1417 update_send_codec (self, TRUE);
1421 send_video_codec_notify_cb (GObject *object,
1425 EmpathyCallWindow *self = user_data;
1427 update_send_codec (self, FALSE);
1431 update_recv_codec (EmpathyCallWindow *self,
1434 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1437 GString *str = NULL;
1441 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1442 widget = priv->acodec_decoding_label;
1446 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1447 widget = priv->vcodec_decoding_label;
1453 for (l = codecs; l != NULL; l = g_list_next (l))
1455 FsCodec *codec = l->data;
1458 str = g_string_new (NULL);
1460 g_string_append (str, ", ");
1462 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1466 gtk_label_set_text (GTK_LABEL (widget), str->str);
1467 g_string_free (str, TRUE);
1471 recv_audio_codecs_notify_cb (GObject *object,
1475 EmpathyCallWindow *self = user_data;
1477 update_recv_codec (self, TRUE);
1481 recv_video_codecs_notify_cb (GObject *object,
1485 EmpathyCallWindow *self = user_data;
1487 update_recv_codec (self, FALSE);
1490 static const gchar *
1491 candidate_type_to_str (FsCandidate *candidate)
1493 switch (candidate->type)
1495 case FS_CANDIDATE_TYPE_HOST:
1497 case FS_CANDIDATE_TYPE_SRFLX:
1498 return "server reflexive";
1499 case FS_CANDIDATE_TYPE_PRFLX:
1500 return "peer reflexive";
1501 case FS_CANDIDATE_TYPE_RELAY:
1503 case FS_CANDIDATE_TYPE_MULTICAST:
1510 static const gchar *
1511 candidate_type_to_desc (FsCandidate *candidate)
1513 switch (candidate->type)
1515 case FS_CANDIDATE_TYPE_HOST:
1516 return _("The IP address as seen by the machine");
1517 case FS_CANDIDATE_TYPE_SRFLX:
1518 return _("The IP address as seen by a server on the Internet");
1519 case FS_CANDIDATE_TYPE_PRFLX:
1520 return _("The IP address of the peer as seen by the other side");
1521 case FS_CANDIDATE_TYPE_RELAY:
1522 return _("The IP address of a relay server");
1523 case FS_CANDIDATE_TYPE_MULTICAST:
1524 return _("The IP address of the multicast group");
1531 update_candidat_widget (EmpathyCallWindow *self,
1534 FsCandidate *candidate)
1538 g_assert (candidate != NULL);
1539 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1540 candidate->port, candidate_type_to_str (candidate));
1542 gtk_label_set_text (GTK_LABEL (label), str);
1543 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1549 candidates_changed_cb (GObject *object,
1551 EmpathyCallWindow *self)
1553 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1554 FsCandidate *candidate = NULL;
1556 if (type == FS_MEDIA_TYPE_VIDEO)
1558 /* Update remote candidate */
1559 candidate = empathy_call_handler_get_video_remote_candidate (
1562 update_candidat_widget (self, priv->video_remote_candidate_label,
1563 priv->video_remote_candidate_info_img, candidate);
1565 /* Update local candidate */
1566 candidate = empathy_call_handler_get_video_local_candidate (
1569 update_candidat_widget (self, priv->video_local_candidate_label,
1570 priv->video_local_candidate_info_img, candidate);
1574 /* Update remote candidate */
1575 candidate = empathy_call_handler_get_audio_remote_candidate (
1578 update_candidat_widget (self, priv->audio_remote_candidate_label,
1579 priv->audio_remote_candidate_info_img, candidate);
1581 /* Update local candidate */
1582 candidate = empathy_call_handler_get_audio_local_candidate (
1585 update_candidat_widget (self, priv->audio_local_candidate_label,
1586 priv->audio_local_candidate_info_img, candidate);
1591 empathy_call_window_constructed (GObject *object)
1593 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1594 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1595 TpyCallChannel *call;
1597 g_assert (priv->handler != NULL);
1599 g_object_get (priv->handler, "call-channel", &call, NULL);
1600 priv->outgoing = (call == NULL);
1602 g_object_unref (call);
1604 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1605 g_assert (priv->contact != NULL);
1607 empathy_call_window_setup_avatars (self, priv->handler);
1608 empathy_call_window_set_state_connecting (self);
1610 if (!empathy_call_handler_has_initial_video (priv->handler))
1612 gtk_toggle_tool_button_set_active (
1613 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1615 /* If call has InitialVideo, the preview will be started once the call has
1616 * been started (start_call()). */
1618 update_send_codec (self, TRUE);
1619 update_send_codec (self, FALSE);
1620 update_recv_codec (self, TRUE);
1621 update_recv_codec (self, FALSE);
1623 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1624 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1625 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1626 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1627 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1628 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1629 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1630 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1632 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1633 G_CALLBACK (candidates_changed_cb), self, 0);
1636 static void empathy_call_window_dispose (GObject *object);
1637 static void empathy_call_window_finalize (GObject *object);
1640 empathy_call_window_set_property (GObject *object,
1641 guint property_id, const GValue *value, GParamSpec *pspec)
1643 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1645 switch (property_id)
1647 case PROP_CALL_HANDLER:
1648 priv->handler = g_value_dup_object (value);
1651 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1656 empathy_call_window_get_property (GObject *object,
1657 guint property_id, GValue *value, GParamSpec *pspec)
1659 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1661 switch (property_id)
1663 case PROP_CALL_HANDLER:
1664 g_value_set_object (value, priv->handler);
1667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1672 empathy_call_window_class_init (
1673 EmpathyCallWindowClass *empathy_call_window_class)
1675 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1676 GParamSpec *param_spec;
1678 g_type_class_add_private (empathy_call_window_class,
1679 sizeof (EmpathyCallWindowPriv));
1681 object_class->constructed = empathy_call_window_constructed;
1682 object_class->set_property = empathy_call_window_set_property;
1683 object_class->get_property = empathy_call_window_get_property;
1685 object_class->dispose = empathy_call_window_dispose;
1686 object_class->finalize = empathy_call_window_finalize;
1688 param_spec = g_param_spec_object ("handler",
1689 "handler", "The call handler",
1690 EMPATHY_TYPE_CALL_HANDLER,
1691 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1692 g_object_class_install_property (object_class,
1693 PROP_CALL_HANDLER, param_spec);
1697 empathy_call_window_dispose (GObject *object)
1699 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1700 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1702 if (priv->dispose_has_run)
1705 priv->dispose_has_run = TRUE;
1707 if (priv->handler != NULL)
1709 empathy_call_handler_stop_call (priv->handler);
1710 tp_clear_object (&priv->handler);
1713 if (priv->bus_message_source_id != 0)
1715 g_source_remove (priv->bus_message_source_id);
1716 priv->bus_message_source_id = 0;
1719 if (priv->got_video_src > 0)
1721 g_source_remove (priv->got_video_src);
1722 priv->got_video_src = 0;
1725 tp_clear_object (&priv->pipeline);
1726 tp_clear_object (&priv->video_input);
1727 tp_clear_object (&priv->audio_input);
1728 tp_clear_object (&priv->video_tee);
1729 tp_clear_object (&priv->ui_manager);
1730 tp_clear_object (&priv->fullscreen);
1731 tp_clear_object (&priv->camera_monitor);
1733 g_list_free_full (priv->notifiers, g_object_unref);
1735 if (priv->timer_id != 0)
1736 g_source_remove (priv->timer_id);
1739 if (priv->contact != NULL)
1741 g_signal_handlers_disconnect_by_func (priv->contact,
1742 contact_name_changed_cb, self);
1743 priv->contact = NULL;
1747 tp_clear_object (&priv->sound_mgr);
1749 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1753 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1757 if (priv->video_output_motion_handler_id != 0)
1759 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1760 priv->video_output_motion_handler_id);
1761 priv->video_output_motion_handler_id = 0;
1766 empathy_call_window_finalize (GObject *object)
1768 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1771 disconnect_video_output_motion_handler (self);
1773 /* free any data held directly by the object here */
1774 g_mutex_free (priv->lock);
1776 g_timer_destroy (priv->timer);
1778 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1783 empathy_call_window_new (EmpathyCallHandler *handler)
1785 return EMPATHY_CALL_WINDOW (
1786 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1790 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1791 GstElement *conference, gpointer user_data)
1793 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1794 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1795 FsElementAddedNotifier *notifier;
1798 DEBUG ("Conference added");
1800 /* Add notifier to set the various element properties as needed */
1801 notifier = fs_element_added_notifier_new ();
1802 keyfile = fs_utils_get_default_element_properties (conference);
1804 if (keyfile != NULL)
1805 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1807 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1809 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1811 gst_bin_add (GST_BIN (priv->pipeline), conference);
1812 gst_element_set_state (conference, GST_STATE_PLAYING);
1816 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1817 GstElement *conference, gpointer user_data)
1819 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1820 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1822 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1823 gst_element_set_state (conference, GST_STATE_NULL);
1827 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1829 GstStateChangeReturn state_change_return;
1830 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1832 if (priv->pipeline == NULL)
1835 if (priv->bus_message_source_id != 0)
1837 g_source_remove (priv->bus_message_source_id);
1838 priv->bus_message_source_id = 0;
1841 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1843 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1844 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1846 if (priv->pipeline != NULL)
1847 g_object_unref (priv->pipeline);
1848 priv->pipeline = NULL;
1850 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1851 empathy_call_window_mic_volume_changed_cb, self);
1853 if (priv->audio_output != NULL)
1854 g_object_unref (priv->audio_output);
1855 priv->audio_output = NULL;
1857 if (priv->video_tee != NULL)
1858 g_object_unref (priv->video_tee);
1859 priv->video_tee = NULL;
1861 if (priv->video_preview != NULL)
1862 clutter_actor_destroy (priv->video_preview);
1863 priv->video_preview = NULL;
1865 priv->funnel = NULL;
1867 create_pipeline (self);
1868 /* Call will be started when user will hit the 'redial' button */
1869 priv->start_call_when_playing = FALSE;
1870 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1876 g_message ("Error: could not destroy pipeline. Closing call window");
1877 gtk_widget_destroy (GTK_WIDGET (self));
1884 reset_details_pane (EmpathyCallWindow *self)
1886 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1888 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1889 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1890 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1891 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1895 empathy_call_window_disconnected (EmpathyCallWindow *self,
1898 gboolean could_disconnect = FALSE;
1899 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1900 gboolean could_reset_pipeline;
1902 /* Leave full screen mode if needed */
1903 gtk_window_unfullscreen (GTK_WINDOW (self));
1905 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1906 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1908 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1910 if (priv->call_state == CONNECTING)
1911 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1913 if (priv->call_state != REDIALING)
1914 priv->call_state = DISCONNECTED;
1916 if (could_reset_pipeline)
1918 g_mutex_lock (priv->lock);
1920 g_timer_stop (priv->timer);
1922 if (priv->timer_id != 0)
1923 g_source_remove (priv->timer_id);
1926 g_mutex_unlock (priv->lock);
1929 /* We are about to destroy the window, no need to update it or create
1930 * a video preview */
1933 empathy_call_window_status_message (self, _("Disconnected"));
1935 empathy_call_window_show_hangup_button (self, FALSE);
1937 /* Unsensitive the camera and mic button */
1938 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1939 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1941 /* Be sure that the mic button is enabled */
1942 gtk_toggle_tool_button_set_active (
1943 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1945 if (priv->camera_state == CAMERA_STATE_ON)
1947 /* Restart the preview with the new pipeline. */
1948 display_video_preview (self, TRUE);
1951 gtk_progress_bar_set_fraction (
1952 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1954 /* destroy the video output; it will be recreated when we'll redial */
1955 disconnect_video_output_motion_handler (self);
1956 if (priv->video_output != NULL)
1957 clutter_actor_destroy (priv->video_output);
1958 priv->video_output = NULL;
1959 if (priv->got_video_src > 0)
1961 g_source_remove (priv->got_video_src);
1962 priv->got_video_src = 0;
1965 gtk_widget_show (priv->remote_user_avatar_widget);
1967 reset_details_pane (self);
1969 priv->sending_video = FALSE;
1970 priv->call_started = FALSE;
1972 could_disconnect = TRUE;
1974 /* TODO: display the self avatar of the preview (depends if the "Always
1975 * Show Video Preview" is enabled or not) */
1978 return could_disconnect;
1983 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1986 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1987 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1989 if (empathy_call_window_disconnected (self, TRUE) &&
1990 priv->call_state == REDIALING)
1991 empathy_call_window_restart_call (self);
1995 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
1997 FsMediaType media_type,
1998 EmpathyCallWindow *self)
2000 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2002 DEBUG ("removing content");
2005 * This assumes that there is only one video stream per channel...
2008 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2010 if (priv->funnel != NULL)
2014 output = priv->video_output_sink;
2016 gst_element_set_state (output, GST_STATE_NULL);
2017 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2019 gst_bin_remove (GST_BIN (priv->pipeline), output);
2020 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2021 priv->funnel = NULL;
2025 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2027 if (priv->audio_output != NULL)
2029 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2031 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2032 priv->audio_output = NULL;
2040 /* Called with global lock held */
2042 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2044 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2048 if (priv->funnel == NULL)
2050 output = priv->video_output_sink;
2052 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2056 g_warning ("Could not create fsfunnel");
2060 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2062 gst_object_unref (priv->funnel);
2063 priv->funnel = NULL;
2064 g_warning ("Could not add funnel to pipeline");
2068 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2070 g_warning ("Could not add the video output widget to the pipeline");
2074 if (!gst_element_link (priv->funnel, output))
2076 g_warning ("Could not link output sink to funnel");
2077 goto error_output_added;
2080 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2082 g_warning ("Could not start video sink");
2083 goto error_output_added;
2086 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2088 g_warning ("Could not start funnel");
2089 goto error_output_added;
2093 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2096 g_warning ("Could not get request pad from funnel");
2103 gst_element_set_locked_state (priv->funnel, TRUE);
2104 gst_element_set_locked_state (output, TRUE);
2106 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2107 gst_element_set_state (output, GST_STATE_NULL);
2109 gst_bin_remove (GST_BIN (priv->pipeline), output);
2110 gst_element_set_locked_state (output, FALSE);
2114 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2115 priv->funnel = NULL;
2120 /* Called with global lock held */
2122 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2124 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2126 GstPadTemplate *template;
2128 if (priv->audio_output == NULL)
2130 priv->audio_output = empathy_audio_sink_new ();
2131 g_object_ref_sink (priv->audio_output);
2133 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2135 g_warning ("Could not add audio sink to pipeline");
2136 g_object_unref (priv->audio_output);
2137 goto error_add_output;
2140 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2142 g_warning ("Could not start audio sink");
2147 template = gst_element_class_get_pad_template (
2148 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2150 pad = gst_element_request_pad (priv->audio_output,
2151 template, NULL, NULL);
2155 g_warning ("Could not get sink pad from sink");
2162 gst_element_set_locked_state (priv->audio_output, TRUE);
2163 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2164 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2165 priv->audio_output = NULL;
2173 empathy_call_window_update_timer (gpointer user_data)
2175 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2176 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2180 time_ = g_timer_elapsed (priv->timer, NULL);
2182 /* Translators: 'status - minutes:seconds' the caller has been connected */
2183 str = g_strdup_printf (_("%s — %d:%02dm"),
2184 priv->call_state == HELD ? _("On hold") : _("Connected"),
2185 (int) time_ / 60, (int) time_ % 60);
2186 empathy_call_window_status_message (self, str);
2194 display_error (EmpathyCallWindow *self,
2195 TpyCallChannel *call,
2199 const gchar *details)
2201 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2202 GtkWidget *info_bar;
2203 GtkWidget *content_area;
2210 /* Create info bar */
2211 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2214 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2216 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2218 /* hbox containing the image and the messages vbox */
2219 hbox = gtk_hbox_new (FALSE, 3);
2220 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2223 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2224 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2226 /* vbox containing the main message and the details expander */
2227 vbox = gtk_vbox_new (FALSE, 3);
2228 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2231 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2233 label = gtk_label_new (NULL);
2234 gtk_label_set_markup (GTK_LABEL (label), txt);
2235 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2236 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2239 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2242 if (details != NULL)
2244 GtkWidget *expander;
2246 expander = gtk_expander_new (_("Technical Details"));
2248 txt = g_strdup_printf ("<i>%s</i>", details);
2250 label = gtk_label_new (NULL);
2251 gtk_label_set_markup (GTK_LABEL (label), txt);
2252 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2253 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2256 gtk_container_add (GTK_CONTAINER (expander), label);
2257 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2260 g_signal_connect (info_bar, "response",
2261 G_CALLBACK (gtk_widget_destroy), NULL);
2263 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2264 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2265 gtk_widget_show_all (info_bar);
2269 media_stream_error_to_txt (EmpathyCallWindow *self,
2270 TpyCallChannel *call,
2272 TpMediaStreamError error)
2274 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2275 const gchar *cm = NULL;
2281 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2283 return g_strdup_printf (
2284 _("%s's software does not understand any of the audio formats "
2285 "supported by your computer"),
2286 empathy_contact_get_alias (priv->contact));
2288 return g_strdup_printf (
2289 _("%s's software does not understand any of the video formats "
2290 "supported by your computer"),
2291 empathy_contact_get_alias (priv->contact));
2293 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2294 return g_strdup_printf (
2295 _("Can't establish a connection to %s. "
2296 "One of you might be on a network that does not allow "
2297 "direct connections."),
2298 empathy_contact_get_alias (priv->contact));
2300 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2301 return g_strdup (_("There was a failure on the network"));
2303 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2305 return g_strdup (_("The audio formats necessary for this call "
2306 "are not installed on your computer"));
2308 return g_strdup (_("The video formats necessary for this call "
2309 "are not installed on your computer"));
2311 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2312 tp_connection_parse_object_path (
2313 tp_channel_borrow_connection (TP_CHANNEL (call)),
2316 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2317 "product=Telepathy&component=%s", cm);
2319 result = g_strdup_printf (
2320 _("Something unexpected happened in a Telepathy component. "
2321 "Please <a href=\"%s\">report this bug</a> and attach "
2322 "logs gathered from the 'Debug' window in the Help menu."), url);
2328 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2329 return g_strdup (_("There was a failure in the call engine"));
2331 case TP_MEDIA_STREAM_ERROR_EOS:
2332 return g_strdup (_("The end of the stream was reached"));
2334 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2341 empathy_call_window_stream_error (EmpathyCallWindow *self,
2342 TpyCallChannel *call,
2351 desc = media_stream_error_to_txt (self, call, audio, code);
2354 /* No description, use the error message. That's not great as it's not
2355 * localized but it's better than nothing. */
2356 display_error (self, call, icon, title, msg, NULL);
2360 display_error (self, call, icon, title, desc, msg);
2366 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2369 EmpathyCallWindow *self)
2371 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2372 "gnome-stock-mic", _("Can't establish audio stream"));
2376 empathy_call_window_video_stream_error (TpyCallChannel *call,
2379 EmpathyCallWindow *self)
2381 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2382 "camera-web", _("Can't establish video stream"));
2387 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2389 EmpathyCallWindow *self)
2391 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2392 TpyCallChannel *call;
2393 gboolean can_send_video;
2395 if (state != TPY_CALL_STATE_ACCEPTED)
2398 if (priv->call_state == CONNECTED)
2401 g_timer_start (priv->timer);
2402 priv->call_state = CONNECTED;
2404 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2406 can_send_video = priv->video_input != NULL &&
2407 empathy_contact_can_voip_video (priv->contact) &&
2408 empathy_camera_monitor_get_available (priv->camera_monitor);
2410 g_object_get (priv->handler, "call-channel", &call, NULL);
2412 if (tpy_call_channel_has_dtmf (call))
2413 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2415 if (priv->video_input == NULL)
2416 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2418 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2420 empathy_call_window_show_hangup_button (self, TRUE);
2422 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2424 clutter_actor_hide (priv->video_output);
2425 gtk_widget_show (priv->remote_user_avatar_widget);
2427 g_object_unref (call);
2429 g_mutex_lock (priv->lock);
2431 priv->timer_id = g_timeout_add_seconds (1,
2432 empathy_call_window_update_timer, self);
2434 g_mutex_unlock (priv->lock);
2436 empathy_call_window_update_timer (self);
2438 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2442 empathy_call_window_show_video_output_cb (gpointer user_data)
2444 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2446 if (self->priv->video_output != NULL)
2448 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2449 clutter_actor_show (self->priv->video_output);
2456 empathy_call_window_check_video_cb (gpointer data)
2458 EmpathyCallWindow *self = data;
2460 if (self->priv->got_video)
2462 self->priv->got_video = FALSE;
2466 /* No video in the last N seconds, display the remote avatar */
2467 empathy_call_window_show_video_output (self, FALSE);
2472 /* Called from the streaming thread */
2474 empathy_call_window_video_probe_cb (GstPad *pad,
2475 GstMiniObject *mini_obj,
2476 EmpathyCallWindow *self)
2479 if (GST_IS_EVENT (mini_obj))
2482 if (G_UNLIKELY (!self->priv->got_video))
2484 /* show the remote video */
2485 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2486 empathy_call_window_show_video_output_cb,
2487 g_object_ref (self), g_object_unref);
2489 self->priv->got_video = TRUE;
2495 /* Called from the streaming thread */
2497 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2498 GstPad *src, guint media_type, gpointer user_data)
2500 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2502 gboolean retval = FALSE;
2506 g_mutex_lock (priv->lock);
2510 case TP_MEDIA_STREAM_TYPE_AUDIO:
2511 pad = empathy_call_window_get_audio_sink_pad (self);
2513 case TP_MEDIA_STREAM_TYPE_VIDEO:
2514 g_idle_add (empathy_call_window_show_video_output_cb, self);
2515 pad = empathy_call_window_get_video_sink_pad (self);
2517 gst_pad_add_data_probe (src,
2518 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2519 if (priv->got_video_src > 0)
2520 g_source_remove (priv->got_video_src);
2521 priv->got_video_src = g_timeout_add_seconds (5,
2522 empathy_call_window_check_video_cb, self);
2525 g_assert_not_reached ();
2531 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2532 g_warning ("Could not link %s sink pad",
2533 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2537 gst_object_unref (pad);
2541 /* If no sink could be linked, try to add fakesink to prevent the whole call
2546 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2548 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2550 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2551 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2552 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2554 gst_element_set_locked_state (fakesink, TRUE);
2555 gst_element_set_state (fakesink, GST_STATE_NULL);
2556 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2560 DEBUG ("Could not link real sink, linked fakesink instead");
2562 gst_object_unref (sinkpad);
2566 gst_object_unref (fakesink);
2571 g_mutex_unlock (priv->lock);
2577 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2578 GstPad *sink, FsMediaType media_type, gpointer user_data)
2580 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2581 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2583 gboolean retval = FALSE;
2587 case FS_MEDIA_TYPE_AUDIO:
2588 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2590 g_warning ("Could not add audio source to pipeline");
2594 pad = gst_element_get_static_pad (priv->audio_input, "src");
2597 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2598 g_warning ("Could not get source pad from audio source");
2602 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2604 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2605 g_warning ("Could not link audio source to farsight");
2609 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2611 g_warning ("Could not start audio source");
2612 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2613 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2619 case FS_MEDIA_TYPE_VIDEO:
2620 if (priv->video_tee != NULL)
2622 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2623 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2625 g_warning ("Could not link video source input pipeline");
2628 gst_object_unref (pad);
2634 g_assert_not_reached ();
2641 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2643 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2644 GstElement *preview;
2646 disable_camera (self);
2648 DEBUG ("remove video input");
2649 preview = priv->video_preview_sink;
2651 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2652 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2653 gst_element_set_state (preview, GST_STATE_NULL);
2655 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2658 g_object_unref (priv->video_input);
2659 priv->video_input = NULL;
2660 g_object_unref (priv->video_tee);
2661 priv->video_tee = NULL;
2662 clutter_actor_destroy (priv->video_preview);
2663 priv->video_preview = NULL;
2665 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2669 start_call (EmpathyCallWindow *self)
2671 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2673 priv->call_started = TRUE;
2674 empathy_call_handler_start_call (priv->handler,
2675 gtk_get_current_event_time ());
2677 if (empathy_call_handler_has_initial_video (priv->handler))
2679 TpyCallChannel *call;
2682 g_object_get (priv->handler, "call-channel", &call, NULL);
2683 s = tpy_call_channel_get_video_state (call);
2685 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2686 s == TPY_SENDING_STATE_SENDING)
2688 /* Enable 'send video' buttons and display the preview */
2689 gtk_toggle_tool_button_set_active (
2690 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2694 gtk_toggle_tool_button_set_active (
2695 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2697 if (priv->video_preview == NULL)
2699 create_video_preview (self);
2700 add_video_preview_to_pipeline (self);
2704 g_object_unref (call);
2709 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2712 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2716 empathy_call_handler_bus_message (priv->handler, bus, message);
2718 switch (GST_MESSAGE_TYPE (message))
2720 case GST_MESSAGE_STATE_CHANGED:
2721 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2723 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2724 if (newstate == GST_STATE_PAUSED)
2725 empathy_call_window_setup_video_input (self);
2727 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2728 !priv->call_started)
2730 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2731 if (newstate == GST_STATE_PAUSED)
2733 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2734 priv->pipeline_playing = TRUE;
2736 if (priv->start_call_when_playing)
2741 case GST_MESSAGE_ERROR:
2743 GError *error = NULL;
2744 GstElement *gst_error;
2747 gst_message_parse_error (message, &error, &debug);
2748 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2750 g_message ("Element error: %s -- %s\n", error->message, debug);
2752 if (g_str_has_prefix (gst_element_get_name (gst_error),
2753 VIDEO_INPUT_ERROR_PREFIX))
2755 /* Remove the video input and continue */
2756 if (priv->video_input != NULL)
2757 empathy_call_window_remove_video_input (self);
2758 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2762 empathy_call_window_disconnected (self, TRUE);
2764 g_error_free (error);
2767 case GST_MESSAGE_UNKNOWN:
2768 case GST_MESSAGE_EOS:
2769 case GST_MESSAGE_WARNING:
2770 case GST_MESSAGE_INFO:
2771 case GST_MESSAGE_TAG:
2772 case GST_MESSAGE_BUFFERING:
2773 case GST_MESSAGE_STATE_DIRTY:
2774 case GST_MESSAGE_STEP_DONE:
2775 case GST_MESSAGE_CLOCK_PROVIDE:
2776 case GST_MESSAGE_CLOCK_LOST:
2777 case GST_MESSAGE_NEW_CLOCK:
2778 case GST_MESSAGE_STRUCTURE_CHANGE:
2779 case GST_MESSAGE_STREAM_STATUS:
2780 case GST_MESSAGE_APPLICATION:
2781 case GST_MESSAGE_ELEMENT:
2782 case GST_MESSAGE_SEGMENT_START:
2783 case GST_MESSAGE_SEGMENT_DONE:
2784 case GST_MESSAGE_DURATION:
2785 case GST_MESSAGE_ANY:
2794 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2795 GHashTable *members,
2796 EmpathyCallWindow *self)
2798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2799 GHashTableIter iter;
2800 gpointer key, value;
2801 gboolean held = FALSE;
2803 g_hash_table_iter_init (&iter, members);
2804 while (g_hash_table_iter_next (&iter, &key, &value))
2806 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2808 /* This assumes this is a 1-1 call, otherwise one participant
2809 * putting the call on hold wouldn't mean the call is on hold
2817 priv->call_state = HELD;
2818 else if (priv->call_state == HELD)
2819 priv->call_state = CONNECTED;
2823 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2825 EmpathyCallWindow *self)
2827 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2828 TpyCallChannel *call;
2830 g_object_get (priv->handler, "call-channel", &call, NULL);
2835 tp_g_signal_connect_object (call, "audio-stream-error",
2836 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2837 tp_g_signal_connect_object (call, "video-stream-error",
2838 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2841 tp_g_signal_connect_object (call, "members-changed",
2842 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2844 g_object_unref (call);
2848 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2850 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2851 TpyCallChannel *call;
2854 /* Make the hangup button twice as wide */
2855 width = gtk_widget_get_allocated_width (priv->hangup_button);
2856 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2858 g_signal_connect (priv->handler, "state-changed",
2859 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2860 g_signal_connect (priv->handler, "conference-added",
2861 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2862 g_signal_connect (priv->handler, "conference-removed",
2863 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2864 g_signal_connect (priv->handler, "closed",
2865 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2866 g_signal_connect (priv->handler, "src-pad-added",
2867 G_CALLBACK (empathy_call_window_src_added_cb), window);
2868 g_signal_connect (priv->handler, "sink-pad-added",
2869 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2870 g_signal_connect (priv->handler, "sink-pad-removed",
2871 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2873 g_object_get (priv->handler, "call-channel", &call, NULL);
2876 call_handler_notify_call_cb (priv->handler, NULL, window);
2877 g_object_unref (call);
2881 /* call-channel doesn't exist yet, we'll connect signals once it has been
2883 g_signal_connect (priv->handler, "notify::call-channel",
2884 G_CALLBACK (call_handler_notify_call_cb), window);
2887 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2891 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2892 EmpathyCallWindow *window)
2894 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2896 if (priv->pipeline != NULL)
2898 if (priv->bus_message_source_id != 0)
2900 g_source_remove (priv->bus_message_source_id);
2901 priv->bus_message_source_id = 0;
2904 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2907 if (priv->call_state == CONNECTING)
2908 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2914 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2917 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2919 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2924 gtk_widget_hide (priv->sidebar);
2925 gtk_widget_hide (menu);
2926 gtk_widget_hide (priv->toolbar);
2930 if (priv->sidebar_was_visible_before_fs)
2931 gtk_widget_show (priv->sidebar);
2933 gtk_widget_show (menu);
2934 gtk_widget_show (priv->toolbar);
2936 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2937 priv->original_height_before_fs);
2942 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2944 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2946 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2947 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2948 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2949 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2951 if (priv->video_output != NULL)
2954 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2955 priv->video_output, TRUE, TRUE,
2956 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2963 empathy_call_window_state_event_cb (GtkWidget *widget,
2964 GdkEventWindowState *event, EmpathyCallWindow *window)
2966 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2968 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2969 gboolean set_fullscreen = event->new_window_state &
2970 GDK_WINDOW_STATE_FULLSCREEN;
2974 gboolean sidebar_was_visible;
2975 GtkAllocation allocation;
2976 gint original_width, original_height;
2978 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2979 original_width = allocation.width;
2980 original_height = allocation.height;
2982 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2984 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2985 priv->original_width_before_fs = original_width;
2986 priv->original_height_before_fs = original_height;
2988 if (priv->video_output_motion_handler_id == 0 &&
2989 priv->video_output != NULL)
2991 priv->video_output_motion_handler_id = g_signal_connect (
2992 G_OBJECT (priv->video_container), "motion-notify-event",
2993 G_CALLBACK (empathy_call_window_video_output_motion_notify),
2999 disconnect_video_output_motion_handler (window);
3002 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3004 show_controls (window, set_fullscreen);
3005 show_borders (window, set_fullscreen);
3006 gtk_action_set_stock_id (priv->menu_fullscreen,
3007 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3008 priv->is_fullscreen = set_fullscreen;
3015 empathy_call_window_update_sidebar_buttons (EmpathyCallWindow *window,
3018 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3020 /* Update dialpad button */
3021 g_signal_handlers_block_by_func (priv->dialpad_button,
3022 empathy_call_window_dialpad_cb, window);
3023 gtk_toggle_tool_button_set_active (
3024 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button),
3026 g_signal_handlers_unblock_by_func (priv->dialpad_button,
3027 empathy_call_window_dialpad_cb, window);
3029 /* Update sidebar menu */
3030 g_signal_handlers_block_by_func (priv->menu_sidebar,
3031 empathy_call_window_sidebar_cb, window);
3032 gtk_toggle_action_set_active (
3033 GTK_TOGGLE_ACTION (priv->menu_sidebar),
3034 gtk_widget_get_visible (priv->sidebar));
3035 g_signal_handlers_unblock_by_func (priv->menu_sidebar,
3036 empathy_call_window_sidebar_cb, window);
3040 empathy_call_window_show_sidebar (EmpathyCallWindow *window,
3043 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3044 int w, h, sidebar_width, handle_size;
3045 GtkAllocation allocation;
3047 gboolean dialpad_shown;
3049 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3050 w = allocation.width;
3051 h = allocation.height;
3053 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
3055 gtk_widget_get_preferred_width (priv->sidebar, &sidebar_width, NULL);
3059 gtk_widget_show (priv->sidebar);
3060 w += sidebar_width + handle_size;
3064 w -= sidebar_width + handle_size;
3065 gtk_widget_hide (priv->sidebar);
3069 gtk_window_resize (GTK_WINDOW (window), w, h);
3071 /* Update the 'Dialpad' menu */
3072 page = ev_sidebar_get_current_page (EV_SIDEBAR (priv->sidebar));
3073 dialpad_shown = active && !tp_strdiff (page, "dialpad");
3076 empathy_call_window_update_sidebar_buttons (window, dialpad_shown);
3080 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3083 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3084 TpyCallChannel *call;
3086 priv->sending_video = (state == CAMERA_STATE_ON);
3088 if (state == CAMERA_STATE_ON)
3090 /* When we start sending video, we want to show the video preview by
3092 display_video_preview (window, TRUE);
3096 display_video_preview (window, FALSE);
3099 if (priv->call_state != CONNECTED)
3102 g_object_get (priv->handler, "call-channel", &call, NULL);
3103 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3104 tpy_call_channel_send_video (call, priv->sending_video);
3105 g_object_unref (call);
3109 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3110 EmpathyCallWindow *window)
3112 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3115 active = (gtk_toggle_tool_button_get_active (toggle));
3119 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3121 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3125 /* TODO, Instead of setting the input volume to 0 we should probably
3126 * stop sending but this would cause the audio call to drop if both
3127 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3128 * in the future. GNOME #574574
3130 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3132 gtk_adjustment_set_value (priv->audio_input_adj, 0);
3137 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3138 EmpathyCallWindow *window)
3140 empathy_call_window_show_sidebar (window, FALSE);
3144 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3145 EmpathyCallWindow *window)
3147 empathy_call_window_show_sidebar (window, TRUE);
3151 empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
3153 EmpathyCallWindow *window)
3155 empathy_call_window_update_sidebar_buttons (window,
3156 !tp_strdiff (page, "dialpad"));
3160 empathy_call_window_hangup_cb (gpointer object,
3161 EmpathyCallWindow *window)
3163 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3165 empathy_call_handler_stop_call (priv->handler);
3167 if (empathy_call_window_disconnected (window, FALSE))
3168 gtk_widget_destroy (GTK_WIDGET (window));
3172 empathy_call_window_restart_call (EmpathyCallWindow *window)
3174 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3176 /* Remove error info bars */
3177 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3178 (GtkCallback) gtk_widget_destroy, NULL);
3180 create_video_output_widget (window);
3182 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3183 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3185 /* While the call was disconnected, the input volume might have changed.
3186 * However, since the audio_input source was destroyed, its volume has not
3187 * been updated during that time. That's why we manually update it here */
3188 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3190 priv->outgoing = TRUE;
3191 empathy_call_window_set_state_connecting (window);
3193 if (priv->pipeline_playing)
3194 start_call (window);
3196 /* call will be started when the pipeline is ready */
3197 priv->start_call_when_playing = TRUE;
3199 empathy_call_window_setup_avatars (window, priv->handler);
3201 empathy_call_window_show_hangup_button (window, TRUE);
3205 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3206 EmpathyCallWindow *window)
3208 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3211 active = gtk_toggle_tool_button_get_active (button);
3214 ev_sidebar_set_current_page (EV_SIDEBAR (priv->sidebar), "dialpad");
3216 empathy_call_window_show_sidebar (window, active);
3220 empathy_call_window_sidebar_cb (GtkToggleAction *menu,
3221 EmpathyCallWindow *self)
3223 empathy_call_window_show_sidebar (self,
3224 gtk_toggle_action_get_active (menu));
3228 empathy_call_window_fullscreen_cb (gpointer object,
3229 EmpathyCallWindow *window)
3231 empathy_call_window_fullscreen_toggle (window);
3235 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3237 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3239 if (priv->is_fullscreen)
3240 gtk_window_unfullscreen (GTK_WINDOW (window));
3242 gtk_window_fullscreen (GTK_WINDOW (window));
3246 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3247 GdkEventButton *event, EmpathyCallWindow *window)
3249 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3251 empathy_call_window_video_menu_popup (window, event->button);
3259 empathy_call_window_key_press_cb (GtkWidget *video_output,
3260 GdkEventKey *event, EmpathyCallWindow *window)
3262 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3264 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3266 /* Since we are in fullscreen mode, toggling will bring us back to
3268 empathy_call_window_fullscreen_toggle (window);
3276 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3277 GdkEventMotion *event, EmpathyCallWindow *window)
3279 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3281 if (priv->is_fullscreen)
3283 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3290 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3294 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3296 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3298 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3299 button, gtk_get_current_event_time ());
3300 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3304 empathy_call_window_status_message (EmpathyCallWindow *self,
3307 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3311 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3312 gdouble value, EmpathyCallWindow *window)
3314 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3316 if (priv->audio_output == NULL)
3319 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),