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 GstElement *pipeline;
232 GstElement *video_tee;
242 gboolean call_started;
243 gboolean sending_video;
244 CameraState camera_state;
246 EmpathyCallWindowFullscreen *fullscreen;
247 gboolean is_fullscreen;
252 guint inactivity_src;
254 /* Those fields represent the state of the window before it actually was in
256 gboolean dialpad_was_visible_before_fs;
257 gint original_width_before_fs;
258 gint original_height_before_fs;
260 gint x, y, w, h, dialpad_width;
263 /* TRUE if the call should be started when the pipeline is playing */
264 gboolean start_call_when_playing;
265 /* TRUE if we requested to set the pipeline in the playing state */
266 gboolean pipeline_playing;
268 EmpathySoundManager *sound_mgr;
271 EmpathyMicMenu *mic_menu;
272 EmpathyCameraMenu *camera_menu;
275 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
277 static void empathy_call_window_realized_cb (GtkWidget *widget,
278 EmpathyCallWindow *window);
280 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
281 GdkEvent *event, EmpathyCallWindow *window);
283 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
284 GdkEventWindowState *event, EmpathyCallWindow *window);
286 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
289 static void empathy_call_window_hangup_cb (gpointer object,
290 EmpathyCallWindow *window);
292 static void empathy_call_window_fullscreen_cb (gpointer object,
293 EmpathyCallWindow *window);
295 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
297 static gboolean empathy_call_window_video_button_press_cb (
298 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
300 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
301 GdkEventKey *event, EmpathyCallWindow *window);
303 static gboolean empathy_call_window_video_output_motion_notify (
304 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
306 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
309 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
311 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
312 EmpathyCallWindow *window);
314 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
316 static void empathy_call_window_status_message (EmpathyCallWindow *window,
319 static gboolean empathy_call_window_bus_message (GstBus *bus,
320 GstMessage *message, gpointer user_data);
323 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
326 gtk_widget_set_visible (self->priv->hangup_button, show);
327 gtk_widget_set_visible (self->priv->audio_call_button, !show);
328 gtk_widget_set_visible (self->priv->video_call_button, !show);
332 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
333 EmpathyCallWindow *self)
335 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
336 empathy_call_window_restart_call (self);
340 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
341 EmpathyCallWindow *self)
343 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
344 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
345 empathy_call_window_restart_call (self);
349 empathy_call_window_emit_tones (EmpathyCallWindow *self)
353 if (tp_str_empty (self->priv->tones->str))
356 g_object_get (self->priv->handler, "call-channel", &channel, NULL);
358 DEBUG ("Emitting multiple tones: %s", self->priv->tones->str);
360 tp_cli_channel_interface_dtmf_call_multiple_tones (channel, -1,
361 self->priv->tones->str,
362 NULL, NULL, NULL, NULL);
364 self->priv->sending_tones = TRUE;
366 g_string_set_size (self->priv->tones, 0);
368 g_object_unref (channel);
372 empathy_call_window_maybe_emit_tones (EmpathyCallWindow *self)
374 if (self->priv->sending_tones)
377 empathy_call_window_emit_tones (self);
381 empathy_call_window_tones_stopped_cb (TpChannel *proxy,
382 gboolean arg_cancelled,
384 GObject *weak_object)
386 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
388 self->priv->sending_tones = FALSE;
390 empathy_call_window_emit_tones (self);
394 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
396 EmpathyCallWindow *self)
398 EmpathyCallWindowPriv *priv = GET_PRIV (self);
400 g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
402 empathy_call_window_maybe_emit_tones (self);
406 empathy_call_window_raise_actors (EmpathyCallWindow *self)
408 clutter_actor_raise_top (self->priv->floating_toolbar);
410 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
411 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
412 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
413 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
417 empathy_call_window_show_video_output (EmpathyCallWindow *self,
420 if (self->priv->video_output != NULL)
421 g_object_set (self->priv->video_output, "visible", show, NULL);
423 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
425 empathy_call_window_raise_actors (self);
429 create_video_output_widget (EmpathyCallWindow *self)
431 EmpathyCallWindowPriv *priv = GET_PRIV (self);
433 g_assert (priv->video_output == NULL);
434 g_assert (priv->pipeline != NULL);
436 priv->video_output = clutter_texture_new ();
438 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
441 priv->video_output_sink = clutter_gst_video_sink_new (
442 CLUTTER_TEXTURE (priv->video_output));
444 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
447 gtk_widget_add_events (priv->video_container,
448 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
449 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
450 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
454 create_video_input (EmpathyCallWindow *self)
456 EmpathyCallWindowPriv *priv = GET_PRIV (self);
458 g_assert (priv->video_input == NULL);
459 priv->video_input = empathy_video_src_new ();
460 gst_object_ref (priv->video_input);
461 gst_object_sink (priv->video_input);
465 audio_control_volume_to_element (GBinding *binding,
466 const GValue *source_value,
467 GValue *target_value,
470 /* AudioControl volume is 0-255, with -1 for unknown */
473 hv = g_value_get_int (source_value);
478 g_value_set_double (target_value, hv/255.0);
484 element_volume_to_audio_control (GBinding *binding,
485 const GValue *source_value,
486 GValue *target_value,
491 ev = g_value_get_double (source_value);
492 ev = CLAMP (ev, 0.0, 1.0);
494 g_value_set_int (target_value, ev * 255);
499 create_audio_input (EmpathyCallWindow *self)
501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
503 g_assert (priv->audio_input == NULL);
504 priv->audio_input = empathy_audio_src_new ();
505 gst_object_ref (priv->audio_input);
506 gst_object_sink (priv->audio_input);
508 g_object_bind_property (priv->mic_button, "active",
509 priv->audio_input, "mute",
510 G_BINDING_BIDIRECTIONAL |
511 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
515 add_video_preview_to_pipeline (EmpathyCallWindow *self)
517 EmpathyCallWindowPriv *priv = GET_PRIV (self);
520 g_assert (priv->video_preview != NULL);
521 g_assert (priv->pipeline != NULL);
522 g_assert (priv->video_input != NULL);
523 g_assert (priv->video_tee != NULL);
525 preview = priv->video_preview_sink;
527 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
529 g_warning ("Could not add video input to pipeline");
533 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
535 g_warning ("Could not add video preview to pipeline");
539 if (!gst_element_link (priv->video_input, priv->video_tee))
541 g_warning ("Could not link video input to video tee");
545 if (!gst_element_link (priv->video_tee, preview))
547 g_warning ("Could not link video tee to video preview");
553 empathy_call_window_disable_camera_cb (GtkAction *action,
554 EmpathyCallWindow *self)
556 clutter_actor_destroy (self->priv->preview_hidden_button);
558 gtk_toggle_tool_button_set_active (
559 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
563 empathy_call_window_minimise_camera_cb (GtkAction *action,
564 EmpathyCallWindow *self)
566 clutter_actor_hide (self->priv->video_preview);
567 clutter_actor_show (self->priv->preview_hidden_button);
571 empathy_call_window_maximise_camera_cb (GtkAction *action,
572 EmpathyCallWindow *self)
574 clutter_actor_show (self->priv->video_preview);
575 clutter_actor_hide (self->priv->preview_hidden_button);
579 empathy_call_window_swap_camera_cb (GtkAction *action,
580 EmpathyCallWindow *self)
582 const GList *cameras, *l;
585 DEBUG ("Swapping the camera");
587 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
588 current_cam = empathy_video_src_dup_device (
589 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
591 for (l = cameras; l != NULL; l = l->next)
593 EmpathyCamera *camera = l->data;
595 if (!tp_strdiff (camera->device, current_cam))
600 next = l->next->data;
602 next = cameras->data;
604 /* EmpathyCameraMenu will update itself and do the actual change
606 g_settings_set_string (self->priv->settings,
607 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
614 g_free (current_cam);
618 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
619 EmpathyCamera *camera,
620 EmpathyCallWindow *self)
622 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
624 gtk_action_set_visible (self->priv->menu_swap_camera,
625 g_list_length ((GList *) cameras) >= 2);
629 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
630 EmpathyCamera *camera,
631 EmpathyCallWindow *self)
633 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
635 gtk_action_set_visible (self->priv->menu_swap_camera,
636 g_list_length ((GList *) cameras) >= 2);
640 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
641 EmpathyCallWindow *self)
645 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
647 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
648 0, gtk_get_current_event_time ());
649 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
653 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
654 EmpathyCallWindow *self)
658 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
659 "/preview-hidden-menu");
660 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
661 0, gtk_get_current_event_time ());
662 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
665 static ClutterActor *
666 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
668 ClutterBinAlignment x,
669 ClutterBinAlignment y)
671 ClutterLayoutManager *layout1, *layout2;
672 ClutterActor *rectangle;
673 ClutterActor *box1, *box2;
675 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
676 CLUTTER_BIN_ALIGNMENT_START);
678 box1 = clutter_box_new (layout1);
682 rectangle = empathy_rounded_rectangle_new (
683 SELF_VIDEO_SECTION_WIDTH + 5,
684 SELF_VIDEO_SECTION_HEIGHT + 5);
686 clutter_actor_set_size (box1,
687 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
688 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
689 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
691 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
692 CLUTTER_BIN_ALIGNMENT_CENTER);
694 /* We have a box with the margins and the video in the middle inside
695 * a bigger box with an extra bottom margin so we're not on top of
696 * the floating toolbar. */
697 box2 = clutter_box_new (layout2);
699 clutter_actor_set_size (box2,
700 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
701 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
703 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
704 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
706 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
709 clutter_actor_hide (rectangle);
715 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
717 self->priv->preview_rectangle1 =
718 empathy_call_window_create_preview_rectangle (self,
719 &self->priv->preview_rectangle_box1,
720 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
721 self->priv->preview_rectangle2 =
722 empathy_call_window_create_preview_rectangle (self,
723 &self->priv->preview_rectangle_box2,
724 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
725 self->priv->preview_rectangle3 =
726 empathy_call_window_create_preview_rectangle (self,
727 &self->priv->preview_rectangle_box3,
728 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
729 self->priv->preview_rectangle4 =
730 empathy_call_window_create_preview_rectangle (self,
731 &self->priv->preview_rectangle_box4,
732 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
736 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
739 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
740 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
741 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
742 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
746 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
751 guint ret_x = 0, ret_y = 0;
754 if (!clutter_actor_has_allocation (self->priv->video_box))
757 clutter_actor_get_geometry (self->priv->video_box, &box);
761 case PREVIEW_POS_TOP_LEFT:
762 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
764 case PREVIEW_POS_TOP_RIGHT:
765 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
766 - SELF_VIDEO_SECTION_WIDTH;
767 ret_y = SELF_VIDEO_SECTION_MARGIN;
769 case PREVIEW_POS_BOTTOM_LEFT:
770 ret_x = SELF_VIDEO_SECTION_MARGIN;
771 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
772 - SELF_VIDEO_SECTION_HEIGHT
773 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
775 case PREVIEW_POS_BOTTOM_RIGHT:
776 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
777 - SELF_VIDEO_SECTION_WIDTH;
778 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
779 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
780 - FLOATING_TOOLBAR_SPACING;
783 g_warn_if_reached ();
794 static PreviewPosition
795 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
800 PreviewPosition pos = PREVIEW_POS_NONE;
802 if (!clutter_actor_has_allocation (self->priv->video_box))
805 clutter_actor_get_geometry (self->priv->video_box, &box);
807 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
808 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
809 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
810 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
812 pos = PREVIEW_POS_TOP_LEFT;
814 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
815 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
816 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
817 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
819 pos = PREVIEW_POS_TOP_RIGHT;
821 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
822 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
823 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
824 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
826 pos = PREVIEW_POS_BOTTOM_LEFT;
828 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
829 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
830 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
831 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
833 pos = PREVIEW_POS_BOTTOM_RIGHT;
839 static ClutterActor *
840 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
843 ClutterActor *rectangle;
847 case PREVIEW_POS_TOP_LEFT:
848 rectangle = self->priv->preview_rectangle1;
850 case PREVIEW_POS_TOP_RIGHT:
851 rectangle = self->priv->preview_rectangle3;
853 case PREVIEW_POS_BOTTOM_LEFT:
854 rectangle = self->priv->preview_rectangle2;
856 case PREVIEW_POS_BOTTOM_RIGHT:
857 rectangle = self->priv->preview_rectangle4;
867 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
870 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
872 DEBUG ("moving the video preview to %d", pos);
874 self->priv->preview_pos = pos;
878 case PREVIEW_POS_TOP_LEFT:
879 clutter_bin_layout_set_alignment (layout,
880 self->priv->video_preview,
881 CLUTTER_BIN_ALIGNMENT_START,
882 CLUTTER_BIN_ALIGNMENT_START);
884 case PREVIEW_POS_TOP_RIGHT:
885 clutter_bin_layout_set_alignment (layout,
886 self->priv->video_preview,
887 CLUTTER_BIN_ALIGNMENT_END,
888 CLUTTER_BIN_ALIGNMENT_START);
890 case PREVIEW_POS_BOTTOM_LEFT:
891 clutter_bin_layout_set_alignment (layout,
892 self->priv->video_preview,
893 CLUTTER_BIN_ALIGNMENT_START,
894 CLUTTER_BIN_ALIGNMENT_END);
896 case PREVIEW_POS_BOTTOM_RIGHT:
897 clutter_bin_layout_set_alignment (layout,
898 self->priv->video_preview,
899 CLUTTER_BIN_ALIGNMENT_END,
900 CLUTTER_BIN_ALIGNMENT_END);
903 g_warn_if_reached ();
906 g_settings_set_enum (self->priv->settings, "camera-position", pos);
910 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
913 ClutterActor *rectangle;
915 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
917 empathy_rounded_rectangle_set_border_width (
918 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
919 empathy_rounded_rectangle_set_border_color (
920 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
924 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
925 ClutterActor *rectangle)
927 empathy_rounded_rectangle_set_border_width (
928 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
929 empathy_rounded_rectangle_set_border_color (
930 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
934 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
936 ClutterActor *rectangle;
938 rectangle = empathy_call_window_get_preview_rectangle (self,
939 self->priv->preview_pos);
941 /* We don't want to darken the rectangle where the preview
944 if (self->priv->preview_rectangle1 != rectangle)
945 empathy_call_window_darken_preview_rectangle (self,
946 self->priv->preview_rectangle1);
948 if (self->priv->preview_rectangle2 != rectangle)
949 empathy_call_window_darken_preview_rectangle (self,
950 self->priv->preview_rectangle2);
952 if (self->priv->preview_rectangle3 != rectangle)
953 empathy_call_window_darken_preview_rectangle (self,
954 self->priv->preview_rectangle3);
956 if (self->priv->preview_rectangle4 != rectangle)
957 empathy_call_window_darken_preview_rectangle (self,
958 self->priv->preview_rectangle4);
962 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
966 ClutterModifierType modifiers,
967 EmpathyCallWindow *self)
969 ClutterActor *stage = clutter_actor_get_stage (actor);
972 self->priv->drag_preview = clutter_clone_new (actor);
974 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
975 self->priv->drag_preview);
977 clutter_actor_transform_stage_point (actor, event_x, event_y,
980 clutter_actor_set_position (self->priv->drag_preview,
981 event_x - rel_x, event_y - rel_y);
983 clutter_drag_action_set_drag_handle (action,
984 self->priv->drag_preview);
986 clutter_actor_set_opacity (actor, 0);
987 clutter_actor_hide (self->priv->preview_shown_button);
989 empathy_call_window_show_preview_rectangles (self, TRUE);
990 empathy_call_window_darken_preview_rectangles (self);
994 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
997 clutter_actor_set_opacity (actor, 255);
1001 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
1002 ClutterActor *actor,
1005 ClutterModifierType modifiers,
1006 EmpathyCallWindow *self)
1008 PreviewPosition pos;
1011 /* Get the position before destroying the drag actor, otherwise the
1012 * preview_box allocation won't be valid and we won't be able to
1013 * calculate the position. */
1014 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1016 empathy_call_window_get_preview_coordinates (self,
1017 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1020 /* Move the preview to the destination and destroy it afterwards */
1021 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1024 "signal-swapped-after::completed",
1025 clutter_actor_destroy, self->priv->drag_preview,
1026 "signal-swapped-after::completed",
1027 clutter_actor_show, self->priv->preview_shown_button,
1028 "signal::completed",
1029 empathy_call_window_on_animation_completed_cb, actor,
1032 self->priv->drag_preview = NULL;
1034 if (pos != PREVIEW_POS_NONE)
1035 empathy_call_window_move_video_preview (self, pos);
1037 empathy_call_window_show_preview_rectangles (self, FALSE);
1041 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1042 ClutterActor *actor,
1045 EmpathyCallWindow *self)
1047 PreviewPosition pos;
1048 gfloat event_x, event_y;
1050 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1052 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1054 if (pos != PREVIEW_POS_NONE)
1055 empathy_call_window_highlight_preview_rectangle (self, pos);
1057 empathy_call_window_darken_preview_rectangles (self);
1061 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1062 ClutterCrossingEvent *event,
1063 EmpathyCallWindow *self)
1065 ClutterActor *rectangle;
1067 rectangle = empathy_call_window_get_preview_rectangle (self,
1068 self->priv->preview_pos);
1070 empathy_call_window_highlight_preview_rectangle (self,
1071 self->priv->preview_pos);
1073 clutter_actor_show (rectangle);
1079 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1080 ClutterCrossingEvent *event,
1081 EmpathyCallWindow *self)
1083 ClutterActor *rectangle;
1085 rectangle = empathy_call_window_get_preview_rectangle (self,
1086 self->priv->preview_pos);
1088 empathy_call_window_darken_preview_rectangle (self, rectangle);
1090 clutter_actor_hide (rectangle);
1096 create_video_preview (EmpathyCallWindow *self)
1098 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1099 ClutterLayoutManager *layout, *layout_center, *layout_end;
1100 ClutterActor *preview;
1103 ClutterAction *action;
1105 PreviewPosition pos;
1106 GdkRGBA transparent = { 0., 0., 0., 0. };
1108 g_assert (priv->video_preview == NULL);
1110 pos = g_settings_get_enum (priv->settings, "camera-position");
1112 preview = empathy_rounded_texture_new ();
1113 clutter_actor_set_size (preview,
1114 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1115 priv->video_preview_sink = clutter_gst_video_sink_new (
1116 CLUTTER_TEXTURE (preview));
1118 /* Add a little offset to the video preview */
1119 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1120 CLUTTER_BIN_ALIGNMENT_START);
1121 priv->video_preview = clutter_box_new (layout);
1122 clutter_actor_set_size (priv->video_preview,
1123 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1124 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1125 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1127 /* Spinner for when changing the camera device */
1128 priv->preview_spinner_widget = gtk_spinner_new ();
1129 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1130 empathy_rounded_actor_set_round_factor (
1131 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1133 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1134 gtk_widget_override_background_color (
1135 gtk_clutter_actor_get_widget (
1136 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1137 GTK_STATE_FLAG_NORMAL, &transparent);
1138 gtk_widget_show (priv->preview_spinner_widget);
1141 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1142 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1143 priv->preview_spinner_widget);
1144 clutter_actor_set_size (priv->preview_spinner_actor,
1145 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1146 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1147 clutter_actor_hide (priv->preview_spinner_actor);
1149 /* We have a box with the margins and the video in the middle inside
1150 * a bigger box with an extra bottom margin so we're not on top of
1151 * the floating toolbar. */
1152 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1153 CLUTTER_BIN_ALIGNMENT_CENTER);
1154 box = clutter_box_new (layout_center);
1155 clutter_actor_set_size (box,
1156 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1157 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1159 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1160 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1161 priv->preview_spinner_actor);
1162 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1164 g_object_set (priv->video_preview_sink,
1169 /* Translators: this is an "Info" label. It should be as short
1171 button = gtk_button_new_with_label (_("i"));
1172 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1174 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1176 clutter_actor_set_size (b, 24, 24);
1178 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1179 CLUTTER_BIN_ALIGNMENT_END);
1180 box = clutter_box_new (layout_end);
1181 clutter_actor_set_size (box,
1182 SELF_VIDEO_SECTION_WIDTH,
1183 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1185 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1186 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1188 g_signal_connect (button, "clicked",
1189 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1192 /* Translators: this is an "Info" label. It should be as short
1194 button = gtk_button_new_with_label (_("i"));
1195 b = empathy_rounded_actor_new ();
1197 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1199 clutter_actor_set_size (b, 24, 24);
1200 priv->preview_hidden_button = b;
1202 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1203 priv->preview_hidden_button,
1204 CLUTTER_BIN_ALIGNMENT_START,
1205 CLUTTER_BIN_ALIGNMENT_END);
1207 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1209 clutter_actor_hide (priv->preview_hidden_button);
1211 g_signal_connect (button, "clicked",
1212 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1215 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1216 priv->video_preview,
1217 CLUTTER_BIN_ALIGNMENT_START,
1218 CLUTTER_BIN_ALIGNMENT_END);
1220 empathy_call_window_move_video_preview (self, pos);
1222 action = clutter_drag_action_new ();
1223 g_signal_connect (action, "drag-begin",
1224 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1225 g_signal_connect (action, "drag-end",
1226 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1227 g_signal_connect (action, "drag-motion",
1228 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1230 g_signal_connect (preview, "enter-event",
1231 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1232 g_signal_connect (preview, "leave-event",
1233 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1235 clutter_actor_add_action (preview, action);
1236 clutter_actor_set_reactive (preview, TRUE);
1237 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1241 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1243 clutter_actor_show (self->priv->preview_spinner_actor);
1244 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1248 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1250 clutter_actor_hide (self->priv->preview_spinner_actor);
1251 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1255 empathy_call_window_play_camera (EmpathyCallWindow *self,
1258 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1259 GstElement *preview;
1262 if (priv->video_preview == NULL)
1264 create_video_preview (self);
1265 add_video_preview_to_pipeline (self);
1270 state = GST_STATE_PLAYING;
1274 empathy_call_window_start_camera_spinning (self);
1275 state = GST_STATE_NULL;
1278 preview = priv->video_preview_sink;
1280 gst_element_set_state (preview, state);
1281 gst_element_set_state (priv->video_tee, state);
1282 gst_element_set_state (priv->video_input, state);
1286 display_video_preview (EmpathyCallWindow *self,
1289 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1291 if (priv->video_preview == NULL)
1293 create_video_preview (self);
1294 add_video_preview_to_pipeline (self);
1299 /* Display the video preview */
1300 DEBUG ("Show video preview");
1302 empathy_call_window_play_camera (self, TRUE);
1303 clutter_actor_show (priv->video_preview);
1304 clutter_actor_raise_top (priv->floating_toolbar);
1308 /* Hide the video preview */
1309 DEBUG ("Hide video preview");
1311 if (priv->video_preview != NULL)
1313 clutter_actor_hide (priv->video_preview);
1314 empathy_call_window_play_camera (self, FALSE);
1320 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1322 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1324 empathy_call_window_status_message (window, _("Connecting…"));
1325 priv->call_state = CONNECTING;
1327 /* Show the toolbar */
1328 clutter_state_set_state (priv->transitions, "fade-in");
1331 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1332 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1336 disable_camera (EmpathyCallWindow *self)
1338 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1340 if (priv->camera_state == CAMERA_STATE_OFF)
1343 DEBUG ("Disable camera");
1345 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1347 priv->camera_state = CAMERA_STATE_OFF;
1351 enable_camera (EmpathyCallWindow *self)
1353 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1355 if (priv->camera_state == CAMERA_STATE_ON)
1358 if (priv->video_input == NULL)
1360 DEBUG ("Can't enable camera, no input");
1364 DEBUG ("Enable camera");
1366 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1368 priv->camera_state = CAMERA_STATE_ON;
1372 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1373 EmpathyCallWindow *self)
1375 if (gtk_toggle_tool_button_get_active (toggle))
1376 enable_camera (self);
1378 disable_camera (self);
1382 create_pipeline (EmpathyCallWindow *self)
1384 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1387 g_assert (priv->pipeline == NULL);
1389 priv->pipeline = gst_pipeline_new (NULL);
1390 priv->pipeline_playing = FALSE;
1392 priv->video_tee = gst_element_factory_make ("tee", NULL);
1393 gst_object_ref (priv->video_tee);
1394 gst_object_sink (priv->video_tee);
1396 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1398 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1399 priv->bus_message_source_id = gst_bus_add_watch (bus,
1400 empathy_call_window_bus_message, self);
1402 g_object_unref (bus);
1406 empathy_call_window_settings_cb (GtkAction *action,
1407 EmpathyCallWindow *self)
1409 gchar *args = g_strdup_printf ("-p %s",
1410 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1412 empathy_launch_program (BIN_DIR, "empathy", args);
1418 empathy_call_window_contents_cb (GtkAction *action,
1419 EmpathyCallWindow *self)
1421 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1425 empathy_call_window_debug_cb (GtkAction *action,
1426 EmpathyCallWindow *self)
1428 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1432 empathy_call_window_about_cb (GtkAction *action,
1433 EmpathyCallWindow *self)
1435 empathy_about_dialog_new (GTK_WINDOW (self));
1439 empathy_call_window_toolbar_timeout (gpointer data)
1441 EmpathyCallWindow *self = data;
1443 /* We don't want to hide the toolbar if we're not in a call, as
1444 * to show the call status all the time. */
1445 if (self->priv->call_state != CONNECTING &&
1446 self->priv->call_state != DISCONNECTED)
1447 clutter_state_set_state (self->priv->transitions, "fade-out");
1453 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1455 EmpathyCallWindow *self)
1457 clutter_state_set_state (self->priv->transitions, "fade-in");
1459 if (self->priv->inactivity_src > 0)
1460 g_source_remove (self->priv->inactivity_src);
1462 self->priv->inactivity_src = g_timeout_add_seconds (3,
1463 empathy_call_window_toolbar_timeout, self);
1469 empathy_call_window_configure_event_cb (GtkWidget *widget,
1471 EmpathyCallWindow *self)
1473 GdkWindow *gdk_window;
1474 GdkWindowState window_state;
1476 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1477 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1479 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1480 &self->priv->dialpad_width, NULL);
1482 gdk_window = gtk_widget_get_window (widget);
1483 window_state = gdk_window_get_state (gdk_window);
1484 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1490 empathy_call_window_destroyed_cb (GtkWidget *object,
1491 EmpathyCallWindow *self)
1493 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1495 /* Save the geometry as if the dialpad was hidden. */
1496 empathy_geometry_save_values (GTK_WINDOW (self),
1497 self->priv->x, self->priv->y,
1498 self->priv->w - self->priv->dialpad_width, self->priv->h,
1499 self->priv->maximized);
1504 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1506 ClutterBindConstraint *constraint)
1508 ClutterActorBox allocation;
1510 clutter_actor_get_allocation_box (stage, &allocation);
1512 clutter_bind_constraint_set_offset (constraint,
1513 allocation.y2 - allocation.y1 -
1514 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1518 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1520 EmpathyCallWindow *self)
1522 switch (response_id)
1524 case GTK_RESPONSE_ACCEPT:
1525 tp_channel_dispatch_operation_handle_with_async (
1526 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1528 tp_clear_object (&self->priv->pending_cdo);
1529 tp_clear_object (&self->priv->pending_channel);
1530 tp_clear_object (&self->priv->pending_context);
1533 case GTK_RESPONSE_CANCEL:
1534 tp_channel_dispatch_operation_close_channels_async (
1535 self->priv->pending_cdo, NULL, NULL);
1537 empathy_call_window_status_message (self, _("Disconnected"));
1538 self->priv->call_state = DISCONNECTED;
1541 g_warn_if_reached ();
1546 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1550 g_assert (self->priv->call_state != CONNECTED);
1552 video = tpy_call_channel_has_initial_video (self->priv->pending_channel);
1554 empathy_call_window_status_message (self, _("Incoming call"));
1555 self->priv->call_state = RINGING;
1557 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1558 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1559 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1560 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1561 empathy_contact_get_alias (self->priv->contact));
1563 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1564 _("Reject"), GTK_RESPONSE_CANCEL,
1565 _("Answer"), GTK_RESPONSE_ACCEPT,
1568 g_signal_connect (self->priv->incoming_call_dialog, "response",
1569 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1570 gtk_widget_show (self->priv->incoming_call_dialog);
1574 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1578 EmpathyCallWindow *self)
1580 tp_clear_object (&self->priv->pending_cdo);
1581 tp_clear_object (&self->priv->pending_channel);
1582 tp_clear_object (&self->priv->pending_context);
1584 /* We don't know if the incoming call has been accepted or not, so we
1585 * assume it hasn't and if it has, we'll set the proper status when
1586 * we get the new handler. */
1587 empathy_call_window_status_message (self, _("Disconnected"));
1588 self->priv->call_state = DISCONNECTED;
1590 gtk_widget_destroy (self->priv->incoming_call_dialog);
1591 self->priv->incoming_call_dialog = NULL;
1595 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1596 TpyCallChannel *channel,
1597 TpChannelDispatchOperation *dispatch_operation,
1598 TpAddDispatchOperationContext *context)
1600 g_assert (self->priv->pending_channel == NULL);
1601 g_assert (self->priv->pending_context == NULL);
1602 g_assert (self->priv->pending_cdo == NULL);
1604 /* Start ringing and delay until the user answers or hangs. */
1605 self->priv->pending_channel = g_object_ref (channel);
1606 self->priv->pending_context = g_object_ref (context);
1607 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1609 g_signal_connect (self->priv->pending_cdo, "invalidated",
1610 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1612 empathy_call_window_set_state_ringing (self);
1613 tp_add_dispatch_operation_context_accept (context);
1617 empathy_call_window_init (EmpathyCallWindow *self)
1619 EmpathyCallWindowPriv *priv;
1621 GtkWidget *top_vbox;
1623 ClutterConstraint *constraint;
1624 ClutterActor *remote_avatar;
1625 GtkStyleContext *context;
1629 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1630 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1632 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1634 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1635 gui = empathy_builder_get_file (filename,
1636 "call_window_vbox", &top_vbox,
1637 "errors_vbox", &priv->errors_vbox,
1638 "pane", &priv->pane,
1639 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1640 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1641 "status_label", &priv->status_label,
1642 "audiocall", &priv->audio_call_button,
1643 "videocall", &priv->video_call_button,
1644 "microphone", &priv->mic_button,
1645 "volume", &priv->volume_button,
1646 "camera", &priv->camera_button,
1647 "hangup", &priv->hangup_button,
1648 "dialpad", &priv->dialpad_button,
1649 "toolbar", &priv->toolbar,
1650 "bottom_toolbar", &priv->bottom_toolbar,
1651 "ui_manager", &priv->ui_manager,
1652 "menufullscreen", &priv->menu_fullscreen,
1653 "menupreviewswap", &priv->menu_swap_camera,
1654 "details_vbox", &priv->details_vbox,
1655 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1656 "acodec_encoding_label", &priv->acodec_encoding_label,
1657 "acodec_decoding_label", &priv->acodec_decoding_label,
1658 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1659 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1660 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1661 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1662 "video_local_candidate_label", &priv->video_local_candidate_label,
1663 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1664 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1665 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1666 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1670 empathy_builder_connect (gui, self,
1671 "hangup", "clicked", empathy_call_window_hangup_cb,
1672 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1673 "videocall", "clicked", empathy_call_window_video_call_cb,
1674 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1675 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1676 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1677 "menusettings", "activate", empathy_call_window_settings_cb,
1678 "menucontents", "activate", empathy_call_window_contents_cb,
1679 "menudebug", "activate", empathy_call_window_debug_cb,
1680 "menuabout", "activate", empathy_call_window_about_cb,
1681 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1682 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1683 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1684 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1687 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1689 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1691 g_object_bind_property (priv->camera_monitor, "available",
1692 priv->camera_button, "sensitive",
1693 G_BINDING_SYNC_CREATE);
1695 g_signal_connect (priv->camera_monitor, "added",
1696 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1697 g_signal_connect (priv->camera_monitor, "removed",
1698 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1700 priv->lock = g_mutex_new ();
1702 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1704 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1705 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1706 CONTENT_HBOX_BORDER_WIDTH);
1707 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1710 /* avatar/video box */
1711 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1712 CLUTTER_BIN_ALIGNMENT_CENTER);
1714 priv->video_box = clutter_box_new (priv->video_layout);
1716 priv->video_container = gtk_clutter_embed_new ();
1718 /* Set the background color to that of the rest of the window */
1719 context = gtk_widget_get_style_context (priv->content_hbox);
1720 gtk_style_context_get_background_color (context,
1721 GTK_STATE_FLAG_NORMAL, &rgba);
1722 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1723 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1724 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1725 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1726 clutter_stage_set_color (
1727 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1728 GTK_CLUTTER_EMBED (priv->video_container))),
1731 clutter_container_add (
1732 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1733 GTK_CLUTTER_EMBED (priv->video_container))),
1737 constraint = clutter_bind_constraint_new (
1738 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1739 CLUTTER_BIND_SIZE, 0);
1740 clutter_actor_add_constraint (priv->video_box, constraint);
1742 priv->remote_user_avatar_widget = gtk_image_new ();
1743 remote_avatar = gtk_clutter_actor_new_with_contents (
1744 priv->remote_user_avatar_widget);
1746 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1749 empathy_call_window_create_preview_rectangles (self);
1751 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1752 priv->video_container, TRUE, TRUE,
1753 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1755 create_pipeline (self);
1756 create_video_output_widget (self);
1757 create_audio_input (self);
1758 create_video_input (self);
1760 priv->floating_toolbar = empathy_rounded_actor_new ();
1762 gtk_widget_reparent (priv->bottom_toolbar,
1763 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1765 constraint = clutter_bind_constraint_new (
1766 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1769 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1772 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1773 "notify::allocation",
1774 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1777 clutter_actor_set_size (priv->floating_toolbar,
1778 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1779 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1781 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1782 priv->floating_toolbar,
1783 CLUTTER_BIN_ALIGNMENT_CENTER,
1784 CLUTTER_BIN_ALIGNMENT_END);
1786 clutter_actor_raise_top (priv->floating_toolbar);
1788 /* Transitions for the floating toolbar */
1789 priv->transitions = clutter_state_new ();
1791 /* all transitions last for 2s */
1792 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1794 /* transition from any state to "fade-out" state */
1795 clutter_state_set (priv->transitions, NULL, "fade-out",
1796 priv->floating_toolbar,
1797 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1800 /* transition from any state to "fade-in" state */
1801 clutter_state_set (priv->transitions, NULL, "fade-in",
1802 priv->floating_toolbar,
1803 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1806 /* put the actor into the "fade-in" state with no animation */
1807 clutter_state_warp_to_state (priv->transitions, "fade-in");
1809 /* The call will be started as soon the pipeline is playing */
1810 priv->start_call_when_playing = TRUE;
1812 priv->dtmf_panel = empathy_dialpad_widget_new ();
1813 g_signal_connect (priv->dtmf_panel, "start-tone",
1814 G_CALLBACK (dtmf_start_tone_cb), self);
1816 priv->tones = g_string_new ("");
1818 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1821 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1824 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1826 gtk_widget_show_all (top_vbox);
1828 gtk_widget_hide (priv->dtmf_panel);
1829 gtk_widget_hide (priv->details_vbox);
1831 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1833 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1834 priv->video_container);
1836 /* We hide the bottom toolbar after 3s of inactivity and show it
1837 * again on mouse movement */
1838 priv->inactivity_src = g_timeout_add_seconds (3,
1839 empathy_call_window_toolbar_timeout, self);
1841 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1842 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1844 g_signal_connect (G_OBJECT (self), "realize",
1845 G_CALLBACK (empathy_call_window_realized_cb), self);
1847 g_signal_connect (G_OBJECT (self), "delete-event",
1848 G_CALLBACK (empathy_call_window_delete_cb), self);
1850 g_signal_connect (G_OBJECT (self), "window-state-event",
1851 G_CALLBACK (empathy_call_window_state_event_cb), self);
1853 g_signal_connect (G_OBJECT (self), "key-press-event",
1854 G_CALLBACK (empathy_call_window_key_press_cb), self);
1856 g_signal_connect (self, "motion-notify-event",
1857 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1859 priv->timer = g_timer_new ();
1861 g_object_ref (priv->ui_manager);
1862 g_object_unref (gui);
1864 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1865 priv->mic_menu = empathy_mic_menu_new (self);
1866 priv->camera_menu = empathy_camera_menu_new (self);
1868 empathy_call_window_show_hangup_button (self, TRUE);
1870 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1871 /* These signals are used to track the window position and save it
1872 * when the window is destroyed. We need to do this as we don't want
1873 * the window geometry to be saved with the dialpad taken into account. */
1874 g_signal_connect (self, "destroy",
1875 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1876 g_signal_connect (self, "configure-event",
1877 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1878 g_signal_connect (self, "window-state-event",
1879 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1881 /* Don't display labels in both toolbars */
1882 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1885 /* Instead of specifying a width and a height, we specify only one size. That's
1886 because we want a square avatar icon. */
1888 init_contact_avatar_with_size (EmpathyContact *contact,
1889 GtkWidget *image_widget,
1892 GdkPixbuf *pixbuf_avatar = NULL;
1894 if (contact != NULL)
1896 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1900 if (pixbuf_avatar == NULL)
1902 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1903 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1906 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1908 if (pixbuf_avatar != NULL)
1909 g_object_unref (pixbuf_avatar);
1913 set_window_title (EmpathyCallWindow *self)
1915 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1918 if (priv->contact != NULL)
1920 /* translators: Call is a noun and %s is the contact name. This string
1921 * is used in the window title */
1922 tmp = g_strdup_printf (_("Call with %s"),
1923 empathy_contact_get_alias (priv->contact));
1924 gtk_window_set_title (GTK_WINDOW (self), tmp);
1929 g_warning ("Unknown remote contact!");
1934 set_remote_user_name (EmpathyCallWindow *self,
1935 EmpathyContact *contact)
1937 const gchar *alias = empathy_contact_get_alias (contact);
1938 const gchar *status = empathy_contact_get_status (contact);
1941 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1942 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1948 contact_name_changed_cb (EmpathyContact *contact,
1950 EmpathyCallWindow *self)
1952 set_window_title (self);
1953 set_remote_user_name (self, contact);
1957 contact_presence_changed_cb (EmpathyContact *contact,
1959 EmpathyCallWindow *self)
1961 set_remote_user_name (self, contact);
1965 contact_avatar_changed_cb (EmpathyContact *contact,
1967 EmpathyCallWindow *self)
1970 GtkAllocation allocation;
1971 GtkWidget *avatar_widget;
1973 avatar_widget = self->priv->remote_user_avatar_widget;
1975 gtk_widget_get_allocation (avatar_widget, &allocation);
1976 size = allocation.height;
1980 /* the widget is not allocated yet, set a default size */
1981 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1982 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1985 init_contact_avatar_with_size (contact, avatar_widget, size);
1987 avatar_widget = self->priv->remote_user_avatar_toolbar;
1989 gtk_widget_get_allocation (avatar_widget, &allocation);
1990 size = allocation.height;
1994 /* the widget is not allocated yet, set a default size */
1995 size = SMALL_TOOLBAR_SIZE;
1998 init_contact_avatar_with_size (contact, avatar_widget, size);
2002 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2003 EmpathyCallHandler *handler)
2005 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2007 tp_g_signal_connect_object (priv->contact, "notify::name",
2008 G_CALLBACK (contact_name_changed_cb), self, 0);
2009 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2010 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2011 tp_g_signal_connect_object (priv->contact, "notify::presence",
2012 G_CALLBACK (contact_presence_changed_cb), self, 0);
2014 set_window_title (self);
2015 set_remote_user_name (self, priv->contact);
2017 init_contact_avatar_with_size (priv->contact,
2018 priv->remote_user_avatar_widget,
2019 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2020 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2022 init_contact_avatar_with_size (priv->contact,
2023 priv->remote_user_avatar_toolbar,
2024 SMALL_TOOLBAR_SIZE);
2026 /* The remote avatar is shown by default and will be hidden when we receive
2027 video from the remote side. */
2028 clutter_actor_hide (priv->video_output);
2029 gtk_widget_show (priv->remote_user_avatar_widget);
2033 update_send_codec (EmpathyCallWindow *self,
2036 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2043 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2044 widget = priv->acodec_encoding_label;
2048 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2049 widget = priv->vcodec_encoding_label;
2055 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2056 gtk_label_set_text (GTK_LABEL (widget), tmp);
2061 send_audio_codec_notify_cb (GObject *object,
2065 EmpathyCallWindow *self = user_data;
2067 update_send_codec (self, TRUE);
2071 send_video_codec_notify_cb (GObject *object,
2075 EmpathyCallWindow *self = user_data;
2077 update_send_codec (self, FALSE);
2081 update_recv_codec (EmpathyCallWindow *self,
2084 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2087 GString *str = NULL;
2091 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2092 widget = priv->acodec_decoding_label;
2096 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2097 widget = priv->vcodec_decoding_label;
2103 for (l = codecs; l != NULL; l = g_list_next (l))
2105 FsCodec *codec = l->data;
2108 str = g_string_new (NULL);
2110 g_string_append (str, ", ");
2112 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2116 gtk_label_set_text (GTK_LABEL (widget), str->str);
2117 g_string_free (str, TRUE);
2121 recv_audio_codecs_notify_cb (GObject *object,
2125 EmpathyCallWindow *self = user_data;
2127 update_recv_codec (self, TRUE);
2131 recv_video_codecs_notify_cb (GObject *object,
2135 EmpathyCallWindow *self = user_data;
2137 update_recv_codec (self, FALSE);
2140 static const gchar *
2141 candidate_type_to_str (FsCandidate *candidate)
2143 switch (candidate->type)
2145 case FS_CANDIDATE_TYPE_HOST:
2147 case FS_CANDIDATE_TYPE_SRFLX:
2148 return "server reflexive";
2149 case FS_CANDIDATE_TYPE_PRFLX:
2150 return "peer reflexive";
2151 case FS_CANDIDATE_TYPE_RELAY:
2153 case FS_CANDIDATE_TYPE_MULTICAST:
2160 static const gchar *
2161 candidate_type_to_desc (FsCandidate *candidate)
2163 switch (candidate->type)
2165 case FS_CANDIDATE_TYPE_HOST:
2166 return _("The IP address as seen by the machine");
2167 case FS_CANDIDATE_TYPE_SRFLX:
2168 return _("The IP address as seen by a server on the Internet");
2169 case FS_CANDIDATE_TYPE_PRFLX:
2170 return _("The IP address of the peer as seen by the other side");
2171 case FS_CANDIDATE_TYPE_RELAY:
2172 return _("The IP address of a relay server");
2173 case FS_CANDIDATE_TYPE_MULTICAST:
2174 return _("The IP address of the multicast group");
2181 update_candidat_widget (EmpathyCallWindow *self,
2184 FsCandidate *candidate)
2188 g_assert (candidate != NULL);
2189 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2190 candidate->port, candidate_type_to_str (candidate));
2192 gtk_label_set_text (GTK_LABEL (label), str);
2193 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2199 candidates_changed_cb (GObject *object,
2201 EmpathyCallWindow *self)
2203 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2204 FsCandidate *candidate = NULL;
2206 if (type == FS_MEDIA_TYPE_VIDEO)
2208 /* Update remote candidate */
2209 candidate = empathy_call_handler_get_video_remote_candidate (
2212 update_candidat_widget (self, priv->video_remote_candidate_label,
2213 priv->video_remote_candidate_info_img, candidate);
2215 /* Update local candidate */
2216 candidate = empathy_call_handler_get_video_local_candidate (
2219 update_candidat_widget (self, priv->video_local_candidate_label,
2220 priv->video_local_candidate_info_img, candidate);
2224 /* Update remote candidate */
2225 candidate = empathy_call_handler_get_audio_remote_candidate (
2228 update_candidat_widget (self, priv->audio_remote_candidate_label,
2229 priv->audio_remote_candidate_info_img, candidate);
2231 /* Update local candidate */
2232 candidate = empathy_call_handler_get_audio_local_candidate (
2235 update_candidat_widget (self, priv->audio_local_candidate_label,
2236 priv->audio_local_candidate_info_img, candidate);
2241 empathy_call_window_constructed (GObject *object)
2243 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2245 TpyCallChannel *call;
2248 g_assert (priv->handler != NULL);
2250 g_object_get (priv->handler, "call-channel", &call, NULL);
2251 state = tpy_call_channel_get_state (call, NULL, NULL);
2252 priv->outgoing = (state == TPY_CALL_STATE_PENDING_INITIATOR);
2253 tp_clear_object (&call);
2255 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2256 g_assert (priv->contact != NULL);
2258 if (!empathy_contact_can_voip_video (priv->contact))
2260 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2261 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2264 empathy_call_window_setup_avatars (self, priv->handler);
2265 empathy_call_window_set_state_connecting (self);
2267 if (!empathy_call_handler_has_initial_video (priv->handler))
2269 gtk_toggle_tool_button_set_active (
2270 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2272 /* If call has InitialVideo, the preview will be started once the call has
2273 * been started (start_call()). */
2275 update_send_codec (self, TRUE);
2276 update_send_codec (self, FALSE);
2277 update_recv_codec (self, TRUE);
2278 update_recv_codec (self, FALSE);
2280 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2281 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2282 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2283 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2284 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2285 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2286 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2287 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2289 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2290 G_CALLBACK (candidates_changed_cb), self, 0);
2293 static void empathy_call_window_dispose (GObject *object);
2294 static void empathy_call_window_finalize (GObject *object);
2297 empathy_call_window_set_property (GObject *object,
2298 guint property_id, const GValue *value, GParamSpec *pspec)
2300 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2302 switch (property_id)
2304 case PROP_CALL_HANDLER:
2305 priv->handler = g_value_dup_object (value);
2308 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2313 empathy_call_window_get_property (GObject *object,
2314 guint property_id, GValue *value, GParamSpec *pspec)
2316 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2318 switch (property_id)
2320 case PROP_CALL_HANDLER:
2321 g_value_set_object (value, priv->handler);
2324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2329 empathy_call_window_class_init (
2330 EmpathyCallWindowClass *empathy_call_window_class)
2332 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2333 GParamSpec *param_spec;
2335 g_type_class_add_private (empathy_call_window_class,
2336 sizeof (EmpathyCallWindowPriv));
2338 object_class->constructed = empathy_call_window_constructed;
2339 object_class->set_property = empathy_call_window_set_property;
2340 object_class->get_property = empathy_call_window_get_property;
2342 object_class->dispose = empathy_call_window_dispose;
2343 object_class->finalize = empathy_call_window_finalize;
2345 param_spec = g_param_spec_object ("handler",
2346 "handler", "The call handler",
2347 EMPATHY_TYPE_CALL_HANDLER,
2348 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2349 g_object_class_install_property (object_class,
2350 PROP_CALL_HANDLER, param_spec);
2354 empathy_call_window_dispose (GObject *object)
2356 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2357 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2359 if (priv->dispose_has_run)
2362 priv->dispose_has_run = TRUE;
2364 if (priv->handler != NULL)
2366 empathy_call_handler_stop_call (priv->handler);
2367 tp_clear_object (&priv->handler);
2370 if (priv->bus_message_source_id != 0)
2372 g_source_remove (priv->bus_message_source_id);
2373 priv->bus_message_source_id = 0;
2376 if (priv->got_video_src > 0)
2378 g_source_remove (priv->got_video_src);
2379 priv->got_video_src = 0;
2382 if (priv->inactivity_src > 0)
2384 g_source_remove (priv->inactivity_src);
2385 priv->inactivity_src = 0;
2388 tp_clear_object (&priv->pipeline);
2389 tp_clear_object (&priv->video_input);
2390 tp_clear_object (&priv->audio_input);
2391 tp_clear_object (&priv->video_tee);
2392 tp_clear_object (&priv->ui_manager);
2393 tp_clear_object (&priv->fullscreen);
2394 tp_clear_object (&priv->camera_monitor);
2395 tp_clear_object (&priv->settings);
2396 tp_clear_object (&priv->sound_mgr);
2397 tp_clear_object (&priv->mic_menu);
2398 tp_clear_object (&priv->camera_menu);
2400 g_list_free_full (priv->notifiers, g_object_unref);
2402 if (priv->timer_id != 0)
2403 g_source_remove (priv->timer_id);
2406 if (priv->contact != NULL)
2408 g_signal_handlers_disconnect_by_func (priv->contact,
2409 contact_name_changed_cb, self);
2410 priv->contact = NULL;
2413 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2417 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2419 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2421 if (priv->video_output_motion_handler_id != 0)
2423 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2424 priv->video_output_motion_handler_id);
2425 priv->video_output_motion_handler_id = 0;
2430 empathy_call_window_finalize (GObject *object)
2432 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2435 disconnect_video_output_motion_handler (self);
2437 /* free any data held directly by the object here */
2438 g_mutex_free (priv->lock);
2440 g_timer_destroy (priv->timer);
2442 g_string_free (priv->tones, TRUE);
2444 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2449 empathy_call_window_new (EmpathyCallHandler *handler)
2451 return EMPATHY_CALL_WINDOW (
2452 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2456 empathy_call_window_present (EmpathyCallWindow *self,
2457 EmpathyCallHandler *handler)
2459 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2461 tp_clear_object (&self->priv->handler);
2462 self->priv->handler = g_object_ref (handler);
2463 empathy_call_window_connect_handler (self);
2465 empathy_window_present (GTK_WINDOW (self));
2466 empathy_call_window_restart_call (self);
2470 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2471 GstElement *conference, gpointer user_data)
2473 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2474 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2475 FsElementAddedNotifier *notifier;
2478 DEBUG ("Conference added");
2480 /* Add notifier to set the various element properties as needed */
2481 notifier = fs_element_added_notifier_new ();
2482 keyfile = fs_utils_get_default_element_properties (conference);
2484 if (keyfile != NULL)
2485 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2487 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2489 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2491 gst_bin_add (GST_BIN (priv->pipeline), conference);
2492 gst_element_set_state (conference, GST_STATE_PLAYING);
2496 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2497 GstElement *conference, gpointer user_data)
2499 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2500 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2502 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2503 gst_element_set_state (conference, GST_STATE_NULL);
2507 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2509 GstStateChangeReturn state_change_return;
2510 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2512 if (priv->pipeline == NULL)
2515 if (priv->bus_message_source_id != 0)
2517 g_source_remove (priv->bus_message_source_id);
2518 priv->bus_message_source_id = 0;
2521 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2523 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2524 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2526 if (priv->pipeline != NULL)
2527 g_object_unref (priv->pipeline);
2528 priv->pipeline = NULL;
2530 if (priv->audio_output != NULL)
2531 g_object_unref (priv->audio_output);
2532 priv->audio_output = NULL;
2534 if (priv->video_tee != NULL)
2535 g_object_unref (priv->video_tee);
2536 priv->video_tee = NULL;
2538 if (priv->video_preview != NULL)
2539 clutter_actor_destroy (priv->video_preview);
2540 priv->video_preview = NULL;
2542 /* If we destroy the preview while it's being dragged, we won't
2543 * get the ::drag-end signal, so manually destroy the clone */
2544 if (priv->drag_preview != NULL)
2546 clutter_actor_destroy (priv->drag_preview);
2547 empathy_call_window_show_preview_rectangles (self, FALSE);
2548 priv->drag_preview = NULL;
2551 priv->funnel = NULL;
2553 create_pipeline (self);
2554 /* Call will be started when user will hit the 'redial' button */
2555 priv->start_call_when_playing = FALSE;
2556 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2562 g_message ("Error: could not destroy pipeline. Closing call window");
2563 gtk_widget_destroy (GTK_WIDGET (self));
2570 reset_details_pane (EmpathyCallWindow *self)
2572 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2574 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2575 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2576 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2577 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2581 empathy_call_window_disconnected (EmpathyCallWindow *self,
2584 gboolean could_disconnect = FALSE;
2585 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2586 gboolean could_reset_pipeline;
2588 /* Leave full screen mode if needed */
2589 gtk_window_unfullscreen (GTK_WINDOW (self));
2591 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2592 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2594 priv->sending_tones = FALSE;
2595 g_string_set_size (priv->tones, 0);
2597 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2599 if (priv->call_state == CONNECTING)
2600 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2602 if (priv->call_state != REDIALING)
2603 priv->call_state = DISCONNECTED;
2605 /* Show the toolbar */
2606 clutter_state_set_state (priv->transitions, "fade-in");
2608 if (could_reset_pipeline)
2610 g_mutex_lock (priv->lock);
2612 g_timer_stop (priv->timer);
2614 if (priv->timer_id != 0)
2615 g_source_remove (priv->timer_id);
2618 g_mutex_unlock (priv->lock);
2621 /* We are about to destroy the window, no need to update it or create
2622 * a video preview */
2625 empathy_call_window_status_message (self, _("Disconnected"));
2627 empathy_call_window_show_hangup_button (self, FALSE);
2629 /* Unsensitive the camera and mic button */
2630 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2631 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2633 /* Be sure that the mic button is enabled */
2634 gtk_toggle_tool_button_set_active (
2635 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2637 if (priv->camera_state == CAMERA_STATE_ON)
2639 /* Restart the preview with the new pipeline. */
2640 display_video_preview (self, TRUE);
2643 /* destroy the video output; it will be recreated when we'll redial */
2644 disconnect_video_output_motion_handler (self);
2645 if (priv->video_output != NULL)
2646 clutter_actor_destroy (priv->video_output);
2647 priv->video_output = NULL;
2648 if (priv->got_video_src > 0)
2650 g_source_remove (priv->got_video_src);
2651 priv->got_video_src = 0;
2654 gtk_widget_show (priv->remote_user_avatar_widget);
2656 reset_details_pane (self);
2658 priv->sending_video = FALSE;
2659 priv->call_started = FALSE;
2661 could_disconnect = TRUE;
2663 /* TODO: display the self avatar of the preview (depends if the "Always
2664 * Show Video Preview" is enabled or not) */
2667 return could_disconnect;
2672 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2675 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2676 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2678 if (empathy_call_window_disconnected (self, TRUE) &&
2679 priv->call_state == REDIALING)
2680 empathy_call_window_restart_call (self);
2684 empathy_call_window_content_is_raw (TfContent *content)
2686 FsConference *conference;
2689 g_object_get (content, "fs-conference", &conference, NULL);
2690 g_assert (conference != NULL);
2692 /* FIXME: Ugly hack, update when moving a packetization property into
2694 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2695 gst_object_unref (conference);
2701 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2703 EmpathyCallWindow *self)
2705 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2706 FsMediaType media_type;
2708 DEBUG ("removing content");
2710 g_object_get (content, "media-type", &media_type, NULL);
2713 * This assumes that there is only one video stream per channel...
2716 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2718 if (priv->funnel != NULL)
2722 output = priv->video_output_sink;
2724 gst_element_set_state (output, GST_STATE_NULL);
2725 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2727 gst_bin_remove (GST_BIN (priv->pipeline), output);
2728 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2729 priv->funnel = NULL;
2732 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2734 if (priv->audio_output != NULL)
2736 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2738 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2739 priv->audio_output = NULL;
2744 g_assert_not_reached ();
2751 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2753 EmpathyCallWindow *self)
2755 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2757 DEBUG ("Framerate changed to %u", framerate);
2759 if (priv->video_input != NULL)
2760 empathy_video_src_set_framerate (priv->video_input, framerate);
2764 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2767 EmpathyCallWindow *self)
2769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2771 DEBUG ("Resolution changed to %ux%u", width, height);
2773 if (priv->video_input != NULL)
2775 empathy_video_src_set_resolution (priv->video_input, width, height);
2779 /* Called with global lock held */
2781 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2783 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2787 if (priv->funnel == NULL)
2789 output = priv->video_output_sink;
2791 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2795 g_warning ("Could not create fsfunnel");
2799 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2801 gst_object_unref (priv->funnel);
2802 priv->funnel = NULL;
2803 g_warning ("Could not add funnel to pipeline");
2807 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2809 g_warning ("Could not add the video output widget to the pipeline");
2813 if (!gst_element_link (priv->funnel, output))
2815 g_warning ("Could not link output sink to funnel");
2816 goto error_output_added;
2819 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2821 g_warning ("Could not start video sink");
2822 goto error_output_added;
2825 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2827 g_warning ("Could not start funnel");
2828 goto error_output_added;
2832 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2835 g_warning ("Could not get request pad from funnel");
2842 gst_element_set_locked_state (priv->funnel, TRUE);
2843 gst_element_set_locked_state (output, TRUE);
2845 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2846 gst_element_set_state (output, GST_STATE_NULL);
2848 gst_bin_remove (GST_BIN (priv->pipeline), output);
2849 gst_element_set_locked_state (output, FALSE);
2853 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2854 priv->funnel = NULL;
2859 /* Called with global lock held */
2861 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2864 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2866 GstPadTemplate *template;
2868 if (priv->audio_output == NULL)
2870 priv->audio_output = empathy_audio_sink_new ();
2871 g_object_ref_sink (priv->audio_output);
2873 /* volume button to output volume linking */
2874 g_object_bind_property (priv->audio_output, "volume",
2875 priv->volume_button, "value",
2876 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
2878 g_object_bind_property_full (content, "requested-output-volume",
2879 priv->audio_output, "volume",
2881 audio_control_volume_to_element,
2882 element_volume_to_audio_control,
2885 /* Link volumes together, sync the current audio input volume property
2886 * back to farstream first */
2887 g_object_bind_property_full (priv->audio_output, "volume",
2888 content, "reported-output-volume",
2889 G_BINDING_SYNC_CREATE,
2890 element_volume_to_audio_control,
2891 audio_control_volume_to_element,
2894 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2896 g_warning ("Could not add audio sink to pipeline");
2897 g_object_unref (priv->audio_output);
2898 goto error_add_output;
2901 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2903 g_warning ("Could not start audio sink");
2908 /* For raw audio conferences assume that the producer of the raw data
2909 * has already processed it, so turn off any echo cancellation and any
2910 * other audio improvements that come with it */
2911 empathy_audio_sink_set_echo_cancel (
2912 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2913 !empathy_call_window_content_is_raw (content));
2915 template = gst_element_class_get_pad_template (
2916 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2918 pad = gst_element_request_pad (priv->audio_output,
2919 template, NULL, NULL);
2923 g_warning ("Could not get sink pad from sink");
2930 gst_element_set_locked_state (priv->audio_output, TRUE);
2931 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2932 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2933 priv->audio_output = NULL;
2941 empathy_call_window_update_timer (gpointer user_data)
2943 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2944 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2945 const gchar *status;
2949 time_ = g_timer_elapsed (priv->timer, NULL);
2951 if (priv->call_state == HELD)
2952 status = _("On hold");
2953 else if (!gtk_toggle_tool_button_get_active (
2954 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2957 status = _("Duration");
2959 /* Translators: 'status - minutes:seconds' the caller has been connected */
2960 str = g_strdup_printf (_("%s — %d:%02dm"),
2962 (int) time_ / 60, (int) time_ % 60);
2963 empathy_call_window_status_message (self, str);
2971 EMP_RESPONSE_BALANCE
2975 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2979 switch (response_id)
2981 case GTK_RESPONSE_CLOSE:
2982 gtk_widget_destroy (GTK_WIDGET (info_bar));
2984 case EMP_RESPONSE_BALANCE:
2985 empathy_url_show (GTK_WIDGET (info_bar),
2986 g_object_get_data (G_OBJECT (info_bar), "uri"));
2992 display_error (EmpathyCallWindow *self,
2996 const gchar *details,
2997 const gchar *button_text,
2999 gint button_response)
3001 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3002 GtkWidget *info_bar;
3003 GtkWidget *content_area;
3010 /* Create info bar */
3011 info_bar = gtk_info_bar_new ();
3013 if (button_text != NULL)
3015 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3016 button_text, button_response);
3017 g_object_set_data_full (G_OBJECT (info_bar),
3018 "uri", g_strdup (uri), g_free);
3021 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3022 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3024 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3026 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3028 /* hbox containing the image and the messages vbox */
3029 hbox = gtk_hbox_new (FALSE, 3);
3030 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3033 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3034 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3036 /* vbox containing the main message and the details expander */
3037 vbox = gtk_vbox_new (FALSE, 3);
3038 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3041 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3043 label = gtk_label_new (NULL);
3044 gtk_label_set_markup (GTK_LABEL (label), txt);
3045 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3046 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3049 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3052 if (details != NULL)
3054 GtkWidget *expander;
3056 expander = gtk_expander_new (_("Technical Details"));
3058 txt = g_strdup_printf ("<i>%s</i>", details);
3060 label = gtk_label_new (NULL);
3061 gtk_label_set_markup (GTK_LABEL (label), txt);
3062 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3063 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3066 gtk_container_add (GTK_CONTAINER (expander), label);
3067 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3070 g_signal_connect (info_bar, "response",
3071 G_CALLBACK (on_error_infobar_response_cb), NULL);
3073 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3074 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3075 gtk_widget_show_all (info_bar);
3080 media_stream_error_to_txt (EmpathyCallWindow *self,
3081 TpyCallChannel *call,
3083 TpMediaStreamError error)
3085 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3086 const gchar *cm = NULL;
3092 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3094 return g_strdup_printf (
3095 _("%s's software does not understand any of the audio formats "
3096 "supported by your computer"),
3097 empathy_contact_get_alias (priv->contact));
3099 return g_strdup_printf (
3100 _("%s's software does not understand any of the video formats "
3101 "supported by your computer"),
3102 empathy_contact_get_alias (priv->contact));
3104 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3105 return g_strdup_printf (
3106 _("Can't establish a connection to %s. "
3107 "One of you might be on a network that does not allow "
3108 "direct connections."),
3109 empathy_contact_get_alias (priv->contact));
3111 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3112 return g_strdup (_("There was a failure on the network"));
3114 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3116 return g_strdup (_("The audio formats necessary for this call "
3117 "are not installed on your computer"));
3119 return g_strdup (_("The video formats necessary for this call "
3120 "are not installed on your computer"));
3122 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3123 tp_connection_parse_object_path (
3124 tp_channel_borrow_connection (TP_CHANNEL (call)),
3127 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3128 "product=Telepathy&component=%s", cm);
3130 result = g_strdup_printf (
3131 _("Something unexpected happened in a Telepathy component. "
3132 "Please <a href=\"%s\">report this bug</a> and attach "
3133 "logs gathered from the 'Debug' window in the Help menu."), url);
3139 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3140 return g_strdup (_("There was a failure in the call engine"));
3142 case TP_MEDIA_STREAM_ERROR_EOS:
3143 return g_strdup (_("The end of the stream was reached"));
3145 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3152 empathy_call_window_stream_error (EmpathyCallWindow *self,
3153 TpyCallChannel *call,
3162 desc = media_stream_error_to_txt (self, call, audio, code);
3165 /* No description, use the error message. That's not great as it's not
3166 * localized but it's better than nothing. */
3167 display_error (self, call, icon, title, msg, NULL);
3171 display_error (self, call, icon, title, desc, msg);
3177 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3180 EmpathyCallWindow *self)
3182 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3183 "gnome-stock-mic", _("Can't establish audio stream"));
3187 empathy_call_window_video_stream_error (TpyCallChannel *call,
3190 EmpathyCallWindow *self)
3192 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3193 "camera-web", _("Can't establish video stream"));
3198 show_balance_error (EmpathyCallWindow *self)
3202 gchar *balance, *tmp;
3203 const gchar *uri, *currency;
3207 g_object_get (self->priv->handler,
3208 "call-channel", &call,
3211 conn = tp_channel_borrow_connection (call);
3212 g_object_unref (call);
3214 uri = tp_connection_get_balance_uri (conn);
3216 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3218 /* unknown balance */
3219 balance = g_strdup ("(--)");
3223 char *money = empathy_format_currency (amount, scale, currency);
3225 balance = g_strdup_printf ("%s %s",
3230 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3232 display_error (self,
3234 _("Sorry, you don’t have enough credit for that call."),
3238 EMP_RESPONSE_BALANCE);
3245 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3248 EmpathyCallWindow *self)
3250 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3251 TpyCallChannel *call;
3252 gboolean can_send_video;
3254 if (state == TPY_CALL_STATE_ENDED &&
3255 !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3257 show_balance_error (self);
3261 if (state != TPY_CALL_STATE_ACCEPTED)
3264 if (priv->call_state == CONNECTED)
3267 g_timer_start (priv->timer);
3268 priv->call_state = CONNECTED;
3270 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3272 can_send_video = priv->video_input != NULL &&
3273 empathy_contact_can_voip_video (priv->contact) &&
3274 empathy_camera_monitor_get_available (priv->camera_monitor);
3276 g_object_get (priv->handler, "call-channel", &call, NULL);
3278 if (tpy_call_channel_has_dtmf (call))
3279 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3281 if (priv->video_input == NULL)
3282 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3284 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3286 empathy_call_window_show_hangup_button (self, TRUE);
3288 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3290 clutter_actor_hide (priv->video_output);
3291 gtk_widget_show (priv->remote_user_avatar_widget);
3293 g_object_unref (call);
3295 g_mutex_lock (priv->lock);
3297 priv->timer_id = g_timeout_add_seconds (1,
3298 empathy_call_window_update_timer, self);
3300 g_mutex_unlock (priv->lock);
3302 empathy_call_window_update_timer (self);
3304 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3308 empathy_call_window_show_video_output_cb (gpointer user_data)
3310 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3312 if (self->priv->video_output != NULL)
3314 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3315 clutter_actor_show (self->priv->video_output);
3316 empathy_call_window_raise_actors (self);
3323 empathy_call_window_check_video_cb (gpointer data)
3325 EmpathyCallWindow *self = data;
3327 if (self->priv->got_video)
3329 self->priv->got_video = FALSE;
3333 /* No video in the last N seconds, display the remote avatar */
3334 empathy_call_window_show_video_output (self, FALSE);
3339 /* Called from the streaming thread */
3341 empathy_call_window_video_probe_cb (GstPad *pad,
3342 GstMiniObject *mini_obj,
3343 EmpathyCallWindow *self)
3346 if (GST_IS_EVENT (mini_obj))
3349 if (G_UNLIKELY (!self->priv->got_video))
3351 /* show the remote video */
3352 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3353 empathy_call_window_show_video_output_cb,
3354 g_object_ref (self), g_object_unref);
3356 self->priv->got_video = TRUE;
3362 /* Called from the streaming thread */
3364 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3365 TfContent *content, GstPad *src, gpointer user_data)
3367 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3368 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3369 gboolean retval = FALSE;
3374 g_mutex_lock (priv->lock);
3376 g_object_get (content, "media-type", &media_type, NULL);
3380 case TP_MEDIA_STREAM_TYPE_AUDIO:
3381 pad = empathy_call_window_get_audio_sink_pad (self, content);
3383 case TP_MEDIA_STREAM_TYPE_VIDEO:
3384 g_idle_add (empathy_call_window_show_video_output_cb, self);
3385 pad = empathy_call_window_get_video_sink_pad (self);
3387 gst_pad_add_data_probe (src,
3388 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3389 if (priv->got_video_src > 0)
3390 g_source_remove (priv->got_video_src);
3391 priv->got_video_src = g_timeout_add_seconds (5,
3392 empathy_call_window_check_video_cb, self);
3395 g_assert_not_reached ();
3401 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3402 g_warning ("Could not link %s sink pad",
3403 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3407 gst_object_unref (pad);
3411 /* If no sink could be linked, try to add fakesink to prevent the whole call
3416 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3418 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3420 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3421 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3422 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3424 gst_element_set_locked_state (fakesink, TRUE);
3425 gst_element_set_state (fakesink, GST_STATE_NULL);
3426 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3430 DEBUG ("Could not link real sink, linked fakesink instead");
3432 gst_object_unref (sinkpad);
3436 gst_object_unref (fakesink);
3441 g_mutex_unlock (priv->lock);
3447 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3448 TfContent *content, gpointer user_data)
3450 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3451 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3453 FsMediaType media_type;
3454 gboolean retval = FALSE;
3456 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3457 g_assert (sink != NULL);
3461 case FS_MEDIA_TYPE_AUDIO:
3463 /* For raw audio conferences assume that the receiver of the raw data
3464 * wants it unprocessed, so turn off any echo cancellation and any
3465 * other audio improvements that come with it */
3466 empathy_audio_src_set_echo_cancel (
3467 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3468 !empathy_call_window_content_is_raw (content));
3470 /* Link volumes together, sync the current audio input volume property
3471 * back to farstream first */
3472 g_object_bind_property_full (content, "requested-input-volume",
3473 priv->audio_input, "volume",
3475 audio_control_volume_to_element,
3476 element_volume_to_audio_control,
3479 g_object_bind_property_full (priv->audio_input, "volume",
3480 content, "reported-input-volume",
3481 G_BINDING_SYNC_CREATE,
3482 element_volume_to_audio_control,
3483 audio_control_volume_to_element,
3486 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3488 g_warning ("Could not add audio source to pipeline");
3492 pad = gst_element_get_static_pad (priv->audio_input, "src");
3495 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3496 g_warning ("Could not get source pad from audio source");
3500 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3502 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3503 g_warning ("Could not link audio source to farsight");
3507 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3509 g_warning ("Could not start audio source");
3510 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3511 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3517 case FS_MEDIA_TYPE_VIDEO:
3518 if (priv->video_tee != NULL)
3520 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3521 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3523 g_warning ("Could not link video source input pipeline");
3526 gst_object_unref (pad);
3532 g_assert_not_reached ();
3535 gst_object_unref (sink);
3540 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3542 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3543 GstElement *preview;
3545 disable_camera (self);
3547 DEBUG ("remove video input");
3548 preview = priv->video_preview_sink;
3550 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3551 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3552 gst_element_set_state (preview, GST_STATE_NULL);
3554 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3557 g_object_unref (priv->video_input);
3558 priv->video_input = NULL;
3559 g_object_unref (priv->video_tee);
3560 priv->video_tee = NULL;
3561 clutter_actor_destroy (priv->video_preview);
3562 priv->video_preview = NULL;
3564 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3568 start_call (EmpathyCallWindow *self)
3570 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3572 priv->call_started = TRUE;
3573 empathy_call_handler_start_call (priv->handler,
3574 gtk_get_current_event_time ());
3576 if (empathy_call_handler_has_initial_video (priv->handler))
3578 TpyCallChannel *call;
3581 g_object_get (priv->handler, "call-channel", &call, NULL);
3582 /* If the call channel isn't set yet we're requesting it, if we're
3583 * requesting it with initial video it should be PENDING_SEND when we get
3586 s = TPY_SENDING_STATE_PENDING_SEND;
3588 s = tpy_call_channel_get_video_state (call);
3590 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3591 s == TPY_SENDING_STATE_SENDING)
3593 /* Enable 'send video' buttons and display the preview */
3594 gtk_toggle_tool_button_set_active (
3595 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3599 gtk_toggle_tool_button_set_active (
3600 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3602 if (priv->video_preview == NULL)
3604 create_video_preview (self);
3605 add_video_preview_to_pipeline (self);
3610 g_object_unref (call);
3615 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3618 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3619 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3620 GstState newstate, pending;
3622 empathy_call_handler_bus_message (priv->handler, bus, message);
3624 switch (GST_MESSAGE_TYPE (message))
3626 case GST_MESSAGE_STATE_CHANGED:
3627 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3629 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3631 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3632 !priv->call_started)
3634 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3635 if (newstate == GST_STATE_PAUSED)
3637 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3638 priv->pipeline_playing = TRUE;
3640 if (priv->start_call_when_playing)
3644 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3646 gst_message_parse_state_changed (message, NULL, &newstate,
3649 if (newstate == GST_STATE_PLAYING &&
3650 pending == GST_STATE_VOID_PENDING)
3651 empathy_call_window_stop_camera_spinning (self);
3654 case GST_MESSAGE_ERROR:
3656 GError *error = NULL;
3657 GstElement *gst_error;
3660 gst_message_parse_error (message, &error, &debug);
3661 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3663 g_message ("Element error: %s -- %s\n", error->message, debug);
3665 if (g_str_has_prefix (gst_element_get_name (gst_error),
3666 VIDEO_INPUT_ERROR_PREFIX))
3668 /* Remove the video input and continue */
3669 if (priv->video_input != NULL)
3670 empathy_call_window_remove_video_input (self);
3671 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3675 empathy_call_window_disconnected (self, TRUE);
3677 g_error_free (error);
3680 case GST_MESSAGE_UNKNOWN:
3681 case GST_MESSAGE_EOS:
3682 case GST_MESSAGE_WARNING:
3683 case GST_MESSAGE_INFO:
3684 case GST_MESSAGE_TAG:
3685 case GST_MESSAGE_BUFFERING:
3686 case GST_MESSAGE_STATE_DIRTY:
3687 case GST_MESSAGE_STEP_DONE:
3688 case GST_MESSAGE_CLOCK_PROVIDE:
3689 case GST_MESSAGE_CLOCK_LOST:
3690 case GST_MESSAGE_NEW_CLOCK:
3691 case GST_MESSAGE_STRUCTURE_CHANGE:
3692 case GST_MESSAGE_STREAM_STATUS:
3693 case GST_MESSAGE_APPLICATION:
3694 case GST_MESSAGE_ELEMENT:
3695 case GST_MESSAGE_SEGMENT_START:
3696 case GST_MESSAGE_SEGMENT_DONE:
3697 case GST_MESSAGE_DURATION:
3698 case GST_MESSAGE_ANY:
3707 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3708 GHashTable *members,
3709 EmpathyCallWindow *self)
3711 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3712 GHashTableIter iter;
3713 gpointer key, value;
3714 gboolean held = FALSE;
3716 g_hash_table_iter_init (&iter, members);
3717 while (g_hash_table_iter_next (&iter, &key, &value))
3719 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3721 /* This assumes this is a 1-1 call, otherwise one participant
3722 * putting the call on hold wouldn't mean the call is on hold
3730 priv->call_state = HELD;
3731 else if (priv->call_state == HELD)
3732 priv->call_state = CONNECTED;
3736 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3738 EmpathyCallWindow *self)
3740 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3741 TpyCallChannel *call;
3743 g_object_get (priv->handler, "call-channel", &call, NULL);
3748 tp_g_signal_connect_object (call, "audio-stream-error",
3749 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3750 tp_g_signal_connect_object (call, "video-stream-error",
3751 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3754 tp_g_signal_connect_object (call, "members-changed",
3755 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3757 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3758 empathy_call_window_tones_stopped_cb, self, NULL,
3759 G_OBJECT (call), NULL);
3761 g_object_unref (call);
3765 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3767 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3768 TpyCallChannel *call;
3770 g_signal_connect (priv->handler, "state-changed",
3771 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3772 g_signal_connect (priv->handler, "conference-added",
3773 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3774 g_signal_connect (priv->handler, "conference-removed",
3775 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3776 g_signal_connect (priv->handler, "closed",
3777 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3778 g_signal_connect (priv->handler, "src-pad-added",
3779 G_CALLBACK (empathy_call_window_src_added_cb), self);
3780 g_signal_connect (priv->handler, "content-added",
3781 G_CALLBACK (empathy_call_window_content_added_cb), self);
3782 g_signal_connect (priv->handler, "content-removed",
3783 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3785 /* We connect to ::call-channel unconditionally since we'll
3786 * get new channels if we hangup and redial or if we reuse the
3788 g_signal_connect (priv->handler, "notify::call-channel",
3789 G_CALLBACK (call_handler_notify_call_cb), self);
3791 g_signal_connect (priv->handler, "framerate-changed",
3792 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3793 g_signal_connect (priv->handler, "resolution-changed",
3794 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3796 g_object_get (priv->handler, "call-channel", &call, NULL);
3799 /* We won't get notify::call-channel for this channel, so
3800 * directly call the callback. */
3801 call_handler_notify_call_cb (priv->handler, NULL, self);
3802 g_object_unref (call);
3807 empathy_call_window_realized_cb (GtkWidget *widget,
3808 EmpathyCallWindow *self)
3812 /* Make the hangup button twice as wide */
3813 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3814 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3816 empathy_call_window_connect_handler (self);
3818 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3822 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3823 EmpathyCallWindow *window)
3825 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3827 if (priv->pipeline != NULL)
3829 if (priv->bus_message_source_id != 0)
3831 g_source_remove (priv->bus_message_source_id);
3832 priv->bus_message_source_id = 0;
3835 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3838 if (priv->call_state == CONNECTING)
3839 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3845 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3848 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3850 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3855 gtk_widget_hide (priv->dtmf_panel);
3856 gtk_widget_hide (menu);
3857 gtk_widget_hide (priv->toolbar);
3861 if (priv->dialpad_was_visible_before_fs)
3862 gtk_widget_show (priv->dtmf_panel);
3864 gtk_widget_show (menu);
3865 gtk_widget_show (priv->toolbar);
3867 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3868 priv->original_height_before_fs);
3873 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3875 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3877 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3878 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3879 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3880 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3882 if (priv->video_output != NULL)
3885 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3886 priv->video_output, TRUE, TRUE,
3887 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3894 empathy_call_window_state_event_cb (GtkWidget *widget,
3895 GdkEventWindowState *event, EmpathyCallWindow *window)
3897 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3899 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3900 gboolean set_fullscreen = event->new_window_state &
3901 GDK_WINDOW_STATE_FULLSCREEN;
3905 gboolean dialpad_was_visible;
3906 GtkAllocation allocation;
3907 gint original_width, original_height;
3909 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3910 original_width = allocation.width;
3911 original_height = allocation.height;
3913 g_object_get (priv->dtmf_panel,
3914 "visible", &dialpad_was_visible,
3917 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3918 priv->original_width_before_fs = original_width;
3919 priv->original_height_before_fs = original_height;
3921 if (priv->video_output_motion_handler_id == 0 &&
3922 priv->video_output != NULL)
3924 priv->video_output_motion_handler_id = g_signal_connect (
3925 G_OBJECT (priv->video_container), "motion-notify-event",
3926 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3932 disconnect_video_output_motion_handler (window);
3935 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3937 show_controls (window, set_fullscreen);
3938 show_borders (window, set_fullscreen);
3939 gtk_action_set_stock_id (priv->menu_fullscreen,
3940 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3941 priv->is_fullscreen = set_fullscreen;
3948 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3951 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3952 int w, h, dialpad_width;
3953 GtkAllocation allocation;
3955 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3956 w = allocation.width;
3957 h = allocation.height;
3959 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3963 gtk_widget_show (priv->dtmf_panel);
3969 gtk_widget_hide (priv->dtmf_panel);
3973 gtk_window_resize (GTK_WINDOW (window), w, h);
3977 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3980 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3981 TpyCallChannel *call;
3983 priv->sending_video = (state == CAMERA_STATE_ON);
3985 if (state == CAMERA_STATE_ON)
3987 /* When we start sending video, we want to show the video preview by
3989 display_video_preview (window, TRUE);
3993 display_video_preview (window, FALSE);
3996 if (priv->call_state != CONNECTED)
3999 g_object_get (priv->handler, "call-channel", &call, NULL);
4000 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4001 tpy_call_channel_send_video (call, priv->sending_video);
4002 g_object_unref (call);
4006 empathy_call_window_hangup_cb (gpointer object,
4007 EmpathyCallWindow *self)
4009 empathy_call_handler_stop_call (self->priv->handler);
4011 empathy_call_window_disconnected (self, TRUE);
4015 empathy_call_window_restart_call (EmpathyCallWindow *window)
4017 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4019 /* Remove error info bars */
4020 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4021 (GtkCallback) gtk_widget_destroy, NULL);
4023 create_video_output_widget (window);
4024 priv->outgoing = TRUE;
4025 empathy_call_window_set_state_connecting (window);
4027 if (priv->pipeline_playing)
4028 start_call (window);
4030 /* call will be started when the pipeline is ready */
4031 priv->start_call_when_playing = TRUE;
4033 empathy_call_window_setup_avatars (window, priv->handler);
4035 empathy_call_window_show_hangup_button (window, TRUE);
4039 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4040 EmpathyCallWindow *window)
4044 active = gtk_toggle_tool_button_get_active (button);
4046 empathy_call_window_show_dialpad (window, active);
4050 empathy_call_window_fullscreen_cb (gpointer object,
4051 EmpathyCallWindow *window)
4053 empathy_call_window_fullscreen_toggle (window);
4057 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4059 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4061 if (priv->is_fullscreen)
4062 gtk_window_unfullscreen (GTK_WINDOW (window));
4064 gtk_window_fullscreen (GTK_WINDOW (window));
4068 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4069 GdkEventButton *event, EmpathyCallWindow *window)
4071 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4073 empathy_call_window_video_menu_popup (window, event->button);
4081 empathy_call_window_key_press_cb (GtkWidget *video_output,
4082 GdkEventKey *event, EmpathyCallWindow *window)
4084 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4086 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4088 /* Since we are in fullscreen mode, toggling will bring us back to
4090 empathy_call_window_fullscreen_toggle (window);
4098 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4099 GdkEventMotion *event, EmpathyCallWindow *window)
4101 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4103 if (priv->is_fullscreen)
4105 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4107 /* Show the bottom toolbar */
4108 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4115 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4119 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4121 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4123 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4124 button, gtk_get_current_event_time ());
4125 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4129 empathy_call_window_status_message (EmpathyCallWindow *self,
4132 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4136 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4138 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4140 return priv->ui_manager;
4143 EmpathyGstAudioSrc *
4144 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4146 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4148 return (EmpathyGstAudioSrc *) priv->audio_input;
4151 EmpathyGstVideoSrc *
4152 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4154 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);