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 <gst/farsight/fs-element-added-notifier.h>
42 #include <gst/farsight/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_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 10
84 #define FLOATING_TOOLBAR_OPACITY 192
85 #define FLOATING_TOOLBAR_WIDTH 280
86 #define FLOATING_TOOLBAR_HEIGHT 36
87 #define FLOATING_TOOLBAR_SPACING 20
89 /* The avatar's default width and height are set to the same value because we
90 want a square icon. */
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
92 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
93 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
95 #define SMALL_TOOLBAR_SIZE 36
97 /* If an video input error occurs, the error message will start with "v4l" */
98 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
100 /* The time interval in milliseconds between 2 outgoing rings */
101 #define MS_BETWEEN_RING 500
103 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
106 PROP_CALL_HANDLER = 1,
110 RINGING, /* Incoming call */
111 CONNECTING, /* Outgoing call */
112 CONNECTED, /* Connected */
113 HELD, /* Connected, but on hold */
114 DISCONNECTED, /* Disconnected */
115 REDIALING /* Redialing (special case of CONNECTING) */
119 CAMERA_STATE_OFF = 0,
125 PREVIEW_POS_TOP_LEFT,
126 PREVIEW_POS_TOP_RIGHT,
127 PREVIEW_POS_BOTTOM_LEFT,
128 PREVIEW_POS_BOTTOM_RIGHT,
131 struct _EmpathyCallWindowPriv
133 gboolean dispose_has_run;
134 EmpathyCallHandler *handler;
136 EmpathyContact *contact;
138 EmpathyCameraMonitor *camera_monitor;
143 GtkUIManager *ui_manager;
144 GtkWidget *errors_vbox;
145 /* widget displays the video received from the remote user. This widget is
146 * alive only during call. */
147 ClutterActor *video_output;
148 ClutterActor *video_preview;
149 ClutterActor *drag_preview;
150 ClutterActor *preview_shown_button;
151 ClutterActor *preview_hidden_button;
152 ClutterActor *preview_rectangle1;
153 ClutterActor *preview_rectangle2;
154 ClutterActor *preview_rectangle3;
155 ClutterActor *preview_rectangle4;
156 ClutterActor *preview_rectangle_box1;
157 ClutterActor *preview_rectangle_box2;
158 ClutterActor *preview_rectangle_box3;
159 ClutterActor *preview_rectangle_box4;
160 ClutterActor *preview_spinner_actor;
161 GtkWidget *preview_spinner_widget;
162 GtkWidget *video_container;
163 GtkWidget *remote_user_avatar_widget;
164 GtkWidget *remote_user_avatar_toolbar;
165 GtkWidget *remote_user_name_toolbar;
166 GtkWidget *status_label;
167 GtkWidget *hangup_button;
168 GtkWidget *audio_call_button;
169 GtkWidget *video_call_button;
170 GtkWidget *mic_button;
171 GtkWidget *volume_button;
172 GtkWidget *camera_button;
173 GtkWidget *dialpad_button;
175 GtkWidget *bottom_toolbar;
176 ClutterActor *floating_toolbar;
178 GtkAction *menu_fullscreen;
179 GtkAction *menu_swap_camera;
181 ClutterState *transitions;
183 /* The box that contains self and remote avatar and video
184 input/output. When we redial, we destroy and re-create the box */
185 ClutterActor *video_box;
186 ClutterLayoutManager *video_layout;
188 /* Coordinates of the preview drag event's start. */
189 PreviewPosition preview_pos;
191 /* We keep a reference on the hbox which contains the main content so we can
192 easilly repack everything when toggling fullscreen */
193 GtkWidget *content_hbox;
195 /* These are used to accept or reject an incoming call when the status
197 GtkWidget *incoming_call_dialog;
198 TpCallChannel *pending_channel;
199 TpChannelDispatchOperation *pending_cdo;
200 TpAddDispatchOperationContext *pending_context;
202 gulong video_output_motion_handler_id;
203 guint bus_message_source_id;
205 GtkWidget *dtmf_panel;
208 GtkWidget *details_vbox;
209 GtkWidget *vcodec_encoding_label;
210 GtkWidget *acodec_encoding_label;
211 GtkWidget *vcodec_decoding_label;
212 GtkWidget *acodec_decoding_label;
214 GtkWidget *audio_remote_candidate_label;
215 GtkWidget *audio_local_candidate_label;
216 GtkWidget *video_remote_candidate_label;
217 GtkWidget *video_local_candidate_label;
218 GtkWidget *video_remote_candidate_info_img;
219 GtkWidget *video_local_candidate_info_img;
220 GtkWidget *audio_remote_candidate_info_img;
221 GtkWidget *audio_local_candidate_info_img;
223 GstElement *video_input;
224 GstElement *video_preview_sink;
225 GstElement *video_output_sink;
226 GstElement *audio_input;
227 GstElement *audio_output;
228 gboolean audio_output_added;
229 GstElement *pipeline;
230 GstElement *video_tee;
240 gboolean call_started;
241 gboolean sending_video;
242 CameraState camera_state;
244 EmpathyCallWindowFullscreen *fullscreen;
245 gboolean is_fullscreen;
250 guint inactivity_src;
252 /* Those fields represent the state of the window before it actually was in
254 gboolean dialpad_was_visible_before_fs;
255 gint original_width_before_fs;
256 gint original_height_before_fs;
258 gint x, y, w, h, dialpad_width;
261 /* TRUE if the call should be started when the pipeline is playing */
262 gboolean start_call_when_playing;
263 /* TRUE if we requested to set the pipeline in the playing state */
264 gboolean pipeline_playing;
266 EmpathySoundManager *sound_mgr;
269 EmpathyMicMenu *mic_menu;
270 EmpathyCameraMenu *camera_menu;
273 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
275 static void empathy_call_window_realized_cb (GtkWidget *widget,
276 EmpathyCallWindow *window);
278 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
279 GdkEvent *event, EmpathyCallWindow *window);
281 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
282 GdkEventWindowState *event, EmpathyCallWindow *window);
284 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
287 static void empathy_call_window_hangup_cb (gpointer object,
288 EmpathyCallWindow *window);
290 static void empathy_call_window_fullscreen_cb (gpointer object,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
295 static gboolean empathy_call_window_video_button_press_cb (
296 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
298 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
299 GdkEventKey *event, EmpathyCallWindow *window);
301 static gboolean empathy_call_window_video_output_motion_notify (
302 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
304 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
307 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
309 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
310 EmpathyCallWindow *window);
312 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
314 static void empathy_call_window_status_message (EmpathyCallWindow *window,
317 static gboolean empathy_call_window_bus_message (GstBus *bus,
318 GstMessage *message, gpointer user_data);
321 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
324 gtk_widget_set_visible (self->priv->hangup_button, show);
325 gtk_widget_set_visible (self->priv->audio_call_button, !show);
326 gtk_widget_set_visible (self->priv->video_call_button, !show);
330 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
331 EmpathyCallWindow *self)
333 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
334 empathy_call_window_restart_call (self);
338 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
339 EmpathyCallWindow *self)
341 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
342 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
343 empathy_call_window_restart_call (self);
347 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
349 EmpathyCallWindow *self)
354 g_object_get (self->priv->handler, "call-channel", &call, NULL);
356 tones[0] = tp_dtmf_event_to_char (event);
358 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
360 g_object_unref (call);
364 empathy_call_window_raise_actors (EmpathyCallWindow *self)
366 clutter_actor_raise_top (self->priv->floating_toolbar);
368 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
369 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
370 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
371 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
375 empathy_call_window_show_video_output (EmpathyCallWindow *self,
378 if (self->priv->video_output != NULL)
379 g_object_set (self->priv->video_output, "visible", show, NULL);
381 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
383 empathy_call_window_raise_actors (self);
387 create_video_output_widget (EmpathyCallWindow *self)
389 EmpathyCallWindowPriv *priv = GET_PRIV (self);
391 g_assert (priv->video_output == NULL);
392 g_assert (priv->pipeline != NULL);
394 priv->video_output = clutter_texture_new ();
396 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
399 priv->video_output_sink = clutter_gst_video_sink_new (
400 CLUTTER_TEXTURE (priv->video_output));
402 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
405 gtk_widget_add_events (priv->video_container,
406 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
407 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
408 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
412 create_video_input (EmpathyCallWindow *self)
414 EmpathyCallWindowPriv *priv = GET_PRIV (self);
416 g_assert (priv->video_input == NULL);
417 priv->video_input = empathy_video_src_new ();
418 gst_object_ref (priv->video_input);
419 gst_object_sink (priv->video_input);
423 audio_control_volume_to_element (GBinding *binding,
424 const GValue *source_value,
425 GValue *target_value,
428 /* AudioControl volume is 0-255, with -1 for unknown */
431 hv = g_value_get_int (source_value);
436 g_value_set_double (target_value, hv/255.0);
442 element_volume_to_audio_control (GBinding *binding,
443 const GValue *source_value,
444 GValue *target_value,
449 ev = g_value_get_double (source_value);
450 ev = CLAMP (ev, 0.0, 1.0);
452 g_value_set_int (target_value, ev * 255);
457 create_audio_input (EmpathyCallWindow *self)
459 EmpathyCallWindowPriv *priv = GET_PRIV (self);
461 g_assert (priv->audio_input == NULL);
462 priv->audio_input = empathy_audio_src_new ();
463 gst_object_ref (priv->audio_input);
464 gst_object_sink (priv->audio_input);
466 g_object_bind_property (priv->mic_button, "active",
467 priv->audio_input, "mute",
468 G_BINDING_BIDIRECTIONAL |
469 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
473 add_video_preview_to_pipeline (EmpathyCallWindow *self)
475 EmpathyCallWindowPriv *priv = GET_PRIV (self);
478 g_assert (priv->video_preview != NULL);
479 g_assert (priv->pipeline != NULL);
480 g_assert (priv->video_input != NULL);
481 g_assert (priv->video_tee != NULL);
483 preview = priv->video_preview_sink;
485 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
487 g_warning ("Could not add video input to pipeline");
491 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
493 g_warning ("Could not add video preview to pipeline");
497 if (!gst_element_link (priv->video_input, priv->video_tee))
499 g_warning ("Could not link video input to video tee");
503 if (!gst_element_link (priv->video_tee, preview))
505 g_warning ("Could not link video tee to video preview");
511 empathy_call_window_disable_camera_cb (GtkAction *action,
512 EmpathyCallWindow *self)
514 clutter_actor_destroy (self->priv->preview_hidden_button);
516 gtk_toggle_tool_button_set_active (
517 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
521 empathy_call_window_minimise_camera_cb (GtkAction *action,
522 EmpathyCallWindow *self)
524 clutter_actor_hide (self->priv->video_preview);
525 clutter_actor_show (self->priv->preview_hidden_button);
529 empathy_call_window_maximise_camera_cb (GtkAction *action,
530 EmpathyCallWindow *self)
532 clutter_actor_show (self->priv->video_preview);
533 clutter_actor_hide (self->priv->preview_hidden_button);
537 empathy_call_window_swap_camera_cb (GtkAction *action,
538 EmpathyCallWindow *self)
540 const GList *cameras, *l;
543 DEBUG ("Swapping the camera");
545 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
546 current_cam = empathy_video_src_dup_device (
547 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
549 for (l = cameras; l != NULL; l = l->next)
551 EmpathyCamera *camera = l->data;
553 if (!tp_strdiff (camera->device, current_cam))
558 next = l->next->data;
560 next = cameras->data;
562 /* EmpathyCameraMenu will update itself and do the actual change
564 g_settings_set_string (self->priv->settings,
565 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
572 g_free (current_cam);
576 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
577 EmpathyCamera *camera,
578 EmpathyCallWindow *self)
580 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
582 gtk_action_set_visible (self->priv->menu_swap_camera,
583 g_list_length ((GList *) cameras) >= 2);
587 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
588 EmpathyCamera *camera,
589 EmpathyCallWindow *self)
591 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
593 gtk_action_set_visible (self->priv->menu_swap_camera,
594 g_list_length ((GList *) cameras) >= 2);
598 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
599 EmpathyCallWindow *self)
603 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
605 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
606 0, gtk_get_current_event_time ());
607 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
611 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
612 EmpathyCallWindow *self)
616 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
617 "/preview-hidden-menu");
618 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
619 0, gtk_get_current_event_time ());
620 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
623 static ClutterActor *
624 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
626 ClutterBinAlignment x,
627 ClutterBinAlignment y)
629 ClutterLayoutManager *layout1, *layout2;
630 ClutterActor *rectangle;
631 ClutterActor *box1, *box2;
633 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
634 CLUTTER_BIN_ALIGNMENT_START);
636 box1 = clutter_box_new (layout1);
640 rectangle = empathy_rounded_rectangle_new (
641 SELF_VIDEO_SECTION_WIDTH + 5,
642 SELF_VIDEO_SECTION_HEIGHT + 5);
644 clutter_actor_set_size (box1,
645 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
646 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
647 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
649 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
650 CLUTTER_BIN_ALIGNMENT_CENTER);
652 /* We have a box with the margins and the video in the middle inside
653 * a bigger box with an extra bottom margin so we're not on top of
654 * the floating toolbar. */
655 box2 = clutter_box_new (layout2);
657 clutter_actor_set_size (box2,
658 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
659 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
661 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
662 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
664 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
667 clutter_actor_hide (rectangle);
673 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
675 self->priv->preview_rectangle1 =
676 empathy_call_window_create_preview_rectangle (self,
677 &self->priv->preview_rectangle_box1,
678 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
679 self->priv->preview_rectangle2 =
680 empathy_call_window_create_preview_rectangle (self,
681 &self->priv->preview_rectangle_box2,
682 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
683 self->priv->preview_rectangle3 =
684 empathy_call_window_create_preview_rectangle (self,
685 &self->priv->preview_rectangle_box3,
686 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
687 self->priv->preview_rectangle4 =
688 empathy_call_window_create_preview_rectangle (self,
689 &self->priv->preview_rectangle_box4,
690 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
694 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
697 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
704 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
709 guint ret_x = 0, ret_y = 0;
712 if (!clutter_actor_has_allocation (self->priv->video_box))
715 clutter_actor_get_geometry (self->priv->video_box, &box);
719 case PREVIEW_POS_TOP_LEFT:
720 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
722 case PREVIEW_POS_TOP_RIGHT:
723 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
724 - SELF_VIDEO_SECTION_WIDTH;
725 ret_y = SELF_VIDEO_SECTION_MARGIN;
727 case PREVIEW_POS_BOTTOM_LEFT:
728 ret_x = SELF_VIDEO_SECTION_MARGIN;
729 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
730 - SELF_VIDEO_SECTION_HEIGHT
731 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
733 case PREVIEW_POS_BOTTOM_RIGHT:
734 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
735 - SELF_VIDEO_SECTION_WIDTH;
736 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
738 - FLOATING_TOOLBAR_SPACING;
741 g_warn_if_reached ();
752 static PreviewPosition
753 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
758 PreviewPosition pos = PREVIEW_POS_NONE;
760 if (!clutter_actor_has_allocation (self->priv->video_box))
763 clutter_actor_get_geometry (self->priv->video_box, &box);
765 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
766 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
767 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
768 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
770 pos = PREVIEW_POS_TOP_LEFT;
772 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
773 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
774 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
775 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
777 pos = PREVIEW_POS_TOP_RIGHT;
779 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
780 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
781 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
782 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
784 pos = PREVIEW_POS_BOTTOM_LEFT;
786 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
787 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
788 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
789 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
791 pos = PREVIEW_POS_BOTTOM_RIGHT;
797 static ClutterActor *
798 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
801 ClutterActor *rectangle;
805 case PREVIEW_POS_TOP_LEFT:
806 rectangle = self->priv->preview_rectangle1;
808 case PREVIEW_POS_TOP_RIGHT:
809 rectangle = self->priv->preview_rectangle3;
811 case PREVIEW_POS_BOTTOM_LEFT:
812 rectangle = self->priv->preview_rectangle2;
814 case PREVIEW_POS_BOTTOM_RIGHT:
815 rectangle = self->priv->preview_rectangle4;
825 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
828 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
830 DEBUG ("moving the video preview to %d", pos);
832 self->priv->preview_pos = pos;
836 case PREVIEW_POS_TOP_LEFT:
837 clutter_bin_layout_set_alignment (layout,
838 self->priv->video_preview,
839 CLUTTER_BIN_ALIGNMENT_START,
840 CLUTTER_BIN_ALIGNMENT_START);
842 case PREVIEW_POS_TOP_RIGHT:
843 clutter_bin_layout_set_alignment (layout,
844 self->priv->video_preview,
845 CLUTTER_BIN_ALIGNMENT_END,
846 CLUTTER_BIN_ALIGNMENT_START);
848 case PREVIEW_POS_BOTTOM_LEFT:
849 clutter_bin_layout_set_alignment (layout,
850 self->priv->video_preview,
851 CLUTTER_BIN_ALIGNMENT_START,
852 CLUTTER_BIN_ALIGNMENT_END);
854 case PREVIEW_POS_BOTTOM_RIGHT:
855 clutter_bin_layout_set_alignment (layout,
856 self->priv->video_preview,
857 CLUTTER_BIN_ALIGNMENT_END,
858 CLUTTER_BIN_ALIGNMENT_END);
861 g_warn_if_reached ();
864 g_settings_set_enum (self->priv->settings, "camera-position", pos);
868 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
871 ClutterActor *rectangle;
873 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
875 empathy_rounded_rectangle_set_border_width (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
877 empathy_rounded_rectangle_set_border_color (
878 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
882 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
883 ClutterActor *rectangle)
885 empathy_rounded_rectangle_set_border_width (
886 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
887 empathy_rounded_rectangle_set_border_color (
888 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
892 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
894 ClutterActor *rectangle;
896 rectangle = empathy_call_window_get_preview_rectangle (self,
897 self->priv->preview_pos);
899 /* We don't want to darken the rectangle where the preview
902 if (self->priv->preview_rectangle1 != rectangle)
903 empathy_call_window_darken_preview_rectangle (self,
904 self->priv->preview_rectangle1);
906 if (self->priv->preview_rectangle2 != rectangle)
907 empathy_call_window_darken_preview_rectangle (self,
908 self->priv->preview_rectangle2);
910 if (self->priv->preview_rectangle3 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle3);
914 if (self->priv->preview_rectangle4 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle4);
920 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
924 ClutterModifierType modifiers,
925 EmpathyCallWindow *self)
927 ClutterActor *stage = clutter_actor_get_stage (actor);
930 self->priv->drag_preview = clutter_clone_new (actor);
932 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
933 self->priv->drag_preview);
935 clutter_actor_transform_stage_point (actor, event_x, event_y,
938 clutter_actor_set_position (self->priv->drag_preview,
939 event_x - rel_x, event_y - rel_y);
941 clutter_drag_action_set_drag_handle (action,
942 self->priv->drag_preview);
944 clutter_actor_set_opacity (actor, 0);
945 clutter_actor_hide (self->priv->preview_shown_button);
947 empathy_call_window_show_preview_rectangles (self, TRUE);
948 empathy_call_window_darken_preview_rectangles (self);
952 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
955 clutter_actor_set_opacity (actor, 255);
959 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
963 ClutterModifierType modifiers,
964 EmpathyCallWindow *self)
969 /* Get the position before destroying the drag actor, otherwise the
970 * preview_box allocation won't be valid and we won't be able to
971 * calculate the position. */
972 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
974 empathy_call_window_get_preview_coordinates (self,
975 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
978 /* Move the preview to the destination and destroy it afterwards */
979 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
982 "signal-swapped-after::completed",
983 clutter_actor_destroy, self->priv->drag_preview,
984 "signal-swapped-after::completed",
985 clutter_actor_show, self->priv->preview_shown_button,
987 empathy_call_window_on_animation_completed_cb, actor,
990 self->priv->drag_preview = NULL;
992 if (pos != PREVIEW_POS_NONE)
993 empathy_call_window_move_video_preview (self, pos);
995 empathy_call_window_show_preview_rectangles (self, FALSE);
999 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1000 ClutterActor *actor,
1003 EmpathyCallWindow *self)
1005 PreviewPosition pos;
1006 gfloat event_x, event_y;
1008 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1010 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1012 if (pos != PREVIEW_POS_NONE)
1013 empathy_call_window_highlight_preview_rectangle (self, pos);
1015 empathy_call_window_darken_preview_rectangles (self);
1019 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1020 ClutterCrossingEvent *event,
1021 EmpathyCallWindow *self)
1023 ClutterActor *rectangle;
1025 rectangle = empathy_call_window_get_preview_rectangle (self,
1026 self->priv->preview_pos);
1028 empathy_call_window_highlight_preview_rectangle (self,
1029 self->priv->preview_pos);
1031 clutter_actor_show (rectangle);
1037 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1038 ClutterCrossingEvent *event,
1039 EmpathyCallWindow *self)
1041 ClutterActor *rectangle;
1043 rectangle = empathy_call_window_get_preview_rectangle (self,
1044 self->priv->preview_pos);
1046 empathy_call_window_darken_preview_rectangle (self, rectangle);
1048 clutter_actor_hide (rectangle);
1054 create_video_preview (EmpathyCallWindow *self)
1056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1057 ClutterLayoutManager *layout, *layout_center, *layout_end;
1058 ClutterActor *preview;
1061 ClutterAction *action;
1063 PreviewPosition pos;
1064 GdkRGBA transparent = { 0., 0., 0., 0. };
1066 g_assert (priv->video_preview == NULL);
1068 pos = g_settings_get_enum (priv->settings, "camera-position");
1070 preview = empathy_rounded_texture_new ();
1071 clutter_actor_set_size (preview,
1072 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1073 priv->video_preview_sink = clutter_gst_video_sink_new (
1074 CLUTTER_TEXTURE (preview));
1076 /* Add a little offset to the video preview */
1077 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1078 CLUTTER_BIN_ALIGNMENT_START);
1079 priv->video_preview = clutter_box_new (layout);
1080 clutter_actor_set_size (priv->video_preview,
1081 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1082 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1083 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1085 /* Spinner for when changing the camera device */
1086 priv->preview_spinner_widget = gtk_spinner_new ();
1087 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1088 empathy_rounded_actor_set_round_factor (
1089 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1091 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1092 gtk_widget_override_background_color (
1093 gtk_clutter_actor_get_widget (
1094 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1095 GTK_STATE_FLAG_NORMAL, &transparent);
1096 gtk_widget_show (priv->preview_spinner_widget);
1099 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1100 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1101 priv->preview_spinner_widget);
1102 clutter_actor_set_size (priv->preview_spinner_actor,
1103 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1104 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1105 clutter_actor_hide (priv->preview_spinner_actor);
1107 /* We have a box with the margins and the video in the middle inside
1108 * a bigger box with an extra bottom margin so we're not on top of
1109 * the floating toolbar. */
1110 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1111 CLUTTER_BIN_ALIGNMENT_CENTER);
1112 box = clutter_box_new (layout_center);
1113 clutter_actor_set_size (box,
1114 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1115 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1117 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1118 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1119 priv->preview_spinner_actor);
1120 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1122 g_object_set (priv->video_preview_sink,
1127 /* Translators: this is an "Info" label. It should be as short
1129 button = gtk_button_new_with_label (_("i"));
1130 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1132 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1134 clutter_actor_set_size (b, 24, 24);
1136 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1137 CLUTTER_BIN_ALIGNMENT_END);
1138 box = clutter_box_new (layout_end);
1139 clutter_actor_set_size (box,
1140 SELF_VIDEO_SECTION_WIDTH,
1141 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1143 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1144 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1146 g_signal_connect (button, "clicked",
1147 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1150 /* Translators: this is an "Info" label. It should be as short
1152 button = gtk_button_new_with_label (_("i"));
1153 b = empathy_rounded_actor_new ();
1155 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1157 clutter_actor_set_size (b, 24, 24);
1158 priv->preview_hidden_button = b;
1160 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1161 priv->preview_hidden_button,
1162 CLUTTER_BIN_ALIGNMENT_START,
1163 CLUTTER_BIN_ALIGNMENT_END);
1165 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1167 clutter_actor_hide (priv->preview_hidden_button);
1169 g_signal_connect (button, "clicked",
1170 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1173 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1174 priv->video_preview,
1175 CLUTTER_BIN_ALIGNMENT_START,
1176 CLUTTER_BIN_ALIGNMENT_END);
1178 empathy_call_window_move_video_preview (self, pos);
1180 action = clutter_drag_action_new ();
1181 g_signal_connect (action, "drag-begin",
1182 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1183 g_signal_connect (action, "drag-end",
1184 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1185 g_signal_connect (action, "drag-motion",
1186 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1188 g_signal_connect (preview, "enter-event",
1189 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1190 g_signal_connect (preview, "leave-event",
1191 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1193 clutter_actor_add_action (preview, action);
1194 clutter_actor_set_reactive (preview, TRUE);
1195 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1199 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1201 clutter_actor_show (self->priv->preview_spinner_actor);
1202 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1206 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1208 clutter_actor_hide (self->priv->preview_spinner_actor);
1209 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1213 empathy_call_window_play_camera (EmpathyCallWindow *self,
1216 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1217 GstElement *preview;
1220 if (priv->video_preview == NULL)
1222 create_video_preview (self);
1223 add_video_preview_to_pipeline (self);
1228 state = GST_STATE_PLAYING;
1232 empathy_call_window_start_camera_spinning (self);
1233 state = GST_STATE_NULL;
1236 preview = priv->video_preview_sink;
1238 gst_element_set_state (preview, state);
1239 gst_element_set_state (priv->video_tee, state);
1240 gst_element_set_state (priv->video_input, state);
1244 display_video_preview (EmpathyCallWindow *self,
1247 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1249 if (priv->video_preview == NULL)
1251 create_video_preview (self);
1252 add_video_preview_to_pipeline (self);
1257 /* Display the video preview */
1258 DEBUG ("Show video preview");
1260 empathy_call_window_play_camera (self, TRUE);
1261 clutter_actor_show (priv->video_preview);
1262 clutter_actor_raise_top (priv->floating_toolbar);
1266 /* Hide the video preview */
1267 DEBUG ("Hide video preview");
1269 if (priv->video_preview != NULL)
1271 clutter_actor_hide (priv->video_preview);
1272 empathy_call_window_play_camera (self, FALSE);
1278 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1280 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1282 empathy_call_window_status_message (window, _("Connecting…"));
1283 priv->call_state = CONNECTING;
1285 /* Show the toolbar */
1286 clutter_state_set_state (priv->transitions, "fade-in");
1289 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1290 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1294 disable_camera (EmpathyCallWindow *self)
1296 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1298 if (priv->camera_state == CAMERA_STATE_OFF)
1301 DEBUG ("Disable camera");
1303 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1305 priv->camera_state = CAMERA_STATE_OFF;
1309 enable_camera (EmpathyCallWindow *self)
1311 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1313 if (priv->camera_state == CAMERA_STATE_ON)
1316 if (priv->video_input == NULL)
1318 DEBUG ("Can't enable camera, no input");
1322 DEBUG ("Enable camera");
1324 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1326 priv->camera_state = CAMERA_STATE_ON;
1330 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1331 EmpathyCallWindow *self)
1333 if (gtk_toggle_tool_button_get_active (toggle))
1334 enable_camera (self);
1336 disable_camera (self);
1340 create_pipeline (EmpathyCallWindow *self)
1342 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1345 g_assert (priv->pipeline == NULL);
1347 priv->pipeline = gst_pipeline_new (NULL);
1348 priv->pipeline_playing = FALSE;
1350 priv->video_tee = gst_element_factory_make ("tee", NULL);
1351 gst_object_ref (priv->video_tee);
1352 gst_object_sink (priv->video_tee);
1354 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1356 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1357 priv->bus_message_source_id = gst_bus_add_watch (bus,
1358 empathy_call_window_bus_message, self);
1360 g_object_unref (bus);
1364 empathy_call_window_settings_cb (GtkAction *action,
1365 EmpathyCallWindow *self)
1367 gchar *args = g_strdup_printf ("-p %s",
1368 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1370 empathy_launch_program (BIN_DIR, "empathy", args);
1376 empathy_call_window_contents_cb (GtkAction *action,
1377 EmpathyCallWindow *self)
1379 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1383 empathy_call_window_debug_cb (GtkAction *action,
1384 EmpathyCallWindow *self)
1386 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1390 empathy_call_window_about_cb (GtkAction *action,
1391 EmpathyCallWindow *self)
1393 empathy_about_dialog_new (GTK_WINDOW (self));
1397 empathy_call_window_toolbar_timeout (gpointer data)
1399 EmpathyCallWindow *self = data;
1401 /* We don't want to hide the toolbar if we're not in a call, as
1402 * to show the call status all the time. */
1403 if (self->priv->call_state != CONNECTING &&
1404 self->priv->call_state != DISCONNECTED)
1405 clutter_state_set_state (self->priv->transitions, "fade-out");
1411 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1413 EmpathyCallWindow *self)
1415 clutter_state_set_state (self->priv->transitions, "fade-in");
1417 if (self->priv->inactivity_src > 0)
1418 g_source_remove (self->priv->inactivity_src);
1420 self->priv->inactivity_src = g_timeout_add_seconds (3,
1421 empathy_call_window_toolbar_timeout, self);
1427 empathy_call_window_configure_event_cb (GtkWidget *widget,
1429 EmpathyCallWindow *self)
1431 GdkWindow *gdk_window;
1432 GdkWindowState window_state;
1434 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1435 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1437 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1438 &self->priv->dialpad_width, NULL);
1440 gdk_window = gtk_widget_get_window (widget);
1441 window_state = gdk_window_get_state (gdk_window);
1442 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1448 empathy_call_window_destroyed_cb (GtkWidget *object,
1449 EmpathyCallWindow *self)
1451 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1453 /* Save the geometry as if the dialpad was hidden. */
1454 empathy_geometry_save_values (GTK_WINDOW (self),
1455 self->priv->x, self->priv->y,
1456 self->priv->w - self->priv->dialpad_width, self->priv->h,
1457 self->priv->maximized);
1462 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1464 ClutterBindConstraint *constraint)
1466 ClutterActorBox allocation;
1468 clutter_actor_get_allocation_box (stage, &allocation);
1470 clutter_bind_constraint_set_offset (constraint,
1471 allocation.y2 - allocation.y1 -
1472 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1476 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1478 EmpathyCallWindow *self)
1480 switch (response_id)
1482 case GTK_RESPONSE_ACCEPT:
1483 tp_channel_dispatch_operation_handle_with_async (
1484 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1486 tp_clear_object (&self->priv->pending_cdo);
1487 tp_clear_object (&self->priv->pending_channel);
1488 tp_clear_object (&self->priv->pending_context);
1491 case GTK_RESPONSE_CANCEL:
1492 tp_channel_dispatch_operation_close_channels_async (
1493 self->priv->pending_cdo, NULL, NULL);
1495 empathy_call_window_status_message (self, _("Disconnected"));
1496 self->priv->call_state = DISCONNECTED;
1499 g_warn_if_reached ();
1504 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1508 g_assert (self->priv->call_state != CONNECTED);
1510 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1512 empathy_call_window_status_message (self, _("Incoming call"));
1513 self->priv->call_state = RINGING;
1515 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1516 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1517 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1518 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1519 empathy_contact_get_alias (self->priv->contact));
1521 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1522 _("Reject"), GTK_RESPONSE_CANCEL,
1523 _("Answer"), GTK_RESPONSE_ACCEPT,
1526 g_signal_connect (self->priv->incoming_call_dialog, "response",
1527 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1528 gtk_widget_show (self->priv->incoming_call_dialog);
1532 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1536 EmpathyCallWindow *self)
1538 tp_clear_object (&self->priv->pending_cdo);
1539 tp_clear_object (&self->priv->pending_channel);
1540 tp_clear_object (&self->priv->pending_context);
1542 /* We don't know if the incoming call has been accepted or not, so we
1543 * assume it hasn't and if it has, we'll set the proper status when
1544 * we get the new handler. */
1545 empathy_call_window_status_message (self, _("Disconnected"));
1546 self->priv->call_state = DISCONNECTED;
1548 gtk_widget_destroy (self->priv->incoming_call_dialog);
1549 self->priv->incoming_call_dialog = NULL;
1553 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1554 TpCallChannel *channel,
1555 TpChannelDispatchOperation *dispatch_operation,
1556 TpAddDispatchOperationContext *context)
1558 g_assert (self->priv->pending_channel == NULL);
1559 g_assert (self->priv->pending_context == NULL);
1560 g_assert (self->priv->pending_cdo == NULL);
1562 /* Start ringing and delay until the user answers or hangs. */
1563 self->priv->pending_channel = g_object_ref (channel);
1564 self->priv->pending_context = g_object_ref (context);
1565 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1567 g_signal_connect (self->priv->pending_cdo, "invalidated",
1568 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1570 empathy_call_window_set_state_ringing (self);
1571 tp_add_dispatch_operation_context_accept (context);
1575 empathy_call_window_init (EmpathyCallWindow *self)
1577 EmpathyCallWindowPriv *priv;
1579 GtkWidget *top_vbox;
1581 ClutterConstraint *constraint;
1582 ClutterActor *remote_avatar;
1583 GtkStyleContext *context;
1587 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1588 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1590 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1592 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1593 gui = empathy_builder_get_file (filename,
1594 "call_window_vbox", &top_vbox,
1595 "errors_vbox", &priv->errors_vbox,
1596 "pane", &priv->pane,
1597 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1598 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1599 "status_label", &priv->status_label,
1600 "audiocall", &priv->audio_call_button,
1601 "videocall", &priv->video_call_button,
1602 "microphone", &priv->mic_button,
1603 "volume", &priv->volume_button,
1604 "camera", &priv->camera_button,
1605 "hangup", &priv->hangup_button,
1606 "dialpad", &priv->dialpad_button,
1607 "toolbar", &priv->toolbar,
1608 "bottom_toolbar", &priv->bottom_toolbar,
1609 "ui_manager", &priv->ui_manager,
1610 "menufullscreen", &priv->menu_fullscreen,
1611 "menupreviewswap", &priv->menu_swap_camera,
1612 "details_vbox", &priv->details_vbox,
1613 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1614 "acodec_encoding_label", &priv->acodec_encoding_label,
1615 "acodec_decoding_label", &priv->acodec_decoding_label,
1616 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1617 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1618 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1619 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1620 "video_local_candidate_label", &priv->video_local_candidate_label,
1621 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1622 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1623 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1624 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1628 empathy_builder_connect (gui, self,
1629 "hangup", "clicked", empathy_call_window_hangup_cb,
1630 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1631 "videocall", "clicked", empathy_call_window_video_call_cb,
1632 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1633 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1634 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1635 "menusettings", "activate", empathy_call_window_settings_cb,
1636 "menucontents", "activate", empathy_call_window_contents_cb,
1637 "menudebug", "activate", empathy_call_window_debug_cb,
1638 "menuabout", "activate", empathy_call_window_about_cb,
1639 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1640 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1641 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1642 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1645 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1647 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1649 g_object_bind_property (priv->camera_monitor, "available",
1650 priv->camera_button, "sensitive",
1651 G_BINDING_SYNC_CREATE);
1653 g_signal_connect (priv->camera_monitor, "added",
1654 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1655 g_signal_connect (priv->camera_monitor, "removed",
1656 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1658 priv->lock = g_mutex_new ();
1660 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1662 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1663 CONTENT_HBOX_SPACING);
1664 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1665 CONTENT_HBOX_BORDER_WIDTH);
1666 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1669 /* avatar/video box */
1670 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1671 CLUTTER_BIN_ALIGNMENT_CENTER);
1673 priv->video_box = clutter_box_new (priv->video_layout);
1675 priv->video_container = gtk_clutter_embed_new ();
1677 gtk_widget_set_size_request (priv->video_container,
1678 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1680 /* Set the background color to that of the rest of the window */
1681 context = gtk_widget_get_style_context (priv->content_hbox);
1682 gtk_style_context_get_background_color (context,
1683 GTK_STATE_FLAG_NORMAL, &rgba);
1684 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1685 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1686 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1687 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1688 clutter_stage_set_color (
1689 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1690 GTK_CLUTTER_EMBED (priv->video_container))),
1693 clutter_container_add (
1694 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1695 GTK_CLUTTER_EMBED (priv->video_container))),
1699 constraint = clutter_bind_constraint_new (
1700 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1701 CLUTTER_BIND_SIZE, 0);
1702 clutter_actor_add_constraint (priv->video_box, constraint);
1704 priv->remote_user_avatar_widget = gtk_image_new ();
1705 remote_avatar = gtk_clutter_actor_new_with_contents (
1706 priv->remote_user_avatar_widget);
1708 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1711 empathy_call_window_create_preview_rectangles (self);
1713 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1714 priv->video_container, TRUE, TRUE,
1715 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1717 create_pipeline (self);
1718 create_video_output_widget (self);
1719 create_audio_input (self);
1720 create_video_input (self);
1722 priv->floating_toolbar = empathy_rounded_actor_new ();
1724 gtk_widget_reparent (priv->bottom_toolbar,
1725 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1727 constraint = clutter_bind_constraint_new (
1728 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1731 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1734 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1735 "notify::allocation",
1736 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1739 clutter_actor_set_size (priv->floating_toolbar,
1740 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1741 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1743 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1744 priv->floating_toolbar,
1745 CLUTTER_BIN_ALIGNMENT_CENTER,
1746 CLUTTER_BIN_ALIGNMENT_END);
1748 clutter_actor_raise_top (priv->floating_toolbar);
1750 /* Transitions for the floating toolbar */
1751 priv->transitions = clutter_state_new ();
1753 /* all transitions last for 2s */
1754 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1756 /* transition from any state to "fade-out" state */
1757 clutter_state_set (priv->transitions, NULL, "fade-out",
1758 priv->floating_toolbar,
1759 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1762 /* transition from any state to "fade-in" state */
1763 clutter_state_set (priv->transitions, NULL, "fade-in",
1764 priv->floating_toolbar,
1765 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1768 /* put the actor into the "fade-in" state with no animation */
1769 clutter_state_warp_to_state (priv->transitions, "fade-in");
1771 /* The call will be started as soon the pipeline is playing */
1772 priv->start_call_when_playing = TRUE;
1774 priv->dtmf_panel = empathy_dialpad_widget_new ();
1775 g_signal_connect (priv->dtmf_panel, "start-tone",
1776 G_CALLBACK (dtmf_start_tone_cb), self);
1778 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1781 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1784 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1786 gtk_widget_show_all (top_vbox);
1788 gtk_widget_hide (priv->dtmf_panel);
1789 gtk_widget_hide (priv->details_vbox);
1791 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1793 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1794 priv->video_container);
1796 /* We hide the bottom toolbar after 3s of inactivity and show it
1797 * again on mouse movement */
1798 priv->inactivity_src = g_timeout_add_seconds (3,
1799 empathy_call_window_toolbar_timeout, self);
1801 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1802 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1804 g_signal_connect (G_OBJECT (self), "realize",
1805 G_CALLBACK (empathy_call_window_realized_cb), self);
1807 g_signal_connect (G_OBJECT (self), "delete-event",
1808 G_CALLBACK (empathy_call_window_delete_cb), self);
1810 g_signal_connect (G_OBJECT (self), "window-state-event",
1811 G_CALLBACK (empathy_call_window_state_event_cb), self);
1813 g_signal_connect (G_OBJECT (self), "key-press-event",
1814 G_CALLBACK (empathy_call_window_key_press_cb), self);
1816 g_signal_connect (self, "motion-notify-event",
1817 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1819 priv->timer = g_timer_new ();
1821 g_object_ref (priv->ui_manager);
1822 g_object_unref (gui);
1824 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1825 priv->mic_menu = empathy_mic_menu_new (self);
1826 priv->camera_menu = empathy_camera_menu_new (self);
1828 empathy_call_window_show_hangup_button (self, TRUE);
1830 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1831 /* These signals are used to track the window position and save it
1832 * when the window is destroyed. We need to do this as we don't want
1833 * the window geometry to be saved with the dialpad taken into account. */
1834 g_signal_connect (self, "destroy",
1835 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1836 g_signal_connect (self, "configure-event",
1837 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1838 g_signal_connect (self, "window-state-event",
1839 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1841 /* Don't display labels in both toolbars */
1842 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1845 /* Instead of specifying a width and a height, we specify only one size. That's
1846 because we want a square avatar icon. */
1848 init_contact_avatar_with_size (EmpathyContact *contact,
1849 GtkWidget *image_widget,
1852 GdkPixbuf *pixbuf_avatar = NULL;
1854 if (contact != NULL)
1856 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1860 if (pixbuf_avatar == NULL)
1862 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1863 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1866 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1868 if (pixbuf_avatar != NULL)
1869 g_object_unref (pixbuf_avatar);
1873 set_window_title (EmpathyCallWindow *self)
1875 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1878 if (priv->contact != NULL)
1880 /* translators: Call is a noun and %s is the contact name. This string
1881 * is used in the window title */
1882 tmp = g_strdup_printf (_("Call with %s"),
1883 empathy_contact_get_alias (priv->contact));
1884 gtk_window_set_title (GTK_WINDOW (self), tmp);
1889 g_warning ("Unknown remote contact!");
1894 set_remote_user_name (EmpathyCallWindow *self,
1895 EmpathyContact *contact)
1897 const gchar *alias = empathy_contact_get_alias (contact);
1898 const gchar *status = empathy_contact_get_status (contact);
1901 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1902 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1908 contact_name_changed_cb (EmpathyContact *contact,
1910 EmpathyCallWindow *self)
1912 set_window_title (self);
1913 set_remote_user_name (self, contact);
1917 contact_presence_changed_cb (EmpathyContact *contact,
1919 EmpathyCallWindow *self)
1921 set_remote_user_name (self, contact);
1925 contact_avatar_changed_cb (EmpathyContact *contact,
1927 EmpathyCallWindow *self)
1930 GtkAllocation allocation;
1931 GtkWidget *avatar_widget;
1933 avatar_widget = self->priv->remote_user_avatar_widget;
1935 gtk_widget_get_allocation (avatar_widget, &allocation);
1936 size = allocation.height;
1940 /* the widget is not allocated yet, set a default size */
1941 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1942 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1945 init_contact_avatar_with_size (contact, avatar_widget, size);
1947 avatar_widget = self->priv->remote_user_avatar_toolbar;
1949 gtk_widget_get_allocation (avatar_widget, &allocation);
1950 size = allocation.height;
1954 /* the widget is not allocated yet, set a default size */
1955 size = SMALL_TOOLBAR_SIZE;
1958 init_contact_avatar_with_size (contact, avatar_widget, size);
1962 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1963 EmpathyCallHandler *handler)
1965 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1967 tp_g_signal_connect_object (priv->contact, "notify::name",
1968 G_CALLBACK (contact_name_changed_cb), self, 0);
1969 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1970 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1971 tp_g_signal_connect_object (priv->contact, "notify::presence",
1972 G_CALLBACK (contact_presence_changed_cb), self, 0);
1974 set_window_title (self);
1975 set_remote_user_name (self, priv->contact);
1977 init_contact_avatar_with_size (priv->contact,
1978 priv->remote_user_avatar_widget,
1979 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1980 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1982 init_contact_avatar_with_size (priv->contact,
1983 priv->remote_user_avatar_toolbar,
1984 SMALL_TOOLBAR_SIZE);
1986 /* The remote avatar is shown by default and will be hidden when we receive
1987 video from the remote side. */
1988 clutter_actor_hide (priv->video_output);
1989 gtk_widget_show (priv->remote_user_avatar_widget);
1993 update_send_codec (EmpathyCallWindow *self,
1996 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2003 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2004 widget = priv->acodec_encoding_label;
2008 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2009 widget = priv->vcodec_encoding_label;
2015 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2016 gtk_label_set_text (GTK_LABEL (widget), tmp);
2021 send_audio_codec_notify_cb (GObject *object,
2025 EmpathyCallWindow *self = user_data;
2027 update_send_codec (self, TRUE);
2031 send_video_codec_notify_cb (GObject *object,
2035 EmpathyCallWindow *self = user_data;
2037 update_send_codec (self, FALSE);
2041 update_recv_codec (EmpathyCallWindow *self,
2044 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2047 GString *str = NULL;
2051 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2052 widget = priv->acodec_decoding_label;
2056 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2057 widget = priv->vcodec_decoding_label;
2063 for (l = codecs; l != NULL; l = g_list_next (l))
2065 FsCodec *codec = l->data;
2068 str = g_string_new (NULL);
2070 g_string_append (str, ", ");
2072 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2076 gtk_label_set_text (GTK_LABEL (widget), str->str);
2077 g_string_free (str, TRUE);
2081 recv_audio_codecs_notify_cb (GObject *object,
2085 EmpathyCallWindow *self = user_data;
2087 update_recv_codec (self, TRUE);
2091 recv_video_codecs_notify_cb (GObject *object,
2095 EmpathyCallWindow *self = user_data;
2097 update_recv_codec (self, FALSE);
2100 static const gchar *
2101 candidate_type_to_str (FsCandidate *candidate)
2103 switch (candidate->type)
2105 case FS_CANDIDATE_TYPE_HOST:
2107 case FS_CANDIDATE_TYPE_SRFLX:
2108 return "server reflexive";
2109 case FS_CANDIDATE_TYPE_PRFLX:
2110 return "peer reflexive";
2111 case FS_CANDIDATE_TYPE_RELAY:
2113 case FS_CANDIDATE_TYPE_MULTICAST:
2120 static const gchar *
2121 candidate_type_to_desc (FsCandidate *candidate)
2123 switch (candidate->type)
2125 case FS_CANDIDATE_TYPE_HOST:
2126 return _("The IP address as seen by the machine");
2127 case FS_CANDIDATE_TYPE_SRFLX:
2128 return _("The IP address as seen by a server on the Internet");
2129 case FS_CANDIDATE_TYPE_PRFLX:
2130 return _("The IP address of the peer as seen by the other side");
2131 case FS_CANDIDATE_TYPE_RELAY:
2132 return _("The IP address of a relay server");
2133 case FS_CANDIDATE_TYPE_MULTICAST:
2134 return _("The IP address of the multicast group");
2141 update_candidat_widget (EmpathyCallWindow *self,
2144 FsCandidate *candidate)
2148 g_assert (candidate != NULL);
2149 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2150 candidate->port, candidate_type_to_str (candidate));
2152 gtk_label_set_text (GTK_LABEL (label), str);
2153 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2159 candidates_changed_cb (GObject *object,
2161 EmpathyCallWindow *self)
2163 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2164 FsCandidate *candidate = NULL;
2166 if (type == FS_MEDIA_TYPE_VIDEO)
2168 /* Update remote candidate */
2169 candidate = empathy_call_handler_get_video_remote_candidate (
2172 update_candidat_widget (self, priv->video_remote_candidate_label,
2173 priv->video_remote_candidate_info_img, candidate);
2175 /* Update local candidate */
2176 candidate = empathy_call_handler_get_video_local_candidate (
2179 update_candidat_widget (self, priv->video_local_candidate_label,
2180 priv->video_local_candidate_info_img, candidate);
2184 /* Update remote candidate */
2185 candidate = empathy_call_handler_get_audio_remote_candidate (
2188 update_candidat_widget (self, priv->audio_remote_candidate_label,
2189 priv->audio_remote_candidate_info_img, candidate);
2191 /* Update local candidate */
2192 candidate = empathy_call_handler_get_audio_local_candidate (
2195 update_candidat_widget (self, priv->audio_local_candidate_label,
2196 priv->audio_local_candidate_info_img, candidate);
2201 empathy_call_window_constructed (GObject *object)
2203 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2204 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2205 TpCallChannel *call;
2208 g_assert (priv->handler != NULL);
2210 g_object_get (priv->handler, "call-channel", &call, NULL);
2211 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2212 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2213 tp_clear_object (&call);
2215 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2216 g_assert (priv->contact != NULL);
2218 if (!empathy_contact_can_voip_video (priv->contact))
2220 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2221 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2224 empathy_call_window_setup_avatars (self, priv->handler);
2225 empathy_call_window_set_state_connecting (self);
2227 if (!empathy_call_handler_has_initial_video (priv->handler))
2229 gtk_toggle_tool_button_set_active (
2230 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2232 /* If call has InitialVideo, the preview will be started once the call has
2233 * been started (start_call()). */
2235 update_send_codec (self, TRUE);
2236 update_send_codec (self, FALSE);
2237 update_recv_codec (self, TRUE);
2238 update_recv_codec (self, FALSE);
2240 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2241 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2242 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2243 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2244 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2245 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2246 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2247 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2249 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2250 G_CALLBACK (candidates_changed_cb), self, 0);
2253 static void empathy_call_window_dispose (GObject *object);
2254 static void empathy_call_window_finalize (GObject *object);
2257 empathy_call_window_set_property (GObject *object,
2258 guint property_id, const GValue *value, GParamSpec *pspec)
2260 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2262 switch (property_id)
2264 case PROP_CALL_HANDLER:
2265 priv->handler = g_value_dup_object (value);
2268 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2273 empathy_call_window_get_property (GObject *object,
2274 guint property_id, GValue *value, GParamSpec *pspec)
2276 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2278 switch (property_id)
2280 case PROP_CALL_HANDLER:
2281 g_value_set_object (value, priv->handler);
2284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2289 empathy_call_window_class_init (
2290 EmpathyCallWindowClass *empathy_call_window_class)
2292 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2293 GParamSpec *param_spec;
2295 g_type_class_add_private (empathy_call_window_class,
2296 sizeof (EmpathyCallWindowPriv));
2298 object_class->constructed = empathy_call_window_constructed;
2299 object_class->set_property = empathy_call_window_set_property;
2300 object_class->get_property = empathy_call_window_get_property;
2302 object_class->dispose = empathy_call_window_dispose;
2303 object_class->finalize = empathy_call_window_finalize;
2305 param_spec = g_param_spec_object ("handler",
2306 "handler", "The call handler",
2307 EMPATHY_TYPE_CALL_HANDLER,
2308 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2309 g_object_class_install_property (object_class,
2310 PROP_CALL_HANDLER, param_spec);
2314 empathy_call_window_dispose (GObject *object)
2316 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2317 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2319 if (priv->dispose_has_run)
2322 priv->dispose_has_run = TRUE;
2324 if (priv->handler != NULL)
2326 empathy_call_handler_stop_call (priv->handler);
2327 tp_clear_object (&priv->handler);
2330 if (priv->bus_message_source_id != 0)
2332 g_source_remove (priv->bus_message_source_id);
2333 priv->bus_message_source_id = 0;
2336 if (priv->got_video_src > 0)
2338 g_source_remove (priv->got_video_src);
2339 priv->got_video_src = 0;
2342 if (priv->inactivity_src > 0)
2344 g_source_remove (priv->inactivity_src);
2345 priv->inactivity_src = 0;
2348 tp_clear_object (&priv->pipeline);
2349 tp_clear_object (&priv->video_input);
2350 tp_clear_object (&priv->audio_input);
2351 tp_clear_object (&priv->video_tee);
2352 tp_clear_object (&priv->ui_manager);
2353 tp_clear_object (&priv->fullscreen);
2354 tp_clear_object (&priv->camera_monitor);
2355 tp_clear_object (&priv->settings);
2356 tp_clear_object (&priv->sound_mgr);
2357 tp_clear_object (&priv->mic_menu);
2358 tp_clear_object (&priv->camera_menu);
2360 g_list_free_full (priv->notifiers, g_object_unref);
2362 if (priv->timer_id != 0)
2363 g_source_remove (priv->timer_id);
2366 if (priv->contact != NULL)
2368 g_signal_handlers_disconnect_by_func (priv->contact,
2369 contact_name_changed_cb, self);
2370 priv->contact = NULL;
2373 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2377 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2379 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2381 if (priv->video_output_motion_handler_id != 0)
2383 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2384 priv->video_output_motion_handler_id);
2385 priv->video_output_motion_handler_id = 0;
2390 empathy_call_window_finalize (GObject *object)
2392 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2395 disconnect_video_output_motion_handler (self);
2397 /* free any data held directly by the object here */
2398 g_mutex_free (priv->lock);
2400 g_timer_destroy (priv->timer);
2402 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2407 empathy_call_window_new (EmpathyCallHandler *handler)
2409 return EMPATHY_CALL_WINDOW (
2410 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2414 empathy_call_window_present (EmpathyCallWindow *self,
2415 EmpathyCallHandler *handler)
2417 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2419 tp_clear_object (&self->priv->handler);
2420 self->priv->handler = g_object_ref (handler);
2421 empathy_call_window_connect_handler (self);
2423 empathy_window_present (GTK_WINDOW (self));
2424 empathy_call_window_restart_call (self);
2428 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2429 GstElement *conference, gpointer user_data)
2431 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 FsElementAddedNotifier *notifier;
2436 DEBUG ("Conference added");
2438 /* Add notifier to set the various element properties as needed */
2439 notifier = fs_element_added_notifier_new ();
2440 keyfile = fs_utils_get_default_element_properties (conference);
2442 if (keyfile != NULL)
2443 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2445 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2447 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2449 gst_bin_add (GST_BIN (priv->pipeline), conference);
2450 gst_element_set_state (conference, GST_STATE_PLAYING);
2454 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2455 GstElement *conference, gpointer user_data)
2457 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2458 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2460 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2461 gst_element_set_state (conference, GST_STATE_NULL);
2465 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2467 GstStateChangeReturn state_change_return;
2468 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2470 if (priv->pipeline == NULL)
2473 if (priv->bus_message_source_id != 0)
2475 g_source_remove (priv->bus_message_source_id);
2476 priv->bus_message_source_id = 0;
2479 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2481 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2482 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2484 if (priv->pipeline != NULL)
2485 g_object_unref (priv->pipeline);
2486 priv->pipeline = NULL;
2488 if (priv->audio_output != NULL)
2489 g_object_unref (priv->audio_output);
2490 priv->audio_output = NULL;
2491 priv->audio_output_added = FALSE;
2493 if (priv->video_tee != NULL)
2494 g_object_unref (priv->video_tee);
2495 priv->video_tee = NULL;
2497 if (priv->video_preview != NULL)
2498 clutter_actor_destroy (priv->video_preview);
2499 priv->video_preview = NULL;
2501 /* If we destroy the preview while it's being dragged, we won't
2502 * get the ::drag-end signal, so manually destroy the clone */
2503 if (priv->drag_preview != NULL)
2505 clutter_actor_destroy (priv->drag_preview);
2506 empathy_call_window_show_preview_rectangles (self, FALSE);
2507 priv->drag_preview = NULL;
2510 priv->funnel = NULL;
2512 create_pipeline (self);
2513 /* Call will be started when user will hit the 'redial' button */
2514 priv->start_call_when_playing = FALSE;
2515 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2521 g_message ("Error: could not destroy pipeline. Closing call window");
2522 gtk_widget_destroy (GTK_WIDGET (self));
2529 reset_details_pane (EmpathyCallWindow *self)
2531 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2533 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2534 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2535 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2536 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2540 empathy_call_window_disconnected (EmpathyCallWindow *self,
2543 gboolean could_disconnect = FALSE;
2544 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2545 gboolean could_reset_pipeline;
2547 /* Leave full screen mode if needed */
2548 gtk_window_unfullscreen (GTK_WINDOW (self));
2550 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2551 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2553 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2555 if (priv->call_state == CONNECTING)
2556 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2558 if (priv->call_state != REDIALING)
2559 priv->call_state = DISCONNECTED;
2561 /* Show the toolbar */
2562 clutter_state_set_state (priv->transitions, "fade-in");
2564 if (could_reset_pipeline)
2566 g_mutex_lock (priv->lock);
2568 g_timer_stop (priv->timer);
2570 if (priv->timer_id != 0)
2571 g_source_remove (priv->timer_id);
2574 g_mutex_unlock (priv->lock);
2577 /* We are about to destroy the window, no need to update it or create
2578 * a video preview */
2581 empathy_call_window_status_message (self, _("Disconnected"));
2583 empathy_call_window_show_hangup_button (self, FALSE);
2585 /* Unsensitive the camera and mic button */
2586 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2587 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2589 /* Be sure that the mic button is enabled */
2590 gtk_toggle_tool_button_set_active (
2591 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2593 if (priv->camera_state == CAMERA_STATE_ON)
2595 /* Restart the preview with the new pipeline. */
2596 display_video_preview (self, TRUE);
2599 /* destroy the video output; it will be recreated when we'll redial */
2600 disconnect_video_output_motion_handler (self);
2601 if (priv->video_output != NULL)
2602 clutter_actor_destroy (priv->video_output);
2603 priv->video_output = NULL;
2604 if (priv->got_video_src > 0)
2606 g_source_remove (priv->got_video_src);
2607 priv->got_video_src = 0;
2610 gtk_widget_show (priv->remote_user_avatar_widget);
2612 reset_details_pane (self);
2614 priv->sending_video = FALSE;
2615 priv->call_started = FALSE;
2617 could_disconnect = TRUE;
2619 /* TODO: display the self avatar of the preview (depends if the "Always
2620 * Show Video Preview" is enabled or not) */
2623 return could_disconnect;
2628 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2631 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2632 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2634 if (empathy_call_window_disconnected (self, TRUE) &&
2635 priv->call_state == REDIALING)
2636 empathy_call_window_restart_call (self);
2640 empathy_call_window_content_is_raw (TfContent *content)
2642 FsConference *conference;
2645 g_object_get (content, "fs-conference", &conference, NULL);
2646 g_assert (conference != NULL);
2648 /* FIXME: Ugly hack, update when moving a packetization property into
2650 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2651 gst_object_unref (conference);
2657 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2659 EmpathyCallWindow *self)
2661 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2662 FsMediaType media_type;
2664 DEBUG ("removing content");
2666 g_object_get (content, "media-type", &media_type, NULL);
2669 * This assumes that there is only one video stream per channel...
2672 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2674 if (priv->funnel != NULL)
2678 output = priv->video_output_sink;
2680 gst_element_set_state (output, GST_STATE_NULL);
2681 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2683 gst_bin_remove (GST_BIN (priv->pipeline), output);
2684 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2685 priv->funnel = NULL;
2688 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2690 if (priv->audio_output != NULL)
2692 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2694 if (priv->audio_output_added)
2695 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2696 priv->audio_output = NULL;
2697 priv->audio_output_added = FALSE;
2702 g_assert_not_reached ();
2709 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2711 EmpathyCallWindow *self)
2713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2715 DEBUG ("Framerate changed to %u", framerate);
2717 if (priv->video_input != NULL)
2718 empathy_video_src_set_framerate (priv->video_input, framerate);
2722 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2725 EmpathyCallWindow *self)
2727 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2729 DEBUG ("Resolution changed to %ux%u", width, height);
2731 if (priv->video_input != NULL)
2733 empathy_video_src_set_resolution (priv->video_input, width, height);
2737 /* Called with global lock held */
2739 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2741 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2745 if (priv->funnel == NULL)
2747 output = priv->video_output_sink;
2749 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2753 g_warning ("Could not create fsfunnel");
2757 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2759 gst_object_unref (priv->funnel);
2760 priv->funnel = NULL;
2761 g_warning ("Could not add funnel to pipeline");
2765 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2767 g_warning ("Could not add the video output widget to the pipeline");
2771 if (!gst_element_link (priv->funnel, output))
2773 g_warning ("Could not link output sink to funnel");
2774 goto error_output_added;
2777 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2779 g_warning ("Could not start video sink");
2780 goto error_output_added;
2783 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2785 g_warning ("Could not start funnel");
2786 goto error_output_added;
2790 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2793 g_warning ("Could not get request pad from funnel");
2800 gst_element_set_locked_state (priv->funnel, TRUE);
2801 gst_element_set_locked_state (output, TRUE);
2803 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2804 gst_element_set_state (output, GST_STATE_NULL);
2806 gst_bin_remove (GST_BIN (priv->pipeline), output);
2807 gst_element_set_locked_state (output, FALSE);
2811 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2812 priv->funnel = NULL;
2817 /* Called with global lock held */
2819 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2822 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2824 GstPadTemplate *template;
2826 if (!priv->audio_output_added)
2828 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2830 g_warning ("Could not add audio sink to pipeline");
2831 g_object_unref (priv->audio_output);
2832 goto error_add_output;
2835 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2837 g_warning ("Could not start audio sink");
2842 template = gst_element_class_get_pad_template (
2843 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2845 pad = gst_element_request_pad (priv->audio_output,
2846 template, NULL, NULL);
2850 g_warning ("Could not get sink pad from sink");
2857 gst_element_set_locked_state (priv->audio_output, TRUE);
2858 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2859 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2860 priv->audio_output = NULL;
2868 empathy_call_window_update_timer (gpointer user_data)
2870 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2871 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2872 const gchar *status;
2876 time_ = g_timer_elapsed (priv->timer, NULL);
2878 if (priv->call_state == HELD)
2879 status = _("On hold");
2880 else if (!gtk_toggle_tool_button_get_active (
2881 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2884 status = _("Duration");
2886 /* Translators: 'status - minutes:seconds' the caller has been connected */
2887 str = g_strdup_printf (_("%s — %d:%02dm"),
2889 (int) time_ / 60, (int) time_ % 60);
2890 empathy_call_window_status_message (self, str);
2898 EMP_RESPONSE_BALANCE
2902 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2906 switch (response_id)
2908 case GTK_RESPONSE_CLOSE:
2909 gtk_widget_destroy (GTK_WIDGET (info_bar));
2911 case EMP_RESPONSE_BALANCE:
2912 empathy_url_show (GTK_WIDGET (info_bar),
2913 g_object_get_data (G_OBJECT (info_bar), "uri"));
2919 display_error (EmpathyCallWindow *self,
2923 const gchar *details,
2924 const gchar *button_text,
2926 gint button_response)
2928 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2929 GtkWidget *info_bar;
2930 GtkWidget *content_area;
2937 /* Create info bar */
2938 info_bar = gtk_info_bar_new ();
2940 if (button_text != NULL)
2942 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2943 button_text, button_response);
2944 g_object_set_data_full (G_OBJECT (info_bar),
2945 "uri", g_strdup (uri), g_free);
2948 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2949 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2951 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2953 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2955 /* hbox containing the image and the messages vbox */
2956 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2957 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2960 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2961 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2963 /* vbox containing the main message and the details expander */
2964 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2965 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2968 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
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_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2979 if (details != NULL)
2981 GtkWidget *expander;
2983 expander = gtk_expander_new (_("Technical Details"));
2985 txt = g_strdup_printf ("<i>%s</i>", details);
2987 label = gtk_label_new (NULL);
2988 gtk_label_set_markup (GTK_LABEL (label), txt);
2989 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2990 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2993 gtk_container_add (GTK_CONTAINER (expander), label);
2994 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2997 g_signal_connect (info_bar, "response",
2998 G_CALLBACK (on_error_infobar_response_cb), NULL);
3000 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3001 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3002 gtk_widget_show_all (info_bar);
3007 media_stream_error_to_txt (EmpathyCallWindow *self,
3008 TpCallChannel *call,
3010 TpMediaStreamError error)
3012 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3013 const gchar *cm = NULL;
3019 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3021 return g_strdup_printf (
3022 _("%s's software does not understand any of the audio formats "
3023 "supported by your computer"),
3024 empathy_contact_get_alias (priv->contact));
3026 return g_strdup_printf (
3027 _("%s's software does not understand any of the video formats "
3028 "supported by your computer"),
3029 empathy_contact_get_alias (priv->contact));
3031 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3032 return g_strdup_printf (
3033 _("Can't establish a connection to %s. "
3034 "One of you might be on a network that does not allow "
3035 "direct connections."),
3036 empathy_contact_get_alias (priv->contact));
3038 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3039 return g_strdup (_("There was a failure on the network"));
3041 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3043 return g_strdup (_("The audio formats necessary for this call "
3044 "are not installed on your computer"));
3046 return g_strdup (_("The video formats necessary for this call "
3047 "are not installed on your computer"));
3049 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3050 tp_connection_parse_object_path (
3051 tp_channel_borrow_connection (TP_CHANNEL (call)),
3054 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3055 "product=Telepathy&component=%s", cm);
3057 result = g_strdup_printf (
3058 _("Something unexpected happened in a Telepathy component. "
3059 "Please <a href=\"%s\">report this bug</a> and attach "
3060 "logs gathered from the 'Debug' window in the Help menu."), url);
3066 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3067 return g_strdup (_("There was a failure in the call engine"));
3069 case TP_MEDIA_STREAM_ERROR_EOS:
3070 return g_strdup (_("The end of the stream was reached"));
3072 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3079 empathy_call_window_stream_error (EmpathyCallWindow *self,
3080 TpCallChannel *call,
3089 desc = media_stream_error_to_txt (self, call, audio, code);
3092 /* No description, use the error message. That's not great as it's not
3093 * localized but it's better than nothing. */
3094 display_error (self, call, icon, title, msg, NULL);
3098 display_error (self, call, icon, title, desc, msg);
3104 empathy_call_window_audio_stream_error (TpCallChannel *call,
3107 EmpathyCallWindow *self)
3109 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3110 "gnome-stock-mic", _("Can't establish audio stream"));
3114 empathy_call_window_video_stream_error (TpCallChannel *call,
3117 EmpathyCallWindow *self)
3119 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3120 "camera-web", _("Can't establish video stream"));
3125 show_balance_error (EmpathyCallWindow *self)
3129 gchar *balance, *tmp;
3130 const gchar *uri, *currency;
3134 g_object_get (self->priv->handler,
3135 "call-channel", &call,
3138 conn = tp_channel_borrow_connection (call);
3139 g_object_unref (call);
3141 uri = tp_connection_get_balance_uri (conn);
3143 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3145 /* unknown balance */
3146 balance = g_strdup ("(--)");
3150 char *money = empathy_format_currency (amount, scale, currency);
3152 balance = g_strdup_printf ("%s %s",
3157 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3159 display_error (self,
3161 _("Sorry, you don’t have enough credit for that call."),
3165 EMP_RESPONSE_BALANCE);
3172 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3175 EmpathyCallWindow *self)
3177 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3178 TpCallChannel *call;
3179 gboolean can_send_video;
3181 if (state == TP_CALL_STATE_ENDED &&
3182 !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3184 show_balance_error (self);
3188 if (state != TP_CALL_STATE_ACCEPTED)
3191 if (priv->call_state == CONNECTED)
3194 g_timer_start (priv->timer);
3195 priv->call_state = CONNECTED;
3197 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3199 can_send_video = priv->video_input != NULL &&
3200 empathy_contact_can_voip_video (priv->contact) &&
3201 empathy_camera_monitor_get_available (priv->camera_monitor);
3203 g_object_get (priv->handler, "call-channel", &call, NULL);
3205 if (tp_call_channel_has_dtmf (call))
3206 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3208 if (priv->video_input == NULL)
3209 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3211 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3213 empathy_call_window_show_hangup_button (self, TRUE);
3215 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3217 clutter_actor_hide (priv->video_output);
3218 gtk_widget_show (priv->remote_user_avatar_widget);
3220 g_object_unref (call);
3222 g_mutex_lock (priv->lock);
3224 priv->timer_id = g_timeout_add_seconds (1,
3225 empathy_call_window_update_timer, self);
3227 g_mutex_unlock (priv->lock);
3229 empathy_call_window_update_timer (self);
3231 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3235 empathy_call_window_show_video_output_cb (gpointer user_data)
3237 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3239 if (self->priv->video_output != NULL)
3241 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3242 clutter_actor_show (self->priv->video_output);
3243 empathy_call_window_raise_actors (self);
3250 empathy_call_window_check_video_cb (gpointer data)
3252 EmpathyCallWindow *self = data;
3254 if (self->priv->got_video)
3256 self->priv->got_video = FALSE;
3260 /* No video in the last N seconds, display the remote avatar */
3261 empathy_call_window_show_video_output (self, FALSE);
3266 /* Called from the streaming thread */
3268 empathy_call_window_video_probe_cb (GstPad *pad,
3269 GstMiniObject *mini_obj,
3270 EmpathyCallWindow *self)
3273 if (GST_IS_EVENT (mini_obj))
3276 if (G_UNLIKELY (!self->priv->got_video))
3278 /* show the remote video */
3279 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3280 empathy_call_window_show_video_output_cb,
3281 g_object_ref (self), g_object_unref);
3283 self->priv->got_video = TRUE;
3289 /* Called from the streaming thread */
3291 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3292 TfContent *content, GstPad *src, gpointer user_data)
3294 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3295 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3296 gboolean retval = FALSE;
3301 g_mutex_lock (priv->lock);
3303 g_object_get (content, "media-type", &media_type, NULL);
3307 case TP_MEDIA_STREAM_TYPE_AUDIO:
3308 pad = empathy_call_window_get_audio_sink_pad (self, content);
3310 case TP_MEDIA_STREAM_TYPE_VIDEO:
3311 g_idle_add (empathy_call_window_show_video_output_cb, self);
3312 pad = empathy_call_window_get_video_sink_pad (self);
3314 gst_pad_add_data_probe (src,
3315 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3316 if (priv->got_video_src > 0)
3317 g_source_remove (priv->got_video_src);
3318 priv->got_video_src = g_timeout_add_seconds (1,
3319 empathy_call_window_check_video_cb, self);
3322 g_assert_not_reached ();
3328 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3329 g_warning ("Could not link %s sink pad",
3330 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3334 gst_object_unref (pad);
3338 /* If no sink could be linked, try to add fakesink to prevent the whole call
3343 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3345 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3347 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3348 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3349 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3351 gst_element_set_locked_state (fakesink, TRUE);
3352 gst_element_set_state (fakesink, GST_STATE_NULL);
3353 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3357 DEBUG ("Could not link real sink, linked fakesink instead");
3359 gst_object_unref (sinkpad);
3363 gst_object_unref (fakesink);
3368 g_mutex_unlock (priv->lock);
3374 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3377 EmpathyCallWindowPriv *priv = self->priv;
3379 g_assert (priv->audio_output_added == FALSE);
3380 g_assert (priv->audio_output == FALSE);
3382 priv->audio_output = empathy_audio_sink_new ();
3383 g_object_ref_sink (priv->audio_output);
3385 /* volume button to output volume linking */
3386 g_object_bind_property (priv->audio_output, "volume",
3387 priv->volume_button, "value",
3388 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3390 g_object_bind_property_full (content, "requested-output-volume",
3391 priv->audio_output, "volume",
3393 audio_control_volume_to_element,
3394 element_volume_to_audio_control,
3397 /* Link volumes together, sync the current audio input volume property
3398 * back to farstream first */
3399 g_object_bind_property_full (priv->audio_output, "volume",
3400 content, "reported-output-volume",
3401 G_BINDING_SYNC_CREATE,
3402 element_volume_to_audio_control,
3403 audio_control_volume_to_element,
3406 /* For raw audio conferences assume that the producer of the raw data
3407 * has already processed it, so turn off any echo cancellation and any
3408 * other audio improvements that come with it */
3409 empathy_audio_sink_set_echo_cancel (
3410 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3411 !empathy_call_window_content_is_raw (content));
3416 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3417 TfContent *content, gpointer user_data)
3419 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3420 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3422 FsMediaType media_type;
3423 gboolean retval = FALSE;
3425 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3426 g_assert (sink != NULL);
3430 case FS_MEDIA_TYPE_AUDIO:
3432 /* For raw audio conferences assume that the receiver of the raw data
3433 * wants it unprocessed, so turn off any echo cancellation and any
3434 * other audio improvements that come with it */
3435 empathy_audio_src_set_echo_cancel (
3436 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3437 !empathy_call_window_content_is_raw (content));
3439 /* Link volumes together, sync the current audio input volume property
3440 * back to farstream first */
3441 g_object_bind_property_full (content, "requested-input-volume",
3442 priv->audio_input, "volume",
3444 audio_control_volume_to_element,
3445 element_volume_to_audio_control,
3448 g_object_bind_property_full (priv->audio_input, "volume",
3449 content, "reported-input-volume",
3450 G_BINDING_SYNC_CREATE,
3451 element_volume_to_audio_control,
3452 audio_control_volume_to_element,
3455 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3457 g_warning ("Could not add audio source to pipeline");
3461 pad = gst_element_get_static_pad (priv->audio_input, "src");
3464 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3465 g_warning ("Could not get source pad from audio source");
3469 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3471 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3472 g_warning ("Could not link audio source to farsight");
3476 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3478 g_warning ("Could not start audio source");
3479 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3480 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3484 /* Prepare our audio output, not added yet though */
3485 empathy_call_window_prepare_audio_output (self, content);
3489 case FS_MEDIA_TYPE_VIDEO:
3490 if (priv->video_tee != NULL)
3492 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3493 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3495 g_warning ("Could not link video source input pipeline");
3498 gst_object_unref (pad);
3504 g_assert_not_reached ();
3507 gst_object_unref (sink);
3512 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3514 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3515 GstElement *preview;
3517 disable_camera (self);
3519 DEBUG ("remove video input");
3520 preview = priv->video_preview_sink;
3522 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3523 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3524 gst_element_set_state (preview, GST_STATE_NULL);
3526 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3529 g_object_unref (priv->video_input);
3530 priv->video_input = NULL;
3531 g_object_unref (priv->video_tee);
3532 priv->video_tee = NULL;
3533 clutter_actor_destroy (priv->video_preview);
3534 priv->video_preview = NULL;
3536 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3540 start_call (EmpathyCallWindow *self)
3542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3544 priv->call_started = TRUE;
3545 empathy_call_handler_start_call (priv->handler,
3546 gtk_get_current_event_time ());
3548 if (empathy_call_handler_has_initial_video (priv->handler))
3550 TpCallChannel *call;
3553 g_object_get (priv->handler, "call-channel", &call, NULL);
3554 /* If the call channel isn't set yet we're requesting it, if we're
3555 * requesting it with initial video it should be PENDING_SEND when we get
3558 s = TP_SENDING_STATE_PENDING_SEND;
3560 s = empathy_call_channel_get_video_state (call);
3562 if (s == TP_SENDING_STATE_PENDING_SEND ||
3563 s == TP_SENDING_STATE_SENDING)
3565 /* Enable 'send video' buttons and display the preview */
3566 gtk_toggle_tool_button_set_active (
3567 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3571 gtk_toggle_tool_button_set_active (
3572 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3574 if (priv->video_preview == NULL)
3576 create_video_preview (self);
3577 add_video_preview_to_pipeline (self);
3582 g_object_unref (call);
3587 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3590 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3591 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3592 GstState newstate, pending;
3594 empathy_call_handler_bus_message (priv->handler, bus, message);
3596 switch (GST_MESSAGE_TYPE (message))
3598 case GST_MESSAGE_STATE_CHANGED:
3599 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3601 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3603 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3604 !priv->call_started)
3606 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3607 if (newstate == GST_STATE_PAUSED)
3609 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3610 priv->pipeline_playing = TRUE;
3612 if (priv->start_call_when_playing)
3616 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3618 gst_message_parse_state_changed (message, NULL, &newstate,
3621 if (newstate == GST_STATE_PLAYING &&
3622 pending == GST_STATE_VOID_PENDING)
3623 empathy_call_window_stop_camera_spinning (self);
3626 case GST_MESSAGE_ERROR:
3628 GError *error = NULL;
3629 GstElement *gst_error;
3632 gst_message_parse_error (message, &error, &debug);
3633 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3635 g_message ("Element error: %s -- %s\n", error->message, debug);
3637 if (g_str_has_prefix (gst_element_get_name (gst_error),
3638 VIDEO_INPUT_ERROR_PREFIX))
3640 /* Remove the video input and continue */
3641 if (priv->video_input != NULL)
3642 empathy_call_window_remove_video_input (self);
3643 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3647 empathy_call_window_disconnected (self, TRUE);
3649 g_error_free (error);
3652 case GST_MESSAGE_UNKNOWN:
3653 case GST_MESSAGE_EOS:
3654 case GST_MESSAGE_WARNING:
3655 case GST_MESSAGE_INFO:
3656 case GST_MESSAGE_TAG:
3657 case GST_MESSAGE_BUFFERING:
3658 case GST_MESSAGE_STATE_DIRTY:
3659 case GST_MESSAGE_STEP_DONE:
3660 case GST_MESSAGE_CLOCK_PROVIDE:
3661 case GST_MESSAGE_CLOCK_LOST:
3662 case GST_MESSAGE_NEW_CLOCK:
3663 case GST_MESSAGE_STRUCTURE_CHANGE:
3664 case GST_MESSAGE_STREAM_STATUS:
3665 case GST_MESSAGE_APPLICATION:
3666 case GST_MESSAGE_ELEMENT:
3667 case GST_MESSAGE_SEGMENT_START:
3668 case GST_MESSAGE_SEGMENT_DONE:
3669 case GST_MESSAGE_DURATION:
3670 case GST_MESSAGE_ANY:
3679 empathy_call_window_members_changed_cb (TpCallChannel *call,
3680 GHashTable *updates,
3682 TpCallStateReason *reason,
3683 EmpathyCallWindow *self)
3685 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3686 GHashTableIter iter;
3687 gpointer key, value;
3688 gboolean held = FALSE;
3690 g_hash_table_iter_init (&iter, updates);
3691 while (g_hash_table_iter_next (&iter, &key, &value))
3693 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3695 /* This assumes this is a 1-1 call, otherwise one participant
3696 * putting the call on hold wouldn't mean the call is on hold
3704 priv->call_state = HELD;
3705 else if (priv->call_state == HELD)
3706 priv->call_state = CONNECTED;
3710 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3712 EmpathyCallWindow *self)
3714 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3715 TpCallChannel *call;
3717 g_object_get (priv->handler, "call-channel", &call, NULL);
3722 tp_g_signal_connect_object (call, "audio-stream-error",
3723 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3724 tp_g_signal_connect_object (call, "video-stream-error",
3725 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3728 tp_g_signal_connect_object (call, "members-changed",
3729 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3731 g_object_unref (call);
3735 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3737 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3738 TpCallChannel *call;
3740 g_signal_connect (priv->handler, "state-changed",
3741 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3742 g_signal_connect (priv->handler, "conference-added",
3743 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3744 g_signal_connect (priv->handler, "conference-removed",
3745 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3746 g_signal_connect (priv->handler, "closed",
3747 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3748 g_signal_connect (priv->handler, "src-pad-added",
3749 G_CALLBACK (empathy_call_window_src_added_cb), self);
3750 g_signal_connect (priv->handler, "content-added",
3751 G_CALLBACK (empathy_call_window_content_added_cb), self);
3752 g_signal_connect (priv->handler, "content-removed",
3753 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3755 /* We connect to ::call-channel unconditionally since we'll
3756 * get new channels if we hangup and redial or if we reuse the
3758 g_signal_connect (priv->handler, "notify::call-channel",
3759 G_CALLBACK (call_handler_notify_call_cb), self);
3761 g_signal_connect (priv->handler, "framerate-changed",
3762 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3763 g_signal_connect (priv->handler, "resolution-changed",
3764 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3766 g_object_get (priv->handler, "call-channel", &call, NULL);
3769 /* We won't get notify::call-channel for this channel, so
3770 * directly call the callback. */
3771 call_handler_notify_call_cb (priv->handler, NULL, self);
3772 g_object_unref (call);
3777 empathy_call_window_realized_cb (GtkWidget *widget,
3778 EmpathyCallWindow *self)
3782 /* Make the hangup button twice as wide */
3783 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3784 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3786 empathy_call_window_connect_handler (self);
3788 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3792 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3793 EmpathyCallWindow *window)
3795 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3797 if (priv->pipeline != NULL)
3799 if (priv->bus_message_source_id != 0)
3801 g_source_remove (priv->bus_message_source_id);
3802 priv->bus_message_source_id = 0;
3805 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3808 if (priv->call_state == CONNECTING)
3809 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3815 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3818 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3820 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3825 gtk_widget_hide (priv->dtmf_panel);
3826 gtk_widget_hide (menu);
3827 gtk_widget_hide (priv->toolbar);
3831 if (priv->dialpad_was_visible_before_fs)
3832 gtk_widget_show (priv->dtmf_panel);
3834 gtk_widget_show (menu);
3835 gtk_widget_show (priv->toolbar);
3837 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3838 priv->original_height_before_fs);
3843 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3845 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3847 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3848 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3849 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3850 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3852 if (priv->video_output != NULL)
3855 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3856 priv->video_output, TRUE, TRUE,
3857 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3864 empathy_call_window_state_event_cb (GtkWidget *widget,
3865 GdkEventWindowState *event, EmpathyCallWindow *window)
3867 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3869 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3870 gboolean set_fullscreen = event->new_window_state &
3871 GDK_WINDOW_STATE_FULLSCREEN;
3875 gboolean dialpad_was_visible;
3876 GtkAllocation allocation;
3877 gint original_width, original_height;
3879 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3880 original_width = allocation.width;
3881 original_height = allocation.height;
3883 g_object_get (priv->dtmf_panel,
3884 "visible", &dialpad_was_visible,
3887 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3888 priv->original_width_before_fs = original_width;
3889 priv->original_height_before_fs = original_height;
3891 if (priv->video_output_motion_handler_id == 0 &&
3892 priv->video_output != NULL)
3894 priv->video_output_motion_handler_id = g_signal_connect (
3895 G_OBJECT (priv->video_container), "motion-notify-event",
3896 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3902 disconnect_video_output_motion_handler (window);
3905 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3907 show_controls (window, set_fullscreen);
3908 show_borders (window, set_fullscreen);
3909 gtk_action_set_stock_id (priv->menu_fullscreen,
3910 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3911 priv->is_fullscreen = set_fullscreen;
3918 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3921 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3922 int w, h, dialpad_width;
3923 GtkAllocation allocation;
3925 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3926 w = allocation.width;
3927 h = allocation.height;
3929 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3933 gtk_widget_show (priv->dtmf_panel);
3939 gtk_widget_hide (priv->dtmf_panel);
3943 gtk_window_resize (GTK_WINDOW (window), w, h);
3947 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3950 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3951 TpCallChannel *call;
3953 priv->sending_video = (state == CAMERA_STATE_ON);
3955 if (state == CAMERA_STATE_ON)
3957 /* When we start sending video, we want to show the video preview by
3959 display_video_preview (window, TRUE);
3963 display_video_preview (window, FALSE);
3966 if (priv->call_state != CONNECTED)
3969 g_object_get (priv->handler, "call-channel", &call, NULL);
3970 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3971 empathy_call_channel_send_video (call, priv->sending_video);
3972 g_object_unref (call);
3976 empathy_call_window_hangup_cb (gpointer object,
3977 EmpathyCallWindow *self)
3979 empathy_call_handler_stop_call (self->priv->handler);
3981 empathy_call_window_disconnected (self, TRUE);
3985 empathy_call_window_restart_call (EmpathyCallWindow *window)
3987 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3989 /* Remove error info bars */
3990 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3991 (GtkCallback) gtk_widget_destroy, NULL);
3993 create_video_output_widget (window);
3994 priv->outgoing = TRUE;
3995 empathy_call_window_set_state_connecting (window);
3997 if (priv->pipeline_playing)
3998 start_call (window);
4000 /* call will be started when the pipeline is ready */
4001 priv->start_call_when_playing = TRUE;
4003 empathy_call_window_setup_avatars (window, priv->handler);
4005 empathy_call_window_show_hangup_button (window, TRUE);
4009 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4010 EmpathyCallWindow *window)
4014 active = gtk_toggle_tool_button_get_active (button);
4016 empathy_call_window_show_dialpad (window, active);
4020 empathy_call_window_fullscreen_cb (gpointer object,
4021 EmpathyCallWindow *window)
4023 empathy_call_window_fullscreen_toggle (window);
4027 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4029 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4031 if (priv->is_fullscreen)
4032 gtk_window_unfullscreen (GTK_WINDOW (window));
4034 gtk_window_fullscreen (GTK_WINDOW (window));
4038 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4039 GdkEventButton *event, EmpathyCallWindow *window)
4041 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4043 empathy_call_window_video_menu_popup (window, event->button);
4051 empathy_call_window_key_press_cb (GtkWidget *video_output,
4052 GdkEventKey *event, EmpathyCallWindow *window)
4054 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4056 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4058 /* Since we are in fullscreen mode, toggling will bring us back to
4060 empathy_call_window_fullscreen_toggle (window);
4068 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4069 GdkEventMotion *event, EmpathyCallWindow *window)
4071 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4073 if (priv->is_fullscreen)
4075 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4077 /* Show the bottom toolbar */
4078 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4085 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4089 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4091 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4093 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4094 button, gtk_get_current_event_time ());
4095 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4099 empathy_call_window_status_message (EmpathyCallWindow *self,
4102 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4106 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4108 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4110 return priv->ui_manager;
4113 EmpathyGstAudioSrc *
4114 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4116 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4118 return (EmpathyGstAudioSrc *) priv->audio_input;
4121 EmpathyGstVideoSrc *
4122 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4124 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4128 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4129 const gchar *device)
4131 EmpathyGstVideoSrc *video;
4134 /* Restart the camera only if it's already running */
4135 running = (self->priv->video_preview != NULL);
4136 video = empathy_call_window_get_video_src (self);
4139 empathy_call_window_play_camera (self, FALSE);
4141 empathy_video_src_change_device (video, device);
4144 empathy_call_window_play_camera (self, TRUE);