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-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_SPACING 3
77 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
78 #define OVERLAY_MARGIN 6
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 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 /* The roundedness of preview box and placeholders */
103 #define PREVIEW_ROUND_FACTOR 16
105 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
108 PROP_CALL_HANDLER = 1,
112 RINGING, /* Incoming call */
113 CONNECTING, /* Outgoing call */
114 CONNECTED, /* Connected */
115 HELD, /* Connected, but on hold */
116 DISCONNECTED, /* Disconnected */
117 REDIALING /* Redialing (special case of CONNECTING) */
121 CAMERA_STATE_OFF = 0,
127 PREVIEW_POS_TOP_LEFT,
128 PREVIEW_POS_TOP_RIGHT,
129 PREVIEW_POS_BOTTOM_LEFT,
130 PREVIEW_POS_BOTTOM_RIGHT,
133 struct _EmpathyCallWindowPriv
135 gboolean dispose_has_run;
136 EmpathyCallHandler *handler;
138 EmpathyContact *contact;
140 EmpathyCameraMonitor *camera_monitor;
145 GtkUIManager *ui_manager;
146 GtkWidget *errors_vbox;
147 /* widget displays the video received from the remote user. This widget is
148 * alive only during call. */
149 ClutterActor *video_output;
150 ClutterActor *video_preview;
151 ClutterActor *drag_preview;
152 ClutterActor *preview_shown_button;
153 ClutterActor *preview_hidden_button;
154 ClutterActor *preview_rectangle1;
155 ClutterActor *preview_rectangle2;
156 ClutterActor *preview_rectangle3;
157 ClutterActor *preview_rectangle4;
158 ClutterActor *preview_spinner_actor;
159 GtkWidget *preview_spinner_widget;
160 GtkWidget *video_container;
161 GtkWidget *remote_user_avatar_widget;
162 GtkWidget *remote_user_avatar_toolbar;
163 GtkWidget *remote_user_name_toolbar;
164 GtkWidget *remote_user_status_toolbar;
165 GtkWidget *status_label;
166 GtkWidget *hangup_button;
167 GtkWidget *audio_call_button;
168 GtkWidget *video_call_button;
169 GtkWidget *mic_button;
170 GtkWidget *volume_button;
171 GtkWidget *camera_button;
172 GtkWidget *dialpad_button;
174 GtkWidget *bottom_toolbar;
175 ClutterActor *floating_toolbar;
177 GtkAction *menu_fullscreen;
178 GtkAction *menu_swap_camera;
180 ClutterState *transitions;
182 /* The main box covering all the stage, contaning remote avatar/video */
183 ClutterActor *video_box;
184 ClutterLayoutManager *video_layout;
186 /* A bin layout manager containing a bin for previews
187 * and the floating toolbar */
188 ClutterActor *overlay_bin;
189 ClutterLayoutManager *overlay_layout;
191 /* Bin layout for the previews */
192 ClutterActor *preview_box;
193 ClutterLayoutManager *preview_layout;
195 /* Coordinates of the preview drag event's start. */
196 PreviewPosition preview_pos;
198 /* We keep a reference on the hbox which contains the main content so we can
199 easilly repack everything when toggling fullscreen */
200 GtkWidget *content_hbox;
202 /* These are used to accept or reject an incoming call when the status
204 GtkWidget *incoming_call_dialog;
205 TpCallChannel *pending_channel;
206 TpChannelDispatchOperation *pending_cdo;
207 TpAddDispatchOperationContext *pending_context;
209 gulong video_output_motion_handler_id;
210 guint bus_message_source_id;
212 GtkWidget *dtmf_panel;
215 GtkWidget *details_vbox;
216 GtkWidget *vcodec_encoding_label;
217 GtkWidget *acodec_encoding_label;
218 GtkWidget *vcodec_decoding_label;
219 GtkWidget *acodec_decoding_label;
221 GtkWidget *audio_remote_candidate_label;
222 GtkWidget *audio_local_candidate_label;
223 GtkWidget *video_remote_candidate_label;
224 GtkWidget *video_local_candidate_label;
225 GtkWidget *video_remote_candidate_info_img;
226 GtkWidget *video_local_candidate_info_img;
227 GtkWidget *audio_remote_candidate_info_img;
228 GtkWidget *audio_local_candidate_info_img;
230 GstElement *video_input;
231 GstElement *video_preview_sink;
232 GstElement *video_output_sink;
233 GstElement *audio_input;
234 GstElement *audio_output;
235 gboolean audio_output_added;
236 GstElement *pipeline;
237 GstElement *video_tee;
247 gboolean call_started;
248 gboolean sending_video;
249 CameraState camera_state;
251 EmpathyCallWindowFullscreen *fullscreen;
252 gboolean is_fullscreen;
257 guint inactivity_src;
259 /* Those fields represent the state of the window before it actually was in
261 gboolean dialpad_was_visible_before_fs;
262 gint original_width_before_fs;
263 gint original_height_before_fs;
265 gint x, y, w, h, dialpad_width;
268 /* TRUE if the call should be started when the pipeline is playing */
269 gboolean start_call_when_playing;
270 /* TRUE if we requested to set the pipeline in the playing state */
271 gboolean pipeline_playing;
273 EmpathySoundManager *sound_mgr;
276 EmpathyMicMenu *mic_menu;
277 EmpathyCameraMenu *camera_menu;
282 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
284 static void empathy_call_window_realized_cb (GtkWidget *widget,
285 EmpathyCallWindow *window);
287 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
288 GdkEvent *event, EmpathyCallWindow *window);
290 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
291 GdkEventWindowState *event, EmpathyCallWindow *window);
293 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
296 static void empathy_call_window_hangup_cb (gpointer object,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_fullscreen_cb (gpointer object,
300 EmpathyCallWindow *window);
302 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
304 static gboolean empathy_call_window_video_button_press_cb (
305 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
307 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
308 GdkEventKey *event, EmpathyCallWindow *window);
310 static gboolean empathy_call_window_video_output_motion_notify (
311 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
313 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
316 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
318 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
319 EmpathyCallWindow *window);
321 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
323 static void empathy_call_window_status_message (EmpathyCallWindow *window,
326 static gboolean empathy_call_window_bus_message (GstBus *bus,
327 GstMessage *message, gpointer user_data);
329 static gboolean empathy_call_window_update_timer (gpointer user_data);
332 make_background_transparent (GtkClutterActor *actor)
334 GdkRGBA transparent = { 0., 0., 0., 0. };
337 widget = gtk_clutter_actor_get_widget (actor);
338 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
342 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
345 gtk_widget_set_visible (self->priv->hangup_button, show);
346 gtk_widget_set_visible (self->priv->audio_call_button, !show);
347 gtk_widget_set_visible (self->priv->video_call_button, !show);
351 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
352 EmpathyCallWindow *self)
354 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
355 empathy_call_window_restart_call (self);
359 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
360 EmpathyCallWindow *self)
362 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
363 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
364 empathy_call_window_restart_call (self);
368 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
370 EmpathyCallWindow *self)
375 g_object_get (self->priv->handler, "call-channel", &call, NULL);
377 tones[0] = tp_dtmf_event_to_char (event);
379 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
381 g_object_unref (call);
385 empathy_call_window_show_video_output (EmpathyCallWindow *self,
388 if (self->priv->video_output != NULL)
389 g_object_set (self->priv->video_output, "visible", show, NULL);
391 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
393 clutter_actor_raise_top (self->priv->overlay_bin);
397 create_video_output_widget (EmpathyCallWindow *self)
399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
401 g_assert (priv->video_output == NULL);
402 g_assert (priv->pipeline != NULL);
404 priv->video_output = clutter_texture_new ();
406 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
409 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
410 if (priv->video_output_sink == NULL)
411 g_error ("Missing cluttersink");
413 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
415 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
418 gtk_widget_add_events (priv->video_container,
419 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
420 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
421 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
425 create_video_input (EmpathyCallWindow *self)
427 EmpathyCallWindowPriv *priv = GET_PRIV (self);
429 g_assert (priv->video_input == NULL);
430 priv->video_input = empathy_video_src_new ();
431 gst_object_ref_sink (priv->video_input);
435 audio_control_volume_to_element (GBinding *binding,
436 const GValue *source_value,
437 GValue *target_value,
440 /* AudioControl volume is 0-255, with -1 for unknown */
443 hv = g_value_get_int (source_value);
448 g_value_set_double (target_value, hv/255.0);
454 element_volume_to_audio_control (GBinding *binding,
455 const GValue *source_value,
456 GValue *target_value,
461 ev = g_value_get_double (source_value);
462 ev = CLAMP (ev, 0.0, 1.0);
464 g_value_set_int (target_value, ev * 255);
469 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
470 EmpathyCallWindow *self)
473 g_object_get (obj, "mute", &muted, NULL);
475 self->priv->muted = muted;
476 if (muted && self->priv->transitions)
477 clutter_state_set_state (self->priv->transitions, "fade-in");
479 empathy_call_window_update_timer (self);
483 create_audio_input (EmpathyCallWindow *self)
485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
487 g_assert (priv->audio_input == NULL);
488 priv->audio_input = empathy_audio_src_new ();
489 gst_object_ref_sink (priv->audio_input);
491 g_signal_connect (priv->audio_input, "notify::mute",
492 G_CALLBACK (audio_input_mute_notify_cb), self);
494 g_object_bind_property (priv->mic_button, "active",
495 priv->audio_input, "mute",
496 G_BINDING_BIDIRECTIONAL |
497 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
502 add_video_preview_to_pipeline (EmpathyCallWindow *self)
504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
507 g_assert (priv->video_preview != NULL);
508 g_assert (priv->pipeline != NULL);
509 g_assert (priv->video_input != NULL);
510 g_assert (priv->video_tee != NULL);
512 preview = priv->video_preview_sink;
514 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
516 g_warning ("Could not add video input to pipeline");
520 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
522 g_warning ("Could not add video preview to pipeline");
526 if (!gst_element_link (priv->video_input, priv->video_tee))
528 g_warning ("Could not link video input to video tee");
532 if (!gst_element_link (priv->video_tee, preview))
534 g_warning ("Could not link video tee to video preview");
540 empathy_call_window_disable_camera_cb (GtkAction *action,
541 EmpathyCallWindow *self)
543 clutter_actor_destroy (self->priv->preview_hidden_button);
545 gtk_toggle_tool_button_set_active (
546 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
550 empathy_call_window_minimise_camera_cb (GtkAction *action,
551 EmpathyCallWindow *self)
553 clutter_actor_hide (self->priv->video_preview);
554 clutter_actor_show (self->priv->preview_hidden_button);
558 empathy_call_window_maximise_camera_cb (GtkAction *action,
559 EmpathyCallWindow *self)
561 clutter_actor_show (self->priv->video_preview);
562 clutter_actor_hide (self->priv->preview_hidden_button);
566 empathy_call_window_swap_camera_cb (GtkAction *action,
567 EmpathyCallWindow *self)
569 const GList *cameras, *l;
572 DEBUG ("Swapping the camera");
574 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
575 current_cam = empathy_video_src_dup_device (
576 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
578 for (l = cameras; l != NULL; l = l->next)
580 EmpathyCamera *camera = l->data;
582 if (!tp_strdiff (camera->device, current_cam))
587 next = l->next->data;
589 next = cameras->data;
591 /* EmpathyCameraMenu will update itself and do the actual change
593 g_settings_set_string (self->priv->settings,
594 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
601 g_free (current_cam);
605 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
606 EmpathyCamera *camera,
607 EmpathyCallWindow *self)
609 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
611 gtk_action_set_visible (self->priv->menu_swap_camera,
612 g_list_length ((GList *) cameras) >= 2);
616 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
617 EmpathyCamera *camera,
618 EmpathyCallWindow *self)
620 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
622 gtk_action_set_visible (self->priv->menu_swap_camera,
623 g_list_length ((GList *) cameras) >= 2);
627 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
628 EmpathyCallWindow *self)
632 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
634 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
635 0, gtk_get_current_event_time ());
636 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
640 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
641 EmpathyCallWindow *self)
645 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
646 "/preview-hidden-menu");
647 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
648 0, gtk_get_current_event_time ());
649 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
652 static ClutterActor *
653 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
654 ClutterBinAlignment x,
655 ClutterBinAlignment y)
657 ClutterActor *rectangle;
659 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
660 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
661 PREVIEW_ROUND_FACTOR));
663 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
665 clutter_actor_hide (rectangle);
671 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
675 self->priv->preview_layout = clutter_bin_layout_new (
676 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
677 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
679 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
681 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
683 self->priv->preview_rectangle1 =
684 empathy_call_window_create_preview_rectangle (self,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
686 self->priv->preview_rectangle2 =
687 empathy_call_window_create_preview_rectangle (self,
688 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
689 self->priv->preview_rectangle3 =
690 empathy_call_window_create_preview_rectangle (self,
691 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
692 self->priv->preview_rectangle4 =
693 empathy_call_window_create_preview_rectangle (self,
694 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
698 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
701 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
702 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
703 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
704 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
708 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
713 guint ret_x = 0, ret_y = 0;
716 if (!clutter_actor_has_allocation (self->priv->preview_box))
719 clutter_actor_get_geometry (self->priv->preview_box, &box);
723 case PREVIEW_POS_TOP_LEFT:
724 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
726 case PREVIEW_POS_TOP_RIGHT:
727 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
728 - SELF_VIDEO_SECTION_WIDTH;
729 ret_y = SELF_VIDEO_SECTION_MARGIN;
731 case PREVIEW_POS_BOTTOM_LEFT:
732 ret_x = SELF_VIDEO_SECTION_MARGIN;
733 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
734 - SELF_VIDEO_SECTION_HEIGHT;
736 case PREVIEW_POS_BOTTOM_RIGHT:
737 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
738 - SELF_VIDEO_SECTION_WIDTH;
739 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
740 - SELF_VIDEO_SECTION_HEIGHT;
743 g_warn_if_reached ();
754 static PreviewPosition
755 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
760 PreviewPosition pos = PREVIEW_POS_NONE;
762 if (!clutter_actor_has_allocation (self->priv->preview_box))
765 clutter_actor_get_geometry (self->priv->preview_box, &box);
767 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
768 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
769 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
770 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
772 pos = PREVIEW_POS_TOP_LEFT;
774 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
775 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
776 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
777 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
779 pos = PREVIEW_POS_TOP_RIGHT;
781 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
782 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
783 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
784 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
786 pos = PREVIEW_POS_BOTTOM_LEFT;
788 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
789 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
790 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
791 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
793 pos = PREVIEW_POS_BOTTOM_RIGHT;
799 static ClutterActor *
800 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
803 ClutterActor *rectangle;
807 case PREVIEW_POS_TOP_LEFT:
808 rectangle = self->priv->preview_rectangle1;
810 case PREVIEW_POS_TOP_RIGHT:
811 rectangle = self->priv->preview_rectangle3;
813 case PREVIEW_POS_BOTTOM_LEFT:
814 rectangle = self->priv->preview_rectangle2;
816 case PREVIEW_POS_BOTTOM_RIGHT:
817 rectangle = self->priv->preview_rectangle4;
827 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
830 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
832 DEBUG ("moving the video preview to %d", pos);
834 self->priv->preview_pos = pos;
838 case PREVIEW_POS_TOP_LEFT:
839 clutter_bin_layout_set_alignment (layout,
840 self->priv->video_preview,
841 CLUTTER_BIN_ALIGNMENT_START,
842 CLUTTER_BIN_ALIGNMENT_START);
844 case PREVIEW_POS_TOP_RIGHT:
845 clutter_bin_layout_set_alignment (layout,
846 self->priv->video_preview,
847 CLUTTER_BIN_ALIGNMENT_END,
848 CLUTTER_BIN_ALIGNMENT_START);
850 case PREVIEW_POS_BOTTOM_LEFT:
851 clutter_bin_layout_set_alignment (layout,
852 self->priv->video_preview,
853 CLUTTER_BIN_ALIGNMENT_START,
854 CLUTTER_BIN_ALIGNMENT_END);
856 case PREVIEW_POS_BOTTOM_RIGHT:
857 clutter_bin_layout_set_alignment (layout,
858 self->priv->video_preview,
859 CLUTTER_BIN_ALIGNMENT_END,
860 CLUTTER_BIN_ALIGNMENT_END);
863 g_warn_if_reached ();
866 g_settings_set_enum (self->priv->settings, "camera-position", pos);
870 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
873 ClutterActor *rectangle;
874 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
876 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
878 empathy_rounded_rectangle_set_border_width (
879 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
880 empathy_rounded_rectangle_set_border_color (
881 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
885 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
886 ClutterActor *rectangle)
888 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
890 clutter_color_shade (&white, 0.55, &darker);
892 empathy_rounded_rectangle_set_border_width (
893 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
894 empathy_rounded_rectangle_set_border_color (
895 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
899 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
901 ClutterActor *rectangle;
903 rectangle = empathy_call_window_get_preview_rectangle (self,
904 self->priv->preview_pos);
906 /* We don't want to darken the rectangle where the preview
909 if (self->priv->preview_rectangle1 != rectangle)
910 empathy_call_window_darken_preview_rectangle (self,
911 self->priv->preview_rectangle1);
913 if (self->priv->preview_rectangle2 != rectangle)
914 empathy_call_window_darken_preview_rectangle (self,
915 self->priv->preview_rectangle2);
917 if (self->priv->preview_rectangle3 != rectangle)
918 empathy_call_window_darken_preview_rectangle (self,
919 self->priv->preview_rectangle3);
921 if (self->priv->preview_rectangle4 != rectangle)
922 empathy_call_window_darken_preview_rectangle (self,
923 self->priv->preview_rectangle4);
927 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
931 ClutterModifierType modifiers,
932 EmpathyCallWindow *self)
934 ClutterActor *stage = clutter_actor_get_stage (actor);
937 self->priv->drag_preview = clutter_clone_new (actor);
939 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
940 self->priv->drag_preview);
942 clutter_actor_transform_stage_point (actor, event_x, event_y,
945 clutter_actor_set_position (self->priv->drag_preview,
946 event_x - rel_x, event_y - rel_y);
948 clutter_drag_action_set_drag_handle (action,
949 self->priv->drag_preview);
951 clutter_actor_set_opacity (actor, 0);
952 clutter_actor_hide (self->priv->preview_shown_button);
954 empathy_call_window_show_preview_rectangles (self, TRUE);
955 empathy_call_window_darken_preview_rectangles (self);
959 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
962 clutter_actor_set_opacity (actor, 255);
966 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
970 ClutterModifierType modifiers,
971 EmpathyCallWindow *self)
976 /* Get the position before destroying the drag actor, otherwise the
977 * preview_box allocation won't be valid and we won't be able to
978 * calculate the position. */
979 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
981 empathy_call_window_get_preview_coordinates (self,
982 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
985 /* Move the preview to the destination and destroy it afterwards */
986 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
989 "signal-swapped-after::completed",
990 clutter_actor_destroy, self->priv->drag_preview,
991 "signal-swapped-after::completed",
992 clutter_actor_show, self->priv->preview_shown_button,
994 empathy_call_window_on_animation_completed_cb, actor,
997 self->priv->drag_preview = NULL;
999 if (pos != PREVIEW_POS_NONE)
1000 empathy_call_window_move_video_preview (self, pos);
1002 empathy_call_window_show_preview_rectangles (self, FALSE);
1006 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1007 ClutterActor *actor,
1010 EmpathyCallWindow *self)
1012 PreviewPosition pos;
1013 gfloat event_x, event_y;
1015 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1017 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1019 if (pos != PREVIEW_POS_NONE)
1020 empathy_call_window_highlight_preview_rectangle (self, pos);
1022 empathy_call_window_darken_preview_rectangles (self);
1026 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1027 ClutterCrossingEvent *event,
1028 EmpathyCallWindow *self)
1030 ClutterActor *rectangle;
1032 rectangle = empathy_call_window_get_preview_rectangle (self,
1033 self->priv->preview_pos);
1035 empathy_call_window_highlight_preview_rectangle (self,
1036 self->priv->preview_pos);
1038 clutter_actor_show (rectangle);
1044 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1045 ClutterCrossingEvent *event,
1046 EmpathyCallWindow *self)
1048 ClutterActor *rectangle;
1050 rectangle = empathy_call_window_get_preview_rectangle (self,
1051 self->priv->preview_pos);
1053 empathy_call_window_darken_preview_rectangle (self, rectangle);
1055 clutter_actor_hide (rectangle);
1061 create_video_preview (EmpathyCallWindow *self)
1063 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1064 ClutterLayoutManager *layout;
1065 ClutterActor *preview;
1067 ClutterAction *action;
1069 PreviewPosition pos;
1071 g_assert (priv->video_preview == NULL);
1073 pos = g_settings_get_enum (priv->settings, "camera-position");
1075 preview = empathy_rounded_texture_new ();
1076 clutter_actor_set_size (preview,
1077 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1079 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1080 if (priv->video_preview_sink == NULL)
1081 g_error ("Missing cluttersink, check your clutter-gst installation");
1082 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1083 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1085 /* Add a little offset to the video preview */
1086 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1087 CLUTTER_BIN_ALIGNMENT_CENTER);
1088 priv->video_preview = clutter_box_new (layout);
1089 clutter_actor_set_size (priv->video_preview,
1090 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1091 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1093 /* Spinner for when changing the camera device */
1094 priv->preview_spinner_widget = gtk_spinner_new ();
1095 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1097 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1098 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1099 gtk_widget_show (priv->preview_spinner_widget);
1102 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1103 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1104 priv->preview_spinner_widget);
1105 clutter_actor_set_size (priv->preview_spinner_actor,
1106 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1107 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1108 clutter_actor_hide (priv->preview_spinner_actor);
1110 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1112 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1113 priv->preview_spinner_actor);
1115 g_object_set (priv->video_preview_sink,
1120 /* Translators: this is an "Info" label. It should be as short
1122 button = gtk_button_new_with_label (_("i"));
1123 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1124 clutter_actor_set_size (b, 24, 24);
1125 clutter_actor_set_margin_right (b, 4);
1126 clutter_actor_set_margin_bottom (b, 2);
1127 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1129 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1130 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1132 g_signal_connect (button, "clicked",
1133 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1136 /* Translators: this is an "Info" label. It should be as short
1138 button = gtk_button_new_with_label (_("i"));
1139 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1140 clutter_actor_set_size (b, 24, 24);
1141 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1143 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1144 priv->preview_hidden_button,
1145 CLUTTER_BIN_ALIGNMENT_START,
1146 CLUTTER_BIN_ALIGNMENT_END);
1148 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1150 clutter_actor_hide (priv->preview_hidden_button);
1152 g_signal_connect (button, "clicked",
1153 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1156 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1157 priv->video_preview,
1158 CLUTTER_BIN_ALIGNMENT_START,
1159 CLUTTER_BIN_ALIGNMENT_END);
1161 empathy_call_window_move_video_preview (self, pos);
1163 action = clutter_drag_action_new ();
1164 g_signal_connect (action, "drag-begin",
1165 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1166 g_signal_connect (action, "drag-end",
1167 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1168 g_signal_connect (action, "drag-motion",
1169 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1171 g_signal_connect (preview, "enter-event",
1172 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1173 g_signal_connect (preview, "leave-event",
1174 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1176 clutter_actor_add_action (preview, action);
1177 clutter_actor_set_reactive (preview, TRUE);
1178 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1182 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1184 clutter_actor_show (self->priv->preview_spinner_actor);
1185 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1189 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1191 clutter_actor_hide (self->priv->preview_spinner_actor);
1192 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1196 empathy_call_window_play_camera (EmpathyCallWindow *self,
1199 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1200 GstElement *preview;
1203 if (priv->video_preview == NULL)
1205 create_video_preview (self);
1206 add_video_preview_to_pipeline (self);
1211 state = GST_STATE_PLAYING;
1215 empathy_call_window_start_camera_spinning (self);
1216 state = GST_STATE_NULL;
1219 preview = priv->video_preview_sink;
1221 gst_element_set_state (preview, state);
1222 gst_element_set_state (priv->video_tee, state);
1223 gst_element_set_state (priv->video_input, state);
1227 display_video_preview (EmpathyCallWindow *self,
1230 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1232 if (priv->video_preview == NULL)
1234 create_video_preview (self);
1235 add_video_preview_to_pipeline (self);
1240 /* Display the video preview */
1241 DEBUG ("Show video preview");
1243 empathy_call_window_play_camera (self, TRUE);
1244 clutter_actor_show (priv->video_preview);
1245 clutter_actor_raise_top (priv->floating_toolbar);
1249 /* Hide the video preview */
1250 DEBUG ("Hide video preview");
1252 if (priv->video_preview != NULL)
1254 clutter_actor_hide (priv->video_preview);
1255 empathy_call_window_play_camera (self, FALSE);
1261 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1263 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1265 empathy_call_window_status_message (window, _("Connecting…"));
1266 priv->call_state = CONNECTING;
1268 /* Show the toolbar */
1269 clutter_state_set_state (priv->transitions, "fade-in");
1272 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1273 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1277 disable_camera (EmpathyCallWindow *self)
1279 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1281 if (priv->camera_state == CAMERA_STATE_OFF)
1284 DEBUG ("Disable camera");
1286 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1288 priv->camera_state = CAMERA_STATE_OFF;
1292 enable_camera (EmpathyCallWindow *self)
1294 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1296 if (priv->camera_state == CAMERA_STATE_ON)
1299 if (priv->video_input == NULL)
1301 DEBUG ("Can't enable camera, no input");
1305 DEBUG ("Enable camera");
1307 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1309 priv->camera_state = CAMERA_STATE_ON;
1313 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1314 EmpathyCallWindow *self)
1316 if (gtk_toggle_tool_button_get_active (toggle))
1317 enable_camera (self);
1319 disable_camera (self);
1323 create_pipeline (EmpathyCallWindow *self)
1325 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1328 g_assert (priv->pipeline == NULL);
1330 priv->pipeline = gst_pipeline_new (NULL);
1331 priv->pipeline_playing = FALSE;
1333 priv->video_tee = gst_element_factory_make ("tee", NULL);
1334 gst_object_ref_sink (priv->video_tee);
1336 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1338 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1339 priv->bus_message_source_id = gst_bus_add_watch (bus,
1340 empathy_call_window_bus_message, self);
1342 g_object_unref (bus);
1346 empathy_call_window_settings_cb (GtkAction *action,
1347 EmpathyCallWindow *self)
1349 gchar *args = g_strdup_printf ("-p %s",
1350 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1352 empathy_launch_program (BIN_DIR, "empathy", args);
1358 empathy_call_window_contents_cb (GtkAction *action,
1359 EmpathyCallWindow *self)
1361 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1365 empathy_call_window_debug_cb (GtkAction *action,
1366 EmpathyCallWindow *self)
1368 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1372 empathy_call_window_about_cb (GtkAction *action,
1373 EmpathyCallWindow *self)
1375 empathy_about_dialog_new (GTK_WINDOW (self));
1379 empathy_call_window_toolbar_timeout (gpointer data)
1381 EmpathyCallWindow *self = data;
1383 /* We don't want to hide the toolbar if we're not in a call, as
1384 * to show the call status all the time. Also don't hide if we're muted
1385 * to prevent the awkward, talking when muted situation */
1386 if (self->priv->call_state != CONNECTING &&
1387 self->priv->call_state != DISCONNECTED &&
1389 clutter_state_set_state (self->priv->transitions, "fade-out");
1395 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1397 EmpathyCallWindow *self)
1399 clutter_state_set_state (self->priv->transitions, "fade-in");
1401 if (self->priv->inactivity_src > 0)
1402 g_source_remove (self->priv->inactivity_src);
1404 self->priv->inactivity_src = g_timeout_add_seconds (3,
1405 empathy_call_window_toolbar_timeout, self);
1411 empathy_call_window_configure_event_cb (GtkWidget *widget,
1413 EmpathyCallWindow *self)
1415 GdkWindow *gdk_window;
1416 GdkWindowState window_state;
1418 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1419 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1421 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1422 &self->priv->dialpad_width, NULL);
1424 gdk_window = gtk_widget_get_window (widget);
1425 window_state = gdk_window_get_state (gdk_window);
1426 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1432 empathy_call_window_destroyed_cb (GtkWidget *object,
1433 EmpathyCallWindow *self)
1435 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1437 /* Save the geometry as if the dialpad was hidden. */
1438 empathy_geometry_save_values (GTK_WINDOW (self),
1439 self->priv->x, self->priv->y,
1440 self->priv->w - self->priv->dialpad_width, self->priv->h,
1441 self->priv->maximized);
1446 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1448 EmpathyCallWindow *self)
1450 switch (response_id)
1452 case GTK_RESPONSE_ACCEPT:
1453 tp_channel_dispatch_operation_handle_with_async (
1454 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1456 tp_clear_object (&self->priv->pending_cdo);
1457 tp_clear_object (&self->priv->pending_channel);
1458 tp_clear_object (&self->priv->pending_context);
1461 case GTK_RESPONSE_CANCEL:
1462 tp_channel_dispatch_operation_close_channels_async (
1463 self->priv->pending_cdo, NULL, NULL);
1465 empathy_call_window_status_message (self, _("Disconnected"));
1466 self->priv->call_state = DISCONNECTED;
1469 g_warn_if_reached ();
1474 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1478 g_assert (self->priv->call_state != CONNECTED);
1480 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1482 empathy_call_window_status_message (self, _("Incoming call"));
1483 self->priv->call_state = RINGING;
1485 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1486 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1487 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1488 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1489 empathy_contact_get_alias (self->priv->contact));
1491 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1492 _("Reject"), GTK_RESPONSE_CANCEL,
1493 _("Answer"), GTK_RESPONSE_ACCEPT,
1496 g_signal_connect (self->priv->incoming_call_dialog, "response",
1497 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1498 gtk_widget_show (self->priv->incoming_call_dialog);
1502 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1506 EmpathyCallWindow *self)
1508 tp_clear_object (&self->priv->pending_cdo);
1509 tp_clear_object (&self->priv->pending_channel);
1510 tp_clear_object (&self->priv->pending_context);
1512 /* We don't know if the incoming call has been accepted or not, so we
1513 * assume it hasn't and if it has, we'll set the proper status when
1514 * we get the new handler. */
1515 empathy_call_window_status_message (self, _("Disconnected"));
1516 self->priv->call_state = DISCONNECTED;
1518 gtk_widget_destroy (self->priv->incoming_call_dialog);
1519 self->priv->incoming_call_dialog = NULL;
1523 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1524 TpCallChannel *channel,
1525 TpChannelDispatchOperation *dispatch_operation,
1526 TpAddDispatchOperationContext *context)
1528 g_assert (self->priv->pending_channel == NULL);
1529 g_assert (self->priv->pending_context == NULL);
1530 g_assert (self->priv->pending_cdo == NULL);
1532 /* Start ringing and delay until the user answers or hangs. */
1533 self->priv->pending_channel = g_object_ref (channel);
1534 self->priv->pending_context = g_object_ref (context);
1535 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1537 g_signal_connect (self->priv->pending_cdo, "invalidated",
1538 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1540 empathy_call_window_set_state_ringing (self);
1541 tp_add_dispatch_operation_context_accept (context);
1545 empathy_call_window_init (EmpathyCallWindow *self)
1547 EmpathyCallWindowPriv *priv;
1549 GtkWidget *top_vbox;
1551 ClutterConstraint *constraint;
1552 ClutterActor *remote_avatar;
1553 GtkCssProvider *provider;
1554 ClutterColor black = { 0, 0, 0, 0 };
1555 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1556 OVERLAY_MARGIN, OVERLAY_MARGIN };
1558 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1559 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1561 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1562 priv->timer = g_timer_new ();
1564 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1565 gui = empathy_builder_get_file (filename,
1566 "call_window_vbox", &top_vbox,
1567 "errors_vbox", &priv->errors_vbox,
1568 "pane", &priv->pane,
1569 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1570 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1571 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1572 "status_label", &priv->status_label,
1573 "audiocall", &priv->audio_call_button,
1574 "videocall", &priv->video_call_button,
1575 "microphone", &priv->mic_button,
1576 "volume", &priv->volume_button,
1577 "camera", &priv->camera_button,
1578 "hangup", &priv->hangup_button,
1579 "dialpad", &priv->dialpad_button,
1580 "toolbar", &priv->toolbar,
1581 "bottom_toolbar", &priv->bottom_toolbar,
1582 "ui_manager", &priv->ui_manager,
1583 "menufullscreen", &priv->menu_fullscreen,
1584 "menupreviewswap", &priv->menu_swap_camera,
1585 "details_vbox", &priv->details_vbox,
1586 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1587 "acodec_encoding_label", &priv->acodec_encoding_label,
1588 "acodec_decoding_label", &priv->acodec_decoding_label,
1589 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1590 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1591 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1592 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1593 "video_local_candidate_label", &priv->video_local_candidate_label,
1594 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1595 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1596 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1597 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1601 empathy_builder_connect (gui, self,
1602 "hangup", "clicked", empathy_call_window_hangup_cb,
1603 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1604 "videocall", "clicked", empathy_call_window_video_call_cb,
1605 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1606 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1607 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1608 "menusettings", "activate", empathy_call_window_settings_cb,
1609 "menucontents", "activate", empathy_call_window_contents_cb,
1610 "menudebug", "activate", empathy_call_window_debug_cb,
1611 "menuabout", "activate", empathy_call_window_about_cb,
1612 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1613 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1614 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1615 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1618 /* FIXME: we should use a stock "OSD" style class for the toolbar,
1619 * once it's available in GTK+/Adwaita.
1621 provider = gtk_css_provider_new ();
1622 gtk_css_provider_load_from_data (provider,
1623 "#CallFloatingToolbar { border-radius: 6px; }", -1, NULL);
1624 gtk_style_context_add_provider (
1625 gtk_widget_get_style_context (priv->bottom_toolbar),
1626 GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
1627 g_object_unref (provider);
1629 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1631 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1633 g_object_bind_property (priv->camera_monitor, "available",
1634 priv->camera_button, "sensitive",
1635 G_BINDING_SYNC_CREATE);
1637 g_signal_connect (priv->camera_monitor, "added",
1638 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1639 g_signal_connect (priv->camera_monitor, "removed",
1640 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1642 priv->lock = g_mutex_new ();
1644 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1646 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1647 CONTENT_HBOX_SPACING);
1648 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1651 /* main contents remote avatar/video box */
1652 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1653 CLUTTER_BIN_ALIGNMENT_FILL);
1655 priv->video_box = clutter_box_new (priv->video_layout);
1657 priv->video_container = gtk_clutter_embed_new ();
1659 gtk_widget_set_size_request (priv->video_container,
1660 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1662 /* Set the background black */
1663 clutter_stage_set_color (
1664 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1665 GTK_CLUTTER_EMBED (priv->video_container))),
1668 clutter_container_add (
1669 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1670 GTK_CLUTTER_EMBED (priv->video_container))),
1674 constraint = clutter_bind_constraint_new (
1675 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1676 CLUTTER_BIND_SIZE, 0);
1677 clutter_actor_add_constraint (priv->video_box, constraint);
1679 priv->remote_user_avatar_widget = gtk_image_new ();
1680 remote_avatar = gtk_clutter_actor_new_with_contents (
1681 priv->remote_user_avatar_widget);
1682 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1684 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1687 /* create the overlay bin */
1688 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1689 CLUTTER_BIN_ALIGNMENT_CENTER);
1690 priv->overlay_bin = clutter_actor_new ();
1691 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1693 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1695 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1697 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1699 empathy_call_window_create_preview_rectangles (self);
1701 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1702 priv->video_container, TRUE, TRUE,
1703 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1705 create_pipeline (self);
1706 create_video_output_widget (self);
1707 create_audio_input (self);
1708 create_video_input (self);
1710 priv->floating_toolbar = gtk_clutter_actor_new ();
1711 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1712 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1714 gtk_widget_reparent (priv->bottom_toolbar,
1715 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1717 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1718 priv->floating_toolbar,
1719 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1721 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1723 clutter_actor_raise_top (priv->floating_toolbar);
1725 /* Transitions for the floating toolbar */
1726 priv->transitions = clutter_state_new ();
1728 /* all transitions last for 2s */
1729 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1731 /* transition from any state to "fade-out" state */
1732 clutter_state_set (priv->transitions, NULL, "fade-out",
1733 priv->floating_toolbar,
1734 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1737 /* transition from any state to "fade-in" state */
1738 clutter_state_set (priv->transitions, NULL, "fade-in",
1739 priv->floating_toolbar,
1740 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1743 /* put the actor into the "fade-in" state with no animation */
1744 clutter_state_warp_to_state (priv->transitions, "fade-in");
1746 /* The call will be started as soon the pipeline is playing */
1747 priv->start_call_when_playing = TRUE;
1749 priv->dtmf_panel = empathy_dialpad_widget_new ();
1750 g_signal_connect (priv->dtmf_panel, "start-tone",
1751 G_CALLBACK (dtmf_start_tone_cb), self);
1753 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1756 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1759 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1761 gtk_widget_show_all (top_vbox);
1763 gtk_widget_hide (priv->dtmf_panel);
1764 gtk_widget_hide (priv->details_vbox);
1766 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1768 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1769 priv->video_container);
1771 /* We hide the bottom toolbar after 3s of inactivity and show it
1772 * again on mouse movement */
1773 priv->inactivity_src = g_timeout_add_seconds (3,
1774 empathy_call_window_toolbar_timeout, self);
1776 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1777 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1779 g_signal_connect (G_OBJECT (self), "realize",
1780 G_CALLBACK (empathy_call_window_realized_cb), self);
1782 g_signal_connect (G_OBJECT (self), "delete-event",
1783 G_CALLBACK (empathy_call_window_delete_cb), self);
1785 g_signal_connect (G_OBJECT (self), "window-state-event",
1786 G_CALLBACK (empathy_call_window_state_event_cb), self);
1788 g_signal_connect (G_OBJECT (self), "key-press-event",
1789 G_CALLBACK (empathy_call_window_key_press_cb), self);
1791 g_signal_connect (self, "motion-notify-event",
1792 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1794 g_object_ref (priv->ui_manager);
1795 g_object_unref (gui);
1797 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1798 priv->mic_menu = empathy_mic_menu_new (self);
1799 priv->camera_menu = empathy_camera_menu_new (self);
1801 empathy_call_window_show_hangup_button (self, TRUE);
1803 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1804 /* These signals are used to track the window position and save it
1805 * when the window is destroyed. We need to do this as we don't want
1806 * the window geometry to be saved with the dialpad taken into account. */
1807 g_signal_connect (self, "destroy",
1808 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1809 g_signal_connect (self, "configure-event",
1810 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1811 g_signal_connect (self, "window-state-event",
1812 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1814 /* Don't display labels in both toolbars */
1815 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1818 /* Instead of specifying a width and a height, we specify only one size. That's
1819 because we want a square avatar icon. */
1821 init_contact_avatar_with_size (EmpathyContact *contact,
1822 GtkWidget *image_widget,
1825 GdkPixbuf *pixbuf_avatar = NULL;
1827 if (contact != NULL)
1829 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1833 if (pixbuf_avatar == NULL)
1835 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1836 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1839 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1841 if (pixbuf_avatar != NULL)
1842 g_object_unref (pixbuf_avatar);
1846 set_window_title (EmpathyCallWindow *self)
1848 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1851 if (priv->contact != NULL)
1853 /* translators: Call is a noun and %s is the contact name. This string
1854 * is used in the window title */
1855 tmp = g_strdup_printf (_("Call with %s"),
1856 empathy_contact_get_alias (priv->contact));
1857 gtk_window_set_title (GTK_WINDOW (self), tmp);
1862 g_warning ("Unknown remote contact!");
1867 set_remote_user_name (EmpathyCallWindow *self,
1868 EmpathyContact *contact)
1870 const gchar *alias = empathy_contact_get_alias (contact);
1871 const gchar *status = empathy_contact_get_status (contact);
1873 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1875 if (status != NULL) {
1878 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1879 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1883 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1889 contact_name_changed_cb (EmpathyContact *contact,
1891 EmpathyCallWindow *self)
1893 set_window_title (self);
1894 set_remote_user_name (self, contact);
1898 contact_presence_changed_cb (EmpathyContact *contact,
1900 EmpathyCallWindow *self)
1902 set_remote_user_name (self, contact);
1906 contact_avatar_changed_cb (EmpathyContact *contact,
1908 EmpathyCallWindow *self)
1911 GtkAllocation allocation;
1912 GtkWidget *avatar_widget;
1914 avatar_widget = self->priv->remote_user_avatar_widget;
1916 gtk_widget_get_allocation (avatar_widget, &allocation);
1917 size = allocation.height;
1921 /* the widget is not allocated yet, set a default size */
1922 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1923 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1926 init_contact_avatar_with_size (contact, avatar_widget, size);
1928 avatar_widget = self->priv->remote_user_avatar_toolbar;
1930 gtk_widget_get_allocation (avatar_widget, &allocation);
1931 size = allocation.height;
1935 /* the widget is not allocated yet, set a default size */
1936 size = SMALL_TOOLBAR_SIZE;
1939 init_contact_avatar_with_size (contact, avatar_widget, size);
1943 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1944 EmpathyCallHandler *handler)
1946 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1948 tp_g_signal_connect_object (priv->contact, "notify::name",
1949 G_CALLBACK (contact_name_changed_cb), self, 0);
1950 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1951 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1952 tp_g_signal_connect_object (priv->contact, "notify::presence",
1953 G_CALLBACK (contact_presence_changed_cb), self, 0);
1955 set_window_title (self);
1956 set_remote_user_name (self, priv->contact);
1958 init_contact_avatar_with_size (priv->contact,
1959 priv->remote_user_avatar_widget,
1960 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1961 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1963 init_contact_avatar_with_size (priv->contact,
1964 priv->remote_user_avatar_toolbar,
1965 SMALL_TOOLBAR_SIZE);
1967 /* The remote avatar is shown by default and will be hidden when we receive
1968 video from the remote side. */
1969 clutter_actor_hide (priv->video_output);
1970 gtk_widget_show (priv->remote_user_avatar_widget);
1974 update_send_codec (EmpathyCallWindow *self,
1977 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1984 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1985 widget = priv->acodec_encoding_label;
1989 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1990 widget = priv->vcodec_encoding_label;
1996 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1997 gtk_label_set_text (GTK_LABEL (widget), tmp);
2002 send_audio_codec_notify_cb (GObject *object,
2006 EmpathyCallWindow *self = user_data;
2008 update_send_codec (self, TRUE);
2012 send_video_codec_notify_cb (GObject *object,
2016 EmpathyCallWindow *self = user_data;
2018 update_send_codec (self, FALSE);
2022 update_recv_codec (EmpathyCallWindow *self,
2025 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2028 GString *str = NULL;
2032 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2033 widget = priv->acodec_decoding_label;
2037 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2038 widget = priv->vcodec_decoding_label;
2044 for (l = codecs; l != NULL; l = g_list_next (l))
2046 FsCodec *codec = l->data;
2049 str = g_string_new (NULL);
2051 g_string_append (str, ", ");
2053 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2057 gtk_label_set_text (GTK_LABEL (widget), str->str);
2058 g_string_free (str, TRUE);
2062 recv_audio_codecs_notify_cb (GObject *object,
2066 EmpathyCallWindow *self = user_data;
2068 update_recv_codec (self, TRUE);
2072 recv_video_codecs_notify_cb (GObject *object,
2076 EmpathyCallWindow *self = user_data;
2078 update_recv_codec (self, FALSE);
2081 static const gchar *
2082 candidate_type_to_str (FsCandidate *candidate)
2084 switch (candidate->type)
2086 case FS_CANDIDATE_TYPE_HOST:
2088 case FS_CANDIDATE_TYPE_SRFLX:
2089 return "server reflexive";
2090 case FS_CANDIDATE_TYPE_PRFLX:
2091 return "peer reflexive";
2092 case FS_CANDIDATE_TYPE_RELAY:
2094 case FS_CANDIDATE_TYPE_MULTICAST:
2101 static const gchar *
2102 candidate_type_to_desc (FsCandidate *candidate)
2104 switch (candidate->type)
2106 case FS_CANDIDATE_TYPE_HOST:
2107 return _("The IP address as seen by the machine");
2108 case FS_CANDIDATE_TYPE_SRFLX:
2109 return _("The IP address as seen by a server on the Internet");
2110 case FS_CANDIDATE_TYPE_PRFLX:
2111 return _("The IP address of the peer as seen by the other side");
2112 case FS_CANDIDATE_TYPE_RELAY:
2113 return _("The IP address of a relay server");
2114 case FS_CANDIDATE_TYPE_MULTICAST:
2115 return _("The IP address of the multicast group");
2122 update_candidat_widget (EmpathyCallWindow *self,
2125 FsCandidate *candidate)
2129 g_assert (candidate != NULL);
2130 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2131 candidate->port, candidate_type_to_str (candidate));
2133 gtk_label_set_text (GTK_LABEL (label), str);
2134 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2140 candidates_changed_cb (GObject *object,
2142 EmpathyCallWindow *self)
2144 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2145 FsCandidate *candidate = NULL;
2147 if (type == FS_MEDIA_TYPE_VIDEO)
2149 /* Update remote candidate */
2150 candidate = empathy_call_handler_get_video_remote_candidate (
2153 update_candidat_widget (self, priv->video_remote_candidate_label,
2154 priv->video_remote_candidate_info_img, candidate);
2156 /* Update local candidate */
2157 candidate = empathy_call_handler_get_video_local_candidate (
2160 update_candidat_widget (self, priv->video_local_candidate_label,
2161 priv->video_local_candidate_info_img, candidate);
2165 /* Update remote candidate */
2166 candidate = empathy_call_handler_get_audio_remote_candidate (
2169 update_candidat_widget (self, priv->audio_remote_candidate_label,
2170 priv->audio_remote_candidate_info_img, candidate);
2172 /* Update local candidate */
2173 candidate = empathy_call_handler_get_audio_local_candidate (
2176 update_candidat_widget (self, priv->audio_local_candidate_label,
2177 priv->audio_local_candidate_info_img, candidate);
2182 empathy_call_window_constructed (GObject *object)
2184 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2185 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2186 TpCallChannel *call;
2189 g_assert (priv->handler != NULL);
2191 g_object_get (priv->handler, "call-channel", &call, NULL);
2192 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2193 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2194 tp_clear_object (&call);
2196 priv->contact = empathy_call_handler_get_contact (priv->handler);
2197 g_assert (priv->contact != NULL);
2198 g_object_ref (priv->contact);
2200 if (!empathy_contact_can_voip_video (priv->contact))
2202 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2203 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2206 empathy_call_window_setup_avatars (self, priv->handler);
2207 empathy_call_window_set_state_connecting (self);
2209 if (!empathy_call_handler_has_initial_video (priv->handler))
2211 gtk_toggle_tool_button_set_active (
2212 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2214 /* If call has InitialVideo, the preview will be started once the call has
2215 * been started (start_call()). */
2217 update_send_codec (self, TRUE);
2218 update_send_codec (self, FALSE);
2219 update_recv_codec (self, TRUE);
2220 update_recv_codec (self, FALSE);
2222 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2223 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2224 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2225 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2226 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2227 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2228 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2229 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2231 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2232 G_CALLBACK (candidates_changed_cb), self, 0);
2235 static void empathy_call_window_dispose (GObject *object);
2236 static void empathy_call_window_finalize (GObject *object);
2239 empathy_call_window_set_property (GObject *object,
2240 guint property_id, const GValue *value, GParamSpec *pspec)
2242 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2244 switch (property_id)
2246 case PROP_CALL_HANDLER:
2247 priv->handler = g_value_dup_object (value);
2250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2255 empathy_call_window_get_property (GObject *object,
2256 guint property_id, GValue *value, GParamSpec *pspec)
2258 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2260 switch (property_id)
2262 case PROP_CALL_HANDLER:
2263 g_value_set_object (value, priv->handler);
2266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2271 empathy_call_window_class_init (
2272 EmpathyCallWindowClass *empathy_call_window_class)
2274 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2275 GParamSpec *param_spec;
2277 g_type_class_add_private (empathy_call_window_class,
2278 sizeof (EmpathyCallWindowPriv));
2280 object_class->constructed = empathy_call_window_constructed;
2281 object_class->set_property = empathy_call_window_set_property;
2282 object_class->get_property = empathy_call_window_get_property;
2284 object_class->dispose = empathy_call_window_dispose;
2285 object_class->finalize = empathy_call_window_finalize;
2287 param_spec = g_param_spec_object ("handler",
2288 "handler", "The call handler",
2289 EMPATHY_TYPE_CALL_HANDLER,
2290 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2291 g_object_class_install_property (object_class,
2292 PROP_CALL_HANDLER, param_spec);
2296 empathy_call_window_dispose (GObject *object)
2298 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2299 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2301 if (priv->dispose_has_run)
2304 priv->dispose_has_run = TRUE;
2306 if (priv->handler != NULL)
2308 empathy_call_handler_stop_call (priv->handler);
2309 tp_clear_object (&priv->handler);
2312 if (priv->bus_message_source_id != 0)
2314 g_source_remove (priv->bus_message_source_id);
2315 priv->bus_message_source_id = 0;
2318 if (priv->got_video_src > 0)
2320 g_source_remove (priv->got_video_src);
2321 priv->got_video_src = 0;
2324 if (priv->inactivity_src > 0)
2326 g_source_remove (priv->inactivity_src);
2327 priv->inactivity_src = 0;
2330 tp_clear_object (&priv->pipeline);
2331 tp_clear_object (&priv->video_input);
2332 tp_clear_object (&priv->audio_input);
2333 tp_clear_object (&priv->video_tee);
2334 tp_clear_object (&priv->ui_manager);
2335 tp_clear_object (&priv->fullscreen);
2336 tp_clear_object (&priv->camera_monitor);
2337 tp_clear_object (&priv->settings);
2338 tp_clear_object (&priv->sound_mgr);
2339 tp_clear_object (&priv->mic_menu);
2340 tp_clear_object (&priv->camera_menu);
2341 tp_clear_object (&priv->transitions);
2343 g_list_free_full (priv->notifiers, g_object_unref);
2345 if (priv->timer_id != 0)
2346 g_source_remove (priv->timer_id);
2349 tp_clear_object (&priv->contact);
2351 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2355 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2357 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2359 if (priv->video_output_motion_handler_id != 0)
2361 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2362 priv->video_output_motion_handler_id);
2363 priv->video_output_motion_handler_id = 0;
2368 empathy_call_window_finalize (GObject *object)
2370 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2371 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2373 disconnect_video_output_motion_handler (self);
2375 /* free any data held directly by the object here */
2376 g_mutex_free (priv->lock);
2378 g_timer_destroy (priv->timer);
2380 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2385 empathy_call_window_new (EmpathyCallHandler *handler)
2387 return EMPATHY_CALL_WINDOW (
2388 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2392 empathy_call_window_present (EmpathyCallWindow *self,
2393 EmpathyCallHandler *handler)
2395 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2397 empathy_window_present (GTK_WINDOW (self));
2399 if (self->priv->call_state == DISCONNECTED)
2401 /* start a new call if one is not already in progress */
2402 tp_clear_object (&self->priv->handler);
2403 self->priv->handler = g_object_ref (handler);
2404 empathy_call_window_connect_handler (self);
2406 empathy_call_window_restart_call (self);
2411 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2412 GstElement *conference, gpointer user_data)
2414 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2415 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2416 FsElementAddedNotifier *notifier;
2419 DEBUG ("Conference added");
2421 /* Add notifier to set the various element properties as needed */
2422 notifier = fs_element_added_notifier_new ();
2423 keyfile = fs_utils_get_default_element_properties (conference);
2425 if (keyfile != NULL)
2426 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2428 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2430 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2432 gst_bin_add (GST_BIN (priv->pipeline), conference);
2433 gst_element_set_state (conference, GST_STATE_PLAYING);
2437 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2438 GstElement *conference, gpointer user_data)
2440 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2441 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2443 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2444 gst_element_set_state (conference, GST_STATE_NULL);
2448 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2450 GstStateChangeReturn state_change_return;
2451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2453 if (priv->pipeline == NULL)
2456 if (priv->bus_message_source_id != 0)
2458 g_source_remove (priv->bus_message_source_id);
2459 priv->bus_message_source_id = 0;
2462 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2464 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2465 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2467 if (priv->pipeline != NULL)
2468 g_object_unref (priv->pipeline);
2469 priv->pipeline = NULL;
2471 if (priv->audio_output != NULL)
2472 g_object_unref (priv->audio_output);
2473 priv->audio_output = NULL;
2474 priv->audio_output_added = FALSE;
2476 if (priv->video_tee != NULL)
2477 g_object_unref (priv->video_tee);
2478 priv->video_tee = NULL;
2480 if (priv->video_preview != NULL)
2481 clutter_actor_destroy (priv->video_preview);
2482 priv->video_preview = NULL;
2484 /* If we destroy the preview while it's being dragged, we won't
2485 * get the ::drag-end signal, so manually destroy the clone */
2486 if (priv->drag_preview != NULL)
2488 clutter_actor_destroy (priv->drag_preview);
2489 empathy_call_window_show_preview_rectangles (self, FALSE);
2490 priv->drag_preview = NULL;
2493 priv->funnel = NULL;
2495 create_pipeline (self);
2496 /* Call will be started when user will hit the 'redial' button */
2497 priv->start_call_when_playing = FALSE;
2498 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2504 g_message ("Error: could not destroy pipeline. Closing call window");
2505 gtk_widget_destroy (GTK_WIDGET (self));
2512 reset_details_pane (EmpathyCallWindow *self)
2514 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2516 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2517 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2518 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2519 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2523 empathy_call_window_disconnected (EmpathyCallWindow *self,
2526 gboolean could_disconnect = FALSE;
2527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2528 gboolean could_reset_pipeline;
2530 /* Leave full screen mode if needed */
2531 gtk_window_unfullscreen (GTK_WINDOW (self));
2533 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2534 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2536 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2538 if (priv->call_state == CONNECTING)
2539 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2541 if (priv->call_state != REDIALING)
2542 priv->call_state = DISCONNECTED;
2544 /* Show the toolbar */
2545 clutter_state_set_state (priv->transitions, "fade-in");
2547 if (could_reset_pipeline)
2549 g_mutex_lock (priv->lock);
2551 g_timer_stop (priv->timer);
2553 if (priv->timer_id != 0)
2554 g_source_remove (priv->timer_id);
2557 g_mutex_unlock (priv->lock);
2560 /* We are about to destroy the window, no need to update it or create
2561 * a video preview */
2564 empathy_call_window_status_message (self, _("Disconnected"));
2566 empathy_call_window_show_hangup_button (self, FALSE);
2568 /* Unsensitive the camera and mic button */
2569 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2570 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2572 /* Be sure that the mic button is enabled */
2573 gtk_toggle_tool_button_set_active (
2574 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2576 if (priv->camera_state == CAMERA_STATE_ON)
2578 /* Restart the preview with the new pipeline. */
2579 display_video_preview (self, TRUE);
2582 /* destroy the video output; it will be recreated when we'll redial */
2583 disconnect_video_output_motion_handler (self);
2584 if (priv->video_output != NULL)
2585 clutter_actor_destroy (priv->video_output);
2586 priv->video_output = NULL;
2587 if (priv->got_video_src > 0)
2589 g_source_remove (priv->got_video_src);
2590 priv->got_video_src = 0;
2593 gtk_widget_show (priv->remote_user_avatar_widget);
2595 reset_details_pane (self);
2597 priv->sending_video = FALSE;
2598 priv->call_started = FALSE;
2600 could_disconnect = TRUE;
2602 /* TODO: display the self avatar of the preview (depends if the "Always
2603 * Show Video Preview" is enabled or not) */
2606 return could_disconnect;
2611 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2614 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2615 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2617 if (empathy_call_window_disconnected (self, TRUE) &&
2618 priv->call_state == REDIALING)
2619 empathy_call_window_restart_call (self);
2623 empathy_call_window_content_is_raw (TfContent *content)
2625 FsConference *conference;
2628 g_object_get (content, "fs-conference", &conference, NULL);
2629 g_assert (conference != NULL);
2631 /* FIXME: Ugly hack, update when moving a packetization property into
2633 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2634 gst_object_unref (conference);
2640 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2642 EmpathyCallWindow *self)
2644 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2645 FsMediaType media_type;
2647 DEBUG ("removing content");
2649 g_object_get (content, "media-type", &media_type, NULL);
2652 * This assumes that there is only one video stream per channel...
2655 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2657 if (priv->funnel != NULL)
2661 output = priv->video_output_sink;
2663 gst_element_set_state (output, GST_STATE_NULL);
2664 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2666 gst_bin_remove (GST_BIN (priv->pipeline), output);
2667 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2668 priv->funnel = NULL;
2671 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2673 if (priv->audio_output != NULL)
2675 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2677 if (priv->audio_output_added)
2678 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2679 priv->audio_output = NULL;
2680 priv->audio_output_added = FALSE;
2685 g_assert_not_reached ();
2692 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2694 EmpathyCallWindow *self)
2696 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2698 DEBUG ("Framerate changed to %u", framerate);
2700 if (priv->video_input != NULL)
2701 empathy_video_src_set_framerate (priv->video_input, framerate);
2705 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2708 EmpathyCallWindow *self)
2710 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2712 DEBUG ("Resolution changed to %ux%u", width, height);
2714 if (priv->video_input != NULL)
2716 empathy_video_src_set_resolution (priv->video_input, width, height);
2720 /* Called with global lock held */
2722 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2724 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2728 if (priv->funnel == NULL)
2730 output = priv->video_output_sink;
2732 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2736 g_warning ("Could not create fsfunnel");
2740 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2742 gst_object_unref (priv->funnel);
2743 priv->funnel = NULL;
2744 g_warning ("Could not add funnel to pipeline");
2748 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2750 g_warning ("Could not add the video output widget to the pipeline");
2754 if (!gst_element_link (priv->funnel, output))
2756 g_warning ("Could not link output sink to funnel");
2757 goto error_output_added;
2760 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2762 g_warning ("Could not start video sink");
2763 goto error_output_added;
2766 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2768 g_warning ("Could not start funnel");
2769 goto error_output_added;
2773 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2776 g_warning ("Could not get request pad from funnel");
2783 gst_element_set_locked_state (priv->funnel, TRUE);
2784 gst_element_set_locked_state (output, TRUE);
2786 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2787 gst_element_set_state (output, GST_STATE_NULL);
2789 gst_bin_remove (GST_BIN (priv->pipeline), output);
2790 gst_element_set_locked_state (output, FALSE);
2794 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2795 priv->funnel = NULL;
2800 /* Called with global lock held */
2802 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2805 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2807 GstPadTemplate *template;
2809 if (!priv->audio_output_added)
2811 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2813 g_warning ("Could not add audio sink to pipeline");
2814 g_object_unref (priv->audio_output);
2815 goto error_add_output;
2818 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2820 g_warning ("Could not start audio sink");
2825 template = gst_element_class_get_pad_template (
2826 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2828 pad = gst_element_request_pad (priv->audio_output,
2829 template, NULL, NULL);
2833 g_warning ("Could not get sink pad from sink");
2840 gst_element_set_locked_state (priv->audio_output, TRUE);
2841 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2842 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2843 priv->audio_output = NULL;
2851 empathy_call_window_update_timer (gpointer user_data)
2853 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2854 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2855 const gchar *status;
2859 time_ = g_timer_elapsed (priv->timer, NULL);
2861 if (priv->call_state == HELD)
2862 status = _("On hold");
2863 else if (!gtk_toggle_tool_button_get_active (
2864 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2867 status = _("Duration");
2869 /* Translators: 'status - minutes:seconds' the caller has been connected */
2870 str = g_strdup_printf (_("%s — %d:%02dm"),
2872 (int) time_ / 60, (int) time_ % 60);
2873 empathy_call_window_status_message (self, str);
2881 EMP_RESPONSE_BALANCE
2885 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2889 switch (response_id)
2891 case GTK_RESPONSE_CLOSE:
2892 gtk_widget_destroy (GTK_WIDGET (info_bar));
2894 case EMP_RESPONSE_BALANCE:
2895 empathy_url_show (GTK_WIDGET (info_bar),
2896 g_object_get_data (G_OBJECT (info_bar), "uri"));
2902 display_error (EmpathyCallWindow *self,
2906 const gchar *details,
2907 const gchar *button_text,
2909 gint button_response)
2911 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2912 GtkWidget *info_bar;
2913 GtkWidget *content_area;
2920 /* Create info bar */
2921 info_bar = gtk_info_bar_new ();
2923 if (button_text != NULL)
2925 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2926 button_text, button_response);
2927 g_object_set_data_full (G_OBJECT (info_bar),
2928 "uri", g_strdup (uri), g_free);
2931 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2932 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2934 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2936 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2938 /* hbox containing the image and the messages vbox */
2939 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2940 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2943 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2944 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2946 /* vbox containing the main message and the details expander */
2947 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2948 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2951 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2953 label = gtk_label_new (NULL);
2954 gtk_label_set_markup (GTK_LABEL (label), txt);
2955 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2956 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2959 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2962 if (details != NULL)
2964 GtkWidget *expander;
2966 expander = gtk_expander_new (_("Technical Details"));
2968 txt = g_strdup_printf ("<i>%s</i>", details);
2970 label = gtk_label_new (NULL);
2971 gtk_label_set_markup (GTK_LABEL (label), txt);
2972 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2973 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2976 gtk_container_add (GTK_CONTAINER (expander), label);
2977 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2980 g_signal_connect (info_bar, "response",
2981 G_CALLBACK (on_error_infobar_response_cb), NULL);
2983 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2984 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2985 gtk_widget_show_all (info_bar);
2990 media_stream_error_to_txt (EmpathyCallWindow *self,
2991 TpCallChannel *call,
2993 TpMediaStreamError error)
2995 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2996 const gchar *cm = NULL;
3002 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3004 return g_strdup_printf (
3005 _("%s's software does not understand any of the audio formats "
3006 "supported by your computer"),
3007 empathy_contact_get_alias (priv->contact));
3009 return g_strdup_printf (
3010 _("%s's software does not understand any of the video formats "
3011 "supported by your computer"),
3012 empathy_contact_get_alias (priv->contact));
3014 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3015 return g_strdup_printf (
3016 _("Can't establish a connection to %s. "
3017 "One of you might be on a network that does not allow "
3018 "direct connections."),
3019 empathy_contact_get_alias (priv->contact));
3021 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3022 return g_strdup (_("There was a failure on the network"));
3024 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3026 return g_strdup (_("The audio formats necessary for this call "
3027 "are not installed on your computer"));
3029 return g_strdup (_("The video formats necessary for this call "
3030 "are not installed on your computer"));
3032 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3033 tp_connection_parse_object_path (
3034 tp_channel_borrow_connection (TP_CHANNEL (call)),
3037 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3038 "product=Telepathy&component=%s", cm);
3040 result = g_strdup_printf (
3041 _("Something unexpected happened in a Telepathy component. "
3042 "Please <a href=\"%s\">report this bug</a> and attach "
3043 "logs gathered from the 'Debug' window in the Help menu."), url);
3049 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3050 return g_strdup (_("There was a failure in the call engine"));
3052 case TP_MEDIA_STREAM_ERROR_EOS:
3053 return g_strdup (_("The end of the stream was reached"));
3055 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3062 empathy_call_window_stream_error (EmpathyCallWindow *self,
3063 TpCallChannel *call,
3072 desc = media_stream_error_to_txt (self, call, audio, code);
3075 /* No description, use the error message. That's not great as it's not
3076 * localized but it's better than nothing. */
3077 display_error (self, call, icon, title, msg, NULL);
3081 display_error (self, call, icon, title, desc, msg);
3087 empathy_call_window_audio_stream_error (TpCallChannel *call,
3090 EmpathyCallWindow *self)
3092 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3093 "gnome-stock-mic", _("Can't establish audio stream"));
3097 empathy_call_window_video_stream_error (TpCallChannel *call,
3100 EmpathyCallWindow *self)
3102 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3103 "camera-web", _("Can't establish video stream"));
3108 show_balance_error (EmpathyCallWindow *self)
3112 gchar *balance, *tmp;
3113 const gchar *uri, *currency;
3117 g_object_get (self->priv->handler,
3118 "call-channel", &call,
3121 conn = tp_channel_borrow_connection (call);
3122 g_object_unref (call);
3124 uri = tp_connection_get_balance_uri (conn);
3126 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3128 /* unknown balance */
3129 balance = g_strdup ("(--)");
3133 char *money = empathy_format_currency (amount, scale, currency);
3135 balance = g_strdup_printf ("%s %s",
3140 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3142 display_error (self,
3144 _("Sorry, you don’t have enough credit for that call."),
3148 EMP_RESPONSE_BALANCE);
3155 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3158 EmpathyCallWindow *self)
3160 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3161 TpCallChannel *call;
3162 gboolean can_send_video;
3164 if (state == TP_CALL_STATE_ENDED)
3166 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3167 empathy_call_window_disconnected (self, TRUE);
3168 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3169 show_balance_error (self);
3173 if (state != TP_CALL_STATE_ACCEPTED)
3176 if (priv->call_state == CONNECTED)
3179 g_timer_start (priv->timer);
3180 priv->call_state = CONNECTED;
3182 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3184 can_send_video = priv->video_input != NULL &&
3185 empathy_contact_can_voip_video (priv->contact) &&
3186 empathy_camera_monitor_get_available (priv->camera_monitor);
3188 g_object_get (priv->handler, "call-channel", &call, NULL);
3190 if (tp_call_channel_has_dtmf (call))
3191 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3193 if (priv->video_input == NULL)
3194 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3196 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3198 empathy_call_window_show_hangup_button (self, TRUE);
3200 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3202 clutter_actor_hide (priv->video_output);
3203 gtk_widget_show (priv->remote_user_avatar_widget);
3205 g_object_unref (call);
3207 g_mutex_lock (priv->lock);
3209 priv->timer_id = g_timeout_add_seconds (1,
3210 empathy_call_window_update_timer, self);
3212 g_mutex_unlock (priv->lock);
3214 empathy_call_window_update_timer (self);
3216 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3220 empathy_call_window_show_video_output_cb (gpointer user_data)
3222 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3224 if (self->priv->video_output != NULL)
3226 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3227 clutter_actor_show (self->priv->video_output);
3228 clutter_actor_raise_top (self->priv->overlay_bin);
3235 empathy_call_window_check_video_cb (gpointer data)
3237 EmpathyCallWindow *self = data;
3239 if (self->priv->got_video)
3241 self->priv->got_video = FALSE;
3245 /* No video in the last N seconds, display the remote avatar */
3246 empathy_call_window_show_video_output (self, FALSE);
3251 /* Called from the streaming thread */
3253 empathy_call_window_video_probe_cb (GstPad *pad,
3254 GstMiniObject *mini_obj,
3255 EmpathyCallWindow *self)
3258 if (GST_IS_EVENT (mini_obj))
3261 if (G_UNLIKELY (!self->priv->got_video))
3263 /* show the remote video */
3264 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3265 empathy_call_window_show_video_output_cb,
3266 g_object_ref (self), g_object_unref);
3268 self->priv->got_video = TRUE;
3274 /* Called from the streaming thread */
3276 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3277 TfContent *content, GstPad *src, gpointer user_data)
3279 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3280 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3281 gboolean retval = FALSE;
3286 g_mutex_lock (priv->lock);
3288 g_object_get (content, "media-type", &media_type, NULL);
3292 case TP_MEDIA_STREAM_TYPE_AUDIO:
3293 pad = empathy_call_window_get_audio_sink_pad (self, content);
3295 case TP_MEDIA_STREAM_TYPE_VIDEO:
3296 g_idle_add (empathy_call_window_show_video_output_cb, self);
3297 pad = empathy_call_window_get_video_sink_pad (self);
3299 gst_pad_add_data_probe (src,
3300 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3301 if (priv->got_video_src > 0)
3302 g_source_remove (priv->got_video_src);
3303 priv->got_video_src = g_timeout_add_seconds (1,
3304 empathy_call_window_check_video_cb, self);
3307 g_assert_not_reached ();
3313 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3314 g_warning ("Could not link %s sink pad",
3315 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3319 gst_object_unref (pad);
3323 /* If no sink could be linked, try to add fakesink to prevent the whole call
3328 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3330 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3332 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3333 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3334 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3336 gst_element_set_locked_state (fakesink, TRUE);
3337 gst_element_set_state (fakesink, GST_STATE_NULL);
3338 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3342 DEBUG ("Could not link real sink, linked fakesink instead");
3344 gst_object_unref (sinkpad);
3348 gst_object_unref (fakesink);
3353 g_mutex_unlock (priv->lock);
3359 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3362 EmpathyCallWindowPriv *priv = self->priv;
3364 g_assert (priv->audio_output_added == FALSE);
3365 g_assert (priv->audio_output == FALSE);
3367 priv->audio_output = empathy_audio_sink_new ();
3368 g_object_ref_sink (priv->audio_output);
3370 /* volume button to output volume linking */
3371 g_object_bind_property (priv->audio_output, "volume",
3372 priv->volume_button, "value",
3373 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3375 g_object_bind_property_full (content, "requested-output-volume",
3376 priv->audio_output, "volume",
3378 audio_control_volume_to_element,
3379 element_volume_to_audio_control,
3382 /* Link volumes together, sync the current audio input volume property
3383 * back to farstream first */
3384 g_object_bind_property_full (priv->audio_output, "volume",
3385 content, "reported-output-volume",
3386 G_BINDING_SYNC_CREATE,
3387 element_volume_to_audio_control,
3388 audio_control_volume_to_element,
3391 /* For raw audio conferences assume that the producer of the raw data
3392 * has already processed it, so turn off any echo cancellation and any
3393 * other audio improvements that come with it */
3394 empathy_audio_sink_set_echo_cancel (
3395 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3396 !empathy_call_window_content_is_raw (content));
3401 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3402 TfContent *content, gpointer user_data)
3404 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3407 FsMediaType media_type;
3408 gboolean retval = FALSE;
3410 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3411 g_assert (sink != NULL);
3415 case FS_MEDIA_TYPE_AUDIO:
3417 /* For raw audio conferences assume that the receiver of the raw data
3418 * wants it unprocessed, so turn off any echo cancellation and any
3419 * other audio improvements that come with it */
3420 empathy_audio_src_set_echo_cancel (
3421 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3422 !empathy_call_window_content_is_raw (content));
3424 /* Link volumes together, sync the current audio input volume property
3425 * back to farstream first */
3426 g_object_bind_property_full (content, "requested-input-volume",
3427 priv->audio_input, "volume",
3429 audio_control_volume_to_element,
3430 element_volume_to_audio_control,
3433 g_object_bind_property_full (priv->audio_input, "volume",
3434 content, "reported-input-volume",
3435 G_BINDING_SYNC_CREATE,
3436 element_volume_to_audio_control,
3437 audio_control_volume_to_element,
3440 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3442 g_warning ("Could not add audio source to pipeline");
3446 pad = gst_element_get_static_pad (priv->audio_input, "src");
3449 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3450 g_warning ("Could not get source pad from audio source");
3454 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3456 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3457 gst_object_unref (pad);
3458 g_warning ("Could not link audio source to farsight");
3461 gst_object_unref (pad);
3463 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3465 g_warning ("Could not start audio source");
3466 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3467 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3471 /* Prepare our audio output, not added yet though */
3472 empathy_call_window_prepare_audio_output (self, content);
3476 case FS_MEDIA_TYPE_VIDEO:
3477 if (priv->video_tee != NULL)
3479 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3480 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3482 g_warning ("Could not link video source input pipeline");
3485 gst_object_unref (pad);
3491 g_assert_not_reached ();
3494 gst_object_unref (sink);
3499 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3502 GstElement *preview;
3504 disable_camera (self);
3506 DEBUG ("remove video input");
3507 preview = priv->video_preview_sink;
3509 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3510 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3511 gst_element_set_state (preview, GST_STATE_NULL);
3513 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3516 g_object_unref (priv->video_input);
3517 priv->video_input = NULL;
3518 g_object_unref (priv->video_tee);
3519 priv->video_tee = NULL;
3520 clutter_actor_destroy (priv->video_preview);
3521 priv->video_preview = NULL;
3523 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3527 start_call (EmpathyCallWindow *self)
3529 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3531 priv->call_started = TRUE;
3532 empathy_call_handler_start_call (priv->handler,
3533 gtk_get_current_event_time ());
3535 if (empathy_call_handler_has_initial_video (priv->handler))
3537 TpCallChannel *call;
3540 g_object_get (priv->handler, "call-channel", &call, NULL);
3541 /* If the call channel isn't set yet we're requesting it, if we're
3542 * requesting it with initial video it should be PENDING_SEND when we get
3545 s = TP_SENDING_STATE_PENDING_SEND;
3547 s = empathy_call_channel_get_video_state (call);
3549 if (s == TP_SENDING_STATE_PENDING_SEND ||
3550 s == TP_SENDING_STATE_SENDING)
3552 /* Enable 'send video' buttons and display the preview */
3553 gtk_toggle_tool_button_set_active (
3554 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3558 gtk_toggle_tool_button_set_active (
3559 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3561 if (priv->video_preview == NULL)
3563 create_video_preview (self);
3564 add_video_preview_to_pipeline (self);
3569 g_object_unref (call);
3574 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3577 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3578 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3579 GstState newstate, pending;
3581 empathy_call_handler_bus_message (priv->handler, bus, message);
3583 switch (GST_MESSAGE_TYPE (message))
3585 case GST_MESSAGE_STATE_CHANGED:
3586 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3588 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3590 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3591 !priv->call_started)
3593 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3594 if (newstate == GST_STATE_PAUSED)
3596 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3597 priv->pipeline_playing = TRUE;
3599 if (priv->start_call_when_playing)
3603 if (priv->video_preview_sink != NULL &&
3604 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3606 gst_message_parse_state_changed (message, NULL, &newstate,
3609 if (newstate == GST_STATE_PLAYING &&
3610 pending == GST_STATE_VOID_PENDING)
3611 empathy_call_window_stop_camera_spinning (self);
3614 case GST_MESSAGE_ERROR:
3616 GError *error = NULL;
3617 GstElement *gst_error;
3621 gst_message_parse_error (message, &error, &debug);
3622 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3624 g_message ("Element error: %s -- %s\n", error->message, debug);
3626 name = gst_element_get_name (gst_error);
3627 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3629 /* Remove the video input and continue */
3630 if (priv->video_input != NULL)
3631 empathy_call_window_remove_video_input (self);
3632 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3636 empathy_call_window_disconnected (self, TRUE);
3639 g_error_free (error);
3642 case GST_MESSAGE_UNKNOWN:
3643 case GST_MESSAGE_EOS:
3644 case GST_MESSAGE_WARNING:
3645 case GST_MESSAGE_INFO:
3646 case GST_MESSAGE_TAG:
3647 case GST_MESSAGE_BUFFERING:
3648 case GST_MESSAGE_STATE_DIRTY:
3649 case GST_MESSAGE_STEP_DONE:
3650 case GST_MESSAGE_CLOCK_PROVIDE:
3651 case GST_MESSAGE_CLOCK_LOST:
3652 case GST_MESSAGE_NEW_CLOCK:
3653 case GST_MESSAGE_STRUCTURE_CHANGE:
3654 case GST_MESSAGE_STREAM_STATUS:
3655 case GST_MESSAGE_APPLICATION:
3656 case GST_MESSAGE_ELEMENT:
3657 case GST_MESSAGE_SEGMENT_START:
3658 case GST_MESSAGE_SEGMENT_DONE:
3659 case GST_MESSAGE_DURATION:
3660 case GST_MESSAGE_ANY:
3669 empathy_call_window_members_changed_cb (TpCallChannel *call,
3670 GHashTable *updates,
3672 TpCallStateReason *reason,
3673 EmpathyCallWindow *self)
3675 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3676 GHashTableIter iter;
3677 gpointer key, value;
3678 gboolean held = FALSE;
3680 g_hash_table_iter_init (&iter, updates);
3681 while (g_hash_table_iter_next (&iter, &key, &value))
3683 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3685 /* This assumes this is a 1-1 call, otherwise one participant
3686 * putting the call on hold wouldn't mean the call is on hold
3694 priv->call_state = HELD;
3695 else if (priv->call_state == HELD)
3696 priv->call_state = CONNECTED;
3700 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3702 EmpathyCallWindow *self)
3704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3705 TpCallChannel *call;
3707 g_object_get (priv->handler, "call-channel", &call, NULL);
3712 tp_g_signal_connect_object (call, "audio-stream-error",
3713 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3714 tp_g_signal_connect_object (call, "video-stream-error",
3715 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3718 tp_g_signal_connect_object (call, "members-changed",
3719 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3721 g_object_unref (call);
3725 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3727 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3728 TpCallChannel *call;
3730 g_signal_connect (priv->handler, "state-changed",
3731 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3732 g_signal_connect (priv->handler, "conference-added",
3733 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3734 g_signal_connect (priv->handler, "conference-removed",
3735 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3736 g_signal_connect (priv->handler, "closed",
3737 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3738 g_signal_connect (priv->handler, "src-pad-added",
3739 G_CALLBACK (empathy_call_window_src_added_cb), self);
3740 g_signal_connect (priv->handler, "content-added",
3741 G_CALLBACK (empathy_call_window_content_added_cb), self);
3742 g_signal_connect (priv->handler, "content-removed",
3743 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3745 /* We connect to ::call-channel unconditionally since we'll
3746 * get new channels if we hangup and redial or if we reuse the
3748 g_signal_connect (priv->handler, "notify::call-channel",
3749 G_CALLBACK (call_handler_notify_call_cb), self);
3751 g_signal_connect (priv->handler, "framerate-changed",
3752 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3753 g_signal_connect (priv->handler, "resolution-changed",
3754 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3756 g_object_get (priv->handler, "call-channel", &call, NULL);
3759 /* We won't get notify::call-channel for this channel, so
3760 * directly call the callback. */
3761 call_handler_notify_call_cb (priv->handler, NULL, self);
3762 g_object_unref (call);
3767 empathy_call_window_realized_cb (GtkWidget *widget,
3768 EmpathyCallWindow *self)
3772 /* Make the hangup button twice as wide */
3773 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3774 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3776 empathy_call_window_connect_handler (self);
3778 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3782 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3783 EmpathyCallWindow *window)
3785 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3787 if (priv->pipeline != NULL)
3789 if (priv->bus_message_source_id != 0)
3791 g_source_remove (priv->bus_message_source_id);
3792 priv->bus_message_source_id = 0;
3795 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3798 if (priv->call_state == CONNECTING)
3799 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3805 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3808 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3810 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3815 gtk_widget_hide (priv->dtmf_panel);
3816 gtk_widget_hide (menu);
3817 gtk_widget_hide (priv->toolbar);
3821 if (priv->dialpad_was_visible_before_fs)
3822 gtk_widget_show (priv->dtmf_panel);
3824 gtk_widget_show (menu);
3825 gtk_widget_show (priv->toolbar);
3827 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3828 priv->original_height_before_fs);
3833 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3835 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3837 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3838 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3840 if (priv->video_output != NULL)
3843 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3844 priv->video_output, TRUE, TRUE,
3845 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3852 empathy_call_window_state_event_cb (GtkWidget *widget,
3853 GdkEventWindowState *event, EmpathyCallWindow *window)
3855 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3857 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3858 gboolean set_fullscreen = event->new_window_state &
3859 GDK_WINDOW_STATE_FULLSCREEN;
3863 gboolean dialpad_was_visible;
3864 GtkAllocation allocation;
3865 gint original_width, original_height;
3867 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3868 original_width = allocation.width;
3869 original_height = allocation.height;
3871 g_object_get (priv->dtmf_panel,
3872 "visible", &dialpad_was_visible,
3875 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3876 priv->original_width_before_fs = original_width;
3877 priv->original_height_before_fs = original_height;
3879 if (priv->video_output_motion_handler_id == 0 &&
3880 priv->video_output != NULL)
3882 priv->video_output_motion_handler_id = g_signal_connect (
3883 G_OBJECT (priv->video_container), "motion-notify-event",
3884 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3890 disconnect_video_output_motion_handler (window);
3893 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3895 show_controls (window, set_fullscreen);
3896 show_borders (window, set_fullscreen);
3897 gtk_action_set_stock_id (priv->menu_fullscreen,
3898 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3899 priv->is_fullscreen = set_fullscreen;
3906 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3909 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3910 int w, h, dialpad_width;
3911 GtkAllocation allocation;
3913 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3914 w = allocation.width;
3915 h = allocation.height;
3917 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3921 gtk_widget_show (priv->dtmf_panel);
3927 gtk_widget_hide (priv->dtmf_panel);
3931 gtk_window_resize (GTK_WINDOW (window), w, h);
3935 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3938 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3939 TpCallChannel *call;
3941 priv->sending_video = (state == CAMERA_STATE_ON);
3943 if (state == CAMERA_STATE_ON)
3945 /* When we start sending video, we want to show the video preview by
3947 display_video_preview (window, TRUE);
3951 display_video_preview (window, FALSE);
3954 if (priv->call_state != CONNECTED)
3957 g_object_get (priv->handler, "call-channel", &call, NULL);
3958 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3959 empathy_call_channel_send_video (call, priv->sending_video);
3960 g_object_unref (call);
3964 empathy_call_window_hangup_cb (gpointer object,
3965 EmpathyCallWindow *self)
3967 /* stopping the call will put it the ENDED state and
3968 * from state_changed_cb we'll reconfigure the window
3970 empathy_call_handler_stop_call (self->priv->handler);
3974 empathy_call_window_restart_call (EmpathyCallWindow *window)
3976 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3978 /* Remove error info bars */
3979 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3980 (GtkCallback) gtk_widget_destroy, NULL);
3982 create_video_output_widget (window);
3983 priv->outgoing = TRUE;
3984 empathy_call_window_set_state_connecting (window);
3986 if (priv->pipeline_playing)
3987 start_call (window);
3989 /* call will be started when the pipeline is ready */
3990 priv->start_call_when_playing = TRUE;
3992 empathy_call_window_setup_avatars (window, priv->handler);
3994 empathy_call_window_show_hangup_button (window, TRUE);
3998 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3999 EmpathyCallWindow *window)
4003 active = gtk_toggle_tool_button_get_active (button);
4005 empathy_call_window_show_dialpad (window, active);
4009 empathy_call_window_fullscreen_cb (gpointer object,
4010 EmpathyCallWindow *window)
4012 empathy_call_window_fullscreen_toggle (window);
4016 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4018 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4020 if (priv->is_fullscreen)
4021 gtk_window_unfullscreen (GTK_WINDOW (window));
4023 gtk_window_fullscreen (GTK_WINDOW (window));
4027 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4028 GdkEventButton *event, EmpathyCallWindow *window)
4030 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4032 empathy_call_window_video_menu_popup (window, event->button);
4040 empathy_call_window_key_press_cb (GtkWidget *video_output,
4041 GdkEventKey *event, EmpathyCallWindow *window)
4043 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4045 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4047 /* Since we are in fullscreen mode, toggling will bring us back to
4049 empathy_call_window_fullscreen_toggle (window);
4057 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4058 GdkEventMotion *event, EmpathyCallWindow *window)
4060 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4062 if (priv->is_fullscreen)
4064 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4066 /* Show the bottom toolbar */
4067 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4074 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4078 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4080 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4082 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4083 button, gtk_get_current_event_time ());
4084 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4088 empathy_call_window_status_message (EmpathyCallWindow *self,
4091 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4095 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4097 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4099 return priv->ui_manager;
4102 EmpathyGstAudioSrc *
4103 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4105 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4107 return (EmpathyGstAudioSrc *) priv->audio_input;
4110 EmpathyGstVideoSrc *
4111 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4113 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4117 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4118 const gchar *device)
4120 EmpathyGstVideoSrc *video;
4123 /* Restart the camera only if it's already running */
4124 running = (self->priv->video_preview != NULL);
4125 video = empathy_call_window_get_video_src (self);
4128 empathy_call_window_play_camera (self, FALSE);
4130 empathy_video_src_change_device (video, device);
4133 empathy_call_window_play_camera (self, TRUE);