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-gsettings.h>
45 #include <libempathy/empathy-tp-contact-factory.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-ui-utils.h>
50 #include <libempathy-gtk/empathy-sound-manager.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-images.h>
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include <libempathy/empathy-debug.h>
57 #include "empathy-call-window.h"
58 #include "empathy-call-window-fullscreen.h"
59 #include "empathy-call-factory.h"
60 #include "empathy-video-widget.h"
61 #include "empathy-about-dialog.h"
62 #include "empathy-audio-src.h"
63 #include "empathy-audio-sink.h"
64 #include "empathy-video-src.h"
65 #include "empathy-mic-menu.h"
66 #include "empathy-preferences.h"
67 #include "empathy-rounded-actor.h"
69 #define CONTENT_HBOX_BORDER_WIDTH 6
70 #define CONTENT_HBOX_SPACING 3
71 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
73 #define SELF_VIDEO_SECTION_WIDTH 120
74 #define SELF_VIDEO_SECTION_HEIGTH 90
75 #define SELF_VIDEO_SECTION_MARGIN 10
77 #define FLOATING_TOOLBAR_OPACITY 192
78 #define FLOATING_TOOLBAR_WIDTH 280
79 #define FLOATING_TOOLBAR_HEIGHT 36
80 #define FLOATING_TOOLBAR_SPACING 20
82 #define SELF_VIDEO_MARGIN 10
84 /* The avatar's default width and height are set to the same value because we
85 want a square icon. */
86 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
88 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
101 PROP_CALL_HANDLER = 1,
113 CAMERA_STATE_OFF = 0,
119 PREVIEW_POS_TOP_LEFT,
120 PREVIEW_POS_TOP_RIGHT,
121 PREVIEW_POS_BOTTOM_LEFT,
122 PREVIEW_POS_BOTTOM_RIGHT,
125 struct _EmpathyCallWindowPriv
127 gboolean dispose_has_run;
128 EmpathyCallHandler *handler;
130 EmpathyContact *contact;
132 EmpathyCameraMonitor *camera_monitor;
137 GtkUIManager *ui_manager;
138 GtkWidget *errors_vbox;
139 /* widget displays the video received from the remote user. This widget is
140 * alive only during call. */
141 ClutterActor *video_output;
142 ClutterActor *video_preview;
143 ClutterActor *preview_hidden_button;
144 ClutterActor *preview_rectangle1;
145 ClutterActor *preview_rectangle2;
146 ClutterActor *preview_rectangle3;
147 ClutterActor *preview_rectangle4;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *status_label;
153 GtkWidget *hangup_button;
154 GtkWidget *audio_call_button;
155 GtkWidget *video_call_button;
156 GtkWidget *mic_button;
157 GtkWidget *camera_button;
158 GtkWidget *dialpad_button;
160 GtkWidget *bottom_toolbar;
161 ClutterActor *floating_toolbar;
163 GtkAction *menu_fullscreen;
165 ClutterState *transitions;
167 /* The box that contains self and remote avatar and video
168 input/output. When we redial, we destroy and re-create the box */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* We keep a reference on the hbox which contains the main content so we can
173 easilly repack everything when toggling fullscreen */
174 GtkWidget *content_hbox;
176 gulong video_output_motion_handler_id;
177 guint bus_message_source_id;
181 GtkWidget *dtmf_panel;
184 GtkWidget *details_vbox;
185 GtkWidget *vcodec_encoding_label;
186 GtkWidget *acodec_encoding_label;
187 GtkWidget *vcodec_decoding_label;
188 GtkWidget *acodec_decoding_label;
190 GtkWidget *audio_remote_candidate_label;
191 GtkWidget *audio_local_candidate_label;
192 GtkWidget *video_remote_candidate_label;
193 GtkWidget *video_local_candidate_label;
194 GtkWidget *video_remote_candidate_info_img;
195 GtkWidget *video_local_candidate_info_img;
196 GtkWidget *audio_remote_candidate_info_img;
197 GtkWidget *audio_local_candidate_info_img;
199 GstElement *video_input;
200 GstElement *video_preview_sink;
201 GstElement *video_output_sink;
202 GstElement *audio_input;
203 GstElement *audio_output;
204 GstElement *pipeline;
205 GstElement *video_tee;
215 gboolean call_started;
216 gboolean sending_video;
217 CameraState camera_state;
219 EmpathyCallWindowFullscreen *fullscreen;
220 gboolean is_fullscreen;
225 guint inactivity_src;
227 /* Those fields represent the state of the window before it actually was in
229 gboolean dialpad_was_visible_before_fs;
230 gint original_width_before_fs;
231 gint original_height_before_fs;
233 gint x, y, w, h, dialpad_width;
236 /* TRUE if the call should be started when the pipeline is playing */
237 gboolean start_call_when_playing;
238 /* TRUE if we requested to set the pipeline in the playing state */
239 gboolean pipeline_playing;
241 EmpathySoundManager *sound_mgr;
244 EmpathyMicMenu *mic_menu;
247 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
249 static void empathy_call_window_realized_cb (GtkWidget *widget,
250 EmpathyCallWindow *window);
252 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
253 GdkEvent *event, EmpathyCallWindow *window);
255 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
256 GdkEventWindowState *event, EmpathyCallWindow *window);
258 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
261 static void empathy_call_window_mic_toggled_cb (
262 GtkToggleToolButton *toggle, EmpathyCallWindow *window);
264 static void empathy_call_window_hangup_cb (gpointer object,
265 EmpathyCallWindow *window);
267 static void empathy_call_window_fullscreen_cb (gpointer object,
268 EmpathyCallWindow *window);
270 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
272 static gboolean empathy_call_window_video_button_press_cb (
273 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
275 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
276 GdkEventKey *event, EmpathyCallWindow *window);
278 static gboolean empathy_call_window_video_output_motion_notify (
279 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
281 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
284 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
285 EmpathyCallWindow *window);
287 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
289 static void empathy_call_window_status_message (EmpathyCallWindow *window,
292 static gboolean empathy_call_window_bus_message (GstBus *bus,
293 GstMessage *message, gpointer user_data);
296 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
297 gdouble value, EmpathyCallWindow *window);
300 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
303 gtk_widget_set_visible (self->priv->hangup_button, show);
304 gtk_widget_set_visible (self->priv->audio_call_button, !show);
305 gtk_widget_set_visible (self->priv->video_call_button, !show);
309 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
310 EmpathyCallWindow *self)
312 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
313 empathy_call_window_restart_call (self);
317 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
318 EmpathyCallWindow *self)
320 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
321 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
322 empathy_call_window_restart_call (self);
326 dtmf_button_pressed_cb (GtkButton *button, EmpathyCallWindow *window)
328 EmpathyCallWindowPriv *priv = GET_PRIV (window);
329 TpyCallChannel *call;
333 g_object_get (priv->handler, "call-channel", &call, NULL);
335 button_quark = g_quark_from_static_string (EMPATHY_DTMF_BUTTON_ID);
336 event = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (button),
339 tpy_call_channel_dtmf_start_tone (call, event);
341 g_object_unref (call);
345 dtmf_button_released_cb (GtkButton *button, EmpathyCallWindow *window)
347 EmpathyCallWindowPriv *priv = GET_PRIV (window);
348 TpyCallChannel *call;
350 g_object_get (priv->handler, "call-channel", &call, NULL);
352 tpy_call_channel_dtmf_stop_tone (call);
354 g_object_unref (call);
358 empathy_call_window_mic_volume_changed (EmpathyCallWindow *self)
360 EmpathyCallWindowPriv *priv = GET_PRIV (self);
363 volume = g_settings_get_double (priv->settings,
364 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
366 /* Don't store the volume because of muting */
367 if (volume > 0 || gtk_toggle_tool_button_get_active (
368 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
369 priv->volume = volume;
371 /* Ensure that the toggle button is active if the volume is > 0 and inactive
372 * if it's smaller than 0 */
373 if ((volume > 0) != gtk_toggle_tool_button_get_active (
374 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
375 gtk_toggle_tool_button_set_active (
376 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), volume > 0);
378 empathy_audio_src_set_volume (EMPATHY_GST_AUDIO_SRC (priv->audio_input),
383 empathy_call_window_prefs_volume_changed_cb (GSettings *settings,
385 EmpathyCallWindow *self)
387 empathy_call_window_mic_volume_changed (self);
391 empathy_call_window_show_video_output (EmpathyCallWindow *self,
394 if (self->priv->video_output != NULL)
395 g_object_set (self->priv->video_output, "visible", show, NULL);
397 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
399 clutter_actor_raise_top (self->priv->floating_toolbar);
403 create_video_output_widget (EmpathyCallWindow *self)
405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
407 g_assert (priv->video_output == NULL);
408 g_assert (priv->pipeline != NULL);
410 priv->video_output = clutter_texture_new ();
412 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
415 priv->video_output_sink = clutter_gst_video_sink_new (
416 CLUTTER_TEXTURE (priv->video_output));
418 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
421 gtk_widget_add_events (priv->video_container,
422 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
423 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
424 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
428 create_video_input (EmpathyCallWindow *self)
430 EmpathyCallWindowPriv *priv = GET_PRIV (self);
432 g_assert (priv->video_input == NULL);
433 priv->video_input = empathy_video_src_new ();
434 gst_object_ref (priv->video_input);
435 gst_object_sink (priv->video_input);
439 create_audio_input (EmpathyCallWindow *self)
441 EmpathyCallWindowPriv *priv = GET_PRIV (self);
443 g_assert (priv->audio_input == NULL);
444 priv->audio_input = empathy_audio_src_new ();
445 gst_object_ref (priv->audio_input);
446 gst_object_sink (priv->audio_input);
450 add_video_preview_to_pipeline (EmpathyCallWindow *self)
452 EmpathyCallWindowPriv *priv = GET_PRIV (self);
455 g_assert (priv->video_preview != NULL);
456 g_assert (priv->pipeline != NULL);
457 g_assert (priv->video_input != NULL);
458 g_assert (priv->video_tee != NULL);
460 preview = priv->video_preview_sink;
462 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
464 g_warning ("Could not add video input to pipeline");
468 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
470 g_warning ("Could not add video preview to pipeline");
474 if (!gst_element_link (priv->video_input, priv->video_tee))
476 g_warning ("Could not link video input to video tee");
480 if (!gst_element_link (priv->video_tee, preview))
482 g_warning ("Could not link video tee to video preview");
488 empathy_call_window_disable_camera_cb (GtkAction *action,
489 EmpathyCallWindow *self)
491 clutter_actor_destroy (self->priv->preview_hidden_button);
493 gtk_toggle_tool_button_set_active (
494 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
498 empathy_call_window_minimise_camera_cb (GtkAction *action,
499 EmpathyCallWindow *self)
501 clutter_actor_hide (self->priv->video_preview);
502 clutter_actor_show (self->priv->preview_hidden_button);
506 empathy_call_window_maximise_camera_cb (GtkAction *action,
507 EmpathyCallWindow *self)
509 clutter_actor_show (self->priv->video_preview);
510 clutter_actor_hide (self->priv->preview_hidden_button);
514 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
515 EmpathyCallWindow *self)
519 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
521 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
522 0, gtk_get_current_event_time ());
523 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
527 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
528 EmpathyCallWindow *self)
532 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
533 "/preview-hidden-menu");
534 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
535 0, gtk_get_current_event_time ());
536 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
539 static ClutterActor *
540 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
541 ClutterBinAlignment x,
542 ClutterBinAlignment y)
544 ClutterLayoutManager *layout;
545 ClutterActor *rectangle;
548 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
549 CLUTTER_BIN_ALIGNMENT_CENTER);
551 box = clutter_box_new (layout);
553 rectangle = clutter_rectangle_new_with_color (
554 CLUTTER_COLOR_Transparent);
556 clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rectangle),
559 clutter_actor_set_size (box,
560 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_MARGIN,
561 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_MARGIN);
563 clutter_actor_set_size (rectangle,
564 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
566 clutter_container_add_actor (CLUTTER_CONTAINER (box), rectangle);
568 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
571 clutter_actor_hide (rectangle);
577 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
579 self->priv->preview_rectangle1 =
580 empathy_call_window_create_preview_rectangle (self,
581 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
582 self->priv->preview_rectangle2 =
583 empathy_call_window_create_preview_rectangle (self,
584 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
585 self->priv->preview_rectangle3 =
586 empathy_call_window_create_preview_rectangle (self,
587 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
588 self->priv->preview_rectangle4 =
589 empathy_call_window_create_preview_rectangle (self,
590 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
594 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
597 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
598 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
599 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
600 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
604 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
607 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
609 DEBUG ("moving the video preview to %d", pos);
613 case PREVIEW_POS_TOP_LEFT:
614 clutter_bin_layout_set_alignment (layout,
615 self->priv->video_preview,
616 CLUTTER_BIN_ALIGNMENT_START,
617 CLUTTER_BIN_ALIGNMENT_START);
619 case PREVIEW_POS_TOP_RIGHT:
620 clutter_bin_layout_set_alignment (layout,
621 self->priv->video_preview,
622 CLUTTER_BIN_ALIGNMENT_END,
623 CLUTTER_BIN_ALIGNMENT_START);
625 case PREVIEW_POS_BOTTOM_LEFT:
626 clutter_bin_layout_set_alignment (layout,
627 self->priv->video_preview,
628 CLUTTER_BIN_ALIGNMENT_START,
629 CLUTTER_BIN_ALIGNMENT_END);
631 case PREVIEW_POS_BOTTOM_RIGHT:
632 clutter_bin_layout_set_alignment (layout,
633 self->priv->video_preview,
634 CLUTTER_BIN_ALIGNMENT_END,
635 CLUTTER_BIN_ALIGNMENT_END);
638 g_warn_if_reached ();
643 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
647 ClutterModifierType modifiers,
648 EmpathyCallWindow *self)
650 empathy_call_window_show_preview_rectangles (self, TRUE);
653 static PreviewPosition
654 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
659 PreviewPosition pos = PREVIEW_POS_NONE;
661 clutter_actor_get_geometry (self->priv->video_box, &box);
663 if (0 + SELF_VIDEO_MARGIN <= event_x &&
664 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
665 0 + SELF_VIDEO_MARGIN <= event_y &&
666 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
668 pos = PREVIEW_POS_TOP_LEFT;
670 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
671 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
672 0 + SELF_VIDEO_MARGIN <= event_y &&
673 event_y <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGTH))
675 pos = PREVIEW_POS_TOP_RIGHT;
677 else if (0 + SELF_VIDEO_MARGIN <= event_x &&
678 event_x <= (0 + SELF_VIDEO_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
679 box.height - SELF_VIDEO_MARGIN >= event_y &&
680 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
682 pos = PREVIEW_POS_BOTTOM_LEFT;
684 else if (box.width - SELF_VIDEO_MARGIN >= event_x &&
685 event_x >= (box.width - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
686 box.height - SELF_VIDEO_MARGIN >= event_y &&
687 event_y >= (box.height - SELF_VIDEO_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGTH))
689 pos = PREVIEW_POS_BOTTOM_RIGHT;
696 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
700 ClutterModifierType modifiers,
701 EmpathyCallWindow *self)
705 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
707 if (pos != PREVIEW_POS_NONE)
708 empathy_call_window_move_video_preview (self, pos);
710 empathy_call_window_show_preview_rectangles (self, FALSE);
714 create_video_preview (EmpathyCallWindow *self)
716 EmpathyCallWindowPriv *priv = GET_PRIV (self);
717 ClutterLayoutManager *layout, *layout_center;
718 ClutterActor *preview;
721 ClutterAction *action;
724 g_assert (priv->video_preview == NULL);
726 preview = clutter_texture_new ();
727 clutter_actor_set_size (preview,
728 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
729 priv->video_preview_sink = clutter_gst_video_sink_new (
730 CLUTTER_TEXTURE (preview));
732 /* Flip the video preview */
733 clutter_actor_set_rotation (preview,
736 SELF_VIDEO_SECTION_WIDTH * 0.5,
740 /* Add a little offset to the video preview */
741 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
742 CLUTTER_BIN_ALIGNMENT_CENTER);
743 priv->video_preview = clutter_box_new (layout);
744 clutter_actor_set_size (priv->video_preview,
745 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
746 SELF_VIDEO_SECTION_HEIGTH + 2 * SELF_VIDEO_SECTION_MARGIN +
747 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
749 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
750 CLUTTER_BIN_ALIGNMENT_CENTER);
751 box = clutter_box_new (layout_center);
752 clutter_actor_set_size (box,
753 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGTH);
755 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
756 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
758 g_object_set (priv->video_preview_sink,
763 /* Translators: this is an "Info" label. It should be as short
765 button = gtk_button_new_with_label (_("i"));
766 b = gtk_clutter_actor_new_with_contents (button);
768 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout_center),
770 CLUTTER_BIN_ALIGNMENT_END,
771 CLUTTER_BIN_ALIGNMENT_END);
773 g_signal_connect (button, "clicked",
774 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
777 /* Translators: this is an "Info" label. It should be as short
779 button = gtk_button_new_with_label (_("i"));
780 priv->preview_hidden_button =
781 gtk_clutter_actor_new_with_contents (button);
783 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
784 priv->preview_hidden_button,
785 CLUTTER_BIN_ALIGNMENT_START,
786 CLUTTER_BIN_ALIGNMENT_END);
788 clutter_actor_hide (priv->preview_hidden_button);
790 g_signal_connect (button, "clicked",
791 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
794 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
796 CLUTTER_BIN_ALIGNMENT_START,
797 CLUTTER_BIN_ALIGNMENT_END);
799 action = clutter_drag_action_new ();
800 g_signal_connect (action, "drag-begin",
801 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
802 g_signal_connect (action, "drag-end",
803 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
805 clutter_actor_add_action (preview, action);
806 clutter_actor_set_reactive (preview, TRUE);
810 play_camera (EmpathyCallWindow *window,
813 EmpathyCallWindowPriv *priv = GET_PRIV (window);
817 if (priv->video_preview == NULL)
819 create_video_preview (window);
820 add_video_preview_to_pipeline (window);
824 state = GST_STATE_PLAYING;
826 state = GST_STATE_NULL;
828 preview = priv->video_preview_sink;
830 gst_element_set_state (preview, state);
831 gst_element_set_state (priv->video_input, state);
832 gst_element_set_state (priv->video_tee, state);
836 display_video_preview (EmpathyCallWindow *self,
839 EmpathyCallWindowPriv *priv = GET_PRIV (self);
843 /* Display the video preview */
844 DEBUG ("Show video preview");
846 play_camera (self, TRUE);
847 clutter_actor_show (priv->video_preview);
848 clutter_actor_raise_top (priv->floating_toolbar);
852 /* Hide the video preview */
853 DEBUG ("Hide video preview");
855 if (priv->video_preview != NULL)
857 clutter_actor_hide (priv->video_preview);
858 play_camera (self, FALSE);
864 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
866 EmpathyCallWindowPriv *priv = GET_PRIV (window);
868 empathy_call_window_status_message (window, _("Connecting…"));
869 priv->call_state = CONNECTING;
872 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
873 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
877 disable_camera (EmpathyCallWindow *self)
879 EmpathyCallWindowPriv *priv = GET_PRIV (self);
881 if (priv->camera_state == CAMERA_STATE_OFF)
884 DEBUG ("Disable camera");
886 display_video_preview (self, FALSE);
888 if (priv->camera_state == CAMERA_STATE_ON)
889 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
891 priv->camera_state = CAMERA_STATE_OFF;
895 enable_camera (EmpathyCallWindow *self)
897 EmpathyCallWindowPriv *priv = GET_PRIV (self);
899 if (priv->camera_state == CAMERA_STATE_ON)
902 if (priv->video_input == NULL)
904 DEBUG ("Can't enable camera, no input");
908 DEBUG ("Enable camera");
910 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
912 priv->camera_state = CAMERA_STATE_ON;
916 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
917 EmpathyCallWindow *self)
919 if (gtk_toggle_tool_button_get_active (toggle))
920 enable_camera (self);
922 disable_camera (self);
926 create_pipeline (EmpathyCallWindow *self)
928 EmpathyCallWindowPriv *priv = GET_PRIV (self);
931 g_assert (priv->pipeline == NULL);
933 priv->pipeline = gst_pipeline_new (NULL);
934 priv->pipeline_playing = FALSE;
936 priv->video_tee = gst_element_factory_make ("tee", NULL);
937 gst_object_ref (priv->video_tee);
938 gst_object_sink (priv->video_tee);
940 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
942 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
943 priv->bus_message_source_id = gst_bus_add_watch (bus,
944 empathy_call_window_bus_message, self);
946 g_object_unref (bus);
950 empathy_call_window_settings_cb (GtkAction *action,
951 EmpathyCallWindow *self)
953 gchar *args = g_strdup_printf ("-p %s",
954 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
956 empathy_launch_program (BIN_DIR, "empathy", args);
962 empathy_call_window_contents_cb (GtkAction *action,
963 EmpathyCallWindow *self)
965 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
969 empathy_call_window_debug_cb (GtkAction *action,
970 EmpathyCallWindow *self)
972 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
976 empathy_call_window_about_cb (GtkAction *action,
977 EmpathyCallWindow *self)
979 empathy_about_dialog_new (GTK_WINDOW (self));
983 empathy_call_window_toolbar_timeout (gpointer data)
985 EmpathyCallWindow *self = data;
987 clutter_state_set_state (self->priv->transitions, "fade-out");
993 empathy_call_window_motion_notify_cb (GtkWidget *widget,
995 EmpathyCallWindow *self)
997 clutter_state_set_state (self->priv->transitions, "fade-in");
999 if (self->priv->inactivity_src > 0)
1000 g_source_remove (self->priv->inactivity_src);
1002 self->priv->inactivity_src = g_timeout_add_seconds (3,
1003 empathy_call_window_toolbar_timeout, self);
1009 empathy_call_window_configure_event_cb (GtkWidget *widget,
1011 EmpathyCallWindow *self)
1013 GdkWindow *gdk_window;
1014 GdkWindowState window_state;
1016 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1017 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1019 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1020 &self->priv->dialpad_width, NULL);
1022 gdk_window = gtk_widget_get_window (widget);
1023 window_state = gdk_window_get_state (gdk_window);
1024 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1030 empathy_call_window_destroyed_cb (GtkWidget *object,
1031 EmpathyCallWindow *self)
1033 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1035 /* Save the geometry as if the dialpad was hidden. */
1036 empathy_geometry_save_values (GTK_WINDOW (self),
1037 self->priv->x, self->priv->y,
1038 self->priv->w - self->priv->dialpad_width, self->priv->h,
1039 self->priv->maximized);
1044 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1046 ClutterBindConstraint *constraint)
1048 ClutterActorBox allocation;
1050 clutter_actor_get_allocation_box (stage, &allocation);
1052 clutter_bind_constraint_set_offset (constraint,
1053 allocation.y2 - allocation.y1 -
1054 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1058 empathy_call_window_init (EmpathyCallWindow *self)
1060 EmpathyCallWindowPriv *priv;
1062 GtkWidget *top_vbox;
1064 ClutterConstraint *constraint;
1065 ClutterActor *remote_avatar;
1066 GtkStyleContext *context;
1070 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1071 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1073 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1074 gui = empathy_builder_get_file (filename,
1075 "call_window_vbox", &top_vbox,
1076 "errors_vbox", &priv->errors_vbox,
1077 "pane", &priv->pane,
1078 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1079 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1080 "status_label", &priv->status_label,
1081 "audiocall", &priv->audio_call_button,
1082 "videocall", &priv->video_call_button,
1083 "microphone", &priv->mic_button,
1084 "camera", &priv->camera_button,
1085 "hangup", &priv->hangup_button,
1086 "dialpad", &priv->dialpad_button,
1087 "toolbar", &priv->toolbar,
1088 "bottom_toolbar", &priv->bottom_toolbar,
1089 "ui_manager", &priv->ui_manager,
1090 "menufullscreen", &priv->menu_fullscreen,
1091 "details_vbox", &priv->details_vbox,
1092 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1093 "acodec_encoding_label", &priv->acodec_encoding_label,
1094 "acodec_decoding_label", &priv->acodec_decoding_label,
1095 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1096 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1097 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1098 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1099 "video_local_candidate_label", &priv->video_local_candidate_label,
1100 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1101 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1102 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1103 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1107 empathy_builder_connect (gui, self,
1108 "hangup", "clicked", empathy_call_window_hangup_cb,
1109 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1110 "videocall", "clicked", empathy_call_window_video_call_cb,
1111 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1112 "microphone", "toggled", empathy_call_window_mic_toggled_cb,
1113 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1114 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1115 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1116 "menusettings", "activate", empathy_call_window_settings_cb,
1117 "menucontents", "activate", empathy_call_window_contents_cb,
1118 "menudebug", "activate", empathy_call_window_debug_cb,
1119 "menuabout", "activate", empathy_call_window_about_cb,
1120 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1121 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1122 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1125 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1127 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1129 g_object_bind_property (priv->camera_monitor, "available",
1130 priv->camera_button, "sensitive",
1131 G_BINDING_SYNC_CREATE);
1133 priv->lock = g_mutex_new ();
1135 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1137 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1138 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1139 CONTENT_HBOX_BORDER_WIDTH);
1140 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1143 /* avatar/video box */
1144 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1145 CLUTTER_BIN_ALIGNMENT_CENTER);
1147 priv->video_box = clutter_box_new (priv->video_layout);
1149 empathy_call_window_create_preview_rectangles (self);
1151 priv->video_container = gtk_clutter_embed_new ();
1153 /* Set the background color to that of the rest of the window */
1154 context = gtk_widget_get_style_context (priv->content_hbox);
1155 gtk_style_context_get_background_color (context,
1156 GTK_STATE_FLAG_NORMAL, &rgba);
1157 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1158 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1159 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1160 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1161 clutter_stage_set_color (
1162 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1163 GTK_CLUTTER_EMBED (priv->video_container))),
1166 clutter_container_add (
1167 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1168 GTK_CLUTTER_EMBED (priv->video_container))),
1172 constraint = clutter_bind_constraint_new (
1173 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1174 CLUTTER_BIND_SIZE, 0);
1175 clutter_actor_add_constraint (priv->video_box, constraint);
1177 priv->remote_user_avatar_widget = gtk_image_new ();
1178 remote_avatar = gtk_clutter_actor_new_with_contents (
1179 priv->remote_user_avatar_widget);
1181 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1184 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1185 priv->video_container, TRUE, TRUE,
1186 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1188 create_pipeline (self);
1189 create_video_output_widget (self);
1190 create_audio_input (self);
1191 create_video_input (self);
1193 priv->floating_toolbar = empathy_rounded_actor_new ();
1195 gtk_widget_reparent (priv->bottom_toolbar,
1196 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1198 constraint = clutter_bind_constraint_new (
1199 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1202 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1205 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1206 "notify::allocation",
1207 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1210 clutter_actor_set_size (priv->floating_toolbar,
1211 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1212 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1214 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1215 priv->floating_toolbar,
1216 CLUTTER_BIN_ALIGNMENT_CENTER,
1217 CLUTTER_BIN_ALIGNMENT_END);
1219 clutter_actor_raise_top (priv->floating_toolbar);
1221 /* Transitions for the floating toolbar */
1222 priv->transitions = clutter_state_new ();
1224 /* all transitions last for 2s */
1225 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1227 /* transition from any state to "fade-out" state */
1228 clutter_state_set (priv->transitions, NULL, "fade-out",
1229 priv->floating_toolbar,
1230 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1233 /* transition from any state to "fade-in" state */
1234 clutter_state_set (priv->transitions, NULL, "fade-in",
1235 priv->floating_toolbar,
1236 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1239 /* put the actor into the "fade-in" state with no animation */
1240 clutter_state_warp_to_state (priv->transitions, "fade-in");
1242 /* The call will be started as soon the pipeline is playing */
1243 priv->start_call_when_playing = TRUE;
1245 priv->dtmf_panel = empathy_create_dtmf_dialpad (G_OBJECT (self),
1246 G_CALLBACK (dtmf_button_pressed_cb),
1247 G_CALLBACK (dtmf_button_released_cb));
1249 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1252 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1255 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1257 gtk_widget_show_all (top_vbox);
1259 gtk_widget_hide (priv->dtmf_panel);
1260 gtk_widget_hide (priv->details_vbox);
1262 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1264 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1265 priv->video_container);
1267 /* We hide the bottom toolbar after 3s of inactivity and show it
1268 * again on mouse movement */
1269 priv->inactivity_src = g_timeout_add_seconds (3,
1270 empathy_call_window_toolbar_timeout, self);
1272 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1273 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1275 g_signal_connect (G_OBJECT (self), "realize",
1276 G_CALLBACK (empathy_call_window_realized_cb), self);
1278 g_signal_connect (G_OBJECT (self), "delete-event",
1279 G_CALLBACK (empathy_call_window_delete_cb), self);
1281 g_signal_connect (G_OBJECT (self), "window-state-event",
1282 G_CALLBACK (empathy_call_window_state_event_cb), self);
1284 g_signal_connect (G_OBJECT (self), "key-press-event",
1285 G_CALLBACK (empathy_call_window_key_press_cb), self);
1287 g_signal_connect (self, "motion-notify-event",
1288 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1290 priv->timer = g_timer_new ();
1292 g_object_ref (priv->ui_manager);
1293 g_object_unref (gui);
1295 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1296 priv->mic_menu = empathy_mic_menu_new (self);
1298 empathy_call_window_show_hangup_button (self, TRUE);
1300 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1302 /* Retrieve initial volume */
1303 priv->volume = g_settings_get_double (priv->settings,
1304 EMPATHY_PREFS_CALL_SOUND_VOLUME) / 100.0;
1306 g_signal_connect (priv->settings, "changed::"EMPATHY_PREFS_CALL_SOUND_VOLUME,
1307 G_CALLBACK (empathy_call_window_prefs_volume_changed_cb), self);
1309 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1310 /* These signals are used to track the window position and save it
1311 * when the window is destroyed. We need to do this as we don't want
1312 * the window geometry to be saved with the dialpad taken into account. */
1313 g_signal_connect (self, "destroy",
1314 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1315 g_signal_connect (self, "configure-event",
1316 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1317 g_signal_connect (self, "window-state-event",
1318 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1320 /* Don't display labels in both toolbars */
1321 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1324 /* Instead of specifying a width and a height, we specify only one size. That's
1325 because we want a square avatar icon. */
1327 init_contact_avatar_with_size (EmpathyContact *contact,
1328 GtkWidget *image_widget,
1331 GdkPixbuf *pixbuf_avatar = NULL;
1333 if (contact != NULL)
1335 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1339 if (pixbuf_avatar == NULL)
1341 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1342 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1345 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1347 if (pixbuf_avatar != NULL)
1348 g_object_unref (pixbuf_avatar);
1352 set_window_title (EmpathyCallWindow *self)
1354 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1357 if (priv->contact != NULL)
1359 /* translators: Call is a noun and %s is the contact name. This string
1360 * is used in the window title */
1361 tmp = g_strdup_printf (_("Call with %s"),
1362 empathy_contact_get_alias (priv->contact));
1363 gtk_window_set_title (GTK_WINDOW (self), tmp);
1368 g_warning ("Unknown remote contact!");
1373 set_remote_user_name (EmpathyCallWindow *self,
1374 EmpathyContact *contact)
1376 const gchar *alias = empathy_contact_get_alias (contact);
1377 const gchar *status = empathy_contact_get_status (contact);
1380 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1381 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1387 contact_name_changed_cb (EmpathyContact *contact,
1389 EmpathyCallWindow *self)
1391 set_window_title (self);
1392 set_remote_user_name (self, contact);
1396 contact_presence_changed_cb (EmpathyContact *contact,
1398 EmpathyCallWindow *self)
1400 set_remote_user_name (self, contact);
1404 contact_avatar_changed_cb (EmpathyContact *contact,
1406 EmpathyCallWindow *self)
1409 GtkAllocation allocation;
1410 GtkWidget *avatar_widget;
1412 avatar_widget = self->priv->remote_user_avatar_widget;
1414 gtk_widget_get_allocation (avatar_widget, &allocation);
1415 size = allocation.height;
1419 /* the widget is not allocated yet, set a default size */
1420 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1421 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1424 init_contact_avatar_with_size (contact, avatar_widget, size);
1426 avatar_widget = self->priv->remote_user_avatar_toolbar;
1428 gtk_widget_get_allocation (avatar_widget, &allocation);
1429 size = allocation.height;
1433 /* the widget is not allocated yet, set a default size */
1434 size = SMALL_TOOLBAR_SIZE;
1437 init_contact_avatar_with_size (contact, avatar_widget, size);
1441 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1442 EmpathyCallHandler *handler)
1444 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1446 tp_g_signal_connect_object (priv->contact, "notify::name",
1447 G_CALLBACK (contact_name_changed_cb), self, 0);
1448 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1449 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1450 tp_g_signal_connect_object (priv->contact, "notify::presence",
1451 G_CALLBACK (contact_presence_changed_cb), self, 0);
1453 set_window_title (self);
1454 set_remote_user_name (self, priv->contact);
1456 init_contact_avatar_with_size (priv->contact,
1457 priv->remote_user_avatar_widget,
1458 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1459 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1461 init_contact_avatar_with_size (priv->contact,
1462 priv->remote_user_avatar_toolbar,
1463 SMALL_TOOLBAR_SIZE);
1465 /* The remote avatar is shown by default and will be hidden when we receive
1466 video from the remote side. */
1467 clutter_actor_hide (priv->video_output);
1468 gtk_widget_show (priv->remote_user_avatar_widget);
1472 update_send_codec (EmpathyCallWindow *self,
1475 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1482 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1483 widget = priv->acodec_encoding_label;
1487 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1488 widget = priv->vcodec_encoding_label;
1494 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1495 gtk_label_set_text (GTK_LABEL (widget), tmp);
1500 send_audio_codec_notify_cb (GObject *object,
1504 EmpathyCallWindow *self = user_data;
1506 update_send_codec (self, TRUE);
1510 send_video_codec_notify_cb (GObject *object,
1514 EmpathyCallWindow *self = user_data;
1516 update_send_codec (self, FALSE);
1520 update_recv_codec (EmpathyCallWindow *self,
1523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1526 GString *str = NULL;
1530 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
1531 widget = priv->acodec_decoding_label;
1535 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
1536 widget = priv->vcodec_decoding_label;
1542 for (l = codecs; l != NULL; l = g_list_next (l))
1544 FsCodec *codec = l->data;
1547 str = g_string_new (NULL);
1549 g_string_append (str, ", ");
1551 g_string_append_printf (str, "%s/%u", codec->encoding_name,
1555 gtk_label_set_text (GTK_LABEL (widget), str->str);
1556 g_string_free (str, TRUE);
1560 recv_audio_codecs_notify_cb (GObject *object,
1564 EmpathyCallWindow *self = user_data;
1566 update_recv_codec (self, TRUE);
1570 recv_video_codecs_notify_cb (GObject *object,
1574 EmpathyCallWindow *self = user_data;
1576 update_recv_codec (self, FALSE);
1579 static const gchar *
1580 candidate_type_to_str (FsCandidate *candidate)
1582 switch (candidate->type)
1584 case FS_CANDIDATE_TYPE_HOST:
1586 case FS_CANDIDATE_TYPE_SRFLX:
1587 return "server reflexive";
1588 case FS_CANDIDATE_TYPE_PRFLX:
1589 return "peer reflexive";
1590 case FS_CANDIDATE_TYPE_RELAY:
1592 case FS_CANDIDATE_TYPE_MULTICAST:
1599 static const gchar *
1600 candidate_type_to_desc (FsCandidate *candidate)
1602 switch (candidate->type)
1604 case FS_CANDIDATE_TYPE_HOST:
1605 return _("The IP address as seen by the machine");
1606 case FS_CANDIDATE_TYPE_SRFLX:
1607 return _("The IP address as seen by a server on the Internet");
1608 case FS_CANDIDATE_TYPE_PRFLX:
1609 return _("The IP address of the peer as seen by the other side");
1610 case FS_CANDIDATE_TYPE_RELAY:
1611 return _("The IP address of a relay server");
1612 case FS_CANDIDATE_TYPE_MULTICAST:
1613 return _("The IP address of the multicast group");
1620 update_candidat_widget (EmpathyCallWindow *self,
1623 FsCandidate *candidate)
1627 g_assert (candidate != NULL);
1628 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
1629 candidate->port, candidate_type_to_str (candidate));
1631 gtk_label_set_text (GTK_LABEL (label), str);
1632 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
1638 candidates_changed_cb (GObject *object,
1640 EmpathyCallWindow *self)
1642 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1643 FsCandidate *candidate = NULL;
1645 if (type == FS_MEDIA_TYPE_VIDEO)
1647 /* Update remote candidate */
1648 candidate = empathy_call_handler_get_video_remote_candidate (
1651 update_candidat_widget (self, priv->video_remote_candidate_label,
1652 priv->video_remote_candidate_info_img, candidate);
1654 /* Update local candidate */
1655 candidate = empathy_call_handler_get_video_local_candidate (
1658 update_candidat_widget (self, priv->video_local_candidate_label,
1659 priv->video_local_candidate_info_img, candidate);
1663 /* Update remote candidate */
1664 candidate = empathy_call_handler_get_audio_remote_candidate (
1667 update_candidat_widget (self, priv->audio_remote_candidate_label,
1668 priv->audio_remote_candidate_info_img, candidate);
1670 /* Update local candidate */
1671 candidate = empathy_call_handler_get_audio_local_candidate (
1674 update_candidat_widget (self, priv->audio_local_candidate_label,
1675 priv->audio_local_candidate_info_img, candidate);
1680 empathy_call_window_constructed (GObject *object)
1682 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1683 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1684 TpyCallChannel *call;
1686 g_assert (priv->handler != NULL);
1688 g_object_get (priv->handler, "call-channel", &call, NULL);
1689 priv->outgoing = (call == NULL);
1691 g_object_unref (call);
1693 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
1694 g_assert (priv->contact != NULL);
1696 empathy_call_window_setup_avatars (self, priv->handler);
1697 empathy_call_window_set_state_connecting (self);
1699 if (!empathy_call_handler_has_initial_video (priv->handler))
1701 gtk_toggle_tool_button_set_active (
1702 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
1704 /* If call has InitialVideo, the preview will be started once the call has
1705 * been started (start_call()). */
1707 update_send_codec (self, TRUE);
1708 update_send_codec (self, FALSE);
1709 update_recv_codec (self, TRUE);
1710 update_recv_codec (self, FALSE);
1712 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
1713 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
1714 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
1715 G_CALLBACK (send_video_codec_notify_cb), self, 0);
1716 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
1717 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
1718 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
1719 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
1721 tp_g_signal_connect_object (priv->handler, "candidates-changed",
1722 G_CALLBACK (candidates_changed_cb), self, 0);
1725 static void empathy_call_window_dispose (GObject *object);
1726 static void empathy_call_window_finalize (GObject *object);
1729 empathy_call_window_set_property (GObject *object,
1730 guint property_id, const GValue *value, GParamSpec *pspec)
1732 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1734 switch (property_id)
1736 case PROP_CALL_HANDLER:
1737 priv->handler = g_value_dup_object (value);
1740 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1745 empathy_call_window_get_property (GObject *object,
1746 guint property_id, GValue *value, GParamSpec *pspec)
1748 EmpathyCallWindowPriv *priv = GET_PRIV (object);
1750 switch (property_id)
1752 case PROP_CALL_HANDLER:
1753 g_value_set_object (value, priv->handler);
1756 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
1761 empathy_call_window_class_init (
1762 EmpathyCallWindowClass *empathy_call_window_class)
1764 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
1765 GParamSpec *param_spec;
1767 g_type_class_add_private (empathy_call_window_class,
1768 sizeof (EmpathyCallWindowPriv));
1770 object_class->constructed = empathy_call_window_constructed;
1771 object_class->set_property = empathy_call_window_set_property;
1772 object_class->get_property = empathy_call_window_get_property;
1774 object_class->dispose = empathy_call_window_dispose;
1775 object_class->finalize = empathy_call_window_finalize;
1777 param_spec = g_param_spec_object ("handler",
1778 "handler", "The call handler",
1779 EMPATHY_TYPE_CALL_HANDLER,
1780 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
1781 g_object_class_install_property (object_class,
1782 PROP_CALL_HANDLER, param_spec);
1786 empathy_call_window_dispose (GObject *object)
1788 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1789 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1791 if (priv->dispose_has_run)
1794 priv->dispose_has_run = TRUE;
1796 if (priv->handler != NULL)
1798 empathy_call_handler_stop_call (priv->handler);
1799 tp_clear_object (&priv->handler);
1802 if (priv->bus_message_source_id != 0)
1804 g_source_remove (priv->bus_message_source_id);
1805 priv->bus_message_source_id = 0;
1808 if (priv->got_video_src > 0)
1810 g_source_remove (priv->got_video_src);
1811 priv->got_video_src = 0;
1814 if (priv->inactivity_src > 0)
1816 g_source_remove (priv->inactivity_src);
1817 priv->inactivity_src = 0;
1820 tp_clear_object (&priv->pipeline);
1821 tp_clear_object (&priv->video_input);
1822 tp_clear_object (&priv->audio_input);
1823 tp_clear_object (&priv->video_tee);
1824 tp_clear_object (&priv->ui_manager);
1825 tp_clear_object (&priv->fullscreen);
1826 tp_clear_object (&priv->camera_monitor);
1827 tp_clear_object (&priv->settings);
1828 tp_clear_object (&priv->transitions);
1830 g_list_free_full (priv->notifiers, g_object_unref);
1832 if (priv->timer_id != 0)
1833 g_source_remove (priv->timer_id);
1836 if (priv->contact != NULL)
1838 g_signal_handlers_disconnect_by_func (priv->contact,
1839 contact_name_changed_cb, self);
1840 priv->contact = NULL;
1844 tp_clear_object (&priv->sound_mgr);
1846 tp_clear_object (&priv->mic_menu);
1848 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
1852 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
1854 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1856 if (priv->video_output_motion_handler_id != 0)
1858 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
1859 priv->video_output_motion_handler_id);
1860 priv->video_output_motion_handler_id = 0;
1865 empathy_call_window_finalize (GObject *object)
1867 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
1868 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1870 disconnect_video_output_motion_handler (self);
1872 /* free any data held directly by the object here */
1873 g_mutex_free (priv->lock);
1875 g_timer_destroy (priv->timer);
1877 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
1882 empathy_call_window_new (EmpathyCallHandler *handler)
1884 return EMPATHY_CALL_WINDOW (
1885 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
1889 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
1890 GstElement *conference, gpointer user_data)
1892 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1893 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1894 FsElementAddedNotifier *notifier;
1897 DEBUG ("Conference added");
1899 /* Add notifier to set the various element properties as needed */
1900 notifier = fs_element_added_notifier_new ();
1901 keyfile = fs_utils_get_default_element_properties (conference);
1903 if (keyfile != NULL)
1904 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
1906 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
1908 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
1910 gst_bin_add (GST_BIN (priv->pipeline), conference);
1911 gst_element_set_state (conference, GST_STATE_PLAYING);
1915 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
1916 GstElement *conference, gpointer user_data)
1918 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
1919 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1921 gst_bin_remove (GST_BIN (priv->pipeline), conference);
1922 gst_element_set_state (conference, GST_STATE_NULL);
1926 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
1928 GstStateChangeReturn state_change_return;
1929 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1931 if (priv->pipeline == NULL)
1934 if (priv->bus_message_source_id != 0)
1936 g_source_remove (priv->bus_message_source_id);
1937 priv->bus_message_source_id = 0;
1940 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
1942 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
1943 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
1945 if (priv->pipeline != NULL)
1946 g_object_unref (priv->pipeline);
1947 priv->pipeline = NULL;
1949 if (priv->audio_output != NULL)
1950 g_object_unref (priv->audio_output);
1951 priv->audio_output = NULL;
1953 if (priv->video_tee != NULL)
1954 g_object_unref (priv->video_tee);
1955 priv->video_tee = NULL;
1957 if (priv->video_preview != NULL)
1958 clutter_actor_destroy (priv->video_preview);
1959 priv->video_preview = NULL;
1961 priv->funnel = NULL;
1963 create_pipeline (self);
1964 /* Call will be started when user will hit the 'redial' button */
1965 priv->start_call_when_playing = FALSE;
1966 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
1972 g_message ("Error: could not destroy pipeline. Closing call window");
1973 gtk_widget_destroy (GTK_WIDGET (self));
1980 reset_details_pane (EmpathyCallWindow *self)
1982 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1984 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
1985 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
1986 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
1987 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
1991 empathy_call_window_disconnected (EmpathyCallWindow *self,
1994 gboolean could_disconnect = FALSE;
1995 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1996 gboolean could_reset_pipeline;
1998 /* Leave full screen mode if needed */
1999 gtk_window_unfullscreen (GTK_WINDOW (self));
2001 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2002 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2004 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2006 if (priv->call_state == CONNECTING)
2007 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2009 if (priv->call_state != REDIALING)
2010 priv->call_state = DISCONNECTED;
2012 if (could_reset_pipeline)
2014 g_mutex_lock (priv->lock);
2016 g_timer_stop (priv->timer);
2018 if (priv->timer_id != 0)
2019 g_source_remove (priv->timer_id);
2022 g_mutex_unlock (priv->lock);
2025 /* We are about to destroy the window, no need to update it or create
2026 * a video preview */
2029 empathy_call_window_status_message (self, _("Disconnected"));
2031 empathy_call_window_show_hangup_button (self, FALSE);
2033 /* Unsensitive the camera and mic button */
2034 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2035 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2037 /* Be sure that the mic button is enabled */
2038 gtk_toggle_tool_button_set_active (
2039 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2041 if (priv->camera_state == CAMERA_STATE_ON)
2043 /* Restart the preview with the new pipeline. */
2044 display_video_preview (self, TRUE);
2047 /* destroy the video output; it will be recreated when we'll redial */
2048 disconnect_video_output_motion_handler (self);
2049 if (priv->video_output != NULL)
2050 clutter_actor_destroy (priv->video_output);
2051 priv->video_output = NULL;
2052 if (priv->got_video_src > 0)
2054 g_source_remove (priv->got_video_src);
2055 priv->got_video_src = 0;
2058 gtk_widget_show (priv->remote_user_avatar_widget);
2060 reset_details_pane (self);
2062 priv->sending_video = FALSE;
2063 priv->call_started = FALSE;
2065 could_disconnect = TRUE;
2067 /* TODO: display the self avatar of the preview (depends if the "Always
2068 * Show Video Preview" is enabled or not) */
2071 return could_disconnect;
2076 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2079 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2080 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2082 if (empathy_call_window_disconnected (self, TRUE) &&
2083 priv->call_state == REDIALING)
2084 empathy_call_window_restart_call (self);
2088 empathy_call_window_sink_removed_cb (EmpathyCallHandler *handler,
2090 FsMediaType media_type,
2091 EmpathyCallWindow *self)
2093 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2095 DEBUG ("removing content");
2098 * This assumes that there is only one video stream per channel...
2101 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2103 if (priv->funnel != NULL)
2107 output = priv->video_output_sink;
2109 gst_element_set_state (output, GST_STATE_NULL);
2110 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2112 gst_bin_remove (GST_BIN (priv->pipeline), output);
2113 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2114 priv->funnel = NULL;
2118 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2120 if (priv->audio_output != NULL)
2122 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2124 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2125 priv->audio_output = NULL;
2133 /* Called with global lock held */
2135 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2137 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2141 if (priv->funnel == NULL)
2143 output = priv->video_output_sink;
2145 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2149 g_warning ("Could not create fsfunnel");
2153 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2155 gst_object_unref (priv->funnel);
2156 priv->funnel = NULL;
2157 g_warning ("Could not add funnel to pipeline");
2161 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2163 g_warning ("Could not add the video output widget to the pipeline");
2167 if (!gst_element_link (priv->funnel, output))
2169 g_warning ("Could not link output sink to funnel");
2170 goto error_output_added;
2173 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2175 g_warning ("Could not start video sink");
2176 goto error_output_added;
2179 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2181 g_warning ("Could not start funnel");
2182 goto error_output_added;
2186 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2189 g_warning ("Could not get request pad from funnel");
2196 gst_element_set_locked_state (priv->funnel, TRUE);
2197 gst_element_set_locked_state (output, TRUE);
2199 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2200 gst_element_set_state (output, GST_STATE_NULL);
2202 gst_bin_remove (GST_BIN (priv->pipeline), output);
2203 gst_element_set_locked_state (output, FALSE);
2207 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2208 priv->funnel = NULL;
2213 /* Called with global lock held */
2215 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self)
2217 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2219 GstPadTemplate *template;
2221 if (priv->audio_output == NULL)
2223 priv->audio_output = empathy_audio_sink_new ();
2224 g_object_ref_sink (priv->audio_output);
2226 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2228 g_warning ("Could not add audio sink to pipeline");
2229 g_object_unref (priv->audio_output);
2230 goto error_add_output;
2233 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2235 g_warning ("Could not start audio sink");
2240 template = gst_element_class_get_pad_template (
2241 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2243 pad = gst_element_request_pad (priv->audio_output,
2244 template, NULL, NULL);
2248 g_warning ("Could not get sink pad from sink");
2255 gst_element_set_locked_state (priv->audio_output, TRUE);
2256 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2257 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2258 priv->audio_output = NULL;
2266 empathy_call_window_update_timer (gpointer user_data)
2268 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2269 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2270 const gchar *status;
2274 time_ = g_timer_elapsed (priv->timer, NULL);
2276 if (priv->call_state == HELD)
2277 status = _("On hold");
2278 else if (!gtk_toggle_tool_button_get_active (
2279 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2282 status = _("Duration");
2284 /* Translators: 'status - minutes:seconds' the caller has been connected */
2285 str = g_strdup_printf (_("%s — %d:%02dm"),
2287 (int) time_ / 60, (int) time_ % 60);
2288 empathy_call_window_status_message (self, str);
2296 display_error (EmpathyCallWindow *self,
2297 TpyCallChannel *call,
2301 const gchar *details)
2303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2304 GtkWidget *info_bar;
2305 GtkWidget *content_area;
2312 /* Create info bar */
2313 info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
2316 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2318 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2320 /* hbox containing the image and the messages vbox */
2321 hbox = gtk_hbox_new (FALSE, 3);
2322 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2325 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2326 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2328 /* vbox containing the main message and the details expander */
2329 vbox = gtk_vbox_new (FALSE, 3);
2330 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2333 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2335 label = gtk_label_new (NULL);
2336 gtk_label_set_markup (GTK_LABEL (label), txt);
2337 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2338 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2341 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2344 if (details != NULL)
2346 GtkWidget *expander;
2348 expander = gtk_expander_new (_("Technical Details"));
2350 txt = g_strdup_printf ("<i>%s</i>", details);
2352 label = gtk_label_new (NULL);
2353 gtk_label_set_markup (GTK_LABEL (label), txt);
2354 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2355 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2358 gtk_container_add (GTK_CONTAINER (expander), label);
2359 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2362 g_signal_connect (info_bar, "response",
2363 G_CALLBACK (gtk_widget_destroy), NULL);
2365 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2366 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2367 gtk_widget_show_all (info_bar);
2371 media_stream_error_to_txt (EmpathyCallWindow *self,
2372 TpyCallChannel *call,
2374 TpMediaStreamError error)
2376 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2377 const gchar *cm = NULL;
2383 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2385 return g_strdup_printf (
2386 _("%s's software does not understand any of the audio formats "
2387 "supported by your computer"),
2388 empathy_contact_get_alias (priv->contact));
2390 return g_strdup_printf (
2391 _("%s's software does not understand any of the video formats "
2392 "supported by your computer"),
2393 empathy_contact_get_alias (priv->contact));
2395 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
2396 return g_strdup_printf (
2397 _("Can't establish a connection to %s. "
2398 "One of you might be on a network that does not allow "
2399 "direct connections."),
2400 empathy_contact_get_alias (priv->contact));
2402 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
2403 return g_strdup (_("There was a failure on the network"));
2405 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
2407 return g_strdup (_("The audio formats necessary for this call "
2408 "are not installed on your computer"));
2410 return g_strdup (_("The video formats necessary for this call "
2411 "are not installed on your computer"));
2413 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
2414 tp_connection_parse_object_path (
2415 tp_channel_borrow_connection (TP_CHANNEL (call)),
2418 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
2419 "product=Telepathy&component=%s", cm);
2421 result = g_strdup_printf (
2422 _("Something unexpected happened in a Telepathy component. "
2423 "Please <a href=\"%s\">report this bug</a> and attach "
2424 "logs gathered from the 'Debug' window in the Help menu."), url);
2430 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
2431 return g_strdup (_("There was a failure in the call engine"));
2433 case TP_MEDIA_STREAM_ERROR_EOS:
2434 return g_strdup (_("The end of the stream was reached"));
2436 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
2443 empathy_call_window_stream_error (EmpathyCallWindow *self,
2444 TpyCallChannel *call,
2453 desc = media_stream_error_to_txt (self, call, audio, code);
2456 /* No description, use the error message. That's not great as it's not
2457 * localized but it's better than nothing. */
2458 display_error (self, call, icon, title, msg, NULL);
2462 display_error (self, call, icon, title, desc, msg);
2468 empathy_call_window_audio_stream_error (TpyCallChannel *call,
2471 EmpathyCallWindow *self)
2473 empathy_call_window_stream_error (self, call, TRUE, code, msg,
2474 "gnome-stock-mic", _("Can't establish audio stream"));
2478 empathy_call_window_video_stream_error (TpyCallChannel *call,
2481 EmpathyCallWindow *self)
2483 empathy_call_window_stream_error (self, call, FALSE, code, msg,
2484 "camera-web", _("Can't establish video stream"));
2489 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
2491 EmpathyCallWindow *self)
2493 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2494 TpyCallChannel *call;
2495 gboolean can_send_video;
2497 if (state != TPY_CALL_STATE_ACCEPTED)
2500 if (priv->call_state == CONNECTED)
2503 g_timer_start (priv->timer);
2504 priv->call_state = CONNECTED;
2506 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2508 can_send_video = priv->video_input != NULL &&
2509 empathy_contact_can_voip_video (priv->contact) &&
2510 empathy_camera_monitor_get_available (priv->camera_monitor);
2512 g_object_get (priv->handler, "call-channel", &call, NULL);
2514 if (tpy_call_channel_has_dtmf (call))
2515 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
2517 if (priv->video_input == NULL)
2518 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
2520 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
2522 empathy_call_window_show_hangup_button (self, TRUE);
2524 gtk_widget_set_sensitive (priv->mic_button, TRUE);
2526 clutter_actor_hide (priv->video_output);
2527 gtk_widget_show (priv->remote_user_avatar_widget);
2529 g_object_unref (call);
2531 g_mutex_lock (priv->lock);
2533 priv->timer_id = g_timeout_add_seconds (1,
2534 empathy_call_window_update_timer, self);
2536 g_mutex_unlock (priv->lock);
2538 empathy_call_window_update_timer (self);
2540 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
2544 empathy_call_window_show_video_output_cb (gpointer user_data)
2546 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2548 if (self->priv->video_output != NULL)
2550 gtk_widget_hide (self->priv->remote_user_avatar_widget);
2551 clutter_actor_show (self->priv->video_output);
2552 clutter_actor_raise_top (self->priv->floating_toolbar);
2559 empathy_call_window_check_video_cb (gpointer data)
2561 EmpathyCallWindow *self = data;
2563 if (self->priv->got_video)
2565 self->priv->got_video = FALSE;
2569 /* No video in the last N seconds, display the remote avatar */
2570 empathy_call_window_show_video_output (self, FALSE);
2575 /* Called from the streaming thread */
2577 empathy_call_window_video_probe_cb (GstPad *pad,
2578 GstMiniObject *mini_obj,
2579 EmpathyCallWindow *self)
2582 if (GST_IS_EVENT (mini_obj))
2585 if (G_UNLIKELY (!self->priv->got_video))
2587 /* show the remote video */
2588 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2589 empathy_call_window_show_video_output_cb,
2590 g_object_ref (self), g_object_unref);
2592 self->priv->got_video = TRUE;
2598 /* Called from the streaming thread */
2600 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
2601 GstPad *src, guint media_type, gpointer user_data)
2603 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2604 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2605 gboolean retval = FALSE;
2609 g_mutex_lock (priv->lock);
2613 case TP_MEDIA_STREAM_TYPE_AUDIO:
2614 pad = empathy_call_window_get_audio_sink_pad (self);
2616 case TP_MEDIA_STREAM_TYPE_VIDEO:
2617 g_idle_add (empathy_call_window_show_video_output_cb, self);
2618 pad = empathy_call_window_get_video_sink_pad (self);
2620 gst_pad_add_data_probe (src,
2621 G_CALLBACK (empathy_call_window_video_probe_cb), self);
2622 if (priv->got_video_src > 0)
2623 g_source_remove (priv->got_video_src);
2624 priv->got_video_src = g_timeout_add_seconds (5,
2625 empathy_call_window_check_video_cb, self);
2628 g_assert_not_reached ();
2634 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
2635 g_warning ("Could not link %s sink pad",
2636 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
2640 gst_object_unref (pad);
2644 /* If no sink could be linked, try to add fakesink to prevent the whole call
2649 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
2651 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
2653 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
2654 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
2655 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
2657 gst_element_set_locked_state (fakesink, TRUE);
2658 gst_element_set_state (fakesink, GST_STATE_NULL);
2659 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
2663 DEBUG ("Could not link real sink, linked fakesink instead");
2665 gst_object_unref (sinkpad);
2669 gst_object_unref (fakesink);
2674 g_mutex_unlock (priv->lock);
2680 empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
2681 GstPad *sink, FsMediaType media_type, gpointer user_data)
2683 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2684 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2686 gboolean retval = FALSE;
2690 case FS_MEDIA_TYPE_AUDIO:
2691 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
2693 g_warning ("Could not add audio source to pipeline");
2697 pad = gst_element_get_static_pad (priv->audio_input, "src");
2700 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2701 g_warning ("Could not get source pad from audio source");
2705 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2707 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2708 g_warning ("Could not link audio source to farsight");
2712 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2714 g_warning ("Could not start audio source");
2715 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
2716 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
2722 case FS_MEDIA_TYPE_VIDEO:
2723 if (priv->video_tee != NULL)
2725 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
2726 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
2728 g_warning ("Could not link video source input pipeline");
2731 gst_object_unref (pad);
2737 g_assert_not_reached ();
2744 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
2746 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2747 GstElement *preview;
2749 disable_camera (self);
2751 DEBUG ("remove video input");
2752 preview = priv->video_preview_sink;
2754 gst_element_set_state (priv->video_input, GST_STATE_NULL);
2755 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
2756 gst_element_set_state (preview, GST_STATE_NULL);
2758 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
2761 g_object_unref (priv->video_input);
2762 priv->video_input = NULL;
2763 g_object_unref (priv->video_tee);
2764 priv->video_tee = NULL;
2765 clutter_actor_destroy (priv->video_preview);
2766 priv->video_preview = NULL;
2768 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2772 start_call (EmpathyCallWindow *self)
2774 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2776 priv->call_started = TRUE;
2777 empathy_call_handler_start_call (priv->handler,
2778 gtk_get_current_event_time ());
2780 if (empathy_call_handler_has_initial_video (priv->handler))
2782 TpyCallChannel *call;
2785 g_object_get (priv->handler, "call-channel", &call, NULL);
2786 s = tpy_call_channel_get_video_state (call);
2788 if (s == TPY_SENDING_STATE_PENDING_SEND ||
2789 s == TPY_SENDING_STATE_SENDING)
2791 /* Enable 'send video' buttons and display the preview */
2792 gtk_toggle_tool_button_set_active (
2793 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
2797 gtk_toggle_tool_button_set_active (
2798 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2800 if (priv->video_preview == NULL)
2802 create_video_preview (self);
2803 add_video_preview_to_pipeline (self);
2807 g_object_unref (call);
2812 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
2815 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2816 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2819 empathy_call_handler_bus_message (priv->handler, bus, message);
2821 switch (GST_MESSAGE_TYPE (message))
2823 case GST_MESSAGE_STATE_CHANGED:
2824 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
2826 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2828 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
2829 !priv->call_started)
2831 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
2832 if (newstate == GST_STATE_PAUSED)
2834 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2835 priv->pipeline_playing = TRUE;
2837 if (priv->start_call_when_playing)
2842 case GST_MESSAGE_ERROR:
2844 GError *error = NULL;
2845 GstElement *gst_error;
2848 gst_message_parse_error (message, &error, &debug);
2849 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
2851 g_message ("Element error: %s -- %s\n", error->message, debug);
2853 if (g_str_has_prefix (gst_element_get_name (gst_error),
2854 VIDEO_INPUT_ERROR_PREFIX))
2856 /* Remove the video input and continue */
2857 if (priv->video_input != NULL)
2858 empathy_call_window_remove_video_input (self);
2859 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
2863 empathy_call_window_disconnected (self, TRUE);
2865 g_error_free (error);
2868 case GST_MESSAGE_UNKNOWN:
2869 case GST_MESSAGE_EOS:
2870 case GST_MESSAGE_WARNING:
2871 case GST_MESSAGE_INFO:
2872 case GST_MESSAGE_TAG:
2873 case GST_MESSAGE_BUFFERING:
2874 case GST_MESSAGE_STATE_DIRTY:
2875 case GST_MESSAGE_STEP_DONE:
2876 case GST_MESSAGE_CLOCK_PROVIDE:
2877 case GST_MESSAGE_CLOCK_LOST:
2878 case GST_MESSAGE_NEW_CLOCK:
2879 case GST_MESSAGE_STRUCTURE_CHANGE:
2880 case GST_MESSAGE_STREAM_STATUS:
2881 case GST_MESSAGE_APPLICATION:
2882 case GST_MESSAGE_ELEMENT:
2883 case GST_MESSAGE_SEGMENT_START:
2884 case GST_MESSAGE_SEGMENT_DONE:
2885 case GST_MESSAGE_DURATION:
2886 case GST_MESSAGE_ANY:
2895 empathy_call_window_members_changed_cb (TpyCallChannel *call,
2896 GHashTable *members,
2897 EmpathyCallWindow *self)
2899 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2900 GHashTableIter iter;
2901 gpointer key, value;
2902 gboolean held = FALSE;
2904 g_hash_table_iter_init (&iter, members);
2905 while (g_hash_table_iter_next (&iter, &key, &value))
2907 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
2909 /* This assumes this is a 1-1 call, otherwise one participant
2910 * putting the call on hold wouldn't mean the call is on hold
2918 priv->call_state = HELD;
2919 else if (priv->call_state == HELD)
2920 priv->call_state = CONNECTED;
2924 call_handler_notify_call_cb (EmpathyCallHandler *handler,
2926 EmpathyCallWindow *self)
2928 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2929 TpyCallChannel *call;
2931 g_object_get (priv->handler, "call-channel", &call, NULL);
2936 tp_g_signal_connect_object (call, "audio-stream-error",
2937 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
2938 tp_g_signal_connect_object (call, "video-stream-error",
2939 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
2942 tp_g_signal_connect_object (call, "members-changed",
2943 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
2945 g_object_unref (call);
2949 empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
2951 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2952 TpyCallChannel *call;
2955 /* Make the hangup button twice as wide */
2956 width = gtk_widget_get_allocated_width (priv->hangup_button);
2957 gtk_widget_set_size_request (priv->hangup_button, width * 2, -1);
2959 g_signal_connect (priv->handler, "state-changed",
2960 G_CALLBACK (empathy_call_window_state_changed_cb), window);
2961 g_signal_connect (priv->handler, "conference-added",
2962 G_CALLBACK (empathy_call_window_conference_added_cb), window);
2963 g_signal_connect (priv->handler, "conference-removed",
2964 G_CALLBACK (empathy_call_window_conference_removed_cb), window);
2965 g_signal_connect (priv->handler, "closed",
2966 G_CALLBACK (empathy_call_window_channel_closed_cb), window);
2967 g_signal_connect (priv->handler, "src-pad-added",
2968 G_CALLBACK (empathy_call_window_src_added_cb), window);
2969 g_signal_connect (priv->handler, "sink-pad-added",
2970 G_CALLBACK (empathy_call_window_sink_added_cb), window);
2971 g_signal_connect (priv->handler, "sink-pad-removed",
2972 G_CALLBACK (empathy_call_window_sink_removed_cb), window);
2974 g_object_get (priv->handler, "call-channel", &call, NULL);
2977 call_handler_notify_call_cb (priv->handler, NULL, window);
2978 g_object_unref (call);
2982 /* call-channel doesn't exist yet, we'll connect signals once it has been
2984 g_signal_connect (priv->handler, "notify::call-channel",
2985 G_CALLBACK (call_handler_notify_call_cb), window);
2988 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2992 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
2993 EmpathyCallWindow *window)
2995 EmpathyCallWindowPriv *priv = GET_PRIV (window);
2997 if (priv->pipeline != NULL)
2999 if (priv->bus_message_source_id != 0)
3001 g_source_remove (priv->bus_message_source_id);
3002 priv->bus_message_source_id = 0;
3005 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3008 if (priv->call_state == CONNECTING)
3009 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3015 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3018 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3020 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3025 gtk_widget_hide (priv->dtmf_panel);
3026 gtk_widget_hide (menu);
3027 gtk_widget_hide (priv->toolbar);
3031 if (priv->dialpad_was_visible_before_fs)
3032 gtk_widget_show (priv->dtmf_panel);
3034 gtk_widget_show (menu);
3035 gtk_widget_show (priv->toolbar);
3037 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3038 priv->original_height_before_fs);
3043 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3045 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3047 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3048 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3049 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3050 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3052 if (priv->video_output != NULL)
3055 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3056 priv->video_output, TRUE, TRUE,
3057 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3064 empathy_call_window_state_event_cb (GtkWidget *widget,
3065 GdkEventWindowState *event, EmpathyCallWindow *window)
3067 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3069 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3070 gboolean set_fullscreen = event->new_window_state &
3071 GDK_WINDOW_STATE_FULLSCREEN;
3075 gboolean dialpad_was_visible;
3076 GtkAllocation allocation;
3077 gint original_width, original_height;
3079 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3080 original_width = allocation.width;
3081 original_height = allocation.height;
3083 g_object_get (priv->dtmf_panel,
3084 "visible", &dialpad_was_visible,
3087 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3088 priv->original_width_before_fs = original_width;
3089 priv->original_height_before_fs = original_height;
3091 if (priv->video_output_motion_handler_id == 0 &&
3092 priv->video_output != NULL)
3094 priv->video_output_motion_handler_id = g_signal_connect (
3095 G_OBJECT (priv->video_container), "motion-notify-event",
3096 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3102 disconnect_video_output_motion_handler (window);
3105 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3107 show_controls (window, set_fullscreen);
3108 show_borders (window, set_fullscreen);
3109 gtk_action_set_stock_id (priv->menu_fullscreen,
3110 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3111 priv->is_fullscreen = set_fullscreen;
3118 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3121 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3122 int w, h, dialpad_width;
3123 GtkAllocation allocation;
3125 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3126 w = allocation.width;
3127 h = allocation.height;
3129 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3133 gtk_widget_show (priv->dtmf_panel);
3139 gtk_widget_hide (priv->dtmf_panel);
3143 gtk_window_resize (GTK_WINDOW (window), w, h);
3147 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3150 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3151 TpyCallChannel *call;
3153 priv->sending_video = (state == CAMERA_STATE_ON);
3155 if (state == CAMERA_STATE_ON)
3157 /* When we start sending video, we want to show the video preview by
3159 display_video_preview (window, TRUE);
3163 display_video_preview (window, FALSE);
3166 if (priv->call_state != CONNECTED)
3169 g_object_get (priv->handler, "call-channel", &call, NULL);
3170 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3171 tpy_call_channel_send_video (call, priv->sending_video);
3172 g_object_unref (call);
3176 empathy_call_window_mic_toggled_cb (GtkToggleToolButton *toggle,
3177 EmpathyCallWindow *self)
3179 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3182 active = (gtk_toggle_tool_button_get_active (toggle));
3184 /* We don't want the settings callback to react to this change to avoid
3186 g_signal_handlers_block_by_func (priv->settings,
3187 empathy_call_window_prefs_volume_changed_cb, self);
3191 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3192 priv->volume * 100);
3196 /* TODO, Instead of setting the input volume to 0 we should probably
3197 * stop sending but this would cause the audio call to drop if both
3198 * sides mute at the same time on certain CMs AFAIK. Need to revisit this
3199 * in the future. GNOME #574574
3201 g_settings_set_double (priv->settings, EMPATHY_PREFS_CALL_SOUND_VOLUME,
3205 g_signal_handlers_unblock_by_func (priv->settings,
3206 empathy_call_window_prefs_volume_changed_cb, self);
3210 empathy_call_window_hangup_cb (gpointer object,
3211 EmpathyCallWindow *self)
3213 empathy_call_handler_stop_call (self->priv->handler);
3215 empathy_call_window_disconnected (self, TRUE);
3219 empathy_call_window_restart_call (EmpathyCallWindow *window)
3221 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3223 /* Remove error info bars */
3224 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3225 (GtkCallback) gtk_widget_destroy, NULL);
3227 create_video_output_widget (window);
3229 /* While the call was disconnected, the input volume might have changed.
3230 * However, since the audio_input source was destroyed, its volume has not
3231 * been updated during that time. That's why we manually update it here */
3232 empathy_call_window_mic_volume_changed (window);
3234 priv->outgoing = TRUE;
3235 empathy_call_window_set_state_connecting (window);
3237 if (priv->pipeline_playing)
3238 start_call (window);
3240 /* call will be started when the pipeline is ready */
3241 priv->start_call_when_playing = TRUE;
3243 empathy_call_window_setup_avatars (window, priv->handler);
3245 empathy_call_window_show_hangup_button (window, TRUE);
3249 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3250 EmpathyCallWindow *window)
3254 active = gtk_toggle_tool_button_get_active (button);
3256 empathy_call_window_show_dialpad (window, active);
3260 empathy_call_window_fullscreen_cb (gpointer object,
3261 EmpathyCallWindow *window)
3263 empathy_call_window_fullscreen_toggle (window);
3267 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
3269 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3271 if (priv->is_fullscreen)
3272 gtk_window_unfullscreen (GTK_WINDOW (window));
3274 gtk_window_fullscreen (GTK_WINDOW (window));
3278 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
3279 GdkEventButton *event, EmpathyCallWindow *window)
3281 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
3283 empathy_call_window_video_menu_popup (window, event->button);
3291 empathy_call_window_key_press_cb (GtkWidget *video_output,
3292 GdkEventKey *event, EmpathyCallWindow *window)
3294 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3296 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
3298 /* Since we are in fullscreen mode, toggling will bring us back to
3300 empathy_call_window_fullscreen_toggle (window);
3308 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
3309 GdkEventMotion *event, EmpathyCallWindow *window)
3311 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3313 if (priv->is_fullscreen)
3315 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
3317 /* Show the bottom toolbar */
3318 empathy_call_window_motion_notify_cb (NULL, NULL, window);
3325 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
3329 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3331 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3333 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
3334 button, gtk_get_current_event_time ());
3335 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
3339 empathy_call_window_status_message (EmpathyCallWindow *self,
3342 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
3346 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
3347 gdouble value, EmpathyCallWindow *window)
3349 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3351 if (priv->audio_output == NULL)
3354 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3359 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
3361 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3363 return priv->ui_manager;
3366 EmpathyGstAudioSrc *
3367 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
3369 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3371 return (EmpathyGstAudioSrc *) priv->audio_input;