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_present (EmpathyCallWindow *self,
2458 EmpathyCallHandler *handler)
2460 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2462 empathy_window_present (GTK_WINDOW (self));
2464 if (self->priv->call_state == DISCONNECTED)
2466 /* start a new call if one is not already in progress */
2467 tp_clear_object (&self->priv->handler);
2468 self->priv->handler = g_object_ref (handler);
2469 empathy_call_window_connect_handler (self);
2471 empathy_call_window_restart_call (self);
2476 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2477 GstElement *conference, gpointer user_data)
2479 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2480 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2481 FsElementAddedNotifier *notifier;
2484 DEBUG ("Conference added");
2486 /* Add notifier to set the various element properties as needed */
2487 notifier = fs_element_added_notifier_new ();
2488 keyfile = fs_utils_get_default_element_properties (conference);
2490 if (keyfile != NULL)
2491 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2493 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2495 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2497 gst_bin_add (GST_BIN (priv->pipeline), conference);
2498 gst_element_set_state (conference, GST_STATE_PLAYING);
2502 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2503 GstElement *conference, gpointer user_data)
2505 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2506 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2508 g_list_free_full (priv->notifiers, g_object_unref);
2509 priv->notifiers = NULL;
2511 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2512 gst_element_set_state (conference, GST_STATE_NULL);
2516 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2518 GstStateChangeReturn state_change_return;
2519 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2521 if (priv->pipeline == NULL)
2524 if (priv->bus_message_source_id != 0)
2526 g_source_remove (priv->bus_message_source_id);
2527 priv->bus_message_source_id = 0;
2530 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2532 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2533 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2535 if (priv->pipeline != NULL)
2536 g_object_unref (priv->pipeline);
2537 priv->pipeline = NULL;
2539 if (priv->audio_output != NULL)
2540 g_object_unref (priv->audio_output);
2541 priv->audio_output = NULL;
2542 priv->audio_output_added = FALSE;
2544 if (priv->video_tee != NULL)
2545 g_object_unref (priv->video_tee);
2546 priv->video_tee = NULL;
2548 if (priv->video_preview != NULL)
2549 clutter_actor_destroy (priv->video_preview);
2550 priv->video_preview = NULL;
2552 /* If we destroy the preview while it's being dragged, we won't
2553 * get the ::drag-end signal, so manually destroy the clone */
2554 if (priv->drag_preview != NULL)
2556 clutter_actor_destroy (priv->drag_preview);
2557 empathy_call_window_show_preview_rectangles (self, FALSE);
2558 priv->drag_preview = NULL;
2561 priv->funnel = NULL;
2563 create_pipeline (self);
2564 /* Call will be started when user will hit the 'redial' button */
2565 priv->start_call_when_playing = FALSE;
2566 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2572 g_message ("Error: could not destroy pipeline. Closing call window");
2573 gtk_widget_destroy (GTK_WIDGET (self));
2580 reset_details_pane (EmpathyCallWindow *self)
2582 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2584 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2585 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2586 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2587 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2591 empathy_call_window_disconnected (EmpathyCallWindow *self,
2594 gboolean could_disconnect = FALSE;
2595 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2596 gboolean could_reset_pipeline;
2598 /* Leave full screen mode if needed */
2599 gtk_window_unfullscreen (GTK_WINDOW (self));
2601 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2603 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2604 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2606 /* Create the video input and then turn on the camera
2607 * menu, so that the active camera gets marked as such.
2609 if (priv->video_input == NULL)
2610 create_video_input (self);
2611 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2613 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2615 if (priv->call_state == CONNECTING)
2616 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2618 if (priv->call_state != REDIALING)
2619 priv->call_state = DISCONNECTED;
2621 /* Show the toolbar */
2622 clutter_state_set_state (priv->transitions, "fade-in");
2624 if (could_reset_pipeline)
2626 g_mutex_lock (&priv->lock);
2628 g_timer_stop (priv->timer);
2630 if (priv->timer_id != 0)
2631 g_source_remove (priv->timer_id);
2634 g_mutex_unlock (&priv->lock);
2637 /* We are about to destroy the window, no need to update it or create
2638 * a video preview */
2641 empathy_call_window_status_message (self, _("Disconnected"));
2643 empathy_call_window_show_hangup_button (self, FALSE);
2645 /* Unsensitive the camera and mic button */
2646 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2647 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2649 /* Be sure that the mic button is enabled */
2650 empathy_audio_src_set_mute (
2651 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2653 if (priv->camera_state == CAMERA_STATE_ON)
2655 /* Restart the preview with the new pipeline. */
2656 display_video_preview (self, TRUE);
2659 /* destroy the video output; it will be recreated when we'll redial */
2660 disconnect_video_output_motion_handler (self);
2661 if (priv->video_output != NULL)
2662 clutter_actor_destroy (priv->video_output);
2663 priv->video_output = NULL;
2664 if (priv->got_video_src > 0)
2666 g_source_remove (priv->got_video_src);
2667 priv->got_video_src = 0;
2670 gtk_widget_show (priv->remote_user_avatar_widget);
2672 reset_details_pane (self);
2674 priv->sending_video = FALSE;
2675 priv->call_started = FALSE;
2677 could_disconnect = TRUE;
2679 /* TODO: display the self avatar of the preview (depends if the "Always
2680 * Show Video Preview" is enabled or not) */
2683 return could_disconnect;
2688 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2691 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2692 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2694 if (empathy_call_window_disconnected (self, TRUE) &&
2695 priv->call_state == REDIALING)
2696 empathy_call_window_restart_call (self);
2700 empathy_call_window_content_is_raw (TfContent *content)
2702 FsConference *conference;
2705 g_object_get (content, "fs-conference", &conference, NULL);
2706 g_assert (conference != NULL);
2708 /* FIXME: Ugly hack, update when moving a packetization property into
2710 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2711 gst_object_unref (conference);
2717 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2719 EmpathyCallWindow *self)
2721 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2722 FsMediaType media_type;
2724 DEBUG ("removing content");
2726 g_object_get (content, "media-type", &media_type, NULL);
2729 * This assumes that there is only one video stream per channel...
2732 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2734 if (priv->funnel != NULL)
2738 output = priv->video_output_sink;
2740 gst_element_set_state (output, GST_STATE_NULL);
2741 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2743 gst_bin_remove (GST_BIN (priv->pipeline), output);
2744 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2745 priv->funnel = NULL;
2748 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2750 if (priv->audio_output != NULL)
2752 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2754 if (priv->audio_output_added)
2755 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2756 priv->audio_output = NULL;
2757 priv->audio_output_added = FALSE;
2762 g_assert_not_reached ();
2769 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2771 EmpathyCallWindow *self)
2773 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2775 DEBUG ("Framerate changed to %u", framerate);
2777 if (priv->video_input != NULL)
2778 empathy_video_src_set_framerate (priv->video_input, framerate);
2782 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2785 EmpathyCallWindow *self)
2787 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2789 DEBUG ("Resolution changed to %ux%u", width, height);
2791 if (priv->video_input != NULL)
2793 empathy_video_src_set_resolution (priv->video_input, width, height);
2797 /* Called with global lock held */
2799 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2801 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2805 if (priv->funnel == NULL)
2807 output = priv->video_output_sink;
2809 priv->funnel = gst_element_factory_make ("funnel", NULL);
2811 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2816 g_warning ("Could not create video funnel");
2820 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2822 gst_object_unref (priv->funnel);
2823 priv->funnel = NULL;
2824 g_warning ("Could not add funnel to pipeline");
2828 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2830 g_warning ("Could not add the video output widget to the pipeline");
2834 if (!gst_element_link (priv->funnel, output))
2836 g_warning ("Could not link output sink to funnel");
2837 goto error_output_added;
2840 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2842 g_warning ("Could not start video sink");
2843 goto error_output_added;
2846 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2848 g_warning ("Could not start funnel");
2849 goto error_output_added;
2853 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2855 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2859 g_warning ("Could not get request pad from funnel");
2866 gst_element_set_locked_state (priv->funnel, TRUE);
2867 gst_element_set_locked_state (output, TRUE);
2869 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2870 gst_element_set_state (output, GST_STATE_NULL);
2872 gst_bin_remove (GST_BIN (priv->pipeline), output);
2873 gst_element_set_locked_state (output, FALSE);
2877 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2878 priv->funnel = NULL;
2883 /* Called with global lock held */
2885 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2888 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2890 GstPadTemplate *template;
2892 if (!priv->audio_output_added)
2894 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2896 g_warning ("Could not add audio sink to pipeline");
2897 g_object_unref (priv->audio_output);
2898 goto error_add_output;
2901 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2903 g_warning ("Could not start audio sink");
2908 template = gst_element_class_get_pad_template (
2909 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2911 pad = gst_element_request_pad (priv->audio_output,
2912 template, NULL, NULL);
2916 g_warning ("Could not get sink pad from sink");
2923 gst_element_set_locked_state (priv->audio_output, TRUE);
2924 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2925 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2926 priv->audio_output = NULL;
2934 empathy_call_window_update_timer (gpointer user_data)
2936 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2937 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2938 const gchar *status;
2942 time_ = g_timer_elapsed (priv->timer, NULL);
2944 if (priv->call_state == HELD)
2945 status = _("On hold");
2946 else if (priv->call_state == DISCONNECTED)
2947 status = _("Disconnected");
2948 else if (priv->muted)
2951 status = _("Duration");
2953 /* Translators: 'status - minutes:seconds' the caller has been connected */
2954 str = g_strdup_printf (_("%s — %d:%02dm"),
2956 (int) time_ / 60, (int) time_ % 60);
2957 empathy_call_window_status_message (self, str);
2965 EMP_RESPONSE_BALANCE
2969 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2973 switch (response_id)
2975 case GTK_RESPONSE_CLOSE:
2976 gtk_widget_destroy (GTK_WIDGET (info_bar));
2978 case EMP_RESPONSE_BALANCE:
2979 empathy_url_show (GTK_WIDGET (info_bar),
2980 g_object_get_data (G_OBJECT (info_bar), "uri"));
2986 display_error (EmpathyCallWindow *self,
2990 const gchar *details,
2991 const gchar *button_text,
2993 gint button_response)
2995 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2996 GtkWidget *info_bar;
2997 GtkWidget *content_area;
3004 /* Create info bar */
3005 info_bar = gtk_info_bar_new ();
3007 if (button_text != NULL)
3009 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3010 button_text, button_response);
3011 g_object_set_data_full (G_OBJECT (info_bar),
3012 "uri", g_strdup (uri), g_free);
3015 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3016 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3018 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3020 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3022 /* hbox containing the image and the messages vbox */
3023 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3024 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3027 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3028 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3030 /* vbox containing the main message and the details expander */
3031 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3032 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3035 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3037 label = gtk_label_new (NULL);
3038 gtk_label_set_markup (GTK_LABEL (label), txt);
3039 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3040 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3043 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3046 if (details != NULL)
3048 GtkWidget *expander;
3050 expander = gtk_expander_new (_("Technical Details"));
3052 txt = g_strdup_printf ("<i>%s</i>", details);
3054 label = gtk_label_new (NULL);
3055 gtk_label_set_markup (GTK_LABEL (label), txt);
3056 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3057 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3060 gtk_container_add (GTK_CONTAINER (expander), label);
3061 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3064 g_signal_connect (info_bar, "response",
3065 G_CALLBACK (on_error_infobar_response_cb), NULL);
3067 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3068 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3069 gtk_widget_show_all (info_bar);
3074 media_stream_error_to_txt (EmpathyCallWindow *self,
3075 TpCallChannel *call,
3077 TpMediaStreamError error)
3079 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3080 const gchar *cm = NULL;
3086 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3088 return g_strdup_printf (
3089 _("%s's software does not understand any of the audio formats "
3090 "supported by your computer"),
3091 empathy_contact_get_alias (priv->contact));
3093 return g_strdup_printf (
3094 _("%s's software does not understand any of the video formats "
3095 "supported by your computer"),
3096 empathy_contact_get_alias (priv->contact));
3098 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3099 return g_strdup_printf (
3100 _("Can't establish a connection to %s. "
3101 "One of you might be on a network that does not allow "
3102 "direct connections."),
3103 empathy_contact_get_alias (priv->contact));
3105 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3106 return g_strdup (_("There was a failure on the network"));
3108 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3110 return g_strdup (_("The audio formats necessary for this call "
3111 "are not installed on your computer"));
3113 return g_strdup (_("The video formats necessary for this call "
3114 "are not installed on your computer"));
3116 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3117 tp_connection_parse_object_path (
3118 tp_channel_get_connection (TP_CHANNEL (call)),
3121 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3122 "product=Telepathy&component=%s", cm);
3124 result = g_strdup_printf (
3125 _("Something unexpected happened in a Telepathy component. "
3126 "Please <a href=\"%s\">report this bug</a> and attach "
3127 "logs gathered from the 'Debug' window in the Help menu."), url);
3133 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3134 return g_strdup (_("There was a failure in the call engine"));
3136 case TP_MEDIA_STREAM_ERROR_EOS:
3137 return g_strdup (_("The end of the stream was reached"));
3139 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3146 empathy_call_window_stream_error (EmpathyCallWindow *self,
3147 TpCallChannel *call,
3156 desc = media_stream_error_to_txt (self, call, audio, code);
3159 /* No description, use the error message. That's not great as it's not
3160 * localized but it's better than nothing. */
3161 display_error (self, call, icon, title, msg, NULL);
3165 display_error (self, call, icon, title, desc, msg);
3171 empathy_call_window_audio_stream_error (TpCallChannel *call,
3174 EmpathyCallWindow *self)
3176 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3177 "gnome-stock-mic", _("Can't establish audio stream"));
3181 empathy_call_window_video_stream_error (TpCallChannel *call,
3184 EmpathyCallWindow *self)
3186 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3187 "camera-web", _("Can't establish video stream"));
3192 show_balance_error (EmpathyCallWindow *self)
3196 gchar *balance, *tmp;
3197 const gchar *uri, *currency;
3201 g_object_get (self->priv->handler,
3202 "call-channel", &call,
3205 conn = tp_channel_get_connection (call);
3206 g_object_unref (call);
3208 uri = tp_connection_get_balance_uri (conn);
3210 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3212 /* unknown balance */
3213 balance = g_strdup ("(--)");
3217 char *money = empathy_format_currency (amount, scale, currency);
3219 balance = g_strdup_printf ("%s %s",
3224 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3226 display_error (self,
3228 _("Sorry, you don’t have enough credit for that call."),
3232 EMP_RESPONSE_BALANCE);
3239 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3242 EmpathyCallWindow *self)
3244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3245 TpCallChannel *call;
3246 gboolean can_send_video;
3248 if (state == TP_CALL_STATE_ENDED)
3250 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3251 empathy_call_window_disconnected (self, TRUE);
3252 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3253 show_balance_error (self);
3257 if (state != TP_CALL_STATE_ACCEPTED)
3260 if (priv->call_state == CONNECTED)
3263 g_timer_start (priv->timer);
3264 priv->call_state = CONNECTED;
3266 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3268 can_send_video = priv->video_input != NULL &&
3269 empathy_contact_can_voip_video (priv->contact) &&
3270 empathy_camera_monitor_get_available (priv->camera_monitor);
3272 g_object_get (priv->handler, "call-channel", &call, NULL);
3274 if (tp_call_channel_has_dtmf (call))
3275 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3277 if (priv->video_input == NULL)
3278 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3280 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3282 empathy_call_window_show_hangup_button (self, TRUE);
3284 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3286 clutter_actor_hide (priv->video_output);
3287 gtk_widget_show (priv->remote_user_avatar_widget);
3289 g_object_unref (call);
3291 g_mutex_lock (&priv->lock);
3293 priv->timer_id = g_timeout_add_seconds (1,
3294 empathy_call_window_update_timer, self);
3296 g_mutex_unlock (&priv->lock);
3298 empathy_call_window_update_timer (self);
3300 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3304 empathy_call_window_show_video_output_cb (gpointer user_data)
3306 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3308 if (self->priv->video_output != NULL)
3310 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3311 clutter_actor_show (self->priv->video_output);
3312 clutter_actor_raise_top (self->priv->overlay_bin);
3319 empathy_call_window_check_video_cb (gpointer data)
3321 EmpathyCallWindow *self = data;
3323 if (self->priv->got_video)
3325 self->priv->got_video = FALSE;
3329 /* No video in the last N seconds, display the remote avatar */
3330 empathy_call_window_show_video_output (self, FALSE);
3335 /* Called from the streaming thread */
3337 static GstPadProbeReturn
3338 empathy_call_window_video_probe_cb (GstPad *pad,
3339 GstPadProbeInfo *info,
3342 EmpathyCallWindow *self = user_data;
3344 if (G_UNLIKELY (!self->priv->got_video))
3346 /* show the remote video */
3347 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3348 empathy_call_window_show_video_output_cb,
3349 g_object_ref (self), g_object_unref);
3351 self->priv->got_video = TRUE;
3354 return GST_PAD_PROBE_OK;
3358 empathy_call_window_video_probe_cb (GstPad *pad,
3359 GstMiniObject *mini_obj,
3360 EmpathyCallWindow *self)
3363 if (GST_IS_EVENT (mini_obj))
3366 if (G_UNLIKELY (!self->priv->got_video))
3368 /* show the remote video */
3369 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3370 empathy_call_window_show_video_output_cb,
3371 g_object_ref (self), g_object_unref);
3373 self->priv->got_video = TRUE;
3380 /* Called from the streaming thread */
3382 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3383 TfContent *content, GstPad *src, gpointer user_data)
3385 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3386 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3387 gboolean retval = FALSE;
3392 g_mutex_lock (&priv->lock);
3394 g_object_get (content, "media-type", &media_type, NULL);
3398 case TP_MEDIA_STREAM_TYPE_AUDIO:
3399 pad = empathy_call_window_get_audio_sink_pad (self, content);
3401 case TP_MEDIA_STREAM_TYPE_VIDEO:
3402 g_idle_add (empathy_call_window_show_video_output_cb, self);
3403 pad = empathy_call_window_get_video_sink_pad (self);
3406 gst_pad_add_probe (src,
3407 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3408 empathy_call_window_video_probe_cb, self, NULL);
3410 gst_pad_add_data_probe (src,
3411 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3413 if (priv->got_video_src > 0)
3414 g_source_remove (priv->got_video_src);
3415 priv->got_video_src = g_timeout_add_seconds (1,
3416 empathy_call_window_check_video_cb, self);
3419 g_assert_not_reached ();
3425 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3426 g_warning ("Could not link %s sink pad",
3427 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3431 gst_object_unref (pad);
3435 /* If no sink could be linked, try to add fakesink to prevent the whole call
3440 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3442 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3444 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3445 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3446 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3448 gst_element_set_locked_state (fakesink, TRUE);
3449 gst_element_set_state (fakesink, GST_STATE_NULL);
3450 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3454 DEBUG ("Could not link real sink, linked fakesink instead");
3456 gst_object_unref (sinkpad);
3460 gst_object_unref (fakesink);
3465 g_mutex_unlock (&priv->lock);
3471 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3474 EmpathyCallWindowPriv *priv = self->priv;
3476 g_assert (priv->audio_output_added == FALSE);
3477 g_assert (priv->audio_output == FALSE);
3479 priv->audio_output = empathy_audio_sink_new ();
3480 g_object_ref_sink (priv->audio_output);
3482 /* volume button to output volume linking */
3483 g_object_bind_property (priv->audio_output, "volume",
3484 priv->volume_button, "value",
3485 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3487 g_object_bind_property_full (content, "requested-output-volume",
3488 priv->audio_output, "volume",
3490 audio_control_volume_to_element,
3491 element_volume_to_audio_control,
3494 /* Link volumes together, sync the current audio input volume property
3495 * back to farstream first */
3496 g_object_bind_property_full (priv->audio_output, "volume",
3497 content, "reported-output-volume",
3498 G_BINDING_SYNC_CREATE,
3499 element_volume_to_audio_control,
3500 audio_control_volume_to_element,
3503 /* For raw audio conferences assume that the producer of the raw data
3504 * has already processed it, so turn off any echo cancellation and any
3505 * other audio improvements that come with it */
3506 empathy_audio_sink_set_echo_cancel (
3507 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3508 !empathy_call_window_content_is_raw (content));
3513 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3514 TfContent *content, gpointer user_data)
3516 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3519 FsMediaType media_type;
3520 gboolean retval = FALSE;
3522 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3523 g_assert (sink != NULL);
3527 case FS_MEDIA_TYPE_AUDIO:
3529 /* For raw audio conferences assume that the receiver of the raw data
3530 * wants it unprocessed, so turn off any echo cancellation and any
3531 * other audio improvements that come with it */
3532 empathy_audio_src_set_echo_cancel (
3533 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3534 !empathy_call_window_content_is_raw (content));
3536 /* Link volumes together, sync the current audio input volume property
3537 * back to farstream first */
3538 g_object_bind_property_full (content, "requested-input-volume",
3539 priv->audio_input, "volume",
3541 audio_control_volume_to_element,
3542 element_volume_to_audio_control,
3545 g_object_bind_property_full (priv->audio_input, "volume",
3546 content, "reported-input-volume",
3547 G_BINDING_SYNC_CREATE,
3548 element_volume_to_audio_control,
3549 audio_control_volume_to_element,
3552 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3554 g_warning ("Could not add audio source to pipeline");
3558 pad = gst_element_get_static_pad (priv->audio_input, "src");
3561 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3562 g_warning ("Could not get source pad from audio source");
3566 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3568 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3569 gst_object_unref (pad);
3570 g_warning ("Could not link audio source to farsight");
3573 gst_object_unref (pad);
3575 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3577 g_warning ("Could not start audio source");
3578 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3579 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3583 /* Prepare our audio output, not added yet though */
3584 empathy_call_window_prepare_audio_output (self, content);
3588 case FS_MEDIA_TYPE_VIDEO:
3589 if (priv->video_tee != NULL)
3592 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3594 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3596 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3598 g_warning ("Could not link video source input pipeline");
3601 gst_object_unref (pad);
3607 g_assert_not_reached ();
3610 gst_object_unref (sink);
3615 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3617 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3618 GstElement *preview;
3620 disable_camera (self);
3622 DEBUG ("remove video input");
3623 preview = priv->video_preview_sink;
3625 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3626 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3627 gst_element_set_state (preview, GST_STATE_NULL);
3629 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3632 g_object_unref (priv->video_input);
3633 priv->video_input = NULL;
3634 g_object_unref (priv->video_tee);
3635 priv->video_tee = NULL;
3636 clutter_actor_destroy (priv->video_preview);
3637 priv->video_preview = NULL;
3639 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3640 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3644 start_call (EmpathyCallWindow *self)
3646 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3648 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3650 priv->call_started = TRUE;
3651 empathy_call_handler_start_call (priv->handler,
3652 gtk_get_current_event_time ());
3654 if (empathy_call_handler_has_initial_video (priv->handler))
3656 TpCallChannel *call;
3659 g_object_get (priv->handler, "call-channel", &call, NULL);
3660 /* If the call channel isn't set yet we're requesting it, if we're
3661 * requesting it with initial video it should be PENDING_SEND when we get
3664 s = TP_SENDING_STATE_PENDING_SEND;
3666 s = empathy_call_channel_get_video_state (call);
3668 if (s == TP_SENDING_STATE_PENDING_SEND ||
3669 s == TP_SENDING_STATE_SENDING)
3671 /* Enable 'send video' buttons and display the preview */
3672 gtk_toggle_button_set_active (
3673 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3677 gtk_toggle_button_set_active (
3678 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3680 if (priv->video_preview == NULL)
3682 create_video_preview (self);
3683 add_video_preview_to_pipeline (self);
3688 g_object_unref (call);
3693 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3696 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3697 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3698 GstState newstate, pending;
3700 empathy_call_handler_bus_message (priv->handler, bus, message);
3702 switch (GST_MESSAGE_TYPE (message))
3704 case GST_MESSAGE_STATE_CHANGED:
3705 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3707 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3709 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3710 !priv->call_started)
3712 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3713 if (newstate == GST_STATE_PAUSED)
3715 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3716 priv->pipeline_playing = TRUE;
3718 if (priv->start_call_when_playing)
3722 if (priv->video_preview_sink != NULL &&
3723 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3725 gst_message_parse_state_changed (message, NULL, &newstate,
3728 if (newstate == GST_STATE_PLAYING &&
3729 pending == GST_STATE_VOID_PENDING)
3730 empathy_call_window_stop_camera_spinning (self);
3733 case GST_MESSAGE_ERROR:
3735 GError *error = NULL;
3736 GstElement *gst_error;
3740 gst_message_parse_error (message, &error, &debug);
3741 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3743 g_message ("Element error: %s -- %s\n", error->message, debug);
3745 name = gst_element_get_name (gst_error);
3746 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3748 /* Remove the video input and continue */
3749 if (priv->video_input != NULL)
3750 empathy_call_window_remove_video_input (self);
3751 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3755 empathy_call_window_disconnected (self, TRUE);
3758 g_error_free (error);
3761 case GST_MESSAGE_UNKNOWN:
3762 case GST_MESSAGE_EOS:
3763 case GST_MESSAGE_WARNING:
3764 case GST_MESSAGE_INFO:
3765 case GST_MESSAGE_TAG:
3766 case GST_MESSAGE_BUFFERING:
3767 case GST_MESSAGE_STATE_DIRTY:
3768 case GST_MESSAGE_STEP_DONE:
3769 case GST_MESSAGE_CLOCK_PROVIDE:
3770 case GST_MESSAGE_CLOCK_LOST:
3771 case GST_MESSAGE_NEW_CLOCK:
3772 case GST_MESSAGE_STRUCTURE_CHANGE:
3773 case GST_MESSAGE_STREAM_STATUS:
3774 case GST_MESSAGE_APPLICATION:
3775 case GST_MESSAGE_ELEMENT:
3776 case GST_MESSAGE_SEGMENT_START:
3777 case GST_MESSAGE_SEGMENT_DONE:
3778 case GST_MESSAGE_DURATION:
3779 case GST_MESSAGE_ANY:
3788 empathy_call_window_members_changed_cb (TpCallChannel *call,
3789 GHashTable *updates,
3791 TpCallStateReason *reason,
3792 EmpathyCallWindow *self)
3794 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3795 GHashTableIter iter;
3796 gpointer key, value;
3797 gboolean held = FALSE;
3799 g_hash_table_iter_init (&iter, updates);
3800 while (g_hash_table_iter_next (&iter, &key, &value))
3802 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3804 /* This assumes this is a 1-1 call, otherwise one participant
3805 * putting the call on hold wouldn't mean the call is on hold
3813 priv->call_state = HELD;
3814 else if (priv->call_state == HELD)
3815 priv->call_state = CONNECTED;
3819 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3821 EmpathyCallWindow *self)
3823 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3824 TpCallChannel *call;
3826 g_object_get (priv->handler, "call-channel", &call, NULL);
3831 tp_g_signal_connect_object (call, "audio-stream-error",
3832 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3833 tp_g_signal_connect_object (call, "video-stream-error",
3834 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3837 tp_g_signal_connect_object (call, "members-changed",
3838 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3840 g_object_unref (call);
3844 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3846 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3847 TpCallChannel *call;
3849 g_signal_connect (priv->handler, "state-changed",
3850 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3851 g_signal_connect (priv->handler, "conference-added",
3852 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3853 g_signal_connect (priv->handler, "conference-removed",
3854 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3855 g_signal_connect (priv->handler, "closed",
3856 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3857 g_signal_connect (priv->handler, "src-pad-added",
3858 G_CALLBACK (empathy_call_window_src_added_cb), self);
3859 g_signal_connect (priv->handler, "content-added",
3860 G_CALLBACK (empathy_call_window_content_added_cb), self);
3861 g_signal_connect (priv->handler, "content-removed",
3862 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3864 /* We connect to ::call-channel unconditionally since we'll
3865 * get new channels if we hangup and redial or if we reuse the
3867 g_signal_connect (priv->handler, "notify::call-channel",
3868 G_CALLBACK (call_handler_notify_call_cb), self);
3870 g_signal_connect (priv->handler, "framerate-changed",
3871 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3872 g_signal_connect (priv->handler, "resolution-changed",
3873 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3875 g_object_get (priv->handler, "call-channel", &call, NULL);
3878 /* We won't get notify::call-channel for this channel, so
3879 * directly call the callback. */
3880 call_handler_notify_call_cb (priv->handler, NULL, self);
3881 g_object_unref (call);
3886 empathy_call_window_realized_cb (GtkWidget *widget,
3887 EmpathyCallWindow *self)
3891 /* Make the hangup button twice as wide */
3892 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3893 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3895 empathy_call_window_connect_handler (self);
3897 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3901 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3902 EmpathyCallWindow *window)
3904 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3906 if (priv->pipeline != NULL)
3908 if (priv->bus_message_source_id != 0)
3910 g_source_remove (priv->bus_message_source_id);
3911 priv->bus_message_source_id = 0;
3914 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3917 if (priv->call_state == CONNECTING)
3918 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3924 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3927 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3929 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3934 gtk_widget_hide (priv->dtmf_panel);
3935 gtk_widget_hide (menu);
3936 gtk_widget_hide (priv->toolbar);
3940 if (priv->dialpad_was_visible_before_fs)
3941 gtk_widget_show (priv->dtmf_panel);
3943 gtk_widget_show (menu);
3944 gtk_widget_show (priv->toolbar);
3946 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3947 priv->original_height_before_fs);
3952 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3954 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3956 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3957 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3959 if (priv->video_output != NULL)
3962 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3963 priv->video_output, TRUE, TRUE,
3964 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3971 empathy_call_window_state_event_cb (GtkWidget *widget,
3972 GdkEventWindowState *event, EmpathyCallWindow *window)
3974 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3976 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3977 gboolean set_fullscreen = event->new_window_state &
3978 GDK_WINDOW_STATE_FULLSCREEN;
3982 gboolean dialpad_was_visible;
3983 GtkAllocation allocation;
3984 gint original_width, original_height;
3986 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3987 original_width = allocation.width;
3988 original_height = allocation.height;
3990 g_object_get (priv->dtmf_panel,
3991 "visible", &dialpad_was_visible,
3994 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3995 priv->original_width_before_fs = original_width;
3996 priv->original_height_before_fs = original_height;
3998 if (priv->video_output_motion_handler_id == 0 &&
3999 priv->video_output != NULL)
4001 priv->video_output_motion_handler_id = g_signal_connect (
4002 G_OBJECT (priv->video_container), "motion-notify-event",
4003 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4009 disconnect_video_output_motion_handler (window);
4012 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4014 show_controls (window, set_fullscreen);
4015 show_borders (window, set_fullscreen);
4016 gtk_action_set_stock_id (priv->menu_fullscreen,
4017 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
4018 priv->is_fullscreen = set_fullscreen;
4025 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4028 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4029 int w, h, dialpad_width;
4030 GtkAllocation allocation;
4032 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4033 w = allocation.width;
4034 h = allocation.height;
4036 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4040 gtk_widget_show (priv->dtmf_panel);
4046 gtk_widget_hide (priv->dtmf_panel);
4050 gtk_window_resize (GTK_WINDOW (window), w, h);
4054 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4057 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4058 TpCallChannel *call;
4060 priv->sending_video = (state == CAMERA_STATE_ON);
4062 if (state == CAMERA_STATE_ON)
4064 /* When we start sending video, we want to show the video preview by
4066 display_video_preview (window, TRUE);
4070 display_video_preview (window, FALSE);
4073 if (priv->call_state != CONNECTED)
4076 g_object_get (priv->handler, "call-channel", &call, NULL);
4077 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4078 empathy_call_channel_send_video (call, priv->sending_video);
4079 g_object_unref (call);
4083 empathy_call_window_hangup_cb (gpointer object,
4084 EmpathyCallWindow *self)
4086 /* stopping the call will put it the ENDED state and
4087 * from state_changed_cb we'll reconfigure the window
4089 empathy_call_handler_stop_call (self->priv->handler);
4093 empathy_call_window_restart_call (EmpathyCallWindow *window)
4095 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4097 /* Remove error info bars */
4098 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4099 (GtkCallback) gtk_widget_destroy, NULL);
4101 create_video_output_widget (window);
4102 priv->outgoing = TRUE;
4103 empathy_call_window_set_state_connecting (window);
4105 if (priv->pipeline_playing)
4106 start_call (window);
4108 /* call will be started when the pipeline is ready */
4109 priv->start_call_when_playing = TRUE;
4111 empathy_call_window_setup_avatars (window, priv->handler);
4113 empathy_call_window_show_hangup_button (window, TRUE);
4117 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4118 EmpathyCallWindow *window)
4122 active = gtk_toggle_tool_button_get_active (button);
4124 empathy_call_window_show_dialpad (window, active);
4128 empathy_call_window_fullscreen_cb (gpointer object,
4129 EmpathyCallWindow *window)
4131 empathy_call_window_fullscreen_toggle (window);
4135 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4137 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4139 if (priv->is_fullscreen)
4140 gtk_window_unfullscreen (GTK_WINDOW (window));
4142 gtk_window_fullscreen (GTK_WINDOW (window));
4146 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4147 GdkEventButton *event, EmpathyCallWindow *window)
4149 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4151 empathy_call_window_video_menu_popup (window, event->button);
4159 empathy_call_window_key_press_cb (GtkWidget *video_output,
4160 GdkEventKey *event, EmpathyCallWindow *window)
4162 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4165 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4167 /* Since we are in fullscreen mode, toggling will bring us back to
4169 empathy_call_window_fullscreen_toggle (window);
4173 key = gdk_keyval_to_unicode (event->keyval);
4194 gtk_toggle_tool_button_set_active (
4195 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4197 empathy_dialpad_widget_press_key (
4198 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4204 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4205 GdkEventMotion *event, EmpathyCallWindow *window)
4207 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4209 if (priv->is_fullscreen)
4211 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4213 /* Show the bottom toolbar */
4214 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4221 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4225 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4227 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4229 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4230 button, gtk_get_current_event_time ());
4231 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4235 empathy_call_window_status_message (EmpathyCallWindow *self,
4238 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4242 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4244 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4246 return priv->ui_manager;
4249 EmpathyGstAudioSrc *
4250 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4252 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4254 return (EmpathyGstAudioSrc *) priv->audio_input;
4257 EmpathyGstVideoSrc *
4258 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4260 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4264 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4265 const gchar *device)
4267 EmpathyGstVideoSrc *video;
4270 /* Restart the camera only if it's already running */
4271 running = (self->priv->video_preview != NULL);
4272 video = empathy_call_window_get_video_src (self);
4275 empathy_call_window_play_camera (self, FALSE);
4277 empathy_video_src_change_device (video, device);
4280 empathy_call_window_play_camera (self, TRUE);