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>
57 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
58 #include <libempathy/empathy-debug.h>
60 #include "empathy-call-window.h"
61 #include "empathy-call-window-fullscreen.h"
62 #include "empathy-call-factory.h"
63 #include "empathy-video-widget.h"
64 #include "empathy-about-dialog.h"
65 #include "empathy-audio-src.h"
66 #include "empathy-audio-sink.h"
67 #include "empathy-video-src.h"
68 #include "empathy-mic-menu.h"
69 #include "empathy-preferences.h"
70 #include "empathy-rounded-actor.h"
71 #include "empathy-rounded-rectangle.h"
72 #include "empathy-rounded-texture.h"
73 #include "empathy-camera-menu.h"
75 #define CONTENT_HBOX_BORDER_WIDTH 6
76 #define CONTENT_HBOX_SPACING 3
77 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
79 #define SELF_VIDEO_SECTION_WIDTH 120
80 #define SELF_VIDEO_SECTION_HEIGHT 90
81 #define SELF_VIDEO_SECTION_MARGIN 10
83 #define FLOATING_TOOLBAR_OPACITY 192
84 #define FLOATING_TOOLBAR_WIDTH 280
85 #define FLOATING_TOOLBAR_HEIGHT 36
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
105 PROP_CALL_HANDLER = 1,
109 RINGING, /* Incoming call */
110 CONNECTING, /* Outgoing call */
111 CONNECTED, /* Connected */
112 HELD, /* Connected, but on hold */
113 DISCONNECTED, /* Disconnected */
114 REDIALING /* Redialing (special case of CONNECTING) */
118 CAMERA_STATE_OFF = 0,
124 PREVIEW_POS_TOP_LEFT,
125 PREVIEW_POS_TOP_RIGHT,
126 PREVIEW_POS_BOTTOM_LEFT,
127 PREVIEW_POS_BOTTOM_RIGHT,
130 struct _EmpathyCallWindowPriv
132 gboolean dispose_has_run;
133 EmpathyCallHandler *handler;
135 EmpathyContact *contact;
137 EmpathyCameraMonitor *camera_monitor;
142 GtkUIManager *ui_manager;
143 GtkWidget *errors_vbox;
144 /* widget displays the video received from the remote user. This widget is
145 * alive only during call. */
146 ClutterActor *video_output;
147 ClutterActor *video_preview;
148 ClutterActor *drag_preview;
149 ClutterActor *preview_shown_button;
150 ClutterActor *preview_hidden_button;
151 ClutterActor *preview_rectangle1;
152 ClutterActor *preview_rectangle2;
153 ClutterActor *preview_rectangle3;
154 ClutterActor *preview_rectangle4;
155 ClutterActor *preview_rectangle_box1;
156 ClutterActor *preview_rectangle_box2;
157 ClutterActor *preview_rectangle_box3;
158 ClutterActor *preview_rectangle_box4;
159 ClutterActor *preview_spinner_actor;
160 GtkWidget *preview_spinner_widget;
161 GtkWidget *video_container;
162 GtkWidget *remote_user_avatar_widget;
163 GtkWidget *remote_user_avatar_toolbar;
164 GtkWidget *remote_user_name_toolbar;
165 GtkWidget *status_label;
166 GtkWidget *hangup_button;
167 GtkWidget *audio_call_button;
168 GtkWidget *video_call_button;
169 GtkWidget *mic_button;
170 GtkWidget *volume_button;
171 GtkWidget *camera_button;
172 GtkWidget *dialpad_button;
174 GtkWidget *bottom_toolbar;
175 ClutterActor *floating_toolbar;
177 GtkAction *menu_fullscreen;
178 GtkAction *menu_swap_camera;
180 ClutterState *transitions;
182 /* The box that contains self and remote avatar and video
183 input/output. When we redial, we destroy and re-create the box */
184 ClutterActor *video_box;
185 ClutterLayoutManager *video_layout;
187 /* Coordinates of the preview drag event's start. */
188 PreviewPosition preview_pos;
190 /* We keep a reference on the hbox which contains the main content so we can
191 easilly repack everything when toggling fullscreen */
192 GtkWidget *content_hbox;
194 /* These are used to accept or reject an incoming call when the status
196 GtkWidget *incoming_call_dialog;
197 TpyCallChannel *pending_channel;
198 TpChannelDispatchOperation *pending_cdo;
199 TpAddDispatchOperationContext *pending_context;
201 gulong video_output_motion_handler_id;
202 guint bus_message_source_id;
204 /* String that contains the queued tones to send after the current ones
207 gboolean sending_tones;
208 GtkWidget *dtmf_panel;
211 GtkWidget *details_vbox;
212 GtkWidget *vcodec_encoding_label;
213 GtkWidget *acodec_encoding_label;
214 GtkWidget *vcodec_decoding_label;
215 GtkWidget *acodec_decoding_label;
217 GtkWidget *audio_remote_candidate_label;
218 GtkWidget *audio_local_candidate_label;
219 GtkWidget *video_remote_candidate_label;
220 GtkWidget *video_local_candidate_label;
221 GtkWidget *video_remote_candidate_info_img;
222 GtkWidget *video_local_candidate_info_img;
223 GtkWidget *audio_remote_candidate_info_img;
224 GtkWidget *audio_local_candidate_info_img;
226 GstElement *video_input;
227 GstElement *video_preview_sink;
228 GstElement *video_output_sink;
229 GstElement *audio_input;
230 GstElement *audio_output;
231 gboolean audio_output_added;
232 GstElement *pipeline;
233 GstElement *video_tee;
243 gboolean call_started;
244 gboolean sending_video;
245 CameraState camera_state;
247 EmpathyCallWindowFullscreen *fullscreen;
248 gboolean is_fullscreen;
253 guint inactivity_src;
255 /* Those fields represent the state of the window before it actually was in
257 gboolean dialpad_was_visible_before_fs;
258 gint original_width_before_fs;
259 gint original_height_before_fs;
261 gint x, y, w, h, dialpad_width;
264 /* TRUE if the call should be started when the pipeline is playing */
265 gboolean start_call_when_playing;
266 /* TRUE if we requested to set the pipeline in the playing state */
267 gboolean pipeline_playing;
269 EmpathySoundManager *sound_mgr;
272 EmpathyMicMenu *mic_menu;
273 EmpathyCameraMenu *camera_menu;
276 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
278 static void empathy_call_window_realized_cb (GtkWidget *widget,
279 EmpathyCallWindow *window);
281 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
282 GdkEvent *event, EmpathyCallWindow *window);
284 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
285 GdkEventWindowState *event, EmpathyCallWindow *window);
287 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
290 static void empathy_call_window_hangup_cb (gpointer object,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_fullscreen_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
298 static gboolean empathy_call_window_video_button_press_cb (
299 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
301 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
302 GdkEventKey *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_video_output_motion_notify (
305 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
307 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
310 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
312 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
313 EmpathyCallWindow *window);
315 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
317 static void empathy_call_window_status_message (EmpathyCallWindow *window,
320 static gboolean empathy_call_window_bus_message (GstBus *bus,
321 GstMessage *message, gpointer user_data);
324 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
327 gtk_widget_set_visible (self->priv->hangup_button, show);
328 gtk_widget_set_visible (self->priv->audio_call_button, !show);
329 gtk_widget_set_visible (self->priv->video_call_button, !show);
333 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
334 EmpathyCallWindow *self)
336 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
337 empathy_call_window_restart_call (self);
341 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
342 EmpathyCallWindow *self)
344 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
345 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
346 empathy_call_window_restart_call (self);
350 empathy_call_window_emit_tones (EmpathyCallWindow *self)
354 if (tp_str_empty (self->priv->tones->str))
357 g_object_get (self->priv->handler, "call-channel", &channel, NULL);
359 DEBUG ("Emitting multiple tones: %s", self->priv->tones->str);
361 tp_cli_channel_interface_dtmf_call_multiple_tones (channel, -1,
362 self->priv->tones->str,
363 NULL, NULL, NULL, NULL);
365 self->priv->sending_tones = TRUE;
367 g_string_set_size (self->priv->tones, 0);
369 g_object_unref (channel);
373 empathy_call_window_maybe_emit_tones (EmpathyCallWindow *self)
375 if (self->priv->sending_tones)
378 empathy_call_window_emit_tones (self);
382 empathy_call_window_tones_stopped_cb (TpChannel *proxy,
383 gboolean arg_cancelled,
385 GObject *weak_object)
387 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
389 self->priv->sending_tones = FALSE;
391 empathy_call_window_emit_tones (self);
395 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
397 EmpathyCallWindow *self)
399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
401 g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
403 empathy_call_window_maybe_emit_tones (self);
407 empathy_call_window_raise_actors (EmpathyCallWindow *self)
409 clutter_actor_raise_top (self->priv->floating_toolbar);
411 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
412 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
413 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
414 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
418 empathy_call_window_show_video_output (EmpathyCallWindow *self,
421 if (self->priv->video_output != NULL)
422 g_object_set (self->priv->video_output, "visible", show, NULL);
424 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
426 empathy_call_window_raise_actors (self);
430 create_video_output_widget (EmpathyCallWindow *self)
432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
434 g_assert (priv->video_output == NULL);
435 g_assert (priv->pipeline != NULL);
437 priv->video_output = clutter_texture_new ();
439 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
442 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
443 if (priv->video_output_sink == NULL)
444 g_error ("Missing cluttersink");
446 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
448 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
451 gtk_widget_add_events (priv->video_container,
452 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
453 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
454 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
458 create_video_input (EmpathyCallWindow *self)
460 EmpathyCallWindowPriv *priv = GET_PRIV (self);
462 g_assert (priv->video_input == NULL);
463 priv->video_input = empathy_video_src_new ();
464 gst_object_ref (priv->video_input);
465 gst_object_sink (priv->video_input);
469 audio_control_volume_to_element (GBinding *binding,
470 const GValue *source_value,
471 GValue *target_value,
474 /* AudioControl volume is 0-255, with -1 for unknown */
477 hv = g_value_get_int (source_value);
482 g_value_set_double (target_value, hv/255.0);
488 element_volume_to_audio_control (GBinding *binding,
489 const GValue *source_value,
490 GValue *target_value,
495 ev = g_value_get_double (source_value);
496 ev = CLAMP (ev, 0.0, 1.0);
498 g_value_set_int (target_value, ev * 255);
503 create_audio_input (EmpathyCallWindow *self)
505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
507 g_assert (priv->audio_input == NULL);
508 priv->audio_input = empathy_audio_src_new ();
509 gst_object_ref (priv->audio_input);
510 gst_object_sink (priv->audio_input);
512 g_object_bind_property (priv->mic_button, "active",
513 priv->audio_input, "mute",
514 G_BINDING_BIDIRECTIONAL |
515 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
519 add_video_preview_to_pipeline (EmpathyCallWindow *self)
521 EmpathyCallWindowPriv *priv = GET_PRIV (self);
524 g_assert (priv->video_preview != NULL);
525 g_assert (priv->pipeline != NULL);
526 g_assert (priv->video_input != NULL);
527 g_assert (priv->video_tee != NULL);
529 preview = priv->video_preview_sink;
531 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
533 g_warning ("Could not add video input to pipeline");
537 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
539 g_warning ("Could not add video preview to pipeline");
543 if (!gst_element_link (priv->video_input, priv->video_tee))
545 g_warning ("Could not link video input to video tee");
549 if (!gst_element_link (priv->video_tee, preview))
551 g_warning ("Could not link video tee to video preview");
557 empathy_call_window_disable_camera_cb (GtkAction *action,
558 EmpathyCallWindow *self)
560 clutter_actor_destroy (self->priv->preview_hidden_button);
562 gtk_toggle_tool_button_set_active (
563 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
567 empathy_call_window_minimise_camera_cb (GtkAction *action,
568 EmpathyCallWindow *self)
570 clutter_actor_hide (self->priv->video_preview);
571 clutter_actor_show (self->priv->preview_hidden_button);
575 empathy_call_window_maximise_camera_cb (GtkAction *action,
576 EmpathyCallWindow *self)
578 clutter_actor_show (self->priv->video_preview);
579 clutter_actor_hide (self->priv->preview_hidden_button);
583 empathy_call_window_swap_camera_cb (GtkAction *action,
584 EmpathyCallWindow *self)
586 const GList *cameras, *l;
589 DEBUG ("Swapping the camera");
591 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
592 current_cam = empathy_video_src_dup_device (
593 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
595 for (l = cameras; l != NULL; l = l->next)
597 EmpathyCamera *camera = l->data;
599 if (!tp_strdiff (camera->device, current_cam))
604 next = l->next->data;
606 next = cameras->data;
608 /* EmpathyCameraMenu will update itself and do the actual change
610 g_settings_set_string (self->priv->settings,
611 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
618 g_free (current_cam);
622 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
623 EmpathyCamera *camera,
624 EmpathyCallWindow *self)
626 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
628 gtk_action_set_visible (self->priv->menu_swap_camera,
629 g_list_length ((GList *) cameras) >= 2);
633 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
634 EmpathyCamera *camera,
635 EmpathyCallWindow *self)
637 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
639 gtk_action_set_visible (self->priv->menu_swap_camera,
640 g_list_length ((GList *) cameras) >= 2);
644 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
645 EmpathyCallWindow *self)
649 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
651 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
652 0, gtk_get_current_event_time ());
653 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
657 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
658 EmpathyCallWindow *self)
662 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
663 "/preview-hidden-menu");
664 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
665 0, gtk_get_current_event_time ());
666 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
669 static ClutterActor *
670 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
672 ClutterBinAlignment x,
673 ClutterBinAlignment y)
675 ClutterLayoutManager *layout1, *layout2;
676 ClutterActor *rectangle;
677 ClutterActor *box1, *box2;
679 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
680 CLUTTER_BIN_ALIGNMENT_START);
682 box1 = clutter_box_new (layout1);
686 rectangle = empathy_rounded_rectangle_new (
687 SELF_VIDEO_SECTION_WIDTH + 5,
688 SELF_VIDEO_SECTION_HEIGHT + 5);
690 clutter_actor_set_size (box1,
691 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
692 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
693 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
695 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
696 CLUTTER_BIN_ALIGNMENT_CENTER);
698 /* We have a box with the margins and the video in the middle inside
699 * a bigger box with an extra bottom margin so we're not on top of
700 * the floating toolbar. */
701 box2 = clutter_box_new (layout2);
703 clutter_actor_set_size (box2,
704 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
705 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
707 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
708 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
710 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
713 clutter_actor_hide (rectangle);
719 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
721 self->priv->preview_rectangle1 =
722 empathy_call_window_create_preview_rectangle (self,
723 &self->priv->preview_rectangle_box1,
724 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
725 self->priv->preview_rectangle2 =
726 empathy_call_window_create_preview_rectangle (self,
727 &self->priv->preview_rectangle_box2,
728 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
729 self->priv->preview_rectangle3 =
730 empathy_call_window_create_preview_rectangle (self,
731 &self->priv->preview_rectangle_box3,
732 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
733 self->priv->preview_rectangle4 =
734 empathy_call_window_create_preview_rectangle (self,
735 &self->priv->preview_rectangle_box4,
736 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
740 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
743 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
744 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
745 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
746 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
750 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
755 guint ret_x = 0, ret_y = 0;
758 if (!clutter_actor_has_allocation (self->priv->video_box))
761 clutter_actor_get_geometry (self->priv->video_box, &box);
765 case PREVIEW_POS_TOP_LEFT:
766 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
768 case PREVIEW_POS_TOP_RIGHT:
769 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
770 - SELF_VIDEO_SECTION_WIDTH;
771 ret_y = SELF_VIDEO_SECTION_MARGIN;
773 case PREVIEW_POS_BOTTOM_LEFT:
774 ret_x = SELF_VIDEO_SECTION_MARGIN;
775 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
776 - SELF_VIDEO_SECTION_HEIGHT
777 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
779 case PREVIEW_POS_BOTTOM_RIGHT:
780 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
781 - SELF_VIDEO_SECTION_WIDTH;
782 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
783 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
784 - FLOATING_TOOLBAR_SPACING;
787 g_warn_if_reached ();
798 static PreviewPosition
799 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
804 PreviewPosition pos = PREVIEW_POS_NONE;
806 if (!clutter_actor_has_allocation (self->priv->video_box))
809 clutter_actor_get_geometry (self->priv->video_box, &box);
811 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
812 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
813 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
814 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
816 pos = PREVIEW_POS_TOP_LEFT;
818 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
819 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
820 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
821 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
823 pos = PREVIEW_POS_TOP_RIGHT;
825 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
826 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
827 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
828 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
830 pos = PREVIEW_POS_BOTTOM_LEFT;
832 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
833 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
834 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
835 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
837 pos = PREVIEW_POS_BOTTOM_RIGHT;
843 static ClutterActor *
844 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
847 ClutterActor *rectangle;
851 case PREVIEW_POS_TOP_LEFT:
852 rectangle = self->priv->preview_rectangle1;
854 case PREVIEW_POS_TOP_RIGHT:
855 rectangle = self->priv->preview_rectangle3;
857 case PREVIEW_POS_BOTTOM_LEFT:
858 rectangle = self->priv->preview_rectangle2;
860 case PREVIEW_POS_BOTTOM_RIGHT:
861 rectangle = self->priv->preview_rectangle4;
871 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
874 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
876 DEBUG ("moving the video preview to %d", pos);
878 self->priv->preview_pos = pos;
882 case PREVIEW_POS_TOP_LEFT:
883 clutter_bin_layout_set_alignment (layout,
884 self->priv->video_preview,
885 CLUTTER_BIN_ALIGNMENT_START,
886 CLUTTER_BIN_ALIGNMENT_START);
888 case PREVIEW_POS_TOP_RIGHT:
889 clutter_bin_layout_set_alignment (layout,
890 self->priv->video_preview,
891 CLUTTER_BIN_ALIGNMENT_END,
892 CLUTTER_BIN_ALIGNMENT_START);
894 case PREVIEW_POS_BOTTOM_LEFT:
895 clutter_bin_layout_set_alignment (layout,
896 self->priv->video_preview,
897 CLUTTER_BIN_ALIGNMENT_START,
898 CLUTTER_BIN_ALIGNMENT_END);
900 case PREVIEW_POS_BOTTOM_RIGHT:
901 clutter_bin_layout_set_alignment (layout,
902 self->priv->video_preview,
903 CLUTTER_BIN_ALIGNMENT_END,
904 CLUTTER_BIN_ALIGNMENT_END);
907 g_warn_if_reached ();
910 g_settings_set_enum (self->priv->settings, "camera-position", pos);
914 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
917 ClutterActor *rectangle;
919 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
921 empathy_rounded_rectangle_set_border_width (
922 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
923 empathy_rounded_rectangle_set_border_color (
924 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
928 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
929 ClutterActor *rectangle)
931 empathy_rounded_rectangle_set_border_width (
932 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
933 empathy_rounded_rectangle_set_border_color (
934 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
938 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
940 ClutterActor *rectangle;
942 rectangle = empathy_call_window_get_preview_rectangle (self,
943 self->priv->preview_pos);
945 /* We don't want to darken the rectangle where the preview
948 if (self->priv->preview_rectangle1 != rectangle)
949 empathy_call_window_darken_preview_rectangle (self,
950 self->priv->preview_rectangle1);
952 if (self->priv->preview_rectangle2 != rectangle)
953 empathy_call_window_darken_preview_rectangle (self,
954 self->priv->preview_rectangle2);
956 if (self->priv->preview_rectangle3 != rectangle)
957 empathy_call_window_darken_preview_rectangle (self,
958 self->priv->preview_rectangle3);
960 if (self->priv->preview_rectangle4 != rectangle)
961 empathy_call_window_darken_preview_rectangle (self,
962 self->priv->preview_rectangle4);
966 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
970 ClutterModifierType modifiers,
971 EmpathyCallWindow *self)
973 ClutterActor *stage = clutter_actor_get_stage (actor);
976 self->priv->drag_preview = clutter_clone_new (actor);
978 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
979 self->priv->drag_preview);
981 clutter_actor_transform_stage_point (actor, event_x, event_y,
984 clutter_actor_set_position (self->priv->drag_preview,
985 event_x - rel_x, event_y - rel_y);
987 clutter_drag_action_set_drag_handle (action,
988 self->priv->drag_preview);
990 clutter_actor_set_opacity (actor, 0);
991 clutter_actor_hide (self->priv->preview_shown_button);
993 empathy_call_window_show_preview_rectangles (self, TRUE);
994 empathy_call_window_darken_preview_rectangles (self);
998 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
1001 clutter_actor_set_opacity (actor, 255);
1005 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
1006 ClutterActor *actor,
1009 ClutterModifierType modifiers,
1010 EmpathyCallWindow *self)
1012 PreviewPosition pos;
1015 /* Get the position before destroying the drag actor, otherwise the
1016 * preview_box allocation won't be valid and we won't be able to
1017 * calculate the position. */
1018 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1020 empathy_call_window_get_preview_coordinates (self,
1021 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1024 /* Move the preview to the destination and destroy it afterwards */
1025 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1028 "signal-swapped-after::completed",
1029 clutter_actor_destroy, self->priv->drag_preview,
1030 "signal-swapped-after::completed",
1031 clutter_actor_show, self->priv->preview_shown_button,
1032 "signal::completed",
1033 empathy_call_window_on_animation_completed_cb, actor,
1036 self->priv->drag_preview = NULL;
1038 if (pos != PREVIEW_POS_NONE)
1039 empathy_call_window_move_video_preview (self, pos);
1041 empathy_call_window_show_preview_rectangles (self, FALSE);
1045 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1046 ClutterActor *actor,
1049 EmpathyCallWindow *self)
1051 PreviewPosition pos;
1052 gfloat event_x, event_y;
1054 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1056 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1058 if (pos != PREVIEW_POS_NONE)
1059 empathy_call_window_highlight_preview_rectangle (self, pos);
1061 empathy_call_window_darken_preview_rectangles (self);
1065 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1066 ClutterCrossingEvent *event,
1067 EmpathyCallWindow *self)
1069 ClutterActor *rectangle;
1071 rectangle = empathy_call_window_get_preview_rectangle (self,
1072 self->priv->preview_pos);
1074 empathy_call_window_highlight_preview_rectangle (self,
1075 self->priv->preview_pos);
1077 clutter_actor_show (rectangle);
1083 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1084 ClutterCrossingEvent *event,
1085 EmpathyCallWindow *self)
1087 ClutterActor *rectangle;
1089 rectangle = empathy_call_window_get_preview_rectangle (self,
1090 self->priv->preview_pos);
1092 empathy_call_window_darken_preview_rectangle (self, rectangle);
1094 clutter_actor_hide (rectangle);
1100 create_video_preview (EmpathyCallWindow *self)
1102 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1103 ClutterLayoutManager *layout, *layout_center, *layout_end;
1104 ClutterActor *preview;
1107 ClutterAction *action;
1109 PreviewPosition pos;
1110 GdkRGBA transparent = { 0., 0., 0., 0. };
1112 g_assert (priv->video_preview == NULL);
1114 pos = g_settings_get_enum (priv->settings, "camera-position");
1116 preview = empathy_rounded_texture_new ();
1117 clutter_actor_set_size (preview,
1118 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1120 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1121 if (priv->video_preview_sink == NULL)
1122 g_error ("Missing cluttersink");
1124 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1126 /* Add a little offset to the video preview */
1127 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1128 CLUTTER_BIN_ALIGNMENT_START);
1129 priv->video_preview = clutter_box_new (layout);
1130 clutter_actor_set_size (priv->video_preview,
1131 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1132 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1133 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1135 /* Spinner for when changing the camera device */
1136 priv->preview_spinner_widget = gtk_spinner_new ();
1137 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1138 empathy_rounded_actor_set_round_factor (
1139 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1141 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1142 gtk_widget_override_background_color (
1143 gtk_clutter_actor_get_widget (
1144 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1145 GTK_STATE_FLAG_NORMAL, &transparent);
1146 gtk_widget_show (priv->preview_spinner_widget);
1149 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1150 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1151 priv->preview_spinner_widget);
1152 clutter_actor_set_size (priv->preview_spinner_actor,
1153 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1154 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1155 clutter_actor_hide (priv->preview_spinner_actor);
1157 /* We have a box with the margins and the video in the middle inside
1158 * a bigger box with an extra bottom margin so we're not on top of
1159 * the floating toolbar. */
1160 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1161 CLUTTER_BIN_ALIGNMENT_CENTER);
1162 box = clutter_box_new (layout_center);
1163 clutter_actor_set_size (box,
1164 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1165 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1167 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1168 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1169 priv->preview_spinner_actor);
1170 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1172 g_object_set (priv->video_preview_sink,
1177 /* Translators: this is an "Info" label. It should be as short
1179 button = gtk_button_new_with_label (_("i"));
1180 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1182 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1184 clutter_actor_set_size (b, 24, 24);
1186 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1187 CLUTTER_BIN_ALIGNMENT_END);
1188 box = clutter_box_new (layout_end);
1189 clutter_actor_set_size (box,
1190 SELF_VIDEO_SECTION_WIDTH,
1191 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1193 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1194 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1196 g_signal_connect (button, "clicked",
1197 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1200 /* Translators: this is an "Info" label. It should be as short
1202 button = gtk_button_new_with_label (_("i"));
1203 b = empathy_rounded_actor_new ();
1205 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1207 clutter_actor_set_size (b, 24, 24);
1208 priv->preview_hidden_button = b;
1210 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1211 priv->preview_hidden_button,
1212 CLUTTER_BIN_ALIGNMENT_START,
1213 CLUTTER_BIN_ALIGNMENT_END);
1215 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1217 clutter_actor_hide (priv->preview_hidden_button);
1219 g_signal_connect (button, "clicked",
1220 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1223 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1224 priv->video_preview,
1225 CLUTTER_BIN_ALIGNMENT_START,
1226 CLUTTER_BIN_ALIGNMENT_END);
1228 empathy_call_window_move_video_preview (self, pos);
1230 action = clutter_drag_action_new ();
1231 g_signal_connect (action, "drag-begin",
1232 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1233 g_signal_connect (action, "drag-end",
1234 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1235 g_signal_connect (action, "drag-motion",
1236 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1238 g_signal_connect (preview, "enter-event",
1239 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1240 g_signal_connect (preview, "leave-event",
1241 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1243 clutter_actor_add_action (preview, action);
1244 clutter_actor_set_reactive (preview, TRUE);
1245 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1249 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1251 clutter_actor_show (self->priv->preview_spinner_actor);
1252 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1256 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1258 clutter_actor_hide (self->priv->preview_spinner_actor);
1259 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1263 empathy_call_window_play_camera (EmpathyCallWindow *self,
1266 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1267 GstElement *preview;
1270 if (priv->video_preview == NULL)
1272 create_video_preview (self);
1273 add_video_preview_to_pipeline (self);
1278 state = GST_STATE_PLAYING;
1282 empathy_call_window_start_camera_spinning (self);
1283 state = GST_STATE_NULL;
1286 preview = priv->video_preview_sink;
1288 gst_element_set_state (preview, state);
1289 gst_element_set_state (priv->video_tee, state);
1290 gst_element_set_state (priv->video_input, state);
1294 display_video_preview (EmpathyCallWindow *self,
1297 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1299 if (priv->video_preview == NULL)
1301 create_video_preview (self);
1302 add_video_preview_to_pipeline (self);
1307 /* Display the video preview */
1308 DEBUG ("Show video preview");
1310 empathy_call_window_play_camera (self, TRUE);
1311 clutter_actor_show (priv->video_preview);
1312 clutter_actor_raise_top (priv->floating_toolbar);
1316 /* Hide the video preview */
1317 DEBUG ("Hide video preview");
1319 if (priv->video_preview != NULL)
1321 clutter_actor_hide (priv->video_preview);
1322 empathy_call_window_play_camera (self, FALSE);
1328 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1330 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1332 empathy_call_window_status_message (window, _("Connecting…"));
1333 priv->call_state = CONNECTING;
1335 /* Show the toolbar */
1336 clutter_state_set_state (priv->transitions, "fade-in");
1339 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1340 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1344 disable_camera (EmpathyCallWindow *self)
1346 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1348 if (priv->camera_state == CAMERA_STATE_OFF)
1351 DEBUG ("Disable camera");
1353 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1355 priv->camera_state = CAMERA_STATE_OFF;
1359 enable_camera (EmpathyCallWindow *self)
1361 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1363 if (priv->camera_state == CAMERA_STATE_ON)
1366 if (priv->video_input == NULL)
1368 DEBUG ("Can't enable camera, no input");
1372 DEBUG ("Enable camera");
1374 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1376 priv->camera_state = CAMERA_STATE_ON;
1380 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1381 EmpathyCallWindow *self)
1383 if (gtk_toggle_tool_button_get_active (toggle))
1384 enable_camera (self);
1386 disable_camera (self);
1390 create_pipeline (EmpathyCallWindow *self)
1392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1395 g_assert (priv->pipeline == NULL);
1397 priv->pipeline = gst_pipeline_new (NULL);
1398 priv->pipeline_playing = FALSE;
1400 priv->video_tee = gst_element_factory_make ("tee", NULL);
1401 gst_object_ref (priv->video_tee);
1402 gst_object_sink (priv->video_tee);
1404 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1406 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1407 priv->bus_message_source_id = gst_bus_add_watch (bus,
1408 empathy_call_window_bus_message, self);
1410 g_object_unref (bus);
1414 empathy_call_window_settings_cb (GtkAction *action,
1415 EmpathyCallWindow *self)
1417 gchar *args = g_strdup_printf ("-p %s",
1418 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1420 empathy_launch_program (BIN_DIR, "empathy", args);
1426 empathy_call_window_contents_cb (GtkAction *action,
1427 EmpathyCallWindow *self)
1429 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1433 empathy_call_window_debug_cb (GtkAction *action,
1434 EmpathyCallWindow *self)
1436 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1440 empathy_call_window_about_cb (GtkAction *action,
1441 EmpathyCallWindow *self)
1443 empathy_about_dialog_new (GTK_WINDOW (self));
1447 empathy_call_window_toolbar_timeout (gpointer data)
1449 EmpathyCallWindow *self = data;
1451 /* We don't want to hide the toolbar if we're not in a call, as
1452 * to show the call status all the time. */
1453 if (self->priv->call_state != CONNECTING &&
1454 self->priv->call_state != DISCONNECTED)
1455 clutter_state_set_state (self->priv->transitions, "fade-out");
1461 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1463 EmpathyCallWindow *self)
1465 clutter_state_set_state (self->priv->transitions, "fade-in");
1467 if (self->priv->inactivity_src > 0)
1468 g_source_remove (self->priv->inactivity_src);
1470 self->priv->inactivity_src = g_timeout_add_seconds (3,
1471 empathy_call_window_toolbar_timeout, self);
1477 empathy_call_window_configure_event_cb (GtkWidget *widget,
1479 EmpathyCallWindow *self)
1481 GdkWindow *gdk_window;
1482 GdkWindowState window_state;
1484 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1485 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1487 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1488 &self->priv->dialpad_width, NULL);
1490 gdk_window = gtk_widget_get_window (widget);
1491 window_state = gdk_window_get_state (gdk_window);
1492 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1498 empathy_call_window_destroyed_cb (GtkWidget *object,
1499 EmpathyCallWindow *self)
1501 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1503 /* Save the geometry as if the dialpad was hidden. */
1504 empathy_geometry_save_values (GTK_WINDOW (self),
1505 self->priv->x, self->priv->y,
1506 self->priv->w - self->priv->dialpad_width, self->priv->h,
1507 self->priv->maximized);
1512 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1514 ClutterBindConstraint *constraint)
1516 ClutterActorBox allocation;
1518 clutter_actor_get_allocation_box (stage, &allocation);
1520 clutter_bind_constraint_set_offset (constraint,
1521 allocation.y2 - allocation.y1 -
1522 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1526 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1528 EmpathyCallWindow *self)
1530 switch (response_id)
1532 case GTK_RESPONSE_ACCEPT:
1533 tp_channel_dispatch_operation_handle_with_async (
1534 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1536 tp_clear_object (&self->priv->pending_cdo);
1537 tp_clear_object (&self->priv->pending_channel);
1538 tp_clear_object (&self->priv->pending_context);
1541 case GTK_RESPONSE_CANCEL:
1542 tp_channel_dispatch_operation_close_channels_async (
1543 self->priv->pending_cdo, NULL, NULL);
1545 empathy_call_window_status_message (self, _("Disconnected"));
1546 self->priv->call_state = DISCONNECTED;
1549 g_warn_if_reached ();
1554 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1558 g_assert (self->priv->call_state != CONNECTED);
1560 video = tpy_call_channel_has_initial_video (self->priv->pending_channel);
1562 empathy_call_window_status_message (self, _("Incoming call"));
1563 self->priv->call_state = RINGING;
1565 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1566 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1567 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1568 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1569 empathy_contact_get_alias (self->priv->contact));
1571 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1572 _("Reject"), GTK_RESPONSE_CANCEL,
1573 _("Answer"), GTK_RESPONSE_ACCEPT,
1576 g_signal_connect (self->priv->incoming_call_dialog, "response",
1577 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1578 gtk_widget_show (self->priv->incoming_call_dialog);
1582 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1586 EmpathyCallWindow *self)
1588 tp_clear_object (&self->priv->pending_cdo);
1589 tp_clear_object (&self->priv->pending_channel);
1590 tp_clear_object (&self->priv->pending_context);
1592 /* We don't know if the incoming call has been accepted or not, so we
1593 * assume it hasn't and if it has, we'll set the proper status when
1594 * we get the new handler. */
1595 empathy_call_window_status_message (self, _("Disconnected"));
1596 self->priv->call_state = DISCONNECTED;
1598 gtk_widget_destroy (self->priv->incoming_call_dialog);
1599 self->priv->incoming_call_dialog = NULL;
1603 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1604 TpyCallChannel *channel,
1605 TpChannelDispatchOperation *dispatch_operation,
1606 TpAddDispatchOperationContext *context)
1608 g_assert (self->priv->pending_channel == NULL);
1609 g_assert (self->priv->pending_context == NULL);
1610 g_assert (self->priv->pending_cdo == NULL);
1612 /* Start ringing and delay until the user answers or hangs. */
1613 self->priv->pending_channel = g_object_ref (channel);
1614 self->priv->pending_context = g_object_ref (context);
1615 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1617 g_signal_connect (self->priv->pending_cdo, "invalidated",
1618 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1620 empathy_call_window_set_state_ringing (self);
1621 tp_add_dispatch_operation_context_accept (context);
1625 empathy_call_window_init (EmpathyCallWindow *self)
1627 EmpathyCallWindowPriv *priv;
1629 GtkWidget *top_vbox;
1631 ClutterConstraint *constraint;
1632 ClutterActor *remote_avatar;
1633 GtkStyleContext *context;
1637 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1638 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1640 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1642 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1643 gui = empathy_builder_get_file (filename,
1644 "call_window_vbox", &top_vbox,
1645 "errors_vbox", &priv->errors_vbox,
1646 "pane", &priv->pane,
1647 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1648 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1649 "status_label", &priv->status_label,
1650 "audiocall", &priv->audio_call_button,
1651 "videocall", &priv->video_call_button,
1652 "microphone", &priv->mic_button,
1653 "volume", &priv->volume_button,
1654 "camera", &priv->camera_button,
1655 "hangup", &priv->hangup_button,
1656 "dialpad", &priv->dialpad_button,
1657 "toolbar", &priv->toolbar,
1658 "bottom_toolbar", &priv->bottom_toolbar,
1659 "ui_manager", &priv->ui_manager,
1660 "menufullscreen", &priv->menu_fullscreen,
1661 "menupreviewswap", &priv->menu_swap_camera,
1662 "details_vbox", &priv->details_vbox,
1663 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1664 "acodec_encoding_label", &priv->acodec_encoding_label,
1665 "acodec_decoding_label", &priv->acodec_decoding_label,
1666 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1667 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1668 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1669 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1670 "video_local_candidate_label", &priv->video_local_candidate_label,
1671 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1672 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1673 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1674 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1678 empathy_builder_connect (gui, self,
1679 "hangup", "clicked", empathy_call_window_hangup_cb,
1680 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1681 "videocall", "clicked", empathy_call_window_video_call_cb,
1682 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1683 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1684 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1685 "menusettings", "activate", empathy_call_window_settings_cb,
1686 "menucontents", "activate", empathy_call_window_contents_cb,
1687 "menudebug", "activate", empathy_call_window_debug_cb,
1688 "menuabout", "activate", empathy_call_window_about_cb,
1689 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1690 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1691 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1692 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1695 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1697 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1699 g_object_bind_property (priv->camera_monitor, "available",
1700 priv->camera_button, "sensitive",
1701 G_BINDING_SYNC_CREATE);
1703 g_signal_connect (priv->camera_monitor, "added",
1704 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1705 g_signal_connect (priv->camera_monitor, "removed",
1706 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1708 priv->lock = g_mutex_new ();
1710 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1712 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1713 CONTENT_HBOX_SPACING);
1714 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1715 CONTENT_HBOX_BORDER_WIDTH);
1716 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1719 /* avatar/video box */
1720 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1721 CLUTTER_BIN_ALIGNMENT_CENTER);
1723 priv->video_box = clutter_box_new (priv->video_layout);
1725 priv->video_container = gtk_clutter_embed_new ();
1727 gtk_widget_set_size_request (priv->video_container,
1728 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1730 /* Set the background color to that of the rest of the window */
1731 context = gtk_widget_get_style_context (priv->content_hbox);
1732 gtk_style_context_get_background_color (context,
1733 GTK_STATE_FLAG_NORMAL, &rgba);
1734 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1735 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1736 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1737 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1738 clutter_stage_set_color (
1739 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1740 GTK_CLUTTER_EMBED (priv->video_container))),
1743 clutter_container_add (
1744 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1745 GTK_CLUTTER_EMBED (priv->video_container))),
1749 constraint = clutter_bind_constraint_new (
1750 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1751 CLUTTER_BIND_SIZE, 0);
1752 clutter_actor_add_constraint (priv->video_box, constraint);
1754 priv->remote_user_avatar_widget = gtk_image_new ();
1755 remote_avatar = gtk_clutter_actor_new_with_contents (
1756 priv->remote_user_avatar_widget);
1758 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1761 empathy_call_window_create_preview_rectangles (self);
1763 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1764 priv->video_container, TRUE, TRUE,
1765 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1767 create_pipeline (self);
1768 create_video_output_widget (self);
1769 create_audio_input (self);
1770 create_video_input (self);
1772 priv->floating_toolbar = empathy_rounded_actor_new ();
1774 gtk_widget_reparent (priv->bottom_toolbar,
1775 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1777 constraint = clutter_bind_constraint_new (
1778 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1781 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1784 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1785 "notify::allocation",
1786 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1789 clutter_actor_set_size (priv->floating_toolbar,
1790 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1791 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1793 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1794 priv->floating_toolbar,
1795 CLUTTER_BIN_ALIGNMENT_CENTER,
1796 CLUTTER_BIN_ALIGNMENT_END);
1798 clutter_actor_raise_top (priv->floating_toolbar);
1800 /* Transitions for the floating toolbar */
1801 priv->transitions = clutter_state_new ();
1803 /* all transitions last for 2s */
1804 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1806 /* transition from any state to "fade-out" state */
1807 clutter_state_set (priv->transitions, NULL, "fade-out",
1808 priv->floating_toolbar,
1809 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1812 /* transition from any state to "fade-in" state */
1813 clutter_state_set (priv->transitions, NULL, "fade-in",
1814 priv->floating_toolbar,
1815 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1818 /* put the actor into the "fade-in" state with no animation */
1819 clutter_state_warp_to_state (priv->transitions, "fade-in");
1821 /* The call will be started as soon the pipeline is playing */
1822 priv->start_call_when_playing = TRUE;
1824 priv->dtmf_panel = empathy_dialpad_widget_new ();
1825 g_signal_connect (priv->dtmf_panel, "start-tone",
1826 G_CALLBACK (dtmf_start_tone_cb), self);
1828 priv->tones = g_string_new ("");
1830 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1833 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1836 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1838 gtk_widget_show_all (top_vbox);
1840 gtk_widget_hide (priv->dtmf_panel);
1841 gtk_widget_hide (priv->details_vbox);
1843 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1845 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1846 priv->video_container);
1848 /* We hide the bottom toolbar after 3s of inactivity and show it
1849 * again on mouse movement */
1850 priv->inactivity_src = g_timeout_add_seconds (3,
1851 empathy_call_window_toolbar_timeout, self);
1853 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1854 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1856 g_signal_connect (G_OBJECT (self), "realize",
1857 G_CALLBACK (empathy_call_window_realized_cb), self);
1859 g_signal_connect (G_OBJECT (self), "delete-event",
1860 G_CALLBACK (empathy_call_window_delete_cb), self);
1862 g_signal_connect (G_OBJECT (self), "window-state-event",
1863 G_CALLBACK (empathy_call_window_state_event_cb), self);
1865 g_signal_connect (G_OBJECT (self), "key-press-event",
1866 G_CALLBACK (empathy_call_window_key_press_cb), self);
1868 g_signal_connect (self, "motion-notify-event",
1869 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1871 priv->timer = g_timer_new ();
1873 g_object_ref (priv->ui_manager);
1874 g_object_unref (gui);
1876 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1877 priv->mic_menu = empathy_mic_menu_new (self);
1878 priv->camera_menu = empathy_camera_menu_new (self);
1880 empathy_call_window_show_hangup_button (self, TRUE);
1882 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1883 /* These signals are used to track the window position and save it
1884 * when the window is destroyed. We need to do this as we don't want
1885 * the window geometry to be saved with the dialpad taken into account. */
1886 g_signal_connect (self, "destroy",
1887 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1888 g_signal_connect (self, "configure-event",
1889 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1890 g_signal_connect (self, "window-state-event",
1891 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1893 /* Don't display labels in both toolbars */
1894 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1897 /* Instead of specifying a width and a height, we specify only one size. That's
1898 because we want a square avatar icon. */
1900 init_contact_avatar_with_size (EmpathyContact *contact,
1901 GtkWidget *image_widget,
1904 GdkPixbuf *pixbuf_avatar = NULL;
1906 if (contact != NULL)
1908 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1912 if (pixbuf_avatar == NULL)
1914 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1915 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1918 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1920 if (pixbuf_avatar != NULL)
1921 g_object_unref (pixbuf_avatar);
1925 set_window_title (EmpathyCallWindow *self)
1927 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1930 if (priv->contact != NULL)
1932 /* translators: Call is a noun and %s is the contact name. This string
1933 * is used in the window title */
1934 tmp = g_strdup_printf (_("Call with %s"),
1935 empathy_contact_get_alias (priv->contact));
1936 gtk_window_set_title (GTK_WINDOW (self), tmp);
1941 g_warning ("Unknown remote contact!");
1946 set_remote_user_name (EmpathyCallWindow *self,
1947 EmpathyContact *contact)
1949 const gchar *alias = empathy_contact_get_alias (contact);
1950 const gchar *status = empathy_contact_get_status (contact);
1953 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1954 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1960 contact_name_changed_cb (EmpathyContact *contact,
1962 EmpathyCallWindow *self)
1964 set_window_title (self);
1965 set_remote_user_name (self, contact);
1969 contact_presence_changed_cb (EmpathyContact *contact,
1971 EmpathyCallWindow *self)
1973 set_remote_user_name (self, contact);
1977 contact_avatar_changed_cb (EmpathyContact *contact,
1979 EmpathyCallWindow *self)
1982 GtkAllocation allocation;
1983 GtkWidget *avatar_widget;
1985 avatar_widget = self->priv->remote_user_avatar_widget;
1987 gtk_widget_get_allocation (avatar_widget, &allocation);
1988 size = allocation.height;
1992 /* the widget is not allocated yet, set a default size */
1993 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1994 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1997 init_contact_avatar_with_size (contact, avatar_widget, size);
1999 avatar_widget = self->priv->remote_user_avatar_toolbar;
2001 gtk_widget_get_allocation (avatar_widget, &allocation);
2002 size = allocation.height;
2006 /* the widget is not allocated yet, set a default size */
2007 size = SMALL_TOOLBAR_SIZE;
2010 init_contact_avatar_with_size (contact, avatar_widget, size);
2014 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2015 EmpathyCallHandler *handler)
2017 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2019 tp_g_signal_connect_object (priv->contact, "notify::name",
2020 G_CALLBACK (contact_name_changed_cb), self, 0);
2021 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2022 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2023 tp_g_signal_connect_object (priv->contact, "notify::presence",
2024 G_CALLBACK (contact_presence_changed_cb), self, 0);
2026 set_window_title (self);
2027 set_remote_user_name (self, priv->contact);
2029 init_contact_avatar_with_size (priv->contact,
2030 priv->remote_user_avatar_widget,
2031 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2032 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2034 init_contact_avatar_with_size (priv->contact,
2035 priv->remote_user_avatar_toolbar,
2036 SMALL_TOOLBAR_SIZE);
2038 /* The remote avatar is shown by default and will be hidden when we receive
2039 video from the remote side. */
2040 clutter_actor_hide (priv->video_output);
2041 gtk_widget_show (priv->remote_user_avatar_widget);
2045 update_send_codec (EmpathyCallWindow *self,
2048 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2055 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2056 widget = priv->acodec_encoding_label;
2060 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2061 widget = priv->vcodec_encoding_label;
2067 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2068 gtk_label_set_text (GTK_LABEL (widget), tmp);
2073 send_audio_codec_notify_cb (GObject *object,
2077 EmpathyCallWindow *self = user_data;
2079 update_send_codec (self, TRUE);
2083 send_video_codec_notify_cb (GObject *object,
2087 EmpathyCallWindow *self = user_data;
2089 update_send_codec (self, FALSE);
2093 update_recv_codec (EmpathyCallWindow *self,
2096 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2099 GString *str = NULL;
2103 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2104 widget = priv->acodec_decoding_label;
2108 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2109 widget = priv->vcodec_decoding_label;
2115 for (l = codecs; l != NULL; l = g_list_next (l))
2117 FsCodec *codec = l->data;
2120 str = g_string_new (NULL);
2122 g_string_append (str, ", ");
2124 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2128 gtk_label_set_text (GTK_LABEL (widget), str->str);
2129 g_string_free (str, TRUE);
2133 recv_audio_codecs_notify_cb (GObject *object,
2137 EmpathyCallWindow *self = user_data;
2139 update_recv_codec (self, TRUE);
2143 recv_video_codecs_notify_cb (GObject *object,
2147 EmpathyCallWindow *self = user_data;
2149 update_recv_codec (self, FALSE);
2152 static const gchar *
2153 candidate_type_to_str (FsCandidate *candidate)
2155 switch (candidate->type)
2157 case FS_CANDIDATE_TYPE_HOST:
2159 case FS_CANDIDATE_TYPE_SRFLX:
2160 return "server reflexive";
2161 case FS_CANDIDATE_TYPE_PRFLX:
2162 return "peer reflexive";
2163 case FS_CANDIDATE_TYPE_RELAY:
2165 case FS_CANDIDATE_TYPE_MULTICAST:
2172 static const gchar *
2173 candidate_type_to_desc (FsCandidate *candidate)
2175 switch (candidate->type)
2177 case FS_CANDIDATE_TYPE_HOST:
2178 return _("The IP address as seen by the machine");
2179 case FS_CANDIDATE_TYPE_SRFLX:
2180 return _("The IP address as seen by a server on the Internet");
2181 case FS_CANDIDATE_TYPE_PRFLX:
2182 return _("The IP address of the peer as seen by the other side");
2183 case FS_CANDIDATE_TYPE_RELAY:
2184 return _("The IP address of a relay server");
2185 case FS_CANDIDATE_TYPE_MULTICAST:
2186 return _("The IP address of the multicast group");
2193 update_candidat_widget (EmpathyCallWindow *self,
2196 FsCandidate *candidate)
2200 g_assert (candidate != NULL);
2201 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2202 candidate->port, candidate_type_to_str (candidate));
2204 gtk_label_set_text (GTK_LABEL (label), str);
2205 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2211 candidates_changed_cb (GObject *object,
2213 EmpathyCallWindow *self)
2215 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2216 FsCandidate *candidate = NULL;
2218 if (type == FS_MEDIA_TYPE_VIDEO)
2220 /* Update remote candidate */
2221 candidate = empathy_call_handler_get_video_remote_candidate (
2224 update_candidat_widget (self, priv->video_remote_candidate_label,
2225 priv->video_remote_candidate_info_img, candidate);
2227 /* Update local candidate */
2228 candidate = empathy_call_handler_get_video_local_candidate (
2231 update_candidat_widget (self, priv->video_local_candidate_label,
2232 priv->video_local_candidate_info_img, candidate);
2236 /* Update remote candidate */
2237 candidate = empathy_call_handler_get_audio_remote_candidate (
2240 update_candidat_widget (self, priv->audio_remote_candidate_label,
2241 priv->audio_remote_candidate_info_img, candidate);
2243 /* Update local candidate */
2244 candidate = empathy_call_handler_get_audio_local_candidate (
2247 update_candidat_widget (self, priv->audio_local_candidate_label,
2248 priv->audio_local_candidate_info_img, candidate);
2253 empathy_call_window_constructed (GObject *object)
2255 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2256 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2257 TpyCallChannel *call;
2260 g_assert (priv->handler != NULL);
2262 g_object_get (priv->handler, "call-channel", &call, NULL);
2263 state = tpy_call_channel_get_state (call, NULL, NULL);
2264 priv->outgoing = (state == TPY_CALL_STATE_PENDING_INITIATOR);
2265 tp_clear_object (&call);
2267 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2268 g_assert (priv->contact != NULL);
2270 if (!empathy_contact_can_voip_video (priv->contact))
2272 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2273 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2276 empathy_call_window_setup_avatars (self, priv->handler);
2277 empathy_call_window_set_state_connecting (self);
2279 if (!empathy_call_handler_has_initial_video (priv->handler))
2281 gtk_toggle_tool_button_set_active (
2282 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2284 /* If call has InitialVideo, the preview will be started once the call has
2285 * been started (start_call()). */
2287 update_send_codec (self, TRUE);
2288 update_send_codec (self, FALSE);
2289 update_recv_codec (self, TRUE);
2290 update_recv_codec (self, FALSE);
2292 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2293 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2294 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2295 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2296 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2297 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2298 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2299 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2301 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2302 G_CALLBACK (candidates_changed_cb), self, 0);
2305 static void empathy_call_window_dispose (GObject *object);
2306 static void empathy_call_window_finalize (GObject *object);
2309 empathy_call_window_set_property (GObject *object,
2310 guint property_id, const GValue *value, GParamSpec *pspec)
2312 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2314 switch (property_id)
2316 case PROP_CALL_HANDLER:
2317 priv->handler = g_value_dup_object (value);
2320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2325 empathy_call_window_get_property (GObject *object,
2326 guint property_id, GValue *value, GParamSpec *pspec)
2328 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2330 switch (property_id)
2332 case PROP_CALL_HANDLER:
2333 g_value_set_object (value, priv->handler);
2336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2341 empathy_call_window_class_init (
2342 EmpathyCallWindowClass *empathy_call_window_class)
2344 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2345 GParamSpec *param_spec;
2347 g_type_class_add_private (empathy_call_window_class,
2348 sizeof (EmpathyCallWindowPriv));
2350 object_class->constructed = empathy_call_window_constructed;
2351 object_class->set_property = empathy_call_window_set_property;
2352 object_class->get_property = empathy_call_window_get_property;
2354 object_class->dispose = empathy_call_window_dispose;
2355 object_class->finalize = empathy_call_window_finalize;
2357 param_spec = g_param_spec_object ("handler",
2358 "handler", "The call handler",
2359 EMPATHY_TYPE_CALL_HANDLER,
2360 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2361 g_object_class_install_property (object_class,
2362 PROP_CALL_HANDLER, param_spec);
2366 empathy_call_window_dispose (GObject *object)
2368 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2369 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2371 if (priv->dispose_has_run)
2374 priv->dispose_has_run = TRUE;
2376 if (priv->handler != NULL)
2378 empathy_call_handler_stop_call (priv->handler);
2379 tp_clear_object (&priv->handler);
2382 if (priv->bus_message_source_id != 0)
2384 g_source_remove (priv->bus_message_source_id);
2385 priv->bus_message_source_id = 0;
2388 if (priv->got_video_src > 0)
2390 g_source_remove (priv->got_video_src);
2391 priv->got_video_src = 0;
2394 if (priv->inactivity_src > 0)
2396 g_source_remove (priv->inactivity_src);
2397 priv->inactivity_src = 0;
2400 tp_clear_object (&priv->pipeline);
2401 tp_clear_object (&priv->video_input);
2402 tp_clear_object (&priv->audio_input);
2403 tp_clear_object (&priv->video_tee);
2404 tp_clear_object (&priv->ui_manager);
2405 tp_clear_object (&priv->fullscreen);
2406 tp_clear_object (&priv->camera_monitor);
2407 tp_clear_object (&priv->settings);
2408 tp_clear_object (&priv->sound_mgr);
2409 tp_clear_object (&priv->mic_menu);
2410 tp_clear_object (&priv->camera_menu);
2412 g_list_free_full (priv->notifiers, g_object_unref);
2414 if (priv->timer_id != 0)
2415 g_source_remove (priv->timer_id);
2418 if (priv->contact != NULL)
2420 g_signal_handlers_disconnect_by_func (priv->contact,
2421 contact_name_changed_cb, self);
2422 priv->contact = NULL;
2425 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2429 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2431 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 if (priv->video_output_motion_handler_id != 0)
2435 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2436 priv->video_output_motion_handler_id);
2437 priv->video_output_motion_handler_id = 0;
2442 empathy_call_window_finalize (GObject *object)
2444 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2445 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2447 disconnect_video_output_motion_handler (self);
2449 /* free any data held directly by the object here */
2450 g_mutex_free (priv->lock);
2452 g_timer_destroy (priv->timer);
2454 g_string_free (priv->tones, TRUE);
2456 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2461 empathy_call_window_new (EmpathyCallHandler *handler)
2463 return EMPATHY_CALL_WINDOW (
2464 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2468 empathy_call_window_present (EmpathyCallWindow *self,
2469 EmpathyCallHandler *handler)
2471 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2473 tp_clear_object (&self->priv->handler);
2474 self->priv->handler = g_object_ref (handler);
2475 empathy_call_window_connect_handler (self);
2477 empathy_window_present (GTK_WINDOW (self));
2478 empathy_call_window_restart_call (self);
2482 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2483 GstElement *conference, gpointer user_data)
2485 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2486 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2487 FsElementAddedNotifier *notifier;
2490 DEBUG ("Conference added");
2492 /* Add notifier to set the various element properties as needed */
2493 notifier = fs_element_added_notifier_new ();
2494 keyfile = fs_utils_get_default_element_properties (conference);
2496 if (keyfile != NULL)
2497 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2499 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2501 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2503 gst_bin_add (GST_BIN (priv->pipeline), conference);
2504 gst_element_set_state (conference, GST_STATE_PLAYING);
2508 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2509 GstElement *conference, gpointer user_data)
2511 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2512 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2514 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2515 gst_element_set_state (conference, GST_STATE_NULL);
2519 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2521 GstStateChangeReturn state_change_return;
2522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2524 if (priv->pipeline == NULL)
2527 if (priv->bus_message_source_id != 0)
2529 g_source_remove (priv->bus_message_source_id);
2530 priv->bus_message_source_id = 0;
2533 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2535 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2536 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2538 if (priv->pipeline != NULL)
2539 g_object_unref (priv->pipeline);
2540 priv->pipeline = NULL;
2542 if (priv->audio_output != NULL)
2543 g_object_unref (priv->audio_output);
2544 priv->audio_output = NULL;
2545 priv->audio_output_added = FALSE;
2547 if (priv->video_tee != NULL)
2548 g_object_unref (priv->video_tee);
2549 priv->video_tee = NULL;
2551 if (priv->video_preview != NULL)
2552 clutter_actor_destroy (priv->video_preview);
2553 priv->video_preview = NULL;
2555 /* If we destroy the preview while it's being dragged, we won't
2556 * get the ::drag-end signal, so manually destroy the clone */
2557 if (priv->drag_preview != NULL)
2559 clutter_actor_destroy (priv->drag_preview);
2560 empathy_call_window_show_preview_rectangles (self, FALSE);
2561 priv->drag_preview = NULL;
2564 priv->funnel = NULL;
2566 create_pipeline (self);
2567 /* Call will be started when user will hit the 'redial' button */
2568 priv->start_call_when_playing = FALSE;
2569 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2575 g_message ("Error: could not destroy pipeline. Closing call window");
2576 gtk_widget_destroy (GTK_WIDGET (self));
2583 reset_details_pane (EmpathyCallWindow *self)
2585 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2587 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2588 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2589 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2590 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2594 empathy_call_window_disconnected (EmpathyCallWindow *self,
2597 gboolean could_disconnect = FALSE;
2598 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2599 gboolean could_reset_pipeline;
2601 /* Leave full screen mode if needed */
2602 gtk_window_unfullscreen (GTK_WINDOW (self));
2604 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2605 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2607 priv->sending_tones = FALSE;
2608 g_string_set_size (priv->tones, 0);
2610 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2612 if (priv->call_state == CONNECTING)
2613 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2615 if (priv->call_state != REDIALING)
2616 priv->call_state = DISCONNECTED;
2618 /* Show the toolbar */
2619 clutter_state_set_state (priv->transitions, "fade-in");
2621 if (could_reset_pipeline)
2623 g_mutex_lock (priv->lock);
2625 g_timer_stop (priv->timer);
2627 if (priv->timer_id != 0)
2628 g_source_remove (priv->timer_id);
2631 g_mutex_unlock (priv->lock);
2634 /* We are about to destroy the window, no need to update it or create
2635 * a video preview */
2638 empathy_call_window_status_message (self, _("Disconnected"));
2640 empathy_call_window_show_hangup_button (self, FALSE);
2642 /* Unsensitive the camera and mic button */
2643 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2644 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2646 /* Be sure that the mic button is enabled */
2647 gtk_toggle_tool_button_set_active (
2648 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2650 if (priv->camera_state == CAMERA_STATE_ON)
2652 /* Restart the preview with the new pipeline. */
2653 display_video_preview (self, TRUE);
2656 /* destroy the video output; it will be recreated when we'll redial */
2657 disconnect_video_output_motion_handler (self);
2658 if (priv->video_output != NULL)
2659 clutter_actor_destroy (priv->video_output);
2660 priv->video_output = NULL;
2661 if (priv->got_video_src > 0)
2663 g_source_remove (priv->got_video_src);
2664 priv->got_video_src = 0;
2667 gtk_widget_show (priv->remote_user_avatar_widget);
2669 reset_details_pane (self);
2671 priv->sending_video = FALSE;
2672 priv->call_started = FALSE;
2674 could_disconnect = TRUE;
2676 /* TODO: display the self avatar of the preview (depends if the "Always
2677 * Show Video Preview" is enabled or not) */
2680 return could_disconnect;
2685 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2688 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2689 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2691 if (empathy_call_window_disconnected (self, TRUE) &&
2692 priv->call_state == REDIALING)
2693 empathy_call_window_restart_call (self);
2697 empathy_call_window_content_is_raw (TfContent *content)
2699 FsConference *conference;
2702 g_object_get (content, "fs-conference", &conference, NULL);
2703 g_assert (conference != NULL);
2705 /* FIXME: Ugly hack, update when moving a packetization property into
2707 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2708 gst_object_unref (conference);
2714 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2716 EmpathyCallWindow *self)
2718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2719 FsMediaType media_type;
2721 DEBUG ("removing content");
2723 g_object_get (content, "media-type", &media_type, NULL);
2726 * This assumes that there is only one video stream per channel...
2729 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2731 if (priv->funnel != NULL)
2735 output = priv->video_output_sink;
2737 gst_element_set_state (output, GST_STATE_NULL);
2738 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2740 gst_bin_remove (GST_BIN (priv->pipeline), output);
2741 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2742 priv->funnel = NULL;
2745 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2747 if (priv->audio_output != NULL)
2749 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2751 if (priv->audio_output_added)
2752 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2753 priv->audio_output = NULL;
2754 priv->audio_output_added = FALSE;
2759 g_assert_not_reached ();
2766 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2768 EmpathyCallWindow *self)
2770 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2772 DEBUG ("Framerate changed to %u", framerate);
2774 if (priv->video_input != NULL)
2775 empathy_video_src_set_framerate (priv->video_input, framerate);
2779 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2782 EmpathyCallWindow *self)
2784 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2786 DEBUG ("Resolution changed to %ux%u", width, height);
2788 if (priv->video_input != NULL)
2790 empathy_video_src_set_resolution (priv->video_input, width, height);
2794 /* Called with global lock held */
2796 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2802 if (priv->funnel == NULL)
2804 output = priv->video_output_sink;
2806 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2810 g_warning ("Could not create fsfunnel");
2814 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2816 gst_object_unref (priv->funnel);
2817 priv->funnel = NULL;
2818 g_warning ("Could not add funnel to pipeline");
2822 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2824 g_warning ("Could not add the video output widget to the pipeline");
2828 if (!gst_element_link (priv->funnel, output))
2830 g_warning ("Could not link output sink to funnel");
2831 goto error_output_added;
2834 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2836 g_warning ("Could not start video sink");
2837 goto error_output_added;
2840 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2842 g_warning ("Could not start funnel");
2843 goto error_output_added;
2847 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2850 g_warning ("Could not get request pad from funnel");
2857 gst_element_set_locked_state (priv->funnel, TRUE);
2858 gst_element_set_locked_state (output, TRUE);
2860 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2861 gst_element_set_state (output, GST_STATE_NULL);
2863 gst_bin_remove (GST_BIN (priv->pipeline), output);
2864 gst_element_set_locked_state (output, FALSE);
2868 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2869 priv->funnel = NULL;
2874 /* Called with global lock held */
2876 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2879 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2881 GstPadTemplate *template;
2883 if (!priv->audio_output_added)
2885 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2887 g_warning ("Could not add audio sink to pipeline");
2888 g_object_unref (priv->audio_output);
2889 goto error_add_output;
2892 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2894 g_warning ("Could not start audio sink");
2899 template = gst_element_class_get_pad_template (
2900 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2902 pad = gst_element_request_pad (priv->audio_output,
2903 template, NULL, NULL);
2907 g_warning ("Could not get sink pad from sink");
2914 gst_element_set_locked_state (priv->audio_output, TRUE);
2915 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2916 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2917 priv->audio_output = NULL;
2925 empathy_call_window_update_timer (gpointer user_data)
2927 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2928 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2929 const gchar *status;
2933 time_ = g_timer_elapsed (priv->timer, NULL);
2935 if (priv->call_state == HELD)
2936 status = _("On hold");
2937 else if (!gtk_toggle_tool_button_get_active (
2938 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2941 status = _("Duration");
2943 /* Translators: 'status - minutes:seconds' the caller has been connected */
2944 str = g_strdup_printf (_("%s — %d:%02dm"),
2946 (int) time_ / 60, (int) time_ % 60);
2947 empathy_call_window_status_message (self, str);
2955 EMP_RESPONSE_BALANCE
2959 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2963 switch (response_id)
2965 case GTK_RESPONSE_CLOSE:
2966 gtk_widget_destroy (GTK_WIDGET (info_bar));
2968 case EMP_RESPONSE_BALANCE:
2969 empathy_url_show (GTK_WIDGET (info_bar),
2970 g_object_get_data (G_OBJECT (info_bar), "uri"));
2976 display_error (EmpathyCallWindow *self,
2980 const gchar *details,
2981 const gchar *button_text,
2983 gint button_response)
2985 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2986 GtkWidget *info_bar;
2987 GtkWidget *content_area;
2994 /* Create info bar */
2995 info_bar = gtk_info_bar_new ();
2997 if (button_text != NULL)
2999 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3000 button_text, button_response);
3001 g_object_set_data_full (G_OBJECT (info_bar),
3002 "uri", g_strdup (uri), g_free);
3005 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3006 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3008 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3010 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3012 /* hbox containing the image and the messages vbox */
3013 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3014 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3017 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3018 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3020 /* vbox containing the main message and the details expander */
3021 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3022 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3025 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3027 label = gtk_label_new (NULL);
3028 gtk_label_set_markup (GTK_LABEL (label), txt);
3029 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3030 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3033 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3036 if (details != NULL)
3038 GtkWidget *expander;
3040 expander = gtk_expander_new (_("Technical Details"));
3042 txt = g_strdup_printf ("<i>%s</i>", details);
3044 label = gtk_label_new (NULL);
3045 gtk_label_set_markup (GTK_LABEL (label), txt);
3046 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3047 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3050 gtk_container_add (GTK_CONTAINER (expander), label);
3051 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3054 g_signal_connect (info_bar, "response",
3055 G_CALLBACK (on_error_infobar_response_cb), NULL);
3057 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3058 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3059 gtk_widget_show_all (info_bar);
3064 media_stream_error_to_txt (EmpathyCallWindow *self,
3065 TpyCallChannel *call,
3067 TpMediaStreamError error)
3069 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3070 const gchar *cm = NULL;
3076 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3078 return g_strdup_printf (
3079 _("%s's software does not understand any of the audio formats "
3080 "supported by your computer"),
3081 empathy_contact_get_alias (priv->contact));
3083 return g_strdup_printf (
3084 _("%s's software does not understand any of the video formats "
3085 "supported by your computer"),
3086 empathy_contact_get_alias (priv->contact));
3088 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3089 return g_strdup_printf (
3090 _("Can't establish a connection to %s. "
3091 "One of you might be on a network that does not allow "
3092 "direct connections."),
3093 empathy_contact_get_alias (priv->contact));
3095 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3096 return g_strdup (_("There was a failure on the network"));
3098 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3100 return g_strdup (_("The audio formats necessary for this call "
3101 "are not installed on your computer"));
3103 return g_strdup (_("The video formats necessary for this call "
3104 "are not installed on your computer"));
3106 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3107 tp_connection_parse_object_path (
3108 tp_channel_borrow_connection (TP_CHANNEL (call)),
3111 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3112 "product=Telepathy&component=%s", cm);
3114 result = g_strdup_printf (
3115 _("Something unexpected happened in a Telepathy component. "
3116 "Please <a href=\"%s\">report this bug</a> and attach "
3117 "logs gathered from the 'Debug' window in the Help menu."), url);
3123 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3124 return g_strdup (_("There was a failure in the call engine"));
3126 case TP_MEDIA_STREAM_ERROR_EOS:
3127 return g_strdup (_("The end of the stream was reached"));
3129 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3136 empathy_call_window_stream_error (EmpathyCallWindow *self,
3137 TpyCallChannel *call,
3146 desc = media_stream_error_to_txt (self, call, audio, code);
3149 /* No description, use the error message. That's not great as it's not
3150 * localized but it's better than nothing. */
3151 display_error (self, call, icon, title, msg, NULL);
3155 display_error (self, call, icon, title, desc, msg);
3161 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3164 EmpathyCallWindow *self)
3166 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3167 "gnome-stock-mic", _("Can't establish audio stream"));
3171 empathy_call_window_video_stream_error (TpyCallChannel *call,
3174 EmpathyCallWindow *self)
3176 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3177 "camera-web", _("Can't establish video stream"));
3182 show_balance_error (EmpathyCallWindow *self)
3186 gchar *balance, *tmp;
3187 const gchar *uri, *currency;
3191 g_object_get (self->priv->handler,
3192 "call-channel", &call,
3195 conn = tp_channel_borrow_connection (call);
3196 g_object_unref (call);
3198 uri = tp_connection_get_balance_uri (conn);
3200 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3202 /* unknown balance */
3203 balance = g_strdup ("(--)");
3207 char *money = empathy_format_currency (amount, scale, currency);
3209 balance = g_strdup_printf ("%s %s",
3214 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3216 display_error (self,
3218 _("Sorry, you don’t have enough credit for that call."),
3222 EMP_RESPONSE_BALANCE);
3229 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3232 EmpathyCallWindow *self)
3234 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3235 TpyCallChannel *call;
3236 gboolean can_send_video;
3238 if (state == TPY_CALL_STATE_ENDED &&
3239 !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3241 show_balance_error (self);
3245 if (state != TPY_CALL_STATE_ACCEPTED)
3248 if (priv->call_state == CONNECTED)
3251 g_timer_start (priv->timer);
3252 priv->call_state = CONNECTED;
3254 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3256 can_send_video = priv->video_input != NULL &&
3257 empathy_contact_can_voip_video (priv->contact) &&
3258 empathy_camera_monitor_get_available (priv->camera_monitor);
3260 g_object_get (priv->handler, "call-channel", &call, NULL);
3262 if (tpy_call_channel_has_dtmf (call))
3263 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3265 if (priv->video_input == NULL)
3266 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3268 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3270 empathy_call_window_show_hangup_button (self, TRUE);
3272 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3274 clutter_actor_hide (priv->video_output);
3275 gtk_widget_show (priv->remote_user_avatar_widget);
3277 g_object_unref (call);
3279 g_mutex_lock (priv->lock);
3281 priv->timer_id = g_timeout_add_seconds (1,
3282 empathy_call_window_update_timer, self);
3284 g_mutex_unlock (priv->lock);
3286 empathy_call_window_update_timer (self);
3288 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3292 empathy_call_window_show_video_output_cb (gpointer user_data)
3294 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3296 if (self->priv->video_output != NULL)
3298 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3299 clutter_actor_show (self->priv->video_output);
3300 empathy_call_window_raise_actors (self);
3307 empathy_call_window_check_video_cb (gpointer data)
3309 EmpathyCallWindow *self = data;
3311 if (self->priv->got_video)
3313 self->priv->got_video = FALSE;
3317 /* No video in the last N seconds, display the remote avatar */
3318 empathy_call_window_show_video_output (self, FALSE);
3323 /* Called from the streaming thread */
3325 empathy_call_window_video_probe_cb (GstPad *pad,
3326 GstMiniObject *mini_obj,
3327 EmpathyCallWindow *self)
3330 if (GST_IS_EVENT (mini_obj))
3333 if (G_UNLIKELY (!self->priv->got_video))
3335 /* show the remote video */
3336 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3337 empathy_call_window_show_video_output_cb,
3338 g_object_ref (self), g_object_unref);
3340 self->priv->got_video = TRUE;
3346 /* Called from the streaming thread */
3348 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3349 TfContent *content, GstPad *src, gpointer user_data)
3351 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3352 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3353 gboolean retval = FALSE;
3358 g_mutex_lock (priv->lock);
3360 g_object_get (content, "media-type", &media_type, NULL);
3364 case TP_MEDIA_STREAM_TYPE_AUDIO:
3365 pad = empathy_call_window_get_audio_sink_pad (self, content);
3367 case TP_MEDIA_STREAM_TYPE_VIDEO:
3368 g_idle_add (empathy_call_window_show_video_output_cb, self);
3369 pad = empathy_call_window_get_video_sink_pad (self);
3371 gst_pad_add_data_probe (src,
3372 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3373 if (priv->got_video_src > 0)
3374 g_source_remove (priv->got_video_src);
3375 priv->got_video_src = g_timeout_add_seconds (1,
3376 empathy_call_window_check_video_cb, self);
3379 g_assert_not_reached ();
3385 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3386 g_warning ("Could not link %s sink pad",
3387 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3391 gst_object_unref (pad);
3395 /* If no sink could be linked, try to add fakesink to prevent the whole call
3400 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3402 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3404 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3405 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3406 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3408 gst_element_set_locked_state (fakesink, TRUE);
3409 gst_element_set_state (fakesink, GST_STATE_NULL);
3410 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3414 DEBUG ("Could not link real sink, linked fakesink instead");
3416 gst_object_unref (sinkpad);
3420 gst_object_unref (fakesink);
3425 g_mutex_unlock (priv->lock);
3431 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3434 EmpathyCallWindowPriv *priv = self->priv;
3436 g_assert (priv->audio_output_added == FALSE);
3437 g_assert (priv->audio_output == FALSE);
3439 priv->audio_output = empathy_audio_sink_new ();
3440 g_object_ref_sink (priv->audio_output);
3442 /* volume button to output volume linking */
3443 g_object_bind_property (priv->audio_output, "volume",
3444 priv->volume_button, "value",
3445 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3447 g_object_bind_property_full (content, "requested-output-volume",
3448 priv->audio_output, "volume",
3450 audio_control_volume_to_element,
3451 element_volume_to_audio_control,
3454 /* Link volumes together, sync the current audio input volume property
3455 * back to farstream first */
3456 g_object_bind_property_full (priv->audio_output, "volume",
3457 content, "reported-output-volume",
3458 G_BINDING_SYNC_CREATE,
3459 element_volume_to_audio_control,
3460 audio_control_volume_to_element,
3463 /* For raw audio conferences assume that the producer of the raw data
3464 * has already processed it, so turn off any echo cancellation and any
3465 * other audio improvements that come with it */
3466 empathy_audio_sink_set_echo_cancel (
3467 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3468 !empathy_call_window_content_is_raw (content));
3473 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3474 TfContent *content, gpointer user_data)
3476 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3477 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3479 FsMediaType media_type;
3480 gboolean retval = FALSE;
3482 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3483 g_assert (sink != NULL);
3487 case FS_MEDIA_TYPE_AUDIO:
3489 /* For raw audio conferences assume that the receiver of the raw data
3490 * wants it unprocessed, so turn off any echo cancellation and any
3491 * other audio improvements that come with it */
3492 empathy_audio_src_set_echo_cancel (
3493 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3494 !empathy_call_window_content_is_raw (content));
3496 /* Link volumes together, sync the current audio input volume property
3497 * back to farstream first */
3498 g_object_bind_property_full (content, "requested-input-volume",
3499 priv->audio_input, "volume",
3501 audio_control_volume_to_element,
3502 element_volume_to_audio_control,
3505 g_object_bind_property_full (priv->audio_input, "volume",
3506 content, "reported-input-volume",
3507 G_BINDING_SYNC_CREATE,
3508 element_volume_to_audio_control,
3509 audio_control_volume_to_element,
3512 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3514 g_warning ("Could not add audio source to pipeline");
3518 pad = gst_element_get_static_pad (priv->audio_input, "src");
3521 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3522 g_warning ("Could not get source pad from audio source");
3526 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3528 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3529 g_warning ("Could not link audio source to farsight");
3533 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3535 g_warning ("Could not start audio source");
3536 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3537 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3541 /* Prepare our audio output, not added yet though */
3542 empathy_call_window_prepare_audio_output (self, content);
3546 case FS_MEDIA_TYPE_VIDEO:
3547 if (priv->video_tee != NULL)
3549 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3550 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3552 g_warning ("Could not link video source input pipeline");
3555 gst_object_unref (pad);
3561 g_assert_not_reached ();
3564 gst_object_unref (sink);
3569 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3571 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3572 GstElement *preview;
3574 disable_camera (self);
3576 DEBUG ("remove video input");
3577 preview = priv->video_preview_sink;
3579 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3580 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3581 gst_element_set_state (preview, GST_STATE_NULL);
3583 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3586 g_object_unref (priv->video_input);
3587 priv->video_input = NULL;
3588 g_object_unref (priv->video_tee);
3589 priv->video_tee = NULL;
3590 clutter_actor_destroy (priv->video_preview);
3591 priv->video_preview = NULL;
3593 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3597 start_call (EmpathyCallWindow *self)
3599 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3601 priv->call_started = TRUE;
3602 empathy_call_handler_start_call (priv->handler,
3603 gtk_get_current_event_time ());
3605 if (empathy_call_handler_has_initial_video (priv->handler))
3607 TpyCallChannel *call;
3610 g_object_get (priv->handler, "call-channel", &call, NULL);
3611 /* If the call channel isn't set yet we're requesting it, if we're
3612 * requesting it with initial video it should be PENDING_SEND when we get
3615 s = TPY_SENDING_STATE_PENDING_SEND;
3617 s = tpy_call_channel_get_video_state (call);
3619 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3620 s == TPY_SENDING_STATE_SENDING)
3622 /* Enable 'send video' buttons and display the preview */
3623 gtk_toggle_tool_button_set_active (
3624 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3628 gtk_toggle_tool_button_set_active (
3629 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3631 if (priv->video_preview == NULL)
3633 create_video_preview (self);
3634 add_video_preview_to_pipeline (self);
3639 g_object_unref (call);
3644 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3647 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3648 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3649 GstState newstate, pending;
3651 empathy_call_handler_bus_message (priv->handler, bus, message);
3653 switch (GST_MESSAGE_TYPE (message))
3655 case GST_MESSAGE_STATE_CHANGED:
3656 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3658 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3660 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3661 !priv->call_started)
3663 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3664 if (newstate == GST_STATE_PAUSED)
3666 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3667 priv->pipeline_playing = TRUE;
3669 if (priv->start_call_when_playing)
3673 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3675 gst_message_parse_state_changed (message, NULL, &newstate,
3678 if (newstate == GST_STATE_PLAYING &&
3679 pending == GST_STATE_VOID_PENDING)
3680 empathy_call_window_stop_camera_spinning (self);
3683 case GST_MESSAGE_ERROR:
3685 GError *error = NULL;
3686 GstElement *gst_error;
3689 gst_message_parse_error (message, &error, &debug);
3690 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3692 g_message ("Element error: %s -- %s\n", error->message, debug);
3694 if (g_str_has_prefix (gst_element_get_name (gst_error),
3695 VIDEO_INPUT_ERROR_PREFIX))
3697 /* Remove the video input and continue */
3698 if (priv->video_input != NULL)
3699 empathy_call_window_remove_video_input (self);
3700 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3704 empathy_call_window_disconnected (self, TRUE);
3706 g_error_free (error);
3709 case GST_MESSAGE_UNKNOWN:
3710 case GST_MESSAGE_EOS:
3711 case GST_MESSAGE_WARNING:
3712 case GST_MESSAGE_INFO:
3713 case GST_MESSAGE_TAG:
3714 case GST_MESSAGE_BUFFERING:
3715 case GST_MESSAGE_STATE_DIRTY:
3716 case GST_MESSAGE_STEP_DONE:
3717 case GST_MESSAGE_CLOCK_PROVIDE:
3718 case GST_MESSAGE_CLOCK_LOST:
3719 case GST_MESSAGE_NEW_CLOCK:
3720 case GST_MESSAGE_STRUCTURE_CHANGE:
3721 case GST_MESSAGE_STREAM_STATUS:
3722 case GST_MESSAGE_APPLICATION:
3723 case GST_MESSAGE_ELEMENT:
3724 case GST_MESSAGE_SEGMENT_START:
3725 case GST_MESSAGE_SEGMENT_DONE:
3726 case GST_MESSAGE_DURATION:
3727 case GST_MESSAGE_ANY:
3736 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3737 GHashTable *members,
3738 EmpathyCallWindow *self)
3740 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3741 GHashTableIter iter;
3742 gpointer key, value;
3743 gboolean held = FALSE;
3745 g_hash_table_iter_init (&iter, members);
3746 while (g_hash_table_iter_next (&iter, &key, &value))
3748 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3750 /* This assumes this is a 1-1 call, otherwise one participant
3751 * putting the call on hold wouldn't mean the call is on hold
3759 priv->call_state = HELD;
3760 else if (priv->call_state == HELD)
3761 priv->call_state = CONNECTED;
3765 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3767 EmpathyCallWindow *self)
3769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3770 TpyCallChannel *call;
3772 g_object_get (priv->handler, "call-channel", &call, NULL);
3777 tp_g_signal_connect_object (call, "audio-stream-error",
3778 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3779 tp_g_signal_connect_object (call, "video-stream-error",
3780 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3783 tp_g_signal_connect_object (call, "members-changed",
3784 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3786 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3787 empathy_call_window_tones_stopped_cb, self, NULL,
3788 G_OBJECT (call), NULL);
3790 g_object_unref (call);
3794 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3796 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3797 TpyCallChannel *call;
3799 g_signal_connect (priv->handler, "state-changed",
3800 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3801 g_signal_connect (priv->handler, "conference-added",
3802 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3803 g_signal_connect (priv->handler, "conference-removed",
3804 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3805 g_signal_connect (priv->handler, "closed",
3806 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3807 g_signal_connect (priv->handler, "src-pad-added",
3808 G_CALLBACK (empathy_call_window_src_added_cb), self);
3809 g_signal_connect (priv->handler, "content-added",
3810 G_CALLBACK (empathy_call_window_content_added_cb), self);
3811 g_signal_connect (priv->handler, "content-removed",
3812 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3814 /* We connect to ::call-channel unconditionally since we'll
3815 * get new channels if we hangup and redial or if we reuse the
3817 g_signal_connect (priv->handler, "notify::call-channel",
3818 G_CALLBACK (call_handler_notify_call_cb), self);
3820 g_signal_connect (priv->handler, "framerate-changed",
3821 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3822 g_signal_connect (priv->handler, "resolution-changed",
3823 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3825 g_object_get (priv->handler, "call-channel", &call, NULL);
3828 /* We won't get notify::call-channel for this channel, so
3829 * directly call the callback. */
3830 call_handler_notify_call_cb (priv->handler, NULL, self);
3831 g_object_unref (call);
3836 empathy_call_window_realized_cb (GtkWidget *widget,
3837 EmpathyCallWindow *self)
3841 /* Make the hangup button twice as wide */
3842 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3843 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3845 empathy_call_window_connect_handler (self);
3847 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3851 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3852 EmpathyCallWindow *window)
3854 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3856 if (priv->pipeline != NULL)
3858 if (priv->bus_message_source_id != 0)
3860 g_source_remove (priv->bus_message_source_id);
3861 priv->bus_message_source_id = 0;
3864 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3867 if (priv->call_state == CONNECTING)
3868 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3874 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3877 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3879 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3884 gtk_widget_hide (priv->dtmf_panel);
3885 gtk_widget_hide (menu);
3886 gtk_widget_hide (priv->toolbar);
3890 if (priv->dialpad_was_visible_before_fs)
3891 gtk_widget_show (priv->dtmf_panel);
3893 gtk_widget_show (menu);
3894 gtk_widget_show (priv->toolbar);
3896 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3897 priv->original_height_before_fs);
3902 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3904 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3906 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3907 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3908 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3909 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3911 if (priv->video_output != NULL)
3914 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3915 priv->video_output, TRUE, TRUE,
3916 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3923 empathy_call_window_state_event_cb (GtkWidget *widget,
3924 GdkEventWindowState *event, EmpathyCallWindow *window)
3926 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3928 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3929 gboolean set_fullscreen = event->new_window_state &
3930 GDK_WINDOW_STATE_FULLSCREEN;
3934 gboolean dialpad_was_visible;
3935 GtkAllocation allocation;
3936 gint original_width, original_height;
3938 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3939 original_width = allocation.width;
3940 original_height = allocation.height;
3942 g_object_get (priv->dtmf_panel,
3943 "visible", &dialpad_was_visible,
3946 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3947 priv->original_width_before_fs = original_width;
3948 priv->original_height_before_fs = original_height;
3950 if (priv->video_output_motion_handler_id == 0 &&
3951 priv->video_output != NULL)
3953 priv->video_output_motion_handler_id = g_signal_connect (
3954 G_OBJECT (priv->video_container), "motion-notify-event",
3955 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3961 disconnect_video_output_motion_handler (window);
3964 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3966 show_controls (window, set_fullscreen);
3967 show_borders (window, set_fullscreen);
3968 gtk_action_set_stock_id (priv->menu_fullscreen,
3969 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3970 priv->is_fullscreen = set_fullscreen;
3977 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3980 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3981 int w, h, dialpad_width;
3982 GtkAllocation allocation;
3984 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3985 w = allocation.width;
3986 h = allocation.height;
3988 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3992 gtk_widget_show (priv->dtmf_panel);
3998 gtk_widget_hide (priv->dtmf_panel);
4002 gtk_window_resize (GTK_WINDOW (window), w, h);
4006 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4009 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4010 TpyCallChannel *call;
4012 priv->sending_video = (state == CAMERA_STATE_ON);
4014 if (state == CAMERA_STATE_ON)
4016 /* When we start sending video, we want to show the video preview by
4018 display_video_preview (window, TRUE);
4022 display_video_preview (window, FALSE);
4025 if (priv->call_state != CONNECTED)
4028 g_object_get (priv->handler, "call-channel", &call, NULL);
4029 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4030 tpy_call_channel_send_video (call, priv->sending_video);
4031 g_object_unref (call);
4035 empathy_call_window_hangup_cb (gpointer object,
4036 EmpathyCallWindow *self)
4038 empathy_call_handler_stop_call (self->priv->handler);
4040 empathy_call_window_disconnected (self, TRUE);
4044 empathy_call_window_restart_call (EmpathyCallWindow *window)
4046 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4048 /* Remove error info bars */
4049 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4050 (GtkCallback) gtk_widget_destroy, NULL);
4052 create_video_output_widget (window);
4053 priv->outgoing = TRUE;
4054 empathy_call_window_set_state_connecting (window);
4056 if (priv->pipeline_playing)
4057 start_call (window);
4059 /* call will be started when the pipeline is ready */
4060 priv->start_call_when_playing = TRUE;
4062 empathy_call_window_setup_avatars (window, priv->handler);
4064 empathy_call_window_show_hangup_button (window, TRUE);
4068 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4069 EmpathyCallWindow *window)
4073 active = gtk_toggle_tool_button_get_active (button);
4075 empathy_call_window_show_dialpad (window, active);
4079 empathy_call_window_fullscreen_cb (gpointer object,
4080 EmpathyCallWindow *window)
4082 empathy_call_window_fullscreen_toggle (window);
4086 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4088 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4090 if (priv->is_fullscreen)
4091 gtk_window_unfullscreen (GTK_WINDOW (window));
4093 gtk_window_fullscreen (GTK_WINDOW (window));
4097 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4098 GdkEventButton *event, EmpathyCallWindow *window)
4100 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4102 empathy_call_window_video_menu_popup (window, event->button);
4110 empathy_call_window_key_press_cb (GtkWidget *video_output,
4111 GdkEventKey *event, EmpathyCallWindow *window)
4113 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4115 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4117 /* Since we are in fullscreen mode, toggling will bring us back to
4119 empathy_call_window_fullscreen_toggle (window);
4127 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4128 GdkEventMotion *event, EmpathyCallWindow *window)
4130 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4132 if (priv->is_fullscreen)
4134 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4136 /* Show the bottom toolbar */
4137 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4144 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4148 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4150 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4152 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4153 button, gtk_get_current_event_time ());
4154 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4158 empathy_call_window_status_message (EmpathyCallWindow *self,
4161 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4165 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4167 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4169 return priv->ui_manager;
4172 EmpathyGstAudioSrc *
4173 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4175 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4177 return (EmpathyGstAudioSrc *) priv->audio_input;
4180 EmpathyGstVideoSrc *
4181 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4183 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4187 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4188 const gchar *device)
4190 EmpathyGstVideoSrc *video;
4193 /* Restart the camera only if it's already running */
4194 running = (self->priv->video_preview != NULL);
4195 video = empathy_call_window_get_video_src (self);
4198 empathy_call_window_play_camera (self, FALSE);
4200 empathy_video_src_change_device (video, device);
4203 empathy_call_window_play_camera (self, TRUE);