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;
140 GtkAction *menu_sidebar;
141 GtkAction *menu_fullscreen;
143 /* The box that contains self and remote avatar and video
144 input/output. When we redial, we destroy and re-create the box */
145 ClutterActor *video_box;
146 ClutterLayoutManager *video_layout;
148 /* We keep a reference on the hbox which contains the main content so we can
149 easilly repack everything when toggling fullscreen */
150 GtkWidget *content_hbox;
152 gulong video_output_motion_handler_id;
153 guint bus_message_source_id;
156 GtkWidget *volume_scale;
157 GtkWidget *volume_progress_bar;
158 GtkAdjustment *audio_input_adj;
160 GtkWidget *dtmf_panel;
163 GtkWidget *details_vbox;
164 GtkWidget *vcodec_encoding_label;
165 GtkWidget *acodec_encoding_label;
166 GtkWidget *vcodec_decoding_label;
167 GtkWidget *acodec_decoding_label;
169 GtkWidget *audio_remote_candidate_label;
170 GtkWidget *audio_local_candidate_label;
171 GtkWidget *video_remote_candidate_label;
172 GtkWidget *video_local_candidate_label;
173 GtkWidget *video_remote_candidate_info_img;
174 GtkWidget *video_local_candidate_info_img;
175 GtkWidget *audio_remote_candidate_info_img;
176 GtkWidget *audio_local_candidate_info_img;
178 GstElement *video_input;
179 GstElement *video_preview_sink;
180 GstElement *video_output_sink;
181 GstElement *audio_input;
182 GstElement *audio_output;
183 GstElement *pipeline;
184 GstElement *video_tee;
193 GtkWidget *video_contrast;
194 GtkWidget *video_brightness;
195 GtkWidget *video_gamma;
198 gboolean call_started;
199 gboolean sending_video;
200 CameraState camera_state;
202 EmpathyCallWindowFullscreen *fullscreen;
203 gboolean is_fullscreen;
208 /* Those fields represent the state of the window before it actually was in
210 gboolean sidebar_was_visible_before_fs;
211 gint original_width_before_fs;
212 gint original_height_before_fs;
214 gint x, y, w, h, sidebar_width;
217 /* TRUE if the call should be started when the pipeline is playing */
218 gboolean start_call_when_playing;
219 /* TRUE if we requested to set the pipeline in the playing state */
220 gboolean pipeline_playing;
222 EmpathySoundManager *sound_mgr;
225 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
227 static void empathy_call_window_realized_cb (GtkWidget *widget,
228 EmpathyCallWindow *window);
230 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
231 GdkEvent *event, EmpathyCallWindow *window);
233 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
234 GdkEventWindowState *event, EmpathyCallWindow *window);
236 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
239 static void empathy_call_window_mic_toggled_cb (
240 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
242 static void empathy_call_window_sidebar_cb (GtkToggleAction *menu,
243 EmpathyCallWindow *self);
245 static void empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
246 EmpathyCallWindow *window);
248 static void empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
249 EmpathyCallWindow *window);
251 static void empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
253 EmpathyCallWindow *window);
255 static void empathy_call_window_hangup_cb (gpointer object,
256 EmpathyCallWindow *window);
258 static void empathy_call_window_fullscreen_cb (gpointer object,
259 EmpathyCallWindow *window);
261 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
263 static gboolean empathy_call_window_video_button_press_cb (
264 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
266 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
267 GdkEventKey *event, EmpathyCallWindow *window);
269 static gboolean empathy_call_window_video_output_motion_notify (
270 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
272 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
275 static void empathy_call_window_redial_cb (gpointer object,
276 EmpathyCallWindow *window);
278 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
279 EmpathyCallWindow *window);
281 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
283 static void empathy_call_window_status_message (EmpathyCallWindow *window,
286 static gboolean empathy_call_window_bus_message (GstBus *bus,
287 GstMessage *message, gpointer user_data);
290 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
291 gdouble value, EmpathyCallWindow *window);
294 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
297 gtk_widget_set_visible (self->priv->hangup_button, show);
298 gtk_widget_set_visible (self->priv->audio_call_button, !show);
299 gtk_widget_set_visible (self->priv->video_call_button, !show);
303 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
304 EmpathyCallWindow *self)
306 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
307 empathy_call_window_restart_call (self);
311 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
312 EmpathyCallWindow *self)
314 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
315 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
316 empathy_call_window_restart_call (self);
320 empathy_call_window_setup_toolbars (EmpathyCallWindow *self)
322 EmpathyCallWindowPriv *priv = GET_PRIV (self);
323 GtkWidget *volume_button;
324 GtkToolItem *tool_item;
326 /* Add an empty expanded GtkToolItem to the top toolbar */
327 tool_item = gtk_tool_item_new ();
328 gtk_tool_item_set_expand (tool_item, TRUE);
329 gtk_widget_show (GTK_WIDGET (tool_item));
330 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
332 /* Set the remote name */
333 tool_item = gtk_tool_item_new ();
334 priv->remote_user_name_toolbar = gtk_label_new (NULL);
335 gtk_container_add (GTK_CONTAINER (tool_item),
336 priv->remote_user_name_toolbar);
337 gtk_widget_show_all (GTK_WIDGET (tool_item));
338 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
340 /* Add some space between the image and the name */
341 tool_item = gtk_separator_tool_item_new ();
342 gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item),
344 gtk_widget_show (GTK_WIDGET (tool_item));
345 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
347 /* Set the remote avatar */
348 tool_item = gtk_tool_item_new ();
349 priv->remote_user_avatar_toolbar = gtk_image_new ();
350 gtk_container_add (GTK_CONTAINER (tool_item),
351 priv->remote_user_avatar_toolbar);
352 gtk_widget_show_all (GTK_WIDGET (tool_item));
353 gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), tool_item, 0);
355 /* Set the volume button */
356 volume_button = gtk_volume_button_new ();
357 /* FIXME listen to the audiosinks signals and update the button according to
358 * that, for now starting out at 1.0 and assuming only the app changes the
360 gtk_scale_button_set_value (GTK_SCALE_BUTTON (volume_button), 1.0);
361 g_signal_connect (G_OBJECT (volume_button), "value-changed",
362 G_CALLBACK (empathy_call_window_volume_changed_cb), self);
364 gtk_container_add (GTK_CONTAINER (priv->volume_item),
366 gtk_widget_show (GTK_WIDGET (volume_button));
368 /* Add an empty expanded GtkToolItem so the label is at the end */
369 tool_item = gtk_tool_item_new ();
370 gtk_tool_item_set_expand (tool_item, TRUE);
371 gtk_widget_show (GTK_WIDGET (tool_item));
372 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
374 /* Set the status label */
375 tool_item = gtk_tool_item_new ();
376 priv->status_label = gtk_label_new (NULL);
377 gtk_container_add (GTK_CONTAINER (tool_item),
379 gtk_widget_show_all (GTK_WIDGET (tool_item));
380 gtk_toolbar_insert (GTK_TOOLBAR (priv->bottom_toolbar), tool_item, -1);
384 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
386 EmpathyCallWindowPriv *priv = GET_PRIV (window);
387 TpyCallChannel *call;
391 g_object_get (priv->handler, "call-channel", &call, NULL);
393 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
394 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
397 tpy_call_channel_dtmf_start_tone (call, event);
399 g_object_unref (call);
403 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
405 EmpathyCallWindowPriv *priv = GET_PRIV (window);
406 TpyCallChannel *call;
408 g_object_get (priv->handler, "call-channel", &call, NULL);
410 tpy_call_channel_dtmf_stop_tone (call);
412 g_object_unref (call);
416 empathy_call_window_create_video_input_add_slider (EmpathyCallWindow *self,
417 gchar *label_text, GtkWidget *bin)
419 GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
420 GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
421 GtkWidget *label = gtk_label_new (label_text);
423 gtk_widget_set_sensitive (scale, FALSE);
425 gtk_container_add (GTK_CONTAINER (bin), vbox);
427 gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
428 gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
429 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
435 empathy_call_window_video_contrast_changed_cb (GtkAdjustment *adj,
436 EmpathyCallWindow *self)
439 EmpathyCallWindowPriv *priv = GET_PRIV (self);
441 empathy_video_src_set_channel (priv->video_input,
442 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST, gtk_adjustment_get_value (adj));
446 empathy_call_window_video_brightness_changed_cb (GtkAdjustment *adj,
447 EmpathyCallWindow *self)
450 EmpathyCallWindowPriv *priv = GET_PRIV (self);
452 empathy_video_src_set_channel (priv->video_input,
453 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS, gtk_adjustment_get_value (adj));
457 empathy_call_window_video_gamma_changed_cb (GtkAdjustment *adj,
458 EmpathyCallWindow *self)
461 EmpathyCallWindowPriv *priv = GET_PRIV (self);
463 empathy_video_src_set_channel (priv->video_input,
464 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA, gtk_adjustment_get_value (adj));
469 empathy_call_window_create_video_input (EmpathyCallWindow *self)
471 EmpathyCallWindowPriv *priv = GET_PRIV (self);
474 hbox = gtk_hbox_new (TRUE, 3);
476 priv->video_contrast = empathy_call_window_create_video_input_add_slider (
477 self, _("Contrast"), hbox);
479 priv->video_brightness = empathy_call_window_create_video_input_add_slider (
480 self, _("Brightness"), hbox);
482 priv->video_gamma = empathy_call_window_create_video_input_add_slider (
483 self, _("Gamma"), hbox);
489 empathy_call_window_setup_video_input (EmpathyCallWindow *self)
491 EmpathyCallWindowPriv *priv = GET_PRIV (self);
495 supported = empathy_video_src_get_supported_channels (priv->video_input);
497 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_CONTRAST)
499 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_contrast));
501 gtk_adjustment_set_value (adj,
502 empathy_video_src_get_channel (priv->video_input,
503 EMPATHY_GST_VIDEO_SRC_CHANNEL_CONTRAST));
505 g_signal_connect (G_OBJECT (adj), "value-changed",
506 G_CALLBACK (empathy_call_window_video_contrast_changed_cb), self);
508 gtk_widget_set_sensitive (priv->video_contrast, TRUE);
511 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_BRIGHTNESS)
513 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_brightness));
515 gtk_adjustment_set_value (adj,
516 empathy_video_src_get_channel (priv->video_input,
517 EMPATHY_GST_VIDEO_SRC_CHANNEL_BRIGHTNESS));
519 g_signal_connect (G_OBJECT (adj), "value-changed",
520 G_CALLBACK (empathy_call_window_video_brightness_changed_cb), self);
521 gtk_widget_set_sensitive (priv->video_brightness, TRUE);
524 if (supported & EMPATHY_GST_VIDEO_SRC_SUPPORTS_GAMMA)
526 adj = gtk_range_get_adjustment (GTK_RANGE (priv->video_gamma));
528 gtk_adjustment_set_value (adj,
529 empathy_video_src_get_channel (priv->video_input,
530 EMPATHY_GST_VIDEO_SRC_CHANNEL_GAMMA));
532 g_signal_connect (G_OBJECT (adj), "value-changed",
533 G_CALLBACK (empathy_call_window_video_gamma_changed_cb), self);
534 gtk_widget_set_sensitive (priv->video_gamma, TRUE);
539 empathy_call_window_mic_volume_changed_cb (GtkAdjustment *adj,
540 EmpathyCallWindow *self)
542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
545 volume = gtk_adjustment_get_value (adj)/100.0;
547 /* Don't store the volume because of muting */
548 if (volume > 0 || gtk_toggle_tool_button_get_active (
549 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
550 priv->volume = volume;
552 /* Ensure that the toggle button is active if the volume is > 0 and inactive
553 * if it's smaller than 0 */
554 if ((volume > 0) != gtk_toggle_tool_button_get_active (
555 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
556 gtk_toggle_tool_button_set_active (
557 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
559 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
564 empathy_call_window_audio_input_level_changed_cb (EmpathyGstAudioSrc *src,
565 gdouble level, EmpathyCallWindow *window)
568 EmpathyCallWindowPriv *priv = GET_PRIV (window);
570 value = CLAMP (pow (10, level / 20), 0.0, 1.0);
571 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
576 empathy_call_window_create_audio_input (EmpathyCallWindow *self)
578 EmpathyCallWindowPriv *priv = GET_PRIV (self);
579 GtkWidget *hbox, *vbox, *label;
581 hbox = gtk_hbox_new (TRUE, 3);
583 vbox = gtk_vbox_new (FALSE, 3);
584 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
586 priv->volume_scale = gtk_vscale_new_with_range (0, 150, 100);
587 gtk_range_set_inverted (GTK_RANGE (priv->volume_scale), TRUE);
588 label = gtk_label_new (_("Volume"));
590 priv->audio_input_adj = gtk_range_get_adjustment (
591 GTK_RANGE (priv->volume_scale));
592 priv->volume = empathy_audio_src_get_volume (EMPATHY_GST_AUDIO_SRC
593 (priv->audio_input));
594 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
596 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
597 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), self);
599 gtk_box_pack_start (GTK_BOX (vbox), priv->volume_scale, TRUE, TRUE, 3);
600 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
602 priv->volume_progress_bar = gtk_progress_bar_new ();
604 gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->volume_progress_bar),
605 GTK_ORIENTATION_VERTICAL);
607 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (priv->volume_progress_bar),
610 gtk_box_pack_start (GTK_BOX (hbox), priv->volume_progress_bar, FALSE, FALSE,
617 empathy_call_window_show_video_output (EmpathyCallWindow *self,
620 if (self->priv->video_output != NULL)
621 g_object_set (self->priv->video_output, "visible", show, NULL);
623 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
627 create_video_output_widget (EmpathyCallWindow *self)
629 EmpathyCallWindowPriv *priv = GET_PRIV (self);
631 g_assert (priv->video_output == NULL);
632 g_assert (priv->pipeline != NULL);
634 priv->video_output = clutter_texture_new ();
636 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
639 priv->video_output_sink = clutter_gst_video_sink_new (
640 CLUTTER_TEXTURE (priv->video_output));
642 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
645 gtk_widget_add_events (priv->video_container,
646 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
647 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
648 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
652 create_video_input (EmpathyCallWindow *self)
654 EmpathyCallWindowPriv *priv = GET_PRIV (self);
656 g_assert (priv->video_input == NULL);
657 priv->video_input = empathy_video_src_new ();
658 gst_object_ref (priv->video_input);
659 gst_object_sink (priv->video_input);
663 create_audio_input (EmpathyCallWindow *self)
665 EmpathyCallWindowPriv *priv = GET_PRIV (self);
667 g_assert (priv->audio_input == NULL);
668 priv->audio_input = empathy_audio_src_new ();
669 gst_object_ref (priv->audio_input);
670 gst_object_sink (priv->audio_input);
672 tp_g_signal_connect_object (priv->audio_input, "peak-level-changed",
673 G_CALLBACK (empathy_call_window_audio_input_level_changed_cb),
678 add_video_preview_to_pipeline (EmpathyCallWindow *self)
680 EmpathyCallWindowPriv *priv = GET_PRIV (self);
683 g_assert (priv->video_preview != NULL);
684 g_assert (priv->pipeline != NULL);
685 g_assert (priv->video_input != NULL);
686 g_assert (priv->video_tee != NULL);
688 preview = priv->video_preview_sink;
690 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
692 g_warning ("Could not add video input to pipeline");
696 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
698 g_warning ("Could not add video preview to pipeline");
702 if (!gst_element_link (priv->video_input, priv->video_tee))
704 g_warning ("Could not link video input to video tee");
708 if (!gst_element_link (priv->video_tee, preview))
710 g_warning ("Could not link video tee to video preview");
716 empathy_call_window_disable_camera_cb (GtkAction *action,
717 EmpathyCallWindow *self)
719 clutter_actor_destroy (self->priv->preview_hidden_button);
721 gtk_toggle_tool_button_set_active (
722 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
726 empathy_call_window_minimise_camera_cb (GtkAction *action,
727 EmpathyCallWindow *self)
729 clutter_actor_hide (self->priv->video_preview);
730 clutter_actor_show (self->priv->preview_hidden_button);
734 empathy_call_window_maximise_camera_cb (GtkAction *action,
735 EmpathyCallWindow *self)
737 clutter_actor_show (self->priv->video_preview);
738 clutter_actor_hide (self->priv->preview_hidden_button);
742 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
743 EmpathyCallWindow *self)
747 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
749 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
750 0, gtk_get_current_event_time ());
751 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
755 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
756 EmpathyCallWindow *self)
760 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
761 "/preview-hidden-menu");
762 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
763 0, gtk_get_current_event_time ());
764 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
768 create_video_preview (EmpathyCallWindow *self)
770 EmpathyCallWindowPriv *priv = GET_PRIV (self);
771 ClutterLayoutManager *layout, *layout_center;
772 ClutterActor *preview;
777 g_assert (priv->video_preview == NULL);
779 preview = clutter_texture_new ();
780 clutter_actor_set_size (preview,
781 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
782 priv->video_preview_sink = clutter_gst_video_sink_new (
783 CLUTTER_TEXTURE (preview));
785 /* Flip the video preview */
786 clutter_actor_set_rotation (preview,
789 SELF_VIDEO_SECTION_WIDTH * 0.5,
793 /* Add a little offset to the video preview */
794 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
795 CLUTTER_BIN_ALIGNMENT_START);
796 priv->video_preview = clutter_box_new (layout);
797 clutter_actor_set_size (priv->video_preview,
798 SELF_VIDEO_SECTION_WIDTH + 10, SELF_VIDEO_SECTION_HEIGTH + 10);
800 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
801 CLUTTER_BIN_ALIGNMENT_CENTER);
802 box = clutter_box_new (layout_center);
803 clutter_actor_set_size (box,
804 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
806 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
807 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
809 g_object_set (priv->video_preview_sink,
814 /* Translators: this is an "Info" label. It should be as short
816 button = gtk_button_new_with_label (_("i"));
817 b = gtk_clutter_actor_new_with_contents (button);
819 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
821 CLUTTER_BIN_ALIGNMENT_END,
822 CLUTTER_BIN_ALIGNMENT_END);
824 g_signal_connect (button, "clicked",
825 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
828 /* Translators: this is an "Info" label. It should be as short
830 button = gtk_button_new_with_label (_("i"));
831 priv->preview_hidden_button =
832 gtk_clutter_actor_new_with_contents (button);
834 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
835 priv->preview_hidden_button,
836 CLUTTER_BIN_ALIGNMENT_START,
837 CLUTTER_BIN_ALIGNMENT_END);
839 clutter_actor_hide (priv->preview_hidden_button);
841 g_signal_connect (button, "clicked",
842 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
845 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
847 CLUTTER_BIN_ALIGNMENT_START,
848 CLUTTER_BIN_ALIGNMENT_END);
852 play_camera (EmpathyCallWindow *window,
855 EmpathyCallWindowPriv *priv = GET_PRIV (window);
859 if (priv->video_preview == NULL)
861 create_video_preview (window);
862 add_video_preview_to_pipeline (window);
866 state = GST_STATE_PLAYING;
868 state = GST_STATE_NULL;
870 preview = priv->video_preview_sink;
872 gst_element_set_state (preview, state);
873 gst_element_set_state (priv->video_input, state);
874 gst_element_set_state (priv->video_tee, state);
878 display_video_preview (EmpathyCallWindow *self,
881 EmpathyCallWindowPriv *priv = GET_PRIV (self);
885 /* Display the video preview */
886 DEBUG ("Show video preview");
888 play_camera (self, TRUE);
889 clutter_actor_show (priv->video_preview);
893 /* Hide the video preview */
894 DEBUG ("Hide video preview");
896 if (priv->video_preview != NULL)
898 clutter_actor_hide (priv->video_preview);
899 play_camera (self, FALSE);
905 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
907 EmpathyCallWindowPriv *priv = GET_PRIV (window);
909 empathy_call_window_status_message (window, _("Connecting…"));
910 priv->call_state = CONNECTING;
913 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
914 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
918 disable_camera (EmpathyCallWindow *self)
920 EmpathyCallWindowPriv *priv = GET_PRIV (self);
922 if (priv->camera_state == CAMERA_STATE_OFF)
925 DEBUG ("Disable camera");
927 display_video_preview (self, FALSE);
929 if (priv->camera_state == CAMERA_STATE_ON)
930 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
932 priv->camera_state = CAMERA_STATE_OFF;
936 enable_camera (EmpathyCallWindow *self)
938 EmpathyCallWindowPriv *priv = GET_PRIV (self);
940 if (priv->camera_state == CAMERA_STATE_ON)
943 if (priv->video_input == NULL)
945 DEBUG ("Can't enable camera, no input");
949 DEBUG ("Enable camera");
951 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
953 priv->camera_state = CAMERA_STATE_ON;
957 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
958 EmpathyCallWindow *self)
960 if (gtk_toggle_tool_button_get_active (toggle))
961 enable_camera (self);
963 disable_camera (self);
967 create_pipeline (EmpathyCallWindow *self)
969 EmpathyCallWindowPriv *priv = GET_PRIV (self);
972 g_assert (priv->pipeline == NULL);
974 priv->pipeline = gst_pipeline_new (NULL);
975 priv->pipeline_playing = FALSE;
977 priv->video_tee = gst_element_factory_make ("tee", NULL);
978 gst_object_ref (priv->video_tee);
979 gst_object_sink (priv->video_tee);
981 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
983 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
984 priv->bus_message_source_id = gst_bus_add_watch (bus,
985 empathy_call_window_bus_message, self);
987 g_object_unref (bus);
991 empathy_call_window_configure_event_cb (GtkWidget *widget,
993 EmpathyCallWindow *self)
995 GdkWindow *gdk_window;
996 GdkWindowState window_state;
998 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
999 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1001 gtk_widget_get_preferred_width (self->priv->sidebar,
1002 &self->priv->sidebar_width, NULL);
1004 gdk_window = gtk_widget_get_window (widget);
1005 window_state = gdk_window_get_state (gdk_window);
1006 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1012 empathy_call_window_destroyed_cb (GtkWidget *object,
1013 EmpathyCallWindow *self)
1015 if (gtk_widget_get_visible (self->priv->sidebar))
1017 /* Save the geometry as if the sidebar was hidden. */
1018 empathy_geometry_save_values (GTK_WINDOW (self),
1019 self->priv->x, self->priv->y,
1020 self->priv->w - self->priv->sidebar_width, self->priv->h,
1021 self->priv->maximized);
1026 empathy_call_window_init (EmpathyCallWindow *self)
1028 EmpathyCallWindowPriv *priv;
1030 GtkWidget *top_vbox;
1034 ClutterConstraint *size_constraint;
1035 ClutterActor *remote_avatar;
1036 GtkStyleContext *context;
1040 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1041 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1043 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1044 gui = empathy_builder_get_file (filename,
1045 "call_window_vbox", &top_vbox,
1046 "errors_vbox", &priv->errors_vbox,
1047 "pane", &priv->pane,
1048 "audiocall", &priv->audio_call_button,
1049 "videocall", &priv->video_call_button,
1050 "volume", &priv->volume_item,
1051 "microphone", &priv->mic_button,
1052 "camera", &priv->camera_button,
1053 "hangup", &priv->hangup_button,
1054 "dialpad", &priv->dialpad_button,
1055 "toolbar", &priv->toolbar,
1056 "bottom_toolbar", &priv->bottom_toolbar,
1057 "menuredial", &priv->redial,
1058 "menusidebar", &priv->menu_sidebar,
1059 "ui_manager", &priv->ui_manager,
1060 "menufullscreen", &priv->menu_fullscreen,
1061 "details_vbox", &priv->details_vbox,
1062 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1063 "acodec_encoding_label", &priv->acodec_encoding_label,
1064 "acodec_decoding_label", &priv->acodec_decoding_label,
1065 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1066 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1067 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1068 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1069 "video_local_candidate_label", &priv->video_local_candidate_label,
1070 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1071 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1072 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1073 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1077 empathy_builder_connect (gui, self,
1078 "menuhangup", "activate", empathy_call_window_hangup_cb,
1079 "hangup", "clicked", empathy_call_window_hangup_cb,
1080 "menuredial", "activate", empathy_call_window_redial_cb,
1081 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1082 "videocall", "clicked", empathy_call_window_video_call_cb,
1083 "menusidebar", "toggled", empathy_call_window_sidebar_cb,
1084 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1085 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1086 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1087 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1088 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1089 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1090 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1093 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1095 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1097 g_object_bind_property (priv->camera_monitor, "available",
1098 priv->camera_button, "sensitive",
1099 G_BINDING_SYNC_CREATE);
1101 priv->lock = g_mutex_new ();
1103 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1105 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1106 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1107 CONTENT_HBOX_BORDER_WIDTH);
1108 gtk_paned_pack1 (GTK_PANED (priv->pane), priv->content_hbox, TRUE, FALSE);
1110 /* avatar/video box */
1111 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1112 CLUTTER_BIN_ALIGNMENT_CENTER);
1114 priv->video_box = clutter_box_new (priv->video_layout);
1116 priv->video_container = gtk_clutter_embed_new ();
1118 /* Set the background color to that of the rest of the window */
1119 context = gtk_widget_get_style_context (priv->content_hbox);
1120 gtk_style_context_get_background_color (context,
1121 GTK_STATE_FLAG_NORMAL, &rgba);
1122 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1123 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1124 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1125 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1126 clutter_stage_set_color (
1127 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1128 GTK_CLUTTER_EMBED (priv->video_container))),
1131 clutter_container_add (
1132 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1133 GTK_CLUTTER_EMBED (priv->video_container))),
1137 size_constraint = clutter_bind_constraint_new (
1138 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1139 CLUTTER_BIND_SIZE, 0);
1140 clutter_actor_add_constraint (priv->video_box, size_constraint);
1142 priv->remote_user_avatar_widget = gtk_image_new ();
1143 remote_avatar = gtk_clutter_actor_new_with_contents (
1144 priv->remote_user_avatar_widget);
1146 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1149 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1150 priv->video_container, TRUE, TRUE,
1151 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1153 create_pipeline (self);
1154 create_video_output_widget (self);
1155 create_audio_input (self);
1156 create_video_input (self);
1158 /* The call will be started as soon the pipeline is playing */
1159 priv->start_call_when_playing = TRUE;
1161 empathy_call_window_setup_toolbars (self);
1163 priv->sidebar = ev_sidebar_new ();
1164 g_signal_connect (G_OBJECT (priv->sidebar),
1165 "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb), self);
1166 g_signal_connect (G_OBJECT (priv->sidebar),
1167 "show", G_CALLBACK (empathy_call_window_sidebar_shown_cb), self);
1168 g_signal_connect (G_OBJECT (priv->sidebar), "changed",
1169 G_CALLBACK (empathy_call_window_sidebar_changed_cb), self);
1170 gtk_paned_pack2 (GTK_PANED (priv->pane), priv->sidebar, FALSE, FALSE);
1172 page = empathy_call_window_create_audio_input (self);
1173 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "audio-input",
1174 _("Audio input"), page);
1176 page = empathy_call_window_create_video_input (self);
1177 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "video-input",
1178 _("Video input"), page);
1180 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1181 G_CALLBACK (dtmf_button_pressed_cb),
1182 G_CALLBACK (dtmf_button_released_cb));
1183 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "dialpad",
1184 _("Dialpad"), priv->dtmf_panel);
1186 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1188 /* Put the details vbox in a scroll window as it can require a lot of
1189 * horizontal space. */
1190 scroll = gtk_scrolled_window_new (NULL, NULL);
1191 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scroll),
1192 priv->details_vbox);
1194 ev_sidebar_add_page (EV_SIDEBAR (priv->sidebar), "details", _("Details"),
1197 gtk_widget_show_all (top_vbox);
1199 gtk_widget_hide (priv->sidebar);
1201 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1203 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1204 priv->video_container);
1206 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1207 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1209 g_signal_connect (G_OBJECT (self), "realize",
1210 G_CALLBACK (empathy_call_window_realized_cb), self);
1212 g_signal_connect (G_OBJECT (self), "delete-event",
1213 G_CALLBACK (empathy_call_window_delete_cb), self);
1215 g_signal_connect (G_OBJECT (self), "window-state-event",
1216 G_CALLBACK (empathy_call_window_state_event_cb), self);
1218 g_signal_connect (G_OBJECT (self), "key-press-event",
1219 G_CALLBACK (empathy_call_window_key_press_cb), self);
1221 priv->timer = g_timer_new ();
1223 g_object_ref (priv->ui_manager);
1224 g_object_unref (gui);
1226 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1228 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1229 /* These signals are used to track the window position and save it
1230 * when the window is destroyed. We need to do this as we don't want
1231 * the window geometry to be saved with the sidebar taken into account. */
1232 g_signal_connect (self, "destroy",
1233 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1234 g_signal_connect (self, "configure-event",
1235 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1236 g_signal_connect (self, "window-state-event",
1237 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1240 /* Instead of specifying a width and a height, we specify only one size. That's
1241 because we want a square avatar icon. */
1243 init_contact_avatar_with_size (EmpathyContact *contact,
1244 GtkWidget *image_widget,
1247 GdkPixbuf *pixbuf_avatar = NULL;
1249 if (contact != NULL)
1251 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1255 if (pixbuf_avatar == NULL)
1257 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1258 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1261 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1263 if (pixbuf_avatar != NULL)
1264 g_object_unref (pixbuf_avatar);
1268 set_window_title (EmpathyCallWindow *self)
1270 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1273 if (priv->contact != NULL)
1275 /* translators: Call is a noun and %s is the contact name. This string
1276 * is used in the window title */
1277 tmp = g_strdup_printf (_("Call with %s"),
1278 empathy_contact_get_alias (priv->contact));
1279 gtk_window_set_title (GTK_WINDOW (self), tmp);
1284 gtk_window_set_title (GTK_WINDOW (self), _("Call with %d participants"));
1289 set_remote_user_name (EmpathyCallWindow *self,
1290 EmpathyContact *contact)
1292 const gchar *alias = empathy_contact_get_alias (contact);
1293 const gchar *status = empathy_contact_get_status (contact);
1296 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1297 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1303 contact_name_changed_cb (EmpathyContact *contact,
1305 EmpathyCallWindow *self)
1307 set_window_title (self);
1308 set_remote_user_name (self, contact);
1312 contact_presence_changed_cb (EmpathyContact *contact,
1314 EmpathyCallWindow *self)
1316 set_remote_user_name (self, contact);
1320 contact_avatar_changed_cb (EmpathyContact *contact,
1322 EmpathyCallWindow *self)
1325 GtkAllocation allocation;
1326 GtkWidget *avatar_widget;
1328 avatar_widget = self->priv->remote_user_avatar_widget;
1330 gtk_widget_get_allocation (avatar_widget, &allocation);
1331 size = allocation.height;
1335 /* the widget is not allocated yet, set a default size */
1336 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1337 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1340 init_contact_avatar_with_size (contact, avatar_widget, size);
1342 avatar_widget = self->priv->remote_user_avatar_toolbar;
1344 gtk_widget_get_allocation (avatar_widget, &allocation);
1345 size = allocation.height;
1349 /* the widget is not allocated yet, set a default size */
1350 size = SMALL_TOOLBAR_SIZE;
1353 init_contact_avatar_with_size (contact, avatar_widget, size);
1357 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1358 EmpathyCallHandler *handler)
1360 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1362 g_signal_connect (priv->contact, "notify::name",
1363 G_CALLBACK (contact_name_changed_cb), self);
1364 g_signal_connect (priv->contact, "notify::avatar",
1365 G_CALLBACK (contact_avatar_changed_cb), self);
1366 /* FIXME: There's no EmpathyContact::presence yet */
1367 g_signal_connect (priv->contact, "notify::presence",
1368 G_CALLBACK (contact_presence_changed_cb), self);
1370 set_window_title (self);
1371 set_remote_user_name (self, priv->contact);
1373 init_contact_avatar_with_size (priv->contact,
1374 priv->remote_user_avatar_widget,
1375 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1376 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1378 init_contact_avatar_with_size (priv->contact,
1379 priv->remote_user_avatar_toolbar,
1380 SMALL_TOOLBAR_SIZE);
1382 /* The remote avatar is shown by default and will be hidden when we receive
1383 video from the remote side. */
1384 clutter_actor_hide (priv->video_output);
1385 gtk_widget_show (priv->remote_user_avatar_widget);
1389 update_send_codec (EmpathyCallWindow *self,
1392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1399 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1400 widget = priv->acodec_encoding_label;
1404 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1405 widget = priv->vcodec_encoding_label;
1411 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1412 gtk_label_set_text (GTK_LABEL (widget), tmp);
1417 send_audio_codec_notify_cb (GObject *object,
1421 EmpathyCallWindow *self = user_data;
1423 update_send_codec (self, TRUE);
1427 send_video_codec_notify_cb (GObject *object,
1431 EmpathyCallWindow *self = user_data;
1433 update_send_codec (self, FALSE);
1437 update_recv_codec (EmpathyCallWindow *self,
1440 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1443 GString *str = NULL;
1447 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1448 widget = priv->acodec_decoding_label;
1452 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1453 widget = priv->vcodec_decoding_label;
1459 for (l = codecs; l != NULL; l = g_list_next (l))
1461 FsCodec *codec = l->data;
1464 str = g_string_new (NULL);
1466 g_string_append (str, ", ");
1468 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1472 gtk_label_set_text (GTK_LABEL (widget), str->str);
1473 g_string_free (str, TRUE);
1477 recv_audio_codecs_notify_cb (GObject *object,
1481 EmpathyCallWindow *self = user_data;
1483 update_recv_codec (self, TRUE);
1487 recv_video_codecs_notify_cb (GObject *object,
1491 EmpathyCallWindow *self = user_data;
1493 update_recv_codec (self, FALSE);
1496 static const gchar *
1497 candidate_type_to_str (FsCandidate *candidate)
1499 switch (candidate->type)
1501 case FS_CANDIDATE_TYPE_HOST:
1503 case FS_CANDIDATE_TYPE_SRFLX:
1504 return "server reflexive";
1505 case FS_CANDIDATE_TYPE_PRFLX:
1506 return "peer reflexive";
1507 case FS_CANDIDATE_TYPE_RELAY:
1509 case FS_CANDIDATE_TYPE_MULTICAST:
1516 static const gchar *
1517 candidate_type_to_desc (FsCandidate *candidate)
1519 switch (candidate->type)
1521 case FS_CANDIDATE_TYPE_HOST:
1522 return _("The IP address as seen by the machine");
1523 case FS_CANDIDATE_TYPE_SRFLX:
1524 return _("The IP address as seen by a server on the Internet");
1525 case FS_CANDIDATE_TYPE_PRFLX:
1526 return _("The IP address of the peer as seen by the other side");
1527 case FS_CANDIDATE_TYPE_RELAY:
1528 return _("The IP address of a relay server");
1529 case FS_CANDIDATE_TYPE_MULTICAST:
1530 return _("The IP address of the multicast group");
1537 update_candidat_widget (EmpathyCallWindow *self,
1540 FsCandidate *candidate)
1544 g_assert (candidate != NULL);
1545 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1546 candidate->port, candidate_type_to_str (candidate));
1548 gtk_label_set_text (GTK_LABEL (label), str);
1549 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1555 candidates_changed_cb (GObject *object,
1557 EmpathyCallWindow *self)
1559 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1560 FsCandidate *candidate = NULL;
1562 if (type == FS_MEDIA_TYPE_VIDEO)
1564 /* Update remote candidate */
1565 candidate = empathy_call_handler_get_video_remote_candidate (
1568 update_candidat_widget (self, priv->video_remote_candidate_label,
1569 priv->video_remote_candidate_info_img, candidate);
1571 /* Update local candidate */
1572 candidate = empathy_call_handler_get_video_local_candidate (
1575 update_candidat_widget (self, priv->video_local_candidate_label,
1576 priv->video_local_candidate_info_img, candidate);
1580 /* Update remote candidate */
1581 candidate = empathy_call_handler_get_audio_remote_candidate (
1584 update_candidat_widget (self, priv->audio_remote_candidate_label,
1585 priv->audio_remote_candidate_info_img, candidate);
1587 /* Update local candidate */
1588 candidate = empathy_call_handler_get_audio_local_candidate (
1591 update_candidat_widget (self, priv->audio_local_candidate_label,
1592 priv->audio_local_candidate_info_img, candidate);
1597 empathy_call_window_constructed (GObject *object)
1599 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1600 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1601 TpyCallChannel *call;
1603 g_assert (priv->handler != NULL);
1605 g_object_get (priv->handler, "call-channel", &call, NULL);
1606 priv->outgoing = (call == NULL);
1608 g_object_unref (call);
1610 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1611 g_assert (priv->contact != NULL);
1613 empathy_call_window_setup_avatars (self, priv->handler);
1614 empathy_call_window_set_state_connecting (self);
1616 if (!empathy_call_handler_has_initial_video (priv->handler))
1618 gtk_toggle_tool_button_set_active (
1619 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1621 /* If call has InitialVideo, the preview will be started once the call has
1622 * been started (start_call()). */
1624 update_send_codec (self, TRUE);
1625 update_send_codec (self, FALSE);
1626 update_recv_codec (self, TRUE);
1627 update_recv_codec (self, FALSE);
1629 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1630 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1631 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1632 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1633 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1634 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1635 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1636 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1638 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1639 G_CALLBACK (candidates_changed_cb), self, 0);
1642 static void empathy_call_window_dispose (GObject *object);
1643 static void empathy_call_window_finalize (GObject *object);
1646 empathy_call_window_set_property (GObject *object,
1647 guint property_id, const GValue *value, GParamSpec *pspec)
1649 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1651 switch (property_id)
1653 case PROP_CALL_HANDLER:
1654 priv->handler = g_value_dup_object (value);
1657 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1662 empathy_call_window_get_property (GObject *object,
1663 guint property_id, GValue *value, GParamSpec *pspec)
1665 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1667 switch (property_id)
1669 case PROP_CALL_HANDLER:
1670 g_value_set_object (value, priv->handler);
1673 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1678 empathy_call_window_class_init (
1679 EmpathyCallWindowClass *empathy_call_window_class)
1681 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1682 GParamSpec *param_spec;
1684 g_type_class_add_private (empathy_call_window_class,
1685 sizeof (EmpathyCallWindowPriv));
1687 object_class->constructed = empathy_call_window_constructed;
1688 object_class->set_property = empathy_call_window_set_property;
1689 object_class->get_property = empathy_call_window_get_property;
1691 object_class->dispose = empathy_call_window_dispose;
1692 object_class->finalize = empathy_call_window_finalize;
1694 param_spec = g_param_spec_object ("handler",
1695 "handler", "The call handler",
1696 EMPATHY_TYPE_CALL_HANDLER,
1697 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1698 g_object_class_install_property (object_class,
1699 PROP_CALL_HANDLER, param_spec);
1703 empathy_call_window_dispose (GObject *object)
1705 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1706 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1708 if (priv->dispose_has_run)
1711 priv->dispose_has_run = TRUE;
1713 if (priv->handler != NULL)
1715 empathy_call_handler_stop_call (priv->handler);
1716 tp_clear_object (&priv->handler);
1719 if (priv->bus_message_source_id != 0)
1721 g_source_remove (priv->bus_message_source_id);
1722 priv->bus_message_source_id = 0;
1725 if (priv->got_video_src > 0)
1727 g_source_remove (priv->got_video_src);
1728 priv->got_video_src = 0;
1731 tp_clear_object (&priv->pipeline);
1732 tp_clear_object (&priv->video_input);
1733 tp_clear_object (&priv->audio_input);
1734 tp_clear_object (&priv->video_tee);
1735 tp_clear_object (&priv->ui_manager);
1736 tp_clear_object (&priv->fullscreen);
1737 tp_clear_object (&priv->camera_monitor);
1739 g_list_free_full (priv->notifiers, g_object_unref);
1741 if (priv->timer_id != 0)
1742 g_source_remove (priv->timer_id);
1745 if (priv->contact != NULL)
1747 g_signal_handlers_disconnect_by_func (priv->contact,
1748 contact_name_changed_cb, self);
1749 priv->contact = NULL;
1753 tp_clear_object (&priv->sound_mgr);
1755 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1759 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1761 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1763 if (priv->video_output_motion_handler_id != 0)
1765 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1766 priv->video_output_motion_handler_id);
1767 priv->video_output_motion_handler_id = 0;
1772 empathy_call_window_finalize (GObject *object)
1774 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1775 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1777 disconnect_video_output_motion_handler (self);
1779 /* free any data held directly by the object here */
1780 g_mutex_free (priv->lock);
1782 g_timer_destroy (priv->timer);
1784 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1789 empathy_call_window_new (EmpathyCallHandler *handler)
1791 return EMPATHY_CALL_WINDOW (
1792 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1796 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1797 GstElement *conference, gpointer user_data)
1799 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1801 FsElementAddedNotifier *notifier;
1804 DEBUG ("Conference added");
1806 /* Add notifier to set the various element properties as needed */
1807 notifier = fs_element_added_notifier_new ();
1808 keyfile = fs_utils_get_default_element_properties (conference);
1810 if (keyfile != NULL)
1811 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1813 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1815 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1817 gst_bin_add (GST_BIN (priv->pipeline), conference);
1818 gst_element_set_state (conference, GST_STATE_PLAYING);
1822 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1823 GstElement *conference, gpointer user_data)
1825 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1826 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1828 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1829 gst_element_set_state (conference, GST_STATE_NULL);
1833 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1835 GstStateChangeReturn state_change_return;
1836 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1838 if (priv->pipeline == NULL)
1841 if (priv->bus_message_source_id != 0)
1843 g_source_remove (priv->bus_message_source_id);
1844 priv->bus_message_source_id = 0;
1847 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1849 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1850 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1852 if (priv->pipeline != NULL)
1853 g_object_unref (priv->pipeline);
1854 priv->pipeline = NULL;
1856 g_signal_handlers_disconnect_by_func (priv->audio_input_adj,
1857 empathy_call_window_mic_volume_changed_cb, self);
1859 if (priv->audio_output != NULL)
1860 g_object_unref (priv->audio_output);
1861 priv->audio_output = NULL;
1863 if (priv->video_tee != NULL)
1864 g_object_unref (priv->video_tee);
1865 priv->video_tee = NULL;
1867 if (priv->video_preview != NULL)
1868 clutter_actor_destroy (priv->video_preview);
1869 priv->video_preview = NULL;
1871 priv->funnel = NULL;
1873 create_pipeline (self);
1874 /* Call will be started when user will hit the 'redial' button */
1875 priv->start_call_when_playing = FALSE;
1876 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1882 g_message ("Error: could not destroy pipeline. Closing call window");
1883 gtk_widget_destroy (GTK_WIDGET (self));
1890 reset_details_pane (EmpathyCallWindow *self)
1892 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1894 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1895 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1896 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1897 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1901 empathy_call_window_disconnected (EmpathyCallWindow *self,
1904 gboolean could_disconnect = FALSE;
1905 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1906 gboolean could_reset_pipeline;
1908 /* Leave full screen mode if needed */
1909 gtk_window_unfullscreen (GTK_WINDOW (self));
1911 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1912 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1914 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
1916 if (priv->call_state == CONNECTING)
1917 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
1919 if (priv->call_state != REDIALING)
1920 priv->call_state = DISCONNECTED;
1922 if (could_reset_pipeline)
1924 g_mutex_lock (priv->lock);
1926 g_timer_stop (priv->timer);
1928 if (priv->timer_id != 0)
1929 g_source_remove (priv->timer_id);
1932 g_mutex_unlock (priv->lock);
1935 /* We are about to destroy the window, no need to update it or create
1936 * a video preview */
1939 empathy_call_window_status_message (self, _("Disconnected"));
1941 gtk_action_set_sensitive (priv->redial, TRUE);
1942 empathy_call_window_show_hangup_button (self, FALSE);
1944 /* Unsensitive the camera and mic button */
1945 gtk_widget_set_sensitive (priv->camera_button, FALSE);
1946 gtk_widget_set_sensitive (priv->mic_button, FALSE);
1948 /* Be sure that the mic button is enabled */
1949 gtk_toggle_tool_button_set_active (
1950 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
1952 if (priv->camera_state == CAMERA_STATE_ON)
1954 /* Restart the preview with the new pipeline. */
1955 display_video_preview (self, TRUE);
1958 gtk_progress_bar_set_fraction (
1959 GTK_PROGRESS_BAR (priv->volume_progress_bar), 0);
1961 /* destroy the video output; it will be recreated when we'll redial */
1962 disconnect_video_output_motion_handler (self);
1963 if (priv->video_output != NULL)
1964 clutter_actor_destroy (priv->video_output);
1965 priv->video_output = NULL;
1966 if (priv->got_video_src > 0)
1968 g_source_remove (priv->got_video_src);
1969 priv->got_video_src = 0;
1972 gtk_widget_show (priv->remote_user_avatar_widget);
1974 reset_details_pane (self);
1976 priv->sending_video = FALSE;
1977 priv->call_started = FALSE;
1979 could_disconnect = TRUE;
1981 /* TODO: display the self avatar of the preview (depends if the "Always
1982 * Show Video Preview" is enabled or not) */
1985 return could_disconnect;
1990 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
1993 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1994 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1996 if (empathy_call_window_disconnected (self, TRUE) &&
1997 priv->call_state == REDIALING)
1998 empathy_call_window_restart_call (self);
2002 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2004 FsMediaType media_type,
2005 EmpathyCallWindow *self)
2007 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2009 DEBUG ("removing content");
2012 * This assumes that there is only one video stream per channel...
2015 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2017 if (priv->funnel != NULL)
2021 output = priv->video_output_sink;
2023 gst_element_set_state (output, GST_STATE_NULL);
2024 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2026 gst_bin_remove (GST_BIN (priv->pipeline), output);
2027 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2028 priv->funnel = NULL;
2032 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2034 if (priv->audio_output != NULL)
2036 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2038 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2039 priv->audio_output = NULL;
2047 /* Called with global lock held */
2049 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2051 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2055 if (priv->funnel == NULL)
2057 output = priv->video_output_sink;
2059 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2063 g_warning ("Could not create fsfunnel");
2067 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2069 gst_object_unref (priv->funnel);
2070 priv->funnel = NULL;
2071 g_warning ("Could not add funnel to pipeline");
2075 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2077 g_warning ("Could not add the video output widget to the pipeline");
2081 if (!gst_element_link (priv->funnel, output))
2083 g_warning ("Could not link output sink to funnel");
2084 goto error_output_added;
2087 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2089 g_warning ("Could not start video sink");
2090 goto error_output_added;
2093 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2095 g_warning ("Could not start funnel");
2096 goto error_output_added;
2100 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2103 g_warning ("Could not get request pad from funnel");
2110 gst_element_set_locked_state (priv->funnel, TRUE);
2111 gst_element_set_locked_state (output, TRUE);
2113 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2114 gst_element_set_state (output, GST_STATE_NULL);
2116 gst_bin_remove (GST_BIN (priv->pipeline), output);
2117 gst_element_set_locked_state (output, FALSE);
2121 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2122 priv->funnel = NULL;
2127 /* Called with global lock held */
2129 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2131 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2133 GstPadTemplate *template;
2135 if (priv->audio_output == NULL)
2137 priv->audio_output = empathy_audio_sink_new ();
2138 g_object_ref_sink (priv->audio_output);
2140 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2142 g_warning ("Could not add audio sink to pipeline");
2143 g_object_unref (priv->audio_output);
2144 goto error_add_output;
2147 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2149 g_warning ("Could not start audio sink");
2154 template = gst_element_class_get_pad_template (
2155 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2157 pad = gst_element_request_pad (priv->audio_output,
2158 template, NULL, NULL);
2162 g_warning ("Could not get sink pad from sink");
2169 gst_element_set_locked_state (priv->audio_output, TRUE);
2170 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2171 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2172 priv->audio_output = NULL;
2180 empathy_call_window_update_timer (gpointer user_data)
2182 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2183 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2187 time_ = g_timer_elapsed (priv->timer, NULL);
2189 /* Translators: 'status - minutes:seconds' the caller has been connected */
2190 str = g_strdup_printf (_("%s — %d:%02dm"),
2191 priv->call_state == HELD ? _("On hold") : _("Connected"),
2192 (int) time_ / 60, (int) time_ % 60);
2193 empathy_call_window_status_message (self, str);
2201 display_error (EmpathyCallWindow *self,
2202 TpyCallChannel *call,
2206 const gchar *details)
2208 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2209 GtkWidget *info_bar;
2210 GtkWidget *content_area;
2217 /* Create info bar */
2218 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2221 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2223 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2225 /* hbox containing the image and the messages vbox */
2226 hbox = gtk_hbox_new (FALSE, 3);
2227 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2230 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2231 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2233 /* vbox containing the main message and the details expander */
2234 vbox = gtk_vbox_new (FALSE, 3);
2235 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2238 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2240 label = gtk_label_new (NULL);
2241 gtk_label_set_markup (GTK_LABEL (label), txt);
2242 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2243 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2246 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2249 if (details != NULL)
2251 GtkWidget *expander;
2253 expander = gtk_expander_new (_("Technical Details"));
2255 txt = g_strdup_printf ("<i>%s</i>", details);
2257 label = gtk_label_new (NULL);
2258 gtk_label_set_markup (GTK_LABEL (label), txt);
2259 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2260 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2263 gtk_container_add (GTK_CONTAINER (expander), label);
2264 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2267 g_signal_connect (info_bar, "response",
2268 G_CALLBACK (gtk_widget_destroy), NULL);
2270 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2271 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2272 gtk_widget_show_all (info_bar);
2276 media_stream_error_to_txt (EmpathyCallWindow *self,
2277 TpyCallChannel *call,
2279 TpMediaStreamError error)
2281 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2282 const gchar *cm = NULL;
2288 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2290 return g_strdup_printf (
2291 _("%s's software does not understand any of the audio formats "
2292 "supported by your computer"),
2293 empathy_contact_get_alias (priv->contact));
2295 return g_strdup_printf (
2296 _("%s's software does not understand any of the video formats "
2297 "supported by your computer"),
2298 empathy_contact_get_alias (priv->contact));
2300 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2301 return g_strdup_printf (
2302 _("Can't establish a connection to %s. "
2303 "One of you might be on a network that does not allow "
2304 "direct connections."),
2305 empathy_contact_get_alias (priv->contact));
2307 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2308 return g_strdup (_("There was a failure on the network"));
2310 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2312 return g_strdup (_("The audio formats necessary for this call "
2313 "are not installed on your computer"));
2315 return g_strdup (_("The video formats necessary for this call "
2316 "are not installed on your computer"));
2318 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2319 tp_connection_parse_object_path (
2320 tp_channel_borrow_connection (TP_CHANNEL (call)),
2323 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2324 "product=Telepathy&component=%s", cm);
2326 result = g_strdup_printf (
2327 _("Something unexpected happened in a Telepathy component. "
2328 "Please <a href=\"%s\">report this bug</a> and attach "
2329 "logs gathered from the 'Debug' window in the Help menu."), url);
2335 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2336 return g_strdup (_("There was a failure in the call engine"));
2338 case TP_MEDIA_STREAM_ERROR_EOS:
2339 return g_strdup (_("The end of the stream was reached"));
2341 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2348 empathy_call_window_stream_error (EmpathyCallWindow *self,
2349 TpyCallChannel *call,
2358 desc = media_stream_error_to_txt (self, call, audio, code);
2361 /* No description, use the error message. That's not great as it's not
2362 * localized but it's better than nothing. */
2363 display_error (self, call, icon, title, msg, NULL);
2367 display_error (self, call, icon, title, desc, msg);
2373 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2376 EmpathyCallWindow *self)
2378 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2379 "gnome-stock-mic", _("Can't establish audio stream"));
2383 empathy_call_window_video_stream_error (TpyCallChannel *call,
2386 EmpathyCallWindow *self)
2388 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2389 "camera-web", _("Can't establish video stream"));
2394 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2396 EmpathyCallWindow *self)
2398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2399 TpyCallChannel *call;
2400 gboolean can_send_video;
2402 if (state != TPY_CALL_STATE_ACCEPTED)
2405 if (priv->call_state == CONNECTED)
2408 g_timer_start (priv->timer);
2409 priv->call_state = CONNECTED;
2411 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2413 can_send_video = priv->video_input != NULL &&
2414 empathy_contact_can_voip_video (priv->contact) &&
2415 empathy_camera_monitor_get_available (priv->camera_monitor);
2417 g_object_get (priv->handler, "call-channel", &call, NULL);
2419 if (tpy_call_channel_has_dtmf (call))
2420 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2422 if (priv->video_input == NULL)
2423 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2425 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2427 gtk_action_set_sensitive (priv->redial, FALSE);
2428 empathy_call_window_show_hangup_button (self, TRUE);
2430 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2432 clutter_actor_hide (priv->video_output);
2433 gtk_widget_show (priv->remote_user_avatar_widget);
2435 g_object_unref (call);
2437 g_mutex_lock (priv->lock);
2439 priv->timer_id = g_timeout_add_seconds (1,
2440 empathy_call_window_update_timer, self);
2442 g_mutex_unlock (priv->lock);
2444 empathy_call_window_update_timer (self);
2446 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2450 empathy_call_window_show_video_output_cb (gpointer user_data)
2452 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2454 if (self->priv->video_output != NULL)
2456 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2457 clutter_actor_show (self->priv->video_output);
2464 empathy_call_window_check_video_cb (gpointer data)
2466 EmpathyCallWindow *self = data;
2468 if (self->priv->got_video)
2470 self->priv->got_video = FALSE;
2474 /* No video in the last N seconds, display the remote avatar */
2475 empathy_call_window_show_video_output (self, FALSE);
2480 /* Called from the streaming thread */
2482 empathy_call_window_video_probe_cb (GstPad *pad,
2483 GstMiniObject *mini_obj,
2484 EmpathyCallWindow *self)
2487 if (GST_IS_EVENT (mini_obj))
2490 if (G_UNLIKELY (!self->priv->got_video))
2492 /* show the remote video */
2493 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2494 empathy_call_window_show_video_output_cb,
2495 g_object_ref (self), g_object_unref);
2497 self->priv->got_video = TRUE;
2503 /* Called from the streaming thread */
2505 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2506 GstPad *src, guint media_type, gpointer user_data)
2508 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2509 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2510 gboolean retval = FALSE;
2514 g_mutex_lock (priv->lock);
2518 case TP_MEDIA_STREAM_TYPE_AUDIO:
2519 pad = empathy_call_window_get_audio_sink_pad (self);
2521 case TP_MEDIA_STREAM_TYPE_VIDEO:
2522 g_idle_add (empathy_call_window_show_video_output_cb, self);
2523 pad = empathy_call_window_get_video_sink_pad (self);
2525 gst_pad_add_data_probe (src,
2526 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2527 if (priv->got_video_src > 0)
2528 g_source_remove (priv->got_video_src);
2529 priv->got_video_src = g_timeout_add_seconds (5,
2530 empathy_call_window_check_video_cb, self);
2533 g_assert_not_reached ();
2539 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2540 g_warning ("Could not link %s sink pad",
2541 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2545 gst_object_unref (pad);
2549 /* If no sink could be linked, try to add fakesink to prevent the whole call
2554 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2556 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2558 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2559 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2560 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2562 gst_element_set_locked_state (fakesink, TRUE);
2563 gst_element_set_state (fakesink, GST_STATE_NULL);
2564 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2568 DEBUG ("Could not link real sink, linked fakesink instead");
2570 gst_object_unref (sinkpad);
2574 gst_object_unref (fakesink);
2579 g_mutex_unlock (priv->lock);
2585 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2586 GstPad *sink, FsMediaType media_type, gpointer user_data)
2588 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2591 gboolean retval = FALSE;
2595 case FS_MEDIA_TYPE_AUDIO:
2596 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2598 g_warning ("Could not add audio source to pipeline");
2602 pad = gst_element_get_static_pad (priv->audio_input, "src");
2605 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2606 g_warning ("Could not get source pad from audio source");
2610 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2612 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2613 g_warning ("Could not link audio source to farsight");
2617 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2619 g_warning ("Could not start audio source");
2620 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2621 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2627 case FS_MEDIA_TYPE_VIDEO:
2628 if (priv->video_tee != NULL)
2630 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2631 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2633 g_warning ("Could not link video source input pipeline");
2636 gst_object_unref (pad);
2642 g_assert_not_reached ();
2649 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2651 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2652 GstElement *preview;
2654 disable_camera (self);
2656 DEBUG ("remove video input");
2657 preview = priv->video_preview_sink;
2659 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2660 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2661 gst_element_set_state (preview, GST_STATE_NULL);
2663 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2666 g_object_unref (priv->video_input);
2667 priv->video_input = NULL;
2668 g_object_unref (priv->video_tee);
2669 priv->video_tee = NULL;
2670 clutter_actor_destroy (priv->video_preview);
2671 priv->video_preview = NULL;
2673 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2677 start_call (EmpathyCallWindow *self)
2679 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2681 priv->call_started = TRUE;
2682 empathy_call_handler_start_call (priv->handler,
2683 gtk_get_current_event_time ());
2685 if (empathy_call_handler_has_initial_video (priv->handler))
2687 TpyCallChannel *call;
2690 g_object_get (priv->handler, "call-channel", &call, NULL);
2691 s = tpy_call_channel_get_video_state (call);
2693 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2694 s == TPY_SENDING_STATE_SENDING)
2696 /* Enable 'send video' buttons and display the preview */
2697 gtk_toggle_tool_button_set_active (
2698 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2702 gtk_toggle_tool_button_set_active (
2703 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2705 if (priv->video_preview == NULL)
2707 create_video_preview (self);
2708 add_video_preview_to_pipeline (self);
2712 g_object_unref (call);
2717 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2720 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2721 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2724 empathy_call_handler_bus_message (priv->handler, bus, message);
2726 switch (GST_MESSAGE_TYPE (message))
2728 case GST_MESSAGE_STATE_CHANGED:
2729 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2731 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2732 if (newstate == GST_STATE_PAUSED)
2733 empathy_call_window_setup_video_input (self);
2735 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2736 !priv->call_started)
2738 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2739 if (newstate == GST_STATE_PAUSED)
2741 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2742 priv->pipeline_playing = TRUE;
2744 if (priv->start_call_when_playing)
2749 case GST_MESSAGE_ERROR:
2751 GError *error = NULL;
2752 GstElement *gst_error;
2755 gst_message_parse_error (message, &error, &debug);
2756 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2758 g_message ("Element error: %s -- %s\n", error->message, debug);
2760 if (g_str_has_prefix (gst_element_get_name (gst_error),
2761 VIDEO_INPUT_ERROR_PREFIX))
2763 /* Remove the video input and continue */
2764 if (priv->video_input != NULL)
2765 empathy_call_window_remove_video_input (self);
2766 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2770 empathy_call_window_disconnected (self, TRUE);
2772 g_error_free (error);
2775 case GST_MESSAGE_UNKNOWN:
2776 case GST_MESSAGE_EOS:
2777 case GST_MESSAGE_WARNING:
2778 case GST_MESSAGE_INFO:
2779 case GST_MESSAGE_TAG:
2780 case GST_MESSAGE_BUFFERING:
2781 case GST_MESSAGE_STATE_DIRTY:
2782 case GST_MESSAGE_STEP_DONE:
2783 case GST_MESSAGE_CLOCK_PROVIDE:
2784 case GST_MESSAGE_CLOCK_LOST:
2785 case GST_MESSAGE_NEW_CLOCK:
2786 case GST_MESSAGE_STRUCTURE_CHANGE:
2787 case GST_MESSAGE_STREAM_STATUS:
2788 case GST_MESSAGE_APPLICATION:
2789 case GST_MESSAGE_ELEMENT:
2790 case GST_MESSAGE_SEGMENT_START:
2791 case GST_MESSAGE_SEGMENT_DONE:
2792 case GST_MESSAGE_DURATION:
2793 case GST_MESSAGE_ANY:
2802 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2803 GHashTable *members,
2804 EmpathyCallWindow *self)
2806 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2807 GHashTableIter iter;
2808 gpointer key, value;
2809 gboolean held = FALSE;
2811 g_hash_table_iter_init (&iter, members);
2812 while (g_hash_table_iter_next (&iter, &key, &value))
2814 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2816 /* This assumes this is a 1-1 call, otherwise one participant
2817 * putting the call on hold wouldn't mean the call is on hold
2825 priv->call_state = HELD;
2826 else if (priv->call_state == HELD)
2827 priv->call_state = CONNECTED;
2831 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2833 EmpathyCallWindow *self)
2835 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2836 TpyCallChannel *call;
2838 g_object_get (priv->handler, "call-channel", &call, NULL);
2843 tp_g_signal_connect_object (call, "audio-stream-error",
2844 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2845 tp_g_signal_connect_object (call, "video-stream-error",
2846 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2849 tp_g_signal_connect_object (call, "members-changed",
2850 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2852 g_object_unref (call);
2856 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2858 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2859 TpyCallChannel *call;
2862 /* Make the hangup button twice as wide */
2863 width = gtk_widget_get_allocated_width (priv->hangup_button);
2864 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2866 g_signal_connect (priv->handler, "state-changed",
2867 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2868 g_signal_connect (priv->handler, "conference-added",
2869 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2870 g_signal_connect (priv->handler, "conference-removed",
2871 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2872 g_signal_connect (priv->handler, "closed",
2873 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2874 g_signal_connect (priv->handler, "src-pad-added",
2875 G_CALLBACK (empathy_call_window_src_added_cb), window);
2876 g_signal_connect (priv->handler, "sink-pad-added",
2877 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2878 g_signal_connect (priv->handler, "sink-pad-removed",
2879 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2881 g_object_get (priv->handler, "call-channel", &call, NULL);
2884 call_handler_notify_call_cb (priv->handler, NULL, window);
2885 g_object_unref (call);
2889 /* call-channel doesn't exist yet, we'll connect signals once it has been
2891 g_signal_connect (priv->handler, "notify::call-channel",
2892 G_CALLBACK (call_handler_notify_call_cb), window);
2895 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2899 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2900 EmpathyCallWindow *window)
2902 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2904 if (priv->pipeline != NULL)
2906 if (priv->bus_message_source_id != 0)
2908 g_source_remove (priv->bus_message_source_id);
2909 priv->bus_message_source_id = 0;
2912 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2915 if (priv->call_state == CONNECTING)
2916 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2922 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
2925 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2927 menu = gtk_ui_manager_get_widget (priv->ui_manager,
2932 gtk_widget_hide (priv->sidebar);
2933 gtk_widget_hide (menu);
2934 gtk_widget_hide (priv->toolbar);
2938 if (priv->sidebar_was_visible_before_fs)
2939 gtk_widget_show (priv->sidebar);
2941 gtk_widget_show (menu);
2942 gtk_widget_show (priv->toolbar);
2944 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
2945 priv->original_height_before_fs);
2950 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
2952 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2954 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
2955 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
2956 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
2957 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
2959 if (priv->video_output != NULL)
2962 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
2963 priv->video_output, TRUE, TRUE,
2964 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
2971 empathy_call_window_state_event_cb (GtkWidget *widget,
2972 GdkEventWindowState *event, EmpathyCallWindow *window)
2974 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
2976 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2977 gboolean set_fullscreen = event->new_window_state &
2978 GDK_WINDOW_STATE_FULLSCREEN;
2982 gboolean sidebar_was_visible;
2983 GtkAllocation allocation;
2984 gint original_width, original_height;
2986 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
2987 original_width = allocation.width;
2988 original_height = allocation.height;
2990 g_object_get (priv->sidebar, "visible", &sidebar_was_visible, NULL);
2992 priv->sidebar_was_visible_before_fs = sidebar_was_visible;
2993 priv->original_width_before_fs = original_width;
2994 priv->original_height_before_fs = original_height;
2996 if (priv->video_output_motion_handler_id == 0 &&
2997 priv->video_output != NULL)
2999 priv->video_output_motion_handler_id = g_signal_connect (
3000 G_OBJECT (priv->video_container), "motion-notify-event",
3001 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3007 disconnect_video_output_motion_handler (window);
3010 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3012 show_controls (window, set_fullscreen);
3013 show_borders (window, set_fullscreen);
3014 gtk_action_set_stock_id (priv->menu_fullscreen,
3015 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3016 priv->is_fullscreen = set_fullscreen;
3023 empathy_call_window_update_sidebar_buttons (EmpathyCallWindow *window,
3026 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3028 /* Update dialpad button */
3029 g_signal_handlers_block_by_func (priv->dialpad_button,
3030 empathy_call_window_dialpad_cb, window);
3031 gtk_toggle_tool_button_set_active (
3032 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button),
3034 g_signal_handlers_unblock_by_func (priv->dialpad_button,
3035 empathy_call_window_dialpad_cb, window);
3037 /* Update sidebar menu */
3038 g_signal_handlers_block_by_func (priv->menu_sidebar,
3039 empathy_call_window_sidebar_cb, window);
3040 gtk_toggle_action_set_active (
3041 GTK_TOGGLE_ACTION (priv->menu_sidebar),
3042 gtk_widget_get_visible (priv->sidebar));
3043 g_signal_handlers_unblock_by_func (priv->menu_sidebar,
3044 empathy_call_window_sidebar_cb, window);
3048 empathy_call_window_show_sidebar (EmpathyCallWindow *window,
3051 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3052 int w, h, sidebar_width, handle_size;
3053 GtkAllocation allocation;
3055 gboolean dialpad_shown;
3057 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3058 w = allocation.width;
3059 h = allocation.height;
3061 gtk_widget_style_get (priv->pane, "handle_size", &handle_size, NULL);
3063 gtk_widget_get_preferred_width (priv->sidebar, &sidebar_width, NULL);
3067 gtk_widget_show (priv->sidebar);
3068 w += sidebar_width + handle_size;
3072 w -= sidebar_width + handle_size;
3073 gtk_widget_hide (priv->sidebar);
3077 gtk_window_resize (GTK_WINDOW (window), w, h);
3079 /* Update the 'Dialpad' menu */
3080 page = ev_sidebar_get_current_page (EV_SIDEBAR (priv->sidebar));
3081 dialpad_shown = active && !tp_strdiff (page, "dialpad");
3084 empathy_call_window_update_sidebar_buttons (window, dialpad_shown);
3088 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3091 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3092 TpyCallChannel *call;
3094 priv->sending_video = (state == CAMERA_STATE_ON);
3096 if (state == CAMERA_STATE_ON)
3098 /* When we start sending video, we want to show the video preview by
3100 display_video_preview (window, TRUE);
3104 display_video_preview (window, FALSE);
3107 if (priv->call_state != CONNECTED)
3110 g_object_get (priv->handler, "call-channel", &call, NULL);
3111 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3112 tpy_call_channel_send_video (call, priv->sending_video);
3113 g_object_unref (call);
3117 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3118 EmpathyCallWindow *window)
3120 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3123 active = (gtk_toggle_tool_button_get_active (toggle));
3127 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3129 gtk_adjustment_set_value (priv->audio_input_adj, priv->volume * 100);
3133 /* TODO, Instead of setting the input volume to 0 we should probably
3134 * stop sending but this would cause the audio call to drop if both
3135 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3136 * in the future. GNOME #574574
3138 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3140 gtk_adjustment_set_value (priv->audio_input_adj, 0);
3145 empathy_call_window_sidebar_hidden_cb (EvSidebar *sidebar,
3146 EmpathyCallWindow *window)
3148 empathy_call_window_show_sidebar (window, FALSE);
3152 empathy_call_window_sidebar_shown_cb (EvSidebar *sidebar,
3153 EmpathyCallWindow *window)
3155 empathy_call_window_show_sidebar (window, TRUE);
3159 empathy_call_window_sidebar_changed_cb (EvSidebar *sidebar,
3161 EmpathyCallWindow *window)
3163 empathy_call_window_update_sidebar_buttons (window,
3164 !tp_strdiff (page, "dialpad"));
3168 empathy_call_window_hangup_cb (gpointer object,
3169 EmpathyCallWindow *window)
3171 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3173 empathy_call_handler_stop_call (priv->handler);
3175 if (empathy_call_window_disconnected (window, FALSE))
3176 gtk_widget_destroy (GTK_WIDGET (window));
3180 empathy_call_window_restart_call (EmpathyCallWindow *window)
3182 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3184 /* Remove error info bars */
3185 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3186 (GtkCallback) gtk_widget_destroy, NULL);
3188 create_video_output_widget (window);
3190 g_signal_connect (G_OBJECT (priv->audio_input_adj), "value-changed",
3191 G_CALLBACK (empathy_call_window_mic_volume_changed_cb), window);
3193 /* While the call was disconnected, the input volume might have changed.
3194 * However, since the audio_input source was destroyed, its volume has not
3195 * been updated during that time. That's why we manually update it here */
3196 empathy_call_window_mic_volume_changed_cb (priv->audio_input_adj, window);
3198 priv->outgoing = TRUE;
3199 empathy_call_window_set_state_connecting (window);
3201 if (priv->pipeline_playing)
3202 start_call (window);
3204 /* call will be started when the pipeline is ready */
3205 priv->start_call_when_playing = TRUE;
3207 empathy_call_window_setup_avatars (window, priv->handler);
3209 gtk_action_set_sensitive (priv->redial, FALSE);
3210 empathy_call_window_show_hangup_button (window, TRUE);
3214 empathy_call_window_redial_cb (gpointer object,
3215 EmpathyCallWindow *window)
3217 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3219 if (priv->call_state == CONNECTED)
3220 priv->call_state = REDIALING;
3222 empathy_call_handler_stop_call (priv->handler);
3224 if (priv->call_state != CONNECTED)
3225 empathy_call_window_restart_call (window);
3229 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3230 EmpathyCallWindow *window)
3232 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3235 active = gtk_toggle_tool_button_get_active (button);
3238 ev_sidebar_set_current_page (EV_SIDEBAR (priv->sidebar), "dialpad");
3240 empathy_call_window_show_sidebar (window, active);
3244 empathy_call_window_sidebar_cb (GtkToggleAction *menu,
3245 EmpathyCallWindow *self)
3247 empathy_call_window_show_sidebar (self,
3248 gtk_toggle_action_get_active (menu));
3252 empathy_call_window_fullscreen_cb (gpointer object,
3253 EmpathyCallWindow *window)
3255 empathy_call_window_fullscreen_toggle (window);
3259 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3261 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3263 if (priv->is_fullscreen)
3264 gtk_window_unfullscreen (GTK_WINDOW (window));
3266 gtk_window_fullscreen (GTK_WINDOW (window));
3270 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3271 GdkEventButton *event, EmpathyCallWindow *window)
3273 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3275 empathy_call_window_video_menu_popup (window, event->button);
3283 empathy_call_window_key_press_cb (GtkWidget *video_output,
3284 GdkEventKey *event, EmpathyCallWindow *window)
3286 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3288 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3290 /* Since we are in fullscreen mode, toggling will bring us back to
3292 empathy_call_window_fullscreen_toggle (window);
3300 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3301 GdkEventMotion *event, EmpathyCallWindow *window)
3303 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3305 if (priv->is_fullscreen)
3307 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3314 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3318 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3320 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3322 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3323 button, gtk_get_current_event_time ());
3324 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3328 empathy_call_window_status_message (EmpathyCallWindow *self,
3331 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3335 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3336 gdouble value, EmpathyCallWindow *window)
3338 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3340 if (priv->audio_output == NULL)
3343 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),