2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "empathy-call-window.h"
24 #include <glib/gi18n.h>
25 #include <telepathy-farstream/telepathy-farstream.h>
26 #include <farstream/fs-element-added-notifier.h>
27 #include <farstream/fs-utils.h>
28 #include <tp-account-widgets/tpaw-builder.h>
29 #include <tp-account-widgets/tpaw-camera-monitor.h>
30 #include <tp-account-widgets/tpaw-images.h>
31 #include <tp-account-widgets/tpaw-pixbuf-utils.h>
32 #include <tp-account-widgets/tpaw-utils.h>
34 #include "empathy-about-dialog.h"
35 #include "empathy-audio-sink.h"
36 #include "empathy-call-utils.h"
37 #include "empathy-call-window-fullscreen.h"
38 #include "empathy-camera-menu.h"
39 #include "empathy-dialpad-widget.h"
40 #include "empathy-geometry.h"
41 #include "empathy-gsettings.h"
42 #include "empathy-images.h"
43 #include "empathy-mic-menu.h"
44 #include "empathy-preferences.h"
45 #include "empathy-request-util.h"
46 #include "empathy-rounded-actor.h"
47 #include "empathy-rounded-rectangle.h"
48 #include "empathy-rounded-texture.h"
49 #include "empathy-sound-manager.h"
50 #include "empathy-ui-utils.h"
51 #include "empathy-utils.h"
53 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
54 #include "empathy-debug.h"
56 #define CONTENT_HBOX_SPACING 3
57 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
58 #define OVERLAY_MARGIN 6
60 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
61 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
63 #define SELF_VIDEO_SECTION_WIDTH 120
64 #define SELF_VIDEO_SECTION_HEIGHT 90
65 #define SELF_VIDEO_SECTION_MARGIN 2
66 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
68 /* The avatar's default width and height are set to the same value because we
69 want a square icon. */
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
71 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
73 #define SMALL_TOOLBAR_SIZE 36
75 /* If an video input error occurs, the error message will start with "v4l" */
76 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
78 /* The time interval in milliseconds between 2 outgoing rings */
79 #define MS_BETWEEN_RING 500
81 /* The roundedness of preview box and placeholders */
82 #define PREVIEW_ROUND_FACTOR 16
84 #define PREVIEW_BUTTON_OPACITY 180
86 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
89 PROP_CALL_HANDLER = 1,
97 static guint signals[LAST_SIGNAL];
100 RINGING, /* Incoming call */
101 CONNECTING, /* Outgoing call */
102 CONNECTED, /* Connected */
103 HELD, /* Connected, but on hold */
104 DISCONNECTED, /* Disconnected */
105 REDIALING /* Redialing (special case of CONNECTING) */
109 CAMERA_STATE_OFF = 0,
115 PREVIEW_POS_TOP_LEFT,
116 PREVIEW_POS_TOP_RIGHT,
117 PREVIEW_POS_BOTTOM_LEFT,
118 PREVIEW_POS_BOTTOM_RIGHT,
121 struct _EmpathyCallWindowPriv
123 gboolean dispose_has_run;
124 EmpathyCallHandler *handler;
126 EmpathyContact *contact;
128 TpawCameraMonitor *camera_monitor;
130 CallState call_state;
133 GtkUIManager *ui_manager;
134 GtkWidget *errors_vbox;
135 /* widget displays the video received from the remote user. This widget is
136 * alive only during call. */
137 ClutterActor *video_output;
138 ClutterActor *video_preview;
139 ClutterActor *drag_preview;
140 ClutterActor *preview_shown_button;
141 ClutterActor *preview_hidden_button;
142 ClutterActor *preview_rectangle1;
143 ClutterActor *preview_rectangle2;
144 ClutterActor *preview_rectangle3;
145 ClutterActor *preview_rectangle4;
146 ClutterActor *preview_spinner_actor;
147 GtkWidget *preview_spinner_widget;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *remote_user_status_toolbar;
153 GtkWidget *status_label;
154 GtkWidget *hangup_button;
155 GtkWidget *audio_call_button;
156 GtkWidget *video_call_button;
157 GtkWidget *mic_button;
158 GtkWidget *microphone_icon;
159 GtkWidget *volume_button;
160 GtkWidget *camera_button;
161 GtkWidget *dialpad_button;
163 GtkWidget *bottom_toolbar;
164 ClutterActor *floating_toolbar;
166 GtkAction *menu_fullscreen;
167 GtkAction *menu_swap_camera;
169 ClutterState *transitions;
171 /* The main box covering all the stage, contaning remote avatar/video */
172 ClutterActor *video_box;
173 ClutterLayoutManager *video_layout;
175 /* A bin layout manager containing a bin for previews
176 * and the floating toolbar */
177 ClutterActor *overlay_bin;
178 ClutterLayoutManager *overlay_layout;
180 /* Bin layout for the previews */
181 ClutterActor *preview_box;
182 ClutterLayoutManager *preview_layout;
184 /* Coordinates of the preview drag event's start. */
185 PreviewPosition preview_pos;
187 /* We keep a reference on the hbox which contains the main content so we can
188 easilly repack everything when toggling fullscreen */
189 GtkWidget *content_hbox;
191 /* These are used to accept or reject an incoming call when the status
193 GtkWidget *incoming_call_dialog;
194 TpCallChannel *pending_channel;
195 TpChannelDispatchOperation *pending_cdo;
196 TpAddDispatchOperationContext *pending_context;
198 gulong video_output_motion_handler_id;
199 guint bus_message_source_id;
201 GtkWidget *dtmf_panel;
204 GtkWidget *details_vbox;
205 GtkWidget *vcodec_encoding_label;
206 GtkWidget *acodec_encoding_label;
207 GtkWidget *vcodec_decoding_label;
208 GtkWidget *acodec_decoding_label;
210 GtkWidget *audio_remote_candidate_label;
211 GtkWidget *audio_local_candidate_label;
212 GtkWidget *video_remote_candidate_label;
213 GtkWidget *video_local_candidate_label;
214 GtkWidget *video_remote_candidate_info_img;
215 GtkWidget *video_local_candidate_info_img;
216 GtkWidget *audio_remote_candidate_info_img;
217 GtkWidget *audio_local_candidate_info_img;
219 GstElement *video_input;
220 GstElement *video_preview_sink;
221 GstElement *video_output_sink;
222 GstElement *audio_input;
223 GstElement *audio_output;
224 gboolean audio_output_added;
225 GstElement *pipeline;
226 GstElement *video_tee;
236 gboolean call_started;
237 gboolean sending_video;
238 CameraState camera_state;
240 EmpathyCallWindowFullscreen *fullscreen;
241 gboolean is_fullscreen;
246 guint inactivity_src;
248 /* Those fields represent the state of the window before it actually was in
250 gboolean dialpad_was_visible_before_fs;
251 gint original_width_before_fs;
252 gint original_height_before_fs;
254 gint x, y, w, h, dialpad_width;
257 /* TRUE if the call should be started when the pipeline is playing */
258 gboolean start_call_when_playing;
259 /* TRUE if we requested to set the pipeline in the playing state */
260 gboolean pipeline_playing;
262 EmpathySoundManager *sound_mgr;
265 EmpathyMicMenu *mic_menu;
266 EmpathyCameraMenu *camera_menu;
271 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
273 static void empathy_call_window_realized_cb (GtkWidget *widget,
274 EmpathyCallWindow *window);
276 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
277 GdkEvent *event, EmpathyCallWindow *window);
279 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
280 GdkEventWindowState *event, EmpathyCallWindow *window);
282 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
285 static void empathy_call_window_hangup_cb (gpointer object,
286 EmpathyCallWindow *window);
288 static void empathy_call_window_fullscreen_cb (gpointer object,
289 EmpathyCallWindow *window);
291 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
293 static gboolean empathy_call_window_video_button_press_cb (
294 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
296 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
297 GdkEventKey *event, EmpathyCallWindow *window);
299 static gboolean empathy_call_window_video_output_motion_notify (
300 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
302 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
305 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
307 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
308 EmpathyCallWindow *window);
310 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
312 static void empathy_call_window_status_message (EmpathyCallWindow *window,
315 static gboolean empathy_call_window_bus_message (GstBus *bus,
316 GstMessage *message, gpointer user_data);
318 static gboolean empathy_call_window_update_timer (gpointer user_data);
321 make_background_transparent (GtkClutterActor *actor)
323 GdkRGBA transparent = { 0., 0., 0., 0. };
326 widget = gtk_clutter_actor_get_widget (actor);
327 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
331 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
334 gtk_widget_set_visible (self->priv->hangup_button, show);
335 gtk_widget_set_visible (self->priv->audio_call_button, !show);
336 gtk_widget_set_visible (self->priv->video_call_button, !show);
340 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
341 EmpathyCallWindow *self)
343 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
344 empathy_call_window_restart_call (self);
348 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
349 EmpathyCallWindow *self)
351 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
352 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
353 empathy_call_window_restart_call (self);
357 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
359 EmpathyCallWindow *self)
364 g_object_get (self->priv->handler, "call-channel", &call, NULL);
366 tones[0] = tp_dtmf_event_to_char (event);
368 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
370 g_object_unref (call);
374 empathy_call_window_show_video_output (EmpathyCallWindow *self,
377 if (self->priv->video_output != NULL)
378 g_object_set (self->priv->video_output, "visible", show, NULL);
380 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
382 clutter_actor_raise_top (self->priv->overlay_bin);
386 create_video_output_widget (EmpathyCallWindow *self)
388 EmpathyCallWindowPriv *priv = GET_PRIV (self);
390 g_assert (priv->video_output == NULL);
391 g_assert (priv->pipeline != NULL);
393 priv->video_output = clutter_texture_new ();
395 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
398 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
399 if (priv->video_output_sink == NULL)
400 g_error ("Missing cluttersink");
402 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
404 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
407 gtk_widget_add_events (priv->video_container,
408 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
409 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
410 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
414 create_video_input (EmpathyCallWindow *self)
416 EmpathyCallWindowPriv *priv = GET_PRIV (self);
418 g_assert (priv->video_input == NULL);
419 priv->video_input = empathy_video_src_new ();
420 gst_object_ref_sink (priv->video_input);
424 audio_control_volume_to_element (GBinding *binding,
425 const GValue *source_value,
426 GValue *target_value,
429 /* AudioControl volume is 0-255, with -1 for unknown */
432 hv = g_value_get_int (source_value);
437 g_value_set_double (target_value, hv/255.0);
443 element_volume_to_audio_control (GBinding *binding,
444 const GValue *source_value,
445 GValue *target_value,
450 ev = g_value_get_double (source_value);
451 ev = CLAMP (ev, 0.0, 1.0);
453 g_value_set_int (target_value, ev * 255);
458 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
459 EmpathyCallWindow *self)
462 g_object_get (obj, "mute", &muted, NULL);
464 self->priv->muted = muted;
465 if (muted && self->priv->transitions)
466 clutter_state_set_state (self->priv->transitions, "fade-in");
470 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
471 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
475 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
476 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
479 empathy_call_window_update_timer (self);
483 create_audio_input (EmpathyCallWindow *self)
485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
487 g_assert (priv->audio_input == NULL);
488 priv->audio_input = empathy_audio_src_new ();
489 gst_object_ref_sink (priv->audio_input);
491 g_signal_connect (priv->audio_input, "notify::mute",
492 G_CALLBACK (audio_input_mute_notify_cb), self);
496 add_video_preview_to_pipeline (EmpathyCallWindow *self)
498 EmpathyCallWindowPriv *priv = GET_PRIV (self);
501 g_assert (priv->video_preview != NULL);
502 g_assert (priv->pipeline != NULL);
503 g_assert (priv->video_input != NULL);
504 g_assert (priv->video_tee != NULL);
506 preview = priv->video_preview_sink;
508 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
510 g_warning ("Could not add video input to pipeline");
514 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
516 g_warning ("Could not add video preview to pipeline");
520 if (!gst_element_link (priv->video_input, priv->video_tee))
522 g_warning ("Could not link video input to video tee");
526 if (!gst_element_link (priv->video_tee, preview))
528 g_warning ("Could not link video tee to video preview");
534 empathy_call_window_disable_camera_cb (GtkAction *action,
535 EmpathyCallWindow *self)
537 clutter_actor_destroy (self->priv->preview_hidden_button);
539 gtk_toggle_button_set_active (
540 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
544 empathy_call_window_minimise_camera_cb (GtkAction *action,
545 EmpathyCallWindow *self)
547 clutter_actor_hide (self->priv->video_preview);
548 clutter_actor_show (self->priv->preview_hidden_button);
552 empathy_call_window_maximise_camera_cb (GtkAction *action,
553 EmpathyCallWindow *self)
555 clutter_actor_show (self->priv->video_preview);
556 clutter_actor_hide (self->priv->preview_hidden_button);
560 empathy_call_window_swap_camera_cb (GtkAction *action,
561 EmpathyCallWindow *self)
563 const GList *cameras, *l;
566 DEBUG ("Swapping the camera");
568 cameras = tpaw_camera_monitor_get_cameras (self->priv->camera_monitor);
569 current_cam = empathy_video_src_dup_device (
570 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
572 for (l = cameras; l != NULL; l = l->next)
574 TpawCamera *camera = l->data;
576 if (!tp_strdiff (camera->device, current_cam))
581 next = l->next->data;
583 next = cameras->data;
585 /* EmpathyCameraMenu will update itself and do the actual change
587 g_settings_set_string (self->priv->settings,
588 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
595 g_free (current_cam);
599 empathy_call_window_camera_added_cb (TpawCameraMonitor *monitor,
601 EmpathyCallWindow *self)
603 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
605 gtk_action_set_visible (self->priv->menu_swap_camera,
606 g_list_length ((GList *) cameras) >= 2);
610 empathy_call_window_camera_removed_cb (TpawCameraMonitor *monitor,
612 EmpathyCallWindow *self)
614 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
616 gtk_action_set_visible (self->priv->menu_swap_camera,
617 g_list_length ((GList *) cameras) >= 2);
621 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
623 EmpathyCallWindow *self)
627 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
629 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
630 0, gtk_get_current_event_time ());
631 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
635 empathy_call_window_preview_hidden_button_clicked_cb (
636 ClutterClickAction *action,
638 EmpathyCallWindow *self)
642 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
643 "/preview-hidden-menu");
644 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
645 0, gtk_get_current_event_time ());
646 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
649 static ClutterActor *
650 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
651 ClutterBinAlignment x,
652 ClutterBinAlignment y)
654 ClutterActor *rectangle;
656 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
657 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
658 PREVIEW_ROUND_FACTOR));
660 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
662 clutter_actor_hide (rectangle);
668 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
672 self->priv->preview_layout = clutter_bin_layout_new (
673 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
674 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
676 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
678 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
680 self->priv->preview_rectangle1 =
681 empathy_call_window_create_preview_rectangle (self,
682 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
683 self->priv->preview_rectangle2 =
684 empathy_call_window_create_preview_rectangle (self,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
686 self->priv->preview_rectangle3 =
687 empathy_call_window_create_preview_rectangle (self,
688 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
689 self->priv->preview_rectangle4 =
690 empathy_call_window_create_preview_rectangle (self,
691 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
695 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
698 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
705 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
710 guint ret_x = 0, ret_y = 0;
713 if (!clutter_actor_has_allocation (self->priv->preview_box))
716 clutter_actor_get_geometry (self->priv->preview_box, &box);
720 case PREVIEW_POS_TOP_LEFT:
721 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
723 case PREVIEW_POS_TOP_RIGHT:
724 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
725 - SELF_VIDEO_SECTION_WIDTH;
726 ret_y = SELF_VIDEO_SECTION_MARGIN;
728 case PREVIEW_POS_BOTTOM_LEFT:
729 ret_x = SELF_VIDEO_SECTION_MARGIN;
730 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
731 - SELF_VIDEO_SECTION_HEIGHT;
733 case PREVIEW_POS_BOTTOM_RIGHT:
734 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
735 - SELF_VIDEO_SECTION_WIDTH;
736 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_HEIGHT;
740 g_warn_if_reached ();
751 static PreviewPosition
752 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
757 PreviewPosition pos = PREVIEW_POS_NONE;
759 if (!clutter_actor_has_allocation (self->priv->preview_box))
762 clutter_actor_get_geometry (self->priv->preview_box, &box);
764 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
765 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
766 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
767 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
769 pos = PREVIEW_POS_TOP_LEFT;
771 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
772 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
773 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
774 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
776 pos = PREVIEW_POS_TOP_RIGHT;
778 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
779 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
780 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
781 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
783 pos = PREVIEW_POS_BOTTOM_LEFT;
785 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
786 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
787 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
788 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
790 pos = PREVIEW_POS_BOTTOM_RIGHT;
796 static ClutterActor *
797 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
800 ClutterActor *rectangle;
804 case PREVIEW_POS_TOP_LEFT:
805 rectangle = self->priv->preview_rectangle1;
807 case PREVIEW_POS_TOP_RIGHT:
808 rectangle = self->priv->preview_rectangle3;
810 case PREVIEW_POS_BOTTOM_LEFT:
811 rectangle = self->priv->preview_rectangle2;
813 case PREVIEW_POS_BOTTOM_RIGHT:
814 rectangle = self->priv->preview_rectangle4;
824 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
827 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
829 DEBUG ("moving the video preview to %d", pos);
831 self->priv->preview_pos = pos;
835 case PREVIEW_POS_TOP_LEFT:
836 clutter_bin_layout_set_alignment (layout,
837 self->priv->video_preview,
838 CLUTTER_BIN_ALIGNMENT_START,
839 CLUTTER_BIN_ALIGNMENT_START);
841 case PREVIEW_POS_TOP_RIGHT:
842 clutter_bin_layout_set_alignment (layout,
843 self->priv->video_preview,
844 CLUTTER_BIN_ALIGNMENT_END,
845 CLUTTER_BIN_ALIGNMENT_START);
847 case PREVIEW_POS_BOTTOM_LEFT:
848 clutter_bin_layout_set_alignment (layout,
849 self->priv->video_preview,
850 CLUTTER_BIN_ALIGNMENT_START,
851 CLUTTER_BIN_ALIGNMENT_END);
853 case PREVIEW_POS_BOTTOM_RIGHT:
854 clutter_bin_layout_set_alignment (layout,
855 self->priv->video_preview,
856 CLUTTER_BIN_ALIGNMENT_END,
857 CLUTTER_BIN_ALIGNMENT_END);
860 g_warn_if_reached ();
863 g_settings_set_enum (self->priv->settings, "camera-position", pos);
867 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
870 ClutterActor *rectangle;
871 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
873 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
875 empathy_rounded_rectangle_set_border_width (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
877 empathy_rounded_rectangle_set_border_color (
878 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
882 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
883 ClutterActor *rectangle)
885 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
887 clutter_color_shade (&white, 0.55, &darker);
889 empathy_rounded_rectangle_set_border_width (
890 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
891 empathy_rounded_rectangle_set_border_color (
892 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
896 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
898 ClutterActor *rectangle;
900 rectangle = empathy_call_window_get_preview_rectangle (self,
901 self->priv->preview_pos);
903 /* We don't want to darken the rectangle where the preview
906 if (self->priv->preview_rectangle1 != rectangle)
907 empathy_call_window_darken_preview_rectangle (self,
908 self->priv->preview_rectangle1);
910 if (self->priv->preview_rectangle2 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle2);
914 if (self->priv->preview_rectangle3 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle3);
918 if (self->priv->preview_rectangle4 != rectangle)
919 empathy_call_window_darken_preview_rectangle (self,
920 self->priv->preview_rectangle4);
924 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
928 ClutterModifierType modifiers,
929 EmpathyCallWindow *self)
931 ClutterActor *stage = clutter_actor_get_stage (actor);
934 self->priv->drag_preview = clutter_clone_new (actor);
936 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
937 self->priv->drag_preview);
939 clutter_actor_transform_stage_point (actor, event_x, event_y,
942 clutter_actor_set_position (self->priv->drag_preview,
943 event_x - rel_x, event_y - rel_y);
945 clutter_drag_action_set_drag_handle (action,
946 self->priv->drag_preview);
948 clutter_actor_set_opacity (actor, 0);
949 clutter_actor_hide (self->priv->preview_shown_button);
951 empathy_call_window_show_preview_rectangles (self, TRUE);
952 empathy_call_window_darken_preview_rectangles (self);
956 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
959 clutter_actor_set_opacity (actor, 255);
963 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
967 ClutterModifierType modifiers,
968 EmpathyCallWindow *self)
973 /* Get the position before destroying the drag actor, otherwise the
974 * preview_box allocation won't be valid and we won't be able to
975 * calculate the position. */
976 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
978 empathy_call_window_get_preview_coordinates (self,
979 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
982 /* Move the preview to the destination and destroy it afterwards */
983 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
986 "signal-swapped-after::completed",
987 clutter_actor_destroy, self->priv->drag_preview,
988 "signal-swapped-after::completed",
989 clutter_actor_show, self->priv->preview_shown_button,
991 empathy_call_window_on_animation_completed_cb, actor,
994 self->priv->drag_preview = NULL;
996 if (pos != PREVIEW_POS_NONE)
997 empathy_call_window_move_video_preview (self, pos);
999 empathy_call_window_show_preview_rectangles (self, FALSE);
1003 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1004 ClutterActor *actor,
1007 EmpathyCallWindow *self)
1009 PreviewPosition pos;
1010 gfloat event_x, event_y;
1012 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1014 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1016 if (pos != PREVIEW_POS_NONE)
1017 empathy_call_window_highlight_preview_rectangle (self, pos);
1019 empathy_call_window_darken_preview_rectangles (self);
1023 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1024 ClutterCrossingEvent *event,
1025 EmpathyCallWindow *self)
1027 ClutterActor *rectangle;
1029 rectangle = empathy_call_window_get_preview_rectangle (self,
1030 self->priv->preview_pos);
1032 empathy_call_window_highlight_preview_rectangle (self,
1033 self->priv->preview_pos);
1035 clutter_actor_show (rectangle);
1041 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1042 ClutterCrossingEvent *event,
1043 EmpathyCallWindow *self)
1045 ClutterActor *rectangle;
1047 rectangle = empathy_call_window_get_preview_rectangle (self,
1048 self->priv->preview_pos);
1050 empathy_call_window_darken_preview_rectangle (self, rectangle);
1052 clutter_actor_hide (rectangle);
1058 create_video_preview (EmpathyCallWindow *self)
1060 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1061 ClutterLayoutManager *layout;
1062 ClutterActor *preview;
1064 ClutterAction *action;
1065 PreviewPosition pos;
1067 g_assert (priv->video_preview == NULL);
1069 pos = g_settings_get_enum (priv->settings, "camera-position");
1071 preview = empathy_rounded_texture_new ();
1072 clutter_actor_set_size (preview,
1073 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1075 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1076 if (priv->video_preview_sink == NULL)
1077 g_error ("Missing cluttersink, check your clutter-gst installation");
1078 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1079 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1081 /* Add a little offset to the video preview */
1082 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1083 CLUTTER_BIN_ALIGNMENT_CENTER);
1084 priv->video_preview = clutter_box_new (layout);
1085 clutter_actor_set_size (priv->video_preview,
1086 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1087 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1089 /* Spinner for when changing the camera device */
1090 priv->preview_spinner_widget = gtk_spinner_new ();
1091 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1093 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1094 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1095 gtk_widget_show (priv->preview_spinner_widget);
1098 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1099 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1100 priv->preview_spinner_widget);
1101 clutter_actor_set_size (priv->preview_spinner_actor,
1102 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1103 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1104 clutter_actor_hide (priv->preview_spinner_actor);
1106 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1108 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1109 priv->preview_spinner_actor);
1111 g_object_set (priv->video_preview_sink,
1117 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1118 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1119 GTK_ICON_SIZE_MENU));
1120 clutter_actor_set_margin_right (b, 4);
1121 clutter_actor_set_margin_bottom (b, 2);
1122 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1123 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1125 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1126 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1128 action = clutter_click_action_new ();
1129 clutter_actor_add_action (b, action);
1130 g_signal_connect (action, "clicked",
1131 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1133 /* Preview hidden */
1134 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1135 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1136 GTK_ICON_SIZE_MENU));
1137 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1139 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1140 priv->preview_hidden_button,
1141 CLUTTER_BIN_ALIGNMENT_START,
1142 CLUTTER_BIN_ALIGNMENT_END);
1144 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1146 clutter_actor_hide (priv->preview_hidden_button);
1148 action = clutter_click_action_new ();
1149 clutter_actor_add_action (b, action);
1150 g_signal_connect (action, "clicked",
1151 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1153 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1154 priv->video_preview,
1155 CLUTTER_BIN_ALIGNMENT_START,
1156 CLUTTER_BIN_ALIGNMENT_END);
1158 empathy_call_window_move_video_preview (self, pos);
1160 action = clutter_drag_action_new ();
1161 g_signal_connect (action, "drag-begin",
1162 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1163 g_signal_connect (action, "drag-end",
1164 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1165 g_signal_connect (action, "drag-motion",
1166 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1168 g_signal_connect (preview, "enter-event",
1169 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1170 g_signal_connect (preview, "leave-event",
1171 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1173 clutter_actor_add_action (preview, action);
1174 clutter_actor_set_reactive (preview, TRUE);
1175 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1179 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1181 clutter_actor_show (self->priv->preview_spinner_actor);
1182 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1186 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1188 clutter_actor_hide (self->priv->preview_spinner_actor);
1189 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1193 empathy_call_window_play_camera (EmpathyCallWindow *self,
1196 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1197 GstElement *preview;
1200 if (priv->video_preview == NULL)
1202 create_video_preview (self);
1203 add_video_preview_to_pipeline (self);
1208 state = GST_STATE_PLAYING;
1212 empathy_call_window_start_camera_spinning (self);
1213 state = GST_STATE_NULL;
1216 preview = priv->video_preview_sink;
1218 gst_element_set_state (preview, state);
1219 gst_element_set_state (priv->video_tee, state);
1220 gst_element_set_state (priv->video_input, state);
1224 display_video_preview (EmpathyCallWindow *self,
1227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1229 if (priv->video_preview == NULL)
1231 create_video_preview (self);
1232 add_video_preview_to_pipeline (self);
1237 /* Display the video preview */
1238 DEBUG ("Show video preview");
1240 empathy_call_window_play_camera (self, TRUE);
1241 clutter_actor_show (priv->video_preview);
1242 clutter_actor_raise_top (priv->floating_toolbar);
1246 /* Hide the video preview */
1247 DEBUG ("Hide video preview");
1249 if (priv->video_preview != NULL)
1251 clutter_actor_hide (priv->video_preview);
1252 empathy_call_window_play_camera (self, FALSE);
1258 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1260 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1262 empathy_call_window_status_message (window, _("Connecting…"));
1263 priv->call_state = CONNECTING;
1265 /* Show the toolbar */
1266 clutter_state_set_state (priv->transitions, "fade-in");
1269 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1270 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1274 disable_camera (EmpathyCallWindow *self)
1276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1278 if (priv->camera_state == CAMERA_STATE_OFF)
1281 DEBUG ("Disable camera");
1283 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1285 priv->camera_state = CAMERA_STATE_OFF;
1289 enable_camera (EmpathyCallWindow *self)
1291 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1293 if (priv->camera_state == CAMERA_STATE_ON)
1296 if (priv->video_input == NULL)
1298 DEBUG ("Can't enable camera, no input");
1302 DEBUG ("Enable camera");
1304 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1306 priv->camera_state = CAMERA_STATE_ON;
1310 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1311 EmpathyCallWindow *self)
1313 if (gtk_toggle_button_get_active (toggle))
1314 enable_camera (self);
1316 disable_camera (self);
1320 create_pipeline (EmpathyCallWindow *self)
1322 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1325 g_assert (priv->pipeline == NULL);
1327 priv->pipeline = gst_pipeline_new (NULL);
1328 priv->pipeline_playing = FALSE;
1330 priv->video_tee = gst_element_factory_make ("tee", NULL);
1331 gst_object_ref_sink (priv->video_tee);
1333 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1335 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1336 priv->bus_message_source_id = gst_bus_add_watch (bus,
1337 empathy_call_window_bus_message, self);
1339 g_object_unref (bus);
1343 empathy_call_window_settings_cb (GtkAction *action,
1344 EmpathyCallWindow *self)
1346 gchar *args = g_strdup_printf ("-p %s",
1347 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1349 empathy_launch_program (BIN_DIR, "empathy", args);
1355 empathy_call_window_contents_cb (GtkAction *action,
1356 EmpathyCallWindow *self)
1358 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1362 show_png (GPid pid, gint status, gpointer user_data)
1364 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1365 g_spawn_close_pid (pid);
1370 empathy_call_window_debug_gst_cb (GtkAction *action,
1371 EmpathyCallWindow *self)
1373 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1374 GDateTime *date_time;
1376 const gchar *dot_dir;
1377 const gchar *prgname;
1383 if (priv->pipeline == NULL)
1384 DEBUG ("No pipeline");
1386 date_time = g_date_time_new_now_utc ();
1387 prgname = g_get_prgname ();
1388 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1389 g_date_time_to_unix (date_time));
1391 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1392 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1394 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1395 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1398 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1400 if (g_spawn_async (dot_dir,
1403 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1409 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1410 g_child_watch_add (dot_pid, show_png, uri);
1416 g_date_time_unref (date_time);
1420 empathy_call_window_debug_tp_cb (GtkAction *action,
1421 EmpathyCallWindow *self)
1423 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1427 empathy_call_window_about_cb (GtkAction *action,
1428 EmpathyCallWindow *self)
1430 empathy_about_dialog_new (GTK_WINDOW (self));
1434 empathy_call_window_toolbar_timeout (gpointer data)
1436 EmpathyCallWindow *self = data;
1438 /* We don't want to hide the toolbar if we're not in a call, as
1439 * to show the call status all the time. Also don't hide if we're muted
1440 * to prevent the awkward, talking when muted situation */
1441 if (self->priv->call_state != CONNECTING &&
1442 self->priv->call_state != DISCONNECTED &&
1444 clutter_state_set_state (self->priv->transitions, "fade-out");
1450 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1452 EmpathyCallWindow *self)
1454 clutter_state_set_state (self->priv->transitions, "fade-in");
1456 if (self->priv->inactivity_src > 0)
1457 g_source_remove (self->priv->inactivity_src);
1459 self->priv->inactivity_src = g_timeout_add_seconds (3,
1460 empathy_call_window_toolbar_timeout, self);
1466 empathy_call_window_configure_event_cb (GtkWidget *widget,
1468 EmpathyCallWindow *self)
1470 GdkWindow *gdk_window;
1471 GdkWindowState window_state;
1473 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1474 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1476 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1477 &self->priv->dialpad_width, NULL);
1479 gdk_window = gtk_widget_get_window (widget);
1480 window_state = gdk_window_get_state (gdk_window);
1481 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1487 empathy_call_window_destroyed_cb (GtkWidget *object,
1488 EmpathyCallWindow *self)
1490 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1492 /* Save the geometry as if the dialpad was hidden. */
1493 empathy_geometry_save_values (GTK_WINDOW (self),
1494 self->priv->x, self->priv->y,
1495 self->priv->w - self->priv->dialpad_width, self->priv->h,
1496 self->priv->maximized);
1501 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1503 EmpathyCallWindow *self)
1505 switch (response_id)
1507 case GTK_RESPONSE_ACCEPT:
1508 tp_channel_dispatch_operation_handle_with_async (
1509 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1511 tp_clear_object (&self->priv->pending_cdo);
1512 tp_clear_object (&self->priv->pending_channel);
1513 tp_clear_object (&self->priv->pending_context);
1516 case GTK_RESPONSE_CANCEL:
1517 tp_channel_dispatch_operation_close_channels_async (
1518 self->priv->pending_cdo, NULL, NULL);
1520 empathy_call_window_status_message (self, _("Disconnected"));
1521 self->priv->call_state = DISCONNECTED;
1524 g_warn_if_reached ();
1529 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1533 g_assert (self->priv->call_state != CONNECTED);
1535 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1537 empathy_call_window_status_message (self, _("Incoming call"));
1538 self->priv->call_state = RINGING;
1540 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1541 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1542 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1543 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1544 empathy_contact_get_alias (self->priv->contact));
1546 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1547 _("Reject"), GTK_RESPONSE_CANCEL,
1548 _("Answer"), GTK_RESPONSE_ACCEPT,
1551 g_signal_connect (self->priv->incoming_call_dialog, "response",
1552 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1553 gtk_widget_show (self->priv->incoming_call_dialog);
1557 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1561 EmpathyCallWindow *self)
1563 tp_clear_object (&self->priv->pending_cdo);
1564 tp_clear_object (&self->priv->pending_channel);
1565 tp_clear_object (&self->priv->pending_context);
1567 /* We don't know if the incoming call has been accepted or not, so we
1568 * assume it hasn't and if it has, we'll set the proper status when
1569 * we get the new handler. */
1570 empathy_call_window_status_message (self, _("Disconnected"));
1571 self->priv->call_state = DISCONNECTED;
1573 gtk_widget_destroy (self->priv->incoming_call_dialog);
1574 self->priv->incoming_call_dialog = NULL;
1578 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1579 TpCallChannel *channel,
1580 TpChannelDispatchOperation *dispatch_operation,
1581 TpAddDispatchOperationContext *context)
1583 g_assert (self->priv->pending_channel == NULL);
1584 g_assert (self->priv->pending_context == NULL);
1585 g_assert (self->priv->pending_cdo == NULL);
1587 /* Start ringing and delay until the user answers or hangs. */
1588 self->priv->pending_channel = g_object_ref (channel);
1589 self->priv->pending_context = g_object_ref (context);
1590 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1592 g_signal_connect (self->priv->pending_cdo, "invalidated",
1593 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1595 empathy_call_window_set_state_ringing (self);
1596 tp_add_dispatch_operation_context_accept (context);
1600 mic_button_clicked (GtkWidget *button,
1601 EmpathyCallWindow *self)
1603 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1605 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1606 !self->priv->muted);
1610 empathy_call_window_init (EmpathyCallWindow *self)
1612 EmpathyCallWindowPriv *priv;
1614 GtkWidget *top_vbox;
1616 ClutterConstraint *constraint;
1617 ClutterActor *remote_avatar;
1618 ClutterColor black = { 0, 0, 0, 0 };
1619 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1620 OVERLAY_MARGIN, OVERLAY_MARGIN };
1622 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1623 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1625 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1626 priv->timer = g_timer_new ();
1628 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1629 gui = tpaw_builder_get_file (filename,
1630 "call_window_vbox", &top_vbox,
1631 "errors_vbox", &priv->errors_vbox,
1632 "pane", &priv->pane,
1633 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1634 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1635 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1636 "status_label", &priv->status_label,
1637 "audiocall", &priv->audio_call_button,
1638 "videocall", &priv->video_call_button,
1639 "microphone", &priv->mic_button,
1640 "microphone_icon", &priv->microphone_icon,
1641 "volume", &priv->volume_button,
1642 "camera", &priv->camera_button,
1643 "hangup", &priv->hangup_button,
1644 "dialpad", &priv->dialpad_button,
1645 "toolbar", &priv->toolbar,
1646 "bottom_toolbar", &priv->bottom_toolbar,
1647 "ui_manager", &priv->ui_manager,
1648 "menufullscreen", &priv->menu_fullscreen,
1649 "menupreviewswap", &priv->menu_swap_camera,
1650 "details_vbox", &priv->details_vbox,
1651 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1652 "acodec_encoding_label", &priv->acodec_encoding_label,
1653 "acodec_decoding_label", &priv->acodec_decoding_label,
1654 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1655 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1656 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1657 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1658 "video_local_candidate_label", &priv->video_local_candidate_label,
1659 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1660 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1661 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1662 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1666 tpaw_builder_connect (gui, self,
1667 "hangup", "clicked", empathy_call_window_hangup_cb,
1668 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1669 "videocall", "clicked", empathy_call_window_video_call_cb,
1670 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1671 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1672 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1673 "menusettings", "activate", empathy_call_window_settings_cb,
1674 "menucontents", "activate", empathy_call_window_contents_cb,
1675 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1676 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1677 "menuabout", "activate", empathy_call_window_about_cb,
1678 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1679 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1680 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1681 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1684 empathy_set_css_provider (GTK_WIDGET (self));
1685 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1687 priv->camera_monitor = tpaw_camera_monitor_dup_singleton ();
1689 g_object_bind_property (priv->camera_monitor, "available",
1690 priv->camera_button, "sensitive",
1691 G_BINDING_SYNC_CREATE);
1693 g_signal_connect (priv->camera_monitor, "added",
1694 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1695 g_signal_connect (priv->camera_monitor, "removed",
1696 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1698 g_signal_connect (priv->mic_button, "clicked",
1699 G_CALLBACK (mic_button_clicked), self);
1701 g_mutex_init (&priv->lock);
1703 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1705 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1706 CONTENT_HBOX_SPACING);
1707 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1710 /* main contents remote avatar/video box */
1711 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1712 CLUTTER_BIN_ALIGNMENT_FILL);
1714 priv->video_box = clutter_box_new (priv->video_layout);
1716 priv->video_container = gtk_clutter_embed_new ();
1718 gtk_widget_set_size_request (priv->video_container,
1719 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1721 /* Set the background black */
1722 clutter_stage_set_color (
1723 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1724 GTK_CLUTTER_EMBED (priv->video_container))),
1727 clutter_container_add (
1728 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1729 GTK_CLUTTER_EMBED (priv->video_container))),
1733 constraint = clutter_bind_constraint_new (
1734 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1735 CLUTTER_BIND_SIZE, 0);
1736 clutter_actor_add_constraint (priv->video_box, constraint);
1738 priv->remote_user_avatar_widget = gtk_image_new ();
1739 remote_avatar = gtk_clutter_actor_new_with_contents (
1740 priv->remote_user_avatar_widget);
1741 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1743 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1746 /* create the overlay bin */
1747 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1748 CLUTTER_BIN_ALIGNMENT_CENTER);
1749 priv->overlay_bin = clutter_actor_new ();
1750 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1752 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1754 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1756 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1758 empathy_call_window_create_preview_rectangles (self);
1760 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1761 priv->video_container, TRUE, TRUE,
1762 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1764 create_pipeline (self);
1765 create_video_output_widget (self);
1766 create_audio_input (self);
1767 create_video_input (self);
1769 priv->floating_toolbar = gtk_clutter_actor_new ();
1770 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1771 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1773 gtk_style_context_add_class (
1774 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1775 GTK_STYLE_CLASS_OSD);
1776 gtk_widget_reparent (priv->bottom_toolbar,
1777 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1779 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1780 priv->floating_toolbar,
1781 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1783 clutter_actor_raise_top (priv->floating_toolbar);
1785 /* Transitions for the floating toolbar */
1786 priv->transitions = clutter_state_new ();
1788 /* all transitions last for 2s */
1789 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1791 /* transition from any state to "fade-out" state */
1792 clutter_state_set (priv->transitions, NULL, "fade-out",
1793 priv->floating_toolbar,
1794 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1797 /* transition from any state to "fade-in" state */
1798 clutter_state_set (priv->transitions, NULL, "fade-in",
1799 priv->floating_toolbar,
1800 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1803 /* put the actor into the "fade-in" state with no animation */
1804 clutter_state_warp_to_state (priv->transitions, "fade-in");
1806 /* The call will be started as soon the pipeline is playing */
1807 priv->start_call_when_playing = TRUE;
1809 priv->dtmf_panel = empathy_dialpad_widget_new ();
1810 g_signal_connect (priv->dtmf_panel, "start-tone",
1811 G_CALLBACK (dtmf_start_tone_cb), self);
1813 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1816 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1819 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1821 gtk_widget_show_all (top_vbox);
1823 gtk_widget_hide (priv->dtmf_panel);
1824 gtk_widget_hide (priv->details_vbox);
1826 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1828 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1829 priv->video_container);
1831 /* We hide the bottom toolbar after 3s of inactivity and show it
1832 * again on mouse movement */
1833 priv->inactivity_src = g_timeout_add_seconds (3,
1834 empathy_call_window_toolbar_timeout, self);
1836 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1837 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1839 g_signal_connect (G_OBJECT (self), "realize",
1840 G_CALLBACK (empathy_call_window_realized_cb), self);
1842 g_signal_connect (G_OBJECT (self), "delete-event",
1843 G_CALLBACK (empathy_call_window_delete_cb), self);
1845 g_signal_connect (G_OBJECT (self), "window-state-event",
1846 G_CALLBACK (empathy_call_window_state_event_cb), self);
1848 g_signal_connect (G_OBJECT (self), "key-press-event",
1849 G_CALLBACK (empathy_call_window_key_press_cb), self);
1851 g_signal_connect (self, "motion-notify-event",
1852 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1854 g_object_ref (priv->ui_manager);
1855 g_object_unref (gui);
1857 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1858 priv->mic_menu = empathy_mic_menu_new (self);
1859 priv->camera_menu = empathy_camera_menu_new (self);
1861 empathy_call_window_show_hangup_button (self, TRUE);
1863 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1865 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1866 /* These signals are used to track the window position and save it
1867 * when the window is destroyed. We need to do this as we don't want
1868 * the window geometry to be saved with the dialpad taken into account. */
1869 g_signal_connect (self, "destroy",
1870 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1871 g_signal_connect (self, "configure-event",
1872 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1873 g_signal_connect (self, "window-state-event",
1874 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1876 /* Don't display labels in both toolbars */
1877 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1880 /* Instead of specifying a width and a height, we specify only one size. That's
1881 because we want a square avatar icon. */
1883 init_contact_avatar_with_size (EmpathyContact *contact,
1884 GtkWidget *image_widget,
1887 GdkPixbuf *pixbuf_avatar = NULL;
1889 if (contact != NULL)
1891 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1895 if (pixbuf_avatar == NULL)
1897 pixbuf_avatar = tpaw_pixbuf_from_icon_name_sized (
1898 TPAW_IMAGE_AVATAR_DEFAULT, size);
1901 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1903 if (pixbuf_avatar != NULL)
1904 g_object_unref (pixbuf_avatar);
1908 set_window_title (EmpathyCallWindow *self)
1910 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1913 if (priv->contact != NULL)
1915 /* translators: Call is a noun and %s is the contact name. This string
1916 * is used in the window title */
1917 tmp = g_strdup_printf (_("Call with %s"),
1918 empathy_contact_get_alias (priv->contact));
1919 gtk_window_set_title (GTK_WINDOW (self), tmp);
1924 g_warning ("Unknown remote contact!");
1929 set_remote_user_name (EmpathyCallWindow *self,
1930 EmpathyContact *contact)
1932 const gchar *alias = empathy_contact_get_alias (contact);
1933 const gchar *status = empathy_contact_get_status (contact);
1935 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1937 if (status != NULL) {
1940 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1941 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1945 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1951 contact_name_changed_cb (EmpathyContact *contact,
1953 EmpathyCallWindow *self)
1955 set_window_title (self);
1956 set_remote_user_name (self, contact);
1960 contact_presence_changed_cb (EmpathyContact *contact,
1962 EmpathyCallWindow *self)
1964 set_remote_user_name (self, contact);
1968 contact_avatar_changed_cb (EmpathyContact *contact,
1970 EmpathyCallWindow *self)
1973 GtkAllocation allocation;
1974 GtkWidget *avatar_widget;
1976 avatar_widget = self->priv->remote_user_avatar_widget;
1978 gtk_widget_get_allocation (avatar_widget, &allocation);
1979 size = allocation.height;
1983 /* the widget is not allocated yet, set a default size */
1984 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1985 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1988 init_contact_avatar_with_size (contact, avatar_widget, size);
1990 avatar_widget = self->priv->remote_user_avatar_toolbar;
1992 gtk_widget_get_allocation (avatar_widget, &allocation);
1993 size = allocation.height;
1997 /* the widget is not allocated yet, set a default size */
1998 size = SMALL_TOOLBAR_SIZE;
2001 init_contact_avatar_with_size (contact, avatar_widget, size);
2005 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2006 EmpathyCallHandler *handler)
2008 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2010 tp_g_signal_connect_object (priv->contact, "notify::name",
2011 G_CALLBACK (contact_name_changed_cb), self, 0);
2012 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2013 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2014 tp_g_signal_connect_object (priv->contact, "notify::presence",
2015 G_CALLBACK (contact_presence_changed_cb), self, 0);
2017 set_window_title (self);
2018 set_remote_user_name (self, priv->contact);
2020 init_contact_avatar_with_size (priv->contact,
2021 priv->remote_user_avatar_widget,
2022 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2023 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2025 init_contact_avatar_with_size (priv->contact,
2026 priv->remote_user_avatar_toolbar,
2027 SMALL_TOOLBAR_SIZE);
2029 /* The remote avatar is shown by default and will be hidden when we receive
2030 video from the remote side. */
2031 clutter_actor_hide (priv->video_output);
2032 gtk_widget_show (priv->remote_user_avatar_widget);
2036 update_send_codec (EmpathyCallWindow *self,
2039 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2046 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2047 widget = priv->acodec_encoding_label;
2051 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2052 widget = priv->vcodec_encoding_label;
2058 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2059 gtk_label_set_text (GTK_LABEL (widget), tmp);
2064 send_audio_codec_notify_cb (GObject *object,
2068 EmpathyCallWindow *self = user_data;
2070 update_send_codec (self, TRUE);
2074 send_video_codec_notify_cb (GObject *object,
2078 EmpathyCallWindow *self = user_data;
2080 update_send_codec (self, FALSE);
2084 update_recv_codec (EmpathyCallWindow *self,
2087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2090 GString *str = NULL;
2094 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2095 widget = priv->acodec_decoding_label;
2099 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2100 widget = priv->vcodec_decoding_label;
2106 for (l = codecs; l != NULL; l = g_list_next (l))
2108 FsCodec *codec = l->data;
2111 str = g_string_new (NULL);
2113 g_string_append (str, ", ");
2115 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2119 gtk_label_set_text (GTK_LABEL (widget), str->str);
2120 g_string_free (str, TRUE);
2124 recv_audio_codecs_notify_cb (GObject *object,
2128 EmpathyCallWindow *self = user_data;
2130 update_recv_codec (self, TRUE);
2134 recv_video_codecs_notify_cb (GObject *object,
2138 EmpathyCallWindow *self = user_data;
2140 update_recv_codec (self, FALSE);
2143 static const gchar *
2144 candidate_type_to_str (FsCandidate *candidate)
2146 switch (candidate->type)
2148 case FS_CANDIDATE_TYPE_HOST:
2150 case FS_CANDIDATE_TYPE_SRFLX:
2151 return "server reflexive";
2152 case FS_CANDIDATE_TYPE_PRFLX:
2153 return "peer reflexive";
2154 case FS_CANDIDATE_TYPE_RELAY:
2156 case FS_CANDIDATE_TYPE_MULTICAST:
2163 static const gchar *
2164 candidate_type_to_desc (FsCandidate *candidate)
2166 switch (candidate->type)
2168 case FS_CANDIDATE_TYPE_HOST:
2169 return _("The IP address as seen by the machine");
2170 case FS_CANDIDATE_TYPE_SRFLX:
2171 return _("The IP address as seen by a server on the Internet");
2172 case FS_CANDIDATE_TYPE_PRFLX:
2173 return _("The IP address of the peer as seen by the other side");
2174 case FS_CANDIDATE_TYPE_RELAY:
2175 return _("The IP address of a relay server");
2176 case FS_CANDIDATE_TYPE_MULTICAST:
2177 return _("The IP address of the multicast group");
2184 update_candidat_widget (EmpathyCallWindow *self,
2187 FsCandidate *candidate)
2191 g_assert (candidate != NULL);
2192 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2193 candidate->port, candidate_type_to_str (candidate));
2195 gtk_label_set_text (GTK_LABEL (label), str);
2196 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2202 candidates_changed_cb (GObject *object,
2204 EmpathyCallWindow *self)
2206 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2207 FsCandidate *candidate = NULL;
2209 if (type == FS_MEDIA_TYPE_VIDEO)
2211 /* Update remote candidate */
2212 candidate = empathy_call_handler_get_video_remote_candidate (
2215 update_candidat_widget (self, priv->video_remote_candidate_label,
2216 priv->video_remote_candidate_info_img, candidate);
2218 /* Update local candidate */
2219 candidate = empathy_call_handler_get_video_local_candidate (
2222 update_candidat_widget (self, priv->video_local_candidate_label,
2223 priv->video_local_candidate_info_img, candidate);
2227 /* Update remote candidate */
2228 candidate = empathy_call_handler_get_audio_remote_candidate (
2231 update_candidat_widget (self, priv->audio_remote_candidate_label,
2232 priv->audio_remote_candidate_info_img, candidate);
2234 /* Update local candidate */
2235 candidate = empathy_call_handler_get_audio_local_candidate (
2238 update_candidat_widget (self, priv->audio_local_candidate_label,
2239 priv->audio_local_candidate_info_img, candidate);
2244 empathy_call_window_constructed (GObject *object)
2246 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2247 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2248 TpCallChannel *call;
2251 g_assert (priv->handler != NULL);
2253 g_object_get (priv->handler, "call-channel", &call, NULL);
2254 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2255 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2256 tp_clear_object (&call);
2258 priv->contact = empathy_call_handler_get_contact (priv->handler);
2259 g_assert (priv->contact != NULL);
2260 g_object_ref (priv->contact);
2262 if (!empathy_contact_can_voip_video (priv->contact))
2264 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2265 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2268 empathy_call_window_setup_avatars (self, priv->handler);
2269 empathy_call_window_set_state_connecting (self);
2271 if (!empathy_call_handler_has_initial_video (priv->handler))
2273 gtk_toggle_button_set_active (
2274 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2276 /* If call has InitialVideo, the preview will be started once the call has
2277 * been started (start_call()). */
2279 update_send_codec (self, TRUE);
2280 update_send_codec (self, FALSE);
2281 update_recv_codec (self, TRUE);
2282 update_recv_codec (self, FALSE);
2284 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2285 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2286 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2287 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2288 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2289 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2290 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2291 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2293 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2294 G_CALLBACK (candidates_changed_cb), self, 0);
2297 static void empathy_call_window_dispose (GObject *object);
2298 static void empathy_call_window_finalize (GObject *object);
2301 empathy_call_window_set_property (GObject *object,
2302 guint property_id, const GValue *value, GParamSpec *pspec)
2304 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2306 switch (property_id)
2308 case PROP_CALL_HANDLER:
2309 priv->handler = g_value_dup_object (value);
2312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2317 empathy_call_window_get_property (GObject *object,
2318 guint property_id, GValue *value, GParamSpec *pspec)
2320 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2322 switch (property_id)
2324 case PROP_CALL_HANDLER:
2325 g_value_set_object (value, priv->handler);
2328 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2333 empathy_call_window_class_init (
2334 EmpathyCallWindowClass *empathy_call_window_class)
2336 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2337 GParamSpec *param_spec;
2339 g_type_class_add_private (empathy_call_window_class,
2340 sizeof (EmpathyCallWindowPriv));
2342 object_class->constructed = empathy_call_window_constructed;
2343 object_class->set_property = empathy_call_window_set_property;
2344 object_class->get_property = empathy_call_window_get_property;
2346 object_class->dispose = empathy_call_window_dispose;
2347 object_class->finalize = empathy_call_window_finalize;
2349 param_spec = g_param_spec_object ("handler",
2350 "handler", "The call handler",
2351 EMPATHY_TYPE_CALL_HANDLER,
2352 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2353 g_object_class_install_property (object_class,
2354 PROP_CALL_HANDLER, param_spec);
2356 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2357 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2359 0, NULL, NULL, NULL,
2365 empathy_call_window_dispose (GObject *object)
2367 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2370 if (priv->dispose_has_run)
2373 priv->dispose_has_run = TRUE;
2375 if (priv->handler != NULL)
2377 empathy_call_handler_stop_call (priv->handler);
2378 tp_clear_object (&priv->handler);
2381 if (priv->bus_message_source_id != 0)
2383 g_source_remove (priv->bus_message_source_id);
2384 priv->bus_message_source_id = 0;
2387 if (priv->got_video_src > 0)
2389 g_source_remove (priv->got_video_src);
2390 priv->got_video_src = 0;
2393 if (priv->inactivity_src > 0)
2395 g_source_remove (priv->inactivity_src);
2396 priv->inactivity_src = 0;
2399 tp_clear_object (&priv->pipeline);
2400 tp_clear_object (&priv->video_input);
2401 tp_clear_object (&priv->audio_input);
2402 tp_clear_object (&priv->video_tee);
2403 tp_clear_object (&priv->ui_manager);
2404 tp_clear_object (&priv->fullscreen);
2405 tp_clear_object (&priv->camera_monitor);
2406 tp_clear_object (&priv->settings);
2407 tp_clear_object (&priv->sound_mgr);
2408 tp_clear_object (&priv->mic_menu);
2409 tp_clear_object (&priv->camera_menu);
2410 tp_clear_object (&priv->transitions);
2412 g_list_free_full (priv->notifiers, g_object_unref);
2414 if (priv->timer_id != 0)
2415 g_source_remove (priv->timer_id);
2418 tp_clear_object (&priv->contact);
2420 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2424 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2426 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2428 if (priv->video_output_motion_handler_id != 0)
2430 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2431 priv->video_output_motion_handler_id);
2432 priv->video_output_motion_handler_id = 0;
2437 empathy_call_window_finalize (GObject *object)
2439 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2440 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2442 disconnect_video_output_motion_handler (self);
2444 /* free any data held directly by the object here */
2445 g_mutex_clear (&priv->lock);
2447 g_timer_destroy (priv->timer);
2449 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2454 empathy_call_window_new (EmpathyCallHandler *handler)
2456 return EMPATHY_CALL_WINDOW (
2457 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2461 empathy_call_window_new_handler (EmpathyCallWindow *self,
2462 EmpathyCallHandler *handler,
2466 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2469 tpaw_window_present_with_time (GTK_WINDOW (self), x11_time);
2471 if (self->priv->call_state == DISCONNECTED)
2473 /* start a new call if one is not already in progress */
2474 tp_clear_object (&self->priv->handler);
2475 self->priv->handler = g_object_ref (handler);
2476 empathy_call_window_connect_handler (self);
2478 empathy_call_window_restart_call (self);
2483 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2484 GstElement *conference, gpointer user_data)
2486 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2487 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2488 FsElementAddedNotifier *notifier;
2491 DEBUG ("Conference added");
2493 /* Add notifier to set the various element properties as needed */
2494 notifier = fs_element_added_notifier_new ();
2495 keyfile = fs_utils_get_default_element_properties (conference);
2497 if (keyfile != NULL)
2498 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2500 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2502 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2504 gst_bin_add (GST_BIN (priv->pipeline), conference);
2505 gst_element_set_state (conference, GST_STATE_PLAYING);
2509 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2510 GstElement *conference, gpointer user_data)
2512 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2515 g_list_free_full (priv->notifiers, g_object_unref);
2516 priv->notifiers = NULL;
2518 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2519 gst_element_set_state (conference, GST_STATE_NULL);
2523 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2525 GstStateChangeReturn state_change_return;
2526 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2528 if (priv->pipeline == NULL)
2531 if (priv->bus_message_source_id != 0)
2533 g_source_remove (priv->bus_message_source_id);
2534 priv->bus_message_source_id = 0;
2537 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2539 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2540 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2542 if (priv->pipeline != NULL)
2543 g_object_unref (priv->pipeline);
2544 priv->pipeline = NULL;
2546 if (priv->audio_output != NULL)
2547 g_object_unref (priv->audio_output);
2548 priv->audio_output = NULL;
2549 priv->audio_output_added = FALSE;
2551 if (priv->video_tee != NULL)
2552 g_object_unref (priv->video_tee);
2553 priv->video_tee = NULL;
2555 if (priv->video_preview != NULL)
2556 clutter_actor_destroy (priv->video_preview);
2557 priv->video_preview = NULL;
2559 /* If we destroy the preview while it's being dragged, we won't
2560 * get the ::drag-end signal, so manually destroy the clone */
2561 if (priv->drag_preview != NULL)
2563 clutter_actor_destroy (priv->drag_preview);
2564 empathy_call_window_show_preview_rectangles (self, FALSE);
2565 priv->drag_preview = NULL;
2568 priv->funnel = NULL;
2570 create_pipeline (self);
2571 /* Call will be started when user will hit the 'redial' button */
2572 priv->start_call_when_playing = FALSE;
2573 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2579 g_message ("Error: could not destroy pipeline. Closing call window");
2580 gtk_widget_destroy (GTK_WIDGET (self));
2587 reset_details_pane (EmpathyCallWindow *self)
2589 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2591 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2592 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2593 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2594 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2598 empathy_call_window_disconnected (EmpathyCallWindow *self,
2601 gboolean could_disconnect = FALSE;
2602 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2603 gboolean could_reset_pipeline;
2605 /* Leave full screen mode if needed */
2606 gtk_window_unfullscreen (GTK_WINDOW (self));
2608 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2610 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2611 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2613 /* Create the video input and then turn on the camera
2614 * menu, so that the active camera gets marked as such.
2616 if (priv->video_input == NULL)
2617 create_video_input (self);
2618 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2620 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2622 if (priv->call_state == CONNECTING)
2623 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2625 if (priv->call_state != REDIALING)
2626 priv->call_state = DISCONNECTED;
2628 /* Show the toolbar */
2629 clutter_state_set_state (priv->transitions, "fade-in");
2631 if (could_reset_pipeline)
2633 g_mutex_lock (&priv->lock);
2635 g_timer_stop (priv->timer);
2637 if (priv->timer_id != 0)
2638 g_source_remove (priv->timer_id);
2641 g_mutex_unlock (&priv->lock);
2644 /* We are about to destroy the window, no need to update it or create
2645 * a video preview */
2648 empathy_call_window_status_message (self, _("Disconnected"));
2650 empathy_call_window_show_hangup_button (self, FALSE);
2652 /* Unsensitive the camera and mic button */
2653 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2654 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2656 /* Be sure that the mic button is enabled */
2657 empathy_audio_src_set_mute (
2658 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2660 if (priv->camera_state == CAMERA_STATE_ON)
2662 /* Restart the preview with the new pipeline. */
2663 display_video_preview (self, TRUE);
2666 /* destroy the video output; it will be recreated when we'll redial */
2667 disconnect_video_output_motion_handler (self);
2668 if (priv->video_output != NULL)
2669 clutter_actor_destroy (priv->video_output);
2670 priv->video_output = NULL;
2671 if (priv->got_video_src > 0)
2673 g_source_remove (priv->got_video_src);
2674 priv->got_video_src = 0;
2677 gtk_widget_show (priv->remote_user_avatar_widget);
2679 reset_details_pane (self);
2681 priv->sending_video = FALSE;
2682 priv->call_started = FALSE;
2684 could_disconnect = TRUE;
2686 /* TODO: display the self avatar of the preview (depends if the "Always
2687 * Show Video Preview" is enabled or not) */
2690 return could_disconnect;
2695 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2698 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2699 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2701 if (empathy_call_window_disconnected (self, TRUE) &&
2702 priv->call_state == REDIALING)
2703 empathy_call_window_restart_call (self);
2707 empathy_call_window_content_is_raw (TfContent *content)
2709 FsConference *conference;
2712 g_object_get (content, "fs-conference", &conference, NULL);
2713 g_assert (conference != NULL);
2715 /* FIXME: Ugly hack, update when moving a packetization property into
2717 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2718 gst_object_unref (conference);
2724 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2726 EmpathyCallWindow *self)
2728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2729 FsMediaType media_type;
2731 DEBUG ("removing content");
2733 g_object_get (content, "media-type", &media_type, NULL);
2736 * This assumes that there is only one video stream per channel...
2739 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2741 if (priv->funnel != NULL)
2745 output = priv->video_output_sink;
2747 gst_element_set_state (output, GST_STATE_NULL);
2748 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2750 gst_bin_remove (GST_BIN (priv->pipeline), output);
2751 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2752 priv->funnel = NULL;
2755 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2757 if (priv->audio_output != NULL)
2759 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2761 if (priv->audio_output_added)
2762 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2763 priv->audio_output = NULL;
2764 priv->audio_output_added = FALSE;
2769 g_assert_not_reached ();
2776 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2778 EmpathyCallWindow *self)
2780 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2782 DEBUG ("Framerate changed to %u", framerate);
2784 if (priv->video_input != NULL)
2785 empathy_video_src_set_framerate (priv->video_input, framerate);
2789 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2792 EmpathyCallWindow *self)
2794 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2796 DEBUG ("Resolution changed to %ux%u", width, height);
2798 if (priv->video_input != NULL)
2800 empathy_video_src_set_resolution (priv->video_input, width, height);
2804 /* Called with global lock held */
2806 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2808 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2812 if (priv->funnel == NULL)
2814 output = priv->video_output_sink;
2816 priv->funnel = gst_element_factory_make ("funnel", NULL);
2818 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2823 g_warning ("Could not create video funnel");
2827 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2829 gst_object_unref (priv->funnel);
2830 priv->funnel = NULL;
2831 g_warning ("Could not add funnel to pipeline");
2835 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2837 g_warning ("Could not add the video output widget to the pipeline");
2841 if (!gst_element_link (priv->funnel, output))
2843 g_warning ("Could not link output sink to funnel");
2844 goto error_output_added;
2847 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2849 g_warning ("Could not start video sink");
2850 goto error_output_added;
2853 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2855 g_warning ("Could not start funnel");
2856 goto error_output_added;
2860 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2862 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2866 g_warning ("Could not get request pad from funnel");
2873 gst_element_set_locked_state (priv->funnel, TRUE);
2874 gst_element_set_locked_state (output, TRUE);
2876 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2877 gst_element_set_state (output, GST_STATE_NULL);
2879 gst_bin_remove (GST_BIN (priv->pipeline), output);
2880 gst_element_set_locked_state (output, FALSE);
2884 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2885 priv->funnel = NULL;
2890 /* Called with global lock held */
2892 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2895 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2897 GstPadTemplate *template;
2899 if (!priv->audio_output_added)
2901 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2903 g_warning ("Could not add audio sink to pipeline");
2904 g_object_unref (priv->audio_output);
2905 goto error_add_output;
2908 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2910 g_warning ("Could not start audio sink");
2913 priv->audio_output_added = TRUE;
2916 template = gst_element_class_get_pad_template (
2917 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2919 pad = gst_element_request_pad (priv->audio_output,
2920 template, NULL, NULL);
2924 g_warning ("Could not get sink pad from sink");
2931 gst_element_set_locked_state (priv->audio_output, TRUE);
2932 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2933 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2934 priv->audio_output = NULL;
2942 empathy_call_window_update_timer (gpointer user_data)
2944 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2945 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2946 const gchar *status;
2950 time_ = g_timer_elapsed (priv->timer, NULL);
2952 if (priv->call_state == HELD)
2953 status = _("On hold");
2954 else if (priv->call_state == DISCONNECTED)
2955 status = _("Disconnected");
2956 else if (priv->muted)
2959 status = _("Duration");
2961 /* Translators: 'status - minutes:seconds' the caller has been connected */
2962 str = g_strdup_printf (_("%s — %d:%02dm"),
2964 (int) time_ / 60, (int) time_ % 60);
2965 empathy_call_window_status_message (self, str);
2973 EMP_RESPONSE_BALANCE
2977 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2981 switch (response_id)
2983 case GTK_RESPONSE_CLOSE:
2984 gtk_widget_destroy (GTK_WIDGET (info_bar));
2986 case EMP_RESPONSE_BALANCE:
2987 empathy_url_show (GTK_WIDGET (info_bar),
2988 g_object_get_data (G_OBJECT (info_bar), "uri"));
2994 display_error (EmpathyCallWindow *self,
2998 const gchar *details,
2999 const gchar *button_text,
3001 gint button_response)
3003 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3004 GtkWidget *info_bar;
3005 GtkWidget *content_area;
3012 /* Create info bar */
3013 info_bar = gtk_info_bar_new ();
3015 if (button_text != NULL)
3017 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3018 button_text, button_response);
3019 g_object_set_data_full (G_OBJECT (info_bar),
3020 "uri", g_strdup (uri), g_free);
3023 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3024 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3026 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3028 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3030 /* hbox containing the image and the messages vbox */
3031 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3032 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3035 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3036 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3038 /* vbox containing the main message and the details expander */
3039 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3040 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3043 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3045 label = gtk_label_new (NULL);
3046 gtk_label_set_markup (GTK_LABEL (label), txt);
3047 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3048 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3051 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3054 if (details != NULL)
3056 GtkWidget *expander;
3058 expander = gtk_expander_new (_("Technical Details"));
3060 txt = g_strdup_printf ("<i>%s</i>", details);
3062 label = gtk_label_new (NULL);
3063 gtk_label_set_markup (GTK_LABEL (label), txt);
3064 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3065 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3068 gtk_container_add (GTK_CONTAINER (expander), label);
3069 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3072 g_signal_connect (info_bar, "response",
3073 G_CALLBACK (on_error_infobar_response_cb), NULL);
3075 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3076 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3077 gtk_widget_show_all (info_bar);
3082 media_stream_error_to_txt (EmpathyCallWindow *self,
3083 TpCallChannel *call,
3085 TpMediaStreamError error)
3087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3088 const gchar *cm = NULL;
3094 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3096 return g_strdup_printf (
3097 _("%s's software does not understand any of the audio formats "
3098 "supported by your computer"),
3099 empathy_contact_get_alias (priv->contact));
3101 return g_strdup_printf (
3102 _("%s's software does not understand any of the video formats "
3103 "supported by your computer"),
3104 empathy_contact_get_alias (priv->contact));
3106 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3107 return g_strdup_printf (
3108 _("Can't establish a connection to %s. "
3109 "One of you might be on a network that does not allow "
3110 "direct connections."),
3111 empathy_contact_get_alias (priv->contact));
3113 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3114 return g_strdup (_("There was a failure on the network"));
3116 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3118 return g_strdup (_("The audio formats necessary for this call "
3119 "are not installed on your computer"));
3121 return g_strdup (_("The video formats necessary for this call "
3122 "are not installed on your computer"));
3124 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3125 tp_connection_parse_object_path (
3126 tp_channel_get_connection (TP_CHANNEL (call)),
3129 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3130 "product=Telepathy&component=%s", cm);
3132 result = g_strdup_printf (
3133 _("Something unexpected happened in a Telepathy component. "
3134 "Please <a href=\"%s\">report this bug</a> and attach "
3135 "logs gathered from the 'Debug' window in the Help menu."), url);
3141 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3142 return g_strdup (_("There was a failure in the call engine"));
3144 case TP_MEDIA_STREAM_ERROR_EOS:
3145 return g_strdup (_("The end of the stream was reached"));
3147 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3154 empathy_call_window_stream_error (EmpathyCallWindow *self,
3155 TpCallChannel *call,
3164 desc = media_stream_error_to_txt (self, call, audio, code);
3167 /* No description, use the error message. That's not great as it's not
3168 * localized but it's better than nothing. */
3169 display_error (self, call, icon, title, msg, NULL);
3173 display_error (self, call, icon, title, desc, msg);
3179 empathy_call_window_audio_stream_error (TpCallChannel *call,
3182 EmpathyCallWindow *self)
3184 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3185 "gnome-stock-mic", _("Can't establish audio stream"));
3189 empathy_call_window_video_stream_error (TpCallChannel *call,
3192 EmpathyCallWindow *self)
3194 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3195 "camera-web", _("Can't establish video stream"));
3200 show_balance_error (EmpathyCallWindow *self)
3204 gchar *balance, *tmp;
3205 const gchar *uri, *currency;
3209 g_object_get (self->priv->handler,
3210 "call-channel", &call,
3213 conn = tp_channel_get_connection (call);
3214 g_object_unref (call);
3216 uri = tp_connection_get_balance_uri (conn);
3218 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3220 /* unknown balance */
3221 balance = g_strdup ("(--)");
3225 char *money = empathy_format_currency (amount, scale, currency);
3227 balance = g_strdup_printf ("%s %s",
3232 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3234 display_error (self,
3236 _("Sorry, you don’t have enough credit for that call."),
3240 EMP_RESPONSE_BALANCE);
3247 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3250 EmpathyCallWindow *self)
3252 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3253 TpCallChannel *call;
3254 gboolean can_send_video;
3256 if (state == TP_CALL_STATE_ENDED)
3258 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3259 empathy_call_window_disconnected (self, TRUE);
3260 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3261 show_balance_error (self);
3265 if (state != TP_CALL_STATE_ACCEPTED)
3268 if (priv->call_state == CONNECTED)
3271 g_timer_start (priv->timer);
3272 priv->call_state = CONNECTED;
3274 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3276 can_send_video = priv->video_input != NULL &&
3277 empathy_contact_can_voip_video (priv->contact) &&
3278 tpaw_camera_monitor_get_available (priv->camera_monitor);
3280 g_object_get (priv->handler, "call-channel", &call, NULL);
3282 if (tp_call_channel_has_dtmf (call))
3283 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3285 if (priv->video_input == NULL)
3286 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3288 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3290 empathy_call_window_show_hangup_button (self, TRUE);
3292 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3294 clutter_actor_hide (priv->video_output);
3295 gtk_widget_show (priv->remote_user_avatar_widget);
3297 g_object_unref (call);
3299 g_mutex_lock (&priv->lock);
3301 priv->timer_id = g_timeout_add_seconds (1,
3302 empathy_call_window_update_timer, self);
3304 g_mutex_unlock (&priv->lock);
3306 empathy_call_window_update_timer (self);
3308 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3312 empathy_call_window_show_video_output_cb (gpointer user_data)
3314 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3316 if (self->priv->video_output != NULL)
3318 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3319 clutter_actor_show (self->priv->video_output);
3320 clutter_actor_raise_top (self->priv->overlay_bin);
3327 empathy_call_window_check_video_cb (gpointer data)
3329 EmpathyCallWindow *self = data;
3331 if (self->priv->got_video)
3333 self->priv->got_video = FALSE;
3337 /* No video in the last N seconds, display the remote avatar */
3338 empathy_call_window_show_video_output (self, FALSE);
3343 /* Called from the streaming thread */
3345 static GstPadProbeReturn
3346 empathy_call_window_video_probe_cb (GstPad *pad,
3347 GstPadProbeInfo *info,
3350 EmpathyCallWindow *self = user_data;
3352 if (G_UNLIKELY (!self->priv->got_video))
3354 /* show the remote video */
3355 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3356 empathy_call_window_show_video_output_cb,
3357 g_object_ref (self), g_object_unref);
3359 self->priv->got_video = TRUE;
3362 return GST_PAD_PROBE_OK;
3366 empathy_call_window_video_probe_cb (GstPad *pad,
3367 GstMiniObject *mini_obj,
3368 EmpathyCallWindow *self)
3371 if (GST_IS_EVENT (mini_obj))
3374 if (G_UNLIKELY (!self->priv->got_video))
3376 /* show the remote video */
3377 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3378 empathy_call_window_show_video_output_cb,
3379 g_object_ref (self), g_object_unref);
3381 self->priv->got_video = TRUE;
3388 /* Called from the streaming thread */
3390 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3391 TfContent *content, GstPad *src, gpointer user_data)
3393 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3394 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3395 gboolean retval = FALSE;
3400 g_mutex_lock (&priv->lock);
3402 g_object_get (content, "media-type", &media_type, NULL);
3406 case TP_MEDIA_STREAM_TYPE_AUDIO:
3407 pad = empathy_call_window_get_audio_sink_pad (self, content);
3409 case TP_MEDIA_STREAM_TYPE_VIDEO:
3410 g_idle_add (empathy_call_window_show_video_output_cb, self);
3411 pad = empathy_call_window_get_video_sink_pad (self);
3414 gst_pad_add_probe (src,
3415 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3416 empathy_call_window_video_probe_cb, self, NULL);
3418 gst_pad_add_data_probe (src,
3419 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3421 if (priv->got_video_src > 0)
3422 g_source_remove (priv->got_video_src);
3423 priv->got_video_src = g_timeout_add_seconds (1,
3424 empathy_call_window_check_video_cb, self);
3427 g_assert_not_reached ();
3433 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3434 g_warning ("Could not link %s sink pad",
3435 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3439 gst_object_unref (pad);
3443 /* If no sink could be linked, try to add fakesink to prevent the whole call
3448 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3450 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3452 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3453 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3454 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3456 gst_element_set_locked_state (fakesink, TRUE);
3457 gst_element_set_state (fakesink, GST_STATE_NULL);
3458 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3462 DEBUG ("Could not link real sink, linked fakesink instead");
3464 gst_object_unref (sinkpad);
3468 gst_object_unref (fakesink);
3473 g_mutex_unlock (&priv->lock);
3479 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3482 EmpathyCallWindowPriv *priv = self->priv;
3484 g_assert (priv->audio_output_added == FALSE);
3485 g_assert (priv->audio_output == FALSE);
3487 priv->audio_output = empathy_audio_sink_new ();
3488 g_object_ref_sink (priv->audio_output);
3490 /* volume button to output volume linking */
3491 g_object_bind_property (priv->audio_output, "volume",
3492 priv->volume_button, "value",
3493 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3495 g_object_bind_property_full (content, "requested-output-volume",
3496 priv->audio_output, "volume",
3498 audio_control_volume_to_element,
3499 element_volume_to_audio_control,
3502 /* Link volumes together, sync the current audio input volume property
3503 * back to farstream first */
3504 g_object_bind_property_full (priv->audio_output, "volume",
3505 content, "reported-output-volume",
3506 G_BINDING_SYNC_CREATE,
3507 element_volume_to_audio_control,
3508 audio_control_volume_to_element,
3511 /* For raw audio conferences assume that the producer of the raw data
3512 * has already processed it, so turn off any echo cancellation and any
3513 * other audio improvements that come with it */
3514 empathy_audio_sink_set_echo_cancel (
3515 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3516 !empathy_call_window_content_is_raw (content));
3521 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3522 TfContent *content, gpointer user_data)
3524 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3525 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3527 FsMediaType media_type;
3528 gboolean retval = FALSE;
3530 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3531 g_assert (sink != NULL);
3535 case FS_MEDIA_TYPE_AUDIO:
3537 /* For raw audio conferences assume that the receiver of the raw data
3538 * wants it unprocessed, so turn off any echo cancellation and any
3539 * other audio improvements that come with it */
3540 empathy_audio_src_set_echo_cancel (
3541 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3542 !empathy_call_window_content_is_raw (content));
3544 /* Link volumes together, sync the current audio input volume property
3545 * back to farstream first */
3546 g_object_bind_property_full (content, "requested-input-volume",
3547 priv->audio_input, "volume",
3549 audio_control_volume_to_element,
3550 element_volume_to_audio_control,
3553 g_object_bind_property_full (priv->audio_input, "volume",
3554 content, "reported-input-volume",
3555 G_BINDING_SYNC_CREATE,
3556 element_volume_to_audio_control,
3557 audio_control_volume_to_element,
3560 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3562 g_warning ("Could not add audio source to pipeline");
3566 pad = gst_element_get_static_pad (priv->audio_input, "src");
3569 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3570 g_warning ("Could not get source pad from audio source");
3574 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3576 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3577 gst_object_unref (pad);
3578 g_warning ("Could not link audio source to farsight");
3581 gst_object_unref (pad);
3583 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3585 g_warning ("Could not start audio source");
3586 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3587 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3591 /* Prepare our audio output, not added yet though */
3592 empathy_call_window_prepare_audio_output (self, content);
3596 case FS_MEDIA_TYPE_VIDEO:
3597 if (priv->video_tee != NULL)
3600 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3602 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3604 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3606 g_warning ("Could not link video source input pipeline");
3609 gst_object_unref (pad);
3615 g_assert_not_reached ();
3618 gst_object_unref (sink);
3623 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3625 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3626 GstElement *preview;
3628 disable_camera (self);
3630 DEBUG ("remove video input");
3631 preview = priv->video_preview_sink;
3633 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3634 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3635 gst_element_set_state (preview, GST_STATE_NULL);
3637 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3640 g_object_unref (priv->video_input);
3641 priv->video_input = NULL;
3642 g_object_unref (priv->video_tee);
3643 priv->video_tee = NULL;
3644 clutter_actor_destroy (priv->video_preview);
3645 priv->video_preview = NULL;
3647 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3648 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3652 start_call (EmpathyCallWindow *self)
3654 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3656 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3658 priv->call_started = TRUE;
3659 empathy_call_handler_start_call (priv->handler,
3660 gtk_get_current_event_time ());
3662 if (empathy_call_handler_has_initial_video (priv->handler))
3664 TpCallChannel *call;
3667 g_object_get (priv->handler, "call-channel", &call, NULL);
3668 /* If the call channel isn't set yet we're requesting it, if we're
3669 * requesting it with initial video it should be PENDING_SEND when we get
3672 s = TP_SENDING_STATE_PENDING_SEND;
3674 s = empathy_call_channel_get_video_state (call);
3676 if (s == TP_SENDING_STATE_PENDING_SEND ||
3677 s == TP_SENDING_STATE_SENDING)
3679 /* Enable 'send video' buttons and display the preview */
3680 gtk_toggle_button_set_active (
3681 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3685 gtk_toggle_button_set_active (
3686 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3688 if (priv->video_preview == NULL)
3690 create_video_preview (self);
3691 add_video_preview_to_pipeline (self);
3696 g_object_unref (call);
3701 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3704 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3705 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3706 GstState newstate, pending;
3708 empathy_call_handler_bus_message (priv->handler, bus, message);
3710 switch (GST_MESSAGE_TYPE (message))
3712 case GST_MESSAGE_STATE_CHANGED:
3713 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3715 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3717 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3718 !priv->call_started)
3720 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3721 if (newstate == GST_STATE_PAUSED)
3723 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3724 priv->pipeline_playing = TRUE;
3726 if (priv->start_call_when_playing)
3730 if (priv->video_preview_sink != NULL &&
3731 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3733 gst_message_parse_state_changed (message, NULL, &newstate,
3736 if (newstate == GST_STATE_PLAYING &&
3737 pending == GST_STATE_VOID_PENDING)
3738 empathy_call_window_stop_camera_spinning (self);
3741 case GST_MESSAGE_ERROR:
3743 GError *error = NULL;
3744 GstElement *gst_error;
3748 gst_message_parse_error (message, &error, &debug);
3749 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3751 g_message ("Element error: %s -- %s\n", error->message, debug);
3753 name = gst_element_get_name (gst_error);
3754 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3756 /* Remove the video input and continue */
3757 if (priv->video_input != NULL)
3758 empathy_call_window_remove_video_input (self);
3759 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3763 empathy_call_window_disconnected (self, TRUE);
3766 g_error_free (error);
3769 case GST_MESSAGE_UNKNOWN:
3770 case GST_MESSAGE_EOS:
3771 case GST_MESSAGE_WARNING:
3772 case GST_MESSAGE_INFO:
3773 case GST_MESSAGE_TAG:
3774 case GST_MESSAGE_BUFFERING:
3775 case GST_MESSAGE_STATE_DIRTY:
3776 case GST_MESSAGE_STEP_DONE:
3777 case GST_MESSAGE_CLOCK_PROVIDE:
3778 case GST_MESSAGE_CLOCK_LOST:
3779 case GST_MESSAGE_NEW_CLOCK:
3780 case GST_MESSAGE_STRUCTURE_CHANGE:
3781 case GST_MESSAGE_STREAM_STATUS:
3782 case GST_MESSAGE_APPLICATION:
3783 case GST_MESSAGE_ELEMENT:
3784 case GST_MESSAGE_SEGMENT_START:
3785 case GST_MESSAGE_SEGMENT_DONE:
3786 case GST_MESSAGE_DURATION:
3787 case GST_MESSAGE_ANY:
3796 empathy_call_window_members_changed_cb (TpCallChannel *call,
3797 GHashTable *updates,
3799 TpCallStateReason *reason,
3800 EmpathyCallWindow *self)
3802 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3803 GHashTableIter iter;
3804 gpointer key, value;
3805 gboolean held = FALSE;
3807 g_hash_table_iter_init (&iter, updates);
3808 while (g_hash_table_iter_next (&iter, &key, &value))
3810 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3812 /* This assumes this is a 1-1 call, otherwise one participant
3813 * putting the call on hold wouldn't mean the call is on hold
3821 priv->call_state = HELD;
3822 else if (priv->call_state == HELD)
3823 priv->call_state = CONNECTED;
3827 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3829 EmpathyCallWindow *self)
3831 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3832 TpCallChannel *call;
3834 g_object_get (priv->handler, "call-channel", &call, NULL);
3839 tp_g_signal_connect_object (call, "audio-stream-error",
3840 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3841 tp_g_signal_connect_object (call, "video-stream-error",
3842 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3845 tp_g_signal_connect_object (call, "members-changed",
3846 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3848 g_object_unref (call);
3852 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3854 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3855 TpCallChannel *call;
3857 g_signal_connect (priv->handler, "state-changed",
3858 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3859 g_signal_connect (priv->handler, "conference-added",
3860 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3861 g_signal_connect (priv->handler, "conference-removed",
3862 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3863 g_signal_connect (priv->handler, "closed",
3864 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3865 g_signal_connect (priv->handler, "src-pad-added",
3866 G_CALLBACK (empathy_call_window_src_added_cb), self);
3867 g_signal_connect (priv->handler, "content-added",
3868 G_CALLBACK (empathy_call_window_content_added_cb), self);
3869 g_signal_connect (priv->handler, "content-removed",
3870 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3872 /* We connect to ::call-channel unconditionally since we'll
3873 * get new channels if we hangup and redial or if we reuse the
3875 g_signal_connect (priv->handler, "notify::call-channel",
3876 G_CALLBACK (call_handler_notify_call_cb), self);
3878 g_signal_connect (priv->handler, "framerate-changed",
3879 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3880 g_signal_connect (priv->handler, "resolution-changed",
3881 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3883 g_object_get (priv->handler, "call-channel", &call, NULL);
3886 /* We won't get notify::call-channel for this channel, so
3887 * directly call the callback. */
3888 call_handler_notify_call_cb (priv->handler, NULL, self);
3889 g_object_unref (call);
3894 empathy_call_window_realized_cb (GtkWidget *widget,
3895 EmpathyCallWindow *self)
3899 /* Make the hangup button twice as wide */
3900 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3901 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3903 empathy_call_window_connect_handler (self);
3905 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3909 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3910 EmpathyCallWindow *window)
3912 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3914 if (priv->pipeline != NULL)
3916 if (priv->bus_message_source_id != 0)
3918 g_source_remove (priv->bus_message_source_id);
3919 priv->bus_message_source_id = 0;
3922 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3925 if (priv->call_state == CONNECTING)
3926 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3932 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3935 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3937 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3942 gtk_widget_hide (priv->dtmf_panel);
3943 gtk_widget_hide (menu);
3944 gtk_widget_hide (priv->toolbar);
3948 if (priv->dialpad_was_visible_before_fs)
3949 gtk_widget_show (priv->dtmf_panel);
3951 gtk_widget_show (menu);
3952 gtk_widget_show (priv->toolbar);
3954 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3955 priv->original_height_before_fs);
3960 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3962 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3964 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3965 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3967 if (priv->video_output != NULL)
3970 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3971 priv->video_output, TRUE, TRUE,
3972 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3979 empathy_call_window_state_event_cb (GtkWidget *widget,
3980 GdkEventWindowState *event, EmpathyCallWindow *window)
3982 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3984 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3985 gboolean set_fullscreen = event->new_window_state &
3986 GDK_WINDOW_STATE_FULLSCREEN;
3990 gboolean dialpad_was_visible;
3991 GtkAllocation allocation;
3992 gint original_width, original_height;
3994 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3995 original_width = allocation.width;
3996 original_height = allocation.height;
3998 g_object_get (priv->dtmf_panel,
3999 "visible", &dialpad_was_visible,
4002 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4003 priv->original_width_before_fs = original_width;
4004 priv->original_height_before_fs = original_height;
4006 if (priv->video_output_motion_handler_id == 0 &&
4007 priv->video_output != NULL)
4009 priv->video_output_motion_handler_id = g_signal_connect (
4010 G_OBJECT (priv->video_container), "motion-notify-event",
4011 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4017 disconnect_video_output_motion_handler (window);
4020 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4022 show_controls (window, set_fullscreen);
4023 show_borders (window, set_fullscreen);
4024 gtk_action_set_stock_id (priv->menu_fullscreen,
4025 (set_fullscreen ? "view-restore" : "view-fullscreen"));
4026 priv->is_fullscreen = set_fullscreen;
4033 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4036 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4037 int w, h, dialpad_width;
4038 GtkAllocation allocation;
4040 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4041 w = allocation.width;
4042 h = allocation.height;
4044 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4048 gtk_widget_show (priv->dtmf_panel);
4054 gtk_widget_hide (priv->dtmf_panel);
4058 gtk_window_resize (GTK_WINDOW (window), w, h);
4062 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4065 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4066 TpCallChannel *call;
4068 priv->sending_video = (state == CAMERA_STATE_ON);
4070 if (state == CAMERA_STATE_ON)
4072 /* When we start sending video, we want to show the video preview by
4074 display_video_preview (window, TRUE);
4078 display_video_preview (window, FALSE);
4081 if (priv->call_state != CONNECTED)
4084 g_object_get (priv->handler, "call-channel", &call, NULL);
4085 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4086 empathy_call_channel_send_video (call, priv->sending_video);
4087 g_object_unref (call);
4091 empathy_call_window_hangup_cb (gpointer object,
4092 EmpathyCallWindow *self)
4094 /* stopping the call will put it the ENDED state and
4095 * from state_changed_cb we'll reconfigure the window
4097 empathy_call_handler_stop_call (self->priv->handler);
4101 empathy_call_window_restart_call (EmpathyCallWindow *window)
4103 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4105 /* Remove error info bars */
4106 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4107 (GtkCallback) gtk_widget_destroy, NULL);
4109 create_video_output_widget (window);
4110 priv->outgoing = TRUE;
4111 empathy_call_window_set_state_connecting (window);
4113 if (priv->pipeline_playing)
4114 start_call (window);
4116 /* call will be started when the pipeline is ready */
4117 priv->start_call_when_playing = TRUE;
4119 empathy_call_window_setup_avatars (window, priv->handler);
4121 empathy_call_window_show_hangup_button (window, TRUE);
4125 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4126 EmpathyCallWindow *window)
4130 active = gtk_toggle_tool_button_get_active (button);
4132 empathy_call_window_show_dialpad (window, active);
4136 empathy_call_window_fullscreen_cb (gpointer object,
4137 EmpathyCallWindow *window)
4139 empathy_call_window_fullscreen_toggle (window);
4143 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4145 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4147 if (priv->is_fullscreen)
4148 gtk_window_unfullscreen (GTK_WINDOW (window));
4150 gtk_window_fullscreen (GTK_WINDOW (window));
4154 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4155 GdkEventButton *event, EmpathyCallWindow *window)
4157 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4159 empathy_call_window_video_menu_popup (window, event->button);
4167 empathy_call_window_key_press_cb (GtkWidget *video_output,
4168 GdkEventKey *event, EmpathyCallWindow *window)
4170 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4173 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4175 /* Since we are in fullscreen mode, toggling will bring us back to
4177 empathy_call_window_fullscreen_toggle (window);
4181 key = gdk_keyval_to_unicode (event->keyval);
4202 gtk_toggle_tool_button_set_active (
4203 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4205 empathy_dialpad_widget_press_key (
4206 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4212 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4213 GdkEventMotion *event, EmpathyCallWindow *window)
4215 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4217 if (priv->is_fullscreen)
4219 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4221 /* Show the bottom toolbar */
4222 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4229 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4233 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4235 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4237 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4238 button, gtk_get_current_event_time ());
4239 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4243 empathy_call_window_status_message (EmpathyCallWindow *self,
4246 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4250 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4252 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4254 return priv->ui_manager;
4257 EmpathyGstAudioSrc *
4258 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4260 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4262 return (EmpathyGstAudioSrc *) priv->audio_input;
4265 EmpathyGstVideoSrc *
4266 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4268 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4272 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4273 const gchar *device)
4275 EmpathyGstVideoSrc *video;
4278 /* Restart the camera only if it's already running */
4279 running = (self->priv->video_preview != NULL);
4280 video = empathy_call_window_get_video_src (self);
4283 empathy_call_window_play_camera (self, FALSE);
4285 empathy_video_src_change_device (video, device);
4288 empathy_call_window_play_camera (self, TRUE);