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>
29 #include "empathy-about-dialog.h"
30 #include "empathy-audio-sink.h"
31 #include "empathy-call-utils.h"
32 #include "empathy-call-window-fullscreen.h"
33 #include "empathy-camera-menu.h"
34 #include "empathy-camera-monitor.h"
35 #include "empathy-dialpad-widget.h"
36 #include "empathy-geometry.h"
37 #include "empathy-gsettings.h"
38 #include "empathy-images.h"
39 #include "empathy-mic-menu.h"
40 #include "empathy-preferences.h"
41 #include "empathy-request-util.h"
42 #include "empathy-rounded-actor.h"
43 #include "empathy-rounded-rectangle.h"
44 #include "empathy-rounded-texture.h"
45 #include "empathy-sound-manager.h"
46 #include "empathy-ui-utils.h"
47 #include "empathy-utils.h"
49 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
50 #include "empathy-debug.h"
52 #define CONTENT_HBOX_SPACING 3
53 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
54 #define OVERLAY_MARGIN 6
56 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
57 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
59 #define SELF_VIDEO_SECTION_WIDTH 120
60 #define SELF_VIDEO_SECTION_HEIGHT 90
61 #define SELF_VIDEO_SECTION_MARGIN 2
62 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
64 /* The avatar's default width and height are set to the same value because we
65 want a square icon. */
66 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
67 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
69 #define SMALL_TOOLBAR_SIZE 36
71 /* If an video input error occurs, the error message will start with "v4l" */
72 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
74 /* The time interval in milliseconds between 2 outgoing rings */
75 #define MS_BETWEEN_RING 500
77 /* The roundedness of preview box and placeholders */
78 #define PREVIEW_ROUND_FACTOR 16
80 #define PREVIEW_BUTTON_OPACITY 180
82 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
85 PROP_CALL_HANDLER = 1,
93 static guint signals[LAST_SIGNAL];
96 RINGING, /* Incoming call */
97 CONNECTING, /* Outgoing call */
98 CONNECTED, /* Connected */
99 HELD, /* Connected, but on hold */
100 DISCONNECTED, /* Disconnected */
101 REDIALING /* Redialing (special case of CONNECTING) */
105 CAMERA_STATE_OFF = 0,
111 PREVIEW_POS_TOP_LEFT,
112 PREVIEW_POS_TOP_RIGHT,
113 PREVIEW_POS_BOTTOM_LEFT,
114 PREVIEW_POS_BOTTOM_RIGHT,
117 struct _EmpathyCallWindowPriv
119 gboolean dispose_has_run;
120 EmpathyCallHandler *handler;
122 EmpathyContact *contact;
124 EmpathyCameraMonitor *camera_monitor;
126 CallState call_state;
129 GtkUIManager *ui_manager;
130 GtkWidget *errors_vbox;
131 /* widget displays the video received from the remote user. This widget is
132 * alive only during call. */
133 ClutterActor *video_output;
134 ClutterActor *video_preview;
135 ClutterActor *drag_preview;
136 ClutterActor *preview_shown_button;
137 ClutterActor *preview_hidden_button;
138 ClutterActor *preview_rectangle1;
139 ClutterActor *preview_rectangle2;
140 ClutterActor *preview_rectangle3;
141 ClutterActor *preview_rectangle4;
142 ClutterActor *preview_spinner_actor;
143 GtkWidget *preview_spinner_widget;
144 GtkWidget *video_container;
145 GtkWidget *remote_user_avatar_widget;
146 GtkWidget *remote_user_avatar_toolbar;
147 GtkWidget *remote_user_name_toolbar;
148 GtkWidget *remote_user_status_toolbar;
149 GtkWidget *status_label;
150 GtkWidget *hangup_button;
151 GtkWidget *audio_call_button;
152 GtkWidget *video_call_button;
153 GtkWidget *mic_button;
154 GtkWidget *microphone_icon;
155 GtkWidget *volume_button;
156 GtkWidget *camera_button;
157 GtkWidget *dialpad_button;
159 GtkWidget *bottom_toolbar;
160 ClutterActor *floating_toolbar;
162 GtkAction *menu_fullscreen;
163 GtkAction *menu_swap_camera;
165 ClutterState *transitions;
167 /* The main box covering all the stage, contaning remote avatar/video */
168 ClutterActor *video_box;
169 ClutterLayoutManager *video_layout;
171 /* A bin layout manager containing a bin for previews
172 * and the floating toolbar */
173 ClutterActor *overlay_bin;
174 ClutterLayoutManager *overlay_layout;
176 /* Bin layout for the previews */
177 ClutterActor *preview_box;
178 ClutterLayoutManager *preview_layout;
180 /* Coordinates of the preview drag event's start. */
181 PreviewPosition preview_pos;
183 /* We keep a reference on the hbox which contains the main content so we can
184 easilly repack everything when toggling fullscreen */
185 GtkWidget *content_hbox;
187 /* These are used to accept or reject an incoming call when the status
189 GtkWidget *incoming_call_dialog;
190 TpCallChannel *pending_channel;
191 TpChannelDispatchOperation *pending_cdo;
192 TpAddDispatchOperationContext *pending_context;
194 gulong video_output_motion_handler_id;
195 guint bus_message_source_id;
197 GtkWidget *dtmf_panel;
200 GtkWidget *details_vbox;
201 GtkWidget *vcodec_encoding_label;
202 GtkWidget *acodec_encoding_label;
203 GtkWidget *vcodec_decoding_label;
204 GtkWidget *acodec_decoding_label;
206 GtkWidget *audio_remote_candidate_label;
207 GtkWidget *audio_local_candidate_label;
208 GtkWidget *video_remote_candidate_label;
209 GtkWidget *video_local_candidate_label;
210 GtkWidget *video_remote_candidate_info_img;
211 GtkWidget *video_local_candidate_info_img;
212 GtkWidget *audio_remote_candidate_info_img;
213 GtkWidget *audio_local_candidate_info_img;
215 GstElement *video_input;
216 GstElement *video_preview_sink;
217 GstElement *video_output_sink;
218 GstElement *audio_input;
219 GstElement *audio_output;
220 gboolean audio_output_added;
221 GstElement *pipeline;
222 GstElement *video_tee;
232 gboolean call_started;
233 gboolean sending_video;
234 CameraState camera_state;
236 EmpathyCallWindowFullscreen *fullscreen;
237 gboolean is_fullscreen;
242 guint inactivity_src;
244 /* Those fields represent the state of the window before it actually was in
246 gboolean dialpad_was_visible_before_fs;
247 gint original_width_before_fs;
248 gint original_height_before_fs;
250 gint x, y, w, h, dialpad_width;
253 /* TRUE if the call should be started when the pipeline is playing */
254 gboolean start_call_when_playing;
255 /* TRUE if we requested to set the pipeline in the playing state */
256 gboolean pipeline_playing;
258 EmpathySoundManager *sound_mgr;
261 EmpathyMicMenu *mic_menu;
262 EmpathyCameraMenu *camera_menu;
267 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
269 static void empathy_call_window_realized_cb (GtkWidget *widget,
270 EmpathyCallWindow *window);
272 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
273 GdkEvent *event, EmpathyCallWindow *window);
275 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
276 GdkEventWindowState *event, EmpathyCallWindow *window);
278 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
281 static void empathy_call_window_hangup_cb (gpointer object,
282 EmpathyCallWindow *window);
284 static void empathy_call_window_fullscreen_cb (gpointer object,
285 EmpathyCallWindow *window);
287 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
289 static gboolean empathy_call_window_video_button_press_cb (
290 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
292 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
293 GdkEventKey *event, EmpathyCallWindow *window);
295 static gboolean empathy_call_window_video_output_motion_notify (
296 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
298 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
301 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
303 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
304 EmpathyCallWindow *window);
306 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
308 static void empathy_call_window_status_message (EmpathyCallWindow *window,
311 static gboolean empathy_call_window_bus_message (GstBus *bus,
312 GstMessage *message, gpointer user_data);
314 static gboolean empathy_call_window_update_timer (gpointer user_data);
317 make_background_transparent (GtkClutterActor *actor)
319 GdkRGBA transparent = { 0., 0., 0., 0. };
322 widget = gtk_clutter_actor_get_widget (actor);
323 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
327 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
330 gtk_widget_set_visible (self->priv->hangup_button, show);
331 gtk_widget_set_visible (self->priv->audio_call_button, !show);
332 gtk_widget_set_visible (self->priv->video_call_button, !show);
336 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
337 EmpathyCallWindow *self)
339 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
340 empathy_call_window_restart_call (self);
344 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
345 EmpathyCallWindow *self)
347 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
348 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
349 empathy_call_window_restart_call (self);
353 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
355 EmpathyCallWindow *self)
360 g_object_get (self->priv->handler, "call-channel", &call, NULL);
362 tones[0] = tp_dtmf_event_to_char (event);
364 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
366 g_object_unref (call);
370 empathy_call_window_show_video_output (EmpathyCallWindow *self,
373 if (self->priv->video_output != NULL)
374 g_object_set (self->priv->video_output, "visible", show, NULL);
376 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
378 clutter_actor_raise_top (self->priv->overlay_bin);
382 create_video_output_widget (EmpathyCallWindow *self)
384 EmpathyCallWindowPriv *priv = GET_PRIV (self);
386 g_assert (priv->video_output == NULL);
387 g_assert (priv->pipeline != NULL);
389 priv->video_output = clutter_texture_new ();
391 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
394 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
395 if (priv->video_output_sink == NULL)
396 g_error ("Missing cluttersink");
398 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
400 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
403 gtk_widget_add_events (priv->video_container,
404 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
405 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
406 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
410 create_video_input (EmpathyCallWindow *self)
412 EmpathyCallWindowPriv *priv = GET_PRIV (self);
414 g_assert (priv->video_input == NULL);
415 priv->video_input = empathy_video_src_new ();
416 gst_object_ref_sink (priv->video_input);
420 audio_control_volume_to_element (GBinding *binding,
421 const GValue *source_value,
422 GValue *target_value,
425 /* AudioControl volume is 0-255, with -1 for unknown */
428 hv = g_value_get_int (source_value);
433 g_value_set_double (target_value, hv/255.0);
439 element_volume_to_audio_control (GBinding *binding,
440 const GValue *source_value,
441 GValue *target_value,
446 ev = g_value_get_double (source_value);
447 ev = CLAMP (ev, 0.0, 1.0);
449 g_value_set_int (target_value, ev * 255);
454 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
455 EmpathyCallWindow *self)
458 g_object_get (obj, "mute", &muted, NULL);
460 self->priv->muted = muted;
461 if (muted && self->priv->transitions)
462 clutter_state_set_state (self->priv->transitions, "fade-in");
466 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
467 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
471 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
472 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
475 empathy_call_window_update_timer (self);
479 create_audio_input (EmpathyCallWindow *self)
481 EmpathyCallWindowPriv *priv = GET_PRIV (self);
483 g_assert (priv->audio_input == NULL);
484 priv->audio_input = empathy_audio_src_new ();
485 gst_object_ref_sink (priv->audio_input);
487 g_signal_connect (priv->audio_input, "notify::mute",
488 G_CALLBACK (audio_input_mute_notify_cb), self);
492 add_video_preview_to_pipeline (EmpathyCallWindow *self)
494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
497 g_assert (priv->video_preview != NULL);
498 g_assert (priv->pipeline != NULL);
499 g_assert (priv->video_input != NULL);
500 g_assert (priv->video_tee != NULL);
502 preview = priv->video_preview_sink;
504 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
506 g_warning ("Could not add video input to pipeline");
510 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
512 g_warning ("Could not add video preview to pipeline");
516 if (!gst_element_link (priv->video_input, priv->video_tee))
518 g_warning ("Could not link video input to video tee");
522 if (!gst_element_link (priv->video_tee, preview))
524 g_warning ("Could not link video tee to video preview");
530 empathy_call_window_disable_camera_cb (GtkAction *action,
531 EmpathyCallWindow *self)
533 clutter_actor_destroy (self->priv->preview_hidden_button);
535 gtk_toggle_button_set_active (
536 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
540 empathy_call_window_minimise_camera_cb (GtkAction *action,
541 EmpathyCallWindow *self)
543 clutter_actor_hide (self->priv->video_preview);
544 clutter_actor_show (self->priv->preview_hidden_button);
548 empathy_call_window_maximise_camera_cb (GtkAction *action,
549 EmpathyCallWindow *self)
551 clutter_actor_show (self->priv->video_preview);
552 clutter_actor_hide (self->priv->preview_hidden_button);
556 empathy_call_window_swap_camera_cb (GtkAction *action,
557 EmpathyCallWindow *self)
559 const GList *cameras, *l;
562 DEBUG ("Swapping the camera");
564 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
565 current_cam = empathy_video_src_dup_device (
566 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
568 for (l = cameras; l != NULL; l = l->next)
570 EmpathyCamera *camera = l->data;
572 if (!tp_strdiff (camera->device, current_cam))
577 next = l->next->data;
579 next = cameras->data;
581 /* EmpathyCameraMenu will update itself and do the actual change
583 g_settings_set_string (self->priv->settings,
584 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
591 g_free (current_cam);
595 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
596 EmpathyCamera *camera,
597 EmpathyCallWindow *self)
599 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
601 gtk_action_set_visible (self->priv->menu_swap_camera,
602 g_list_length ((GList *) cameras) >= 2);
606 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
607 EmpathyCamera *camera,
608 EmpathyCallWindow *self)
610 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
612 gtk_action_set_visible (self->priv->menu_swap_camera,
613 g_list_length ((GList *) cameras) >= 2);
617 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
619 EmpathyCallWindow *self)
623 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
625 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
626 0, gtk_get_current_event_time ());
627 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
631 empathy_call_window_preview_hidden_button_clicked_cb (
632 ClutterClickAction *action,
634 EmpathyCallWindow *self)
638 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
639 "/preview-hidden-menu");
640 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
641 0, gtk_get_current_event_time ());
642 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
645 static ClutterActor *
646 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
647 ClutterBinAlignment x,
648 ClutterBinAlignment y)
650 ClutterActor *rectangle;
652 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
653 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
654 PREVIEW_ROUND_FACTOR));
656 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
658 clutter_actor_hide (rectangle);
664 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
668 self->priv->preview_layout = clutter_bin_layout_new (
669 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
670 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
672 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
674 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
676 self->priv->preview_rectangle1 =
677 empathy_call_window_create_preview_rectangle (self,
678 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
679 self->priv->preview_rectangle2 =
680 empathy_call_window_create_preview_rectangle (self,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
682 self->priv->preview_rectangle3 =
683 empathy_call_window_create_preview_rectangle (self,
684 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
685 self->priv->preview_rectangle4 =
686 empathy_call_window_create_preview_rectangle (self,
687 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
691 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
694 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
695 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
696 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
697 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
701 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
706 guint ret_x = 0, ret_y = 0;
709 if (!clutter_actor_has_allocation (self->priv->preview_box))
712 clutter_actor_get_geometry (self->priv->preview_box, &box);
716 case PREVIEW_POS_TOP_LEFT:
717 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
719 case PREVIEW_POS_TOP_RIGHT:
720 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
721 - SELF_VIDEO_SECTION_WIDTH;
722 ret_y = SELF_VIDEO_SECTION_MARGIN;
724 case PREVIEW_POS_BOTTOM_LEFT:
725 ret_x = SELF_VIDEO_SECTION_MARGIN;
726 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
727 - SELF_VIDEO_SECTION_HEIGHT;
729 case PREVIEW_POS_BOTTOM_RIGHT:
730 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
731 - SELF_VIDEO_SECTION_WIDTH;
732 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
733 - SELF_VIDEO_SECTION_HEIGHT;
736 g_warn_if_reached ();
747 static PreviewPosition
748 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
753 PreviewPosition pos = PREVIEW_POS_NONE;
755 if (!clutter_actor_has_allocation (self->priv->preview_box))
758 clutter_actor_get_geometry (self->priv->preview_box, &box);
760 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
761 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
762 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
763 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
765 pos = PREVIEW_POS_TOP_LEFT;
767 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
768 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
769 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
770 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
772 pos = PREVIEW_POS_TOP_RIGHT;
774 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
775 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
776 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
777 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
779 pos = PREVIEW_POS_BOTTOM_LEFT;
781 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
782 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
783 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
784 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
786 pos = PREVIEW_POS_BOTTOM_RIGHT;
792 static ClutterActor *
793 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
796 ClutterActor *rectangle;
800 case PREVIEW_POS_TOP_LEFT:
801 rectangle = self->priv->preview_rectangle1;
803 case PREVIEW_POS_TOP_RIGHT:
804 rectangle = self->priv->preview_rectangle3;
806 case PREVIEW_POS_BOTTOM_LEFT:
807 rectangle = self->priv->preview_rectangle2;
809 case PREVIEW_POS_BOTTOM_RIGHT:
810 rectangle = self->priv->preview_rectangle4;
820 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
823 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
825 DEBUG ("moving the video preview to %d", pos);
827 self->priv->preview_pos = pos;
831 case PREVIEW_POS_TOP_LEFT:
832 clutter_bin_layout_set_alignment (layout,
833 self->priv->video_preview,
834 CLUTTER_BIN_ALIGNMENT_START,
835 CLUTTER_BIN_ALIGNMENT_START);
837 case PREVIEW_POS_TOP_RIGHT:
838 clutter_bin_layout_set_alignment (layout,
839 self->priv->video_preview,
840 CLUTTER_BIN_ALIGNMENT_END,
841 CLUTTER_BIN_ALIGNMENT_START);
843 case PREVIEW_POS_BOTTOM_LEFT:
844 clutter_bin_layout_set_alignment (layout,
845 self->priv->video_preview,
846 CLUTTER_BIN_ALIGNMENT_START,
847 CLUTTER_BIN_ALIGNMENT_END);
849 case PREVIEW_POS_BOTTOM_RIGHT:
850 clutter_bin_layout_set_alignment (layout,
851 self->priv->video_preview,
852 CLUTTER_BIN_ALIGNMENT_END,
853 CLUTTER_BIN_ALIGNMENT_END);
856 g_warn_if_reached ();
859 g_settings_set_enum (self->priv->settings, "camera-position", pos);
863 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
866 ClutterActor *rectangle;
867 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
869 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
871 empathy_rounded_rectangle_set_border_width (
872 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
873 empathy_rounded_rectangle_set_border_color (
874 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
878 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
879 ClutterActor *rectangle)
881 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
883 clutter_color_shade (&white, 0.55, &darker);
885 empathy_rounded_rectangle_set_border_width (
886 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
887 empathy_rounded_rectangle_set_border_color (
888 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
892 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
894 ClutterActor *rectangle;
896 rectangle = empathy_call_window_get_preview_rectangle (self,
897 self->priv->preview_pos);
899 /* We don't want to darken the rectangle where the preview
902 if (self->priv->preview_rectangle1 != rectangle)
903 empathy_call_window_darken_preview_rectangle (self,
904 self->priv->preview_rectangle1);
906 if (self->priv->preview_rectangle2 != rectangle)
907 empathy_call_window_darken_preview_rectangle (self,
908 self->priv->preview_rectangle2);
910 if (self->priv->preview_rectangle3 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle3);
914 if (self->priv->preview_rectangle4 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle4);
920 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
924 ClutterModifierType modifiers,
925 EmpathyCallWindow *self)
927 ClutterActor *stage = clutter_actor_get_stage (actor);
930 self->priv->drag_preview = clutter_clone_new (actor);
932 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
933 self->priv->drag_preview);
935 clutter_actor_transform_stage_point (actor, event_x, event_y,
938 clutter_actor_set_position (self->priv->drag_preview,
939 event_x - rel_x, event_y - rel_y);
941 clutter_drag_action_set_drag_handle (action,
942 self->priv->drag_preview);
944 clutter_actor_set_opacity (actor, 0);
945 clutter_actor_hide (self->priv->preview_shown_button);
947 empathy_call_window_show_preview_rectangles (self, TRUE);
948 empathy_call_window_darken_preview_rectangles (self);
952 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
955 clutter_actor_set_opacity (actor, 255);
959 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
963 ClutterModifierType modifiers,
964 EmpathyCallWindow *self)
969 /* Get the position before destroying the drag actor, otherwise the
970 * preview_box allocation won't be valid and we won't be able to
971 * calculate the position. */
972 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
974 empathy_call_window_get_preview_coordinates (self,
975 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
978 /* Move the preview to the destination and destroy it afterwards */
979 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
982 "signal-swapped-after::completed",
983 clutter_actor_destroy, self->priv->drag_preview,
984 "signal-swapped-after::completed",
985 clutter_actor_show, self->priv->preview_shown_button,
987 empathy_call_window_on_animation_completed_cb, actor,
990 self->priv->drag_preview = NULL;
992 if (pos != PREVIEW_POS_NONE)
993 empathy_call_window_move_video_preview (self, pos);
995 empathy_call_window_show_preview_rectangles (self, FALSE);
999 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1000 ClutterActor *actor,
1003 EmpathyCallWindow *self)
1005 PreviewPosition pos;
1006 gfloat event_x, event_y;
1008 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1010 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1012 if (pos != PREVIEW_POS_NONE)
1013 empathy_call_window_highlight_preview_rectangle (self, pos);
1015 empathy_call_window_darken_preview_rectangles (self);
1019 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1020 ClutterCrossingEvent *event,
1021 EmpathyCallWindow *self)
1023 ClutterActor *rectangle;
1025 rectangle = empathy_call_window_get_preview_rectangle (self,
1026 self->priv->preview_pos);
1028 empathy_call_window_highlight_preview_rectangle (self,
1029 self->priv->preview_pos);
1031 clutter_actor_show (rectangle);
1037 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1038 ClutterCrossingEvent *event,
1039 EmpathyCallWindow *self)
1041 ClutterActor *rectangle;
1043 rectangle = empathy_call_window_get_preview_rectangle (self,
1044 self->priv->preview_pos);
1046 empathy_call_window_darken_preview_rectangle (self, rectangle);
1048 clutter_actor_hide (rectangle);
1054 create_video_preview (EmpathyCallWindow *self)
1056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1057 ClutterLayoutManager *layout;
1058 ClutterActor *preview;
1060 ClutterAction *action;
1061 PreviewPosition pos;
1063 g_assert (priv->video_preview == NULL);
1065 pos = g_settings_get_enum (priv->settings, "camera-position");
1067 preview = empathy_rounded_texture_new ();
1068 clutter_actor_set_size (preview,
1069 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1071 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1072 if (priv->video_preview_sink == NULL)
1073 g_error ("Missing cluttersink, check your clutter-gst installation");
1074 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1075 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1077 /* Add a little offset to the video preview */
1078 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1079 CLUTTER_BIN_ALIGNMENT_CENTER);
1080 priv->video_preview = clutter_box_new (layout);
1081 clutter_actor_set_size (priv->video_preview,
1082 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1083 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1085 /* Spinner for when changing the camera device */
1086 priv->preview_spinner_widget = gtk_spinner_new ();
1087 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1089 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1090 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1091 gtk_widget_show (priv->preview_spinner_widget);
1094 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1095 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1096 priv->preview_spinner_widget);
1097 clutter_actor_set_size (priv->preview_spinner_actor,
1098 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1099 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1100 clutter_actor_hide (priv->preview_spinner_actor);
1102 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1104 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1105 priv->preview_spinner_actor);
1107 g_object_set (priv->video_preview_sink,
1113 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1114 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1115 GTK_ICON_SIZE_MENU));
1116 clutter_actor_set_margin_right (b, 4);
1117 clutter_actor_set_margin_bottom (b, 2);
1118 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1119 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1121 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1122 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1124 action = clutter_click_action_new ();
1125 clutter_actor_add_action (b, action);
1126 g_signal_connect (action, "clicked",
1127 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1129 /* Preview hidden */
1130 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1131 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1132 GTK_ICON_SIZE_MENU));
1133 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1135 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1136 priv->preview_hidden_button,
1137 CLUTTER_BIN_ALIGNMENT_START,
1138 CLUTTER_BIN_ALIGNMENT_END);
1140 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1142 clutter_actor_hide (priv->preview_hidden_button);
1144 action = clutter_click_action_new ();
1145 clutter_actor_add_action (b, action);
1146 g_signal_connect (action, "clicked",
1147 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1149 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1150 priv->video_preview,
1151 CLUTTER_BIN_ALIGNMENT_START,
1152 CLUTTER_BIN_ALIGNMENT_END);
1154 empathy_call_window_move_video_preview (self, pos);
1156 action = clutter_drag_action_new ();
1157 g_signal_connect (action, "drag-begin",
1158 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1159 g_signal_connect (action, "drag-end",
1160 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1161 g_signal_connect (action, "drag-motion",
1162 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1164 g_signal_connect (preview, "enter-event",
1165 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1166 g_signal_connect (preview, "leave-event",
1167 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1169 clutter_actor_add_action (preview, action);
1170 clutter_actor_set_reactive (preview, TRUE);
1171 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1175 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1177 clutter_actor_show (self->priv->preview_spinner_actor);
1178 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1182 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1184 clutter_actor_hide (self->priv->preview_spinner_actor);
1185 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1189 empathy_call_window_play_camera (EmpathyCallWindow *self,
1192 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1193 GstElement *preview;
1196 if (priv->video_preview == NULL)
1198 create_video_preview (self);
1199 add_video_preview_to_pipeline (self);
1204 state = GST_STATE_PLAYING;
1208 empathy_call_window_start_camera_spinning (self);
1209 state = GST_STATE_NULL;
1212 preview = priv->video_preview_sink;
1214 gst_element_set_state (preview, state);
1215 gst_element_set_state (priv->video_tee, state);
1216 gst_element_set_state (priv->video_input, state);
1220 display_video_preview (EmpathyCallWindow *self,
1223 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1225 if (priv->video_preview == NULL)
1227 create_video_preview (self);
1228 add_video_preview_to_pipeline (self);
1233 /* Display the video preview */
1234 DEBUG ("Show video preview");
1236 empathy_call_window_play_camera (self, TRUE);
1237 clutter_actor_show (priv->video_preview);
1238 clutter_actor_raise_top (priv->floating_toolbar);
1242 /* Hide the video preview */
1243 DEBUG ("Hide video preview");
1245 if (priv->video_preview != NULL)
1247 clutter_actor_hide (priv->video_preview);
1248 empathy_call_window_play_camera (self, FALSE);
1254 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1256 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1258 empathy_call_window_status_message (window, _("Connecting…"));
1259 priv->call_state = CONNECTING;
1261 /* Show the toolbar */
1262 clutter_state_set_state (priv->transitions, "fade-in");
1265 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1266 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1270 disable_camera (EmpathyCallWindow *self)
1272 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1274 if (priv->camera_state == CAMERA_STATE_OFF)
1277 DEBUG ("Disable camera");
1279 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1281 priv->camera_state = CAMERA_STATE_OFF;
1285 enable_camera (EmpathyCallWindow *self)
1287 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1289 if (priv->camera_state == CAMERA_STATE_ON)
1292 if (priv->video_input == NULL)
1294 DEBUG ("Can't enable camera, no input");
1298 DEBUG ("Enable camera");
1300 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1302 priv->camera_state = CAMERA_STATE_ON;
1306 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1307 EmpathyCallWindow *self)
1309 if (gtk_toggle_button_get_active (toggle))
1310 enable_camera (self);
1312 disable_camera (self);
1316 create_pipeline (EmpathyCallWindow *self)
1318 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1321 g_assert (priv->pipeline == NULL);
1323 priv->pipeline = gst_pipeline_new (NULL);
1324 priv->pipeline_playing = FALSE;
1326 priv->video_tee = gst_element_factory_make ("tee", NULL);
1327 gst_object_ref_sink (priv->video_tee);
1329 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1331 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1332 priv->bus_message_source_id = gst_bus_add_watch (bus,
1333 empathy_call_window_bus_message, self);
1335 g_object_unref (bus);
1339 empathy_call_window_settings_cb (GtkAction *action,
1340 EmpathyCallWindow *self)
1342 gchar *args = g_strdup_printf ("-p %s",
1343 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1345 empathy_launch_program (BIN_DIR, "empathy", args);
1351 empathy_call_window_contents_cb (GtkAction *action,
1352 EmpathyCallWindow *self)
1354 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1358 show_png (GPid pid, gint status, gpointer user_data)
1360 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1361 g_spawn_close_pid (pid);
1366 empathy_call_window_debug_gst_cb (GtkAction *action,
1367 EmpathyCallWindow *self)
1369 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1370 GDateTime *date_time;
1372 const gchar *dot_dir;
1373 const gchar *prgname;
1379 if (priv->pipeline == NULL)
1380 DEBUG ("No pipeline");
1382 date_time = g_date_time_new_now_utc ();
1383 prgname = g_get_prgname ();
1384 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1385 g_date_time_to_unix (date_time));
1387 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1388 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1390 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1391 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1394 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1396 if (g_spawn_async (dot_dir,
1399 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1405 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1406 g_child_watch_add (dot_pid, show_png, uri);
1412 g_date_time_unref (date_time);
1416 empathy_call_window_debug_tp_cb (GtkAction *action,
1417 EmpathyCallWindow *self)
1419 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1423 empathy_call_window_about_cb (GtkAction *action,
1424 EmpathyCallWindow *self)
1426 empathy_about_dialog_new (GTK_WINDOW (self));
1430 empathy_call_window_toolbar_timeout (gpointer data)
1432 EmpathyCallWindow *self = data;
1434 /* We don't want to hide the toolbar if we're not in a call, as
1435 * to show the call status all the time. Also don't hide if we're muted
1436 * to prevent the awkward, talking when muted situation */
1437 if (self->priv->call_state != CONNECTING &&
1438 self->priv->call_state != DISCONNECTED &&
1440 clutter_state_set_state (self->priv->transitions, "fade-out");
1446 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1448 EmpathyCallWindow *self)
1450 clutter_state_set_state (self->priv->transitions, "fade-in");
1452 if (self->priv->inactivity_src > 0)
1453 g_source_remove (self->priv->inactivity_src);
1455 self->priv->inactivity_src = g_timeout_add_seconds (3,
1456 empathy_call_window_toolbar_timeout, self);
1462 empathy_call_window_configure_event_cb (GtkWidget *widget,
1464 EmpathyCallWindow *self)
1466 GdkWindow *gdk_window;
1467 GdkWindowState window_state;
1469 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1470 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1472 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1473 &self->priv->dialpad_width, NULL);
1475 gdk_window = gtk_widget_get_window (widget);
1476 window_state = gdk_window_get_state (gdk_window);
1477 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1483 empathy_call_window_destroyed_cb (GtkWidget *object,
1484 EmpathyCallWindow *self)
1486 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1488 /* Save the geometry as if the dialpad was hidden. */
1489 empathy_geometry_save_values (GTK_WINDOW (self),
1490 self->priv->x, self->priv->y,
1491 self->priv->w - self->priv->dialpad_width, self->priv->h,
1492 self->priv->maximized);
1497 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1499 EmpathyCallWindow *self)
1501 switch (response_id)
1503 case GTK_RESPONSE_ACCEPT:
1504 tp_channel_dispatch_operation_handle_with_async (
1505 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1507 tp_clear_object (&self->priv->pending_cdo);
1508 tp_clear_object (&self->priv->pending_channel);
1509 tp_clear_object (&self->priv->pending_context);
1512 case GTK_RESPONSE_CANCEL:
1513 tp_channel_dispatch_operation_close_channels_async (
1514 self->priv->pending_cdo, NULL, NULL);
1516 empathy_call_window_status_message (self, _("Disconnected"));
1517 self->priv->call_state = DISCONNECTED;
1520 g_warn_if_reached ();
1525 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1529 g_assert (self->priv->call_state != CONNECTED);
1531 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1533 empathy_call_window_status_message (self, _("Incoming call"));
1534 self->priv->call_state = RINGING;
1536 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1537 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1538 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1539 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1540 empathy_contact_get_alias (self->priv->contact));
1542 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1543 _("Reject"), GTK_RESPONSE_CANCEL,
1544 _("Answer"), GTK_RESPONSE_ACCEPT,
1547 g_signal_connect (self->priv->incoming_call_dialog, "response",
1548 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1549 gtk_widget_show (self->priv->incoming_call_dialog);
1553 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1557 EmpathyCallWindow *self)
1559 tp_clear_object (&self->priv->pending_cdo);
1560 tp_clear_object (&self->priv->pending_channel);
1561 tp_clear_object (&self->priv->pending_context);
1563 /* We don't know if the incoming call has been accepted or not, so we
1564 * assume it hasn't and if it has, we'll set the proper status when
1565 * we get the new handler. */
1566 empathy_call_window_status_message (self, _("Disconnected"));
1567 self->priv->call_state = DISCONNECTED;
1569 gtk_widget_destroy (self->priv->incoming_call_dialog);
1570 self->priv->incoming_call_dialog = NULL;
1574 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1575 TpCallChannel *channel,
1576 TpChannelDispatchOperation *dispatch_operation,
1577 TpAddDispatchOperationContext *context)
1579 g_assert (self->priv->pending_channel == NULL);
1580 g_assert (self->priv->pending_context == NULL);
1581 g_assert (self->priv->pending_cdo == NULL);
1583 /* Start ringing and delay until the user answers or hangs. */
1584 self->priv->pending_channel = g_object_ref (channel);
1585 self->priv->pending_context = g_object_ref (context);
1586 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1588 g_signal_connect (self->priv->pending_cdo, "invalidated",
1589 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1591 empathy_call_window_set_state_ringing (self);
1592 tp_add_dispatch_operation_context_accept (context);
1596 mic_button_clicked (GtkWidget *button,
1597 EmpathyCallWindow *self)
1599 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1601 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1602 !self->priv->muted);
1606 empathy_call_window_init (EmpathyCallWindow *self)
1608 EmpathyCallWindowPriv *priv;
1610 GtkWidget *top_vbox;
1612 ClutterConstraint *constraint;
1613 ClutterActor *remote_avatar;
1614 ClutterColor black = { 0, 0, 0, 0 };
1615 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1616 OVERLAY_MARGIN, OVERLAY_MARGIN };
1618 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1619 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1621 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1622 priv->timer = g_timer_new ();
1624 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1625 gui = empathy_builder_get_file (filename,
1626 "call_window_vbox", &top_vbox,
1627 "errors_vbox", &priv->errors_vbox,
1628 "pane", &priv->pane,
1629 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1630 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1631 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1632 "status_label", &priv->status_label,
1633 "audiocall", &priv->audio_call_button,
1634 "videocall", &priv->video_call_button,
1635 "microphone", &priv->mic_button,
1636 "microphone_icon", &priv->microphone_icon,
1637 "volume", &priv->volume_button,
1638 "camera", &priv->camera_button,
1639 "hangup", &priv->hangup_button,
1640 "dialpad", &priv->dialpad_button,
1641 "toolbar", &priv->toolbar,
1642 "bottom_toolbar", &priv->bottom_toolbar,
1643 "ui_manager", &priv->ui_manager,
1644 "menufullscreen", &priv->menu_fullscreen,
1645 "menupreviewswap", &priv->menu_swap_camera,
1646 "details_vbox", &priv->details_vbox,
1647 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1648 "acodec_encoding_label", &priv->acodec_encoding_label,
1649 "acodec_decoding_label", &priv->acodec_decoding_label,
1650 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1651 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1652 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1653 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1654 "video_local_candidate_label", &priv->video_local_candidate_label,
1655 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1656 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1657 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1658 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1662 empathy_builder_connect (gui, self,
1663 "hangup", "clicked", empathy_call_window_hangup_cb,
1664 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1665 "videocall", "clicked", empathy_call_window_video_call_cb,
1666 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1667 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1668 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1669 "menusettings", "activate", empathy_call_window_settings_cb,
1670 "menucontents", "activate", empathy_call_window_contents_cb,
1671 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1672 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1673 "menuabout", "activate", empathy_call_window_about_cb,
1674 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1675 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1676 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1677 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1680 empathy_set_css_provider (GTK_WIDGET (self));
1681 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1683 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1685 g_object_bind_property (priv->camera_monitor, "available",
1686 priv->camera_button, "sensitive",
1687 G_BINDING_SYNC_CREATE);
1689 g_signal_connect (priv->camera_monitor, "added",
1690 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1691 g_signal_connect (priv->camera_monitor, "removed",
1692 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1694 g_signal_connect (priv->mic_button, "clicked",
1695 G_CALLBACK (mic_button_clicked), self);
1697 g_mutex_init (&priv->lock);
1699 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1701 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1702 CONTENT_HBOX_SPACING);
1703 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1706 /* main contents remote avatar/video box */
1707 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1708 CLUTTER_BIN_ALIGNMENT_FILL);
1710 priv->video_box = clutter_box_new (priv->video_layout);
1712 priv->video_container = gtk_clutter_embed_new ();
1714 gtk_widget_set_size_request (priv->video_container,
1715 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1717 /* Set the background black */
1718 clutter_stage_set_color (
1719 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1720 GTK_CLUTTER_EMBED (priv->video_container))),
1723 clutter_container_add (
1724 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1725 GTK_CLUTTER_EMBED (priv->video_container))),
1729 constraint = clutter_bind_constraint_new (
1730 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1731 CLUTTER_BIND_SIZE, 0);
1732 clutter_actor_add_constraint (priv->video_box, constraint);
1734 priv->remote_user_avatar_widget = gtk_image_new ();
1735 remote_avatar = gtk_clutter_actor_new_with_contents (
1736 priv->remote_user_avatar_widget);
1737 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1739 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1742 /* create the overlay bin */
1743 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1744 CLUTTER_BIN_ALIGNMENT_CENTER);
1745 priv->overlay_bin = clutter_actor_new ();
1746 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1748 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1750 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1752 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1754 empathy_call_window_create_preview_rectangles (self);
1756 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1757 priv->video_container, TRUE, TRUE,
1758 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1760 create_pipeline (self);
1761 create_video_output_widget (self);
1762 create_audio_input (self);
1763 create_video_input (self);
1765 priv->floating_toolbar = gtk_clutter_actor_new ();
1766 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1767 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1769 gtk_style_context_add_class (
1770 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1771 GTK_STYLE_CLASS_OSD);
1772 gtk_widget_reparent (priv->bottom_toolbar,
1773 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1775 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1776 priv->floating_toolbar,
1777 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1779 clutter_actor_raise_top (priv->floating_toolbar);
1781 /* Transitions for the floating toolbar */
1782 priv->transitions = clutter_state_new ();
1784 /* all transitions last for 2s */
1785 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1787 /* transition from any state to "fade-out" state */
1788 clutter_state_set (priv->transitions, NULL, "fade-out",
1789 priv->floating_toolbar,
1790 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1793 /* transition from any state to "fade-in" state */
1794 clutter_state_set (priv->transitions, NULL, "fade-in",
1795 priv->floating_toolbar,
1796 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1799 /* put the actor into the "fade-in" state with no animation */
1800 clutter_state_warp_to_state (priv->transitions, "fade-in");
1802 /* The call will be started as soon the pipeline is playing */
1803 priv->start_call_when_playing = TRUE;
1805 priv->dtmf_panel = empathy_dialpad_widget_new ();
1806 g_signal_connect (priv->dtmf_panel, "start-tone",
1807 G_CALLBACK (dtmf_start_tone_cb), self);
1809 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1812 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1815 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1817 gtk_widget_show_all (top_vbox);
1819 gtk_widget_hide (priv->dtmf_panel);
1820 gtk_widget_hide (priv->details_vbox);
1822 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1824 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1825 priv->video_container);
1827 /* We hide the bottom toolbar after 3s of inactivity and show it
1828 * again on mouse movement */
1829 priv->inactivity_src = g_timeout_add_seconds (3,
1830 empathy_call_window_toolbar_timeout, self);
1832 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1833 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1835 g_signal_connect (G_OBJECT (self), "realize",
1836 G_CALLBACK (empathy_call_window_realized_cb), self);
1838 g_signal_connect (G_OBJECT (self), "delete-event",
1839 G_CALLBACK (empathy_call_window_delete_cb), self);
1841 g_signal_connect (G_OBJECT (self), "window-state-event",
1842 G_CALLBACK (empathy_call_window_state_event_cb), self);
1844 g_signal_connect (G_OBJECT (self), "key-press-event",
1845 G_CALLBACK (empathy_call_window_key_press_cb), self);
1847 g_signal_connect (self, "motion-notify-event",
1848 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1850 g_object_ref (priv->ui_manager);
1851 g_object_unref (gui);
1853 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1854 priv->mic_menu = empathy_mic_menu_new (self);
1855 priv->camera_menu = empathy_camera_menu_new (self);
1857 empathy_call_window_show_hangup_button (self, TRUE);
1859 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1861 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1862 /* These signals are used to track the window position and save it
1863 * when the window is destroyed. We need to do this as we don't want
1864 * the window geometry to be saved with the dialpad taken into account. */
1865 g_signal_connect (self, "destroy",
1866 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1867 g_signal_connect (self, "configure-event",
1868 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1869 g_signal_connect (self, "window-state-event",
1870 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1872 /* Don't display labels in both toolbars */
1873 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1876 /* Instead of specifying a width and a height, we specify only one size. That's
1877 because we want a square avatar icon. */
1879 init_contact_avatar_with_size (EmpathyContact *contact,
1880 GtkWidget *image_widget,
1883 GdkPixbuf *pixbuf_avatar = NULL;
1885 if (contact != NULL)
1887 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1891 if (pixbuf_avatar == NULL)
1893 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1894 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1897 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1899 if (pixbuf_avatar != NULL)
1900 g_object_unref (pixbuf_avatar);
1904 set_window_title (EmpathyCallWindow *self)
1906 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1909 if (priv->contact != NULL)
1911 /* translators: Call is a noun and %s is the contact name. This string
1912 * is used in the window title */
1913 tmp = g_strdup_printf (_("Call with %s"),
1914 empathy_contact_get_alias (priv->contact));
1915 gtk_window_set_title (GTK_WINDOW (self), tmp);
1920 g_warning ("Unknown remote contact!");
1925 set_remote_user_name (EmpathyCallWindow *self,
1926 EmpathyContact *contact)
1928 const gchar *alias = empathy_contact_get_alias (contact);
1929 const gchar *status = empathy_contact_get_status (contact);
1931 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1933 if (status != NULL) {
1936 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1937 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1941 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1947 contact_name_changed_cb (EmpathyContact *contact,
1949 EmpathyCallWindow *self)
1951 set_window_title (self);
1952 set_remote_user_name (self, contact);
1956 contact_presence_changed_cb (EmpathyContact *contact,
1958 EmpathyCallWindow *self)
1960 set_remote_user_name (self, contact);
1964 contact_avatar_changed_cb (EmpathyContact *contact,
1966 EmpathyCallWindow *self)
1969 GtkAllocation allocation;
1970 GtkWidget *avatar_widget;
1972 avatar_widget = self->priv->remote_user_avatar_widget;
1974 gtk_widget_get_allocation (avatar_widget, &allocation);
1975 size = allocation.height;
1979 /* the widget is not allocated yet, set a default size */
1980 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1981 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1984 init_contact_avatar_with_size (contact, avatar_widget, size);
1986 avatar_widget = self->priv->remote_user_avatar_toolbar;
1988 gtk_widget_get_allocation (avatar_widget, &allocation);
1989 size = allocation.height;
1993 /* the widget is not allocated yet, set a default size */
1994 size = SMALL_TOOLBAR_SIZE;
1997 init_contact_avatar_with_size (contact, avatar_widget, size);
2001 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2002 EmpathyCallHandler *handler)
2004 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2006 tp_g_signal_connect_object (priv->contact, "notify::name",
2007 G_CALLBACK (contact_name_changed_cb), self, 0);
2008 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2009 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2010 tp_g_signal_connect_object (priv->contact, "notify::presence",
2011 G_CALLBACK (contact_presence_changed_cb), self, 0);
2013 set_window_title (self);
2014 set_remote_user_name (self, priv->contact);
2016 init_contact_avatar_with_size (priv->contact,
2017 priv->remote_user_avatar_widget,
2018 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2019 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2021 init_contact_avatar_with_size (priv->contact,
2022 priv->remote_user_avatar_toolbar,
2023 SMALL_TOOLBAR_SIZE);
2025 /* The remote avatar is shown by default and will be hidden when we receive
2026 video from the remote side. */
2027 clutter_actor_hide (priv->video_output);
2028 gtk_widget_show (priv->remote_user_avatar_widget);
2032 update_send_codec (EmpathyCallWindow *self,
2035 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2042 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2043 widget = priv->acodec_encoding_label;
2047 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2048 widget = priv->vcodec_encoding_label;
2054 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2055 gtk_label_set_text (GTK_LABEL (widget), tmp);
2060 send_audio_codec_notify_cb (GObject *object,
2064 EmpathyCallWindow *self = user_data;
2066 update_send_codec (self, TRUE);
2070 send_video_codec_notify_cb (GObject *object,
2074 EmpathyCallWindow *self = user_data;
2076 update_send_codec (self, FALSE);
2080 update_recv_codec (EmpathyCallWindow *self,
2083 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2086 GString *str = NULL;
2090 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2091 widget = priv->acodec_decoding_label;
2095 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2096 widget = priv->vcodec_decoding_label;
2102 for (l = codecs; l != NULL; l = g_list_next (l))
2104 FsCodec *codec = l->data;
2107 str = g_string_new (NULL);
2109 g_string_append (str, ", ");
2111 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2115 gtk_label_set_text (GTK_LABEL (widget), str->str);
2116 g_string_free (str, TRUE);
2120 recv_audio_codecs_notify_cb (GObject *object,
2124 EmpathyCallWindow *self = user_data;
2126 update_recv_codec (self, TRUE);
2130 recv_video_codecs_notify_cb (GObject *object,
2134 EmpathyCallWindow *self = user_data;
2136 update_recv_codec (self, FALSE);
2139 static const gchar *
2140 candidate_type_to_str (FsCandidate *candidate)
2142 switch (candidate->type)
2144 case FS_CANDIDATE_TYPE_HOST:
2146 case FS_CANDIDATE_TYPE_SRFLX:
2147 return "server reflexive";
2148 case FS_CANDIDATE_TYPE_PRFLX:
2149 return "peer reflexive";
2150 case FS_CANDIDATE_TYPE_RELAY:
2152 case FS_CANDIDATE_TYPE_MULTICAST:
2159 static const gchar *
2160 candidate_type_to_desc (FsCandidate *candidate)
2162 switch (candidate->type)
2164 case FS_CANDIDATE_TYPE_HOST:
2165 return _("The IP address as seen by the machine");
2166 case FS_CANDIDATE_TYPE_SRFLX:
2167 return _("The IP address as seen by a server on the Internet");
2168 case FS_CANDIDATE_TYPE_PRFLX:
2169 return _("The IP address of the peer as seen by the other side");
2170 case FS_CANDIDATE_TYPE_RELAY:
2171 return _("The IP address of a relay server");
2172 case FS_CANDIDATE_TYPE_MULTICAST:
2173 return _("The IP address of the multicast group");
2180 update_candidat_widget (EmpathyCallWindow *self,
2183 FsCandidate *candidate)
2187 g_assert (candidate != NULL);
2188 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2189 candidate->port, candidate_type_to_str (candidate));
2191 gtk_label_set_text (GTK_LABEL (label), str);
2192 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2198 candidates_changed_cb (GObject *object,
2200 EmpathyCallWindow *self)
2202 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2203 FsCandidate *candidate = NULL;
2205 if (type == FS_MEDIA_TYPE_VIDEO)
2207 /* Update remote candidate */
2208 candidate = empathy_call_handler_get_video_remote_candidate (
2211 update_candidat_widget (self, priv->video_remote_candidate_label,
2212 priv->video_remote_candidate_info_img, candidate);
2214 /* Update local candidate */
2215 candidate = empathy_call_handler_get_video_local_candidate (
2218 update_candidat_widget (self, priv->video_local_candidate_label,
2219 priv->video_local_candidate_info_img, candidate);
2223 /* Update remote candidate */
2224 candidate = empathy_call_handler_get_audio_remote_candidate (
2227 update_candidat_widget (self, priv->audio_remote_candidate_label,
2228 priv->audio_remote_candidate_info_img, candidate);
2230 /* Update local candidate */
2231 candidate = empathy_call_handler_get_audio_local_candidate (
2234 update_candidat_widget (self, priv->audio_local_candidate_label,
2235 priv->audio_local_candidate_info_img, candidate);
2240 empathy_call_window_constructed (GObject *object)
2242 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2243 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2244 TpCallChannel *call;
2247 g_assert (priv->handler != NULL);
2249 g_object_get (priv->handler, "call-channel", &call, NULL);
2250 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2251 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2252 tp_clear_object (&call);
2254 priv->contact = empathy_call_handler_get_contact (priv->handler);
2255 g_assert (priv->contact != NULL);
2256 g_object_ref (priv->contact);
2258 if (!empathy_contact_can_voip_video (priv->contact))
2260 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2261 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2264 empathy_call_window_setup_avatars (self, priv->handler);
2265 empathy_call_window_set_state_connecting (self);
2267 if (!empathy_call_handler_has_initial_video (priv->handler))
2269 gtk_toggle_button_set_active (
2270 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2272 /* If call has InitialVideo, the preview will be started once the call has
2273 * been started (start_call()). */
2275 update_send_codec (self, TRUE);
2276 update_send_codec (self, FALSE);
2277 update_recv_codec (self, TRUE);
2278 update_recv_codec (self, FALSE);
2280 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2281 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2282 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2283 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2284 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2285 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2286 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2287 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2289 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2290 G_CALLBACK (candidates_changed_cb), self, 0);
2293 static void empathy_call_window_dispose (GObject *object);
2294 static void empathy_call_window_finalize (GObject *object);
2297 empathy_call_window_set_property (GObject *object,
2298 guint property_id, const GValue *value, GParamSpec *pspec)
2300 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2302 switch (property_id)
2304 case PROP_CALL_HANDLER:
2305 priv->handler = g_value_dup_object (value);
2308 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2313 empathy_call_window_get_property (GObject *object,
2314 guint property_id, GValue *value, GParamSpec *pspec)
2316 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2318 switch (property_id)
2320 case PROP_CALL_HANDLER:
2321 g_value_set_object (value, priv->handler);
2324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2329 empathy_call_window_class_init (
2330 EmpathyCallWindowClass *empathy_call_window_class)
2332 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2333 GParamSpec *param_spec;
2335 g_type_class_add_private (empathy_call_window_class,
2336 sizeof (EmpathyCallWindowPriv));
2338 object_class->constructed = empathy_call_window_constructed;
2339 object_class->set_property = empathy_call_window_set_property;
2340 object_class->get_property = empathy_call_window_get_property;
2342 object_class->dispose = empathy_call_window_dispose;
2343 object_class->finalize = empathy_call_window_finalize;
2345 param_spec = g_param_spec_object ("handler",
2346 "handler", "The call handler",
2347 EMPATHY_TYPE_CALL_HANDLER,
2348 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2349 g_object_class_install_property (object_class,
2350 PROP_CALL_HANDLER, param_spec);
2352 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2353 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2355 0, NULL, NULL, NULL,
2361 empathy_call_window_dispose (GObject *object)
2363 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2364 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2366 if (priv->dispose_has_run)
2369 priv->dispose_has_run = TRUE;
2371 if (priv->handler != NULL)
2373 empathy_call_handler_stop_call (priv->handler);
2374 tp_clear_object (&priv->handler);
2377 if (priv->bus_message_source_id != 0)
2379 g_source_remove (priv->bus_message_source_id);
2380 priv->bus_message_source_id = 0;
2383 if (priv->got_video_src > 0)
2385 g_source_remove (priv->got_video_src);
2386 priv->got_video_src = 0;
2389 if (priv->inactivity_src > 0)
2391 g_source_remove (priv->inactivity_src);
2392 priv->inactivity_src = 0;
2395 tp_clear_object (&priv->pipeline);
2396 tp_clear_object (&priv->video_input);
2397 tp_clear_object (&priv->audio_input);
2398 tp_clear_object (&priv->video_tee);
2399 tp_clear_object (&priv->ui_manager);
2400 tp_clear_object (&priv->fullscreen);
2401 tp_clear_object (&priv->camera_monitor);
2402 tp_clear_object (&priv->settings);
2403 tp_clear_object (&priv->sound_mgr);
2404 tp_clear_object (&priv->mic_menu);
2405 tp_clear_object (&priv->camera_menu);
2406 tp_clear_object (&priv->transitions);
2408 g_list_free_full (priv->notifiers, g_object_unref);
2410 if (priv->timer_id != 0)
2411 g_source_remove (priv->timer_id);
2414 tp_clear_object (&priv->contact);
2416 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2420 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2424 if (priv->video_output_motion_handler_id != 0)
2426 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2427 priv->video_output_motion_handler_id);
2428 priv->video_output_motion_handler_id = 0;
2433 empathy_call_window_finalize (GObject *object)
2435 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2438 disconnect_video_output_motion_handler (self);
2440 /* free any data held directly by the object here */
2441 g_mutex_clear (&priv->lock);
2443 g_timer_destroy (priv->timer);
2445 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2450 empathy_call_window_new (EmpathyCallHandler *handler)
2452 return EMPATHY_CALL_WINDOW (
2453 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2457 empathy_call_window_new_handler (EmpathyCallWindow *self,
2458 EmpathyCallHandler *handler,
2462 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2465 empathy_window_present_with_time (GTK_WINDOW (self), x11_time);
2467 if (self->priv->call_state == DISCONNECTED)
2469 /* start a new call if one is not already in progress */
2470 tp_clear_object (&self->priv->handler);
2471 self->priv->handler = g_object_ref (handler);
2472 empathy_call_window_connect_handler (self);
2474 empathy_call_window_restart_call (self);
2479 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2480 GstElement *conference, gpointer user_data)
2482 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2483 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2484 FsElementAddedNotifier *notifier;
2487 DEBUG ("Conference added");
2489 /* Add notifier to set the various element properties as needed */
2490 notifier = fs_element_added_notifier_new ();
2491 keyfile = fs_utils_get_default_element_properties (conference);
2493 if (keyfile != NULL)
2494 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2496 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2498 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2500 gst_bin_add (GST_BIN (priv->pipeline), conference);
2501 gst_element_set_state (conference, GST_STATE_PLAYING);
2505 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2506 GstElement *conference, gpointer user_data)
2508 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2509 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2511 g_list_free_full (priv->notifiers, g_object_unref);
2512 priv->notifiers = NULL;
2514 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2515 gst_element_set_state (conference, GST_STATE_NULL);
2519 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2521 GstStateChangeReturn state_change_return;
2522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2524 if (priv->pipeline == NULL)
2527 if (priv->bus_message_source_id != 0)
2529 g_source_remove (priv->bus_message_source_id);
2530 priv->bus_message_source_id = 0;
2533 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2535 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2536 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2538 if (priv->pipeline != NULL)
2539 g_object_unref (priv->pipeline);
2540 priv->pipeline = NULL;
2542 if (priv->audio_output != NULL)
2543 g_object_unref (priv->audio_output);
2544 priv->audio_output = NULL;
2545 priv->audio_output_added = FALSE;
2547 if (priv->video_tee != NULL)
2548 g_object_unref (priv->video_tee);
2549 priv->video_tee = NULL;
2551 if (priv->video_preview != NULL)
2552 clutter_actor_destroy (priv->video_preview);
2553 priv->video_preview = NULL;
2555 /* If we destroy the preview while it's being dragged, we won't
2556 * get the ::drag-end signal, so manually destroy the clone */
2557 if (priv->drag_preview != NULL)
2559 clutter_actor_destroy (priv->drag_preview);
2560 empathy_call_window_show_preview_rectangles (self, FALSE);
2561 priv->drag_preview = NULL;
2564 priv->funnel = NULL;
2566 create_pipeline (self);
2567 /* Call will be started when user will hit the 'redial' button */
2568 priv->start_call_when_playing = FALSE;
2569 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2575 g_message ("Error: could not destroy pipeline. Closing call window");
2576 gtk_widget_destroy (GTK_WIDGET (self));
2583 reset_details_pane (EmpathyCallWindow *self)
2585 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2587 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2588 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2589 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2590 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2594 empathy_call_window_disconnected (EmpathyCallWindow *self,
2597 gboolean could_disconnect = FALSE;
2598 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2599 gboolean could_reset_pipeline;
2601 /* Leave full screen mode if needed */
2602 gtk_window_unfullscreen (GTK_WINDOW (self));
2604 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2606 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2607 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2609 /* Create the video input and then turn on the camera
2610 * menu, so that the active camera gets marked as such.
2612 if (priv->video_input == NULL)
2613 create_video_input (self);
2614 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2616 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2618 if (priv->call_state == CONNECTING)
2619 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2621 if (priv->call_state != REDIALING)
2622 priv->call_state = DISCONNECTED;
2624 /* Show the toolbar */
2625 clutter_state_set_state (priv->transitions, "fade-in");
2627 if (could_reset_pipeline)
2629 g_mutex_lock (&priv->lock);
2631 g_timer_stop (priv->timer);
2633 if (priv->timer_id != 0)
2634 g_source_remove (priv->timer_id);
2637 g_mutex_unlock (&priv->lock);
2640 /* We are about to destroy the window, no need to update it or create
2641 * a video preview */
2644 empathy_call_window_status_message (self, _("Disconnected"));
2646 empathy_call_window_show_hangup_button (self, FALSE);
2648 /* Unsensitive the camera and mic button */
2649 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2650 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2652 /* Be sure that the mic button is enabled */
2653 empathy_audio_src_set_mute (
2654 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2656 if (priv->camera_state == CAMERA_STATE_ON)
2658 /* Restart the preview with the new pipeline. */
2659 display_video_preview (self, TRUE);
2662 /* destroy the video output; it will be recreated when we'll redial */
2663 disconnect_video_output_motion_handler (self);
2664 if (priv->video_output != NULL)
2665 clutter_actor_destroy (priv->video_output);
2666 priv->video_output = NULL;
2667 if (priv->got_video_src > 0)
2669 g_source_remove (priv->got_video_src);
2670 priv->got_video_src = 0;
2673 gtk_widget_show (priv->remote_user_avatar_widget);
2675 reset_details_pane (self);
2677 priv->sending_video = FALSE;
2678 priv->call_started = FALSE;
2680 could_disconnect = TRUE;
2682 /* TODO: display the self avatar of the preview (depends if the "Always
2683 * Show Video Preview" is enabled or not) */
2686 return could_disconnect;
2691 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2694 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2695 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2697 if (empathy_call_window_disconnected (self, TRUE) &&
2698 priv->call_state == REDIALING)
2699 empathy_call_window_restart_call (self);
2703 empathy_call_window_content_is_raw (TfContent *content)
2705 FsConference *conference;
2708 g_object_get (content, "fs-conference", &conference, NULL);
2709 g_assert (conference != NULL);
2711 /* FIXME: Ugly hack, update when moving a packetization property into
2713 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2714 gst_object_unref (conference);
2720 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2722 EmpathyCallWindow *self)
2724 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2725 FsMediaType media_type;
2727 DEBUG ("removing content");
2729 g_object_get (content, "media-type", &media_type, NULL);
2732 * This assumes that there is only one video stream per channel...
2735 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2737 if (priv->funnel != NULL)
2741 output = priv->video_output_sink;
2743 gst_element_set_state (output, GST_STATE_NULL);
2744 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2746 gst_bin_remove (GST_BIN (priv->pipeline), output);
2747 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2748 priv->funnel = NULL;
2751 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2753 if (priv->audio_output != NULL)
2755 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2757 if (priv->audio_output_added)
2758 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2759 priv->audio_output = NULL;
2760 priv->audio_output_added = FALSE;
2765 g_assert_not_reached ();
2772 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2774 EmpathyCallWindow *self)
2776 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2778 DEBUG ("Framerate changed to %u", framerate);
2780 if (priv->video_input != NULL)
2781 empathy_video_src_set_framerate (priv->video_input, framerate);
2785 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2788 EmpathyCallWindow *self)
2790 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2792 DEBUG ("Resolution changed to %ux%u", width, height);
2794 if (priv->video_input != NULL)
2796 empathy_video_src_set_resolution (priv->video_input, width, height);
2800 /* Called with global lock held */
2802 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2804 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2808 if (priv->funnel == NULL)
2810 output = priv->video_output_sink;
2812 priv->funnel = gst_element_factory_make ("funnel", NULL);
2814 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2819 g_warning ("Could not create video funnel");
2823 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2825 gst_object_unref (priv->funnel);
2826 priv->funnel = NULL;
2827 g_warning ("Could not add funnel to pipeline");
2831 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2833 g_warning ("Could not add the video output widget to the pipeline");
2837 if (!gst_element_link (priv->funnel, output))
2839 g_warning ("Could not link output sink to funnel");
2840 goto error_output_added;
2843 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2845 g_warning ("Could not start video sink");
2846 goto error_output_added;
2849 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2851 g_warning ("Could not start funnel");
2852 goto error_output_added;
2856 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2858 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2862 g_warning ("Could not get request pad from funnel");
2869 gst_element_set_locked_state (priv->funnel, TRUE);
2870 gst_element_set_locked_state (output, TRUE);
2872 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2873 gst_element_set_state (output, GST_STATE_NULL);
2875 gst_bin_remove (GST_BIN (priv->pipeline), output);
2876 gst_element_set_locked_state (output, FALSE);
2880 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2881 priv->funnel = NULL;
2886 /* Called with global lock held */
2888 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2891 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2893 GstPadTemplate *template;
2895 if (!priv->audio_output_added)
2897 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2899 g_warning ("Could not add audio sink to pipeline");
2900 g_object_unref (priv->audio_output);
2901 goto error_add_output;
2904 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2906 g_warning ("Could not start audio sink");
2909 priv->audio_output_added = TRUE;
2912 template = gst_element_class_get_pad_template (
2913 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2915 pad = gst_element_request_pad (priv->audio_output,
2916 template, NULL, NULL);
2920 g_warning ("Could not get sink pad from sink");
2927 gst_element_set_locked_state (priv->audio_output, TRUE);
2928 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2929 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2930 priv->audio_output = NULL;
2938 empathy_call_window_update_timer (gpointer user_data)
2940 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2941 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2942 const gchar *status;
2946 time_ = g_timer_elapsed (priv->timer, NULL);
2948 if (priv->call_state == HELD)
2949 status = _("On hold");
2950 else if (priv->call_state == DISCONNECTED)
2951 status = _("Disconnected");
2952 else if (priv->muted)
2955 status = _("Duration");
2957 /* Translators: 'status - minutes:seconds' the caller has been connected */
2958 str = g_strdup_printf (_("%s — %d:%02dm"),
2960 (int) time_ / 60, (int) time_ % 60);
2961 empathy_call_window_status_message (self, str);
2969 EMP_RESPONSE_BALANCE
2973 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2977 switch (response_id)
2979 case GTK_RESPONSE_CLOSE:
2980 gtk_widget_destroy (GTK_WIDGET (info_bar));
2982 case EMP_RESPONSE_BALANCE:
2983 empathy_url_show (GTK_WIDGET (info_bar),
2984 g_object_get_data (G_OBJECT (info_bar), "uri"));
2990 display_error (EmpathyCallWindow *self,
2994 const gchar *details,
2995 const gchar *button_text,
2997 gint button_response)
2999 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3000 GtkWidget *info_bar;
3001 GtkWidget *content_area;
3008 /* Create info bar */
3009 info_bar = gtk_info_bar_new ();
3011 if (button_text != NULL)
3013 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3014 button_text, button_response);
3015 g_object_set_data_full (G_OBJECT (info_bar),
3016 "uri", g_strdup (uri), g_free);
3019 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3020 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3022 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3024 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3026 /* hbox containing the image and the messages vbox */
3027 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3028 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3031 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3032 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3034 /* vbox containing the main message and the details expander */
3035 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3036 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3039 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3041 label = gtk_label_new (NULL);
3042 gtk_label_set_markup (GTK_LABEL (label), txt);
3043 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3044 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3047 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3050 if (details != NULL)
3052 GtkWidget *expander;
3054 expander = gtk_expander_new (_("Technical Details"));
3056 txt = g_strdup_printf ("<i>%s</i>", details);
3058 label = gtk_label_new (NULL);
3059 gtk_label_set_markup (GTK_LABEL (label), txt);
3060 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3061 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3064 gtk_container_add (GTK_CONTAINER (expander), label);
3065 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3068 g_signal_connect (info_bar, "response",
3069 G_CALLBACK (on_error_infobar_response_cb), NULL);
3071 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3072 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3073 gtk_widget_show_all (info_bar);
3078 media_stream_error_to_txt (EmpathyCallWindow *self,
3079 TpCallChannel *call,
3081 TpMediaStreamError error)
3083 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3084 const gchar *cm = NULL;
3090 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3092 return g_strdup_printf (
3093 _("%s's software does not understand any of the audio formats "
3094 "supported by your computer"),
3095 empathy_contact_get_alias (priv->contact));
3097 return g_strdup_printf (
3098 _("%s's software does not understand any of the video formats "
3099 "supported by your computer"),
3100 empathy_contact_get_alias (priv->contact));
3102 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3103 return g_strdup_printf (
3104 _("Can't establish a connection to %s. "
3105 "One of you might be on a network that does not allow "
3106 "direct connections."),
3107 empathy_contact_get_alias (priv->contact));
3109 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3110 return g_strdup (_("There was a failure on the network"));
3112 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3114 return g_strdup (_("The audio formats necessary for this call "
3115 "are not installed on your computer"));
3117 return g_strdup (_("The video formats necessary for this call "
3118 "are not installed on your computer"));
3120 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3121 tp_connection_parse_object_path (
3122 tp_channel_get_connection (TP_CHANNEL (call)),
3125 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3126 "product=Telepathy&component=%s", cm);
3128 result = g_strdup_printf (
3129 _("Something unexpected happened in a Telepathy component. "
3130 "Please <a href=\"%s\">report this bug</a> and attach "
3131 "logs gathered from the 'Debug' window in the Help menu."), url);
3137 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3138 return g_strdup (_("There was a failure in the call engine"));
3140 case TP_MEDIA_STREAM_ERROR_EOS:
3141 return g_strdup (_("The end of the stream was reached"));
3143 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3150 empathy_call_window_stream_error (EmpathyCallWindow *self,
3151 TpCallChannel *call,
3160 desc = media_stream_error_to_txt (self, call, audio, code);
3163 /* No description, use the error message. That's not great as it's not
3164 * localized but it's better than nothing. */
3165 display_error (self, call, icon, title, msg, NULL);
3169 display_error (self, call, icon, title, desc, msg);
3175 empathy_call_window_audio_stream_error (TpCallChannel *call,
3178 EmpathyCallWindow *self)
3180 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3181 "gnome-stock-mic", _("Can't establish audio stream"));
3185 empathy_call_window_video_stream_error (TpCallChannel *call,
3188 EmpathyCallWindow *self)
3190 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3191 "camera-web", _("Can't establish video stream"));
3196 show_balance_error (EmpathyCallWindow *self)
3200 gchar *balance, *tmp;
3201 const gchar *uri, *currency;
3205 g_object_get (self->priv->handler,
3206 "call-channel", &call,
3209 conn = tp_channel_get_connection (call);
3210 g_object_unref (call);
3212 uri = tp_connection_get_balance_uri (conn);
3214 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3216 /* unknown balance */
3217 balance = g_strdup ("(--)");
3221 char *money = empathy_format_currency (amount, scale, currency);
3223 balance = g_strdup_printf ("%s %s",
3228 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3230 display_error (self,
3232 _("Sorry, you don’t have enough credit for that call."),
3236 EMP_RESPONSE_BALANCE);
3243 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3246 EmpathyCallWindow *self)
3248 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3249 TpCallChannel *call;
3250 gboolean can_send_video;
3252 if (state == TP_CALL_STATE_ENDED)
3254 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3255 empathy_call_window_disconnected (self, TRUE);
3256 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3257 show_balance_error (self);
3261 if (state != TP_CALL_STATE_ACCEPTED)
3264 if (priv->call_state == CONNECTED)
3267 g_timer_start (priv->timer);
3268 priv->call_state = CONNECTED;
3270 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3272 can_send_video = priv->video_input != NULL &&
3273 empathy_contact_can_voip_video (priv->contact) &&
3274 empathy_camera_monitor_get_available (priv->camera_monitor);
3276 g_object_get (priv->handler, "call-channel", &call, NULL);
3278 if (tp_call_channel_has_dtmf (call))
3279 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3281 if (priv->video_input == NULL)
3282 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3284 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3286 empathy_call_window_show_hangup_button (self, TRUE);
3288 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3290 clutter_actor_hide (priv->video_output);
3291 gtk_widget_show (priv->remote_user_avatar_widget);
3293 g_object_unref (call);
3295 g_mutex_lock (&priv->lock);
3297 priv->timer_id = g_timeout_add_seconds (1,
3298 empathy_call_window_update_timer, self);
3300 g_mutex_unlock (&priv->lock);
3302 empathy_call_window_update_timer (self);
3304 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3308 empathy_call_window_show_video_output_cb (gpointer user_data)
3310 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3312 if (self->priv->video_output != NULL)
3314 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3315 clutter_actor_show (self->priv->video_output);
3316 clutter_actor_raise_top (self->priv->overlay_bin);
3323 empathy_call_window_check_video_cb (gpointer data)
3325 EmpathyCallWindow *self = data;
3327 if (self->priv->got_video)
3329 self->priv->got_video = FALSE;
3333 /* No video in the last N seconds, display the remote avatar */
3334 empathy_call_window_show_video_output (self, FALSE);
3339 /* Called from the streaming thread */
3341 static GstPadProbeReturn
3342 empathy_call_window_video_probe_cb (GstPad *pad,
3343 GstPadProbeInfo *info,
3346 EmpathyCallWindow *self = user_data;
3348 if (G_UNLIKELY (!self->priv->got_video))
3350 /* show the remote video */
3351 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3352 empathy_call_window_show_video_output_cb,
3353 g_object_ref (self), g_object_unref);
3355 self->priv->got_video = TRUE;
3358 return GST_PAD_PROBE_OK;
3362 empathy_call_window_video_probe_cb (GstPad *pad,
3363 GstMiniObject *mini_obj,
3364 EmpathyCallWindow *self)
3367 if (GST_IS_EVENT (mini_obj))
3370 if (G_UNLIKELY (!self->priv->got_video))
3372 /* show the remote video */
3373 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3374 empathy_call_window_show_video_output_cb,
3375 g_object_ref (self), g_object_unref);
3377 self->priv->got_video = TRUE;
3384 /* Called from the streaming thread */
3386 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3387 TfContent *content, GstPad *src, gpointer user_data)
3389 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3390 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3391 gboolean retval = FALSE;
3396 g_mutex_lock (&priv->lock);
3398 g_object_get (content, "media-type", &media_type, NULL);
3402 case TP_MEDIA_STREAM_TYPE_AUDIO:
3403 pad = empathy_call_window_get_audio_sink_pad (self, content);
3405 case TP_MEDIA_STREAM_TYPE_VIDEO:
3406 g_idle_add (empathy_call_window_show_video_output_cb, self);
3407 pad = empathy_call_window_get_video_sink_pad (self);
3410 gst_pad_add_probe (src,
3411 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3412 empathy_call_window_video_probe_cb, self, NULL);
3414 gst_pad_add_data_probe (src,
3415 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3417 if (priv->got_video_src > 0)
3418 g_source_remove (priv->got_video_src);
3419 priv->got_video_src = g_timeout_add_seconds (1,
3420 empathy_call_window_check_video_cb, self);
3423 g_assert_not_reached ();
3429 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3430 g_warning ("Could not link %s sink pad",
3431 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3435 gst_object_unref (pad);
3439 /* If no sink could be linked, try to add fakesink to prevent the whole call
3444 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3446 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3448 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3449 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3450 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3452 gst_element_set_locked_state (fakesink, TRUE);
3453 gst_element_set_state (fakesink, GST_STATE_NULL);
3454 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3458 DEBUG ("Could not link real sink, linked fakesink instead");
3460 gst_object_unref (sinkpad);
3464 gst_object_unref (fakesink);
3469 g_mutex_unlock (&priv->lock);
3475 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3478 EmpathyCallWindowPriv *priv = self->priv;
3480 g_assert (priv->audio_output_added == FALSE);
3481 g_assert (priv->audio_output == FALSE);
3483 priv->audio_output = empathy_audio_sink_new ();
3484 g_object_ref_sink (priv->audio_output);
3486 /* volume button to output volume linking */
3487 g_object_bind_property (priv->audio_output, "volume",
3488 priv->volume_button, "value",
3489 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3491 g_object_bind_property_full (content, "requested-output-volume",
3492 priv->audio_output, "volume",
3494 audio_control_volume_to_element,
3495 element_volume_to_audio_control,
3498 /* Link volumes together, sync the current audio input volume property
3499 * back to farstream first */
3500 g_object_bind_property_full (priv->audio_output, "volume",
3501 content, "reported-output-volume",
3502 G_BINDING_SYNC_CREATE,
3503 element_volume_to_audio_control,
3504 audio_control_volume_to_element,
3507 /* For raw audio conferences assume that the producer of the raw data
3508 * has already processed it, so turn off any echo cancellation and any
3509 * other audio improvements that come with it */
3510 empathy_audio_sink_set_echo_cancel (
3511 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3512 !empathy_call_window_content_is_raw (content));
3517 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3518 TfContent *content, gpointer user_data)
3520 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3523 FsMediaType media_type;
3524 gboolean retval = FALSE;
3526 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3527 g_assert (sink != NULL);
3531 case FS_MEDIA_TYPE_AUDIO:
3533 /* For raw audio conferences assume that the receiver of the raw data
3534 * wants it unprocessed, so turn off any echo cancellation and any
3535 * other audio improvements that come with it */
3536 empathy_audio_src_set_echo_cancel (
3537 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3538 !empathy_call_window_content_is_raw (content));
3540 /* Link volumes together, sync the current audio input volume property
3541 * back to farstream first */
3542 g_object_bind_property_full (content, "requested-input-volume",
3543 priv->audio_input, "volume",
3545 audio_control_volume_to_element,
3546 element_volume_to_audio_control,
3549 g_object_bind_property_full (priv->audio_input, "volume",
3550 content, "reported-input-volume",
3551 G_BINDING_SYNC_CREATE,
3552 element_volume_to_audio_control,
3553 audio_control_volume_to_element,
3556 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3558 g_warning ("Could not add audio source to pipeline");
3562 pad = gst_element_get_static_pad (priv->audio_input, "src");
3565 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3566 g_warning ("Could not get source pad from audio source");
3570 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3572 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3573 gst_object_unref (pad);
3574 g_warning ("Could not link audio source to farsight");
3577 gst_object_unref (pad);
3579 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3581 g_warning ("Could not start audio source");
3582 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3583 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3587 /* Prepare our audio output, not added yet though */
3588 empathy_call_window_prepare_audio_output (self, content);
3592 case FS_MEDIA_TYPE_VIDEO:
3593 if (priv->video_tee != NULL)
3596 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3598 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3600 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3602 g_warning ("Could not link video source input pipeline");
3605 gst_object_unref (pad);
3611 g_assert_not_reached ();
3614 gst_object_unref (sink);
3619 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3622 GstElement *preview;
3624 disable_camera (self);
3626 DEBUG ("remove video input");
3627 preview = priv->video_preview_sink;
3629 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3630 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3631 gst_element_set_state (preview, GST_STATE_NULL);
3633 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3636 g_object_unref (priv->video_input);
3637 priv->video_input = NULL;
3638 g_object_unref (priv->video_tee);
3639 priv->video_tee = NULL;
3640 clutter_actor_destroy (priv->video_preview);
3641 priv->video_preview = NULL;
3643 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3644 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3648 start_call (EmpathyCallWindow *self)
3650 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3652 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3654 priv->call_started = TRUE;
3655 empathy_call_handler_start_call (priv->handler,
3656 gtk_get_current_event_time ());
3658 if (empathy_call_handler_has_initial_video (priv->handler))
3660 TpCallChannel *call;
3663 g_object_get (priv->handler, "call-channel", &call, NULL);
3664 /* If the call channel isn't set yet we're requesting it, if we're
3665 * requesting it with initial video it should be PENDING_SEND when we get
3668 s = TP_SENDING_STATE_PENDING_SEND;
3670 s = empathy_call_channel_get_video_state (call);
3672 if (s == TP_SENDING_STATE_PENDING_SEND ||
3673 s == TP_SENDING_STATE_SENDING)
3675 /* Enable 'send video' buttons and display the preview */
3676 gtk_toggle_button_set_active (
3677 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3681 gtk_toggle_button_set_active (
3682 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3684 if (priv->video_preview == NULL)
3686 create_video_preview (self);
3687 add_video_preview_to_pipeline (self);
3692 g_object_unref (call);
3697 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3700 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3701 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3702 GstState newstate, pending;
3704 empathy_call_handler_bus_message (priv->handler, bus, message);
3706 switch (GST_MESSAGE_TYPE (message))
3708 case GST_MESSAGE_STATE_CHANGED:
3709 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3711 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3713 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3714 !priv->call_started)
3716 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3717 if (newstate == GST_STATE_PAUSED)
3719 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3720 priv->pipeline_playing = TRUE;
3722 if (priv->start_call_when_playing)
3726 if (priv->video_preview_sink != NULL &&
3727 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3729 gst_message_parse_state_changed (message, NULL, &newstate,
3732 if (newstate == GST_STATE_PLAYING &&
3733 pending == GST_STATE_VOID_PENDING)
3734 empathy_call_window_stop_camera_spinning (self);
3737 case GST_MESSAGE_ERROR:
3739 GError *error = NULL;
3740 GstElement *gst_error;
3744 gst_message_parse_error (message, &error, &debug);
3745 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3747 g_message ("Element error: %s -- %s\n", error->message, debug);
3749 name = gst_element_get_name (gst_error);
3750 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3752 /* Remove the video input and continue */
3753 if (priv->video_input != NULL)
3754 empathy_call_window_remove_video_input (self);
3755 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3759 empathy_call_window_disconnected (self, TRUE);
3762 g_error_free (error);
3765 case GST_MESSAGE_UNKNOWN:
3766 case GST_MESSAGE_EOS:
3767 case GST_MESSAGE_WARNING:
3768 case GST_MESSAGE_INFO:
3769 case GST_MESSAGE_TAG:
3770 case GST_MESSAGE_BUFFERING:
3771 case GST_MESSAGE_STATE_DIRTY:
3772 case GST_MESSAGE_STEP_DONE:
3773 case GST_MESSAGE_CLOCK_PROVIDE:
3774 case GST_MESSAGE_CLOCK_LOST:
3775 case GST_MESSAGE_NEW_CLOCK:
3776 case GST_MESSAGE_STRUCTURE_CHANGE:
3777 case GST_MESSAGE_STREAM_STATUS:
3778 case GST_MESSAGE_APPLICATION:
3779 case GST_MESSAGE_ELEMENT:
3780 case GST_MESSAGE_SEGMENT_START:
3781 case GST_MESSAGE_SEGMENT_DONE:
3782 case GST_MESSAGE_DURATION:
3783 case GST_MESSAGE_ANY:
3792 empathy_call_window_members_changed_cb (TpCallChannel *call,
3793 GHashTable *updates,
3795 TpCallStateReason *reason,
3796 EmpathyCallWindow *self)
3798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3799 GHashTableIter iter;
3800 gpointer key, value;
3801 gboolean held = FALSE;
3803 g_hash_table_iter_init (&iter, updates);
3804 while (g_hash_table_iter_next (&iter, &key, &value))
3806 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3808 /* This assumes this is a 1-1 call, otherwise one participant
3809 * putting the call on hold wouldn't mean the call is on hold
3817 priv->call_state = HELD;
3818 else if (priv->call_state == HELD)
3819 priv->call_state = CONNECTED;
3823 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3825 EmpathyCallWindow *self)
3827 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3828 TpCallChannel *call;
3830 g_object_get (priv->handler, "call-channel", &call, NULL);
3835 tp_g_signal_connect_object (call, "audio-stream-error",
3836 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3837 tp_g_signal_connect_object (call, "video-stream-error",
3838 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3841 tp_g_signal_connect_object (call, "members-changed",
3842 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3844 g_object_unref (call);
3848 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3850 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3851 TpCallChannel *call;
3853 g_signal_connect (priv->handler, "state-changed",
3854 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3855 g_signal_connect (priv->handler, "conference-added",
3856 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3857 g_signal_connect (priv->handler, "conference-removed",
3858 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3859 g_signal_connect (priv->handler, "closed",
3860 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3861 g_signal_connect (priv->handler, "src-pad-added",
3862 G_CALLBACK (empathy_call_window_src_added_cb), self);
3863 g_signal_connect (priv->handler, "content-added",
3864 G_CALLBACK (empathy_call_window_content_added_cb), self);
3865 g_signal_connect (priv->handler, "content-removed",
3866 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3868 /* We connect to ::call-channel unconditionally since we'll
3869 * get new channels if we hangup and redial or if we reuse the
3871 g_signal_connect (priv->handler, "notify::call-channel",
3872 G_CALLBACK (call_handler_notify_call_cb), self);
3874 g_signal_connect (priv->handler, "framerate-changed",
3875 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3876 g_signal_connect (priv->handler, "resolution-changed",
3877 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3879 g_object_get (priv->handler, "call-channel", &call, NULL);
3882 /* We won't get notify::call-channel for this channel, so
3883 * directly call the callback. */
3884 call_handler_notify_call_cb (priv->handler, NULL, self);
3885 g_object_unref (call);
3890 empathy_call_window_realized_cb (GtkWidget *widget,
3891 EmpathyCallWindow *self)
3895 /* Make the hangup button twice as wide */
3896 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3897 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3899 empathy_call_window_connect_handler (self);
3901 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3905 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3906 EmpathyCallWindow *window)
3908 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3910 if (priv->pipeline != NULL)
3912 if (priv->bus_message_source_id != 0)
3914 g_source_remove (priv->bus_message_source_id);
3915 priv->bus_message_source_id = 0;
3918 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3921 if (priv->call_state == CONNECTING)
3922 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3928 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3931 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3933 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3938 gtk_widget_hide (priv->dtmf_panel);
3939 gtk_widget_hide (menu);
3940 gtk_widget_hide (priv->toolbar);
3944 if (priv->dialpad_was_visible_before_fs)
3945 gtk_widget_show (priv->dtmf_panel);
3947 gtk_widget_show (menu);
3948 gtk_widget_show (priv->toolbar);
3950 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3951 priv->original_height_before_fs);
3956 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3958 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3960 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3961 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3963 if (priv->video_output != NULL)
3966 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3967 priv->video_output, TRUE, TRUE,
3968 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3975 empathy_call_window_state_event_cb (GtkWidget *widget,
3976 GdkEventWindowState *event, EmpathyCallWindow *window)
3978 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3980 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3981 gboolean set_fullscreen = event->new_window_state &
3982 GDK_WINDOW_STATE_FULLSCREEN;
3986 gboolean dialpad_was_visible;
3987 GtkAllocation allocation;
3988 gint original_width, original_height;
3990 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3991 original_width = allocation.width;
3992 original_height = allocation.height;
3994 g_object_get (priv->dtmf_panel,
3995 "visible", &dialpad_was_visible,
3998 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3999 priv->original_width_before_fs = original_width;
4000 priv->original_height_before_fs = original_height;
4002 if (priv->video_output_motion_handler_id == 0 &&
4003 priv->video_output != NULL)
4005 priv->video_output_motion_handler_id = g_signal_connect (
4006 G_OBJECT (priv->video_container), "motion-notify-event",
4007 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4013 disconnect_video_output_motion_handler (window);
4016 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4018 show_controls (window, set_fullscreen);
4019 show_borders (window, set_fullscreen);
4020 gtk_action_set_stock_id (priv->menu_fullscreen,
4021 (set_fullscreen ? "view-restore" : "view-fullscreen"));
4022 priv->is_fullscreen = set_fullscreen;
4029 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4032 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4033 int w, h, dialpad_width;
4034 GtkAllocation allocation;
4036 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4037 w = allocation.width;
4038 h = allocation.height;
4040 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4044 gtk_widget_show (priv->dtmf_panel);
4050 gtk_widget_hide (priv->dtmf_panel);
4054 gtk_window_resize (GTK_WINDOW (window), w, h);
4058 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4061 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4062 TpCallChannel *call;
4064 priv->sending_video = (state == CAMERA_STATE_ON);
4066 if (state == CAMERA_STATE_ON)
4068 /* When we start sending video, we want to show the video preview by
4070 display_video_preview (window, TRUE);
4074 display_video_preview (window, FALSE);
4077 if (priv->call_state != CONNECTED)
4080 g_object_get (priv->handler, "call-channel", &call, NULL);
4081 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4082 empathy_call_channel_send_video (call, priv->sending_video);
4083 g_object_unref (call);
4087 empathy_call_window_hangup_cb (gpointer object,
4088 EmpathyCallWindow *self)
4090 /* stopping the call will put it the ENDED state and
4091 * from state_changed_cb we'll reconfigure the window
4093 empathy_call_handler_stop_call (self->priv->handler);
4097 empathy_call_window_restart_call (EmpathyCallWindow *window)
4099 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4101 /* Remove error info bars */
4102 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4103 (GtkCallback) gtk_widget_destroy, NULL);
4105 create_video_output_widget (window);
4106 priv->outgoing = TRUE;
4107 empathy_call_window_set_state_connecting (window);
4109 if (priv->pipeline_playing)
4110 start_call (window);
4112 /* call will be started when the pipeline is ready */
4113 priv->start_call_when_playing = TRUE;
4115 empathy_call_window_setup_avatars (window, priv->handler);
4117 empathy_call_window_show_hangup_button (window, TRUE);
4121 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4122 EmpathyCallWindow *window)
4126 active = gtk_toggle_tool_button_get_active (button);
4128 empathy_call_window_show_dialpad (window, active);
4132 empathy_call_window_fullscreen_cb (gpointer object,
4133 EmpathyCallWindow *window)
4135 empathy_call_window_fullscreen_toggle (window);
4139 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4141 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4143 if (priv->is_fullscreen)
4144 gtk_window_unfullscreen (GTK_WINDOW (window));
4146 gtk_window_fullscreen (GTK_WINDOW (window));
4150 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4151 GdkEventButton *event, EmpathyCallWindow *window)
4153 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4155 empathy_call_window_video_menu_popup (window, event->button);
4163 empathy_call_window_key_press_cb (GtkWidget *video_output,
4164 GdkEventKey *event, EmpathyCallWindow *window)
4166 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4169 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4171 /* Since we are in fullscreen mode, toggling will bring us back to
4173 empathy_call_window_fullscreen_toggle (window);
4177 key = gdk_keyval_to_unicode (event->keyval);
4198 gtk_toggle_tool_button_set_active (
4199 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4201 empathy_dialpad_widget_press_key (
4202 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4208 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4209 GdkEventMotion *event, EmpathyCallWindow *window)
4211 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4213 if (priv->is_fullscreen)
4215 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4217 /* Show the bottom toolbar */
4218 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4225 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4229 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4231 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4233 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4234 button, gtk_get_current_event_time ());
4235 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4239 empathy_call_window_status_message (EmpathyCallWindow *self,
4242 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4246 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4248 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4250 return priv->ui_manager;
4253 EmpathyGstAudioSrc *
4254 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4256 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4258 return (EmpathyGstAudioSrc *) priv->audio_input;
4261 EmpathyGstVideoSrc *
4262 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4264 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4268 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4269 const gchar *device)
4271 EmpathyGstVideoSrc *video;
4274 /* Restart the camera only if it's already running */
4275 running = (self->priv->video_preview != NULL);
4276 video = empathy_call_window_get_video_src (self);
4279 empathy_call_window_play_camera (self, FALSE);
4281 empathy_video_src_change_device (video, device);
4284 empathy_call_window_play_camera (self, TRUE);