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 *camera_button;
171 GtkWidget *dialpad_button;
173 GtkWidget *bottom_toolbar;
174 ClutterActor *floating_toolbar;
176 GtkAction *menu_fullscreen;
177 GtkAction *menu_swap_camera;
179 ClutterState *transitions;
181 /* The box that contains self and remote avatar and video
182 input/output. When we redial, we destroy and re-create the box */
183 ClutterActor *video_box;
184 ClutterLayoutManager *video_layout;
186 /* Coordinates of the preview drag event's start. */
187 PreviewPosition preview_pos;
189 /* We keep a reference on the hbox which contains the main content so we can
190 easilly repack everything when toggling fullscreen */
191 GtkWidget *content_hbox;
193 /* These are used to accept or reject an incoming call when the status
195 GtkWidget *incoming_call_dialog;
196 TpyCallChannel *pending_channel;
197 TpChannelDispatchOperation *pending_cdo;
198 TpAddDispatchOperationContext *pending_context;
200 gulong video_output_motion_handler_id;
201 guint bus_message_source_id;
203 /* String that contains the queued tones to send after the current ones
206 gboolean sending_tones;
207 GtkWidget *dtmf_panel;
210 GtkWidget *details_vbox;
211 GtkWidget *vcodec_encoding_label;
212 GtkWidget *acodec_encoding_label;
213 GtkWidget *vcodec_decoding_label;
214 GtkWidget *acodec_decoding_label;
216 GtkWidget *audio_remote_candidate_label;
217 GtkWidget *audio_local_candidate_label;
218 GtkWidget *video_remote_candidate_label;
219 GtkWidget *video_local_candidate_label;
220 GtkWidget *video_remote_candidate_info_img;
221 GtkWidget *video_local_candidate_info_img;
222 GtkWidget *audio_remote_candidate_info_img;
223 GtkWidget *audio_local_candidate_info_img;
225 GstElement *video_input;
226 GstElement *video_preview_sink;
227 GstElement *video_output_sink;
228 GstElement *audio_input;
229 GstElement *audio_output;
230 GstElement *pipeline;
231 GstElement *video_tee;
241 gboolean call_started;
242 gboolean sending_video;
243 CameraState camera_state;
245 EmpathyCallWindowFullscreen *fullscreen;
246 gboolean is_fullscreen;
251 guint inactivity_src;
253 /* Those fields represent the state of the window before it actually was in
255 gboolean dialpad_was_visible_before_fs;
256 gint original_width_before_fs;
257 gint original_height_before_fs;
259 gint x, y, w, h, dialpad_width;
262 /* TRUE if the call should be started when the pipeline is playing */
263 gboolean start_call_when_playing;
264 /* TRUE if we requested to set the pipeline in the playing state */
265 gboolean pipeline_playing;
267 EmpathySoundManager *sound_mgr;
270 EmpathyMicMenu *mic_menu;
271 EmpathyCameraMenu *camera_menu;
274 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
276 static void empathy_call_window_realized_cb (GtkWidget *widget,
277 EmpathyCallWindow *window);
279 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
280 GdkEvent *event, EmpathyCallWindow *window);
282 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
283 GdkEventWindowState *event, EmpathyCallWindow *window);
285 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
288 static void empathy_call_window_hangup_cb (gpointer object,
289 EmpathyCallWindow *window);
291 static void empathy_call_window_fullscreen_cb (gpointer object,
292 EmpathyCallWindow *window);
294 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
296 static gboolean empathy_call_window_video_button_press_cb (
297 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
299 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
300 GdkEventKey *event, EmpathyCallWindow *window);
302 static gboolean empathy_call_window_video_output_motion_notify (
303 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
305 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
308 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
310 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
311 EmpathyCallWindow *window);
313 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
315 static void empathy_call_window_status_message (EmpathyCallWindow *window,
318 static gboolean empathy_call_window_bus_message (GstBus *bus,
319 GstMessage *message, gpointer user_data);
322 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
323 gdouble value, EmpathyCallWindow *window);
326 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
329 gtk_widget_set_visible (self->priv->hangup_button, show);
330 gtk_widget_set_visible (self->priv->audio_call_button, !show);
331 gtk_widget_set_visible (self->priv->video_call_button, !show);
335 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
336 EmpathyCallWindow *self)
338 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
339 empathy_call_window_restart_call (self);
343 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
344 EmpathyCallWindow *self)
346 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
347 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
348 empathy_call_window_restart_call (self);
352 empathy_call_window_emit_tones (EmpathyCallWindow *self)
356 if (tp_str_empty (self->priv->tones->str))
359 g_object_get (self->priv->handler, "call-channel", &channel, NULL);
361 DEBUG ("Emitting multiple tones: %s", self->priv->tones->str);
363 tp_cli_channel_interface_dtmf_call_multiple_tones (channel, -1,
364 self->priv->tones->str,
365 NULL, NULL, NULL, NULL);
367 self->priv->sending_tones = TRUE;
369 g_string_set_size (self->priv->tones, 0);
371 g_object_unref (channel);
375 empathy_call_window_maybe_emit_tones (EmpathyCallWindow *self)
377 if (self->priv->sending_tones)
380 empathy_call_window_emit_tones (self);
384 empathy_call_window_tones_stopped_cb (TpChannel *proxy,
385 gboolean arg_cancelled,
387 GObject *weak_object)
389 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
391 self->priv->sending_tones = FALSE;
393 empathy_call_window_emit_tones (self);
397 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
399 EmpathyCallWindow *self)
401 EmpathyCallWindowPriv *priv = GET_PRIV (self);
403 g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
405 empathy_call_window_maybe_emit_tones (self);
409 empathy_call_window_raise_actors (EmpathyCallWindow *self)
411 clutter_actor_raise_top (self->priv->floating_toolbar);
413 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
414 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
415 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
416 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
420 empathy_call_window_show_video_output (EmpathyCallWindow *self,
423 if (self->priv->video_output != NULL)
424 g_object_set (self->priv->video_output, "visible", show, NULL);
426 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
428 empathy_call_window_raise_actors (self);
432 create_video_output_widget (EmpathyCallWindow *self)
434 EmpathyCallWindowPriv *priv = GET_PRIV (self);
436 g_assert (priv->video_output == NULL);
437 g_assert (priv->pipeline != NULL);
439 priv->video_output = clutter_texture_new ();
441 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
444 priv->video_output_sink = clutter_gst_video_sink_new (
445 CLUTTER_TEXTURE (priv->video_output));
447 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
450 gtk_widget_add_events (priv->video_container,
451 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
452 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
453 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
457 create_video_input (EmpathyCallWindow *self)
459 EmpathyCallWindowPriv *priv = GET_PRIV (self);
461 g_assert (priv->video_input == NULL);
462 priv->video_input = empathy_video_src_new ();
463 gst_object_ref (priv->video_input);
464 gst_object_sink (priv->video_input);
468 audio_control_volume_to_element (GBinding *binding,
469 const GValue *source_value,
470 GValue *target_value,
473 /* AudioControl volume is 0-255, with -1 for unknown */
476 hv = g_value_get_int (source_value);
481 g_value_set_double (target_value, hv/255.0);
487 element_volume_to_audio_control (GBinding *binding,
488 const GValue *source_value,
489 GValue *target_value,
494 ev = g_value_get_double (source_value);
495 ev = CLAMP (ev, 0.0, 1.0);
497 g_value_set_int (target_value, ev * 255);
502 create_audio_input (EmpathyCallWindow *self)
504 EmpathyCallWindowPriv *priv = GET_PRIV (self);
506 g_assert (priv->audio_input == NULL);
507 priv->audio_input = empathy_audio_src_new ();
508 gst_object_ref (priv->audio_input);
509 gst_object_sink (priv->audio_input);
511 g_object_bind_property (priv->mic_button, "active",
512 priv->audio_input, "mute",
513 G_BINDING_BIDIRECTIONAL |
514 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
518 add_video_preview_to_pipeline (EmpathyCallWindow *self)
520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
523 g_assert (priv->video_preview != NULL);
524 g_assert (priv->pipeline != NULL);
525 g_assert (priv->video_input != NULL);
526 g_assert (priv->video_tee != NULL);
528 preview = priv->video_preview_sink;
530 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
532 g_warning ("Could not add video input to pipeline");
536 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
538 g_warning ("Could not add video preview to pipeline");
542 if (!gst_element_link (priv->video_input, priv->video_tee))
544 g_warning ("Could not link video input to video tee");
548 if (!gst_element_link (priv->video_tee, preview))
550 g_warning ("Could not link video tee to video preview");
556 empathy_call_window_disable_camera_cb (GtkAction *action,
557 EmpathyCallWindow *self)
559 clutter_actor_destroy (self->priv->preview_hidden_button);
561 gtk_toggle_tool_button_set_active (
562 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
566 empathy_call_window_minimise_camera_cb (GtkAction *action,
567 EmpathyCallWindow *self)
569 clutter_actor_hide (self->priv->video_preview);
570 clutter_actor_show (self->priv->preview_hidden_button);
574 empathy_call_window_maximise_camera_cb (GtkAction *action,
575 EmpathyCallWindow *self)
577 clutter_actor_show (self->priv->video_preview);
578 clutter_actor_hide (self->priv->preview_hidden_button);
582 empathy_call_window_swap_camera_cb (GtkAction *action,
583 EmpathyCallWindow *self)
585 const GList *cameras, *l;
588 DEBUG ("Swapping the camera");
590 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
591 current_cam = empathy_video_src_dup_device (
592 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
594 for (l = cameras; l != NULL; l = l->next)
596 EmpathyCamera *camera = l->data;
598 if (!tp_strdiff (camera->device, current_cam))
603 next = l->next->data;
605 next = cameras->data;
607 /* EmpathyCameraMenu will update itself and do the actual change
609 g_settings_set_string (self->priv->settings,
610 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
617 g_free (current_cam);
621 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
622 EmpathyCamera *camera,
623 EmpathyCallWindow *self)
625 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
627 gtk_action_set_visible (self->priv->menu_swap_camera,
628 g_list_length ((GList *) cameras) >= 2);
632 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
633 EmpathyCamera *camera,
634 EmpathyCallWindow *self)
636 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
638 gtk_action_set_visible (self->priv->menu_swap_camera,
639 g_list_length ((GList *) cameras) >= 2);
643 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
644 EmpathyCallWindow *self)
648 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
650 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
651 0, gtk_get_current_event_time ());
652 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
656 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
657 EmpathyCallWindow *self)
661 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
662 "/preview-hidden-menu");
663 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
664 0, gtk_get_current_event_time ());
665 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
668 static ClutterActor *
669 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
671 ClutterBinAlignment x,
672 ClutterBinAlignment y)
674 ClutterLayoutManager *layout1, *layout2;
675 ClutterActor *rectangle;
676 ClutterActor *box1, *box2;
678 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
679 CLUTTER_BIN_ALIGNMENT_START);
681 box1 = clutter_box_new (layout1);
685 rectangle = empathy_rounded_rectangle_new (
686 SELF_VIDEO_SECTION_WIDTH + 5,
687 SELF_VIDEO_SECTION_HEIGHT + 5);
689 clutter_actor_set_size (box1,
690 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
691 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
692 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
694 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
695 CLUTTER_BIN_ALIGNMENT_CENTER);
697 /* We have a box with the margins and the video in the middle inside
698 * a bigger box with an extra bottom margin so we're not on top of
699 * the floating toolbar. */
700 box2 = clutter_box_new (layout2);
702 clutter_actor_set_size (box2,
703 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
704 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
706 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
707 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
709 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
712 clutter_actor_hide (rectangle);
718 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
720 self->priv->preview_rectangle1 =
721 empathy_call_window_create_preview_rectangle (self,
722 &self->priv->preview_rectangle_box1,
723 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
724 self->priv->preview_rectangle2 =
725 empathy_call_window_create_preview_rectangle (self,
726 &self->priv->preview_rectangle_box2,
727 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
728 self->priv->preview_rectangle3 =
729 empathy_call_window_create_preview_rectangle (self,
730 &self->priv->preview_rectangle_box3,
731 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
732 self->priv->preview_rectangle4 =
733 empathy_call_window_create_preview_rectangle (self,
734 &self->priv->preview_rectangle_box4,
735 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
739 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
742 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
743 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
744 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
745 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
749 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
754 guint ret_x = 0, ret_y = 0;
757 if (!clutter_actor_has_allocation (self->priv->video_box))
760 clutter_actor_get_geometry (self->priv->video_box, &box);
764 case PREVIEW_POS_TOP_LEFT:
765 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
767 case PREVIEW_POS_TOP_RIGHT:
768 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
769 - SELF_VIDEO_SECTION_WIDTH;
770 ret_y = SELF_VIDEO_SECTION_MARGIN;
772 case PREVIEW_POS_BOTTOM_LEFT:
773 ret_x = SELF_VIDEO_SECTION_MARGIN;
774 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
775 - SELF_VIDEO_SECTION_HEIGHT
776 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
778 case PREVIEW_POS_BOTTOM_RIGHT:
779 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
780 - SELF_VIDEO_SECTION_WIDTH;
781 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
782 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
783 - FLOATING_TOOLBAR_SPACING;
786 g_warn_if_reached ();
797 static PreviewPosition
798 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
803 PreviewPosition pos = PREVIEW_POS_NONE;
805 if (!clutter_actor_has_allocation (self->priv->video_box))
808 clutter_actor_get_geometry (self->priv->video_box, &box);
810 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
811 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
812 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
813 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
815 pos = PREVIEW_POS_TOP_LEFT;
817 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
818 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
819 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
820 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
822 pos = PREVIEW_POS_TOP_RIGHT;
824 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
825 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
826 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
827 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
829 pos = PREVIEW_POS_BOTTOM_LEFT;
831 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
832 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
833 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
834 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
836 pos = PREVIEW_POS_BOTTOM_RIGHT;
842 static ClutterActor *
843 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
846 ClutterActor *rectangle;
850 case PREVIEW_POS_TOP_LEFT:
851 rectangle = self->priv->preview_rectangle1;
853 case PREVIEW_POS_TOP_RIGHT:
854 rectangle = self->priv->preview_rectangle3;
856 case PREVIEW_POS_BOTTOM_LEFT:
857 rectangle = self->priv->preview_rectangle2;
859 case PREVIEW_POS_BOTTOM_RIGHT:
860 rectangle = self->priv->preview_rectangle4;
870 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
873 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
875 DEBUG ("moving the video preview to %d", pos);
877 self->priv->preview_pos = pos;
881 case PREVIEW_POS_TOP_LEFT:
882 clutter_bin_layout_set_alignment (layout,
883 self->priv->video_preview,
884 CLUTTER_BIN_ALIGNMENT_START,
885 CLUTTER_BIN_ALIGNMENT_START);
887 case PREVIEW_POS_TOP_RIGHT:
888 clutter_bin_layout_set_alignment (layout,
889 self->priv->video_preview,
890 CLUTTER_BIN_ALIGNMENT_END,
891 CLUTTER_BIN_ALIGNMENT_START);
893 case PREVIEW_POS_BOTTOM_LEFT:
894 clutter_bin_layout_set_alignment (layout,
895 self->priv->video_preview,
896 CLUTTER_BIN_ALIGNMENT_START,
897 CLUTTER_BIN_ALIGNMENT_END);
899 case PREVIEW_POS_BOTTOM_RIGHT:
900 clutter_bin_layout_set_alignment (layout,
901 self->priv->video_preview,
902 CLUTTER_BIN_ALIGNMENT_END,
903 CLUTTER_BIN_ALIGNMENT_END);
906 g_warn_if_reached ();
909 g_settings_set_enum (self->priv->settings, "camera-position", pos);
913 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
916 ClutterActor *rectangle;
918 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
920 empathy_rounded_rectangle_set_border_width (
921 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
922 empathy_rounded_rectangle_set_border_color (
923 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
927 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
928 ClutterActor *rectangle)
930 empathy_rounded_rectangle_set_border_width (
931 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
932 empathy_rounded_rectangle_set_border_color (
933 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
937 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
939 ClutterActor *rectangle;
941 rectangle = empathy_call_window_get_preview_rectangle (self,
942 self->priv->preview_pos);
944 /* We don't want to darken the rectangle where the preview
947 if (self->priv->preview_rectangle1 != rectangle)
948 empathy_call_window_darken_preview_rectangle (self,
949 self->priv->preview_rectangle1);
951 if (self->priv->preview_rectangle2 != rectangle)
952 empathy_call_window_darken_preview_rectangle (self,
953 self->priv->preview_rectangle2);
955 if (self->priv->preview_rectangle3 != rectangle)
956 empathy_call_window_darken_preview_rectangle (self,
957 self->priv->preview_rectangle3);
959 if (self->priv->preview_rectangle4 != rectangle)
960 empathy_call_window_darken_preview_rectangle (self,
961 self->priv->preview_rectangle4);
965 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
969 ClutterModifierType modifiers,
970 EmpathyCallWindow *self)
972 ClutterActor *stage = clutter_actor_get_stage (actor);
975 self->priv->drag_preview = clutter_clone_new (actor);
977 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
978 self->priv->drag_preview);
980 clutter_actor_transform_stage_point (actor, event_x, event_y,
983 clutter_actor_set_position (self->priv->drag_preview,
984 event_x - rel_x, event_y - rel_y);
986 clutter_drag_action_set_drag_handle (action,
987 self->priv->drag_preview);
989 clutter_actor_set_opacity (actor, 0);
990 clutter_actor_hide (self->priv->preview_shown_button);
992 empathy_call_window_show_preview_rectangles (self, TRUE);
993 empathy_call_window_darken_preview_rectangles (self);
997 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
1000 clutter_actor_set_opacity (actor, 255);
1004 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
1005 ClutterActor *actor,
1008 ClutterModifierType modifiers,
1009 EmpathyCallWindow *self)
1011 PreviewPosition pos;
1014 /* Get the position before destroying the drag actor, otherwise the
1015 * preview_box allocation won't be valid and we won't be able to
1016 * calculate the position. */
1017 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1019 empathy_call_window_get_preview_coordinates (self,
1020 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1023 /* Move the preview to the destination and destroy it afterwards */
1024 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1027 "signal-swapped-after::completed",
1028 clutter_actor_destroy, self->priv->drag_preview,
1029 "signal-swapped-after::completed",
1030 clutter_actor_show, self->priv->preview_shown_button,
1031 "signal::completed",
1032 empathy_call_window_on_animation_completed_cb, actor,
1035 self->priv->drag_preview = NULL;
1037 if (pos != PREVIEW_POS_NONE)
1038 empathy_call_window_move_video_preview (self, pos);
1040 empathy_call_window_show_preview_rectangles (self, FALSE);
1044 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1045 ClutterActor *actor,
1048 EmpathyCallWindow *self)
1050 PreviewPosition pos;
1051 gfloat event_x, event_y;
1053 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1055 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1057 if (pos != PREVIEW_POS_NONE)
1058 empathy_call_window_highlight_preview_rectangle (self, pos);
1060 empathy_call_window_darken_preview_rectangles (self);
1064 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1065 ClutterCrossingEvent *event,
1066 EmpathyCallWindow *self)
1068 ClutterActor *rectangle;
1070 rectangle = empathy_call_window_get_preview_rectangle (self,
1071 self->priv->preview_pos);
1073 empathy_call_window_highlight_preview_rectangle (self,
1074 self->priv->preview_pos);
1076 clutter_actor_show (rectangle);
1082 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1083 ClutterCrossingEvent *event,
1084 EmpathyCallWindow *self)
1086 ClutterActor *rectangle;
1088 rectangle = empathy_call_window_get_preview_rectangle (self,
1089 self->priv->preview_pos);
1091 empathy_call_window_darken_preview_rectangle (self, rectangle);
1093 clutter_actor_hide (rectangle);
1099 create_video_preview (EmpathyCallWindow *self)
1101 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1102 ClutterLayoutManager *layout, *layout_center, *layout_end;
1103 ClutterActor *preview;
1106 ClutterAction *action;
1108 PreviewPosition pos;
1109 GdkRGBA transparent = { 0., 0., 0., 0. };
1111 g_assert (priv->video_preview == NULL);
1113 pos = g_settings_get_enum (priv->settings, "camera-position");
1115 preview = empathy_rounded_texture_new ();
1116 clutter_actor_set_size (preview,
1117 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1118 priv->video_preview_sink = clutter_gst_video_sink_new (
1119 CLUTTER_TEXTURE (preview));
1121 /* Add a little offset to the video preview */
1122 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1123 CLUTTER_BIN_ALIGNMENT_START);
1124 priv->video_preview = clutter_box_new (layout);
1125 clutter_actor_set_size (priv->video_preview,
1126 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1127 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1128 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1130 /* Spinner for when changing the camera device */
1131 priv->preview_spinner_widget = gtk_spinner_new ();
1132 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1133 empathy_rounded_actor_set_round_factor (
1134 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1136 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1137 gtk_widget_override_background_color (
1138 gtk_clutter_actor_get_widget (
1139 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1140 GTK_STATE_FLAG_NORMAL, &transparent);
1141 gtk_widget_show (priv->preview_spinner_widget);
1144 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1145 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1146 priv->preview_spinner_widget);
1147 clutter_actor_set_size (priv->preview_spinner_actor,
1148 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1149 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1150 clutter_actor_hide (priv->preview_spinner_actor);
1152 /* We have a box with the margins and the video in the middle inside
1153 * a bigger box with an extra bottom margin so we're not on top of
1154 * the floating toolbar. */
1155 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1156 CLUTTER_BIN_ALIGNMENT_CENTER);
1157 box = clutter_box_new (layout_center);
1158 clutter_actor_set_size (box,
1159 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1160 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1162 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1163 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1164 priv->preview_spinner_actor);
1165 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1167 g_object_set (priv->video_preview_sink,
1172 /* Translators: this is an "Info" label. It should be as short
1174 button = gtk_button_new_with_label (_("i"));
1175 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1177 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1179 clutter_actor_set_size (b, 24, 24);
1181 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1182 CLUTTER_BIN_ALIGNMENT_END);
1183 box = clutter_box_new (layout_end);
1184 clutter_actor_set_size (box,
1185 SELF_VIDEO_SECTION_WIDTH,
1186 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1188 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1189 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1191 g_signal_connect (button, "clicked",
1192 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1195 /* Translators: this is an "Info" label. It should be as short
1197 button = gtk_button_new_with_label (_("i"));
1198 b = empathy_rounded_actor_new ();
1200 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1202 clutter_actor_set_size (b, 24, 24);
1203 priv->preview_hidden_button = b;
1205 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1206 priv->preview_hidden_button,
1207 CLUTTER_BIN_ALIGNMENT_START,
1208 CLUTTER_BIN_ALIGNMENT_END);
1210 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1212 clutter_actor_hide (priv->preview_hidden_button);
1214 g_signal_connect (button, "clicked",
1215 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1218 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1219 priv->video_preview,
1220 CLUTTER_BIN_ALIGNMENT_START,
1221 CLUTTER_BIN_ALIGNMENT_END);
1223 empathy_call_window_move_video_preview (self, pos);
1225 action = clutter_drag_action_new ();
1226 g_signal_connect (action, "drag-begin",
1227 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1228 g_signal_connect (action, "drag-end",
1229 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1230 g_signal_connect (action, "drag-motion",
1231 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1233 g_signal_connect (preview, "enter-event",
1234 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1235 g_signal_connect (preview, "leave-event",
1236 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1238 clutter_actor_add_action (preview, action);
1239 clutter_actor_set_reactive (preview, TRUE);
1240 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1244 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1246 clutter_actor_show (self->priv->preview_spinner_actor);
1247 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1251 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1253 clutter_actor_hide (self->priv->preview_spinner_actor);
1254 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1258 empathy_call_window_play_camera (EmpathyCallWindow *self,
1261 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1262 GstElement *preview;
1265 if (priv->video_preview == NULL)
1267 create_video_preview (self);
1268 add_video_preview_to_pipeline (self);
1273 state = GST_STATE_PLAYING;
1277 empathy_call_window_start_camera_spinning (self);
1278 state = GST_STATE_NULL;
1281 preview = priv->video_preview_sink;
1283 gst_element_set_state (preview, state);
1284 gst_element_set_state (priv->video_tee, state);
1285 gst_element_set_state (priv->video_input, state);
1289 display_video_preview (EmpathyCallWindow *self,
1292 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1294 if (priv->video_preview == NULL)
1296 create_video_preview (self);
1297 add_video_preview_to_pipeline (self);
1302 /* Display the video preview */
1303 DEBUG ("Show video preview");
1305 empathy_call_window_play_camera (self, TRUE);
1306 clutter_actor_show (priv->video_preview);
1307 clutter_actor_raise_top (priv->floating_toolbar);
1311 /* Hide the video preview */
1312 DEBUG ("Hide video preview");
1314 if (priv->video_preview != NULL)
1316 clutter_actor_hide (priv->video_preview);
1317 empathy_call_window_play_camera (self, FALSE);
1323 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1325 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1327 empathy_call_window_status_message (window, _("Connecting…"));
1328 priv->call_state = CONNECTING;
1330 /* Show the toolbar */
1331 clutter_state_set_state (priv->transitions, "fade-in");
1334 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1335 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1339 disable_camera (EmpathyCallWindow *self)
1341 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1343 if (priv->camera_state == CAMERA_STATE_OFF)
1346 DEBUG ("Disable camera");
1348 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1350 priv->camera_state = CAMERA_STATE_OFF;
1354 enable_camera (EmpathyCallWindow *self)
1356 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1358 if (priv->camera_state == CAMERA_STATE_ON)
1361 if (priv->video_input == NULL)
1363 DEBUG ("Can't enable camera, no input");
1367 DEBUG ("Enable camera");
1369 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1371 priv->camera_state = CAMERA_STATE_ON;
1375 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1376 EmpathyCallWindow *self)
1378 if (gtk_toggle_tool_button_get_active (toggle))
1379 enable_camera (self);
1381 disable_camera (self);
1385 create_pipeline (EmpathyCallWindow *self)
1387 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1390 g_assert (priv->pipeline == NULL);
1392 priv->pipeline = gst_pipeline_new (NULL);
1393 priv->pipeline_playing = FALSE;
1395 priv->video_tee = gst_element_factory_make ("tee", NULL);
1396 gst_object_ref (priv->video_tee);
1397 gst_object_sink (priv->video_tee);
1399 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1401 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1402 priv->bus_message_source_id = gst_bus_add_watch (bus,
1403 empathy_call_window_bus_message, self);
1405 g_object_unref (bus);
1409 empathy_call_window_settings_cb (GtkAction *action,
1410 EmpathyCallWindow *self)
1412 gchar *args = g_strdup_printf ("-p %s",
1413 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1415 empathy_launch_program (BIN_DIR, "empathy", args);
1421 empathy_call_window_contents_cb (GtkAction *action,
1422 EmpathyCallWindow *self)
1424 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1428 empathy_call_window_debug_cb (GtkAction *action,
1429 EmpathyCallWindow *self)
1431 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1435 empathy_call_window_about_cb (GtkAction *action,
1436 EmpathyCallWindow *self)
1438 empathy_about_dialog_new (GTK_WINDOW (self));
1442 empathy_call_window_toolbar_timeout (gpointer data)
1444 EmpathyCallWindow *self = data;
1446 /* We don't want to hide the toolbar if we're not in a call, as
1447 * to show the call status all the time. */
1448 if (self->priv->call_state != CONNECTING &&
1449 self->priv->call_state != DISCONNECTED)
1450 clutter_state_set_state (self->priv->transitions, "fade-out");
1456 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1458 EmpathyCallWindow *self)
1460 clutter_state_set_state (self->priv->transitions, "fade-in");
1462 if (self->priv->inactivity_src > 0)
1463 g_source_remove (self->priv->inactivity_src);
1465 self->priv->inactivity_src = g_timeout_add_seconds (3,
1466 empathy_call_window_toolbar_timeout, self);
1472 empathy_call_window_configure_event_cb (GtkWidget *widget,
1474 EmpathyCallWindow *self)
1476 GdkWindow *gdk_window;
1477 GdkWindowState window_state;
1479 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1480 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1482 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1483 &self->priv->dialpad_width, NULL);
1485 gdk_window = gtk_widget_get_window (widget);
1486 window_state = gdk_window_get_state (gdk_window);
1487 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1493 empathy_call_window_destroyed_cb (GtkWidget *object,
1494 EmpathyCallWindow *self)
1496 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1498 /* Save the geometry as if the dialpad was hidden. */
1499 empathy_geometry_save_values (GTK_WINDOW (self),
1500 self->priv->x, self->priv->y,
1501 self->priv->w - self->priv->dialpad_width, self->priv->h,
1502 self->priv->maximized);
1507 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1509 ClutterBindConstraint *constraint)
1511 ClutterActorBox allocation;
1513 clutter_actor_get_allocation_box (stage, &allocation);
1515 clutter_bind_constraint_set_offset (constraint,
1516 allocation.y2 - allocation.y1 -
1517 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1521 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1523 EmpathyCallWindow *self)
1525 switch (response_id)
1527 case GTK_RESPONSE_ACCEPT:
1528 tp_channel_dispatch_operation_handle_with_async (
1529 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1531 tp_clear_object (&self->priv->pending_cdo);
1532 tp_clear_object (&self->priv->pending_channel);
1533 tp_clear_object (&self->priv->pending_context);
1536 case GTK_RESPONSE_CANCEL:
1537 tp_channel_dispatch_operation_close_channels_async (
1538 self->priv->pending_cdo, NULL, NULL);
1540 empathy_call_window_status_message (self, _("Disconnected"));
1541 self->priv->call_state = DISCONNECTED;
1544 g_warn_if_reached ();
1549 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1553 g_assert (self->priv->call_state != CONNECTED);
1555 video = tpy_call_channel_has_initial_video (self->priv->pending_channel);
1557 empathy_call_window_status_message (self, _("Incoming call"));
1558 self->priv->call_state = RINGING;
1560 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1561 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1562 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1563 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1564 empathy_contact_get_alias (self->priv->contact));
1566 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1567 _("Reject"), GTK_RESPONSE_CANCEL,
1568 _("Answer"), GTK_RESPONSE_ACCEPT,
1571 g_signal_connect (self->priv->incoming_call_dialog, "response",
1572 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1573 gtk_widget_show (self->priv->incoming_call_dialog);
1577 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1581 EmpathyCallWindow *self)
1583 tp_clear_object (&self->priv->pending_cdo);
1584 tp_clear_object (&self->priv->pending_channel);
1585 tp_clear_object (&self->priv->pending_context);
1587 /* We don't know if the incoming call has been accepted or not, so we
1588 * assume it hasn't and if it has, we'll set the proper status when
1589 * we get the new handler. */
1590 empathy_call_window_status_message (self, _("Disconnected"));
1591 self->priv->call_state = DISCONNECTED;
1593 gtk_widget_destroy (self->priv->incoming_call_dialog);
1594 self->priv->incoming_call_dialog = NULL;
1598 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1599 TpyCallChannel *channel,
1600 TpChannelDispatchOperation *dispatch_operation,
1601 TpAddDispatchOperationContext *context)
1603 g_assert (self->priv->pending_channel == NULL);
1604 g_assert (self->priv->pending_context == NULL);
1605 g_assert (self->priv->pending_cdo == NULL);
1607 /* Start ringing and delay until the user answers or hangs. */
1608 self->priv->pending_channel = g_object_ref (channel);
1609 self->priv->pending_context = g_object_ref (context);
1610 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1612 g_signal_connect (self->priv->pending_cdo, "invalidated",
1613 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1615 empathy_call_window_set_state_ringing (self);
1616 tp_add_dispatch_operation_context_accept (context);
1620 empathy_call_window_init (EmpathyCallWindow *self)
1622 EmpathyCallWindowPriv *priv;
1624 GtkWidget *top_vbox;
1626 ClutterConstraint *constraint;
1627 ClutterActor *remote_avatar;
1628 GtkStyleContext *context;
1632 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1633 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1635 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1637 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1638 gui = empathy_builder_get_file (filename,
1639 "call_window_vbox", &top_vbox,
1640 "errors_vbox", &priv->errors_vbox,
1641 "pane", &priv->pane,
1642 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1643 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1644 "status_label", &priv->status_label,
1645 "audiocall", &priv->audio_call_button,
1646 "videocall", &priv->video_call_button,
1647 "microphone", &priv->mic_button,
1648 "camera", &priv->camera_button,
1649 "hangup", &priv->hangup_button,
1650 "dialpad", &priv->dialpad_button,
1651 "toolbar", &priv->toolbar,
1652 "bottom_toolbar", &priv->bottom_toolbar,
1653 "ui_manager", &priv->ui_manager,
1654 "menufullscreen", &priv->menu_fullscreen,
1655 "menupreviewswap", &priv->menu_swap_camera,
1656 "details_vbox", &priv->details_vbox,
1657 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1658 "acodec_encoding_label", &priv->acodec_encoding_label,
1659 "acodec_decoding_label", &priv->acodec_decoding_label,
1660 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1661 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1662 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1663 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1664 "video_local_candidate_label", &priv->video_local_candidate_label,
1665 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1666 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1667 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1668 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1672 empathy_builder_connect (gui, self,
1673 "hangup", "clicked", empathy_call_window_hangup_cb,
1674 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1675 "videocall", "clicked", empathy_call_window_video_call_cb,
1676 "volume", "value-changed", empathy_call_window_volume_changed_cb,
1677 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1678 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1679 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1680 "menusettings", "activate", empathy_call_window_settings_cb,
1681 "menucontents", "activate", empathy_call_window_contents_cb,
1682 "menudebug", "activate", empathy_call_window_debug_cb,
1683 "menuabout", "activate", empathy_call_window_about_cb,
1684 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1685 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1686 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1687 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1690 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1692 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1694 g_object_bind_property (priv->camera_monitor, "available",
1695 priv->camera_button, "sensitive",
1696 G_BINDING_SYNC_CREATE);
1698 g_signal_connect (priv->camera_monitor, "added",
1699 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1700 g_signal_connect (priv->camera_monitor, "removed",
1701 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1703 priv->lock = g_mutex_new ();
1705 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1707 priv->content_hbox = gtk_hbox_new (FALSE, CONTENT_HBOX_SPACING);
1708 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1709 CONTENT_HBOX_BORDER_WIDTH);
1710 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1713 /* avatar/video box */
1714 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1715 CLUTTER_BIN_ALIGNMENT_CENTER);
1717 priv->video_box = clutter_box_new (priv->video_layout);
1719 priv->video_container = gtk_clutter_embed_new ();
1721 /* Set the background color to that of the rest of the window */
1722 context = gtk_widget_get_style_context (priv->content_hbox);
1723 gtk_style_context_get_background_color (context,
1724 GTK_STATE_FLAG_NORMAL, &rgba);
1725 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1726 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1727 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1728 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1729 clutter_stage_set_color (
1730 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1731 GTK_CLUTTER_EMBED (priv->video_container))),
1734 clutter_container_add (
1735 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1736 GTK_CLUTTER_EMBED (priv->video_container))),
1740 constraint = clutter_bind_constraint_new (
1741 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1742 CLUTTER_BIND_SIZE, 0);
1743 clutter_actor_add_constraint (priv->video_box, constraint);
1745 priv->remote_user_avatar_widget = gtk_image_new ();
1746 remote_avatar = gtk_clutter_actor_new_with_contents (
1747 priv->remote_user_avatar_widget);
1749 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1752 empathy_call_window_create_preview_rectangles (self);
1754 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1755 priv->video_container, TRUE, TRUE,
1756 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1758 create_pipeline (self);
1759 create_video_output_widget (self);
1760 create_audio_input (self);
1761 create_video_input (self);
1763 priv->floating_toolbar = empathy_rounded_actor_new ();
1765 gtk_widget_reparent (priv->bottom_toolbar,
1766 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1768 constraint = clutter_bind_constraint_new (
1769 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1772 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1775 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1776 "notify::allocation",
1777 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1780 clutter_actor_set_size (priv->floating_toolbar,
1781 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1782 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1784 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1785 priv->floating_toolbar,
1786 CLUTTER_BIN_ALIGNMENT_CENTER,
1787 CLUTTER_BIN_ALIGNMENT_END);
1789 clutter_actor_raise_top (priv->floating_toolbar);
1791 /* Transitions for the floating toolbar */
1792 priv->transitions = clutter_state_new ();
1794 /* all transitions last for 2s */
1795 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1797 /* transition from any state to "fade-out" state */
1798 clutter_state_set (priv->transitions, NULL, "fade-out",
1799 priv->floating_toolbar,
1800 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1803 /* transition from any state to "fade-in" state */
1804 clutter_state_set (priv->transitions, NULL, "fade-in",
1805 priv->floating_toolbar,
1806 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1809 /* put the actor into the "fade-in" state with no animation */
1810 clutter_state_warp_to_state (priv->transitions, "fade-in");
1812 /* The call will be started as soon the pipeline is playing */
1813 priv->start_call_when_playing = TRUE;
1815 priv->dtmf_panel = empathy_dialpad_widget_new ();
1816 g_signal_connect (priv->dtmf_panel, "start-tone",
1817 G_CALLBACK (dtmf_start_tone_cb), self);
1819 priv->tones = g_string_new ("");
1821 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1824 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1827 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1829 gtk_widget_show_all (top_vbox);
1831 gtk_widget_hide (priv->dtmf_panel);
1832 gtk_widget_hide (priv->details_vbox);
1834 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1836 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1837 priv->video_container);
1839 /* We hide the bottom toolbar after 3s of inactivity and show it
1840 * again on mouse movement */
1841 priv->inactivity_src = g_timeout_add_seconds (3,
1842 empathy_call_window_toolbar_timeout, self);
1844 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1845 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1847 g_signal_connect (G_OBJECT (self), "realize",
1848 G_CALLBACK (empathy_call_window_realized_cb), self);
1850 g_signal_connect (G_OBJECT (self), "delete-event",
1851 G_CALLBACK (empathy_call_window_delete_cb), self);
1853 g_signal_connect (G_OBJECT (self), "window-state-event",
1854 G_CALLBACK (empathy_call_window_state_event_cb), self);
1856 g_signal_connect (G_OBJECT (self), "key-press-event",
1857 G_CALLBACK (empathy_call_window_key_press_cb), self);
1859 g_signal_connect (self, "motion-notify-event",
1860 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1862 priv->timer = g_timer_new ();
1864 g_object_ref (priv->ui_manager);
1865 g_object_unref (gui);
1867 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1868 priv->mic_menu = empathy_mic_menu_new (self);
1869 priv->camera_menu = empathy_camera_menu_new (self);
1871 empathy_call_window_show_hangup_button (self, TRUE);
1873 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1874 /* These signals are used to track the window position and save it
1875 * when the window is destroyed. We need to do this as we don't want
1876 * the window geometry to be saved with the dialpad taken into account. */
1877 g_signal_connect (self, "destroy",
1878 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1879 g_signal_connect (self, "configure-event",
1880 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1881 g_signal_connect (self, "window-state-event",
1882 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1884 /* Don't display labels in both toolbars */
1885 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1888 /* Instead of specifying a width and a height, we specify only one size. That's
1889 because we want a square avatar icon. */
1891 init_contact_avatar_with_size (EmpathyContact *contact,
1892 GtkWidget *image_widget,
1895 GdkPixbuf *pixbuf_avatar = NULL;
1897 if (contact != NULL)
1899 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1903 if (pixbuf_avatar == NULL)
1905 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1906 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1909 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1911 if (pixbuf_avatar != NULL)
1912 g_object_unref (pixbuf_avatar);
1916 set_window_title (EmpathyCallWindow *self)
1918 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1921 if (priv->contact != NULL)
1923 /* translators: Call is a noun and %s is the contact name. This string
1924 * is used in the window title */
1925 tmp = g_strdup_printf (_("Call with %s"),
1926 empathy_contact_get_alias (priv->contact));
1927 gtk_window_set_title (GTK_WINDOW (self), tmp);
1932 g_warning ("Unknown remote contact!");
1937 set_remote_user_name (EmpathyCallWindow *self,
1938 EmpathyContact *contact)
1940 const gchar *alias = empathy_contact_get_alias (contact);
1941 const gchar *status = empathy_contact_get_status (contact);
1944 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1945 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1951 contact_name_changed_cb (EmpathyContact *contact,
1953 EmpathyCallWindow *self)
1955 set_window_title (self);
1956 set_remote_user_name (self, contact);
1960 contact_presence_changed_cb (EmpathyContact *contact,
1962 EmpathyCallWindow *self)
1964 set_remote_user_name (self, contact);
1968 contact_avatar_changed_cb (EmpathyContact *contact,
1970 EmpathyCallWindow *self)
1973 GtkAllocation allocation;
1974 GtkWidget *avatar_widget;
1976 avatar_widget = self->priv->remote_user_avatar_widget;
1978 gtk_widget_get_allocation (avatar_widget, &allocation);
1979 size = allocation.height;
1983 /* the widget is not allocated yet, set a default size */
1984 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1985 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1988 init_contact_avatar_with_size (contact, avatar_widget, size);
1990 avatar_widget = self->priv->remote_user_avatar_toolbar;
1992 gtk_widget_get_allocation (avatar_widget, &allocation);
1993 size = allocation.height;
1997 /* the widget is not allocated yet, set a default size */
1998 size = SMALL_TOOLBAR_SIZE;
2001 init_contact_avatar_with_size (contact, avatar_widget, size);
2005 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2006 EmpathyCallHandler *handler)
2008 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2010 tp_g_signal_connect_object (priv->contact, "notify::name",
2011 G_CALLBACK (contact_name_changed_cb), self, 0);
2012 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2013 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2014 tp_g_signal_connect_object (priv->contact, "notify::presence",
2015 G_CALLBACK (contact_presence_changed_cb), self, 0);
2017 set_window_title (self);
2018 set_remote_user_name (self, priv->contact);
2020 init_contact_avatar_with_size (priv->contact,
2021 priv->remote_user_avatar_widget,
2022 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2023 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2025 init_contact_avatar_with_size (priv->contact,
2026 priv->remote_user_avatar_toolbar,
2027 SMALL_TOOLBAR_SIZE);
2029 /* The remote avatar is shown by default and will be hidden when we receive
2030 video from the remote side. */
2031 clutter_actor_hide (priv->video_output);
2032 gtk_widget_show (priv->remote_user_avatar_widget);
2036 update_send_codec (EmpathyCallWindow *self,
2039 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2046 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2047 widget = priv->acodec_encoding_label;
2051 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2052 widget = priv->vcodec_encoding_label;
2058 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2059 gtk_label_set_text (GTK_LABEL (widget), tmp);
2064 send_audio_codec_notify_cb (GObject *object,
2068 EmpathyCallWindow *self = user_data;
2070 update_send_codec (self, TRUE);
2074 send_video_codec_notify_cb (GObject *object,
2078 EmpathyCallWindow *self = user_data;
2080 update_send_codec (self, FALSE);
2084 update_recv_codec (EmpathyCallWindow *self,
2087 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2090 GString *str = NULL;
2094 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2095 widget = priv->acodec_decoding_label;
2099 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2100 widget = priv->vcodec_decoding_label;
2106 for (l = codecs; l != NULL; l = g_list_next (l))
2108 FsCodec *codec = l->data;
2111 str = g_string_new (NULL);
2113 g_string_append (str, ", ");
2115 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2119 gtk_label_set_text (GTK_LABEL (widget), str->str);
2120 g_string_free (str, TRUE);
2124 recv_audio_codecs_notify_cb (GObject *object,
2128 EmpathyCallWindow *self = user_data;
2130 update_recv_codec (self, TRUE);
2134 recv_video_codecs_notify_cb (GObject *object,
2138 EmpathyCallWindow *self = user_data;
2140 update_recv_codec (self, FALSE);
2143 static const gchar *
2144 candidate_type_to_str (FsCandidate *candidate)
2146 switch (candidate->type)
2148 case FS_CANDIDATE_TYPE_HOST:
2150 case FS_CANDIDATE_TYPE_SRFLX:
2151 return "server reflexive";
2152 case FS_CANDIDATE_TYPE_PRFLX:
2153 return "peer reflexive";
2154 case FS_CANDIDATE_TYPE_RELAY:
2156 case FS_CANDIDATE_TYPE_MULTICAST:
2163 static const gchar *
2164 candidate_type_to_desc (FsCandidate *candidate)
2166 switch (candidate->type)
2168 case FS_CANDIDATE_TYPE_HOST:
2169 return _("The IP address as seen by the machine");
2170 case FS_CANDIDATE_TYPE_SRFLX:
2171 return _("The IP address as seen by a server on the Internet");
2172 case FS_CANDIDATE_TYPE_PRFLX:
2173 return _("The IP address of the peer as seen by the other side");
2174 case FS_CANDIDATE_TYPE_RELAY:
2175 return _("The IP address of a relay server");
2176 case FS_CANDIDATE_TYPE_MULTICAST:
2177 return _("The IP address of the multicast group");
2184 update_candidat_widget (EmpathyCallWindow *self,
2187 FsCandidate *candidate)
2191 g_assert (candidate != NULL);
2192 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2193 candidate->port, candidate_type_to_str (candidate));
2195 gtk_label_set_text (GTK_LABEL (label), str);
2196 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2202 candidates_changed_cb (GObject *object,
2204 EmpathyCallWindow *self)
2206 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2207 FsCandidate *candidate = NULL;
2209 if (type == FS_MEDIA_TYPE_VIDEO)
2211 /* Update remote candidate */
2212 candidate = empathy_call_handler_get_video_remote_candidate (
2215 update_candidat_widget (self, priv->video_remote_candidate_label,
2216 priv->video_remote_candidate_info_img, candidate);
2218 /* Update local candidate */
2219 candidate = empathy_call_handler_get_video_local_candidate (
2222 update_candidat_widget (self, priv->video_local_candidate_label,
2223 priv->video_local_candidate_info_img, candidate);
2227 /* Update remote candidate */
2228 candidate = empathy_call_handler_get_audio_remote_candidate (
2231 update_candidat_widget (self, priv->audio_remote_candidate_label,
2232 priv->audio_remote_candidate_info_img, candidate);
2234 /* Update local candidate */
2235 candidate = empathy_call_handler_get_audio_local_candidate (
2238 update_candidat_widget (self, priv->audio_local_candidate_label,
2239 priv->audio_local_candidate_info_img, candidate);
2244 empathy_call_window_constructed (GObject *object)
2246 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2247 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2248 TpyCallChannel *call;
2251 g_assert (priv->handler != NULL);
2253 g_object_get (priv->handler, "call-channel", &call, NULL);
2254 state = tpy_call_channel_get_state (call, NULL, NULL);
2255 priv->outgoing = (state == TPY_CALL_STATE_PENDING_INITIATOR);
2256 tp_clear_object (&call);
2258 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2259 g_assert (priv->contact != NULL);
2261 if (!empathy_contact_can_voip_video (priv->contact))
2263 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2264 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2267 empathy_call_window_setup_avatars (self, priv->handler);
2268 empathy_call_window_set_state_connecting (self);
2270 if (!empathy_call_handler_has_initial_video (priv->handler))
2272 gtk_toggle_tool_button_set_active (
2273 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2275 /* If call has InitialVideo, the preview will be started once the call has
2276 * been started (start_call()). */
2278 update_send_codec (self, TRUE);
2279 update_send_codec (self, FALSE);
2280 update_recv_codec (self, TRUE);
2281 update_recv_codec (self, FALSE);
2283 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2284 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2285 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2286 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2287 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2288 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2289 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2290 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2292 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2293 G_CALLBACK (candidates_changed_cb), self, 0);
2296 static void empathy_call_window_dispose (GObject *object);
2297 static void empathy_call_window_finalize (GObject *object);
2300 empathy_call_window_set_property (GObject *object,
2301 guint property_id, const GValue *value, GParamSpec *pspec)
2303 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2305 switch (property_id)
2307 case PROP_CALL_HANDLER:
2308 priv->handler = g_value_dup_object (value);
2311 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2316 empathy_call_window_get_property (GObject *object,
2317 guint property_id, GValue *value, GParamSpec *pspec)
2319 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2321 switch (property_id)
2323 case PROP_CALL_HANDLER:
2324 g_value_set_object (value, priv->handler);
2327 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2332 empathy_call_window_class_init (
2333 EmpathyCallWindowClass *empathy_call_window_class)
2335 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2336 GParamSpec *param_spec;
2338 g_type_class_add_private (empathy_call_window_class,
2339 sizeof (EmpathyCallWindowPriv));
2341 object_class->constructed = empathy_call_window_constructed;
2342 object_class->set_property = empathy_call_window_set_property;
2343 object_class->get_property = empathy_call_window_get_property;
2345 object_class->dispose = empathy_call_window_dispose;
2346 object_class->finalize = empathy_call_window_finalize;
2348 param_spec = g_param_spec_object ("handler",
2349 "handler", "The call handler",
2350 EMPATHY_TYPE_CALL_HANDLER,
2351 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2352 g_object_class_install_property (object_class,
2353 PROP_CALL_HANDLER, param_spec);
2357 empathy_call_window_dispose (GObject *object)
2359 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2360 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2362 if (priv->dispose_has_run)
2365 priv->dispose_has_run = TRUE;
2367 if (priv->handler != NULL)
2369 empathy_call_handler_stop_call (priv->handler);
2370 tp_clear_object (&priv->handler);
2373 if (priv->bus_message_source_id != 0)
2375 g_source_remove (priv->bus_message_source_id);
2376 priv->bus_message_source_id = 0;
2379 if (priv->got_video_src > 0)
2381 g_source_remove (priv->got_video_src);
2382 priv->got_video_src = 0;
2385 if (priv->inactivity_src > 0)
2387 g_source_remove (priv->inactivity_src);
2388 priv->inactivity_src = 0;
2391 tp_clear_object (&priv->pipeline);
2392 tp_clear_object (&priv->video_input);
2393 tp_clear_object (&priv->audio_input);
2394 tp_clear_object (&priv->video_tee);
2395 tp_clear_object (&priv->ui_manager);
2396 tp_clear_object (&priv->fullscreen);
2397 tp_clear_object (&priv->camera_monitor);
2398 tp_clear_object (&priv->settings);
2399 tp_clear_object (&priv->sound_mgr);
2400 tp_clear_object (&priv->mic_menu);
2401 tp_clear_object (&priv->camera_menu);
2403 g_list_free_full (priv->notifiers, g_object_unref);
2405 if (priv->timer_id != 0)
2406 g_source_remove (priv->timer_id);
2409 if (priv->contact != NULL)
2411 g_signal_handlers_disconnect_by_func (priv->contact,
2412 contact_name_changed_cb, self);
2413 priv->contact = NULL;
2416 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2420 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2422 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2424 if (priv->video_output_motion_handler_id != 0)
2426 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2427 priv->video_output_motion_handler_id);
2428 priv->video_output_motion_handler_id = 0;
2433 empathy_call_window_finalize (GObject *object)
2435 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2436 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2438 disconnect_video_output_motion_handler (self);
2440 /* free any data held directly by the object here */
2441 g_mutex_free (priv->lock);
2443 g_timer_destroy (priv->timer);
2445 g_string_free (priv->tones, TRUE);
2447 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2452 empathy_call_window_new (EmpathyCallHandler *handler)
2454 return EMPATHY_CALL_WINDOW (
2455 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2459 empathy_call_window_present (EmpathyCallWindow *self,
2460 EmpathyCallHandler *handler)
2462 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2464 tp_clear_object (&self->priv->handler);
2465 self->priv->handler = g_object_ref (handler);
2466 empathy_call_window_connect_handler (self);
2468 empathy_window_present (GTK_WINDOW (self));
2469 empathy_call_window_restart_call (self);
2473 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2474 GstElement *conference, gpointer user_data)
2476 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2477 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2478 FsElementAddedNotifier *notifier;
2481 DEBUG ("Conference added");
2483 /* Add notifier to set the various element properties as needed */
2484 notifier = fs_element_added_notifier_new ();
2485 keyfile = fs_utils_get_default_element_properties (conference);
2487 if (keyfile != NULL)
2488 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2490 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2492 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2494 gst_bin_add (GST_BIN (priv->pipeline), conference);
2495 gst_element_set_state (conference, GST_STATE_PLAYING);
2499 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2500 GstElement *conference, gpointer user_data)
2502 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2503 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2505 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2506 gst_element_set_state (conference, GST_STATE_NULL);
2510 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2512 GstStateChangeReturn state_change_return;
2513 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2515 if (priv->pipeline == NULL)
2518 if (priv->bus_message_source_id != 0)
2520 g_source_remove (priv->bus_message_source_id);
2521 priv->bus_message_source_id = 0;
2524 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2526 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2527 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2529 if (priv->pipeline != NULL)
2530 g_object_unref (priv->pipeline);
2531 priv->pipeline = NULL;
2533 if (priv->audio_output != NULL)
2534 g_object_unref (priv->audio_output);
2535 priv->audio_output = NULL;
2537 if (priv->video_tee != NULL)
2538 g_object_unref (priv->video_tee);
2539 priv->video_tee = NULL;
2541 if (priv->video_preview != NULL)
2542 clutter_actor_destroy (priv->video_preview);
2543 priv->video_preview = NULL;
2545 /* If we destroy the preview while it's being dragged, we won't
2546 * get the ::drag-end signal, so manually destroy the clone */
2547 if (priv->drag_preview != NULL)
2549 clutter_actor_destroy (priv->drag_preview);
2550 empathy_call_window_show_preview_rectangles (self, FALSE);
2551 priv->drag_preview = NULL;
2554 priv->funnel = NULL;
2556 create_pipeline (self);
2557 /* Call will be started when user will hit the 'redial' button */
2558 priv->start_call_when_playing = FALSE;
2559 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2565 g_message ("Error: could not destroy pipeline. Closing call window");
2566 gtk_widget_destroy (GTK_WIDGET (self));
2573 reset_details_pane (EmpathyCallWindow *self)
2575 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2577 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2578 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2579 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2580 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2584 empathy_call_window_disconnected (EmpathyCallWindow *self,
2587 gboolean could_disconnect = FALSE;
2588 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2589 gboolean could_reset_pipeline;
2591 /* Leave full screen mode if needed */
2592 gtk_window_unfullscreen (GTK_WINDOW (self));
2594 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2595 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2597 priv->sending_tones = FALSE;
2598 g_string_set_size (priv->tones, 0);
2600 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2602 if (priv->call_state == CONNECTING)
2603 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2605 if (priv->call_state != REDIALING)
2606 priv->call_state = DISCONNECTED;
2608 /* Show the toolbar */
2609 clutter_state_set_state (priv->transitions, "fade-in");
2611 if (could_reset_pipeline)
2613 g_mutex_lock (priv->lock);
2615 g_timer_stop (priv->timer);
2617 if (priv->timer_id != 0)
2618 g_source_remove (priv->timer_id);
2621 g_mutex_unlock (priv->lock);
2624 /* We are about to destroy the window, no need to update it or create
2625 * a video preview */
2628 empathy_call_window_status_message (self, _("Disconnected"));
2630 empathy_call_window_show_hangup_button (self, FALSE);
2632 /* Unsensitive the camera and mic button */
2633 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2634 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2636 /* Be sure that the mic button is enabled */
2637 gtk_toggle_tool_button_set_active (
2638 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2640 if (priv->camera_state == CAMERA_STATE_ON)
2642 /* Restart the preview with the new pipeline. */
2643 display_video_preview (self, TRUE);
2646 /* destroy the video output; it will be recreated when we'll redial */
2647 disconnect_video_output_motion_handler (self);
2648 if (priv->video_output != NULL)
2649 clutter_actor_destroy (priv->video_output);
2650 priv->video_output = NULL;
2651 if (priv->got_video_src > 0)
2653 g_source_remove (priv->got_video_src);
2654 priv->got_video_src = 0;
2657 gtk_widget_show (priv->remote_user_avatar_widget);
2659 reset_details_pane (self);
2661 priv->sending_video = FALSE;
2662 priv->call_started = FALSE;
2664 could_disconnect = TRUE;
2666 /* TODO: display the self avatar of the preview (depends if the "Always
2667 * Show Video Preview" is enabled or not) */
2670 return could_disconnect;
2675 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2678 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2679 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2681 if (empathy_call_window_disconnected (self, TRUE) &&
2682 priv->call_state == REDIALING)
2683 empathy_call_window_restart_call (self);
2687 empathy_call_window_content_is_raw (TfContent *content)
2689 FsConference *conference;
2692 g_object_get (content, "fs-conference", &conference, NULL);
2693 g_assert (conference != NULL);
2695 /* FIXME: Ugly hack, update when moving a packetization property into
2697 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2698 gst_object_unref (conference);
2704 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2706 EmpathyCallWindow *self)
2708 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2709 FsMediaType media_type;
2711 DEBUG ("removing content");
2713 g_object_get (content, "media-type", &media_type, NULL);
2716 * This assumes that there is only one video stream per channel...
2719 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2721 if (priv->funnel != NULL)
2725 output = priv->video_output_sink;
2727 gst_element_set_state (output, GST_STATE_NULL);
2728 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2730 gst_bin_remove (GST_BIN (priv->pipeline), output);
2731 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2732 priv->funnel = NULL;
2735 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2737 if (priv->audio_output != NULL)
2739 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2741 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2742 priv->audio_output = NULL;
2747 g_assert_not_reached ();
2754 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2756 EmpathyCallWindow *self)
2758 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2760 DEBUG ("Framerate changed to %u", framerate);
2762 if (priv->video_input != NULL)
2763 empathy_video_src_set_framerate (priv->video_input, framerate);
2767 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2770 EmpathyCallWindow *self)
2772 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2774 DEBUG ("Resolution changed to %ux%u", width, height);
2776 if (priv->video_input != NULL)
2778 empathy_video_src_set_resolution (priv->video_input, width, height);
2782 /* Called with global lock held */
2784 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2786 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2790 if (priv->funnel == NULL)
2792 output = priv->video_output_sink;
2794 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2798 g_warning ("Could not create fsfunnel");
2802 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2804 gst_object_unref (priv->funnel);
2805 priv->funnel = NULL;
2806 g_warning ("Could not add funnel to pipeline");
2810 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2812 g_warning ("Could not add the video output widget to the pipeline");
2816 if (!gst_element_link (priv->funnel, output))
2818 g_warning ("Could not link output sink to funnel");
2819 goto error_output_added;
2822 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2824 g_warning ("Could not start video sink");
2825 goto error_output_added;
2828 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2830 g_warning ("Could not start funnel");
2831 goto error_output_added;
2835 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2838 g_warning ("Could not get request pad from funnel");
2845 gst_element_set_locked_state (priv->funnel, TRUE);
2846 gst_element_set_locked_state (output, TRUE);
2848 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2849 gst_element_set_state (output, GST_STATE_NULL);
2851 gst_bin_remove (GST_BIN (priv->pipeline), output);
2852 gst_element_set_locked_state (output, FALSE);
2856 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2857 priv->funnel = NULL;
2862 /* Called with global lock held */
2864 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2867 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2869 GstPadTemplate *template;
2871 if (priv->audio_output == NULL)
2873 priv->audio_output = empathy_audio_sink_new ();
2874 g_object_ref_sink (priv->audio_output);
2876 g_object_bind_property_full (content, "requested-output-volume",
2877 priv->audio_output, "volume",
2879 audio_control_volume_to_element,
2880 element_volume_to_audio_control,
2883 /* Link volumes together, sync the current audio input volume property
2884 * back to farstream first */
2885 g_object_bind_property_full (priv->audio_output, "volume",
2886 content, "reported-output-volume",
2887 G_BINDING_SYNC_CREATE,
2888 element_volume_to_audio_control,
2889 audio_control_volume_to_element,
2892 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2894 g_warning ("Could not add audio sink to pipeline");
2895 g_object_unref (priv->audio_output);
2896 goto error_add_output;
2899 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2901 g_warning ("Could not start audio sink");
2906 /* For raw audio conferences assume that the producer of the raw data
2907 * has already processed it, so turn off any echo cancellation and any
2908 * other audio improvements that come with it */
2909 empathy_audio_sink_set_echo_cancel (
2910 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
2911 !empathy_call_window_content_is_raw (content));
2913 template = gst_element_class_get_pad_template (
2914 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2916 pad = gst_element_request_pad (priv->audio_output,
2917 template, NULL, NULL);
2921 g_warning ("Could not get sink pad from sink");
2928 gst_element_set_locked_state (priv->audio_output, TRUE);
2929 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2930 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2931 priv->audio_output = NULL;
2939 empathy_call_window_update_timer (gpointer user_data)
2941 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2942 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2943 const gchar *status;
2947 time_ = g_timer_elapsed (priv->timer, NULL);
2949 if (priv->call_state == HELD)
2950 status = _("On hold");
2951 else if (!gtk_toggle_tool_button_get_active (
2952 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2955 status = _("Duration");
2957 /* Translators: 'status - minutes:seconds' the caller has been connected */
2958 str = g_strdup_printf (_("%s — %d:%02dm"),
2960 (int) time_ / 60, (int) time_ % 60);
2961 empathy_call_window_status_message (self, str);
2969 EMP_RESPONSE_BALANCE
2973 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2977 switch (response_id)
2979 case GTK_RESPONSE_CLOSE:
2980 gtk_widget_destroy (GTK_WIDGET (info_bar));
2982 case EMP_RESPONSE_BALANCE:
2983 empathy_url_show (GTK_WIDGET (info_bar),
2984 g_object_get_data (G_OBJECT (info_bar), "uri"));
2990 display_error (EmpathyCallWindow *self,
2994 const gchar *details,
2995 const gchar *button_text,
2997 gint button_response)
2999 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3000 GtkWidget *info_bar;
3001 GtkWidget *content_area;
3008 /* Create info bar */
3009 info_bar = gtk_info_bar_new ();
3011 if (button_text != NULL)
3013 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3014 button_text, button_response);
3015 g_object_set_data_full (G_OBJECT (info_bar),
3016 "uri", g_strdup (uri), g_free);
3019 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3020 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3022 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3024 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3026 /* hbox containing the image and the messages vbox */
3027 hbox = gtk_hbox_new (FALSE, 3);
3028 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3031 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3032 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3034 /* vbox containing the main message and the details expander */
3035 vbox = gtk_vbox_new (FALSE, 3);
3036 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3039 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3041 label = gtk_label_new (NULL);
3042 gtk_label_set_markup (GTK_LABEL (label), txt);
3043 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3044 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3047 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3050 if (details != NULL)
3052 GtkWidget *expander;
3054 expander = gtk_expander_new (_("Technical Details"));
3056 txt = g_strdup_printf ("<i>%s</i>", details);
3058 label = gtk_label_new (NULL);
3059 gtk_label_set_markup (GTK_LABEL (label), txt);
3060 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3061 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3064 gtk_container_add (GTK_CONTAINER (expander), label);
3065 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3068 g_signal_connect (info_bar, "response",
3069 G_CALLBACK (on_error_infobar_response_cb), NULL);
3071 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3072 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3073 gtk_widget_show_all (info_bar);
3078 media_stream_error_to_txt (EmpathyCallWindow *self,
3079 TpyCallChannel *call,
3081 TpMediaStreamError error)
3083 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3084 const gchar *cm = NULL;
3090 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3092 return g_strdup_printf (
3093 _("%s's software does not understand any of the audio formats "
3094 "supported by your computer"),
3095 empathy_contact_get_alias (priv->contact));
3097 return g_strdup_printf (
3098 _("%s's software does not understand any of the video formats "
3099 "supported by your computer"),
3100 empathy_contact_get_alias (priv->contact));
3102 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3103 return g_strdup_printf (
3104 _("Can't establish a connection to %s. "
3105 "One of you might be on a network that does not allow "
3106 "direct connections."),
3107 empathy_contact_get_alias (priv->contact));
3109 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3110 return g_strdup (_("There was a failure on the network"));
3112 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3114 return g_strdup (_("The audio formats necessary for this call "
3115 "are not installed on your computer"));
3117 return g_strdup (_("The video formats necessary for this call "
3118 "are not installed on your computer"));
3120 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3121 tp_connection_parse_object_path (
3122 tp_channel_borrow_connection (TP_CHANNEL (call)),
3125 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3126 "product=Telepathy&component=%s", cm);
3128 result = g_strdup_printf (
3129 _("Something unexpected happened in a Telepathy component. "
3130 "Please <a href=\"%s\">report this bug</a> and attach "
3131 "logs gathered from the 'Debug' window in the Help menu."), url);
3137 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3138 return g_strdup (_("There was a failure in the call engine"));
3140 case TP_MEDIA_STREAM_ERROR_EOS:
3141 return g_strdup (_("The end of the stream was reached"));
3143 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3150 empathy_call_window_stream_error (EmpathyCallWindow *self,
3151 TpyCallChannel *call,
3160 desc = media_stream_error_to_txt (self, call, audio, code);
3163 /* No description, use the error message. That's not great as it's not
3164 * localized but it's better than nothing. */
3165 display_error (self, call, icon, title, msg, NULL);
3169 display_error (self, call, icon, title, desc, msg);
3175 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3178 EmpathyCallWindow *self)
3180 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3181 "gnome-stock-mic", _("Can't establish audio stream"));
3185 empathy_call_window_video_stream_error (TpyCallChannel *call,
3188 EmpathyCallWindow *self)
3190 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3191 "camera-web", _("Can't establish video stream"));
3196 show_balance_error (EmpathyCallWindow *self)
3200 gchar *balance, *tmp;
3201 const gchar *uri, *currency;
3205 g_object_get (self->priv->handler,
3206 "call-channel", &call,
3209 conn = tp_channel_borrow_connection (call);
3210 g_object_unref (call);
3212 uri = tp_connection_get_balance_uri (conn);
3214 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3216 /* unknown balance */
3217 balance = g_strdup ("(--)");
3221 char *money = empathy_format_currency (amount, scale, currency);
3223 balance = g_strdup_printf ("%s %s",
3228 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3230 display_error (self,
3232 _("Sorry, you don’t have enough credit for that call."),
3236 EMP_RESPONSE_BALANCE);
3243 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3246 EmpathyCallWindow *self)
3248 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3249 TpyCallChannel *call;
3250 gboolean can_send_video;
3252 if (state == TPY_CALL_STATE_ENDED &&
3253 !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3255 show_balance_error (self);
3259 if (state != TPY_CALL_STATE_ACCEPTED)
3262 if (priv->call_state == CONNECTED)
3265 g_timer_start (priv->timer);
3266 priv->call_state = CONNECTED;
3268 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3270 can_send_video = priv->video_input != NULL &&
3271 empathy_contact_can_voip_video (priv->contact) &&
3272 empathy_camera_monitor_get_available (priv->camera_monitor);
3274 g_object_get (priv->handler, "call-channel", &call, NULL);
3276 if (tpy_call_channel_has_dtmf (call))
3277 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3279 if (priv->video_input == NULL)
3280 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3282 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3284 empathy_call_window_show_hangup_button (self, TRUE);
3286 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3288 clutter_actor_hide (priv->video_output);
3289 gtk_widget_show (priv->remote_user_avatar_widget);
3291 g_object_unref (call);
3293 g_mutex_lock (priv->lock);
3295 priv->timer_id = g_timeout_add_seconds (1,
3296 empathy_call_window_update_timer, self);
3298 g_mutex_unlock (priv->lock);
3300 empathy_call_window_update_timer (self);
3302 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3306 empathy_call_window_show_video_output_cb (gpointer user_data)
3308 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3310 if (self->priv->video_output != NULL)
3312 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3313 clutter_actor_show (self->priv->video_output);
3314 empathy_call_window_raise_actors (self);
3321 empathy_call_window_check_video_cb (gpointer data)
3323 EmpathyCallWindow *self = data;
3325 if (self->priv->got_video)
3327 self->priv->got_video = FALSE;
3331 /* No video in the last N seconds, display the remote avatar */
3332 empathy_call_window_show_video_output (self, FALSE);
3337 /* Called from the streaming thread */
3339 empathy_call_window_video_probe_cb (GstPad *pad,
3340 GstMiniObject *mini_obj,
3341 EmpathyCallWindow *self)
3344 if (GST_IS_EVENT (mini_obj))
3347 if (G_UNLIKELY (!self->priv->got_video))
3349 /* show the remote video */
3350 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3351 empathy_call_window_show_video_output_cb,
3352 g_object_ref (self), g_object_unref);
3354 self->priv->got_video = TRUE;
3360 /* Called from the streaming thread */
3362 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3363 TfContent *content, GstPad *src, gpointer user_data)
3365 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3366 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3367 gboolean retval = FALSE;
3372 g_mutex_lock (priv->lock);
3374 g_object_get (content, "media-type", &media_type, NULL);
3378 case TP_MEDIA_STREAM_TYPE_AUDIO:
3379 pad = empathy_call_window_get_audio_sink_pad (self, content);
3381 case TP_MEDIA_STREAM_TYPE_VIDEO:
3382 g_idle_add (empathy_call_window_show_video_output_cb, self);
3383 pad = empathy_call_window_get_video_sink_pad (self);
3385 gst_pad_add_data_probe (src,
3386 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3387 if (priv->got_video_src > 0)
3388 g_source_remove (priv->got_video_src);
3389 priv->got_video_src = g_timeout_add_seconds (5,
3390 empathy_call_window_check_video_cb, self);
3393 g_assert_not_reached ();
3399 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3400 g_warning ("Could not link %s sink pad",
3401 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3405 gst_object_unref (pad);
3409 /* If no sink could be linked, try to add fakesink to prevent the whole call
3414 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3416 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3418 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3419 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3420 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3422 gst_element_set_locked_state (fakesink, TRUE);
3423 gst_element_set_state (fakesink, GST_STATE_NULL);
3424 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3428 DEBUG ("Could not link real sink, linked fakesink instead");
3430 gst_object_unref (sinkpad);
3434 gst_object_unref (fakesink);
3439 g_mutex_unlock (priv->lock);
3445 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3446 TfContent *content, gpointer user_data)
3448 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3449 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3451 FsMediaType media_type;
3452 gboolean retval = FALSE;
3454 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3455 g_assert (sink != NULL);
3459 case FS_MEDIA_TYPE_AUDIO:
3461 /* For raw audio conferences assume that the receiver of the raw data
3462 * wants it unprocessed, so turn off any echo cancellation and any
3463 * other audio improvements that come with it */
3464 empathy_audio_src_set_echo_cancel (
3465 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3466 !empathy_call_window_content_is_raw (content));
3468 /* Link volumes together, sync the current audio input volume property
3469 * back to farstream first */
3470 g_object_bind_property_full (content, "requested-input-volume",
3471 priv->audio_input, "volume",
3473 audio_control_volume_to_element,
3474 element_volume_to_audio_control,
3477 g_object_bind_property_full (priv->audio_input, "volume",
3478 content, "reported-input-volume",
3479 G_BINDING_SYNC_CREATE,
3480 element_volume_to_audio_control,
3481 audio_control_volume_to_element,
3484 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3486 g_warning ("Could not add audio source to pipeline");
3490 pad = gst_element_get_static_pad (priv->audio_input, "src");
3493 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3494 g_warning ("Could not get source pad from audio source");
3498 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3500 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3501 g_warning ("Could not link audio source to farsight");
3505 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3507 g_warning ("Could not start audio source");
3508 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3509 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3515 case FS_MEDIA_TYPE_VIDEO:
3516 if (priv->video_tee != NULL)
3518 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3519 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3521 g_warning ("Could not link video source input pipeline");
3524 gst_object_unref (pad);
3530 g_assert_not_reached ();
3533 gst_object_unref (sink);
3538 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3540 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3541 GstElement *preview;
3543 disable_camera (self);
3545 DEBUG ("remove video input");
3546 preview = priv->video_preview_sink;
3548 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3549 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3550 gst_element_set_state (preview, GST_STATE_NULL);
3552 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3555 g_object_unref (priv->video_input);
3556 priv->video_input = NULL;
3557 g_object_unref (priv->video_tee);
3558 priv->video_tee = NULL;
3559 clutter_actor_destroy (priv->video_preview);
3560 priv->video_preview = NULL;
3562 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3566 start_call (EmpathyCallWindow *self)
3568 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3570 priv->call_started = TRUE;
3571 empathy_call_handler_start_call (priv->handler,
3572 gtk_get_current_event_time ());
3574 if (empathy_call_handler_has_initial_video (priv->handler))
3576 TpyCallChannel *call;
3579 g_object_get (priv->handler, "call-channel", &call, NULL);
3580 /* If the call channel isn't set yet we're requesting it, if we're
3581 * requesting it with initial video it should be PENDING_SEND when we get
3584 s = TPY_SENDING_STATE_PENDING_SEND;
3586 s = tpy_call_channel_get_video_state (call);
3588 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3589 s == TPY_SENDING_STATE_SENDING)
3591 /* Enable 'send video' buttons and display the preview */
3592 gtk_toggle_tool_button_set_active (
3593 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3597 gtk_toggle_tool_button_set_active (
3598 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3600 if (priv->video_preview == NULL)
3602 create_video_preview (self);
3603 add_video_preview_to_pipeline (self);
3608 g_object_unref (call);
3613 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3616 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3617 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3618 GstState newstate, pending;
3620 empathy_call_handler_bus_message (priv->handler, bus, message);
3622 switch (GST_MESSAGE_TYPE (message))
3624 case GST_MESSAGE_STATE_CHANGED:
3625 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3627 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3629 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3630 !priv->call_started)
3632 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3633 if (newstate == GST_STATE_PAUSED)
3635 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3636 priv->pipeline_playing = TRUE;
3638 if (priv->start_call_when_playing)
3642 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3644 gst_message_parse_state_changed (message, NULL, &newstate,
3647 if (newstate == GST_STATE_PLAYING &&
3648 pending == GST_STATE_VOID_PENDING)
3649 empathy_call_window_stop_camera_spinning (self);
3652 case GST_MESSAGE_ERROR:
3654 GError *error = NULL;
3655 GstElement *gst_error;
3658 gst_message_parse_error (message, &error, &debug);
3659 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3661 g_message ("Element error: %s -- %s\n", error->message, debug);
3663 if (g_str_has_prefix (gst_element_get_name (gst_error),
3664 VIDEO_INPUT_ERROR_PREFIX))
3666 /* Remove the video input and continue */
3667 if (priv->video_input != NULL)
3668 empathy_call_window_remove_video_input (self);
3669 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3673 empathy_call_window_disconnected (self, TRUE);
3675 g_error_free (error);
3678 case GST_MESSAGE_UNKNOWN:
3679 case GST_MESSAGE_EOS:
3680 case GST_MESSAGE_WARNING:
3681 case GST_MESSAGE_INFO:
3682 case GST_MESSAGE_TAG:
3683 case GST_MESSAGE_BUFFERING:
3684 case GST_MESSAGE_STATE_DIRTY:
3685 case GST_MESSAGE_STEP_DONE:
3686 case GST_MESSAGE_CLOCK_PROVIDE:
3687 case GST_MESSAGE_CLOCK_LOST:
3688 case GST_MESSAGE_NEW_CLOCK:
3689 case GST_MESSAGE_STRUCTURE_CHANGE:
3690 case GST_MESSAGE_STREAM_STATUS:
3691 case GST_MESSAGE_APPLICATION:
3692 case GST_MESSAGE_ELEMENT:
3693 case GST_MESSAGE_SEGMENT_START:
3694 case GST_MESSAGE_SEGMENT_DONE:
3695 case GST_MESSAGE_DURATION:
3696 case GST_MESSAGE_ANY:
3705 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3706 GHashTable *members,
3707 EmpathyCallWindow *self)
3709 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3710 GHashTableIter iter;
3711 gpointer key, value;
3712 gboolean held = FALSE;
3714 g_hash_table_iter_init (&iter, members);
3715 while (g_hash_table_iter_next (&iter, &key, &value))
3717 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3719 /* This assumes this is a 1-1 call, otherwise one participant
3720 * putting the call on hold wouldn't mean the call is on hold
3728 priv->call_state = HELD;
3729 else if (priv->call_state == HELD)
3730 priv->call_state = CONNECTED;
3734 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3736 EmpathyCallWindow *self)
3738 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3739 TpyCallChannel *call;
3741 g_object_get (priv->handler, "call-channel", &call, NULL);
3746 tp_g_signal_connect_object (call, "audio-stream-error",
3747 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3748 tp_g_signal_connect_object (call, "video-stream-error",
3749 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3752 tp_g_signal_connect_object (call, "members-changed",
3753 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3755 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3756 empathy_call_window_tones_stopped_cb, self, NULL,
3757 G_OBJECT (call), NULL);
3759 g_object_unref (call);
3763 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3765 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3766 TpyCallChannel *call;
3768 g_signal_connect (priv->handler, "state-changed",
3769 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3770 g_signal_connect (priv->handler, "conference-added",
3771 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3772 g_signal_connect (priv->handler, "conference-removed",
3773 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3774 g_signal_connect (priv->handler, "closed",
3775 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3776 g_signal_connect (priv->handler, "src-pad-added",
3777 G_CALLBACK (empathy_call_window_src_added_cb), self);
3778 g_signal_connect (priv->handler, "content-added",
3779 G_CALLBACK (empathy_call_window_content_added_cb), self);
3780 g_signal_connect (priv->handler, "content-removed",
3781 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3783 /* We connect to ::call-channel unconditionally since we'll
3784 * get new channels if we hangup and redial or if we reuse the
3786 g_signal_connect (priv->handler, "notify::call-channel",
3787 G_CALLBACK (call_handler_notify_call_cb), self);
3789 g_signal_connect (priv->handler, "framerate-changed",
3790 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3791 g_signal_connect (priv->handler, "resolution-changed",
3792 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3794 g_object_get (priv->handler, "call-channel", &call, NULL);
3797 /* We won't get notify::call-channel for this channel, so
3798 * directly call the callback. */
3799 call_handler_notify_call_cb (priv->handler, NULL, self);
3800 g_object_unref (call);
3805 empathy_call_window_realized_cb (GtkWidget *widget,
3806 EmpathyCallWindow *self)
3810 /* Make the hangup button twice as wide */
3811 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3812 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3814 empathy_call_window_connect_handler (self);
3816 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3820 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3821 EmpathyCallWindow *window)
3823 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3825 if (priv->pipeline != NULL)
3827 if (priv->bus_message_source_id != 0)
3829 g_source_remove (priv->bus_message_source_id);
3830 priv->bus_message_source_id = 0;
3833 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3836 if (priv->call_state == CONNECTING)
3837 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3843 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3846 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3848 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3853 gtk_widget_hide (priv->dtmf_panel);
3854 gtk_widget_hide (menu);
3855 gtk_widget_hide (priv->toolbar);
3859 if (priv->dialpad_was_visible_before_fs)
3860 gtk_widget_show (priv->dtmf_panel);
3862 gtk_widget_show (menu);
3863 gtk_widget_show (priv->toolbar);
3865 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3866 priv->original_height_before_fs);
3871 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3873 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3875 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3876 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3877 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3878 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3880 if (priv->video_output != NULL)
3883 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3884 priv->video_output, TRUE, TRUE,
3885 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3892 empathy_call_window_state_event_cb (GtkWidget *widget,
3893 GdkEventWindowState *event, EmpathyCallWindow *window)
3895 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3897 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3898 gboolean set_fullscreen = event->new_window_state &
3899 GDK_WINDOW_STATE_FULLSCREEN;
3903 gboolean dialpad_was_visible;
3904 GtkAllocation allocation;
3905 gint original_width, original_height;
3907 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3908 original_width = allocation.width;
3909 original_height = allocation.height;
3911 g_object_get (priv->dtmf_panel,
3912 "visible", &dialpad_was_visible,
3915 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3916 priv->original_width_before_fs = original_width;
3917 priv->original_height_before_fs = original_height;
3919 if (priv->video_output_motion_handler_id == 0 &&
3920 priv->video_output != NULL)
3922 priv->video_output_motion_handler_id = g_signal_connect (
3923 G_OBJECT (priv->video_container), "motion-notify-event",
3924 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3930 disconnect_video_output_motion_handler (window);
3933 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3935 show_controls (window, set_fullscreen);
3936 show_borders (window, set_fullscreen);
3937 gtk_action_set_stock_id (priv->menu_fullscreen,
3938 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3939 priv->is_fullscreen = set_fullscreen;
3946 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3949 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3950 int w, h, dialpad_width;
3951 GtkAllocation allocation;
3953 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3954 w = allocation.width;
3955 h = allocation.height;
3957 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3961 gtk_widget_show (priv->dtmf_panel);
3967 gtk_widget_hide (priv->dtmf_panel);
3971 gtk_window_resize (GTK_WINDOW (window), w, h);
3975 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3978 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3979 TpyCallChannel *call;
3981 priv->sending_video = (state == CAMERA_STATE_ON);
3983 if (state == CAMERA_STATE_ON)
3985 /* When we start sending video, we want to show the video preview by
3987 display_video_preview (window, TRUE);
3991 display_video_preview (window, FALSE);
3994 if (priv->call_state != CONNECTED)
3997 g_object_get (priv->handler, "call-channel", &call, NULL);
3998 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3999 tpy_call_channel_send_video (call, priv->sending_video);
4000 g_object_unref (call);
4004 empathy_call_window_hangup_cb (gpointer object,
4005 EmpathyCallWindow *self)
4007 empathy_call_handler_stop_call (self->priv->handler);
4009 empathy_call_window_disconnected (self, TRUE);
4013 empathy_call_window_restart_call (EmpathyCallWindow *window)
4015 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4017 /* Remove error info bars */
4018 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4019 (GtkCallback) gtk_widget_destroy, NULL);
4021 create_video_output_widget (window);
4022 priv->outgoing = TRUE;
4023 empathy_call_window_set_state_connecting (window);
4025 if (priv->pipeline_playing)
4026 start_call (window);
4028 /* call will be started when the pipeline is ready */
4029 priv->start_call_when_playing = TRUE;
4031 empathy_call_window_setup_avatars (window, priv->handler);
4033 empathy_call_window_show_hangup_button (window, TRUE);
4037 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4038 EmpathyCallWindow *window)
4042 active = gtk_toggle_tool_button_get_active (button);
4044 empathy_call_window_show_dialpad (window, active);
4048 empathy_call_window_fullscreen_cb (gpointer object,
4049 EmpathyCallWindow *window)
4051 empathy_call_window_fullscreen_toggle (window);
4055 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4057 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4059 if (priv->is_fullscreen)
4060 gtk_window_unfullscreen (GTK_WINDOW (window));
4062 gtk_window_fullscreen (GTK_WINDOW (window));
4066 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4067 GdkEventButton *event, EmpathyCallWindow *window)
4069 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4071 empathy_call_window_video_menu_popup (window, event->button);
4079 empathy_call_window_key_press_cb (GtkWidget *video_output,
4080 GdkEventKey *event, EmpathyCallWindow *window)
4082 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4084 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4086 /* Since we are in fullscreen mode, toggling will bring us back to
4088 empathy_call_window_fullscreen_toggle (window);
4096 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4097 GdkEventMotion *event, EmpathyCallWindow *window)
4099 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4101 if (priv->is_fullscreen)
4103 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4105 /* Show the bottom toolbar */
4106 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4113 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4117 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4119 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4121 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4122 button, gtk_get_current_event_time ());
4123 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4127 empathy_call_window_status_message (EmpathyCallWindow *self,
4130 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4134 empathy_call_window_volume_changed_cb (GtkScaleButton *button,
4135 gdouble value, EmpathyCallWindow *window)
4137 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4139 if (priv->audio_output == NULL)
4142 empathy_audio_sink_set_volume (EMPATHY_GST_AUDIO_SINK (priv->audio_output),
4147 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4149 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4151 return priv->ui_manager;
4154 EmpathyGstAudioSrc *
4155 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4157 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4159 return (EmpathyGstAudioSrc *) priv->audio_input;
4162 EmpathyGstVideoSrc *
4163 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4165 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);