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
22 #include "empathy-call-window.h"
24 #include <glib/gi18n.h>
25 #include <telepathy-farstream/telepathy-farstream.h>
26 #include <farstream/fs-element-added-notifier.h>
27 #include <farstream/fs-utils.h>
28 #include <tp-account-widgets/tpaw-builder.h>
29 #include <tp-account-widgets/tpaw-camera-monitor.h>
30 #include <tp-account-widgets/tpaw-images.h>
32 #include "empathy-about-dialog.h"
33 #include "empathy-audio-sink.h"
34 #include "empathy-call-utils.h"
35 #include "empathy-call-window-fullscreen.h"
36 #include "empathy-camera-menu.h"
37 #include "empathy-dialpad-widget.h"
38 #include "empathy-geometry.h"
39 #include "empathy-gsettings.h"
40 #include "empathy-images.h"
41 #include "empathy-mic-menu.h"
42 #include "empathy-preferences.h"
43 #include "empathy-request-util.h"
44 #include "empathy-rounded-actor.h"
45 #include "empathy-rounded-rectangle.h"
46 #include "empathy-rounded-texture.h"
47 #include "empathy-sound-manager.h"
48 #include "empathy-ui-utils.h"
49 #include "empathy-utils.h"
51 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
52 #include "empathy-debug.h"
54 #define CONTENT_HBOX_SPACING 3
55 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
56 #define OVERLAY_MARGIN 6
58 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
59 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
61 #define SELF_VIDEO_SECTION_WIDTH 120
62 #define SELF_VIDEO_SECTION_HEIGHT 90
63 #define SELF_VIDEO_SECTION_MARGIN 2
64 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
66 /* The avatar's default width and height are set to the same value because we
67 want a square icon. */
68 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
71 #define SMALL_TOOLBAR_SIZE 36
73 /* If an video input error occurs, the error message will start with "v4l" */
74 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
76 /* The time interval in milliseconds between 2 outgoing rings */
77 #define MS_BETWEEN_RING 500
79 /* The roundedness of preview box and placeholders */
80 #define PREVIEW_ROUND_FACTOR 16
82 #define PREVIEW_BUTTON_OPACITY 180
84 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
87 PROP_CALL_HANDLER = 1,
95 static guint signals[LAST_SIGNAL];
98 RINGING, /* Incoming call */
99 CONNECTING, /* Outgoing call */
100 CONNECTED, /* Connected */
101 HELD, /* Connected, but on hold */
102 DISCONNECTED, /* Disconnected */
103 REDIALING /* Redialing (special case of CONNECTING) */
107 CAMERA_STATE_OFF = 0,
113 PREVIEW_POS_TOP_LEFT,
114 PREVIEW_POS_TOP_RIGHT,
115 PREVIEW_POS_BOTTOM_LEFT,
116 PREVIEW_POS_BOTTOM_RIGHT,
119 struct _EmpathyCallWindowPriv
121 gboolean dispose_has_run;
122 EmpathyCallHandler *handler;
124 EmpathyContact *contact;
126 TpawCameraMonitor *camera_monitor;
128 CallState call_state;
131 GtkUIManager *ui_manager;
132 GtkWidget *errors_vbox;
133 /* widget displays the video received from the remote user. This widget is
134 * alive only during call. */
135 ClutterActor *video_output;
136 ClutterActor *video_preview;
137 ClutterActor *drag_preview;
138 ClutterActor *preview_shown_button;
139 ClutterActor *preview_hidden_button;
140 ClutterActor *preview_rectangle1;
141 ClutterActor *preview_rectangle2;
142 ClutterActor *preview_rectangle3;
143 ClutterActor *preview_rectangle4;
144 ClutterActor *preview_spinner_actor;
145 GtkWidget *preview_spinner_widget;
146 GtkWidget *video_container;
147 GtkWidget *remote_user_avatar_widget;
148 GtkWidget *remote_user_avatar_toolbar;
149 GtkWidget *remote_user_name_toolbar;
150 GtkWidget *remote_user_status_toolbar;
151 GtkWidget *status_label;
152 GtkWidget *hangup_button;
153 GtkWidget *audio_call_button;
154 GtkWidget *video_call_button;
155 GtkWidget *mic_button;
156 GtkWidget *microphone_icon;
157 GtkWidget *volume_button;
158 GtkWidget *camera_button;
159 GtkWidget *dialpad_button;
161 GtkWidget *bottom_toolbar;
162 ClutterActor *floating_toolbar;
164 GtkAction *menu_fullscreen;
165 GtkAction *menu_swap_camera;
167 ClutterState *transitions;
169 /* The main box covering all the stage, contaning remote avatar/video */
170 ClutterActor *video_box;
171 ClutterLayoutManager *video_layout;
173 /* A bin layout manager containing a bin for previews
174 * and the floating toolbar */
175 ClutterActor *overlay_bin;
176 ClutterLayoutManager *overlay_layout;
178 /* Bin layout for the previews */
179 ClutterActor *preview_box;
180 ClutterLayoutManager *preview_layout;
182 /* Coordinates of the preview drag event's start. */
183 PreviewPosition preview_pos;
185 /* We keep a reference on the hbox which contains the main content so we can
186 easilly repack everything when toggling fullscreen */
187 GtkWidget *content_hbox;
189 /* These are used to accept or reject an incoming call when the status
191 GtkWidget *incoming_call_dialog;
192 TpCallChannel *pending_channel;
193 TpChannelDispatchOperation *pending_cdo;
194 TpAddDispatchOperationContext *pending_context;
196 gulong video_output_motion_handler_id;
197 guint bus_message_source_id;
199 GtkWidget *dtmf_panel;
202 GtkWidget *details_vbox;
203 GtkWidget *vcodec_encoding_label;
204 GtkWidget *acodec_encoding_label;
205 GtkWidget *vcodec_decoding_label;
206 GtkWidget *acodec_decoding_label;
208 GtkWidget *audio_remote_candidate_label;
209 GtkWidget *audio_local_candidate_label;
210 GtkWidget *video_remote_candidate_label;
211 GtkWidget *video_local_candidate_label;
212 GtkWidget *video_remote_candidate_info_img;
213 GtkWidget *video_local_candidate_info_img;
214 GtkWidget *audio_remote_candidate_info_img;
215 GtkWidget *audio_local_candidate_info_img;
217 GstElement *video_input;
218 GstElement *video_preview_sink;
219 GstElement *video_output_sink;
220 GstElement *audio_input;
221 GstElement *audio_output;
222 gboolean audio_output_added;
223 GstElement *pipeline;
224 GstElement *video_tee;
234 gboolean call_started;
235 gboolean sending_video;
236 CameraState camera_state;
238 EmpathyCallWindowFullscreen *fullscreen;
239 gboolean is_fullscreen;
244 guint inactivity_src;
246 /* Those fields represent the state of the window before it actually was in
248 gboolean dialpad_was_visible_before_fs;
249 gint original_width_before_fs;
250 gint original_height_before_fs;
252 gint x, y, w, h, dialpad_width;
255 /* TRUE if the call should be started when the pipeline is playing */
256 gboolean start_call_when_playing;
257 /* TRUE if we requested to set the pipeline in the playing state */
258 gboolean pipeline_playing;
260 EmpathySoundManager *sound_mgr;
263 EmpathyMicMenu *mic_menu;
264 EmpathyCameraMenu *camera_menu;
269 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
271 static void empathy_call_window_realized_cb (GtkWidget *widget,
272 EmpathyCallWindow *window);
274 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
275 GdkEvent *event, EmpathyCallWindow *window);
277 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
278 GdkEventWindowState *event, EmpathyCallWindow *window);
280 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
283 static void empathy_call_window_hangup_cb (gpointer object,
284 EmpathyCallWindow *window);
286 static void empathy_call_window_fullscreen_cb (gpointer object,
287 EmpathyCallWindow *window);
289 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
291 static gboolean empathy_call_window_video_button_press_cb (
292 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
294 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
295 GdkEventKey *event, EmpathyCallWindow *window);
297 static gboolean empathy_call_window_video_output_motion_notify (
298 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
300 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
303 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
305 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
306 EmpathyCallWindow *window);
308 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
310 static void empathy_call_window_status_message (EmpathyCallWindow *window,
313 static gboolean empathy_call_window_bus_message (GstBus *bus,
314 GstMessage *message, gpointer user_data);
316 static gboolean empathy_call_window_update_timer (gpointer user_data);
319 make_background_transparent (GtkClutterActor *actor)
321 GdkRGBA transparent = { 0., 0., 0., 0. };
324 widget = gtk_clutter_actor_get_widget (actor);
325 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
329 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
332 gtk_widget_set_visible (self->priv->hangup_button, show);
333 gtk_widget_set_visible (self->priv->audio_call_button, !show);
334 gtk_widget_set_visible (self->priv->video_call_button, !show);
338 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
339 EmpathyCallWindow *self)
341 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
342 empathy_call_window_restart_call (self);
346 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
347 EmpathyCallWindow *self)
349 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
350 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
351 empathy_call_window_restart_call (self);
355 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
357 EmpathyCallWindow *self)
362 g_object_get (self->priv->handler, "call-channel", &call, NULL);
364 tones[0] = tp_dtmf_event_to_char (event);
366 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
368 g_object_unref (call);
372 empathy_call_window_show_video_output (EmpathyCallWindow *self,
375 if (self->priv->video_output != NULL)
376 g_object_set (self->priv->video_output, "visible", show, NULL);
378 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
380 clutter_actor_raise_top (self->priv->overlay_bin);
384 create_video_output_widget (EmpathyCallWindow *self)
386 EmpathyCallWindowPriv *priv = GET_PRIV (self);
388 g_assert (priv->video_output == NULL);
389 g_assert (priv->pipeline != NULL);
391 priv->video_output = clutter_texture_new ();
393 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
396 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
397 if (priv->video_output_sink == NULL)
398 g_error ("Missing cluttersink");
400 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
402 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
405 gtk_widget_add_events (priv->video_container,
406 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
407 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
408 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
412 create_video_input (EmpathyCallWindow *self)
414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
416 g_assert (priv->video_input == NULL);
417 priv->video_input = empathy_video_src_new ();
418 gst_object_ref_sink (priv->video_input);
422 audio_control_volume_to_element (GBinding *binding,
423 const GValue *source_value,
424 GValue *target_value,
427 /* AudioControl volume is 0-255, with -1 for unknown */
430 hv = g_value_get_int (source_value);
435 g_value_set_double (target_value, hv/255.0);
441 element_volume_to_audio_control (GBinding *binding,
442 const GValue *source_value,
443 GValue *target_value,
448 ev = g_value_get_double (source_value);
449 ev = CLAMP (ev, 0.0, 1.0);
451 g_value_set_int (target_value, ev * 255);
456 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
457 EmpathyCallWindow *self)
460 g_object_get (obj, "mute", &muted, NULL);
462 self->priv->muted = muted;
463 if (muted && self->priv->transitions)
464 clutter_state_set_state (self->priv->transitions, "fade-in");
468 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
469 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
473 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
474 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
477 empathy_call_window_update_timer (self);
481 create_audio_input (EmpathyCallWindow *self)
483 EmpathyCallWindowPriv *priv = GET_PRIV (self);
485 g_assert (priv->audio_input == NULL);
486 priv->audio_input = empathy_audio_src_new ();
487 gst_object_ref_sink (priv->audio_input);
489 g_signal_connect (priv->audio_input, "notify::mute",
490 G_CALLBACK (audio_input_mute_notify_cb), self);
494 add_video_preview_to_pipeline (EmpathyCallWindow *self)
496 EmpathyCallWindowPriv *priv = GET_PRIV (self);
499 g_assert (priv->video_preview != NULL);
500 g_assert (priv->pipeline != NULL);
501 g_assert (priv->video_input != NULL);
502 g_assert (priv->video_tee != NULL);
504 preview = priv->video_preview_sink;
506 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
508 g_warning ("Could not add video input to pipeline");
512 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
514 g_warning ("Could not add video preview to pipeline");
518 if (!gst_element_link (priv->video_input, priv->video_tee))
520 g_warning ("Could not link video input to video tee");
524 if (!gst_element_link (priv->video_tee, preview))
526 g_warning ("Could not link video tee to video preview");
532 empathy_call_window_disable_camera_cb (GtkAction *action,
533 EmpathyCallWindow *self)
535 clutter_actor_destroy (self->priv->preview_hidden_button);
537 gtk_toggle_button_set_active (
538 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
542 empathy_call_window_minimise_camera_cb (GtkAction *action,
543 EmpathyCallWindow *self)
545 clutter_actor_hide (self->priv->video_preview);
546 clutter_actor_show (self->priv->preview_hidden_button);
550 empathy_call_window_maximise_camera_cb (GtkAction *action,
551 EmpathyCallWindow *self)
553 clutter_actor_show (self->priv->video_preview);
554 clutter_actor_hide (self->priv->preview_hidden_button);
558 empathy_call_window_swap_camera_cb (GtkAction *action,
559 EmpathyCallWindow *self)
561 const GList *cameras, *l;
564 DEBUG ("Swapping the camera");
566 cameras = tpaw_camera_monitor_get_cameras (self->priv->camera_monitor);
567 current_cam = empathy_video_src_dup_device (
568 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
570 for (l = cameras; l != NULL; l = l->next)
572 TpawCamera *camera = l->data;
574 if (!tp_strdiff (camera->device, current_cam))
579 next = l->next->data;
581 next = cameras->data;
583 /* EmpathyCameraMenu will update itself and do the actual change
585 g_settings_set_string (self->priv->settings,
586 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
593 g_free (current_cam);
597 empathy_call_window_camera_added_cb (TpawCameraMonitor *monitor,
599 EmpathyCallWindow *self)
601 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
603 gtk_action_set_visible (self->priv->menu_swap_camera,
604 g_list_length ((GList *) cameras) >= 2);
608 empathy_call_window_camera_removed_cb (TpawCameraMonitor *monitor,
610 EmpathyCallWindow *self)
612 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
614 gtk_action_set_visible (self->priv->menu_swap_camera,
615 g_list_length ((GList *) cameras) >= 2);
619 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
621 EmpathyCallWindow *self)
625 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
627 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
628 0, gtk_get_current_event_time ());
629 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
633 empathy_call_window_preview_hidden_button_clicked_cb (
634 ClutterClickAction *action,
636 EmpathyCallWindow *self)
640 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
641 "/preview-hidden-menu");
642 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
643 0, gtk_get_current_event_time ());
644 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
647 static ClutterActor *
648 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
649 ClutterBinAlignment x,
650 ClutterBinAlignment y)
652 ClutterActor *rectangle;
654 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
655 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
656 PREVIEW_ROUND_FACTOR));
658 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
660 clutter_actor_hide (rectangle);
666 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
670 self->priv->preview_layout = clutter_bin_layout_new (
671 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
672 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
674 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
676 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
678 self->priv->preview_rectangle1 =
679 empathy_call_window_create_preview_rectangle (self,
680 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
681 self->priv->preview_rectangle2 =
682 empathy_call_window_create_preview_rectangle (self,
683 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
684 self->priv->preview_rectangle3 =
685 empathy_call_window_create_preview_rectangle (self,
686 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
687 self->priv->preview_rectangle4 =
688 empathy_call_window_create_preview_rectangle (self,
689 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
693 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
696 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
697 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
703 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
708 guint ret_x = 0, ret_y = 0;
711 if (!clutter_actor_has_allocation (self->priv->preview_box))
714 clutter_actor_get_geometry (self->priv->preview_box, &box);
718 case PREVIEW_POS_TOP_LEFT:
719 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
721 case PREVIEW_POS_TOP_RIGHT:
722 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
723 - SELF_VIDEO_SECTION_WIDTH;
724 ret_y = SELF_VIDEO_SECTION_MARGIN;
726 case PREVIEW_POS_BOTTOM_LEFT:
727 ret_x = SELF_VIDEO_SECTION_MARGIN;
728 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
729 - SELF_VIDEO_SECTION_HEIGHT;
731 case PREVIEW_POS_BOTTOM_RIGHT:
732 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
733 - SELF_VIDEO_SECTION_WIDTH;
734 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
735 - SELF_VIDEO_SECTION_HEIGHT;
738 g_warn_if_reached ();
749 static PreviewPosition
750 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
755 PreviewPosition pos = PREVIEW_POS_NONE;
757 if (!clutter_actor_has_allocation (self->priv->preview_box))
760 clutter_actor_get_geometry (self->priv->preview_box, &box);
762 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
763 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
764 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
765 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
767 pos = PREVIEW_POS_TOP_LEFT;
769 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
770 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
771 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
772 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
774 pos = PREVIEW_POS_TOP_RIGHT;
776 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
777 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
778 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
779 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
781 pos = PREVIEW_POS_BOTTOM_LEFT;
783 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
784 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
785 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
786 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
788 pos = PREVIEW_POS_BOTTOM_RIGHT;
794 static ClutterActor *
795 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
798 ClutterActor *rectangle;
802 case PREVIEW_POS_TOP_LEFT:
803 rectangle = self->priv->preview_rectangle1;
805 case PREVIEW_POS_TOP_RIGHT:
806 rectangle = self->priv->preview_rectangle3;
808 case PREVIEW_POS_BOTTOM_LEFT:
809 rectangle = self->priv->preview_rectangle2;
811 case PREVIEW_POS_BOTTOM_RIGHT:
812 rectangle = self->priv->preview_rectangle4;
822 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
825 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
827 DEBUG ("moving the video preview to %d", pos);
829 self->priv->preview_pos = pos;
833 case PREVIEW_POS_TOP_LEFT:
834 clutter_bin_layout_set_alignment (layout,
835 self->priv->video_preview,
836 CLUTTER_BIN_ALIGNMENT_START,
837 CLUTTER_BIN_ALIGNMENT_START);
839 case PREVIEW_POS_TOP_RIGHT:
840 clutter_bin_layout_set_alignment (layout,
841 self->priv->video_preview,
842 CLUTTER_BIN_ALIGNMENT_END,
843 CLUTTER_BIN_ALIGNMENT_START);
845 case PREVIEW_POS_BOTTOM_LEFT:
846 clutter_bin_layout_set_alignment (layout,
847 self->priv->video_preview,
848 CLUTTER_BIN_ALIGNMENT_START,
849 CLUTTER_BIN_ALIGNMENT_END);
851 case PREVIEW_POS_BOTTOM_RIGHT:
852 clutter_bin_layout_set_alignment (layout,
853 self->priv->video_preview,
854 CLUTTER_BIN_ALIGNMENT_END,
855 CLUTTER_BIN_ALIGNMENT_END);
858 g_warn_if_reached ();
861 g_settings_set_enum (self->priv->settings, "camera-position", pos);
865 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
868 ClutterActor *rectangle;
869 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
871 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
873 empathy_rounded_rectangle_set_border_width (
874 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
875 empathy_rounded_rectangle_set_border_color (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
880 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
881 ClutterActor *rectangle)
883 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
885 clutter_color_shade (&white, 0.55, &darker);
887 empathy_rounded_rectangle_set_border_width (
888 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
889 empathy_rounded_rectangle_set_border_color (
890 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
894 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
896 ClutterActor *rectangle;
898 rectangle = empathy_call_window_get_preview_rectangle (self,
899 self->priv->preview_pos);
901 /* We don't want to darken the rectangle where the preview
904 if (self->priv->preview_rectangle1 != rectangle)
905 empathy_call_window_darken_preview_rectangle (self,
906 self->priv->preview_rectangle1);
908 if (self->priv->preview_rectangle2 != rectangle)
909 empathy_call_window_darken_preview_rectangle (self,
910 self->priv->preview_rectangle2);
912 if (self->priv->preview_rectangle3 != rectangle)
913 empathy_call_window_darken_preview_rectangle (self,
914 self->priv->preview_rectangle3);
916 if (self->priv->preview_rectangle4 != rectangle)
917 empathy_call_window_darken_preview_rectangle (self,
918 self->priv->preview_rectangle4);
922 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
926 ClutterModifierType modifiers,
927 EmpathyCallWindow *self)
929 ClutterActor *stage = clutter_actor_get_stage (actor);
932 self->priv->drag_preview = clutter_clone_new (actor);
934 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
935 self->priv->drag_preview);
937 clutter_actor_transform_stage_point (actor, event_x, event_y,
940 clutter_actor_set_position (self->priv->drag_preview,
941 event_x - rel_x, event_y - rel_y);
943 clutter_drag_action_set_drag_handle (action,
944 self->priv->drag_preview);
946 clutter_actor_set_opacity (actor, 0);
947 clutter_actor_hide (self->priv->preview_shown_button);
949 empathy_call_window_show_preview_rectangles (self, TRUE);
950 empathy_call_window_darken_preview_rectangles (self);
954 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
957 clutter_actor_set_opacity (actor, 255);
961 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
965 ClutterModifierType modifiers,
966 EmpathyCallWindow *self)
971 /* Get the position before destroying the drag actor, otherwise the
972 * preview_box allocation won't be valid and we won't be able to
973 * calculate the position. */
974 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
976 empathy_call_window_get_preview_coordinates (self,
977 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
980 /* Move the preview to the destination and destroy it afterwards */
981 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
984 "signal-swapped-after::completed",
985 clutter_actor_destroy, self->priv->drag_preview,
986 "signal-swapped-after::completed",
987 clutter_actor_show, self->priv->preview_shown_button,
989 empathy_call_window_on_animation_completed_cb, actor,
992 self->priv->drag_preview = NULL;
994 if (pos != PREVIEW_POS_NONE)
995 empathy_call_window_move_video_preview (self, pos);
997 empathy_call_window_show_preview_rectangles (self, FALSE);
1001 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1002 ClutterActor *actor,
1005 EmpathyCallWindow *self)
1007 PreviewPosition pos;
1008 gfloat event_x, event_y;
1010 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1012 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1014 if (pos != PREVIEW_POS_NONE)
1015 empathy_call_window_highlight_preview_rectangle (self, pos);
1017 empathy_call_window_darken_preview_rectangles (self);
1021 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1022 ClutterCrossingEvent *event,
1023 EmpathyCallWindow *self)
1025 ClutterActor *rectangle;
1027 rectangle = empathy_call_window_get_preview_rectangle (self,
1028 self->priv->preview_pos);
1030 empathy_call_window_highlight_preview_rectangle (self,
1031 self->priv->preview_pos);
1033 clutter_actor_show (rectangle);
1039 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1040 ClutterCrossingEvent *event,
1041 EmpathyCallWindow *self)
1043 ClutterActor *rectangle;
1045 rectangle = empathy_call_window_get_preview_rectangle (self,
1046 self->priv->preview_pos);
1048 empathy_call_window_darken_preview_rectangle (self, rectangle);
1050 clutter_actor_hide (rectangle);
1056 create_video_preview (EmpathyCallWindow *self)
1058 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1059 ClutterLayoutManager *layout;
1060 ClutterActor *preview;
1062 ClutterAction *action;
1063 PreviewPosition pos;
1065 g_assert (priv->video_preview == NULL);
1067 pos = g_settings_get_enum (priv->settings, "camera-position");
1069 preview = empathy_rounded_texture_new ();
1070 clutter_actor_set_size (preview,
1071 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1073 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1074 if (priv->video_preview_sink == NULL)
1075 g_error ("Missing cluttersink, check your clutter-gst installation");
1076 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1077 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1079 /* Add a little offset to the video preview */
1080 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1081 CLUTTER_BIN_ALIGNMENT_CENTER);
1082 priv->video_preview = clutter_box_new (layout);
1083 clutter_actor_set_size (priv->video_preview,
1084 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1085 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1087 /* Spinner for when changing the camera device */
1088 priv->preview_spinner_widget = gtk_spinner_new ();
1089 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1091 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1092 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1093 gtk_widget_show (priv->preview_spinner_widget);
1096 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1097 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1098 priv->preview_spinner_widget);
1099 clutter_actor_set_size (priv->preview_spinner_actor,
1100 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1101 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1102 clutter_actor_hide (priv->preview_spinner_actor);
1104 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1106 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1107 priv->preview_spinner_actor);
1109 g_object_set (priv->video_preview_sink,
1115 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1116 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1117 GTK_ICON_SIZE_MENU));
1118 clutter_actor_set_margin_right (b, 4);
1119 clutter_actor_set_margin_bottom (b, 2);
1120 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1121 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1123 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1124 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1126 action = clutter_click_action_new ();
1127 clutter_actor_add_action (b, action);
1128 g_signal_connect (action, "clicked",
1129 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1131 /* Preview hidden */
1132 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1133 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1134 GTK_ICON_SIZE_MENU));
1135 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1137 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1138 priv->preview_hidden_button,
1139 CLUTTER_BIN_ALIGNMENT_START,
1140 CLUTTER_BIN_ALIGNMENT_END);
1142 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1144 clutter_actor_hide (priv->preview_hidden_button);
1146 action = clutter_click_action_new ();
1147 clutter_actor_add_action (b, action);
1148 g_signal_connect (action, "clicked",
1149 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1151 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1152 priv->video_preview,
1153 CLUTTER_BIN_ALIGNMENT_START,
1154 CLUTTER_BIN_ALIGNMENT_END);
1156 empathy_call_window_move_video_preview (self, pos);
1158 action = clutter_drag_action_new ();
1159 g_signal_connect (action, "drag-begin",
1160 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1161 g_signal_connect (action, "drag-end",
1162 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1163 g_signal_connect (action, "drag-motion",
1164 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1166 g_signal_connect (preview, "enter-event",
1167 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1168 g_signal_connect (preview, "leave-event",
1169 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1171 clutter_actor_add_action (preview, action);
1172 clutter_actor_set_reactive (preview, TRUE);
1173 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1177 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1179 clutter_actor_show (self->priv->preview_spinner_actor);
1180 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1184 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1186 clutter_actor_hide (self->priv->preview_spinner_actor);
1187 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1191 empathy_call_window_play_camera (EmpathyCallWindow *self,
1194 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1195 GstElement *preview;
1198 if (priv->video_preview == NULL)
1200 create_video_preview (self);
1201 add_video_preview_to_pipeline (self);
1206 state = GST_STATE_PLAYING;
1210 empathy_call_window_start_camera_spinning (self);
1211 state = GST_STATE_NULL;
1214 preview = priv->video_preview_sink;
1216 gst_element_set_state (preview, state);
1217 gst_element_set_state (priv->video_tee, state);
1218 gst_element_set_state (priv->video_input, state);
1222 display_video_preview (EmpathyCallWindow *self,
1225 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1227 if (priv->video_preview == NULL)
1229 create_video_preview (self);
1230 add_video_preview_to_pipeline (self);
1235 /* Display the video preview */
1236 DEBUG ("Show video preview");
1238 empathy_call_window_play_camera (self, TRUE);
1239 clutter_actor_show (priv->video_preview);
1240 clutter_actor_raise_top (priv->floating_toolbar);
1244 /* Hide the video preview */
1245 DEBUG ("Hide video preview");
1247 if (priv->video_preview != NULL)
1249 clutter_actor_hide (priv->video_preview);
1250 empathy_call_window_play_camera (self, FALSE);
1256 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1258 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1260 empathy_call_window_status_message (window, _("Connecting…"));
1261 priv->call_state = CONNECTING;
1263 /* Show the toolbar */
1264 clutter_state_set_state (priv->transitions, "fade-in");
1267 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1268 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1272 disable_camera (EmpathyCallWindow *self)
1274 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1276 if (priv->camera_state == CAMERA_STATE_OFF)
1279 DEBUG ("Disable camera");
1281 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1283 priv->camera_state = CAMERA_STATE_OFF;
1287 enable_camera (EmpathyCallWindow *self)
1289 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1291 if (priv->camera_state == CAMERA_STATE_ON)
1294 if (priv->video_input == NULL)
1296 DEBUG ("Can't enable camera, no input");
1300 DEBUG ("Enable camera");
1302 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1304 priv->camera_state = CAMERA_STATE_ON;
1308 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1309 EmpathyCallWindow *self)
1311 if (gtk_toggle_button_get_active (toggle))
1312 enable_camera (self);
1314 disable_camera (self);
1318 create_pipeline (EmpathyCallWindow *self)
1320 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1323 g_assert (priv->pipeline == NULL);
1325 priv->pipeline = gst_pipeline_new (NULL);
1326 priv->pipeline_playing = FALSE;
1328 priv->video_tee = gst_element_factory_make ("tee", NULL);
1329 gst_object_ref_sink (priv->video_tee);
1331 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1333 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1334 priv->bus_message_source_id = gst_bus_add_watch (bus,
1335 empathy_call_window_bus_message, self);
1337 g_object_unref (bus);
1341 empathy_call_window_settings_cb (GtkAction *action,
1342 EmpathyCallWindow *self)
1344 gchar *args = g_strdup_printf ("-p %s",
1345 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1347 empathy_launch_program (BIN_DIR, "empathy", args);
1353 empathy_call_window_contents_cb (GtkAction *action,
1354 EmpathyCallWindow *self)
1356 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1360 show_png (GPid pid, gint status, gpointer user_data)
1362 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1363 g_spawn_close_pid (pid);
1368 empathy_call_window_debug_gst_cb (GtkAction *action,
1369 EmpathyCallWindow *self)
1371 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1372 GDateTime *date_time;
1374 const gchar *dot_dir;
1375 const gchar *prgname;
1381 if (priv->pipeline == NULL)
1382 DEBUG ("No pipeline");
1384 date_time = g_date_time_new_now_utc ();
1385 prgname = g_get_prgname ();
1386 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1387 g_date_time_to_unix (date_time));
1389 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1390 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1392 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1393 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1396 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1398 if (g_spawn_async (dot_dir,
1401 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1407 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1408 g_child_watch_add (dot_pid, show_png, uri);
1414 g_date_time_unref (date_time);
1418 empathy_call_window_debug_tp_cb (GtkAction *action,
1419 EmpathyCallWindow *self)
1421 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1425 empathy_call_window_about_cb (GtkAction *action,
1426 EmpathyCallWindow *self)
1428 empathy_about_dialog_new (GTK_WINDOW (self));
1432 empathy_call_window_toolbar_timeout (gpointer data)
1434 EmpathyCallWindow *self = data;
1436 /* We don't want to hide the toolbar if we're not in a call, as
1437 * to show the call status all the time. Also don't hide if we're muted
1438 * to prevent the awkward, talking when muted situation */
1439 if (self->priv->call_state != CONNECTING &&
1440 self->priv->call_state != DISCONNECTED &&
1442 clutter_state_set_state (self->priv->transitions, "fade-out");
1448 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1450 EmpathyCallWindow *self)
1452 clutter_state_set_state (self->priv->transitions, "fade-in");
1454 if (self->priv->inactivity_src > 0)
1455 g_source_remove (self->priv->inactivity_src);
1457 self->priv->inactivity_src = g_timeout_add_seconds (3,
1458 empathy_call_window_toolbar_timeout, self);
1464 empathy_call_window_configure_event_cb (GtkWidget *widget,
1466 EmpathyCallWindow *self)
1468 GdkWindow *gdk_window;
1469 GdkWindowState window_state;
1471 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1472 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1474 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1475 &self->priv->dialpad_width, NULL);
1477 gdk_window = gtk_widget_get_window (widget);
1478 window_state = gdk_window_get_state (gdk_window);
1479 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1485 empathy_call_window_destroyed_cb (GtkWidget *object,
1486 EmpathyCallWindow *self)
1488 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1490 /* Save the geometry as if the dialpad was hidden. */
1491 empathy_geometry_save_values (GTK_WINDOW (self),
1492 self->priv->x, self->priv->y,
1493 self->priv->w - self->priv->dialpad_width, self->priv->h,
1494 self->priv->maximized);
1499 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1501 EmpathyCallWindow *self)
1503 switch (response_id)
1505 case GTK_RESPONSE_ACCEPT:
1506 tp_channel_dispatch_operation_handle_with_async (
1507 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1509 tp_clear_object (&self->priv->pending_cdo);
1510 tp_clear_object (&self->priv->pending_channel);
1511 tp_clear_object (&self->priv->pending_context);
1514 case GTK_RESPONSE_CANCEL:
1515 tp_channel_dispatch_operation_close_channels_async (
1516 self->priv->pending_cdo, NULL, NULL);
1518 empathy_call_window_status_message (self, _("Disconnected"));
1519 self->priv->call_state = DISCONNECTED;
1522 g_warn_if_reached ();
1527 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1531 g_assert (self->priv->call_state != CONNECTED);
1533 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1535 empathy_call_window_status_message (self, _("Incoming call"));
1536 self->priv->call_state = RINGING;
1538 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1539 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1540 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1541 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1542 empathy_contact_get_alias (self->priv->contact));
1544 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1545 _("Reject"), GTK_RESPONSE_CANCEL,
1546 _("Answer"), GTK_RESPONSE_ACCEPT,
1549 g_signal_connect (self->priv->incoming_call_dialog, "response",
1550 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1551 gtk_widget_show (self->priv->incoming_call_dialog);
1555 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1559 EmpathyCallWindow *self)
1561 tp_clear_object (&self->priv->pending_cdo);
1562 tp_clear_object (&self->priv->pending_channel);
1563 tp_clear_object (&self->priv->pending_context);
1565 /* We don't know if the incoming call has been accepted or not, so we
1566 * assume it hasn't and if it has, we'll set the proper status when
1567 * we get the new handler. */
1568 empathy_call_window_status_message (self, _("Disconnected"));
1569 self->priv->call_state = DISCONNECTED;
1571 gtk_widget_destroy (self->priv->incoming_call_dialog);
1572 self->priv->incoming_call_dialog = NULL;
1576 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1577 TpCallChannel *channel,
1578 TpChannelDispatchOperation *dispatch_operation,
1579 TpAddDispatchOperationContext *context)
1581 g_assert (self->priv->pending_channel == NULL);
1582 g_assert (self->priv->pending_context == NULL);
1583 g_assert (self->priv->pending_cdo == NULL);
1585 /* Start ringing and delay until the user answers or hangs. */
1586 self->priv->pending_channel = g_object_ref (channel);
1587 self->priv->pending_context = g_object_ref (context);
1588 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1590 g_signal_connect (self->priv->pending_cdo, "invalidated",
1591 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1593 empathy_call_window_set_state_ringing (self);
1594 tp_add_dispatch_operation_context_accept (context);
1598 mic_button_clicked (GtkWidget *button,
1599 EmpathyCallWindow *self)
1601 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1603 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1604 !self->priv->muted);
1608 empathy_call_window_init (EmpathyCallWindow *self)
1610 EmpathyCallWindowPriv *priv;
1612 GtkWidget *top_vbox;
1614 ClutterConstraint *constraint;
1615 ClutterActor *remote_avatar;
1616 ClutterColor black = { 0, 0, 0, 0 };
1617 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1618 OVERLAY_MARGIN, OVERLAY_MARGIN };
1620 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1621 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1623 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1624 priv->timer = g_timer_new ();
1626 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1627 gui = tpaw_builder_get_file (filename,
1628 "call_window_vbox", &top_vbox,
1629 "errors_vbox", &priv->errors_vbox,
1630 "pane", &priv->pane,
1631 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1632 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1633 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1634 "status_label", &priv->status_label,
1635 "audiocall", &priv->audio_call_button,
1636 "videocall", &priv->video_call_button,
1637 "microphone", &priv->mic_button,
1638 "microphone_icon", &priv->microphone_icon,
1639 "volume", &priv->volume_button,
1640 "camera", &priv->camera_button,
1641 "hangup", &priv->hangup_button,
1642 "dialpad", &priv->dialpad_button,
1643 "toolbar", &priv->toolbar,
1644 "bottom_toolbar", &priv->bottom_toolbar,
1645 "ui_manager", &priv->ui_manager,
1646 "menufullscreen", &priv->menu_fullscreen,
1647 "menupreviewswap", &priv->menu_swap_camera,
1648 "details_vbox", &priv->details_vbox,
1649 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1650 "acodec_encoding_label", &priv->acodec_encoding_label,
1651 "acodec_decoding_label", &priv->acodec_decoding_label,
1652 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1653 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1654 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1655 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1656 "video_local_candidate_label", &priv->video_local_candidate_label,
1657 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1658 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1659 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1660 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1664 tpaw_builder_connect (gui, self,
1665 "hangup", "clicked", empathy_call_window_hangup_cb,
1666 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1667 "videocall", "clicked", empathy_call_window_video_call_cb,
1668 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1669 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1670 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1671 "menusettings", "activate", empathy_call_window_settings_cb,
1672 "menucontents", "activate", empathy_call_window_contents_cb,
1673 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1674 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1675 "menuabout", "activate", empathy_call_window_about_cb,
1676 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1677 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1678 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1679 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1682 empathy_set_css_provider (GTK_WIDGET (self));
1683 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1685 priv->camera_monitor = tpaw_camera_monitor_dup_singleton ();
1687 g_object_bind_property (priv->camera_monitor, "available",
1688 priv->camera_button, "sensitive",
1689 G_BINDING_SYNC_CREATE);
1691 g_signal_connect (priv->camera_monitor, "added",
1692 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1693 g_signal_connect (priv->camera_monitor, "removed",
1694 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1696 g_signal_connect (priv->mic_button, "clicked",
1697 G_CALLBACK (mic_button_clicked), self);
1699 g_mutex_init (&priv->lock);
1701 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1703 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1704 CONTENT_HBOX_SPACING);
1705 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1708 /* main contents remote avatar/video box */
1709 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1710 CLUTTER_BIN_ALIGNMENT_FILL);
1712 priv->video_box = clutter_box_new (priv->video_layout);
1714 priv->video_container = gtk_clutter_embed_new ();
1716 gtk_widget_set_size_request (priv->video_container,
1717 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1719 /* Set the background black */
1720 clutter_stage_set_color (
1721 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1722 GTK_CLUTTER_EMBED (priv->video_container))),
1725 clutter_container_add (
1726 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1727 GTK_CLUTTER_EMBED (priv->video_container))),
1731 constraint = clutter_bind_constraint_new (
1732 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1733 CLUTTER_BIND_SIZE, 0);
1734 clutter_actor_add_constraint (priv->video_box, constraint);
1736 priv->remote_user_avatar_widget = gtk_image_new ();
1737 remote_avatar = gtk_clutter_actor_new_with_contents (
1738 priv->remote_user_avatar_widget);
1739 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1741 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1744 /* create the overlay bin */
1745 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1746 CLUTTER_BIN_ALIGNMENT_CENTER);
1747 priv->overlay_bin = clutter_actor_new ();
1748 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1750 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1752 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1754 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1756 empathy_call_window_create_preview_rectangles (self);
1758 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1759 priv->video_container, TRUE, TRUE,
1760 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1762 create_pipeline (self);
1763 create_video_output_widget (self);
1764 create_audio_input (self);
1765 create_video_input (self);
1767 priv->floating_toolbar = gtk_clutter_actor_new ();
1768 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1769 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1771 gtk_style_context_add_class (
1772 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1773 GTK_STYLE_CLASS_OSD);
1774 gtk_widget_reparent (priv->bottom_toolbar,
1775 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1777 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1778 priv->floating_toolbar,
1779 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1781 clutter_actor_raise_top (priv->floating_toolbar);
1783 /* Transitions for the floating toolbar */
1784 priv->transitions = clutter_state_new ();
1786 /* all transitions last for 2s */
1787 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1789 /* transition from any state to "fade-out" state */
1790 clutter_state_set (priv->transitions, NULL, "fade-out",
1791 priv->floating_toolbar,
1792 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1795 /* transition from any state to "fade-in" state */
1796 clutter_state_set (priv->transitions, NULL, "fade-in",
1797 priv->floating_toolbar,
1798 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1801 /* put the actor into the "fade-in" state with no animation */
1802 clutter_state_warp_to_state (priv->transitions, "fade-in");
1804 /* The call will be started as soon the pipeline is playing */
1805 priv->start_call_when_playing = TRUE;
1807 priv->dtmf_panel = empathy_dialpad_widget_new ();
1808 g_signal_connect (priv->dtmf_panel, "start-tone",
1809 G_CALLBACK (dtmf_start_tone_cb), self);
1811 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1814 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1817 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1819 gtk_widget_show_all (top_vbox);
1821 gtk_widget_hide (priv->dtmf_panel);
1822 gtk_widget_hide (priv->details_vbox);
1824 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1826 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1827 priv->video_container);
1829 /* We hide the bottom toolbar after 3s of inactivity and show it
1830 * again on mouse movement */
1831 priv->inactivity_src = g_timeout_add_seconds (3,
1832 empathy_call_window_toolbar_timeout, self);
1834 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1835 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1837 g_signal_connect (G_OBJECT (self), "realize",
1838 G_CALLBACK (empathy_call_window_realized_cb), self);
1840 g_signal_connect (G_OBJECT (self), "delete-event",
1841 G_CALLBACK (empathy_call_window_delete_cb), self);
1843 g_signal_connect (G_OBJECT (self), "window-state-event",
1844 G_CALLBACK (empathy_call_window_state_event_cb), self);
1846 g_signal_connect (G_OBJECT (self), "key-press-event",
1847 G_CALLBACK (empathy_call_window_key_press_cb), self);
1849 g_signal_connect (self, "motion-notify-event",
1850 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1852 g_object_ref (priv->ui_manager);
1853 g_object_unref (gui);
1855 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1856 priv->mic_menu = empathy_mic_menu_new (self);
1857 priv->camera_menu = empathy_camera_menu_new (self);
1859 empathy_call_window_show_hangup_button (self, TRUE);
1861 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1863 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1864 /* These signals are used to track the window position and save it
1865 * when the window is destroyed. We need to do this as we don't want
1866 * the window geometry to be saved with the dialpad taken into account. */
1867 g_signal_connect (self, "destroy",
1868 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1869 g_signal_connect (self, "configure-event",
1870 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1871 g_signal_connect (self, "window-state-event",
1872 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1874 /* Don't display labels in both toolbars */
1875 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1878 /* Instead of specifying a width and a height, we specify only one size. That's
1879 because we want a square avatar icon. */
1881 init_contact_avatar_with_size (EmpathyContact *contact,
1882 GtkWidget *image_widget,
1885 GdkPixbuf *pixbuf_avatar = NULL;
1887 if (contact != NULL)
1889 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1893 if (pixbuf_avatar == NULL)
1895 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1896 TPAW_IMAGE_AVATAR_DEFAULT, size);
1899 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1901 if (pixbuf_avatar != NULL)
1902 g_object_unref (pixbuf_avatar);
1906 set_window_title (EmpathyCallWindow *self)
1908 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1911 if (priv->contact != NULL)
1913 /* translators: Call is a noun and %s is the contact name. This string
1914 * is used in the window title */
1915 tmp = g_strdup_printf (_("Call with %s"),
1916 empathy_contact_get_alias (priv->contact));
1917 gtk_window_set_title (GTK_WINDOW (self), tmp);
1922 g_warning ("Unknown remote contact!");
1927 set_remote_user_name (EmpathyCallWindow *self,
1928 EmpathyContact *contact)
1930 const gchar *alias = empathy_contact_get_alias (contact);
1931 const gchar *status = empathy_contact_get_status (contact);
1933 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1935 if (status != NULL) {
1938 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1939 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1943 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1949 contact_name_changed_cb (EmpathyContact *contact,
1951 EmpathyCallWindow *self)
1953 set_window_title (self);
1954 set_remote_user_name (self, contact);
1958 contact_presence_changed_cb (EmpathyContact *contact,
1960 EmpathyCallWindow *self)
1962 set_remote_user_name (self, contact);
1966 contact_avatar_changed_cb (EmpathyContact *contact,
1968 EmpathyCallWindow *self)
1971 GtkAllocation allocation;
1972 GtkWidget *avatar_widget;
1974 avatar_widget = self->priv->remote_user_avatar_widget;
1976 gtk_widget_get_allocation (avatar_widget, &allocation);
1977 size = allocation.height;
1981 /* the widget is not allocated yet, set a default size */
1982 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1983 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1986 init_contact_avatar_with_size (contact, avatar_widget, size);
1988 avatar_widget = self->priv->remote_user_avatar_toolbar;
1990 gtk_widget_get_allocation (avatar_widget, &allocation);
1991 size = allocation.height;
1995 /* the widget is not allocated yet, set a default size */
1996 size = SMALL_TOOLBAR_SIZE;
1999 init_contact_avatar_with_size (contact, avatar_widget, size);
2003 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2004 EmpathyCallHandler *handler)
2006 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2008 tp_g_signal_connect_object (priv->contact, "notify::name",
2009 G_CALLBACK (contact_name_changed_cb), self, 0);
2010 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2011 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2012 tp_g_signal_connect_object (priv->contact, "notify::presence",
2013 G_CALLBACK (contact_presence_changed_cb), self, 0);
2015 set_window_title (self);
2016 set_remote_user_name (self, priv->contact);
2018 init_contact_avatar_with_size (priv->contact,
2019 priv->remote_user_avatar_widget,
2020 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2021 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2023 init_contact_avatar_with_size (priv->contact,
2024 priv->remote_user_avatar_toolbar,
2025 SMALL_TOOLBAR_SIZE);
2027 /* The remote avatar is shown by default and will be hidden when we receive
2028 video from the remote side. */
2029 clutter_actor_hide (priv->video_output);
2030 gtk_widget_show (priv->remote_user_avatar_widget);
2034 update_send_codec (EmpathyCallWindow *self,
2037 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2044 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2045 widget = priv->acodec_encoding_label;
2049 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2050 widget = priv->vcodec_encoding_label;
2056 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2057 gtk_label_set_text (GTK_LABEL (widget), tmp);
2062 send_audio_codec_notify_cb (GObject *object,
2066 EmpathyCallWindow *self = user_data;
2068 update_send_codec (self, TRUE);
2072 send_video_codec_notify_cb (GObject *object,
2076 EmpathyCallWindow *self = user_data;
2078 update_send_codec (self, FALSE);
2082 update_recv_codec (EmpathyCallWindow *self,
2085 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2088 GString *str = NULL;
2092 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2093 widget = priv->acodec_decoding_label;
2097 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2098 widget = priv->vcodec_decoding_label;
2104 for (l = codecs; l != NULL; l = g_list_next (l))
2106 FsCodec *codec = l->data;
2109 str = g_string_new (NULL);
2111 g_string_append (str, ", ");
2113 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2117 gtk_label_set_text (GTK_LABEL (widget), str->str);
2118 g_string_free (str, TRUE);
2122 recv_audio_codecs_notify_cb (GObject *object,
2126 EmpathyCallWindow *self = user_data;
2128 update_recv_codec (self, TRUE);
2132 recv_video_codecs_notify_cb (GObject *object,
2136 EmpathyCallWindow *self = user_data;
2138 update_recv_codec (self, FALSE);
2141 static const gchar *
2142 candidate_type_to_str (FsCandidate *candidate)
2144 switch (candidate->type)
2146 case FS_CANDIDATE_TYPE_HOST:
2148 case FS_CANDIDATE_TYPE_SRFLX:
2149 return "server reflexive";
2150 case FS_CANDIDATE_TYPE_PRFLX:
2151 return "peer reflexive";
2152 case FS_CANDIDATE_TYPE_RELAY:
2154 case FS_CANDIDATE_TYPE_MULTICAST:
2161 static const gchar *
2162 candidate_type_to_desc (FsCandidate *candidate)
2164 switch (candidate->type)
2166 case FS_CANDIDATE_TYPE_HOST:
2167 return _("The IP address as seen by the machine");
2168 case FS_CANDIDATE_TYPE_SRFLX:
2169 return _("The IP address as seen by a server on the Internet");
2170 case FS_CANDIDATE_TYPE_PRFLX:
2171 return _("The IP address of the peer as seen by the other side");
2172 case FS_CANDIDATE_TYPE_RELAY:
2173 return _("The IP address of a relay server");
2174 case FS_CANDIDATE_TYPE_MULTICAST:
2175 return _("The IP address of the multicast group");
2182 update_candidat_widget (EmpathyCallWindow *self,
2185 FsCandidate *candidate)
2189 g_assert (candidate != NULL);
2190 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2191 candidate->port, candidate_type_to_str (candidate));
2193 gtk_label_set_text (GTK_LABEL (label), str);
2194 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2200 candidates_changed_cb (GObject *object,
2202 EmpathyCallWindow *self)
2204 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2205 FsCandidate *candidate = NULL;
2207 if (type == FS_MEDIA_TYPE_VIDEO)
2209 /* Update remote candidate */
2210 candidate = empathy_call_handler_get_video_remote_candidate (
2213 update_candidat_widget (self, priv->video_remote_candidate_label,
2214 priv->video_remote_candidate_info_img, candidate);
2216 /* Update local candidate */
2217 candidate = empathy_call_handler_get_video_local_candidate (
2220 update_candidat_widget (self, priv->video_local_candidate_label,
2221 priv->video_local_candidate_info_img, candidate);
2225 /* Update remote candidate */
2226 candidate = empathy_call_handler_get_audio_remote_candidate (
2229 update_candidat_widget (self, priv->audio_remote_candidate_label,
2230 priv->audio_remote_candidate_info_img, candidate);
2232 /* Update local candidate */
2233 candidate = empathy_call_handler_get_audio_local_candidate (
2236 update_candidat_widget (self, priv->audio_local_candidate_label,
2237 priv->audio_local_candidate_info_img, candidate);
2242 empathy_call_window_constructed (GObject *object)
2244 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2245 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2246 TpCallChannel *call;
2249 g_assert (priv->handler != NULL);
2251 g_object_get (priv->handler, "call-channel", &call, NULL);
2252 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2253 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2254 tp_clear_object (&call);
2256 priv->contact = empathy_call_handler_get_contact (priv->handler);
2257 g_assert (priv->contact != NULL);
2258 g_object_ref (priv->contact);
2260 if (!empathy_contact_can_voip_video (priv->contact))
2262 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2263 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2266 empathy_call_window_setup_avatars (self, priv->handler);
2267 empathy_call_window_set_state_connecting (self);
2269 if (!empathy_call_handler_has_initial_video (priv->handler))
2271 gtk_toggle_button_set_active (
2272 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2274 /* If call has InitialVideo, the preview will be started once the call has
2275 * been started (start_call()). */
2277 update_send_codec (self, TRUE);
2278 update_send_codec (self, FALSE);
2279 update_recv_codec (self, TRUE);
2280 update_recv_codec (self, FALSE);
2282 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2283 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2284 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2285 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2286 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2287 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2288 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2289 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2291 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2292 G_CALLBACK (candidates_changed_cb), self, 0);
2295 static void empathy_call_window_dispose (GObject *object);
2296 static void empathy_call_window_finalize (GObject *object);
2299 empathy_call_window_set_property (GObject *object,
2300 guint property_id, const GValue *value, GParamSpec *pspec)
2302 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2304 switch (property_id)
2306 case PROP_CALL_HANDLER:
2307 priv->handler = g_value_dup_object (value);
2310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2315 empathy_call_window_get_property (GObject *object,
2316 guint property_id, GValue *value, GParamSpec *pspec)
2318 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2320 switch (property_id)
2322 case PROP_CALL_HANDLER:
2323 g_value_set_object (value, priv->handler);
2326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2331 empathy_call_window_class_init (
2332 EmpathyCallWindowClass *empathy_call_window_class)
2334 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2335 GParamSpec *param_spec;
2337 g_type_class_add_private (empathy_call_window_class,
2338 sizeof (EmpathyCallWindowPriv));
2340 object_class->constructed = empathy_call_window_constructed;
2341 object_class->set_property = empathy_call_window_set_property;
2342 object_class->get_property = empathy_call_window_get_property;
2344 object_class->dispose = empathy_call_window_dispose;
2345 object_class->finalize = empathy_call_window_finalize;
2347 param_spec = g_param_spec_object ("handler",
2348 "handler", "The call handler",
2349 EMPATHY_TYPE_CALL_HANDLER,
2350 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2351 g_object_class_install_property (object_class,
2352 PROP_CALL_HANDLER, param_spec);
2354 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2355 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2357 0, NULL, NULL, NULL,
2363 empathy_call_window_dispose (GObject *object)
2365 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2368 if (priv->dispose_has_run)
2371 priv->dispose_has_run = TRUE;
2373 if (priv->handler != NULL)
2375 empathy_call_handler_stop_call (priv->handler);
2376 tp_clear_object (&priv->handler);
2379 if (priv->bus_message_source_id != 0)
2381 g_source_remove (priv->bus_message_source_id);
2382 priv->bus_message_source_id = 0;
2385 if (priv->got_video_src > 0)
2387 g_source_remove (priv->got_video_src);
2388 priv->got_video_src = 0;
2391 if (priv->inactivity_src > 0)
2393 g_source_remove (priv->inactivity_src);
2394 priv->inactivity_src = 0;
2397 tp_clear_object (&priv->pipeline);
2398 tp_clear_object (&priv->video_input);
2399 tp_clear_object (&priv->audio_input);
2400 tp_clear_object (&priv->video_tee);
2401 tp_clear_object (&priv->ui_manager);
2402 tp_clear_object (&priv->fullscreen);
2403 tp_clear_object (&priv->camera_monitor);
2404 tp_clear_object (&priv->settings);
2405 tp_clear_object (&priv->sound_mgr);
2406 tp_clear_object (&priv->mic_menu);
2407 tp_clear_object (&priv->camera_menu);
2408 tp_clear_object (&priv->transitions);
2410 g_list_free_full (priv->notifiers, g_object_unref);
2412 if (priv->timer_id != 0)
2413 g_source_remove (priv->timer_id);
2416 tp_clear_object (&priv->contact);
2418 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2422 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2426 if (priv->video_output_motion_handler_id != 0)
2428 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2429 priv->video_output_motion_handler_id);
2430 priv->video_output_motion_handler_id = 0;
2435 empathy_call_window_finalize (GObject *object)
2437 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2440 disconnect_video_output_motion_handler (self);
2442 /* free any data held directly by the object here */
2443 g_mutex_clear (&priv->lock);
2445 g_timer_destroy (priv->timer);
2447 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2452 empathy_call_window_new (EmpathyCallHandler *handler)
2454 return EMPATHY_CALL_WINDOW (
2455 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2459 empathy_call_window_new_handler (EmpathyCallWindow *self,
2460 EmpathyCallHandler *handler,
2464 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2467 empathy_window_present_with_time (GTK_WINDOW (self), x11_time);
2469 if (self->priv->call_state == DISCONNECTED)
2471 /* start a new call if one is not already in progress */
2472 tp_clear_object (&self->priv->handler);
2473 self->priv->handler = g_object_ref (handler);
2474 empathy_call_window_connect_handler (self);
2476 empathy_call_window_restart_call (self);
2481 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2482 GstElement *conference, gpointer user_data)
2484 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2486 FsElementAddedNotifier *notifier;
2489 DEBUG ("Conference added");
2491 /* Add notifier to set the various element properties as needed */
2492 notifier = fs_element_added_notifier_new ();
2493 keyfile = fs_utils_get_default_element_properties (conference);
2495 if (keyfile != NULL)
2496 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2498 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2500 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2502 gst_bin_add (GST_BIN (priv->pipeline), conference);
2503 gst_element_set_state (conference, GST_STATE_PLAYING);
2507 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2508 GstElement *conference, gpointer user_data)
2510 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2511 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2513 g_list_free_full (priv->notifiers, g_object_unref);
2514 priv->notifiers = NULL;
2516 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2517 gst_element_set_state (conference, GST_STATE_NULL);
2521 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2523 GstStateChangeReturn state_change_return;
2524 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2526 if (priv->pipeline == NULL)
2529 if (priv->bus_message_source_id != 0)
2531 g_source_remove (priv->bus_message_source_id);
2532 priv->bus_message_source_id = 0;
2535 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2537 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2538 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2540 if (priv->pipeline != NULL)
2541 g_object_unref (priv->pipeline);
2542 priv->pipeline = NULL;
2544 if (priv->audio_output != NULL)
2545 g_object_unref (priv->audio_output);
2546 priv->audio_output = NULL;
2547 priv->audio_output_added = FALSE;
2549 if (priv->video_tee != NULL)
2550 g_object_unref (priv->video_tee);
2551 priv->video_tee = NULL;
2553 if (priv->video_preview != NULL)
2554 clutter_actor_destroy (priv->video_preview);
2555 priv->video_preview = NULL;
2557 /* If we destroy the preview while it's being dragged, we won't
2558 * get the ::drag-end signal, so manually destroy the clone */
2559 if (priv->drag_preview != NULL)
2561 clutter_actor_destroy (priv->drag_preview);
2562 empathy_call_window_show_preview_rectangles (self, FALSE);
2563 priv->drag_preview = NULL;
2566 priv->funnel = NULL;
2568 create_pipeline (self);
2569 /* Call will be started when user will hit the 'redial' button */
2570 priv->start_call_when_playing = FALSE;
2571 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2577 g_message ("Error: could not destroy pipeline. Closing call window");
2578 gtk_widget_destroy (GTK_WIDGET (self));
2585 reset_details_pane (EmpathyCallWindow *self)
2587 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2589 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2590 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2591 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2592 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2596 empathy_call_window_disconnected (EmpathyCallWindow *self,
2599 gboolean could_disconnect = FALSE;
2600 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2601 gboolean could_reset_pipeline;
2603 /* Leave full screen mode if needed */
2604 gtk_window_unfullscreen (GTK_WINDOW (self));
2606 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2608 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2609 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2611 /* Create the video input and then turn on the camera
2612 * menu, so that the active camera gets marked as such.
2614 if (priv->video_input == NULL)
2615 create_video_input (self);
2616 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2618 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2620 if (priv->call_state == CONNECTING)
2621 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2623 if (priv->call_state != REDIALING)
2624 priv->call_state = DISCONNECTED;
2626 /* Show the toolbar */
2627 clutter_state_set_state (priv->transitions, "fade-in");
2629 if (could_reset_pipeline)
2631 g_mutex_lock (&priv->lock);
2633 g_timer_stop (priv->timer);
2635 if (priv->timer_id != 0)
2636 g_source_remove (priv->timer_id);
2639 g_mutex_unlock (&priv->lock);
2642 /* We are about to destroy the window, no need to update it or create
2643 * a video preview */
2646 empathy_call_window_status_message (self, _("Disconnected"));
2648 empathy_call_window_show_hangup_button (self, FALSE);
2650 /* Unsensitive the camera and mic button */
2651 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2652 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2654 /* Be sure that the mic button is enabled */
2655 empathy_audio_src_set_mute (
2656 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2658 if (priv->camera_state == CAMERA_STATE_ON)
2660 /* Restart the preview with the new pipeline. */
2661 display_video_preview (self, TRUE);
2664 /* destroy the video output; it will be recreated when we'll redial */
2665 disconnect_video_output_motion_handler (self);
2666 if (priv->video_output != NULL)
2667 clutter_actor_destroy (priv->video_output);
2668 priv->video_output = NULL;
2669 if (priv->got_video_src > 0)
2671 g_source_remove (priv->got_video_src);
2672 priv->got_video_src = 0;
2675 gtk_widget_show (priv->remote_user_avatar_widget);
2677 reset_details_pane (self);
2679 priv->sending_video = FALSE;
2680 priv->call_started = FALSE;
2682 could_disconnect = TRUE;
2684 /* TODO: display the self avatar of the preview (depends if the "Always
2685 * Show Video Preview" is enabled or not) */
2688 return could_disconnect;
2693 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2696 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2697 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2699 if (empathy_call_window_disconnected (self, TRUE) &&
2700 priv->call_state == REDIALING)
2701 empathy_call_window_restart_call (self);
2705 empathy_call_window_content_is_raw (TfContent *content)
2707 FsConference *conference;
2710 g_object_get (content, "fs-conference", &conference, NULL);
2711 g_assert (conference != NULL);
2713 /* FIXME: Ugly hack, update when moving a packetization property into
2715 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2716 gst_object_unref (conference);
2722 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2724 EmpathyCallWindow *self)
2726 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2727 FsMediaType media_type;
2729 DEBUG ("removing content");
2731 g_object_get (content, "media-type", &media_type, NULL);
2734 * This assumes that there is only one video stream per channel...
2737 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2739 if (priv->funnel != NULL)
2743 output = priv->video_output_sink;
2745 gst_element_set_state (output, GST_STATE_NULL);
2746 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2748 gst_bin_remove (GST_BIN (priv->pipeline), output);
2749 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2750 priv->funnel = NULL;
2753 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2755 if (priv->audio_output != NULL)
2757 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2759 if (priv->audio_output_added)
2760 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2761 priv->audio_output = NULL;
2762 priv->audio_output_added = FALSE;
2767 g_assert_not_reached ();
2774 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2776 EmpathyCallWindow *self)
2778 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2780 DEBUG ("Framerate changed to %u", framerate);
2782 if (priv->video_input != NULL)
2783 empathy_video_src_set_framerate (priv->video_input, framerate);
2787 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2790 EmpathyCallWindow *self)
2792 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2794 DEBUG ("Resolution changed to %ux%u", width, height);
2796 if (priv->video_input != NULL)
2798 empathy_video_src_set_resolution (priv->video_input, width, height);
2802 /* Called with global lock held */
2804 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2806 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2810 if (priv->funnel == NULL)
2812 output = priv->video_output_sink;
2814 priv->funnel = gst_element_factory_make ("funnel", NULL);
2816 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2821 g_warning ("Could not create video funnel");
2825 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2827 gst_object_unref (priv->funnel);
2828 priv->funnel = NULL;
2829 g_warning ("Could not add funnel to pipeline");
2833 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2835 g_warning ("Could not add the video output widget to the pipeline");
2839 if (!gst_element_link (priv->funnel, output))
2841 g_warning ("Could not link output sink to funnel");
2842 goto error_output_added;
2845 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2847 g_warning ("Could not start video sink");
2848 goto error_output_added;
2851 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2853 g_warning ("Could not start funnel");
2854 goto error_output_added;
2858 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2860 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2864 g_warning ("Could not get request pad from funnel");
2871 gst_element_set_locked_state (priv->funnel, TRUE);
2872 gst_element_set_locked_state (output, TRUE);
2874 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2875 gst_element_set_state (output, GST_STATE_NULL);
2877 gst_bin_remove (GST_BIN (priv->pipeline), output);
2878 gst_element_set_locked_state (output, FALSE);
2882 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2883 priv->funnel = NULL;
2888 /* Called with global lock held */
2890 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2893 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2895 GstPadTemplate *template;
2897 if (!priv->audio_output_added)
2899 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2901 g_warning ("Could not add audio sink to pipeline");
2902 g_object_unref (priv->audio_output);
2903 goto error_add_output;
2906 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2908 g_warning ("Could not start audio sink");
2911 priv->audio_output_added = TRUE;
2914 template = gst_element_class_get_pad_template (
2915 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2917 pad = gst_element_request_pad (priv->audio_output,
2918 template, NULL, NULL);
2922 g_warning ("Could not get sink pad from sink");
2929 gst_element_set_locked_state (priv->audio_output, TRUE);
2930 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2931 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2932 priv->audio_output = NULL;
2940 empathy_call_window_update_timer (gpointer user_data)
2942 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2943 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2944 const gchar *status;
2948 time_ = g_timer_elapsed (priv->timer, NULL);
2950 if (priv->call_state == HELD)
2951 status = _("On hold");
2952 else if (priv->call_state == DISCONNECTED)
2953 status = _("Disconnected");
2954 else if (priv->muted)
2957 status = _("Duration");
2959 /* Translators: 'status - minutes:seconds' the caller has been connected */
2960 str = g_strdup_printf (_("%s — %d:%02dm"),
2962 (int) time_ / 60, (int) time_ % 60);
2963 empathy_call_window_status_message (self, str);
2971 EMP_RESPONSE_BALANCE
2975 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2979 switch (response_id)
2981 case GTK_RESPONSE_CLOSE:
2982 gtk_widget_destroy (GTK_WIDGET (info_bar));
2984 case EMP_RESPONSE_BALANCE:
2985 empathy_url_show (GTK_WIDGET (info_bar),
2986 g_object_get_data (G_OBJECT (info_bar), "uri"));
2992 display_error (EmpathyCallWindow *self,
2996 const gchar *details,
2997 const gchar *button_text,
2999 gint button_response)
3001 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3002 GtkWidget *info_bar;
3003 GtkWidget *content_area;
3010 /* Create info bar */
3011 info_bar = gtk_info_bar_new ();
3013 if (button_text != NULL)
3015 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3016 button_text, button_response);
3017 g_object_set_data_full (G_OBJECT (info_bar),
3018 "uri", g_strdup (uri), g_free);
3021 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3022 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3024 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3026 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3028 /* hbox containing the image and the messages vbox */
3029 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3030 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3033 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3034 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3036 /* vbox containing the main message and the details expander */
3037 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3038 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3041 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3043 label = gtk_label_new (NULL);
3044 gtk_label_set_markup (GTK_LABEL (label), txt);
3045 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3046 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3049 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3052 if (details != NULL)
3054 GtkWidget *expander;
3056 expander = gtk_expander_new (_("Technical Details"));
3058 txt = g_strdup_printf ("<i>%s</i>", details);
3060 label = gtk_label_new (NULL);
3061 gtk_label_set_markup (GTK_LABEL (label), txt);
3062 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3063 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3066 gtk_container_add (GTK_CONTAINER (expander), label);
3067 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3070 g_signal_connect (info_bar, "response",
3071 G_CALLBACK (on_error_infobar_response_cb), NULL);
3073 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3074 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3075 gtk_widget_show_all (info_bar);
3080 media_stream_error_to_txt (EmpathyCallWindow *self,
3081 TpCallChannel *call,
3083 TpMediaStreamError error)
3085 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3086 const gchar *cm = NULL;
3092 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3094 return g_strdup_printf (
3095 _("%s's software does not understand any of the audio formats "
3096 "supported by your computer"),
3097 empathy_contact_get_alias (priv->contact));
3099 return g_strdup_printf (
3100 _("%s's software does not understand any of the video formats "
3101 "supported by your computer"),
3102 empathy_contact_get_alias (priv->contact));
3104 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3105 return g_strdup_printf (
3106 _("Can't establish a connection to %s. "
3107 "One of you might be on a network that does not allow "
3108 "direct connections."),
3109 empathy_contact_get_alias (priv->contact));
3111 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3112 return g_strdup (_("There was a failure on the network"));
3114 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3116 return g_strdup (_("The audio formats necessary for this call "
3117 "are not installed on your computer"));
3119 return g_strdup (_("The video formats necessary for this call "
3120 "are not installed on your computer"));
3122 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3123 tp_connection_parse_object_path (
3124 tp_channel_get_connection (TP_CHANNEL (call)),
3127 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3128 "product=Telepathy&component=%s", cm);
3130 result = g_strdup_printf (
3131 _("Something unexpected happened in a Telepathy component. "
3132 "Please <a href=\"%s\">report this bug</a> and attach "
3133 "logs gathered from the 'Debug' window in the Help menu."), url);
3139 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3140 return g_strdup (_("There was a failure in the call engine"));
3142 case TP_MEDIA_STREAM_ERROR_EOS:
3143 return g_strdup (_("The end of the stream was reached"));
3145 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3152 empathy_call_window_stream_error (EmpathyCallWindow *self,
3153 TpCallChannel *call,
3162 desc = media_stream_error_to_txt (self, call, audio, code);
3165 /* No description, use the error message. That's not great as it's not
3166 * localized but it's better than nothing. */
3167 display_error (self, call, icon, title, msg, NULL);
3171 display_error (self, call, icon, title, desc, msg);
3177 empathy_call_window_audio_stream_error (TpCallChannel *call,
3180 EmpathyCallWindow *self)
3182 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3183 "gnome-stock-mic", _("Can't establish audio stream"));
3187 empathy_call_window_video_stream_error (TpCallChannel *call,
3190 EmpathyCallWindow *self)
3192 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3193 "camera-web", _("Can't establish video stream"));
3198 show_balance_error (EmpathyCallWindow *self)
3202 gchar *balance, *tmp;
3203 const gchar *uri, *currency;
3207 g_object_get (self->priv->handler,
3208 "call-channel", &call,
3211 conn = tp_channel_get_connection (call);
3212 g_object_unref (call);
3214 uri = tp_connection_get_balance_uri (conn);
3216 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3218 /* unknown balance */
3219 balance = g_strdup ("(--)");
3223 char *money = empathy_format_currency (amount, scale, currency);
3225 balance = g_strdup_printf ("%s %s",
3230 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3232 display_error (self,
3234 _("Sorry, you don’t have enough credit for that call."),
3238 EMP_RESPONSE_BALANCE);
3245 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3248 EmpathyCallWindow *self)
3250 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3251 TpCallChannel *call;
3252 gboolean can_send_video;
3254 if (state == TP_CALL_STATE_ENDED)
3256 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3257 empathy_call_window_disconnected (self, TRUE);
3258 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3259 show_balance_error (self);
3263 if (state != TP_CALL_STATE_ACCEPTED)
3266 if (priv->call_state == CONNECTED)
3269 g_timer_start (priv->timer);
3270 priv->call_state = CONNECTED;
3272 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3274 can_send_video = priv->video_input != NULL &&
3275 empathy_contact_can_voip_video (priv->contact) &&
3276 tpaw_camera_monitor_get_available (priv->camera_monitor);
3278 g_object_get (priv->handler, "call-channel", &call, NULL);
3280 if (tp_call_channel_has_dtmf (call))
3281 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3283 if (priv->video_input == NULL)
3284 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3286 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3288 empathy_call_window_show_hangup_button (self, TRUE);
3290 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3292 clutter_actor_hide (priv->video_output);
3293 gtk_widget_show (priv->remote_user_avatar_widget);
3295 g_object_unref (call);
3297 g_mutex_lock (&priv->lock);
3299 priv->timer_id = g_timeout_add_seconds (1,
3300 empathy_call_window_update_timer, self);
3302 g_mutex_unlock (&priv->lock);
3304 empathy_call_window_update_timer (self);
3306 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3310 empathy_call_window_show_video_output_cb (gpointer user_data)
3312 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3314 if (self->priv->video_output != NULL)
3316 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3317 clutter_actor_show (self->priv->video_output);
3318 clutter_actor_raise_top (self->priv->overlay_bin);
3325 empathy_call_window_check_video_cb (gpointer data)
3327 EmpathyCallWindow *self = data;
3329 if (self->priv->got_video)
3331 self->priv->got_video = FALSE;
3335 /* No video in the last N seconds, display the remote avatar */
3336 empathy_call_window_show_video_output (self, FALSE);
3341 /* Called from the streaming thread */
3343 static GstPadProbeReturn
3344 empathy_call_window_video_probe_cb (GstPad *pad,
3345 GstPadProbeInfo *info,
3348 EmpathyCallWindow *self = user_data;
3350 if (G_UNLIKELY (!self->priv->got_video))
3352 /* show the remote video */
3353 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3354 empathy_call_window_show_video_output_cb,
3355 g_object_ref (self), g_object_unref);
3357 self->priv->got_video = TRUE;
3360 return GST_PAD_PROBE_OK;
3364 empathy_call_window_video_probe_cb (GstPad *pad,
3365 GstMiniObject *mini_obj,
3366 EmpathyCallWindow *self)
3369 if (GST_IS_EVENT (mini_obj))
3372 if (G_UNLIKELY (!self->priv->got_video))
3374 /* show the remote video */
3375 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3376 empathy_call_window_show_video_output_cb,
3377 g_object_ref (self), g_object_unref);
3379 self->priv->got_video = TRUE;
3386 /* Called from the streaming thread */
3388 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3389 TfContent *content, GstPad *src, gpointer user_data)
3391 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3393 gboolean retval = FALSE;
3398 g_mutex_lock (&priv->lock);
3400 g_object_get (content, "media-type", &media_type, NULL);
3404 case TP_MEDIA_STREAM_TYPE_AUDIO:
3405 pad = empathy_call_window_get_audio_sink_pad (self, content);
3407 case TP_MEDIA_STREAM_TYPE_VIDEO:
3408 g_idle_add (empathy_call_window_show_video_output_cb, self);
3409 pad = empathy_call_window_get_video_sink_pad (self);
3412 gst_pad_add_probe (src,
3413 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3414 empathy_call_window_video_probe_cb, self, NULL);
3416 gst_pad_add_data_probe (src,
3417 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3419 if (priv->got_video_src > 0)
3420 g_source_remove (priv->got_video_src);
3421 priv->got_video_src = g_timeout_add_seconds (1,
3422 empathy_call_window_check_video_cb, self);
3425 g_assert_not_reached ();
3431 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3432 g_warning ("Could not link %s sink pad",
3433 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3437 gst_object_unref (pad);
3441 /* If no sink could be linked, try to add fakesink to prevent the whole call
3446 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3448 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3450 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3451 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3452 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3454 gst_element_set_locked_state (fakesink, TRUE);
3455 gst_element_set_state (fakesink, GST_STATE_NULL);
3456 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3460 DEBUG ("Could not link real sink, linked fakesink instead");
3462 gst_object_unref (sinkpad);
3466 gst_object_unref (fakesink);
3471 g_mutex_unlock (&priv->lock);
3477 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3480 EmpathyCallWindowPriv *priv = self->priv;
3482 g_assert (priv->audio_output_added == FALSE);
3483 g_assert (priv->audio_output == FALSE);
3485 priv->audio_output = empathy_audio_sink_new ();
3486 g_object_ref_sink (priv->audio_output);
3488 /* volume button to output volume linking */
3489 g_object_bind_property (priv->audio_output, "volume",
3490 priv->volume_button, "value",
3491 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3493 g_object_bind_property_full (content, "requested-output-volume",
3494 priv->audio_output, "volume",
3496 audio_control_volume_to_element,
3497 element_volume_to_audio_control,
3500 /* Link volumes together, sync the current audio input volume property
3501 * back to farstream first */
3502 g_object_bind_property_full (priv->audio_output, "volume",
3503 content, "reported-output-volume",
3504 G_BINDING_SYNC_CREATE,
3505 element_volume_to_audio_control,
3506 audio_control_volume_to_element,
3509 /* For raw audio conferences assume that the producer of the raw data
3510 * has already processed it, so turn off any echo cancellation and any
3511 * other audio improvements that come with it */
3512 empathy_audio_sink_set_echo_cancel (
3513 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3514 !empathy_call_window_content_is_raw (content));
3519 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3520 TfContent *content, gpointer user_data)
3522 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3525 FsMediaType media_type;
3526 gboolean retval = FALSE;
3528 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3529 g_assert (sink != NULL);
3533 case FS_MEDIA_TYPE_AUDIO:
3535 /* For raw audio conferences assume that the receiver of the raw data
3536 * wants it unprocessed, so turn off any echo cancellation and any
3537 * other audio improvements that come with it */
3538 empathy_audio_src_set_echo_cancel (
3539 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3540 !empathy_call_window_content_is_raw (content));
3542 /* Link volumes together, sync the current audio input volume property
3543 * back to farstream first */
3544 g_object_bind_property_full (content, "requested-input-volume",
3545 priv->audio_input, "volume",
3547 audio_control_volume_to_element,
3548 element_volume_to_audio_control,
3551 g_object_bind_property_full (priv->audio_input, "volume",
3552 content, "reported-input-volume",
3553 G_BINDING_SYNC_CREATE,
3554 element_volume_to_audio_control,
3555 audio_control_volume_to_element,
3558 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3560 g_warning ("Could not add audio source to pipeline");
3564 pad = gst_element_get_static_pad (priv->audio_input, "src");
3567 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3568 g_warning ("Could not get source pad from audio source");
3572 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3574 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3575 gst_object_unref (pad);
3576 g_warning ("Could not link audio source to farsight");
3579 gst_object_unref (pad);
3581 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3583 g_warning ("Could not start audio source");
3584 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3585 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3589 /* Prepare our audio output, not added yet though */
3590 empathy_call_window_prepare_audio_output (self, content);
3594 case FS_MEDIA_TYPE_VIDEO:
3595 if (priv->video_tee != NULL)
3598 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3600 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3602 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3604 g_warning ("Could not link video source input pipeline");
3607 gst_object_unref (pad);
3613 g_assert_not_reached ();
3616 gst_object_unref (sink);
3621 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3623 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3624 GstElement *preview;
3626 disable_camera (self);
3628 DEBUG ("remove video input");
3629 preview = priv->video_preview_sink;
3631 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3632 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3633 gst_element_set_state (preview, GST_STATE_NULL);
3635 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3638 g_object_unref (priv->video_input);
3639 priv->video_input = NULL;
3640 g_object_unref (priv->video_tee);
3641 priv->video_tee = NULL;
3642 clutter_actor_destroy (priv->video_preview);
3643 priv->video_preview = NULL;
3645 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3646 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3650 start_call (EmpathyCallWindow *self)
3652 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3654 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3656 priv->call_started = TRUE;
3657 empathy_call_handler_start_call (priv->handler,
3658 gtk_get_current_event_time ());
3660 if (empathy_call_handler_has_initial_video (priv->handler))
3662 TpCallChannel *call;
3665 g_object_get (priv->handler, "call-channel", &call, NULL);
3666 /* If the call channel isn't set yet we're requesting it, if we're
3667 * requesting it with initial video it should be PENDING_SEND when we get
3670 s = TP_SENDING_STATE_PENDING_SEND;
3672 s = empathy_call_channel_get_video_state (call);
3674 if (s == TP_SENDING_STATE_PENDING_SEND ||
3675 s == TP_SENDING_STATE_SENDING)
3677 /* Enable 'send video' buttons and display the preview */
3678 gtk_toggle_button_set_active (
3679 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3683 gtk_toggle_button_set_active (
3684 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3686 if (priv->video_preview == NULL)
3688 create_video_preview (self);
3689 add_video_preview_to_pipeline (self);
3694 g_object_unref (call);
3699 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3702 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3703 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3704 GstState newstate, pending;
3706 empathy_call_handler_bus_message (priv->handler, bus, message);
3708 switch (GST_MESSAGE_TYPE (message))
3710 case GST_MESSAGE_STATE_CHANGED:
3711 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3713 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3715 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3716 !priv->call_started)
3718 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3719 if (newstate == GST_STATE_PAUSED)
3721 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3722 priv->pipeline_playing = TRUE;
3724 if (priv->start_call_when_playing)
3728 if (priv->video_preview_sink != NULL &&
3729 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3731 gst_message_parse_state_changed (message, NULL, &newstate,
3734 if (newstate == GST_STATE_PLAYING &&
3735 pending == GST_STATE_VOID_PENDING)
3736 empathy_call_window_stop_camera_spinning (self);
3739 case GST_MESSAGE_ERROR:
3741 GError *error = NULL;
3742 GstElement *gst_error;
3746 gst_message_parse_error (message, &error, &debug);
3747 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3749 g_message ("Element error: %s -- %s\n", error->message, debug);
3751 name = gst_element_get_name (gst_error);
3752 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3754 /* Remove the video input and continue */
3755 if (priv->video_input != NULL)
3756 empathy_call_window_remove_video_input (self);
3757 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3761 empathy_call_window_disconnected (self, TRUE);
3764 g_error_free (error);
3767 case GST_MESSAGE_UNKNOWN:
3768 case GST_MESSAGE_EOS:
3769 case GST_MESSAGE_WARNING:
3770 case GST_MESSAGE_INFO:
3771 case GST_MESSAGE_TAG:
3772 case GST_MESSAGE_BUFFERING:
3773 case GST_MESSAGE_STATE_DIRTY:
3774 case GST_MESSAGE_STEP_DONE:
3775 case GST_MESSAGE_CLOCK_PROVIDE:
3776 case GST_MESSAGE_CLOCK_LOST:
3777 case GST_MESSAGE_NEW_CLOCK:
3778 case GST_MESSAGE_STRUCTURE_CHANGE:
3779 case GST_MESSAGE_STREAM_STATUS:
3780 case GST_MESSAGE_APPLICATION:
3781 case GST_MESSAGE_ELEMENT:
3782 case GST_MESSAGE_SEGMENT_START:
3783 case GST_MESSAGE_SEGMENT_DONE:
3784 case GST_MESSAGE_DURATION:
3785 case GST_MESSAGE_ANY:
3794 empathy_call_window_members_changed_cb (TpCallChannel *call,
3795 GHashTable *updates,
3797 TpCallStateReason *reason,
3798 EmpathyCallWindow *self)
3800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3801 GHashTableIter iter;
3802 gpointer key, value;
3803 gboolean held = FALSE;
3805 g_hash_table_iter_init (&iter, updates);
3806 while (g_hash_table_iter_next (&iter, &key, &value))
3808 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3810 /* This assumes this is a 1-1 call, otherwise one participant
3811 * putting the call on hold wouldn't mean the call is on hold
3819 priv->call_state = HELD;
3820 else if (priv->call_state == HELD)
3821 priv->call_state = CONNECTED;
3825 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3827 EmpathyCallWindow *self)
3829 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3830 TpCallChannel *call;
3832 g_object_get (priv->handler, "call-channel", &call, NULL);
3837 tp_g_signal_connect_object (call, "audio-stream-error",
3838 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3839 tp_g_signal_connect_object (call, "video-stream-error",
3840 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3843 tp_g_signal_connect_object (call, "members-changed",
3844 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3846 g_object_unref (call);
3850 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3852 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3853 TpCallChannel *call;
3855 g_signal_connect (priv->handler, "state-changed",
3856 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3857 g_signal_connect (priv->handler, "conference-added",
3858 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3859 g_signal_connect (priv->handler, "conference-removed",
3860 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3861 g_signal_connect (priv->handler, "closed",
3862 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3863 g_signal_connect (priv->handler, "src-pad-added",
3864 G_CALLBACK (empathy_call_window_src_added_cb), self);
3865 g_signal_connect (priv->handler, "content-added",
3866 G_CALLBACK (empathy_call_window_content_added_cb), self);
3867 g_signal_connect (priv->handler, "content-removed",
3868 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3870 /* We connect to ::call-channel unconditionally since we'll
3871 * get new channels if we hangup and redial or if we reuse the
3873 g_signal_connect (priv->handler, "notify::call-channel",
3874 G_CALLBACK (call_handler_notify_call_cb), self);
3876 g_signal_connect (priv->handler, "framerate-changed",
3877 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3878 g_signal_connect (priv->handler, "resolution-changed",
3879 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3881 g_object_get (priv->handler, "call-channel", &call, NULL);
3884 /* We won't get notify::call-channel for this channel, so
3885 * directly call the callback. */
3886 call_handler_notify_call_cb (priv->handler, NULL, self);
3887 g_object_unref (call);
3892 empathy_call_window_realized_cb (GtkWidget *widget,
3893 EmpathyCallWindow *self)
3897 /* Make the hangup button twice as wide */
3898 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3899 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3901 empathy_call_window_connect_handler (self);
3903 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3907 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3908 EmpathyCallWindow *window)
3910 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3912 if (priv->pipeline != NULL)
3914 if (priv->bus_message_source_id != 0)
3916 g_source_remove (priv->bus_message_source_id);
3917 priv->bus_message_source_id = 0;
3920 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3923 if (priv->call_state == CONNECTING)
3924 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3930 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3933 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3935 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3940 gtk_widget_hide (priv->dtmf_panel);
3941 gtk_widget_hide (menu);
3942 gtk_widget_hide (priv->toolbar);
3946 if (priv->dialpad_was_visible_before_fs)
3947 gtk_widget_show (priv->dtmf_panel);
3949 gtk_widget_show (menu);
3950 gtk_widget_show (priv->toolbar);
3952 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3953 priv->original_height_before_fs);
3958 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3960 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3962 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3963 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3965 if (priv->video_output != NULL)
3968 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3969 priv->video_output, TRUE, TRUE,
3970 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3977 empathy_call_window_state_event_cb (GtkWidget *widget,
3978 GdkEventWindowState *event, EmpathyCallWindow *window)
3980 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3982 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3983 gboolean set_fullscreen = event->new_window_state &
3984 GDK_WINDOW_STATE_FULLSCREEN;
3988 gboolean dialpad_was_visible;
3989 GtkAllocation allocation;
3990 gint original_width, original_height;
3992 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3993 original_width = allocation.width;
3994 original_height = allocation.height;
3996 g_object_get (priv->dtmf_panel,
3997 "visible", &dialpad_was_visible,
4000 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4001 priv->original_width_before_fs = original_width;
4002 priv->original_height_before_fs = original_height;
4004 if (priv->video_output_motion_handler_id == 0 &&
4005 priv->video_output != NULL)
4007 priv->video_output_motion_handler_id = g_signal_connect (
4008 G_OBJECT (priv->video_container), "motion-notify-event",
4009 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4015 disconnect_video_output_motion_handler (window);
4018 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4020 show_controls (window, set_fullscreen);
4021 show_borders (window, set_fullscreen);
4022 gtk_action_set_stock_id (priv->menu_fullscreen,
4023 (set_fullscreen ? "view-restore" : "view-fullscreen"));
4024 priv->is_fullscreen = set_fullscreen;
4031 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4034 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4035 int w, h, dialpad_width;
4036 GtkAllocation allocation;
4038 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4039 w = allocation.width;
4040 h = allocation.height;
4042 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4046 gtk_widget_show (priv->dtmf_panel);
4052 gtk_widget_hide (priv->dtmf_panel);
4056 gtk_window_resize (GTK_WINDOW (window), w, h);
4060 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4063 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4064 TpCallChannel *call;
4066 priv->sending_video = (state == CAMERA_STATE_ON);
4068 if (state == CAMERA_STATE_ON)
4070 /* When we start sending video, we want to show the video preview by
4072 display_video_preview (window, TRUE);
4076 display_video_preview (window, FALSE);
4079 if (priv->call_state != CONNECTED)
4082 g_object_get (priv->handler, "call-channel", &call, NULL);
4083 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4084 empathy_call_channel_send_video (call, priv->sending_video);
4085 g_object_unref (call);
4089 empathy_call_window_hangup_cb (gpointer object,
4090 EmpathyCallWindow *self)
4092 /* stopping the call will put it the ENDED state and
4093 * from state_changed_cb we'll reconfigure the window
4095 empathy_call_handler_stop_call (self->priv->handler);
4099 empathy_call_window_restart_call (EmpathyCallWindow *window)
4101 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4103 /* Remove error info bars */
4104 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4105 (GtkCallback) gtk_widget_destroy, NULL);
4107 create_video_output_widget (window);
4108 priv->outgoing = TRUE;
4109 empathy_call_window_set_state_connecting (window);
4111 if (priv->pipeline_playing)
4112 start_call (window);
4114 /* call will be started when the pipeline is ready */
4115 priv->start_call_when_playing = TRUE;
4117 empathy_call_window_setup_avatars (window, priv->handler);
4119 empathy_call_window_show_hangup_button (window, TRUE);
4123 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4124 EmpathyCallWindow *window)
4128 active = gtk_toggle_tool_button_get_active (button);
4130 empathy_call_window_show_dialpad (window, active);
4134 empathy_call_window_fullscreen_cb (gpointer object,
4135 EmpathyCallWindow *window)
4137 empathy_call_window_fullscreen_toggle (window);
4141 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4143 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4145 if (priv->is_fullscreen)
4146 gtk_window_unfullscreen (GTK_WINDOW (window));
4148 gtk_window_fullscreen (GTK_WINDOW (window));
4152 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4153 GdkEventButton *event, EmpathyCallWindow *window)
4155 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4157 empathy_call_window_video_menu_popup (window, event->button);
4165 empathy_call_window_key_press_cb (GtkWidget *video_output,
4166 GdkEventKey *event, EmpathyCallWindow *window)
4168 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4171 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4173 /* Since we are in fullscreen mode, toggling will bring us back to
4175 empathy_call_window_fullscreen_toggle (window);
4179 key = gdk_keyval_to_unicode (event->keyval);
4200 gtk_toggle_tool_button_set_active (
4201 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4203 empathy_dialpad_widget_press_key (
4204 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4210 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4211 GdkEventMotion *event, EmpathyCallWindow *window)
4213 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4215 if (priv->is_fullscreen)
4217 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4219 /* Show the bottom toolbar */
4220 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4227 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4231 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4233 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4235 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4236 button, gtk_get_current_event_time ());
4237 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4241 empathy_call_window_status_message (EmpathyCallWindow *self,
4244 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4248 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4250 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4252 return priv->ui_manager;
4255 EmpathyGstAudioSrc *
4256 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4258 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4260 return (EmpathyGstAudioSrc *) priv->audio_input;
4263 EmpathyGstVideoSrc *
4264 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4266 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4270 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4271 const gchar *device)
4273 EmpathyGstVideoSrc *video;
4276 /* Restart the camera only if it's already running */
4277 running = (self->priv->video_preview != NULL);
4278 video = empathy_call_window_get_video_src (self);
4281 empathy_call_window_play_camera (self, FALSE);
4283 empathy_video_src_change_device (video, device);
4286 empathy_call_window_play_camera (self, TRUE);