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>
31 #include "empathy-about-dialog.h"
32 #include "empathy-audio-sink.h"
33 #include "empathy-call-utils.h"
34 #include "empathy-call-window-fullscreen.h"
35 #include "empathy-camera-menu.h"
36 #include "empathy-dialpad-widget.h"
37 #include "empathy-geometry.h"
38 #include "empathy-gsettings.h"
39 #include "empathy-images.h"
40 #include "empathy-mic-menu.h"
41 #include "empathy-preferences.h"
42 #include "empathy-request-util.h"
43 #include "empathy-rounded-actor.h"
44 #include "empathy-rounded-rectangle.h"
45 #include "empathy-rounded-texture.h"
46 #include "empathy-sound-manager.h"
47 #include "empathy-ui-utils.h"
48 #include "empathy-utils.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
51 #include "empathy-debug.h"
53 #define CONTENT_HBOX_SPACING 3
54 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
55 #define OVERLAY_MARGIN 6
57 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
58 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
60 #define SELF_VIDEO_SECTION_WIDTH 120
61 #define SELF_VIDEO_SECTION_HEIGHT 90
62 #define SELF_VIDEO_SECTION_MARGIN 2
63 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
65 /* The avatar's default width and height are set to the same value because we
66 want a square icon. */
67 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
68 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
70 #define SMALL_TOOLBAR_SIZE 36
72 /* If an video input error occurs, the error message will start with "v4l" */
73 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
75 /* The time interval in milliseconds between 2 outgoing rings */
76 #define MS_BETWEEN_RING 500
78 /* The roundedness of preview box and placeholders */
79 #define PREVIEW_ROUND_FACTOR 16
81 #define PREVIEW_BUTTON_OPACITY 180
83 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
86 PROP_CALL_HANDLER = 1,
94 static guint signals[LAST_SIGNAL];
97 RINGING, /* Incoming call */
98 CONNECTING, /* Outgoing call */
99 CONNECTED, /* Connected */
100 HELD, /* Connected, but on hold */
101 DISCONNECTED, /* Disconnected */
102 REDIALING /* Redialing (special case of CONNECTING) */
106 CAMERA_STATE_OFF = 0,
112 PREVIEW_POS_TOP_LEFT,
113 PREVIEW_POS_TOP_RIGHT,
114 PREVIEW_POS_BOTTOM_LEFT,
115 PREVIEW_POS_BOTTOM_RIGHT,
118 struct _EmpathyCallWindowPriv
120 gboolean dispose_has_run;
121 EmpathyCallHandler *handler;
123 EmpathyContact *contact;
125 TpawCameraMonitor *camera_monitor;
127 CallState call_state;
130 GtkUIManager *ui_manager;
131 GtkWidget *errors_vbox;
132 /* widget displays the video received from the remote user. This widget is
133 * alive only during call. */
134 ClutterActor *video_output;
135 ClutterActor *video_preview;
136 ClutterActor *drag_preview;
137 ClutterActor *preview_shown_button;
138 ClutterActor *preview_hidden_button;
139 ClutterActor *preview_rectangle1;
140 ClutterActor *preview_rectangle2;
141 ClutterActor *preview_rectangle3;
142 ClutterActor *preview_rectangle4;
143 ClutterActor *preview_spinner_actor;
144 GtkWidget *preview_spinner_widget;
145 GtkWidget *video_container;
146 GtkWidget *remote_user_avatar_widget;
147 GtkWidget *remote_user_avatar_toolbar;
148 GtkWidget *remote_user_name_toolbar;
149 GtkWidget *remote_user_status_toolbar;
150 GtkWidget *status_label;
151 GtkWidget *hangup_button;
152 GtkWidget *audio_call_button;
153 GtkWidget *video_call_button;
154 GtkWidget *mic_button;
155 GtkWidget *microphone_icon;
156 GtkWidget *volume_button;
157 GtkWidget *camera_button;
158 GtkWidget *dialpad_button;
160 GtkWidget *bottom_toolbar;
161 ClutterActor *floating_toolbar;
163 GtkAction *menu_fullscreen;
164 GtkAction *menu_swap_camera;
166 ClutterState *transitions;
168 /* The main box covering all the stage, contaning remote avatar/video */
169 ClutterActor *video_box;
170 ClutterLayoutManager *video_layout;
172 /* A bin layout manager containing a bin for previews
173 * and the floating toolbar */
174 ClutterActor *overlay_bin;
175 ClutterLayoutManager *overlay_layout;
177 /* Bin layout for the previews */
178 ClutterActor *preview_box;
179 ClutterLayoutManager *preview_layout;
181 /* Coordinates of the preview drag event's start. */
182 PreviewPosition preview_pos;
184 /* We keep a reference on the hbox which contains the main content so we can
185 easilly repack everything when toggling fullscreen */
186 GtkWidget *content_hbox;
188 /* These are used to accept or reject an incoming call when the status
190 GtkWidget *incoming_call_dialog;
191 TpCallChannel *pending_channel;
192 TpChannelDispatchOperation *pending_cdo;
193 TpAddDispatchOperationContext *pending_context;
195 gulong video_output_motion_handler_id;
196 guint bus_message_source_id;
198 GtkWidget *dtmf_panel;
201 GtkWidget *details_vbox;
202 GtkWidget *vcodec_encoding_label;
203 GtkWidget *acodec_encoding_label;
204 GtkWidget *vcodec_decoding_label;
205 GtkWidget *acodec_decoding_label;
207 GtkWidget *audio_remote_candidate_label;
208 GtkWidget *audio_local_candidate_label;
209 GtkWidget *video_remote_candidate_label;
210 GtkWidget *video_local_candidate_label;
211 GtkWidget *video_remote_candidate_info_img;
212 GtkWidget *video_local_candidate_info_img;
213 GtkWidget *audio_remote_candidate_info_img;
214 GtkWidget *audio_local_candidate_info_img;
216 GstElement *video_input;
217 GstElement *video_preview_sink;
218 GstElement *video_output_sink;
219 GstElement *audio_input;
220 GstElement *audio_output;
221 gboolean audio_output_added;
222 GstElement *pipeline;
223 GstElement *video_tee;
233 gboolean call_started;
234 gboolean sending_video;
235 CameraState camera_state;
237 EmpathyCallWindowFullscreen *fullscreen;
238 gboolean is_fullscreen;
243 guint inactivity_src;
245 /* Those fields represent the state of the window before it actually was in
247 gboolean dialpad_was_visible_before_fs;
248 gint original_width_before_fs;
249 gint original_height_before_fs;
251 gint x, y, w, h, dialpad_width;
254 /* TRUE if the call should be started when the pipeline is playing */
255 gboolean start_call_when_playing;
256 /* TRUE if we requested to set the pipeline in the playing state */
257 gboolean pipeline_playing;
259 EmpathySoundManager *sound_mgr;
262 EmpathyMicMenu *mic_menu;
263 EmpathyCameraMenu *camera_menu;
268 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
270 static void empathy_call_window_realized_cb (GtkWidget *widget,
271 EmpathyCallWindow *window);
273 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
274 GdkEvent *event, EmpathyCallWindow *window);
276 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
277 GdkEventWindowState *event, EmpathyCallWindow *window);
279 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
282 static void empathy_call_window_hangup_cb (gpointer object,
283 EmpathyCallWindow *window);
285 static void empathy_call_window_fullscreen_cb (gpointer object,
286 EmpathyCallWindow *window);
288 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
290 static gboolean empathy_call_window_video_button_press_cb (
291 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
293 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
294 GdkEventKey *event, EmpathyCallWindow *window);
296 static gboolean empathy_call_window_video_output_motion_notify (
297 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
299 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
302 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
304 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
305 EmpathyCallWindow *window);
307 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
309 static void empathy_call_window_status_message (EmpathyCallWindow *window,
312 static gboolean empathy_call_window_bus_message (GstBus *bus,
313 GstMessage *message, gpointer user_data);
315 static gboolean empathy_call_window_update_timer (gpointer user_data);
318 make_background_transparent (GtkClutterActor *actor)
320 GdkRGBA transparent = { 0., 0., 0., 0. };
323 widget = gtk_clutter_actor_get_widget (actor);
324 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
328 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
331 gtk_widget_set_visible (self->priv->hangup_button, show);
332 gtk_widget_set_visible (self->priv->audio_call_button, !show);
333 gtk_widget_set_visible (self->priv->video_call_button, !show);
337 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
338 EmpathyCallWindow *self)
340 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
341 empathy_call_window_restart_call (self);
345 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
346 EmpathyCallWindow *self)
348 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
349 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
350 empathy_call_window_restart_call (self);
354 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
356 EmpathyCallWindow *self)
361 g_object_get (self->priv->handler, "call-channel", &call, NULL);
363 tones[0] = tp_dtmf_event_to_char (event);
365 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
367 g_object_unref (call);
371 empathy_call_window_show_video_output (EmpathyCallWindow *self,
374 if (self->priv->video_output != NULL)
375 g_object_set (self->priv->video_output, "visible", show, NULL);
377 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
379 clutter_actor_raise_top (self->priv->overlay_bin);
383 create_video_output_widget (EmpathyCallWindow *self)
385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
387 g_assert (priv->video_output == NULL);
388 g_assert (priv->pipeline != NULL);
390 priv->video_output = clutter_texture_new ();
392 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
395 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
396 if (priv->video_output_sink == NULL)
397 g_error ("Missing cluttersink");
399 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
401 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
404 gtk_widget_add_events (priv->video_container,
405 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
406 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
407 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
411 create_video_input (EmpathyCallWindow *self)
413 EmpathyCallWindowPriv *priv = GET_PRIV (self);
415 g_assert (priv->video_input == NULL);
416 priv->video_input = empathy_video_src_new ();
417 gst_object_ref_sink (priv->video_input);
421 audio_control_volume_to_element (GBinding *binding,
422 const GValue *source_value,
423 GValue *target_value,
426 /* AudioControl volume is 0-255, with -1 for unknown */
429 hv = g_value_get_int (source_value);
434 g_value_set_double (target_value, hv/255.0);
440 element_volume_to_audio_control (GBinding *binding,
441 const GValue *source_value,
442 GValue *target_value,
447 ev = g_value_get_double (source_value);
448 ev = CLAMP (ev, 0.0, 1.0);
450 g_value_set_int (target_value, ev * 255);
455 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
456 EmpathyCallWindow *self)
459 g_object_get (obj, "mute", &muted, NULL);
461 self->priv->muted = muted;
462 if (muted && self->priv->transitions)
463 clutter_state_set_state (self->priv->transitions, "fade-in");
467 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
468 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
472 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
473 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
476 empathy_call_window_update_timer (self);
480 create_audio_input (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
484 g_assert (priv->audio_input == NULL);
485 priv->audio_input = empathy_audio_src_new ();
486 gst_object_ref_sink (priv->audio_input);
488 g_signal_connect (priv->audio_input, "notify::mute",
489 G_CALLBACK (audio_input_mute_notify_cb), self);
493 add_video_preview_to_pipeline (EmpathyCallWindow *self)
495 EmpathyCallWindowPriv *priv = GET_PRIV (self);
498 g_assert (priv->video_preview != NULL);
499 g_assert (priv->pipeline != NULL);
500 g_assert (priv->video_input != NULL);
501 g_assert (priv->video_tee != NULL);
503 preview = priv->video_preview_sink;
505 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
507 g_warning ("Could not add video input to pipeline");
511 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
513 g_warning ("Could not add video preview to pipeline");
517 if (!gst_element_link (priv->video_input, priv->video_tee))
519 g_warning ("Could not link video input to video tee");
523 if (!gst_element_link (priv->video_tee, preview))
525 g_warning ("Could not link video tee to video preview");
531 empathy_call_window_disable_camera_cb (GtkAction *action,
532 EmpathyCallWindow *self)
534 clutter_actor_destroy (self->priv->preview_hidden_button);
536 gtk_toggle_button_set_active (
537 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
541 empathy_call_window_minimise_camera_cb (GtkAction *action,
542 EmpathyCallWindow *self)
544 clutter_actor_hide (self->priv->video_preview);
545 clutter_actor_show (self->priv->preview_hidden_button);
549 empathy_call_window_maximise_camera_cb (GtkAction *action,
550 EmpathyCallWindow *self)
552 clutter_actor_show (self->priv->video_preview);
553 clutter_actor_hide (self->priv->preview_hidden_button);
557 empathy_call_window_swap_camera_cb (GtkAction *action,
558 EmpathyCallWindow *self)
560 const GList *cameras, *l;
563 DEBUG ("Swapping the camera");
565 cameras = tpaw_camera_monitor_get_cameras (self->priv->camera_monitor);
566 current_cam = empathy_video_src_dup_device (
567 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
569 for (l = cameras; l != NULL; l = l->next)
571 TpawCamera *camera = l->data;
573 if (!tp_strdiff (camera->device, current_cam))
578 next = l->next->data;
580 next = cameras->data;
582 /* EmpathyCameraMenu will update itself and do the actual change
584 g_settings_set_string (self->priv->settings,
585 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
592 g_free (current_cam);
596 empathy_call_window_camera_added_cb (TpawCameraMonitor *monitor,
598 EmpathyCallWindow *self)
600 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
602 gtk_action_set_visible (self->priv->menu_swap_camera,
603 g_list_length ((GList *) cameras) >= 2);
607 empathy_call_window_camera_removed_cb (TpawCameraMonitor *monitor,
609 EmpathyCallWindow *self)
611 const GList *cameras = tpaw_camera_monitor_get_cameras (monitor);
613 gtk_action_set_visible (self->priv->menu_swap_camera,
614 g_list_length ((GList *) cameras) >= 2);
618 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
620 EmpathyCallWindow *self)
624 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
626 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
627 0, gtk_get_current_event_time ());
628 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
632 empathy_call_window_preview_hidden_button_clicked_cb (
633 ClutterClickAction *action,
635 EmpathyCallWindow *self)
639 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
640 "/preview-hidden-menu");
641 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
642 0, gtk_get_current_event_time ());
643 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
646 static ClutterActor *
647 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
648 ClutterBinAlignment x,
649 ClutterBinAlignment y)
651 ClutterActor *rectangle;
653 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
654 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
655 PREVIEW_ROUND_FACTOR));
657 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
659 clutter_actor_hide (rectangle);
665 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
669 self->priv->preview_layout = clutter_bin_layout_new (
670 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
671 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
673 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
675 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
677 self->priv->preview_rectangle1 =
678 empathy_call_window_create_preview_rectangle (self,
679 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
680 self->priv->preview_rectangle2 =
681 empathy_call_window_create_preview_rectangle (self,
682 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
683 self->priv->preview_rectangle3 =
684 empathy_call_window_create_preview_rectangle (self,
685 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
686 self->priv->preview_rectangle4 =
687 empathy_call_window_create_preview_rectangle (self,
688 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
692 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
695 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
696 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
697 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
702 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
707 guint ret_x = 0, ret_y = 0;
710 if (!clutter_actor_has_allocation (self->priv->preview_box))
713 clutter_actor_get_geometry (self->priv->preview_box, &box);
717 case PREVIEW_POS_TOP_LEFT:
718 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
720 case PREVIEW_POS_TOP_RIGHT:
721 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
722 - SELF_VIDEO_SECTION_WIDTH;
723 ret_y = SELF_VIDEO_SECTION_MARGIN;
725 case PREVIEW_POS_BOTTOM_LEFT:
726 ret_x = SELF_VIDEO_SECTION_MARGIN;
727 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
728 - SELF_VIDEO_SECTION_HEIGHT;
730 case PREVIEW_POS_BOTTOM_RIGHT:
731 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
732 - SELF_VIDEO_SECTION_WIDTH;
733 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
734 - SELF_VIDEO_SECTION_HEIGHT;
737 g_warn_if_reached ();
748 static PreviewPosition
749 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
754 PreviewPosition pos = PREVIEW_POS_NONE;
756 if (!clutter_actor_has_allocation (self->priv->preview_box))
759 clutter_actor_get_geometry (self->priv->preview_box, &box);
761 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
762 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
763 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
764 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
766 pos = PREVIEW_POS_TOP_LEFT;
768 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
769 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
770 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
771 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
773 pos = PREVIEW_POS_TOP_RIGHT;
775 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
776 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
777 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
778 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
780 pos = PREVIEW_POS_BOTTOM_LEFT;
782 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
783 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
784 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
785 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
787 pos = PREVIEW_POS_BOTTOM_RIGHT;
793 static ClutterActor *
794 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
797 ClutterActor *rectangle;
801 case PREVIEW_POS_TOP_LEFT:
802 rectangle = self->priv->preview_rectangle1;
804 case PREVIEW_POS_TOP_RIGHT:
805 rectangle = self->priv->preview_rectangle3;
807 case PREVIEW_POS_BOTTOM_LEFT:
808 rectangle = self->priv->preview_rectangle2;
810 case PREVIEW_POS_BOTTOM_RIGHT:
811 rectangle = self->priv->preview_rectangle4;
821 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
824 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
826 DEBUG ("moving the video preview to %d", pos);
828 self->priv->preview_pos = pos;
832 case PREVIEW_POS_TOP_LEFT:
833 clutter_bin_layout_set_alignment (layout,
834 self->priv->video_preview,
835 CLUTTER_BIN_ALIGNMENT_START,
836 CLUTTER_BIN_ALIGNMENT_START);
838 case PREVIEW_POS_TOP_RIGHT:
839 clutter_bin_layout_set_alignment (layout,
840 self->priv->video_preview,
841 CLUTTER_BIN_ALIGNMENT_END,
842 CLUTTER_BIN_ALIGNMENT_START);
844 case PREVIEW_POS_BOTTOM_LEFT:
845 clutter_bin_layout_set_alignment (layout,
846 self->priv->video_preview,
847 CLUTTER_BIN_ALIGNMENT_START,
848 CLUTTER_BIN_ALIGNMENT_END);
850 case PREVIEW_POS_BOTTOM_RIGHT:
851 clutter_bin_layout_set_alignment (layout,
852 self->priv->video_preview,
853 CLUTTER_BIN_ALIGNMENT_END,
854 CLUTTER_BIN_ALIGNMENT_END);
857 g_warn_if_reached ();
860 g_settings_set_enum (self->priv->settings, "camera-position", pos);
864 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
867 ClutterActor *rectangle;
868 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
870 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
872 empathy_rounded_rectangle_set_border_width (
873 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
874 empathy_rounded_rectangle_set_border_color (
875 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
879 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
880 ClutterActor *rectangle)
882 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
884 clutter_color_shade (&white, 0.55, &darker);
886 empathy_rounded_rectangle_set_border_width (
887 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
888 empathy_rounded_rectangle_set_border_color (
889 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
893 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
895 ClutterActor *rectangle;
897 rectangle = empathy_call_window_get_preview_rectangle (self,
898 self->priv->preview_pos);
900 /* We don't want to darken the rectangle where the preview
903 if (self->priv->preview_rectangle1 != rectangle)
904 empathy_call_window_darken_preview_rectangle (self,
905 self->priv->preview_rectangle1);
907 if (self->priv->preview_rectangle2 != rectangle)
908 empathy_call_window_darken_preview_rectangle (self,
909 self->priv->preview_rectangle2);
911 if (self->priv->preview_rectangle3 != rectangle)
912 empathy_call_window_darken_preview_rectangle (self,
913 self->priv->preview_rectangle3);
915 if (self->priv->preview_rectangle4 != rectangle)
916 empathy_call_window_darken_preview_rectangle (self,
917 self->priv->preview_rectangle4);
921 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
925 ClutterModifierType modifiers,
926 EmpathyCallWindow *self)
928 ClutterActor *stage = clutter_actor_get_stage (actor);
931 self->priv->drag_preview = clutter_clone_new (actor);
933 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
934 self->priv->drag_preview);
936 clutter_actor_transform_stage_point (actor, event_x, event_y,
939 clutter_actor_set_position (self->priv->drag_preview,
940 event_x - rel_x, event_y - rel_y);
942 clutter_drag_action_set_drag_handle (action,
943 self->priv->drag_preview);
945 clutter_actor_set_opacity (actor, 0);
946 clutter_actor_hide (self->priv->preview_shown_button);
948 empathy_call_window_show_preview_rectangles (self, TRUE);
949 empathy_call_window_darken_preview_rectangles (self);
953 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
956 clutter_actor_set_opacity (actor, 255);
960 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
964 ClutterModifierType modifiers,
965 EmpathyCallWindow *self)
970 /* Get the position before destroying the drag actor, otherwise the
971 * preview_box allocation won't be valid and we won't be able to
972 * calculate the position. */
973 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
975 empathy_call_window_get_preview_coordinates (self,
976 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
979 /* Move the preview to the destination and destroy it afterwards */
980 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
983 "signal-swapped-after::completed",
984 clutter_actor_destroy, self->priv->drag_preview,
985 "signal-swapped-after::completed",
986 clutter_actor_show, self->priv->preview_shown_button,
988 empathy_call_window_on_animation_completed_cb, actor,
991 self->priv->drag_preview = NULL;
993 if (pos != PREVIEW_POS_NONE)
994 empathy_call_window_move_video_preview (self, pos);
996 empathy_call_window_show_preview_rectangles (self, FALSE);
1000 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1001 ClutterActor *actor,
1004 EmpathyCallWindow *self)
1006 PreviewPosition pos;
1007 gfloat event_x, event_y;
1009 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1011 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1013 if (pos != PREVIEW_POS_NONE)
1014 empathy_call_window_highlight_preview_rectangle (self, pos);
1016 empathy_call_window_darken_preview_rectangles (self);
1020 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1021 ClutterCrossingEvent *event,
1022 EmpathyCallWindow *self)
1024 ClutterActor *rectangle;
1026 rectangle = empathy_call_window_get_preview_rectangle (self,
1027 self->priv->preview_pos);
1029 empathy_call_window_highlight_preview_rectangle (self,
1030 self->priv->preview_pos);
1032 clutter_actor_show (rectangle);
1038 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1039 ClutterCrossingEvent *event,
1040 EmpathyCallWindow *self)
1042 ClutterActor *rectangle;
1044 rectangle = empathy_call_window_get_preview_rectangle (self,
1045 self->priv->preview_pos);
1047 empathy_call_window_darken_preview_rectangle (self, rectangle);
1049 clutter_actor_hide (rectangle);
1055 create_video_preview (EmpathyCallWindow *self)
1057 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1058 ClutterLayoutManager *layout;
1059 ClutterActor *preview;
1061 ClutterAction *action;
1062 PreviewPosition pos;
1064 g_assert (priv->video_preview == NULL);
1066 pos = g_settings_get_enum (priv->settings, "camera-position");
1068 preview = empathy_rounded_texture_new ();
1069 clutter_actor_set_size (preview,
1070 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1072 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1073 if (priv->video_preview_sink == NULL)
1074 g_error ("Missing cluttersink, check your clutter-gst installation");
1075 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1076 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1078 /* Add a little offset to the video preview */
1079 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1080 CLUTTER_BIN_ALIGNMENT_CENTER);
1081 priv->video_preview = clutter_box_new (layout);
1082 clutter_actor_set_size (priv->video_preview,
1083 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1084 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1086 /* Spinner for when changing the camera device */
1087 priv->preview_spinner_widget = gtk_spinner_new ();
1088 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1090 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1091 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1092 gtk_widget_show (priv->preview_spinner_widget);
1095 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1096 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1097 priv->preview_spinner_widget);
1098 clutter_actor_set_size (priv->preview_spinner_actor,
1099 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1100 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1101 clutter_actor_hide (priv->preview_spinner_actor);
1103 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1105 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1106 priv->preview_spinner_actor);
1108 g_object_set (priv->video_preview_sink,
1114 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1115 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1116 GTK_ICON_SIZE_MENU));
1117 clutter_actor_set_margin_right (b, 4);
1118 clutter_actor_set_margin_bottom (b, 2);
1119 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1120 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1122 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1123 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1125 action = clutter_click_action_new ();
1126 clutter_actor_add_action (b, action);
1127 g_signal_connect (action, "clicked",
1128 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1130 /* Preview hidden */
1131 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1132 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1133 GTK_ICON_SIZE_MENU));
1134 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1136 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1137 priv->preview_hidden_button,
1138 CLUTTER_BIN_ALIGNMENT_START,
1139 CLUTTER_BIN_ALIGNMENT_END);
1141 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1143 clutter_actor_hide (priv->preview_hidden_button);
1145 action = clutter_click_action_new ();
1146 clutter_actor_add_action (b, action);
1147 g_signal_connect (action, "clicked",
1148 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1150 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1151 priv->video_preview,
1152 CLUTTER_BIN_ALIGNMENT_START,
1153 CLUTTER_BIN_ALIGNMENT_END);
1155 empathy_call_window_move_video_preview (self, pos);
1157 action = clutter_drag_action_new ();
1158 g_signal_connect (action, "drag-begin",
1159 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1160 g_signal_connect (action, "drag-end",
1161 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1162 g_signal_connect (action, "drag-motion",
1163 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1165 g_signal_connect (preview, "enter-event",
1166 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1167 g_signal_connect (preview, "leave-event",
1168 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1170 clutter_actor_add_action (preview, action);
1171 clutter_actor_set_reactive (preview, TRUE);
1172 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1176 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1178 clutter_actor_show (self->priv->preview_spinner_actor);
1179 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1183 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1185 clutter_actor_hide (self->priv->preview_spinner_actor);
1186 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1190 empathy_call_window_play_camera (EmpathyCallWindow *self,
1193 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1194 GstElement *preview;
1197 if (priv->video_preview == NULL)
1199 create_video_preview (self);
1200 add_video_preview_to_pipeline (self);
1205 state = GST_STATE_PLAYING;
1209 empathy_call_window_start_camera_spinning (self);
1210 state = GST_STATE_NULL;
1213 preview = priv->video_preview_sink;
1215 gst_element_set_state (preview, state);
1216 gst_element_set_state (priv->video_tee, state);
1217 gst_element_set_state (priv->video_input, state);
1221 display_video_preview (EmpathyCallWindow *self,
1224 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1226 if (priv->video_preview == NULL)
1228 create_video_preview (self);
1229 add_video_preview_to_pipeline (self);
1234 /* Display the video preview */
1235 DEBUG ("Show video preview");
1237 empathy_call_window_play_camera (self, TRUE);
1238 clutter_actor_show (priv->video_preview);
1239 clutter_actor_raise_top (priv->floating_toolbar);
1243 /* Hide the video preview */
1244 DEBUG ("Hide video preview");
1246 if (priv->video_preview != NULL)
1248 clutter_actor_hide (priv->video_preview);
1249 empathy_call_window_play_camera (self, FALSE);
1255 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1259 empathy_call_window_status_message (window, _("Connecting…"));
1260 priv->call_state = CONNECTING;
1262 /* Show the toolbar */
1263 clutter_state_set_state (priv->transitions, "fade-in");
1266 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1267 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1271 disable_camera (EmpathyCallWindow *self)
1273 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1275 if (priv->camera_state == CAMERA_STATE_OFF)
1278 DEBUG ("Disable camera");
1280 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1282 priv->camera_state = CAMERA_STATE_OFF;
1286 enable_camera (EmpathyCallWindow *self)
1288 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1290 if (priv->camera_state == CAMERA_STATE_ON)
1293 if (priv->video_input == NULL)
1295 DEBUG ("Can't enable camera, no input");
1299 DEBUG ("Enable camera");
1301 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1303 priv->camera_state = CAMERA_STATE_ON;
1307 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1308 EmpathyCallWindow *self)
1310 if (gtk_toggle_button_get_active (toggle))
1311 enable_camera (self);
1313 disable_camera (self);
1317 create_pipeline (EmpathyCallWindow *self)
1319 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1322 g_assert (priv->pipeline == NULL);
1324 priv->pipeline = gst_pipeline_new (NULL);
1325 priv->pipeline_playing = FALSE;
1327 priv->video_tee = gst_element_factory_make ("tee", NULL);
1328 gst_object_ref_sink (priv->video_tee);
1330 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1332 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1333 priv->bus_message_source_id = gst_bus_add_watch (bus,
1334 empathy_call_window_bus_message, self);
1336 g_object_unref (bus);
1340 empathy_call_window_settings_cb (GtkAction *action,
1341 EmpathyCallWindow *self)
1343 gchar *args = g_strdup_printf ("-p %s",
1344 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1346 empathy_launch_program (BIN_DIR, "empathy", args);
1352 empathy_call_window_contents_cb (GtkAction *action,
1353 EmpathyCallWindow *self)
1355 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1359 show_png (GPid pid, gint status, gpointer user_data)
1361 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1362 g_spawn_close_pid (pid);
1367 empathy_call_window_debug_gst_cb (GtkAction *action,
1368 EmpathyCallWindow *self)
1370 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1371 GDateTime *date_time;
1373 const gchar *dot_dir;
1374 const gchar *prgname;
1380 if (priv->pipeline == NULL)
1381 DEBUG ("No pipeline");
1383 date_time = g_date_time_new_now_utc ();
1384 prgname = g_get_prgname ();
1385 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1386 g_date_time_to_unix (date_time));
1388 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1389 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1391 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1392 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1395 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1397 if (g_spawn_async (dot_dir,
1400 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1406 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1407 g_child_watch_add (dot_pid, show_png, uri);
1413 g_date_time_unref (date_time);
1417 empathy_call_window_debug_tp_cb (GtkAction *action,
1418 EmpathyCallWindow *self)
1420 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1424 empathy_call_window_about_cb (GtkAction *action,
1425 EmpathyCallWindow *self)
1427 empathy_about_dialog_new (GTK_WINDOW (self));
1431 empathy_call_window_toolbar_timeout (gpointer data)
1433 EmpathyCallWindow *self = data;
1435 /* We don't want to hide the toolbar if we're not in a call, as
1436 * to show the call status all the time. Also don't hide if we're muted
1437 * to prevent the awkward, talking when muted situation */
1438 if (self->priv->call_state != CONNECTING &&
1439 self->priv->call_state != DISCONNECTED &&
1441 clutter_state_set_state (self->priv->transitions, "fade-out");
1447 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1449 EmpathyCallWindow *self)
1451 clutter_state_set_state (self->priv->transitions, "fade-in");
1453 if (self->priv->inactivity_src > 0)
1454 g_source_remove (self->priv->inactivity_src);
1456 self->priv->inactivity_src = g_timeout_add_seconds (3,
1457 empathy_call_window_toolbar_timeout, self);
1463 empathy_call_window_configure_event_cb (GtkWidget *widget,
1465 EmpathyCallWindow *self)
1467 GdkWindow *gdk_window;
1468 GdkWindowState window_state;
1470 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1471 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1473 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1474 &self->priv->dialpad_width, NULL);
1476 gdk_window = gtk_widget_get_window (widget);
1477 window_state = gdk_window_get_state (gdk_window);
1478 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1484 empathy_call_window_destroyed_cb (GtkWidget *object,
1485 EmpathyCallWindow *self)
1487 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1489 /* Save the geometry as if the dialpad was hidden. */
1490 empathy_geometry_save_values (GTK_WINDOW (self),
1491 self->priv->x, self->priv->y,
1492 self->priv->w - self->priv->dialpad_width, self->priv->h,
1493 self->priv->maximized);
1498 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1500 EmpathyCallWindow *self)
1502 switch (response_id)
1504 case GTK_RESPONSE_ACCEPT:
1505 tp_channel_dispatch_operation_handle_with_async (
1506 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1508 tp_clear_object (&self->priv->pending_cdo);
1509 tp_clear_object (&self->priv->pending_channel);
1510 tp_clear_object (&self->priv->pending_context);
1513 case GTK_RESPONSE_CANCEL:
1514 tp_channel_dispatch_operation_close_channels_async (
1515 self->priv->pending_cdo, NULL, NULL);
1517 empathy_call_window_status_message (self, _("Disconnected"));
1518 self->priv->call_state = DISCONNECTED;
1521 g_warn_if_reached ();
1526 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1530 g_assert (self->priv->call_state != CONNECTED);
1532 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1534 empathy_call_window_status_message (self, _("Incoming call"));
1535 self->priv->call_state = RINGING;
1537 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1538 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1539 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1540 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1541 empathy_contact_get_alias (self->priv->contact));
1543 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1544 _("Reject"), GTK_RESPONSE_CANCEL,
1545 _("Answer"), GTK_RESPONSE_ACCEPT,
1548 g_signal_connect (self->priv->incoming_call_dialog, "response",
1549 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1550 gtk_widget_show (self->priv->incoming_call_dialog);
1554 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1558 EmpathyCallWindow *self)
1560 tp_clear_object (&self->priv->pending_cdo);
1561 tp_clear_object (&self->priv->pending_channel);
1562 tp_clear_object (&self->priv->pending_context);
1564 /* We don't know if the incoming call has been accepted or not, so we
1565 * assume it hasn't and if it has, we'll set the proper status when
1566 * we get the new handler. */
1567 empathy_call_window_status_message (self, _("Disconnected"));
1568 self->priv->call_state = DISCONNECTED;
1570 gtk_widget_destroy (self->priv->incoming_call_dialog);
1571 self->priv->incoming_call_dialog = NULL;
1575 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1576 TpCallChannel *channel,
1577 TpChannelDispatchOperation *dispatch_operation,
1578 TpAddDispatchOperationContext *context)
1580 g_assert (self->priv->pending_channel == NULL);
1581 g_assert (self->priv->pending_context == NULL);
1582 g_assert (self->priv->pending_cdo == NULL);
1584 /* Start ringing and delay until the user answers or hangs. */
1585 self->priv->pending_channel = g_object_ref (channel);
1586 self->priv->pending_context = g_object_ref (context);
1587 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1589 g_signal_connect (self->priv->pending_cdo, "invalidated",
1590 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1592 empathy_call_window_set_state_ringing (self);
1593 tp_add_dispatch_operation_context_accept (context);
1597 mic_button_clicked (GtkWidget *button,
1598 EmpathyCallWindow *self)
1600 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1602 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1603 !self->priv->muted);
1607 empathy_call_window_init (EmpathyCallWindow *self)
1609 EmpathyCallWindowPriv *priv;
1611 GtkWidget *top_vbox;
1613 ClutterConstraint *constraint;
1614 ClutterActor *remote_avatar;
1615 ClutterColor black = { 0, 0, 0, 0 };
1616 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1617 OVERLAY_MARGIN, OVERLAY_MARGIN };
1619 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1620 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1622 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1623 priv->timer = g_timer_new ();
1625 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1626 gui = tpaw_builder_get_file (filename,
1627 "call_window_vbox", &top_vbox,
1628 "errors_vbox", &priv->errors_vbox,
1629 "pane", &priv->pane,
1630 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1631 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1632 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1633 "status_label", &priv->status_label,
1634 "audiocall", &priv->audio_call_button,
1635 "videocall", &priv->video_call_button,
1636 "microphone", &priv->mic_button,
1637 "microphone_icon", &priv->microphone_icon,
1638 "volume", &priv->volume_button,
1639 "camera", &priv->camera_button,
1640 "hangup", &priv->hangup_button,
1641 "dialpad", &priv->dialpad_button,
1642 "toolbar", &priv->toolbar,
1643 "bottom_toolbar", &priv->bottom_toolbar,
1644 "ui_manager", &priv->ui_manager,
1645 "menufullscreen", &priv->menu_fullscreen,
1646 "menupreviewswap", &priv->menu_swap_camera,
1647 "details_vbox", &priv->details_vbox,
1648 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1649 "acodec_encoding_label", &priv->acodec_encoding_label,
1650 "acodec_decoding_label", &priv->acodec_decoding_label,
1651 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1652 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1653 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1654 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1655 "video_local_candidate_label", &priv->video_local_candidate_label,
1656 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1657 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1658 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1659 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1663 tpaw_builder_connect (gui, self,
1664 "hangup", "clicked", empathy_call_window_hangup_cb,
1665 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1666 "videocall", "clicked", empathy_call_window_video_call_cb,
1667 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1668 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1669 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1670 "menusettings", "activate", empathy_call_window_settings_cb,
1671 "menucontents", "activate", empathy_call_window_contents_cb,
1672 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1673 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1674 "menuabout", "activate", empathy_call_window_about_cb,
1675 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1676 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1677 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1678 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1681 empathy_set_css_provider (GTK_WIDGET (self));
1682 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1684 priv->camera_monitor = tpaw_camera_monitor_dup_singleton ();
1686 g_object_bind_property (priv->camera_monitor, "available",
1687 priv->camera_button, "sensitive",
1688 G_BINDING_SYNC_CREATE);
1690 g_signal_connect (priv->camera_monitor, "added",
1691 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1692 g_signal_connect (priv->camera_monitor, "removed",
1693 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1695 g_signal_connect (priv->mic_button, "clicked",
1696 G_CALLBACK (mic_button_clicked), self);
1698 g_mutex_init (&priv->lock);
1700 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1702 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1703 CONTENT_HBOX_SPACING);
1704 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1707 /* main contents remote avatar/video box */
1708 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1709 CLUTTER_BIN_ALIGNMENT_FILL);
1711 priv->video_box = clutter_box_new (priv->video_layout);
1713 priv->video_container = gtk_clutter_embed_new ();
1715 gtk_widget_set_size_request (priv->video_container,
1716 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1718 /* Set the background black */
1719 clutter_stage_set_color (
1720 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1721 GTK_CLUTTER_EMBED (priv->video_container))),
1724 clutter_container_add (
1725 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1726 GTK_CLUTTER_EMBED (priv->video_container))),
1730 constraint = clutter_bind_constraint_new (
1731 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1732 CLUTTER_BIND_SIZE, 0);
1733 clutter_actor_add_constraint (priv->video_box, constraint);
1735 priv->remote_user_avatar_widget = gtk_image_new ();
1736 remote_avatar = gtk_clutter_actor_new_with_contents (
1737 priv->remote_user_avatar_widget);
1738 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1740 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1743 /* create the overlay bin */
1744 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1745 CLUTTER_BIN_ALIGNMENT_CENTER);
1746 priv->overlay_bin = clutter_actor_new ();
1747 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1749 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1751 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1753 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1755 empathy_call_window_create_preview_rectangles (self);
1757 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1758 priv->video_container, TRUE, TRUE,
1759 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1761 create_pipeline (self);
1762 create_video_output_widget (self);
1763 create_audio_input (self);
1764 create_video_input (self);
1766 priv->floating_toolbar = gtk_clutter_actor_new ();
1767 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1768 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1770 gtk_style_context_add_class (
1771 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1772 GTK_STYLE_CLASS_OSD);
1773 gtk_widget_reparent (priv->bottom_toolbar,
1774 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1776 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1777 priv->floating_toolbar,
1778 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1780 clutter_actor_raise_top (priv->floating_toolbar);
1782 /* Transitions for the floating toolbar */
1783 priv->transitions = clutter_state_new ();
1785 /* all transitions last for 2s */
1786 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1788 /* transition from any state to "fade-out" state */
1789 clutter_state_set (priv->transitions, NULL, "fade-out",
1790 priv->floating_toolbar,
1791 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1794 /* transition from any state to "fade-in" state */
1795 clutter_state_set (priv->transitions, NULL, "fade-in",
1796 priv->floating_toolbar,
1797 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1800 /* put the actor into the "fade-in" state with no animation */
1801 clutter_state_warp_to_state (priv->transitions, "fade-in");
1803 /* The call will be started as soon the pipeline is playing */
1804 priv->start_call_when_playing = TRUE;
1806 priv->dtmf_panel = empathy_dialpad_widget_new ();
1807 g_signal_connect (priv->dtmf_panel, "start-tone",
1808 G_CALLBACK (dtmf_start_tone_cb), self);
1810 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1813 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1816 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1818 gtk_widget_show_all (top_vbox);
1820 gtk_widget_hide (priv->dtmf_panel);
1821 gtk_widget_hide (priv->details_vbox);
1823 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1825 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1826 priv->video_container);
1828 /* We hide the bottom toolbar after 3s of inactivity and show it
1829 * again on mouse movement */
1830 priv->inactivity_src = g_timeout_add_seconds (3,
1831 empathy_call_window_toolbar_timeout, self);
1833 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1834 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1836 g_signal_connect (G_OBJECT (self), "realize",
1837 G_CALLBACK (empathy_call_window_realized_cb), self);
1839 g_signal_connect (G_OBJECT (self), "delete-event",
1840 G_CALLBACK (empathy_call_window_delete_cb), self);
1842 g_signal_connect (G_OBJECT (self), "window-state-event",
1843 G_CALLBACK (empathy_call_window_state_event_cb), self);
1845 g_signal_connect (G_OBJECT (self), "key-press-event",
1846 G_CALLBACK (empathy_call_window_key_press_cb), self);
1848 g_signal_connect (self, "motion-notify-event",
1849 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1851 g_object_ref (priv->ui_manager);
1852 g_object_unref (gui);
1854 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1855 priv->mic_menu = empathy_mic_menu_new (self);
1856 priv->camera_menu = empathy_camera_menu_new (self);
1858 empathy_call_window_show_hangup_button (self, TRUE);
1860 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1862 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1863 /* These signals are used to track the window position and save it
1864 * when the window is destroyed. We need to do this as we don't want
1865 * the window geometry to be saved with the dialpad taken into account. */
1866 g_signal_connect (self, "destroy",
1867 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1868 g_signal_connect (self, "configure-event",
1869 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1870 g_signal_connect (self, "window-state-event",
1871 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1873 /* Don't display labels in both toolbars */
1874 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1877 /* Instead of specifying a width and a height, we specify only one size. That's
1878 because we want a square avatar icon. */
1880 init_contact_avatar_with_size (EmpathyContact *contact,
1881 GtkWidget *image_widget,
1884 GdkPixbuf *pixbuf_avatar = NULL;
1886 if (contact != NULL)
1888 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1892 if (pixbuf_avatar == NULL)
1894 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1895 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1898 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1900 if (pixbuf_avatar != NULL)
1901 g_object_unref (pixbuf_avatar);
1905 set_window_title (EmpathyCallWindow *self)
1907 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1910 if (priv->contact != NULL)
1912 /* translators: Call is a noun and %s is the contact name. This string
1913 * is used in the window title */
1914 tmp = g_strdup_printf (_("Call with %s"),
1915 empathy_contact_get_alias (priv->contact));
1916 gtk_window_set_title (GTK_WINDOW (self), tmp);
1921 g_warning ("Unknown remote contact!");
1926 set_remote_user_name (EmpathyCallWindow *self,
1927 EmpathyContact *contact)
1929 const gchar *alias = empathy_contact_get_alias (contact);
1930 const gchar *status = empathy_contact_get_status (contact);
1932 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1934 if (status != NULL) {
1937 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1938 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1942 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1948 contact_name_changed_cb (EmpathyContact *contact,
1950 EmpathyCallWindow *self)
1952 set_window_title (self);
1953 set_remote_user_name (self, contact);
1957 contact_presence_changed_cb (EmpathyContact *contact,
1959 EmpathyCallWindow *self)
1961 set_remote_user_name (self, contact);
1965 contact_avatar_changed_cb (EmpathyContact *contact,
1967 EmpathyCallWindow *self)
1970 GtkAllocation allocation;
1971 GtkWidget *avatar_widget;
1973 avatar_widget = self->priv->remote_user_avatar_widget;
1975 gtk_widget_get_allocation (avatar_widget, &allocation);
1976 size = allocation.height;
1980 /* the widget is not allocated yet, set a default size */
1981 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1982 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1985 init_contact_avatar_with_size (contact, avatar_widget, size);
1987 avatar_widget = self->priv->remote_user_avatar_toolbar;
1989 gtk_widget_get_allocation (avatar_widget, &allocation);
1990 size = allocation.height;
1994 /* the widget is not allocated yet, set a default size */
1995 size = SMALL_TOOLBAR_SIZE;
1998 init_contact_avatar_with_size (contact, avatar_widget, size);
2002 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2003 EmpathyCallHandler *handler)
2005 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2007 tp_g_signal_connect_object (priv->contact, "notify::name",
2008 G_CALLBACK (contact_name_changed_cb), self, 0);
2009 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2010 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2011 tp_g_signal_connect_object (priv->contact, "notify::presence",
2012 G_CALLBACK (contact_presence_changed_cb), self, 0);
2014 set_window_title (self);
2015 set_remote_user_name (self, priv->contact);
2017 init_contact_avatar_with_size (priv->contact,
2018 priv->remote_user_avatar_widget,
2019 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2020 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2022 init_contact_avatar_with_size (priv->contact,
2023 priv->remote_user_avatar_toolbar,
2024 SMALL_TOOLBAR_SIZE);
2026 /* The remote avatar is shown by default and will be hidden when we receive
2027 video from the remote side. */
2028 clutter_actor_hide (priv->video_output);
2029 gtk_widget_show (priv->remote_user_avatar_widget);
2033 update_send_codec (EmpathyCallWindow *self,
2036 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2043 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2044 widget = priv->acodec_encoding_label;
2048 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2049 widget = priv->vcodec_encoding_label;
2055 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2056 gtk_label_set_text (GTK_LABEL (widget), tmp);
2061 send_audio_codec_notify_cb (GObject *object,
2065 EmpathyCallWindow *self = user_data;
2067 update_send_codec (self, TRUE);
2071 send_video_codec_notify_cb (GObject *object,
2075 EmpathyCallWindow *self = user_data;
2077 update_send_codec (self, FALSE);
2081 update_recv_codec (EmpathyCallWindow *self,
2084 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2087 GString *str = NULL;
2091 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2092 widget = priv->acodec_decoding_label;
2096 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2097 widget = priv->vcodec_decoding_label;
2103 for (l = codecs; l != NULL; l = g_list_next (l))
2105 FsCodec *codec = l->data;
2108 str = g_string_new (NULL);
2110 g_string_append (str, ", ");
2112 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2116 gtk_label_set_text (GTK_LABEL (widget), str->str);
2117 g_string_free (str, TRUE);
2121 recv_audio_codecs_notify_cb (GObject *object,
2125 EmpathyCallWindow *self = user_data;
2127 update_recv_codec (self, TRUE);
2131 recv_video_codecs_notify_cb (GObject *object,
2135 EmpathyCallWindow *self = user_data;
2137 update_recv_codec (self, FALSE);
2140 static const gchar *
2141 candidate_type_to_str (FsCandidate *candidate)
2143 switch (candidate->type)
2145 case FS_CANDIDATE_TYPE_HOST:
2147 case FS_CANDIDATE_TYPE_SRFLX:
2148 return "server reflexive";
2149 case FS_CANDIDATE_TYPE_PRFLX:
2150 return "peer reflexive";
2151 case FS_CANDIDATE_TYPE_RELAY:
2153 case FS_CANDIDATE_TYPE_MULTICAST:
2160 static const gchar *
2161 candidate_type_to_desc (FsCandidate *candidate)
2163 switch (candidate->type)
2165 case FS_CANDIDATE_TYPE_HOST:
2166 return _("The IP address as seen by the machine");
2167 case FS_CANDIDATE_TYPE_SRFLX:
2168 return _("The IP address as seen by a server on the Internet");
2169 case FS_CANDIDATE_TYPE_PRFLX:
2170 return _("The IP address of the peer as seen by the other side");
2171 case FS_CANDIDATE_TYPE_RELAY:
2172 return _("The IP address of a relay server");
2173 case FS_CANDIDATE_TYPE_MULTICAST:
2174 return _("The IP address of the multicast group");
2181 update_candidat_widget (EmpathyCallWindow *self,
2184 FsCandidate *candidate)
2188 g_assert (candidate != NULL);
2189 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2190 candidate->port, candidate_type_to_str (candidate));
2192 gtk_label_set_text (GTK_LABEL (label), str);
2193 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2199 candidates_changed_cb (GObject *object,
2201 EmpathyCallWindow *self)
2203 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2204 FsCandidate *candidate = NULL;
2206 if (type == FS_MEDIA_TYPE_VIDEO)
2208 /* Update remote candidate */
2209 candidate = empathy_call_handler_get_video_remote_candidate (
2212 update_candidat_widget (self, priv->video_remote_candidate_label,
2213 priv->video_remote_candidate_info_img, candidate);
2215 /* Update local candidate */
2216 candidate = empathy_call_handler_get_video_local_candidate (
2219 update_candidat_widget (self, priv->video_local_candidate_label,
2220 priv->video_local_candidate_info_img, candidate);
2224 /* Update remote candidate */
2225 candidate = empathy_call_handler_get_audio_remote_candidate (
2228 update_candidat_widget (self, priv->audio_remote_candidate_label,
2229 priv->audio_remote_candidate_info_img, candidate);
2231 /* Update local candidate */
2232 candidate = empathy_call_handler_get_audio_local_candidate (
2235 update_candidat_widget (self, priv->audio_local_candidate_label,
2236 priv->audio_local_candidate_info_img, candidate);
2241 empathy_call_window_constructed (GObject *object)
2243 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2245 TpCallChannel *call;
2248 g_assert (priv->handler != NULL);
2250 g_object_get (priv->handler, "call-channel", &call, NULL);
2251 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2252 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2253 tp_clear_object (&call);
2255 priv->contact = empathy_call_handler_get_contact (priv->handler);
2256 g_assert (priv->contact != NULL);
2257 g_object_ref (priv->contact);
2259 if (!empathy_contact_can_voip_video (priv->contact))
2261 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2262 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2265 empathy_call_window_setup_avatars (self, priv->handler);
2266 empathy_call_window_set_state_connecting (self);
2268 if (!empathy_call_handler_has_initial_video (priv->handler))
2270 gtk_toggle_button_set_active (
2271 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2273 /* If call has InitialVideo, the preview will be started once the call has
2274 * been started (start_call()). */
2276 update_send_codec (self, TRUE);
2277 update_send_codec (self, FALSE);
2278 update_recv_codec (self, TRUE);
2279 update_recv_codec (self, FALSE);
2281 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2282 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2283 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2284 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2285 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2286 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2287 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2288 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2290 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2291 G_CALLBACK (candidates_changed_cb), self, 0);
2294 static void empathy_call_window_dispose (GObject *object);
2295 static void empathy_call_window_finalize (GObject *object);
2298 empathy_call_window_set_property (GObject *object,
2299 guint property_id, const GValue *value, GParamSpec *pspec)
2301 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2303 switch (property_id)
2305 case PROP_CALL_HANDLER:
2306 priv->handler = g_value_dup_object (value);
2309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2314 empathy_call_window_get_property (GObject *object,
2315 guint property_id, GValue *value, GParamSpec *pspec)
2317 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2319 switch (property_id)
2321 case PROP_CALL_HANDLER:
2322 g_value_set_object (value, priv->handler);
2325 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2330 empathy_call_window_class_init (
2331 EmpathyCallWindowClass *empathy_call_window_class)
2333 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2334 GParamSpec *param_spec;
2336 g_type_class_add_private (empathy_call_window_class,
2337 sizeof (EmpathyCallWindowPriv));
2339 object_class->constructed = empathy_call_window_constructed;
2340 object_class->set_property = empathy_call_window_set_property;
2341 object_class->get_property = empathy_call_window_get_property;
2343 object_class->dispose = empathy_call_window_dispose;
2344 object_class->finalize = empathy_call_window_finalize;
2346 param_spec = g_param_spec_object ("handler",
2347 "handler", "The call handler",
2348 EMPATHY_TYPE_CALL_HANDLER,
2349 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2350 g_object_class_install_property (object_class,
2351 PROP_CALL_HANDLER, param_spec);
2353 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2354 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2356 0, NULL, NULL, NULL,
2362 empathy_call_window_dispose (GObject *object)
2364 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2365 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2367 if (priv->dispose_has_run)
2370 priv->dispose_has_run = TRUE;
2372 if (priv->handler != NULL)
2374 empathy_call_handler_stop_call (priv->handler);
2375 tp_clear_object (&priv->handler);
2378 if (priv->bus_message_source_id != 0)
2380 g_source_remove (priv->bus_message_source_id);
2381 priv->bus_message_source_id = 0;
2384 if (priv->got_video_src > 0)
2386 g_source_remove (priv->got_video_src);
2387 priv->got_video_src = 0;
2390 if (priv->inactivity_src > 0)
2392 g_source_remove (priv->inactivity_src);
2393 priv->inactivity_src = 0;
2396 tp_clear_object (&priv->pipeline);
2397 tp_clear_object (&priv->video_input);
2398 tp_clear_object (&priv->audio_input);
2399 tp_clear_object (&priv->video_tee);
2400 tp_clear_object (&priv->ui_manager);
2401 tp_clear_object (&priv->fullscreen);
2402 tp_clear_object (&priv->camera_monitor);
2403 tp_clear_object (&priv->settings);
2404 tp_clear_object (&priv->sound_mgr);
2405 tp_clear_object (&priv->mic_menu);
2406 tp_clear_object (&priv->camera_menu);
2407 tp_clear_object (&priv->transitions);
2409 g_list_free_full (priv->notifiers, g_object_unref);
2411 if (priv->timer_id != 0)
2412 g_source_remove (priv->timer_id);
2415 tp_clear_object (&priv->contact);
2417 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2421 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2423 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2425 if (priv->video_output_motion_handler_id != 0)
2427 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2428 priv->video_output_motion_handler_id);
2429 priv->video_output_motion_handler_id = 0;
2434 empathy_call_window_finalize (GObject *object)
2436 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2437 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2439 disconnect_video_output_motion_handler (self);
2441 /* free any data held directly by the object here */
2442 g_mutex_clear (&priv->lock);
2444 g_timer_destroy (priv->timer);
2446 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2451 empathy_call_window_new (EmpathyCallHandler *handler)
2453 return EMPATHY_CALL_WINDOW (
2454 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2458 empathy_call_window_new_handler (EmpathyCallWindow *self,
2459 EmpathyCallHandler *handler,
2463 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2466 empathy_window_present_with_time (GTK_WINDOW (self), x11_time);
2468 if (self->priv->call_state == DISCONNECTED)
2470 /* start a new call if one is not already in progress */
2471 tp_clear_object (&self->priv->handler);
2472 self->priv->handler = g_object_ref (handler);
2473 empathy_call_window_connect_handler (self);
2475 empathy_call_window_restart_call (self);
2480 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2481 GstElement *conference, gpointer user_data)
2483 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2485 FsElementAddedNotifier *notifier;
2488 DEBUG ("Conference added");
2490 /* Add notifier to set the various element properties as needed */
2491 notifier = fs_element_added_notifier_new ();
2492 keyfile = fs_utils_get_default_element_properties (conference);
2494 if (keyfile != NULL)
2495 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2497 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2499 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2501 gst_bin_add (GST_BIN (priv->pipeline), conference);
2502 gst_element_set_state (conference, GST_STATE_PLAYING);
2506 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2507 GstElement *conference, gpointer user_data)
2509 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2512 g_list_free_full (priv->notifiers, g_object_unref);
2513 priv->notifiers = NULL;
2515 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2516 gst_element_set_state (conference, GST_STATE_NULL);
2520 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2522 GstStateChangeReturn state_change_return;
2523 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2525 if (priv->pipeline == NULL)
2528 if (priv->bus_message_source_id != 0)
2530 g_source_remove (priv->bus_message_source_id);
2531 priv->bus_message_source_id = 0;
2534 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2536 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2537 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2539 if (priv->pipeline != NULL)
2540 g_object_unref (priv->pipeline);
2541 priv->pipeline = NULL;
2543 if (priv->audio_output != NULL)
2544 g_object_unref (priv->audio_output);
2545 priv->audio_output = NULL;
2546 priv->audio_output_added = FALSE;
2548 if (priv->video_tee != NULL)
2549 g_object_unref (priv->video_tee);
2550 priv->video_tee = NULL;
2552 if (priv->video_preview != NULL)
2553 clutter_actor_destroy (priv->video_preview);
2554 priv->video_preview = NULL;
2556 /* If we destroy the preview while it's being dragged, we won't
2557 * get the ::drag-end signal, so manually destroy the clone */
2558 if (priv->drag_preview != NULL)
2560 clutter_actor_destroy (priv->drag_preview);
2561 empathy_call_window_show_preview_rectangles (self, FALSE);
2562 priv->drag_preview = NULL;
2565 priv->funnel = NULL;
2567 create_pipeline (self);
2568 /* Call will be started when user will hit the 'redial' button */
2569 priv->start_call_when_playing = FALSE;
2570 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2576 g_message ("Error: could not destroy pipeline. Closing call window");
2577 gtk_widget_destroy (GTK_WIDGET (self));
2584 reset_details_pane (EmpathyCallWindow *self)
2586 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2588 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2589 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2590 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2591 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2595 empathy_call_window_disconnected (EmpathyCallWindow *self,
2598 gboolean could_disconnect = FALSE;
2599 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2600 gboolean could_reset_pipeline;
2602 /* Leave full screen mode if needed */
2603 gtk_window_unfullscreen (GTK_WINDOW (self));
2605 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2607 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2608 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2610 /* Create the video input and then turn on the camera
2611 * menu, so that the active camera gets marked as such.
2613 if (priv->video_input == NULL)
2614 create_video_input (self);
2615 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2617 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2619 if (priv->call_state == CONNECTING)
2620 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2622 if (priv->call_state != REDIALING)
2623 priv->call_state = DISCONNECTED;
2625 /* Show the toolbar */
2626 clutter_state_set_state (priv->transitions, "fade-in");
2628 if (could_reset_pipeline)
2630 g_mutex_lock (&priv->lock);
2632 g_timer_stop (priv->timer);
2634 if (priv->timer_id != 0)
2635 g_source_remove (priv->timer_id);
2638 g_mutex_unlock (&priv->lock);
2641 /* We are about to destroy the window, no need to update it or create
2642 * a video preview */
2645 empathy_call_window_status_message (self, _("Disconnected"));
2647 empathy_call_window_show_hangup_button (self, FALSE);
2649 /* Unsensitive the camera and mic button */
2650 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2651 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2653 /* Be sure that the mic button is enabled */
2654 empathy_audio_src_set_mute (
2655 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2657 if (priv->camera_state == CAMERA_STATE_ON)
2659 /* Restart the preview with the new pipeline. */
2660 display_video_preview (self, TRUE);
2663 /* destroy the video output; it will be recreated when we'll redial */
2664 disconnect_video_output_motion_handler (self);
2665 if (priv->video_output != NULL)
2666 clutter_actor_destroy (priv->video_output);
2667 priv->video_output = NULL;
2668 if (priv->got_video_src > 0)
2670 g_source_remove (priv->got_video_src);
2671 priv->got_video_src = 0;
2674 gtk_widget_show (priv->remote_user_avatar_widget);
2676 reset_details_pane (self);
2678 priv->sending_video = FALSE;
2679 priv->call_started = FALSE;
2681 could_disconnect = TRUE;
2683 /* TODO: display the self avatar of the preview (depends if the "Always
2684 * Show Video Preview" is enabled or not) */
2687 return could_disconnect;
2692 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2695 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2696 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2698 if (empathy_call_window_disconnected (self, TRUE) &&
2699 priv->call_state == REDIALING)
2700 empathy_call_window_restart_call (self);
2704 empathy_call_window_content_is_raw (TfContent *content)
2706 FsConference *conference;
2709 g_object_get (content, "fs-conference", &conference, NULL);
2710 g_assert (conference != NULL);
2712 /* FIXME: Ugly hack, update when moving a packetization property into
2714 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2715 gst_object_unref (conference);
2721 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2723 EmpathyCallWindow *self)
2725 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2726 FsMediaType media_type;
2728 DEBUG ("removing content");
2730 g_object_get (content, "media-type", &media_type, NULL);
2733 * This assumes that there is only one video stream per channel...
2736 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2738 if (priv->funnel != NULL)
2742 output = priv->video_output_sink;
2744 gst_element_set_state (output, GST_STATE_NULL);
2745 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2747 gst_bin_remove (GST_BIN (priv->pipeline), output);
2748 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2749 priv->funnel = NULL;
2752 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2754 if (priv->audio_output != NULL)
2756 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2758 if (priv->audio_output_added)
2759 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2760 priv->audio_output = NULL;
2761 priv->audio_output_added = FALSE;
2766 g_assert_not_reached ();
2773 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2775 EmpathyCallWindow *self)
2777 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2779 DEBUG ("Framerate changed to %u", framerate);
2781 if (priv->video_input != NULL)
2782 empathy_video_src_set_framerate (priv->video_input, framerate);
2786 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2789 EmpathyCallWindow *self)
2791 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2793 DEBUG ("Resolution changed to %ux%u", width, height);
2795 if (priv->video_input != NULL)
2797 empathy_video_src_set_resolution (priv->video_input, width, height);
2801 /* Called with global lock held */
2803 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2805 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2809 if (priv->funnel == NULL)
2811 output = priv->video_output_sink;
2813 priv->funnel = gst_element_factory_make ("funnel", NULL);
2815 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2820 g_warning ("Could not create video funnel");
2824 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2826 gst_object_unref (priv->funnel);
2827 priv->funnel = NULL;
2828 g_warning ("Could not add funnel to pipeline");
2832 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2834 g_warning ("Could not add the video output widget to the pipeline");
2838 if (!gst_element_link (priv->funnel, output))
2840 g_warning ("Could not link output sink to funnel");
2841 goto error_output_added;
2844 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2846 g_warning ("Could not start video sink");
2847 goto error_output_added;
2850 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2852 g_warning ("Could not start funnel");
2853 goto error_output_added;
2857 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2859 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2863 g_warning ("Could not get request pad from funnel");
2870 gst_element_set_locked_state (priv->funnel, TRUE);
2871 gst_element_set_locked_state (output, TRUE);
2873 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2874 gst_element_set_state (output, GST_STATE_NULL);
2876 gst_bin_remove (GST_BIN (priv->pipeline), output);
2877 gst_element_set_locked_state (output, FALSE);
2881 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2882 priv->funnel = NULL;
2887 /* Called with global lock held */
2889 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2892 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2894 GstPadTemplate *template;
2896 if (!priv->audio_output_added)
2898 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2900 g_warning ("Could not add audio sink to pipeline");
2901 g_object_unref (priv->audio_output);
2902 goto error_add_output;
2905 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2907 g_warning ("Could not start audio sink");
2910 priv->audio_output_added = TRUE;
2913 template = gst_element_class_get_pad_template (
2914 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2916 pad = gst_element_request_pad (priv->audio_output,
2917 template, NULL, NULL);
2921 g_warning ("Could not get sink pad from sink");
2928 gst_element_set_locked_state (priv->audio_output, TRUE);
2929 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2930 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2931 priv->audio_output = NULL;
2939 empathy_call_window_update_timer (gpointer user_data)
2941 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2942 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2943 const gchar *status;
2947 time_ = g_timer_elapsed (priv->timer, NULL);
2949 if (priv->call_state == HELD)
2950 status = _("On hold");
2951 else if (priv->call_state == DISCONNECTED)
2952 status = _("Disconnected");
2953 else if (priv->muted)
2956 status = _("Duration");
2958 /* Translators: 'status - minutes:seconds' the caller has been connected */
2959 str = g_strdup_printf (_("%s — %d:%02dm"),
2961 (int) time_ / 60, (int) time_ % 60);
2962 empathy_call_window_status_message (self, str);
2970 EMP_RESPONSE_BALANCE
2974 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2978 switch (response_id)
2980 case GTK_RESPONSE_CLOSE:
2981 gtk_widget_destroy (GTK_WIDGET (info_bar));
2983 case EMP_RESPONSE_BALANCE:
2984 empathy_url_show (GTK_WIDGET (info_bar),
2985 g_object_get_data (G_OBJECT (info_bar), "uri"));
2991 display_error (EmpathyCallWindow *self,
2995 const gchar *details,
2996 const gchar *button_text,
2998 gint button_response)
3000 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3001 GtkWidget *info_bar;
3002 GtkWidget *content_area;
3009 /* Create info bar */
3010 info_bar = gtk_info_bar_new ();
3012 if (button_text != NULL)
3014 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3015 button_text, button_response);
3016 g_object_set_data_full (G_OBJECT (info_bar),
3017 "uri", g_strdup (uri), g_free);
3020 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3021 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3023 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3025 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3027 /* hbox containing the image and the messages vbox */
3028 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3029 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3032 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3033 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3035 /* vbox containing the main message and the details expander */
3036 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3037 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3040 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3042 label = gtk_label_new (NULL);
3043 gtk_label_set_markup (GTK_LABEL (label), txt);
3044 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3045 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3048 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3051 if (details != NULL)
3053 GtkWidget *expander;
3055 expander = gtk_expander_new (_("Technical Details"));
3057 txt = g_strdup_printf ("<i>%s</i>", details);
3059 label = gtk_label_new (NULL);
3060 gtk_label_set_markup (GTK_LABEL (label), txt);
3061 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3062 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3065 gtk_container_add (GTK_CONTAINER (expander), label);
3066 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3069 g_signal_connect (info_bar, "response",
3070 G_CALLBACK (on_error_infobar_response_cb), NULL);
3072 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3073 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3074 gtk_widget_show_all (info_bar);
3079 media_stream_error_to_txt (EmpathyCallWindow *self,
3080 TpCallChannel *call,
3082 TpMediaStreamError error)
3084 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3085 const gchar *cm = NULL;
3091 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3093 return g_strdup_printf (
3094 _("%s's software does not understand any of the audio formats "
3095 "supported by your computer"),
3096 empathy_contact_get_alias (priv->contact));
3098 return g_strdup_printf (
3099 _("%s's software does not understand any of the video formats "
3100 "supported by your computer"),
3101 empathy_contact_get_alias (priv->contact));
3103 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3104 return g_strdup_printf (
3105 _("Can't establish a connection to %s. "
3106 "One of you might be on a network that does not allow "
3107 "direct connections."),
3108 empathy_contact_get_alias (priv->contact));
3110 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3111 return g_strdup (_("There was a failure on the network"));
3113 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3115 return g_strdup (_("The audio formats necessary for this call "
3116 "are not installed on your computer"));
3118 return g_strdup (_("The video formats necessary for this call "
3119 "are not installed on your computer"));
3121 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3122 tp_connection_parse_object_path (
3123 tp_channel_get_connection (TP_CHANNEL (call)),
3126 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3127 "product=Telepathy&component=%s", cm);
3129 result = g_strdup_printf (
3130 _("Something unexpected happened in a Telepathy component. "
3131 "Please <a href=\"%s\">report this bug</a> and attach "
3132 "logs gathered from the 'Debug' window in the Help menu."), url);
3138 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3139 return g_strdup (_("There was a failure in the call engine"));
3141 case TP_MEDIA_STREAM_ERROR_EOS:
3142 return g_strdup (_("The end of the stream was reached"));
3144 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3151 empathy_call_window_stream_error (EmpathyCallWindow *self,
3152 TpCallChannel *call,
3161 desc = media_stream_error_to_txt (self, call, audio, code);
3164 /* No description, use the error message. That's not great as it's not
3165 * localized but it's better than nothing. */
3166 display_error (self, call, icon, title, msg, NULL);
3170 display_error (self, call, icon, title, desc, msg);
3176 empathy_call_window_audio_stream_error (TpCallChannel *call,
3179 EmpathyCallWindow *self)
3181 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3182 "gnome-stock-mic", _("Can't establish audio stream"));
3186 empathy_call_window_video_stream_error (TpCallChannel *call,
3189 EmpathyCallWindow *self)
3191 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3192 "camera-web", _("Can't establish video stream"));
3197 show_balance_error (EmpathyCallWindow *self)
3201 gchar *balance, *tmp;
3202 const gchar *uri, *currency;
3206 g_object_get (self->priv->handler,
3207 "call-channel", &call,
3210 conn = tp_channel_get_connection (call);
3211 g_object_unref (call);
3213 uri = tp_connection_get_balance_uri (conn);
3215 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3217 /* unknown balance */
3218 balance = g_strdup ("(--)");
3222 char *money = empathy_format_currency (amount, scale, currency);
3224 balance = g_strdup_printf ("%s %s",
3229 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3231 display_error (self,
3233 _("Sorry, you don’t have enough credit for that call."),
3237 EMP_RESPONSE_BALANCE);
3244 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3247 EmpathyCallWindow *self)
3249 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3250 TpCallChannel *call;
3251 gboolean can_send_video;
3253 if (state == TP_CALL_STATE_ENDED)
3255 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3256 empathy_call_window_disconnected (self, TRUE);
3257 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3258 show_balance_error (self);
3262 if (state != TP_CALL_STATE_ACCEPTED)
3265 if (priv->call_state == CONNECTED)
3268 g_timer_start (priv->timer);
3269 priv->call_state = CONNECTED;
3271 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3273 can_send_video = priv->video_input != NULL &&
3274 empathy_contact_can_voip_video (priv->contact) &&
3275 tpaw_camera_monitor_get_available (priv->camera_monitor);
3277 g_object_get (priv->handler, "call-channel", &call, NULL);
3279 if (tp_call_channel_has_dtmf (call))
3280 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3282 if (priv->video_input == NULL)
3283 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3285 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3287 empathy_call_window_show_hangup_button (self, TRUE);
3289 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3291 clutter_actor_hide (priv->video_output);
3292 gtk_widget_show (priv->remote_user_avatar_widget);
3294 g_object_unref (call);
3296 g_mutex_lock (&priv->lock);
3298 priv->timer_id = g_timeout_add_seconds (1,
3299 empathy_call_window_update_timer, self);
3301 g_mutex_unlock (&priv->lock);
3303 empathy_call_window_update_timer (self);
3305 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3309 empathy_call_window_show_video_output_cb (gpointer user_data)
3311 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3313 if (self->priv->video_output != NULL)
3315 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3316 clutter_actor_show (self->priv->video_output);
3317 clutter_actor_raise_top (self->priv->overlay_bin);
3324 empathy_call_window_check_video_cb (gpointer data)
3326 EmpathyCallWindow *self = data;
3328 if (self->priv->got_video)
3330 self->priv->got_video = FALSE;
3334 /* No video in the last N seconds, display the remote avatar */
3335 empathy_call_window_show_video_output (self, FALSE);
3340 /* Called from the streaming thread */
3342 static GstPadProbeReturn
3343 empathy_call_window_video_probe_cb (GstPad *pad,
3344 GstPadProbeInfo *info,
3347 EmpathyCallWindow *self = user_data;
3349 if (G_UNLIKELY (!self->priv->got_video))
3351 /* show the remote video */
3352 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3353 empathy_call_window_show_video_output_cb,
3354 g_object_ref (self), g_object_unref);
3356 self->priv->got_video = TRUE;
3359 return GST_PAD_PROBE_OK;
3363 empathy_call_window_video_probe_cb (GstPad *pad,
3364 GstMiniObject *mini_obj,
3365 EmpathyCallWindow *self)
3368 if (GST_IS_EVENT (mini_obj))
3371 if (G_UNLIKELY (!self->priv->got_video))
3373 /* show the remote video */
3374 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3375 empathy_call_window_show_video_output_cb,
3376 g_object_ref (self), g_object_unref);
3378 self->priv->got_video = TRUE;
3385 /* Called from the streaming thread */
3387 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3388 TfContent *content, GstPad *src, gpointer user_data)
3390 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3391 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3392 gboolean retval = FALSE;
3397 g_mutex_lock (&priv->lock);
3399 g_object_get (content, "media-type", &media_type, NULL);
3403 case TP_MEDIA_STREAM_TYPE_AUDIO:
3404 pad = empathy_call_window_get_audio_sink_pad (self, content);
3406 case TP_MEDIA_STREAM_TYPE_VIDEO:
3407 g_idle_add (empathy_call_window_show_video_output_cb, self);
3408 pad = empathy_call_window_get_video_sink_pad (self);
3411 gst_pad_add_probe (src,
3412 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3413 empathy_call_window_video_probe_cb, self, NULL);
3415 gst_pad_add_data_probe (src,
3416 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3418 if (priv->got_video_src > 0)
3419 g_source_remove (priv->got_video_src);
3420 priv->got_video_src = g_timeout_add_seconds (1,
3421 empathy_call_window_check_video_cb, self);
3424 g_assert_not_reached ();
3430 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3431 g_warning ("Could not link %s sink pad",
3432 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3436 gst_object_unref (pad);
3440 /* If no sink could be linked, try to add fakesink to prevent the whole call
3445 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3447 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3449 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3450 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3451 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3453 gst_element_set_locked_state (fakesink, TRUE);
3454 gst_element_set_state (fakesink, GST_STATE_NULL);
3455 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3459 DEBUG ("Could not link real sink, linked fakesink instead");
3461 gst_object_unref (sinkpad);
3465 gst_object_unref (fakesink);
3470 g_mutex_unlock (&priv->lock);
3476 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3479 EmpathyCallWindowPriv *priv = self->priv;
3481 g_assert (priv->audio_output_added == FALSE);
3482 g_assert (priv->audio_output == FALSE);
3484 priv->audio_output = empathy_audio_sink_new ();
3485 g_object_ref_sink (priv->audio_output);
3487 /* volume button to output volume linking */
3488 g_object_bind_property (priv->audio_output, "volume",
3489 priv->volume_button, "value",
3490 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3492 g_object_bind_property_full (content, "requested-output-volume",
3493 priv->audio_output, "volume",
3495 audio_control_volume_to_element,
3496 element_volume_to_audio_control,
3499 /* Link volumes together, sync the current audio input volume property
3500 * back to farstream first */
3501 g_object_bind_property_full (priv->audio_output, "volume",
3502 content, "reported-output-volume",
3503 G_BINDING_SYNC_CREATE,
3504 element_volume_to_audio_control,
3505 audio_control_volume_to_element,
3508 /* For raw audio conferences assume that the producer of the raw data
3509 * has already processed it, so turn off any echo cancellation and any
3510 * other audio improvements that come with it */
3511 empathy_audio_sink_set_echo_cancel (
3512 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3513 !empathy_call_window_content_is_raw (content));
3518 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3519 TfContent *content, gpointer user_data)
3521 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3524 FsMediaType media_type;
3525 gboolean retval = FALSE;
3527 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3528 g_assert (sink != NULL);
3532 case FS_MEDIA_TYPE_AUDIO:
3534 /* For raw audio conferences assume that the receiver of the raw data
3535 * wants it unprocessed, so turn off any echo cancellation and any
3536 * other audio improvements that come with it */
3537 empathy_audio_src_set_echo_cancel (
3538 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3539 !empathy_call_window_content_is_raw (content));
3541 /* Link volumes together, sync the current audio input volume property
3542 * back to farstream first */
3543 g_object_bind_property_full (content, "requested-input-volume",
3544 priv->audio_input, "volume",
3546 audio_control_volume_to_element,
3547 element_volume_to_audio_control,
3550 g_object_bind_property_full (priv->audio_input, "volume",
3551 content, "reported-input-volume",
3552 G_BINDING_SYNC_CREATE,
3553 element_volume_to_audio_control,
3554 audio_control_volume_to_element,
3557 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3559 g_warning ("Could not add audio source to pipeline");
3563 pad = gst_element_get_static_pad (priv->audio_input, "src");
3566 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3567 g_warning ("Could not get source pad from audio source");
3571 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3573 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3574 gst_object_unref (pad);
3575 g_warning ("Could not link audio source to farsight");
3578 gst_object_unref (pad);
3580 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3582 g_warning ("Could not start audio source");
3583 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3584 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3588 /* Prepare our audio output, not added yet though */
3589 empathy_call_window_prepare_audio_output (self, content);
3593 case FS_MEDIA_TYPE_VIDEO:
3594 if (priv->video_tee != NULL)
3597 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3599 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3601 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3603 g_warning ("Could not link video source input pipeline");
3606 gst_object_unref (pad);
3612 g_assert_not_reached ();
3615 gst_object_unref (sink);
3620 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3622 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3623 GstElement *preview;
3625 disable_camera (self);
3627 DEBUG ("remove video input");
3628 preview = priv->video_preview_sink;
3630 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3631 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3632 gst_element_set_state (preview, GST_STATE_NULL);
3634 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3637 g_object_unref (priv->video_input);
3638 priv->video_input = NULL;
3639 g_object_unref (priv->video_tee);
3640 priv->video_tee = NULL;
3641 clutter_actor_destroy (priv->video_preview);
3642 priv->video_preview = NULL;
3644 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3645 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3649 start_call (EmpathyCallWindow *self)
3651 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3653 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3655 priv->call_started = TRUE;
3656 empathy_call_handler_start_call (priv->handler,
3657 gtk_get_current_event_time ());
3659 if (empathy_call_handler_has_initial_video (priv->handler))
3661 TpCallChannel *call;
3664 g_object_get (priv->handler, "call-channel", &call, NULL);
3665 /* If the call channel isn't set yet we're requesting it, if we're
3666 * requesting it with initial video it should be PENDING_SEND when we get
3669 s = TP_SENDING_STATE_PENDING_SEND;
3671 s = empathy_call_channel_get_video_state (call);
3673 if (s == TP_SENDING_STATE_PENDING_SEND ||
3674 s == TP_SENDING_STATE_SENDING)
3676 /* Enable 'send video' buttons and display the preview */
3677 gtk_toggle_button_set_active (
3678 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3682 gtk_toggle_button_set_active (
3683 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3685 if (priv->video_preview == NULL)
3687 create_video_preview (self);
3688 add_video_preview_to_pipeline (self);
3693 g_object_unref (call);
3698 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3701 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3702 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3703 GstState newstate, pending;
3705 empathy_call_handler_bus_message (priv->handler, bus, message);
3707 switch (GST_MESSAGE_TYPE (message))
3709 case GST_MESSAGE_STATE_CHANGED:
3710 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3712 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3714 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3715 !priv->call_started)
3717 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3718 if (newstate == GST_STATE_PAUSED)
3720 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3721 priv->pipeline_playing = TRUE;
3723 if (priv->start_call_when_playing)
3727 if (priv->video_preview_sink != NULL &&
3728 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3730 gst_message_parse_state_changed (message, NULL, &newstate,
3733 if (newstate == GST_STATE_PLAYING &&
3734 pending == GST_STATE_VOID_PENDING)
3735 empathy_call_window_stop_camera_spinning (self);
3738 case GST_MESSAGE_ERROR:
3740 GError *error = NULL;
3741 GstElement *gst_error;
3745 gst_message_parse_error (message, &error, &debug);
3746 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3748 g_message ("Element error: %s -- %s\n", error->message, debug);
3750 name = gst_element_get_name (gst_error);
3751 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3753 /* Remove the video input and continue */
3754 if (priv->video_input != NULL)
3755 empathy_call_window_remove_video_input (self);
3756 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3760 empathy_call_window_disconnected (self, TRUE);
3763 g_error_free (error);
3766 case GST_MESSAGE_UNKNOWN:
3767 case GST_MESSAGE_EOS:
3768 case GST_MESSAGE_WARNING:
3769 case GST_MESSAGE_INFO:
3770 case GST_MESSAGE_TAG:
3771 case GST_MESSAGE_BUFFERING:
3772 case GST_MESSAGE_STATE_DIRTY:
3773 case GST_MESSAGE_STEP_DONE:
3774 case GST_MESSAGE_CLOCK_PROVIDE:
3775 case GST_MESSAGE_CLOCK_LOST:
3776 case GST_MESSAGE_NEW_CLOCK:
3777 case GST_MESSAGE_STRUCTURE_CHANGE:
3778 case GST_MESSAGE_STREAM_STATUS:
3779 case GST_MESSAGE_APPLICATION:
3780 case GST_MESSAGE_ELEMENT:
3781 case GST_MESSAGE_SEGMENT_START:
3782 case GST_MESSAGE_SEGMENT_DONE:
3783 case GST_MESSAGE_DURATION:
3784 case GST_MESSAGE_ANY:
3793 empathy_call_window_members_changed_cb (TpCallChannel *call,
3794 GHashTable *updates,
3796 TpCallStateReason *reason,
3797 EmpathyCallWindow *self)
3799 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3800 GHashTableIter iter;
3801 gpointer key, value;
3802 gboolean held = FALSE;
3804 g_hash_table_iter_init (&iter, updates);
3805 while (g_hash_table_iter_next (&iter, &key, &value))
3807 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3809 /* This assumes this is a 1-1 call, otherwise one participant
3810 * putting the call on hold wouldn't mean the call is on hold
3818 priv->call_state = HELD;
3819 else if (priv->call_state == HELD)
3820 priv->call_state = CONNECTED;
3824 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3826 EmpathyCallWindow *self)
3828 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3829 TpCallChannel *call;
3831 g_object_get (priv->handler, "call-channel", &call, NULL);
3836 tp_g_signal_connect_object (call, "audio-stream-error",
3837 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3838 tp_g_signal_connect_object (call, "video-stream-error",
3839 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3842 tp_g_signal_connect_object (call, "members-changed",
3843 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3845 g_object_unref (call);
3849 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3851 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3852 TpCallChannel *call;
3854 g_signal_connect (priv->handler, "state-changed",
3855 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3856 g_signal_connect (priv->handler, "conference-added",
3857 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3858 g_signal_connect (priv->handler, "conference-removed",
3859 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3860 g_signal_connect (priv->handler, "closed",
3861 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3862 g_signal_connect (priv->handler, "src-pad-added",
3863 G_CALLBACK (empathy_call_window_src_added_cb), self);
3864 g_signal_connect (priv->handler, "content-added",
3865 G_CALLBACK (empathy_call_window_content_added_cb), self);
3866 g_signal_connect (priv->handler, "content-removed",
3867 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3869 /* We connect to ::call-channel unconditionally since we'll
3870 * get new channels if we hangup and redial or if we reuse the
3872 g_signal_connect (priv->handler, "notify::call-channel",
3873 G_CALLBACK (call_handler_notify_call_cb), self);
3875 g_signal_connect (priv->handler, "framerate-changed",
3876 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3877 g_signal_connect (priv->handler, "resolution-changed",
3878 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3880 g_object_get (priv->handler, "call-channel", &call, NULL);
3883 /* We won't get notify::call-channel for this channel, so
3884 * directly call the callback. */
3885 call_handler_notify_call_cb (priv->handler, NULL, self);
3886 g_object_unref (call);
3891 empathy_call_window_realized_cb (GtkWidget *widget,
3892 EmpathyCallWindow *self)
3896 /* Make the hangup button twice as wide */
3897 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3898 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3900 empathy_call_window_connect_handler (self);
3902 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3906 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3907 EmpathyCallWindow *window)
3909 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3911 if (priv->pipeline != NULL)
3913 if (priv->bus_message_source_id != 0)
3915 g_source_remove (priv->bus_message_source_id);
3916 priv->bus_message_source_id = 0;
3919 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3922 if (priv->call_state == CONNECTING)
3923 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3929 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3932 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3934 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3939 gtk_widget_hide (priv->dtmf_panel);
3940 gtk_widget_hide (menu);
3941 gtk_widget_hide (priv->toolbar);
3945 if (priv->dialpad_was_visible_before_fs)
3946 gtk_widget_show (priv->dtmf_panel);
3948 gtk_widget_show (menu);
3949 gtk_widget_show (priv->toolbar);
3951 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3952 priv->original_height_before_fs);
3957 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3959 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3961 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3962 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3964 if (priv->video_output != NULL)
3967 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3968 priv->video_output, TRUE, TRUE,
3969 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3976 empathy_call_window_state_event_cb (GtkWidget *widget,
3977 GdkEventWindowState *event, EmpathyCallWindow *window)
3979 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3981 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3982 gboolean set_fullscreen = event->new_window_state &
3983 GDK_WINDOW_STATE_FULLSCREEN;
3987 gboolean dialpad_was_visible;
3988 GtkAllocation allocation;
3989 gint original_width, original_height;
3991 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3992 original_width = allocation.width;
3993 original_height = allocation.height;
3995 g_object_get (priv->dtmf_panel,
3996 "visible", &dialpad_was_visible,
3999 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4000 priv->original_width_before_fs = original_width;
4001 priv->original_height_before_fs = original_height;
4003 if (priv->video_output_motion_handler_id == 0 &&
4004 priv->video_output != NULL)
4006 priv->video_output_motion_handler_id = g_signal_connect (
4007 G_OBJECT (priv->video_container), "motion-notify-event",
4008 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4014 disconnect_video_output_motion_handler (window);
4017 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4019 show_controls (window, set_fullscreen);
4020 show_borders (window, set_fullscreen);
4021 gtk_action_set_stock_id (priv->menu_fullscreen,
4022 (set_fullscreen ? "view-restore" : "view-fullscreen"));
4023 priv->is_fullscreen = set_fullscreen;
4030 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4033 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4034 int w, h, dialpad_width;
4035 GtkAllocation allocation;
4037 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4038 w = allocation.width;
4039 h = allocation.height;
4041 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4045 gtk_widget_show (priv->dtmf_panel);
4051 gtk_widget_hide (priv->dtmf_panel);
4055 gtk_window_resize (GTK_WINDOW (window), w, h);
4059 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4062 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4063 TpCallChannel *call;
4065 priv->sending_video = (state == CAMERA_STATE_ON);
4067 if (state == CAMERA_STATE_ON)
4069 /* When we start sending video, we want to show the video preview by
4071 display_video_preview (window, TRUE);
4075 display_video_preview (window, FALSE);
4078 if (priv->call_state != CONNECTED)
4081 g_object_get (priv->handler, "call-channel", &call, NULL);
4082 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4083 empathy_call_channel_send_video (call, priv->sending_video);
4084 g_object_unref (call);
4088 empathy_call_window_hangup_cb (gpointer object,
4089 EmpathyCallWindow *self)
4091 /* stopping the call will put it the ENDED state and
4092 * from state_changed_cb we'll reconfigure the window
4094 empathy_call_handler_stop_call (self->priv->handler);
4098 empathy_call_window_restart_call (EmpathyCallWindow *window)
4100 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4102 /* Remove error info bars */
4103 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4104 (GtkCallback) gtk_widget_destroy, NULL);
4106 create_video_output_widget (window);
4107 priv->outgoing = TRUE;
4108 empathy_call_window_set_state_connecting (window);
4110 if (priv->pipeline_playing)
4111 start_call (window);
4113 /* call will be started when the pipeline is ready */
4114 priv->start_call_when_playing = TRUE;
4116 empathy_call_window_setup_avatars (window, priv->handler);
4118 empathy_call_window_show_hangup_button (window, TRUE);
4122 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4123 EmpathyCallWindow *window)
4127 active = gtk_toggle_tool_button_get_active (button);
4129 empathy_call_window_show_dialpad (window, active);
4133 empathy_call_window_fullscreen_cb (gpointer object,
4134 EmpathyCallWindow *window)
4136 empathy_call_window_fullscreen_toggle (window);
4140 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4142 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4144 if (priv->is_fullscreen)
4145 gtk_window_unfullscreen (GTK_WINDOW (window));
4147 gtk_window_fullscreen (GTK_WINDOW (window));
4151 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4152 GdkEventButton *event, EmpathyCallWindow *window)
4154 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4156 empathy_call_window_video_menu_popup (window, event->button);
4164 empathy_call_window_key_press_cb (GtkWidget *video_output,
4165 GdkEventKey *event, EmpathyCallWindow *window)
4167 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4170 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4172 /* Since we are in fullscreen mode, toggling will bring us back to
4174 empathy_call_window_fullscreen_toggle (window);
4178 key = gdk_keyval_to_unicode (event->keyval);
4199 gtk_toggle_tool_button_set_active (
4200 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4202 empathy_dialpad_widget_press_key (
4203 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4209 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4210 GdkEventMotion *event, EmpathyCallWindow *window)
4212 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4214 if (priv->is_fullscreen)
4216 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4218 /* Show the bottom toolbar */
4219 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4226 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4230 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4232 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4234 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4235 button, gtk_get_current_event_time ());
4236 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4240 empathy_call_window_status_message (EmpathyCallWindow *self,
4243 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4247 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4249 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4251 return priv->ui_manager;
4254 EmpathyGstAudioSrc *
4255 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4259 return (EmpathyGstAudioSrc *) priv->audio_input;
4262 EmpathyGstVideoSrc *
4263 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4265 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4269 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4270 const gchar *device)
4272 EmpathyGstVideoSrc *video;
4275 /* Restart the camera only if it's already running */
4276 running = (self->priv->video_preview != NULL);
4277 video = empathy_call_window_get_video_src (self);
4280 empathy_call_window_play_camera (self, FALSE);
4282 empathy_video_src_change_device (video, device);
4285 empathy_call_window_play_camera (self, TRUE);