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
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/telepathy-glib.h>
40 #include <farstream/fs-element-added-notifier.h>
41 #include <farstream/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-request-util.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-dialpad-widget.h>
50 #include <libempathy-gtk/empathy-ui-utils.h>
51 #include <libempathy-gtk/empathy-sound-manager.h>
52 #include <libempathy-gtk/empathy-geometry.h>
53 #include <libempathy-gtk/empathy-images.h>
54 #include <libempathy-gtk/empathy-call-utils.h>
56 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
57 #include <libempathy/empathy-debug.h>
59 #include "empathy-call-window.h"
60 #include "empathy-call-window-fullscreen.h"
61 #include "empathy-call-factory.h"
62 #include "empathy-about-dialog.h"
63 #include "empathy-audio-src.h"
64 #include "empathy-audio-sink.h"
65 #include "empathy-video-src.h"
66 #include "empathy-mic-menu.h"
67 #include "empathy-preferences.h"
68 #include "empathy-rounded-actor.h"
69 #include "empathy-rounded-rectangle.h"
70 #include "empathy-rounded-texture.h"
71 #include "empathy-camera-menu.h"
73 #define CONTENT_HBOX_SPACING 3
74 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
75 #define OVERLAY_MARGIN 6
77 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
78 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 /* The avatar's default width and height are set to the same value because we
86 want a square icon. */
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 /* The roundedness of preview box and placeholders */
99 #define PREVIEW_ROUND_FACTOR 16
101 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
104 PROP_CALL_HANDLER = 1,
112 static guint signals[LAST_SIGNAL];
115 RINGING, /* Incoming call */
116 CONNECTING, /* Outgoing call */
117 CONNECTED, /* Connected */
118 HELD, /* Connected, but on hold */
119 DISCONNECTED, /* Disconnected */
120 REDIALING /* Redialing (special case of CONNECTING) */
124 CAMERA_STATE_OFF = 0,
130 PREVIEW_POS_TOP_LEFT,
131 PREVIEW_POS_TOP_RIGHT,
132 PREVIEW_POS_BOTTOM_LEFT,
133 PREVIEW_POS_BOTTOM_RIGHT,
136 struct _EmpathyCallWindowPriv
138 gboolean dispose_has_run;
139 EmpathyCallHandler *handler;
141 EmpathyContact *contact;
143 EmpathyCameraMonitor *camera_monitor;
145 CallState call_state;
148 GtkUIManager *ui_manager;
149 GtkWidget *errors_vbox;
150 /* widget displays the video received from the remote user. This widget is
151 * alive only during call. */
152 ClutterActor *video_output;
153 ClutterActor *video_preview;
154 ClutterActor *drag_preview;
155 ClutterActor *preview_shown_button;
156 ClutterActor *preview_hidden_button;
157 ClutterActor *preview_rectangle1;
158 ClutterActor *preview_rectangle2;
159 ClutterActor *preview_rectangle3;
160 ClutterActor *preview_rectangle4;
161 ClutterActor *preview_spinner_actor;
162 GtkWidget *preview_spinner_widget;
163 GtkWidget *video_container;
164 GtkWidget *remote_user_avatar_widget;
165 GtkWidget *remote_user_avatar_toolbar;
166 GtkWidget *remote_user_name_toolbar;
167 GtkWidget *remote_user_status_toolbar;
168 GtkWidget *status_label;
169 GtkWidget *hangup_button;
170 GtkWidget *audio_call_button;
171 GtkWidget *video_call_button;
172 GtkWidget *mic_button;
173 GtkWidget *microphone_icon;
174 GtkWidget *volume_button;
175 GtkWidget *camera_button;
176 GtkWidget *dialpad_button;
178 GtkWidget *bottom_toolbar;
179 ClutterActor *floating_toolbar;
181 GtkAction *menu_fullscreen;
182 GtkAction *menu_swap_camera;
184 ClutterState *transitions;
186 /* The main box covering all the stage, contaning remote avatar/video */
187 ClutterActor *video_box;
188 ClutterLayoutManager *video_layout;
190 /* A bin layout manager containing a bin for previews
191 * and the floating toolbar */
192 ClutterActor *overlay_bin;
193 ClutterLayoutManager *overlay_layout;
195 /* Bin layout for the previews */
196 ClutterActor *preview_box;
197 ClutterLayoutManager *preview_layout;
199 /* Coordinates of the preview drag event's start. */
200 PreviewPosition preview_pos;
202 /* We keep a reference on the hbox which contains the main content so we can
203 easilly repack everything when toggling fullscreen */
204 GtkWidget *content_hbox;
206 /* These are used to accept or reject an incoming call when the status
208 GtkWidget *incoming_call_dialog;
209 TpCallChannel *pending_channel;
210 TpChannelDispatchOperation *pending_cdo;
211 TpAddDispatchOperationContext *pending_context;
213 gulong video_output_motion_handler_id;
214 guint bus_message_source_id;
216 GtkWidget *dtmf_panel;
219 GtkWidget *details_vbox;
220 GtkWidget *vcodec_encoding_label;
221 GtkWidget *acodec_encoding_label;
222 GtkWidget *vcodec_decoding_label;
223 GtkWidget *acodec_decoding_label;
225 GtkWidget *audio_remote_candidate_label;
226 GtkWidget *audio_local_candidate_label;
227 GtkWidget *video_remote_candidate_label;
228 GtkWidget *video_local_candidate_label;
229 GtkWidget *video_remote_candidate_info_img;
230 GtkWidget *video_local_candidate_info_img;
231 GtkWidget *audio_remote_candidate_info_img;
232 GtkWidget *audio_local_candidate_info_img;
234 GstElement *video_input;
235 GstElement *video_preview_sink;
236 GstElement *video_output_sink;
237 GstElement *audio_input;
238 GstElement *audio_output;
239 gboolean audio_output_added;
240 GstElement *pipeline;
241 GstElement *video_tee;
251 gboolean call_started;
252 gboolean sending_video;
253 CameraState camera_state;
255 EmpathyCallWindowFullscreen *fullscreen;
256 gboolean is_fullscreen;
261 guint inactivity_src;
263 /* Those fields represent the state of the window before it actually was in
265 gboolean dialpad_was_visible_before_fs;
266 gint original_width_before_fs;
267 gint original_height_before_fs;
269 gint x, y, w, h, dialpad_width;
272 /* TRUE if the call should be started when the pipeline is playing */
273 gboolean start_call_when_playing;
274 /* TRUE if we requested to set the pipeline in the playing state */
275 gboolean pipeline_playing;
277 EmpathySoundManager *sound_mgr;
280 EmpathyMicMenu *mic_menu;
281 EmpathyCameraMenu *camera_menu;
286 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
288 static void empathy_call_window_realized_cb (GtkWidget *widget,
289 EmpathyCallWindow *window);
291 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
292 GdkEvent *event, EmpathyCallWindow *window);
294 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
295 GdkEventWindowState *event, EmpathyCallWindow *window);
297 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
300 static void empathy_call_window_hangup_cb (gpointer object,
301 EmpathyCallWindow *window);
303 static void empathy_call_window_fullscreen_cb (gpointer object,
304 EmpathyCallWindow *window);
306 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
308 static gboolean empathy_call_window_video_button_press_cb (
309 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
311 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
312 GdkEventKey *event, EmpathyCallWindow *window);
314 static gboolean empathy_call_window_video_output_motion_notify (
315 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
317 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
320 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
322 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
323 EmpathyCallWindow *window);
325 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
327 static void empathy_call_window_status_message (EmpathyCallWindow *window,
330 static gboolean empathy_call_window_bus_message (GstBus *bus,
331 GstMessage *message, gpointer user_data);
333 static gboolean empathy_call_window_update_timer (gpointer user_data);
336 make_background_transparent (GtkClutterActor *actor)
338 GdkRGBA transparent = { 0., 0., 0., 0. };
341 widget = gtk_clutter_actor_get_widget (actor);
342 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
346 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
349 gtk_widget_set_visible (self->priv->hangup_button, show);
350 gtk_widget_set_visible (self->priv->audio_call_button, !show);
351 gtk_widget_set_visible (self->priv->video_call_button, !show);
355 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
356 EmpathyCallWindow *self)
358 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
359 empathy_call_window_restart_call (self);
363 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
364 EmpathyCallWindow *self)
366 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
367 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
368 empathy_call_window_restart_call (self);
372 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
374 EmpathyCallWindow *self)
379 g_object_get (self->priv->handler, "call-channel", &call, NULL);
381 tones[0] = tp_dtmf_event_to_char (event);
383 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
385 g_object_unref (call);
389 empathy_call_window_show_video_output (EmpathyCallWindow *self,
392 if (self->priv->video_output != NULL)
393 g_object_set (self->priv->video_output, "visible", show, NULL);
395 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
397 clutter_actor_raise_top (self->priv->overlay_bin);
401 create_video_output_widget (EmpathyCallWindow *self)
403 EmpathyCallWindowPriv *priv = GET_PRIV (self);
405 g_assert (priv->video_output == NULL);
406 g_assert (priv->pipeline != NULL);
408 priv->video_output = clutter_texture_new ();
410 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
413 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
414 if (priv->video_output_sink == NULL)
415 g_error ("Missing cluttersink");
417 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
419 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
422 gtk_widget_add_events (priv->video_container,
423 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
424 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
425 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
429 create_video_input (EmpathyCallWindow *self)
431 EmpathyCallWindowPriv *priv = GET_PRIV (self);
433 g_assert (priv->video_input == NULL);
434 priv->video_input = empathy_video_src_new ();
435 gst_object_ref_sink (priv->video_input);
439 audio_control_volume_to_element (GBinding *binding,
440 const GValue *source_value,
441 GValue *target_value,
444 /* AudioControl volume is 0-255, with -1 for unknown */
447 hv = g_value_get_int (source_value);
452 g_value_set_double (target_value, hv/255.0);
458 element_volume_to_audio_control (GBinding *binding,
459 const GValue *source_value,
460 GValue *target_value,
465 ev = g_value_get_double (source_value);
466 ev = CLAMP (ev, 0.0, 1.0);
468 g_value_set_int (target_value, ev * 255);
473 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
474 EmpathyCallWindow *self)
477 g_object_get (obj, "mute", &muted, NULL);
479 self->priv->muted = muted;
480 if (muted && self->priv->transitions)
481 clutter_state_set_state (self->priv->transitions, "fade-in");
485 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
486 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
490 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
491 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
494 empathy_call_window_update_timer (self);
498 create_audio_input (EmpathyCallWindow *self)
500 EmpathyCallWindowPriv *priv = GET_PRIV (self);
502 g_assert (priv->audio_input == NULL);
503 priv->audio_input = empathy_audio_src_new ();
504 gst_object_ref_sink (priv->audio_input);
506 g_signal_connect (priv->audio_input, "notify::mute",
507 G_CALLBACK (audio_input_mute_notify_cb), self);
511 add_video_preview_to_pipeline (EmpathyCallWindow *self)
513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
516 g_assert (priv->video_preview != NULL);
517 g_assert (priv->pipeline != NULL);
518 g_assert (priv->video_input != NULL);
519 g_assert (priv->video_tee != NULL);
521 preview = priv->video_preview_sink;
523 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
525 g_warning ("Could not add video input to pipeline");
529 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
531 g_warning ("Could not add video preview to pipeline");
535 if (!gst_element_link (priv->video_input, priv->video_tee))
537 g_warning ("Could not link video input to video tee");
541 if (!gst_element_link (priv->video_tee, preview))
543 g_warning ("Could not link video tee to video preview");
549 empathy_call_window_disable_camera_cb (GtkAction *action,
550 EmpathyCallWindow *self)
552 clutter_actor_destroy (self->priv->preview_hidden_button);
554 gtk_toggle_button_set_active (
555 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
559 empathy_call_window_minimise_camera_cb (GtkAction *action,
560 EmpathyCallWindow *self)
562 clutter_actor_hide (self->priv->video_preview);
563 clutter_actor_show (self->priv->preview_hidden_button);
567 empathy_call_window_maximise_camera_cb (GtkAction *action,
568 EmpathyCallWindow *self)
570 clutter_actor_show (self->priv->video_preview);
571 clutter_actor_hide (self->priv->preview_hidden_button);
575 empathy_call_window_swap_camera_cb (GtkAction *action,
576 EmpathyCallWindow *self)
578 const GList *cameras, *l;
581 DEBUG ("Swapping the camera");
583 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
584 current_cam = empathy_video_src_dup_device (
585 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
587 for (l = cameras; l != NULL; l = l->next)
589 EmpathyCamera *camera = l->data;
591 if (!tp_strdiff (camera->device, current_cam))
596 next = l->next->data;
598 next = cameras->data;
600 /* EmpathyCameraMenu will update itself and do the actual change
602 g_settings_set_string (self->priv->settings,
603 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
610 g_free (current_cam);
614 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
615 EmpathyCamera *camera,
616 EmpathyCallWindow *self)
618 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
620 gtk_action_set_visible (self->priv->menu_swap_camera,
621 g_list_length ((GList *) cameras) >= 2);
625 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
626 EmpathyCamera *camera,
627 EmpathyCallWindow *self)
629 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
631 gtk_action_set_visible (self->priv->menu_swap_camera,
632 g_list_length ((GList *) cameras) >= 2);
636 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
637 EmpathyCallWindow *self)
641 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
643 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
644 0, gtk_get_current_event_time ());
645 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
649 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
650 EmpathyCallWindow *self)
654 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
655 "/preview-hidden-menu");
656 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
657 0, gtk_get_current_event_time ());
658 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
661 static ClutterActor *
662 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
663 ClutterBinAlignment x,
664 ClutterBinAlignment y)
666 ClutterActor *rectangle;
668 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
669 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
670 PREVIEW_ROUND_FACTOR));
672 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
674 clutter_actor_hide (rectangle);
680 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
684 self->priv->preview_layout = clutter_bin_layout_new (
685 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
686 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
688 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
690 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
692 self->priv->preview_rectangle1 =
693 empathy_call_window_create_preview_rectangle (self,
694 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
695 self->priv->preview_rectangle2 =
696 empathy_call_window_create_preview_rectangle (self,
697 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
698 self->priv->preview_rectangle3 =
699 empathy_call_window_create_preview_rectangle (self,
700 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
701 self->priv->preview_rectangle4 =
702 empathy_call_window_create_preview_rectangle (self,
703 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
707 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
710 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
711 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
712 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
713 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
717 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
722 guint ret_x = 0, ret_y = 0;
725 if (!clutter_actor_has_allocation (self->priv->preview_box))
728 clutter_actor_get_geometry (self->priv->preview_box, &box);
732 case PREVIEW_POS_TOP_LEFT:
733 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
735 case PREVIEW_POS_TOP_RIGHT:
736 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_WIDTH;
738 ret_y = SELF_VIDEO_SECTION_MARGIN;
740 case PREVIEW_POS_BOTTOM_LEFT:
741 ret_x = SELF_VIDEO_SECTION_MARGIN;
742 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
743 - SELF_VIDEO_SECTION_HEIGHT;
745 case PREVIEW_POS_BOTTOM_RIGHT:
746 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
747 - SELF_VIDEO_SECTION_WIDTH;
748 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
749 - SELF_VIDEO_SECTION_HEIGHT;
752 g_warn_if_reached ();
763 static PreviewPosition
764 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
769 PreviewPosition pos = PREVIEW_POS_NONE;
771 if (!clutter_actor_has_allocation (self->priv->preview_box))
774 clutter_actor_get_geometry (self->priv->preview_box, &box);
776 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
777 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
778 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
779 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
781 pos = PREVIEW_POS_TOP_LEFT;
783 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
784 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
785 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
786 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
788 pos = PREVIEW_POS_TOP_RIGHT;
790 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
791 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
792 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
793 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
795 pos = PREVIEW_POS_BOTTOM_LEFT;
797 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
798 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
799 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
800 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
802 pos = PREVIEW_POS_BOTTOM_RIGHT;
808 static ClutterActor *
809 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
812 ClutterActor *rectangle;
816 case PREVIEW_POS_TOP_LEFT:
817 rectangle = self->priv->preview_rectangle1;
819 case PREVIEW_POS_TOP_RIGHT:
820 rectangle = self->priv->preview_rectangle3;
822 case PREVIEW_POS_BOTTOM_LEFT:
823 rectangle = self->priv->preview_rectangle2;
825 case PREVIEW_POS_BOTTOM_RIGHT:
826 rectangle = self->priv->preview_rectangle4;
836 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
839 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
841 DEBUG ("moving the video preview to %d", pos);
843 self->priv->preview_pos = pos;
847 case PREVIEW_POS_TOP_LEFT:
848 clutter_bin_layout_set_alignment (layout,
849 self->priv->video_preview,
850 CLUTTER_BIN_ALIGNMENT_START,
851 CLUTTER_BIN_ALIGNMENT_START);
853 case PREVIEW_POS_TOP_RIGHT:
854 clutter_bin_layout_set_alignment (layout,
855 self->priv->video_preview,
856 CLUTTER_BIN_ALIGNMENT_END,
857 CLUTTER_BIN_ALIGNMENT_START);
859 case PREVIEW_POS_BOTTOM_LEFT:
860 clutter_bin_layout_set_alignment (layout,
861 self->priv->video_preview,
862 CLUTTER_BIN_ALIGNMENT_START,
863 CLUTTER_BIN_ALIGNMENT_END);
865 case PREVIEW_POS_BOTTOM_RIGHT:
866 clutter_bin_layout_set_alignment (layout,
867 self->priv->video_preview,
868 CLUTTER_BIN_ALIGNMENT_END,
869 CLUTTER_BIN_ALIGNMENT_END);
872 g_warn_if_reached ();
875 g_settings_set_enum (self->priv->settings, "camera-position", pos);
879 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
882 ClutterActor *rectangle;
883 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
885 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
887 empathy_rounded_rectangle_set_border_width (
888 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
889 empathy_rounded_rectangle_set_border_color (
890 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
894 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
895 ClutterActor *rectangle)
897 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
899 clutter_color_shade (&white, 0.55, &darker);
901 empathy_rounded_rectangle_set_border_width (
902 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
903 empathy_rounded_rectangle_set_border_color (
904 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
908 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
910 ClutterActor *rectangle;
912 rectangle = empathy_call_window_get_preview_rectangle (self,
913 self->priv->preview_pos);
915 /* We don't want to darken the rectangle where the preview
918 if (self->priv->preview_rectangle1 != rectangle)
919 empathy_call_window_darken_preview_rectangle (self,
920 self->priv->preview_rectangle1);
922 if (self->priv->preview_rectangle2 != rectangle)
923 empathy_call_window_darken_preview_rectangle (self,
924 self->priv->preview_rectangle2);
926 if (self->priv->preview_rectangle3 != rectangle)
927 empathy_call_window_darken_preview_rectangle (self,
928 self->priv->preview_rectangle3);
930 if (self->priv->preview_rectangle4 != rectangle)
931 empathy_call_window_darken_preview_rectangle (self,
932 self->priv->preview_rectangle4);
936 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
940 ClutterModifierType modifiers,
941 EmpathyCallWindow *self)
943 ClutterActor *stage = clutter_actor_get_stage (actor);
946 self->priv->drag_preview = clutter_clone_new (actor);
948 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
949 self->priv->drag_preview);
951 clutter_actor_transform_stage_point (actor, event_x, event_y,
954 clutter_actor_set_position (self->priv->drag_preview,
955 event_x - rel_x, event_y - rel_y);
957 clutter_drag_action_set_drag_handle (action,
958 self->priv->drag_preview);
960 clutter_actor_set_opacity (actor, 0);
961 clutter_actor_hide (self->priv->preview_shown_button);
963 empathy_call_window_show_preview_rectangles (self, TRUE);
964 empathy_call_window_darken_preview_rectangles (self);
968 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
971 clutter_actor_set_opacity (actor, 255);
975 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
979 ClutterModifierType modifiers,
980 EmpathyCallWindow *self)
985 /* Get the position before destroying the drag actor, otherwise the
986 * preview_box allocation won't be valid and we won't be able to
987 * calculate the position. */
988 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
990 empathy_call_window_get_preview_coordinates (self,
991 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
994 /* Move the preview to the destination and destroy it afterwards */
995 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
998 "signal-swapped-after::completed",
999 clutter_actor_destroy, self->priv->drag_preview,
1000 "signal-swapped-after::completed",
1001 clutter_actor_show, self->priv->preview_shown_button,
1002 "signal::completed",
1003 empathy_call_window_on_animation_completed_cb, actor,
1006 self->priv->drag_preview = NULL;
1008 if (pos != PREVIEW_POS_NONE)
1009 empathy_call_window_move_video_preview (self, pos);
1011 empathy_call_window_show_preview_rectangles (self, FALSE);
1015 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1016 ClutterActor *actor,
1019 EmpathyCallWindow *self)
1021 PreviewPosition pos;
1022 gfloat event_x, event_y;
1024 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1026 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1028 if (pos != PREVIEW_POS_NONE)
1029 empathy_call_window_highlight_preview_rectangle (self, pos);
1031 empathy_call_window_darken_preview_rectangles (self);
1035 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1036 ClutterCrossingEvent *event,
1037 EmpathyCallWindow *self)
1039 ClutterActor *rectangle;
1041 rectangle = empathy_call_window_get_preview_rectangle (self,
1042 self->priv->preview_pos);
1044 empathy_call_window_highlight_preview_rectangle (self,
1045 self->priv->preview_pos);
1047 clutter_actor_show (rectangle);
1053 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1054 ClutterCrossingEvent *event,
1055 EmpathyCallWindow *self)
1057 ClutterActor *rectangle;
1059 rectangle = empathy_call_window_get_preview_rectangle (self,
1060 self->priv->preview_pos);
1062 empathy_call_window_darken_preview_rectangle (self, rectangle);
1064 clutter_actor_hide (rectangle);
1070 create_video_preview (EmpathyCallWindow *self)
1072 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1073 ClutterLayoutManager *layout;
1074 ClutterActor *preview;
1076 ClutterAction *action;
1078 PreviewPosition pos;
1080 g_assert (priv->video_preview == NULL);
1082 pos = g_settings_get_enum (priv->settings, "camera-position");
1084 preview = empathy_rounded_texture_new ();
1085 clutter_actor_set_size (preview,
1086 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1088 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1089 if (priv->video_preview_sink == NULL)
1090 g_error ("Missing cluttersink, check your clutter-gst installation");
1091 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1092 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1094 /* Add a little offset to the video preview */
1095 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1096 CLUTTER_BIN_ALIGNMENT_CENTER);
1097 priv->video_preview = clutter_box_new (layout);
1098 clutter_actor_set_size (priv->video_preview,
1099 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1100 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1102 /* Spinner for when changing the camera device */
1103 priv->preview_spinner_widget = gtk_spinner_new ();
1104 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1106 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1107 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1108 gtk_widget_show (priv->preview_spinner_widget);
1111 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1112 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1113 priv->preview_spinner_widget);
1114 clutter_actor_set_size (priv->preview_spinner_actor,
1115 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1116 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1117 clutter_actor_hide (priv->preview_spinner_actor);
1119 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1121 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1122 priv->preview_spinner_actor);
1124 g_object_set (priv->video_preview_sink,
1129 /* Translators: this is an "Info" label. It should be as short
1131 button = gtk_button_new_with_label (_("i"));
1132 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1133 clutter_actor_set_size (b, 24, 24);
1134 clutter_actor_set_margin_right (b, 4);
1135 clutter_actor_set_margin_bottom (b, 2);
1136 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1138 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1139 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1141 g_signal_connect (button, "clicked",
1142 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1145 /* Translators: this is an "Info" label. It should be as short
1147 button = gtk_button_new_with_label (_("i"));
1148 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1149 clutter_actor_set_size (b, 24, 24);
1150 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1152 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1153 priv->preview_hidden_button,
1154 CLUTTER_BIN_ALIGNMENT_START,
1155 CLUTTER_BIN_ALIGNMENT_END);
1157 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1159 clutter_actor_hide (priv->preview_hidden_button);
1161 g_signal_connect (button, "clicked",
1162 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1165 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1166 priv->video_preview,
1167 CLUTTER_BIN_ALIGNMENT_START,
1168 CLUTTER_BIN_ALIGNMENT_END);
1170 empathy_call_window_move_video_preview (self, pos);
1172 action = clutter_drag_action_new ();
1173 g_signal_connect (action, "drag-begin",
1174 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1175 g_signal_connect (action, "drag-end",
1176 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1177 g_signal_connect (action, "drag-motion",
1178 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1180 g_signal_connect (preview, "enter-event",
1181 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1182 g_signal_connect (preview, "leave-event",
1183 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1185 clutter_actor_add_action (preview, action);
1186 clutter_actor_set_reactive (preview, TRUE);
1187 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1191 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1193 clutter_actor_show (self->priv->preview_spinner_actor);
1194 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1198 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1200 clutter_actor_hide (self->priv->preview_spinner_actor);
1201 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1205 empathy_call_window_play_camera (EmpathyCallWindow *self,
1208 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1209 GstElement *preview;
1212 if (priv->video_preview == NULL)
1214 create_video_preview (self);
1215 add_video_preview_to_pipeline (self);
1220 state = GST_STATE_PLAYING;
1224 empathy_call_window_start_camera_spinning (self);
1225 state = GST_STATE_NULL;
1228 preview = priv->video_preview_sink;
1230 gst_element_set_state (preview, state);
1231 gst_element_set_state (priv->video_tee, state);
1232 gst_element_set_state (priv->video_input, state);
1236 display_video_preview (EmpathyCallWindow *self,
1239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1241 if (priv->video_preview == NULL)
1243 create_video_preview (self);
1244 add_video_preview_to_pipeline (self);
1249 /* Display the video preview */
1250 DEBUG ("Show video preview");
1252 empathy_call_window_play_camera (self, TRUE);
1253 clutter_actor_show (priv->video_preview);
1254 clutter_actor_raise_top (priv->floating_toolbar);
1258 /* Hide the video preview */
1259 DEBUG ("Hide video preview");
1261 if (priv->video_preview != NULL)
1263 clutter_actor_hide (priv->video_preview);
1264 empathy_call_window_play_camera (self, FALSE);
1270 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1272 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1274 empathy_call_window_status_message (window, _("Connecting…"));
1275 priv->call_state = CONNECTING;
1277 /* Show the toolbar */
1278 clutter_state_set_state (priv->transitions, "fade-in");
1281 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1282 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1286 disable_camera (EmpathyCallWindow *self)
1288 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1290 if (priv->camera_state == CAMERA_STATE_OFF)
1293 DEBUG ("Disable camera");
1295 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1297 priv->camera_state = CAMERA_STATE_OFF;
1301 enable_camera (EmpathyCallWindow *self)
1303 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1305 if (priv->camera_state == CAMERA_STATE_ON)
1308 if (priv->video_input == NULL)
1310 DEBUG ("Can't enable camera, no input");
1314 DEBUG ("Enable camera");
1316 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1318 priv->camera_state = CAMERA_STATE_ON;
1322 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1323 EmpathyCallWindow *self)
1325 if (gtk_toggle_button_get_active (toggle))
1326 enable_camera (self);
1328 disable_camera (self);
1332 create_pipeline (EmpathyCallWindow *self)
1334 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1337 g_assert (priv->pipeline == NULL);
1339 priv->pipeline = gst_pipeline_new (NULL);
1340 priv->pipeline_playing = FALSE;
1342 priv->video_tee = gst_element_factory_make ("tee", NULL);
1343 gst_object_ref_sink (priv->video_tee);
1345 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1347 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1348 priv->bus_message_source_id = gst_bus_add_watch (bus,
1349 empathy_call_window_bus_message, self);
1351 g_object_unref (bus);
1355 empathy_call_window_settings_cb (GtkAction *action,
1356 EmpathyCallWindow *self)
1358 gchar *args = g_strdup_printf ("-p %s",
1359 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1361 empathy_launch_program (BIN_DIR, "empathy", args);
1367 empathy_call_window_contents_cb (GtkAction *action,
1368 EmpathyCallWindow *self)
1370 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1374 show_png (GPid pid, gint status, gpointer user_data)
1376 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1377 g_spawn_close_pid (pid);
1382 empathy_call_window_debug_gst_cb (GtkAction *action,
1383 EmpathyCallWindow *self)
1385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1386 GDateTime *date_time;
1388 const gchar *dot_dir;
1389 const gchar *prgname;
1395 if (priv->pipeline == NULL)
1396 DEBUG ("No pipeline");
1398 date_time = g_date_time_new_now_utc ();
1399 prgname = g_get_prgname ();
1400 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1401 g_date_time_to_unix (date_time));
1403 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1404 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1406 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1407 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1410 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1412 if (g_spawn_async (dot_dir,
1415 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1421 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1422 g_child_watch_add (dot_pid, show_png, uri);
1428 g_date_time_unref (date_time);
1432 empathy_call_window_debug_tp_cb (GtkAction *action,
1433 EmpathyCallWindow *self)
1435 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1439 empathy_call_window_about_cb (GtkAction *action,
1440 EmpathyCallWindow *self)
1442 empathy_about_dialog_new (GTK_WINDOW (self));
1446 empathy_call_window_toolbar_timeout (gpointer data)
1448 EmpathyCallWindow *self = data;
1450 /* We don't want to hide the toolbar if we're not in a call, as
1451 * to show the call status all the time. Also don't hide if we're muted
1452 * to prevent the awkward, talking when muted situation */
1453 if (self->priv->call_state != CONNECTING &&
1454 self->priv->call_state != DISCONNECTED &&
1456 clutter_state_set_state (self->priv->transitions, "fade-out");
1462 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1464 EmpathyCallWindow *self)
1466 clutter_state_set_state (self->priv->transitions, "fade-in");
1468 if (self->priv->inactivity_src > 0)
1469 g_source_remove (self->priv->inactivity_src);
1471 self->priv->inactivity_src = g_timeout_add_seconds (3,
1472 empathy_call_window_toolbar_timeout, self);
1478 empathy_call_window_configure_event_cb (GtkWidget *widget,
1480 EmpathyCallWindow *self)
1482 GdkWindow *gdk_window;
1483 GdkWindowState window_state;
1485 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1486 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1488 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1489 &self->priv->dialpad_width, NULL);
1491 gdk_window = gtk_widget_get_window (widget);
1492 window_state = gdk_window_get_state (gdk_window);
1493 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1499 empathy_call_window_destroyed_cb (GtkWidget *object,
1500 EmpathyCallWindow *self)
1502 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1504 /* Save the geometry as if the dialpad was hidden. */
1505 empathy_geometry_save_values (GTK_WINDOW (self),
1506 self->priv->x, self->priv->y,
1507 self->priv->w - self->priv->dialpad_width, self->priv->h,
1508 self->priv->maximized);
1513 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1515 EmpathyCallWindow *self)
1517 switch (response_id)
1519 case GTK_RESPONSE_ACCEPT:
1520 tp_channel_dispatch_operation_handle_with_async (
1521 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1523 tp_clear_object (&self->priv->pending_cdo);
1524 tp_clear_object (&self->priv->pending_channel);
1525 tp_clear_object (&self->priv->pending_context);
1528 case GTK_RESPONSE_CANCEL:
1529 tp_channel_dispatch_operation_close_channels_async (
1530 self->priv->pending_cdo, NULL, NULL);
1532 empathy_call_window_status_message (self, _("Disconnected"));
1533 self->priv->call_state = DISCONNECTED;
1536 g_warn_if_reached ();
1541 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1545 g_assert (self->priv->call_state != CONNECTED);
1547 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1549 empathy_call_window_status_message (self, _("Incoming call"));
1550 self->priv->call_state = RINGING;
1552 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1553 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1554 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1555 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1556 empathy_contact_get_alias (self->priv->contact));
1558 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1559 _("Reject"), GTK_RESPONSE_CANCEL,
1560 _("Answer"), GTK_RESPONSE_ACCEPT,
1563 g_signal_connect (self->priv->incoming_call_dialog, "response",
1564 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1565 gtk_widget_show (self->priv->incoming_call_dialog);
1569 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1573 EmpathyCallWindow *self)
1575 tp_clear_object (&self->priv->pending_cdo);
1576 tp_clear_object (&self->priv->pending_channel);
1577 tp_clear_object (&self->priv->pending_context);
1579 /* We don't know if the incoming call has been accepted or not, so we
1580 * assume it hasn't and if it has, we'll set the proper status when
1581 * we get the new handler. */
1582 empathy_call_window_status_message (self, _("Disconnected"));
1583 self->priv->call_state = DISCONNECTED;
1585 gtk_widget_destroy (self->priv->incoming_call_dialog);
1586 self->priv->incoming_call_dialog = NULL;
1590 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1591 TpCallChannel *channel,
1592 TpChannelDispatchOperation *dispatch_operation,
1593 TpAddDispatchOperationContext *context)
1595 g_assert (self->priv->pending_channel == NULL);
1596 g_assert (self->priv->pending_context == NULL);
1597 g_assert (self->priv->pending_cdo == NULL);
1599 /* Start ringing and delay until the user answers or hangs. */
1600 self->priv->pending_channel = g_object_ref (channel);
1601 self->priv->pending_context = g_object_ref (context);
1602 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1604 g_signal_connect (self->priv->pending_cdo, "invalidated",
1605 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1607 empathy_call_window_set_state_ringing (self);
1608 tp_add_dispatch_operation_context_accept (context);
1612 mic_button_clicked (GtkWidget *button,
1613 EmpathyCallWindow *self)
1615 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1617 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1618 !self->priv->muted);
1622 empathy_call_window_init (EmpathyCallWindow *self)
1624 EmpathyCallWindowPriv *priv;
1626 GtkWidget *top_vbox;
1628 ClutterConstraint *constraint;
1629 ClutterActor *remote_avatar;
1630 ClutterColor black = { 0, 0, 0, 0 };
1631 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1632 OVERLAY_MARGIN, OVERLAY_MARGIN };
1634 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1635 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1637 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1638 priv->timer = g_timer_new ();
1640 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1641 gui = empathy_builder_get_file (filename,
1642 "call_window_vbox", &top_vbox,
1643 "errors_vbox", &priv->errors_vbox,
1644 "pane", &priv->pane,
1645 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1646 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1647 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1648 "status_label", &priv->status_label,
1649 "audiocall", &priv->audio_call_button,
1650 "videocall", &priv->video_call_button,
1651 "microphone", &priv->mic_button,
1652 "microphone_icon", &priv->microphone_icon,
1653 "volume", &priv->volume_button,
1654 "camera", &priv->camera_button,
1655 "hangup", &priv->hangup_button,
1656 "dialpad", &priv->dialpad_button,
1657 "toolbar", &priv->toolbar,
1658 "bottom_toolbar", &priv->bottom_toolbar,
1659 "ui_manager", &priv->ui_manager,
1660 "menufullscreen", &priv->menu_fullscreen,
1661 "menupreviewswap", &priv->menu_swap_camera,
1662 "details_vbox", &priv->details_vbox,
1663 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1664 "acodec_encoding_label", &priv->acodec_encoding_label,
1665 "acodec_decoding_label", &priv->acodec_decoding_label,
1666 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1667 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1668 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1669 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1670 "video_local_candidate_label", &priv->video_local_candidate_label,
1671 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1672 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1673 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1674 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1678 empathy_builder_connect (gui, self,
1679 "hangup", "clicked", empathy_call_window_hangup_cb,
1680 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1681 "videocall", "clicked", empathy_call_window_video_call_cb,
1682 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1683 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1684 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1685 "menusettings", "activate", empathy_call_window_settings_cb,
1686 "menucontents", "activate", empathy_call_window_contents_cb,
1687 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1688 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1689 "menuabout", "activate", empathy_call_window_about_cb,
1690 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1691 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1692 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1693 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1696 empathy_set_css_provider (GTK_WIDGET (self));
1697 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1699 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1701 g_object_bind_property (priv->camera_monitor, "available",
1702 priv->camera_button, "sensitive",
1703 G_BINDING_SYNC_CREATE);
1705 g_signal_connect (priv->camera_monitor, "added",
1706 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1707 g_signal_connect (priv->camera_monitor, "removed",
1708 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1710 g_signal_connect (priv->mic_button, "clicked",
1711 G_CALLBACK (mic_button_clicked), self);
1713 g_mutex_init (&priv->lock);
1715 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1717 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1718 CONTENT_HBOX_SPACING);
1719 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1722 /* main contents remote avatar/video box */
1723 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1724 CLUTTER_BIN_ALIGNMENT_FILL);
1726 priv->video_box = clutter_box_new (priv->video_layout);
1728 priv->video_container = gtk_clutter_embed_new ();
1730 gtk_widget_set_size_request (priv->video_container,
1731 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1733 /* Set the background black */
1734 clutter_stage_set_color (
1735 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1736 GTK_CLUTTER_EMBED (priv->video_container))),
1739 clutter_container_add (
1740 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1741 GTK_CLUTTER_EMBED (priv->video_container))),
1745 constraint = clutter_bind_constraint_new (
1746 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1747 CLUTTER_BIND_SIZE, 0);
1748 clutter_actor_add_constraint (priv->video_box, constraint);
1750 priv->remote_user_avatar_widget = gtk_image_new ();
1751 remote_avatar = gtk_clutter_actor_new_with_contents (
1752 priv->remote_user_avatar_widget);
1753 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1755 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1758 /* create the overlay bin */
1759 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1760 CLUTTER_BIN_ALIGNMENT_CENTER);
1761 priv->overlay_bin = clutter_actor_new ();
1762 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1764 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1766 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1768 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1770 empathy_call_window_create_preview_rectangles (self);
1772 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1773 priv->video_container, TRUE, TRUE,
1774 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1776 create_pipeline (self);
1777 create_video_output_widget (self);
1778 create_audio_input (self);
1779 create_video_input (self);
1781 priv->floating_toolbar = gtk_clutter_actor_new ();
1782 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1783 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1785 gtk_style_context_add_class (
1786 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1787 GTK_STYLE_CLASS_OSD);
1788 gtk_widget_reparent (priv->bottom_toolbar,
1789 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1791 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1792 priv->floating_toolbar,
1793 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1795 clutter_actor_raise_top (priv->floating_toolbar);
1797 /* Transitions for the floating toolbar */
1798 priv->transitions = clutter_state_new ();
1800 /* all transitions last for 2s */
1801 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1803 /* transition from any state to "fade-out" state */
1804 clutter_state_set (priv->transitions, NULL, "fade-out",
1805 priv->floating_toolbar,
1806 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1809 /* transition from any state to "fade-in" state */
1810 clutter_state_set (priv->transitions, NULL, "fade-in",
1811 priv->floating_toolbar,
1812 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1815 /* put the actor into the "fade-in" state with no animation */
1816 clutter_state_warp_to_state (priv->transitions, "fade-in");
1818 /* The call will be started as soon the pipeline is playing */
1819 priv->start_call_when_playing = TRUE;
1821 priv->dtmf_panel = empathy_dialpad_widget_new ();
1822 g_signal_connect (priv->dtmf_panel, "start-tone",
1823 G_CALLBACK (dtmf_start_tone_cb), self);
1825 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1828 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1831 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1833 gtk_widget_show_all (top_vbox);
1835 gtk_widget_hide (priv->dtmf_panel);
1836 gtk_widget_hide (priv->details_vbox);
1838 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1840 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1841 priv->video_container);
1843 /* We hide the bottom toolbar after 3s of inactivity and show it
1844 * again on mouse movement */
1845 priv->inactivity_src = g_timeout_add_seconds (3,
1846 empathy_call_window_toolbar_timeout, self);
1848 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1849 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1851 g_signal_connect (G_OBJECT (self), "realize",
1852 G_CALLBACK (empathy_call_window_realized_cb), self);
1854 g_signal_connect (G_OBJECT (self), "delete-event",
1855 G_CALLBACK (empathy_call_window_delete_cb), self);
1857 g_signal_connect (G_OBJECT (self), "window-state-event",
1858 G_CALLBACK (empathy_call_window_state_event_cb), self);
1860 g_signal_connect (G_OBJECT (self), "key-press-event",
1861 G_CALLBACK (empathy_call_window_key_press_cb), self);
1863 g_signal_connect (self, "motion-notify-event",
1864 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1866 g_object_ref (priv->ui_manager);
1867 g_object_unref (gui);
1869 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1870 priv->mic_menu = empathy_mic_menu_new (self);
1871 priv->camera_menu = empathy_camera_menu_new (self);
1873 empathy_call_window_show_hangup_button (self, TRUE);
1875 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1876 /* These signals are used to track the window position and save it
1877 * when the window is destroyed. We need to do this as we don't want
1878 * the window geometry to be saved with the dialpad taken into account. */
1879 g_signal_connect (self, "destroy",
1880 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1881 g_signal_connect (self, "configure-event",
1882 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1883 g_signal_connect (self, "window-state-event",
1884 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1886 /* Don't display labels in both toolbars */
1887 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1890 /* Instead of specifying a width and a height, we specify only one size. That's
1891 because we want a square avatar icon. */
1893 init_contact_avatar_with_size (EmpathyContact *contact,
1894 GtkWidget *image_widget,
1897 GdkPixbuf *pixbuf_avatar = NULL;
1899 if (contact != NULL)
1901 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1905 if (pixbuf_avatar == NULL)
1907 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1908 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1911 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1913 if (pixbuf_avatar != NULL)
1914 g_object_unref (pixbuf_avatar);
1918 set_window_title (EmpathyCallWindow *self)
1920 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1923 if (priv->contact != NULL)
1925 /* translators: Call is a noun and %s is the contact name. This string
1926 * is used in the window title */
1927 tmp = g_strdup_printf (_("Call with %s"),
1928 empathy_contact_get_alias (priv->contact));
1929 gtk_window_set_title (GTK_WINDOW (self), tmp);
1934 g_warning ("Unknown remote contact!");
1939 set_remote_user_name (EmpathyCallWindow *self,
1940 EmpathyContact *contact)
1942 const gchar *alias = empathy_contact_get_alias (contact);
1943 const gchar *status = empathy_contact_get_status (contact);
1945 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1947 if (status != NULL) {
1950 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1951 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1955 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1961 contact_name_changed_cb (EmpathyContact *contact,
1963 EmpathyCallWindow *self)
1965 set_window_title (self);
1966 set_remote_user_name (self, contact);
1970 contact_presence_changed_cb (EmpathyContact *contact,
1972 EmpathyCallWindow *self)
1974 set_remote_user_name (self, contact);
1978 contact_avatar_changed_cb (EmpathyContact *contact,
1980 EmpathyCallWindow *self)
1983 GtkAllocation allocation;
1984 GtkWidget *avatar_widget;
1986 avatar_widget = self->priv->remote_user_avatar_widget;
1988 gtk_widget_get_allocation (avatar_widget, &allocation);
1989 size = allocation.height;
1993 /* the widget is not allocated yet, set a default size */
1994 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1995 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1998 init_contact_avatar_with_size (contact, avatar_widget, size);
2000 avatar_widget = self->priv->remote_user_avatar_toolbar;
2002 gtk_widget_get_allocation (avatar_widget, &allocation);
2003 size = allocation.height;
2007 /* the widget is not allocated yet, set a default size */
2008 size = SMALL_TOOLBAR_SIZE;
2011 init_contact_avatar_with_size (contact, avatar_widget, size);
2015 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2016 EmpathyCallHandler *handler)
2018 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2020 tp_g_signal_connect_object (priv->contact, "notify::name",
2021 G_CALLBACK (contact_name_changed_cb), self, 0);
2022 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2023 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2024 tp_g_signal_connect_object (priv->contact, "notify::presence",
2025 G_CALLBACK (contact_presence_changed_cb), self, 0);
2027 set_window_title (self);
2028 set_remote_user_name (self, priv->contact);
2030 init_contact_avatar_with_size (priv->contact,
2031 priv->remote_user_avatar_widget,
2032 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2033 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2035 init_contact_avatar_with_size (priv->contact,
2036 priv->remote_user_avatar_toolbar,
2037 SMALL_TOOLBAR_SIZE);
2039 /* The remote avatar is shown by default and will be hidden when we receive
2040 video from the remote side. */
2041 clutter_actor_hide (priv->video_output);
2042 gtk_widget_show (priv->remote_user_avatar_widget);
2046 update_send_codec (EmpathyCallWindow *self,
2049 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2056 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2057 widget = priv->acodec_encoding_label;
2061 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2062 widget = priv->vcodec_encoding_label;
2068 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2069 gtk_label_set_text (GTK_LABEL (widget), tmp);
2074 send_audio_codec_notify_cb (GObject *object,
2078 EmpathyCallWindow *self = user_data;
2080 update_send_codec (self, TRUE);
2084 send_video_codec_notify_cb (GObject *object,
2088 EmpathyCallWindow *self = user_data;
2090 update_send_codec (self, FALSE);
2094 update_recv_codec (EmpathyCallWindow *self,
2097 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2100 GString *str = NULL;
2104 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2105 widget = priv->acodec_decoding_label;
2109 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2110 widget = priv->vcodec_decoding_label;
2116 for (l = codecs; l != NULL; l = g_list_next (l))
2118 FsCodec *codec = l->data;
2121 str = g_string_new (NULL);
2123 g_string_append (str, ", ");
2125 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2129 gtk_label_set_text (GTK_LABEL (widget), str->str);
2130 g_string_free (str, TRUE);
2134 recv_audio_codecs_notify_cb (GObject *object,
2138 EmpathyCallWindow *self = user_data;
2140 update_recv_codec (self, TRUE);
2144 recv_video_codecs_notify_cb (GObject *object,
2148 EmpathyCallWindow *self = user_data;
2150 update_recv_codec (self, FALSE);
2153 static const gchar *
2154 candidate_type_to_str (FsCandidate *candidate)
2156 switch (candidate->type)
2158 case FS_CANDIDATE_TYPE_HOST:
2160 case FS_CANDIDATE_TYPE_SRFLX:
2161 return "server reflexive";
2162 case FS_CANDIDATE_TYPE_PRFLX:
2163 return "peer reflexive";
2164 case FS_CANDIDATE_TYPE_RELAY:
2166 case FS_CANDIDATE_TYPE_MULTICAST:
2173 static const gchar *
2174 candidate_type_to_desc (FsCandidate *candidate)
2176 switch (candidate->type)
2178 case FS_CANDIDATE_TYPE_HOST:
2179 return _("The IP address as seen by the machine");
2180 case FS_CANDIDATE_TYPE_SRFLX:
2181 return _("The IP address as seen by a server on the Internet");
2182 case FS_CANDIDATE_TYPE_PRFLX:
2183 return _("The IP address of the peer as seen by the other side");
2184 case FS_CANDIDATE_TYPE_RELAY:
2185 return _("The IP address of a relay server");
2186 case FS_CANDIDATE_TYPE_MULTICAST:
2187 return _("The IP address of the multicast group");
2194 update_candidat_widget (EmpathyCallWindow *self,
2197 FsCandidate *candidate)
2201 g_assert (candidate != NULL);
2202 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2203 candidate->port, candidate_type_to_str (candidate));
2205 gtk_label_set_text (GTK_LABEL (label), str);
2206 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2212 candidates_changed_cb (GObject *object,
2214 EmpathyCallWindow *self)
2216 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2217 FsCandidate *candidate = NULL;
2219 if (type == FS_MEDIA_TYPE_VIDEO)
2221 /* Update remote candidate */
2222 candidate = empathy_call_handler_get_video_remote_candidate (
2225 update_candidat_widget (self, priv->video_remote_candidate_label,
2226 priv->video_remote_candidate_info_img, candidate);
2228 /* Update local candidate */
2229 candidate = empathy_call_handler_get_video_local_candidate (
2232 update_candidat_widget (self, priv->video_local_candidate_label,
2233 priv->video_local_candidate_info_img, candidate);
2237 /* Update remote candidate */
2238 candidate = empathy_call_handler_get_audio_remote_candidate (
2241 update_candidat_widget (self, priv->audio_remote_candidate_label,
2242 priv->audio_remote_candidate_info_img, candidate);
2244 /* Update local candidate */
2245 candidate = empathy_call_handler_get_audio_local_candidate (
2248 update_candidat_widget (self, priv->audio_local_candidate_label,
2249 priv->audio_local_candidate_info_img, candidate);
2254 empathy_call_window_constructed (GObject *object)
2256 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2258 TpCallChannel *call;
2261 g_assert (priv->handler != NULL);
2263 g_object_get (priv->handler, "call-channel", &call, NULL);
2264 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2265 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2266 tp_clear_object (&call);
2268 priv->contact = empathy_call_handler_get_contact (priv->handler);
2269 g_assert (priv->contact != NULL);
2270 g_object_ref (priv->contact);
2272 if (!empathy_contact_can_voip_video (priv->contact))
2274 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2275 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2278 empathy_call_window_setup_avatars (self, priv->handler);
2279 empathy_call_window_set_state_connecting (self);
2281 if (!empathy_call_handler_has_initial_video (priv->handler))
2283 gtk_toggle_button_set_active (
2284 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2286 /* If call has InitialVideo, the preview will be started once the call has
2287 * been started (start_call()). */
2289 update_send_codec (self, TRUE);
2290 update_send_codec (self, FALSE);
2291 update_recv_codec (self, TRUE);
2292 update_recv_codec (self, FALSE);
2294 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2295 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2296 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2297 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2298 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2299 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2300 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2301 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2303 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2304 G_CALLBACK (candidates_changed_cb), self, 0);
2307 static void empathy_call_window_dispose (GObject *object);
2308 static void empathy_call_window_finalize (GObject *object);
2311 empathy_call_window_set_property (GObject *object,
2312 guint property_id, const GValue *value, GParamSpec *pspec)
2314 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2316 switch (property_id)
2318 case PROP_CALL_HANDLER:
2319 priv->handler = g_value_dup_object (value);
2322 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2327 empathy_call_window_get_property (GObject *object,
2328 guint property_id, GValue *value, GParamSpec *pspec)
2330 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2332 switch (property_id)
2334 case PROP_CALL_HANDLER:
2335 g_value_set_object (value, priv->handler);
2338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2343 empathy_call_window_class_init (
2344 EmpathyCallWindowClass *empathy_call_window_class)
2346 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2347 GParamSpec *param_spec;
2349 g_type_class_add_private (empathy_call_window_class,
2350 sizeof (EmpathyCallWindowPriv));
2352 object_class->constructed = empathy_call_window_constructed;
2353 object_class->set_property = empathy_call_window_set_property;
2354 object_class->get_property = empathy_call_window_get_property;
2356 object_class->dispose = empathy_call_window_dispose;
2357 object_class->finalize = empathy_call_window_finalize;
2359 param_spec = g_param_spec_object ("handler",
2360 "handler", "The call handler",
2361 EMPATHY_TYPE_CALL_HANDLER,
2362 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2363 g_object_class_install_property (object_class,
2364 PROP_CALL_HANDLER, param_spec);
2366 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2367 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2369 0, NULL, NULL, NULL,
2375 empathy_call_window_dispose (GObject *object)
2377 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2378 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2380 if (priv->dispose_has_run)
2383 priv->dispose_has_run = TRUE;
2385 if (priv->handler != NULL)
2387 empathy_call_handler_stop_call (priv->handler);
2388 tp_clear_object (&priv->handler);
2391 if (priv->bus_message_source_id != 0)
2393 g_source_remove (priv->bus_message_source_id);
2394 priv->bus_message_source_id = 0;
2397 if (priv->got_video_src > 0)
2399 g_source_remove (priv->got_video_src);
2400 priv->got_video_src = 0;
2403 if (priv->inactivity_src > 0)
2405 g_source_remove (priv->inactivity_src);
2406 priv->inactivity_src = 0;
2409 tp_clear_object (&priv->pipeline);
2410 tp_clear_object (&priv->video_input);
2411 tp_clear_object (&priv->audio_input);
2412 tp_clear_object (&priv->video_tee);
2413 tp_clear_object (&priv->ui_manager);
2414 tp_clear_object (&priv->fullscreen);
2415 tp_clear_object (&priv->camera_monitor);
2416 tp_clear_object (&priv->settings);
2417 tp_clear_object (&priv->sound_mgr);
2418 tp_clear_object (&priv->mic_menu);
2419 tp_clear_object (&priv->camera_menu);
2420 tp_clear_object (&priv->transitions);
2422 g_list_free_full (priv->notifiers, g_object_unref);
2424 if (priv->timer_id != 0)
2425 g_source_remove (priv->timer_id);
2428 tp_clear_object (&priv->contact);
2430 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2434 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2438 if (priv->video_output_motion_handler_id != 0)
2440 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2441 priv->video_output_motion_handler_id);
2442 priv->video_output_motion_handler_id = 0;
2447 empathy_call_window_finalize (GObject *object)
2449 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2450 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2452 disconnect_video_output_motion_handler (self);
2454 /* free any data held directly by the object here */
2455 g_mutex_clear (&priv->lock);
2457 g_timer_destroy (priv->timer);
2459 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2464 empathy_call_window_new (EmpathyCallHandler *handler)
2466 return EMPATHY_CALL_WINDOW (
2467 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2471 empathy_call_window_present (EmpathyCallWindow *self,
2472 EmpathyCallHandler *handler)
2474 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2476 empathy_window_present (GTK_WINDOW (self));
2478 if (self->priv->call_state == DISCONNECTED)
2480 /* start a new call if one is not already in progress */
2481 tp_clear_object (&self->priv->handler);
2482 self->priv->handler = g_object_ref (handler);
2483 empathy_call_window_connect_handler (self);
2485 empathy_call_window_restart_call (self);
2490 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2491 GstElement *conference, gpointer user_data)
2493 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2495 FsElementAddedNotifier *notifier;
2498 DEBUG ("Conference added");
2500 /* Add notifier to set the various element properties as needed */
2501 notifier = fs_element_added_notifier_new ();
2502 keyfile = fs_utils_get_default_element_properties (conference);
2504 if (keyfile != NULL)
2505 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2507 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2509 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2511 gst_bin_add (GST_BIN (priv->pipeline), conference);
2512 gst_element_set_state (conference, GST_STATE_PLAYING);
2516 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2517 GstElement *conference, gpointer user_data)
2519 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2522 g_list_free_full (priv->notifiers, g_object_unref);
2523 priv->notifiers = NULL;
2525 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2526 gst_element_set_state (conference, GST_STATE_NULL);
2530 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2532 GstStateChangeReturn state_change_return;
2533 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2535 if (priv->pipeline == NULL)
2538 if (priv->bus_message_source_id != 0)
2540 g_source_remove (priv->bus_message_source_id);
2541 priv->bus_message_source_id = 0;
2544 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2546 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2547 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2549 if (priv->pipeline != NULL)
2550 g_object_unref (priv->pipeline);
2551 priv->pipeline = NULL;
2553 if (priv->audio_output != NULL)
2554 g_object_unref (priv->audio_output);
2555 priv->audio_output = NULL;
2556 priv->audio_output_added = FALSE;
2558 if (priv->video_tee != NULL)
2559 g_object_unref (priv->video_tee);
2560 priv->video_tee = NULL;
2562 if (priv->video_preview != NULL)
2563 clutter_actor_destroy (priv->video_preview);
2564 priv->video_preview = NULL;
2566 /* If we destroy the preview while it's being dragged, we won't
2567 * get the ::drag-end signal, so manually destroy the clone */
2568 if (priv->drag_preview != NULL)
2570 clutter_actor_destroy (priv->drag_preview);
2571 empathy_call_window_show_preview_rectangles (self, FALSE);
2572 priv->drag_preview = NULL;
2575 priv->funnel = NULL;
2577 create_pipeline (self);
2578 /* Call will be started when user will hit the 'redial' button */
2579 priv->start_call_when_playing = FALSE;
2580 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2586 g_message ("Error: could not destroy pipeline. Closing call window");
2587 gtk_widget_destroy (GTK_WIDGET (self));
2594 reset_details_pane (EmpathyCallWindow *self)
2596 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2598 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2599 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2600 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2601 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2605 empathy_call_window_disconnected (EmpathyCallWindow *self,
2608 gboolean could_disconnect = FALSE;
2609 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2610 gboolean could_reset_pipeline;
2612 /* Leave full screen mode if needed */
2613 gtk_window_unfullscreen (GTK_WINDOW (self));
2615 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2617 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2618 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2620 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2622 if (priv->call_state == CONNECTING)
2623 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2625 if (priv->call_state != REDIALING)
2626 priv->call_state = DISCONNECTED;
2628 /* Show the toolbar */
2629 clutter_state_set_state (priv->transitions, "fade-in");
2631 if (could_reset_pipeline)
2633 g_mutex_lock (&priv->lock);
2635 g_timer_stop (priv->timer);
2637 if (priv->timer_id != 0)
2638 g_source_remove (priv->timer_id);
2641 g_mutex_unlock (&priv->lock);
2644 /* We are about to destroy the window, no need to update it or create
2645 * a video preview */
2648 empathy_call_window_status_message (self, _("Disconnected"));
2650 empathy_call_window_show_hangup_button (self, FALSE);
2652 /* Unsensitive the camera and mic button */
2653 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2654 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2656 /* Be sure that the mic button is enabled */
2657 empathy_audio_src_set_mute (
2658 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2660 if (priv->camera_state == CAMERA_STATE_ON)
2662 /* Restart the preview with the new pipeline. */
2663 display_video_preview (self, TRUE);
2666 /* destroy the video output; it will be recreated when we'll redial */
2667 disconnect_video_output_motion_handler (self);
2668 if (priv->video_output != NULL)
2669 clutter_actor_destroy (priv->video_output);
2670 priv->video_output = NULL;
2671 if (priv->got_video_src > 0)
2673 g_source_remove (priv->got_video_src);
2674 priv->got_video_src = 0;
2677 gtk_widget_show (priv->remote_user_avatar_widget);
2679 reset_details_pane (self);
2681 priv->sending_video = FALSE;
2682 priv->call_started = FALSE;
2684 could_disconnect = TRUE;
2686 /* TODO: display the self avatar of the preview (depends if the "Always
2687 * Show Video Preview" is enabled or not) */
2690 return could_disconnect;
2695 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2698 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2699 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2701 if (empathy_call_window_disconnected (self, TRUE) &&
2702 priv->call_state == REDIALING)
2703 empathy_call_window_restart_call (self);
2707 empathy_call_window_content_is_raw (TfContent *content)
2709 FsConference *conference;
2712 g_object_get (content, "fs-conference", &conference, NULL);
2713 g_assert (conference != NULL);
2715 /* FIXME: Ugly hack, update when moving a packetization property into
2717 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2718 gst_object_unref (conference);
2724 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2726 EmpathyCallWindow *self)
2728 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2729 FsMediaType media_type;
2731 DEBUG ("removing content");
2733 g_object_get (content, "media-type", &media_type, NULL);
2736 * This assumes that there is only one video stream per channel...
2739 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2741 if (priv->funnel != NULL)
2745 output = priv->video_output_sink;
2747 gst_element_set_state (output, GST_STATE_NULL);
2748 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2750 gst_bin_remove (GST_BIN (priv->pipeline), output);
2751 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2752 priv->funnel = NULL;
2755 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2757 if (priv->audio_output != NULL)
2759 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2761 if (priv->audio_output_added)
2762 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2763 priv->audio_output = NULL;
2764 priv->audio_output_added = FALSE;
2769 g_assert_not_reached ();
2776 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2778 EmpathyCallWindow *self)
2780 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2782 DEBUG ("Framerate changed to %u", framerate);
2784 if (priv->video_input != NULL)
2785 empathy_video_src_set_framerate (priv->video_input, framerate);
2789 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2792 EmpathyCallWindow *self)
2794 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2796 DEBUG ("Resolution changed to %ux%u", width, height);
2798 if (priv->video_input != NULL)
2800 empathy_video_src_set_resolution (priv->video_input, width, height);
2804 /* Called with global lock held */
2806 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2808 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2812 if (priv->funnel == NULL)
2814 output = priv->video_output_sink;
2816 priv->funnel = gst_element_factory_make ("funnel", NULL);
2818 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2823 g_warning ("Could not create video funnel");
2827 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2829 gst_object_unref (priv->funnel);
2830 priv->funnel = NULL;
2831 g_warning ("Could not add funnel to pipeline");
2835 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2837 g_warning ("Could not add the video output widget to the pipeline");
2841 if (!gst_element_link (priv->funnel, output))
2843 g_warning ("Could not link output sink to funnel");
2844 goto error_output_added;
2847 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2849 g_warning ("Could not start video sink");
2850 goto error_output_added;
2853 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2855 g_warning ("Could not start funnel");
2856 goto error_output_added;
2860 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2862 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2866 g_warning ("Could not get request pad from funnel");
2873 gst_element_set_locked_state (priv->funnel, TRUE);
2874 gst_element_set_locked_state (output, TRUE);
2876 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2877 gst_element_set_state (output, GST_STATE_NULL);
2879 gst_bin_remove (GST_BIN (priv->pipeline), output);
2880 gst_element_set_locked_state (output, FALSE);
2884 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2885 priv->funnel = NULL;
2890 /* Called with global lock held */
2892 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2895 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2897 GstPadTemplate *template;
2899 if (!priv->audio_output_added)
2901 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2903 g_warning ("Could not add audio sink to pipeline");
2904 g_object_unref (priv->audio_output);
2905 goto error_add_output;
2908 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2910 g_warning ("Could not start audio sink");
2915 template = gst_element_class_get_pad_template (
2916 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2918 pad = gst_element_request_pad (priv->audio_output,
2919 template, NULL, NULL);
2923 g_warning ("Could not get sink pad from sink");
2930 gst_element_set_locked_state (priv->audio_output, TRUE);
2931 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2932 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2933 priv->audio_output = NULL;
2941 empathy_call_window_update_timer (gpointer user_data)
2943 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2944 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2945 const gchar *status;
2949 time_ = g_timer_elapsed (priv->timer, NULL);
2951 if (priv->call_state == HELD)
2952 status = _("On hold");
2953 else if (priv->call_state == DISCONNECTED)
2954 status = _("Disconnected");
2955 else if (priv->muted)
2958 status = _("Duration");
2960 /* Translators: 'status - minutes:seconds' the caller has been connected */
2961 str = g_strdup_printf (_("%s — %d:%02dm"),
2963 (int) time_ / 60, (int) time_ % 60);
2964 empathy_call_window_status_message (self, str);
2972 EMP_RESPONSE_BALANCE
2976 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2980 switch (response_id)
2982 case GTK_RESPONSE_CLOSE:
2983 gtk_widget_destroy (GTK_WIDGET (info_bar));
2985 case EMP_RESPONSE_BALANCE:
2986 empathy_url_show (GTK_WIDGET (info_bar),
2987 g_object_get_data (G_OBJECT (info_bar), "uri"));
2993 display_error (EmpathyCallWindow *self,
2997 const gchar *details,
2998 const gchar *button_text,
3000 gint button_response)
3002 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3003 GtkWidget *info_bar;
3004 GtkWidget *content_area;
3011 /* Create info bar */
3012 info_bar = gtk_info_bar_new ();
3014 if (button_text != NULL)
3016 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3017 button_text, button_response);
3018 g_object_set_data_full (G_OBJECT (info_bar),
3019 "uri", g_strdup (uri), g_free);
3022 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3023 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3025 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3027 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3029 /* hbox containing the image and the messages vbox */
3030 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3031 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3034 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3035 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3037 /* vbox containing the main message and the details expander */
3038 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3039 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3042 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3044 label = gtk_label_new (NULL);
3045 gtk_label_set_markup (GTK_LABEL (label), txt);
3046 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3047 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3050 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3053 if (details != NULL)
3055 GtkWidget *expander;
3057 expander = gtk_expander_new (_("Technical Details"));
3059 txt = g_strdup_printf ("<i>%s</i>", details);
3061 label = gtk_label_new (NULL);
3062 gtk_label_set_markup (GTK_LABEL (label), txt);
3063 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3064 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3067 gtk_container_add (GTK_CONTAINER (expander), label);
3068 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3071 g_signal_connect (info_bar, "response",
3072 G_CALLBACK (on_error_infobar_response_cb), NULL);
3074 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3075 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3076 gtk_widget_show_all (info_bar);
3081 media_stream_error_to_txt (EmpathyCallWindow *self,
3082 TpCallChannel *call,
3084 TpMediaStreamError error)
3086 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3087 const gchar *cm = NULL;
3093 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3095 return g_strdup_printf (
3096 _("%s's software does not understand any of the audio formats "
3097 "supported by your computer"),
3098 empathy_contact_get_alias (priv->contact));
3100 return g_strdup_printf (
3101 _("%s's software does not understand any of the video formats "
3102 "supported by your computer"),
3103 empathy_contact_get_alias (priv->contact));
3105 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3106 return g_strdup_printf (
3107 _("Can't establish a connection to %s. "
3108 "One of you might be on a network that does not allow "
3109 "direct connections."),
3110 empathy_contact_get_alias (priv->contact));
3112 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3113 return g_strdup (_("There was a failure on the network"));
3115 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3117 return g_strdup (_("The audio formats necessary for this call "
3118 "are not installed on your computer"));
3120 return g_strdup (_("The video formats necessary for this call "
3121 "are not installed on your computer"));
3123 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3124 tp_connection_parse_object_path (
3125 tp_channel_get_connection (TP_CHANNEL (call)),
3128 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3129 "product=Telepathy&component=%s", cm);
3131 result = g_strdup_printf (
3132 _("Something unexpected happened in a Telepathy component. "
3133 "Please <a href=\"%s\">report this bug</a> and attach "
3134 "logs gathered from the 'Debug' window in the Help menu."), url);
3140 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3141 return g_strdup (_("There was a failure in the call engine"));
3143 case TP_MEDIA_STREAM_ERROR_EOS:
3144 return g_strdup (_("The end of the stream was reached"));
3146 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3153 empathy_call_window_stream_error (EmpathyCallWindow *self,
3154 TpCallChannel *call,
3163 desc = media_stream_error_to_txt (self, call, audio, code);
3166 /* No description, use the error message. That's not great as it's not
3167 * localized but it's better than nothing. */
3168 display_error (self, call, icon, title, msg, NULL);
3172 display_error (self, call, icon, title, desc, msg);
3178 empathy_call_window_audio_stream_error (TpCallChannel *call,
3181 EmpathyCallWindow *self)
3183 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3184 "gnome-stock-mic", _("Can't establish audio stream"));
3188 empathy_call_window_video_stream_error (TpCallChannel *call,
3191 EmpathyCallWindow *self)
3193 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3194 "camera-web", _("Can't establish video stream"));
3199 show_balance_error (EmpathyCallWindow *self)
3203 gchar *balance, *tmp;
3204 const gchar *uri, *currency;
3208 g_object_get (self->priv->handler,
3209 "call-channel", &call,
3212 conn = tp_channel_get_connection (call);
3213 g_object_unref (call);
3215 uri = tp_connection_get_balance_uri (conn);
3217 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3219 /* unknown balance */
3220 balance = g_strdup ("(--)");
3224 char *money = empathy_format_currency (amount, scale, currency);
3226 balance = g_strdup_printf ("%s %s",
3231 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3233 display_error (self,
3235 _("Sorry, you don’t have enough credit for that call."),
3239 EMP_RESPONSE_BALANCE);
3246 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3249 EmpathyCallWindow *self)
3251 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3252 TpCallChannel *call;
3253 gboolean can_send_video;
3255 if (state == TP_CALL_STATE_ENDED)
3257 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3258 empathy_call_window_disconnected (self, TRUE);
3259 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3260 show_balance_error (self);
3264 if (state != TP_CALL_STATE_ACCEPTED)
3267 if (priv->call_state == CONNECTED)
3270 g_timer_start (priv->timer);
3271 priv->call_state = CONNECTED;
3273 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3275 can_send_video = priv->video_input != NULL &&
3276 empathy_contact_can_voip_video (priv->contact) &&
3277 empathy_camera_monitor_get_available (priv->camera_monitor);
3279 g_object_get (priv->handler, "call-channel", &call, NULL);
3281 if (tp_call_channel_has_dtmf (call))
3282 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3284 if (priv->video_input == NULL)
3285 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3287 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3289 empathy_call_window_show_hangup_button (self, TRUE);
3291 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3293 clutter_actor_hide (priv->video_output);
3294 gtk_widget_show (priv->remote_user_avatar_widget);
3296 g_object_unref (call);
3298 g_mutex_lock (&priv->lock);
3300 priv->timer_id = g_timeout_add_seconds (1,
3301 empathy_call_window_update_timer, self);
3303 g_mutex_unlock (&priv->lock);
3305 empathy_call_window_update_timer (self);
3307 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3311 empathy_call_window_show_video_output_cb (gpointer user_data)
3313 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3315 if (self->priv->video_output != NULL)
3317 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3318 clutter_actor_show (self->priv->video_output);
3319 clutter_actor_raise_top (self->priv->overlay_bin);
3326 empathy_call_window_check_video_cb (gpointer data)
3328 EmpathyCallWindow *self = data;
3330 if (self->priv->got_video)
3332 self->priv->got_video = FALSE;
3336 /* No video in the last N seconds, display the remote avatar */
3337 empathy_call_window_show_video_output (self, FALSE);
3342 /* Called from the streaming thread */
3344 static GstPadProbeReturn
3345 empathy_call_window_video_probe_cb (GstPad *pad,
3346 GstPadProbeInfo *info,
3349 EmpathyCallWindow *self = user_data;
3351 if (G_UNLIKELY (!self->priv->got_video))
3353 /* show the remote video */
3354 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3355 empathy_call_window_show_video_output_cb,
3356 g_object_ref (self), g_object_unref);
3358 self->priv->got_video = TRUE;
3361 return GST_PAD_PROBE_OK;
3365 empathy_call_window_video_probe_cb (GstPad *pad,
3366 GstMiniObject *mini_obj,
3367 EmpathyCallWindow *self)
3370 if (GST_IS_EVENT (mini_obj))
3373 if (G_UNLIKELY (!self->priv->got_video))
3375 /* show the remote video */
3376 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3377 empathy_call_window_show_video_output_cb,
3378 g_object_ref (self), g_object_unref);
3380 self->priv->got_video = TRUE;
3387 /* Called from the streaming thread */
3389 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3390 TfContent *content, GstPad *src, gpointer user_data)
3392 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3394 gboolean retval = FALSE;
3399 g_mutex_lock (&priv->lock);
3401 g_object_get (content, "media-type", &media_type, NULL);
3405 case TP_MEDIA_STREAM_TYPE_AUDIO:
3406 pad = empathy_call_window_get_audio_sink_pad (self, content);
3408 case TP_MEDIA_STREAM_TYPE_VIDEO:
3409 g_idle_add (empathy_call_window_show_video_output_cb, self);
3410 pad = empathy_call_window_get_video_sink_pad (self);
3413 gst_pad_add_probe (src,
3414 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3415 empathy_call_window_video_probe_cb, self, NULL);
3417 gst_pad_add_data_probe (src,
3418 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3420 if (priv->got_video_src > 0)
3421 g_source_remove (priv->got_video_src);
3422 priv->got_video_src = g_timeout_add_seconds (1,
3423 empathy_call_window_check_video_cb, self);
3426 g_assert_not_reached ();
3432 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3433 g_warning ("Could not link %s sink pad",
3434 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3438 gst_object_unref (pad);
3442 /* If no sink could be linked, try to add fakesink to prevent the whole call
3447 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3449 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3451 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3452 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3453 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3455 gst_element_set_locked_state (fakesink, TRUE);
3456 gst_element_set_state (fakesink, GST_STATE_NULL);
3457 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3461 DEBUG ("Could not link real sink, linked fakesink instead");
3463 gst_object_unref (sinkpad);
3467 gst_object_unref (fakesink);
3472 g_mutex_unlock (&priv->lock);
3478 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3481 EmpathyCallWindowPriv *priv = self->priv;
3483 g_assert (priv->audio_output_added == FALSE);
3484 g_assert (priv->audio_output == FALSE);
3486 priv->audio_output = empathy_audio_sink_new ();
3487 g_object_ref_sink (priv->audio_output);
3489 /* volume button to output volume linking */
3490 g_object_bind_property (priv->audio_output, "volume",
3491 priv->volume_button, "value",
3492 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3494 g_object_bind_property_full (content, "requested-output-volume",
3495 priv->audio_output, "volume",
3497 audio_control_volume_to_element,
3498 element_volume_to_audio_control,
3501 /* Link volumes together, sync the current audio input volume property
3502 * back to farstream first */
3503 g_object_bind_property_full (priv->audio_output, "volume",
3504 content, "reported-output-volume",
3505 G_BINDING_SYNC_CREATE,
3506 element_volume_to_audio_control,
3507 audio_control_volume_to_element,
3510 /* For raw audio conferences assume that the producer of the raw data
3511 * has already processed it, so turn off any echo cancellation and any
3512 * other audio improvements that come with it */
3513 empathy_audio_sink_set_echo_cancel (
3514 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3515 !empathy_call_window_content_is_raw (content));
3520 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3521 TfContent *content, gpointer user_data)
3523 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3524 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3526 FsMediaType media_type;
3527 gboolean retval = FALSE;
3529 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3530 g_assert (sink != NULL);
3534 case FS_MEDIA_TYPE_AUDIO:
3536 /* For raw audio conferences assume that the receiver of the raw data
3537 * wants it unprocessed, so turn off any echo cancellation and any
3538 * other audio improvements that come with it */
3539 empathy_audio_src_set_echo_cancel (
3540 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3541 !empathy_call_window_content_is_raw (content));
3543 /* Link volumes together, sync the current audio input volume property
3544 * back to farstream first */
3545 g_object_bind_property_full (content, "requested-input-volume",
3546 priv->audio_input, "volume",
3548 audio_control_volume_to_element,
3549 element_volume_to_audio_control,
3552 g_object_bind_property_full (priv->audio_input, "volume",
3553 content, "reported-input-volume",
3554 G_BINDING_SYNC_CREATE,
3555 element_volume_to_audio_control,
3556 audio_control_volume_to_element,
3559 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3561 g_warning ("Could not add audio source to pipeline");
3565 pad = gst_element_get_static_pad (priv->audio_input, "src");
3568 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3569 g_warning ("Could not get source pad from audio source");
3573 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3575 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3576 gst_object_unref (pad);
3577 g_warning ("Could not link audio source to farsight");
3580 gst_object_unref (pad);
3582 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3584 g_warning ("Could not start audio source");
3585 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3586 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3590 /* Prepare our audio output, not added yet though */
3591 empathy_call_window_prepare_audio_output (self, content);
3595 case FS_MEDIA_TYPE_VIDEO:
3596 if (priv->video_tee != NULL)
3599 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3601 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3603 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3605 g_warning ("Could not link video source input pipeline");
3608 gst_object_unref (pad);
3614 g_assert_not_reached ();
3617 gst_object_unref (sink);
3622 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3624 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3625 GstElement *preview;
3627 disable_camera (self);
3629 DEBUG ("remove video input");
3630 preview = priv->video_preview_sink;
3632 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3633 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3634 gst_element_set_state (preview, GST_STATE_NULL);
3636 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3639 g_object_unref (priv->video_input);
3640 priv->video_input = NULL;
3641 g_object_unref (priv->video_tee);
3642 priv->video_tee = NULL;
3643 clutter_actor_destroy (priv->video_preview);
3644 priv->video_preview = NULL;
3646 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3650 start_call (EmpathyCallWindow *self)
3652 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3654 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3656 priv->call_started = TRUE;
3657 empathy_call_handler_start_call (priv->handler,
3658 gtk_get_current_event_time ());
3660 if (empathy_call_handler_has_initial_video (priv->handler))
3662 TpCallChannel *call;
3665 g_object_get (priv->handler, "call-channel", &call, NULL);
3666 /* If the call channel isn't set yet we're requesting it, if we're
3667 * requesting it with initial video it should be PENDING_SEND when we get
3670 s = TP_SENDING_STATE_PENDING_SEND;
3672 s = empathy_call_channel_get_video_state (call);
3674 if (s == TP_SENDING_STATE_PENDING_SEND ||
3675 s == TP_SENDING_STATE_SENDING)
3677 /* Enable 'send video' buttons and display the preview */
3678 gtk_toggle_button_set_active (
3679 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3683 gtk_toggle_button_set_active (
3684 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3686 if (priv->video_preview == NULL)
3688 create_video_preview (self);
3689 add_video_preview_to_pipeline (self);
3694 g_object_unref (call);
3699 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3702 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3703 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3704 GstState newstate, pending;
3706 empathy_call_handler_bus_message (priv->handler, bus, message);
3708 switch (GST_MESSAGE_TYPE (message))
3710 case GST_MESSAGE_STATE_CHANGED:
3711 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3713 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3715 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3716 !priv->call_started)
3718 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3719 if (newstate == GST_STATE_PAUSED)
3721 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3722 priv->pipeline_playing = TRUE;
3724 if (priv->start_call_when_playing)
3728 if (priv->video_preview_sink != NULL &&
3729 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3731 gst_message_parse_state_changed (message, NULL, &newstate,
3734 if (newstate == GST_STATE_PLAYING &&
3735 pending == GST_STATE_VOID_PENDING)
3736 empathy_call_window_stop_camera_spinning (self);
3739 case GST_MESSAGE_ERROR:
3741 GError *error = NULL;
3742 GstElement *gst_error;
3746 gst_message_parse_error (message, &error, &debug);
3747 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3749 g_message ("Element error: %s -- %s\n", error->message, debug);
3751 name = gst_element_get_name (gst_error);
3752 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3754 /* Remove the video input and continue */
3755 if (priv->video_input != NULL)
3756 empathy_call_window_remove_video_input (self);
3757 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3761 empathy_call_window_disconnected (self, TRUE);
3764 g_error_free (error);
3767 case GST_MESSAGE_UNKNOWN:
3768 case GST_MESSAGE_EOS:
3769 case GST_MESSAGE_WARNING:
3770 case GST_MESSAGE_INFO:
3771 case GST_MESSAGE_TAG:
3772 case GST_MESSAGE_BUFFERING:
3773 case GST_MESSAGE_STATE_DIRTY:
3774 case GST_MESSAGE_STEP_DONE:
3775 case GST_MESSAGE_CLOCK_PROVIDE:
3776 case GST_MESSAGE_CLOCK_LOST:
3777 case GST_MESSAGE_NEW_CLOCK:
3778 case GST_MESSAGE_STRUCTURE_CHANGE:
3779 case GST_MESSAGE_STREAM_STATUS:
3780 case GST_MESSAGE_APPLICATION:
3781 case GST_MESSAGE_ELEMENT:
3782 case GST_MESSAGE_SEGMENT_START:
3783 case GST_MESSAGE_SEGMENT_DONE:
3784 case GST_MESSAGE_DURATION:
3785 case GST_MESSAGE_ANY:
3794 empathy_call_window_members_changed_cb (TpCallChannel *call,
3795 GHashTable *updates,
3797 TpCallStateReason *reason,
3798 EmpathyCallWindow *self)
3800 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3801 GHashTableIter iter;
3802 gpointer key, value;
3803 gboolean held = FALSE;
3805 g_hash_table_iter_init (&iter, updates);
3806 while (g_hash_table_iter_next (&iter, &key, &value))
3808 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3810 /* This assumes this is a 1-1 call, otherwise one participant
3811 * putting the call on hold wouldn't mean the call is on hold
3819 priv->call_state = HELD;
3820 else if (priv->call_state == HELD)
3821 priv->call_state = CONNECTED;
3825 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3827 EmpathyCallWindow *self)
3829 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3830 TpCallChannel *call;
3832 g_object_get (priv->handler, "call-channel", &call, NULL);
3837 tp_g_signal_connect_object (call, "audio-stream-error",
3838 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3839 tp_g_signal_connect_object (call, "video-stream-error",
3840 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3843 tp_g_signal_connect_object (call, "members-changed",
3844 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3846 g_object_unref (call);
3850 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3852 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3853 TpCallChannel *call;
3855 g_signal_connect (priv->handler, "state-changed",
3856 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3857 g_signal_connect (priv->handler, "conference-added",
3858 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3859 g_signal_connect (priv->handler, "conference-removed",
3860 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3861 g_signal_connect (priv->handler, "closed",
3862 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3863 g_signal_connect (priv->handler, "src-pad-added",
3864 G_CALLBACK (empathy_call_window_src_added_cb), self);
3865 g_signal_connect (priv->handler, "content-added",
3866 G_CALLBACK (empathy_call_window_content_added_cb), self);
3867 g_signal_connect (priv->handler, "content-removed",
3868 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3870 /* We connect to ::call-channel unconditionally since we'll
3871 * get new channels if we hangup and redial or if we reuse the
3873 g_signal_connect (priv->handler, "notify::call-channel",
3874 G_CALLBACK (call_handler_notify_call_cb), self);
3876 g_signal_connect (priv->handler, "framerate-changed",
3877 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3878 g_signal_connect (priv->handler, "resolution-changed",
3879 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3881 g_object_get (priv->handler, "call-channel", &call, NULL);
3884 /* We won't get notify::call-channel for this channel, so
3885 * directly call the callback. */
3886 call_handler_notify_call_cb (priv->handler, NULL, self);
3887 g_object_unref (call);
3892 empathy_call_window_realized_cb (GtkWidget *widget,
3893 EmpathyCallWindow *self)
3897 /* Make the hangup button twice as wide */
3898 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3899 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3901 empathy_call_window_connect_handler (self);
3903 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3907 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3908 EmpathyCallWindow *window)
3910 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3912 if (priv->pipeline != NULL)
3914 if (priv->bus_message_source_id != 0)
3916 g_source_remove (priv->bus_message_source_id);
3917 priv->bus_message_source_id = 0;
3920 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3923 if (priv->call_state == CONNECTING)
3924 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3930 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3933 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3935 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3940 gtk_widget_hide (priv->dtmf_panel);
3941 gtk_widget_hide (menu);
3942 gtk_widget_hide (priv->toolbar);
3946 if (priv->dialpad_was_visible_before_fs)
3947 gtk_widget_show (priv->dtmf_panel);
3949 gtk_widget_show (menu);
3950 gtk_widget_show (priv->toolbar);
3952 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3953 priv->original_height_before_fs);
3958 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3960 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3962 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3963 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3965 if (priv->video_output != NULL)
3968 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3969 priv->video_output, TRUE, TRUE,
3970 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3977 empathy_call_window_state_event_cb (GtkWidget *widget,
3978 GdkEventWindowState *event, EmpathyCallWindow *window)
3980 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3982 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3983 gboolean set_fullscreen = event->new_window_state &
3984 GDK_WINDOW_STATE_FULLSCREEN;
3988 gboolean dialpad_was_visible;
3989 GtkAllocation allocation;
3990 gint original_width, original_height;
3992 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3993 original_width = allocation.width;
3994 original_height = allocation.height;
3996 g_object_get (priv->dtmf_panel,
3997 "visible", &dialpad_was_visible,
4000 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4001 priv->original_width_before_fs = original_width;
4002 priv->original_height_before_fs = original_height;
4004 if (priv->video_output_motion_handler_id == 0 &&
4005 priv->video_output != NULL)
4007 priv->video_output_motion_handler_id = g_signal_connect (
4008 G_OBJECT (priv->video_container), "motion-notify-event",
4009 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4015 disconnect_video_output_motion_handler (window);
4018 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4020 show_controls (window, set_fullscreen);
4021 show_borders (window, set_fullscreen);
4022 gtk_action_set_stock_id (priv->menu_fullscreen,
4023 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
4024 priv->is_fullscreen = set_fullscreen;
4031 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4034 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4035 int w, h, dialpad_width;
4036 GtkAllocation allocation;
4038 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4039 w = allocation.width;
4040 h = allocation.height;
4042 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4046 gtk_widget_show (priv->dtmf_panel);
4052 gtk_widget_hide (priv->dtmf_panel);
4056 gtk_window_resize (GTK_WINDOW (window), w, h);
4060 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4063 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4064 TpCallChannel *call;
4066 priv->sending_video = (state == CAMERA_STATE_ON);
4068 if (state == CAMERA_STATE_ON)
4070 /* When we start sending video, we want to show the video preview by
4072 display_video_preview (window, TRUE);
4076 display_video_preview (window, FALSE);
4079 if (priv->call_state != CONNECTED)
4082 g_object_get (priv->handler, "call-channel", &call, NULL);
4083 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4084 empathy_call_channel_send_video (call, priv->sending_video);
4085 g_object_unref (call);
4089 empathy_call_window_hangup_cb (gpointer object,
4090 EmpathyCallWindow *self)
4092 /* stopping the call will put it the ENDED state and
4093 * from state_changed_cb we'll reconfigure the window
4095 empathy_call_handler_stop_call (self->priv->handler);
4099 empathy_call_window_restart_call (EmpathyCallWindow *window)
4101 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4103 /* Remove error info bars */
4104 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4105 (GtkCallback) gtk_widget_destroy, NULL);
4107 create_video_output_widget (window);
4108 priv->outgoing = TRUE;
4109 empathy_call_window_set_state_connecting (window);
4111 if (priv->pipeline_playing)
4112 start_call (window);
4114 /* call will be started when the pipeline is ready */
4115 priv->start_call_when_playing = TRUE;
4117 empathy_call_window_setup_avatars (window, priv->handler);
4119 empathy_call_window_show_hangup_button (window, TRUE);
4123 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4124 EmpathyCallWindow *window)
4128 active = gtk_toggle_tool_button_get_active (button);
4130 empathy_call_window_show_dialpad (window, active);
4134 empathy_call_window_fullscreen_cb (gpointer object,
4135 EmpathyCallWindow *window)
4137 empathy_call_window_fullscreen_toggle (window);
4141 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4143 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4145 if (priv->is_fullscreen)
4146 gtk_window_unfullscreen (GTK_WINDOW (window));
4148 gtk_window_fullscreen (GTK_WINDOW (window));
4152 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4153 GdkEventButton *event, EmpathyCallWindow *window)
4155 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4157 empathy_call_window_video_menu_popup (window, event->button);
4165 empathy_call_window_key_press_cb (GtkWidget *video_output,
4166 GdkEventKey *event, EmpathyCallWindow *window)
4168 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4171 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4173 /* Since we are in fullscreen mode, toggling will bring us back to
4175 empathy_call_window_fullscreen_toggle (window);
4179 key = gdk_keyval_to_unicode (event->keyval);
4200 gtk_toggle_tool_button_set_active (
4201 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4203 empathy_dialpad_widget_press_key (
4204 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4210 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4211 GdkEventMotion *event, EmpathyCallWindow *window)
4213 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4215 if (priv->is_fullscreen)
4217 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4219 /* Show the bottom toolbar */
4220 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4227 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4231 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4233 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4235 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4236 button, gtk_get_current_event_time ());
4237 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4241 empathy_call_window_status_message (EmpathyCallWindow *self,
4244 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4248 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4250 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4252 return priv->ui_manager;
4255 EmpathyGstAudioSrc *
4256 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4258 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4260 return (EmpathyGstAudioSrc *) priv->audio_input;
4263 EmpathyGstVideoSrc *
4264 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4266 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4270 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4271 const gchar *device)
4273 EmpathyGstVideoSrc *video;
4276 /* Restart the camera only if it's already running */
4277 running = (self->priv->video_preview != NULL);
4278 video = empathy_call_window_get_video_src (self);
4281 empathy_call_window_play_camera (self, FALSE);
4283 empathy_video_src_change_device (video, device);
4286 empathy_call_window_play_camera (self, TRUE);